1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup.h"
44 #include "gtkwidget.h"
45 #include "gtkwindow.h"
46 #include "gtkbindings.h"
47 #include "gtkprivate.h"
49 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
50 #include <gobject/gvaluecollector.h>
51 #include <gobject/gobjectnotifyqueue.c>
52 #include <cairo-gobject.h>
53 #include "gdk/gdkkeysyms.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
64 * @Short_description: Base class for all widgets
67 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
68 * widget lifecycle, states and style.
70 * <refsect2 id="style-properties">
72 * <structname>GtkWidget</structname> introduces <firstterm>style
73 * properties</firstterm> - these are basically object properties that are stored
74 * not on the object, but in the style object associated to the widget. Style
75 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
76 * This mechanism is used for configuring such things as the location of the
77 * scrollbar arrows through the theme, giving theme authors more control over the
78 * look of applications without the need to write a theme engine in C.
81 * Use gtk_widget_class_install_style_property() to install style properties for
82 * a widget class, gtk_widget_class_find_style_property() or
83 * gtk_widget_class_list_style_properties() to get information about existing
84 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
85 * gtk_widget_style_get_valist() to obtain the value of a style property.
88 * <refsect2 id="GtkWidget-BUILDER-UI">
89 * <title>GtkWidget as GtkBuildable</title>
91 * The GtkWidget implementation of the GtkBuildable interface supports a
92 * custom <accelerator> element, which has attributes named key,
93 * modifiers and signal and allows to specify accelerators.
96 * <title>A UI definition fragment specifying an accelerator</title>
97 * <programlisting><![CDATA[
98 * <object class="GtkButton">
99 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
101 * ]]></programlisting>
104 * In addition to accelerators, <structname>GtkWidget</structname> also support a
105 * custom <accessible> element, which supports actions and relations.
106 * Properties on the accessible implementation of an object can be set by accessing the
107 * internal child "accessible" of a <structname>GtkWidget</structname>.
110 * <title>A UI definition fragment specifying an accessible</title>
111 * <programlisting><![CDATA[
112 * <object class="GtkButton" id="label1"/>
113 * <property name="label">I am a Label for a Button</property>
115 * <object class="GtkButton" id="button1">
117 * <action action_name="click" translatable="yes">Click the button.</action>
118 * <relation target="label1" type="labelled-by"/>
120 * <child internal-child="accessible">
121 * <object class="AtkObject" id="a11y-button1">
122 * <property name="AtkObject::name">Clickable Button</property>
126 * ]]></programlisting>
131 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
132 #define INIT_PATH_SIZE (512)
134 struct _GtkWidgetPrivate
136 /* The state of the widget. There are actually only
137 * 5 widget states (defined in "gtkenums.h")
142 /* The saved state of the widget. When a widget's state
143 * is changed to GTK_STATE_INSENSITIVE via
144 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
145 * the old state is kept around in this field. The state
146 * will be restored once the widget gets sensitive again.
148 guint saved_state : 3;
150 /* unused bits in our 32-bit block */
153 /* The widget's name. If the widget does not have a name
154 * (the name is NULL), then its name (as returned by
155 * "gtk_widget_get_name") is its class's name.
156 * Among other things, the widget name is used to determine
157 * the style to use for a widget.
161 /* The style for the widget. The style contains the
162 * colors the widget should be drawn in for each state
163 * along with graphics contexts used to draw with and
164 * the font to use for text.
168 /* The widget's allocated size.
170 GtkAllocation allocation;
172 /* The widget's requested sizes */
173 SizeRequestCache requests;
175 /* The widget's window or its parent window if it does
176 * not have a window. (Which will be indicated by the
177 * GTK_NO_WINDOW flag being set).
181 /* The widget's parent.
210 BUTTON_RELEASE_EVENT,
225 PROPERTY_NOTIFY_EVENT,
226 SELECTION_CLEAR_EVENT,
227 SELECTION_REQUEST_EVENT,
228 SELECTION_NOTIFY_EVENT,
243 VISIBILITY_NOTIFY_EVENT,
247 ACCEL_CLOSURES_CHANGED,
273 PROP_RECEIVES_DEFAULT,
274 PROP_COMPOSITE_CHILD,
277 PROP_EXTENSION_EVENTS,
283 PROP_DOUBLE_BUFFERED,
293 typedef struct _GtkStateData GtkStateData;
298 guint state_restoration : 1;
299 guint parent_sensitive : 1;
300 guint use_forall : 1;
303 /* --- prototypes --- */
304 static void gtk_widget_class_init (GtkWidgetClass *klass);
305 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
306 static void gtk_widget_init (GtkWidget *widget);
307 static void gtk_widget_set_property (GObject *object,
311 static void gtk_widget_get_property (GObject *object,
315 static void gtk_widget_dispose (GObject *object);
316 static void gtk_widget_real_destroy (GtkObject *object);
317 static void gtk_widget_finalize (GObject *object);
318 static void gtk_widget_real_show (GtkWidget *widget);
319 static void gtk_widget_real_hide (GtkWidget *widget);
320 static void gtk_widget_real_map (GtkWidget *widget);
321 static void gtk_widget_real_unmap (GtkWidget *widget);
322 static void gtk_widget_real_realize (GtkWidget *widget);
323 static void gtk_widget_real_unrealize (GtkWidget *widget);
324 static void gtk_widget_real_size_request (GtkWidget *widget,
325 GtkRequisition *requisition);
326 static void gtk_widget_real_size_allocate (GtkWidget *widget,
327 GtkAllocation *allocation);
328 static void gtk_widget_real_style_set (GtkWidget *widget,
329 GtkStyle *previous_style);
330 static void gtk_widget_real_direction_changed(GtkWidget *widget,
331 GtkTextDirection previous_direction);
333 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
334 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
337 gboolean keyboard_tip,
338 GtkTooltip *tooltip);
339 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
340 GtkWidgetHelpType help_type);
342 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
344 GParamSpec **pspecs);
345 static gboolean gtk_widget_real_expose_event (GtkWidget *widget,
346 GdkEventExpose *event);
347 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
349 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
351 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
352 GdkEventFocus *event);
353 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
354 GdkEventFocus *event);
355 static gboolean gtk_widget_real_focus (GtkWidget *widget,
356 GtkDirectionType direction);
357 static void gtk_widget_real_move_focus (GtkWidget *widget,
358 GtkDirectionType direction);
359 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
360 GtkDirectionType direction);
361 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
362 static void gtk_widget_update_pango_context (GtkWidget *widget);
363 static void gtk_widget_propagate_state (GtkWidget *widget,
365 static void gtk_widget_reset_rc_style (GtkWidget *widget);
366 static void gtk_widget_set_style_internal (GtkWidget *widget,
368 gboolean initial_emission);
369 static gint gtk_widget_event_internal (GtkWidget *widget,
371 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
372 gboolean group_cycling);
373 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
374 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
375 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
376 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
377 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
378 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
379 cairo_region_t *region);
380 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
381 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
382 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
385 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
386 gboolean has_tooltip,
388 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
389 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
391 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
392 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
394 const gchar *childname);
395 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
398 const GValue *value);
399 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
402 const gchar *tagname,
403 GMarkupParser *parser,
405 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
408 const gchar *tagname,
410 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
411 GtkBuilder *builder);
413 static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
414 static void gtk_widget_real_get_width (GtkSizeRequest *widget,
417 static void gtk_widget_real_get_height (GtkSizeRequest *widget,
421 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
424 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
425 GtkOrientation orientation,
429 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
430 GtkAllocation *allocation);
432 static void gtk_widget_set_usize_internal (GtkWidget *widget,
436 static void gtk_widget_add_events_internal (GtkWidget *widget,
440 /* --- variables --- */
441 static gpointer gtk_widget_parent_class = NULL;
442 static guint widget_signals[LAST_SIGNAL] = { 0 };
443 static GtkStyle *gtk_default_style = NULL;
444 static guint composite_child_stack = 0;
445 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
446 static GParamSpecPool *style_property_spec_pool = NULL;
448 static GQuark quark_property_parser = 0;
449 static GQuark quark_aux_info = 0;
450 static GQuark quark_accel_path = 0;
451 static GQuark quark_accel_closures = 0;
452 static GQuark quark_event_mask = 0;
453 static GQuark quark_device_event_mask = 0;
454 static GQuark quark_extension_event_mode = 0;
455 static GQuark quark_parent_window = 0;
456 static GQuark quark_pointer_window = 0;
457 static GQuark quark_shape_info = 0;
458 static GQuark quark_input_shape_info = 0;
459 static GQuark quark_pango_context = 0;
460 static GQuark quark_rc_style = 0;
461 static GQuark quark_accessible_object = 0;
462 static GQuark quark_mnemonic_labels = 0;
463 static GQuark quark_tooltip_markup = 0;
464 static GQuark quark_has_tooltip = 0;
465 static GQuark quark_tooltip_window = 0;
466 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
467 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
469 /* --- functions --- */
471 gtk_widget_get_type (void)
473 static GType widget_type = 0;
475 if (G_UNLIKELY (widget_type == 0))
477 const GTypeInfo widget_info =
479 sizeof (GtkWidgetClass),
480 NULL, /* base_init */
481 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
482 (GClassInitFunc) gtk_widget_class_init,
483 NULL, /* class_finalize */
484 NULL, /* class_init */
487 (GInstanceInitFunc) gtk_widget_init,
488 NULL, /* value_table */
491 const GInterfaceInfo accessibility_info =
493 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
494 (GInterfaceFinalizeFunc) NULL,
495 NULL /* interface data */
498 const GInterfaceInfo buildable_info =
500 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
501 (GInterfaceFinalizeFunc) NULL,
502 NULL /* interface data */
505 const GInterfaceInfo layout_info =
507 (GInterfaceInitFunc) gtk_widget_size_request_init,
508 (GInterfaceFinalizeFunc) NULL,
509 NULL /* interface data */
512 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
513 &widget_info, G_TYPE_FLAG_ABSTRACT);
515 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
516 &accessibility_info) ;
517 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
519 g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
527 child_property_notify_dispatcher (GObject *object,
531 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
534 /* We guard against the draw signal callbacks modifying the state of the
535 * cairo context by surounding it with save/restore.
536 * Maybe we should also cairo_new_path() just to be sure?
539 gtk_widget_draw_marshaller (GClosure *closure,
540 GValue *return_value,
541 guint n_param_values,
542 const GValue *param_values,
543 gpointer invocation_hint,
544 gpointer marshal_data)
546 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
550 _gtk_marshal_BOOLEAN__BOXED (closure,
561 gtk_widget_class_init (GtkWidgetClass *klass)
563 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
564 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
565 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
566 GtkBindingSet *binding_set;
568 gtk_widget_parent_class = g_type_class_peek_parent (klass);
570 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
571 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
572 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
573 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
574 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
575 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
576 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
577 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
578 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
579 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
580 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
581 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
582 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
583 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
584 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
585 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
586 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
587 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
589 style_property_spec_pool = g_param_spec_pool_new (FALSE);
590 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
591 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
592 cpn_context.dispatcher = child_property_notify_dispatcher;
593 _gtk_widget_child_property_notify_context = &cpn_context;
595 gobject_class->dispose = gtk_widget_dispose;
596 gobject_class->finalize = gtk_widget_finalize;
597 gobject_class->set_property = gtk_widget_set_property;
598 gobject_class->get_property = gtk_widget_get_property;
600 object_class->destroy = gtk_widget_real_destroy;
602 klass->activate_signal = 0;
603 klass->set_scroll_adjustments_signal = 0;
604 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
605 klass->show = gtk_widget_real_show;
606 klass->show_all = gtk_widget_show;
607 klass->hide = gtk_widget_real_hide;
608 klass->hide_all = gtk_widget_hide;
609 klass->map = gtk_widget_real_map;
610 klass->unmap = gtk_widget_real_unmap;
611 klass->realize = gtk_widget_real_realize;
612 klass->unrealize = gtk_widget_real_unrealize;
613 klass->size_request = gtk_widget_real_size_request;
614 klass->size_allocate = gtk_widget_real_size_allocate;
615 klass->state_changed = NULL;
616 klass->parent_set = NULL;
617 klass->hierarchy_changed = NULL;
618 klass->style_set = gtk_widget_real_style_set;
619 klass->direction_changed = gtk_widget_real_direction_changed;
620 klass->grab_notify = NULL;
621 klass->child_notify = NULL;
623 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
624 klass->grab_focus = gtk_widget_real_grab_focus;
625 klass->focus = gtk_widget_real_focus;
627 klass->button_press_event = NULL;
628 klass->button_release_event = NULL;
629 klass->motion_notify_event = NULL;
630 klass->delete_event = NULL;
631 klass->destroy_event = NULL;
632 klass->expose_event = gtk_widget_real_expose_event;
633 klass->key_press_event = gtk_widget_real_key_press_event;
634 klass->key_release_event = gtk_widget_real_key_release_event;
635 klass->enter_notify_event = NULL;
636 klass->leave_notify_event = NULL;
637 klass->configure_event = NULL;
638 klass->focus_in_event = gtk_widget_real_focus_in_event;
639 klass->focus_out_event = gtk_widget_real_focus_out_event;
640 klass->map_event = NULL;
641 klass->unmap_event = NULL;
642 klass->window_state_event = NULL;
643 klass->property_notify_event = _gtk_selection_property_notify;
644 klass->selection_clear_event = _gtk_selection_clear;
645 klass->selection_request_event = _gtk_selection_request;
646 klass->selection_notify_event = _gtk_selection_notify;
647 klass->selection_received = NULL;
648 klass->proximity_in_event = NULL;
649 klass->proximity_out_event = NULL;
650 klass->drag_begin = NULL;
651 klass->drag_end = NULL;
652 klass->drag_data_delete = NULL;
653 klass->drag_leave = NULL;
654 klass->drag_motion = NULL;
655 klass->drag_drop = NULL;
656 klass->drag_data_received = NULL;
657 klass->screen_changed = NULL;
658 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
659 klass->grab_broken_event = NULL;
660 klass->query_tooltip = gtk_widget_real_query_tooltip;
662 klass->show_help = gtk_widget_real_show_help;
664 /* Accessibility support */
665 klass->get_accessible = gtk_widget_real_get_accessible;
667 klass->no_expose_event = NULL;
669 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
670 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
672 g_object_class_install_property (gobject_class,
674 g_param_spec_string ("name",
676 P_("The name of the widget"),
678 GTK_PARAM_READWRITE));
679 g_object_class_install_property (gobject_class,
681 g_param_spec_object ("parent",
683 P_("The parent widget of this widget. Must be a Container widget"),
685 GTK_PARAM_READWRITE));
687 g_object_class_install_property (gobject_class,
689 g_param_spec_int ("width-request",
691 P_("Override for width request of the widget, or -1 if natural request should be used"),
695 GTK_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class,
698 g_param_spec_int ("height-request",
699 P_("Height request"),
700 P_("Override for height request of the widget, or -1 if natural request should be used"),
704 GTK_PARAM_READWRITE));
705 g_object_class_install_property (gobject_class,
707 g_param_spec_boolean ("visible",
709 P_("Whether the widget is visible"),
711 GTK_PARAM_READWRITE));
712 g_object_class_install_property (gobject_class,
714 g_param_spec_boolean ("sensitive",
716 P_("Whether the widget responds to input"),
718 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_boolean ("app-paintable",
722 P_("Application paintable"),
723 P_("Whether the application will paint directly on the widget"),
725 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_boolean ("can-focus",
730 P_("Whether the widget can accept the input focus"),
732 GTK_PARAM_READWRITE));
733 g_object_class_install_property (gobject_class,
735 g_param_spec_boolean ("has-focus",
737 P_("Whether the widget has the input focus"),
739 GTK_PARAM_READWRITE));
740 g_object_class_install_property (gobject_class,
742 g_param_spec_boolean ("is-focus",
744 P_("Whether the widget is the focus widget within the toplevel"),
746 GTK_PARAM_READWRITE));
747 g_object_class_install_property (gobject_class,
749 g_param_spec_boolean ("can-default",
751 P_("Whether the widget can be the default widget"),
753 GTK_PARAM_READWRITE));
754 g_object_class_install_property (gobject_class,
756 g_param_spec_boolean ("has-default",
758 P_("Whether the widget is the default widget"),
760 GTK_PARAM_READWRITE));
761 g_object_class_install_property (gobject_class,
762 PROP_RECEIVES_DEFAULT,
763 g_param_spec_boolean ("receives-default",
764 P_("Receives default"),
765 P_("If TRUE, the widget will receive the default action when it is focused"),
767 GTK_PARAM_READWRITE));
768 g_object_class_install_property (gobject_class,
769 PROP_COMPOSITE_CHILD,
770 g_param_spec_boolean ("composite-child",
771 P_("Composite child"),
772 P_("Whether the widget is part of a composite widget"),
774 GTK_PARAM_READABLE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_object ("style",
779 P_("The style of the widget, which contains information about how it will look (colors etc)"),
781 GTK_PARAM_READWRITE));
782 g_object_class_install_property (gobject_class,
784 g_param_spec_flags ("events",
786 P_("The event mask that decides what kind of GdkEvents this widget gets"),
789 GTK_PARAM_READWRITE));
790 g_object_class_install_property (gobject_class,
791 PROP_EXTENSION_EVENTS,
792 g_param_spec_enum ("extension-events",
793 P_("Extension events"),
794 P_("The mask that decides what kind of extension events this widget gets"),
795 GDK_TYPE_EXTENSION_MODE,
796 GDK_EXTENSION_EVENTS_NONE,
797 GTK_PARAM_READWRITE));
798 g_object_class_install_property (gobject_class,
800 g_param_spec_boolean ("no-show-all",
802 P_("Whether gtk_widget_show_all() should not affect this widget"),
804 GTK_PARAM_READWRITE));
807 * GtkWidget:has-tooltip:
809 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
810 * A value of %TRUE indicates that @widget can have a tooltip, in this case
811 * the widget will be queried using #GtkWidget::query-tooltip to determine
812 * whether it will provide a tooltip or not.
814 * Note that setting this property to %TRUE for the first time will change
815 * the event masks of the GdkWindows of this widget to include leave-notify
816 * and motion-notify events. This cannot and will not be undone when the
817 * property is set to %FALSE again.
821 g_object_class_install_property (gobject_class,
823 g_param_spec_boolean ("has-tooltip",
825 P_("Whether this widget has a tooltip"),
827 GTK_PARAM_READWRITE));
829 * GtkWidget:tooltip-text:
831 * Sets the text of tooltip to be the given string.
833 * Also see gtk_tooltip_set_text().
835 * This is a convenience property which will take care of getting the
836 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
837 * will automatically be set to %TRUE and there will be taken care of
838 * #GtkWidget::query-tooltip in the default signal handler.
842 g_object_class_install_property (gobject_class,
844 g_param_spec_string ("tooltip-text",
846 P_("The contents of the tooltip for this widget"),
848 GTK_PARAM_READWRITE));
850 * GtkWidget:tooltip-markup:
852 * Sets the text of tooltip to be the given string, which is marked up
853 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
854 * Also see gtk_tooltip_set_markup().
856 * This is a convenience property which will take care of getting the
857 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
858 * will automatically be set to %TRUE and there will be taken care of
859 * #GtkWidget::query-tooltip in the default signal handler.
863 g_object_class_install_property (gobject_class,
865 g_param_spec_string ("tooltip-markup",
866 P_("Tooltip markup"),
867 P_("The contents of the tooltip for this widget"),
869 GTK_PARAM_READWRITE));
874 * The widget's window if it is realized, %NULL otherwise.
878 g_object_class_install_property (gobject_class,
880 g_param_spec_object ("window",
882 P_("The widget's window if it is realized"),
884 GTK_PARAM_READABLE));
887 * GtkWidget:double-buffered
889 * Whether the widget is double buffered.
893 g_object_class_install_property (gobject_class,
894 PROP_DOUBLE_BUFFERED,
895 g_param_spec_boolean ("double-buffered",
896 P_("Double Buffered"),
897 P_("Whether the widget is double buffered"),
899 GTK_PARAM_READWRITE));
904 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
908 g_object_class_install_property (gobject_class,
910 g_param_spec_enum ("halign",
911 P_("Horizontal Alignment"),
912 P_("How to position in extra horizontal space"),
915 GTK_PARAM_READWRITE));
920 * How to distribute vertical space if widget gets extra space, see #GtkAlign
924 g_object_class_install_property (gobject_class,
926 g_param_spec_enum ("valign",
927 P_("Vertical Alignment"),
928 P_("How to position in extra vertical space"),
931 GTK_PARAM_READWRITE));
934 * GtkWidget:margin-left
936 * Margin on left side of widget.
938 * This property adds margin outside of the widget's normal size
939 * request, the margin will be added in addition to the size from
940 * gtk_widget_set_size_request() for example.
944 g_object_class_install_property (gobject_class,
946 g_param_spec_int ("margin-left",
947 P_("Margin on Left"),
948 P_("Pixels of extra space on the left side"),
952 GTK_PARAM_READWRITE));
955 * GtkWidget:margin-right
957 * Margin on right side of widget.
959 * This property adds margin outside of the widget's normal size
960 * request, the margin will be added in addition to the size from
961 * gtk_widget_set_size_request() for example.
965 g_object_class_install_property (gobject_class,
967 g_param_spec_int ("margin-right",
968 P_("Margin on Right"),
969 P_("Pixels of extra space on the right side"),
973 GTK_PARAM_READWRITE));
976 * GtkWidget:margin-top
978 * Margin on top side of widget.
980 * This property adds margin outside of the widget's normal size
981 * request, the margin will be added in addition to the size from
982 * gtk_widget_set_size_request() for example.
986 g_object_class_install_property (gobject_class,
988 g_param_spec_int ("margin-top",
990 P_("Pixels of extra space on the top side"),
994 GTK_PARAM_READWRITE));
997 * GtkWidget:margin-bottom
999 * Margin on bottom side of widget.
1001 * This property adds margin outside of the widget's normal size
1002 * request, the margin will be added in addition to the size from
1003 * gtk_widget_set_size_request() for example.
1007 g_object_class_install_property (gobject_class,
1009 g_param_spec_int ("margin-bottom",
1010 P_("Margin on Bottom"),
1011 P_("Pixels of extra space on the bottom side"),
1015 GTK_PARAM_READWRITE));
1020 * Sets all four sides' margin at once. If read, returns max
1021 * margin on any side.
1025 g_object_class_install_property (gobject_class,
1027 g_param_spec_int ("margin",
1029 P_("Pixels of extra space on all four sides"),
1033 GTK_PARAM_READWRITE));
1037 * @widget: the object which received the signal.
1039 widget_signals[SHOW] =
1040 g_signal_new (I_("show"),
1041 G_TYPE_FROM_CLASS (gobject_class),
1043 G_STRUCT_OFFSET (GtkWidgetClass, show),
1045 _gtk_marshal_VOID__VOID,
1050 * @widget: the object which received the signal.
1052 widget_signals[HIDE] =
1053 g_signal_new (I_("hide"),
1054 G_TYPE_FROM_CLASS (gobject_class),
1056 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1058 _gtk_marshal_VOID__VOID,
1063 * @widget: the object which received the signal.
1065 widget_signals[MAP] =
1066 g_signal_new (I_("map"),
1067 G_TYPE_FROM_CLASS (gobject_class),
1069 G_STRUCT_OFFSET (GtkWidgetClass, map),
1071 _gtk_marshal_VOID__VOID,
1076 * @widget: the object which received the signal.
1078 widget_signals[UNMAP] =
1079 g_signal_new (I_("unmap"),
1080 G_TYPE_FROM_CLASS (gobject_class),
1082 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1084 _gtk_marshal_VOID__VOID,
1088 * GtkWidget::realize:
1089 * @widget: the object which received the signal.
1091 widget_signals[REALIZE] =
1092 g_signal_new (I_("realize"),
1093 G_TYPE_FROM_CLASS (gobject_class),
1095 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1097 _gtk_marshal_VOID__VOID,
1101 * GtkWidget::unrealize:
1102 * @widget: the object which received the signal.
1104 widget_signals[UNREALIZE] =
1105 g_signal_new (I_("unrealize"),
1106 G_TYPE_FROM_CLASS (gobject_class),
1108 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1110 _gtk_marshal_VOID__VOID,
1114 * GtkWidget::size-request:
1115 * @widget: the object which received the signal.
1118 widget_signals[SIZE_REQUEST] =
1119 g_signal_new (I_("size-request"),
1120 G_TYPE_FROM_CLASS (gobject_class),
1122 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1124 _gtk_marshal_VOID__BOXED,
1126 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1129 * GtkWidget::size-allocate:
1130 * @widget: the object which received the signal.
1133 widget_signals[SIZE_ALLOCATE] =
1134 g_signal_new (I_("size-allocate"),
1135 G_TYPE_FROM_CLASS (gobject_class),
1137 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1139 _gtk_marshal_VOID__BOXED,
1141 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1144 * GtkWidget::state-changed:
1145 * @widget: the object which received the signal.
1146 * @state: the previous state
1148 * The ::state-changed signal is emitted when the widget state changes.
1149 * See gtk_widget_get_state().
1151 widget_signals[STATE_CHANGED] =
1152 g_signal_new (I_("state-changed"),
1153 G_TYPE_FROM_CLASS (gobject_class),
1155 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1157 _gtk_marshal_VOID__ENUM,
1159 GTK_TYPE_STATE_TYPE);
1162 * GtkWidget::parent-set:
1163 * @widget: the object on which the signal is emitted
1164 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1165 * just got its initial parent.
1167 * The ::parent-set signal is emitted when a new parent
1168 * has been set on a widget.
1170 widget_signals[PARENT_SET] =
1171 g_signal_new (I_("parent-set"),
1172 G_TYPE_FROM_CLASS (gobject_class),
1174 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1176 _gtk_marshal_VOID__OBJECT,
1181 * GtkWidget::hierarchy-changed:
1182 * @widget: the object on which the signal is emitted
1183 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1184 * if the widget was previously unanchored
1186 * The ::hierarchy-changed signal is emitted when the
1187 * anchored state of a widget changes. A widget is
1188 * <firstterm>anchored</firstterm> when its toplevel
1189 * ancestor is a #GtkWindow. This signal is emitted when
1190 * a widget changes from un-anchored to anchored or vice-versa.
1192 widget_signals[HIERARCHY_CHANGED] =
1193 g_signal_new (I_("hierarchy-changed"),
1194 G_TYPE_FROM_CLASS (gobject_class),
1196 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1198 _gtk_marshal_VOID__OBJECT,
1203 * GtkWidget::style-set:
1204 * @widget: the object on which the signal is emitted
1205 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1206 * just got its initial style
1208 * The ::style-set signal is emitted when a new style has been set
1209 * on a widget. Note that style-modifying functions like
1210 * gtk_widget_modify_base() also cause this signal to be emitted.
1212 widget_signals[STYLE_SET] =
1213 g_signal_new (I_("style-set"),
1214 G_TYPE_FROM_CLASS (gobject_class),
1216 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1218 _gtk_marshal_VOID__OBJECT,
1222 * GtkWidget::direction-changed:
1223 * @widget: the object on which the signal is emitted
1224 * @previous_direction: the previous text direction of @widget
1226 * The ::direction-changed signal is emitted when the text direction
1227 * of a widget changes.
1229 widget_signals[DIRECTION_CHANGED] =
1230 g_signal_new (I_("direction-changed"),
1231 G_TYPE_FROM_CLASS (gobject_class),
1233 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1235 _gtk_marshal_VOID__ENUM,
1237 GTK_TYPE_TEXT_DIRECTION);
1240 * GtkWidget::grab-notify:
1241 * @widget: the object which received the signal
1242 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1243 * if it becomes unshadowed
1245 * The ::grab-notify signal is emitted when a widget becomes
1246 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1247 * another widget, or when it becomes unshadowed due to a grab
1250 * A widget is shadowed by a gtk_grab_add() when the topmost
1251 * grab widget in the grab stack of its window group is not
1254 widget_signals[GRAB_NOTIFY] =
1255 g_signal_new (I_("grab-notify"),
1256 G_TYPE_FROM_CLASS (gobject_class),
1258 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1260 _gtk_marshal_VOID__BOOLEAN,
1265 * GtkWidget::child-notify:
1266 * @widget: the object which received the signal
1267 * @pspec: the #GParamSpec of the changed child property
1269 * The ::child-notify signal is emitted for each
1270 * <link linkend="child-properties">child property</link> that has
1271 * changed on an object. The signal's detail holds the property name.
1273 widget_signals[CHILD_NOTIFY] =
1274 g_signal_new (I_("child-notify"),
1275 G_TYPE_FROM_CLASS (gobject_class),
1276 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1277 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1279 g_cclosure_marshal_VOID__PARAM,
1285 * @widget: the object which received the signal
1286 * @cr: the cairo context to draw to
1287 * @width: width of the widget
1288 * @height: height of the widget
1290 * This signal is emitted when a widget is supposed to render itself.
1291 * The @widget's top left corner must be painted at the origin of
1292 * the passed in context and be sized in the given @width and @height.
1294 * Signal handlers connected to this signal can modify the cairo
1295 * context passed as @cr in any way they like and don't need to
1296 * restore it. The signal emission takes care of calling cairo_save()
1297 * before and cairo_restore() after invoking the handler.
1299 widget_signals[DRAW] =
1300 g_signal_new (I_("draw"),
1301 G_TYPE_FROM_CLASS (gobject_class),
1303 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1304 _gtk_boolean_handled_accumulator, NULL,
1305 gtk_widget_draw_marshaller,
1307 CAIRO_GOBJECT_TYPE_CONTEXT);
1310 * GtkWidget::mnemonic-activate:
1311 * @widget: the object which received the signal.
1314 widget_signals[MNEMONIC_ACTIVATE] =
1315 g_signal_new (I_("mnemonic-activate"),
1316 G_TYPE_FROM_CLASS (gobject_class),
1318 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1319 _gtk_boolean_handled_accumulator, NULL,
1320 _gtk_marshal_BOOLEAN__BOOLEAN,
1325 * GtkWidget::grab-focus:
1326 * @widget: the object which received the signal.
1328 widget_signals[GRAB_FOCUS] =
1329 g_signal_new (I_("grab-focus"),
1330 G_TYPE_FROM_CLASS (gobject_class),
1331 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1332 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1334 _gtk_marshal_VOID__VOID,
1339 * @widget: the object which received the signal.
1342 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1344 widget_signals[FOCUS] =
1345 g_signal_new (I_("focus"),
1346 G_TYPE_FROM_CLASS (object_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1349 _gtk_boolean_handled_accumulator, NULL,
1350 _gtk_marshal_BOOLEAN__ENUM,
1352 GTK_TYPE_DIRECTION_TYPE);
1355 * GtkWidget::move-focus:
1356 * @widget: the object which received the signal.
1359 widget_signals[MOVE_FOCUS] =
1360 g_signal_new_class_handler (I_("move-focus"),
1361 G_TYPE_FROM_CLASS (object_class),
1362 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1363 G_CALLBACK (gtk_widget_real_move_focus),
1365 _gtk_marshal_VOID__ENUM,
1368 GTK_TYPE_DIRECTION_TYPE);
1371 * @widget: the object which received the signal.
1372 * @event: the #GdkEvent which triggered this signal
1374 * The GTK+ main loop will emit three signals for each GDK event delivered
1375 * to a widget: one generic ::event signal, another, more specific,
1376 * signal that matches the type of event delivered (e.g.
1377 * #GtkWidget::key-press-event) and finally a generic
1378 * #GtkWidget::event-after signal.
1380 * Returns: %TRUE to stop other handlers from being invoked for the event
1381 * and to cancel the emission of the second specific ::event signal.
1382 * %FALSE to propagate the event further and to allow the emission of
1383 * the second signal. The ::event-after signal is emitted regardless of
1386 widget_signals[EVENT] =
1387 g_signal_new (I_("event"),
1388 G_TYPE_FROM_CLASS (gobject_class),
1390 G_STRUCT_OFFSET (GtkWidgetClass, event),
1391 _gtk_boolean_handled_accumulator, NULL,
1392 _gtk_marshal_BOOLEAN__BOXED,
1394 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1397 * GtkWidget::event-after:
1398 * @widget: the object which received the signal.
1399 * @event: the #GdkEvent which triggered this signal
1401 * After the emission of the #GtkWidget::event signal and (optionally)
1402 * the second more specific signal, ::event-after will be emitted
1403 * regardless of the previous two signals handlers return values.
1406 widget_signals[EVENT_AFTER] =
1407 g_signal_new (I_("event-after"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1412 _gtk_marshal_VOID__BOXED,
1414 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1417 * GtkWidget::button-press-event:
1418 * @widget: the object which received the signal.
1419 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1422 * The ::button-press-event signal will be emitted when a button
1423 * (typically from a mouse) is pressed.
1425 * To receive this signal, the #GdkWindow associated to the
1426 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1428 * This signal will be sent to the grab widget if there is one.
1430 * Returns: %TRUE to stop other handlers from being invoked for the event.
1431 * %FALSE to propagate the event further.
1433 widget_signals[BUTTON_PRESS_EVENT] =
1434 g_signal_new (I_("button-press-event"),
1435 G_TYPE_FROM_CLASS (gobject_class),
1437 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1438 _gtk_boolean_handled_accumulator, NULL,
1439 _gtk_marshal_BOOLEAN__BOXED,
1441 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1444 * GtkWidget::button-release-event:
1445 * @widget: the object which received the signal.
1446 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1449 * The ::button-release-event signal will be emitted when a button
1450 * (typically from a mouse) is released.
1452 * To receive this signal, the #GdkWindow associated to the
1453 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1455 * This signal will be sent to the grab widget if there is one.
1457 * Returns: %TRUE to stop other handlers from being invoked for the event.
1458 * %FALSE to propagate the event further.
1460 widget_signals[BUTTON_RELEASE_EVENT] =
1461 g_signal_new (I_("button-release-event"),
1462 G_TYPE_FROM_CLASS (gobject_class),
1464 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1465 _gtk_boolean_handled_accumulator, NULL,
1466 _gtk_marshal_BOOLEAN__BOXED,
1468 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1471 * GtkWidget::scroll-event:
1472 * @widget: the object which received the signal.
1473 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1476 * The ::scroll-event signal is emitted when a button in the 4 to 7
1477 * range is pressed. Wheel mice are usually configured to generate
1478 * button press events for buttons 4 and 5 when the wheel is turned.
1480 * To receive this signal, the #GdkWindow associated to the widget needs
1481 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1483 * This signal will be sent to the grab widget if there is one.
1485 * Returns: %TRUE to stop other handlers from being invoked for the event.
1486 * %FALSE to propagate the event further.
1488 widget_signals[SCROLL_EVENT] =
1489 g_signal_new (I_("scroll-event"),
1490 G_TYPE_FROM_CLASS (gobject_class),
1492 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1493 _gtk_boolean_handled_accumulator, NULL,
1494 _gtk_marshal_BOOLEAN__BOXED,
1496 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1498 * GtkWidget::motion-notify-event:
1499 * @widget: the object which received the signal.
1500 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1503 * The ::motion-notify-event signal is emitted when the pointer moves
1504 * over the widget's #GdkWindow.
1506 * To receive this signal, the #GdkWindow associated to the widget
1507 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1509 * This signal will be sent to the grab widget if there is one.
1511 * Returns: %TRUE to stop other handlers from being invoked for the event.
1512 * %FALSE to propagate the event further.
1514 widget_signals[MOTION_NOTIFY_EVENT] =
1515 g_signal_new (I_("motion-notify-event"),
1516 G_TYPE_FROM_CLASS (gobject_class),
1518 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1519 _gtk_boolean_handled_accumulator, NULL,
1520 _gtk_marshal_BOOLEAN__BOXED,
1522 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1525 * GtkWidget::composited-changed:
1526 * @widget: the object on which the signal is emitted
1528 * The ::composited-changed signal is emitted when the composited
1529 * status of @widget<!-- -->s screen changes.
1530 * See gdk_screen_is_composited().
1532 widget_signals[COMPOSITED_CHANGED] =
1533 g_signal_new (I_("composited-changed"),
1534 G_TYPE_FROM_CLASS (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1538 _gtk_marshal_VOID__VOID,
1542 * GtkWidget::keynav-failed:
1543 * @widget: the object which received the signal
1544 * @direction: the direction of movement
1546 * Gets emitted if keyboard navigation fails.
1547 * See gtk_widget_keynav_failed() for details.
1549 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1550 * if the emitting widget should try to handle the keyboard
1551 * navigation attempt in its parent container(s).
1555 widget_signals[KEYNAV_FAILED] =
1556 g_signal_new_class_handler (I_("keynav-failed"),
1557 G_TYPE_FROM_CLASS (gobject_class),
1559 G_CALLBACK (gtk_widget_real_keynav_failed),
1560 _gtk_boolean_handled_accumulator, NULL,
1561 _gtk_marshal_BOOLEAN__ENUM,
1563 GTK_TYPE_DIRECTION_TYPE);
1566 * GtkWidget::delete-event:
1567 * @widget: the object which received the signal
1568 * @event: the event which triggered this signal
1570 * The ::delete-event signal is emitted if a user requests that
1571 * a toplevel window is closed. The default handler for this signal
1572 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1573 * this signal will cause the window to be hidden instead, so that
1574 * it can later be shown again without reconstructing it.
1576 * Returns: %TRUE to stop other handlers from being invoked for the event.
1577 * %FALSE to propagate the event further.
1579 widget_signals[DELETE_EVENT] =
1580 g_signal_new (I_("delete-event"),
1581 G_TYPE_FROM_CLASS (gobject_class),
1583 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1584 _gtk_boolean_handled_accumulator, NULL,
1585 _gtk_marshal_BOOLEAN__BOXED,
1587 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1590 * GtkWidget::destroy-event:
1591 * @widget: the object which received the signal.
1592 * @event: the event which triggered this signal
1594 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1595 * You rarely get this signal, because most widgets disconnect themselves
1596 * from their window before they destroy it, so no widget owns the
1597 * window at destroy time.
1599 * To receive this signal, the #GdkWindow associated to the widget needs
1600 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1601 * automatically for all new windows.
1603 * Returns: %TRUE to stop other handlers from being invoked for the event.
1604 * %FALSE to propagate the event further.
1606 widget_signals[DESTROY_EVENT] =
1607 g_signal_new (I_("destroy-event"),
1608 G_TYPE_FROM_CLASS (gobject_class),
1610 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1611 _gtk_boolean_handled_accumulator, NULL,
1612 _gtk_marshal_BOOLEAN__BOXED,
1614 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1617 * GtkWidget::expose-event:
1618 * @widget: the object which received the signal.
1619 * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
1622 * The ::expose-event signal is emitted when an area of a previously
1623 * obscured #GdkWindow is made visible and needs to be redrawn.
1624 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1627 * To receive this signal, the #GdkWindow associated to the widget needs
1628 * to enable the #GDK_EXPOSURE_MASK mask.
1630 * Returns: %TRUE to stop other handlers from being invoked for the event.
1631 * %FALSE to propagate the event further.
1633 widget_signals[EXPOSE_EVENT] =
1634 g_signal_new (I_("expose-event"),
1635 G_TYPE_FROM_CLASS (gobject_class),
1637 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1638 _gtk_boolean_handled_accumulator, NULL,
1639 _gtk_marshal_BOOLEAN__BOXED,
1641 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1644 * GtkWidget::key-press-event:
1645 * @widget: the object which received the signal
1646 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1648 * The ::key-press-event signal is emitted when a key is pressed.
1650 * To receive this signal, the #GdkWindow associated to the widget needs
1651 * to enable the #GDK_KEY_PRESS_MASK mask.
1653 * This signal will be sent to the grab widget if there is one.
1655 * Returns: %TRUE to stop other handlers from being invoked for the event.
1656 * %FALSE to propagate the event further.
1658 widget_signals[KEY_PRESS_EVENT] =
1659 g_signal_new (I_("key-press-event"),
1660 G_TYPE_FROM_CLASS (gobject_class),
1662 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1663 _gtk_boolean_handled_accumulator, NULL,
1664 _gtk_marshal_BOOLEAN__BOXED,
1666 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1669 * GtkWidget::key-release-event:
1670 * @widget: the object which received the signal
1671 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1673 * The ::key-release-event signal is emitted when a key is pressed.
1675 * To receive this signal, the #GdkWindow associated to the widget needs
1676 * to enable the #GDK_KEY_RELEASE_MASK mask.
1678 * This signal will be sent to the grab widget if there is one.
1680 * Returns: %TRUE to stop other handlers from being invoked for the event.
1681 * %FALSE to propagate the event further.
1683 widget_signals[KEY_RELEASE_EVENT] =
1684 g_signal_new (I_("key-release-event"),
1685 G_TYPE_FROM_CLASS (gobject_class),
1687 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1688 _gtk_boolean_handled_accumulator, NULL,
1689 _gtk_marshal_BOOLEAN__BOXED,
1691 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1694 * GtkWidget::enter-notify-event:
1695 * @widget: the object which received the signal
1696 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1699 * The ::enter-notify-event will be emitted when the pointer enters
1700 * the @widget's window.
1702 * To receive this signal, the #GdkWindow associated to the widget needs
1703 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1705 * This signal will be sent to the grab widget if there is one.
1707 * Returns: %TRUE to stop other handlers from being invoked for the event.
1708 * %FALSE to propagate the event further.
1710 widget_signals[ENTER_NOTIFY_EVENT] =
1711 g_signal_new (I_("enter-notify-event"),
1712 G_TYPE_FROM_CLASS (gobject_class),
1714 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1715 _gtk_boolean_handled_accumulator, NULL,
1716 _gtk_marshal_BOOLEAN__BOXED,
1718 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1721 * GtkWidget::leave-notify-event:
1722 * @widget: the object which received the signal
1723 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1726 * The ::leave-notify-event will be emitted when the pointer leaves
1727 * the @widget's window.
1729 * To receive this signal, the #GdkWindow associated to the widget needs
1730 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1732 * This signal will be sent to the grab widget if there is one.
1734 * Returns: %TRUE to stop other handlers from being invoked for the event.
1735 * %FALSE to propagate the event further.
1737 widget_signals[LEAVE_NOTIFY_EVENT] =
1738 g_signal_new (I_("leave-notify-event"),
1739 G_TYPE_FROM_CLASS (gobject_class),
1741 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1742 _gtk_boolean_handled_accumulator, NULL,
1743 _gtk_marshal_BOOLEAN__BOXED,
1745 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1748 * GtkWidget::configure-event
1749 * @widget: the object which received the signal
1750 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1753 * The ::configure-event signal will be emitted when the size, position or
1754 * stacking of the @widget's window has changed.
1756 * To receive this signal, the #GdkWindow associated to the widget needs
1757 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1758 * automatically for all new windows.
1760 * Returns: %TRUE to stop other handlers from being invoked for the event.
1761 * %FALSE to propagate the event further.
1763 widget_signals[CONFIGURE_EVENT] =
1764 g_signal_new (I_("configure-event"),
1765 G_TYPE_FROM_CLASS (gobject_class),
1767 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1768 _gtk_boolean_handled_accumulator, NULL,
1769 _gtk_marshal_BOOLEAN__BOXED,
1771 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1774 * GtkWidget::focus-in-event
1775 * @widget: the object which received the signal
1776 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1779 * The ::focus-in-event signal will be emitted when the keyboard focus
1780 * enters the @widget's window.
1782 * To receive this signal, the #GdkWindow associated to the widget needs
1783 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1785 * Returns: %TRUE to stop other handlers from being invoked for the event.
1786 * %FALSE to propagate the event further.
1788 widget_signals[FOCUS_IN_EVENT] =
1789 g_signal_new (I_("focus-in-event"),
1790 G_TYPE_FROM_CLASS (gobject_class),
1792 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1793 _gtk_boolean_handled_accumulator, NULL,
1794 _gtk_marshal_BOOLEAN__BOXED,
1796 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1799 * GtkWidget::focus-out-event
1800 * @widget: the object which received the signal
1801 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1804 * The ::focus-out-event signal will be emitted when the keyboard focus
1805 * leaves the @widget's window.
1807 * To receive this signal, the #GdkWindow associated to the widget needs
1808 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1810 * Returns: %TRUE to stop other handlers from being invoked for the event.
1811 * %FALSE to propagate the event further.
1813 widget_signals[FOCUS_OUT_EVENT] =
1814 g_signal_new (I_("focus-out-event"),
1815 G_TYPE_FROM_CLASS (gobject_class),
1817 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1818 _gtk_boolean_handled_accumulator, NULL,
1819 _gtk_marshal_BOOLEAN__BOXED,
1821 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1824 * GtkWidget::map-event
1825 * @widget: the object which received the signal
1826 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1828 * The ::map-event signal will be emitted when the @widget's window is
1829 * mapped. A window is mapped when it becomes visible on the screen.
1831 * To receive this signal, the #GdkWindow associated to the widget needs
1832 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1833 * automatically for all new windows.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event.
1836 * %FALSE to propagate the event further.
1838 widget_signals[MAP_EVENT] =
1839 g_signal_new (I_("map-event"),
1840 G_TYPE_FROM_CLASS (gobject_class),
1842 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1843 _gtk_boolean_handled_accumulator, NULL,
1844 _gtk_marshal_BOOLEAN__BOXED,
1846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1849 * GtkWidget::unmap-event
1850 * @widget: the object which received the signal
1851 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1853 * The ::unmap-event signal may be emitted when the @widget's window is
1854 * unmapped. A window is unmapped when it becomes invisible on the screen.
1856 * For performance reasons GTK+ may not emit ::unmap-event, so one
1857 * should always also implement ::unrealize in order to release
1858 * resources and disconnect signal handlers.
1860 * To receive this signal, the #GdkWindow associated to the widget needs
1861 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1862 * automatically for all new windows.
1864 * Returns: %TRUE to stop other handlers from being invoked for the event.
1865 * %FALSE to propagate the event further.
1867 widget_signals[UNMAP_EVENT] =
1868 g_signal_new (I_("unmap-event"),
1869 G_TYPE_FROM_CLASS (gobject_class),
1871 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1872 _gtk_boolean_handled_accumulator, NULL,
1873 _gtk_marshal_BOOLEAN__BOXED,
1875 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1878 * GtkWidget::property-notify-event
1879 * @widget: the object which received the signal
1880 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1883 * The ::property-notify-event signal will be emitted when a property on
1884 * the @widget's window has been changed or deleted.
1886 * To receive this signal, the #GdkWindow associated to the widget needs
1887 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[PROPERTY_NOTIFY_EVENT] =
1893 g_signal_new (I_("property-notify-event"),
1894 G_TYPE_FROM_CLASS (gobject_class),
1896 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1903 * GtkWidget::selection-clear-event
1904 * @widget: the object which received the signal
1905 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1908 * The ::selection-clear-event signal will be emitted when the
1909 * the @widget's window has lost ownership of a selection.
1911 * Returns: %TRUE to stop other handlers from being invoked for the event.
1912 * %FALSE to propagate the event further.
1914 widget_signals[SELECTION_CLEAR_EVENT] =
1915 g_signal_new (I_("selection-clear-event"),
1916 G_TYPE_FROM_CLASS (gobject_class),
1918 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1919 _gtk_boolean_handled_accumulator, NULL,
1920 _gtk_marshal_BOOLEAN__BOXED,
1922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1925 * GtkWidget::selection-request-event
1926 * @widget: the object which received the signal
1927 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1930 * The ::selection-request-event signal will be emitted when
1931 * another client requests ownership of the selection owned by
1932 * the @widget's window.
1934 * Returns: %TRUE to stop other handlers from being invoked for the event.
1935 * %FALSE to propagate the event further.
1937 widget_signals[SELECTION_REQUEST_EVENT] =
1938 g_signal_new (I_("selection-request-event"),
1939 G_TYPE_FROM_CLASS (gobject_class),
1941 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1942 _gtk_boolean_handled_accumulator, NULL,
1943 _gtk_marshal_BOOLEAN__BOXED,
1945 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1948 * GtkWidget::selection-notify-event:
1949 * @widget: the object which received the signal.
1952 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1954 widget_signals[SELECTION_NOTIFY_EVENT] =
1955 g_signal_new (I_("selection-notify-event"),
1956 G_TYPE_FROM_CLASS (gobject_class),
1958 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::selection-received:
1966 * @widget: the object which received the signal.
1970 widget_signals[SELECTION_RECEIVED] =
1971 g_signal_new (I_("selection-received"),
1972 G_TYPE_FROM_CLASS (gobject_class),
1974 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1976 _gtk_marshal_VOID__BOXED_UINT,
1978 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1982 * GtkWidget::selection-get:
1983 * @widget: the object which received the signal.
1988 widget_signals[SELECTION_GET] =
1989 g_signal_new (I_("selection-get"),
1990 G_TYPE_FROM_CLASS (gobject_class),
1992 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1994 _gtk_marshal_VOID__BOXED_UINT_UINT,
1996 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2001 * GtkWidget::proximity-in-event
2002 * @widget: the object which received the signal
2003 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2006 * To receive this signal the #GdkWindow associated to the widget needs
2007 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2009 * This signal will be sent to the grab widget if there is one.
2011 * Returns: %TRUE to stop other handlers from being invoked for the event.
2012 * %FALSE to propagate the event further.
2014 widget_signals[PROXIMITY_IN_EVENT] =
2015 g_signal_new (I_("proximity-in-event"),
2016 G_TYPE_FROM_CLASS (gobject_class),
2018 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2019 _gtk_boolean_handled_accumulator, NULL,
2020 _gtk_marshal_BOOLEAN__BOXED,
2022 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2025 * GtkWidget::proximity-out-event
2026 * @widget: the object which received the signal
2027 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2030 * To receive this signal the #GdkWindow associated to the widget needs
2031 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2033 * This signal will be sent to the grab widget if there is one.
2035 * Returns: %TRUE to stop other handlers from being invoked for the event.
2036 * %FALSE to propagate the event further.
2038 widget_signals[PROXIMITY_OUT_EVENT] =
2039 g_signal_new (I_("proximity-out-event"),
2040 G_TYPE_FROM_CLASS (gobject_class),
2042 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2043 _gtk_boolean_handled_accumulator, NULL,
2044 _gtk_marshal_BOOLEAN__BOXED,
2046 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2049 * GtkWidget::drag-leave:
2050 * @widget: the object which received the signal.
2051 * @drag_context: the drag context
2052 * @time: the timestamp of the motion event
2054 * The ::drag-leave signal is emitted on the drop site when the cursor
2055 * leaves the widget. A typical reason to connect to this signal is to
2056 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2057 * with gtk_drag_unhighlight()
2059 widget_signals[DRAG_LEAVE] =
2060 g_signal_new (I_("drag-leave"),
2061 G_TYPE_FROM_CLASS (gobject_class),
2063 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2065 _gtk_marshal_VOID__OBJECT_UINT,
2067 GDK_TYPE_DRAG_CONTEXT,
2071 * GtkWidget::drag-begin:
2072 * @widget: the object which received the signal
2073 * @drag_context: the drag context
2075 * The ::drag-begin signal is emitted on the drag source when a drag is
2076 * started. A typical reason to connect to this signal is to set up a
2077 * custom drag icon with gtk_drag_source_set_icon().
2079 * Note that some widgets set up a drag icon in the default handler of
2080 * this signal, so you may have to use g_signal_connect_after() to
2081 * override what the default handler did.
2083 widget_signals[DRAG_BEGIN] =
2084 g_signal_new (I_("drag-begin"),
2085 G_TYPE_FROM_CLASS (gobject_class),
2087 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2089 _gtk_marshal_VOID__OBJECT,
2091 GDK_TYPE_DRAG_CONTEXT);
2094 * GtkWidget::drag-end:
2095 * @widget: the object which received the signal
2096 * @drag_context: the drag context
2098 * The ::drag-end signal is emitted on the drag source when a drag is
2099 * finished. A typical reason to connect to this signal is to undo
2100 * things done in #GtkWidget::drag-begin.
2102 widget_signals[DRAG_END] =
2103 g_signal_new (I_("drag-end"),
2104 G_TYPE_FROM_CLASS (gobject_class),
2106 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2108 _gtk_marshal_VOID__OBJECT,
2110 GDK_TYPE_DRAG_CONTEXT);
2113 * GtkWidget::drag-data-delete:
2114 * @widget: the object which received the signal
2115 * @drag_context: the drag context
2117 * The ::drag-data-delete signal is emitted on the drag source when a drag
2118 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2119 * handler is responsible for deleting the data that has been dropped. What
2120 * "delete" means depends on the context of the drag operation.
2122 widget_signals[DRAG_DATA_DELETE] =
2123 g_signal_new (I_("drag-data-delete"),
2124 G_TYPE_FROM_CLASS (gobject_class),
2126 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2128 _gtk_marshal_VOID__OBJECT,
2130 GDK_TYPE_DRAG_CONTEXT);
2133 * GtkWidget::drag-failed:
2134 * @widget: the object which received the signal
2135 * @drag_context: the drag context
2136 * @result: the result of the drag operation
2138 * The ::drag-failed signal is emitted on the drag source when a drag has
2139 * failed. The signal handler may hook custom code to handle a failed DND
2140 * operation based on the type of error, it returns %TRUE is the failure has
2141 * been already handled (not showing the default "drag operation failed"
2142 * animation), otherwise it returns %FALSE.
2144 * Return value: %TRUE if the failed drag operation has been already handled.
2148 widget_signals[DRAG_FAILED] =
2149 g_signal_new (I_("drag-failed"),
2150 G_TYPE_FROM_CLASS (gobject_class),
2152 0, _gtk_boolean_handled_accumulator, NULL,
2153 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2155 GDK_TYPE_DRAG_CONTEXT,
2156 GTK_TYPE_DRAG_RESULT);
2159 * GtkWidget::drag-motion:
2160 * @widget: the object which received the signal
2161 * @drag_context: the drag context
2162 * @x: the x coordinate of the current cursor position
2163 * @y: the y coordinate of the current cursor position
2164 * @time: the timestamp of the motion event
2165 * @returns: whether the cursor position is in a drop zone
2167 * The drag-motion signal is emitted on the drop site when the user
2168 * moves the cursor over the widget during a drag. The signal handler
2169 * must determine whether the cursor position is in a drop zone or not.
2170 * If it is not in a drop zone, it returns %FALSE and no further processing
2171 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2172 * handler is responsible for providing the necessary information for
2173 * displaying feedback to the user, by calling gdk_drag_status().
2175 * If the decision whether the drop will be accepted or rejected can't be
2176 * made based solely on the cursor position and the type of the data, the
2177 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2178 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2179 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2180 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2181 * when using the drag-motion signal that way.
2183 * Also note that there is no drag-enter signal. The drag receiver has to
2184 * keep track of whether he has received any drag-motion signals since the
2185 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2186 * an "enter" signal. Upon an "enter", the handler will typically highlight
2187 * the drop site with gtk_drag_highlight().
2190 * drag_motion (GtkWidget *widget,
2191 * GdkDragContext *context,
2198 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2200 * if (!private_data->drag_highlight)
2202 * private_data->drag_highlight = 1;
2203 * gtk_drag_highlight (widget);
2206 * target = gtk_drag_dest_find_target (widget, context, NULL);
2207 * if (target == GDK_NONE)
2208 * gdk_drag_status (context, 0, time);
2211 * private_data->pending_status = context->suggested_action;
2212 * gtk_drag_get_data (widget, context, target, time);
2219 * drag_data_received (GtkWidget *widget,
2220 * GdkDragContext *context,
2223 * GtkSelectionData *selection_data,
2227 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2229 * if (private_data->suggested_action)
2231 * private_data->suggested_action = 0;
2233 * /* We are getting this data due to a request in drag_motion,
2234 * * rather than due to a request in drag_drop, so we are just
2235 * * supposed to call gdk_drag_status (), not actually paste in
2238 * str = gtk_selection_data_get_text (selection_data);
2239 * if (!data_is_acceptable (str))
2240 * gdk_drag_status (context, 0, time);
2242 * gdk_drag_status (context, private_data->suggested_action, time);
2246 * /* accept the drop */
2251 widget_signals[DRAG_MOTION] =
2252 g_signal_new (I_("drag-motion"),
2253 G_TYPE_FROM_CLASS (gobject_class),
2255 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2256 _gtk_boolean_handled_accumulator, NULL,
2257 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2259 GDK_TYPE_DRAG_CONTEXT,
2265 * GtkWidget::drag-drop:
2266 * @widget: the object which received the signal
2267 * @drag_context: the drag context
2268 * @x: the x coordinate of the current cursor position
2269 * @y: the y coordinate of the current cursor position
2270 * @time: the timestamp of the motion event
2271 * @returns: whether the cursor position is in a drop zone
2273 * The ::drag-drop signal is emitted on the drop site when the user drops
2274 * the data onto the widget. The signal handler must determine whether
2275 * the cursor position is in a drop zone or not. If it is not in a drop
2276 * zone, it returns %FALSE and no further processing is necessary.
2277 * Otherwise, the handler returns %TRUE. In this case, the handler must
2278 * ensure that gtk_drag_finish() is called to let the source know that
2279 * the drop is done. The call to gtk_drag_finish() can be done either
2280 * directly or in a #GtkWidget::drag-data-received handler which gets
2281 * triggered by calling gtk_drag_get_data() to receive the data for one
2282 * or more of the supported targets.
2284 widget_signals[DRAG_DROP] =
2285 g_signal_new (I_("drag-drop"),
2286 G_TYPE_FROM_CLASS (gobject_class),
2288 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2289 _gtk_boolean_handled_accumulator, NULL,
2290 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2292 GDK_TYPE_DRAG_CONTEXT,
2298 * GtkWidget::drag-data-get:
2299 * @widget: the object which received the signal
2300 * @drag_context: the drag context
2301 * @data: the #GtkSelectionData to be filled with the dragged data
2302 * @info: the info that has been registered with the target in the
2304 * @time: the timestamp at which the data was requested
2306 * The ::drag-data-get signal is emitted on the drag source when the drop
2307 * site requests the data which is dragged. It is the responsibility of
2308 * the signal handler to fill @data with the data in the format which
2309 * is indicated by @info. See gtk_selection_data_set() and
2310 * gtk_selection_data_set_text().
2312 widget_signals[DRAG_DATA_GET] =
2313 g_signal_new (I_("drag-data-get"),
2314 G_TYPE_FROM_CLASS (gobject_class),
2316 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2318 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2320 GDK_TYPE_DRAG_CONTEXT,
2321 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2326 * GtkWidget::drag-data-received:
2327 * @widget: the object which received the signal
2328 * @drag_context: the drag context
2329 * @x: where the drop happened
2330 * @y: where the drop happened
2331 * @data: the received data
2332 * @info: the info that has been registered with the target in the
2334 * @time: the timestamp at which the data was received
2336 * The ::drag-data-received signal is emitted on the drop site when the
2337 * dragged data has been received. If the data was received in order to
2338 * determine whether the drop will be accepted, the handler is expected
2339 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2340 * If the data was received in response to a #GtkWidget::drag-drop signal
2341 * (and this is the last target to be received), the handler for this
2342 * signal is expected to process the received data and then call
2343 * gtk_drag_finish(), setting the @success parameter depending on whether
2344 * the data was processed successfully.
2346 * The handler may inspect and modify @drag_context->action before calling
2347 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2348 * following example:
2351 * drag_data_received (GtkWidget *widget,
2352 * GdkDragContext *drag_context,
2355 * GtkSelectionData *data,
2359 * if ((data->length >= 0) && (data->format == 8))
2361 * if (drag_context->action == GDK_ACTION_ASK)
2363 * GtkWidget *dialog;
2366 * dialog = gtk_message_dialog_new (NULL,
2367 * GTK_DIALOG_MODAL |
2368 * GTK_DIALOG_DESTROY_WITH_PARENT,
2370 * GTK_BUTTONS_YES_NO,
2371 * "Move the data ?\n");
2372 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2373 * gtk_widget_destroy (dialog);
2375 * if (response == GTK_RESPONSE_YES)
2376 * drag_context->action = GDK_ACTION_MOVE;
2378 * drag_context->action = GDK_ACTION_COPY;
2381 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2385 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2389 widget_signals[DRAG_DATA_RECEIVED] =
2390 g_signal_new (I_("drag-data-received"),
2391 G_TYPE_FROM_CLASS (gobject_class),
2393 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2395 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2397 GDK_TYPE_DRAG_CONTEXT,
2400 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2405 * GtkWidget::visibility-notify-event:
2406 * @widget: the object which received the signal
2407 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2408 * triggered this signal.
2410 * The ::visibility-notify-event will be emitted when the @widget's window
2411 * is obscured or unobscured.
2413 * To receive this signal the #GdkWindow associated to the widget needs
2414 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2416 * Returns: %TRUE to stop other handlers from being invoked for the event.
2417 * %FALSE to propagate the event further.
2419 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2420 g_signal_new (I_("visibility-notify-event"),
2421 G_TYPE_FROM_CLASS (gobject_class),
2423 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2424 _gtk_boolean_handled_accumulator, NULL,
2425 _gtk_marshal_BOOLEAN__BOXED,
2427 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2430 * GtkWidget::client-event:
2431 * @widget: the object which received the signal
2432 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2435 * The ::client-event will be emitted when the @widget's window
2436 * receives a message (via a ClientMessage event) from another
2439 * Returns: %TRUE to stop other handlers from being invoked for
2440 * the event. %FALSE to propagate the event further.
2442 widget_signals[CLIENT_EVENT] =
2443 g_signal_new (I_("client-event"),
2444 G_TYPE_FROM_CLASS (gobject_class),
2446 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2447 _gtk_boolean_handled_accumulator, NULL,
2448 _gtk_marshal_BOOLEAN__BOXED,
2450 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2453 * GtkWidget::no-expose-event:
2454 * @widget: the object which received the signal
2455 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2458 * The ::no-expose-event will be emitted when the @widget's window is
2459 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2460 * If the source window was partially obscured #GdkEventExpose events will
2461 * be generated for those areas.
2463 * Returns: %TRUE to stop other handlers from being invoked for the event.
2464 * %FALSE to propagate the event further.
2466 widget_signals[NO_EXPOSE_EVENT] =
2467 g_signal_new (I_("no-expose-event"),
2468 G_TYPE_FROM_CLASS (gobject_class),
2470 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2471 _gtk_boolean_handled_accumulator, NULL,
2472 _gtk_marshal_BOOLEAN__BOXED,
2474 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2477 * GtkWidget::window-state-event:
2478 * @widget: the object which received the signal
2479 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2480 * triggered this signal.
2482 * The ::window-state-event will be emitted when the state of the
2483 * toplevel window associated to the @widget changes.
2485 * To receive this signal the #GdkWindow associated to the widget
2486 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2487 * this mask automatically for all new windows.
2489 * Returns: %TRUE to stop other handlers from being invoked for the
2490 * event. %FALSE to propagate the event further.
2492 widget_signals[WINDOW_STATE_EVENT] =
2493 g_signal_new (I_("window-state-event"),
2494 G_TYPE_FROM_CLASS (gobject_class),
2496 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2497 _gtk_boolean_handled_accumulator, NULL,
2498 _gtk_marshal_BOOLEAN__BOXED,
2500 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2503 * GtkWidget::damage-event:
2504 * @widget: the object which received the signal
2505 * @event: the #GdkEventExpose event
2507 * Emitted when a redirected window belonging to @widget gets drawn into.
2508 * The region/area members of the event shows what area of the redirected
2509 * drawable was drawn into.
2511 * Returns: %TRUE to stop other handlers from being invoked for the event.
2512 * %FALSE to propagate the event further.
2516 widget_signals[DAMAGE_EVENT] =
2517 g_signal_new (I_("damage-event"),
2518 G_TYPE_FROM_CLASS (gobject_class),
2521 _gtk_boolean_handled_accumulator, NULL,
2522 _gtk_marshal_BOOLEAN__BOXED,
2524 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2526 * GtkWidget::grab-broken-event:
2527 * @widget: the object which received the signal
2528 * @event: the #GdkEventGrabBroken event
2530 * Emitted when a pointer or keyboard grab on a window belonging
2531 * to @widget gets broken.
2533 * On X11, this happens when the grab window becomes unviewable
2534 * (i.e. it or one of its ancestors is unmapped), or if the same
2535 * application grabs the pointer or keyboard again.
2537 * Returns: %TRUE to stop other handlers from being invoked for
2538 * the event. %FALSE to propagate the event further.
2542 widget_signals[GRAB_BROKEN] =
2543 g_signal_new (I_("grab-broken-event"),
2544 G_TYPE_FROM_CLASS (gobject_class),
2546 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2547 _gtk_boolean_handled_accumulator, NULL,
2548 _gtk_marshal_BOOLEAN__BOXED,
2550 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2552 * GtkWidget::query-tooltip:
2553 * @widget: the object which received the signal
2554 * @x: the x coordinate of the cursor position where the request has
2555 * been emitted, relative to @widget->window
2556 * @y: the y coordinate of the cursor position where the request has
2557 * been emitted, relative to @widget->window
2558 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2559 * @tooltip: a #GtkTooltip
2561 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2562 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2563 * focus in keyboard mode.
2565 * Using the given coordinates, the signal handler should determine
2566 * whether a tooltip should be shown for @widget. If this is the case
2567 * %TRUE should be returned, %FALSE otherwise. Note that if
2568 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2569 * should not be used.
2571 * The signal handler is free to manipulate @tooltip with the therefore
2572 * destined function calls.
2574 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2578 widget_signals[QUERY_TOOLTIP] =
2579 g_signal_new (I_("query-tooltip"),
2580 G_TYPE_FROM_CLASS (gobject_class),
2582 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2583 _gtk_boolean_handled_accumulator, NULL,
2584 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2592 * GtkWidget::popup-menu
2593 * @widget: the object which received the signal
2595 * This signal gets emitted whenever a widget should pop up a context
2596 * menu. This usually happens through the standard key binding mechanism;
2597 * by pressing a certain key while a widget is focused, the user can cause
2598 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2599 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2600 * for an example of how to use this signal.
2602 * Returns: %TRUE if a menu was activated
2604 widget_signals[POPUP_MENU] =
2605 g_signal_new (I_("popup-menu"),
2606 G_TYPE_FROM_CLASS (gobject_class),
2607 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2608 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2609 _gtk_boolean_handled_accumulator, NULL,
2610 _gtk_marshal_BOOLEAN__VOID,
2614 * GtkWidget::show-help:
2615 * @widget: the object which received the signal.
2618 widget_signals[SHOW_HELP] =
2619 g_signal_new (I_("show-help"),
2620 G_TYPE_FROM_CLASS (gobject_class),
2621 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2622 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2623 _gtk_boolean_handled_accumulator, NULL,
2624 _gtk_marshal_BOOLEAN__ENUM,
2626 GTK_TYPE_WIDGET_HELP_TYPE);
2629 * GtkWidget::accel-closures-changed:
2630 * @widget: the object which received the signal.
2632 widget_signals[ACCEL_CLOSURES_CHANGED] =
2633 g_signal_new (I_("accel-closures-changed"),
2634 G_TYPE_FROM_CLASS (gobject_class),
2638 _gtk_marshal_VOID__VOID,
2642 * GtkWidget::screen-changed:
2643 * @widget: the object on which the signal is emitted
2644 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2645 * widget was not associated with a screen before
2647 * The ::screen-changed signal gets emitted when the
2648 * screen of a widget has changed.
2650 widget_signals[SCREEN_CHANGED] =
2651 g_signal_new (I_("screen-changed"),
2652 G_TYPE_FROM_CLASS (gobject_class),
2654 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2656 _gtk_marshal_VOID__OBJECT,
2661 * GtkWidget::can-activate-accel:
2662 * @widget: the object which received the signal
2663 * @signal_id: the ID of a signal installed on @widget
2665 * Determines whether an accelerator that activates the signal
2666 * identified by @signal_id can currently be activated.
2667 * This signal is present to allow applications and derived
2668 * widgets to override the default #GtkWidget handling
2669 * for determining whether an accelerator can be activated.
2671 * Returns: %TRUE if the signal can be activated.
2673 widget_signals[CAN_ACTIVATE_ACCEL] =
2674 g_signal_new (I_("can-activate-accel"),
2675 G_TYPE_FROM_CLASS (gobject_class),
2677 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2678 _gtk_boolean_handled_accumulator, NULL,
2679 _gtk_marshal_BOOLEAN__UINT,
2680 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2682 binding_set = gtk_binding_set_by_class (klass);
2683 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2685 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2688 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2690 GTK_TYPE_WIDGET_HELP_TYPE,
2691 GTK_WIDGET_HELP_TOOLTIP);
2692 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2694 GTK_TYPE_WIDGET_HELP_TYPE,
2695 GTK_WIDGET_HELP_TOOLTIP);
2696 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2698 GTK_TYPE_WIDGET_HELP_TYPE,
2699 GTK_WIDGET_HELP_WHATS_THIS);
2700 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2702 GTK_TYPE_WIDGET_HELP_TYPE,
2703 GTK_WIDGET_HELP_WHATS_THIS);
2705 gtk_widget_class_install_style_property (klass,
2706 g_param_spec_boolean ("interior-focus",
2707 P_("Interior Focus"),
2708 P_("Whether to draw the focus indicator inside widgets"),
2710 GTK_PARAM_READABLE));
2712 gtk_widget_class_install_style_property (klass,
2713 g_param_spec_int ("focus-line-width",
2714 P_("Focus linewidth"),
2715 P_("Width, in pixels, of the focus indicator line"),
2717 GTK_PARAM_READABLE));
2719 gtk_widget_class_install_style_property (klass,
2720 g_param_spec_string ("focus-line-pattern",
2721 P_("Focus line dash pattern"),
2722 P_("Dash pattern used to draw the focus indicator"),
2724 GTK_PARAM_READABLE));
2725 gtk_widget_class_install_style_property (klass,
2726 g_param_spec_int ("focus-padding",
2727 P_("Focus padding"),
2728 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2730 GTK_PARAM_READABLE));
2731 gtk_widget_class_install_style_property (klass,
2732 g_param_spec_boxed ("cursor-color",
2734 P_("Color with which to draw insertion cursor"),
2736 GTK_PARAM_READABLE));
2737 gtk_widget_class_install_style_property (klass,
2738 g_param_spec_boxed ("secondary-cursor-color",
2739 P_("Secondary cursor color"),
2740 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2742 GTK_PARAM_READABLE));
2743 gtk_widget_class_install_style_property (klass,
2744 g_param_spec_float ("cursor-aspect-ratio",
2745 P_("Cursor line aspect ratio"),
2746 P_("Aspect ratio with which to draw insertion cursor"),
2748 GTK_PARAM_READABLE));
2750 gtk_widget_class_install_style_property (klass,
2751 g_param_spec_boolean ("window-dragging",
2752 P_("Window dragging"),
2753 P_("Whether windows can be dragged by clicking on empty areas"),
2755 GTK_PARAM_READABLE));
2758 * GtkWidget:link-color:
2760 * The "link-color" style property defines the color of unvisited links.
2764 gtk_widget_class_install_style_property (klass,
2765 g_param_spec_boxed ("link-color",
2766 P_("Unvisited Link Color"),
2767 P_("Color of unvisited links"),
2769 GTK_PARAM_READABLE));
2772 * GtkWidget:visited-link-color:
2774 * The "visited-link-color" style property defines the color of visited links.
2778 gtk_widget_class_install_style_property (klass,
2779 g_param_spec_boxed ("visited-link-color",
2780 P_("Visited Link Color"),
2781 P_("Color of visited links"),
2783 GTK_PARAM_READABLE));
2786 * GtkWidget:wide-separators:
2788 * The "wide-separators" style property defines whether separators have
2789 * configurable width and should be drawn using a box instead of a line.
2793 gtk_widget_class_install_style_property (klass,
2794 g_param_spec_boolean ("wide-separators",
2795 P_("Wide Separators"),
2796 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2798 GTK_PARAM_READABLE));
2801 * GtkWidget:separator-width:
2803 * The "separator-width" style property defines the width of separators.
2804 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2808 gtk_widget_class_install_style_property (klass,
2809 g_param_spec_int ("separator-width",
2810 P_("Separator Width"),
2811 P_("The width of separators if wide-separators is TRUE"),
2813 GTK_PARAM_READABLE));
2816 * GtkWidget:separator-height:
2818 * The "separator-height" style property defines the height of separators.
2819 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2823 gtk_widget_class_install_style_property (klass,
2824 g_param_spec_int ("separator-height",
2825 P_("Separator Height"),
2826 P_("The height of separators if \"wide-separators\" is TRUE"),
2828 GTK_PARAM_READABLE));
2831 * GtkWidget:scroll-arrow-hlength:
2833 * The "scroll-arrow-hlength" style property defines the length of
2834 * horizontal scroll arrows.
2838 gtk_widget_class_install_style_property (klass,
2839 g_param_spec_int ("scroll-arrow-hlength",
2840 P_("Horizontal Scroll Arrow Length"),
2841 P_("The length of horizontal scroll arrows"),
2843 GTK_PARAM_READABLE));
2846 * GtkWidget:scroll-arrow-vlength:
2848 * The "scroll-arrow-vlength" style property defines the length of
2849 * vertical scroll arrows.
2853 gtk_widget_class_install_style_property (klass,
2854 g_param_spec_int ("scroll-arrow-vlength",
2855 P_("Vertical Scroll Arrow Length"),
2856 P_("The length of vertical scroll arrows"),
2858 GTK_PARAM_READABLE));
2860 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2864 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2868 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2869 for (node = list; node; node = node->next)
2871 GParamSpec *pspec = node->data;
2873 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2874 g_param_spec_unref (pspec);
2880 gtk_widget_set_property (GObject *object,
2882 const GValue *value,
2885 GtkWidget *widget = GTK_WIDGET (object);
2890 gchar *tooltip_markup;
2891 const gchar *tooltip_text;
2892 GtkWindow *tooltip_window;
2895 gtk_widget_set_name (widget, g_value_get_string (value));
2898 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2900 case PROP_WIDTH_REQUEST:
2901 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2903 case PROP_HEIGHT_REQUEST:
2904 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2907 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2909 case PROP_SENSITIVE:
2910 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2912 case PROP_APP_PAINTABLE:
2913 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2915 case PROP_CAN_FOCUS:
2916 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2918 case PROP_HAS_FOCUS:
2919 if (g_value_get_boolean (value))
2920 gtk_widget_grab_focus (widget);
2923 if (g_value_get_boolean (value))
2924 gtk_widget_grab_focus (widget);
2926 case PROP_CAN_DEFAULT:
2927 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2929 case PROP_HAS_DEFAULT:
2930 if (g_value_get_boolean (value))
2931 gtk_widget_grab_default (widget);
2933 case PROP_RECEIVES_DEFAULT:
2934 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2937 gtk_widget_set_style (widget, g_value_get_object (value));
2940 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2941 gtk_widget_set_events (widget, g_value_get_flags (value));
2943 case PROP_EXTENSION_EVENTS:
2944 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2946 case PROP_NO_SHOW_ALL:
2947 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2949 case PROP_HAS_TOOLTIP:
2950 gtk_widget_real_set_has_tooltip (widget,
2951 g_value_get_boolean (value), FALSE);
2953 case PROP_TOOLTIP_MARKUP:
2954 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2955 tooltip_markup = g_value_dup_string (value);
2957 /* Treat an empty string as a NULL string,
2958 * because an empty string would be useless for a tooltip:
2960 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2962 g_free (tooltip_markup);
2963 tooltip_markup = NULL;
2966 g_object_set_qdata_full (object, quark_tooltip_markup,
2967 tooltip_markup, g_free);
2969 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2970 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2971 if (gtk_widget_get_visible (widget))
2972 gtk_widget_queue_tooltip_query (widget);
2974 case PROP_TOOLTIP_TEXT:
2975 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2977 tooltip_text = g_value_get_string (value);
2979 /* Treat an empty string as a NULL string,
2980 * because an empty string would be useless for a tooltip:
2982 if (tooltip_text && (strlen (tooltip_text) == 0))
2983 tooltip_text = NULL;
2985 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2987 g_object_set_qdata_full (object, quark_tooltip_markup,
2988 tooltip_markup, g_free);
2990 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2991 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2992 if (gtk_widget_get_visible (widget))
2993 gtk_widget_queue_tooltip_query (widget);
2995 case PROP_DOUBLE_BUFFERED:
2996 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2999 gtk_widget_set_halign (widget, g_value_get_enum (value));
3002 gtk_widget_set_valign (widget, g_value_get_enum (value));
3004 case PROP_MARGIN_LEFT:
3005 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3007 case PROP_MARGIN_RIGHT:
3008 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3010 case PROP_MARGIN_TOP:
3011 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3013 case PROP_MARGIN_BOTTOM:
3014 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3017 g_object_freeze_notify (G_OBJECT (widget));
3018 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3019 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3020 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3021 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3022 g_object_thaw_notify (G_OBJECT (widget));
3025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3031 gtk_widget_get_property (GObject *object,
3036 GtkWidget *widget = GTK_WIDGET (object);
3037 GtkWidgetPrivate *priv = widget->priv;
3046 g_value_set_string (value, priv->name);
3048 g_value_set_static_string (value, "");
3051 g_value_set_object (value, priv->parent);
3053 case PROP_WIDTH_REQUEST:
3056 gtk_widget_get_size_request (widget, &w, NULL);
3057 g_value_set_int (value, w);
3060 case PROP_HEIGHT_REQUEST:
3063 gtk_widget_get_size_request (widget, NULL, &h);
3064 g_value_set_int (value, h);
3068 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3070 case PROP_SENSITIVE:
3071 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3073 case PROP_APP_PAINTABLE:
3074 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3076 case PROP_CAN_FOCUS:
3077 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3079 case PROP_HAS_FOCUS:
3080 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3083 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3085 case PROP_CAN_DEFAULT:
3086 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3088 case PROP_HAS_DEFAULT:
3089 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3091 case PROP_RECEIVES_DEFAULT:
3092 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3094 case PROP_COMPOSITE_CHILD:
3095 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3098 g_value_set_object (value, gtk_widget_get_style (widget));
3101 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3102 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3104 case PROP_EXTENSION_EVENTS:
3105 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3106 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3108 case PROP_NO_SHOW_ALL:
3109 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3111 case PROP_HAS_TOOLTIP:
3112 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3114 case PROP_TOOLTIP_TEXT:
3116 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3119 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3120 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3122 g_value_take_string (value, text);
3125 case PROP_TOOLTIP_MARKUP:
3126 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3129 g_value_set_object (value, gtk_widget_get_window (widget));
3131 case PROP_DOUBLE_BUFFERED:
3132 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3135 g_value_set_enum (value, gtk_widget_get_halign (widget));
3138 g_value_set_enum (value, gtk_widget_get_valign (widget));
3140 case PROP_MARGIN_LEFT:
3141 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3143 case PROP_MARGIN_RIGHT:
3144 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3146 case PROP_MARGIN_TOP:
3147 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3149 case PROP_MARGIN_BOTTOM:
3150 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3154 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3155 if (aux_info == NULL)
3157 g_value_set_int (value, 0);
3161 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3162 aux_info->margin.right),
3163 MAX (aux_info->margin.top,
3164 aux_info->margin.bottom)));
3169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3175 gtk_widget_init (GtkWidget *widget)
3177 GtkWidgetPrivate *priv;
3179 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3182 priv = widget->priv;
3184 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3185 priv->state = GTK_STATE_NORMAL;
3186 priv->saved_state = GTK_STATE_NORMAL;
3188 priv->allocation.x = -1;
3189 priv->allocation.y = -1;
3190 priv->allocation.width = 1;
3191 priv->allocation.height = 1;
3192 priv->window = NULL;
3193 priv->parent = NULL;
3195 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3196 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3197 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3198 gtk_widget_set_double_buffered (widget, TRUE);
3200 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3201 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3202 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3203 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3205 priv->style = gtk_widget_get_default_style ();
3206 g_object_ref (priv->style);
3211 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3213 GParamSpec **pspecs)
3215 GtkWidgetPrivate *priv = widget->priv;
3216 GtkWidget *container = priv->parent;
3219 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3220 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3224 * gtk_widget_freeze_child_notify:
3225 * @widget: a #GtkWidget
3227 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3228 * signals are queued until gtk_widget_thaw_child_notify() is called
3231 * This is the analogue of g_object_freeze_notify() for child properties.
3234 gtk_widget_freeze_child_notify (GtkWidget *widget)
3236 g_return_if_fail (GTK_IS_WIDGET (widget));
3238 if (!G_OBJECT (widget)->ref_count)
3241 g_object_ref (widget);
3242 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3243 g_object_unref (widget);
3247 * gtk_widget_child_notify:
3248 * @widget: a #GtkWidget
3249 * @child_property: the name of a child property installed on the
3250 * class of @widget<!-- -->'s parent
3252 * Emits a #GtkWidget::child-notify signal for the
3253 * <link linkend="child-properties">child property</link> @child_property
3256 * This is the analogue of g_object_notify() for child properties.
3259 gtk_widget_child_notify (GtkWidget *widget,
3260 const gchar *child_property)
3262 GtkWidgetPrivate *priv = widget->priv;
3265 g_return_if_fail (GTK_IS_WIDGET (widget));
3266 g_return_if_fail (child_property != NULL);
3267 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3270 g_object_ref (widget);
3271 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3273 G_OBJECT_TYPE (priv->parent),
3276 g_warning ("%s: container class `%s' has no child property named `%s'",
3278 G_OBJECT_TYPE_NAME (priv->parent),
3282 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3284 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3285 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3287 g_object_unref (widget);
3291 * gtk_widget_thaw_child_notify:
3292 * @widget: a #GtkWidget
3294 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3295 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3299 gtk_widget_thaw_child_notify (GtkWidget *widget)
3301 GObjectNotifyQueue *nqueue;
3303 g_return_if_fail (GTK_IS_WIDGET (widget));
3305 if (!G_OBJECT (widget)->ref_count)
3308 g_object_ref (widget);
3309 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3310 if (!nqueue || !nqueue->freeze_count)
3311 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3312 G_OBJECT_TYPE_NAME (widget), widget);
3314 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3315 g_object_unref (widget);
3321 * @type: type ID of the widget to create
3322 * @first_property_name: name of first property to set
3323 * @Varargs: value of first property, followed by more properties,
3326 * This is a convenience function for creating a widget and setting
3327 * its properties in one go. For example you might write:
3328 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3329 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3330 * g_object_new(), but returns a widget so you don't have to
3331 * cast the object yourself.
3333 * Return value: a new #GtkWidget of type @widget_type
3336 gtk_widget_new (GType type,
3337 const gchar *first_property_name,
3343 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3345 va_start (var_args, first_property_name);
3346 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3353 gtk_widget_queue_draw_child (GtkWidget *widget)
3355 GtkWidgetPrivate *priv = widget->priv;
3358 parent = priv->parent;
3359 if (parent && gtk_widget_is_drawable (parent))
3360 gtk_widget_queue_draw_area (parent,
3363 priv->allocation.width,
3364 priv->allocation.height);
3368 * gtk_widget_unparent:
3369 * @widget: a #GtkWidget
3371 * This function is only for use in widget implementations.
3372 * Should be called by implementations of the remove method
3373 * on #GtkContainer, to dissociate a child from the container.
3376 gtk_widget_unparent (GtkWidget *widget)
3378 GtkWidgetPrivate *priv;
3379 GObjectNotifyQueue *nqueue;
3380 GtkWidget *toplevel;
3381 GtkWidget *old_parent;
3383 g_return_if_fail (GTK_IS_WIDGET (widget));
3385 priv = widget->priv;
3387 if (priv->parent == NULL)
3390 /* keep this function in sync with gtk_menu_detach()
3393 g_object_freeze_notify (G_OBJECT (widget));
3394 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3396 toplevel = gtk_widget_get_toplevel (widget);
3397 if (gtk_widget_is_toplevel (toplevel))
3398 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3400 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3401 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3403 /* If we are unanchoring the child, we save around the toplevel
3404 * to emit hierarchy changed
3406 if (GTK_WIDGET_ANCHORED (priv->parent))
3407 g_object_ref (toplevel);
3411 gtk_widget_queue_draw_child (widget);
3413 /* Reset the width and height here, to force reallocation if we
3414 * get added back to a new parent. This won't work if our new
3415 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3416 * (would 0x0 be OK here?)
3418 priv->allocation.width = 1;
3419 priv->allocation.height = 1;
3421 if (gtk_widget_get_realized (widget))
3423 if (GTK_WIDGET_IN_REPARENT (widget))
3424 gtk_widget_unmap (widget);
3426 gtk_widget_unrealize (widget);
3429 /* Removing a widget from a container restores the child visible
3430 * flag to the default state, so it doesn't affect the child
3431 * in the next parent.
3433 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3435 old_parent = priv->parent;
3436 priv->parent = NULL;
3437 gtk_widget_set_parent_window (widget, NULL);
3438 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3441 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3442 g_object_unref (toplevel);
3445 g_object_notify (G_OBJECT (widget), "parent");
3446 g_object_thaw_notify (G_OBJECT (widget));
3448 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3449 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3450 g_object_unref (widget);
3454 * gtk_widget_destroy:
3455 * @widget: a #GtkWidget
3457 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3458 * you don't have to cast the widget to #GtkObject. When a widget is
3459 * destroyed, it will break any references it holds to other objects.
3460 * If the widget is inside a container, the widget will be removed
3461 * from the container. If the widget is a toplevel (derived from
3462 * #GtkWindow), it will be removed from the list of toplevels, and the
3463 * reference GTK+ holds to it will be removed. Removing a
3464 * widget from its container or the list of toplevels results in the
3465 * widget being finalized, unless you've added additional references
3466 * to the widget with g_object_ref().
3468 * In most cases, only toplevel widgets (windows) require explicit
3469 * destruction, because when you destroy a toplevel its children will
3470 * be destroyed as well.
3473 gtk_widget_destroy (GtkWidget *widget)
3475 g_return_if_fail (GTK_IS_WIDGET (widget));
3477 gtk_object_destroy ((GtkObject*) widget);
3481 * gtk_widget_destroyed:
3482 * @widget: a #GtkWidget
3483 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3485 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3486 * %NULL. It's intended to be used as a callback connected to the
3487 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3488 * as a signal handler, and pass the address of your widget variable
3489 * as user data. Then when the widget is destroyed, the variable will
3490 * be set to %NULL. Useful for example to avoid multiple copies
3491 * of the same dialog.
3494 gtk_widget_destroyed (GtkWidget *widget,
3495 GtkWidget **widget_pointer)
3497 /* Don't make any assumptions about the
3499 * Even check widget_pointer.
3502 *widget_pointer = NULL;
3507 * @widget: a #GtkWidget
3509 * Flags a widget to be displayed. Any widget that isn't shown will
3510 * not appear on the screen. If you want to show all the widgets in a
3511 * container, it's easier to call gtk_widget_show_all() on the
3512 * container, instead of individually showing the widgets.
3514 * Remember that you have to show the containers containing a widget,
3515 * in addition to the widget itself, before it will appear onscreen.
3517 * When a toplevel container is shown, it is immediately realized and
3518 * mapped; other shown widgets are realized and mapped when their
3519 * toplevel container is realized and mapped.
3522 gtk_widget_show (GtkWidget *widget)
3524 g_return_if_fail (GTK_IS_WIDGET (widget));
3526 if (!gtk_widget_get_visible (widget))
3528 g_object_ref (widget);
3529 if (!gtk_widget_is_toplevel (widget))
3530 gtk_widget_queue_resize (widget);
3531 g_signal_emit (widget, widget_signals[SHOW], 0);
3532 g_object_notify (G_OBJECT (widget), "visible");
3533 g_object_unref (widget);
3538 gtk_widget_real_show (GtkWidget *widget)
3540 GtkWidgetPrivate *priv = widget->priv;
3542 if (!gtk_widget_get_visible (widget))
3544 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3547 gtk_widget_get_mapped (priv->parent) &&
3548 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3549 !gtk_widget_get_mapped (widget))
3550 gtk_widget_map (widget);
3555 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3558 g_signal_handlers_disconnect_by_func (widget,
3559 gtk_widget_show_map_callback,
3564 * gtk_widget_show_now:
3565 * @widget: a #GtkWidget
3567 * Shows a widget. If the widget is an unmapped toplevel widget
3568 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3569 * loop and wait for the window to actually be mapped. Be careful;
3570 * because the main loop is running, anything can happen during
3574 gtk_widget_show_now (GtkWidget *widget)
3578 g_return_if_fail (GTK_IS_WIDGET (widget));
3580 /* make sure we will get event */
3581 if (!gtk_widget_get_mapped (widget) &&
3582 gtk_widget_is_toplevel (widget))
3584 gtk_widget_show (widget);
3586 g_signal_connect (widget, "map-event",
3587 G_CALLBACK (gtk_widget_show_map_callback),
3591 gtk_main_iteration ();
3594 gtk_widget_show (widget);
3599 * @widget: a #GtkWidget
3601 * Reverses the effects of gtk_widget_show(), causing the widget to be
3602 * hidden (invisible to the user).
3605 gtk_widget_hide (GtkWidget *widget)
3607 g_return_if_fail (GTK_IS_WIDGET (widget));
3609 if (gtk_widget_get_visible (widget))
3611 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3613 g_object_ref (widget);
3614 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3615 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3617 g_signal_emit (widget, widget_signals[HIDE], 0);
3618 if (!gtk_widget_is_toplevel (widget))
3619 gtk_widget_queue_resize (widget);
3620 g_object_notify (G_OBJECT (widget), "visible");
3621 g_object_unref (widget);
3626 gtk_widget_real_hide (GtkWidget *widget)
3628 if (gtk_widget_get_visible (widget))
3630 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3632 if (gtk_widget_get_mapped (widget))
3633 gtk_widget_unmap (widget);
3638 * gtk_widget_hide_on_delete:
3639 * @widget: a #GtkWidget
3641 * Utility function; intended to be connected to the #GtkWidget::delete-event
3642 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3643 * argument, then returns %TRUE. If connected to ::delete-event, the
3644 * result is that clicking the close button for a window (on the
3645 * window frame, top right corner usually) will hide but not destroy
3646 * the window. By default, GTK+ destroys windows when ::delete-event
3649 * Return value: %TRUE
3652 gtk_widget_hide_on_delete (GtkWidget *widget)
3654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3656 gtk_widget_hide (widget);
3662 * gtk_widget_show_all:
3663 * @widget: a #GtkWidget
3665 * Recursively shows a widget, and any child widgets (if the widget is
3669 gtk_widget_show_all (GtkWidget *widget)
3671 GtkWidgetClass *class;
3673 g_return_if_fail (GTK_IS_WIDGET (widget));
3675 if (gtk_widget_get_no_show_all (widget))
3678 class = GTK_WIDGET_GET_CLASS (widget);
3680 if (class->show_all)
3681 class->show_all (widget);
3685 * gtk_widget_hide_all:
3686 * @widget: a #GtkWidget
3688 * Recursively hides a widget and any child widgets.
3691 gtk_widget_hide_all (GtkWidget *widget)
3693 GtkWidgetClass *class;
3695 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 if (gtk_widget_get_no_show_all (widget))
3700 class = GTK_WIDGET_GET_CLASS (widget);
3702 if (class->hide_all)
3703 class->hide_all (widget);
3708 * @widget: a #GtkWidget
3710 * This function is only for use in widget implementations. Causes
3711 * a widget to be mapped if it isn't already.
3714 gtk_widget_map (GtkWidget *widget)
3716 GtkWidgetPrivate *priv;
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3719 g_return_if_fail (gtk_widget_get_visible (widget));
3720 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3722 priv = widget->priv;
3724 if (!gtk_widget_get_mapped (widget))
3726 if (!gtk_widget_get_realized (widget))
3727 gtk_widget_realize (widget);
3729 g_signal_emit (widget, widget_signals[MAP], 0);
3731 if (!gtk_widget_get_has_window (widget))
3732 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3738 * @widget: a #GtkWidget
3740 * This function is only for use in widget implementations. Causes
3741 * a widget to be unmapped if it's currently mapped.
3744 gtk_widget_unmap (GtkWidget *widget)
3746 GtkWidgetPrivate *priv;
3748 g_return_if_fail (GTK_IS_WIDGET (widget));
3750 priv = widget->priv;
3752 if (gtk_widget_get_mapped (widget))
3754 if (!gtk_widget_get_has_window (widget))
3755 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3756 _gtk_tooltip_hide (widget);
3757 g_signal_emit (widget, widget_signals[UNMAP], 0);
3762 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3763 GdkExtensionMode mode,
3766 GtkWidgetPrivate *priv = widget->priv;
3767 GList *free_list = NULL;
3770 if (window_list == NULL)
3772 if (gtk_widget_get_has_window (widget))
3773 window_list = g_list_prepend (NULL, priv->window);
3775 window_list = gdk_window_get_children (priv->window);
3777 free_list = window_list;
3780 for (l = window_list; l != NULL; l = l->next)
3782 GdkWindow *window = l->data;
3785 gdk_window_get_user_data (window, &user_data);
3786 if (user_data == widget)
3790 gdk_input_set_extension_events (window,
3791 gdk_window_get_events (window),
3794 children = gdk_window_get_children (window);
3797 gtk_widget_set_extension_events_internal (widget, mode, children);
3798 g_list_free (children);
3804 g_list_free (free_list);
3808 _gtk_widget_enable_device_events (GtkWidget *widget)
3810 GHashTable *device_events;
3811 GHashTableIter iter;
3812 gpointer key, value;
3814 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3819 g_hash_table_iter_init (&iter, device_events);
3821 while (g_hash_table_iter_next (&iter, &key, &value))
3824 GdkEventMask event_mask;
3827 event_mask = GPOINTER_TO_UINT (value);
3828 gtk_widget_add_events_internal (widget, device, event_mask);
3833 * gtk_widget_realize:
3834 * @widget: a #GtkWidget
3836 * Creates the GDK (windowing system) resources associated with a
3837 * widget. For example, @widget->window will be created when a widget
3838 * is realized. Normally realization happens implicitly; if you show
3839 * a widget and all its parent containers, then the widget will be
3840 * realized and mapped automatically.
3842 * Realizing a widget requires all
3843 * the widget's parent widgets to be realized; calling
3844 * gtk_widget_realize() realizes the widget's parents in addition to
3845 * @widget itself. If a widget is not yet inside a toplevel window
3846 * when you realize it, bad things will happen.
3848 * This function is primarily used in widget implementations, and
3849 * isn't very useful otherwise. Many times when you think you might
3850 * need it, a better approach is to connect to a signal that will be
3851 * called after the widget is realized automatically, such as
3852 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3853 * GtkWidget::realize signal.
3856 gtk_widget_realize (GtkWidget *widget)
3858 GtkWidgetPrivate *priv;
3859 GdkExtensionMode mode;
3860 cairo_region_t *region;
3862 g_return_if_fail (GTK_IS_WIDGET (widget));
3863 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3864 GTK_IS_INVISIBLE (widget));
3866 priv = widget->priv;
3868 if (!gtk_widget_get_realized (widget))
3871 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3872 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3875 if (priv->parent == NULL &&
3876 !gtk_widget_is_toplevel (widget))
3877 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3878 "inside a toplevel window is not going to work very well. "
3879 "Widgets must be inside a toplevel container before realizing them.");
3881 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3882 gtk_widget_realize (priv->parent);
3884 gtk_widget_ensure_style (widget);
3886 g_signal_emit (widget, widget_signals[REALIZE], 0);
3888 gtk_widget_real_set_has_tooltip (widget,
3889 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3892 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3894 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3895 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3898 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3900 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3902 mode = gtk_widget_get_extension_events (widget);
3903 if (mode != GDK_EXTENSION_EVENTS_NONE)
3904 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3906 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3907 gdk_window_set_support_multidevice (priv->window, TRUE);
3909 _gtk_widget_enable_device_events (widget);
3914 * gtk_widget_unrealize:
3915 * @widget: a #GtkWidget
3917 * This function is only useful in widget implementations.
3918 * Causes a widget to be unrealized (frees all GDK resources
3919 * associated with the widget, such as @widget->window).
3922 gtk_widget_unrealize (GtkWidget *widget)
3924 g_return_if_fail (GTK_IS_WIDGET (widget));
3926 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3927 gtk_widget_shape_combine_region (widget, NULL);
3929 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3930 gtk_widget_input_shape_combine_region (widget, NULL);
3932 if (gtk_widget_get_realized (widget))
3934 g_object_ref (widget);
3935 _gtk_tooltip_hide (widget);
3936 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3937 gtk_widget_set_realized (widget, FALSE);
3938 gtk_widget_set_mapped (widget, FALSE);
3939 g_object_unref (widget);
3943 /*****************************************
3945 *****************************************/
3948 * gtk_widget_queue_draw_area:
3949 * @widget: a #GtkWidget
3950 * @x: x coordinate of upper-left corner of rectangle to redraw
3951 * @y: y coordinate of upper-left corner of rectangle to redraw
3952 * @width: width of region to draw
3953 * @height: height of region to draw
3955 * Invalidates the rectangular area of @widget defined by @x, @y,
3956 * @width and @height by calling gdk_window_invalidate_rect() on the
3957 * widget's window and all its child windows. Once the main loop
3958 * becomes idle (after the current batch of events has been processed,
3959 * roughly), the window will receive expose events for the union of
3960 * all regions that have been invalidated.
3962 * Normally you would only use this function in widget
3963 * implementations. You might also use it, or
3964 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3965 * #GtkDrawingArea or some portion thereof.
3967 * Frequently you can just call gdk_window_invalidate_rect() or
3968 * gdk_window_invalidate_region() instead of this function. Those
3969 * functions will invalidate only a single window, instead of the
3970 * widget and all its children.
3972 * The advantage of adding to the invalidated region compared to
3973 * simply drawing immediately is efficiency; using an invalid region
3974 * ensures that you only have to redraw one time.
3977 gtk_widget_queue_draw_area (GtkWidget *widget,
3983 GtkWidgetPrivate *priv;
3984 GdkRectangle invalid_rect;
3987 g_return_if_fail (GTK_IS_WIDGET (widget));
3989 priv = widget->priv;
3991 if (!gtk_widget_get_realized (widget))
3994 /* Just return if the widget or one of its ancestors isn't mapped */
3995 for (w = widget; w != NULL; w = w->priv->parent)
3996 if (!gtk_widget_get_mapped (w))
3999 /* Find the correct widget */
4001 if (gtk_widget_get_has_window (widget))
4005 /* Translate widget relative to window-relative */
4007 gint wx, wy, wwidth, wheight;
4009 gdk_window_get_position (priv->window, &wx, &wy);
4010 x -= wx - priv->allocation.x;
4011 y -= wy - priv->allocation.y;
4013 gdk_drawable_get_size (priv->window, &wwidth, &wheight);
4015 if (x + width <= 0 || y + height <= 0 ||
4016 x >= wwidth || y >= wheight)
4027 if (x + width > wwidth)
4029 if (y + height > wheight)
4030 height = wheight - y;
4036 invalid_rect.width = width;
4037 invalid_rect.height = height;
4039 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4043 * gtk_widget_queue_draw:
4044 * @widget: a #GtkWidget
4046 * Equivalent to calling gtk_widget_queue_draw_area() for the
4047 * entire area of a widget.
4050 gtk_widget_queue_draw (GtkWidget *widget)
4054 g_return_if_fail (GTK_IS_WIDGET (widget));
4056 gtk_widget_get_allocation (widget, &rect);
4058 if (!gtk_widget_get_has_window (widget))
4059 gtk_widget_queue_draw_area (widget,
4060 rect.x, rect.y, rect.width, rect.height);
4062 gtk_widget_queue_draw_area (widget,
4063 0, 0, rect.width, rect.height);
4067 * gtk_widget_queue_resize:
4068 * @widget: a #GtkWidget
4070 * This function is only for use in widget implementations.
4071 * Flags a widget to have its size renegotiated; should
4072 * be called when a widget for some reason has a new size request.
4073 * For example, when you change the text in a #GtkLabel, #GtkLabel
4074 * queues a resize to ensure there's enough space for the new text.
4077 gtk_widget_queue_resize (GtkWidget *widget)
4079 g_return_if_fail (GTK_IS_WIDGET (widget));
4081 if (gtk_widget_get_realized (widget))
4082 gtk_widget_queue_shallow_draw (widget);
4084 _gtk_size_group_queue_resize (widget);
4088 * gtk_widget_queue_resize_no_redraw:
4089 * @widget: a #GtkWidget
4091 * This function works like gtk_widget_queue_resize(),
4092 * except that the widget is not invalidated.
4097 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4099 g_return_if_fail (GTK_IS_WIDGET (widget));
4101 _gtk_size_group_queue_resize (widget);
4105 * gtk_widget_size_request:
4106 * @widget: a #GtkWidget
4107 * @requisition: (out): a #GtkRequisition to be filled in
4109 * This function is typically used when implementing a #GtkContainer
4110 * subclass. Obtains the preferred size of a widget. The container
4111 * uses this information to arrange its child widgets and decide what
4112 * size allocations to give them with gtk_widget_size_allocate().
4114 * You can also call this function from an application, with some
4115 * caveats. Most notably, getting a size request requires the widget
4116 * to be associated with a screen, because font information may be
4117 * needed. Multihead-aware applications should keep this in mind.
4119 * Also remember that the size request is not necessarily the size
4120 * a widget will actually be allocated.
4122 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4125 gtk_widget_size_request (GtkWidget *widget,
4126 GtkRequisition *requisition)
4128 g_return_if_fail (GTK_IS_WIDGET (widget));
4130 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4134 * gtk_widget_get_child_requisition:
4135 * @widget: a #GtkWidget
4136 * @requisition: (out): a #GtkRequisition to be filled in
4138 * This function is only for use in widget implementations. Obtains
4139 * @widget->requisition, unless someone has forced a particular
4140 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4141 * in which case it returns that geometry instead of the widget's
4144 * This function differs from gtk_widget_size_request() in that
4145 * it retrieves the last size request value from @widget->requisition,
4146 * while gtk_widget_size_request() actually calls the "size_request" method
4147 * on @widget to compute the size request and fill in @widget->requisition,
4148 * and only then returns @widget->requisition.
4150 * Because this function does not call the "size_request" method, it
4151 * can only be used when you know that @widget->requisition is
4152 * up-to-date, that is, gtk_widget_size_request() has been called
4153 * since the last time a resize was queued. In general, only container
4154 * implementations have this information; applications should use
4155 * gtk_widget_size_request().
4158 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4161 gtk_widget_get_child_requisition (GtkWidget *widget,
4162 GtkRequisition *requisition)
4164 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4168 invalidate_predicate (GdkWindow *window,
4173 gdk_window_get_user_data (window, &user_data);
4175 return (user_data == data);
4178 /* Invalidate @region in widget->window and all children
4179 * of widget->window owned by widget. @region is in the
4180 * same coordinates as widget->allocation and will be
4181 * modified by this call.
4184 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4185 cairo_region_t *region)
4187 GtkWidgetPrivate *priv = widget->priv;
4189 if (!gtk_widget_get_realized (widget))
4192 if (gtk_widget_get_has_window (widget) && priv->parent)
4196 gdk_window_get_position (priv->window, &x, &y);
4197 cairo_region_translate (region, -x, -y);
4200 gdk_window_invalidate_maybe_recurse (priv->window, region,
4201 invalidate_predicate, widget);
4205 * gtk_widget_queue_shallow_draw:
4206 * @widget: a #GtkWidget
4208 * Like gtk_widget_queue_draw(), but only windows owned
4209 * by @widget are invalidated.
4212 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4215 cairo_region_t *region;
4217 if (!gtk_widget_get_realized (widget))
4220 gtk_widget_get_allocation (widget, &rect);
4222 region = cairo_region_create_rectangle (&rect);
4223 gtk_widget_invalidate_widget_windows (widget, region);
4224 cairo_region_destroy (region);
4228 * gtk_widget_size_allocate:
4229 * @widget: a #GtkWidget
4230 * @allocation: (inout): position and size to be allocated to @widget
4232 * This function is only used by #GtkContainer subclasses, to assign a size
4233 * and position to their child widgets.
4235 * In this function, the allocation may be adjusted. It will be forced
4236 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4237 * method on the child will be used to adjust the allocation. Standard
4238 * adjustments include removing the widget's margins, and applying the
4239 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4242 gtk_widget_size_allocate (GtkWidget *widget,
4243 GtkAllocation *allocation)
4245 GtkWidgetPrivate *priv;
4246 GdkRectangle real_allocation;
4247 GdkRectangle old_allocation;
4248 GdkRectangle adjusted_allocation;
4249 gboolean alloc_needed;
4250 gboolean size_changed;
4251 gboolean position_changed;
4253 priv = widget->priv;
4255 g_return_if_fail (GTK_IS_WIDGET (widget));
4257 #ifdef G_ENABLE_DEBUG
4258 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4269 parent = gtk_widget_get_parent (parent);
4272 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4273 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4274 2 * depth, " ", name,
4275 allocation->width, allocation->height);
4277 #endif /* G_ENABLE_DEBUG */
4279 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4280 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4281 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4282 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4284 old_allocation = priv->allocation;
4285 real_allocation = *allocation;
4287 adjusted_allocation = real_allocation;
4288 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4290 if (adjusted_allocation.x < real_allocation.x ||
4291 adjusted_allocation.y < real_allocation.y ||
4292 (adjusted_allocation.x + adjusted_allocation.width) >
4293 (real_allocation.x + real_allocation.width) ||
4294 (adjusted_allocation.y + adjusted_allocation.height >
4295 real_allocation.y + real_allocation.height))
4297 g_warning ("%s %p attempted to adjust its size allocation from %d,%d %dx%d to %d,%d %dx%d. adjust_size_allocation must keep allocation inside original bounds",
4298 G_OBJECT_TYPE_NAME (widget), widget,
4299 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4300 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4301 adjusted_allocation = real_allocation; /* veto it */
4305 real_allocation = adjusted_allocation;
4308 if (real_allocation.width < 0 || real_allocation.height < 0)
4310 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4311 real_allocation.width,
4312 real_allocation.height);
4315 real_allocation.width = MAX (real_allocation.width, 1);
4316 real_allocation.height = MAX (real_allocation.height, 1);
4318 size_changed = (old_allocation.width != real_allocation.width ||
4319 old_allocation.height != real_allocation.height);
4320 position_changed = (old_allocation.x != real_allocation.x ||
4321 old_allocation.y != real_allocation.y);
4323 if (!alloc_needed && !size_changed && !position_changed)
4326 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4328 if (gtk_widget_get_mapped (widget))
4330 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4332 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4334 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4335 cairo_region_union_rectangle (invalidate, &old_allocation);
4337 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4338 cairo_region_destroy (invalidate);
4343 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4345 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4347 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4348 cairo_region_union_rectangle (invalidate, &old_allocation);
4350 gtk_widget_invalidate_widget_windows (widget, invalidate);
4351 cairo_region_destroy (invalidate);
4356 if ((size_changed || position_changed) && priv->parent &&
4357 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4359 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4360 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4361 cairo_region_destroy (invalidate);
4366 * gtk_widget_common_ancestor:
4367 * @widget_a: a #GtkWidget
4368 * @widget_b: a #GtkWidget
4370 * Find the common ancestor of @widget_a and @widget_b that
4371 * is closest to the two widgets.
4373 * Return value: the closest common ancestor of @widget_a and
4374 * @widget_b or %NULL if @widget_a and @widget_b do not
4375 * share a common ancestor.
4378 gtk_widget_common_ancestor (GtkWidget *widget_a,
4379 GtkWidget *widget_b)
4381 GtkWidget *parent_a;
4382 GtkWidget *parent_b;
4386 parent_a = widget_a;
4387 while (parent_a->priv->parent)
4389 parent_a = parent_a->priv->parent;
4393 parent_b = widget_b;
4394 while (parent_b->priv->parent)
4396 parent_b = parent_b->priv->parent;
4400 if (parent_a != parent_b)
4403 while (depth_a > depth_b)
4405 widget_a = widget_a->priv->parent;
4409 while (depth_b > depth_a)
4411 widget_b = widget_b->priv->parent;
4415 while (widget_a != widget_b)
4417 widget_a = widget_a->priv->parent;
4418 widget_b = widget_b->priv->parent;
4425 * gtk_widget_translate_coordinates:
4426 * @src_widget: a #GtkWidget
4427 * @dest_widget: a #GtkWidget
4428 * @src_x: X position relative to @src_widget
4429 * @src_y: Y position relative to @src_widget
4430 * @dest_x: (out): location to store X position relative to @dest_widget
4431 * @dest_y: (out): location to store Y position relative to @dest_widget
4433 * Translate coordinates relative to @src_widget's allocation to coordinates
4434 * relative to @dest_widget's allocations. In order to perform this
4435 * operation, both widgets must be realized, and must share a common
4438 * Return value: %FALSE if either widget was not realized, or there
4439 * was no common ancestor. In this case, nothing is stored in
4440 * *@dest_x and *@dest_y. Otherwise %TRUE.
4443 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4444 GtkWidget *dest_widget,
4450 GtkWidgetPrivate *src_priv = src_widget->priv;
4451 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4452 GtkWidget *ancestor;
4454 GList *dest_list = NULL;
4456 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4457 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4459 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4460 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4463 /* Translate from allocation relative to window relative */
4464 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4467 gdk_window_get_position (src_priv->window, &wx, &wy);
4469 src_x -= wx - src_priv->allocation.x;
4470 src_y -= wy - src_priv->allocation.y;
4474 src_x += src_priv->allocation.x;
4475 src_y += src_priv->allocation.y;
4478 /* Translate to the common ancestor */
4479 window = src_priv->window;
4480 while (window != ancestor->priv->window)
4484 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4489 window = gdk_window_get_effective_parent (window);
4491 if (!window) /* Handle GtkHandleBox */
4496 window = dest_priv->window;
4497 while (window != ancestor->priv->window)
4499 dest_list = g_list_prepend (dest_list, window);
4501 window = gdk_window_get_effective_parent (window);
4503 if (!window) /* Handle GtkHandleBox */
4505 g_list_free (dest_list);
4514 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4519 dest_list = g_list_remove (dest_list, dest_list->data);
4522 /* Translate from window relative to allocation relative */
4523 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4526 gdk_window_get_position (dest_priv->window, &wx, &wy);
4528 src_x += wx - dest_priv->allocation.x;
4529 src_y += wy - dest_priv->allocation.y;
4533 src_x -= dest_priv->allocation.x;
4534 src_y -= dest_priv->allocation.y;
4546 gtk_widget_real_size_allocate (GtkWidget *widget,
4547 GtkAllocation *allocation)
4549 GtkWidgetPrivate *priv = widget->priv;
4551 priv->allocation = *allocation;
4553 if (gtk_widget_get_realized (widget) &&
4554 gtk_widget_get_has_window (widget))
4556 gdk_window_move_resize (priv->window,
4557 allocation->x, allocation->y,
4558 allocation->width, allocation->height);
4563 get_span_inside_border (GtkWidget *widget,
4567 int allocated_outside_size,
4568 int natural_inside_size,
4569 int *coord_inside_p,
4572 int inside_allocated;
4576 inside_allocated = allocated_outside_size - start_pad - end_pad;
4578 content_size = natural_inside_size;
4579 if (content_size > inside_allocated)
4581 /* didn't get full natural size */
4582 content_size = inside_allocated;
4585 coord = size = 0; /* silence compiler */
4588 case GTK_ALIGN_FILL:
4590 size = inside_allocated;
4592 case GTK_ALIGN_START:
4594 size = content_size;
4597 coord = allocated_outside_size - end_pad - content_size;
4598 size = content_size;
4600 case GTK_ALIGN_CENTER:
4601 coord = start_pad + (inside_allocated - content_size) / 2;
4602 size = content_size;
4607 *coord_inside_p = coord;
4610 *size_inside_p = size;
4614 get_span_inside_border_horizontal (GtkWidget *widget,
4615 const GtkWidgetAuxInfo *aux_info,
4616 int allocated_outside_width,
4617 int natural_inside_width,
4619 int *width_inside_p)
4621 get_span_inside_border (widget,
4623 aux_info->margin.left,
4624 aux_info->margin.right,
4625 allocated_outside_width,
4626 natural_inside_width,
4632 get_span_inside_border_vertical (GtkWidget *widget,
4633 const GtkWidgetAuxInfo *aux_info,
4634 int allocated_outside_height,
4635 int natural_inside_height,
4637 int *height_inside_p)
4639 get_span_inside_border (widget,
4641 aux_info->margin.top,
4642 aux_info->margin.bottom,
4643 allocated_outside_height,
4644 natural_inside_height,
4650 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4651 GtkAllocation *allocation)
4653 const GtkWidgetAuxInfo *aux_info;
4654 GtkRequisition min, natural;
4657 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4659 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &min, &natural);
4661 get_span_inside_border_horizontal (widget,
4666 get_span_inside_border_vertical (widget,
4674 allocation->width = w;
4675 allocation->height = h;
4679 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4682 GtkWidgetPrivate *priv = widget->priv;
4684 /* widgets must be onscreen for accels to take effect */
4685 return gtk_widget_is_sensitive (widget) &&
4686 gtk_widget_is_drawable (widget) &&
4687 gdk_window_is_viewable (priv->window);
4691 * gtk_widget_can_activate_accel:
4692 * @widget: a #GtkWidget
4693 * @signal_id: the ID of a signal installed on @widget
4695 * Determines whether an accelerator that activates the signal
4696 * identified by @signal_id can currently be activated.
4697 * This is done by emitting the #GtkWidget::can-activate-accel
4698 * signal on @widget; if the signal isn't overridden by a
4699 * handler or in a derived widget, then the default check is
4700 * that the widget must be sensitive, and the widget and all
4701 * its ancestors mapped.
4703 * Return value: %TRUE if the accelerator can be activated.
4708 gtk_widget_can_activate_accel (GtkWidget *widget,
4711 gboolean can_activate = FALSE;
4712 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4713 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4714 return can_activate;
4723 closure_accel_activate (GClosure *closure,
4724 GValue *return_value,
4725 guint n_param_values,
4726 const GValue *param_values,
4727 gpointer invocation_hint,
4728 gpointer marshal_data)
4730 AccelClosure *aclosure = (AccelClosure*) closure;
4731 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4734 g_signal_emit (closure->data, aclosure->signal_id, 0);
4736 /* whether accelerator was handled */
4737 g_value_set_boolean (return_value, can_activate);
4741 closures_destroy (gpointer data)
4743 GSList *slist, *closures = data;
4745 for (slist = closures; slist; slist = slist->next)
4747 g_closure_invalidate (slist->data);
4748 g_closure_unref (slist->data);
4750 g_slist_free (closures);
4754 widget_new_accel_closure (GtkWidget *widget,
4757 AccelClosure *aclosure;
4758 GClosure *closure = NULL;
4759 GSList *slist, *closures;
4761 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4762 for (slist = closures; slist; slist = slist->next)
4763 if (!gtk_accel_group_from_accel_closure (slist->data))
4765 /* reuse this closure */
4766 closure = slist->data;
4771 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4772 closures = g_slist_prepend (closures, g_closure_ref (closure));
4773 g_closure_sink (closure);
4774 g_closure_set_marshal (closure, closure_accel_activate);
4776 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4778 aclosure = (AccelClosure*) closure;
4779 g_assert (closure->data == widget);
4780 g_assert (closure->marshal == closure_accel_activate);
4781 aclosure->signal_id = signal_id;
4787 * gtk_widget_add_accelerator
4788 * @widget: widget to install an accelerator on
4789 * @accel_signal: widget signal to emit on accelerator activation
4790 * @accel_group: accel group for this widget, added to its toplevel
4791 * @accel_key: GDK keyval of the accelerator
4792 * @accel_mods: modifier key combination of the accelerator
4793 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4795 * Installs an accelerator for this @widget in @accel_group that causes
4796 * @accel_signal to be emitted if the accelerator is activated.
4797 * The @accel_group needs to be added to the widget's toplevel via
4798 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4799 * Accelerators added through this function are not user changeable during
4800 * runtime. If you want to support accelerators that can be changed by the
4801 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4802 * gtk_menu_item_set_accel_path() instead.
4805 gtk_widget_add_accelerator (GtkWidget *widget,
4806 const gchar *accel_signal,
4807 GtkAccelGroup *accel_group,
4809 GdkModifierType accel_mods,
4810 GtkAccelFlags accel_flags)
4815 g_return_if_fail (GTK_IS_WIDGET (widget));
4816 g_return_if_fail (accel_signal != NULL);
4817 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4819 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4820 if (!query.signal_id ||
4821 !(query.signal_flags & G_SIGNAL_ACTION) ||
4822 query.return_type != G_TYPE_NONE ||
4825 /* hmm, should be elaborate enough */
4826 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4827 G_OBJECT_TYPE_NAME (widget), accel_signal);
4831 closure = widget_new_accel_closure (widget, query.signal_id);
4833 g_object_ref (widget);
4835 /* install the accelerator. since we don't map this onto an accel_path,
4836 * the accelerator will automatically be locked.
4838 gtk_accel_group_connect (accel_group,
4841 accel_flags | GTK_ACCEL_LOCKED,
4844 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4846 g_object_unref (widget);
4850 * gtk_widget_remove_accelerator:
4851 * @widget: widget to install an accelerator on
4852 * @accel_group: accel group for this widget
4853 * @accel_key: GDK keyval of the accelerator
4854 * @accel_mods: modifier key combination of the accelerator
4855 * @returns: whether an accelerator was installed and could be removed
4857 * Removes an accelerator from @widget, previously installed with
4858 * gtk_widget_add_accelerator().
4861 gtk_widget_remove_accelerator (GtkWidget *widget,
4862 GtkAccelGroup *accel_group,
4864 GdkModifierType accel_mods)
4866 GtkAccelGroupEntry *ag_entry;
4867 GList *slist, *clist;
4870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4871 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4873 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4874 clist = gtk_widget_list_accel_closures (widget);
4875 for (slist = clist; slist; slist = slist->next)
4879 for (i = 0; i < n; i++)
4880 if (slist->data == (gpointer) ag_entry[i].closure)
4882 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4884 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4886 g_list_free (clist);
4891 g_list_free (clist);
4893 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4894 accel_key, accel_mods, accel_group,
4895 G_OBJECT_TYPE_NAME (widget), widget);
4901 * gtk_widget_list_accel_closures:
4902 * @widget: widget to list accelerator closures for
4904 * Lists the closures used by @widget for accelerator group connections
4905 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4906 * The closures can be used to monitor accelerator changes on @widget,
4907 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4908 * #GtkAccelGroup of a closure which can be found out with
4909 * gtk_accel_group_from_accel_closure().
4911 * Return value: (transfer container) (element-type GClosure):
4912 * a newly allocated #GList of closures
4915 gtk_widget_list_accel_closures (GtkWidget *widget)
4918 GList *clist = NULL;
4920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4922 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4923 if (gtk_accel_group_from_accel_closure (slist->data))
4924 clist = g_list_prepend (clist, slist->data);
4930 GtkAccelGroup *accel_group;
4935 destroy_accel_path (gpointer data)
4937 AccelPath *apath = data;
4939 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4941 /* closures_destroy takes care of unrefing the closure */
4942 g_object_unref (apath->accel_group);
4944 g_slice_free (AccelPath, apath);
4949 * gtk_widget_set_accel_path:
4950 * @widget: a #GtkWidget
4951 * @accel_path: (allow-none): path used to look up the accelerator
4952 * @accel_group: (allow-none): a #GtkAccelGroup.
4954 * Given an accelerator group, @accel_group, and an accelerator path,
4955 * @accel_path, sets up an accelerator in @accel_group so whenever the
4956 * key binding that is defined for @accel_path is pressed, @widget
4957 * will be activated. This removes any accelerators (for any
4958 * accelerator group) installed by previous calls to
4959 * gtk_widget_set_accel_path(). Associating accelerators with
4960 * paths allows them to be modified by the user and the modifications
4961 * to be saved for future use. (See gtk_accel_map_save().)
4963 * This function is a low level function that would most likely
4964 * be used by a menu creation system like #GtkUIManager. If you
4965 * use #GtkUIManager, setting up accelerator paths will be done
4968 * Even when you you aren't using #GtkUIManager, if you only want to
4969 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4970 * provides a somewhat more convenient interface.
4972 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4973 * pass a static string, you can save some memory by interning it first with
4974 * g_intern_static_string().
4977 gtk_widget_set_accel_path (GtkWidget *widget,
4978 const gchar *accel_path,
4979 GtkAccelGroup *accel_group)
4983 g_return_if_fail (GTK_IS_WIDGET (widget));
4984 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4988 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4989 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4991 gtk_accel_map_add_entry (accel_path, 0, 0);
4992 apath = g_slice_new (AccelPath);
4993 apath->accel_group = g_object_ref (accel_group);
4994 apath->path_quark = g_quark_from_string (accel_path);
4995 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5000 /* also removes possible old settings */
5001 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5004 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5006 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5010 _gtk_widget_get_accel_path (GtkWidget *widget,
5015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5017 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5019 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5020 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5024 * gtk_widget_mnemonic_activate:
5025 * @widget: a #GtkWidget
5026 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5028 * Emits the #GtkWidget::mnemonic-activate signal.
5030 * The default handler for this signal activates the @widget if
5031 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5034 * Returns: %TRUE if the signal has been handled
5037 gtk_widget_mnemonic_activate (GtkWidget *widget,
5038 gboolean group_cycling)
5042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5044 group_cycling = group_cycling != FALSE;
5045 if (!gtk_widget_is_sensitive (widget))
5048 g_signal_emit (widget,
5049 widget_signals[MNEMONIC_ACTIVATE],
5057 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5058 gboolean group_cycling)
5060 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5061 gtk_widget_activate (widget);
5062 else if (gtk_widget_get_can_focus (widget))
5063 gtk_widget_grab_focus (widget);
5066 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5067 G_OBJECT_TYPE_NAME (widget));
5068 gtk_widget_error_bell (widget);
5074 gtk_widget_real_expose_event (GtkWidget *widget,
5075 GdkEventExpose *expose)
5077 gboolean result = FALSE;
5080 if (!gtk_widget_is_drawable (widget))
5083 cr = gdk_cairo_create (expose->window);
5084 gdk_cairo_region (cr, expose->region);
5087 if (!gtk_widget_get_has_window (widget))
5089 cairo_translate (cr,
5090 widget->priv->allocation.x,
5091 widget->priv->allocation.y);
5094 g_signal_emit (widget, widget_signals[DRAW],
5104 gtk_widget_real_key_press_event (GtkWidget *widget,
5107 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5111 gtk_widget_real_key_release_event (GtkWidget *widget,
5114 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5118 gtk_widget_real_focus_in_event (GtkWidget *widget,
5119 GdkEventFocus *event)
5121 gtk_widget_queue_shallow_draw (widget);
5127 gtk_widget_real_focus_out_event (GtkWidget *widget,
5128 GdkEventFocus *event)
5130 gtk_widget_queue_shallow_draw (widget);
5135 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5136 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5140 * @widget: a #GtkWidget
5141 * @event: a #GdkEvent
5143 * Rarely-used function. This function is used to emit
5144 * the event signals on a widget (those signals should never
5145 * be emitted without using this function to do so).
5146 * If you want to synthesize an event though, don't use this function;
5147 * instead, use gtk_main_do_event() so the event will behave as if
5148 * it were in the event queue. Don't synthesize expose events; instead,
5149 * use gdk_window_invalidate_rect() to invalidate a region of the
5152 * Return value: return from the event signal emission (%TRUE if
5153 * the event was handled)
5156 gtk_widget_event (GtkWidget *widget,
5159 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5160 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5162 if (event->type == GDK_EXPOSE)
5164 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5165 "the same effect, call gdk_window_invalidate_rect/region(), "
5166 "followed by gdk_window_process_updates().");
5170 return gtk_widget_event_internal (widget, event);
5175 * gtk_widget_send_expose:
5176 * @widget: a #GtkWidget
5177 * @event: a expose #GdkEvent
5179 * Very rarely-used function. This function is used to emit
5180 * an expose event signals on a widget. This function is not
5181 * normally used directly. The only time it is used is when
5182 * propagating an expose event to a child %NO_WINDOW widget, and
5183 * that is normally done using gtk_container_propagate_expose().
5185 * If you want to force an area of a window to be redrawn,
5186 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5187 * To cause the redraw to be done immediately, follow that call
5188 * with a call to gdk_window_process_updates().
5190 * Return value: return from the event signal emission (%TRUE if
5191 * the event was handled)
5194 gtk_widget_send_expose (GtkWidget *widget,
5197 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5198 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5199 g_return_val_if_fail (event != NULL, TRUE);
5200 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5202 return gtk_widget_event_internal (widget, event);
5206 event_window_is_still_viewable (GdkEvent *event)
5208 /* Check that we think the event's window is viewable before
5209 * delivering the event, to prevent suprises. We do this here
5210 * at the last moment, since the event may have been queued
5211 * up behind other events, held over a recursive main loop, etc.
5213 switch (event->type)
5216 case GDK_MOTION_NOTIFY:
5217 case GDK_BUTTON_PRESS:
5218 case GDK_2BUTTON_PRESS:
5219 case GDK_3BUTTON_PRESS:
5221 case GDK_ENTER_NOTIFY:
5222 case GDK_PROXIMITY_IN:
5224 return event->any.window && gdk_window_is_viewable (event->any.window);
5227 /* The following events are the second half of paired events;
5228 * we always deliver them to deal with widgets that clean up
5229 * on the second half.
5231 case GDK_BUTTON_RELEASE:
5232 case GDK_KEY_RELEASE:
5233 case GDK_LEAVE_NOTIFY:
5234 case GDK_PROXIMITY_OUT:
5238 /* Remaining events would make sense on an not-viewable window,
5239 * or don't have an associated window.
5246 gtk_widget_event_internal (GtkWidget *widget,
5249 gboolean return_val = FALSE;
5251 /* We check only once for is-still-visible; if someone
5252 * hides the window in on of the signals on the widget,
5253 * they are responsible for returning TRUE to terminate
5256 if (!event_window_is_still_viewable (event))
5259 g_object_ref (widget);
5261 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5262 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5267 switch (event->type)
5272 case GDK_BUTTON_PRESS:
5273 case GDK_2BUTTON_PRESS:
5274 case GDK_3BUTTON_PRESS:
5275 signal_num = BUTTON_PRESS_EVENT;
5278 signal_num = SCROLL_EVENT;
5280 case GDK_BUTTON_RELEASE:
5281 signal_num = BUTTON_RELEASE_EVENT;
5283 case GDK_MOTION_NOTIFY:
5284 signal_num = MOTION_NOTIFY_EVENT;
5287 signal_num = DELETE_EVENT;
5290 signal_num = DESTROY_EVENT;
5291 _gtk_tooltip_hide (widget);
5294 signal_num = KEY_PRESS_EVENT;
5296 case GDK_KEY_RELEASE:
5297 signal_num = KEY_RELEASE_EVENT;
5299 case GDK_ENTER_NOTIFY:
5300 signal_num = ENTER_NOTIFY_EVENT;
5302 case GDK_LEAVE_NOTIFY:
5303 signal_num = LEAVE_NOTIFY_EVENT;
5305 case GDK_FOCUS_CHANGE:
5306 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5307 if (event->focus_change.in)
5308 _gtk_tooltip_focus_in (widget);
5310 _gtk_tooltip_focus_out (widget);
5313 signal_num = CONFIGURE_EVENT;
5316 signal_num = MAP_EVENT;
5319 signal_num = UNMAP_EVENT;
5321 case GDK_WINDOW_STATE:
5322 signal_num = WINDOW_STATE_EVENT;
5324 case GDK_PROPERTY_NOTIFY:
5325 signal_num = PROPERTY_NOTIFY_EVENT;
5327 case GDK_SELECTION_CLEAR:
5328 signal_num = SELECTION_CLEAR_EVENT;
5330 case GDK_SELECTION_REQUEST:
5331 signal_num = SELECTION_REQUEST_EVENT;
5333 case GDK_SELECTION_NOTIFY:
5334 signal_num = SELECTION_NOTIFY_EVENT;
5336 case GDK_PROXIMITY_IN:
5337 signal_num = PROXIMITY_IN_EVENT;
5339 case GDK_PROXIMITY_OUT:
5340 signal_num = PROXIMITY_OUT_EVENT;
5343 signal_num = NO_EXPOSE_EVENT;
5345 case GDK_CLIENT_EVENT:
5346 signal_num = CLIENT_EVENT;
5349 signal_num = EXPOSE_EVENT;
5351 case GDK_VISIBILITY_NOTIFY:
5352 signal_num = VISIBILITY_NOTIFY_EVENT;
5354 case GDK_GRAB_BROKEN:
5355 signal_num = GRAB_BROKEN;
5358 signal_num = DAMAGE_EVENT;
5361 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5365 if (signal_num != -1)
5366 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5368 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5369 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5373 g_object_unref (widget);
5379 * gtk_widget_activate:
5380 * @widget: a #GtkWidget that's activatable
5382 * For widgets that can be "activated" (buttons, menu items, etc.)
5383 * this function activates them. Activation is what happens when you
5384 * press Enter on a widget during key navigation. If @widget isn't
5385 * activatable, the function returns %FALSE.
5387 * Return value: %TRUE if the widget was activatable
5390 gtk_widget_activate (GtkWidget *widget)
5392 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5394 if (WIDGET_CLASS (widget)->activate_signal)
5396 /* FIXME: we should eventually check the signals signature here */
5397 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5406 * gtk_widget_set_scroll_adjustments:
5407 * @widget: a #GtkWidget
5408 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5409 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5411 * For widgets that support scrolling, sets the scroll adjustments and
5412 * returns %TRUE. For widgets that don't support scrolling, does
5413 * nothing and returns %FALSE. Widgets that don't support scrolling
5414 * can be scrolled by placing them in a #GtkViewport, which does
5415 * support scrolling.
5417 * Return value: %TRUE if the widget supports scrolling
5420 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5421 GtkAdjustment *hadjustment,
5422 GtkAdjustment *vadjustment)
5427 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5430 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5432 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5434 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5438 g_signal_query (signal_id, &query);
5439 if (!query.signal_id ||
5440 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5441 query.return_type != G_TYPE_NONE ||
5442 query.n_params != 2 ||
5443 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5444 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5446 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5447 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5451 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5456 gtk_widget_reparent_subwindows (GtkWidget *widget,
5457 GdkWindow *new_window)
5459 GtkWidgetPrivate *priv = widget->priv;
5461 if (!gtk_widget_get_has_window (widget))
5463 GList *children = gdk_window_get_children (priv->window);
5466 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5468 GdkWindow *window = tmp_list->data;
5471 gdk_window_get_user_data (window, &child);
5472 while (child && child != widget)
5473 child = ((GtkWidget*) child)->priv->parent;
5476 gdk_window_reparent (window, new_window, 0, 0);
5479 g_list_free (children);
5484 GList *tmp_list, *children;
5486 parent = gdk_window_get_parent (priv->window);
5489 gdk_window_reparent (priv->window, new_window, 0, 0);
5492 children = gdk_window_get_children (parent);
5494 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5496 GdkWindow *window = tmp_list->data;
5499 gdk_window_get_user_data (window, &child);
5501 if (child == widget)
5502 gdk_window_reparent (window, new_window, 0, 0);
5505 g_list_free (children);
5511 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5512 gpointer client_data)
5514 GtkWidgetPrivate *priv = widget->priv;
5516 g_assert (client_data != NULL);
5518 if (!gtk_widget_get_has_window (widget))
5521 g_object_unref (priv->window);
5522 priv->window = (GdkWindow*) client_data;
5524 g_object_ref (priv->window);
5526 if (GTK_IS_CONTAINER (widget))
5527 gtk_container_forall (GTK_CONTAINER (widget),
5528 gtk_widget_reparent_fixup_child,
5534 * gtk_widget_reparent:
5535 * @widget: a #GtkWidget
5536 * @new_parent: a #GtkContainer to move the widget into
5538 * Moves a widget from one #GtkContainer to another, handling reference
5539 * count issues to avoid destroying the widget.
5542 gtk_widget_reparent (GtkWidget *widget,
5543 GtkWidget *new_parent)
5545 GtkWidgetPrivate *priv;
5547 g_return_if_fail (GTK_IS_WIDGET (widget));
5548 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5549 priv = widget->priv;
5550 g_return_if_fail (priv->parent != NULL);
5552 if (priv->parent != new_parent)
5554 /* First try to see if we can get away without unrealizing
5555 * the widget as we reparent it. if so we set a flag so
5556 * that gtk_widget_unparent doesn't unrealize widget
5558 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5559 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5561 g_object_ref (widget);
5562 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5563 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5564 g_object_unref (widget);
5566 if (GTK_WIDGET_IN_REPARENT (widget))
5568 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5570 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5571 gtk_widget_reparent_fixup_child (widget,
5572 gtk_widget_get_parent_window (widget));
5575 g_object_notify (G_OBJECT (widget), "parent");
5580 * gtk_widget_intersect:
5581 * @widget: a #GtkWidget
5582 * @area: a rectangle
5583 * @intersection: rectangle to store intersection of @widget and @area
5585 * Computes the intersection of a @widget's area and @area, storing
5586 * the intersection in @intersection, and returns %TRUE if there was
5587 * an intersection. @intersection may be %NULL if you're only
5588 * interested in whether there was an intersection.
5590 * Return value: %TRUE if there was an intersection
5593 gtk_widget_intersect (GtkWidget *widget,
5594 const GdkRectangle *area,
5595 GdkRectangle *intersection)
5597 GtkWidgetPrivate *priv;
5602 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5603 g_return_val_if_fail (area != NULL, FALSE);
5605 priv = widget->priv;
5608 dest = intersection;
5612 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5614 if (return_val && intersection && gtk_widget_get_has_window (widget))
5616 intersection->x -= priv->allocation.x;
5617 intersection->y -= priv->allocation.y;
5624 * gtk_widget_region_intersect:
5625 * @widget: a #GtkWidget
5626 * @region: a #cairo_region_t, in the same coordinate system as
5627 * @widget->allocation. That is, relative to @widget->window
5628 * for %NO_WINDOW widgets; relative to the parent window
5629 * of @widget->window for widgets with their own window.
5630 * @returns: A newly allocated region holding the intersection of @widget
5631 * and @region. The coordinates of the return value are
5632 * relative to @widget->window for %NO_WINDOW widgets, and
5633 * relative to the parent window of @widget->window for
5634 * widgets with their own window.
5636 * Computes the intersection of a @widget's area and @region, returning
5637 * the intersection. The result may be empty, use cairo_region_is_empty() to
5641 gtk_widget_region_intersect (GtkWidget *widget,
5642 const cairo_region_t *region)
5645 cairo_region_t *dest;
5647 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5648 g_return_val_if_fail (region != NULL, NULL);
5650 gtk_widget_get_allocation (widget, &rect);
5652 dest = cairo_region_create_rectangle (&rect);
5654 cairo_region_intersect (dest, region);
5660 * _gtk_widget_grab_notify:
5661 * @widget: a #GtkWidget
5662 * @was_grabbed: whether a grab is now in effect
5664 * Emits the #GtkWidget::grab-notify signal on @widget.
5669 _gtk_widget_grab_notify (GtkWidget *widget,
5670 gboolean was_grabbed)
5672 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5676 * gtk_widget_grab_focus:
5677 * @widget: a #GtkWidget
5679 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5680 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5681 * something like #GtkFrame won't work.
5683 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5684 * gtk_widget_set_can_focus() to modify that flag.
5686 * The widget also needs to be realized and mapped. This is indicated by the
5687 * related signals. Grabbing the focus immediately after creating the widget
5688 * will likely fail and cause critical warnings.
5691 gtk_widget_grab_focus (GtkWidget *widget)
5693 g_return_if_fail (GTK_IS_WIDGET (widget));
5695 if (!gtk_widget_is_sensitive (widget))
5698 g_object_ref (widget);
5699 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5700 g_object_notify (G_OBJECT (widget), "has-focus");
5701 g_object_unref (widget);
5705 reset_focus_recurse (GtkWidget *widget,
5708 if (GTK_IS_CONTAINER (widget))
5710 GtkContainer *container;
5712 container = GTK_CONTAINER (widget);
5713 gtk_container_set_focus_child (container, NULL);
5715 gtk_container_foreach (container,
5716 reset_focus_recurse,
5722 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5724 if (gtk_widget_get_can_focus (focus_widget))
5726 GtkWidget *toplevel;
5729 /* clear the current focus setting, break if the current widget
5730 * is the focus widget's parent, since containers above that will
5731 * be set by the next loop.
5733 toplevel = gtk_widget_get_toplevel (focus_widget);
5734 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5736 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5738 if (widget == focus_widget)
5740 /* We call _gtk_window_internal_set_focus() here so that the
5741 * toplevel window can request the focus if necessary.
5742 * This is needed when the toplevel is a GtkPlug
5744 if (!gtk_widget_has_focus (widget))
5745 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5752 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5754 widget = widget->priv->parent;
5755 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5759 else if (toplevel != focus_widget)
5761 /* gtk_widget_grab_focus() operates on a tree without window...
5762 * actually, this is very questionable behaviour.
5765 gtk_container_foreach (GTK_CONTAINER (toplevel),
5766 reset_focus_recurse,
5770 /* now propagate the new focus up the widget tree and finally
5771 * set it on the window
5773 widget = focus_widget;
5774 while (widget->priv->parent)
5776 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5777 widget = widget->priv->parent;
5779 if (GTK_IS_WINDOW (widget))
5780 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5785 gtk_widget_real_query_tooltip (GtkWidget *widget,
5788 gboolean keyboard_tip,
5789 GtkTooltip *tooltip)
5791 gchar *tooltip_markup;
5792 gboolean has_tooltip;
5794 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5795 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5797 if (has_tooltip && tooltip_markup)
5799 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5807 gtk_widget_real_show_help (GtkWidget *widget,
5808 GtkWidgetHelpType help_type)
5810 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5812 _gtk_tooltip_toggle_keyboard_mode (widget);
5821 gtk_widget_real_focus (GtkWidget *widget,
5822 GtkDirectionType direction)
5824 if (!gtk_widget_get_can_focus (widget))
5827 if (!gtk_widget_is_focus (widget))
5829 gtk_widget_grab_focus (widget);
5837 gtk_widget_real_move_focus (GtkWidget *widget,
5838 GtkDirectionType direction)
5840 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5842 if (GTK_IS_WINDOW (toplevel) &&
5843 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5845 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5851 gtk_widget_real_keynav_failed (GtkWidget *widget,
5852 GtkDirectionType direction)
5854 gboolean cursor_only;
5858 case GTK_DIR_TAB_FORWARD:
5859 case GTK_DIR_TAB_BACKWARD:
5866 g_object_get (gtk_widget_get_settings (widget),
5867 "gtk-keynav-cursor-only", &cursor_only,
5874 gtk_widget_error_bell (widget);
5880 * gtk_widget_set_can_focus:
5881 * @widget: a #GtkWidget
5882 * @can_focus: whether or not @widget can own the input focus.
5884 * Specifies whether @widget can own the input focus. See
5885 * gtk_widget_grab_focus() for actually setting the input focus on a
5891 gtk_widget_set_can_focus (GtkWidget *widget,
5894 g_return_if_fail (GTK_IS_WIDGET (widget));
5896 if (can_focus != gtk_widget_get_can_focus (widget))
5899 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5901 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5903 gtk_widget_queue_resize (widget);
5904 g_object_notify (G_OBJECT (widget), "can-focus");
5909 * gtk_widget_get_can_focus:
5910 * @widget: a #GtkWidget
5912 * Determines whether @widget can own the input focus. See
5913 * gtk_widget_set_can_focus().
5915 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5920 gtk_widget_get_can_focus (GtkWidget *widget)
5922 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5924 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5928 * gtk_widget_has_focus:
5929 * @widget: a #GtkWidget
5931 * Determines if the widget has the global input focus. See
5932 * gtk_widget_is_focus() for the difference between having the global
5933 * input focus, and only having the focus within a toplevel.
5935 * Return value: %TRUE if the widget has the global input focus.
5940 gtk_widget_has_focus (GtkWidget *widget)
5942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5944 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5948 * gtk_widget_is_focus:
5949 * @widget: a #GtkWidget
5951 * Determines if the widget is the focus widget within its
5952 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5953 * necessarily set; %HAS_FOCUS will only be set if the
5954 * toplevel widget additionally has the global input focus.)
5956 * Return value: %TRUE if the widget is the focus widget.
5959 gtk_widget_is_focus (GtkWidget *widget)
5961 GtkWidget *toplevel;
5963 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5965 toplevel = gtk_widget_get_toplevel (widget);
5967 if (GTK_IS_WINDOW (toplevel))
5968 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
5974 * gtk_widget_set_can_default:
5975 * @widget: a #GtkWidget
5976 * @can_default: whether or not @widget can be a default widget.
5978 * Specifies whether @widget can be a default widget. See
5979 * gtk_widget_grab_default() for details about the meaning of
5985 gtk_widget_set_can_default (GtkWidget *widget,
5986 gboolean can_default)
5988 g_return_if_fail (GTK_IS_WIDGET (widget));
5990 if (can_default != gtk_widget_get_can_default (widget))
5993 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5995 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5997 gtk_widget_queue_resize (widget);
5998 g_object_notify (G_OBJECT (widget), "can-default");
6003 * gtk_widget_get_can_default:
6004 * @widget: a #GtkWidget
6006 * Determines whether @widget can be a default widget. See
6007 * gtk_widget_set_can_default().
6009 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6014 gtk_widget_get_can_default (GtkWidget *widget)
6016 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6018 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6022 * gtk_widget_has_default:
6023 * @widget: a #GtkWidget
6025 * Determines whether @widget is the current default widget within its
6026 * toplevel. See gtk_widget_set_can_default().
6028 * Return value: %TRUE if @widget is the current default widget within
6029 * its toplevel, %FALSE otherwise
6034 gtk_widget_has_default (GtkWidget *widget)
6036 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6038 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6042 _gtk_widget_set_has_default (GtkWidget *widget,
6043 gboolean has_default)
6046 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6048 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6052 * gtk_widget_grab_default:
6053 * @widget: a #GtkWidget
6055 * Causes @widget to become the default widget. @widget must have the
6056 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6057 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6058 * %TRUE)</literal>. The default widget is activated when
6059 * the user presses Enter in a window. Default widgets must be
6060 * activatable, that is, gtk_widget_activate() should affect them. Note
6061 * that #GtkEntry widgets require the "activates-default" property
6062 * set to %TRUE before they activate the default widget when Enter
6063 * is pressed and the #GtkEntry is focused.
6066 gtk_widget_grab_default (GtkWidget *widget)
6070 g_return_if_fail (GTK_IS_WIDGET (widget));
6071 g_return_if_fail (gtk_widget_get_can_default (widget));
6073 window = gtk_widget_get_toplevel (widget);
6075 if (window && gtk_widget_is_toplevel (window))
6076 gtk_window_set_default (GTK_WINDOW (window), widget);
6078 g_warning (G_STRLOC ": widget not within a GtkWindow");
6082 * gtk_widget_set_receives_default:
6083 * @widget: a #GtkWidget
6084 * @receives_default: whether or not @widget can be a default widget.
6086 * Specifies whether @widget will be treated as the default widget
6087 * within its toplevel when it has the focus, even if another widget
6090 * See gtk_widget_grab_default() for details about the meaning of
6096 gtk_widget_set_receives_default (GtkWidget *widget,
6097 gboolean receives_default)
6099 g_return_if_fail (GTK_IS_WIDGET (widget));
6101 if (receives_default != gtk_widget_get_receives_default (widget))
6103 if (receives_default)
6104 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6106 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6108 g_object_notify (G_OBJECT (widget), "receives-default");
6113 * gtk_widget_get_receives_default:
6114 * @widget: a #GtkWidget
6116 * Determines whether @widget is alyways treated as default widget
6117 * withing its toplevel when it has the focus, even if another widget
6120 * See gtk_widget_set_receives_default().
6122 * Return value: %TRUE if @widget acts as default widget when focussed,
6128 gtk_widget_get_receives_default (GtkWidget *widget)
6130 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6132 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6136 * gtk_widget_has_grab:
6137 * @widget: a #GtkWidget
6139 * Determines whether the widget is currently grabbing events, so it
6140 * is the only widget receiving input events (keyboard and mouse).
6142 * See also gtk_grab_add().
6144 * Return value: %TRUE if the widget is in the grab_widgets stack
6149 gtk_widget_has_grab (GtkWidget *widget)
6151 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6153 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6157 _gtk_widget_set_has_grab (GtkWidget *widget,
6161 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6163 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6167 * gtk_widget_device_is_shadowed:
6168 * @widget: a #GtkWidget
6169 * @device: a #GdkDevice
6171 * Returns %TRUE if @device has been shadowed by a GTK+
6172 * device grab on another widget, so it would stop sending
6173 * events to @widget. This may be used in the
6174 * #GtkWidget::grab-notify signal to check for specific
6175 * devices. See gtk_device_grab_add().
6177 * Returns: %TRUE if there is an ongoing grab on @device
6178 * by another #GtkWidget than @widget.
6183 gtk_widget_device_is_shadowed (GtkWidget *widget,
6186 GtkWindowGroup *group;
6187 GtkWidget *grab_widget, *toplevel;
6189 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6190 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6192 if (!gtk_widget_get_realized (widget))
6195 toplevel = gtk_widget_get_toplevel (widget);
6197 if (GTK_IS_WINDOW (toplevel))
6198 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6200 group = gtk_window_get_group (NULL);
6202 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6204 /* Widget not inside the hierarchy of grab_widget */
6206 widget != grab_widget &&
6207 !gtk_widget_is_ancestor (widget, grab_widget))
6210 grab_widget = gtk_window_group_get_current_grab (group);
6211 if (grab_widget && widget != grab_widget &&
6212 !gtk_widget_is_ancestor (widget, grab_widget))
6219 * gtk_widget_set_name:
6220 * @widget: a #GtkWidget
6221 * @name: name for the widget
6223 * Widgets can be named, which allows you to refer to them from a
6224 * gtkrc file. You can apply a style to widgets with a particular name
6225 * in the gtkrc file. See the documentation for gtkrc files (on the
6226 * same page as the docs for #GtkRcStyle).
6228 * Note that widget names are separated by periods in paths (see
6229 * gtk_widget_path()), so names with embedded periods may cause confusion.
6232 gtk_widget_set_name (GtkWidget *widget,
6235 GtkWidgetPrivate *priv;
6238 g_return_if_fail (GTK_IS_WIDGET (widget));
6240 priv = widget->priv;
6242 new_name = g_strdup (name);
6243 g_free (priv->name);
6244 priv->name = new_name;
6246 if (gtk_widget_has_rc_style (widget))
6247 gtk_widget_reset_rc_style (widget);
6249 g_object_notify (G_OBJECT (widget), "name");
6253 * gtk_widget_get_name:
6254 * @widget: a #GtkWidget
6256 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6257 * significance of widget names.
6259 * Return value: name of the widget. This string is owned by GTK+ and
6260 * should not be modified or freed
6262 G_CONST_RETURN gchar*
6263 gtk_widget_get_name (GtkWidget *widget)
6265 GtkWidgetPrivate *priv;
6267 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6269 priv = widget->priv;
6273 return G_OBJECT_TYPE_NAME (widget);
6277 * gtk_widget_set_state:
6278 * @widget: a #GtkWidget
6279 * @state: new state for @widget
6281 * This function is for use in widget implementations. Sets the state
6282 * of a widget (insensitive, prelighted, etc.) Usually you should set
6283 * the state using wrapper functions such as gtk_widget_set_sensitive().
6286 gtk_widget_set_state (GtkWidget *widget,
6289 GtkWidgetPrivate *priv;
6291 g_return_if_fail (GTK_IS_WIDGET (widget));
6293 priv = widget->priv;
6295 if (state == gtk_widget_get_state (widget))
6298 if (state == GTK_STATE_INSENSITIVE)
6299 gtk_widget_set_sensitive (widget, FALSE);
6305 data.state_restoration = FALSE;
6306 data.use_forall = FALSE;
6308 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6310 data.parent_sensitive = TRUE;
6312 gtk_widget_propagate_state (widget, &data);
6314 if (gtk_widget_is_drawable (widget))
6315 gtk_widget_queue_draw (widget);
6320 * gtk_widget_get_state:
6321 * @widget: a #GtkWidget
6323 * Returns the widget's state. See gtk_widget_set_state().
6325 * Returns: the state of @widget.
6330 gtk_widget_get_state (GtkWidget *widget)
6332 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6334 return widget->priv->state;
6338 * gtk_widget_set_visible:
6339 * @widget: a #GtkWidget
6340 * @visible: whether the widget should be shown or not
6342 * Sets the visibility state of @widget. Note that setting this to
6343 * %TRUE doesn't mean the widget is actually viewable, see
6344 * gtk_widget_get_visible().
6346 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6347 * but is nicer to use when the visibility of the widget depends on
6353 gtk_widget_set_visible (GtkWidget *widget,
6356 g_return_if_fail (GTK_IS_WIDGET (widget));
6358 if (visible != gtk_widget_get_visible (widget))
6361 gtk_widget_show (widget);
6363 gtk_widget_hide (widget);
6368 * gtk_widget_get_visible:
6369 * @widget: a #GtkWidget
6371 * Determines whether the widget is visible. Note that this doesn't
6372 * take into account whether the widget's parent is also visible
6373 * or the widget is obscured in any way.
6375 * See gtk_widget_set_visible().
6377 * Return value: %TRUE if the widget is visible
6382 gtk_widget_get_visible (GtkWidget *widget)
6384 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6386 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6390 * gtk_widget_set_has_window:
6391 * @widget: a #GtkWidget
6392 * @has_window: whether or not @widget has a window.
6394 * Specifies whether @widget has a #GdkWindow of its own. Note that
6395 * all realized widgets have a non-%NULL "window" pointer
6396 * (gtk_widget_get_window() never returns a %NULL window when a widget
6397 * is realized), but for many of them it's actually the #GdkWindow of
6398 * one of its parent widgets. Widgets that do not create a %window for
6399 * themselves in GtkWidget::realize() must announce this by
6400 * calling this function with @has_window = %FALSE.
6402 * This function should only be called by widget implementations,
6403 * and they should call it in their init() function.
6408 gtk_widget_set_has_window (GtkWidget *widget,
6409 gboolean has_window)
6411 g_return_if_fail (GTK_IS_WIDGET (widget));
6414 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6416 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6420 * gtk_widget_get_has_window:
6421 * @widget: a #GtkWidget
6423 * Determines whether @widget has a #GdkWindow of its own. See
6424 * gtk_widget_set_has_window().
6426 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6431 gtk_widget_get_has_window (GtkWidget *widget)
6433 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6435 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6439 * gtk_widget_is_toplevel:
6440 * @widget: a #GtkWidget
6442 * Determines whether @widget is a toplevel widget. Currently only
6443 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6444 * widgets have no parent widget.
6446 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6451 gtk_widget_is_toplevel (GtkWidget *widget)
6453 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6455 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6459 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6460 gboolean is_toplevel)
6463 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6465 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6469 * gtk_widget_is_drawable:
6470 * @widget: a #GtkWidget
6472 * Determines whether @widget can be drawn to. A widget can be drawn
6473 * to if it is mapped and visible.
6475 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6480 gtk_widget_is_drawable (GtkWidget *widget)
6482 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6484 return (gtk_widget_get_visible (widget) &&
6485 gtk_widget_get_mapped (widget));
6489 * gtk_widget_get_realized:
6490 * @widget: a #GtkWidget
6492 * Determines whether @widget is realized.
6494 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6499 gtk_widget_get_realized (GtkWidget *widget)
6501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6503 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6507 * gtk_widget_set_realized:
6508 * @widget: a #GtkWidget
6509 * @realized: %TRUE to mark the widget as realized
6511 * Marks the widget as being realized.
6513 * This function should only ever be called in a derived widget's
6514 * "realize" or "unrealize" implementation.
6519 gtk_widget_set_realized (GtkWidget *widget,
6522 g_return_if_fail (GTK_IS_WIDGET (widget));
6525 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6527 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6531 * gtk_widget_get_mapped:
6532 * @widget: a #GtkWidget
6534 * Whether the widget is mapped.
6536 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6541 gtk_widget_get_mapped (GtkWidget *widget)
6543 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6545 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6549 * gtk_widget_set_mapped:
6550 * @widget: a #GtkWidget
6551 * @mapped: %TRUE to mark the widget as mapped
6553 * Marks the widget as being realized.
6555 * This function should only ever be called in a derived widget's
6556 * "map" or "unmap" implementation.
6561 gtk_widget_set_mapped (GtkWidget *widget,
6564 g_return_if_fail (GTK_IS_WIDGET (widget));
6567 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6569 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6573 * gtk_widget_set_app_paintable:
6574 * @widget: a #GtkWidget
6575 * @app_paintable: %TRUE if the application will paint on the widget
6577 * Sets whether the application intends to draw on the widget in
6578 * an #GtkWidget::expose-event handler.
6580 * This is a hint to the widget and does not affect the behavior of
6581 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6582 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6583 * the effect is to suppress default themed drawing of the widget's
6584 * background. (Children of the widget will still be drawn.) The application
6585 * is then entirely responsible for drawing the widget background.
6587 * Note that the background is still drawn when the widget is mapped.
6590 gtk_widget_set_app_paintable (GtkWidget *widget,
6591 gboolean app_paintable)
6593 g_return_if_fail (GTK_IS_WIDGET (widget));
6595 app_paintable = (app_paintable != FALSE);
6597 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6600 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6602 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6604 if (gtk_widget_is_drawable (widget))
6605 gtk_widget_queue_draw (widget);
6607 g_object_notify (G_OBJECT (widget), "app-paintable");
6612 * gtk_widget_get_app_paintable:
6613 * @widget: a #GtkWidget
6615 * Determines whether the application intends to draw on the widget in
6616 * an #GtkWidget::expose-event handler.
6618 * See gtk_widget_set_app_paintable()
6620 * Return value: %TRUE if the widget is app paintable
6625 gtk_widget_get_app_paintable (GtkWidget *widget)
6627 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6629 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6633 * gtk_widget_set_double_buffered:
6634 * @widget: a #GtkWidget
6635 * @double_buffered: %TRUE to double-buffer a widget
6637 * Widgets are double buffered by default; you can use this function
6638 * to turn off the buffering. "Double buffered" simply means that
6639 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6640 * automatically around expose events sent to the
6641 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6642 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6643 * buffer to the screen. The result is that users see the window
6644 * update in one smooth step, and don't see individual graphics
6645 * primitives being rendered.
6647 * In very simple terms, double buffered widgets don't flicker,
6648 * so you would only use this function to turn off double buffering
6649 * if you had special needs and really knew what you were doing.
6651 * Note: if you turn off double-buffering, you have to handle
6652 * expose events, since even the clearing to the background color or
6653 * pixmap will not happen automatically (as it is done in
6654 * gdk_window_begin_paint()).
6657 gtk_widget_set_double_buffered (GtkWidget *widget,
6658 gboolean double_buffered)
6660 g_return_if_fail (GTK_IS_WIDGET (widget));
6662 double_buffered = (double_buffered != FALSE);
6664 if (double_buffered != gtk_widget_get_double_buffered (widget))
6666 if (double_buffered)
6667 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6669 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6671 g_object_notify (G_OBJECT (widget), "double-buffered");
6676 * gtk_widget_get_double_buffered:
6677 * @widget: a #GtkWidget
6679 * Determines whether the widget is double buffered.
6681 * See gtk_widget_set_double_buffered()
6683 * Return value: %TRUE if the widget is double buffered
6688 gtk_widget_get_double_buffered (GtkWidget *widget)
6690 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6692 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6696 * gtk_widget_set_redraw_on_allocate:
6697 * @widget: a #GtkWidget
6698 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6699 * when it is allocated to a new size. Otherwise, only the
6700 * new portion of the widget will be redrawn.
6702 * Sets whether the entire widget is queued for drawing when its size
6703 * allocation changes. By default, this setting is %TRUE and
6704 * the entire widget is redrawn on every size change. If your widget
6705 * leaves the upper left unchanged when made bigger, turning this
6706 * setting off will improve performance.
6708 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6709 * off all allocation on resizing: the widget will not even redraw if
6710 * its position changes; this is to allow containers that don't draw
6711 * anything to avoid excess invalidations. If you set this flag on a
6712 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6713 * you are responsible for invalidating both the old and new allocation
6714 * of the widget when the widget is moved and responsible for invalidating
6715 * regions newly when the widget increases size.
6718 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6719 gboolean redraw_on_allocate)
6721 g_return_if_fail (GTK_IS_WIDGET (widget));
6723 if (redraw_on_allocate)
6724 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6726 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6730 * gtk_widget_set_sensitive:
6731 * @widget: a #GtkWidget
6732 * @sensitive: %TRUE to make the widget sensitive
6734 * Sets the sensitivity of a widget. A widget is sensitive if the user
6735 * can interact with it. Insensitive widgets are "grayed out" and the
6736 * user can't interact with them. Insensitive widgets are known as
6737 * "inactive", "disabled", or "ghosted" in some other toolkits.
6740 gtk_widget_set_sensitive (GtkWidget *widget,
6743 GtkWidgetPrivate *priv;
6746 g_return_if_fail (GTK_IS_WIDGET (widget));
6748 priv = widget->priv;
6750 sensitive = (sensitive != FALSE);
6752 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6757 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6758 data.state = priv->saved_state;
6762 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6763 data.state = gtk_widget_get_state (widget);
6765 data.state_restoration = TRUE;
6766 data.use_forall = TRUE;
6769 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6771 data.parent_sensitive = TRUE;
6773 gtk_widget_propagate_state (widget, &data);
6774 if (gtk_widget_is_drawable (widget))
6775 gtk_widget_queue_draw (widget);
6777 g_object_notify (G_OBJECT (widget), "sensitive");
6781 * gtk_widget_get_sensitive:
6782 * @widget: a #GtkWidget
6784 * Returns the widget's sensitivity (in the sense of returning
6785 * the value that has been set using gtk_widget_set_sensitive()).
6787 * The effective sensitivity of a widget is however determined by both its
6788 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6790 * Returns: %TRUE if the widget is sensitive
6795 gtk_widget_get_sensitive (GtkWidget *widget)
6797 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6799 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6803 * gtk_widget_is_sensitive:
6804 * @widget: a #GtkWidget
6806 * Returns the widget's effective sensitivity, which means
6807 * it is sensitive itself and also its parent widget is sensntive
6809 * Returns: %TRUE if the widget is effectively sensitive
6814 gtk_widget_is_sensitive (GtkWidget *widget)
6816 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6818 return (gtk_widget_get_sensitive (widget) &&
6819 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6823 * gtk_widget_set_parent:
6824 * @widget: a #GtkWidget
6825 * @parent: parent container
6827 * This function is useful only when implementing subclasses of
6829 * Sets the container as the parent of @widget, and takes care of
6830 * some details such as updating the state and style of the child
6831 * to reflect its new location. The opposite function is
6832 * gtk_widget_unparent().
6835 gtk_widget_set_parent (GtkWidget *widget,
6838 GtkWidgetPrivate *priv;
6841 g_return_if_fail (GTK_IS_WIDGET (widget));
6842 g_return_if_fail (GTK_IS_WIDGET (parent));
6843 g_return_if_fail (widget != parent);
6845 priv = widget->priv;
6847 if (priv->parent != NULL)
6849 g_warning ("Can't set a parent on widget which has a parent\n");
6852 if (gtk_widget_is_toplevel (widget))
6854 g_warning ("Can't set a parent on a toplevel widget\n");
6858 /* keep this function in sync with gtk_menu_attach_to_widget()
6861 g_object_ref_sink (widget);
6862 priv->parent = parent;
6864 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6865 data.state = gtk_widget_get_state (parent);
6867 data.state = gtk_widget_get_state (widget);
6868 data.state_restoration = FALSE;
6869 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6870 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6872 gtk_widget_propagate_state (widget, &data);
6874 gtk_widget_reset_rc_styles (widget);
6876 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6877 if (GTK_WIDGET_ANCHORED (priv->parent))
6878 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6879 g_object_notify (G_OBJECT (widget), "parent");
6881 /* Enforce realized/mapped invariants
6883 if (gtk_widget_get_realized (priv->parent))
6884 gtk_widget_realize (widget);
6886 if (gtk_widget_get_visible (priv->parent) &&
6887 gtk_widget_get_visible (widget))
6889 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6890 gtk_widget_get_mapped (priv->parent))
6891 gtk_widget_map (widget);
6893 gtk_widget_queue_resize (widget);
6898 * gtk_widget_get_parent:
6899 * @widget: a #GtkWidget
6901 * Returns the parent container of @widget.
6903 * Return value: (transfer none): the parent container of @widget, or %NULL
6906 gtk_widget_get_parent (GtkWidget *widget)
6908 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6910 return widget->priv->parent;
6913 /*****************************************
6915 * see docs/styles.txt
6916 *****************************************/
6919 * gtk_widget_style_attach:
6920 * @widget: a #GtkWidget
6922 * This function attaches the widget's #GtkStyle to the widget's
6923 * #GdkWindow. It is a replacement for
6926 * widget->style = gtk_style_attach (widget->style, widget->window);
6929 * and should only ever be called in a derived widget's "realize"
6930 * implementation which does not chain up to its parent class'
6931 * "realize" implementation, because one of the parent classes
6932 * (finally #GtkWidget) would attach the style itself.
6937 gtk_widget_style_attach (GtkWidget *widget)
6939 GtkWidgetPrivate *priv;
6941 g_return_if_fail (GTK_IS_WIDGET (widget));
6942 g_return_if_fail (gtk_widget_get_realized (widget));
6944 priv = widget->priv;
6946 priv->style = gtk_style_attach (priv->style, priv->window);
6950 * gtk_widget_has_rc_style:
6951 * @widget: a #GtkWidget
6953 * Determines if the widget style has been looked up through the rc mechanism.
6955 * Returns: %TRUE if the widget has been looked up through the rc
6956 * mechanism, %FALSE otherwise.
6961 gtk_widget_has_rc_style (GtkWidget *widget)
6963 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6965 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6969 * gtk_widget_set_style:
6970 * @widget: a #GtkWidget
6971 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6972 * gtk_widget_set_style() and go back to the default style
6974 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6975 * want to use this function; it interacts badly with themes, because
6976 * themes work by replacing the #GtkStyle. Instead, use
6977 * gtk_widget_modify_style().
6980 gtk_widget_set_style (GtkWidget *widget,
6983 g_return_if_fail (GTK_IS_WIDGET (widget));
6987 gboolean initial_emission;
6989 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6991 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6992 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6994 gtk_widget_set_style_internal (widget, style, initial_emission);
6998 if (GTK_WIDGET_USER_STYLE (widget))
6999 gtk_widget_reset_rc_style (widget);
7004 * gtk_widget_ensure_style:
7005 * @widget: a #GtkWidget
7007 * Ensures that @widget has a style (@widget->style). Not a very useful
7008 * function; most of the time, if you want the style, the widget is
7009 * realized, and realized widgets are guaranteed to have a style
7013 gtk_widget_ensure_style (GtkWidget *widget)
7015 g_return_if_fail (GTK_IS_WIDGET (widget));
7017 if (!GTK_WIDGET_USER_STYLE (widget) &&
7018 !gtk_widget_has_rc_style (widget))
7019 gtk_widget_reset_rc_style (widget);
7022 /* Look up the RC style for this widget, unsetting any user style that
7023 * may be in effect currently
7026 gtk_widget_reset_rc_style (GtkWidget *widget)
7028 GtkWidgetPrivate *priv = widget->priv;
7029 GtkStyle *new_style = NULL;
7030 gboolean initial_emission;
7032 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7034 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7035 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7037 if (gtk_widget_has_screen (widget))
7038 new_style = gtk_rc_get_style (widget);
7040 new_style = gtk_widget_get_default_style ();
7042 if (initial_emission || new_style != priv->style)
7043 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7047 * gtk_widget_get_style:
7048 * @widget: a #GtkWidget
7050 * Simply an accessor function that returns @widget->style.
7052 * Return value: (transfer none): the widget's #GtkStyle
7055 gtk_widget_get_style (GtkWidget *widget)
7057 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7059 return widget->priv->style;
7063 * gtk_widget_modify_style:
7064 * @widget: a #GtkWidget
7065 * @style: the #GtkRcStyle holding the style modifications
7067 * Modifies style values on the widget. Modifications made using this
7068 * technique take precedence over style values set via an RC file,
7069 * however, they will be overriden if a style is explicitely set on
7070 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7071 * is designed so each field can either be set or unset, so it is
7072 * possible, using this function, to modify some style values and
7073 * leave the others unchanged.
7075 * Note that modifications made with this function are not cumulative
7076 * with previous calls to gtk_widget_modify_style() or with such
7077 * functions as gtk_widget_modify_fg(). If you wish to retain
7078 * previous values, you must first call gtk_widget_get_modifier_style(),
7079 * make your modifications to the returned style, then call
7080 * gtk_widget_modify_style() with that style. On the other hand,
7081 * if you first call gtk_widget_modify_style(), subsequent calls
7082 * to such functions gtk_widget_modify_fg() will have a cumulative
7083 * effect with the initial modifications.
7086 gtk_widget_modify_style (GtkWidget *widget,
7089 g_return_if_fail (GTK_IS_WIDGET (widget));
7090 g_return_if_fail (GTK_IS_RC_STYLE (style));
7092 g_object_set_qdata_full (G_OBJECT (widget),
7094 gtk_rc_style_copy (style),
7095 (GDestroyNotify) g_object_unref);
7097 /* note that "style" may be invalid here if it was the old
7098 * modifier style and the only reference was our own.
7101 if (gtk_widget_has_rc_style (widget))
7102 gtk_widget_reset_rc_style (widget);
7106 * gtk_widget_get_modifier_style:
7107 * @widget: a #GtkWidget
7109 * Returns the current modifier style for the widget. (As set by
7110 * gtk_widget_modify_style().) If no style has previously set, a new
7111 * #GtkRcStyle will be created with all values unset, and set as the
7112 * modifier style for the widget. If you make changes to this rc
7113 * style, you must call gtk_widget_modify_style(), passing in the
7114 * returned rc style, to make sure that your changes take effect.
7116 * Caution: passing the style back to gtk_widget_modify_style() will
7117 * normally end up destroying it, because gtk_widget_modify_style() copies
7118 * the passed-in style and sets the copy as the new modifier style,
7119 * thus dropping any reference to the old modifier style. Add a reference
7120 * to the modifier style if you want to keep it alive.
7122 * Return value: (transfer none): the modifier style for the widget. This rc style is
7123 * owned by the widget. If you want to keep a pointer to value this
7124 * around, you must add a refcount using g_object_ref().
7127 gtk_widget_get_modifier_style (GtkWidget *widget)
7129 GtkRcStyle *rc_style;
7131 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7133 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7137 rc_style = gtk_rc_style_new ();
7138 g_object_set_qdata_full (G_OBJECT (widget),
7141 (GDestroyNotify) g_object_unref);
7148 gtk_widget_modify_color_component (GtkWidget *widget,
7149 GtkRcFlags component,
7151 const GdkColor *color)
7153 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7160 rc_style->fg[state] = *color;
7163 rc_style->bg[state] = *color;
7166 rc_style->text[state] = *color;
7169 rc_style->base[state] = *color;
7172 g_assert_not_reached();
7175 rc_style->color_flags[state] |= component;
7178 rc_style->color_flags[state] &= ~component;
7180 gtk_widget_modify_style (widget, rc_style);
7184 * gtk_widget_modify_symbolic_color:
7185 * @widget: a #GtkWidget
7186 * @name: the name of the symbolic color to modify
7187 * @color: (allow-none): the color to assign (does not need to be allocated),
7188 * or %NULL to undo the effect of previous calls to
7189 * of gtk_widget_modify_symbolic_color().
7191 * Sets a symbolic color for a widget.
7192 * All other style values are left untouched. See also
7193 * gtk_widget_modify_style().
7198 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7200 const GdkColor *color)
7202 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7204 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7206 gtk_widget_modify_style (widget, rc_style);
7210 * gtk_widget_modify_fg:
7211 * @widget: a #GtkWidget
7212 * @state: the state for which to set the foreground color
7213 * @color: (allow-none): the color to assign (does not need to be allocated),
7214 * or %NULL to undo the effect of previous calls to
7215 * of gtk_widget_modify_fg().
7217 * Sets the foreground color for a widget in a particular state.
7218 * All other style values are left untouched. See also
7219 * gtk_widget_modify_style().
7222 gtk_widget_modify_fg (GtkWidget *widget,
7224 const GdkColor *color)
7226 g_return_if_fail (GTK_IS_WIDGET (widget));
7227 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7229 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7233 * gtk_widget_modify_bg:
7234 * @widget: a #GtkWidget
7235 * @state: the state for which to set the background color
7236 * @color: (allow-none): the color to assign (does not need to be allocated),
7237 * or %NULL to undo the effect of previous calls to
7238 * of gtk_widget_modify_bg().
7240 * Sets the background color for a widget in a particular state.
7241 * All other style values are left untouched. See also
7242 * gtk_widget_modify_style().
7244 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7245 * draw on their parent container's window and thus may not draw any
7246 * background themselves. This is the case for e.g. #GtkLabel. To modify
7247 * the background of such widgets, you have to set the background color
7248 * on their parent; if you want to set the background of a rectangular
7249 * area around a label, try placing the label in a #GtkEventBox widget
7250 * and setting the background color on that.
7253 gtk_widget_modify_bg (GtkWidget *widget,
7255 const GdkColor *color)
7257 g_return_if_fail (GTK_IS_WIDGET (widget));
7258 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7260 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7264 * gtk_widget_modify_text:
7265 * @widget: a #GtkWidget
7266 * @state: the state for which to set the text color
7267 * @color: (allow-none): the color to assign (does not need to be allocated),
7268 * or %NULL to undo the effect of previous calls to
7269 * of gtk_widget_modify_text().
7271 * Sets the text color for a widget in a particular state. All other
7272 * style values are left untouched. The text color is the foreground
7273 * color used along with the base color (see gtk_widget_modify_base())
7274 * for widgets such as #GtkEntry and #GtkTextView. See also
7275 * gtk_widget_modify_style().
7278 gtk_widget_modify_text (GtkWidget *widget,
7280 const GdkColor *color)
7282 g_return_if_fail (GTK_IS_WIDGET (widget));
7283 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7285 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7289 * gtk_widget_modify_base:
7290 * @widget: a #GtkWidget
7291 * @state: the state for which to set the base color
7292 * @color: (allow-none): the color to assign (does not need to be allocated),
7293 * or %NULL to undo the effect of previous calls to
7294 * of gtk_widget_modify_base().
7296 * Sets the base color for a widget in a particular state.
7297 * All other style values are left untouched. The base color
7298 * is the background color used along with the text color
7299 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7300 * and #GtkTextView. See also gtk_widget_modify_style().
7302 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7303 * draw on their parent container's window and thus may not draw any
7304 * background themselves. This is the case for e.g. #GtkLabel. To modify
7305 * the background of such widgets, you have to set the base color on their
7306 * parent; if you want to set the background of a rectangular area around
7307 * a label, try placing the label in a #GtkEventBox widget and setting
7308 * the base color on that.
7311 gtk_widget_modify_base (GtkWidget *widget,
7313 const GdkColor *color)
7315 g_return_if_fail (GTK_IS_WIDGET (widget));
7316 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7318 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7322 modify_color_property (GtkWidget *widget,
7323 GtkRcStyle *rc_style,
7325 const GdkColor *color)
7327 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7328 GQuark property_name = g_quark_from_string (name);
7332 GtkRcProperty rc_property = {0};
7335 rc_property.type_name = type_name;
7336 rc_property.property_name = property_name;
7337 rc_property.origin = NULL;
7339 color_name = gdk_color_to_string (color);
7340 g_value_init (&rc_property.value, G_TYPE_STRING);
7341 g_value_take_string (&rc_property.value, color_name);
7343 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7345 g_value_unset (&rc_property.value);
7348 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7352 * gtk_widget_modify_cursor:
7353 * @widget: a #GtkWidget
7354 * @primary: the color to use for primary cursor (does not need to be
7355 * allocated), or %NULL to undo the effect of previous calls to
7356 * of gtk_widget_modify_cursor().
7357 * @secondary: the color to use for secondary cursor (does not need to be
7358 * allocated), or %NULL to undo the effect of previous calls to
7359 * of gtk_widget_modify_cursor().
7361 * Sets the cursor color to use in a widget, overriding the
7362 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7363 * style properties. All other style values are left untouched.
7364 * See also gtk_widget_modify_style().
7369 gtk_widget_modify_cursor (GtkWidget *widget,
7370 const GdkColor *primary,
7371 const GdkColor *secondary)
7373 GtkRcStyle *rc_style;
7375 g_return_if_fail (GTK_IS_WIDGET (widget));
7377 rc_style = gtk_widget_get_modifier_style (widget);
7379 modify_color_property (widget, rc_style, "cursor-color", primary);
7380 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7382 gtk_widget_modify_style (widget, rc_style);
7386 * gtk_widget_modify_font:
7387 * @widget: a #GtkWidget
7388 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7389 * the effect of previous calls to gtk_widget_modify_font().
7391 * Sets the font to use for a widget. All other style values are left
7392 * untouched. See also gtk_widget_modify_style().
7395 gtk_widget_modify_font (GtkWidget *widget,
7396 PangoFontDescription *font_desc)
7398 GtkRcStyle *rc_style;
7400 g_return_if_fail (GTK_IS_WIDGET (widget));
7402 rc_style = gtk_widget_get_modifier_style (widget);
7404 if (rc_style->font_desc)
7405 pango_font_description_free (rc_style->font_desc);
7408 rc_style->font_desc = pango_font_description_copy (font_desc);
7410 rc_style->font_desc = NULL;
7412 gtk_widget_modify_style (widget, rc_style);
7416 gtk_widget_real_direction_changed (GtkWidget *widget,
7417 GtkTextDirection previous_direction)
7419 gtk_widget_queue_resize (widget);
7423 gtk_widget_real_style_set (GtkWidget *widget,
7424 GtkStyle *previous_style)
7426 GtkWidgetPrivate *priv = widget->priv;
7428 if (gtk_widget_get_realized (widget) &&
7429 gtk_widget_get_has_window (widget))
7430 gtk_style_set_background (priv->style, priv->window, priv->state);
7434 gtk_widget_set_style_internal (GtkWidget *widget,
7436 gboolean initial_emission)
7438 GtkWidgetPrivate *priv = widget->priv;
7440 g_object_ref (widget);
7441 g_object_freeze_notify (G_OBJECT (widget));
7443 if (priv->style != style)
7445 GtkStyle *previous_style;
7447 if (gtk_widget_get_realized (widget))
7449 gtk_widget_reset_shapes (widget);
7450 gtk_style_detach (priv->style);
7453 previous_style = priv->style;
7454 priv->style = style;
7455 g_object_ref (priv->style);
7457 if (gtk_widget_get_realized (widget))
7458 priv->style = gtk_style_attach (priv->style, priv->window);
7460 gtk_widget_update_pango_context (widget);
7461 g_signal_emit (widget,
7462 widget_signals[STYLE_SET],
7464 initial_emission ? NULL : previous_style);
7465 g_object_unref (previous_style);
7467 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7468 gtk_widget_queue_resize (widget);
7470 else if (initial_emission)
7472 gtk_widget_update_pango_context (widget);
7473 g_signal_emit (widget,
7474 widget_signals[STYLE_SET],
7478 g_object_notify (G_OBJECT (widget), "style");
7479 g_object_thaw_notify (G_OBJECT (widget));
7480 g_object_unref (widget);
7484 GtkWidget *previous_toplevel;
7485 GdkScreen *previous_screen;
7486 GdkScreen *new_screen;
7487 } HierarchyChangedInfo;
7490 do_screen_change (GtkWidget *widget,
7491 GdkScreen *old_screen,
7492 GdkScreen *new_screen)
7494 if (old_screen != new_screen)
7498 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7500 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7503 _gtk_tooltip_hide (widget);
7504 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7509 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7510 gpointer client_data)
7512 GtkWidgetPrivate *priv = widget->priv;
7513 HierarchyChangedInfo *info = client_data;
7514 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7515 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7517 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7519 g_object_ref (widget);
7522 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7524 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7526 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7527 do_screen_change (widget, info->previous_screen, info->new_screen);
7529 if (GTK_IS_CONTAINER (widget))
7530 gtk_container_forall (GTK_CONTAINER (widget),
7531 gtk_widget_propagate_hierarchy_changed_recurse,
7534 g_object_unref (widget);
7539 * _gtk_widget_propagate_hierarchy_changed:
7540 * @widget: a #GtkWidget
7541 * @previous_toplevel: Previous toplevel
7543 * Propagates changes in the anchored state to a widget and all
7544 * children, unsetting or setting the %ANCHORED flag, and
7545 * emitting #GtkWidget::hierarchy-changed.
7548 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7549 GtkWidget *previous_toplevel)
7551 GtkWidgetPrivate *priv = widget->priv;
7552 HierarchyChangedInfo info;
7554 info.previous_toplevel = previous_toplevel;
7555 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7557 if (gtk_widget_is_toplevel (widget) ||
7558 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7559 info.new_screen = gtk_widget_get_screen (widget);
7561 info.new_screen = NULL;
7563 if (info.previous_screen)
7564 g_object_ref (info.previous_screen);
7565 if (previous_toplevel)
7566 g_object_ref (previous_toplevel);
7568 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7570 if (previous_toplevel)
7571 g_object_unref (previous_toplevel);
7572 if (info.previous_screen)
7573 g_object_unref (info.previous_screen);
7577 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7578 gpointer client_data)
7580 HierarchyChangedInfo *info = client_data;
7582 g_object_ref (widget);
7584 do_screen_change (widget, info->previous_screen, info->new_screen);
7586 if (GTK_IS_CONTAINER (widget))
7587 gtk_container_forall (GTK_CONTAINER (widget),
7588 gtk_widget_propagate_screen_changed_recurse,
7591 g_object_unref (widget);
7595 * gtk_widget_is_composited:
7596 * @widget: a #GtkWidget
7598 * Whether @widget can rely on having its alpha channel
7599 * drawn correctly. On X11 this function returns whether a
7600 * compositing manager is running for @widget's screen.
7602 * Please note that the semantics of this call will change
7603 * in the future if used on a widget that has a composited
7604 * window in its hierarchy (as set by gdk_window_set_composited()).
7606 * Return value: %TRUE if the widget can rely on its alpha
7607 * channel being drawn correctly.
7612 gtk_widget_is_composited (GtkWidget *widget)
7616 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7618 screen = gtk_widget_get_screen (widget);
7620 return gdk_screen_is_composited (screen);
7624 propagate_composited_changed (GtkWidget *widget,
7627 if (GTK_IS_CONTAINER (widget))
7629 gtk_container_forall (GTK_CONTAINER (widget),
7630 propagate_composited_changed,
7634 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7638 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7640 propagate_composited_changed (widget, NULL);
7644 * _gtk_widget_propagate_screen_changed:
7645 * @widget: a #GtkWidget
7646 * @previous_screen: Previous screen
7648 * Propagates changes in the screen for a widget to all
7649 * children, emitting #GtkWidget::screen-changed.
7652 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7653 GdkScreen *previous_screen)
7655 HierarchyChangedInfo info;
7657 info.previous_screen = previous_screen;
7658 info.new_screen = gtk_widget_get_screen (widget);
7660 if (previous_screen)
7661 g_object_ref (previous_screen);
7663 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7665 if (previous_screen)
7666 g_object_unref (previous_screen);
7670 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7672 if (gtk_widget_has_rc_style (widget))
7673 gtk_widget_reset_rc_style (widget);
7675 if (GTK_IS_CONTAINER (widget))
7676 gtk_container_forall (GTK_CONTAINER (widget),
7677 reset_rc_styles_recurse,
7683 * gtk_widget_reset_rc_styles:
7684 * @widget: a #GtkWidget.
7686 * Reset the styles of @widget and all descendents, so when
7687 * they are looked up again, they get the correct values
7688 * for the currently loaded RC file settings.
7690 * This function is not useful for applications.
7693 gtk_widget_reset_rc_styles (GtkWidget *widget)
7695 g_return_if_fail (GTK_IS_WIDGET (widget));
7697 reset_rc_styles_recurse (widget, NULL);
7701 * gtk_widget_get_default_style:
7703 * Returns the default style used by all widgets initially.
7705 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7706 * by GTK+ and should not be modified or freed.
7709 gtk_widget_get_default_style (void)
7711 if (!gtk_default_style)
7713 gtk_default_style = gtk_style_new ();
7714 g_object_ref (gtk_default_style);
7717 return gtk_default_style;
7720 static PangoContext *
7721 gtk_widget_peek_pango_context (GtkWidget *widget)
7723 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7727 * gtk_widget_get_pango_context:
7728 * @widget: a #GtkWidget
7730 * Gets a #PangoContext with the appropriate font map, font description,
7731 * and base direction for this widget. Unlike the context returned
7732 * by gtk_widget_create_pango_context(), this context is owned by
7733 * the widget (it can be used until the screen for the widget changes
7734 * or the widget is removed from its toplevel), and will be updated to
7735 * match any changes to the widget's attributes.
7737 * If you create and keep a #PangoLayout using this context, you must
7738 * deal with changes to the context by calling pango_layout_context_changed()
7739 * on the layout in response to the #GtkWidget::style-set and
7740 * #GtkWidget::direction-changed signals for the widget.
7742 * Return value: (transfer none): the #PangoContext for the widget.
7745 gtk_widget_get_pango_context (GtkWidget *widget)
7747 PangoContext *context;
7749 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7751 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7754 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7755 g_object_set_qdata_full (G_OBJECT (widget),
7756 quark_pango_context,
7765 update_pango_context (GtkWidget *widget,
7766 PangoContext *context)
7768 GtkWidgetPrivate *priv = widget->priv;
7770 pango_context_set_font_description (context, priv->style->font_desc);
7771 pango_context_set_base_dir (context,
7772 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7773 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7777 gtk_widget_update_pango_context (GtkWidget *widget)
7779 PangoContext *context = gtk_widget_peek_pango_context (widget);
7785 update_pango_context (widget, context);
7787 screen = gtk_widget_get_screen_unchecked (widget);
7790 pango_cairo_context_set_resolution (context,
7791 gdk_screen_get_resolution (screen));
7792 pango_cairo_context_set_font_options (context,
7793 gdk_screen_get_font_options (screen));
7799 * gtk_widget_create_pango_context:
7800 * @widget: a #GtkWidget
7802 * Creates a new #PangoContext with the appropriate font map,
7803 * font description, and base direction for drawing text for
7804 * this widget. See also gtk_widget_get_pango_context().
7806 * Return value: (transfer full): the new #PangoContext
7809 gtk_widget_create_pango_context (GtkWidget *widget)
7812 PangoContext *context;
7814 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7816 screen = gtk_widget_get_screen_unchecked (widget);
7819 GTK_NOTE (MULTIHEAD,
7820 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7822 screen = gdk_screen_get_default ();
7825 context = gdk_pango_context_get_for_screen (screen);
7827 update_pango_context (widget, context);
7828 pango_context_set_language (context, gtk_get_default_language ());
7834 * gtk_widget_create_pango_layout:
7835 * @widget: a #GtkWidget
7836 * @text: text to set on the layout (can be %NULL)
7838 * Creates a new #PangoLayout with the appropriate font map,
7839 * font description, and base direction for drawing text for
7842 * If you keep a #PangoLayout created in this way around, in order to
7843 * notify the layout of changes to the base direction or font of this
7844 * widget, you must call pango_layout_context_changed() in response to
7845 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7848 * Return value: (transfer full): the new #PangoLayout
7851 gtk_widget_create_pango_layout (GtkWidget *widget,
7854 PangoLayout *layout;
7855 PangoContext *context;
7857 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7859 context = gtk_widget_get_pango_context (widget);
7860 layout = pango_layout_new (context);
7863 pango_layout_set_text (layout, text, -1);
7869 * gtk_widget_render_icon:
7870 * @widget: a #GtkWidget
7871 * @stock_id: a stock ID
7872 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7873 * render at the size of the source and don't scale (if there are
7874 * multiple source sizes, GTK+ picks one of the available sizes).
7875 * @detail: (allow-none): render detail to pass to theme engine
7877 * A convenience function that uses the theme engine and RC file
7878 * settings for @widget to look up @stock_id and render it to
7879 * a pixbuf. @stock_id should be a stock icon ID such as
7880 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7881 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7882 * identifies the widget or code doing the rendering, so that
7883 * theme engines can special-case rendering for that widget or code.
7885 * The pixels in the returned #GdkPixbuf are shared with the rest of
7886 * the application and should not be modified. The pixbuf should be freed
7887 * after use with g_object_unref().
7889 * Return value: (transfer full): a new pixbuf, or %NULL if the
7890 * stock ID wasn't known
7893 gtk_widget_render_icon (GtkWidget *widget,
7894 const gchar *stock_id,
7896 const gchar *detail)
7898 GtkWidgetPrivate *priv;
7899 GtkIconSet *icon_set;
7902 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7903 g_return_val_if_fail (stock_id != NULL, NULL);
7904 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7906 priv = widget->priv;
7908 gtk_widget_ensure_style (widget);
7910 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7912 if (icon_set == NULL)
7915 retval = gtk_icon_set_render_icon (icon_set,
7917 gtk_widget_get_direction (widget),
7918 gtk_widget_get_state (widget),
7927 * gtk_widget_set_parent_window:
7928 * @widget: a #GtkWidget.
7929 * @parent_window: the new parent window.
7931 * Sets a non default parent window for @widget.
7934 gtk_widget_set_parent_window (GtkWidget *widget,
7935 GdkWindow *parent_window)
7937 GdkWindow *old_parent_window;
7939 g_return_if_fail (GTK_IS_WIDGET (widget));
7941 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7942 quark_parent_window);
7944 if (parent_window != old_parent_window)
7946 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7948 if (old_parent_window)
7949 g_object_unref (old_parent_window);
7951 g_object_ref (parent_window);
7956 * gtk_widget_get_parent_window:
7957 * @widget: a #GtkWidget.
7959 * Gets @widget's parent window.
7961 * Returns: (transfer none): the parent window of @widget.
7964 gtk_widget_get_parent_window (GtkWidget *widget)
7966 GtkWidgetPrivate *priv;
7967 GdkWindow *parent_window;
7969 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7971 priv = widget->priv;
7973 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7975 return (parent_window != NULL) ? parent_window :
7976 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
7981 * gtk_widget_set_child_visible:
7982 * @widget: a #GtkWidget
7983 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7985 * Sets whether @widget should be mapped along with its when its parent
7986 * is mapped and @widget has been shown with gtk_widget_show().
7988 * The child visibility can be set for widget before it is added to
7989 * a container with gtk_widget_set_parent(), to avoid mapping
7990 * children unnecessary before immediately unmapping them. However
7991 * it will be reset to its default state of %TRUE when the widget
7992 * is removed from a container.
7994 * Note that changing the child visibility of a widget does not
7995 * queue a resize on the widget. Most of the time, the size of
7996 * a widget is computed from all visible children, whether or
7997 * not they are mapped. If this is not the case, the container
7998 * can queue a resize itself.
8000 * This function is only useful for container implementations and
8001 * never should be called by an application.
8004 gtk_widget_set_child_visible (GtkWidget *widget,
8005 gboolean is_visible)
8007 GtkWidgetPrivate *priv;
8009 g_return_if_fail (GTK_IS_WIDGET (widget));
8010 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8012 priv = widget->priv;
8014 g_object_ref (widget);
8017 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8020 GtkWidget *toplevel;
8022 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8024 toplevel = gtk_widget_get_toplevel (widget);
8025 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8026 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8029 if (priv->parent && gtk_widget_get_realized (priv->parent))
8031 if (gtk_widget_get_mapped (priv->parent) &&
8032 GTK_WIDGET_CHILD_VISIBLE (widget) &&
8033 gtk_widget_get_visible (widget))
8034 gtk_widget_map (widget);
8036 gtk_widget_unmap (widget);
8039 g_object_unref (widget);
8043 * gtk_widget_get_child_visible:
8044 * @widget: a #GtkWidget
8046 * Gets the value set with gtk_widget_set_child_visible().
8047 * If you feel a need to use this function, your code probably
8048 * needs reorganization.
8050 * This function is only useful for container implementations and
8051 * never should be called by an application.
8053 * Return value: %TRUE if the widget is mapped with the parent.
8056 gtk_widget_get_child_visible (GtkWidget *widget)
8058 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8060 return GTK_WIDGET_CHILD_VISIBLE (widget);
8064 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8066 GtkWidget *toplevel;
8068 toplevel = gtk_widget_get_toplevel (widget);
8070 if (gtk_widget_is_toplevel (toplevel))
8072 if (GTK_IS_WINDOW (toplevel))
8073 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8074 else if (GTK_IS_INVISIBLE (toplevel))
8075 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8082 * gtk_widget_get_screen:
8083 * @widget: a #GtkWidget
8085 * Get the #GdkScreen from the toplevel window associated with
8086 * this widget. This function can only be called after the widget
8087 * has been added to a widget hierarchy with a #GtkWindow
8090 * In general, you should only create screen specific
8091 * resources when a widget has been realized, and you should
8092 * free those resources when the widget is unrealized.
8094 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8099 gtk_widget_get_screen (GtkWidget *widget)
8103 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8105 screen = gtk_widget_get_screen_unchecked (widget);
8112 g_warning (G_STRLOC ": Can't get associated screen"
8113 " for a widget unless it is inside a toplevel GtkWindow\n"
8114 " widget type is %s associated top level type is %s",
8115 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8116 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8118 return gdk_screen_get_default ();
8123 * gtk_widget_has_screen:
8124 * @widget: a #GtkWidget
8126 * Checks whether there is a #GdkScreen is associated with
8127 * this widget. All toplevel widgets have an associated
8128 * screen, and all widgets added into a hierarchy with a toplevel
8129 * window at the top.
8131 * Return value: %TRUE if there is a #GdkScreen associcated
8137 gtk_widget_has_screen (GtkWidget *widget)
8139 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8141 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8145 * gtk_widget_get_display:
8146 * @widget: a #GtkWidget
8148 * Get the #GdkDisplay for the toplevel window associated with
8149 * this widget. This function can only be called after the widget
8150 * has been added to a widget hierarchy with a #GtkWindow at the top.
8152 * In general, you should only create display specific
8153 * resources when a widget has been realized, and you should
8154 * free those resources when the widget is unrealized.
8156 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8161 gtk_widget_get_display (GtkWidget *widget)
8163 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8165 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8169 * gtk_widget_get_root_window:
8170 * @widget: a #GtkWidget
8172 * Get the root window where this widget is located. This function can
8173 * only be called after the widget has been added to a widget
8174 * hierarchy with #GtkWindow at the top.
8176 * The root window is useful for such purposes as creating a popup
8177 * #GdkWindow associated with the window. In general, you should only
8178 * create display specific resources when a widget has been realized,
8179 * and you should free those resources when the widget is unrealized.
8181 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8186 gtk_widget_get_root_window (GtkWidget *widget)
8188 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8190 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8194 * gtk_widget_child_focus:
8195 * @widget: a #GtkWidget
8196 * @direction: direction of focus movement
8198 * This function is used by custom widget implementations; if you're
8199 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8200 * to a particular widget, and gtk_container_set_focus_chain() to
8201 * change the focus tab order. So you may want to investigate those
8202 * functions instead.
8204 * gtk_widget_child_focus() is called by containers as the user moves
8205 * around the window using keyboard shortcuts. @direction indicates
8206 * what kind of motion is taking place (up, down, left, right, tab
8207 * forward, tab backward). gtk_widget_child_focus() emits the
8208 * #GtkWidget::focus signal; widgets override the default handler
8209 * for this signal in order to implement appropriate focus behavior.
8211 * The default ::focus handler for a widget should return %TRUE if
8212 * moving in @direction left the focus on a focusable location inside
8213 * that widget, and %FALSE if moving in @direction moved the focus
8214 * outside the widget. If returning %TRUE, widgets normally
8215 * call gtk_widget_grab_focus() to place the focus accordingly;
8216 * if returning %FALSE, they don't modify the current focus location.
8218 * Return value: %TRUE if focus ended up inside @widget
8221 gtk_widget_child_focus (GtkWidget *widget,
8222 GtkDirectionType direction)
8224 gboolean return_val;
8226 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8228 if (!gtk_widget_get_visible (widget) ||
8229 !gtk_widget_is_sensitive (widget))
8232 /* child widgets must set CAN_FOCUS, containers
8233 * don't have to though.
8235 if (!GTK_IS_CONTAINER (widget) &&
8236 !gtk_widget_get_can_focus (widget))
8239 g_signal_emit (widget,
8240 widget_signals[FOCUS],
8242 direction, &return_val);
8248 * gtk_widget_keynav_failed:
8249 * @widget: a #GtkWidget
8250 * @direction: direction of focus movement
8252 * This function should be called whenever keyboard navigation within
8253 * a single widget hits a boundary. The function emits the
8254 * #GtkWidget::keynav-failed signal on the widget and its return
8255 * value should be interpreted in a way similar to the return value of
8256 * gtk_widget_child_focus():
8258 * When %TRUE is returned, stay in the widget, the failed keyboard
8259 * navigation is Ok and/or there is nowhere we can/should move the
8262 * When %FALSE is returned, the caller should continue with keyboard
8263 * navigation outside the widget, e.g. by calling
8264 * gtk_widget_child_focus() on the widget's toplevel.
8266 * The default ::keynav-failed handler returns %TRUE for
8267 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8268 * values of #GtkDirectionType, it looks at the
8269 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8270 * if the setting is %TRUE. This way the entire user interface
8271 * becomes cursor-navigatable on input devices such as mobile phones
8272 * which only have cursor keys but no tab key.
8274 * Whenever the default handler returns %TRUE, it also calls
8275 * gtk_widget_error_bell() to notify the user of the failed keyboard
8278 * A use case for providing an own implementation of ::keynav-failed
8279 * (either by connecting to it or by overriding it) would be a row of
8280 * #GtkEntry widgets where the user should be able to navigate the
8281 * entire row with the cursor keys, as e.g. known from user interfaces
8282 * that require entering license keys.
8284 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8285 * if the emitting widget should try to handle the keyboard
8286 * navigation attempt in its parent container(s).
8291 gtk_widget_keynav_failed (GtkWidget *widget,
8292 GtkDirectionType direction)
8294 gboolean return_val;
8296 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8298 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8299 direction, &return_val);
8305 * gtk_widget_error_bell:
8306 * @widget: a #GtkWidget
8308 * Notifies the user about an input-related error on this widget.
8309 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8310 * gdk_window_beep(), otherwise it does nothing.
8312 * Note that the effect of gdk_window_beep() can be configured in many
8313 * ways, depending on the windowing backend and the desktop environment
8314 * or window manager that is used.
8319 gtk_widget_error_bell (GtkWidget *widget)
8321 GtkWidgetPrivate *priv;
8322 GtkSettings* settings;
8325 g_return_if_fail (GTK_IS_WIDGET (widget));
8327 priv = widget->priv;
8329 settings = gtk_widget_get_settings (widget);
8333 g_object_get (settings,
8334 "gtk-error-bell", &beep,
8337 if (beep && priv->window)
8338 gdk_window_beep (priv->window);
8342 gtk_widget_set_usize_internal (GtkWidget *widget,
8346 GtkWidgetAuxInfo *aux_info;
8347 gboolean changed = FALSE;
8349 g_object_freeze_notify (G_OBJECT (widget));
8351 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8353 if (width > -2 && aux_info->width != width)
8355 g_object_notify (G_OBJECT (widget), "width-request");
8356 aux_info->width = width;
8359 if (height > -2 && aux_info->height != height)
8361 g_object_notify (G_OBJECT (widget), "height-request");
8362 aux_info->height = height;
8366 if (gtk_widget_get_visible (widget) && changed)
8367 gtk_widget_queue_resize (widget);
8369 g_object_thaw_notify (G_OBJECT (widget));
8373 * gtk_widget_set_size_request:
8374 * @widget: a #GtkWidget
8375 * @width: width @widget should request, or -1 to unset
8376 * @height: height @widget should request, or -1 to unset
8378 * Sets the minimum size of a widget; that is, the widget's size
8379 * request will be @width by @height. You can use this function to
8380 * force a widget to be either larger or smaller than it normally
8383 * In most cases, gtk_window_set_default_size() is a better choice for
8384 * toplevel windows than this function; setting the default size will
8385 * still allow users to shrink the window. Setting the size request
8386 * will force them to leave the window at least as large as the size
8387 * request. When dealing with window sizes,
8388 * gtk_window_set_geometry_hints() can be a useful function as well.
8390 * Note the inherent danger of setting any fixed size - themes,
8391 * translations into other languages, different fonts, and user action
8392 * can all change the appropriate size for a given widget. So, it's
8393 * basically impossible to hardcode a size that will always be
8396 * The size request of a widget is the smallest size a widget can
8397 * accept while still functioning well and drawing itself correctly.
8398 * However in some strange cases a widget may be allocated less than
8399 * its requested size, and in many cases a widget may be allocated more
8400 * space than it requested.
8402 * If the size request in a given direction is -1 (unset), then
8403 * the "natural" size request of the widget will be used instead.
8405 * Widgets can't actually be allocated a size less than 1 by 1, but
8406 * you can pass 0,0 to this function to mean "as small as possible."
8408 * The size request set here does not include any margin from the
8409 * #GtkWidget properties margin-left, margin-right, margin-top, and
8410 * margin-bottom, but it does include pretty much all other padding
8411 * or border properties set by any subclass of #GtkWidget.
8414 gtk_widget_set_size_request (GtkWidget *widget,
8418 g_return_if_fail (GTK_IS_WIDGET (widget));
8419 g_return_if_fail (width >= -1);
8420 g_return_if_fail (height >= -1);
8427 gtk_widget_set_usize_internal (widget, width, height);
8432 * gtk_widget_get_size_request:
8433 * @widget: a #GtkWidget
8434 * @width: (out) (allow-none): return location for width, or %NULL
8435 * @height: (out) (allow-none): return location for height, or %NULL
8437 * Gets the size request that was explicitly set for the widget using
8438 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8439 * @height indicates that that dimension has not been set explicitly
8440 * and the natural requisition of the widget will be used intead. See
8441 * gtk_widget_set_size_request(). To get the size a widget will
8442 * actually request, call gtk_size_request_get_size() instead of
8446 gtk_widget_get_size_request (GtkWidget *widget,
8450 const GtkWidgetAuxInfo *aux_info;
8452 g_return_if_fail (GTK_IS_WIDGET (widget));
8454 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8457 *width = aux_info->width;
8460 *height = aux_info->height;
8464 * gtk_widget_set_events:
8465 * @widget: a #GtkWidget
8466 * @events: event mask
8468 * Sets the event mask (see #GdkEventMask) for a widget. The event
8469 * mask determines which events a widget will receive. Keep in mind
8470 * that different widgets have different default event masks, and by
8471 * changing the event mask you may disrupt a widget's functionality,
8472 * so be careful. This function must be called while a widget is
8473 * unrealized. Consider gtk_widget_add_events() for widgets that are
8474 * already realized, or if you want to preserve the existing event
8475 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8476 * to get events on those widgets, place them inside a #GtkEventBox
8477 * and receive events on the event box.
8480 gtk_widget_set_events (GtkWidget *widget,
8483 g_return_if_fail (GTK_IS_WIDGET (widget));
8484 g_return_if_fail (!gtk_widget_get_realized (widget));
8486 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8487 GINT_TO_POINTER (events));
8488 g_object_notify (G_OBJECT (widget), "events");
8492 * gtk_widget_set_device_events:
8493 * @widget: a #GtkWidget
8494 * @device: a #GdkDevice
8495 * @events: event mask
8497 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8498 * mask determines which events a widget will receive from @device. Keep
8499 * in mind that different widgets have different default event masks, and by
8500 * changing the event mask you may disrupt a widget's functionality,
8501 * so be careful. This function must be called while a widget is
8502 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8503 * already realized, or if you want to preserve the existing event
8504 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8505 * to get events on those widgets, place them inside a #GtkEventBox
8506 * and receive events on the event box.
8511 gtk_widget_set_device_events (GtkWidget *widget,
8513 GdkEventMask events)
8515 GHashTable *device_events;
8517 g_return_if_fail (GTK_IS_WIDGET (widget));
8518 g_return_if_fail (GDK_IS_DEVICE (device));
8519 g_return_if_fail (!gtk_widget_get_realized (widget));
8521 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8523 if (G_UNLIKELY (!device_events))
8525 device_events = g_hash_table_new (NULL, NULL);
8526 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8527 (GDestroyNotify) g_hash_table_unref);
8530 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8534 gtk_widget_add_events_internal_list (GtkWidget *widget,
8541 for (l = window_list; l != NULL; l = l->next)
8543 GdkWindow *window = l->data;
8546 gdk_window_get_user_data (window, &user_data);
8547 if (user_data == widget)
8552 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8554 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8556 children = gdk_window_get_children (window);
8557 gtk_widget_add_events_internal_list (widget, device, events, children);
8558 g_list_free (children);
8564 gtk_widget_add_events_internal (GtkWidget *widget,
8568 GtkWidgetPrivate *priv = widget->priv;
8571 if (!gtk_widget_get_has_window (widget))
8572 window_list = gdk_window_get_children (priv->window);
8574 window_list = g_list_prepend (NULL, priv->window);
8576 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8578 g_list_free (window_list);
8582 * gtk_widget_add_events:
8583 * @widget: a #GtkWidget
8584 * @events: an event mask, see #GdkEventMask
8586 * Adds the events in the bitfield @events to the event mask for
8587 * @widget. See gtk_widget_set_events() for details.
8590 gtk_widget_add_events (GtkWidget *widget,
8595 g_return_if_fail (GTK_IS_WIDGET (widget));
8597 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8598 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8599 GINT_TO_POINTER (old_events | events));
8601 if (gtk_widget_get_realized (widget))
8602 gtk_widget_add_events_internal (widget, NULL, events);
8604 g_object_notify (G_OBJECT (widget), "events");
8608 * gtk_widget_add_device_events:
8609 * @widget: a #GtkWidget
8610 * @device: a #GdkDevice
8611 * @events: an event mask, see #GdkEventMask
8613 * Adds the device events in the bitfield @events to the event mask for
8614 * @widget. See gtk_widget_set_device_events() for details.
8619 gtk_widget_add_device_events (GtkWidget *widget,
8621 GdkEventMask events)
8623 GdkEventMask old_events;
8624 GHashTable *device_events;
8626 g_return_if_fail (GTK_IS_WIDGET (widget));
8627 g_return_if_fail (GDK_IS_DEVICE (device));
8629 old_events = gtk_widget_get_device_events (widget, device);
8631 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8633 if (G_UNLIKELY (!device_events))
8635 device_events = g_hash_table_new (NULL, NULL);
8636 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8637 (GDestroyNotify) g_hash_table_unref);
8640 g_hash_table_insert (device_events, device,
8641 GUINT_TO_POINTER (old_events | events));
8643 if (gtk_widget_get_realized (widget))
8644 gtk_widget_add_events_internal (widget, device, events);
8646 g_object_notify (G_OBJECT (widget), "events");
8650 * gtk_widget_set_extension_events:
8651 * @widget: a #GtkWidget
8652 * @mode: bitfield of extension events to receive
8654 * Sets the extension events mask to @mode. See #GdkExtensionMode
8655 * and gdk_input_set_extension_events().
8658 gtk_widget_set_extension_events (GtkWidget *widget,
8659 GdkExtensionMode mode)
8661 g_return_if_fail (GTK_IS_WIDGET (widget));
8663 if (gtk_widget_get_realized (widget))
8664 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8666 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8667 GINT_TO_POINTER (mode));
8668 g_object_notify (G_OBJECT (widget), "extension-events");
8672 * gtk_widget_get_toplevel:
8673 * @widget: a #GtkWidget
8675 * This function returns the topmost widget in the container hierarchy
8676 * @widget is a part of. If @widget has no parent widgets, it will be
8677 * returned as the topmost widget. No reference will be added to the
8678 * returned widget; it should not be unreferenced.
8680 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8681 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8683 * %NULL if @widget wasn't inside a toplevel window, and if the
8684 * window was inside a #GtkWindow-derived widget which was in turn
8685 * inside the toplevel #GtkWindow. While the second case may
8686 * seem unlikely, it actually happens when a #GtkPlug is embedded
8687 * inside a #GtkSocket within the same application.
8689 * To reliably find the toplevel #GtkWindow, use
8690 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8691 * is set on the result.
8693 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8694 * if (gtk_widget_is_toplevel (toplevel))
8696 * /* Perform action on toplevel. */
8700 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8701 * if there's no ancestor.
8704 gtk_widget_get_toplevel (GtkWidget *widget)
8706 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8708 while (widget->priv->parent)
8709 widget = widget->priv->parent;
8715 * gtk_widget_get_ancestor:
8716 * @widget: a #GtkWidget
8717 * @widget_type: ancestor type
8719 * Gets the first ancestor of @widget with type @widget_type. For example,
8720 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8721 * the first #GtkBox that's an ancestor of @widget. No reference will be
8722 * added to the returned widget; it should not be unreferenced. See note
8723 * about checking for a toplevel #GtkWindow in the docs for
8724 * gtk_widget_get_toplevel().
8726 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8727 * considers @widget to be an ancestor of itself.
8729 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8732 gtk_widget_get_ancestor (GtkWidget *widget,
8735 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8737 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8738 widget = widget->priv->parent;
8740 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8747 * gtk_widget_get_visual:
8748 * @widget: a #GtkWidget
8750 * Gets the visual that will be used to render @widget.
8752 * Return value: (transfer none): the visual for @widget
8755 gtk_widget_get_visual (GtkWidget *widget)
8759 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8761 for (w = widget; w != NULL; w = w->priv->parent)
8763 if (gtk_widget_get_has_window (w) &&
8765 return gdk_window_get_visual (w->priv->window);
8767 if (GTK_IS_WINDOW (w))
8768 return _gtk_window_get_visual (GTK_WINDOW (w));
8771 return gdk_screen_get_system_visual (gdk_screen_get_default ());
8775 * gtk_widget_get_settings:
8776 * @widget: a #GtkWidget
8778 * Gets the settings object holding the settings (global property
8779 * settings, RC file information, etc) used for this widget.
8781 * Note that this function can only be called when the #GtkWidget
8782 * is attached to a toplevel, since the settings object is specific
8783 * to a particular #GdkScreen.
8785 * Return value: (transfer none): the relevant #GtkSettings object
8788 gtk_widget_get_settings (GtkWidget *widget)
8790 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8792 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8796 * gtk_widget_get_events:
8797 * @widget: a #GtkWidget
8799 * Returns the event mask for the widget (a bitfield containing flags
8800 * from the #GdkEventMask enumeration). These are the events that the widget
8803 * Return value: event mask for @widget
8806 gtk_widget_get_events (GtkWidget *widget)
8808 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8810 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8814 * gtk_widget_get_device_events:
8815 * @widget: a #GtkWidget
8816 * @device: a #GdkDevice
8818 * Returns the events mask for the widget corresponding to an specific device. These
8819 * are the events that the widget will receive when @device operates on it.
8821 * Returns: device event mask for @widget
8826 gtk_widget_get_device_events (GtkWidget *widget,
8829 GHashTable *device_events;
8831 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8832 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8834 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8839 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8843 * gtk_widget_get_extension_events:
8844 * @widget: a #GtkWidget
8846 * Retrieves the extension events the widget will receive; see
8847 * gdk_input_set_extension_events().
8849 * Return value: extension events for @widget
8852 gtk_widget_get_extension_events (GtkWidget *widget)
8854 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8856 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8860 * gtk_widget_get_pointer:
8861 * @widget: a #GtkWidget
8862 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8863 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8865 * Obtains the location of the mouse pointer in widget coordinates.
8866 * Widget coordinates are a bit odd; for historical reasons, they are
8867 * defined as @widget->window coordinates for widgets that are not
8868 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8869 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8872 gtk_widget_get_pointer (GtkWidget *widget,
8876 GtkWidgetPrivate *priv;
8878 g_return_if_fail (GTK_IS_WIDGET (widget));
8880 priv = widget->priv;
8887 if (gtk_widget_get_realized (widget))
8889 gdk_window_get_pointer (priv->window, x, y, NULL);
8891 if (!gtk_widget_get_has_window (widget))
8894 *x -= priv->allocation.x;
8896 *y -= priv->allocation.y;
8902 * gtk_widget_is_ancestor:
8903 * @widget: a #GtkWidget
8904 * @ancestor: another #GtkWidget
8906 * Determines whether @widget is somewhere inside @ancestor, possibly with
8907 * intermediate containers.
8909 * Return value: %TRUE if @ancestor contains @widget as a child,
8910 * grandchild, great grandchild, etc.
8913 gtk_widget_is_ancestor (GtkWidget *widget,
8914 GtkWidget *ancestor)
8916 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8917 g_return_val_if_fail (ancestor != NULL, FALSE);
8921 if (widget->priv->parent == ancestor)
8923 widget = widget->priv->parent;
8929 static GQuark quark_composite_name = 0;
8932 * gtk_widget_set_composite_name:
8933 * @widget: a #GtkWidget.
8934 * @name: the name to set
8936 * Sets a widgets composite name. The widget must be
8937 * a composite child of its parent; see gtk_widget_push_composite_child().
8940 gtk_widget_set_composite_name (GtkWidget *widget,
8943 g_return_if_fail (GTK_IS_WIDGET (widget));
8944 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8945 g_return_if_fail (name != NULL);
8947 if (!quark_composite_name)
8948 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8950 g_object_set_qdata_full (G_OBJECT (widget),
8951 quark_composite_name,
8957 * gtk_widget_get_composite_name:
8958 * @widget: a #GtkWidget
8960 * Obtains the composite name of a widget.
8962 * Returns: the composite name of @widget, or %NULL if @widget is not
8963 * a composite child. The string should be freed when it is no
8967 gtk_widget_get_composite_name (GtkWidget *widget)
8969 GtkWidgetPrivate *priv;
8971 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8973 priv = widget->priv;
8975 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
8976 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
8983 * gtk_widget_push_composite_child:
8985 * Makes all newly-created widgets as composite children until
8986 * the corresponding gtk_widget_pop_composite_child() call.
8988 * A composite child is a child that's an implementation detail of the
8989 * container it's inside and should not be visible to people using the
8990 * container. Composite children aren't treated differently by GTK (but
8991 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8992 * builders might want to treat them in a different way.
8994 * Here is a simple example:
8996 * gtk_widget_push_composite_child ();
8997 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8998 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8999 * gtk_widget_pop_composite_child ();
9000 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9001 * GTK_WIDGET (scrolled_window));
9002 * g_object_ref (scrolled_window->hscrollbar);
9006 gtk_widget_push_composite_child (void)
9008 composite_child_stack++;
9012 * gtk_widget_pop_composite_child:
9014 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9017 gtk_widget_pop_composite_child (void)
9019 if (composite_child_stack)
9020 composite_child_stack--;
9024 gtk_widget_emit_direction_changed (GtkWidget *widget,
9025 GtkTextDirection old_dir)
9027 gtk_widget_update_pango_context (widget);
9029 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9033 * gtk_widget_set_direction:
9034 * @widget: a #GtkWidget
9035 * @dir: the new direction
9037 * Sets the reading direction on a particular widget. This direction
9038 * controls the primary direction for widgets containing text,
9039 * and also the direction in which the children of a container are
9040 * packed. The ability to set the direction is present in order
9041 * so that correct localization into languages with right-to-left
9042 * reading directions can be done. Generally, applications will
9043 * let the default reading direction present, except for containers
9044 * where the containers are arranged in an order that is explicitely
9045 * visual rather than logical (such as buttons for text justification).
9047 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9048 * set by gtk_widget_set_default_direction() will be used.
9051 gtk_widget_set_direction (GtkWidget *widget,
9052 GtkTextDirection dir)
9054 GtkTextDirection old_dir;
9056 g_return_if_fail (GTK_IS_WIDGET (widget));
9057 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9059 old_dir = gtk_widget_get_direction (widget);
9061 if (dir == GTK_TEXT_DIR_NONE)
9062 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9065 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9066 if (dir == GTK_TEXT_DIR_LTR)
9067 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9069 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9072 if (old_dir != gtk_widget_get_direction (widget))
9073 gtk_widget_emit_direction_changed (widget, old_dir);
9077 * gtk_widget_get_direction:
9078 * @widget: a #GtkWidget
9080 * Gets the reading direction for a particular widget. See
9081 * gtk_widget_set_direction().
9083 * Return value: the reading direction for the widget.
9086 gtk_widget_get_direction (GtkWidget *widget)
9088 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9090 if (GTK_WIDGET_DIRECTION_SET (widget))
9091 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9093 return gtk_default_direction;
9097 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9099 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9101 g_object_ref (widget);
9103 if (!GTK_WIDGET_DIRECTION_SET (widget))
9104 gtk_widget_emit_direction_changed (widget, old_dir);
9106 if (GTK_IS_CONTAINER (widget))
9107 gtk_container_forall (GTK_CONTAINER (widget),
9108 gtk_widget_set_default_direction_recurse,
9111 g_object_unref (widget);
9115 * gtk_widget_set_default_direction:
9116 * @dir: the new default direction. This cannot be
9117 * %GTK_TEXT_DIR_NONE.
9119 * Sets the default reading direction for widgets where the
9120 * direction has not been explicitly set by gtk_widget_set_direction().
9123 gtk_widget_set_default_direction (GtkTextDirection dir)
9125 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9127 if (dir != gtk_default_direction)
9129 GList *toplevels, *tmp_list;
9130 GtkTextDirection old_dir = gtk_default_direction;
9132 gtk_default_direction = dir;
9134 tmp_list = toplevels = gtk_window_list_toplevels ();
9135 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9139 gtk_widget_set_default_direction_recurse (tmp_list->data,
9140 GUINT_TO_POINTER (old_dir));
9141 g_object_unref (tmp_list->data);
9142 tmp_list = tmp_list->next;
9145 g_list_free (toplevels);
9150 * gtk_widget_get_default_direction:
9152 * Obtains the current default reading direction. See
9153 * gtk_widget_set_default_direction().
9155 * Return value: the current default direction.
9158 gtk_widget_get_default_direction (void)
9160 return gtk_default_direction;
9164 gtk_widget_dispose (GObject *object)
9166 GtkWidget *widget = GTK_WIDGET (object);
9167 GtkWidgetPrivate *priv = widget->priv;
9170 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9171 else if (gtk_widget_get_visible (widget))
9172 gtk_widget_hide (widget);
9174 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9175 if (gtk_widget_get_realized (widget))
9176 gtk_widget_unrealize (widget);
9178 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9182 gtk_widget_real_destroy (GtkObject *object)
9184 /* gtk_object_destroy() will already hold a refcount on object */
9185 GtkWidget *widget = GTK_WIDGET (object);
9186 GtkWidgetPrivate *priv = widget->priv;
9188 /* wipe accelerator closures (keep order) */
9189 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9190 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9192 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9193 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9195 gtk_grab_remove (widget);
9197 g_object_unref (priv->style);
9198 priv->style = gtk_widget_get_default_style ();
9199 g_object_ref (priv->style);
9201 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9205 gtk_widget_finalize (GObject *object)
9207 GtkWidget *widget = GTK_WIDGET (object);
9208 GtkWidgetPrivate *priv = widget->priv;
9209 GtkWidgetAuxInfo *aux_info;
9210 GtkAccessible *accessible;
9212 gtk_grab_remove (widget);
9214 g_object_unref (priv->style);
9217 g_free (priv->name);
9219 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9221 gtk_widget_aux_info_destroy (aux_info);
9223 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9225 g_object_unref (accessible);
9227 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9230 /*****************************************
9231 * gtk_widget_real_map:
9236 *****************************************/
9239 gtk_widget_real_map (GtkWidget *widget)
9241 GtkWidgetPrivate *priv = widget->priv;
9243 g_assert (gtk_widget_get_realized (widget));
9245 if (!gtk_widget_get_mapped (widget))
9247 gtk_widget_set_mapped (widget, TRUE);
9249 if (gtk_widget_get_has_window (widget))
9250 gdk_window_show (priv->window);
9254 /*****************************************
9255 * gtk_widget_real_unmap:
9260 *****************************************/
9263 gtk_widget_real_unmap (GtkWidget *widget)
9265 GtkWidgetPrivate *priv = widget->priv;
9267 if (gtk_widget_get_mapped (widget))
9269 gtk_widget_set_mapped (widget, FALSE);
9271 if (gtk_widget_get_has_window (widget))
9272 gdk_window_hide (priv->window);
9276 /*****************************************
9277 * gtk_widget_real_realize:
9282 *****************************************/
9285 gtk_widget_real_realize (GtkWidget *widget)
9287 GtkWidgetPrivate *priv = widget->priv;
9289 g_assert (!gtk_widget_get_has_window (widget));
9291 gtk_widget_set_realized (widget, TRUE);
9294 priv->window = gtk_widget_get_parent_window (widget);
9295 g_object_ref (priv->window);
9297 priv->style = gtk_style_attach (priv->style, priv->window);
9300 /*****************************************
9301 * gtk_widget_real_unrealize:
9306 *****************************************/
9309 gtk_widget_real_unrealize (GtkWidget *widget)
9311 GtkWidgetPrivate *priv = widget->priv;
9313 if (gtk_widget_get_mapped (widget))
9314 gtk_widget_real_unmap (widget);
9316 gtk_widget_set_mapped (widget, FALSE);
9318 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9321 /* We must do unrealize child widget BEFORE container widget.
9322 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9323 * So, unrealizing container widget bofore its children causes the problem
9324 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9327 if (GTK_IS_CONTAINER (widget))
9328 gtk_container_forall (GTK_CONTAINER (widget),
9329 (GtkCallback) gtk_widget_unrealize,
9332 gtk_style_detach (priv->style);
9333 if (gtk_widget_get_has_window (widget))
9335 gdk_window_set_user_data (priv->window, NULL);
9336 gdk_window_destroy (priv->window);
9337 priv->window = NULL;
9341 g_object_unref (priv->window);
9342 priv->window = NULL;
9345 gtk_selection_remove_all (widget);
9347 gtk_widget_set_realized (widget, FALSE);
9351 gtk_widget_real_size_request (GtkWidget *widget,
9352 GtkRequisition *requisition)
9354 requisition->width = 0;
9355 requisition->height = 0;
9359 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9360 GtkOrientation orientation,
9365 const GtkWidgetAuxInfo *aux_info;
9367 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9369 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9370 aux_info->width > 0)
9372 *minimum_size = MAX (*minimum_size, aux_info->width);
9374 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9375 aux_info->height > 0)
9377 *minimum_size = MAX (*minimum_size, aux_info->height);
9380 /* Fix it if set_size_request made natural size smaller than min size.
9381 * This would also silently fix broken widgets, but we warn about them
9382 * in gtksizerequest.c when calling their size request vfuncs.
9384 *natural_size = MAX (*natural_size, *minimum_size);
9386 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9388 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9389 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9393 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9394 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9399 * _gtk_widget_peek_request_cache:
9401 * Returns the address of the widget's request cache (strictly for
9402 * internal use in gtksizerequest.c)
9404 * Return value: the address of @widget's size request cache.
9407 _gtk_widget_peek_request_cache (GtkWidget *widget)
9409 /* Don't bother slowing things down with the return_if_fail guards here */
9410 return &widget->priv->requests;
9414 * _gtk_widget_set_device_window:
9415 * @widget: a #GtkWidget.
9416 * @device: a #GdkDevice.
9417 * @window: the new device window.
9419 * Sets pointer window for @widget and @device. Does not ref @window.
9420 * Actually stores it on the #GdkScreen, but you don't need to know that.
9423 _gtk_widget_set_device_window (GtkWidget *widget,
9427 GtkWidgetPrivate *priv;
9429 GHashTable *device_window;
9431 g_return_if_fail (GTK_IS_WIDGET (widget));
9432 g_return_if_fail (GDK_IS_DEVICE (device));
9433 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9435 priv = widget->priv;
9437 if (!gtk_widget_get_realized (widget))
9440 screen = gdk_window_get_screen (priv->window);
9441 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9443 if (G_UNLIKELY (!device_window))
9445 device_window = g_hash_table_new (NULL, NULL);
9446 g_object_set_qdata_full (G_OBJECT (screen),
9447 quark_pointer_window,
9449 (GDestroyNotify) g_hash_table_destroy);
9453 g_hash_table_insert (device_window, device, window);
9455 g_hash_table_remove (device_window, device);
9459 * _gtk_widget_get_device_window:
9460 * @widget: a #GtkWidget.
9461 * @device: a #GdkDevice.
9463 * Return value: the device window set on the #GdkScreen @widget is attached
9467 _gtk_widget_get_device_window (GtkWidget *widget,
9470 GtkWidgetPrivate *priv;
9472 GHashTable *device_window;
9476 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9477 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9479 priv = widget->priv;
9481 if (!gtk_widget_get_realized (widget))
9484 screen = gdk_window_get_screen (priv->window);
9485 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9487 if (G_UNLIKELY (!device_window))
9490 window = g_hash_table_lookup (device_window, device);
9495 gdk_window_get_user_data (window, (gpointer *) &w);
9504 * _gtk_widget_list_devices:
9505 * @widget: a #GtkWidget.
9507 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9508 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9512 _gtk_widget_list_devices (GtkWidget *widget)
9514 GtkWidgetPrivate *priv;
9516 GHashTableIter iter;
9517 GHashTable *device_window;
9518 GList *devices = NULL;
9519 gpointer key, value;
9521 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9523 priv = widget->priv;
9525 if (!gtk_widget_get_realized (widget))
9528 screen = gdk_window_get_screen (priv->window);
9529 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9531 if (G_UNLIKELY (!device_window))
9534 g_hash_table_iter_init (&iter, device_window);
9536 while (g_hash_table_iter_next (&iter, &key, &value))
9538 GdkDevice *device = key;
9539 GdkWindow *window = value;
9544 gdk_window_get_user_data (window, (gpointer *) &w);
9547 devices = g_list_prepend (devices, device);
9555 synth_crossing (GtkWidget *widget,
9559 GdkCrossingMode mode,
9560 GdkNotifyType detail)
9564 event = gdk_event_new (type);
9566 event->crossing.window = g_object_ref (window);
9567 event->crossing.send_event = TRUE;
9568 event->crossing.subwindow = g_object_ref (window);
9569 event->crossing.time = GDK_CURRENT_TIME;
9570 event->crossing.x = event->crossing.y = 0;
9571 event->crossing.x_root = event->crossing.y_root = 0;
9572 event->crossing.mode = mode;
9573 event->crossing.detail = detail;
9574 event->crossing.focus = FALSE;
9575 event->crossing.state = 0;
9576 gdk_event_set_device (event, device);
9579 widget = gtk_get_event_widget (event);
9582 gtk_widget_event_internal (widget, event);
9584 gdk_event_free (event);
9588 * _gtk_widget_synthesize_crossing:
9589 * @from: the #GtkWidget the virtual pointer is leaving.
9590 * @to: the #GtkWidget the virtual pointer is moving to.
9591 * @mode: the #GdkCrossingMode to place on the synthesized events.
9593 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9595 * The real pointer window is the window that most recently received an enter notify
9596 * event. Windows that don't select for crossing events can't become the real
9597 * poiner window. The real pointer widget that owns the real pointer window. The
9598 * effective pointer window is the same as the real pointer window unless the real
9599 * pointer widget is either insensitive or there is a grab on a widget that is not
9600 * an ancestor of the real pointer widget (in which case the effective pointer
9601 * window should be the root window).
9603 * When the effective pointer window is the same as the real poiner window, we
9604 * receive crossing events from the windowing system. When the effective pointer
9605 * window changes to become different from the real pointer window we synthesize
9606 * crossing events, attempting to follow X protocol rules:
9608 * When the root window becomes the effective pointer window:
9609 * - leave notify on real pointer window, detail Ancestor
9610 * - leave notify on all of its ancestors, detail Virtual
9611 * - enter notify on root window, detail Inferior
9613 * When the root window ceases to be the effective pointer window:
9614 * - leave notify on root window, detail Inferior
9615 * - enter notify on all ancestors of real pointer window, detail Virtual
9616 * - enter notify on real pointer window, detail Ancestor
9619 _gtk_widget_synthesize_crossing (GtkWidget *from,
9622 GdkCrossingMode mode)
9624 GdkWindow *from_window = NULL, *to_window = NULL;
9626 g_return_if_fail (from != NULL || to != NULL);
9630 from_window = _gtk_widget_get_device_window (from, device);
9633 from_window = from->priv->window;
9638 to_window = _gtk_widget_get_device_window (to, device);
9641 to_window = to->priv->window;
9644 if (from_window == NULL && to_window == NULL)
9646 else if (from_window != NULL && to_window == NULL)
9648 GList *from_ancestors = NULL, *list;
9649 GdkWindow *from_ancestor = from_window;
9651 while (from_ancestor != NULL)
9653 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9654 if (from_ancestor == NULL)
9656 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9659 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9660 device, mode, GDK_NOTIFY_ANCESTOR);
9661 for (list = g_list_last (from_ancestors); list; list = list->prev)
9663 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9664 device, mode, GDK_NOTIFY_VIRTUAL);
9667 /* XXX: enter/inferior on root window? */
9669 g_list_free (from_ancestors);
9671 else if (from_window == NULL && to_window != NULL)
9673 GList *to_ancestors = NULL, *list;
9674 GdkWindow *to_ancestor = to_window;
9676 while (to_ancestor != NULL)
9678 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9679 if (to_ancestor == NULL)
9681 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9684 /* XXX: leave/inferior on root window? */
9686 for (list = to_ancestors; list; list = list->next)
9688 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9689 device, mode, GDK_NOTIFY_VIRTUAL);
9691 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9692 device, mode, GDK_NOTIFY_ANCESTOR);
9694 g_list_free (to_ancestors);
9696 else if (from_window == to_window)
9700 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9701 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9703 while (from_ancestor != NULL || to_ancestor != NULL)
9705 if (from_ancestor != NULL)
9707 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9708 if (from_ancestor == to_window)
9711 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9713 if (to_ancestor != NULL)
9715 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9716 if (to_ancestor == from_window)
9719 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9722 if (to_ancestor == from_window)
9724 if (mode != GDK_CROSSING_GTK_UNGRAB)
9725 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9726 device, mode, GDK_NOTIFY_INFERIOR);
9727 for (list = to_ancestors; list; list = list->next)
9728 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9729 device, mode, GDK_NOTIFY_VIRTUAL);
9730 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9731 device, mode, GDK_NOTIFY_ANCESTOR);
9733 else if (from_ancestor == to_window)
9735 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9736 device, mode, GDK_NOTIFY_ANCESTOR);
9737 for (list = g_list_last (from_ancestors); list; list = list->prev)
9739 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9740 device, mode, GDK_NOTIFY_VIRTUAL);
9742 if (mode != GDK_CROSSING_GTK_GRAB)
9743 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9744 device, mode, GDK_NOTIFY_INFERIOR);
9748 while (from_ancestors != NULL && to_ancestors != NULL
9749 && from_ancestors->data == to_ancestors->data)
9751 from_ancestors = g_list_delete_link (from_ancestors,
9753 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9756 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9757 device, mode, GDK_NOTIFY_NONLINEAR);
9759 for (list = g_list_last (from_ancestors); list; list = list->prev)
9761 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9762 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9764 for (list = to_ancestors; list; list = list->next)
9766 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9767 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9769 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9770 device, mode, GDK_NOTIFY_NONLINEAR);
9772 g_list_free (from_ancestors);
9773 g_list_free (to_ancestors);
9778 gtk_widget_propagate_state (GtkWidget *widget,
9781 GtkWidgetPrivate *priv = widget->priv;
9782 guint8 old_state = gtk_widget_get_state (widget);
9783 guint8 old_saved_state = priv->saved_state;
9785 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9786 * parent_sensitive==TRUE on a sensitive widget
9790 if (data->parent_sensitive)
9791 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9793 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9795 if (gtk_widget_is_sensitive (widget))
9797 if (data->state_restoration)
9798 priv->state = priv->saved_state;
9800 priv->state = data->state;
9804 if (!data->state_restoration)
9806 if (data->state != GTK_STATE_INSENSITIVE)
9807 priv->saved_state = data->state;
9809 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9810 priv->saved_state = gtk_widget_get_state (widget);
9811 priv->state = GTK_STATE_INSENSITIVE;
9814 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9818 window = gtk_widget_get_toplevel (widget);
9819 if (window && gtk_widget_is_toplevel (window))
9820 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9823 if (old_state != gtk_widget_get_state (widget) ||
9824 old_saved_state != priv->saved_state)
9826 g_object_ref (widget);
9828 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9829 gtk_grab_remove (widget);
9831 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9833 if (!GTK_WIDGET_SHADOWED (widget))
9835 GList *event_windows = NULL;
9838 devices = _gtk_widget_list_devices (widget);
9840 for (d = devices; d; d = d->next)
9846 window = _gtk_widget_get_device_window (widget, device);
9848 /* Do not propagate more than once to the
9849 * same window if non-multidevice aware.
9851 if (!gdk_window_get_support_multidevice (window) &&
9852 g_list_find (event_windows, window))
9855 if (!gtk_widget_is_sensitive (widget))
9856 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9857 GDK_CROSSING_STATE_CHANGED);
9858 else if (old_state == GTK_STATE_INSENSITIVE)
9859 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9860 GDK_CROSSING_STATE_CHANGED);
9862 event_windows = g_list_prepend (event_windows, window);
9865 g_list_free (event_windows);
9866 g_list_free (devices);
9869 if (GTK_IS_CONTAINER (widget))
9871 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9872 if (data->use_forall)
9873 gtk_container_forall (GTK_CONTAINER (widget),
9874 (GtkCallback) gtk_widget_propagate_state,
9877 gtk_container_foreach (GTK_CONTAINER (widget),
9878 (GtkCallback) gtk_widget_propagate_state,
9881 g_object_unref (widget);
9885 static const GtkWidgetAuxInfo default_aux_info = {
9893 * _gtk_widget_get_aux_info:
9894 * @widget: a #GtkWidget
9895 * @create: if %TRUE, create the structure if it doesn't exist
9897 * Get the #GtkWidgetAuxInfo structure for the widget.
9899 * Return value: the #GtkAuxInfo structure for the widget, or
9900 * %NULL if @create is %FALSE and one doesn't already exist.
9903 _gtk_widget_get_aux_info (GtkWidget *widget,
9906 GtkWidgetAuxInfo *aux_info;
9908 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9909 if (!aux_info && create)
9911 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9913 *aux_info = default_aux_info;
9915 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9921 static const GtkWidgetAuxInfo*
9922 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
9924 GtkWidgetAuxInfo *aux_info;
9926 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
9927 if (aux_info == NULL)
9929 return &default_aux_info;
9937 /*****************************************
9938 * gtk_widget_aux_info_destroy:
9943 *****************************************/
9946 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9948 g_slice_free (GtkWidgetAuxInfo, aux_info);
9952 * gtk_widget_shape_combine_region:
9953 * @widget: a #GtkWidget
9954 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
9956 * Sets a shape for this widget's GDK window. This allows for
9957 * transparent windows etc., see gdk_window_shape_combine_region()
9958 * for more information.
9963 gtk_widget_shape_combine_region (GtkWidget *widget,
9964 cairo_region_t *region)
9966 GtkWidgetPrivate *priv;
9968 g_return_if_fail (GTK_IS_WIDGET (widget));
9969 /* set_shape doesn't work on widgets without gdk window */
9970 g_return_if_fail (gtk_widget_get_has_window (widget));
9972 priv = widget->priv;
9976 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9979 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
9981 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9985 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9987 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
9988 cairo_region_copy (region),
9989 (GDestroyNotify) cairo_region_destroy);
9991 /* set shape if widget has a gdk window already.
9992 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9995 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10000 * gtk_widget_input_shape_combine_region:
10001 * @widget: a #GtkWidget
10002 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10004 * Sets an input shape for this widget's GDK window. This allows for
10005 * windows which react to mouse click in a nonrectangular region, see
10006 * gdk_window_input_shape_combine_region() for more information.
10011 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10012 cairo_region_t *region)
10014 GtkWidgetPrivate *priv;
10016 g_return_if_fail (GTK_IS_WIDGET (widget));
10017 /* set_shape doesn't work on widgets without gdk window */
10018 g_return_if_fail (gtk_widget_get_has_window (widget));
10020 priv = widget->priv;
10022 if (region == NULL)
10025 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10027 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10031 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10032 cairo_region_copy (region),
10033 (GDestroyNotify) cairo_region_destroy);
10035 /* set shape if widget has a gdk window already.
10036 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10039 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10045 gtk_reset_shapes_recurse (GtkWidget *widget,
10051 gdk_window_get_user_data (window, &data);
10052 if (data != widget)
10055 gdk_window_shape_combine_region (window, NULL, 0, 0);
10056 for (list = gdk_window_peek_children (window); list; list = list->next)
10057 gtk_reset_shapes_recurse (widget, list->data);
10061 * gtk_widget_reset_shapes:
10062 * @widget: a #GtkWidget
10064 * Recursively resets the shape on this widget and its descendants.
10067 gtk_widget_reset_shapes (GtkWidget *widget)
10069 GtkWidgetPrivate *priv;
10071 g_return_if_fail (GTK_IS_WIDGET (widget));
10072 g_return_if_fail (gtk_widget_get_realized (widget));
10074 priv = widget->priv;
10076 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10077 gtk_reset_shapes_recurse (widget, priv->window);
10080 /* style properties
10084 * gtk_widget_class_install_style_property_parser:
10085 * @klass: a #GtkWidgetClass
10086 * @pspec: the #GParamSpec for the style property
10087 * @parser: the parser for the style property
10089 * Installs a style property on a widget class.
10092 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10094 GtkRcPropertyParser parser)
10096 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10097 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10098 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10099 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10101 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10103 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10104 G_OBJECT_CLASS_NAME (klass),
10109 g_param_spec_ref_sink (pspec);
10110 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10111 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10115 * gtk_widget_class_install_style_property:
10116 * @klass: a #GtkWidgetClass
10117 * @pspec: the #GParamSpec for the property
10119 * Installs a style property on a widget class. The parser for the
10120 * style property is determined by the value type of @pspec.
10123 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10126 GtkRcPropertyParser parser;
10128 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10129 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10131 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10133 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10137 * gtk_widget_class_find_style_property:
10138 * @klass: a #GtkWidgetClass
10139 * @property_name: the name of the style property to find
10140 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10141 * style property with that name.
10143 * Finds a style property of a widget class by name.
10148 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10149 const gchar *property_name)
10151 g_return_val_if_fail (property_name != NULL, NULL);
10153 return g_param_spec_pool_lookup (style_property_spec_pool,
10155 G_OBJECT_CLASS_TYPE (klass),
10160 * gtk_widget_class_list_style_properties:
10161 * @klass: a #GtkWidgetClass
10162 * @n_properties: location to return the number of style properties found
10163 * @returns: an newly allocated array of #GParamSpec*. The array must
10164 * be freed with g_free().
10166 * Returns all style properties of a widget class.
10171 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10172 guint *n_properties)
10174 GParamSpec **pspecs;
10177 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10178 G_OBJECT_CLASS_TYPE (klass),
10187 * gtk_widget_style_get_property:
10188 * @widget: a #GtkWidget
10189 * @property_name: the name of a style property
10190 * @value: location to return the property value
10192 * Gets the value of a style property of @widget.
10195 gtk_widget_style_get_property (GtkWidget *widget,
10196 const gchar *property_name,
10199 GtkWidgetPrivate *priv;
10202 g_return_if_fail (GTK_IS_WIDGET (widget));
10203 g_return_if_fail (property_name != NULL);
10204 g_return_if_fail (G_IS_VALUE (value));
10206 priv = widget->priv;
10208 g_object_ref (widget);
10209 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10211 G_OBJECT_TYPE (widget),
10214 g_warning ("%s: widget class `%s' has no property named `%s'",
10216 G_OBJECT_TYPE_NAME (widget),
10220 const GValue *peek_value;
10222 peek_value = _gtk_style_peek_property_value (priv->style,
10223 G_OBJECT_TYPE (widget),
10225 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10227 /* auto-conversion of the caller's value type
10229 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10230 g_value_copy (peek_value, value);
10231 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10232 g_value_transform (peek_value, value);
10234 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10236 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10237 G_VALUE_TYPE_NAME (value));
10239 g_object_unref (widget);
10243 * gtk_widget_style_get_valist:
10244 * @widget: a #GtkWidget
10245 * @first_property_name: the name of the first property to get
10246 * @var_args: a <type>va_list</type> of pairs of property names and
10247 * locations to return the property values, starting with the location
10248 * for @first_property_name.
10250 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10254 gtk_widget_style_get_valist (GtkWidget *widget,
10255 const gchar *first_property_name,
10258 GtkWidgetPrivate *priv;
10261 g_return_if_fail (GTK_IS_WIDGET (widget));
10263 priv = widget->priv;
10265 g_object_ref (widget);
10267 name = first_property_name;
10270 const GValue *peek_value;
10274 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10276 G_OBJECT_TYPE (widget),
10280 g_warning ("%s: widget class `%s' has no property named `%s'",
10282 G_OBJECT_TYPE_NAME (widget),
10286 /* style pspecs are always readable so we can spare that check here */
10288 peek_value = _gtk_style_peek_property_value (priv->style,
10289 G_OBJECT_TYPE (widget),
10291 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10292 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10295 g_warning ("%s: %s", G_STRLOC, error);
10300 name = va_arg (var_args, gchar*);
10303 g_object_unref (widget);
10307 * gtk_widget_style_get:
10308 * @widget: a #GtkWidget
10309 * @first_property_name: the name of the first property to get
10310 * @Varargs: pairs of property names and locations to
10311 * return the property values, starting with the location for
10312 * @first_property_name, terminated by %NULL.
10314 * Gets the values of a multiple style properties of @widget.
10317 gtk_widget_style_get (GtkWidget *widget,
10318 const gchar *first_property_name,
10323 g_return_if_fail (GTK_IS_WIDGET (widget));
10325 va_start (var_args, first_property_name);
10326 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10332 * @widget: a #GtkWidget
10333 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10334 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10335 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10337 * Obtains the full path to @widget. The path is simply the name of a
10338 * widget and all its parents in the container hierarchy, separated by
10339 * periods. The name of a widget comes from
10340 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10341 * in gtkrc configuration files. Widget names are the type of the
10342 * widget by default (e.g. "GtkButton") or can be set to an
10343 * application-specific value with gtk_widget_set_name(). By setting
10344 * the name of a widget, you allow users or theme authors to apply
10345 * styles to that specific widget in their gtkrc
10346 * file. @path_reversed_p fills in the path in reverse order,
10347 * i.e. starting with @widget's name instead of starting with the name
10348 * of @widget's outermost ancestor.
10351 gtk_widget_path (GtkWidget *widget,
10352 guint *path_length,
10354 gchar **path_reversed)
10356 static gchar *rev_path = NULL;
10357 static guint tmp_path_len = 0;
10360 g_return_if_fail (GTK_IS_WIDGET (widget));
10365 const gchar *string;
10370 string = gtk_widget_get_name (widget);
10371 l = strlen (string);
10372 while (tmp_path_len <= len + l + 1)
10374 tmp_path_len += INIT_PATH_SIZE;
10375 rev_path = g_realloc (rev_path, tmp_path_len);
10377 s = string + l - 1;
10378 d = rev_path + len;
10379 while (s >= string)
10383 widget = widget->priv->parent;
10386 rev_path[len++] = '.';
10388 rev_path[len++] = 0;
10393 *path_length = len - 1;
10395 *path_reversed = g_strdup (rev_path);
10398 *path = g_strdup (rev_path);
10399 g_strreverse (*path);
10404 * gtk_widget_class_path:
10405 * @widget: a #GtkWidget
10406 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10407 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10408 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10411 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10412 * never uses a custom name set with gtk_widget_set_name().
10416 gtk_widget_class_path (GtkWidget *widget,
10417 guint *path_length,
10419 gchar **path_reversed)
10421 static gchar *rev_path = NULL;
10422 static guint tmp_path_len = 0;
10425 g_return_if_fail (GTK_IS_WIDGET (widget));
10430 const gchar *string;
10435 string = g_type_name (G_OBJECT_TYPE (widget));
10436 l = strlen (string);
10437 while (tmp_path_len <= len + l + 1)
10439 tmp_path_len += INIT_PATH_SIZE;
10440 rev_path = g_realloc (rev_path, tmp_path_len);
10442 s = string + l - 1;
10443 d = rev_path + len;
10444 while (s >= string)
10448 widget = widget->priv->parent;
10451 rev_path[len++] = '.';
10453 rev_path[len++] = 0;
10458 *path_length = len - 1;
10460 *path_reversed = g_strdup (rev_path);
10463 *path = g_strdup (rev_path);
10464 g_strreverse (*path);
10469 * gtk_requisition_new:
10471 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10473 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10474 * be freed with gtk_requisition_free().
10479 gtk_requisition_new (void)
10481 return g_slice_new0 (GtkRequisition);
10485 * gtk_requisition_copy:
10486 * @requisition: a #GtkRequisition
10488 * Copies a #GtkRequisition.
10490 * Returns: a copy of @requisition
10493 gtk_requisition_copy (const GtkRequisition *requisition)
10495 return g_slice_dup (GtkRequisition, requisition);
10499 * gtk_requisition_free:
10500 * @requisition: a #GtkRequisition
10502 * Frees a #GtkRequisition.
10505 gtk_requisition_free (GtkRequisition *requisition)
10507 g_slice_free (GtkRequisition, requisition);
10510 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10511 gtk_requisition_copy,
10512 gtk_requisition_free)
10515 * gtk_widget_get_accessible:
10516 * @widget: a #GtkWidget
10518 * Returns the accessible object that describes the widget to an
10519 * assistive technology.
10521 * If no accessibility library is loaded (i.e. no ATK implementation library is
10522 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10523 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10524 * if no class-specific #AtkObject implementation is available for the widget
10525 * instance in question, it will inherit an #AtkObject implementation from the
10526 * first ancestor class for which such an implementation is defined.
10528 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10529 * library contains more information about accessible objects and their uses.
10531 * Returns: (transfer none): the #AtkObject associated with @widget
10534 gtk_widget_get_accessible (GtkWidget *widget)
10536 GtkWidgetClass *klass;
10538 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10540 klass = GTK_WIDGET_GET_CLASS (widget);
10542 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10544 return klass->get_accessible (widget);
10548 gtk_widget_real_get_accessible (GtkWidget *widget)
10550 AtkObject* accessible;
10552 accessible = g_object_get_qdata (G_OBJECT (widget),
10553 quark_accessible_object);
10556 AtkObjectFactory *factory;
10557 AtkRegistry *default_registry;
10559 default_registry = atk_get_default_registry ();
10560 factory = atk_registry_get_factory (default_registry,
10561 G_TYPE_FROM_INSTANCE (widget));
10563 atk_object_factory_create_accessible (factory,
10564 G_OBJECT (widget));
10565 g_object_set_qdata (G_OBJECT (widget),
10566 quark_accessible_object,
10573 * Initialize a AtkImplementorIface instance's virtual pointers as
10574 * appropriate to this implementor's class (GtkWidget).
10577 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10579 iface->ref_accessible = gtk_widget_ref_accessible;
10583 gtk_widget_ref_accessible (AtkImplementor *implementor)
10585 AtkObject *accessible;
10587 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10589 g_object_ref (accessible);
10594 * GtkBuildable implementation
10596 static GQuark quark_builder_has_default = 0;
10597 static GQuark quark_builder_has_focus = 0;
10598 static GQuark quark_builder_atk_relations = 0;
10599 static GQuark quark_builder_set_name = 0;
10602 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10604 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10605 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10606 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10607 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10609 iface->set_name = gtk_widget_buildable_set_name;
10610 iface->get_name = gtk_widget_buildable_get_name;
10611 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10612 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10613 iface->parser_finished = gtk_widget_buildable_parser_finished;
10614 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10615 iface->custom_finished = gtk_widget_buildable_custom_finished;
10619 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10622 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10623 g_strdup (name), g_free);
10626 static const gchar *
10627 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10629 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10633 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10634 GtkBuilder *builder,
10635 const gchar *childname)
10637 if (strcmp (childname, "accessible") == 0)
10638 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10644 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10645 GtkBuilder *builder,
10647 const GValue *value)
10649 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10650 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10651 GINT_TO_POINTER (TRUE));
10652 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10653 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10654 GINT_TO_POINTER (TRUE));
10656 g_object_set_property (G_OBJECT (buildable), name, value);
10661 gchar *action_name;
10662 GString *description;
10664 gboolean translatable;
10674 free_action (AtkActionData *data, gpointer user_data)
10676 g_free (data->action_name);
10677 g_string_free (data->description, TRUE);
10678 g_free (data->context);
10679 g_slice_free (AtkActionData, data);
10683 free_relation (AtkRelationData *data, gpointer user_data)
10685 g_free (data->target);
10686 g_free (data->type);
10687 g_slice_free (AtkRelationData, data);
10691 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10692 GtkBuilder *builder)
10694 GSList *atk_relations;
10696 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10697 gtk_widget_grab_default (GTK_WIDGET (buildable));
10698 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10699 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10701 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10702 quark_builder_atk_relations);
10705 AtkObject *accessible;
10706 AtkRelationSet *relation_set;
10709 AtkRelationType relation_type;
10710 AtkObject *target_accessible;
10712 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10713 relation_set = atk_object_ref_relation_set (accessible);
10715 for (l = atk_relations; l; l = l->next)
10717 AtkRelationData *relation = (AtkRelationData*)l->data;
10719 target = gtk_builder_get_object (builder, relation->target);
10722 g_warning ("Target object %s in <relation> does not exist",
10726 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10727 g_assert (target_accessible != NULL);
10729 relation_type = atk_relation_type_for_name (relation->type);
10730 if (relation_type == ATK_RELATION_NULL)
10732 g_warning ("<relation> type %s not found",
10736 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10737 target_accessible);
10739 g_object_unref (relation_set);
10741 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10742 g_slist_free (atk_relations);
10743 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10752 } AccessibilitySubParserData;
10755 accessibility_start_element (GMarkupParseContext *context,
10756 const gchar *element_name,
10757 const gchar **names,
10758 const gchar **values,
10759 gpointer user_data,
10762 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10764 gint line_number, char_number;
10766 if (strcmp (element_name, "relation") == 0)
10768 gchar *target = NULL;
10769 gchar *type = NULL;
10770 AtkRelationData *relation;
10772 for (i = 0; names[i]; i++)
10774 if (strcmp (names[i], "target") == 0)
10775 target = g_strdup (values[i]);
10776 else if (strcmp (names[i], "type") == 0)
10777 type = g_strdup (values[i]);
10780 g_markup_parse_context_get_position (context,
10783 g_set_error (error,
10785 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10786 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10788 line_number, char_number, names[i], "relation");
10795 if (!target || !type)
10797 g_markup_parse_context_get_position (context,
10800 g_set_error (error,
10802 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10803 "%s:%d:%d <%s> requires attribute \"%s\"",
10805 line_number, char_number, "relation",
10806 type ? "target" : "type");
10812 relation = g_slice_new (AtkRelationData);
10813 relation->target = target;
10814 relation->type = type;
10816 data->relations = g_slist_prepend (data->relations, relation);
10818 else if (strcmp (element_name, "action") == 0)
10820 const gchar *action_name = NULL;
10821 const gchar *description = NULL;
10822 const gchar *msg_context = NULL;
10823 gboolean translatable = FALSE;
10824 AtkActionData *action;
10826 for (i = 0; names[i]; i++)
10828 if (strcmp (names[i], "action_name") == 0)
10829 action_name = values[i];
10830 else if (strcmp (names[i], "description") == 0)
10831 description = values[i];
10832 else if (strcmp (names[i], "translatable") == 0)
10834 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10837 else if (strcmp (names[i], "comments") == 0)
10839 /* do nothing, comments are for translators */
10841 else if (strcmp (names[i], "context") == 0)
10842 msg_context = values[i];
10845 g_markup_parse_context_get_position (context,
10848 g_set_error (error,
10850 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10851 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10853 line_number, char_number, names[i], "action");
10860 g_markup_parse_context_get_position (context,
10863 g_set_error (error,
10865 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10866 "%s:%d:%d <%s> requires attribute \"%s\"",
10868 line_number, char_number, "action",
10873 action = g_slice_new (AtkActionData);
10874 action->action_name = g_strdup (action_name);
10875 action->description = g_string_new (description);
10876 action->context = g_strdup (msg_context);
10877 action->translatable = translatable;
10879 data->actions = g_slist_prepend (data->actions, action);
10881 else if (strcmp (element_name, "accessibility") == 0)
10884 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10888 accessibility_text (GMarkupParseContext *context,
10891 gpointer user_data,
10894 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10896 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10898 AtkActionData *action = data->actions->data;
10900 g_string_append_len (action->description, text, text_len);
10904 static const GMarkupParser accessibility_parser =
10906 accessibility_start_element,
10908 accessibility_text,
10917 } AccelGroupParserData;
10920 accel_group_start_element (GMarkupParseContext *context,
10921 const gchar *element_name,
10922 const gchar **names,
10923 const gchar **values,
10924 gpointer user_data,
10929 guint modifiers = 0;
10930 gchar *signal = NULL;
10931 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10933 for (i = 0; names[i]; i++)
10935 if (strcmp (names[i], "key") == 0)
10936 key = gdk_keyval_from_name (values[i]);
10937 else if (strcmp (names[i], "modifiers") == 0)
10939 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10945 else if (strcmp (names[i], "signal") == 0)
10946 signal = g_strdup (values[i]);
10949 if (key == 0 || signal == NULL)
10951 g_warning ("<accelerator> requires key and signal attributes");
10954 parser_data->key = key;
10955 parser_data->modifiers = modifiers;
10956 parser_data->signal = signal;
10959 static const GMarkupParser accel_group_parser =
10961 accel_group_start_element,
10965 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10966 GtkBuilder *builder,
10968 const gchar *tagname,
10969 GMarkupParser *parser,
10972 g_assert (buildable);
10974 if (strcmp (tagname, "accelerator") == 0)
10976 AccelGroupParserData *parser_data;
10978 parser_data = g_slice_new0 (AccelGroupParserData);
10979 parser_data->object = g_object_ref (buildable);
10980 *parser = accel_group_parser;
10981 *data = parser_data;
10984 if (strcmp (tagname, "accessibility") == 0)
10986 AccessibilitySubParserData *parser_data;
10988 parser_data = g_slice_new0 (AccessibilitySubParserData);
10989 *parser = accessibility_parser;
10990 *data = parser_data;
10997 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10998 GtkWidget *toplevel,
10999 gpointer user_data)
11001 AccelGroupParserData *accel_data;
11002 GSList *accel_groups;
11003 GtkAccelGroup *accel_group;
11005 g_return_if_fail (GTK_IS_WIDGET (widget));
11006 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11007 g_return_if_fail (user_data != NULL);
11009 accel_data = (AccelGroupParserData*)user_data;
11010 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11011 if (g_slist_length (accel_groups) == 0)
11013 accel_group = gtk_accel_group_new ();
11014 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11018 g_assert (g_slist_length (accel_groups) == 1);
11019 accel_group = g_slist_nth_data (accel_groups, 0);
11022 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11023 accel_data->signal,
11026 accel_data->modifiers,
11027 GTK_ACCEL_VISIBLE);
11029 g_object_unref (accel_data->object);
11030 g_free (accel_data->signal);
11031 g_slice_free (AccelGroupParserData, accel_data);
11035 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11036 GtkBuilder *builder,
11038 const gchar *tagname,
11039 gpointer user_data)
11041 AccelGroupParserData *accel_data;
11042 AccessibilitySubParserData *a11y_data;
11043 GtkWidget *toplevel;
11045 if (strcmp (tagname, "accelerator") == 0)
11047 accel_data = (AccelGroupParserData*)user_data;
11048 g_assert (accel_data->object);
11050 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11052 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11054 else if (strcmp (tagname, "accessibility") == 0)
11056 a11y_data = (AccessibilitySubParserData*)user_data;
11058 if (a11y_data->actions)
11060 AtkObject *accessible;
11065 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11067 action = ATK_ACTION (accessible);
11068 n_actions = atk_action_get_n_actions (action);
11070 for (l = a11y_data->actions; l; l = l->next)
11072 AtkActionData *action_data = (AtkActionData*)l->data;
11074 for (i = 0; i < n_actions; i++)
11075 if (strcmp (atk_action_get_name (action, i),
11076 action_data->action_name) == 0)
11081 gchar *description;
11083 if (action_data->translatable && action_data->description->len)
11084 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11085 action_data->context,
11086 action_data->description->str);
11088 description = action_data->description->str;
11090 atk_action_set_description (action, i, description);
11094 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11095 g_slist_free (a11y_data->actions);
11098 if (a11y_data->relations)
11099 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11100 a11y_data->relations);
11102 g_slice_free (AccessibilitySubParserData, a11y_data);
11107 * GtkSizeRequest implementation
11110 gtk_widget_real_get_width (GtkSizeRequest *widget,
11111 gint *minimum_size,
11112 gint *natural_size)
11122 gtk_widget_real_get_height (GtkSizeRequest *widget,
11123 gint *minimum_size,
11124 gint *natural_size)
11134 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11136 gint *minimum_height,
11137 gint *natural_height)
11139 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11143 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11145 gint *minimum_width,
11146 gint *natural_width)
11148 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11152 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11154 iface->get_width = gtk_widget_real_get_width;
11155 iface->get_height = gtk_widget_real_get_height;
11156 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11157 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
11161 * gtk_widget_get_halign:
11162 * @widget: a #GtkWidget
11164 * Gets the value of the #GtkWidget:halign property.
11166 * Returns: the horizontal alignment of @widget
11169 gtk_widget_get_halign (GtkWidget *widget)
11171 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11172 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11176 * gtk_widget_set_halign:
11177 * @widget: a #GtkWidget
11178 * @align: the horizontal alignment
11180 * Sets the horizontal alignment of @widget.
11181 * See the #GtkWidget:halign property.
11184 gtk_widget_set_halign (GtkWidget *widget,
11187 GtkWidgetAuxInfo *aux_info;
11189 g_return_if_fail (GTK_IS_WIDGET (widget));
11191 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11193 if (aux_info->halign == align)
11196 aux_info->halign = align;
11197 gtk_widget_queue_resize (widget);
11198 g_object_notify (G_OBJECT (widget), "halign");
11202 * gtk_widget_get_valign:
11203 * @widget: a #GtkWidget
11205 * Gets the value of the #GtkWidget:valign property.
11207 * Returns: the vertical alignment of @widget
11210 gtk_widget_get_valign (GtkWidget *widget)
11212 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11213 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11217 * gtk_widget_set_valign:
11218 * @widget: a #GtkWidget
11219 * @align: the vertical alignment
11221 * Sets the vertical alignment of @widget.
11222 * See the #GtkWidget:valign property.
11225 gtk_widget_set_valign (GtkWidget *widget,
11228 GtkWidgetAuxInfo *aux_info;
11230 g_return_if_fail (GTK_IS_WIDGET (widget));
11232 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11234 if (aux_info->valign == align)
11237 aux_info->valign = align;
11238 gtk_widget_queue_resize (widget);
11239 g_object_notify (G_OBJECT (widget), "valign");
11243 * gtk_widget_get_margin_left:
11244 * @widget: a #GtkWidget
11246 * Gets the value of the #GtkWidget:margin-left property.
11248 * Returns: The left margin of @widget
11251 gtk_widget_get_margin_left (GtkWidget *widget)
11253 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11255 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11259 * gtk_widget_set_margin_left:
11260 * @widget: a #GtkWidget
11261 * @margin: the left margin
11263 * Sets the left margin of @widget.
11264 * See the #GtkWidget:margin-left property.
11267 gtk_widget_set_margin_left (GtkWidget *widget,
11270 GtkWidgetAuxInfo *aux_info;
11272 g_return_if_fail (GTK_IS_WIDGET (widget));
11273 g_return_if_fail (margin <= G_MAXINT16);
11275 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11277 if (aux_info->margin.left == margin)
11280 aux_info->margin.left = margin;
11281 gtk_widget_queue_resize (widget);
11282 g_object_notify (G_OBJECT (widget), "margin-left");
11286 * gtk_widget_get_margin_right:
11287 * @widget: a #GtkWidget
11289 * Gets the value of the #GtkWidget:margin-right property.
11291 * Returns: The left margin of @widget
11294 gtk_widget_get_margin_right (GtkWidget *widget)
11296 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11298 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11302 * gtk_widget_set_margin_right:
11303 * @widget: a #GtkWidget
11304 * @margin: the right margin
11306 * Sets the right margin of @widget.
11307 * See the #GtkWidget:margin-right property.
11310 gtk_widget_set_margin_right (GtkWidget *widget,
11313 GtkWidgetAuxInfo *aux_info;
11315 g_return_if_fail (GTK_IS_WIDGET (widget));
11316 g_return_if_fail (margin <= G_MAXINT16);
11318 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11320 if (aux_info->margin.right == margin)
11323 aux_info->margin.right = margin;
11324 gtk_widget_queue_resize (widget);
11325 g_object_notify (G_OBJECT (widget), "margin-right");
11329 * gtk_widget_get_margin_top:
11330 * @widget: a #GtkWidget
11332 * Gets the value of the #GtkWidget:margin-top property.
11334 * Returns: The top margin of @widget
11337 gtk_widget_get_margin_top (GtkWidget *widget)
11339 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11341 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11345 * gtk_widget_set_margin_top:
11346 * @widget: a #GtkWidget
11347 * @margin: the top margin
11349 * Sets the top margin of @widget.
11350 * See the #GtkWidget:margin-top property.
11353 gtk_widget_set_margin_top (GtkWidget *widget,
11356 GtkWidgetAuxInfo *aux_info;
11358 g_return_if_fail (GTK_IS_WIDGET (widget));
11359 g_return_if_fail (margin <= G_MAXINT16);
11361 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11363 if (aux_info->margin.top == margin)
11366 aux_info->margin.top = margin;
11367 gtk_widget_queue_resize (widget);
11368 g_object_notify (G_OBJECT (widget), "margin-top");
11372 * gtk_widget_get_margin_bottom:
11373 * @widget: a #GtkWidget
11375 * Gets the value of the #GtkWidget:margin-bottom property.
11377 * Returns: The bottom margin of @widget
11380 gtk_widget_get_margin_bottom (GtkWidget *widget)
11382 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11384 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11388 * gtk_widget_set_margin_bottom:
11389 * @widget: a #GtkWidget
11390 * @margin: the bottom margin
11392 * Sets the bottom margin of @widget.
11393 * See the #GtkWidget:margin-bottom property.
11396 gtk_widget_set_margin_bottom (GtkWidget *widget,
11399 GtkWidgetAuxInfo *aux_info;
11401 g_return_if_fail (GTK_IS_WIDGET (widget));
11402 g_return_if_fail (margin <= G_MAXINT16);
11404 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11406 if (aux_info->margin.bottom == margin)
11409 aux_info->margin.bottom = margin;
11410 gtk_widget_queue_resize (widget);
11411 g_object_notify (G_OBJECT (widget), "margin-bottom");
11415 * gtk_widget_get_clipboard:
11416 * @widget: a #GtkWidget
11417 * @selection: a #GdkAtom which identifies the clipboard
11418 * to use. %GDK_SELECTION_CLIPBOARD gives the
11419 * default clipboard. Another common value
11420 * is %GDK_SELECTION_PRIMARY, which gives
11421 * the primary X selection.
11423 * Returns the clipboard object for the given selection to
11424 * be used with @widget. @widget must have a #GdkDisplay
11425 * associated with it, so must be attached to a toplevel
11428 * Return value: (transfer none): the appropriate clipboard object. If no
11429 * clipboard already exists, a new one will
11430 * be created. Once a clipboard object has
11431 * been created, it is persistent for all time.
11436 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11438 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11439 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11441 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11446 * gtk_widget_list_mnemonic_labels:
11447 * @widget: a #GtkWidget
11449 * Returns a newly allocated list of the widgets, normally labels, for
11450 * which this widget is the target of a mnemonic (see for example,
11451 * gtk_label_set_mnemonic_widget()).
11453 * The widgets in the list are not individually referenced. If you
11454 * want to iterate through the list and perform actions involving
11455 * callbacks that might destroy the widgets, you
11456 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11457 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11458 * widgets afterwards.
11460 * Return value: (element-type GtkWidget) (transfer container): the list of
11461 * mnemonic labels; free this list
11462 * with g_list_free() when you are done with it.
11467 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11469 GList *list = NULL;
11472 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11474 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11475 list = g_list_prepend (list, l->data);
11481 * gtk_widget_add_mnemonic_label:
11482 * @widget: a #GtkWidget
11483 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11485 * Adds a widget to the list of mnemonic labels for
11486 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11487 * list of mnemonic labels for the widget is cleared when the
11488 * widget is destroyed, so the caller must make sure to update
11489 * its internal state at this point as well, by using a connection
11490 * to the #GtkWidget::destroy signal or a weak notifier.
11495 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11498 GSList *old_list, *new_list;
11500 g_return_if_fail (GTK_IS_WIDGET (widget));
11501 g_return_if_fail (GTK_IS_WIDGET (label));
11503 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11504 new_list = g_slist_prepend (old_list, label);
11506 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11507 new_list, (GDestroyNotify) g_slist_free);
11511 * gtk_widget_remove_mnemonic_label:
11512 * @widget: a #GtkWidget
11513 * @label: a #GtkWidget that was previously set as a mnemnic label for
11514 * @widget with gtk_widget_add_mnemonic_label().
11516 * Removes a widget from the list of mnemonic labels for
11517 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11518 * must have previously been added to the list with
11519 * gtk_widget_add_mnemonic_label().
11524 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11527 GSList *old_list, *new_list;
11529 g_return_if_fail (GTK_IS_WIDGET (widget));
11530 g_return_if_fail (GTK_IS_WIDGET (label));
11532 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11533 new_list = g_slist_remove (old_list, label);
11536 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11537 new_list, (GDestroyNotify) g_slist_free);
11541 * gtk_widget_get_no_show_all:
11542 * @widget: a #GtkWidget
11544 * Returns the current value of the GtkWidget:no-show-all property,
11545 * which determines whether calls to gtk_widget_show_all() and
11546 * gtk_widget_hide_all() will affect this widget.
11548 * Return value: the current value of the "no-show-all" property.
11553 gtk_widget_get_no_show_all (GtkWidget *widget)
11555 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11557 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11561 * gtk_widget_set_no_show_all:
11562 * @widget: a #GtkWidget
11563 * @no_show_all: the new value for the "no-show-all" property
11565 * Sets the #GtkWidget:no-show-all property, which determines whether
11566 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11569 * This is mostly for use in constructing widget hierarchies with externally
11570 * controlled visibility, see #GtkUIManager.
11575 gtk_widget_set_no_show_all (GtkWidget *widget,
11576 gboolean no_show_all)
11578 g_return_if_fail (GTK_IS_WIDGET (widget));
11580 no_show_all = (no_show_all != FALSE);
11582 if (no_show_all == gtk_widget_get_no_show_all (widget))
11586 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11588 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11590 g_object_notify (G_OBJECT (widget), "no-show-all");
11595 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11596 gboolean has_tooltip,
11599 GtkWidgetPrivate *priv = widget->priv;
11600 gboolean priv_has_tooltip;
11602 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11603 quark_has_tooltip));
11605 if (priv_has_tooltip != has_tooltip || force)
11607 priv_has_tooltip = has_tooltip;
11609 if (priv_has_tooltip)
11611 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11612 gdk_window_set_events (priv->window,
11613 gdk_window_get_events (priv->window) |
11614 GDK_LEAVE_NOTIFY_MASK |
11615 GDK_POINTER_MOTION_MASK |
11616 GDK_POINTER_MOTION_HINT_MASK);
11618 if (gtk_widget_get_has_window (widget))
11619 gtk_widget_add_events (widget,
11620 GDK_LEAVE_NOTIFY_MASK |
11621 GDK_POINTER_MOTION_MASK |
11622 GDK_POINTER_MOTION_HINT_MASK);
11625 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11626 GUINT_TO_POINTER (priv_has_tooltip));
11631 * gtk_widget_set_tooltip_window:
11632 * @widget: a #GtkWidget
11633 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11635 * Replaces the default, usually yellow, window used for displaying
11636 * tooltips with @custom_window. GTK+ will take care of showing and
11637 * hiding @custom_window at the right moment, to behave likewise as
11638 * the default tooltip window. If @custom_window is %NULL, the default
11639 * tooltip window will be used.
11641 * If the custom window should have the default theming it needs to
11642 * have the name "gtk-tooltip", see gtk_widget_set_name().
11647 gtk_widget_set_tooltip_window (GtkWidget *widget,
11648 GtkWindow *custom_window)
11650 gboolean has_tooltip;
11651 gchar *tooltip_markup;
11653 g_return_if_fail (GTK_IS_WIDGET (widget));
11654 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11656 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11659 g_object_ref (custom_window);
11661 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11662 custom_window, g_object_unref);
11664 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11665 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11667 if (has_tooltip && gtk_widget_get_visible (widget))
11668 gtk_widget_queue_tooltip_query (widget);
11672 * gtk_widget_get_tooltip_window:
11673 * @widget: a #GtkWidget
11675 * Returns the #GtkWindow of the current tooltip. This can be the
11676 * GtkWindow created by default, or the custom tooltip window set
11677 * using gtk_widget_set_tooltip_window().
11679 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11684 gtk_widget_get_tooltip_window (GtkWidget *widget)
11686 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11688 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11692 * gtk_widget_trigger_tooltip_query:
11693 * @widget: a #GtkWidget
11695 * Triggers a tooltip query on the display where the toplevel of @widget
11696 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11702 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11704 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11707 static guint tooltip_query_id;
11708 static GSList *tooltip_query_displays;
11711 tooltip_query_idle (gpointer data)
11713 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11714 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11715 g_slist_free (tooltip_query_displays);
11717 tooltip_query_displays = NULL;
11718 tooltip_query_id = 0;
11724 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11726 GdkDisplay *display;
11728 display = gtk_widget_get_display (widget);
11730 if (!g_slist_find (tooltip_query_displays, display))
11731 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11733 if (tooltip_query_id == 0)
11734 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11738 * gtk_widget_set_tooltip_text:
11739 * @widget: a #GtkWidget
11740 * @text: the contents of the tooltip for @widget
11742 * Sets @text as the contents of the tooltip. This function will take
11743 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11744 * handler for the GtkWidget::query-tooltip signal.
11746 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11751 gtk_widget_set_tooltip_text (GtkWidget *widget,
11754 g_return_if_fail (GTK_IS_WIDGET (widget));
11756 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11760 * gtk_widget_get_tooltip_text:
11761 * @widget: a #GtkWidget
11763 * Gets the contents of the tooltip for @widget.
11765 * Return value: the tooltip text, or %NULL. You should free the
11766 * returned string with g_free() when done.
11771 gtk_widget_get_tooltip_text (GtkWidget *widget)
11773 gchar *text = NULL;
11775 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11777 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11783 * gtk_widget_set_tooltip_markup:
11784 * @widget: a #GtkWidget
11785 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11787 * Sets @markup as the contents of the tooltip, which is marked up with
11788 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11790 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11791 * and of the default handler for the GtkWidget::query-tooltip signal.
11793 * See also the GtkWidget:tooltip-markup property and
11794 * gtk_tooltip_set_markup().
11799 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11800 const gchar *markup)
11802 g_return_if_fail (GTK_IS_WIDGET (widget));
11804 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11808 * gtk_widget_get_tooltip_markup:
11809 * @widget: a #GtkWidget
11811 * Gets the contents of the tooltip for @widget.
11813 * Return value: the tooltip text, or %NULL. You should free the
11814 * returned string with g_free() when done.
11819 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11821 gchar *text = NULL;
11823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11825 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11831 * gtk_widget_set_has_tooltip:
11832 * @widget: a #GtkWidget
11833 * @has_tooltip: whether or not @widget has a tooltip.
11835 * Sets the has-tooltip property on @widget to @has_tooltip. See
11836 * GtkWidget:has-tooltip for more information.
11841 gtk_widget_set_has_tooltip (GtkWidget *widget,
11842 gboolean has_tooltip)
11844 g_return_if_fail (GTK_IS_WIDGET (widget));
11846 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11850 * gtk_widget_get_has_tooltip:
11851 * @widget: a #GtkWidget
11853 * Returns the current value of the has-tooltip property. See
11854 * GtkWidget:has-tooltip for more information.
11856 * Return value: current value of has-tooltip on @widget.
11861 gtk_widget_get_has_tooltip (GtkWidget *widget)
11863 gboolean has_tooltip = FALSE;
11865 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11867 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11869 return has_tooltip;
11873 * gtk_widget_get_allocation:
11874 * @widget: a #GtkWidget
11875 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11877 * Retrieves the widget's allocation.
11879 * Note, when implementing a #GtkContainer: a widget's allocation will
11880 * be its "adjusted" allocation, that is, the widget's parent
11881 * container typically calls gtk_widget_size_allocate() with an
11882 * allocation, and that allocation is then adjusted (to handle margin
11883 * and alignment for example) before assignment to the widget.
11884 * gtk_widget_get_allocation() returns the adjusted allocation that
11885 * was actually assigned to the widget. The adjusted allocation is
11886 * guaranteed to be completely contained within the
11887 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11888 * is guaranteed that its children stay inside the assigned bounds,
11889 * but not that they have exactly the bounds the container assigned.
11890 * There is no way to get the original allocation assigned by
11891 * gtk_widget_size_allocate(), since it isn't stored; if a container
11892 * implementation needs that information it will have to track it itself.
11897 gtk_widget_get_allocation (GtkWidget *widget,
11898 GtkAllocation *allocation)
11900 GtkWidgetPrivate *priv;
11902 g_return_if_fail (GTK_IS_WIDGET (widget));
11903 g_return_if_fail (allocation != NULL);
11905 priv = widget->priv;
11907 *allocation = priv->allocation;
11911 * gtk_widget_set_allocation:
11912 * @widget: a #GtkWidget
11913 * @allocation: a pointer to a #GtkAllocation to copy from
11915 * Sets the widget's allocation. This should not be used
11916 * directly, but from within a widget's size_allocate method.
11918 * The allocation set should be the "adjusted" or actual
11919 * allocation. If you're implementing a #GtkContainer, you want to use
11920 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
11921 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
11922 * allocation inside gtk_widget_size_allocate() to create an adjusted
11928 gtk_widget_set_allocation (GtkWidget *widget,
11929 const GtkAllocation *allocation)
11931 GtkWidgetPrivate *priv;
11933 g_return_if_fail (GTK_IS_WIDGET (widget));
11934 g_return_if_fail (allocation != NULL);
11936 priv = widget->priv;
11938 priv->allocation = *allocation;
11942 * gtk_widget_get_allocated_width:
11943 * @widget: the widget to query
11945 * Returns the width that has currently been allocated to @widget.
11946 * This function is intended to be used when implementing handlers
11947 * for the GtkWidget::draw function.
11949 * Returns: the width of the @widget
11952 gtk_widget_get_allocated_width (GtkWidget *widget)
11954 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11956 return widget->priv->allocation.width;
11960 * gtk_widget_get_allocated_height:
11961 * @widget: the widget to query
11963 * Returns the height that has currently been allocated to @widget.
11964 * This function is intended to be used when implementing handlers
11965 * for the GtkWidget::draw function.
11967 * Returns: the height of the @widget
11970 gtk_widget_get_allocated_height (GtkWidget *widget)
11972 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11974 return widget->priv->allocation.height;
11978 * gtk_widget_get_requisition:
11979 * @widget: a #GtkWidget
11980 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11982 * Retrieves the widget's requisition.
11984 * This function should only be used by widget implementations in
11985 * order to figure whether the widget's requisition has actually
11986 * changed after some internal state change (so that they can call
11987 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11989 * Normally, gtk_widget_size_request() should be used.
11993 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
11994 * removed, If you need to cache sizes across requests and allocations,
11995 * add an explicit cache to the widget in question instead.
11998 gtk_widget_get_requisition (GtkWidget *widget,
11999 GtkRequisition *requisition)
12001 g_return_if_fail (GTK_IS_WIDGET (widget));
12002 g_return_if_fail (requisition != NULL);
12004 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12008 * gtk_widget_set_window:
12009 * @widget: a #GtkWidget
12010 * @window: a #GdkWindow
12012 * Sets a widget's window. This function should only be used in a
12013 * widget's GtkWidget::realize() implementation. The %window passed is
12014 * usually either new window created with gdk_window_new(), or the
12015 * window of its parent widget as returned by
12016 * gtk_widget_get_parent_window().
12018 * Widgets must indicate whether they will create their own #GdkWindow
12019 * by calling gtk_widget_set_has_window(). This is usually done in the
12020 * widget's init() function.
12022 * <note><para>This function does not add any reference to @window.</para></note>
12027 gtk_widget_set_window (GtkWidget *widget,
12030 GtkWidgetPrivate *priv;
12032 g_return_if_fail (GTK_IS_WIDGET (widget));
12033 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12035 priv = widget->priv;
12037 if (priv->window != window)
12039 priv->window = window;
12040 g_object_notify (G_OBJECT (widget), "window");
12045 * gtk_widget_get_window:
12046 * @widget: a #GtkWidget
12048 * Returns the widget's window if it is realized, %NULL otherwise
12050 * Return value: (transfer none): @widget's window.
12055 gtk_widget_get_window (GtkWidget *widget)
12057 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12059 return widget->priv->window;
12063 * gtk_widget_get_support_multidevice:
12064 * @widget: a #GtkWidget
12066 * Returns %TRUE if @widget is multiple pointer aware. See
12067 * gtk_widget_set_support_multidevice() for more information.
12069 * Returns: %TRUE is @widget is multidevice aware.
12072 gtk_widget_get_support_multidevice (GtkWidget *widget)
12074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12076 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12080 * gtk_widget_set_support_multidevice:
12081 * @widget: a #GtkWidget
12082 * @support_multidevice: %TRUE to support input from multiple devices.
12084 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12085 * @widget will start receiving multiple, per device enter/leave events. Note
12086 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12087 * gdk_window_set_support_multidevice() will have to be called manually on them.
12092 gtk_widget_set_support_multidevice (GtkWidget *widget,
12093 gboolean support_multidevice)
12095 GtkWidgetPrivate *priv;
12097 g_return_if_fail (GTK_IS_WIDGET (widget));
12099 priv = widget->priv;
12101 if (support_multidevice)
12103 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12104 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12108 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12109 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12112 if (gtk_widget_get_realized (widget))
12113 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12117 _gtk_widget_set_has_focus (GtkWidget *widget,
12118 gboolean has_focus)
12121 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12123 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12127 * gtk_widget_send_focus_change:
12128 * @widget: a #GtkWidget
12129 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12131 * Sends the focus change @event to @widget
12133 * This function is not meant to be used by applications. The only time it
12134 * should be used is when it is necessary for a #GtkWidget to assign focus
12135 * to a widget that is semantically owned by the first widget even though
12136 * it's not a direct child - for instance, a search entry in a floating
12137 * window similar to the quick search in #GtkTreeView.
12139 * An example of its usage is:
12142 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12144 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12145 * fevent->focus_change.in = TRUE;
12146 * fevent->focus_change.window = gtk_widget_get_window (widget);
12147 * if (fevent->focus_change.window != NULL)
12148 * g_object_ref (fevent->focus_change.window);
12150 * gtk_widget_send_focus_change (widget, fevent);
12152 * gdk_event_free (event);
12155 * Return value: the return value from the event signal emission: %TRUE
12156 * if the event was handled, and %FALSE otherwise
12161 gtk_widget_send_focus_change (GtkWidget *widget,
12166 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12167 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12169 g_object_ref (widget);
12171 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12173 res = gtk_widget_event (widget, event);
12175 g_object_notify (G_OBJECT (widget), "has-focus");
12177 g_object_unref (widget);