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 "gdk/gdkkeysyms.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
63 * @Short_description: Base class for all widgets
66 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
67 * widget lifecycle, states and style.
69 * <refsect2 id="style-properties">
71 * <structname>GtkWidget</structname> introduces <firstterm>style
72 * properties</firstterm> - these are basically object properties that are stored
73 * not on the object, but in the style object associated to the widget. Style
74 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
75 * This mechanism is used for configuring such things as the location of the
76 * scrollbar arrows through the theme, giving theme authors more control over the
77 * look of applications without the need to write a theme engine in C.
80 * Use gtk_widget_class_install_style_property() to install style properties for
81 * a widget class, gtk_widget_class_find_style_property() or
82 * gtk_widget_class_list_style_properties() to get information about existing
83 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
84 * gtk_widget_style_get_valist() to obtain the value of a style property.
87 * <refsect2 id="GtkWidget-BUILDER-UI">
88 * <title>GtkWidget as GtkBuildable</title>
90 * The GtkWidget implementation of the GtkBuildable interface supports a
91 * custom <accelerator> element, which has attributes named key,
92 * modifiers and signal and allows to specify accelerators.
95 * <title>A UI definition fragment specifying an accelerator</title>
96 * <programlisting><![CDATA[
97 * <object class="GtkButton">
98 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
100 * ]]></programlisting>
103 * In addition to accelerators, <structname>GtkWidget</structname> also support a
104 * custom <accessible> element, which supports actions and relations.
105 * Properties on the accessible implementation of an object can be set by accessing the
106 * internal child "accessible" of a <structname>GtkWidget</structname>.
109 * <title>A UI definition fragment specifying an accessible</title>
110 * <programlisting><![CDATA[
111 * <object class="GtkButton" id="label1"/>
112 * <property name="label">I am a Label for a Button</property>
114 * <object class="GtkButton" id="button1">
116 * <action action_name="click" translatable="yes">Click the button.</action>
117 * <relation target="label1" type="labelled-by"/>
119 * <child internal-child="accessible">
120 * <object class="AtkObject" id="a11y-button1">
121 * <property name="AtkObject::name">Clickable Button</property>
125 * ]]></programlisting>
130 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
131 #define INIT_PATH_SIZE (512)
133 struct _GtkWidgetPrivate
135 /* The state of the widget. There are actually only
136 * 5 widget states (defined in "gtkenums.h")
141 /* The saved state of the widget. When a widget's state
142 * is changed to GTK_STATE_INSENSITIVE via
143 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
144 * the old state is kept around in this field. The state
145 * will be restored once the widget gets sensitive again.
147 guint saved_state : 3;
149 /* unused bits in our 32-bit block */
152 /* The widget's name. If the widget does not have a name
153 * (the name is NULL), then its name (as returned by
154 * "gtk_widget_get_name") is its class's name.
155 * Among other things, the widget name is used to determine
156 * the style to use for a widget.
160 /* The style for the widget. The style contains the
161 * colors the widget should be drawn in for each state
162 * along with graphics contexts used to draw with and
163 * the font to use for text.
167 /* The widget's allocated size.
169 GtkAllocation allocation;
171 /* The widget's requested sizes */
172 SizeRequestCache requests;
174 /* The widget's window or its parent window if it does
175 * not have a window. (Which will be indicated by the
176 * GTK_NO_WINDOW flag being set).
180 /* The widget's parent.
208 BUTTON_RELEASE_EVENT,
223 PROPERTY_NOTIFY_EVENT,
224 SELECTION_CLEAR_EVENT,
225 SELECTION_REQUEST_EVENT,
226 SELECTION_NOTIFY_EVENT,
241 VISIBILITY_NOTIFY_EVENT,
245 ACCEL_CLOSURES_CHANGED,
271 PROP_RECEIVES_DEFAULT,
272 PROP_COMPOSITE_CHILD,
275 PROP_EXTENSION_EVENTS,
281 PROP_DOUBLE_BUFFERED,
291 typedef struct _GtkStateData GtkStateData;
296 guint state_restoration : 1;
297 guint parent_sensitive : 1;
298 guint use_forall : 1;
301 /* --- prototypes --- */
302 static void gtk_widget_class_init (GtkWidgetClass *klass);
303 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
304 static void gtk_widget_init (GtkWidget *widget);
305 static void gtk_widget_set_property (GObject *object,
309 static void gtk_widget_get_property (GObject *object,
313 static void gtk_widget_dispose (GObject *object);
314 static void gtk_widget_real_destroy (GtkObject *object);
315 static void gtk_widget_finalize (GObject *object);
316 static void gtk_widget_real_show (GtkWidget *widget);
317 static void gtk_widget_real_hide (GtkWidget *widget);
318 static void gtk_widget_real_map (GtkWidget *widget);
319 static void gtk_widget_real_unmap (GtkWidget *widget);
320 static void gtk_widget_real_realize (GtkWidget *widget);
321 static void gtk_widget_real_unrealize (GtkWidget *widget);
322 static void gtk_widget_real_size_request (GtkWidget *widget,
323 GtkRequisition *requisition);
324 static void gtk_widget_real_size_allocate (GtkWidget *widget,
325 GtkAllocation *allocation);
326 static void gtk_widget_real_style_set (GtkWidget *widget,
327 GtkStyle *previous_style);
328 static void gtk_widget_real_direction_changed(GtkWidget *widget,
329 GtkTextDirection previous_direction);
331 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
332 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
335 gboolean keyboard_tip,
336 GtkTooltip *tooltip);
337 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
338 GtkWidgetHelpType help_type);
340 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
342 GParamSpec **pspecs);
343 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
345 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
347 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
348 GdkEventFocus *event);
349 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
350 GdkEventFocus *event);
351 static gboolean gtk_widget_real_focus (GtkWidget *widget,
352 GtkDirectionType direction);
353 static void gtk_widget_real_move_focus (GtkWidget *widget,
354 GtkDirectionType direction);
355 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
356 GtkDirectionType direction);
357 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
358 static void gtk_widget_update_pango_context (GtkWidget *widget);
359 static void gtk_widget_propagate_state (GtkWidget *widget,
361 static void gtk_widget_reset_rc_style (GtkWidget *widget);
362 static void gtk_widget_set_style_internal (GtkWidget *widget,
364 gboolean initial_emission);
365 static gint gtk_widget_event_internal (GtkWidget *widget,
367 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
368 gboolean group_cycling);
369 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
370 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
371 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
372 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
373 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
374 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
375 cairo_region_t *region);
376 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
377 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
378 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
381 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
382 gboolean has_tooltip,
384 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
385 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
387 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
388 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
390 const gchar *childname);
391 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
394 const GValue *value);
395 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
398 const gchar *tagname,
399 GMarkupParser *parser,
401 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
404 const gchar *tagname,
406 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
407 GtkBuilder *builder);
409 static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
410 static void gtk_widget_real_get_width (GtkSizeRequest *widget,
413 static void gtk_widget_real_get_height (GtkSizeRequest *widget,
417 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
420 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
421 GtkOrientation orientation,
425 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
426 GtkAllocation *allocation);
428 static void gtk_widget_set_usize_internal (GtkWidget *widget,
432 static void gtk_widget_add_events_internal (GtkWidget *widget,
436 /* --- variables --- */
437 static gpointer gtk_widget_parent_class = NULL;
438 static guint widget_signals[LAST_SIGNAL] = { 0 };
439 static GtkStyle *gtk_default_style = NULL;
440 static GSList *colormap_stack = NULL;
441 static guint composite_child_stack = 0;
442 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
443 static GParamSpecPool *style_property_spec_pool = NULL;
445 static GQuark quark_property_parser = 0;
446 static GQuark quark_aux_info = 0;
447 static GQuark quark_accel_path = 0;
448 static GQuark quark_accel_closures = 0;
449 static GQuark quark_event_mask = 0;
450 static GQuark quark_device_event_mask = 0;
451 static GQuark quark_extension_event_mode = 0;
452 static GQuark quark_parent_window = 0;
453 static GQuark quark_pointer_window = 0;
454 static GQuark quark_shape_info = 0;
455 static GQuark quark_input_shape_info = 0;
456 static GQuark quark_colormap = 0;
457 static GQuark quark_pango_context = 0;
458 static GQuark quark_rc_style = 0;
459 static GQuark quark_accessible_object = 0;
460 static GQuark quark_mnemonic_labels = 0;
461 static GQuark quark_tooltip_markup = 0;
462 static GQuark quark_has_tooltip = 0;
463 static GQuark quark_tooltip_window = 0;
464 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
465 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
467 /* --- functions --- */
469 gtk_widget_get_type (void)
471 static GType widget_type = 0;
473 if (G_UNLIKELY (widget_type == 0))
475 const GTypeInfo widget_info =
477 sizeof (GtkWidgetClass),
478 NULL, /* base_init */
479 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
480 (GClassInitFunc) gtk_widget_class_init,
481 NULL, /* class_finalize */
482 NULL, /* class_init */
485 (GInstanceInitFunc) gtk_widget_init,
486 NULL, /* value_table */
489 const GInterfaceInfo accessibility_info =
491 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
492 (GInterfaceFinalizeFunc) NULL,
493 NULL /* interface data */
496 const GInterfaceInfo buildable_info =
498 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
499 (GInterfaceFinalizeFunc) NULL,
500 NULL /* interface data */
503 const GInterfaceInfo layout_info =
505 (GInterfaceInitFunc) gtk_widget_size_request_init,
506 (GInterfaceFinalizeFunc) NULL,
507 NULL /* interface data */
510 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
511 &widget_info, G_TYPE_FLAG_ABSTRACT);
513 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
514 &accessibility_info) ;
515 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
517 g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
525 child_property_notify_dispatcher (GObject *object,
529 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
533 gtk_widget_class_init (GtkWidgetClass *klass)
535 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
536 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
537 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
538 GtkBindingSet *binding_set;
540 gtk_widget_parent_class = g_type_class_peek_parent (klass);
542 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
543 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
544 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
545 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
546 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
547 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
548 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
549 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
550 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
551 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
552 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
553 quark_colormap = g_quark_from_static_string ("gtk-colormap");
554 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
555 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
556 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
557 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
558 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
559 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
560 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
562 style_property_spec_pool = g_param_spec_pool_new (FALSE);
563 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
564 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
565 cpn_context.dispatcher = child_property_notify_dispatcher;
566 _gtk_widget_child_property_notify_context = &cpn_context;
568 gobject_class->dispose = gtk_widget_dispose;
569 gobject_class->finalize = gtk_widget_finalize;
570 gobject_class->set_property = gtk_widget_set_property;
571 gobject_class->get_property = gtk_widget_get_property;
573 object_class->destroy = gtk_widget_real_destroy;
575 klass->activate_signal = 0;
576 klass->set_scroll_adjustments_signal = 0;
577 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
578 klass->show = gtk_widget_real_show;
579 klass->show_all = gtk_widget_show;
580 klass->hide = gtk_widget_real_hide;
581 klass->hide_all = gtk_widget_hide;
582 klass->map = gtk_widget_real_map;
583 klass->unmap = gtk_widget_real_unmap;
584 klass->realize = gtk_widget_real_realize;
585 klass->unrealize = gtk_widget_real_unrealize;
586 klass->size_request = gtk_widget_real_size_request;
587 klass->size_allocate = gtk_widget_real_size_allocate;
588 klass->state_changed = NULL;
589 klass->parent_set = NULL;
590 klass->hierarchy_changed = NULL;
591 klass->style_set = gtk_widget_real_style_set;
592 klass->direction_changed = gtk_widget_real_direction_changed;
593 klass->grab_notify = NULL;
594 klass->child_notify = NULL;
595 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
596 klass->grab_focus = gtk_widget_real_grab_focus;
597 klass->focus = gtk_widget_real_focus;
599 klass->button_press_event = NULL;
600 klass->button_release_event = NULL;
601 klass->motion_notify_event = NULL;
602 klass->delete_event = NULL;
603 klass->destroy_event = NULL;
604 klass->expose_event = NULL;
605 klass->key_press_event = gtk_widget_real_key_press_event;
606 klass->key_release_event = gtk_widget_real_key_release_event;
607 klass->enter_notify_event = NULL;
608 klass->leave_notify_event = NULL;
609 klass->configure_event = NULL;
610 klass->focus_in_event = gtk_widget_real_focus_in_event;
611 klass->focus_out_event = gtk_widget_real_focus_out_event;
612 klass->map_event = NULL;
613 klass->unmap_event = NULL;
614 klass->window_state_event = NULL;
615 klass->property_notify_event = _gtk_selection_property_notify;
616 klass->selection_clear_event = _gtk_selection_clear;
617 klass->selection_request_event = _gtk_selection_request;
618 klass->selection_notify_event = _gtk_selection_notify;
619 klass->selection_received = NULL;
620 klass->proximity_in_event = NULL;
621 klass->proximity_out_event = NULL;
622 klass->drag_begin = NULL;
623 klass->drag_end = NULL;
624 klass->drag_data_delete = NULL;
625 klass->drag_leave = NULL;
626 klass->drag_motion = NULL;
627 klass->drag_drop = NULL;
628 klass->drag_data_received = NULL;
629 klass->screen_changed = NULL;
630 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
631 klass->grab_broken_event = NULL;
632 klass->query_tooltip = gtk_widget_real_query_tooltip;
634 klass->show_help = gtk_widget_real_show_help;
636 /* Accessibility support */
637 klass->get_accessible = gtk_widget_real_get_accessible;
639 klass->no_expose_event = NULL;
641 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
642 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
644 g_object_class_install_property (gobject_class,
646 g_param_spec_string ("name",
648 P_("The name of the widget"),
650 GTK_PARAM_READWRITE));
651 g_object_class_install_property (gobject_class,
653 g_param_spec_object ("parent",
655 P_("The parent widget of this widget. Must be a Container widget"),
657 GTK_PARAM_READWRITE));
659 g_object_class_install_property (gobject_class,
661 g_param_spec_int ("width-request",
663 P_("Override for width request of the widget, or -1 if natural request should be used"),
667 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
670 g_param_spec_int ("height-request",
671 P_("Height request"),
672 P_("Override for height request of the widget, or -1 if natural request should be used"),
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_boolean ("visible",
681 P_("Whether the widget is visible"),
683 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_boolean ("sensitive",
688 P_("Whether the widget responds to input"),
690 GTK_PARAM_READWRITE));
691 g_object_class_install_property (gobject_class,
693 g_param_spec_boolean ("app-paintable",
694 P_("Application paintable"),
695 P_("Whether the application will paint directly on the widget"),
697 GTK_PARAM_READWRITE));
698 g_object_class_install_property (gobject_class,
700 g_param_spec_boolean ("can-focus",
702 P_("Whether the widget can accept the input focus"),
704 GTK_PARAM_READWRITE));
705 g_object_class_install_property (gobject_class,
707 g_param_spec_boolean ("has-focus",
709 P_("Whether the widget has the input focus"),
711 GTK_PARAM_READWRITE));
712 g_object_class_install_property (gobject_class,
714 g_param_spec_boolean ("is-focus",
716 P_("Whether the widget is the focus widget within the toplevel"),
718 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_boolean ("can-default",
723 P_("Whether the widget can be the default widget"),
725 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_boolean ("has-default",
730 P_("Whether the widget is the default widget"),
732 GTK_PARAM_READWRITE));
733 g_object_class_install_property (gobject_class,
734 PROP_RECEIVES_DEFAULT,
735 g_param_spec_boolean ("receives-default",
736 P_("Receives default"),
737 P_("If TRUE, the widget will receive the default action when it is focused"),
739 GTK_PARAM_READWRITE));
740 g_object_class_install_property (gobject_class,
741 PROP_COMPOSITE_CHILD,
742 g_param_spec_boolean ("composite-child",
743 P_("Composite child"),
744 P_("Whether the widget is part of a composite widget"),
746 GTK_PARAM_READABLE));
747 g_object_class_install_property (gobject_class,
749 g_param_spec_object ("style",
751 P_("The style of the widget, which contains information about how it will look (colors etc)"),
753 GTK_PARAM_READWRITE));
754 g_object_class_install_property (gobject_class,
756 g_param_spec_flags ("events",
758 P_("The event mask that decides what kind of GdkEvents this widget gets"),
761 GTK_PARAM_READWRITE));
762 g_object_class_install_property (gobject_class,
763 PROP_EXTENSION_EVENTS,
764 g_param_spec_enum ("extension-events",
765 P_("Extension events"),
766 P_("The mask that decides what kind of extension events this widget gets"),
767 GDK_TYPE_EXTENSION_MODE,
768 GDK_EXTENSION_EVENTS_NONE,
769 GTK_PARAM_READWRITE));
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("no-show-all",
774 P_("Whether gtk_widget_show_all() should not affect this widget"),
776 GTK_PARAM_READWRITE));
779 * GtkWidget:has-tooltip:
781 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
782 * A value of %TRUE indicates that @widget can have a tooltip, in this case
783 * the widget will be queried using #GtkWidget::query-tooltip to determine
784 * whether it will provide a tooltip or not.
786 * Note that setting this property to %TRUE for the first time will change
787 * the event masks of the GdkWindows of this widget to include leave-notify
788 * and motion-notify events. This cannot and will not be undone when the
789 * property is set to %FALSE again.
793 g_object_class_install_property (gobject_class,
795 g_param_spec_boolean ("has-tooltip",
797 P_("Whether this widget has a tooltip"),
799 GTK_PARAM_READWRITE));
801 * GtkWidget:tooltip-text:
803 * Sets the text of tooltip to be the given string.
805 * Also see gtk_tooltip_set_text().
807 * This is a convenience property which will take care of getting the
808 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
809 * will automatically be set to %TRUE and there will be taken care of
810 * #GtkWidget::query-tooltip in the default signal handler.
814 g_object_class_install_property (gobject_class,
816 g_param_spec_string ("tooltip-text",
818 P_("The contents of the tooltip for this widget"),
820 GTK_PARAM_READWRITE));
822 * GtkWidget:tooltip-markup:
824 * Sets the text of tooltip to be the given string, which is marked up
825 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
826 * Also see gtk_tooltip_set_markup().
828 * This is a convenience property which will take care of getting the
829 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
830 * will automatically be set to %TRUE and there will be taken care of
831 * #GtkWidget::query-tooltip in the default signal handler.
835 g_object_class_install_property (gobject_class,
837 g_param_spec_string ("tooltip-markup",
838 P_("Tooltip markup"),
839 P_("The contents of the tooltip for this widget"),
841 GTK_PARAM_READWRITE));
846 * The widget's window if it is realized, %NULL otherwise.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_object ("window",
854 P_("The widget's window if it is realized"),
856 GTK_PARAM_READABLE));
859 * GtkWidget:double-buffered
861 * Whether the widget is double buffered.
865 g_object_class_install_property (gobject_class,
866 PROP_DOUBLE_BUFFERED,
867 g_param_spec_boolean ("double-buffered",
868 P_("Double Buffered"),
869 P_("Whether the widget is double buffered"),
871 GTK_PARAM_READWRITE));
876 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
880 g_object_class_install_property (gobject_class,
882 g_param_spec_enum ("halign",
883 P_("Horizontal Alignment"),
884 P_("How to position in extra horizontal space"),
887 GTK_PARAM_READWRITE));
892 * How to distribute vertical space if widget gets extra space, see #GtkAlign
896 g_object_class_install_property (gobject_class,
898 g_param_spec_enum ("valign",
899 P_("Vertical Alignment"),
900 P_("How to position in extra vertical space"),
903 GTK_PARAM_READWRITE));
906 * GtkWidget:margin-left
908 * Margin on left side of widget.
910 * This property adds margin outside of the widget's normal size
911 * request, the margin will be added in addition to the size from
912 * gtk_widget_set_size_request() for example.
916 g_object_class_install_property (gobject_class,
918 g_param_spec_int ("margin-left",
919 P_("Margin on Left"),
920 P_("Pixels of extra space on the left side"),
924 GTK_PARAM_READWRITE));
927 * GtkWidget:margin-right
929 * Margin on right side of widget.
931 * This property adds margin outside of the widget's normal size
932 * request, the margin will be added in addition to the size from
933 * gtk_widget_set_size_request() for example.
937 g_object_class_install_property (gobject_class,
939 g_param_spec_int ("margin-right",
940 P_("Margin on Right"),
941 P_("Pixels of extra space on the right side"),
945 GTK_PARAM_READWRITE));
948 * GtkWidget:margin-top
950 * Margin on top side of widget.
952 * This property adds margin outside of the widget's normal size
953 * request, the margin will be added in addition to the size from
954 * gtk_widget_set_size_request() for example.
958 g_object_class_install_property (gobject_class,
960 g_param_spec_int ("margin-top",
962 P_("Pixels of extra space on the top side"),
966 GTK_PARAM_READWRITE));
969 * GtkWidget:margin-bottom
971 * Margin on bottom side of widget.
973 * This property adds margin outside of the widget's normal size
974 * request, the margin will be added in addition to the size from
975 * gtk_widget_set_size_request() for example.
979 g_object_class_install_property (gobject_class,
981 g_param_spec_int ("margin-bottom",
982 P_("Margin on Bottom"),
983 P_("Pixels of extra space on the bottom side"),
987 GTK_PARAM_READWRITE));
992 * Sets all four sides' margin at once. If read, returns max
993 * margin on any side.
997 g_object_class_install_property (gobject_class,
999 g_param_spec_int ("margin",
1001 P_("Pixels of extra space on all four sides"),
1005 GTK_PARAM_READWRITE));
1009 * @widget: the object which received the signal.
1011 widget_signals[SHOW] =
1012 g_signal_new (I_("show"),
1013 G_TYPE_FROM_CLASS (gobject_class),
1015 G_STRUCT_OFFSET (GtkWidgetClass, show),
1017 _gtk_marshal_VOID__VOID,
1022 * @widget: the object which received the signal.
1024 widget_signals[HIDE] =
1025 g_signal_new (I_("hide"),
1026 G_TYPE_FROM_CLASS (gobject_class),
1028 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1030 _gtk_marshal_VOID__VOID,
1035 * @widget: the object which received the signal.
1037 widget_signals[MAP] =
1038 g_signal_new (I_("map"),
1039 G_TYPE_FROM_CLASS (gobject_class),
1041 G_STRUCT_OFFSET (GtkWidgetClass, map),
1043 _gtk_marshal_VOID__VOID,
1048 * @widget: the object which received the signal.
1050 widget_signals[UNMAP] =
1051 g_signal_new (I_("unmap"),
1052 G_TYPE_FROM_CLASS (gobject_class),
1054 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1056 _gtk_marshal_VOID__VOID,
1060 * GtkWidget::realize:
1061 * @widget: the object which received the signal.
1063 widget_signals[REALIZE] =
1064 g_signal_new (I_("realize"),
1065 G_TYPE_FROM_CLASS (gobject_class),
1067 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1069 _gtk_marshal_VOID__VOID,
1073 * GtkWidget::unrealize:
1074 * @widget: the object which received the signal.
1076 widget_signals[UNREALIZE] =
1077 g_signal_new (I_("unrealize"),
1078 G_TYPE_FROM_CLASS (gobject_class),
1080 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1082 _gtk_marshal_VOID__VOID,
1086 * GtkWidget::size-request:
1087 * @widget: the object which received the signal.
1090 widget_signals[SIZE_REQUEST] =
1091 g_signal_new (I_("size-request"),
1092 G_TYPE_FROM_CLASS (gobject_class),
1094 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1096 _gtk_marshal_VOID__BOXED,
1098 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1101 * GtkWidget::size-allocate:
1102 * @widget: the object which received the signal.
1105 widget_signals[SIZE_ALLOCATE] =
1106 g_signal_new (I_("size-allocate"),
1107 G_TYPE_FROM_CLASS (gobject_class),
1109 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1111 _gtk_marshal_VOID__BOXED,
1113 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1116 * GtkWidget::state-changed:
1117 * @widget: the object which received the signal.
1118 * @state: the previous state
1120 * The ::state-changed signal is emitted when the widget state changes.
1121 * See gtk_widget_get_state().
1123 widget_signals[STATE_CHANGED] =
1124 g_signal_new (I_("state-changed"),
1125 G_TYPE_FROM_CLASS (gobject_class),
1127 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1129 _gtk_marshal_VOID__ENUM,
1131 GTK_TYPE_STATE_TYPE);
1134 * GtkWidget::parent-set:
1135 * @widget: the object on which the signal is emitted
1136 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1137 * just got its initial parent.
1139 * The ::parent-set signal is emitted when a new parent
1140 * has been set on a widget.
1142 widget_signals[PARENT_SET] =
1143 g_signal_new (I_("parent-set"),
1144 G_TYPE_FROM_CLASS (gobject_class),
1146 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1148 _gtk_marshal_VOID__OBJECT,
1153 * GtkWidget::hierarchy-changed:
1154 * @widget: the object on which the signal is emitted
1155 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1156 * if the widget was previously unanchored
1158 * The ::hierarchy-changed signal is emitted when the
1159 * anchored state of a widget changes. A widget is
1160 * <firstterm>anchored</firstterm> when its toplevel
1161 * ancestor is a #GtkWindow. This signal is emitted when
1162 * a widget changes from un-anchored to anchored or vice-versa.
1164 widget_signals[HIERARCHY_CHANGED] =
1165 g_signal_new (I_("hierarchy-changed"),
1166 G_TYPE_FROM_CLASS (gobject_class),
1168 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1170 _gtk_marshal_VOID__OBJECT,
1175 * GtkWidget::style-set:
1176 * @widget: the object on which the signal is emitted
1177 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1178 * just got its initial style
1180 * The ::style-set signal is emitted when a new style has been set
1181 * on a widget. Note that style-modifying functions like
1182 * gtk_widget_modify_base() also cause this signal to be emitted.
1184 widget_signals[STYLE_SET] =
1185 g_signal_new (I_("style-set"),
1186 G_TYPE_FROM_CLASS (gobject_class),
1188 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1190 _gtk_marshal_VOID__OBJECT,
1194 * GtkWidget::direction-changed:
1195 * @widget: the object on which the signal is emitted
1196 * @previous_direction: the previous text direction of @widget
1198 * The ::direction-changed signal is emitted when the text direction
1199 * of a widget changes.
1201 widget_signals[DIRECTION_CHANGED] =
1202 g_signal_new (I_("direction-changed"),
1203 G_TYPE_FROM_CLASS (gobject_class),
1205 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1207 _gtk_marshal_VOID__ENUM,
1209 GTK_TYPE_TEXT_DIRECTION);
1212 * GtkWidget::grab-notify:
1213 * @widget: the object which received the signal
1214 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1215 * if it becomes unshadowed
1217 * The ::grab-notify signal is emitted when a widget becomes
1218 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1219 * another widget, or when it becomes unshadowed due to a grab
1222 * A widget is shadowed by a gtk_grab_add() when the topmost
1223 * grab widget in the grab stack of its window group is not
1226 widget_signals[GRAB_NOTIFY] =
1227 g_signal_new (I_("grab-notify"),
1228 G_TYPE_FROM_CLASS (gobject_class),
1230 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1232 _gtk_marshal_VOID__BOOLEAN,
1237 * GtkWidget::child-notify:
1238 * @widget: the object which received the signal
1239 * @pspec: the #GParamSpec of the changed child property
1241 * The ::child-notify signal is emitted for each
1242 * <link linkend="child-properties">child property</link> that has
1243 * changed on an object. The signal's detail holds the property name.
1245 widget_signals[CHILD_NOTIFY] =
1246 g_signal_new (I_("child-notify"),
1247 G_TYPE_FROM_CLASS (gobject_class),
1248 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1249 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1251 g_cclosure_marshal_VOID__PARAM,
1256 * GtkWidget::mnemonic-activate:
1257 * @widget: the object which received the signal.
1260 widget_signals[MNEMONIC_ACTIVATE] =
1261 g_signal_new (I_("mnemonic-activate"),
1262 G_TYPE_FROM_CLASS (gobject_class),
1264 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1265 _gtk_boolean_handled_accumulator, NULL,
1266 _gtk_marshal_BOOLEAN__BOOLEAN,
1271 * GtkWidget::grab-focus:
1272 * @widget: the object which received the signal.
1274 widget_signals[GRAB_FOCUS] =
1275 g_signal_new (I_("grab-focus"),
1276 G_TYPE_FROM_CLASS (gobject_class),
1277 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1278 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1280 _gtk_marshal_VOID__VOID,
1285 * @widget: the object which received the signal.
1288 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1290 widget_signals[FOCUS] =
1291 g_signal_new (I_("focus"),
1292 G_TYPE_FROM_CLASS (object_class),
1294 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1295 _gtk_boolean_handled_accumulator, NULL,
1296 _gtk_marshal_BOOLEAN__ENUM,
1298 GTK_TYPE_DIRECTION_TYPE);
1301 * GtkWidget::move-focus:
1302 * @widget: the object which received the signal.
1305 widget_signals[MOVE_FOCUS] =
1306 g_signal_new_class_handler (I_("move-focus"),
1307 G_TYPE_FROM_CLASS (object_class),
1308 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1309 G_CALLBACK (gtk_widget_real_move_focus),
1311 _gtk_marshal_VOID__ENUM,
1314 GTK_TYPE_DIRECTION_TYPE);
1317 * @widget: the object which received the signal.
1318 * @event: the #GdkEvent which triggered this signal
1320 * The GTK+ main loop will emit three signals for each GDK event delivered
1321 * to a widget: one generic ::event signal, another, more specific,
1322 * signal that matches the type of event delivered (e.g.
1323 * #GtkWidget::key-press-event) and finally a generic
1324 * #GtkWidget::event-after signal.
1326 * Returns: %TRUE to stop other handlers from being invoked for the event
1327 * and to cancel the emission of the second specific ::event signal.
1328 * %FALSE to propagate the event further and to allow the emission of
1329 * the second signal. The ::event-after signal is emitted regardless of
1332 widget_signals[EVENT] =
1333 g_signal_new (I_("event"),
1334 G_TYPE_FROM_CLASS (gobject_class),
1336 G_STRUCT_OFFSET (GtkWidgetClass, event),
1337 _gtk_boolean_handled_accumulator, NULL,
1338 _gtk_marshal_BOOLEAN__BOXED,
1340 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1343 * GtkWidget::event-after:
1344 * @widget: the object which received the signal.
1345 * @event: the #GdkEvent which triggered this signal
1347 * After the emission of the #GtkWidget::event signal and (optionally)
1348 * the second more specific signal, ::event-after will be emitted
1349 * regardless of the previous two signals handlers return values.
1352 widget_signals[EVENT_AFTER] =
1353 g_signal_new (I_("event-after"),
1354 G_TYPE_FROM_CLASS (gobject_class),
1358 _gtk_marshal_VOID__BOXED,
1360 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1363 * GtkWidget::button-press-event:
1364 * @widget: the object which received the signal.
1365 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1368 * The ::button-press-event signal will be emitted when a button
1369 * (typically from a mouse) is pressed.
1371 * To receive this signal, the #GdkWindow associated to the
1372 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1374 * This signal will be sent to the grab widget if there is one.
1376 * Returns: %TRUE to stop other handlers from being invoked for the event.
1377 * %FALSE to propagate the event further.
1379 widget_signals[BUTTON_PRESS_EVENT] =
1380 g_signal_new (I_("button-press-event"),
1381 G_TYPE_FROM_CLASS (gobject_class),
1383 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1384 _gtk_boolean_handled_accumulator, NULL,
1385 _gtk_marshal_BOOLEAN__BOXED,
1387 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1390 * GtkWidget::button-release-event:
1391 * @widget: the object which received the signal.
1392 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1395 * The ::button-release-event signal will be emitted when a button
1396 * (typically from a mouse) is released.
1398 * To receive this signal, the #GdkWindow associated to the
1399 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1401 * This signal will be sent to the grab widget if there is one.
1403 * Returns: %TRUE to stop other handlers from being invoked for the event.
1404 * %FALSE to propagate the event further.
1406 widget_signals[BUTTON_RELEASE_EVENT] =
1407 g_signal_new (I_("button-release-event"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1410 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1411 _gtk_boolean_handled_accumulator, NULL,
1412 _gtk_marshal_BOOLEAN__BOXED,
1414 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1417 * GtkWidget::scroll-event:
1418 * @widget: the object which received the signal.
1419 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1422 * The ::scroll-event signal is emitted when a button in the 4 to 7
1423 * range is pressed. Wheel mice are usually configured to generate
1424 * button press events for buttons 4 and 5 when the wheel is turned.
1426 * To receive this signal, the #GdkWindow associated to the widget needs
1427 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1429 * This signal will be sent to the grab widget if there is one.
1431 * Returns: %TRUE to stop other handlers from being invoked for the event.
1432 * %FALSE to propagate the event further.
1434 widget_signals[SCROLL_EVENT] =
1435 g_signal_new (I_("scroll-event"),
1436 G_TYPE_FROM_CLASS (gobject_class),
1438 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1439 _gtk_boolean_handled_accumulator, NULL,
1440 _gtk_marshal_BOOLEAN__BOXED,
1442 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1444 * GtkWidget::motion-notify-event:
1445 * @widget: the object which received the signal.
1446 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1449 * The ::motion-notify-event signal is emitted when the pointer moves
1450 * over the widget's #GdkWindow.
1452 * To receive this signal, the #GdkWindow associated to the widget
1453 * needs to enable the #GDK_POINTER_MOTION_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[MOTION_NOTIFY_EVENT] =
1461 g_signal_new (I_("motion-notify-event"),
1462 G_TYPE_FROM_CLASS (gobject_class),
1464 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1465 _gtk_boolean_handled_accumulator, NULL,
1466 _gtk_marshal_BOOLEAN__BOXED,
1468 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1471 * GtkWidget::composited-changed:
1472 * @widget: the object on which the signal is emitted
1474 * The ::composited-changed signal is emitted when the composited
1475 * status of @widget<!-- -->s screen changes.
1476 * See gdk_screen_is_composited().
1478 widget_signals[COMPOSITED_CHANGED] =
1479 g_signal_new (I_("composited-changed"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1481 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1482 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1484 _gtk_marshal_VOID__VOID,
1488 * GtkWidget::keynav-failed:
1489 * @widget: the object which received the signal
1490 * @direction: the direction of movement
1492 * Gets emitted if keyboard navigation fails.
1493 * See gtk_widget_keynav_failed() for details.
1495 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1496 * if the emitting widget should try to handle the keyboard
1497 * navigation attempt in its parent container(s).
1501 widget_signals[KEYNAV_FAILED] =
1502 g_signal_new_class_handler (I_("keynav-failed"),
1503 G_TYPE_FROM_CLASS (gobject_class),
1505 G_CALLBACK (gtk_widget_real_keynav_failed),
1506 _gtk_boolean_handled_accumulator, NULL,
1507 _gtk_marshal_BOOLEAN__ENUM,
1509 GTK_TYPE_DIRECTION_TYPE);
1512 * GtkWidget::delete-event:
1513 * @widget: the object which received the signal
1514 * @event: the event which triggered this signal
1516 * The ::delete-event signal is emitted if a user requests that
1517 * a toplevel window is closed. The default handler for this signal
1518 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1519 * this signal will cause the window to be hidden instead, so that
1520 * it can later be shown again without reconstructing it.
1522 * Returns: %TRUE to stop other handlers from being invoked for the event.
1523 * %FALSE to propagate the event further.
1525 widget_signals[DELETE_EVENT] =
1526 g_signal_new (I_("delete-event"),
1527 G_TYPE_FROM_CLASS (gobject_class),
1529 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1530 _gtk_boolean_handled_accumulator, NULL,
1531 _gtk_marshal_BOOLEAN__BOXED,
1533 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1536 * GtkWidget::destroy-event:
1537 * @widget: the object which received the signal.
1538 * @event: the event which triggered this signal
1540 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1541 * You rarely get this signal, because most widgets disconnect themselves
1542 * from their window before they destroy it, so no widget owns the
1543 * window at destroy time.
1545 * To receive this signal, the #GdkWindow associated to the widget needs
1546 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1547 * automatically for all new windows.
1549 * Returns: %TRUE to stop other handlers from being invoked for the event.
1550 * %FALSE to propagate the event further.
1552 widget_signals[DESTROY_EVENT] =
1553 g_signal_new (I_("destroy-event"),
1554 G_TYPE_FROM_CLASS (gobject_class),
1556 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1557 _gtk_boolean_handled_accumulator, NULL,
1558 _gtk_marshal_BOOLEAN__BOXED,
1560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1563 * GtkWidget::expose-event:
1564 * @widget: the object which received the signal.
1565 * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
1568 * The ::expose-event signal is emitted when an area of a previously
1569 * obscured #GdkWindow is made visible and needs to be redrawn.
1570 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1573 * To receive this signal, the #GdkWindow associated to the widget needs
1574 * to enable the #GDK_EXPOSURE_MASK mask.
1576 * Returns: %TRUE to stop other handlers from being invoked for the event.
1577 * %FALSE to propagate the event further.
1579 widget_signals[EXPOSE_EVENT] =
1580 g_signal_new (I_("expose-event"),
1581 G_TYPE_FROM_CLASS (gobject_class),
1583 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1584 _gtk_boolean_handled_accumulator, NULL,
1585 _gtk_marshal_BOOLEAN__BOXED,
1587 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1590 * GtkWidget::key-press-event:
1591 * @widget: the object which received the signal
1592 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1594 * The ::key-press-event signal is emitted when a key is pressed.
1596 * To receive this signal, the #GdkWindow associated to the widget needs
1597 * to enable the #GDK_KEY_PRESS_MASK mask.
1599 * This signal will be sent to the grab widget if there is one.
1601 * Returns: %TRUE to stop other handlers from being invoked for the event.
1602 * %FALSE to propagate the event further.
1604 widget_signals[KEY_PRESS_EVENT] =
1605 g_signal_new (I_("key-press-event"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1608 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1609 _gtk_boolean_handled_accumulator, NULL,
1610 _gtk_marshal_BOOLEAN__BOXED,
1612 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1615 * GtkWidget::key-release-event:
1616 * @widget: the object which received the signal
1617 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1619 * The ::key-release-event signal is emitted when a key is pressed.
1621 * To receive this signal, the #GdkWindow associated to the widget needs
1622 * to enable the #GDK_KEY_RELEASE_MASK mask.
1624 * This signal will be sent to the grab widget if there is one.
1626 * Returns: %TRUE to stop other handlers from being invoked for the event.
1627 * %FALSE to propagate the event further.
1629 widget_signals[KEY_RELEASE_EVENT] =
1630 g_signal_new (I_("key-release-event"),
1631 G_TYPE_FROM_CLASS (gobject_class),
1633 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1634 _gtk_boolean_handled_accumulator, NULL,
1635 _gtk_marshal_BOOLEAN__BOXED,
1637 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1640 * GtkWidget::enter-notify-event:
1641 * @widget: the object which received the signal
1642 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1645 * The ::enter-notify-event will be emitted when the pointer enters
1646 * the @widget's window.
1648 * To receive this signal, the #GdkWindow associated to the widget needs
1649 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1651 * This signal will be sent to the grab widget if there is one.
1653 * Returns: %TRUE to stop other handlers from being invoked for the event.
1654 * %FALSE to propagate the event further.
1656 widget_signals[ENTER_NOTIFY_EVENT] =
1657 g_signal_new (I_("enter-notify-event"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1661 _gtk_boolean_handled_accumulator, NULL,
1662 _gtk_marshal_BOOLEAN__BOXED,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkWidget::leave-notify-event:
1668 * @widget: the object which received the signal
1669 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1672 * The ::leave-notify-event will be emitted when the pointer leaves
1673 * the @widget's window.
1675 * To receive this signal, the #GdkWindow associated to the widget needs
1676 * to enable the #GDK_LEAVE_NOTIFY_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[LEAVE_NOTIFY_EVENT] =
1684 g_signal_new (I_("leave-notify-event"),
1685 G_TYPE_FROM_CLASS (gobject_class),
1687 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1688 _gtk_boolean_handled_accumulator, NULL,
1689 _gtk_marshal_BOOLEAN__BOXED,
1691 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1694 * GtkWidget::configure-event
1695 * @widget: the object which received the signal
1696 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1699 * The ::configure-event signal will be emitted when the size, position or
1700 * stacking of the @widget's window has changed.
1702 * To receive this signal, the #GdkWindow associated to the widget needs
1703 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1704 * automatically for all new windows.
1706 * Returns: %TRUE to stop other handlers from being invoked for the event.
1707 * %FALSE to propagate the event further.
1709 widget_signals[CONFIGURE_EVENT] =
1710 g_signal_new (I_("configure-event"),
1711 G_TYPE_FROM_CLASS (gobject_class),
1713 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1714 _gtk_boolean_handled_accumulator, NULL,
1715 _gtk_marshal_BOOLEAN__BOXED,
1717 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1720 * GtkWidget::focus-in-event
1721 * @widget: the object which received the signal
1722 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1725 * The ::focus-in-event signal will be emitted when the keyboard focus
1726 * enters the @widget's window.
1728 * To receive this signal, the #GdkWindow associated to the widget needs
1729 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1731 * Returns: %TRUE to stop other handlers from being invoked for the event.
1732 * %FALSE to propagate the event further.
1734 widget_signals[FOCUS_IN_EVENT] =
1735 g_signal_new (I_("focus-in-event"),
1736 G_TYPE_FROM_CLASS (gobject_class),
1738 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1739 _gtk_boolean_handled_accumulator, NULL,
1740 _gtk_marshal_BOOLEAN__BOXED,
1742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1745 * GtkWidget::focus-out-event
1746 * @widget: the object which received the signal
1747 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1750 * The ::focus-out-event signal will be emitted when the keyboard focus
1751 * leaves the @widget's window.
1753 * To receive this signal, the #GdkWindow associated to the widget needs
1754 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1756 * Returns: %TRUE to stop other handlers from being invoked for the event.
1757 * %FALSE to propagate the event further.
1759 widget_signals[FOCUS_OUT_EVENT] =
1760 g_signal_new (I_("focus-out-event"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1763 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1764 _gtk_boolean_handled_accumulator, NULL,
1765 _gtk_marshal_BOOLEAN__BOXED,
1767 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1770 * GtkWidget::map-event
1771 * @widget: the object which received the signal
1772 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1774 * The ::map-event signal will be emitted when the @widget's window is
1775 * mapped. A window is mapped when it becomes visible on the screen.
1777 * To receive this signal, the #GdkWindow associated to the widget needs
1778 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1779 * automatically for all new windows.
1781 * Returns: %TRUE to stop other handlers from being invoked for the event.
1782 * %FALSE to propagate the event further.
1784 widget_signals[MAP_EVENT] =
1785 g_signal_new (I_("map-event"),
1786 G_TYPE_FROM_CLASS (gobject_class),
1788 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1789 _gtk_boolean_handled_accumulator, NULL,
1790 _gtk_marshal_BOOLEAN__BOXED,
1792 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1795 * GtkWidget::unmap-event
1796 * @widget: the object which received the signal
1797 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1799 * The ::unmap-event signal may be emitted when the @widget's window is
1800 * unmapped. A window is unmapped when it becomes invisible on the screen.
1802 * For performance reasons GTK+ may not emit ::unmap-event, so one
1803 * should always also implement ::unrealize in order to release
1804 * resources and disconnect signal handlers.
1806 * To receive this signal, the #GdkWindow associated to the widget needs
1807 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1808 * automatically for all new windows.
1810 * Returns: %TRUE to stop other handlers from being invoked for the event.
1811 * %FALSE to propagate the event further.
1813 widget_signals[UNMAP_EVENT] =
1814 g_signal_new (I_("unmap-event"),
1815 G_TYPE_FROM_CLASS (gobject_class),
1817 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1818 _gtk_boolean_handled_accumulator, NULL,
1819 _gtk_marshal_BOOLEAN__BOXED,
1821 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1824 * GtkWidget::property-notify-event
1825 * @widget: the object which received the signal
1826 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1829 * The ::property-notify-event signal will be emitted when a property on
1830 * the @widget's window has been changed or deleted.
1832 * To receive this signal, the #GdkWindow associated to the widget needs
1833 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event.
1836 * %FALSE to propagate the event further.
1838 widget_signals[PROPERTY_NOTIFY_EVENT] =
1839 g_signal_new (I_("property-notify-event"),
1840 G_TYPE_FROM_CLASS (gobject_class),
1842 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1843 _gtk_boolean_handled_accumulator, NULL,
1844 _gtk_marshal_BOOLEAN__BOXED,
1846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1849 * GtkWidget::selection-clear-event
1850 * @widget: the object which received the signal
1851 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1854 * The ::selection-clear-event signal will be emitted when the
1855 * the @widget's window has lost ownership of a selection.
1857 * Returns: %TRUE to stop other handlers from being invoked for the event.
1858 * %FALSE to propagate the event further.
1860 widget_signals[SELECTION_CLEAR_EVENT] =
1861 g_signal_new (I_("selection-clear-event"),
1862 G_TYPE_FROM_CLASS (gobject_class),
1864 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1865 _gtk_boolean_handled_accumulator, NULL,
1866 _gtk_marshal_BOOLEAN__BOXED,
1868 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1871 * GtkWidget::selection-request-event
1872 * @widget: the object which received the signal
1873 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1876 * The ::selection-request-event signal will be emitted when
1877 * another client requests ownership of the selection owned by
1878 * the @widget's window.
1880 * Returns: %TRUE to stop other handlers from being invoked for the event.
1881 * %FALSE to propagate the event further.
1883 widget_signals[SELECTION_REQUEST_EVENT] =
1884 g_signal_new (I_("selection-request-event"),
1885 G_TYPE_FROM_CLASS (gobject_class),
1887 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1888 _gtk_boolean_handled_accumulator, NULL,
1889 _gtk_marshal_BOOLEAN__BOXED,
1891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1894 * GtkWidget::selection-notify-event:
1895 * @widget: the object which received the signal.
1898 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1900 widget_signals[SELECTION_NOTIFY_EVENT] =
1901 g_signal_new (I_("selection-notify-event"),
1902 G_TYPE_FROM_CLASS (gobject_class),
1904 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1905 _gtk_boolean_handled_accumulator, NULL,
1906 _gtk_marshal_BOOLEAN__BOXED,
1908 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1911 * GtkWidget::selection-received:
1912 * @widget: the object which received the signal.
1916 widget_signals[SELECTION_RECEIVED] =
1917 g_signal_new (I_("selection-received"),
1918 G_TYPE_FROM_CLASS (gobject_class),
1920 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1922 _gtk_marshal_VOID__BOXED_UINT,
1924 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1928 * GtkWidget::selection-get:
1929 * @widget: the object which received the signal.
1934 widget_signals[SELECTION_GET] =
1935 g_signal_new (I_("selection-get"),
1936 G_TYPE_FROM_CLASS (gobject_class),
1938 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1940 _gtk_marshal_VOID__BOXED_UINT_UINT,
1942 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1947 * GtkWidget::proximity-in-event
1948 * @widget: the object which received the signal
1949 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1952 * To receive this signal the #GdkWindow associated to the widget needs
1953 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1955 * This signal will be sent to the grab widget if there is one.
1957 * Returns: %TRUE to stop other handlers from being invoked for the event.
1958 * %FALSE to propagate the event further.
1960 widget_signals[PROXIMITY_IN_EVENT] =
1961 g_signal_new (I_("proximity-in-event"),
1962 G_TYPE_FROM_CLASS (gobject_class),
1964 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1965 _gtk_boolean_handled_accumulator, NULL,
1966 _gtk_marshal_BOOLEAN__BOXED,
1968 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1971 * GtkWidget::proximity-out-event
1972 * @widget: the object which received the signal
1973 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1976 * To receive this signal the #GdkWindow associated to the widget needs
1977 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1979 * This signal will be sent to the grab widget if there is one.
1981 * Returns: %TRUE to stop other handlers from being invoked for the event.
1982 * %FALSE to propagate the event further.
1984 widget_signals[PROXIMITY_OUT_EVENT] =
1985 g_signal_new (I_("proximity-out-event"),
1986 G_TYPE_FROM_CLASS (gobject_class),
1988 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1989 _gtk_boolean_handled_accumulator, NULL,
1990 _gtk_marshal_BOOLEAN__BOXED,
1992 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1995 * GtkWidget::drag-leave:
1996 * @widget: the object which received the signal.
1997 * @drag_context: the drag context
1998 * @time: the timestamp of the motion event
2000 * The ::drag-leave signal is emitted on the drop site when the cursor
2001 * leaves the widget. A typical reason to connect to this signal is to
2002 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2003 * with gtk_drag_unhighlight()
2005 widget_signals[DRAG_LEAVE] =
2006 g_signal_new (I_("drag-leave"),
2007 G_TYPE_FROM_CLASS (gobject_class),
2009 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2011 _gtk_marshal_VOID__OBJECT_UINT,
2013 GDK_TYPE_DRAG_CONTEXT,
2017 * GtkWidget::drag-begin:
2018 * @widget: the object which received the signal
2019 * @drag_context: the drag context
2021 * The ::drag-begin signal is emitted on the drag source when a drag is
2022 * started. A typical reason to connect to this signal is to set up a
2023 * custom drag icon with gtk_drag_source_set_icon().
2025 * Note that some widgets set up a drag icon in the default handler of
2026 * this signal, so you may have to use g_signal_connect_after() to
2027 * override what the default handler did.
2029 widget_signals[DRAG_BEGIN] =
2030 g_signal_new (I_("drag-begin"),
2031 G_TYPE_FROM_CLASS (gobject_class),
2033 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2035 _gtk_marshal_VOID__OBJECT,
2037 GDK_TYPE_DRAG_CONTEXT);
2040 * GtkWidget::drag-end:
2041 * @widget: the object which received the signal
2042 * @drag_context: the drag context
2044 * The ::drag-end signal is emitted on the drag source when a drag is
2045 * finished. A typical reason to connect to this signal is to undo
2046 * things done in #GtkWidget::drag-begin.
2048 widget_signals[DRAG_END] =
2049 g_signal_new (I_("drag-end"),
2050 G_TYPE_FROM_CLASS (gobject_class),
2052 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2054 _gtk_marshal_VOID__OBJECT,
2056 GDK_TYPE_DRAG_CONTEXT);
2059 * GtkWidget::drag-data-delete:
2060 * @widget: the object which received the signal
2061 * @drag_context: the drag context
2063 * The ::drag-data-delete signal is emitted on the drag source when a drag
2064 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2065 * handler is responsible for deleting the data that has been dropped. What
2066 * "delete" means depends on the context of the drag operation.
2068 widget_signals[DRAG_DATA_DELETE] =
2069 g_signal_new (I_("drag-data-delete"),
2070 G_TYPE_FROM_CLASS (gobject_class),
2072 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2074 _gtk_marshal_VOID__OBJECT,
2076 GDK_TYPE_DRAG_CONTEXT);
2079 * GtkWidget::drag-failed:
2080 * @widget: the object which received the signal
2081 * @drag_context: the drag context
2082 * @result: the result of the drag operation
2084 * The ::drag-failed signal is emitted on the drag source when a drag has
2085 * failed. The signal handler may hook custom code to handle a failed DND
2086 * operation based on the type of error, it returns %TRUE is the failure has
2087 * been already handled (not showing the default "drag operation failed"
2088 * animation), otherwise it returns %FALSE.
2090 * Return value: %TRUE if the failed drag operation has been already handled.
2094 widget_signals[DRAG_FAILED] =
2095 g_signal_new (I_("drag-failed"),
2096 G_TYPE_FROM_CLASS (gobject_class),
2098 0, _gtk_boolean_handled_accumulator, NULL,
2099 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2101 GDK_TYPE_DRAG_CONTEXT,
2102 GTK_TYPE_DRAG_RESULT);
2105 * GtkWidget::drag-motion:
2106 * @widget: the object which received the signal
2107 * @drag_context: the drag context
2108 * @x: the x coordinate of the current cursor position
2109 * @y: the y coordinate of the current cursor position
2110 * @time: the timestamp of the motion event
2111 * @returns: whether the cursor position is in a drop zone
2113 * The drag-motion signal is emitted on the drop site when the user
2114 * moves the cursor over the widget during a drag. The signal handler
2115 * must determine whether the cursor position is in a drop zone or not.
2116 * If it is not in a drop zone, it returns %FALSE and no further processing
2117 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2118 * handler is responsible for providing the necessary information for
2119 * displaying feedback to the user, by calling gdk_drag_status().
2121 * If the decision whether the drop will be accepted or rejected can't be
2122 * made based solely on the cursor position and the type of the data, the
2123 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2124 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2125 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2126 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2127 * when using the drag-motion signal that way.
2129 * Also note that there is no drag-enter signal. The drag receiver has to
2130 * keep track of whether he has received any drag-motion signals since the
2131 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2132 * an "enter" signal. Upon an "enter", the handler will typically highlight
2133 * the drop site with gtk_drag_highlight().
2136 * drag_motion (GtkWidget *widget,
2137 * GdkDragContext *context,
2144 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2146 * if (!private_data->drag_highlight)
2148 * private_data->drag_highlight = 1;
2149 * gtk_drag_highlight (widget);
2152 * target = gtk_drag_dest_find_target (widget, context, NULL);
2153 * if (target == GDK_NONE)
2154 * gdk_drag_status (context, 0, time);
2157 * private_data->pending_status = context->suggested_action;
2158 * gtk_drag_get_data (widget, context, target, time);
2165 * drag_data_received (GtkWidget *widget,
2166 * GdkDragContext *context,
2169 * GtkSelectionData *selection_data,
2173 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2175 * if (private_data->suggested_action)
2177 * private_data->suggested_action = 0;
2179 * /* We are getting this data due to a request in drag_motion,
2180 * * rather than due to a request in drag_drop, so we are just
2181 * * supposed to call gdk_drag_status (), not actually paste in
2184 * str = gtk_selection_data_get_text (selection_data);
2185 * if (!data_is_acceptable (str))
2186 * gdk_drag_status (context, 0, time);
2188 * gdk_drag_status (context, private_data->suggested_action, time);
2192 * /* accept the drop */
2197 widget_signals[DRAG_MOTION] =
2198 g_signal_new (I_("drag-motion"),
2199 G_TYPE_FROM_CLASS (gobject_class),
2201 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2202 _gtk_boolean_handled_accumulator, NULL,
2203 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2205 GDK_TYPE_DRAG_CONTEXT,
2211 * GtkWidget::drag-drop:
2212 * @widget: the object which received the signal
2213 * @drag_context: the drag context
2214 * @x: the x coordinate of the current cursor position
2215 * @y: the y coordinate of the current cursor position
2216 * @time: the timestamp of the motion event
2217 * @returns: whether the cursor position is in a drop zone
2219 * The ::drag-drop signal is emitted on the drop site when the user drops
2220 * the data onto the widget. The signal handler must determine whether
2221 * the cursor position is in a drop zone or not. If it is not in a drop
2222 * zone, it returns %FALSE and no further processing is necessary.
2223 * Otherwise, the handler returns %TRUE. In this case, the handler must
2224 * ensure that gtk_drag_finish() is called to let the source know that
2225 * the drop is done. The call to gtk_drag_finish() can be done either
2226 * directly or in a #GtkWidget::drag-data-received handler which gets
2227 * triggered by calling gtk_drag_get_data() to receive the data for one
2228 * or more of the supported targets.
2230 widget_signals[DRAG_DROP] =
2231 g_signal_new (I_("drag-drop"),
2232 G_TYPE_FROM_CLASS (gobject_class),
2234 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2235 _gtk_boolean_handled_accumulator, NULL,
2236 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2238 GDK_TYPE_DRAG_CONTEXT,
2244 * GtkWidget::drag-data-get:
2245 * @widget: the object which received the signal
2246 * @drag_context: the drag context
2247 * @data: the #GtkSelectionData to be filled with the dragged data
2248 * @info: the info that has been registered with the target in the
2250 * @time: the timestamp at which the data was requested
2252 * The ::drag-data-get signal is emitted on the drag source when the drop
2253 * site requests the data which is dragged. It is the responsibility of
2254 * the signal handler to fill @data with the data in the format which
2255 * is indicated by @info. See gtk_selection_data_set() and
2256 * gtk_selection_data_set_text().
2258 widget_signals[DRAG_DATA_GET] =
2259 g_signal_new (I_("drag-data-get"),
2260 G_TYPE_FROM_CLASS (gobject_class),
2262 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2264 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2266 GDK_TYPE_DRAG_CONTEXT,
2267 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2272 * GtkWidget::drag-data-received:
2273 * @widget: the object which received the signal
2274 * @drag_context: the drag context
2275 * @x: where the drop happened
2276 * @y: where the drop happened
2277 * @data: the received data
2278 * @info: the info that has been registered with the target in the
2280 * @time: the timestamp at which the data was received
2282 * The ::drag-data-received signal is emitted on the drop site when the
2283 * dragged data has been received. If the data was received in order to
2284 * determine whether the drop will be accepted, the handler is expected
2285 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2286 * If the data was received in response to a #GtkWidget::drag-drop signal
2287 * (and this is the last target to be received), the handler for this
2288 * signal is expected to process the received data and then call
2289 * gtk_drag_finish(), setting the @success parameter depending on whether
2290 * the data was processed successfully.
2292 * The handler may inspect and modify @drag_context->action before calling
2293 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2294 * following example:
2297 * drag_data_received (GtkWidget *widget,
2298 * GdkDragContext *drag_context,
2301 * GtkSelectionData *data,
2305 * if ((data->length >= 0) && (data->format == 8))
2307 * if (drag_context->action == GDK_ACTION_ASK)
2309 * GtkWidget *dialog;
2312 * dialog = gtk_message_dialog_new (NULL,
2313 * GTK_DIALOG_MODAL |
2314 * GTK_DIALOG_DESTROY_WITH_PARENT,
2316 * GTK_BUTTONS_YES_NO,
2317 * "Move the data ?\n");
2318 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2319 * gtk_widget_destroy (dialog);
2321 * if (response == GTK_RESPONSE_YES)
2322 * drag_context->action = GDK_ACTION_MOVE;
2324 * drag_context->action = GDK_ACTION_COPY;
2327 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2331 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2335 widget_signals[DRAG_DATA_RECEIVED] =
2336 g_signal_new (I_("drag-data-received"),
2337 G_TYPE_FROM_CLASS (gobject_class),
2339 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2341 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2343 GDK_TYPE_DRAG_CONTEXT,
2346 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2351 * GtkWidget::visibility-notify-event:
2352 * @widget: the object which received the signal
2353 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2354 * triggered this signal.
2356 * The ::visibility-notify-event will be emitted when the @widget's window
2357 * is obscured or unobscured.
2359 * To receive this signal the #GdkWindow associated to the widget needs
2360 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2362 * Returns: %TRUE to stop other handlers from being invoked for the event.
2363 * %FALSE to propagate the event further.
2365 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2366 g_signal_new (I_("visibility-notify-event"),
2367 G_TYPE_FROM_CLASS (gobject_class),
2369 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2370 _gtk_boolean_handled_accumulator, NULL,
2371 _gtk_marshal_BOOLEAN__BOXED,
2373 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2376 * GtkWidget::client-event:
2377 * @widget: the object which received the signal
2378 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2381 * The ::client-event will be emitted when the @widget's window
2382 * receives a message (via a ClientMessage event) from another
2385 * Returns: %TRUE to stop other handlers from being invoked for
2386 * the event. %FALSE to propagate the event further.
2388 widget_signals[CLIENT_EVENT] =
2389 g_signal_new (I_("client-event"),
2390 G_TYPE_FROM_CLASS (gobject_class),
2392 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2393 _gtk_boolean_handled_accumulator, NULL,
2394 _gtk_marshal_BOOLEAN__BOXED,
2396 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2399 * GtkWidget::no-expose-event:
2400 * @widget: the object which received the signal
2401 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2404 * The ::no-expose-event will be emitted when the @widget's window is
2405 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2406 * If the source window was partially obscured #GdkEventExpose events will
2407 * be generated for those areas.
2409 * Returns: %TRUE to stop other handlers from being invoked for the event.
2410 * %FALSE to propagate the event further.
2412 widget_signals[NO_EXPOSE_EVENT] =
2413 g_signal_new (I_("no-expose-event"),
2414 G_TYPE_FROM_CLASS (gobject_class),
2416 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2417 _gtk_boolean_handled_accumulator, NULL,
2418 _gtk_marshal_BOOLEAN__BOXED,
2420 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2423 * GtkWidget::window-state-event:
2424 * @widget: the object which received the signal
2425 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2426 * triggered this signal.
2428 * The ::window-state-event will be emitted when the state of the
2429 * toplevel window associated to the @widget changes.
2431 * To receive this signal the #GdkWindow associated to the widget
2432 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2433 * this mask automatically for all new windows.
2435 * Returns: %TRUE to stop other handlers from being invoked for the
2436 * event. %FALSE to propagate the event further.
2438 widget_signals[WINDOW_STATE_EVENT] =
2439 g_signal_new (I_("window-state-event"),
2440 G_TYPE_FROM_CLASS (gobject_class),
2442 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2443 _gtk_boolean_handled_accumulator, NULL,
2444 _gtk_marshal_BOOLEAN__BOXED,
2446 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2449 * GtkWidget::damage-event:
2450 * @widget: the object which received the signal
2451 * @event: the #GdkEventExpose event
2453 * Emitted when a redirected window belonging to @widget gets drawn into.
2454 * The region/area members of the event shows what area of the redirected
2455 * drawable was drawn into.
2457 * Returns: %TRUE to stop other handlers from being invoked for the event.
2458 * %FALSE to propagate the event further.
2462 widget_signals[DAMAGE_EVENT] =
2463 g_signal_new (I_("damage-event"),
2464 G_TYPE_FROM_CLASS (gobject_class),
2467 _gtk_boolean_handled_accumulator, NULL,
2468 _gtk_marshal_BOOLEAN__BOXED,
2470 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2472 * GtkWidget::grab-broken-event:
2473 * @widget: the object which received the signal
2474 * @event: the #GdkEventGrabBroken event
2476 * Emitted when a pointer or keyboard grab on a window belonging
2477 * to @widget gets broken.
2479 * On X11, this happens when the grab window becomes unviewable
2480 * (i.e. it or one of its ancestors is unmapped), or if the same
2481 * application grabs the pointer or keyboard again.
2483 * Returns: %TRUE to stop other handlers from being invoked for
2484 * the event. %FALSE to propagate the event further.
2488 widget_signals[GRAB_BROKEN] =
2489 g_signal_new (I_("grab-broken-event"),
2490 G_TYPE_FROM_CLASS (gobject_class),
2492 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2493 _gtk_boolean_handled_accumulator, NULL,
2494 _gtk_marshal_BOOLEAN__BOXED,
2496 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2498 * GtkWidget::query-tooltip:
2499 * @widget: the object which received the signal
2500 * @x: the x coordinate of the cursor position where the request has
2501 * been emitted, relative to @widget->window
2502 * @y: the y coordinate of the cursor position where the request has
2503 * been emitted, relative to @widget->window
2504 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2505 * @tooltip: a #GtkTooltip
2507 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2508 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2509 * focus in keyboard mode.
2511 * Using the given coordinates, the signal handler should determine
2512 * whether a tooltip should be shown for @widget. If this is the case
2513 * %TRUE should be returned, %FALSE otherwise. Note that if
2514 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2515 * should not be used.
2517 * The signal handler is free to manipulate @tooltip with the therefore
2518 * destined function calls.
2520 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2524 widget_signals[QUERY_TOOLTIP] =
2525 g_signal_new (I_("query-tooltip"),
2526 G_TYPE_FROM_CLASS (gobject_class),
2528 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2529 _gtk_boolean_handled_accumulator, NULL,
2530 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2538 * GtkWidget::popup-menu
2539 * @widget: the object which received the signal
2541 * This signal gets emitted whenever a widget should pop up a context
2542 * menu. This usually happens through the standard key binding mechanism;
2543 * by pressing a certain key while a widget is focused, the user can cause
2544 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2545 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2546 * for an example of how to use this signal.
2548 * Returns: %TRUE if a menu was activated
2550 widget_signals[POPUP_MENU] =
2551 g_signal_new (I_("popup-menu"),
2552 G_TYPE_FROM_CLASS (gobject_class),
2553 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2554 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2555 _gtk_boolean_handled_accumulator, NULL,
2556 _gtk_marshal_BOOLEAN__VOID,
2560 * GtkWidget::show-help:
2561 * @widget: the object which received the signal.
2564 widget_signals[SHOW_HELP] =
2565 g_signal_new (I_("show-help"),
2566 G_TYPE_FROM_CLASS (gobject_class),
2567 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2568 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2569 _gtk_boolean_handled_accumulator, NULL,
2570 _gtk_marshal_BOOLEAN__ENUM,
2572 GTK_TYPE_WIDGET_HELP_TYPE);
2575 * GtkWidget::accel-closures-changed:
2576 * @widget: the object which received the signal.
2578 widget_signals[ACCEL_CLOSURES_CHANGED] =
2579 g_signal_new (I_("accel-closures-changed"),
2580 G_TYPE_FROM_CLASS (gobject_class),
2584 _gtk_marshal_VOID__VOID,
2588 * GtkWidget::screen-changed:
2589 * @widget: the object on which the signal is emitted
2590 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2591 * widget was not associated with a screen before
2593 * The ::screen-changed signal gets emitted when the
2594 * screen of a widget has changed.
2596 widget_signals[SCREEN_CHANGED] =
2597 g_signal_new (I_("screen-changed"),
2598 G_TYPE_FROM_CLASS (gobject_class),
2600 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2602 _gtk_marshal_VOID__OBJECT,
2607 * GtkWidget::can-activate-accel:
2608 * @widget: the object which received the signal
2609 * @signal_id: the ID of a signal installed on @widget
2611 * Determines whether an accelerator that activates the signal
2612 * identified by @signal_id can currently be activated.
2613 * This signal is present to allow applications and derived
2614 * widgets to override the default #GtkWidget handling
2615 * for determining whether an accelerator can be activated.
2617 * Returns: %TRUE if the signal can be activated.
2619 widget_signals[CAN_ACTIVATE_ACCEL] =
2620 g_signal_new (I_("can-activate-accel"),
2621 G_TYPE_FROM_CLASS (gobject_class),
2623 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2624 _gtk_boolean_handled_accumulator, NULL,
2625 _gtk_marshal_BOOLEAN__UINT,
2626 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2628 binding_set = gtk_binding_set_by_class (klass);
2629 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2631 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2634 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2636 GTK_TYPE_WIDGET_HELP_TYPE,
2637 GTK_WIDGET_HELP_TOOLTIP);
2638 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2640 GTK_TYPE_WIDGET_HELP_TYPE,
2641 GTK_WIDGET_HELP_TOOLTIP);
2642 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2644 GTK_TYPE_WIDGET_HELP_TYPE,
2645 GTK_WIDGET_HELP_WHATS_THIS);
2646 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2648 GTK_TYPE_WIDGET_HELP_TYPE,
2649 GTK_WIDGET_HELP_WHATS_THIS);
2651 gtk_widget_class_install_style_property (klass,
2652 g_param_spec_boolean ("interior-focus",
2653 P_("Interior Focus"),
2654 P_("Whether to draw the focus indicator inside widgets"),
2656 GTK_PARAM_READABLE));
2658 gtk_widget_class_install_style_property (klass,
2659 g_param_spec_int ("focus-line-width",
2660 P_("Focus linewidth"),
2661 P_("Width, in pixels, of the focus indicator line"),
2663 GTK_PARAM_READABLE));
2665 gtk_widget_class_install_style_property (klass,
2666 g_param_spec_string ("focus-line-pattern",
2667 P_("Focus line dash pattern"),
2668 P_("Dash pattern used to draw the focus indicator"),
2670 GTK_PARAM_READABLE));
2671 gtk_widget_class_install_style_property (klass,
2672 g_param_spec_int ("focus-padding",
2673 P_("Focus padding"),
2674 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2676 GTK_PARAM_READABLE));
2677 gtk_widget_class_install_style_property (klass,
2678 g_param_spec_boxed ("cursor-color",
2680 P_("Color with which to draw insertion cursor"),
2682 GTK_PARAM_READABLE));
2683 gtk_widget_class_install_style_property (klass,
2684 g_param_spec_boxed ("secondary-cursor-color",
2685 P_("Secondary cursor color"),
2686 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2688 GTK_PARAM_READABLE));
2689 gtk_widget_class_install_style_property (klass,
2690 g_param_spec_float ("cursor-aspect-ratio",
2691 P_("Cursor line aspect ratio"),
2692 P_("Aspect ratio with which to draw insertion cursor"),
2694 GTK_PARAM_READABLE));
2696 gtk_widget_class_install_style_property (klass,
2697 g_param_spec_boolean ("window-dragging",
2698 P_("Window dragging"),
2699 P_("Whether windows can be dragged by clicking on empty areas"),
2701 GTK_PARAM_READABLE));
2704 * GtkWidget:link-color:
2706 * The "link-color" style property defines the color of unvisited links.
2710 gtk_widget_class_install_style_property (klass,
2711 g_param_spec_boxed ("link-color",
2712 P_("Unvisited Link Color"),
2713 P_("Color of unvisited links"),
2715 GTK_PARAM_READABLE));
2718 * GtkWidget:visited-link-color:
2720 * The "visited-link-color" style property defines the color of visited links.
2724 gtk_widget_class_install_style_property (klass,
2725 g_param_spec_boxed ("visited-link-color",
2726 P_("Visited Link Color"),
2727 P_("Color of visited links"),
2729 GTK_PARAM_READABLE));
2732 * GtkWidget:wide-separators:
2734 * The "wide-separators" style property defines whether separators have
2735 * configurable width and should be drawn using a box instead of a line.
2739 gtk_widget_class_install_style_property (klass,
2740 g_param_spec_boolean ("wide-separators",
2741 P_("Wide Separators"),
2742 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2744 GTK_PARAM_READABLE));
2747 * GtkWidget:separator-width:
2749 * The "separator-width" style property defines the width of separators.
2750 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2754 gtk_widget_class_install_style_property (klass,
2755 g_param_spec_int ("separator-width",
2756 P_("Separator Width"),
2757 P_("The width of separators if wide-separators is TRUE"),
2759 GTK_PARAM_READABLE));
2762 * GtkWidget:separator-height:
2764 * The "separator-height" style property defines the height of separators.
2765 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2769 gtk_widget_class_install_style_property (klass,
2770 g_param_spec_int ("separator-height",
2771 P_("Separator Height"),
2772 P_("The height of separators if \"wide-separators\" is TRUE"),
2774 GTK_PARAM_READABLE));
2777 * GtkWidget:scroll-arrow-hlength:
2779 * The "scroll-arrow-hlength" style property defines the length of
2780 * horizontal scroll arrows.
2784 gtk_widget_class_install_style_property (klass,
2785 g_param_spec_int ("scroll-arrow-hlength",
2786 P_("Horizontal Scroll Arrow Length"),
2787 P_("The length of horizontal scroll arrows"),
2789 GTK_PARAM_READABLE));
2792 * GtkWidget:scroll-arrow-vlength:
2794 * The "scroll-arrow-vlength" style property defines the length of
2795 * vertical scroll arrows.
2799 gtk_widget_class_install_style_property (klass,
2800 g_param_spec_int ("scroll-arrow-vlength",
2801 P_("Vertical Scroll Arrow Length"),
2802 P_("The length of vertical scroll arrows"),
2804 GTK_PARAM_READABLE));
2806 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2810 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2814 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2815 for (node = list; node; node = node->next)
2817 GParamSpec *pspec = node->data;
2819 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2820 g_param_spec_unref (pspec);
2826 gtk_widget_set_property (GObject *object,
2828 const GValue *value,
2831 GtkWidget *widget = GTK_WIDGET (object);
2836 gchar *tooltip_markup;
2837 const gchar *tooltip_text;
2838 GtkWindow *tooltip_window;
2841 gtk_widget_set_name (widget, g_value_get_string (value));
2844 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2846 case PROP_WIDTH_REQUEST:
2847 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2849 case PROP_HEIGHT_REQUEST:
2850 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2853 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2855 case PROP_SENSITIVE:
2856 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2858 case PROP_APP_PAINTABLE:
2859 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2861 case PROP_CAN_FOCUS:
2862 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2864 case PROP_HAS_FOCUS:
2865 if (g_value_get_boolean (value))
2866 gtk_widget_grab_focus (widget);
2869 if (g_value_get_boolean (value))
2870 gtk_widget_grab_focus (widget);
2872 case PROP_CAN_DEFAULT:
2873 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2875 case PROP_HAS_DEFAULT:
2876 if (g_value_get_boolean (value))
2877 gtk_widget_grab_default (widget);
2879 case PROP_RECEIVES_DEFAULT:
2880 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2883 gtk_widget_set_style (widget, g_value_get_object (value));
2886 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2887 gtk_widget_set_events (widget, g_value_get_flags (value));
2889 case PROP_EXTENSION_EVENTS:
2890 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2892 case PROP_NO_SHOW_ALL:
2893 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2895 case PROP_HAS_TOOLTIP:
2896 gtk_widget_real_set_has_tooltip (widget,
2897 g_value_get_boolean (value), FALSE);
2899 case PROP_TOOLTIP_MARKUP:
2900 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2901 tooltip_markup = g_value_dup_string (value);
2903 /* Treat an empty string as a NULL string,
2904 * because an empty string would be useless for a tooltip:
2906 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2908 g_free (tooltip_markup);
2909 tooltip_markup = NULL;
2912 g_object_set_qdata_full (object, quark_tooltip_markup,
2913 tooltip_markup, g_free);
2915 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2916 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2917 if (gtk_widget_get_visible (widget))
2918 gtk_widget_queue_tooltip_query (widget);
2920 case PROP_TOOLTIP_TEXT:
2921 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2923 tooltip_text = g_value_get_string (value);
2925 /* Treat an empty string as a NULL string,
2926 * because an empty string would be useless for a tooltip:
2928 if (tooltip_text && (strlen (tooltip_text) == 0))
2929 tooltip_text = NULL;
2931 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2933 g_object_set_qdata_full (object, quark_tooltip_markup,
2934 tooltip_markup, g_free);
2936 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2937 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2938 if (gtk_widget_get_visible (widget))
2939 gtk_widget_queue_tooltip_query (widget);
2941 case PROP_DOUBLE_BUFFERED:
2942 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2945 gtk_widget_set_halign (widget, g_value_get_enum (value));
2948 gtk_widget_set_valign (widget, g_value_get_enum (value));
2950 case PROP_MARGIN_LEFT:
2951 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2953 case PROP_MARGIN_RIGHT:
2954 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2956 case PROP_MARGIN_TOP:
2957 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2959 case PROP_MARGIN_BOTTOM:
2960 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
2963 g_object_freeze_notify (G_OBJECT (widget));
2964 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2965 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2966 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2967 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
2968 g_object_thaw_notify (G_OBJECT (widget));
2971 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2977 gtk_widget_get_property (GObject *object,
2982 GtkWidget *widget = GTK_WIDGET (object);
2983 GtkWidgetPrivate *priv = widget->priv;
2992 g_value_set_string (value, priv->name);
2994 g_value_set_static_string (value, "");
2997 g_value_set_object (value, priv->parent);
2999 case PROP_WIDTH_REQUEST:
3002 gtk_widget_get_size_request (widget, &w, NULL);
3003 g_value_set_int (value, w);
3006 case PROP_HEIGHT_REQUEST:
3009 gtk_widget_get_size_request (widget, NULL, &h);
3010 g_value_set_int (value, h);
3014 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3016 case PROP_SENSITIVE:
3017 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3019 case PROP_APP_PAINTABLE:
3020 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3022 case PROP_CAN_FOCUS:
3023 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3025 case PROP_HAS_FOCUS:
3026 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3029 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3031 case PROP_CAN_DEFAULT:
3032 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3034 case PROP_HAS_DEFAULT:
3035 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3037 case PROP_RECEIVES_DEFAULT:
3038 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3040 case PROP_COMPOSITE_CHILD:
3041 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3044 g_value_set_object (value, gtk_widget_get_style (widget));
3047 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3048 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3050 case PROP_EXTENSION_EVENTS:
3051 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3052 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3054 case PROP_NO_SHOW_ALL:
3055 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3057 case PROP_HAS_TOOLTIP:
3058 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3060 case PROP_TOOLTIP_TEXT:
3062 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3065 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3066 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3068 g_value_take_string (value, text);
3071 case PROP_TOOLTIP_MARKUP:
3072 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3075 g_value_set_object (value, gtk_widget_get_window (widget));
3077 case PROP_DOUBLE_BUFFERED:
3078 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3081 g_value_set_enum (value, gtk_widget_get_halign (widget));
3084 g_value_set_enum (value, gtk_widget_get_valign (widget));
3086 case PROP_MARGIN_LEFT:
3087 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3089 case PROP_MARGIN_RIGHT:
3090 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3092 case PROP_MARGIN_TOP:
3093 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3095 case PROP_MARGIN_BOTTOM:
3096 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3100 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3101 if (aux_info == NULL)
3103 g_value_set_int (value, 0);
3107 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3108 aux_info->margin.right),
3109 MAX (aux_info->margin.top,
3110 aux_info->margin.bottom)));
3115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3121 gtk_widget_init (GtkWidget *widget)
3123 GtkWidgetPrivate *priv;
3125 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3128 priv = widget->priv;
3130 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3131 priv->state = GTK_STATE_NORMAL;
3132 priv->saved_state = GTK_STATE_NORMAL;
3134 priv->allocation.x = -1;
3135 priv->allocation.y = -1;
3136 priv->allocation.width = 1;
3137 priv->allocation.height = 1;
3138 priv->window = NULL;
3139 priv->parent = NULL;
3141 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3142 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3143 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3144 gtk_widget_set_double_buffered (widget, TRUE);
3146 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3147 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3148 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3149 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3151 priv->style = gtk_widget_get_default_style ();
3152 g_object_ref (priv->style);
3157 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3159 GParamSpec **pspecs)
3161 GtkWidgetPrivate *priv = widget->priv;
3162 GtkWidget *container = priv->parent;
3165 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3166 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3170 * gtk_widget_freeze_child_notify:
3171 * @widget: a #GtkWidget
3173 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3174 * signals are queued until gtk_widget_thaw_child_notify() is called
3177 * This is the analogue of g_object_freeze_notify() for child properties.
3180 gtk_widget_freeze_child_notify (GtkWidget *widget)
3182 g_return_if_fail (GTK_IS_WIDGET (widget));
3184 if (!G_OBJECT (widget)->ref_count)
3187 g_object_ref (widget);
3188 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3189 g_object_unref (widget);
3193 * gtk_widget_child_notify:
3194 * @widget: a #GtkWidget
3195 * @child_property: the name of a child property installed on the
3196 * class of @widget<!-- -->'s parent
3198 * Emits a #GtkWidget::child-notify signal for the
3199 * <link linkend="child-properties">child property</link> @child_property
3202 * This is the analogue of g_object_notify() for child properties.
3205 gtk_widget_child_notify (GtkWidget *widget,
3206 const gchar *child_property)
3208 GtkWidgetPrivate *priv = widget->priv;
3211 g_return_if_fail (GTK_IS_WIDGET (widget));
3212 g_return_if_fail (child_property != NULL);
3213 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3216 g_object_ref (widget);
3217 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3219 G_OBJECT_TYPE (priv->parent),
3222 g_warning ("%s: container class `%s' has no child property named `%s'",
3224 G_OBJECT_TYPE_NAME (priv->parent),
3228 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3230 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3231 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3233 g_object_unref (widget);
3237 * gtk_widget_thaw_child_notify:
3238 * @widget: a #GtkWidget
3240 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3241 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3245 gtk_widget_thaw_child_notify (GtkWidget *widget)
3247 GObjectNotifyQueue *nqueue;
3249 g_return_if_fail (GTK_IS_WIDGET (widget));
3251 if (!G_OBJECT (widget)->ref_count)
3254 g_object_ref (widget);
3255 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3256 if (!nqueue || !nqueue->freeze_count)
3257 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3258 G_OBJECT_TYPE_NAME (widget), widget);
3260 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3261 g_object_unref (widget);
3267 * @type: type ID of the widget to create
3268 * @first_property_name: name of first property to set
3269 * @Varargs: value of first property, followed by more properties,
3272 * This is a convenience function for creating a widget and setting
3273 * its properties in one go. For example you might write:
3274 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3275 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3276 * g_object_new(), but returns a widget so you don't have to
3277 * cast the object yourself.
3279 * Return value: a new #GtkWidget of type @widget_type
3282 gtk_widget_new (GType type,
3283 const gchar *first_property_name,
3289 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3291 va_start (var_args, first_property_name);
3292 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3299 gtk_widget_queue_draw_child (GtkWidget *widget)
3301 GtkWidgetPrivate *priv = widget->priv;
3304 parent = priv->parent;
3305 if (parent && gtk_widget_is_drawable (parent))
3306 gtk_widget_queue_draw_area (parent,
3309 priv->allocation.width,
3310 priv->allocation.height);
3314 * gtk_widget_unparent:
3315 * @widget: a #GtkWidget
3317 * This function is only for use in widget implementations.
3318 * Should be called by implementations of the remove method
3319 * on #GtkContainer, to dissociate a child from the container.
3322 gtk_widget_unparent (GtkWidget *widget)
3324 GtkWidgetPrivate *priv;
3325 GObjectNotifyQueue *nqueue;
3326 GtkWidget *toplevel;
3327 GtkWidget *old_parent;
3329 g_return_if_fail (GTK_IS_WIDGET (widget));
3331 priv = widget->priv;
3333 if (priv->parent == NULL)
3336 /* keep this function in sync with gtk_menu_detach()
3339 g_object_freeze_notify (G_OBJECT (widget));
3340 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3342 toplevel = gtk_widget_get_toplevel (widget);
3343 if (gtk_widget_is_toplevel (toplevel))
3344 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3346 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3347 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3349 /* If we are unanchoring the child, we save around the toplevel
3350 * to emit hierarchy changed
3352 if (GTK_WIDGET_ANCHORED (priv->parent))
3353 g_object_ref (toplevel);
3357 gtk_widget_queue_draw_child (widget);
3359 /* Reset the width and height here, to force reallocation if we
3360 * get added back to a new parent. This won't work if our new
3361 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3362 * (would 0x0 be OK here?)
3364 priv->allocation.width = 1;
3365 priv->allocation.height = 1;
3367 if (gtk_widget_get_realized (widget))
3369 if (GTK_WIDGET_IN_REPARENT (widget))
3370 gtk_widget_unmap (widget);
3372 gtk_widget_unrealize (widget);
3375 /* Removing a widget from a container restores the child visible
3376 * flag to the default state, so it doesn't affect the child
3377 * in the next parent.
3379 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3381 old_parent = priv->parent;
3382 priv->parent = NULL;
3383 gtk_widget_set_parent_window (widget, NULL);
3384 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3387 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3388 g_object_unref (toplevel);
3391 g_object_notify (G_OBJECT (widget), "parent");
3392 g_object_thaw_notify (G_OBJECT (widget));
3394 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3395 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3396 g_object_unref (widget);
3400 * gtk_widget_destroy:
3401 * @widget: a #GtkWidget
3403 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3404 * you don't have to cast the widget to #GtkObject. When a widget is
3405 * destroyed, it will break any references it holds to other objects.
3406 * If the widget is inside a container, the widget will be removed
3407 * from the container. If the widget is a toplevel (derived from
3408 * #GtkWindow), it will be removed from the list of toplevels, and the
3409 * reference GTK+ holds to it will be removed. Removing a
3410 * widget from its container or the list of toplevels results in the
3411 * widget being finalized, unless you've added additional references
3412 * to the widget with g_object_ref().
3414 * In most cases, only toplevel widgets (windows) require explicit
3415 * destruction, because when you destroy a toplevel its children will
3416 * be destroyed as well.
3419 gtk_widget_destroy (GtkWidget *widget)
3421 g_return_if_fail (GTK_IS_WIDGET (widget));
3423 gtk_object_destroy ((GtkObject*) widget);
3427 * gtk_widget_destroyed:
3428 * @widget: a #GtkWidget
3429 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3431 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3432 * %NULL. It's intended to be used as a callback connected to the
3433 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3434 * as a signal handler, and pass the address of your widget variable
3435 * as user data. Then when the widget is destroyed, the variable will
3436 * be set to %NULL. Useful for example to avoid multiple copies
3437 * of the same dialog.
3440 gtk_widget_destroyed (GtkWidget *widget,
3441 GtkWidget **widget_pointer)
3443 /* Don't make any assumptions about the
3445 * Even check widget_pointer.
3448 *widget_pointer = NULL;
3453 * @widget: a #GtkWidget
3455 * Flags a widget to be displayed. Any widget that isn't shown will
3456 * not appear on the screen. If you want to show all the widgets in a
3457 * container, it's easier to call gtk_widget_show_all() on the
3458 * container, instead of individually showing the widgets.
3460 * Remember that you have to show the containers containing a widget,
3461 * in addition to the widget itself, before it will appear onscreen.
3463 * When a toplevel container is shown, it is immediately realized and
3464 * mapped; other shown widgets are realized and mapped when their
3465 * toplevel container is realized and mapped.
3468 gtk_widget_show (GtkWidget *widget)
3470 g_return_if_fail (GTK_IS_WIDGET (widget));
3472 if (!gtk_widget_get_visible (widget))
3474 g_object_ref (widget);
3475 if (!gtk_widget_is_toplevel (widget))
3476 gtk_widget_queue_resize (widget);
3477 g_signal_emit (widget, widget_signals[SHOW], 0);
3478 g_object_notify (G_OBJECT (widget), "visible");
3479 g_object_unref (widget);
3484 gtk_widget_real_show (GtkWidget *widget)
3486 GtkWidgetPrivate *priv = widget->priv;
3488 if (!gtk_widget_get_visible (widget))
3490 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3493 gtk_widget_get_mapped (priv->parent) &&
3494 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3495 !gtk_widget_get_mapped (widget))
3496 gtk_widget_map (widget);
3501 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3504 g_signal_handlers_disconnect_by_func (widget,
3505 gtk_widget_show_map_callback,
3510 * gtk_widget_show_now:
3511 * @widget: a #GtkWidget
3513 * Shows a widget. If the widget is an unmapped toplevel widget
3514 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3515 * loop and wait for the window to actually be mapped. Be careful;
3516 * because the main loop is running, anything can happen during
3520 gtk_widget_show_now (GtkWidget *widget)
3524 g_return_if_fail (GTK_IS_WIDGET (widget));
3526 /* make sure we will get event */
3527 if (!gtk_widget_get_mapped (widget) &&
3528 gtk_widget_is_toplevel (widget))
3530 gtk_widget_show (widget);
3532 g_signal_connect (widget, "map-event",
3533 G_CALLBACK (gtk_widget_show_map_callback),
3537 gtk_main_iteration ();
3540 gtk_widget_show (widget);
3545 * @widget: a #GtkWidget
3547 * Reverses the effects of gtk_widget_show(), causing the widget to be
3548 * hidden (invisible to the user).
3551 gtk_widget_hide (GtkWidget *widget)
3553 g_return_if_fail (GTK_IS_WIDGET (widget));
3555 if (gtk_widget_get_visible (widget))
3557 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3559 g_object_ref (widget);
3560 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3561 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3563 g_signal_emit (widget, widget_signals[HIDE], 0);
3564 if (!gtk_widget_is_toplevel (widget))
3565 gtk_widget_queue_resize (widget);
3566 g_object_notify (G_OBJECT (widget), "visible");
3567 g_object_unref (widget);
3572 gtk_widget_real_hide (GtkWidget *widget)
3574 if (gtk_widget_get_visible (widget))
3576 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3578 if (gtk_widget_get_mapped (widget))
3579 gtk_widget_unmap (widget);
3584 * gtk_widget_hide_on_delete:
3585 * @widget: a #GtkWidget
3587 * Utility function; intended to be connected to the #GtkWidget::delete-event
3588 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3589 * argument, then returns %TRUE. If connected to ::delete-event, the
3590 * result is that clicking the close button for a window (on the
3591 * window frame, top right corner usually) will hide but not destroy
3592 * the window. By default, GTK+ destroys windows when ::delete-event
3595 * Return value: %TRUE
3598 gtk_widget_hide_on_delete (GtkWidget *widget)
3600 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3602 gtk_widget_hide (widget);
3608 * gtk_widget_show_all:
3609 * @widget: a #GtkWidget
3611 * Recursively shows a widget, and any child widgets (if the widget is
3615 gtk_widget_show_all (GtkWidget *widget)
3617 GtkWidgetClass *class;
3619 g_return_if_fail (GTK_IS_WIDGET (widget));
3621 if (gtk_widget_get_no_show_all (widget))
3624 class = GTK_WIDGET_GET_CLASS (widget);
3626 if (class->show_all)
3627 class->show_all (widget);
3631 * gtk_widget_hide_all:
3632 * @widget: a #GtkWidget
3634 * Recursively hides a widget and any child widgets.
3637 gtk_widget_hide_all (GtkWidget *widget)
3639 GtkWidgetClass *class;
3641 g_return_if_fail (GTK_IS_WIDGET (widget));
3643 if (gtk_widget_get_no_show_all (widget))
3646 class = GTK_WIDGET_GET_CLASS (widget);
3648 if (class->hide_all)
3649 class->hide_all (widget);
3654 * @widget: a #GtkWidget
3656 * This function is only for use in widget implementations. Causes
3657 * a widget to be mapped if it isn't already.
3660 gtk_widget_map (GtkWidget *widget)
3662 GtkWidgetPrivate *priv;
3664 g_return_if_fail (GTK_IS_WIDGET (widget));
3665 g_return_if_fail (gtk_widget_get_visible (widget));
3666 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3668 priv = widget->priv;
3670 if (!gtk_widget_get_mapped (widget))
3672 if (!gtk_widget_get_realized (widget))
3673 gtk_widget_realize (widget);
3675 g_signal_emit (widget, widget_signals[MAP], 0);
3677 if (!gtk_widget_get_has_window (widget))
3678 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3684 * @widget: a #GtkWidget
3686 * This function is only for use in widget implementations. Causes
3687 * a widget to be unmapped if it's currently mapped.
3690 gtk_widget_unmap (GtkWidget *widget)
3692 GtkWidgetPrivate *priv;
3694 g_return_if_fail (GTK_IS_WIDGET (widget));
3696 priv = widget->priv;
3698 if (gtk_widget_get_mapped (widget))
3700 if (!gtk_widget_get_has_window (widget))
3701 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3702 _gtk_tooltip_hide (widget);
3703 g_signal_emit (widget, widget_signals[UNMAP], 0);
3708 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3709 GdkExtensionMode mode,
3712 GtkWidgetPrivate *priv = widget->priv;
3713 GList *free_list = NULL;
3716 if (window_list == NULL)
3718 if (gtk_widget_get_has_window (widget))
3719 window_list = g_list_prepend (NULL, priv->window);
3721 window_list = gdk_window_get_children (priv->window);
3723 free_list = window_list;
3726 for (l = window_list; l != NULL; l = l->next)
3728 GdkWindow *window = l->data;
3731 gdk_window_get_user_data (window, &user_data);
3732 if (user_data == widget)
3736 gdk_input_set_extension_events (window,
3737 gdk_window_get_events (window),
3740 children = gdk_window_get_children (window);
3743 gtk_widget_set_extension_events_internal (widget, mode, children);
3744 g_list_free (children);
3750 g_list_free (free_list);
3754 _gtk_widget_enable_device_events (GtkWidget *widget)
3756 GHashTable *device_events;
3757 GHashTableIter iter;
3758 gpointer key, value;
3760 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3765 g_hash_table_iter_init (&iter, device_events);
3767 while (g_hash_table_iter_next (&iter, &key, &value))
3770 GdkEventMask event_mask;
3773 event_mask = GPOINTER_TO_UINT (value);
3774 gtk_widget_add_events_internal (widget, device, event_mask);
3779 * gtk_widget_realize:
3780 * @widget: a #GtkWidget
3782 * Creates the GDK (windowing system) resources associated with a
3783 * widget. For example, @widget->window will be created when a widget
3784 * is realized. Normally realization happens implicitly; if you show
3785 * a widget and all its parent containers, then the widget will be
3786 * realized and mapped automatically.
3788 * Realizing a widget requires all
3789 * the widget's parent widgets to be realized; calling
3790 * gtk_widget_realize() realizes the widget's parents in addition to
3791 * @widget itself. If a widget is not yet inside a toplevel window
3792 * when you realize it, bad things will happen.
3794 * This function is primarily used in widget implementations, and
3795 * isn't very useful otherwise. Many times when you think you might
3796 * need it, a better approach is to connect to a signal that will be
3797 * called after the widget is realized automatically, such as
3798 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3799 * GtkWidget::realize signal.
3802 gtk_widget_realize (GtkWidget *widget)
3804 GtkWidgetPrivate *priv;
3805 GdkExtensionMode mode;
3806 cairo_region_t *region;
3808 g_return_if_fail (GTK_IS_WIDGET (widget));
3809 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3810 GTK_IS_INVISIBLE (widget));
3812 priv = widget->priv;
3814 if (!gtk_widget_get_realized (widget))
3817 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3818 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3821 if (priv->parent == NULL &&
3822 !gtk_widget_is_toplevel (widget))
3823 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3824 "inside a toplevel window is not going to work very well. "
3825 "Widgets must be inside a toplevel container before realizing them.");
3827 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3828 gtk_widget_realize (priv->parent);
3830 gtk_widget_ensure_style (widget);
3832 g_signal_emit (widget, widget_signals[REALIZE], 0);
3834 gtk_widget_real_set_has_tooltip (widget,
3835 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3838 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3840 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3841 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3844 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3846 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3848 mode = gtk_widget_get_extension_events (widget);
3849 if (mode != GDK_EXTENSION_EVENTS_NONE)
3850 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3852 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3853 gdk_window_set_support_multidevice (priv->window, TRUE);
3855 _gtk_widget_enable_device_events (widget);
3860 * gtk_widget_unrealize:
3861 * @widget: a #GtkWidget
3863 * This function is only useful in widget implementations.
3864 * Causes a widget to be unrealized (frees all GDK resources
3865 * associated with the widget, such as @widget->window).
3868 gtk_widget_unrealize (GtkWidget *widget)
3870 g_return_if_fail (GTK_IS_WIDGET (widget));
3872 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3873 gtk_widget_shape_combine_region (widget, NULL);
3875 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3876 gtk_widget_input_shape_combine_region (widget, NULL);
3878 if (gtk_widget_get_realized (widget))
3880 g_object_ref (widget);
3881 _gtk_tooltip_hide (widget);
3882 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3883 gtk_widget_set_realized (widget, FALSE);
3884 gtk_widget_set_mapped (widget, FALSE);
3885 g_object_unref (widget);
3889 /*****************************************
3891 *****************************************/
3894 * gtk_widget_queue_draw_area:
3895 * @widget: a #GtkWidget
3896 * @x: x coordinate of upper-left corner of rectangle to redraw
3897 * @y: y coordinate of upper-left corner of rectangle to redraw
3898 * @width: width of region to draw
3899 * @height: height of region to draw
3901 * Invalidates the rectangular area of @widget defined by @x, @y,
3902 * @width and @height by calling gdk_window_invalidate_rect() on the
3903 * widget's window and all its child windows. Once the main loop
3904 * becomes idle (after the current batch of events has been processed,
3905 * roughly), the window will receive expose events for the union of
3906 * all regions that have been invalidated.
3908 * Normally you would only use this function in widget
3909 * implementations. You might also use it, or
3910 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3911 * #GtkDrawingArea or some portion thereof.
3913 * Frequently you can just call gdk_window_invalidate_rect() or
3914 * gdk_window_invalidate_region() instead of this function. Those
3915 * functions will invalidate only a single window, instead of the
3916 * widget and all its children.
3918 * The advantage of adding to the invalidated region compared to
3919 * simply drawing immediately is efficiency; using an invalid region
3920 * ensures that you only have to redraw one time.
3923 gtk_widget_queue_draw_area (GtkWidget *widget,
3929 GtkWidgetPrivate *priv;
3930 GdkRectangle invalid_rect;
3933 g_return_if_fail (GTK_IS_WIDGET (widget));
3935 priv = widget->priv;
3937 if (!gtk_widget_get_realized (widget))
3940 /* Just return if the widget or one of its ancestors isn't mapped */
3941 for (w = widget; w != NULL; w = w->priv->parent)
3942 if (!gtk_widget_get_mapped (w))
3945 /* Find the correct widget */
3947 if (gtk_widget_get_has_window (widget))
3951 /* Translate widget relative to window-relative */
3953 gint wx, wy, wwidth, wheight;
3955 gdk_window_get_position (priv->window, &wx, &wy);
3956 x -= wx - priv->allocation.x;
3957 y -= wy - priv->allocation.y;
3959 gdk_drawable_get_size (priv->window, &wwidth, &wheight);
3961 if (x + width <= 0 || y + height <= 0 ||
3962 x >= wwidth || y >= wheight)
3973 if (x + width > wwidth)
3975 if (y + height > wheight)
3976 height = wheight - y;
3982 invalid_rect.width = width;
3983 invalid_rect.height = height;
3985 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
3989 * gtk_widget_queue_draw:
3990 * @widget: a #GtkWidget
3992 * Equivalent to calling gtk_widget_queue_draw_area() for the
3993 * entire area of a widget.
3996 gtk_widget_queue_draw (GtkWidget *widget)
4000 g_return_if_fail (GTK_IS_WIDGET (widget));
4002 gtk_widget_get_allocation (widget, &rect);
4004 if (!gtk_widget_get_has_window (widget))
4005 gtk_widget_queue_draw_area (widget,
4006 rect.x, rect.y, rect.width, rect.height);
4008 gtk_widget_queue_draw_area (widget,
4009 0, 0, rect.width, rect.height);
4013 * gtk_widget_queue_resize:
4014 * @widget: a #GtkWidget
4016 * This function is only for use in widget implementations.
4017 * Flags a widget to have its size renegotiated; should
4018 * be called when a widget for some reason has a new size request.
4019 * For example, when you change the text in a #GtkLabel, #GtkLabel
4020 * queues a resize to ensure there's enough space for the new text.
4023 gtk_widget_queue_resize (GtkWidget *widget)
4025 g_return_if_fail (GTK_IS_WIDGET (widget));
4027 if (gtk_widget_get_realized (widget))
4028 gtk_widget_queue_shallow_draw (widget);
4030 _gtk_size_group_queue_resize (widget);
4034 * gtk_widget_queue_resize_no_redraw:
4035 * @widget: a #GtkWidget
4037 * This function works like gtk_widget_queue_resize(),
4038 * except that the widget is not invalidated.
4043 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4045 g_return_if_fail (GTK_IS_WIDGET (widget));
4047 _gtk_size_group_queue_resize (widget);
4051 * gtk_widget_size_request:
4052 * @widget: a #GtkWidget
4053 * @requisition: (out): a #GtkRequisition to be filled in
4055 * This function is typically used when implementing a #GtkContainer
4056 * subclass. Obtains the preferred size of a widget. The container
4057 * uses this information to arrange its child widgets and decide what
4058 * size allocations to give them with gtk_widget_size_allocate().
4060 * You can also call this function from an application, with some
4061 * caveats. Most notably, getting a size request requires the widget
4062 * to be associated with a screen, because font information may be
4063 * needed. Multihead-aware applications should keep this in mind.
4065 * Also remember that the size request is not necessarily the size
4066 * a widget will actually be allocated.
4068 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4071 gtk_widget_size_request (GtkWidget *widget,
4072 GtkRequisition *requisition)
4074 g_return_if_fail (GTK_IS_WIDGET (widget));
4076 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4080 * gtk_widget_get_child_requisition:
4081 * @widget: a #GtkWidget
4082 * @requisition: (out): a #GtkRequisition to be filled in
4084 * This function is only for use in widget implementations. Obtains
4085 * @widget->requisition, unless someone has forced a particular
4086 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4087 * in which case it returns that geometry instead of the widget's
4090 * This function differs from gtk_widget_size_request() in that
4091 * it retrieves the last size request value from @widget->requisition,
4092 * while gtk_widget_size_request() actually calls the "size_request" method
4093 * on @widget to compute the size request and fill in @widget->requisition,
4094 * and only then returns @widget->requisition.
4096 * Because this function does not call the "size_request" method, it
4097 * can only be used when you know that @widget->requisition is
4098 * up-to-date, that is, gtk_widget_size_request() has been called
4099 * since the last time a resize was queued. In general, only container
4100 * implementations have this information; applications should use
4101 * gtk_widget_size_request().
4104 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4107 gtk_widget_get_child_requisition (GtkWidget *widget,
4108 GtkRequisition *requisition)
4110 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4114 invalidate_predicate (GdkWindow *window,
4119 gdk_window_get_user_data (window, &user_data);
4121 return (user_data == data);
4124 /* Invalidate @region in widget->window and all children
4125 * of widget->window owned by widget. @region is in the
4126 * same coordinates as widget->allocation and will be
4127 * modified by this call.
4130 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4131 cairo_region_t *region)
4133 GtkWidgetPrivate *priv = widget->priv;
4135 if (!gtk_widget_get_realized (widget))
4138 if (gtk_widget_get_has_window (widget) && priv->parent)
4142 gdk_window_get_position (priv->window, &x, &y);
4143 cairo_region_translate (region, -x, -y);
4146 gdk_window_invalidate_maybe_recurse (priv->window, region,
4147 invalidate_predicate, widget);
4151 * gtk_widget_queue_shallow_draw:
4152 * @widget: a #GtkWidget
4154 * Like gtk_widget_queue_draw(), but only windows owned
4155 * by @widget are invalidated.
4158 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4161 cairo_region_t *region;
4163 if (!gtk_widget_get_realized (widget))
4166 gtk_widget_get_allocation (widget, &rect);
4168 region = cairo_region_create_rectangle (&rect);
4169 gtk_widget_invalidate_widget_windows (widget, region);
4170 cairo_region_destroy (region);
4174 * gtk_widget_size_allocate:
4175 * @widget: a #GtkWidget
4176 * @allocation: (inout): position and size to be allocated to @widget
4178 * This function is only used by #GtkContainer subclasses, to assign a size
4179 * and position to their child widgets.
4181 * In this function, the allocation may be adjusted. It will be forced
4182 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4183 * method on the child will be used to adjust the allocation. Standard
4184 * adjustments include removing the widget's margins, and applying the
4185 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4188 gtk_widget_size_allocate (GtkWidget *widget,
4189 GtkAllocation *allocation)
4191 GtkWidgetPrivate *priv;
4192 GdkRectangle real_allocation;
4193 GdkRectangle old_allocation;
4194 GdkRectangle adjusted_allocation;
4195 gboolean alloc_needed;
4196 gboolean size_changed;
4197 gboolean position_changed;
4199 priv = widget->priv;
4201 g_return_if_fail (GTK_IS_WIDGET (widget));
4203 #ifdef G_ENABLE_DEBUG
4204 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4215 parent = gtk_widget_get_parent (parent);
4218 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4219 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4220 2 * depth, " ", name,
4221 allocation->width, allocation->height);
4223 #endif /* G_ENABLE_DEBUG */
4225 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4226 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4227 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4228 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4230 old_allocation = priv->allocation;
4231 real_allocation = *allocation;
4233 adjusted_allocation = real_allocation;
4234 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4236 if (adjusted_allocation.x < real_allocation.x ||
4237 adjusted_allocation.y < real_allocation.y ||
4238 (adjusted_allocation.x + adjusted_allocation.width) >
4239 (real_allocation.x + real_allocation.width) ||
4240 (adjusted_allocation.y + adjusted_allocation.height >
4241 real_allocation.y + real_allocation.height))
4243 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",
4244 G_OBJECT_TYPE_NAME (widget), widget,
4245 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4246 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4247 adjusted_allocation = real_allocation; /* veto it */
4251 real_allocation = adjusted_allocation;
4254 if (real_allocation.width < 0 || real_allocation.height < 0)
4256 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4257 real_allocation.width,
4258 real_allocation.height);
4261 real_allocation.width = MAX (real_allocation.width, 1);
4262 real_allocation.height = MAX (real_allocation.height, 1);
4264 size_changed = (old_allocation.width != real_allocation.width ||
4265 old_allocation.height != real_allocation.height);
4266 position_changed = (old_allocation.x != real_allocation.x ||
4267 old_allocation.y != real_allocation.y);
4269 if (!alloc_needed && !size_changed && !position_changed)
4272 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4274 if (gtk_widget_get_mapped (widget))
4276 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4278 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4280 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4281 cairo_region_union_rectangle (invalidate, &old_allocation);
4283 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4284 cairo_region_destroy (invalidate);
4289 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4291 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4293 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4294 cairo_region_union_rectangle (invalidate, &old_allocation);
4296 gtk_widget_invalidate_widget_windows (widget, invalidate);
4297 cairo_region_destroy (invalidate);
4302 if ((size_changed || position_changed) && priv->parent &&
4303 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4305 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4306 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4307 cairo_region_destroy (invalidate);
4312 * gtk_widget_common_ancestor:
4313 * @widget_a: a #GtkWidget
4314 * @widget_b: a #GtkWidget
4316 * Find the common ancestor of @widget_a and @widget_b that
4317 * is closest to the two widgets.
4319 * Return value: the closest common ancestor of @widget_a and
4320 * @widget_b or %NULL if @widget_a and @widget_b do not
4321 * share a common ancestor.
4324 gtk_widget_common_ancestor (GtkWidget *widget_a,
4325 GtkWidget *widget_b)
4327 GtkWidget *parent_a;
4328 GtkWidget *parent_b;
4332 parent_a = widget_a;
4333 while (parent_a->priv->parent)
4335 parent_a = parent_a->priv->parent;
4339 parent_b = widget_b;
4340 while (parent_b->priv->parent)
4342 parent_b = parent_b->priv->parent;
4346 if (parent_a != parent_b)
4349 while (depth_a > depth_b)
4351 widget_a = widget_a->priv->parent;
4355 while (depth_b > depth_a)
4357 widget_b = widget_b->priv->parent;
4361 while (widget_a != widget_b)
4363 widget_a = widget_a->priv->parent;
4364 widget_b = widget_b->priv->parent;
4371 * gtk_widget_translate_coordinates:
4372 * @src_widget: a #GtkWidget
4373 * @dest_widget: a #GtkWidget
4374 * @src_x: X position relative to @src_widget
4375 * @src_y: Y position relative to @src_widget
4376 * @dest_x: (out): location to store X position relative to @dest_widget
4377 * @dest_y: (out): location to store Y position relative to @dest_widget
4379 * Translate coordinates relative to @src_widget's allocation to coordinates
4380 * relative to @dest_widget's allocations. In order to perform this
4381 * operation, both widgets must be realized, and must share a common
4384 * Return value: %FALSE if either widget was not realized, or there
4385 * was no common ancestor. In this case, nothing is stored in
4386 * *@dest_x and *@dest_y. Otherwise %TRUE.
4389 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4390 GtkWidget *dest_widget,
4396 GtkWidgetPrivate *src_priv = src_widget->priv;
4397 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4398 GtkWidget *ancestor;
4400 GList *dest_list = NULL;
4402 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4403 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4405 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4406 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4409 /* Translate from allocation relative to window relative */
4410 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4413 gdk_window_get_position (src_priv->window, &wx, &wy);
4415 src_x -= wx - src_priv->allocation.x;
4416 src_y -= wy - src_priv->allocation.y;
4420 src_x += src_priv->allocation.x;
4421 src_y += src_priv->allocation.y;
4424 /* Translate to the common ancestor */
4425 window = src_priv->window;
4426 while (window != ancestor->priv->window)
4430 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4435 window = gdk_window_get_effective_parent (window);
4437 if (!window) /* Handle GtkHandleBox */
4442 window = dest_priv->window;
4443 while (window != ancestor->priv->window)
4445 dest_list = g_list_prepend (dest_list, window);
4447 window = gdk_window_get_effective_parent (window);
4449 if (!window) /* Handle GtkHandleBox */
4451 g_list_free (dest_list);
4460 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4465 dest_list = g_list_remove (dest_list, dest_list->data);
4468 /* Translate from window relative to allocation relative */
4469 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4472 gdk_window_get_position (dest_priv->window, &wx, &wy);
4474 src_x += wx - dest_priv->allocation.x;
4475 src_y += wy - dest_priv->allocation.y;
4479 src_x -= dest_priv->allocation.x;
4480 src_y -= dest_priv->allocation.y;
4492 gtk_widget_real_size_allocate (GtkWidget *widget,
4493 GtkAllocation *allocation)
4495 GtkWidgetPrivate *priv = widget->priv;
4497 priv->allocation = *allocation;
4499 if (gtk_widget_get_realized (widget) &&
4500 gtk_widget_get_has_window (widget))
4502 gdk_window_move_resize (priv->window,
4503 allocation->x, allocation->y,
4504 allocation->width, allocation->height);
4509 get_span_inside_border (GtkWidget *widget,
4513 int allocated_outside_size,
4514 int natural_inside_size,
4515 int *coord_inside_p,
4518 int inside_allocated;
4522 inside_allocated = allocated_outside_size - start_pad - end_pad;
4524 content_size = natural_inside_size;
4525 if (content_size > inside_allocated)
4527 /* didn't get full natural size */
4528 content_size = inside_allocated;
4531 coord = size = 0; /* silence compiler */
4534 case GTK_ALIGN_FILL:
4536 size = inside_allocated;
4538 case GTK_ALIGN_START:
4540 size = content_size;
4543 coord = allocated_outside_size - end_pad - content_size;
4544 size = content_size;
4546 case GTK_ALIGN_CENTER:
4547 coord = start_pad + (inside_allocated - content_size) / 2;
4548 size = content_size;
4553 *coord_inside_p = coord;
4556 *size_inside_p = size;
4560 get_span_inside_border_horizontal (GtkWidget *widget,
4561 const GtkWidgetAuxInfo *aux_info,
4562 int allocated_outside_width,
4563 int natural_inside_width,
4565 int *width_inside_p)
4567 get_span_inside_border (widget,
4569 aux_info->margin.left,
4570 aux_info->margin.right,
4571 allocated_outside_width,
4572 natural_inside_width,
4578 get_span_inside_border_vertical (GtkWidget *widget,
4579 const GtkWidgetAuxInfo *aux_info,
4580 int allocated_outside_height,
4581 int natural_inside_height,
4583 int *height_inside_p)
4585 get_span_inside_border (widget,
4587 aux_info->margin.top,
4588 aux_info->margin.bottom,
4589 allocated_outside_height,
4590 natural_inside_height,
4596 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4597 GtkAllocation *allocation)
4599 const GtkWidgetAuxInfo *aux_info;
4600 GtkRequisition min, natural;
4603 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4605 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &min, &natural);
4607 get_span_inside_border_horizontal (widget,
4612 get_span_inside_border_vertical (widget,
4620 allocation->width = w;
4621 allocation->height = h;
4625 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4628 GtkWidgetPrivate *priv = widget->priv;
4630 /* widgets must be onscreen for accels to take effect */
4631 return gtk_widget_is_sensitive (widget) &&
4632 gtk_widget_is_drawable (widget) &&
4633 gdk_window_is_viewable (priv->window);
4637 * gtk_widget_can_activate_accel:
4638 * @widget: a #GtkWidget
4639 * @signal_id: the ID of a signal installed on @widget
4641 * Determines whether an accelerator that activates the signal
4642 * identified by @signal_id can currently be activated.
4643 * This is done by emitting the #GtkWidget::can-activate-accel
4644 * signal on @widget; if the signal isn't overridden by a
4645 * handler or in a derived widget, then the default check is
4646 * that the widget must be sensitive, and the widget and all
4647 * its ancestors mapped.
4649 * Return value: %TRUE if the accelerator can be activated.
4654 gtk_widget_can_activate_accel (GtkWidget *widget,
4657 gboolean can_activate = FALSE;
4658 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4659 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4660 return can_activate;
4669 closure_accel_activate (GClosure *closure,
4670 GValue *return_value,
4671 guint n_param_values,
4672 const GValue *param_values,
4673 gpointer invocation_hint,
4674 gpointer marshal_data)
4676 AccelClosure *aclosure = (AccelClosure*) closure;
4677 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4680 g_signal_emit (closure->data, aclosure->signal_id, 0);
4682 /* whether accelerator was handled */
4683 g_value_set_boolean (return_value, can_activate);
4687 closures_destroy (gpointer data)
4689 GSList *slist, *closures = data;
4691 for (slist = closures; slist; slist = slist->next)
4693 g_closure_invalidate (slist->data);
4694 g_closure_unref (slist->data);
4696 g_slist_free (closures);
4700 widget_new_accel_closure (GtkWidget *widget,
4703 AccelClosure *aclosure;
4704 GClosure *closure = NULL;
4705 GSList *slist, *closures;
4707 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4708 for (slist = closures; slist; slist = slist->next)
4709 if (!gtk_accel_group_from_accel_closure (slist->data))
4711 /* reuse this closure */
4712 closure = slist->data;
4717 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4718 closures = g_slist_prepend (closures, g_closure_ref (closure));
4719 g_closure_sink (closure);
4720 g_closure_set_marshal (closure, closure_accel_activate);
4722 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4724 aclosure = (AccelClosure*) closure;
4725 g_assert (closure->data == widget);
4726 g_assert (closure->marshal == closure_accel_activate);
4727 aclosure->signal_id = signal_id;
4733 * gtk_widget_add_accelerator
4734 * @widget: widget to install an accelerator on
4735 * @accel_signal: widget signal to emit on accelerator activation
4736 * @accel_group: accel group for this widget, added to its toplevel
4737 * @accel_key: GDK keyval of the accelerator
4738 * @accel_mods: modifier key combination of the accelerator
4739 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4741 * Installs an accelerator for this @widget in @accel_group that causes
4742 * @accel_signal to be emitted if the accelerator is activated.
4743 * The @accel_group needs to be added to the widget's toplevel via
4744 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4745 * Accelerators added through this function are not user changeable during
4746 * runtime. If you want to support accelerators that can be changed by the
4747 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4748 * gtk_menu_item_set_accel_path() instead.
4751 gtk_widget_add_accelerator (GtkWidget *widget,
4752 const gchar *accel_signal,
4753 GtkAccelGroup *accel_group,
4755 GdkModifierType accel_mods,
4756 GtkAccelFlags accel_flags)
4761 g_return_if_fail (GTK_IS_WIDGET (widget));
4762 g_return_if_fail (accel_signal != NULL);
4763 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4765 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4766 if (!query.signal_id ||
4767 !(query.signal_flags & G_SIGNAL_ACTION) ||
4768 query.return_type != G_TYPE_NONE ||
4771 /* hmm, should be elaborate enough */
4772 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4773 G_OBJECT_TYPE_NAME (widget), accel_signal);
4777 closure = widget_new_accel_closure (widget, query.signal_id);
4779 g_object_ref (widget);
4781 /* install the accelerator. since we don't map this onto an accel_path,
4782 * the accelerator will automatically be locked.
4784 gtk_accel_group_connect (accel_group,
4787 accel_flags | GTK_ACCEL_LOCKED,
4790 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4792 g_object_unref (widget);
4796 * gtk_widget_remove_accelerator:
4797 * @widget: widget to install an accelerator on
4798 * @accel_group: accel group for this widget
4799 * @accel_key: GDK keyval of the accelerator
4800 * @accel_mods: modifier key combination of the accelerator
4801 * @returns: whether an accelerator was installed and could be removed
4803 * Removes an accelerator from @widget, previously installed with
4804 * gtk_widget_add_accelerator().
4807 gtk_widget_remove_accelerator (GtkWidget *widget,
4808 GtkAccelGroup *accel_group,
4810 GdkModifierType accel_mods)
4812 GtkAccelGroupEntry *ag_entry;
4813 GList *slist, *clist;
4816 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4817 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4819 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4820 clist = gtk_widget_list_accel_closures (widget);
4821 for (slist = clist; slist; slist = slist->next)
4825 for (i = 0; i < n; i++)
4826 if (slist->data == (gpointer) ag_entry[i].closure)
4828 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4830 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4832 g_list_free (clist);
4837 g_list_free (clist);
4839 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4840 accel_key, accel_mods, accel_group,
4841 G_OBJECT_TYPE_NAME (widget), widget);
4847 * gtk_widget_list_accel_closures:
4848 * @widget: widget to list accelerator closures for
4850 * Lists the closures used by @widget for accelerator group connections
4851 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4852 * The closures can be used to monitor accelerator changes on @widget,
4853 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4854 * #GtkAccelGroup of a closure which can be found out with
4855 * gtk_accel_group_from_accel_closure().
4857 * Return value: (transfer container) (element-type GClosure):
4858 * a newly allocated #GList of closures
4861 gtk_widget_list_accel_closures (GtkWidget *widget)
4864 GList *clist = NULL;
4866 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4868 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4869 if (gtk_accel_group_from_accel_closure (slist->data))
4870 clist = g_list_prepend (clist, slist->data);
4876 GtkAccelGroup *accel_group;
4881 destroy_accel_path (gpointer data)
4883 AccelPath *apath = data;
4885 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4887 /* closures_destroy takes care of unrefing the closure */
4888 g_object_unref (apath->accel_group);
4890 g_slice_free (AccelPath, apath);
4895 * gtk_widget_set_accel_path:
4896 * @widget: a #GtkWidget
4897 * @accel_path: (allow-none): path used to look up the accelerator
4898 * @accel_group: (allow-none): a #GtkAccelGroup.
4900 * Given an accelerator group, @accel_group, and an accelerator path,
4901 * @accel_path, sets up an accelerator in @accel_group so whenever the
4902 * key binding that is defined for @accel_path is pressed, @widget
4903 * will be activated. This removes any accelerators (for any
4904 * accelerator group) installed by previous calls to
4905 * gtk_widget_set_accel_path(). Associating accelerators with
4906 * paths allows them to be modified by the user and the modifications
4907 * to be saved for future use. (See gtk_accel_map_save().)
4909 * This function is a low level function that would most likely
4910 * be used by a menu creation system like #GtkUIManager. If you
4911 * use #GtkUIManager, setting up accelerator paths will be done
4914 * Even when you you aren't using #GtkUIManager, if you only want to
4915 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4916 * provides a somewhat more convenient interface.
4918 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4919 * pass a static string, you can save some memory by interning it first with
4920 * g_intern_static_string().
4923 gtk_widget_set_accel_path (GtkWidget *widget,
4924 const gchar *accel_path,
4925 GtkAccelGroup *accel_group)
4929 g_return_if_fail (GTK_IS_WIDGET (widget));
4930 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4934 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4935 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4937 gtk_accel_map_add_entry (accel_path, 0, 0);
4938 apath = g_slice_new (AccelPath);
4939 apath->accel_group = g_object_ref (accel_group);
4940 apath->path_quark = g_quark_from_string (accel_path);
4941 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4946 /* also removes possible old settings */
4947 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4950 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4952 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4956 _gtk_widget_get_accel_path (GtkWidget *widget,
4961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4963 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4965 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4966 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4970 * gtk_widget_mnemonic_activate:
4971 * @widget: a #GtkWidget
4972 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4974 * Emits the #GtkWidget::mnemonic-activate signal.
4976 * The default handler for this signal activates the @widget if
4977 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4980 * Returns: %TRUE if the signal has been handled
4983 gtk_widget_mnemonic_activate (GtkWidget *widget,
4984 gboolean group_cycling)
4988 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4990 group_cycling = group_cycling != FALSE;
4991 if (!gtk_widget_is_sensitive (widget))
4994 g_signal_emit (widget,
4995 widget_signals[MNEMONIC_ACTIVATE],
5003 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5004 gboolean group_cycling)
5006 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5007 gtk_widget_activate (widget);
5008 else if (gtk_widget_get_can_focus (widget))
5009 gtk_widget_grab_focus (widget);
5012 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5013 G_OBJECT_TYPE_NAME (widget));
5014 gtk_widget_error_bell (widget);
5020 gtk_widget_real_key_press_event (GtkWidget *widget,
5023 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5027 gtk_widget_real_key_release_event (GtkWidget *widget,
5030 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5034 gtk_widget_real_focus_in_event (GtkWidget *widget,
5035 GdkEventFocus *event)
5037 gtk_widget_queue_shallow_draw (widget);
5043 gtk_widget_real_focus_out_event (GtkWidget *widget,
5044 GdkEventFocus *event)
5046 gtk_widget_queue_shallow_draw (widget);
5051 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5052 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5056 * @widget: a #GtkWidget
5057 * @event: a #GdkEvent
5059 * Rarely-used function. This function is used to emit
5060 * the event signals on a widget (those signals should never
5061 * be emitted without using this function to do so).
5062 * If you want to synthesize an event though, don't use this function;
5063 * instead, use gtk_main_do_event() so the event will behave as if
5064 * it were in the event queue. Don't synthesize expose events; instead,
5065 * use gdk_window_invalidate_rect() to invalidate a region of the
5068 * Return value: return from the event signal emission (%TRUE if
5069 * the event was handled)
5072 gtk_widget_event (GtkWidget *widget,
5075 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5076 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5078 if (event->type == GDK_EXPOSE)
5080 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5081 "the same effect, call gdk_window_invalidate_rect/region(), "
5082 "followed by gdk_window_process_updates().");
5086 return gtk_widget_event_internal (widget, event);
5091 * gtk_widget_send_expose:
5092 * @widget: a #GtkWidget
5093 * @event: a expose #GdkEvent
5095 * Very rarely-used function. This function is used to emit
5096 * an expose event signals on a widget. This function is not
5097 * normally used directly. The only time it is used is when
5098 * propagating an expose event to a child %NO_WINDOW widget, and
5099 * that is normally done using gtk_container_propagate_expose().
5101 * If you want to force an area of a window to be redrawn,
5102 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5103 * To cause the redraw to be done immediately, follow that call
5104 * with a call to gdk_window_process_updates().
5106 * Return value: return from the event signal emission (%TRUE if
5107 * the event was handled)
5110 gtk_widget_send_expose (GtkWidget *widget,
5113 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5114 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5115 g_return_val_if_fail (event != NULL, TRUE);
5116 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5118 return gtk_widget_event_internal (widget, event);
5122 event_window_is_still_viewable (GdkEvent *event)
5124 /* Some programs, such as gnome-theme-manager, fake widgets
5125 * into exposing onto a pixmap by sending expose events with
5126 * event->window pointing to a pixmap
5128 if (GDK_IS_PIXMAP (event->any.window))
5129 return event->type == GDK_EXPOSE;
5131 /* Check that we think the event's window is viewable before
5132 * delivering the event, to prevent suprises. We do this here
5133 * at the last moment, since the event may have been queued
5134 * up behind other events, held over a recursive main loop, etc.
5136 switch (event->type)
5139 case GDK_MOTION_NOTIFY:
5140 case GDK_BUTTON_PRESS:
5141 case GDK_2BUTTON_PRESS:
5142 case GDK_3BUTTON_PRESS:
5144 case GDK_ENTER_NOTIFY:
5145 case GDK_PROXIMITY_IN:
5147 return event->any.window && gdk_window_is_viewable (event->any.window);
5150 /* The following events are the second half of paired events;
5151 * we always deliver them to deal with widgets that clean up
5152 * on the second half.
5154 case GDK_BUTTON_RELEASE:
5155 case GDK_KEY_RELEASE:
5156 case GDK_LEAVE_NOTIFY:
5157 case GDK_PROXIMITY_OUT:
5161 /* Remaining events would make sense on an not-viewable window,
5162 * or don't have an associated window.
5169 gtk_widget_event_internal (GtkWidget *widget,
5172 gboolean return_val = FALSE;
5174 /* We check only once for is-still-visible; if someone
5175 * hides the window in on of the signals on the widget,
5176 * they are responsible for returning TRUE to terminate
5179 if (!event_window_is_still_viewable (event))
5182 g_object_ref (widget);
5184 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5185 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5190 switch (event->type)
5195 case GDK_BUTTON_PRESS:
5196 case GDK_2BUTTON_PRESS:
5197 case GDK_3BUTTON_PRESS:
5198 signal_num = BUTTON_PRESS_EVENT;
5201 signal_num = SCROLL_EVENT;
5203 case GDK_BUTTON_RELEASE:
5204 signal_num = BUTTON_RELEASE_EVENT;
5206 case GDK_MOTION_NOTIFY:
5207 signal_num = MOTION_NOTIFY_EVENT;
5210 signal_num = DELETE_EVENT;
5213 signal_num = DESTROY_EVENT;
5214 _gtk_tooltip_hide (widget);
5217 signal_num = KEY_PRESS_EVENT;
5219 case GDK_KEY_RELEASE:
5220 signal_num = KEY_RELEASE_EVENT;
5222 case GDK_ENTER_NOTIFY:
5223 signal_num = ENTER_NOTIFY_EVENT;
5225 case GDK_LEAVE_NOTIFY:
5226 signal_num = LEAVE_NOTIFY_EVENT;
5228 case GDK_FOCUS_CHANGE:
5229 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5230 if (event->focus_change.in)
5231 _gtk_tooltip_focus_in (widget);
5233 _gtk_tooltip_focus_out (widget);
5236 signal_num = CONFIGURE_EVENT;
5239 signal_num = MAP_EVENT;
5242 signal_num = UNMAP_EVENT;
5244 case GDK_WINDOW_STATE:
5245 signal_num = WINDOW_STATE_EVENT;
5247 case GDK_PROPERTY_NOTIFY:
5248 signal_num = PROPERTY_NOTIFY_EVENT;
5250 case GDK_SELECTION_CLEAR:
5251 signal_num = SELECTION_CLEAR_EVENT;
5253 case GDK_SELECTION_REQUEST:
5254 signal_num = SELECTION_REQUEST_EVENT;
5256 case GDK_SELECTION_NOTIFY:
5257 signal_num = SELECTION_NOTIFY_EVENT;
5259 case GDK_PROXIMITY_IN:
5260 signal_num = PROXIMITY_IN_EVENT;
5262 case GDK_PROXIMITY_OUT:
5263 signal_num = PROXIMITY_OUT_EVENT;
5266 signal_num = NO_EXPOSE_EVENT;
5268 case GDK_CLIENT_EVENT:
5269 signal_num = CLIENT_EVENT;
5272 signal_num = EXPOSE_EVENT;
5274 case GDK_VISIBILITY_NOTIFY:
5275 signal_num = VISIBILITY_NOTIFY_EVENT;
5277 case GDK_GRAB_BROKEN:
5278 signal_num = GRAB_BROKEN;
5281 signal_num = DAMAGE_EVENT;
5284 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5288 if (signal_num != -1)
5289 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5291 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5292 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5296 g_object_unref (widget);
5302 * gtk_widget_activate:
5303 * @widget: a #GtkWidget that's activatable
5305 * For widgets that can be "activated" (buttons, menu items, etc.)
5306 * this function activates them. Activation is what happens when you
5307 * press Enter on a widget during key navigation. If @widget isn't
5308 * activatable, the function returns %FALSE.
5310 * Return value: %TRUE if the widget was activatable
5313 gtk_widget_activate (GtkWidget *widget)
5315 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5317 if (WIDGET_CLASS (widget)->activate_signal)
5319 /* FIXME: we should eventually check the signals signature here */
5320 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5329 * gtk_widget_set_scroll_adjustments:
5330 * @widget: a #GtkWidget
5331 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5332 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5334 * For widgets that support scrolling, sets the scroll adjustments and
5335 * returns %TRUE. For widgets that don't support scrolling, does
5336 * nothing and returns %FALSE. Widgets that don't support scrolling
5337 * can be scrolled by placing them in a #GtkViewport, which does
5338 * support scrolling.
5340 * Return value: %TRUE if the widget supports scrolling
5343 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5344 GtkAdjustment *hadjustment,
5345 GtkAdjustment *vadjustment)
5350 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5353 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5355 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5357 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5361 g_signal_query (signal_id, &query);
5362 if (!query.signal_id ||
5363 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5364 query.return_type != G_TYPE_NONE ||
5365 query.n_params != 2 ||
5366 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5367 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5369 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5370 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5374 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5379 gtk_widget_reparent_subwindows (GtkWidget *widget,
5380 GdkWindow *new_window)
5382 GtkWidgetPrivate *priv = widget->priv;
5384 if (!gtk_widget_get_has_window (widget))
5386 GList *children = gdk_window_get_children (priv->window);
5389 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5391 GdkWindow *window = tmp_list->data;
5394 gdk_window_get_user_data (window, &child);
5395 while (child && child != widget)
5396 child = ((GtkWidget*) child)->priv->parent;
5399 gdk_window_reparent (window, new_window, 0, 0);
5402 g_list_free (children);
5407 GList *tmp_list, *children;
5409 parent = gdk_window_get_parent (priv->window);
5412 gdk_window_reparent (priv->window, new_window, 0, 0);
5415 children = gdk_window_get_children (parent);
5417 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5419 GdkWindow *window = tmp_list->data;
5422 gdk_window_get_user_data (window, &child);
5424 if (child == widget)
5425 gdk_window_reparent (window, new_window, 0, 0);
5428 g_list_free (children);
5434 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5435 gpointer client_data)
5437 GtkWidgetPrivate *priv = widget->priv;
5439 g_assert (client_data != NULL);
5441 if (!gtk_widget_get_has_window (widget))
5444 g_object_unref (priv->window);
5445 priv->window = (GdkWindow*) client_data;
5447 g_object_ref (priv->window);
5449 if (GTK_IS_CONTAINER (widget))
5450 gtk_container_forall (GTK_CONTAINER (widget),
5451 gtk_widget_reparent_fixup_child,
5457 * gtk_widget_reparent:
5458 * @widget: a #GtkWidget
5459 * @new_parent: a #GtkContainer to move the widget into
5461 * Moves a widget from one #GtkContainer to another, handling reference
5462 * count issues to avoid destroying the widget.
5465 gtk_widget_reparent (GtkWidget *widget,
5466 GtkWidget *new_parent)
5468 GtkWidgetPrivate *priv;
5470 g_return_if_fail (GTK_IS_WIDGET (widget));
5471 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5472 priv = widget->priv;
5473 g_return_if_fail (priv->parent != NULL);
5475 if (priv->parent != new_parent)
5477 /* First try to see if we can get away without unrealizing
5478 * the widget as we reparent it. if so we set a flag so
5479 * that gtk_widget_unparent doesn't unrealize widget
5481 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5482 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5484 g_object_ref (widget);
5485 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5486 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5487 g_object_unref (widget);
5489 if (GTK_WIDGET_IN_REPARENT (widget))
5491 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5493 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5494 gtk_widget_reparent_fixup_child (widget,
5495 gtk_widget_get_parent_window (widget));
5498 g_object_notify (G_OBJECT (widget), "parent");
5503 * gtk_widget_intersect:
5504 * @widget: a #GtkWidget
5505 * @area: a rectangle
5506 * @intersection: rectangle to store intersection of @widget and @area
5508 * Computes the intersection of a @widget's area and @area, storing
5509 * the intersection in @intersection, and returns %TRUE if there was
5510 * an intersection. @intersection may be %NULL if you're only
5511 * interested in whether there was an intersection.
5513 * Return value: %TRUE if there was an intersection
5516 gtk_widget_intersect (GtkWidget *widget,
5517 const GdkRectangle *area,
5518 GdkRectangle *intersection)
5520 GtkWidgetPrivate *priv;
5525 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5526 g_return_val_if_fail (area != NULL, FALSE);
5528 priv = widget->priv;
5531 dest = intersection;
5535 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5537 if (return_val && intersection && gtk_widget_get_has_window (widget))
5539 intersection->x -= priv->allocation.x;
5540 intersection->y -= priv->allocation.y;
5547 * gtk_widget_region_intersect:
5548 * @widget: a #GtkWidget
5549 * @region: a #cairo_region_t, in the same coordinate system as
5550 * @widget->allocation. That is, relative to @widget->window
5551 * for %NO_WINDOW widgets; relative to the parent window
5552 * of @widget->window for widgets with their own window.
5553 * @returns: A newly allocated region holding the intersection of @widget
5554 * and @region. The coordinates of the return value are
5555 * relative to @widget->window for %NO_WINDOW widgets, and
5556 * relative to the parent window of @widget->window for
5557 * widgets with their own window.
5559 * Computes the intersection of a @widget's area and @region, returning
5560 * the intersection. The result may be empty, use cairo_region_is_empty() to
5564 gtk_widget_region_intersect (GtkWidget *widget,
5565 const cairo_region_t *region)
5568 cairo_region_t *dest;
5570 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5571 g_return_val_if_fail (region != NULL, NULL);
5573 gtk_widget_get_allocation (widget, &rect);
5575 dest = cairo_region_create_rectangle (&rect);
5577 cairo_region_intersect (dest, region);
5583 * _gtk_widget_grab_notify:
5584 * @widget: a #GtkWidget
5585 * @was_grabbed: whether a grab is now in effect
5587 * Emits the #GtkWidget::grab-notify signal on @widget.
5592 _gtk_widget_grab_notify (GtkWidget *widget,
5593 gboolean was_grabbed)
5595 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5599 * gtk_widget_grab_focus:
5600 * @widget: a #GtkWidget
5602 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5603 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5604 * something like #GtkFrame won't work.
5606 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5607 * gtk_widget_set_can_focus() to modify that flag.
5609 * The widget also needs to be realized and mapped. This is indicated by the
5610 * related signals. Grabbing the focus immediately after creating the widget
5611 * will likely fail and cause critical warnings.
5614 gtk_widget_grab_focus (GtkWidget *widget)
5616 g_return_if_fail (GTK_IS_WIDGET (widget));
5618 if (!gtk_widget_is_sensitive (widget))
5621 g_object_ref (widget);
5622 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5623 g_object_notify (G_OBJECT (widget), "has-focus");
5624 g_object_unref (widget);
5628 reset_focus_recurse (GtkWidget *widget,
5631 if (GTK_IS_CONTAINER (widget))
5633 GtkContainer *container;
5635 container = GTK_CONTAINER (widget);
5636 gtk_container_set_focus_child (container, NULL);
5638 gtk_container_foreach (container,
5639 reset_focus_recurse,
5645 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5647 if (gtk_widget_get_can_focus (focus_widget))
5649 GtkWidget *toplevel;
5652 /* clear the current focus setting, break if the current widget
5653 * is the focus widget's parent, since containers above that will
5654 * be set by the next loop.
5656 toplevel = gtk_widget_get_toplevel (focus_widget);
5657 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5659 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5661 if (widget == focus_widget)
5663 /* We call _gtk_window_internal_set_focus() here so that the
5664 * toplevel window can request the focus if necessary.
5665 * This is needed when the toplevel is a GtkPlug
5667 if (!gtk_widget_has_focus (widget))
5668 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5675 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5677 widget = widget->priv->parent;
5678 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5682 else if (toplevel != focus_widget)
5684 /* gtk_widget_grab_focus() operates on a tree without window...
5685 * actually, this is very questionable behaviour.
5688 gtk_container_foreach (GTK_CONTAINER (toplevel),
5689 reset_focus_recurse,
5693 /* now propagate the new focus up the widget tree and finally
5694 * set it on the window
5696 widget = focus_widget;
5697 while (widget->priv->parent)
5699 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5700 widget = widget->priv->parent;
5702 if (GTK_IS_WINDOW (widget))
5703 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5708 gtk_widget_real_query_tooltip (GtkWidget *widget,
5711 gboolean keyboard_tip,
5712 GtkTooltip *tooltip)
5714 gchar *tooltip_markup;
5715 gboolean has_tooltip;
5717 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5718 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5720 if (has_tooltip && tooltip_markup)
5722 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5730 gtk_widget_real_show_help (GtkWidget *widget,
5731 GtkWidgetHelpType help_type)
5733 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5735 _gtk_tooltip_toggle_keyboard_mode (widget);
5744 gtk_widget_real_focus (GtkWidget *widget,
5745 GtkDirectionType direction)
5747 if (!gtk_widget_get_can_focus (widget))
5750 if (!gtk_widget_is_focus (widget))
5752 gtk_widget_grab_focus (widget);
5760 gtk_widget_real_move_focus (GtkWidget *widget,
5761 GtkDirectionType direction)
5763 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5765 if (GTK_IS_WINDOW (toplevel) &&
5766 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5768 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5774 gtk_widget_real_keynav_failed (GtkWidget *widget,
5775 GtkDirectionType direction)
5777 gboolean cursor_only;
5781 case GTK_DIR_TAB_FORWARD:
5782 case GTK_DIR_TAB_BACKWARD:
5789 g_object_get (gtk_widget_get_settings (widget),
5790 "gtk-keynav-cursor-only", &cursor_only,
5797 gtk_widget_error_bell (widget);
5803 * gtk_widget_set_can_focus:
5804 * @widget: a #GtkWidget
5805 * @can_focus: whether or not @widget can own the input focus.
5807 * Specifies whether @widget can own the input focus. See
5808 * gtk_widget_grab_focus() for actually setting the input focus on a
5814 gtk_widget_set_can_focus (GtkWidget *widget,
5817 g_return_if_fail (GTK_IS_WIDGET (widget));
5819 if (can_focus != gtk_widget_get_can_focus (widget))
5822 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5824 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5826 gtk_widget_queue_resize (widget);
5827 g_object_notify (G_OBJECT (widget), "can-focus");
5832 * gtk_widget_get_can_focus:
5833 * @widget: a #GtkWidget
5835 * Determines whether @widget can own the input focus. See
5836 * gtk_widget_set_can_focus().
5838 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5843 gtk_widget_get_can_focus (GtkWidget *widget)
5845 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5847 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5851 * gtk_widget_has_focus:
5852 * @widget: a #GtkWidget
5854 * Determines if the widget has the global input focus. See
5855 * gtk_widget_is_focus() for the difference between having the global
5856 * input focus, and only having the focus within a toplevel.
5858 * Return value: %TRUE if the widget has the global input focus.
5863 gtk_widget_has_focus (GtkWidget *widget)
5865 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5867 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5871 * gtk_widget_is_focus:
5872 * @widget: a #GtkWidget
5874 * Determines if the widget is the focus widget within its
5875 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5876 * necessarily set; %HAS_FOCUS will only be set if the
5877 * toplevel widget additionally has the global input focus.)
5879 * Return value: %TRUE if the widget is the focus widget.
5882 gtk_widget_is_focus (GtkWidget *widget)
5884 GtkWidget *toplevel;
5886 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5888 toplevel = gtk_widget_get_toplevel (widget);
5890 if (GTK_IS_WINDOW (toplevel))
5891 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
5897 * gtk_widget_set_can_default:
5898 * @widget: a #GtkWidget
5899 * @can_default: whether or not @widget can be a default widget.
5901 * Specifies whether @widget can be a default widget. See
5902 * gtk_widget_grab_default() for details about the meaning of
5908 gtk_widget_set_can_default (GtkWidget *widget,
5909 gboolean can_default)
5911 g_return_if_fail (GTK_IS_WIDGET (widget));
5913 if (can_default != gtk_widget_get_can_default (widget))
5916 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5918 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5920 gtk_widget_queue_resize (widget);
5921 g_object_notify (G_OBJECT (widget), "can-default");
5926 * gtk_widget_get_can_default:
5927 * @widget: a #GtkWidget
5929 * Determines whether @widget can be a default widget. See
5930 * gtk_widget_set_can_default().
5932 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5937 gtk_widget_get_can_default (GtkWidget *widget)
5939 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5941 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5945 * gtk_widget_has_default:
5946 * @widget: a #GtkWidget
5948 * Determines whether @widget is the current default widget within its
5949 * toplevel. See gtk_widget_set_can_default().
5951 * Return value: %TRUE if @widget is the current default widget within
5952 * its toplevel, %FALSE otherwise
5957 gtk_widget_has_default (GtkWidget *widget)
5959 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5961 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5965 _gtk_widget_set_has_default (GtkWidget *widget,
5966 gboolean has_default)
5969 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5971 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5975 * gtk_widget_grab_default:
5976 * @widget: a #GtkWidget
5978 * Causes @widget to become the default widget. @widget must have the
5979 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5980 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5981 * %TRUE)</literal>. The default widget is activated when
5982 * the user presses Enter in a window. Default widgets must be
5983 * activatable, that is, gtk_widget_activate() should affect them. Note
5984 * that #GtkEntry widgets require the "activates-default" property
5985 * set to %TRUE before they activate the default widget when Enter
5986 * is pressed and the #GtkEntry is focused.
5989 gtk_widget_grab_default (GtkWidget *widget)
5993 g_return_if_fail (GTK_IS_WIDGET (widget));
5994 g_return_if_fail (gtk_widget_get_can_default (widget));
5996 window = gtk_widget_get_toplevel (widget);
5998 if (window && gtk_widget_is_toplevel (window))
5999 gtk_window_set_default (GTK_WINDOW (window), widget);
6001 g_warning (G_STRLOC ": widget not within a GtkWindow");
6005 * gtk_widget_set_receives_default:
6006 * @widget: a #GtkWidget
6007 * @receives_default: whether or not @widget can be a default widget.
6009 * Specifies whether @widget will be treated as the default widget
6010 * within its toplevel when it has the focus, even if another widget
6013 * See gtk_widget_grab_default() for details about the meaning of
6019 gtk_widget_set_receives_default (GtkWidget *widget,
6020 gboolean receives_default)
6022 g_return_if_fail (GTK_IS_WIDGET (widget));
6024 if (receives_default != gtk_widget_get_receives_default (widget))
6026 if (receives_default)
6027 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6029 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6031 g_object_notify (G_OBJECT (widget), "receives-default");
6036 * gtk_widget_get_receives_default:
6037 * @widget: a #GtkWidget
6039 * Determines whether @widget is alyways treated as default widget
6040 * withing its toplevel when it has the focus, even if another widget
6043 * See gtk_widget_set_receives_default().
6045 * Return value: %TRUE if @widget acts as default widget when focussed,
6051 gtk_widget_get_receives_default (GtkWidget *widget)
6053 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6055 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6059 * gtk_widget_has_grab:
6060 * @widget: a #GtkWidget
6062 * Determines whether the widget is currently grabbing events, so it
6063 * is the only widget receiving input events (keyboard and mouse).
6065 * See also gtk_grab_add().
6067 * Return value: %TRUE if the widget is in the grab_widgets stack
6072 gtk_widget_has_grab (GtkWidget *widget)
6074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6076 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6080 _gtk_widget_set_has_grab (GtkWidget *widget,
6084 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6086 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6090 * gtk_widget_device_is_shadowed:
6091 * @widget: a #GtkWidget
6092 * @device: a #GdkDevice
6094 * Returns %TRUE if @device has been shadowed by a GTK+
6095 * device grab on another widget, so it would stop sending
6096 * events to @widget. This may be used in the
6097 * #GtkWidget::grab-notify signal to check for specific
6098 * devices. See gtk_device_grab_add().
6100 * Returns: %TRUE if there is an ongoing grab on @device
6101 * by another #GtkWidget than @widget.
6106 gtk_widget_device_is_shadowed (GtkWidget *widget,
6109 GtkWindowGroup *group;
6110 GtkWidget *grab_widget, *toplevel;
6112 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6113 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6115 if (!gtk_widget_get_realized (widget))
6118 toplevel = gtk_widget_get_toplevel (widget);
6120 if (GTK_IS_WINDOW (toplevel))
6121 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6123 group = gtk_window_get_group (NULL);
6125 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6127 /* Widget not inside the hierarchy of grab_widget */
6129 widget != grab_widget &&
6130 !gtk_widget_is_ancestor (widget, grab_widget))
6133 grab_widget = gtk_window_group_get_current_grab (group);
6134 if (grab_widget && widget != grab_widget &&
6135 !gtk_widget_is_ancestor (widget, grab_widget))
6142 * gtk_widget_set_name:
6143 * @widget: a #GtkWidget
6144 * @name: name for the widget
6146 * Widgets can be named, which allows you to refer to them from a
6147 * gtkrc file. You can apply a style to widgets with a particular name
6148 * in the gtkrc file. See the documentation for gtkrc files (on the
6149 * same page as the docs for #GtkRcStyle).
6151 * Note that widget names are separated by periods in paths (see
6152 * gtk_widget_path()), so names with embedded periods may cause confusion.
6155 gtk_widget_set_name (GtkWidget *widget,
6158 GtkWidgetPrivate *priv;
6161 g_return_if_fail (GTK_IS_WIDGET (widget));
6163 priv = widget->priv;
6165 new_name = g_strdup (name);
6166 g_free (priv->name);
6167 priv->name = new_name;
6169 if (gtk_widget_has_rc_style (widget))
6170 gtk_widget_reset_rc_style (widget);
6172 g_object_notify (G_OBJECT (widget), "name");
6176 * gtk_widget_get_name:
6177 * @widget: a #GtkWidget
6179 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6180 * significance of widget names.
6182 * Return value: name of the widget. This string is owned by GTK+ and
6183 * should not be modified or freed
6185 G_CONST_RETURN gchar*
6186 gtk_widget_get_name (GtkWidget *widget)
6188 GtkWidgetPrivate *priv;
6190 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6192 priv = widget->priv;
6196 return G_OBJECT_TYPE_NAME (widget);
6200 * gtk_widget_set_state:
6201 * @widget: a #GtkWidget
6202 * @state: new state for @widget
6204 * This function is for use in widget implementations. Sets the state
6205 * of a widget (insensitive, prelighted, etc.) Usually you should set
6206 * the state using wrapper functions such as gtk_widget_set_sensitive().
6209 gtk_widget_set_state (GtkWidget *widget,
6212 GtkWidgetPrivate *priv;
6214 g_return_if_fail (GTK_IS_WIDGET (widget));
6216 priv = widget->priv;
6218 if (state == gtk_widget_get_state (widget))
6221 if (state == GTK_STATE_INSENSITIVE)
6222 gtk_widget_set_sensitive (widget, FALSE);
6228 data.state_restoration = FALSE;
6229 data.use_forall = FALSE;
6231 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6233 data.parent_sensitive = TRUE;
6235 gtk_widget_propagate_state (widget, &data);
6237 if (gtk_widget_is_drawable (widget))
6238 gtk_widget_queue_draw (widget);
6243 * gtk_widget_get_state:
6244 * @widget: a #GtkWidget
6246 * Returns the widget's state. See gtk_widget_set_state().
6248 * Returns: the state of @widget.
6253 gtk_widget_get_state (GtkWidget *widget)
6255 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6257 return widget->priv->state;
6261 * gtk_widget_set_visible:
6262 * @widget: a #GtkWidget
6263 * @visible: whether the widget should be shown or not
6265 * Sets the visibility state of @widget. Note that setting this to
6266 * %TRUE doesn't mean the widget is actually viewable, see
6267 * gtk_widget_get_visible().
6269 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6270 * but is nicer to use when the visibility of the widget depends on
6276 gtk_widget_set_visible (GtkWidget *widget,
6279 g_return_if_fail (GTK_IS_WIDGET (widget));
6281 if (visible != gtk_widget_get_visible (widget))
6284 gtk_widget_show (widget);
6286 gtk_widget_hide (widget);
6291 * gtk_widget_get_visible:
6292 * @widget: a #GtkWidget
6294 * Determines whether the widget is visible. Note that this doesn't
6295 * take into account whether the widget's parent is also visible
6296 * or the widget is obscured in any way.
6298 * See gtk_widget_set_visible().
6300 * Return value: %TRUE if the widget is visible
6305 gtk_widget_get_visible (GtkWidget *widget)
6307 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6309 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6313 * gtk_widget_set_has_window:
6314 * @widget: a #GtkWidget
6315 * @has_window: whether or not @widget has a window.
6317 * Specifies whether @widget has a #GdkWindow of its own. Note that
6318 * all realized widgets have a non-%NULL "window" pointer
6319 * (gtk_widget_get_window() never returns a %NULL window when a widget
6320 * is realized), but for many of them it's actually the #GdkWindow of
6321 * one of its parent widgets. Widgets that do not create a %window for
6322 * themselves in GtkWidget::realize() must announce this by
6323 * calling this function with @has_window = %FALSE.
6325 * This function should only be called by widget implementations,
6326 * and they should call it in their init() function.
6331 gtk_widget_set_has_window (GtkWidget *widget,
6332 gboolean has_window)
6334 g_return_if_fail (GTK_IS_WIDGET (widget));
6337 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6339 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6343 * gtk_widget_get_has_window:
6344 * @widget: a #GtkWidget
6346 * Determines whether @widget has a #GdkWindow of its own. See
6347 * gtk_widget_set_has_window().
6349 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6354 gtk_widget_get_has_window (GtkWidget *widget)
6356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6358 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6362 * gtk_widget_is_toplevel:
6363 * @widget: a #GtkWidget
6365 * Determines whether @widget is a toplevel widget. Currently only
6366 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6367 * widgets have no parent widget.
6369 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6374 gtk_widget_is_toplevel (GtkWidget *widget)
6376 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6378 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6382 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6383 gboolean is_toplevel)
6386 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6388 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6392 * gtk_widget_is_drawable:
6393 * @widget: a #GtkWidget
6395 * Determines whether @widget can be drawn to. A widget can be drawn
6396 * to if it is mapped and visible.
6398 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6403 gtk_widget_is_drawable (GtkWidget *widget)
6405 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6407 return (gtk_widget_get_visible (widget) &&
6408 gtk_widget_get_mapped (widget));
6412 * gtk_widget_get_realized:
6413 * @widget: a #GtkWidget
6415 * Determines whether @widget is realized.
6417 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6422 gtk_widget_get_realized (GtkWidget *widget)
6424 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6426 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6430 * gtk_widget_set_realized:
6431 * @widget: a #GtkWidget
6432 * @realized: %TRUE to mark the widget as realized
6434 * Marks the widget as being realized.
6436 * This function should only ever be called in a derived widget's
6437 * "realize" or "unrealize" implementation.
6442 gtk_widget_set_realized (GtkWidget *widget,
6445 g_return_if_fail (GTK_IS_WIDGET (widget));
6448 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6450 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6454 * gtk_widget_get_mapped:
6455 * @widget: a #GtkWidget
6457 * Whether the widget is mapped.
6459 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6464 gtk_widget_get_mapped (GtkWidget *widget)
6466 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6468 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6472 * gtk_widget_set_mapped:
6473 * @widget: a #GtkWidget
6474 * @mapped: %TRUE to mark the widget as mapped
6476 * Marks the widget as being realized.
6478 * This function should only ever be called in a derived widget's
6479 * "map" or "unmap" implementation.
6484 gtk_widget_set_mapped (GtkWidget *widget,
6487 g_return_if_fail (GTK_IS_WIDGET (widget));
6490 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6492 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6496 * gtk_widget_set_app_paintable:
6497 * @widget: a #GtkWidget
6498 * @app_paintable: %TRUE if the application will paint on the widget
6500 * Sets whether the application intends to draw on the widget in
6501 * an #GtkWidget::expose-event handler.
6503 * This is a hint to the widget and does not affect the behavior of
6504 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6505 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6506 * the effect is to suppress default themed drawing of the widget's
6507 * background. (Children of the widget will still be drawn.) The application
6508 * is then entirely responsible for drawing the widget background.
6510 * Note that the background is still drawn when the widget is mapped.
6513 gtk_widget_set_app_paintable (GtkWidget *widget,
6514 gboolean app_paintable)
6516 g_return_if_fail (GTK_IS_WIDGET (widget));
6518 app_paintable = (app_paintable != FALSE);
6520 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6523 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6525 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6527 if (gtk_widget_is_drawable (widget))
6528 gtk_widget_queue_draw (widget);
6530 g_object_notify (G_OBJECT (widget), "app-paintable");
6535 * gtk_widget_get_app_paintable:
6536 * @widget: a #GtkWidget
6538 * Determines whether the application intends to draw on the widget in
6539 * an #GtkWidget::expose-event handler.
6541 * See gtk_widget_set_app_paintable()
6543 * Return value: %TRUE if the widget is app paintable
6548 gtk_widget_get_app_paintable (GtkWidget *widget)
6550 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6552 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6556 * gtk_widget_set_double_buffered:
6557 * @widget: a #GtkWidget
6558 * @double_buffered: %TRUE to double-buffer a widget
6560 * Widgets are double buffered by default; you can use this function
6561 * to turn off the buffering. "Double buffered" simply means that
6562 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6563 * automatically around expose events sent to the
6564 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6565 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6566 * buffer to the screen. The result is that users see the window
6567 * update in one smooth step, and don't see individual graphics
6568 * primitives being rendered.
6570 * In very simple terms, double buffered widgets don't flicker,
6571 * so you would only use this function to turn off double buffering
6572 * if you had special needs and really knew what you were doing.
6574 * Note: if you turn off double-buffering, you have to handle
6575 * expose events, since even the clearing to the background color or
6576 * pixmap will not happen automatically (as it is done in
6577 * gdk_window_begin_paint()).
6580 gtk_widget_set_double_buffered (GtkWidget *widget,
6581 gboolean double_buffered)
6583 g_return_if_fail (GTK_IS_WIDGET (widget));
6585 double_buffered = (double_buffered != FALSE);
6587 if (double_buffered != gtk_widget_get_double_buffered (widget))
6589 if (double_buffered)
6590 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6592 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6594 g_object_notify (G_OBJECT (widget), "double-buffered");
6599 * gtk_widget_get_double_buffered:
6600 * @widget: a #GtkWidget
6602 * Determines whether the widget is double buffered.
6604 * See gtk_widget_set_double_buffered()
6606 * Return value: %TRUE if the widget is double buffered
6611 gtk_widget_get_double_buffered (GtkWidget *widget)
6613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6615 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6619 * gtk_widget_set_redraw_on_allocate:
6620 * @widget: a #GtkWidget
6621 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6622 * when it is allocated to a new size. Otherwise, only the
6623 * new portion of the widget will be redrawn.
6625 * Sets whether the entire widget is queued for drawing when its size
6626 * allocation changes. By default, this setting is %TRUE and
6627 * the entire widget is redrawn on every size change. If your widget
6628 * leaves the upper left unchanged when made bigger, turning this
6629 * setting off will improve performance.
6631 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6632 * off all allocation on resizing: the widget will not even redraw if
6633 * its position changes; this is to allow containers that don't draw
6634 * anything to avoid excess invalidations. If you set this flag on a
6635 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6636 * you are responsible for invalidating both the old and new allocation
6637 * of the widget when the widget is moved and responsible for invalidating
6638 * regions newly when the widget increases size.
6641 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6642 gboolean redraw_on_allocate)
6644 g_return_if_fail (GTK_IS_WIDGET (widget));
6646 if (redraw_on_allocate)
6647 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6649 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6653 * gtk_widget_set_sensitive:
6654 * @widget: a #GtkWidget
6655 * @sensitive: %TRUE to make the widget sensitive
6657 * Sets the sensitivity of a widget. A widget is sensitive if the user
6658 * can interact with it. Insensitive widgets are "grayed out" and the
6659 * user can't interact with them. Insensitive widgets are known as
6660 * "inactive", "disabled", or "ghosted" in some other toolkits.
6663 gtk_widget_set_sensitive (GtkWidget *widget,
6666 GtkWidgetPrivate *priv;
6669 g_return_if_fail (GTK_IS_WIDGET (widget));
6671 priv = widget->priv;
6673 sensitive = (sensitive != FALSE);
6675 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6680 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6681 data.state = priv->saved_state;
6685 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6686 data.state = gtk_widget_get_state (widget);
6688 data.state_restoration = TRUE;
6689 data.use_forall = TRUE;
6692 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6694 data.parent_sensitive = TRUE;
6696 gtk_widget_propagate_state (widget, &data);
6697 if (gtk_widget_is_drawable (widget))
6698 gtk_widget_queue_draw (widget);
6700 g_object_notify (G_OBJECT (widget), "sensitive");
6704 * gtk_widget_get_sensitive:
6705 * @widget: a #GtkWidget
6707 * Returns the widget's sensitivity (in the sense of returning
6708 * the value that has been set using gtk_widget_set_sensitive()).
6710 * The effective sensitivity of a widget is however determined by both its
6711 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6713 * Returns: %TRUE if the widget is sensitive
6718 gtk_widget_get_sensitive (GtkWidget *widget)
6720 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6722 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6726 * gtk_widget_is_sensitive:
6727 * @widget: a #GtkWidget
6729 * Returns the widget's effective sensitivity, which means
6730 * it is sensitive itself and also its parent widget is sensntive
6732 * Returns: %TRUE if the widget is effectively sensitive
6737 gtk_widget_is_sensitive (GtkWidget *widget)
6739 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6741 return (gtk_widget_get_sensitive (widget) &&
6742 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6746 * gtk_widget_set_parent:
6747 * @widget: a #GtkWidget
6748 * @parent: parent container
6750 * This function is useful only when implementing subclasses of
6752 * Sets the container as the parent of @widget, and takes care of
6753 * some details such as updating the state and style of the child
6754 * to reflect its new location. The opposite function is
6755 * gtk_widget_unparent().
6758 gtk_widget_set_parent (GtkWidget *widget,
6761 GtkWidgetPrivate *priv;
6764 g_return_if_fail (GTK_IS_WIDGET (widget));
6765 g_return_if_fail (GTK_IS_WIDGET (parent));
6766 g_return_if_fail (widget != parent);
6768 priv = widget->priv;
6770 if (priv->parent != NULL)
6772 g_warning ("Can't set a parent on widget which has a parent\n");
6775 if (gtk_widget_is_toplevel (widget))
6777 g_warning ("Can't set a parent on a toplevel widget\n");
6781 /* keep this function in sync with gtk_menu_attach_to_widget()
6784 g_object_ref_sink (widget);
6785 priv->parent = parent;
6787 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6788 data.state = gtk_widget_get_state (parent);
6790 data.state = gtk_widget_get_state (widget);
6791 data.state_restoration = FALSE;
6792 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6793 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6795 gtk_widget_propagate_state (widget, &data);
6797 gtk_widget_reset_rc_styles (widget);
6799 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6800 if (GTK_WIDGET_ANCHORED (priv->parent))
6801 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6802 g_object_notify (G_OBJECT (widget), "parent");
6804 /* Enforce realized/mapped invariants
6806 if (gtk_widget_get_realized (priv->parent))
6807 gtk_widget_realize (widget);
6809 if (gtk_widget_get_visible (priv->parent) &&
6810 gtk_widget_get_visible (widget))
6812 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6813 gtk_widget_get_mapped (priv->parent))
6814 gtk_widget_map (widget);
6816 gtk_widget_queue_resize (widget);
6821 * gtk_widget_get_parent:
6822 * @widget: a #GtkWidget
6824 * Returns the parent container of @widget.
6826 * Return value: (transfer none): the parent container of @widget, or %NULL
6829 gtk_widget_get_parent (GtkWidget *widget)
6831 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6833 return widget->priv->parent;
6836 /*****************************************
6838 * see docs/styles.txt
6839 *****************************************/
6842 * gtk_widget_style_attach:
6843 * @widget: a #GtkWidget
6845 * This function attaches the widget's #GtkStyle to the widget's
6846 * #GdkWindow. It is a replacement for
6849 * widget->style = gtk_style_attach (widget->style, widget->window);
6852 * and should only ever be called in a derived widget's "realize"
6853 * implementation which does not chain up to its parent class'
6854 * "realize" implementation, because one of the parent classes
6855 * (finally #GtkWidget) would attach the style itself.
6860 gtk_widget_style_attach (GtkWidget *widget)
6862 GtkWidgetPrivate *priv;
6864 g_return_if_fail (GTK_IS_WIDGET (widget));
6865 g_return_if_fail (gtk_widget_get_realized (widget));
6867 priv = widget->priv;
6869 priv->style = gtk_style_attach (priv->style, priv->window);
6873 * gtk_widget_has_rc_style:
6874 * @widget: a #GtkWidget
6876 * Determines if the widget style has been looked up through the rc mechanism.
6878 * Returns: %TRUE if the widget has been looked up through the rc
6879 * mechanism, %FALSE otherwise.
6884 gtk_widget_has_rc_style (GtkWidget *widget)
6886 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6888 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6892 * gtk_widget_set_style:
6893 * @widget: a #GtkWidget
6894 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6895 * gtk_widget_set_style() and go back to the default style
6897 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6898 * want to use this function; it interacts badly with themes, because
6899 * themes work by replacing the #GtkStyle. Instead, use
6900 * gtk_widget_modify_style().
6903 gtk_widget_set_style (GtkWidget *widget,
6906 g_return_if_fail (GTK_IS_WIDGET (widget));
6910 gboolean initial_emission;
6912 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6914 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6915 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6917 gtk_widget_set_style_internal (widget, style, initial_emission);
6921 if (GTK_WIDGET_USER_STYLE (widget))
6922 gtk_widget_reset_rc_style (widget);
6927 * gtk_widget_ensure_style:
6928 * @widget: a #GtkWidget
6930 * Ensures that @widget has a style (@widget->style). Not a very useful
6931 * function; most of the time, if you want the style, the widget is
6932 * realized, and realized widgets are guaranteed to have a style
6936 gtk_widget_ensure_style (GtkWidget *widget)
6938 g_return_if_fail (GTK_IS_WIDGET (widget));
6940 if (!GTK_WIDGET_USER_STYLE (widget) &&
6941 !gtk_widget_has_rc_style (widget))
6942 gtk_widget_reset_rc_style (widget);
6945 /* Look up the RC style for this widget, unsetting any user style that
6946 * may be in effect currently
6949 gtk_widget_reset_rc_style (GtkWidget *widget)
6951 GtkWidgetPrivate *priv = widget->priv;
6952 GtkStyle *new_style = NULL;
6953 gboolean initial_emission;
6955 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6957 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6958 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6960 if (gtk_widget_has_screen (widget))
6961 new_style = gtk_rc_get_style (widget);
6963 new_style = gtk_widget_get_default_style ();
6965 if (initial_emission || new_style != priv->style)
6966 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6970 * gtk_widget_get_style:
6971 * @widget: a #GtkWidget
6973 * Simply an accessor function that returns @widget->style.
6975 * Return value: (transfer none): the widget's #GtkStyle
6978 gtk_widget_get_style (GtkWidget *widget)
6980 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6982 return widget->priv->style;
6986 * gtk_widget_modify_style:
6987 * @widget: a #GtkWidget
6988 * @style: the #GtkRcStyle holding the style modifications
6990 * Modifies style values on the widget. Modifications made using this
6991 * technique take precedence over style values set via an RC file,
6992 * however, they will be overriden if a style is explicitely set on
6993 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6994 * is designed so each field can either be set or unset, so it is
6995 * possible, using this function, to modify some style values and
6996 * leave the others unchanged.
6998 * Note that modifications made with this function are not cumulative
6999 * with previous calls to gtk_widget_modify_style() or with such
7000 * functions as gtk_widget_modify_fg(). If you wish to retain
7001 * previous values, you must first call gtk_widget_get_modifier_style(),
7002 * make your modifications to the returned style, then call
7003 * gtk_widget_modify_style() with that style. On the other hand,
7004 * if you first call gtk_widget_modify_style(), subsequent calls
7005 * to such functions gtk_widget_modify_fg() will have a cumulative
7006 * effect with the initial modifications.
7009 gtk_widget_modify_style (GtkWidget *widget,
7012 g_return_if_fail (GTK_IS_WIDGET (widget));
7013 g_return_if_fail (GTK_IS_RC_STYLE (style));
7015 g_object_set_qdata_full (G_OBJECT (widget),
7017 gtk_rc_style_copy (style),
7018 (GDestroyNotify) g_object_unref);
7020 /* note that "style" may be invalid here if it was the old
7021 * modifier style and the only reference was our own.
7024 if (gtk_widget_has_rc_style (widget))
7025 gtk_widget_reset_rc_style (widget);
7029 * gtk_widget_get_modifier_style:
7030 * @widget: a #GtkWidget
7032 * Returns the current modifier style for the widget. (As set by
7033 * gtk_widget_modify_style().) If no style has previously set, a new
7034 * #GtkRcStyle will be created with all values unset, and set as the
7035 * modifier style for the widget. If you make changes to this rc
7036 * style, you must call gtk_widget_modify_style(), passing in the
7037 * returned rc style, to make sure that your changes take effect.
7039 * Caution: passing the style back to gtk_widget_modify_style() will
7040 * normally end up destroying it, because gtk_widget_modify_style() copies
7041 * the passed-in style and sets the copy as the new modifier style,
7042 * thus dropping any reference to the old modifier style. Add a reference
7043 * to the modifier style if you want to keep it alive.
7045 * Return value: (transfer none): the modifier style for the widget. This rc style is
7046 * owned by the widget. If you want to keep a pointer to value this
7047 * around, you must add a refcount using g_object_ref().
7050 gtk_widget_get_modifier_style (GtkWidget *widget)
7052 GtkRcStyle *rc_style;
7054 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7056 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7060 rc_style = gtk_rc_style_new ();
7061 g_object_set_qdata_full (G_OBJECT (widget),
7064 (GDestroyNotify) g_object_unref);
7071 gtk_widget_modify_color_component (GtkWidget *widget,
7072 GtkRcFlags component,
7074 const GdkColor *color)
7076 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7083 rc_style->fg[state] = *color;
7086 rc_style->bg[state] = *color;
7089 rc_style->text[state] = *color;
7092 rc_style->base[state] = *color;
7095 g_assert_not_reached();
7098 rc_style->color_flags[state] |= component;
7101 rc_style->color_flags[state] &= ~component;
7103 gtk_widget_modify_style (widget, rc_style);
7107 * gtk_widget_modify_symbolic_color:
7108 * @widget: a #GtkWidget
7109 * @name: the name of the symbolic color to modify
7110 * @color: (allow-none): the color to assign (does not need to be allocated),
7111 * or %NULL to undo the effect of previous calls to
7112 * of gtk_widget_modify_symbolic_color().
7114 * Sets a symbolic color for a widget.
7115 * All other style values are left untouched. See also
7116 * gtk_widget_modify_style().
7121 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7123 const GdkColor *color)
7125 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7127 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7129 gtk_widget_modify_style (widget, rc_style);
7133 * gtk_widget_modify_fg:
7134 * @widget: a #GtkWidget
7135 * @state: the state for which to set the foreground color
7136 * @color: (allow-none): the color to assign (does not need to be allocated),
7137 * or %NULL to undo the effect of previous calls to
7138 * of gtk_widget_modify_fg().
7140 * Sets the foreground color for a widget in a particular state.
7141 * All other style values are left untouched. See also
7142 * gtk_widget_modify_style().
7145 gtk_widget_modify_fg (GtkWidget *widget,
7147 const GdkColor *color)
7149 g_return_if_fail (GTK_IS_WIDGET (widget));
7150 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7152 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7156 * gtk_widget_modify_bg:
7157 * @widget: a #GtkWidget
7158 * @state: the state for which to set the background color
7159 * @color: (allow-none): the color to assign (does not need to be allocated),
7160 * or %NULL to undo the effect of previous calls to
7161 * of gtk_widget_modify_bg().
7163 * Sets the background color for a widget in a particular state.
7164 * All other style values are left untouched. See also
7165 * gtk_widget_modify_style().
7167 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7168 * draw on their parent container's window and thus may not draw any
7169 * background themselves. This is the case for e.g. #GtkLabel. To modify
7170 * the background of such widgets, you have to set the background color
7171 * on their parent; if you want to set the background of a rectangular
7172 * area around a label, try placing the label in a #GtkEventBox widget
7173 * and setting the background color on that.
7176 gtk_widget_modify_bg (GtkWidget *widget,
7178 const GdkColor *color)
7180 g_return_if_fail (GTK_IS_WIDGET (widget));
7181 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7183 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7187 * gtk_widget_modify_text:
7188 * @widget: a #GtkWidget
7189 * @state: the state for which to set the text color
7190 * @color: (allow-none): the color to assign (does not need to be allocated),
7191 * or %NULL to undo the effect of previous calls to
7192 * of gtk_widget_modify_text().
7194 * Sets the text color for a widget in a particular state. All other
7195 * style values are left untouched. The text color is the foreground
7196 * color used along with the base color (see gtk_widget_modify_base())
7197 * for widgets such as #GtkEntry and #GtkTextView. See also
7198 * gtk_widget_modify_style().
7201 gtk_widget_modify_text (GtkWidget *widget,
7203 const GdkColor *color)
7205 g_return_if_fail (GTK_IS_WIDGET (widget));
7206 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7208 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7212 * gtk_widget_modify_base:
7213 * @widget: a #GtkWidget
7214 * @state: the state for which to set the base color
7215 * @color: (allow-none): the color to assign (does not need to be allocated),
7216 * or %NULL to undo the effect of previous calls to
7217 * of gtk_widget_modify_base().
7219 * Sets the base color for a widget in a particular state.
7220 * All other style values are left untouched. The base color
7221 * is the background color used along with the text color
7222 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7223 * and #GtkTextView. See also gtk_widget_modify_style().
7225 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7226 * draw on their parent container's window and thus may not draw any
7227 * background themselves. This is the case for e.g. #GtkLabel. To modify
7228 * the background of such widgets, you have to set the base color on their
7229 * parent; if you want to set the background of a rectangular area around
7230 * a label, try placing the label in a #GtkEventBox widget and setting
7231 * the base color on that.
7234 gtk_widget_modify_base (GtkWidget *widget,
7236 const GdkColor *color)
7238 g_return_if_fail (GTK_IS_WIDGET (widget));
7239 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7241 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7245 modify_color_property (GtkWidget *widget,
7246 GtkRcStyle *rc_style,
7248 const GdkColor *color)
7250 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7251 GQuark property_name = g_quark_from_string (name);
7255 GtkRcProperty rc_property = {0};
7258 rc_property.type_name = type_name;
7259 rc_property.property_name = property_name;
7260 rc_property.origin = NULL;
7262 color_name = gdk_color_to_string (color);
7263 g_value_init (&rc_property.value, G_TYPE_STRING);
7264 g_value_take_string (&rc_property.value, color_name);
7266 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7268 g_value_unset (&rc_property.value);
7271 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7275 * gtk_widget_modify_cursor:
7276 * @widget: a #GtkWidget
7277 * @primary: the color to use for primary cursor (does not need to be
7278 * allocated), or %NULL to undo the effect of previous calls to
7279 * of gtk_widget_modify_cursor().
7280 * @secondary: the color to use for secondary cursor (does not need to be
7281 * allocated), or %NULL to undo the effect of previous calls to
7282 * of gtk_widget_modify_cursor().
7284 * Sets the cursor color to use in a widget, overriding the
7285 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7286 * style properties. All other style values are left untouched.
7287 * See also gtk_widget_modify_style().
7292 gtk_widget_modify_cursor (GtkWidget *widget,
7293 const GdkColor *primary,
7294 const GdkColor *secondary)
7296 GtkRcStyle *rc_style;
7298 g_return_if_fail (GTK_IS_WIDGET (widget));
7300 rc_style = gtk_widget_get_modifier_style (widget);
7302 modify_color_property (widget, rc_style, "cursor-color", primary);
7303 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7305 gtk_widget_modify_style (widget, rc_style);
7309 * gtk_widget_modify_font:
7310 * @widget: a #GtkWidget
7311 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7312 * the effect of previous calls to gtk_widget_modify_font().
7314 * Sets the font to use for a widget. All other style values are left
7315 * untouched. See also gtk_widget_modify_style().
7318 gtk_widget_modify_font (GtkWidget *widget,
7319 PangoFontDescription *font_desc)
7321 GtkRcStyle *rc_style;
7323 g_return_if_fail (GTK_IS_WIDGET (widget));
7325 rc_style = gtk_widget_get_modifier_style (widget);
7327 if (rc_style->font_desc)
7328 pango_font_description_free (rc_style->font_desc);
7331 rc_style->font_desc = pango_font_description_copy (font_desc);
7333 rc_style->font_desc = NULL;
7335 gtk_widget_modify_style (widget, rc_style);
7339 gtk_widget_real_direction_changed (GtkWidget *widget,
7340 GtkTextDirection previous_direction)
7342 gtk_widget_queue_resize (widget);
7346 gtk_widget_real_style_set (GtkWidget *widget,
7347 GtkStyle *previous_style)
7349 GtkWidgetPrivate *priv = widget->priv;
7351 if (gtk_widget_get_realized (widget) &&
7352 gtk_widget_get_has_window (widget))
7353 gtk_style_set_background (priv->style, priv->window, priv->state);
7357 gtk_widget_set_style_internal (GtkWidget *widget,
7359 gboolean initial_emission)
7361 GtkWidgetPrivate *priv = widget->priv;
7363 g_object_ref (widget);
7364 g_object_freeze_notify (G_OBJECT (widget));
7366 if (priv->style != style)
7368 GtkStyle *previous_style;
7370 if (gtk_widget_get_realized (widget))
7372 gtk_widget_reset_shapes (widget);
7373 gtk_style_detach (priv->style);
7376 previous_style = priv->style;
7377 priv->style = style;
7378 g_object_ref (priv->style);
7380 if (gtk_widget_get_realized (widget))
7381 priv->style = gtk_style_attach (priv->style, priv->window);
7383 gtk_widget_update_pango_context (widget);
7384 g_signal_emit (widget,
7385 widget_signals[STYLE_SET],
7387 initial_emission ? NULL : previous_style);
7388 g_object_unref (previous_style);
7390 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7391 gtk_widget_queue_resize (widget);
7393 else if (initial_emission)
7395 gtk_widget_update_pango_context (widget);
7396 g_signal_emit (widget,
7397 widget_signals[STYLE_SET],
7401 g_object_notify (G_OBJECT (widget), "style");
7402 g_object_thaw_notify (G_OBJECT (widget));
7403 g_object_unref (widget);
7407 GtkWidget *previous_toplevel;
7408 GdkScreen *previous_screen;
7409 GdkScreen *new_screen;
7410 } HierarchyChangedInfo;
7413 do_screen_change (GtkWidget *widget,
7414 GdkScreen *old_screen,
7415 GdkScreen *new_screen)
7417 if (old_screen != new_screen)
7421 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7423 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7426 _gtk_tooltip_hide (widget);
7427 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7432 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7433 gpointer client_data)
7435 GtkWidgetPrivate *priv = widget->priv;
7436 HierarchyChangedInfo *info = client_data;
7437 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7438 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7440 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7442 g_object_ref (widget);
7445 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7447 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7449 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7450 do_screen_change (widget, info->previous_screen, info->new_screen);
7452 if (GTK_IS_CONTAINER (widget))
7453 gtk_container_forall (GTK_CONTAINER (widget),
7454 gtk_widget_propagate_hierarchy_changed_recurse,
7457 g_object_unref (widget);
7462 * _gtk_widget_propagate_hierarchy_changed:
7463 * @widget: a #GtkWidget
7464 * @previous_toplevel: Previous toplevel
7466 * Propagates changes in the anchored state to a widget and all
7467 * children, unsetting or setting the %ANCHORED flag, and
7468 * emitting #GtkWidget::hierarchy-changed.
7471 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7472 GtkWidget *previous_toplevel)
7474 GtkWidgetPrivate *priv = widget->priv;
7475 HierarchyChangedInfo info;
7477 info.previous_toplevel = previous_toplevel;
7478 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7480 if (gtk_widget_is_toplevel (widget) ||
7481 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7482 info.new_screen = gtk_widget_get_screen (widget);
7484 info.new_screen = NULL;
7486 if (info.previous_screen)
7487 g_object_ref (info.previous_screen);
7488 if (previous_toplevel)
7489 g_object_ref (previous_toplevel);
7491 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7493 if (previous_toplevel)
7494 g_object_unref (previous_toplevel);
7495 if (info.previous_screen)
7496 g_object_unref (info.previous_screen);
7500 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7501 gpointer client_data)
7503 HierarchyChangedInfo *info = client_data;
7505 g_object_ref (widget);
7507 do_screen_change (widget, info->previous_screen, info->new_screen);
7509 if (GTK_IS_CONTAINER (widget))
7510 gtk_container_forall (GTK_CONTAINER (widget),
7511 gtk_widget_propagate_screen_changed_recurse,
7514 g_object_unref (widget);
7518 * gtk_widget_is_composited:
7519 * @widget: a #GtkWidget
7521 * Whether @widget can rely on having its alpha channel
7522 * drawn correctly. On X11 this function returns whether a
7523 * compositing manager is running for @widget's screen.
7525 * Please note that the semantics of this call will change
7526 * in the future if used on a widget that has a composited
7527 * window in its hierarchy (as set by gdk_window_set_composited()).
7529 * Return value: %TRUE if the widget can rely on its alpha
7530 * channel being drawn correctly.
7535 gtk_widget_is_composited (GtkWidget *widget)
7539 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7541 screen = gtk_widget_get_screen (widget);
7543 return gdk_screen_is_composited (screen);
7547 propagate_composited_changed (GtkWidget *widget,
7550 if (GTK_IS_CONTAINER (widget))
7552 gtk_container_forall (GTK_CONTAINER (widget),
7553 propagate_composited_changed,
7557 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7561 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7563 propagate_composited_changed (widget, NULL);
7567 * _gtk_widget_propagate_screen_changed:
7568 * @widget: a #GtkWidget
7569 * @previous_screen: Previous screen
7571 * Propagates changes in the screen for a widget to all
7572 * children, emitting #GtkWidget::screen-changed.
7575 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7576 GdkScreen *previous_screen)
7578 HierarchyChangedInfo info;
7580 info.previous_screen = previous_screen;
7581 info.new_screen = gtk_widget_get_screen (widget);
7583 if (previous_screen)
7584 g_object_ref (previous_screen);
7586 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7588 if (previous_screen)
7589 g_object_unref (previous_screen);
7593 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7595 if (gtk_widget_has_rc_style (widget))
7596 gtk_widget_reset_rc_style (widget);
7598 if (GTK_IS_CONTAINER (widget))
7599 gtk_container_forall (GTK_CONTAINER (widget),
7600 reset_rc_styles_recurse,
7606 * gtk_widget_reset_rc_styles:
7607 * @widget: a #GtkWidget.
7609 * Reset the styles of @widget and all descendents, so when
7610 * they are looked up again, they get the correct values
7611 * for the currently loaded RC file settings.
7613 * This function is not useful for applications.
7616 gtk_widget_reset_rc_styles (GtkWidget *widget)
7618 g_return_if_fail (GTK_IS_WIDGET (widget));
7620 reset_rc_styles_recurse (widget, NULL);
7624 * gtk_widget_get_default_style:
7626 * Returns the default style used by all widgets initially.
7628 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7629 * by GTK+ and should not be modified or freed.
7632 gtk_widget_get_default_style (void)
7634 if (!gtk_default_style)
7636 gtk_default_style = gtk_style_new ();
7637 g_object_ref (gtk_default_style);
7640 return gtk_default_style;
7643 static PangoContext *
7644 gtk_widget_peek_pango_context (GtkWidget *widget)
7646 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7650 * gtk_widget_get_pango_context:
7651 * @widget: a #GtkWidget
7653 * Gets a #PangoContext with the appropriate font map, font description,
7654 * and base direction for this widget. Unlike the context returned
7655 * by gtk_widget_create_pango_context(), this context is owned by
7656 * the widget (it can be used until the screen for the widget changes
7657 * or the widget is removed from its toplevel), and will be updated to
7658 * match any changes to the widget's attributes.
7660 * If you create and keep a #PangoLayout using this context, you must
7661 * deal with changes to the context by calling pango_layout_context_changed()
7662 * on the layout in response to the #GtkWidget::style-set and
7663 * #GtkWidget::direction-changed signals for the widget.
7665 * Return value: (transfer none): the #PangoContext for the widget.
7668 gtk_widget_get_pango_context (GtkWidget *widget)
7670 PangoContext *context;
7672 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7674 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7677 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7678 g_object_set_qdata_full (G_OBJECT (widget),
7679 quark_pango_context,
7688 update_pango_context (GtkWidget *widget,
7689 PangoContext *context)
7691 GtkWidgetPrivate *priv = widget->priv;
7693 pango_context_set_font_description (context, priv->style->font_desc);
7694 pango_context_set_base_dir (context,
7695 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7696 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7700 gtk_widget_update_pango_context (GtkWidget *widget)
7702 PangoContext *context = gtk_widget_peek_pango_context (widget);
7708 update_pango_context (widget, context);
7710 screen = gtk_widget_get_screen_unchecked (widget);
7713 pango_cairo_context_set_resolution (context,
7714 gdk_screen_get_resolution (screen));
7715 pango_cairo_context_set_font_options (context,
7716 gdk_screen_get_font_options (screen));
7722 * gtk_widget_create_pango_context:
7723 * @widget: a #GtkWidget
7725 * Creates a new #PangoContext with the appropriate font map,
7726 * font description, and base direction for drawing text for
7727 * this widget. See also gtk_widget_get_pango_context().
7729 * Return value: (transfer full): the new #PangoContext
7732 gtk_widget_create_pango_context (GtkWidget *widget)
7735 PangoContext *context;
7737 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7739 screen = gtk_widget_get_screen_unchecked (widget);
7742 GTK_NOTE (MULTIHEAD,
7743 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7745 screen = gdk_screen_get_default ();
7748 context = gdk_pango_context_get_for_screen (screen);
7750 update_pango_context (widget, context);
7751 pango_context_set_language (context, gtk_get_default_language ());
7757 * gtk_widget_create_pango_layout:
7758 * @widget: a #GtkWidget
7759 * @text: text to set on the layout (can be %NULL)
7761 * Creates a new #PangoLayout with the appropriate font map,
7762 * font description, and base direction for drawing text for
7765 * If you keep a #PangoLayout created in this way around, in order to
7766 * notify the layout of changes to the base direction or font of this
7767 * widget, you must call pango_layout_context_changed() in response to
7768 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7771 * Return value: (transfer full): the new #PangoLayout
7774 gtk_widget_create_pango_layout (GtkWidget *widget,
7777 PangoLayout *layout;
7778 PangoContext *context;
7780 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7782 context = gtk_widget_get_pango_context (widget);
7783 layout = pango_layout_new (context);
7786 pango_layout_set_text (layout, text, -1);
7792 * gtk_widget_render_icon:
7793 * @widget: a #GtkWidget
7794 * @stock_id: a stock ID
7795 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7796 * render at the size of the source and don't scale (if there are
7797 * multiple source sizes, GTK+ picks one of the available sizes).
7798 * @detail: (allow-none): render detail to pass to theme engine
7800 * A convenience function that uses the theme engine and RC file
7801 * settings for @widget to look up @stock_id and render it to
7802 * a pixbuf. @stock_id should be a stock icon ID such as
7803 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7804 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7805 * identifies the widget or code doing the rendering, so that
7806 * theme engines can special-case rendering for that widget or code.
7808 * The pixels in the returned #GdkPixbuf are shared with the rest of
7809 * the application and should not be modified. The pixbuf should be freed
7810 * after use with g_object_unref().
7812 * Return value: (transfer full): a new pixbuf, or %NULL if the
7813 * stock ID wasn't known
7816 gtk_widget_render_icon (GtkWidget *widget,
7817 const gchar *stock_id,
7819 const gchar *detail)
7821 GtkWidgetPrivate *priv;
7822 GtkIconSet *icon_set;
7825 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7826 g_return_val_if_fail (stock_id != NULL, NULL);
7827 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7829 priv = widget->priv;
7831 gtk_widget_ensure_style (widget);
7833 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7835 if (icon_set == NULL)
7838 retval = gtk_icon_set_render_icon (icon_set,
7840 gtk_widget_get_direction (widget),
7841 gtk_widget_get_state (widget),
7850 * gtk_widget_set_parent_window:
7851 * @widget: a #GtkWidget.
7852 * @parent_window: the new parent window.
7854 * Sets a non default parent window for @widget.
7857 gtk_widget_set_parent_window (GtkWidget *widget,
7858 GdkWindow *parent_window)
7860 GdkWindow *old_parent_window;
7862 g_return_if_fail (GTK_IS_WIDGET (widget));
7864 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7865 quark_parent_window);
7867 if (parent_window != old_parent_window)
7869 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7871 if (old_parent_window)
7872 g_object_unref (old_parent_window);
7874 g_object_ref (parent_window);
7879 * gtk_widget_get_parent_window:
7880 * @widget: a #GtkWidget.
7882 * Gets @widget's parent window.
7884 * Returns: (transfer none): the parent window of @widget.
7887 gtk_widget_get_parent_window (GtkWidget *widget)
7889 GtkWidgetPrivate *priv;
7890 GdkWindow *parent_window;
7892 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7894 priv = widget->priv;
7896 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7898 return (parent_window != NULL) ? parent_window :
7899 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
7904 * gtk_widget_set_child_visible:
7905 * @widget: a #GtkWidget
7906 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7908 * Sets whether @widget should be mapped along with its when its parent
7909 * is mapped and @widget has been shown with gtk_widget_show().
7911 * The child visibility can be set for widget before it is added to
7912 * a container with gtk_widget_set_parent(), to avoid mapping
7913 * children unnecessary before immediately unmapping them. However
7914 * it will be reset to its default state of %TRUE when the widget
7915 * is removed from a container.
7917 * Note that changing the child visibility of a widget does not
7918 * queue a resize on the widget. Most of the time, the size of
7919 * a widget is computed from all visible children, whether or
7920 * not they are mapped. If this is not the case, the container
7921 * can queue a resize itself.
7923 * This function is only useful for container implementations and
7924 * never should be called by an application.
7927 gtk_widget_set_child_visible (GtkWidget *widget,
7928 gboolean is_visible)
7930 GtkWidgetPrivate *priv;
7932 g_return_if_fail (GTK_IS_WIDGET (widget));
7933 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7935 priv = widget->priv;
7937 g_object_ref (widget);
7940 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7943 GtkWidget *toplevel;
7945 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7947 toplevel = gtk_widget_get_toplevel (widget);
7948 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7949 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7952 if (priv->parent && gtk_widget_get_realized (priv->parent))
7954 if (gtk_widget_get_mapped (priv->parent) &&
7955 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7956 gtk_widget_get_visible (widget))
7957 gtk_widget_map (widget);
7959 gtk_widget_unmap (widget);
7962 g_object_unref (widget);
7966 * gtk_widget_get_child_visible:
7967 * @widget: a #GtkWidget
7969 * Gets the value set with gtk_widget_set_child_visible().
7970 * If you feel a need to use this function, your code probably
7971 * needs reorganization.
7973 * This function is only useful for container implementations and
7974 * never should be called by an application.
7976 * Return value: %TRUE if the widget is mapped with the parent.
7979 gtk_widget_get_child_visible (GtkWidget *widget)
7981 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7983 return GTK_WIDGET_CHILD_VISIBLE (widget);
7987 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7989 GtkWidget *toplevel;
7991 toplevel = gtk_widget_get_toplevel (widget);
7993 if (gtk_widget_is_toplevel (toplevel))
7995 if (GTK_IS_WINDOW (toplevel))
7996 return gtk_window_get_screen (GTK_WINDOW (toplevel));
7997 else if (GTK_IS_INVISIBLE (toplevel))
7998 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8005 * gtk_widget_get_screen:
8006 * @widget: a #GtkWidget
8008 * Get the #GdkScreen from the toplevel window associated with
8009 * this widget. This function can only be called after the widget
8010 * has been added to a widget hierarchy with a #GtkWindow
8013 * In general, you should only create screen specific
8014 * resources when a widget has been realized, and you should
8015 * free those resources when the widget is unrealized.
8017 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8022 gtk_widget_get_screen (GtkWidget *widget)
8026 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8028 screen = gtk_widget_get_screen_unchecked (widget);
8035 g_warning (G_STRLOC ": Can't get associated screen"
8036 " for a widget unless it is inside a toplevel GtkWindow\n"
8037 " widget type is %s associated top level type is %s",
8038 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8039 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8041 return gdk_screen_get_default ();
8046 * gtk_widget_has_screen:
8047 * @widget: a #GtkWidget
8049 * Checks whether there is a #GdkScreen is associated with
8050 * this widget. All toplevel widgets have an associated
8051 * screen, and all widgets added into a hierarchy with a toplevel
8052 * window at the top.
8054 * Return value: %TRUE if there is a #GdkScreen associcated
8060 gtk_widget_has_screen (GtkWidget *widget)
8062 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8064 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8068 * gtk_widget_get_display:
8069 * @widget: a #GtkWidget
8071 * Get the #GdkDisplay for the toplevel window associated with
8072 * this widget. This function can only be called after the widget
8073 * has been added to a widget hierarchy with a #GtkWindow at the top.
8075 * In general, you should only create display specific
8076 * resources when a widget has been realized, and you should
8077 * free those resources when the widget is unrealized.
8079 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8084 gtk_widget_get_display (GtkWidget *widget)
8086 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8088 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8092 * gtk_widget_get_root_window:
8093 * @widget: a #GtkWidget
8095 * Get the root window where this widget is located. This function can
8096 * only be called after the widget has been added to a widget
8097 * hierarchy with #GtkWindow at the top.
8099 * The root window is useful for such purposes as creating a popup
8100 * #GdkWindow associated with the window. In general, you should only
8101 * create display specific resources when a widget has been realized,
8102 * and you should free those resources when the widget is unrealized.
8104 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8109 gtk_widget_get_root_window (GtkWidget *widget)
8111 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8113 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8117 * gtk_widget_child_focus:
8118 * @widget: a #GtkWidget
8119 * @direction: direction of focus movement
8121 * This function is used by custom widget implementations; if you're
8122 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8123 * to a particular widget, and gtk_container_set_focus_chain() to
8124 * change the focus tab order. So you may want to investigate those
8125 * functions instead.
8127 * gtk_widget_child_focus() is called by containers as the user moves
8128 * around the window using keyboard shortcuts. @direction indicates
8129 * what kind of motion is taking place (up, down, left, right, tab
8130 * forward, tab backward). gtk_widget_child_focus() emits the
8131 * #GtkWidget::focus signal; widgets override the default handler
8132 * for this signal in order to implement appropriate focus behavior.
8134 * The default ::focus handler for a widget should return %TRUE if
8135 * moving in @direction left the focus on a focusable location inside
8136 * that widget, and %FALSE if moving in @direction moved the focus
8137 * outside the widget. If returning %TRUE, widgets normally
8138 * call gtk_widget_grab_focus() to place the focus accordingly;
8139 * if returning %FALSE, they don't modify the current focus location.
8141 * Return value: %TRUE if focus ended up inside @widget
8144 gtk_widget_child_focus (GtkWidget *widget,
8145 GtkDirectionType direction)
8147 gboolean return_val;
8149 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8151 if (!gtk_widget_get_visible (widget) ||
8152 !gtk_widget_is_sensitive (widget))
8155 /* child widgets must set CAN_FOCUS, containers
8156 * don't have to though.
8158 if (!GTK_IS_CONTAINER (widget) &&
8159 !gtk_widget_get_can_focus (widget))
8162 g_signal_emit (widget,
8163 widget_signals[FOCUS],
8165 direction, &return_val);
8171 * gtk_widget_keynav_failed:
8172 * @widget: a #GtkWidget
8173 * @direction: direction of focus movement
8175 * This function should be called whenever keyboard navigation within
8176 * a single widget hits a boundary. The function emits the
8177 * #GtkWidget::keynav-failed signal on the widget and its return
8178 * value should be interpreted in a way similar to the return value of
8179 * gtk_widget_child_focus():
8181 * When %TRUE is returned, stay in the widget, the failed keyboard
8182 * navigation is Ok and/or there is nowhere we can/should move the
8185 * When %FALSE is returned, the caller should continue with keyboard
8186 * navigation outside the widget, e.g. by calling
8187 * gtk_widget_child_focus() on the widget's toplevel.
8189 * The default ::keynav-failed handler returns %TRUE for
8190 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8191 * values of #GtkDirectionType, it looks at the
8192 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8193 * if the setting is %TRUE. This way the entire user interface
8194 * becomes cursor-navigatable on input devices such as mobile phones
8195 * which only have cursor keys but no tab key.
8197 * Whenever the default handler returns %TRUE, it also calls
8198 * gtk_widget_error_bell() to notify the user of the failed keyboard
8201 * A use case for providing an own implementation of ::keynav-failed
8202 * (either by connecting to it or by overriding it) would be a row of
8203 * #GtkEntry widgets where the user should be able to navigate the
8204 * entire row with the cursor keys, as e.g. known from user interfaces
8205 * that require entering license keys.
8207 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8208 * if the emitting widget should try to handle the keyboard
8209 * navigation attempt in its parent container(s).
8214 gtk_widget_keynav_failed (GtkWidget *widget,
8215 GtkDirectionType direction)
8217 gboolean return_val;
8219 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8221 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8222 direction, &return_val);
8228 * gtk_widget_error_bell:
8229 * @widget: a #GtkWidget
8231 * Notifies the user about an input-related error on this widget.
8232 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8233 * gdk_window_beep(), otherwise it does nothing.
8235 * Note that the effect of gdk_window_beep() can be configured in many
8236 * ways, depending on the windowing backend and the desktop environment
8237 * or window manager that is used.
8242 gtk_widget_error_bell (GtkWidget *widget)
8244 GtkWidgetPrivate *priv;
8245 GtkSettings* settings;
8248 g_return_if_fail (GTK_IS_WIDGET (widget));
8250 priv = widget->priv;
8252 settings = gtk_widget_get_settings (widget);
8256 g_object_get (settings,
8257 "gtk-error-bell", &beep,
8260 if (beep && priv->window)
8261 gdk_window_beep (priv->window);
8265 gtk_widget_set_usize_internal (GtkWidget *widget,
8269 GtkWidgetAuxInfo *aux_info;
8270 gboolean changed = FALSE;
8272 g_object_freeze_notify (G_OBJECT (widget));
8274 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8276 if (width > -2 && aux_info->width != width)
8278 g_object_notify (G_OBJECT (widget), "width-request");
8279 aux_info->width = width;
8282 if (height > -2 && aux_info->height != height)
8284 g_object_notify (G_OBJECT (widget), "height-request");
8285 aux_info->height = height;
8289 if (gtk_widget_get_visible (widget) && changed)
8290 gtk_widget_queue_resize (widget);
8292 g_object_thaw_notify (G_OBJECT (widget));
8296 * gtk_widget_set_size_request:
8297 * @widget: a #GtkWidget
8298 * @width: width @widget should request, or -1 to unset
8299 * @height: height @widget should request, or -1 to unset
8301 * Sets the minimum size of a widget; that is, the widget's size
8302 * request will be @width by @height. You can use this function to
8303 * force a widget to be either larger or smaller than it normally
8306 * In most cases, gtk_window_set_default_size() is a better choice for
8307 * toplevel windows than this function; setting the default size will
8308 * still allow users to shrink the window. Setting the size request
8309 * will force them to leave the window at least as large as the size
8310 * request. When dealing with window sizes,
8311 * gtk_window_set_geometry_hints() can be a useful function as well.
8313 * Note the inherent danger of setting any fixed size - themes,
8314 * translations into other languages, different fonts, and user action
8315 * can all change the appropriate size for a given widget. So, it's
8316 * basically impossible to hardcode a size that will always be
8319 * The size request of a widget is the smallest size a widget can
8320 * accept while still functioning well and drawing itself correctly.
8321 * However in some strange cases a widget may be allocated less than
8322 * its requested size, and in many cases a widget may be allocated more
8323 * space than it requested.
8325 * If the size request in a given direction is -1 (unset), then
8326 * the "natural" size request of the widget will be used instead.
8328 * Widgets can't actually be allocated a size less than 1 by 1, but
8329 * you can pass 0,0 to this function to mean "as small as possible."
8331 * The size request set here does not include any margin from the
8332 * #GtkWidget properties margin-left, margin-right, margin-top, and
8333 * margin-bottom, but it does include pretty much all other padding
8334 * or border properties set by any subclass of #GtkWidget.
8337 gtk_widget_set_size_request (GtkWidget *widget,
8341 g_return_if_fail (GTK_IS_WIDGET (widget));
8342 g_return_if_fail (width >= -1);
8343 g_return_if_fail (height >= -1);
8350 gtk_widget_set_usize_internal (widget, width, height);
8355 * gtk_widget_get_size_request:
8356 * @widget: a #GtkWidget
8357 * @width: (out) (allow-none): return location for width, or %NULL
8358 * @height: (out) (allow-none): return location for height, or %NULL
8360 * Gets the size request that was explicitly set for the widget using
8361 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8362 * @height indicates that that dimension has not been set explicitly
8363 * and the natural requisition of the widget will be used intead. See
8364 * gtk_widget_set_size_request(). To get the size a widget will
8365 * actually request, call gtk_size_request_get_size() instead of
8369 gtk_widget_get_size_request (GtkWidget *widget,
8373 const GtkWidgetAuxInfo *aux_info;
8375 g_return_if_fail (GTK_IS_WIDGET (widget));
8377 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8380 *width = aux_info->width;
8383 *height = aux_info->height;
8387 * gtk_widget_set_events:
8388 * @widget: a #GtkWidget
8389 * @events: event mask
8391 * Sets the event mask (see #GdkEventMask) for a widget. The event
8392 * mask determines which events a widget will receive. Keep in mind
8393 * that different widgets have different default event masks, and by
8394 * changing the event mask you may disrupt a widget's functionality,
8395 * so be careful. This function must be called while a widget is
8396 * unrealized. Consider gtk_widget_add_events() for widgets that are
8397 * already realized, or if you want to preserve the existing event
8398 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8399 * to get events on those widgets, place them inside a #GtkEventBox
8400 * and receive events on the event box.
8403 gtk_widget_set_events (GtkWidget *widget,
8406 g_return_if_fail (GTK_IS_WIDGET (widget));
8407 g_return_if_fail (!gtk_widget_get_realized (widget));
8409 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8410 GINT_TO_POINTER (events));
8411 g_object_notify (G_OBJECT (widget), "events");
8415 * gtk_widget_set_device_events:
8416 * @widget: a #GtkWidget
8417 * @device: a #GdkDevice
8418 * @events: event mask
8420 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8421 * mask determines which events a widget will receive from @device. Keep
8422 * in mind that different widgets have different default event masks, and by
8423 * changing the event mask you may disrupt a widget's functionality,
8424 * so be careful. This function must be called while a widget is
8425 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8426 * already realized, or if you want to preserve the existing event
8427 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8428 * to get events on those widgets, place them inside a #GtkEventBox
8429 * and receive events on the event box.
8434 gtk_widget_set_device_events (GtkWidget *widget,
8436 GdkEventMask events)
8438 GHashTable *device_events;
8440 g_return_if_fail (GTK_IS_WIDGET (widget));
8441 g_return_if_fail (GDK_IS_DEVICE (device));
8442 g_return_if_fail (!gtk_widget_get_realized (widget));
8444 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8446 if (G_UNLIKELY (!device_events))
8448 device_events = g_hash_table_new (NULL, NULL);
8449 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8450 (GDestroyNotify) g_hash_table_unref);
8453 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8457 gtk_widget_add_events_internal_list (GtkWidget *widget,
8464 for (l = window_list; l != NULL; l = l->next)
8466 GdkWindow *window = l->data;
8469 gdk_window_get_user_data (window, &user_data);
8470 if (user_data == widget)
8475 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8477 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8479 children = gdk_window_get_children (window);
8480 gtk_widget_add_events_internal_list (widget, device, events, children);
8481 g_list_free (children);
8487 gtk_widget_add_events_internal (GtkWidget *widget,
8491 GtkWidgetPrivate *priv = widget->priv;
8494 if (!gtk_widget_get_has_window (widget))
8495 window_list = gdk_window_get_children (priv->window);
8497 window_list = g_list_prepend (NULL, priv->window);
8499 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8501 g_list_free (window_list);
8505 * gtk_widget_add_events:
8506 * @widget: a #GtkWidget
8507 * @events: an event mask, see #GdkEventMask
8509 * Adds the events in the bitfield @events to the event mask for
8510 * @widget. See gtk_widget_set_events() for details.
8513 gtk_widget_add_events (GtkWidget *widget,
8518 g_return_if_fail (GTK_IS_WIDGET (widget));
8520 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8521 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8522 GINT_TO_POINTER (old_events | events));
8524 if (gtk_widget_get_realized (widget))
8525 gtk_widget_add_events_internal (widget, NULL, events);
8527 g_object_notify (G_OBJECT (widget), "events");
8531 * gtk_widget_add_device_events:
8532 * @widget: a #GtkWidget
8533 * @device: a #GdkDevice
8534 * @events: an event mask, see #GdkEventMask
8536 * Adds the device events in the bitfield @events to the event mask for
8537 * @widget. See gtk_widget_set_device_events() for details.
8542 gtk_widget_add_device_events (GtkWidget *widget,
8544 GdkEventMask events)
8546 GdkEventMask old_events;
8547 GHashTable *device_events;
8549 g_return_if_fail (GTK_IS_WIDGET (widget));
8550 g_return_if_fail (GDK_IS_DEVICE (device));
8552 old_events = gtk_widget_get_device_events (widget, device);
8554 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8556 if (G_UNLIKELY (!device_events))
8558 device_events = g_hash_table_new (NULL, NULL);
8559 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8560 (GDestroyNotify) g_hash_table_unref);
8563 g_hash_table_insert (device_events, device,
8564 GUINT_TO_POINTER (old_events | events));
8566 if (gtk_widget_get_realized (widget))
8567 gtk_widget_add_events_internal (widget, device, events);
8569 g_object_notify (G_OBJECT (widget), "events");
8573 * gtk_widget_set_extension_events:
8574 * @widget: a #GtkWidget
8575 * @mode: bitfield of extension events to receive
8577 * Sets the extension events mask to @mode. See #GdkExtensionMode
8578 * and gdk_input_set_extension_events().
8581 gtk_widget_set_extension_events (GtkWidget *widget,
8582 GdkExtensionMode mode)
8584 g_return_if_fail (GTK_IS_WIDGET (widget));
8586 if (gtk_widget_get_realized (widget))
8587 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8589 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8590 GINT_TO_POINTER (mode));
8591 g_object_notify (G_OBJECT (widget), "extension-events");
8595 * gtk_widget_get_toplevel:
8596 * @widget: a #GtkWidget
8598 * This function returns the topmost widget in the container hierarchy
8599 * @widget is a part of. If @widget has no parent widgets, it will be
8600 * returned as the topmost widget. No reference will be added to the
8601 * returned widget; it should not be unreferenced.
8603 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8604 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8606 * %NULL if @widget wasn't inside a toplevel window, and if the
8607 * window was inside a #GtkWindow-derived widget which was in turn
8608 * inside the toplevel #GtkWindow. While the second case may
8609 * seem unlikely, it actually happens when a #GtkPlug is embedded
8610 * inside a #GtkSocket within the same application.
8612 * To reliably find the toplevel #GtkWindow, use
8613 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8614 * is set on the result.
8616 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8617 * if (gtk_widget_is_toplevel (toplevel))
8619 * /* Perform action on toplevel. */
8623 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8624 * if there's no ancestor.
8627 gtk_widget_get_toplevel (GtkWidget *widget)
8629 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8631 while (widget->priv->parent)
8632 widget = widget->priv->parent;
8638 * gtk_widget_get_ancestor:
8639 * @widget: a #GtkWidget
8640 * @widget_type: ancestor type
8642 * Gets the first ancestor of @widget with type @widget_type. For example,
8643 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8644 * the first #GtkBox that's an ancestor of @widget. No reference will be
8645 * added to the returned widget; it should not be unreferenced. See note
8646 * about checking for a toplevel #GtkWindow in the docs for
8647 * gtk_widget_get_toplevel().
8649 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8650 * considers @widget to be an ancestor of itself.
8652 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8655 gtk_widget_get_ancestor (GtkWidget *widget,
8658 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8660 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8661 widget = widget->priv->parent;
8663 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8670 * gtk_widget_get_colormap:
8671 * @widget: a #GtkWidget
8673 * Gets the colormap that will be used to render @widget. No reference will
8674 * be added to the returned colormap; it should not be unreferenced.
8676 * Return value: (transfer none): the colormap used by @widget
8679 gtk_widget_get_colormap (GtkWidget *widget)
8681 GtkWidgetPrivate *priv;
8682 GdkColormap *colormap;
8683 GtkWidget *tmp_widget;
8685 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8687 priv = widget->priv;
8691 colormap = gdk_drawable_get_colormap (priv->window);
8692 /* If window was destroyed previously, we'll get NULL here */
8697 tmp_widget = widget;
8700 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8704 tmp_widget= tmp_widget->priv->parent;
8707 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8711 * gtk_widget_get_visual:
8712 * @widget: a #GtkWidget
8714 * Gets the visual that will be used to render @widget.
8716 * Return value: (transfer none): the visual for @widget
8719 gtk_widget_get_visual (GtkWidget *widget)
8721 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8723 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8727 * gtk_widget_get_settings:
8728 * @widget: a #GtkWidget
8730 * Gets the settings object holding the settings (global property
8731 * settings, RC file information, etc) used for this widget.
8733 * Note that this function can only be called when the #GtkWidget
8734 * is attached to a toplevel, since the settings object is specific
8735 * to a particular #GdkScreen.
8737 * Return value: (transfer none): the relevant #GtkSettings object
8740 gtk_widget_get_settings (GtkWidget *widget)
8742 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8744 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8748 * gtk_widget_set_colormap:
8749 * @widget: a #GtkWidget
8750 * @colormap: a colormap
8752 * Sets the colormap for the widget to the given value. Widget must not
8753 * have been previously realized. This probably should only be used
8754 * from an <function>init()</function> function (i.e. from the constructor
8758 gtk_widget_set_colormap (GtkWidget *widget,
8759 GdkColormap *colormap)
8761 g_return_if_fail (GTK_IS_WIDGET (widget));
8762 g_return_if_fail (!gtk_widget_get_realized (widget));
8763 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8765 g_object_ref (colormap);
8767 g_object_set_qdata_full (G_OBJECT (widget),
8774 * gtk_widget_get_events:
8775 * @widget: a #GtkWidget
8777 * Returns the event mask for the widget (a bitfield containing flags
8778 * from the #GdkEventMask enumeration). These are the events that the widget
8781 * Return value: event mask for @widget
8784 gtk_widget_get_events (GtkWidget *widget)
8786 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8788 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8792 * gtk_widget_get_device_events:
8793 * @widget: a #GtkWidget
8794 * @device: a #GdkDevice
8796 * Returns the events mask for the widget corresponding to an specific device. These
8797 * are the events that the widget will receive when @device operates on it.
8799 * Returns: device event mask for @widget
8804 gtk_widget_get_device_events (GtkWidget *widget,
8807 GHashTable *device_events;
8809 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8810 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8812 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8817 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8821 * gtk_widget_get_extension_events:
8822 * @widget: a #GtkWidget
8824 * Retrieves the extension events the widget will receive; see
8825 * gdk_input_set_extension_events().
8827 * Return value: extension events for @widget
8830 gtk_widget_get_extension_events (GtkWidget *widget)
8832 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8834 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8838 * gtk_widget_get_pointer:
8839 * @widget: a #GtkWidget
8840 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8841 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8843 * Obtains the location of the mouse pointer in widget coordinates.
8844 * Widget coordinates are a bit odd; for historical reasons, they are
8845 * defined as @widget->window coordinates for widgets that are not
8846 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8847 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8850 gtk_widget_get_pointer (GtkWidget *widget,
8854 GtkWidgetPrivate *priv;
8856 g_return_if_fail (GTK_IS_WIDGET (widget));
8858 priv = widget->priv;
8865 if (gtk_widget_get_realized (widget))
8867 gdk_window_get_pointer (priv->window, x, y, NULL);
8869 if (!gtk_widget_get_has_window (widget))
8872 *x -= priv->allocation.x;
8874 *y -= priv->allocation.y;
8880 * gtk_widget_is_ancestor:
8881 * @widget: a #GtkWidget
8882 * @ancestor: another #GtkWidget
8884 * Determines whether @widget is somewhere inside @ancestor, possibly with
8885 * intermediate containers.
8887 * Return value: %TRUE if @ancestor contains @widget as a child,
8888 * grandchild, great grandchild, etc.
8891 gtk_widget_is_ancestor (GtkWidget *widget,
8892 GtkWidget *ancestor)
8894 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8895 g_return_val_if_fail (ancestor != NULL, FALSE);
8899 if (widget->priv->parent == ancestor)
8901 widget = widget->priv->parent;
8907 static GQuark quark_composite_name = 0;
8910 * gtk_widget_set_composite_name:
8911 * @widget: a #GtkWidget.
8912 * @name: the name to set
8914 * Sets a widgets composite name. The widget must be
8915 * a composite child of its parent; see gtk_widget_push_composite_child().
8918 gtk_widget_set_composite_name (GtkWidget *widget,
8921 g_return_if_fail (GTK_IS_WIDGET (widget));
8922 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8923 g_return_if_fail (name != NULL);
8925 if (!quark_composite_name)
8926 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8928 g_object_set_qdata_full (G_OBJECT (widget),
8929 quark_composite_name,
8935 * gtk_widget_get_composite_name:
8936 * @widget: a #GtkWidget
8938 * Obtains the composite name of a widget.
8940 * Returns: the composite name of @widget, or %NULL if @widget is not
8941 * a composite child. The string should be freed when it is no
8945 gtk_widget_get_composite_name (GtkWidget *widget)
8947 GtkWidgetPrivate *priv;
8949 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8951 priv = widget->priv;
8953 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
8954 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
8961 * gtk_widget_push_composite_child:
8963 * Makes all newly-created widgets as composite children until
8964 * the corresponding gtk_widget_pop_composite_child() call.
8966 * A composite child is a child that's an implementation detail of the
8967 * container it's inside and should not be visible to people using the
8968 * container. Composite children aren't treated differently by GTK (but
8969 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8970 * builders might want to treat them in a different way.
8972 * Here is a simple example:
8974 * gtk_widget_push_composite_child ();
8975 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8976 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8977 * gtk_widget_pop_composite_child ();
8978 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8979 * GTK_WIDGET (scrolled_window));
8980 * g_object_ref (scrolled_window->hscrollbar);
8984 gtk_widget_push_composite_child (void)
8986 composite_child_stack++;
8990 * gtk_widget_pop_composite_child:
8992 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8995 gtk_widget_pop_composite_child (void)
8997 if (composite_child_stack)
8998 composite_child_stack--;
9002 * gtk_widget_push_colormap:
9003 * @cmap: a #GdkColormap
9005 * Pushes @cmap onto a global stack of colormaps; the topmost
9006 * colormap on the stack will be used to create all widgets.
9007 * Remove @cmap with gtk_widget_pop_colormap(). There's little
9008 * reason to use this function.
9011 gtk_widget_push_colormap (GdkColormap *cmap)
9013 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
9015 colormap_stack = g_slist_prepend (colormap_stack, cmap);
9019 * gtk_widget_pop_colormap:
9021 * Removes a colormap pushed with gtk_widget_push_colormap().
9024 gtk_widget_pop_colormap (void)
9027 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
9031 * gtk_widget_set_default_colormap:
9032 * @colormap: a #GdkColormap
9034 * Sets the default colormap to use when creating widgets.
9035 * gtk_widget_push_colormap() is a better function to use if
9036 * you only want to affect a few widgets, rather than all widgets.
9039 gtk_widget_set_default_colormap (GdkColormap *colormap)
9041 g_return_if_fail (GDK_IS_COLORMAP (colormap));
9043 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
9048 * gtk_widget_get_default_colormap:
9050 * Obtains the default colormap used to create widgets.
9052 * Return value: (transfer none): default widget colormap
9055 gtk_widget_get_default_colormap (void)
9057 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
9061 * gtk_widget_get_default_visual:
9063 * Obtains the visual of the default colormap. Not really useful;
9064 * used to be useful before gdk_colormap_get_visual() existed.
9066 * Return value: (transfer none): visual of the default colormap
9069 gtk_widget_get_default_visual (void)
9071 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
9075 gtk_widget_emit_direction_changed (GtkWidget *widget,
9076 GtkTextDirection old_dir)
9078 gtk_widget_update_pango_context (widget);
9080 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9084 * gtk_widget_set_direction:
9085 * @widget: a #GtkWidget
9086 * @dir: the new direction
9088 * Sets the reading direction on a particular widget. This direction
9089 * controls the primary direction for widgets containing text,
9090 * and also the direction in which the children of a container are
9091 * packed. The ability to set the direction is present in order
9092 * so that correct localization into languages with right-to-left
9093 * reading directions can be done. Generally, applications will
9094 * let the default reading direction present, except for containers
9095 * where the containers are arranged in an order that is explicitely
9096 * visual rather than logical (such as buttons for text justification).
9098 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9099 * set by gtk_widget_set_default_direction() will be used.
9102 gtk_widget_set_direction (GtkWidget *widget,
9103 GtkTextDirection dir)
9105 GtkTextDirection old_dir;
9107 g_return_if_fail (GTK_IS_WIDGET (widget));
9108 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9110 old_dir = gtk_widget_get_direction (widget);
9112 if (dir == GTK_TEXT_DIR_NONE)
9113 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9116 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9117 if (dir == GTK_TEXT_DIR_LTR)
9118 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9120 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9123 if (old_dir != gtk_widget_get_direction (widget))
9124 gtk_widget_emit_direction_changed (widget, old_dir);
9128 * gtk_widget_get_direction:
9129 * @widget: a #GtkWidget
9131 * Gets the reading direction for a particular widget. See
9132 * gtk_widget_set_direction().
9134 * Return value: the reading direction for the widget.
9137 gtk_widget_get_direction (GtkWidget *widget)
9139 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9141 if (GTK_WIDGET_DIRECTION_SET (widget))
9142 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9144 return gtk_default_direction;
9148 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9150 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9152 g_object_ref (widget);
9154 if (!GTK_WIDGET_DIRECTION_SET (widget))
9155 gtk_widget_emit_direction_changed (widget, old_dir);
9157 if (GTK_IS_CONTAINER (widget))
9158 gtk_container_forall (GTK_CONTAINER (widget),
9159 gtk_widget_set_default_direction_recurse,
9162 g_object_unref (widget);
9166 * gtk_widget_set_default_direction:
9167 * @dir: the new default direction. This cannot be
9168 * %GTK_TEXT_DIR_NONE.
9170 * Sets the default reading direction for widgets where the
9171 * direction has not been explicitly set by gtk_widget_set_direction().
9174 gtk_widget_set_default_direction (GtkTextDirection dir)
9176 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9178 if (dir != gtk_default_direction)
9180 GList *toplevels, *tmp_list;
9181 GtkTextDirection old_dir = gtk_default_direction;
9183 gtk_default_direction = dir;
9185 tmp_list = toplevels = gtk_window_list_toplevels ();
9186 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9190 gtk_widget_set_default_direction_recurse (tmp_list->data,
9191 GUINT_TO_POINTER (old_dir));
9192 g_object_unref (tmp_list->data);
9193 tmp_list = tmp_list->next;
9196 g_list_free (toplevels);
9201 * gtk_widget_get_default_direction:
9203 * Obtains the current default reading direction. See
9204 * gtk_widget_set_default_direction().
9206 * Return value: the current default direction.
9209 gtk_widget_get_default_direction (void)
9211 return gtk_default_direction;
9215 gtk_widget_dispose (GObject *object)
9217 GtkWidget *widget = GTK_WIDGET (object);
9218 GtkWidgetPrivate *priv = widget->priv;
9221 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9222 else if (gtk_widget_get_visible (widget))
9223 gtk_widget_hide (widget);
9225 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9226 if (gtk_widget_get_realized (widget))
9227 gtk_widget_unrealize (widget);
9229 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9233 gtk_widget_real_destroy (GtkObject *object)
9235 /* gtk_object_destroy() will already hold a refcount on object */
9236 GtkWidget *widget = GTK_WIDGET (object);
9237 GtkWidgetPrivate *priv = widget->priv;
9239 /* wipe accelerator closures (keep order) */
9240 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9241 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9243 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9244 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9246 gtk_grab_remove (widget);
9248 g_object_unref (priv->style);
9249 priv->style = gtk_widget_get_default_style ();
9250 g_object_ref (priv->style);
9252 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9256 gtk_widget_finalize (GObject *object)
9258 GtkWidget *widget = GTK_WIDGET (object);
9259 GtkWidgetPrivate *priv = widget->priv;
9260 GtkWidgetAuxInfo *aux_info;
9261 GtkAccessible *accessible;
9263 gtk_grab_remove (widget);
9265 g_object_unref (priv->style);
9268 g_free (priv->name);
9270 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9272 gtk_widget_aux_info_destroy (aux_info);
9274 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9276 g_object_unref (accessible);
9278 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9281 /*****************************************
9282 * gtk_widget_real_map:
9287 *****************************************/
9290 gtk_widget_real_map (GtkWidget *widget)
9292 GtkWidgetPrivate *priv = widget->priv;
9294 g_assert (gtk_widget_get_realized (widget));
9296 if (!gtk_widget_get_mapped (widget))
9298 gtk_widget_set_mapped (widget, TRUE);
9300 if (gtk_widget_get_has_window (widget))
9301 gdk_window_show (priv->window);
9305 /*****************************************
9306 * gtk_widget_real_unmap:
9311 *****************************************/
9314 gtk_widget_real_unmap (GtkWidget *widget)
9316 GtkWidgetPrivate *priv = widget->priv;
9318 if (gtk_widget_get_mapped (widget))
9320 gtk_widget_set_mapped (widget, FALSE);
9322 if (gtk_widget_get_has_window (widget))
9323 gdk_window_hide (priv->window);
9327 /*****************************************
9328 * gtk_widget_real_realize:
9333 *****************************************/
9336 gtk_widget_real_realize (GtkWidget *widget)
9338 GtkWidgetPrivate *priv = widget->priv;
9340 g_assert (!gtk_widget_get_has_window (widget));
9342 gtk_widget_set_realized (widget, TRUE);
9345 priv->window = gtk_widget_get_parent_window (widget);
9346 g_object_ref (priv->window);
9348 priv->style = gtk_style_attach (priv->style, priv->window);
9351 /*****************************************
9352 * gtk_widget_real_unrealize:
9357 *****************************************/
9360 gtk_widget_real_unrealize (GtkWidget *widget)
9362 GtkWidgetPrivate *priv = widget->priv;
9364 if (gtk_widget_get_mapped (widget))
9365 gtk_widget_real_unmap (widget);
9367 gtk_widget_set_mapped (widget, FALSE);
9369 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9372 /* We must do unrealize child widget BEFORE container widget.
9373 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9374 * So, unrealizing container widget bofore its children causes the problem
9375 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9378 if (GTK_IS_CONTAINER (widget))
9379 gtk_container_forall (GTK_CONTAINER (widget),
9380 (GtkCallback) gtk_widget_unrealize,
9383 gtk_style_detach (priv->style);
9384 if (gtk_widget_get_has_window (widget))
9386 gdk_window_set_user_data (priv->window, NULL);
9387 gdk_window_destroy (priv->window);
9388 priv->window = NULL;
9392 g_object_unref (priv->window);
9393 priv->window = NULL;
9396 gtk_selection_remove_all (widget);
9398 gtk_widget_set_realized (widget, FALSE);
9402 gtk_widget_real_size_request (GtkWidget *widget,
9403 GtkRequisition *requisition)
9405 requisition->width = 0;
9406 requisition->height = 0;
9410 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9411 GtkOrientation orientation,
9416 const GtkWidgetAuxInfo *aux_info;
9418 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9420 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9421 aux_info->width > 0)
9423 *minimum_size = MAX (*minimum_size, aux_info->width);
9425 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9426 aux_info->height > 0)
9428 *minimum_size = MAX (*minimum_size, aux_info->height);
9431 /* Fix it if set_size_request made natural size smaller than min size.
9432 * This would also silently fix broken widgets, but we warn about them
9433 * in gtksizerequest.c when calling their size request vfuncs.
9435 *natural_size = MAX (*natural_size, *minimum_size);
9437 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9439 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9440 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9444 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9445 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9450 * _gtk_widget_peek_colormap:
9452 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
9454 * Return value: the currently pushed colormap, or %NULL if there is none.
9457 _gtk_widget_peek_colormap (void)
9460 return (GdkColormap*) colormap_stack->data;
9465 * _gtk_widget_peek_request_cache:
9467 * Returns the address of the widget's request cache (strictly for
9468 * internal use in gtksizerequest.c)
9470 * Return value: the address of @widget's size request cache.
9473 _gtk_widget_peek_request_cache (GtkWidget *widget)
9475 /* Don't bother slowing things down with the return_if_fail guards here */
9476 return &widget->priv->requests;
9480 * _gtk_widget_set_device_window:
9481 * @widget: a #GtkWidget.
9482 * @device: a #GdkDevice.
9483 * @window: the new device window.
9485 * Sets pointer window for @widget and @device. Does not ref @window.
9486 * Actually stores it on the #GdkScreen, but you don't need to know that.
9489 _gtk_widget_set_device_window (GtkWidget *widget,
9493 GtkWidgetPrivate *priv;
9495 GHashTable *device_window;
9497 g_return_if_fail (GTK_IS_WIDGET (widget));
9498 g_return_if_fail (GDK_IS_DEVICE (device));
9499 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9501 priv = widget->priv;
9503 if (!gtk_widget_get_realized (widget))
9506 screen = gdk_drawable_get_screen (priv->window);
9507 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9509 if (G_UNLIKELY (!device_window))
9511 device_window = g_hash_table_new (NULL, NULL);
9512 g_object_set_qdata_full (G_OBJECT (screen),
9513 quark_pointer_window,
9515 (GDestroyNotify) g_hash_table_destroy);
9519 g_hash_table_insert (device_window, device, window);
9521 g_hash_table_remove (device_window, device);
9525 * _gtk_widget_get_device_window:
9526 * @widget: a #GtkWidget.
9527 * @device: a #GdkDevice.
9529 * Return value: the device window set on the #GdkScreen @widget is attached
9533 _gtk_widget_get_device_window (GtkWidget *widget,
9536 GtkWidgetPrivate *priv;
9538 GHashTable *device_window;
9542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9543 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9545 priv = widget->priv;
9547 if (!gtk_widget_get_realized (widget))
9550 screen = gdk_drawable_get_screen (priv->window);
9551 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9553 if (G_UNLIKELY (!device_window))
9556 window = g_hash_table_lookup (device_window, device);
9561 gdk_window_get_user_data (window, (gpointer *) &w);
9570 * _gtk_widget_list_devices:
9571 * @widget: a #GtkWidget.
9573 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9574 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9578 _gtk_widget_list_devices (GtkWidget *widget)
9580 GtkWidgetPrivate *priv;
9582 GHashTableIter iter;
9583 GHashTable *device_window;
9584 GList *devices = NULL;
9585 gpointer key, value;
9587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9589 priv = widget->priv;
9591 if (!gtk_widget_get_realized (widget))
9594 screen = gdk_drawable_get_screen (priv->window);
9595 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9597 if (G_UNLIKELY (!device_window))
9600 g_hash_table_iter_init (&iter, device_window);
9602 while (g_hash_table_iter_next (&iter, &key, &value))
9604 GdkDevice *device = key;
9605 GdkWindow *window = value;
9610 gdk_window_get_user_data (window, (gpointer *) &w);
9613 devices = g_list_prepend (devices, device);
9621 synth_crossing (GtkWidget *widget,
9625 GdkCrossingMode mode,
9626 GdkNotifyType detail)
9630 event = gdk_event_new (type);
9632 event->crossing.window = g_object_ref (window);
9633 event->crossing.send_event = TRUE;
9634 event->crossing.subwindow = g_object_ref (window);
9635 event->crossing.time = GDK_CURRENT_TIME;
9636 event->crossing.x = event->crossing.y = 0;
9637 event->crossing.x_root = event->crossing.y_root = 0;
9638 event->crossing.mode = mode;
9639 event->crossing.detail = detail;
9640 event->crossing.focus = FALSE;
9641 event->crossing.state = 0;
9642 gdk_event_set_device (event, device);
9645 widget = gtk_get_event_widget (event);
9648 gtk_widget_event_internal (widget, event);
9650 gdk_event_free (event);
9654 * _gtk_widget_synthesize_crossing:
9655 * @from: the #GtkWidget the virtual pointer is leaving.
9656 * @to: the #GtkWidget the virtual pointer is moving to.
9657 * @mode: the #GdkCrossingMode to place on the synthesized events.
9659 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9661 * The real pointer window is the window that most recently received an enter notify
9662 * event. Windows that don't select for crossing events can't become the real
9663 * poiner window. The real pointer widget that owns the real pointer window. The
9664 * effective pointer window is the same as the real pointer window unless the real
9665 * pointer widget is either insensitive or there is a grab on a widget that is not
9666 * an ancestor of the real pointer widget (in which case the effective pointer
9667 * window should be the root window).
9669 * When the effective pointer window is the same as the real poiner window, we
9670 * receive crossing events from the windowing system. When the effective pointer
9671 * window changes to become different from the real pointer window we synthesize
9672 * crossing events, attempting to follow X protocol rules:
9674 * When the root window becomes the effective pointer window:
9675 * - leave notify on real pointer window, detail Ancestor
9676 * - leave notify on all of its ancestors, detail Virtual
9677 * - enter notify on root window, detail Inferior
9679 * When the root window ceases to be the effective pointer window:
9680 * - leave notify on root window, detail Inferior
9681 * - enter notify on all ancestors of real pointer window, detail Virtual
9682 * - enter notify on real pointer window, detail Ancestor
9685 _gtk_widget_synthesize_crossing (GtkWidget *from,
9688 GdkCrossingMode mode)
9690 GdkWindow *from_window = NULL, *to_window = NULL;
9692 g_return_if_fail (from != NULL || to != NULL);
9696 from_window = _gtk_widget_get_device_window (from, device);
9699 from_window = from->priv->window;
9704 to_window = _gtk_widget_get_device_window (to, device);
9707 to_window = to->priv->window;
9710 if (from_window == NULL && to_window == NULL)
9712 else if (from_window != NULL && to_window == NULL)
9714 GList *from_ancestors = NULL, *list;
9715 GdkWindow *from_ancestor = from_window;
9717 while (from_ancestor != NULL)
9719 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9720 if (from_ancestor == NULL)
9722 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9725 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9726 device, mode, GDK_NOTIFY_ANCESTOR);
9727 for (list = g_list_last (from_ancestors); list; list = list->prev)
9729 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9730 device, mode, GDK_NOTIFY_VIRTUAL);
9733 /* XXX: enter/inferior on root window? */
9735 g_list_free (from_ancestors);
9737 else if (from_window == NULL && to_window != NULL)
9739 GList *to_ancestors = NULL, *list;
9740 GdkWindow *to_ancestor = to_window;
9742 while (to_ancestor != NULL)
9744 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9745 if (to_ancestor == NULL)
9747 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9750 /* XXX: leave/inferior on root window? */
9752 for (list = to_ancestors; list; list = list->next)
9754 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9755 device, mode, GDK_NOTIFY_VIRTUAL);
9757 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9758 device, mode, GDK_NOTIFY_ANCESTOR);
9760 g_list_free (to_ancestors);
9762 else if (from_window == to_window)
9766 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9767 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9769 while (from_ancestor != NULL || to_ancestor != NULL)
9771 if (from_ancestor != NULL)
9773 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9774 if (from_ancestor == to_window)
9777 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9779 if (to_ancestor != NULL)
9781 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9782 if (to_ancestor == from_window)
9785 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9788 if (to_ancestor == from_window)
9790 if (mode != GDK_CROSSING_GTK_UNGRAB)
9791 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9792 device, mode, GDK_NOTIFY_INFERIOR);
9793 for (list = to_ancestors; list; list = list->next)
9794 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9795 device, mode, GDK_NOTIFY_VIRTUAL);
9796 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9797 device, mode, GDK_NOTIFY_ANCESTOR);
9799 else if (from_ancestor == to_window)
9801 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9802 device, mode, GDK_NOTIFY_ANCESTOR);
9803 for (list = g_list_last (from_ancestors); list; list = list->prev)
9805 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9806 device, mode, GDK_NOTIFY_VIRTUAL);
9808 if (mode != GDK_CROSSING_GTK_GRAB)
9809 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9810 device, mode, GDK_NOTIFY_INFERIOR);
9814 while (from_ancestors != NULL && to_ancestors != NULL
9815 && from_ancestors->data == to_ancestors->data)
9817 from_ancestors = g_list_delete_link (from_ancestors,
9819 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9822 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9823 device, mode, GDK_NOTIFY_NONLINEAR);
9825 for (list = g_list_last (from_ancestors); list; list = list->prev)
9827 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9828 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9830 for (list = to_ancestors; list; list = list->next)
9832 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9833 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9835 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9836 device, mode, GDK_NOTIFY_NONLINEAR);
9838 g_list_free (from_ancestors);
9839 g_list_free (to_ancestors);
9844 gtk_widget_propagate_state (GtkWidget *widget,
9847 GtkWidgetPrivate *priv = widget->priv;
9848 guint8 old_state = gtk_widget_get_state (widget);
9849 guint8 old_saved_state = priv->saved_state;
9851 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9852 * parent_sensitive==TRUE on a sensitive widget
9856 if (data->parent_sensitive)
9857 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9859 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9861 if (gtk_widget_is_sensitive (widget))
9863 if (data->state_restoration)
9864 priv->state = priv->saved_state;
9866 priv->state = data->state;
9870 if (!data->state_restoration)
9872 if (data->state != GTK_STATE_INSENSITIVE)
9873 priv->saved_state = data->state;
9875 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9876 priv->saved_state = gtk_widget_get_state (widget);
9877 priv->state = GTK_STATE_INSENSITIVE;
9880 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9884 window = gtk_widget_get_toplevel (widget);
9885 if (window && gtk_widget_is_toplevel (window))
9886 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9889 if (old_state != gtk_widget_get_state (widget) ||
9890 old_saved_state != priv->saved_state)
9892 g_object_ref (widget);
9894 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9895 gtk_grab_remove (widget);
9897 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9899 if (!GTK_WIDGET_SHADOWED (widget))
9901 GList *event_windows = NULL;
9904 devices = _gtk_widget_list_devices (widget);
9906 for (d = devices; d; d = d->next)
9912 window = _gtk_widget_get_device_window (widget, device);
9914 /* Do not propagate more than once to the
9915 * same window if non-multidevice aware.
9917 if (!gdk_window_get_support_multidevice (window) &&
9918 g_list_find (event_windows, window))
9921 if (!gtk_widget_is_sensitive (widget))
9922 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9923 GDK_CROSSING_STATE_CHANGED);
9924 else if (old_state == GTK_STATE_INSENSITIVE)
9925 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9926 GDK_CROSSING_STATE_CHANGED);
9928 event_windows = g_list_prepend (event_windows, window);
9931 g_list_free (event_windows);
9932 g_list_free (devices);
9935 if (GTK_IS_CONTAINER (widget))
9937 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9938 if (data->use_forall)
9939 gtk_container_forall (GTK_CONTAINER (widget),
9940 (GtkCallback) gtk_widget_propagate_state,
9943 gtk_container_foreach (GTK_CONTAINER (widget),
9944 (GtkCallback) gtk_widget_propagate_state,
9947 g_object_unref (widget);
9951 static const GtkWidgetAuxInfo default_aux_info = {
9959 * _gtk_widget_get_aux_info:
9960 * @widget: a #GtkWidget
9961 * @create: if %TRUE, create the structure if it doesn't exist
9963 * Get the #GtkWidgetAuxInfo structure for the widget.
9965 * Return value: the #GtkAuxInfo structure for the widget, or
9966 * %NULL if @create is %FALSE and one doesn't already exist.
9969 _gtk_widget_get_aux_info (GtkWidget *widget,
9972 GtkWidgetAuxInfo *aux_info;
9974 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9975 if (!aux_info && create)
9977 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9979 *aux_info = default_aux_info;
9981 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9987 static const GtkWidgetAuxInfo*
9988 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
9990 GtkWidgetAuxInfo *aux_info;
9992 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
9993 if (aux_info == NULL)
9995 return &default_aux_info;
10003 /*****************************************
10004 * gtk_widget_aux_info_destroy:
10009 *****************************************/
10012 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10014 g_slice_free (GtkWidgetAuxInfo, aux_info);
10018 * gtk_widget_shape_combine_region:
10019 * @widget: a #GtkWidget
10020 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10022 * Sets a shape for this widget's GDK window. This allows for
10023 * transparent windows etc., see gdk_window_shape_combine_region()
10024 * for more information.
10029 gtk_widget_shape_combine_region (GtkWidget *widget,
10030 cairo_region_t *region)
10032 GtkWidgetPrivate *priv;
10034 g_return_if_fail (GTK_IS_WIDGET (widget));
10035 /* set_shape doesn't work on widgets without gdk window */
10036 g_return_if_fail (gtk_widget_get_has_window (widget));
10038 priv = widget->priv;
10040 if (region == NULL)
10042 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10045 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10047 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10051 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10053 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10054 cairo_region_copy (region),
10055 (GDestroyNotify) cairo_region_destroy);
10057 /* set shape if widget has a gdk window already.
10058 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10061 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10066 * gtk_widget_input_shape_combine_region:
10067 * @widget: a #GtkWidget
10068 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10070 * Sets an input shape for this widget's GDK window. This allows for
10071 * windows which react to mouse click in a nonrectangular region, see
10072 * gdk_window_input_shape_combine_region() for more information.
10077 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10078 cairo_region_t *region)
10080 GtkWidgetPrivate *priv;
10082 g_return_if_fail (GTK_IS_WIDGET (widget));
10083 /* set_shape doesn't work on widgets without gdk window */
10084 g_return_if_fail (gtk_widget_get_has_window (widget));
10086 priv = widget->priv;
10088 if (region == NULL)
10091 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10093 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10097 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10098 cairo_region_copy (region),
10099 (GDestroyNotify) cairo_region_destroy);
10101 /* set shape if widget has a gdk window already.
10102 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10105 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10111 gtk_reset_shapes_recurse (GtkWidget *widget,
10117 gdk_window_get_user_data (window, &data);
10118 if (data != widget)
10121 gdk_window_shape_combine_region (window, NULL, 0, 0);
10122 for (list = gdk_window_peek_children (window); list; list = list->next)
10123 gtk_reset_shapes_recurse (widget, list->data);
10127 * gtk_widget_reset_shapes:
10128 * @widget: a #GtkWidget
10130 * Recursively resets the shape on this widget and its descendants.
10133 gtk_widget_reset_shapes (GtkWidget *widget)
10135 GtkWidgetPrivate *priv;
10137 g_return_if_fail (GTK_IS_WIDGET (widget));
10138 g_return_if_fail (gtk_widget_get_realized (widget));
10140 priv = widget->priv;
10142 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10143 gtk_reset_shapes_recurse (widget, priv->window);
10146 /* style properties
10150 * gtk_widget_class_install_style_property_parser:
10151 * @klass: a #GtkWidgetClass
10152 * @pspec: the #GParamSpec for the style property
10153 * @parser: the parser for the style property
10155 * Installs a style property on a widget class.
10158 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10160 GtkRcPropertyParser parser)
10162 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10163 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10164 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10165 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10167 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10169 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10170 G_OBJECT_CLASS_NAME (klass),
10175 g_param_spec_ref_sink (pspec);
10176 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10177 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10181 * gtk_widget_class_install_style_property:
10182 * @klass: a #GtkWidgetClass
10183 * @pspec: the #GParamSpec for the property
10185 * Installs a style property on a widget class. The parser for the
10186 * style property is determined by the value type of @pspec.
10189 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10192 GtkRcPropertyParser parser;
10194 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10195 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10197 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10199 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10203 * gtk_widget_class_find_style_property:
10204 * @klass: a #GtkWidgetClass
10205 * @property_name: the name of the style property to find
10206 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10207 * style property with that name.
10209 * Finds a style property of a widget class by name.
10214 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10215 const gchar *property_name)
10217 g_return_val_if_fail (property_name != NULL, NULL);
10219 return g_param_spec_pool_lookup (style_property_spec_pool,
10221 G_OBJECT_CLASS_TYPE (klass),
10226 * gtk_widget_class_list_style_properties:
10227 * @klass: a #GtkWidgetClass
10228 * @n_properties: location to return the number of style properties found
10229 * @returns: an newly allocated array of #GParamSpec*. The array must
10230 * be freed with g_free().
10232 * Returns all style properties of a widget class.
10237 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10238 guint *n_properties)
10240 GParamSpec **pspecs;
10243 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10244 G_OBJECT_CLASS_TYPE (klass),
10253 * gtk_widget_style_get_property:
10254 * @widget: a #GtkWidget
10255 * @property_name: the name of a style property
10256 * @value: location to return the property value
10258 * Gets the value of a style property of @widget.
10261 gtk_widget_style_get_property (GtkWidget *widget,
10262 const gchar *property_name,
10265 GtkWidgetPrivate *priv;
10268 g_return_if_fail (GTK_IS_WIDGET (widget));
10269 g_return_if_fail (property_name != NULL);
10270 g_return_if_fail (G_IS_VALUE (value));
10272 priv = widget->priv;
10274 g_object_ref (widget);
10275 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10277 G_OBJECT_TYPE (widget),
10280 g_warning ("%s: widget class `%s' has no property named `%s'",
10282 G_OBJECT_TYPE_NAME (widget),
10286 const GValue *peek_value;
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));
10293 /* auto-conversion of the caller's value type
10295 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10296 g_value_copy (peek_value, value);
10297 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10298 g_value_transform (peek_value, value);
10300 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10302 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10303 G_VALUE_TYPE_NAME (value));
10305 g_object_unref (widget);
10309 * gtk_widget_style_get_valist:
10310 * @widget: a #GtkWidget
10311 * @first_property_name: the name of the first property to get
10312 * @var_args: a <type>va_list</type> of pairs of property names and
10313 * locations to return the property values, starting with the location
10314 * for @first_property_name.
10316 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10320 gtk_widget_style_get_valist (GtkWidget *widget,
10321 const gchar *first_property_name,
10324 GtkWidgetPrivate *priv;
10327 g_return_if_fail (GTK_IS_WIDGET (widget));
10329 priv = widget->priv;
10331 g_object_ref (widget);
10333 name = first_property_name;
10336 const GValue *peek_value;
10340 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10342 G_OBJECT_TYPE (widget),
10346 g_warning ("%s: widget class `%s' has no property named `%s'",
10348 G_OBJECT_TYPE_NAME (widget),
10352 /* style pspecs are always readable so we can spare that check here */
10354 peek_value = _gtk_style_peek_property_value (priv->style,
10355 G_OBJECT_TYPE (widget),
10357 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10358 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10361 g_warning ("%s: %s", G_STRLOC, error);
10366 name = va_arg (var_args, gchar*);
10369 g_object_unref (widget);
10373 * gtk_widget_style_get:
10374 * @widget: a #GtkWidget
10375 * @first_property_name: the name of the first property to get
10376 * @Varargs: pairs of property names and locations to
10377 * return the property values, starting with the location for
10378 * @first_property_name, terminated by %NULL.
10380 * Gets the values of a multiple style properties of @widget.
10383 gtk_widget_style_get (GtkWidget *widget,
10384 const gchar *first_property_name,
10389 g_return_if_fail (GTK_IS_WIDGET (widget));
10391 va_start (var_args, first_property_name);
10392 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10398 * @widget: a #GtkWidget
10399 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10400 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10401 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10403 * Obtains the full path to @widget. The path is simply the name of a
10404 * widget and all its parents in the container hierarchy, separated by
10405 * periods. The name of a widget comes from
10406 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10407 * in gtkrc configuration files. Widget names are the type of the
10408 * widget by default (e.g. "GtkButton") or can be set to an
10409 * application-specific value with gtk_widget_set_name(). By setting
10410 * the name of a widget, you allow users or theme authors to apply
10411 * styles to that specific widget in their gtkrc
10412 * file. @path_reversed_p fills in the path in reverse order,
10413 * i.e. starting with @widget's name instead of starting with the name
10414 * of @widget's outermost ancestor.
10417 gtk_widget_path (GtkWidget *widget,
10418 guint *path_length,
10420 gchar **path_reversed)
10422 static gchar *rev_path = NULL;
10423 static guint tmp_path_len = 0;
10426 g_return_if_fail (GTK_IS_WIDGET (widget));
10431 const gchar *string;
10436 string = gtk_widget_get_name (widget);
10437 l = strlen (string);
10438 while (tmp_path_len <= len + l + 1)
10440 tmp_path_len += INIT_PATH_SIZE;
10441 rev_path = g_realloc (rev_path, tmp_path_len);
10443 s = string + l - 1;
10444 d = rev_path + len;
10445 while (s >= string)
10449 widget = widget->priv->parent;
10452 rev_path[len++] = '.';
10454 rev_path[len++] = 0;
10459 *path_length = len - 1;
10461 *path_reversed = g_strdup (rev_path);
10464 *path = g_strdup (rev_path);
10465 g_strreverse (*path);
10470 * gtk_widget_class_path:
10471 * @widget: a #GtkWidget
10472 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10473 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10474 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10477 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10478 * never uses a custom name set with gtk_widget_set_name().
10482 gtk_widget_class_path (GtkWidget *widget,
10483 guint *path_length,
10485 gchar **path_reversed)
10487 static gchar *rev_path = NULL;
10488 static guint tmp_path_len = 0;
10491 g_return_if_fail (GTK_IS_WIDGET (widget));
10496 const gchar *string;
10501 string = g_type_name (G_OBJECT_TYPE (widget));
10502 l = strlen (string);
10503 while (tmp_path_len <= len + l + 1)
10505 tmp_path_len += INIT_PATH_SIZE;
10506 rev_path = g_realloc (rev_path, tmp_path_len);
10508 s = string + l - 1;
10509 d = rev_path + len;
10510 while (s >= string)
10514 widget = widget->priv->parent;
10517 rev_path[len++] = '.';
10519 rev_path[len++] = 0;
10524 *path_length = len - 1;
10526 *path_reversed = g_strdup (rev_path);
10529 *path = g_strdup (rev_path);
10530 g_strreverse (*path);
10535 * gtk_requisition_new:
10537 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10539 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10540 * be freed with gtk_requisition_free().
10545 gtk_requisition_new (void)
10547 return g_slice_new0 (GtkRequisition);
10551 * gtk_requisition_copy:
10552 * @requisition: a #GtkRequisition
10554 * Copies a #GtkRequisition.
10556 * Returns: a copy of @requisition
10559 gtk_requisition_copy (const GtkRequisition *requisition)
10561 return g_slice_dup (GtkRequisition, requisition);
10565 * gtk_requisition_free:
10566 * @requisition: a #GtkRequisition
10568 * Frees a #GtkRequisition.
10571 gtk_requisition_free (GtkRequisition *requisition)
10573 g_slice_free (GtkRequisition, requisition);
10576 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10577 gtk_requisition_copy,
10578 gtk_requisition_free)
10581 * gtk_widget_get_accessible:
10582 * @widget: a #GtkWidget
10584 * Returns the accessible object that describes the widget to an
10585 * assistive technology.
10587 * If no accessibility library is loaded (i.e. no ATK implementation library is
10588 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10589 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10590 * if no class-specific #AtkObject implementation is available for the widget
10591 * instance in question, it will inherit an #AtkObject implementation from the
10592 * first ancestor class for which such an implementation is defined.
10594 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10595 * library contains more information about accessible objects and their uses.
10597 * Returns: (transfer none): the #AtkObject associated with @widget
10600 gtk_widget_get_accessible (GtkWidget *widget)
10602 GtkWidgetClass *klass;
10604 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10606 klass = GTK_WIDGET_GET_CLASS (widget);
10608 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10610 return klass->get_accessible (widget);
10614 gtk_widget_real_get_accessible (GtkWidget *widget)
10616 AtkObject* accessible;
10618 accessible = g_object_get_qdata (G_OBJECT (widget),
10619 quark_accessible_object);
10622 AtkObjectFactory *factory;
10623 AtkRegistry *default_registry;
10625 default_registry = atk_get_default_registry ();
10626 factory = atk_registry_get_factory (default_registry,
10627 G_TYPE_FROM_INSTANCE (widget));
10629 atk_object_factory_create_accessible (factory,
10630 G_OBJECT (widget));
10631 g_object_set_qdata (G_OBJECT (widget),
10632 quark_accessible_object,
10639 * Initialize a AtkImplementorIface instance's virtual pointers as
10640 * appropriate to this implementor's class (GtkWidget).
10643 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10645 iface->ref_accessible = gtk_widget_ref_accessible;
10649 gtk_widget_ref_accessible (AtkImplementor *implementor)
10651 AtkObject *accessible;
10653 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10655 g_object_ref (accessible);
10660 * GtkBuildable implementation
10662 static GQuark quark_builder_has_default = 0;
10663 static GQuark quark_builder_has_focus = 0;
10664 static GQuark quark_builder_atk_relations = 0;
10665 static GQuark quark_builder_set_name = 0;
10668 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10670 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10671 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10672 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10673 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10675 iface->set_name = gtk_widget_buildable_set_name;
10676 iface->get_name = gtk_widget_buildable_get_name;
10677 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10678 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10679 iface->parser_finished = gtk_widget_buildable_parser_finished;
10680 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10681 iface->custom_finished = gtk_widget_buildable_custom_finished;
10685 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10688 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10689 g_strdup (name), g_free);
10692 static const gchar *
10693 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10695 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10699 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10700 GtkBuilder *builder,
10701 const gchar *childname)
10703 if (strcmp (childname, "accessible") == 0)
10704 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10710 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10711 GtkBuilder *builder,
10713 const GValue *value)
10715 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10716 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10717 GINT_TO_POINTER (TRUE));
10718 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10719 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10720 GINT_TO_POINTER (TRUE));
10722 g_object_set_property (G_OBJECT (buildable), name, value);
10727 gchar *action_name;
10728 GString *description;
10730 gboolean translatable;
10740 free_action (AtkActionData *data, gpointer user_data)
10742 g_free (data->action_name);
10743 g_string_free (data->description, TRUE);
10744 g_free (data->context);
10745 g_slice_free (AtkActionData, data);
10749 free_relation (AtkRelationData *data, gpointer user_data)
10751 g_free (data->target);
10752 g_free (data->type);
10753 g_slice_free (AtkRelationData, data);
10757 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10758 GtkBuilder *builder)
10760 GSList *atk_relations;
10762 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10763 gtk_widget_grab_default (GTK_WIDGET (buildable));
10764 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10765 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10767 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10768 quark_builder_atk_relations);
10771 AtkObject *accessible;
10772 AtkRelationSet *relation_set;
10775 AtkRelationType relation_type;
10776 AtkObject *target_accessible;
10778 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10779 relation_set = atk_object_ref_relation_set (accessible);
10781 for (l = atk_relations; l; l = l->next)
10783 AtkRelationData *relation = (AtkRelationData*)l->data;
10785 target = gtk_builder_get_object (builder, relation->target);
10788 g_warning ("Target object %s in <relation> does not exist",
10792 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10793 g_assert (target_accessible != NULL);
10795 relation_type = atk_relation_type_for_name (relation->type);
10796 if (relation_type == ATK_RELATION_NULL)
10798 g_warning ("<relation> type %s not found",
10802 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10803 target_accessible);
10805 g_object_unref (relation_set);
10807 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10808 g_slist_free (atk_relations);
10809 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10818 } AccessibilitySubParserData;
10821 accessibility_start_element (GMarkupParseContext *context,
10822 const gchar *element_name,
10823 const gchar **names,
10824 const gchar **values,
10825 gpointer user_data,
10828 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10830 gint line_number, char_number;
10832 if (strcmp (element_name, "relation") == 0)
10834 gchar *target = NULL;
10835 gchar *type = NULL;
10836 AtkRelationData *relation;
10838 for (i = 0; names[i]; i++)
10840 if (strcmp (names[i], "target") == 0)
10841 target = g_strdup (values[i]);
10842 else if (strcmp (names[i], "type") == 0)
10843 type = g_strdup (values[i]);
10846 g_markup_parse_context_get_position (context,
10849 g_set_error (error,
10851 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10852 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10854 line_number, char_number, names[i], "relation");
10861 if (!target || !type)
10863 g_markup_parse_context_get_position (context,
10866 g_set_error (error,
10868 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10869 "%s:%d:%d <%s> requires attribute \"%s\"",
10871 line_number, char_number, "relation",
10872 type ? "target" : "type");
10878 relation = g_slice_new (AtkRelationData);
10879 relation->target = target;
10880 relation->type = type;
10882 data->relations = g_slist_prepend (data->relations, relation);
10884 else if (strcmp (element_name, "action") == 0)
10886 const gchar *action_name = NULL;
10887 const gchar *description = NULL;
10888 const gchar *msg_context = NULL;
10889 gboolean translatable = FALSE;
10890 AtkActionData *action;
10892 for (i = 0; names[i]; i++)
10894 if (strcmp (names[i], "action_name") == 0)
10895 action_name = values[i];
10896 else if (strcmp (names[i], "description") == 0)
10897 description = values[i];
10898 else if (strcmp (names[i], "translatable") == 0)
10900 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10903 else if (strcmp (names[i], "comments") == 0)
10905 /* do nothing, comments are for translators */
10907 else if (strcmp (names[i], "context") == 0)
10908 msg_context = values[i];
10911 g_markup_parse_context_get_position (context,
10914 g_set_error (error,
10916 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10917 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10919 line_number, char_number, names[i], "action");
10926 g_markup_parse_context_get_position (context,
10929 g_set_error (error,
10931 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10932 "%s:%d:%d <%s> requires attribute \"%s\"",
10934 line_number, char_number, "action",
10939 action = g_slice_new (AtkActionData);
10940 action->action_name = g_strdup (action_name);
10941 action->description = g_string_new (description);
10942 action->context = g_strdup (msg_context);
10943 action->translatable = translatable;
10945 data->actions = g_slist_prepend (data->actions, action);
10947 else if (strcmp (element_name, "accessibility") == 0)
10950 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10954 accessibility_text (GMarkupParseContext *context,
10957 gpointer user_data,
10960 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10962 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10964 AtkActionData *action = data->actions->data;
10966 g_string_append_len (action->description, text, text_len);
10970 static const GMarkupParser accessibility_parser =
10972 accessibility_start_element,
10974 accessibility_text,
10983 } AccelGroupParserData;
10986 accel_group_start_element (GMarkupParseContext *context,
10987 const gchar *element_name,
10988 const gchar **names,
10989 const gchar **values,
10990 gpointer user_data,
10995 guint modifiers = 0;
10996 gchar *signal = NULL;
10997 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10999 for (i = 0; names[i]; i++)
11001 if (strcmp (names[i], "key") == 0)
11002 key = gdk_keyval_from_name (values[i]);
11003 else if (strcmp (names[i], "modifiers") == 0)
11005 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11011 else if (strcmp (names[i], "signal") == 0)
11012 signal = g_strdup (values[i]);
11015 if (key == 0 || signal == NULL)
11017 g_warning ("<accelerator> requires key and signal attributes");
11020 parser_data->key = key;
11021 parser_data->modifiers = modifiers;
11022 parser_data->signal = signal;
11025 static const GMarkupParser accel_group_parser =
11027 accel_group_start_element,
11031 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11032 GtkBuilder *builder,
11034 const gchar *tagname,
11035 GMarkupParser *parser,
11038 g_assert (buildable);
11040 if (strcmp (tagname, "accelerator") == 0)
11042 AccelGroupParserData *parser_data;
11044 parser_data = g_slice_new0 (AccelGroupParserData);
11045 parser_data->object = g_object_ref (buildable);
11046 *parser = accel_group_parser;
11047 *data = parser_data;
11050 if (strcmp (tagname, "accessibility") == 0)
11052 AccessibilitySubParserData *parser_data;
11054 parser_data = g_slice_new0 (AccessibilitySubParserData);
11055 *parser = accessibility_parser;
11056 *data = parser_data;
11063 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11064 GtkWidget *toplevel,
11065 gpointer user_data)
11067 AccelGroupParserData *accel_data;
11068 GSList *accel_groups;
11069 GtkAccelGroup *accel_group;
11071 g_return_if_fail (GTK_IS_WIDGET (widget));
11072 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11073 g_return_if_fail (user_data != NULL);
11075 accel_data = (AccelGroupParserData*)user_data;
11076 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11077 if (g_slist_length (accel_groups) == 0)
11079 accel_group = gtk_accel_group_new ();
11080 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11084 g_assert (g_slist_length (accel_groups) == 1);
11085 accel_group = g_slist_nth_data (accel_groups, 0);
11088 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11089 accel_data->signal,
11092 accel_data->modifiers,
11093 GTK_ACCEL_VISIBLE);
11095 g_object_unref (accel_data->object);
11096 g_free (accel_data->signal);
11097 g_slice_free (AccelGroupParserData, accel_data);
11101 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11102 GtkBuilder *builder,
11104 const gchar *tagname,
11105 gpointer user_data)
11107 AccelGroupParserData *accel_data;
11108 AccessibilitySubParserData *a11y_data;
11109 GtkWidget *toplevel;
11111 if (strcmp (tagname, "accelerator") == 0)
11113 accel_data = (AccelGroupParserData*)user_data;
11114 g_assert (accel_data->object);
11116 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11118 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11120 else if (strcmp (tagname, "accessibility") == 0)
11122 a11y_data = (AccessibilitySubParserData*)user_data;
11124 if (a11y_data->actions)
11126 AtkObject *accessible;
11131 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11133 action = ATK_ACTION (accessible);
11134 n_actions = atk_action_get_n_actions (action);
11136 for (l = a11y_data->actions; l; l = l->next)
11138 AtkActionData *action_data = (AtkActionData*)l->data;
11140 for (i = 0; i < n_actions; i++)
11141 if (strcmp (atk_action_get_name (action, i),
11142 action_data->action_name) == 0)
11147 gchar *description;
11149 if (action_data->translatable && action_data->description->len)
11150 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11151 action_data->context,
11152 action_data->description->str);
11154 description = action_data->description->str;
11156 atk_action_set_description (action, i, description);
11160 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11161 g_slist_free (a11y_data->actions);
11164 if (a11y_data->relations)
11165 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11166 a11y_data->relations);
11168 g_slice_free (AccessibilitySubParserData, a11y_data);
11173 * GtkSizeRequest implementation
11176 gtk_widget_real_get_width (GtkSizeRequest *widget,
11177 gint *minimum_size,
11178 gint *natural_size)
11188 gtk_widget_real_get_height (GtkSizeRequest *widget,
11189 gint *minimum_size,
11190 gint *natural_size)
11200 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11202 gint *minimum_height,
11203 gint *natural_height)
11205 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11209 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11211 gint *minimum_width,
11212 gint *natural_width)
11214 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11218 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11220 iface->get_width = gtk_widget_real_get_width;
11221 iface->get_height = gtk_widget_real_get_height;
11222 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11223 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
11227 * gtk_widget_get_halign:
11228 * @widget: a #GtkWidget
11230 * Gets the value of the #GtkWidget:halign property.
11232 * Returns: the horizontal alignment of @widget
11235 gtk_widget_get_halign (GtkWidget *widget)
11237 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11238 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11242 * gtk_widget_set_halign:
11243 * @widget: a #GtkWidget
11244 * @align: the horizontal alignment
11246 * Sets the horizontal alignment of @widget.
11247 * See the #GtkWidget:halign property.
11250 gtk_widget_set_halign (GtkWidget *widget,
11253 GtkWidgetAuxInfo *aux_info;
11255 g_return_if_fail (GTK_IS_WIDGET (widget));
11257 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11259 if (aux_info->halign == align)
11262 aux_info->halign = align;
11263 gtk_widget_queue_resize (widget);
11264 g_object_notify (G_OBJECT (widget), "halign");
11268 * gtk_widget_get_valign:
11269 * @widget: a #GtkWidget
11271 * Gets the value of the #GtkWidget:valign property.
11273 * Returns: the vertical alignment of @widget
11276 gtk_widget_get_valign (GtkWidget *widget)
11278 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11279 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11283 * gtk_widget_set_valign:
11284 * @widget: a #GtkWidget
11285 * @align: the vertical alignment
11287 * Sets the vertical alignment of @widget.
11288 * See the #GtkWidget:valign property.
11291 gtk_widget_set_valign (GtkWidget *widget,
11294 GtkWidgetAuxInfo *aux_info;
11296 g_return_if_fail (GTK_IS_WIDGET (widget));
11298 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11300 if (aux_info->valign == align)
11303 aux_info->valign = align;
11304 gtk_widget_queue_resize (widget);
11305 g_object_notify (G_OBJECT (widget), "valign");
11309 * gtk_widget_get_margin_left:
11310 * @widget: a #GtkWidget
11312 * Gets the value of the #GtkWidget:margin-left property.
11314 * Returns: The left margin of @widget
11317 gtk_widget_get_margin_left (GtkWidget *widget)
11319 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11321 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11325 * gtk_widget_set_margin_left:
11326 * @widget: a #GtkWidget
11327 * @margin: the left margin
11329 * Sets the left margin of @widget.
11330 * See the #GtkWidget:margin-left property.
11333 gtk_widget_set_margin_left (GtkWidget *widget,
11336 GtkWidgetAuxInfo *aux_info;
11338 g_return_if_fail (GTK_IS_WIDGET (widget));
11339 g_return_if_fail (margin <= G_MAXINT16);
11341 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11343 if (aux_info->margin.left == margin)
11346 aux_info->margin.left = margin;
11347 gtk_widget_queue_resize (widget);
11348 g_object_notify (G_OBJECT (widget), "margin-left");
11352 * gtk_widget_get_margin_right:
11353 * @widget: a #GtkWidget
11355 * Gets the value of the #GtkWidget:margin-right property.
11357 * Returns: The left margin of @widget
11360 gtk_widget_get_margin_right (GtkWidget *widget)
11362 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11364 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11368 * gtk_widget_set_margin_right:
11369 * @widget: a #GtkWidget
11370 * @margin: the right margin
11372 * Sets the right margin of @widget.
11373 * See the #GtkWidget:margin-right property.
11376 gtk_widget_set_margin_right (GtkWidget *widget,
11379 GtkWidgetAuxInfo *aux_info;
11381 g_return_if_fail (GTK_IS_WIDGET (widget));
11382 g_return_if_fail (margin <= G_MAXINT16);
11384 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11386 if (aux_info->margin.right == margin)
11389 aux_info->margin.right = margin;
11390 gtk_widget_queue_resize (widget);
11391 g_object_notify (G_OBJECT (widget), "margin-right");
11395 * gtk_widget_get_margin_top:
11396 * @widget: a #GtkWidget
11398 * Gets the value of the #GtkWidget:margin-top property.
11400 * Returns: The top margin of @widget
11403 gtk_widget_get_margin_top (GtkWidget *widget)
11405 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11407 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11411 * gtk_widget_set_margin_top:
11412 * @widget: a #GtkWidget
11413 * @margin: the top margin
11415 * Sets the top margin of @widget.
11416 * See the #GtkWidget:margin-top property.
11419 gtk_widget_set_margin_top (GtkWidget *widget,
11422 GtkWidgetAuxInfo *aux_info;
11424 g_return_if_fail (GTK_IS_WIDGET (widget));
11425 g_return_if_fail (margin <= G_MAXINT16);
11427 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11429 if (aux_info->margin.top == margin)
11432 aux_info->margin.top = margin;
11433 gtk_widget_queue_resize (widget);
11434 g_object_notify (G_OBJECT (widget), "margin-top");
11438 * gtk_widget_get_margin_bottom:
11439 * @widget: a #GtkWidget
11441 * Gets the value of the #GtkWidget:margin-bottom property.
11443 * Returns: The bottom margin of @widget
11446 gtk_widget_get_margin_bottom (GtkWidget *widget)
11448 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11450 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11454 * gtk_widget_set_margin_bottom:
11455 * @widget: a #GtkWidget
11456 * @margin: the bottom margin
11458 * Sets the bottom margin of @widget.
11459 * See the #GtkWidget:margin-bottom property.
11462 gtk_widget_set_margin_bottom (GtkWidget *widget,
11465 GtkWidgetAuxInfo *aux_info;
11467 g_return_if_fail (GTK_IS_WIDGET (widget));
11468 g_return_if_fail (margin <= G_MAXINT16);
11470 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11472 if (aux_info->margin.bottom == margin)
11475 aux_info->margin.bottom = margin;
11476 gtk_widget_queue_resize (widget);
11477 g_object_notify (G_OBJECT (widget), "margin-bottom");
11481 * gtk_widget_get_clipboard:
11482 * @widget: a #GtkWidget
11483 * @selection: a #GdkAtom which identifies the clipboard
11484 * to use. %GDK_SELECTION_CLIPBOARD gives the
11485 * default clipboard. Another common value
11486 * is %GDK_SELECTION_PRIMARY, which gives
11487 * the primary X selection.
11489 * Returns the clipboard object for the given selection to
11490 * be used with @widget. @widget must have a #GdkDisplay
11491 * associated with it, so must be attached to a toplevel
11494 * Return value: (transfer none): the appropriate clipboard object. If no
11495 * clipboard already exists, a new one will
11496 * be created. Once a clipboard object has
11497 * been created, it is persistent for all time.
11502 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11504 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11505 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11507 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11512 * gtk_widget_list_mnemonic_labels:
11513 * @widget: a #GtkWidget
11515 * Returns a newly allocated list of the widgets, normally labels, for
11516 * which this widget is the target of a mnemonic (see for example,
11517 * gtk_label_set_mnemonic_widget()).
11519 * The widgets in the list are not individually referenced. If you
11520 * want to iterate through the list and perform actions involving
11521 * callbacks that might destroy the widgets, you
11522 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11523 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11524 * widgets afterwards.
11526 * Return value: (element-type GtkWidget) (transfer container): the list of
11527 * mnemonic labels; free this list
11528 * with g_list_free() when you are done with it.
11533 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11535 GList *list = NULL;
11538 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11540 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11541 list = g_list_prepend (list, l->data);
11547 * gtk_widget_add_mnemonic_label:
11548 * @widget: a #GtkWidget
11549 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11551 * Adds a widget to the list of mnemonic labels for
11552 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11553 * list of mnemonic labels for the widget is cleared when the
11554 * widget is destroyed, so the caller must make sure to update
11555 * its internal state at this point as well, by using a connection
11556 * to the #GtkWidget::destroy signal or a weak notifier.
11561 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11564 GSList *old_list, *new_list;
11566 g_return_if_fail (GTK_IS_WIDGET (widget));
11567 g_return_if_fail (GTK_IS_WIDGET (label));
11569 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11570 new_list = g_slist_prepend (old_list, label);
11572 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11573 new_list, (GDestroyNotify) g_slist_free);
11577 * gtk_widget_remove_mnemonic_label:
11578 * @widget: a #GtkWidget
11579 * @label: a #GtkWidget that was previously set as a mnemnic label for
11580 * @widget with gtk_widget_add_mnemonic_label().
11582 * Removes a widget from the list of mnemonic labels for
11583 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11584 * must have previously been added to the list with
11585 * gtk_widget_add_mnemonic_label().
11590 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11593 GSList *old_list, *new_list;
11595 g_return_if_fail (GTK_IS_WIDGET (widget));
11596 g_return_if_fail (GTK_IS_WIDGET (label));
11598 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11599 new_list = g_slist_remove (old_list, label);
11602 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11603 new_list, (GDestroyNotify) g_slist_free);
11607 * gtk_widget_get_no_show_all:
11608 * @widget: a #GtkWidget
11610 * Returns the current value of the GtkWidget:no-show-all property,
11611 * which determines whether calls to gtk_widget_show_all() and
11612 * gtk_widget_hide_all() will affect this widget.
11614 * Return value: the current value of the "no-show-all" property.
11619 gtk_widget_get_no_show_all (GtkWidget *widget)
11621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11623 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11627 * gtk_widget_set_no_show_all:
11628 * @widget: a #GtkWidget
11629 * @no_show_all: the new value for the "no-show-all" property
11631 * Sets the #GtkWidget:no-show-all property, which determines whether
11632 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11635 * This is mostly for use in constructing widget hierarchies with externally
11636 * controlled visibility, see #GtkUIManager.
11641 gtk_widget_set_no_show_all (GtkWidget *widget,
11642 gboolean no_show_all)
11644 g_return_if_fail (GTK_IS_WIDGET (widget));
11646 no_show_all = (no_show_all != FALSE);
11648 if (no_show_all == gtk_widget_get_no_show_all (widget))
11652 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11654 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11656 g_object_notify (G_OBJECT (widget), "no-show-all");
11661 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11662 gboolean has_tooltip,
11665 GtkWidgetPrivate *priv = widget->priv;
11666 gboolean priv_has_tooltip;
11668 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11669 quark_has_tooltip));
11671 if (priv_has_tooltip != has_tooltip || force)
11673 priv_has_tooltip = has_tooltip;
11675 if (priv_has_tooltip)
11677 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11678 gdk_window_set_events (priv->window,
11679 gdk_window_get_events (priv->window) |
11680 GDK_LEAVE_NOTIFY_MASK |
11681 GDK_POINTER_MOTION_MASK |
11682 GDK_POINTER_MOTION_HINT_MASK);
11684 if (gtk_widget_get_has_window (widget))
11685 gtk_widget_add_events (widget,
11686 GDK_LEAVE_NOTIFY_MASK |
11687 GDK_POINTER_MOTION_MASK |
11688 GDK_POINTER_MOTION_HINT_MASK);
11691 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11692 GUINT_TO_POINTER (priv_has_tooltip));
11697 * gtk_widget_set_tooltip_window:
11698 * @widget: a #GtkWidget
11699 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11701 * Replaces the default, usually yellow, window used for displaying
11702 * tooltips with @custom_window. GTK+ will take care of showing and
11703 * hiding @custom_window at the right moment, to behave likewise as
11704 * the default tooltip window. If @custom_window is %NULL, the default
11705 * tooltip window will be used.
11707 * If the custom window should have the default theming it needs to
11708 * have the name "gtk-tooltip", see gtk_widget_set_name().
11713 gtk_widget_set_tooltip_window (GtkWidget *widget,
11714 GtkWindow *custom_window)
11716 gboolean has_tooltip;
11717 gchar *tooltip_markup;
11719 g_return_if_fail (GTK_IS_WIDGET (widget));
11720 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11722 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11725 g_object_ref (custom_window);
11727 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11728 custom_window, g_object_unref);
11730 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11731 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11733 if (has_tooltip && gtk_widget_get_visible (widget))
11734 gtk_widget_queue_tooltip_query (widget);
11738 * gtk_widget_get_tooltip_window:
11739 * @widget: a #GtkWidget
11741 * Returns the #GtkWindow of the current tooltip. This can be the
11742 * GtkWindow created by default, or the custom tooltip window set
11743 * using gtk_widget_set_tooltip_window().
11745 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11750 gtk_widget_get_tooltip_window (GtkWidget *widget)
11752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11754 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11758 * gtk_widget_trigger_tooltip_query:
11759 * @widget: a #GtkWidget
11761 * Triggers a tooltip query on the display where the toplevel of @widget
11762 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11768 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11770 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11773 static guint tooltip_query_id;
11774 static GSList *tooltip_query_displays;
11777 tooltip_query_idle (gpointer data)
11779 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11780 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11781 g_slist_free (tooltip_query_displays);
11783 tooltip_query_displays = NULL;
11784 tooltip_query_id = 0;
11790 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11792 GdkDisplay *display;
11794 display = gtk_widget_get_display (widget);
11796 if (!g_slist_find (tooltip_query_displays, display))
11797 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11799 if (tooltip_query_id == 0)
11800 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11804 * gtk_widget_set_tooltip_text:
11805 * @widget: a #GtkWidget
11806 * @text: the contents of the tooltip for @widget
11808 * Sets @text as the contents of the tooltip. This function will take
11809 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11810 * handler for the GtkWidget::query-tooltip signal.
11812 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11817 gtk_widget_set_tooltip_text (GtkWidget *widget,
11820 g_return_if_fail (GTK_IS_WIDGET (widget));
11822 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11826 * gtk_widget_get_tooltip_text:
11827 * @widget: a #GtkWidget
11829 * Gets the contents of the tooltip for @widget.
11831 * Return value: the tooltip text, or %NULL. You should free the
11832 * returned string with g_free() when done.
11837 gtk_widget_get_tooltip_text (GtkWidget *widget)
11839 gchar *text = NULL;
11841 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11843 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11849 * gtk_widget_set_tooltip_markup:
11850 * @widget: a #GtkWidget
11851 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11853 * Sets @markup as the contents of the tooltip, which is marked up with
11854 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11856 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11857 * and of the default handler for the GtkWidget::query-tooltip signal.
11859 * See also the GtkWidget:tooltip-markup property and
11860 * gtk_tooltip_set_markup().
11865 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11866 const gchar *markup)
11868 g_return_if_fail (GTK_IS_WIDGET (widget));
11870 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11874 * gtk_widget_get_tooltip_markup:
11875 * @widget: a #GtkWidget
11877 * Gets the contents of the tooltip for @widget.
11879 * Return value: the tooltip text, or %NULL. You should free the
11880 * returned string with g_free() when done.
11885 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11887 gchar *text = NULL;
11889 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11891 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11897 * gtk_widget_set_has_tooltip:
11898 * @widget: a #GtkWidget
11899 * @has_tooltip: whether or not @widget has a tooltip.
11901 * Sets the has-tooltip property on @widget to @has_tooltip. See
11902 * GtkWidget:has-tooltip for more information.
11907 gtk_widget_set_has_tooltip (GtkWidget *widget,
11908 gboolean has_tooltip)
11910 g_return_if_fail (GTK_IS_WIDGET (widget));
11912 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11916 * gtk_widget_get_has_tooltip:
11917 * @widget: a #GtkWidget
11919 * Returns the current value of the has-tooltip property. See
11920 * GtkWidget:has-tooltip for more information.
11922 * Return value: current value of has-tooltip on @widget.
11927 gtk_widget_get_has_tooltip (GtkWidget *widget)
11929 gboolean has_tooltip = FALSE;
11931 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11933 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11935 return has_tooltip;
11939 * gtk_widget_get_allocation:
11940 * @widget: a #GtkWidget
11941 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11943 * Retrieves the widget's allocation.
11945 * Note, when implementing a #GtkContainer: a widget's allocation will
11946 * be its "adjusted" allocation, that is, the widget's parent
11947 * container typically calls gtk_widget_size_allocate() with an
11948 * allocation, and that allocation is then adjusted (to handle margin
11949 * and alignment for example) before assignment to the widget.
11950 * gtk_widget_get_allocation() returns the adjusted allocation that
11951 * was actually assigned to the widget. The adjusted allocation is
11952 * guaranteed to be completely contained within the
11953 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11954 * is guaranteed that its children stay inside the assigned bounds,
11955 * but not that they have exactly the bounds the container assigned.
11956 * There is no way to get the original allocation assigned by
11957 * gtk_widget_size_allocate(), since it isn't stored; if a container
11958 * implementation needs that information it will have to track it itself.
11963 gtk_widget_get_allocation (GtkWidget *widget,
11964 GtkAllocation *allocation)
11966 GtkWidgetPrivate *priv;
11968 g_return_if_fail (GTK_IS_WIDGET (widget));
11969 g_return_if_fail (allocation != NULL);
11971 priv = widget->priv;
11973 *allocation = priv->allocation;
11977 * gtk_widget_set_allocation:
11978 * @widget: a #GtkWidget
11979 * @allocation: a pointer to a #GtkAllocation to copy from
11981 * Sets the widget's allocation. This should not be used
11982 * directly, but from within a widget's size_allocate method.
11984 * The allocation set should be the "adjusted" or actual
11985 * allocation. If you're implementing a #GtkContainer, you want to use
11986 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
11987 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
11988 * allocation inside gtk_widget_size_allocate() to create an adjusted
11994 gtk_widget_set_allocation (GtkWidget *widget,
11995 const GtkAllocation *allocation)
11997 GtkWidgetPrivate *priv;
11999 g_return_if_fail (GTK_IS_WIDGET (widget));
12000 g_return_if_fail (allocation != NULL);
12002 priv = widget->priv;
12004 priv->allocation = *allocation;
12008 * gtk_widget_get_requisition:
12009 * @widget: a #GtkWidget
12010 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12012 * Retrieves the widget's requisition.
12014 * This function should only be used by widget implementations in
12015 * order to figure whether the widget's requisition has actually
12016 * changed after some internal state change (so that they can call
12017 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12019 * Normally, gtk_widget_size_request() should be used.
12023 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12024 * removed, If you need to cache sizes across requests and allocations,
12025 * add an explicit cache to the widget in question instead.
12028 gtk_widget_get_requisition (GtkWidget *widget,
12029 GtkRequisition *requisition)
12031 g_return_if_fail (GTK_IS_WIDGET (widget));
12032 g_return_if_fail (requisition != NULL);
12034 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12038 * gtk_widget_set_window:
12039 * @widget: a #GtkWidget
12040 * @window: a #GdkWindow
12042 * Sets a widget's window. This function should only be used in a
12043 * widget's GtkWidget::realize() implementation. The %window passed is
12044 * usually either new window created with gdk_window_new(), or the
12045 * window of its parent widget as returned by
12046 * gtk_widget_get_parent_window().
12048 * Widgets must indicate whether they will create their own #GdkWindow
12049 * by calling gtk_widget_set_has_window(). This is usually done in the
12050 * widget's init() function.
12052 * <note><para>This function does not add any reference to @window.</para></note>
12057 gtk_widget_set_window (GtkWidget *widget,
12060 GtkWidgetPrivate *priv;
12062 g_return_if_fail (GTK_IS_WIDGET (widget));
12063 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12065 priv = widget->priv;
12067 if (priv->window != window)
12069 priv->window = window;
12070 g_object_notify (G_OBJECT (widget), "window");
12075 * gtk_widget_get_window:
12076 * @widget: a #GtkWidget
12078 * Returns the widget's window if it is realized, %NULL otherwise
12080 * Return value: (transfer none): @widget's window.
12085 gtk_widget_get_window (GtkWidget *widget)
12087 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12089 return widget->priv->window;
12093 * gtk_widget_get_support_multidevice:
12094 * @widget: a #GtkWidget
12096 * Returns %TRUE if @widget is multiple pointer aware. See
12097 * gtk_widget_set_support_multidevice() for more information.
12099 * Returns: %TRUE is @widget is multidevice aware.
12102 gtk_widget_get_support_multidevice (GtkWidget *widget)
12104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12106 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12110 * gtk_widget_set_support_multidevice:
12111 * @widget: a #GtkWidget
12112 * @support_multidevice: %TRUE to support input from multiple devices.
12114 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12115 * @widget will start receiving multiple, per device enter/leave events. Note
12116 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12117 * gdk_window_set_support_multidevice() will have to be called manually on them.
12122 gtk_widget_set_support_multidevice (GtkWidget *widget,
12123 gboolean support_multidevice)
12125 GtkWidgetPrivate *priv;
12127 g_return_if_fail (GTK_IS_WIDGET (widget));
12129 priv = widget->priv;
12131 if (support_multidevice)
12133 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12134 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12138 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12139 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12142 if (gtk_widget_get_realized (widget))
12143 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12147 _gtk_widget_set_has_focus (GtkWidget *widget,
12148 gboolean has_focus)
12151 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12153 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12157 * gtk_widget_send_focus_change:
12158 * @widget: a #GtkWidget
12159 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12161 * Sends the focus change @event to @widget
12163 * This function is not meant to be used by applications. The only time it
12164 * should be used is when it is necessary for a #GtkWidget to assign focus
12165 * to a widget that is semantically owned by the first widget even though
12166 * it's not a direct child - for instance, a search entry in a floating
12167 * window similar to the quick search in #GtkTreeView.
12169 * An example of its usage is:
12172 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12174 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12175 * fevent->focus_change.in = TRUE;
12176 * fevent->focus_change.window = gtk_widget_get_window (widget);
12177 * if (fevent->focus_change.window != NULL)
12178 * g_object_ref (fevent->focus_change.window);
12180 * gtk_widget_send_focus_change (widget, fevent);
12182 * gdk_event_free (event);
12185 * Return value: the return value from the event signal emission: %TRUE
12186 * if the event was handled, and %FALSE otherwise
12191 gtk_widget_send_focus_change (GtkWidget *widget,
12196 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12197 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12199 g_object_ref (widget);
12201 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12203 res = gtk_widget_event (widget, event);
12205 g_object_notify (G_OBJECT (widget), "has-focus");
12207 g_object_unref (widget);