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 ("h-align",
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 ("v-align",
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_h_align (widget, g_value_get_enum (value));
2948 gtk_widget_set_v_align (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_h_align (widget));
3084 g_value_set_enum (value, gtk_widget_get_v_align (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 GtkWidgetShapeInfo *shape_info;
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 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3841 gdk_window_shape_combine_mask (priv->window,
3842 shape_info->shape_mask,
3843 shape_info->offset_x,
3844 shape_info->offset_y);
3847 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3849 gdk_window_input_shape_combine_mask (priv->window,
3850 shape_info->shape_mask,
3851 shape_info->offset_x,
3852 shape_info->offset_y);
3854 mode = gtk_widget_get_extension_events (widget);
3855 if (mode != GDK_EXTENSION_EVENTS_NONE)
3856 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3858 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3859 gdk_window_set_support_multidevice (priv->window, TRUE);
3861 _gtk_widget_enable_device_events (widget);
3866 * gtk_widget_unrealize:
3867 * @widget: a #GtkWidget
3869 * This function is only useful in widget implementations.
3870 * Causes a widget to be unrealized (frees all GDK resources
3871 * associated with the widget, such as @widget->window).
3874 gtk_widget_unrealize (GtkWidget *widget)
3876 g_return_if_fail (GTK_IS_WIDGET (widget));
3878 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3879 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3881 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3882 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3884 if (gtk_widget_get_realized (widget))
3886 g_object_ref (widget);
3887 _gtk_tooltip_hide (widget);
3888 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3889 gtk_widget_set_realized (widget, FALSE);
3890 gtk_widget_set_mapped (widget, FALSE);
3891 g_object_unref (widget);
3895 /*****************************************
3897 *****************************************/
3900 * gtk_widget_queue_draw_area:
3901 * @widget: a #GtkWidget
3902 * @x: x coordinate of upper-left corner of rectangle to redraw
3903 * @y: y coordinate of upper-left corner of rectangle to redraw
3904 * @width: width of region to draw
3905 * @height: height of region to draw
3907 * Invalidates the rectangular area of @widget defined by @x, @y,
3908 * @width and @height by calling gdk_window_invalidate_rect() on the
3909 * widget's window and all its child windows. Once the main loop
3910 * becomes idle (after the current batch of events has been processed,
3911 * roughly), the window will receive expose events for the union of
3912 * all regions that have been invalidated.
3914 * Normally you would only use this function in widget
3915 * implementations. You might also use it, or
3916 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3917 * #GtkDrawingArea or some portion thereof.
3919 * Frequently you can just call gdk_window_invalidate_rect() or
3920 * gdk_window_invalidate_region() instead of this function. Those
3921 * functions will invalidate only a single window, instead of the
3922 * widget and all its children.
3924 * The advantage of adding to the invalidated region compared to
3925 * simply drawing immediately is efficiency; using an invalid region
3926 * ensures that you only have to redraw one time.
3929 gtk_widget_queue_draw_area (GtkWidget *widget,
3935 GtkWidgetPrivate *priv;
3936 GdkRectangle invalid_rect;
3939 g_return_if_fail (GTK_IS_WIDGET (widget));
3941 priv = widget->priv;
3943 if (!gtk_widget_get_realized (widget))
3946 /* Just return if the widget or one of its ancestors isn't mapped */
3947 for (w = widget; w != NULL; w = w->priv->parent)
3948 if (!gtk_widget_get_mapped (w))
3951 /* Find the correct widget */
3953 if (gtk_widget_get_has_window (widget))
3957 /* Translate widget relative to window-relative */
3959 gint wx, wy, wwidth, wheight;
3961 gdk_window_get_position (priv->window, &wx, &wy);
3962 x -= wx - priv->allocation.x;
3963 y -= wy - priv->allocation.y;
3965 gdk_drawable_get_size (priv->window, &wwidth, &wheight);
3967 if (x + width <= 0 || y + height <= 0 ||
3968 x >= wwidth || y >= wheight)
3979 if (x + width > wwidth)
3981 if (y + height > wheight)
3982 height = wheight - y;
3988 invalid_rect.width = width;
3989 invalid_rect.height = height;
3991 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
3995 * gtk_widget_queue_draw:
3996 * @widget: a #GtkWidget
3998 * Equivalent to calling gtk_widget_queue_draw_area() for the
3999 * entire area of a widget.
4002 gtk_widget_queue_draw (GtkWidget *widget)
4006 g_return_if_fail (GTK_IS_WIDGET (widget));
4008 gtk_widget_get_allocation (widget, &rect);
4010 if (!gtk_widget_get_has_window (widget))
4011 gtk_widget_queue_draw_area (widget,
4012 rect.x, rect.y, rect.width, rect.height);
4014 gtk_widget_queue_draw_area (widget,
4015 0, 0, rect.width, rect.height);
4019 * gtk_widget_queue_resize:
4020 * @widget: a #GtkWidget
4022 * This function is only for use in widget implementations.
4023 * Flags a widget to have its size renegotiated; should
4024 * be called when a widget for some reason has a new size request.
4025 * For example, when you change the text in a #GtkLabel, #GtkLabel
4026 * queues a resize to ensure there's enough space for the new text.
4029 gtk_widget_queue_resize (GtkWidget *widget)
4031 g_return_if_fail (GTK_IS_WIDGET (widget));
4033 if (gtk_widget_get_realized (widget))
4034 gtk_widget_queue_shallow_draw (widget);
4036 _gtk_size_group_queue_resize (widget);
4040 * gtk_widget_queue_resize_no_redraw:
4041 * @widget: a #GtkWidget
4043 * This function works like gtk_widget_queue_resize(),
4044 * except that the widget is not invalidated.
4049 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4051 g_return_if_fail (GTK_IS_WIDGET (widget));
4053 _gtk_size_group_queue_resize (widget);
4057 * gtk_widget_size_request:
4058 * @widget: a #GtkWidget
4059 * @requisition: (out): a #GtkRequisition to be filled in
4061 * This function is typically used when implementing a #GtkContainer
4062 * subclass. Obtains the preferred size of a widget. The container
4063 * uses this information to arrange its child widgets and decide what
4064 * size allocations to give them with gtk_widget_size_allocate().
4066 * You can also call this function from an application, with some
4067 * caveats. Most notably, getting a size request requires the widget
4068 * to be associated with a screen, because font information may be
4069 * needed. Multihead-aware applications should keep this in mind.
4071 * Also remember that the size request is not necessarily the size
4072 * a widget will actually be allocated.
4074 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4077 gtk_widget_size_request (GtkWidget *widget,
4078 GtkRequisition *requisition)
4080 g_return_if_fail (GTK_IS_WIDGET (widget));
4082 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4086 * gtk_widget_get_child_requisition:
4087 * @widget: a #GtkWidget
4088 * @requisition: (out): a #GtkRequisition to be filled in
4090 * This function is only for use in widget implementations. Obtains
4091 * @widget->requisition, unless someone has forced a particular
4092 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4093 * in which case it returns that geometry instead of the widget's
4096 * This function differs from gtk_widget_size_request() in that
4097 * it retrieves the last size request value from @widget->requisition,
4098 * while gtk_widget_size_request() actually calls the "size_request" method
4099 * on @widget to compute the size request and fill in @widget->requisition,
4100 * and only then returns @widget->requisition.
4102 * Because this function does not call the "size_request" method, it
4103 * can only be used when you know that @widget->requisition is
4104 * up-to-date, that is, gtk_widget_size_request() has been called
4105 * since the last time a resize was queued. In general, only container
4106 * implementations have this information; applications should use
4107 * gtk_widget_size_request().
4110 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4113 gtk_widget_get_child_requisition (GtkWidget *widget,
4114 GtkRequisition *requisition)
4116 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4120 invalidate_predicate (GdkWindow *window,
4125 gdk_window_get_user_data (window, &user_data);
4127 return (user_data == data);
4130 /* Invalidate @region in widget->window and all children
4131 * of widget->window owned by widget. @region is in the
4132 * same coordinates as widget->allocation and will be
4133 * modified by this call.
4136 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4137 cairo_region_t *region)
4139 GtkWidgetPrivate *priv = widget->priv;
4141 if (!gtk_widget_get_realized (widget))
4144 if (gtk_widget_get_has_window (widget) && priv->parent)
4148 gdk_window_get_position (priv->window, &x, &y);
4149 cairo_region_translate (region, -x, -y);
4152 gdk_window_invalidate_maybe_recurse (priv->window, region,
4153 invalidate_predicate, widget);
4157 * gtk_widget_queue_shallow_draw:
4158 * @widget: a #GtkWidget
4160 * Like gtk_widget_queue_draw(), but only windows owned
4161 * by @widget are invalidated.
4164 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4167 cairo_region_t *region;
4169 if (!gtk_widget_get_realized (widget))
4172 gtk_widget_get_allocation (widget, &rect);
4174 region = cairo_region_create_rectangle (&rect);
4175 gtk_widget_invalidate_widget_windows (widget, region);
4176 cairo_region_destroy (region);
4180 * gtk_widget_size_allocate:
4181 * @widget: a #GtkWidget
4182 * @allocation: (inout): position and size to be allocated to @widget
4184 * This function is only used by #GtkContainer subclasses, to assign a size
4185 * and position to their child widgets.
4187 * In this function, the allocation may be adjusted. It will be forced
4188 * to a 1x1 minimum size, and the adjust_size_allocation virtual method
4189 * on the child will be used to adjust the allocation.
4192 gtk_widget_size_allocate (GtkWidget *widget,
4193 GtkAllocation *allocation)
4195 GtkWidgetPrivate *priv;
4196 GdkRectangle real_allocation;
4197 GdkRectangle old_allocation;
4198 GdkRectangle adjusted_allocation;
4199 gboolean alloc_needed;
4200 gboolean size_changed;
4201 gboolean position_changed;
4203 priv = widget->priv;
4205 g_return_if_fail (GTK_IS_WIDGET (widget));
4207 #ifdef G_ENABLE_DEBUG
4208 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4219 parent = gtk_widget_get_parent (parent);
4222 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4223 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4224 2 * depth, " ", name,
4225 allocation->width, allocation->height);
4227 #endif /* G_ENABLE_DEBUG */
4229 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4230 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4231 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4232 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4234 old_allocation = priv->allocation;
4235 real_allocation = *allocation;
4237 adjusted_allocation = real_allocation;
4238 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4240 if (adjusted_allocation.x < real_allocation.x ||
4241 adjusted_allocation.y < real_allocation.y ||
4242 (adjusted_allocation.x + adjusted_allocation.width) >
4243 (real_allocation.x + real_allocation.width) ||
4244 (adjusted_allocation.y + adjusted_allocation.height >
4245 real_allocation.y + real_allocation.height))
4247 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",
4248 G_OBJECT_TYPE_NAME (widget), widget,
4249 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4250 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4251 adjusted_allocation = real_allocation; /* veto it */
4255 real_allocation = adjusted_allocation;
4258 if (real_allocation.width < 0 || real_allocation.height < 0)
4260 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4261 real_allocation.width,
4262 real_allocation.height);
4265 real_allocation.width = MAX (real_allocation.width, 1);
4266 real_allocation.height = MAX (real_allocation.height, 1);
4268 size_changed = (old_allocation.width != real_allocation.width ||
4269 old_allocation.height != real_allocation.height);
4270 position_changed = (old_allocation.x != real_allocation.x ||
4271 old_allocation.y != real_allocation.y);
4273 if (!alloc_needed && !size_changed && !position_changed)
4276 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4278 if (gtk_widget_get_mapped (widget))
4280 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4282 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4284 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4285 cairo_region_union_rectangle (invalidate, &old_allocation);
4287 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4288 cairo_region_destroy (invalidate);
4293 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4295 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4297 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4298 cairo_region_union_rectangle (invalidate, &old_allocation);
4300 gtk_widget_invalidate_widget_windows (widget, invalidate);
4301 cairo_region_destroy (invalidate);
4306 if ((size_changed || position_changed) && priv->parent &&
4307 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4309 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4310 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4311 cairo_region_destroy (invalidate);
4316 * gtk_widget_common_ancestor:
4317 * @widget_a: a #GtkWidget
4318 * @widget_b: a #GtkWidget
4320 * Find the common ancestor of @widget_a and @widget_b that
4321 * is closest to the two widgets.
4323 * Return value: the closest common ancestor of @widget_a and
4324 * @widget_b or %NULL if @widget_a and @widget_b do not
4325 * share a common ancestor.
4328 gtk_widget_common_ancestor (GtkWidget *widget_a,
4329 GtkWidget *widget_b)
4331 GtkWidget *parent_a;
4332 GtkWidget *parent_b;
4336 parent_a = widget_a;
4337 while (parent_a->priv->parent)
4339 parent_a = parent_a->priv->parent;
4343 parent_b = widget_b;
4344 while (parent_b->priv->parent)
4346 parent_b = parent_b->priv->parent;
4350 if (parent_a != parent_b)
4353 while (depth_a > depth_b)
4355 widget_a = widget_a->priv->parent;
4359 while (depth_b > depth_a)
4361 widget_b = widget_b->priv->parent;
4365 while (widget_a != widget_b)
4367 widget_a = widget_a->priv->parent;
4368 widget_b = widget_b->priv->parent;
4375 * gtk_widget_translate_coordinates:
4376 * @src_widget: a #GtkWidget
4377 * @dest_widget: a #GtkWidget
4378 * @src_x: X position relative to @src_widget
4379 * @src_y: Y position relative to @src_widget
4380 * @dest_x: (out): location to store X position relative to @dest_widget
4381 * @dest_y: (out): location to store Y position relative to @dest_widget
4383 * Translate coordinates relative to @src_widget's allocation to coordinates
4384 * relative to @dest_widget's allocations. In order to perform this
4385 * operation, both widgets must be realized, and must share a common
4388 * Return value: %FALSE if either widget was not realized, or there
4389 * was no common ancestor. In this case, nothing is stored in
4390 * *@dest_x and *@dest_y. Otherwise %TRUE.
4393 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4394 GtkWidget *dest_widget,
4400 GtkWidgetPrivate *src_priv = src_widget->priv;
4401 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4402 GtkWidget *ancestor;
4404 GList *dest_list = NULL;
4406 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4407 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4409 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4410 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4413 /* Translate from allocation relative to window relative */
4414 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4417 gdk_window_get_position (src_priv->window, &wx, &wy);
4419 src_x -= wx - src_priv->allocation.x;
4420 src_y -= wy - src_priv->allocation.y;
4424 src_x += src_priv->allocation.x;
4425 src_y += src_priv->allocation.y;
4428 /* Translate to the common ancestor */
4429 window = src_priv->window;
4430 while (window != ancestor->priv->window)
4434 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4439 window = gdk_window_get_effective_parent (window);
4441 if (!window) /* Handle GtkHandleBox */
4446 window = dest_priv->window;
4447 while (window != ancestor->priv->window)
4449 dest_list = g_list_prepend (dest_list, window);
4451 window = gdk_window_get_effective_parent (window);
4453 if (!window) /* Handle GtkHandleBox */
4455 g_list_free (dest_list);
4464 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4469 dest_list = g_list_remove (dest_list, dest_list->data);
4472 /* Translate from window relative to allocation relative */
4473 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4476 gdk_window_get_position (dest_priv->window, &wx, &wy);
4478 src_x += wx - dest_priv->allocation.x;
4479 src_y += wy - dest_priv->allocation.y;
4483 src_x -= dest_priv->allocation.x;
4484 src_y -= dest_priv->allocation.y;
4496 gtk_widget_real_size_allocate (GtkWidget *widget,
4497 GtkAllocation *allocation)
4499 GtkWidgetPrivate *priv = widget->priv;
4501 priv->allocation = *allocation;
4503 if (gtk_widget_get_realized (widget) &&
4504 gtk_widget_get_has_window (widget))
4506 gdk_window_move_resize (priv->window,
4507 allocation->x, allocation->y,
4508 allocation->width, allocation->height);
4513 get_span_inside_border (GtkWidget *widget,
4517 int allocated_outside_size,
4518 int natural_inside_size,
4519 int *coord_inside_p,
4522 int inside_allocated;
4526 inside_allocated = allocated_outside_size - start_pad - end_pad;
4528 content_size = natural_inside_size;
4529 if (content_size > inside_allocated)
4531 /* didn't get full natural size */
4532 content_size = inside_allocated;
4535 coord = size = 0; /* silence compiler */
4538 case GTK_ALIGN_FILL:
4540 size = inside_allocated;
4542 case GTK_ALIGN_START:
4544 size = content_size;
4547 coord = allocated_outside_size - end_pad - content_size;
4548 size = content_size;
4550 case GTK_ALIGN_CENTER:
4551 coord = start_pad + (inside_allocated - content_size) / 2;
4552 size = content_size;
4557 *coord_inside_p = coord;
4560 *size_inside_p = size;
4564 get_span_inside_border_horizontal (GtkWidget *widget,
4565 const GtkWidgetAuxInfo *aux_info,
4566 int allocated_outside_width,
4567 int natural_inside_width,
4569 int *width_inside_p)
4571 get_span_inside_border (widget,
4573 aux_info->margin.left,
4574 aux_info->margin.right,
4575 allocated_outside_width,
4576 natural_inside_width,
4582 get_span_inside_border_vertical (GtkWidget *widget,
4583 const GtkWidgetAuxInfo *aux_info,
4584 int allocated_outside_height,
4585 int natural_inside_height,
4587 int *height_inside_p)
4589 get_span_inside_border (widget,
4591 aux_info->margin.top,
4592 aux_info->margin.bottom,
4593 allocated_outside_height,
4594 natural_inside_height,
4600 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4601 GtkAllocation *allocation)
4603 const GtkWidgetAuxInfo *aux_info;
4604 GtkRequisition min, natural;
4607 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4609 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &min, &natural);
4611 get_span_inside_border_horizontal (widget,
4616 get_span_inside_border_vertical (widget,
4624 allocation->width = w;
4625 allocation->height = h;
4629 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4632 GtkWidgetPrivate *priv = widget->priv;
4634 /* widgets must be onscreen for accels to take effect */
4635 return gtk_widget_is_sensitive (widget) &&
4636 gtk_widget_is_drawable (widget) &&
4637 gdk_window_is_viewable (priv->window);
4641 * gtk_widget_can_activate_accel:
4642 * @widget: a #GtkWidget
4643 * @signal_id: the ID of a signal installed on @widget
4645 * Determines whether an accelerator that activates the signal
4646 * identified by @signal_id can currently be activated.
4647 * This is done by emitting the #GtkWidget::can-activate-accel
4648 * signal on @widget; if the signal isn't overridden by a
4649 * handler or in a derived widget, then the default check is
4650 * that the widget must be sensitive, and the widget and all
4651 * its ancestors mapped.
4653 * Return value: %TRUE if the accelerator can be activated.
4658 gtk_widget_can_activate_accel (GtkWidget *widget,
4661 gboolean can_activate = FALSE;
4662 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4663 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4664 return can_activate;
4673 closure_accel_activate (GClosure *closure,
4674 GValue *return_value,
4675 guint n_param_values,
4676 const GValue *param_values,
4677 gpointer invocation_hint,
4678 gpointer marshal_data)
4680 AccelClosure *aclosure = (AccelClosure*) closure;
4681 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4684 g_signal_emit (closure->data, aclosure->signal_id, 0);
4686 /* whether accelerator was handled */
4687 g_value_set_boolean (return_value, can_activate);
4691 closures_destroy (gpointer data)
4693 GSList *slist, *closures = data;
4695 for (slist = closures; slist; slist = slist->next)
4697 g_closure_invalidate (slist->data);
4698 g_closure_unref (slist->data);
4700 g_slist_free (closures);
4704 widget_new_accel_closure (GtkWidget *widget,
4707 AccelClosure *aclosure;
4708 GClosure *closure = NULL;
4709 GSList *slist, *closures;
4711 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4712 for (slist = closures; slist; slist = slist->next)
4713 if (!gtk_accel_group_from_accel_closure (slist->data))
4715 /* reuse this closure */
4716 closure = slist->data;
4721 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4722 closures = g_slist_prepend (closures, g_closure_ref (closure));
4723 g_closure_sink (closure);
4724 g_closure_set_marshal (closure, closure_accel_activate);
4726 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4728 aclosure = (AccelClosure*) closure;
4729 g_assert (closure->data == widget);
4730 g_assert (closure->marshal == closure_accel_activate);
4731 aclosure->signal_id = signal_id;
4737 * gtk_widget_add_accelerator
4738 * @widget: widget to install an accelerator on
4739 * @accel_signal: widget signal to emit on accelerator activation
4740 * @accel_group: accel group for this widget, added to its toplevel
4741 * @accel_key: GDK keyval of the accelerator
4742 * @accel_mods: modifier key combination of the accelerator
4743 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4745 * Installs an accelerator for this @widget in @accel_group that causes
4746 * @accel_signal to be emitted if the accelerator is activated.
4747 * The @accel_group needs to be added to the widget's toplevel via
4748 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4749 * Accelerators added through this function are not user changeable during
4750 * runtime. If you want to support accelerators that can be changed by the
4751 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4752 * gtk_menu_item_set_accel_path() instead.
4755 gtk_widget_add_accelerator (GtkWidget *widget,
4756 const gchar *accel_signal,
4757 GtkAccelGroup *accel_group,
4759 GdkModifierType accel_mods,
4760 GtkAccelFlags accel_flags)
4765 g_return_if_fail (GTK_IS_WIDGET (widget));
4766 g_return_if_fail (accel_signal != NULL);
4767 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4769 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4770 if (!query.signal_id ||
4771 !(query.signal_flags & G_SIGNAL_ACTION) ||
4772 query.return_type != G_TYPE_NONE ||
4775 /* hmm, should be elaborate enough */
4776 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4777 G_OBJECT_TYPE_NAME (widget), accel_signal);
4781 closure = widget_new_accel_closure (widget, query.signal_id);
4783 g_object_ref (widget);
4785 /* install the accelerator. since we don't map this onto an accel_path,
4786 * the accelerator will automatically be locked.
4788 gtk_accel_group_connect (accel_group,
4791 accel_flags | GTK_ACCEL_LOCKED,
4794 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4796 g_object_unref (widget);
4800 * gtk_widget_remove_accelerator:
4801 * @widget: widget to install an accelerator on
4802 * @accel_group: accel group for this widget
4803 * @accel_key: GDK keyval of the accelerator
4804 * @accel_mods: modifier key combination of the accelerator
4805 * @returns: whether an accelerator was installed and could be removed
4807 * Removes an accelerator from @widget, previously installed with
4808 * gtk_widget_add_accelerator().
4811 gtk_widget_remove_accelerator (GtkWidget *widget,
4812 GtkAccelGroup *accel_group,
4814 GdkModifierType accel_mods)
4816 GtkAccelGroupEntry *ag_entry;
4817 GList *slist, *clist;
4820 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4821 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4823 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4824 clist = gtk_widget_list_accel_closures (widget);
4825 for (slist = clist; slist; slist = slist->next)
4829 for (i = 0; i < n; i++)
4830 if (slist->data == (gpointer) ag_entry[i].closure)
4832 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4834 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4836 g_list_free (clist);
4841 g_list_free (clist);
4843 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4844 accel_key, accel_mods, accel_group,
4845 G_OBJECT_TYPE_NAME (widget), widget);
4851 * gtk_widget_list_accel_closures
4852 * @widget: widget to list accelerator closures for
4853 * @returns: a newly allocated #GList of closures
4855 * Lists the closures used by @widget for accelerator group connections
4856 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4857 * The closures can be used to monitor accelerator changes on @widget,
4858 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4859 * #GtkAccelGroup of a closure which can be found out with
4860 * gtk_accel_group_from_accel_closure().
4863 gtk_widget_list_accel_closures (GtkWidget *widget)
4866 GList *clist = NULL;
4868 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4870 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4871 if (gtk_accel_group_from_accel_closure (slist->data))
4872 clist = g_list_prepend (clist, slist->data);
4878 GtkAccelGroup *accel_group;
4883 destroy_accel_path (gpointer data)
4885 AccelPath *apath = data;
4887 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4889 /* closures_destroy takes care of unrefing the closure */
4890 g_object_unref (apath->accel_group);
4892 g_slice_free (AccelPath, apath);
4897 * gtk_widget_set_accel_path:
4898 * @widget: a #GtkWidget
4899 * @accel_path: (allow-none): path used to look up the accelerator
4900 * @accel_group: (allow-none): a #GtkAccelGroup.
4902 * Given an accelerator group, @accel_group, and an accelerator path,
4903 * @accel_path, sets up an accelerator in @accel_group so whenever the
4904 * key binding that is defined for @accel_path is pressed, @widget
4905 * will be activated. This removes any accelerators (for any
4906 * accelerator group) installed by previous calls to
4907 * gtk_widget_set_accel_path(). Associating accelerators with
4908 * paths allows them to be modified by the user and the modifications
4909 * to be saved for future use. (See gtk_accel_map_save().)
4911 * This function is a low level function that would most likely
4912 * be used by a menu creation system like #GtkUIManager. If you
4913 * use #GtkUIManager, setting up accelerator paths will be done
4916 * Even when you you aren't using #GtkUIManager, if you only want to
4917 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4918 * provides a somewhat more convenient interface.
4920 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4921 * pass a static string, you can save some memory by interning it first with
4922 * g_intern_static_string().
4925 gtk_widget_set_accel_path (GtkWidget *widget,
4926 const gchar *accel_path,
4927 GtkAccelGroup *accel_group)
4931 g_return_if_fail (GTK_IS_WIDGET (widget));
4932 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4936 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4937 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4939 gtk_accel_map_add_entry (accel_path, 0, 0);
4940 apath = g_slice_new (AccelPath);
4941 apath->accel_group = g_object_ref (accel_group);
4942 apath->path_quark = g_quark_from_string (accel_path);
4943 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4948 /* also removes possible old settings */
4949 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4952 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4954 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4958 _gtk_widget_get_accel_path (GtkWidget *widget,
4963 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4965 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4967 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4968 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4972 * gtk_widget_mnemonic_activate:
4973 * @widget: a #GtkWidget
4974 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4976 * Emits the #GtkWidget::mnemonic-activate signal.
4978 * The default handler for this signal activates the @widget if
4979 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4982 * Returns: %TRUE if the signal has been handled
4985 gtk_widget_mnemonic_activate (GtkWidget *widget,
4986 gboolean group_cycling)
4990 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4992 group_cycling = group_cycling != FALSE;
4993 if (!gtk_widget_is_sensitive (widget))
4996 g_signal_emit (widget,
4997 widget_signals[MNEMONIC_ACTIVATE],
5005 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5006 gboolean group_cycling)
5008 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5009 gtk_widget_activate (widget);
5010 else if (gtk_widget_get_can_focus (widget))
5011 gtk_widget_grab_focus (widget);
5014 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5015 G_OBJECT_TYPE_NAME (widget));
5016 gtk_widget_error_bell (widget);
5022 gtk_widget_real_key_press_event (GtkWidget *widget,
5025 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5029 gtk_widget_real_key_release_event (GtkWidget *widget,
5032 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5036 gtk_widget_real_focus_in_event (GtkWidget *widget,
5037 GdkEventFocus *event)
5039 gtk_widget_queue_shallow_draw (widget);
5045 gtk_widget_real_focus_out_event (GtkWidget *widget,
5046 GdkEventFocus *event)
5048 gtk_widget_queue_shallow_draw (widget);
5053 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5054 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5058 * @widget: a #GtkWidget
5059 * @event: a #GdkEvent
5061 * Rarely-used function. This function is used to emit
5062 * the event signals on a widget (those signals should never
5063 * be emitted without using this function to do so).
5064 * If you want to synthesize an event though, don't use this function;
5065 * instead, use gtk_main_do_event() so the event will behave as if
5066 * it were in the event queue. Don't synthesize expose events; instead,
5067 * use gdk_window_invalidate_rect() to invalidate a region of the
5070 * Return value: return from the event signal emission (%TRUE if
5071 * the event was handled)
5074 gtk_widget_event (GtkWidget *widget,
5077 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5078 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5080 if (event->type == GDK_EXPOSE)
5082 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5083 "the same effect, call gdk_window_invalidate_rect/region(), "
5084 "followed by gdk_window_process_updates().");
5088 return gtk_widget_event_internal (widget, event);
5093 * gtk_widget_send_expose:
5094 * @widget: a #GtkWidget
5095 * @event: a expose #GdkEvent
5097 * Very rarely-used function. This function is used to emit
5098 * an expose event signals on a widget. This function is not
5099 * normally used directly. The only time it is used is when
5100 * propagating an expose event to a child %NO_WINDOW widget, and
5101 * that is normally done using gtk_container_propagate_expose().
5103 * If you want to force an area of a window to be redrawn,
5104 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5105 * To cause the redraw to be done immediately, follow that call
5106 * with a call to gdk_window_process_updates().
5108 * Return value: return from the event signal emission (%TRUE if
5109 * the event was handled)
5112 gtk_widget_send_expose (GtkWidget *widget,
5115 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5116 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5117 g_return_val_if_fail (event != NULL, TRUE);
5118 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5120 return gtk_widget_event_internal (widget, event);
5124 event_window_is_still_viewable (GdkEvent *event)
5126 /* Some programs, such as gnome-theme-manager, fake widgets
5127 * into exposing onto a pixmap by sending expose events with
5128 * event->window pointing to a pixmap
5130 if (GDK_IS_PIXMAP (event->any.window))
5131 return event->type == GDK_EXPOSE;
5133 /* Check that we think the event's window is viewable before
5134 * delivering the event, to prevent suprises. We do this here
5135 * at the last moment, since the event may have been queued
5136 * up behind other events, held over a recursive main loop, etc.
5138 switch (event->type)
5141 case GDK_MOTION_NOTIFY:
5142 case GDK_BUTTON_PRESS:
5143 case GDK_2BUTTON_PRESS:
5144 case GDK_3BUTTON_PRESS:
5146 case GDK_ENTER_NOTIFY:
5147 case GDK_PROXIMITY_IN:
5149 return event->any.window && gdk_window_is_viewable (event->any.window);
5152 /* The following events are the second half of paired events;
5153 * we always deliver them to deal with widgets that clean up
5154 * on the second half.
5156 case GDK_BUTTON_RELEASE:
5157 case GDK_KEY_RELEASE:
5158 case GDK_LEAVE_NOTIFY:
5159 case GDK_PROXIMITY_OUT:
5163 /* Remaining events would make sense on an not-viewable window,
5164 * or don't have an associated window.
5171 gtk_widget_event_internal (GtkWidget *widget,
5174 gboolean return_val = FALSE;
5176 /* We check only once for is-still-visible; if someone
5177 * hides the window in on of the signals on the widget,
5178 * they are responsible for returning TRUE to terminate
5181 if (!event_window_is_still_viewable (event))
5184 g_object_ref (widget);
5186 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5187 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5192 switch (event->type)
5197 case GDK_BUTTON_PRESS:
5198 case GDK_2BUTTON_PRESS:
5199 case GDK_3BUTTON_PRESS:
5200 signal_num = BUTTON_PRESS_EVENT;
5203 signal_num = SCROLL_EVENT;
5205 case GDK_BUTTON_RELEASE:
5206 signal_num = BUTTON_RELEASE_EVENT;
5208 case GDK_MOTION_NOTIFY:
5209 signal_num = MOTION_NOTIFY_EVENT;
5212 signal_num = DELETE_EVENT;
5215 signal_num = DESTROY_EVENT;
5216 _gtk_tooltip_hide (widget);
5219 signal_num = KEY_PRESS_EVENT;
5221 case GDK_KEY_RELEASE:
5222 signal_num = KEY_RELEASE_EVENT;
5224 case GDK_ENTER_NOTIFY:
5225 signal_num = ENTER_NOTIFY_EVENT;
5227 case GDK_LEAVE_NOTIFY:
5228 signal_num = LEAVE_NOTIFY_EVENT;
5230 case GDK_FOCUS_CHANGE:
5231 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5232 if (event->focus_change.in)
5233 _gtk_tooltip_focus_in (widget);
5235 _gtk_tooltip_focus_out (widget);
5238 signal_num = CONFIGURE_EVENT;
5241 signal_num = MAP_EVENT;
5244 signal_num = UNMAP_EVENT;
5246 case GDK_WINDOW_STATE:
5247 signal_num = WINDOW_STATE_EVENT;
5249 case GDK_PROPERTY_NOTIFY:
5250 signal_num = PROPERTY_NOTIFY_EVENT;
5252 case GDK_SELECTION_CLEAR:
5253 signal_num = SELECTION_CLEAR_EVENT;
5255 case GDK_SELECTION_REQUEST:
5256 signal_num = SELECTION_REQUEST_EVENT;
5258 case GDK_SELECTION_NOTIFY:
5259 signal_num = SELECTION_NOTIFY_EVENT;
5261 case GDK_PROXIMITY_IN:
5262 signal_num = PROXIMITY_IN_EVENT;
5264 case GDK_PROXIMITY_OUT:
5265 signal_num = PROXIMITY_OUT_EVENT;
5268 signal_num = NO_EXPOSE_EVENT;
5270 case GDK_CLIENT_EVENT:
5271 signal_num = CLIENT_EVENT;
5274 signal_num = EXPOSE_EVENT;
5276 case GDK_VISIBILITY_NOTIFY:
5277 signal_num = VISIBILITY_NOTIFY_EVENT;
5279 case GDK_GRAB_BROKEN:
5280 signal_num = GRAB_BROKEN;
5283 signal_num = DAMAGE_EVENT;
5286 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5290 if (signal_num != -1)
5291 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5293 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5294 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5298 g_object_unref (widget);
5304 * gtk_widget_activate:
5305 * @widget: a #GtkWidget that's activatable
5307 * For widgets that can be "activated" (buttons, menu items, etc.)
5308 * this function activates them. Activation is what happens when you
5309 * press Enter on a widget during key navigation. If @widget isn't
5310 * activatable, the function returns %FALSE.
5312 * Return value: %TRUE if the widget was activatable
5315 gtk_widget_activate (GtkWidget *widget)
5317 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5319 if (WIDGET_CLASS (widget)->activate_signal)
5321 /* FIXME: we should eventually check the signals signature here */
5322 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5331 * gtk_widget_set_scroll_adjustments:
5332 * @widget: a #GtkWidget
5333 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5334 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5336 * For widgets that support scrolling, sets the scroll adjustments and
5337 * returns %TRUE. For widgets that don't support scrolling, does
5338 * nothing and returns %FALSE. Widgets that don't support scrolling
5339 * can be scrolled by placing them in a #GtkViewport, which does
5340 * support scrolling.
5342 * Return value: %TRUE if the widget supports scrolling
5345 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5346 GtkAdjustment *hadjustment,
5347 GtkAdjustment *vadjustment)
5352 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5355 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5357 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5359 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5363 g_signal_query (signal_id, &query);
5364 if (!query.signal_id ||
5365 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5366 query.return_type != G_TYPE_NONE ||
5367 query.n_params != 2 ||
5368 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5369 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5371 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5372 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5376 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5381 gtk_widget_reparent_subwindows (GtkWidget *widget,
5382 GdkWindow *new_window)
5384 GtkWidgetPrivate *priv = widget->priv;
5386 if (!gtk_widget_get_has_window (widget))
5388 GList *children = gdk_window_get_children (priv->window);
5391 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5393 GdkWindow *window = tmp_list->data;
5396 gdk_window_get_user_data (window, &child);
5397 while (child && child != widget)
5398 child = ((GtkWidget*) child)->priv->parent;
5401 gdk_window_reparent (window, new_window, 0, 0);
5404 g_list_free (children);
5409 GList *tmp_list, *children;
5411 parent = gdk_window_get_parent (priv->window);
5414 gdk_window_reparent (priv->window, new_window, 0, 0);
5417 children = gdk_window_get_children (parent);
5419 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5421 GdkWindow *window = tmp_list->data;
5424 gdk_window_get_user_data (window, &child);
5426 if (child == widget)
5427 gdk_window_reparent (window, new_window, 0, 0);
5430 g_list_free (children);
5436 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5437 gpointer client_data)
5439 GtkWidgetPrivate *priv = widget->priv;
5441 g_assert (client_data != NULL);
5443 if (!gtk_widget_get_has_window (widget))
5446 g_object_unref (priv->window);
5447 priv->window = (GdkWindow*) client_data;
5449 g_object_ref (priv->window);
5451 if (GTK_IS_CONTAINER (widget))
5452 gtk_container_forall (GTK_CONTAINER (widget),
5453 gtk_widget_reparent_fixup_child,
5459 * gtk_widget_reparent:
5460 * @widget: a #GtkWidget
5461 * @new_parent: a #GtkContainer to move the widget into
5463 * Moves a widget from one #GtkContainer to another, handling reference
5464 * count issues to avoid destroying the widget.
5467 gtk_widget_reparent (GtkWidget *widget,
5468 GtkWidget *new_parent)
5470 GtkWidgetPrivate *priv;
5472 g_return_if_fail (GTK_IS_WIDGET (widget));
5473 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5474 priv = widget->priv;
5475 g_return_if_fail (priv->parent != NULL);
5477 if (priv->parent != new_parent)
5479 /* First try to see if we can get away without unrealizing
5480 * the widget as we reparent it. if so we set a flag so
5481 * that gtk_widget_unparent doesn't unrealize widget
5483 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5484 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5486 g_object_ref (widget);
5487 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5488 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5489 g_object_unref (widget);
5491 if (GTK_WIDGET_IN_REPARENT (widget))
5493 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5495 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5496 gtk_widget_reparent_fixup_child (widget,
5497 gtk_widget_get_parent_window (widget));
5500 g_object_notify (G_OBJECT (widget), "parent");
5505 * gtk_widget_intersect:
5506 * @widget: a #GtkWidget
5507 * @area: a rectangle
5508 * @intersection: rectangle to store intersection of @widget and @area
5510 * Computes the intersection of a @widget's area and @area, storing
5511 * the intersection in @intersection, and returns %TRUE if there was
5512 * an intersection. @intersection may be %NULL if you're only
5513 * interested in whether there was an intersection.
5515 * Return value: %TRUE if there was an intersection
5518 gtk_widget_intersect (GtkWidget *widget,
5519 const GdkRectangle *area,
5520 GdkRectangle *intersection)
5522 GtkWidgetPrivate *priv;
5527 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5528 g_return_val_if_fail (area != NULL, FALSE);
5530 priv = widget->priv;
5533 dest = intersection;
5537 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5539 if (return_val && intersection && gtk_widget_get_has_window (widget))
5541 intersection->x -= priv->allocation.x;
5542 intersection->y -= priv->allocation.y;
5549 * gtk_widget_region_intersect:
5550 * @widget: a #GtkWidget
5551 * @region: a #cairo_region_t, in the same coordinate system as
5552 * @widget->allocation. That is, relative to @widget->window
5553 * for %NO_WINDOW widgets; relative to the parent window
5554 * of @widget->window for widgets with their own window.
5555 * @returns: A newly allocated region holding the intersection of @widget
5556 * and @region. The coordinates of the return value are
5557 * relative to @widget->window for %NO_WINDOW widgets, and
5558 * relative to the parent window of @widget->window for
5559 * widgets with their own window.
5561 * Computes the intersection of a @widget's area and @region, returning
5562 * the intersection. The result may be empty, use cairo_region_is_empty() to
5566 gtk_widget_region_intersect (GtkWidget *widget,
5567 const cairo_region_t *region)
5570 cairo_region_t *dest;
5572 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5573 g_return_val_if_fail (region != NULL, NULL);
5575 gtk_widget_get_allocation (widget, &rect);
5577 dest = cairo_region_create_rectangle (&rect);
5579 cairo_region_intersect (dest, region);
5585 * _gtk_widget_grab_notify:
5586 * @widget: a #GtkWidget
5587 * @was_grabbed: whether a grab is now in effect
5589 * Emits the #GtkWidget::grab-notify signal on @widget.
5594 _gtk_widget_grab_notify (GtkWidget *widget,
5595 gboolean was_grabbed)
5597 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5601 * gtk_widget_grab_focus:
5602 * @widget: a #GtkWidget
5604 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5605 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5606 * something like #GtkFrame won't work.
5608 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5609 * gtk_widget_set_can_focus() to modify that flag.
5611 * The widget also needs to be realized and mapped. This is indicated by the
5612 * related signals. Grabbing the focus immediately after creating the widget
5613 * will likely fail and cause critical warnings.
5616 gtk_widget_grab_focus (GtkWidget *widget)
5618 g_return_if_fail (GTK_IS_WIDGET (widget));
5620 if (!gtk_widget_is_sensitive (widget))
5623 g_object_ref (widget);
5624 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5625 g_object_notify (G_OBJECT (widget), "has-focus");
5626 g_object_unref (widget);
5630 reset_focus_recurse (GtkWidget *widget,
5633 if (GTK_IS_CONTAINER (widget))
5635 GtkContainer *container;
5637 container = GTK_CONTAINER (widget);
5638 gtk_container_set_focus_child (container, NULL);
5640 gtk_container_foreach (container,
5641 reset_focus_recurse,
5647 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5649 if (gtk_widget_get_can_focus (focus_widget))
5651 GtkWidget *toplevel;
5654 /* clear the current focus setting, break if the current widget
5655 * is the focus widget's parent, since containers above that will
5656 * be set by the next loop.
5658 toplevel = gtk_widget_get_toplevel (focus_widget);
5659 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5661 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5663 if (widget == focus_widget)
5665 /* We call _gtk_window_internal_set_focus() here so that the
5666 * toplevel window can request the focus if necessary.
5667 * This is needed when the toplevel is a GtkPlug
5669 if (!gtk_widget_has_focus (widget))
5670 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5677 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5679 widget = widget->priv->parent;
5680 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5684 else if (toplevel != focus_widget)
5686 /* gtk_widget_grab_focus() operates on a tree without window...
5687 * actually, this is very questionable behaviour.
5690 gtk_container_foreach (GTK_CONTAINER (toplevel),
5691 reset_focus_recurse,
5695 /* now propagate the new focus up the widget tree and finally
5696 * set it on the window
5698 widget = focus_widget;
5699 while (widget->priv->parent)
5701 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5702 widget = widget->priv->parent;
5704 if (GTK_IS_WINDOW (widget))
5705 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5710 gtk_widget_real_query_tooltip (GtkWidget *widget,
5713 gboolean keyboard_tip,
5714 GtkTooltip *tooltip)
5716 gchar *tooltip_markup;
5717 gboolean has_tooltip;
5719 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5720 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5722 if (has_tooltip && tooltip_markup)
5724 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5732 gtk_widget_real_show_help (GtkWidget *widget,
5733 GtkWidgetHelpType help_type)
5735 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5737 _gtk_tooltip_toggle_keyboard_mode (widget);
5746 gtk_widget_real_focus (GtkWidget *widget,
5747 GtkDirectionType direction)
5749 if (!gtk_widget_get_can_focus (widget))
5752 if (!gtk_widget_is_focus (widget))
5754 gtk_widget_grab_focus (widget);
5762 gtk_widget_real_move_focus (GtkWidget *widget,
5763 GtkDirectionType direction)
5765 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5767 if (GTK_IS_WINDOW (toplevel) &&
5768 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5770 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5776 gtk_widget_real_keynav_failed (GtkWidget *widget,
5777 GtkDirectionType direction)
5779 gboolean cursor_only;
5783 case GTK_DIR_TAB_FORWARD:
5784 case GTK_DIR_TAB_BACKWARD:
5791 g_object_get (gtk_widget_get_settings (widget),
5792 "gtk-keynav-cursor-only", &cursor_only,
5799 gtk_widget_error_bell (widget);
5805 * gtk_widget_set_can_focus:
5806 * @widget: a #GtkWidget
5807 * @can_focus: whether or not @widget can own the input focus.
5809 * Specifies whether @widget can own the input focus. See
5810 * gtk_widget_grab_focus() for actually setting the input focus on a
5816 gtk_widget_set_can_focus (GtkWidget *widget,
5819 g_return_if_fail (GTK_IS_WIDGET (widget));
5821 if (can_focus != gtk_widget_get_can_focus (widget))
5824 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5826 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5828 gtk_widget_queue_resize (widget);
5829 g_object_notify (G_OBJECT (widget), "can-focus");
5834 * gtk_widget_get_can_focus:
5835 * @widget: a #GtkWidget
5837 * Determines whether @widget can own the input focus. See
5838 * gtk_widget_set_can_focus().
5840 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5845 gtk_widget_get_can_focus (GtkWidget *widget)
5847 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5849 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5853 * gtk_widget_has_focus:
5854 * @widget: a #GtkWidget
5856 * Determines if the widget has the global input focus. See
5857 * gtk_widget_is_focus() for the difference between having the global
5858 * input focus, and only having the focus within a toplevel.
5860 * Return value: %TRUE if the widget has the global input focus.
5865 gtk_widget_has_focus (GtkWidget *widget)
5867 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5869 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5873 * gtk_widget_is_focus:
5874 * @widget: a #GtkWidget
5876 * Determines if the widget is the focus widget within its
5877 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5878 * necessarily set; %HAS_FOCUS will only be set if the
5879 * toplevel widget additionally has the global input focus.)
5881 * Return value: %TRUE if the widget is the focus widget.
5884 gtk_widget_is_focus (GtkWidget *widget)
5886 GtkWidget *toplevel;
5888 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5890 toplevel = gtk_widget_get_toplevel (widget);
5892 if (GTK_IS_WINDOW (toplevel))
5893 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
5899 * gtk_widget_set_can_default:
5900 * @widget: a #GtkWidget
5901 * @can_default: whether or not @widget can be a default widget.
5903 * Specifies whether @widget can be a default widget. See
5904 * gtk_widget_grab_default() for details about the meaning of
5910 gtk_widget_set_can_default (GtkWidget *widget,
5911 gboolean can_default)
5913 g_return_if_fail (GTK_IS_WIDGET (widget));
5915 if (can_default != gtk_widget_get_can_default (widget))
5918 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5920 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5922 gtk_widget_queue_resize (widget);
5923 g_object_notify (G_OBJECT (widget), "can-default");
5928 * gtk_widget_get_can_default:
5929 * @widget: a #GtkWidget
5931 * Determines whether @widget can be a default widget. See
5932 * gtk_widget_set_can_default().
5934 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5939 gtk_widget_get_can_default (GtkWidget *widget)
5941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5943 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5947 * gtk_widget_has_default:
5948 * @widget: a #GtkWidget
5950 * Determines whether @widget is the current default widget within its
5951 * toplevel. See gtk_widget_set_can_default().
5953 * Return value: %TRUE if @widget is the current default widget within
5954 * its toplevel, %FALSE otherwise
5959 gtk_widget_has_default (GtkWidget *widget)
5961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5963 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5967 _gtk_widget_set_has_default (GtkWidget *widget,
5968 gboolean has_default)
5971 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5973 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5977 * gtk_widget_grab_default:
5978 * @widget: a #GtkWidget
5980 * Causes @widget to become the default widget. @widget must have the
5981 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5982 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5983 * %TRUE)</literal>. The default widget is activated when
5984 * the user presses Enter in a window. Default widgets must be
5985 * activatable, that is, gtk_widget_activate() should affect them. Note
5986 * that #GtkEntry widgets require the "activates-default" property
5987 * set to %TRUE before they activate the default widget when Enter
5988 * is pressed and the #GtkEntry is focused.
5991 gtk_widget_grab_default (GtkWidget *widget)
5995 g_return_if_fail (GTK_IS_WIDGET (widget));
5996 g_return_if_fail (gtk_widget_get_can_default (widget));
5998 window = gtk_widget_get_toplevel (widget);
6000 if (window && gtk_widget_is_toplevel (window))
6001 gtk_window_set_default (GTK_WINDOW (window), widget);
6003 g_warning (G_STRLOC ": widget not within a GtkWindow");
6007 * gtk_widget_set_receives_default:
6008 * @widget: a #GtkWidget
6009 * @receives_default: whether or not @widget can be a default widget.
6011 * Specifies whether @widget will be treated as the default widget
6012 * within its toplevel when it has the focus, even if another widget
6015 * See gtk_widget_grab_default() for details about the meaning of
6021 gtk_widget_set_receives_default (GtkWidget *widget,
6022 gboolean receives_default)
6024 g_return_if_fail (GTK_IS_WIDGET (widget));
6026 if (receives_default != gtk_widget_get_receives_default (widget))
6028 if (receives_default)
6029 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6031 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6033 g_object_notify (G_OBJECT (widget), "receives-default");
6038 * gtk_widget_get_receives_default:
6039 * @widget: a #GtkWidget
6041 * Determines whether @widget is alyways treated as default widget
6042 * withing its toplevel when it has the focus, even if another widget
6045 * See gtk_widget_set_receives_default().
6047 * Return value: %TRUE if @widget acts as default widget when focussed,
6053 gtk_widget_get_receives_default (GtkWidget *widget)
6055 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6057 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6061 * gtk_widget_has_grab:
6062 * @widget: a #GtkWidget
6064 * Determines whether the widget is currently grabbing events, so it
6065 * is the only widget receiving input events (keyboard and mouse).
6067 * See also gtk_grab_add().
6069 * Return value: %TRUE if the widget is in the grab_widgets stack
6074 gtk_widget_has_grab (GtkWidget *widget)
6076 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6078 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6082 _gtk_widget_set_has_grab (GtkWidget *widget,
6086 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6088 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6092 * gtk_widget_device_is_shadowed:
6093 * @widget: a #GtkWidget
6094 * @device: a #GdkDevice
6096 * Returns %TRUE if @device has been shadowed by a GTK+
6097 * device grab on another widget, so it would stop sending
6098 * events to @widget. This may be used in the
6099 * #GtkWidget::grab-notify signal to check for specific
6100 * devices. See gtk_device_grab_add().
6102 * Returns: %TRUE if there is an ongoing grab on @device
6103 * by another #GtkWidget than @widget.
6108 gtk_widget_device_is_shadowed (GtkWidget *widget,
6111 GtkWindowGroup *group;
6112 GtkWidget *grab_widget, *toplevel;
6114 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6115 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6117 if (!gtk_widget_get_realized (widget))
6120 toplevel = gtk_widget_get_toplevel (widget);
6122 if (GTK_IS_WINDOW (toplevel))
6123 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6125 group = gtk_window_get_group (NULL);
6127 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6129 /* Widget not inside the hierarchy of grab_widget */
6131 widget != grab_widget &&
6132 !gtk_widget_is_ancestor (widget, grab_widget))
6135 grab_widget = gtk_window_group_get_current_grab (group);
6136 if (grab_widget && widget != grab_widget &&
6137 !gtk_widget_is_ancestor (widget, grab_widget))
6144 * gtk_widget_set_name:
6145 * @widget: a #GtkWidget
6146 * @name: name for the widget
6148 * Widgets can be named, which allows you to refer to them from a
6149 * gtkrc file. You can apply a style to widgets with a particular name
6150 * in the gtkrc file. See the documentation for gtkrc files (on the
6151 * same page as the docs for #GtkRcStyle).
6153 * Note that widget names are separated by periods in paths (see
6154 * gtk_widget_path()), so names with embedded periods may cause confusion.
6157 gtk_widget_set_name (GtkWidget *widget,
6160 GtkWidgetPrivate *priv;
6163 g_return_if_fail (GTK_IS_WIDGET (widget));
6165 priv = widget->priv;
6167 new_name = g_strdup (name);
6168 g_free (priv->name);
6169 priv->name = new_name;
6171 if (gtk_widget_has_rc_style (widget))
6172 gtk_widget_reset_rc_style (widget);
6174 g_object_notify (G_OBJECT (widget), "name");
6178 * gtk_widget_get_name:
6179 * @widget: a #GtkWidget
6181 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6182 * significance of widget names.
6184 * Return value: name of the widget. This string is owned by GTK+ and
6185 * should not be modified or freed
6187 G_CONST_RETURN gchar*
6188 gtk_widget_get_name (GtkWidget *widget)
6190 GtkWidgetPrivate *priv;
6192 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6194 priv = widget->priv;
6198 return G_OBJECT_TYPE_NAME (widget);
6202 * gtk_widget_set_state:
6203 * @widget: a #GtkWidget
6204 * @state: new state for @widget
6206 * This function is for use in widget implementations. Sets the state
6207 * of a widget (insensitive, prelighted, etc.) Usually you should set
6208 * the state using wrapper functions such as gtk_widget_set_sensitive().
6211 gtk_widget_set_state (GtkWidget *widget,
6214 GtkWidgetPrivate *priv;
6216 g_return_if_fail (GTK_IS_WIDGET (widget));
6218 priv = widget->priv;
6220 if (state == gtk_widget_get_state (widget))
6223 if (state == GTK_STATE_INSENSITIVE)
6224 gtk_widget_set_sensitive (widget, FALSE);
6230 data.state_restoration = FALSE;
6231 data.use_forall = FALSE;
6233 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6235 data.parent_sensitive = TRUE;
6237 gtk_widget_propagate_state (widget, &data);
6239 if (gtk_widget_is_drawable (widget))
6240 gtk_widget_queue_draw (widget);
6245 * gtk_widget_get_state:
6246 * @widget: a #GtkWidget
6248 * Returns the widget's state. See gtk_widget_set_state().
6250 * Returns: the state of @widget.
6255 gtk_widget_get_state (GtkWidget *widget)
6257 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6259 return widget->priv->state;
6263 * gtk_widget_set_visible:
6264 * @widget: a #GtkWidget
6265 * @visible: whether the widget should be shown or not
6267 * Sets the visibility state of @widget. Note that setting this to
6268 * %TRUE doesn't mean the widget is actually viewable, see
6269 * gtk_widget_get_visible().
6271 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6272 * but is nicer to use when the visibility of the widget depends on
6278 gtk_widget_set_visible (GtkWidget *widget,
6281 g_return_if_fail (GTK_IS_WIDGET (widget));
6283 if (visible != gtk_widget_get_visible (widget))
6286 gtk_widget_show (widget);
6288 gtk_widget_hide (widget);
6293 * gtk_widget_get_visible:
6294 * @widget: a #GtkWidget
6296 * Determines whether the widget is visible. Note that this doesn't
6297 * take into account whether the widget's parent is also visible
6298 * or the widget is obscured in any way.
6300 * See gtk_widget_set_visible().
6302 * Return value: %TRUE if the widget is visible
6307 gtk_widget_get_visible (GtkWidget *widget)
6309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6311 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6315 * gtk_widget_set_has_window:
6316 * @widget: a #GtkWidget
6317 * @has_window: whether or not @widget has a window.
6319 * Specifies whether @widget has a #GdkWindow of its own. Note that
6320 * all realized widgets have a non-%NULL "window" pointer
6321 * (gtk_widget_get_window() never returns a %NULL window when a widget
6322 * is realized), but for many of them it's actually the #GdkWindow of
6323 * one of its parent widgets. Widgets that do not create a %window for
6324 * themselves in GtkWidget::realize() must announce this by
6325 * calling this function with @has_window = %FALSE.
6327 * This function should only be called by widget implementations,
6328 * and they should call it in their init() function.
6333 gtk_widget_set_has_window (GtkWidget *widget,
6334 gboolean has_window)
6336 g_return_if_fail (GTK_IS_WIDGET (widget));
6339 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6341 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6345 * gtk_widget_get_has_window:
6346 * @widget: a #GtkWidget
6348 * Determines whether @widget has a #GdkWindow of its own. See
6349 * gtk_widget_set_has_window().
6351 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6356 gtk_widget_get_has_window (GtkWidget *widget)
6358 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6360 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6364 * gtk_widget_is_toplevel:
6365 * @widget: a #GtkWidget
6367 * Determines whether @widget is a toplevel widget. Currently only
6368 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6369 * widgets have no parent widget.
6371 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6376 gtk_widget_is_toplevel (GtkWidget *widget)
6378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6380 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6384 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6385 gboolean is_toplevel)
6388 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6390 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6394 * gtk_widget_is_drawable:
6395 * @widget: a #GtkWidget
6397 * Determines whether @widget can be drawn to. A widget can be drawn
6398 * to if it is mapped and visible.
6400 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6405 gtk_widget_is_drawable (GtkWidget *widget)
6407 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6409 return (gtk_widget_get_visible (widget) &&
6410 gtk_widget_get_mapped (widget));
6414 * gtk_widget_get_realized:
6415 * @widget: a #GtkWidget
6417 * Determines whether @widget is realized.
6419 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6424 gtk_widget_get_realized (GtkWidget *widget)
6426 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6428 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6432 * gtk_widget_set_realized:
6433 * @widget: a #GtkWidget
6434 * @realized: %TRUE to mark the widget as realized
6436 * Marks the widget as being realized.
6438 * This function should only ever be called in a derived widget's
6439 * "realize" or "unrealize" implementation.
6444 gtk_widget_set_realized (GtkWidget *widget,
6447 g_return_if_fail (GTK_IS_WIDGET (widget));
6450 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6452 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6456 * gtk_widget_get_mapped:
6457 * @widget: a #GtkWidget
6459 * Whether the widget is mapped.
6461 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6466 gtk_widget_get_mapped (GtkWidget *widget)
6468 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6470 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6474 * gtk_widget_set_mapped:
6475 * @widget: a #GtkWidget
6476 * @mapped: %TRUE to mark the widget as mapped
6478 * Marks the widget as being realized.
6480 * This function should only ever be called in a derived widget's
6481 * "map" or "unmap" implementation.
6486 gtk_widget_set_mapped (GtkWidget *widget,
6489 g_return_if_fail (GTK_IS_WIDGET (widget));
6492 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6494 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6498 * gtk_widget_set_app_paintable:
6499 * @widget: a #GtkWidget
6500 * @app_paintable: %TRUE if the application will paint on the widget
6502 * Sets whether the application intends to draw on the widget in
6503 * an #GtkWidget::expose-event handler.
6505 * This is a hint to the widget and does not affect the behavior of
6506 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6507 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6508 * the effect is to suppress default themed drawing of the widget's
6509 * background. (Children of the widget will still be drawn.) The application
6510 * is then entirely responsible for drawing the widget background.
6512 * Note that the background is still drawn when the widget is mapped.
6513 * If this is not suitable (e.g. because you want to make a transparent
6514 * window using an RGBA visual), you can work around this by doing:
6516 * gtk_widget_realize (window);
6517 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6518 * gtk_widget_show (window);
6522 gtk_widget_set_app_paintable (GtkWidget *widget,
6523 gboolean app_paintable)
6525 g_return_if_fail (GTK_IS_WIDGET (widget));
6527 app_paintable = (app_paintable != FALSE);
6529 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6532 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6534 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6536 if (gtk_widget_is_drawable (widget))
6537 gtk_widget_queue_draw (widget);
6539 g_object_notify (G_OBJECT (widget), "app-paintable");
6544 * gtk_widget_get_app_paintable:
6545 * @widget: a #GtkWidget
6547 * Determines whether the application intends to draw on the widget in
6548 * an #GtkWidget::expose-event handler.
6550 * See gtk_widget_set_app_paintable()
6552 * Return value: %TRUE if the widget is app paintable
6557 gtk_widget_get_app_paintable (GtkWidget *widget)
6559 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6561 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6565 * gtk_widget_set_double_buffered:
6566 * @widget: a #GtkWidget
6567 * @double_buffered: %TRUE to double-buffer a widget
6569 * Widgets are double buffered by default; you can use this function
6570 * to turn off the buffering. "Double buffered" simply means that
6571 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6572 * automatically around expose events sent to the
6573 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6574 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6575 * buffer to the screen. The result is that users see the window
6576 * update in one smooth step, and don't see individual graphics
6577 * primitives being rendered.
6579 * In very simple terms, double buffered widgets don't flicker,
6580 * so you would only use this function to turn off double buffering
6581 * if you had special needs and really knew what you were doing.
6583 * Note: if you turn off double-buffering, you have to handle
6584 * expose events, since even the clearing to the background color or
6585 * pixmap will not happen automatically (as it is done in
6586 * gdk_window_begin_paint()).
6589 gtk_widget_set_double_buffered (GtkWidget *widget,
6590 gboolean double_buffered)
6592 g_return_if_fail (GTK_IS_WIDGET (widget));
6594 double_buffered = (double_buffered != FALSE);
6596 if (double_buffered != gtk_widget_get_double_buffered (widget))
6598 if (double_buffered)
6599 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6601 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6603 g_object_notify (G_OBJECT (widget), "double-buffered");
6608 * gtk_widget_get_double_buffered:
6609 * @widget: a #GtkWidget
6611 * Determines whether the widget is double buffered.
6613 * See gtk_widget_set_double_buffered()
6615 * Return value: %TRUE if the widget is double buffered
6620 gtk_widget_get_double_buffered (GtkWidget *widget)
6622 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6624 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6628 * gtk_widget_set_redraw_on_allocate:
6629 * @widget: a #GtkWidget
6630 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6631 * when it is allocated to a new size. Otherwise, only the
6632 * new portion of the widget will be redrawn.
6634 * Sets whether the entire widget is queued for drawing when its size
6635 * allocation changes. By default, this setting is %TRUE and
6636 * the entire widget is redrawn on every size change. If your widget
6637 * leaves the upper left unchanged when made bigger, turning this
6638 * setting off will improve performance.
6640 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6641 * off all allocation on resizing: the widget will not even redraw if
6642 * its position changes; this is to allow containers that don't draw
6643 * anything to avoid excess invalidations. If you set this flag on a
6644 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6645 * you are responsible for invalidating both the old and new allocation
6646 * of the widget when the widget is moved and responsible for invalidating
6647 * regions newly when the widget increases size.
6650 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6651 gboolean redraw_on_allocate)
6653 g_return_if_fail (GTK_IS_WIDGET (widget));
6655 if (redraw_on_allocate)
6656 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6658 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6662 * gtk_widget_set_sensitive:
6663 * @widget: a #GtkWidget
6664 * @sensitive: %TRUE to make the widget sensitive
6666 * Sets the sensitivity of a widget. A widget is sensitive if the user
6667 * can interact with it. Insensitive widgets are "grayed out" and the
6668 * user can't interact with them. Insensitive widgets are known as
6669 * "inactive", "disabled", or "ghosted" in some other toolkits.
6672 gtk_widget_set_sensitive (GtkWidget *widget,
6675 GtkWidgetPrivate *priv;
6678 g_return_if_fail (GTK_IS_WIDGET (widget));
6680 priv = widget->priv;
6682 sensitive = (sensitive != FALSE);
6684 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6689 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6690 data.state = priv->saved_state;
6694 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6695 data.state = gtk_widget_get_state (widget);
6697 data.state_restoration = TRUE;
6698 data.use_forall = TRUE;
6701 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6703 data.parent_sensitive = TRUE;
6705 gtk_widget_propagate_state (widget, &data);
6706 if (gtk_widget_is_drawable (widget))
6707 gtk_widget_queue_draw (widget);
6709 g_object_notify (G_OBJECT (widget), "sensitive");
6713 * gtk_widget_get_sensitive:
6714 * @widget: a #GtkWidget
6716 * Returns the widget's sensitivity (in the sense of returning
6717 * the value that has been set using gtk_widget_set_sensitive()).
6719 * The effective sensitivity of a widget is however determined by both its
6720 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6722 * Returns: %TRUE if the widget is sensitive
6727 gtk_widget_get_sensitive (GtkWidget *widget)
6729 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6731 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6735 * gtk_widget_is_sensitive:
6736 * @widget: a #GtkWidget
6738 * Returns the widget's effective sensitivity, which means
6739 * it is sensitive itself and also its parent widget is sensntive
6741 * Returns: %TRUE if the widget is effectively sensitive
6746 gtk_widget_is_sensitive (GtkWidget *widget)
6748 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6750 return (gtk_widget_get_sensitive (widget) &&
6751 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6755 * gtk_widget_set_parent:
6756 * @widget: a #GtkWidget
6757 * @parent: parent container
6759 * This function is useful only when implementing subclasses of
6761 * Sets the container as the parent of @widget, and takes care of
6762 * some details such as updating the state and style of the child
6763 * to reflect its new location. The opposite function is
6764 * gtk_widget_unparent().
6767 gtk_widget_set_parent (GtkWidget *widget,
6770 GtkWidgetPrivate *priv;
6773 g_return_if_fail (GTK_IS_WIDGET (widget));
6774 g_return_if_fail (GTK_IS_WIDGET (parent));
6775 g_return_if_fail (widget != parent);
6777 priv = widget->priv;
6779 if (priv->parent != NULL)
6781 g_warning ("Can't set a parent on widget which has a parent\n");
6784 if (gtk_widget_is_toplevel (widget))
6786 g_warning ("Can't set a parent on a toplevel widget\n");
6790 /* keep this function in sync with gtk_menu_attach_to_widget()
6793 g_object_ref_sink (widget);
6794 priv->parent = parent;
6796 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6797 data.state = gtk_widget_get_state (parent);
6799 data.state = gtk_widget_get_state (widget);
6800 data.state_restoration = FALSE;
6801 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6802 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6804 gtk_widget_propagate_state (widget, &data);
6806 gtk_widget_reset_rc_styles (widget);
6808 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6809 if (GTK_WIDGET_ANCHORED (priv->parent))
6810 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6811 g_object_notify (G_OBJECT (widget), "parent");
6813 /* Enforce realized/mapped invariants
6815 if (gtk_widget_get_realized (priv->parent))
6816 gtk_widget_realize (widget);
6818 if (gtk_widget_get_visible (priv->parent) &&
6819 gtk_widget_get_visible (widget))
6821 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6822 gtk_widget_get_mapped (priv->parent))
6823 gtk_widget_map (widget);
6825 gtk_widget_queue_resize (widget);
6830 * gtk_widget_get_parent:
6831 * @widget: a #GtkWidget
6833 * Returns the parent container of @widget.
6835 * Return value: (transfer none): the parent container of @widget, or %NULL
6838 gtk_widget_get_parent (GtkWidget *widget)
6840 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6842 return widget->priv->parent;
6845 /*****************************************
6847 * see docs/styles.txt
6848 *****************************************/
6851 * gtk_widget_style_attach:
6852 * @widget: a #GtkWidget
6854 * This function attaches the widget's #GtkStyle to the widget's
6855 * #GdkWindow. It is a replacement for
6858 * widget->style = gtk_style_attach (widget->style, widget->window);
6861 * and should only ever be called in a derived widget's "realize"
6862 * implementation which does not chain up to its parent class'
6863 * "realize" implementation, because one of the parent classes
6864 * (finally #GtkWidget) would attach the style itself.
6869 gtk_widget_style_attach (GtkWidget *widget)
6871 GtkWidgetPrivate *priv;
6873 g_return_if_fail (GTK_IS_WIDGET (widget));
6874 g_return_if_fail (gtk_widget_get_realized (widget));
6876 priv = widget->priv;
6878 priv->style = gtk_style_attach (priv->style, priv->window);
6882 * gtk_widget_has_rc_style:
6883 * @widget: a #GtkWidget
6885 * Determines if the widget style has been looked up through the rc mechanism.
6887 * Returns: %TRUE if the widget has been looked up through the rc
6888 * mechanism, %FALSE otherwise.
6893 gtk_widget_has_rc_style (GtkWidget *widget)
6895 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6897 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6901 * gtk_widget_set_style:
6902 * @widget: a #GtkWidget
6903 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6904 * gtk_widget_set_style() and go back to the default style
6906 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6907 * want to use this function; it interacts badly with themes, because
6908 * themes work by replacing the #GtkStyle. Instead, use
6909 * gtk_widget_modify_style().
6912 gtk_widget_set_style (GtkWidget *widget,
6915 g_return_if_fail (GTK_IS_WIDGET (widget));
6919 gboolean initial_emission;
6921 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6923 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6924 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6926 gtk_widget_set_style_internal (widget, style, initial_emission);
6930 if (GTK_WIDGET_USER_STYLE (widget))
6931 gtk_widget_reset_rc_style (widget);
6936 * gtk_widget_ensure_style:
6937 * @widget: a #GtkWidget
6939 * Ensures that @widget has a style (@widget->style). Not a very useful
6940 * function; most of the time, if you want the style, the widget is
6941 * realized, and realized widgets are guaranteed to have a style
6945 gtk_widget_ensure_style (GtkWidget *widget)
6947 g_return_if_fail (GTK_IS_WIDGET (widget));
6949 if (!GTK_WIDGET_USER_STYLE (widget) &&
6950 !gtk_widget_has_rc_style (widget))
6951 gtk_widget_reset_rc_style (widget);
6954 /* Look up the RC style for this widget, unsetting any user style that
6955 * may be in effect currently
6958 gtk_widget_reset_rc_style (GtkWidget *widget)
6960 GtkWidgetPrivate *priv = widget->priv;
6961 GtkStyle *new_style = NULL;
6962 gboolean initial_emission;
6964 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6966 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6967 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6969 if (gtk_widget_has_screen (widget))
6970 new_style = gtk_rc_get_style (widget);
6972 new_style = gtk_widget_get_default_style ();
6974 if (initial_emission || new_style != priv->style)
6975 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6979 * gtk_widget_get_style:
6980 * @widget: a #GtkWidget
6982 * Simply an accessor function that returns @widget->style.
6984 * Return value: (transfer none): the widget's #GtkStyle
6987 gtk_widget_get_style (GtkWidget *widget)
6989 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6991 return widget->priv->style;
6995 * gtk_widget_modify_style:
6996 * @widget: a #GtkWidget
6997 * @style: the #GtkRcStyle holding the style modifications
6999 * Modifies style values on the widget. Modifications made using this
7000 * technique take precedence over style values set via an RC file,
7001 * however, they will be overriden if a style is explicitely set on
7002 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7003 * is designed so each field can either be set or unset, so it is
7004 * possible, using this function, to modify some style values and
7005 * leave the others unchanged.
7007 * Note that modifications made with this function are not cumulative
7008 * with previous calls to gtk_widget_modify_style() or with such
7009 * functions as gtk_widget_modify_fg(). If you wish to retain
7010 * previous values, you must first call gtk_widget_get_modifier_style(),
7011 * make your modifications to the returned style, then call
7012 * gtk_widget_modify_style() with that style. On the other hand,
7013 * if you first call gtk_widget_modify_style(), subsequent calls
7014 * to such functions gtk_widget_modify_fg() will have a cumulative
7015 * effect with the initial modifications.
7018 gtk_widget_modify_style (GtkWidget *widget,
7021 g_return_if_fail (GTK_IS_WIDGET (widget));
7022 g_return_if_fail (GTK_IS_RC_STYLE (style));
7024 g_object_set_qdata_full (G_OBJECT (widget),
7026 gtk_rc_style_copy (style),
7027 (GDestroyNotify) g_object_unref);
7029 /* note that "style" may be invalid here if it was the old
7030 * modifier style and the only reference was our own.
7033 if (gtk_widget_has_rc_style (widget))
7034 gtk_widget_reset_rc_style (widget);
7038 * gtk_widget_get_modifier_style:
7039 * @widget: a #GtkWidget
7041 * Returns the current modifier style for the widget. (As set by
7042 * gtk_widget_modify_style().) If no style has previously set, a new
7043 * #GtkRcStyle will be created with all values unset, and set as the
7044 * modifier style for the widget. If you make changes to this rc
7045 * style, you must call gtk_widget_modify_style(), passing in the
7046 * returned rc style, to make sure that your changes take effect.
7048 * Caution: passing the style back to gtk_widget_modify_style() will
7049 * normally end up destroying it, because gtk_widget_modify_style() copies
7050 * the passed-in style and sets the copy as the new modifier style,
7051 * thus dropping any reference to the old modifier style. Add a reference
7052 * to the modifier style if you want to keep it alive.
7054 * Return value: (transfer none): the modifier style for the widget. This rc style is
7055 * owned by the widget. If you want to keep a pointer to value this
7056 * around, you must add a refcount using g_object_ref().
7059 gtk_widget_get_modifier_style (GtkWidget *widget)
7061 GtkRcStyle *rc_style;
7063 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7065 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7069 rc_style = gtk_rc_style_new ();
7070 g_object_set_qdata_full (G_OBJECT (widget),
7073 (GDestroyNotify) g_object_unref);
7080 gtk_widget_modify_color_component (GtkWidget *widget,
7081 GtkRcFlags component,
7083 const GdkColor *color)
7085 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7092 rc_style->fg[state] = *color;
7095 rc_style->bg[state] = *color;
7098 rc_style->text[state] = *color;
7101 rc_style->base[state] = *color;
7104 g_assert_not_reached();
7107 rc_style->color_flags[state] |= component;
7110 rc_style->color_flags[state] &= ~component;
7112 gtk_widget_modify_style (widget, rc_style);
7116 * gtk_widget_modify_symbolic_color:
7117 * @widget: a #GtkWidget
7118 * @name: the name of the symbolic color to modify
7119 * @color: (allow-none): the color to assign (does not need to be allocated),
7120 * or %NULL to undo the effect of previous calls to
7121 * of gtk_widget_modify_symbolic_color().
7123 * Sets a symbolic color for a widget.
7124 * All other style values are left untouched. See also
7125 * gtk_widget_modify_style().
7130 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7132 const GdkColor *color)
7134 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7136 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7138 gtk_widget_modify_style (widget, rc_style);
7142 * gtk_widget_modify_fg:
7143 * @widget: a #GtkWidget
7144 * @state: the state for which to set the foreground color
7145 * @color: (allow-none): the color to assign (does not need to be allocated),
7146 * or %NULL to undo the effect of previous calls to
7147 * of gtk_widget_modify_fg().
7149 * Sets the foreground color for a widget in a particular state.
7150 * All other style values are left untouched. See also
7151 * gtk_widget_modify_style().
7154 gtk_widget_modify_fg (GtkWidget *widget,
7156 const GdkColor *color)
7158 g_return_if_fail (GTK_IS_WIDGET (widget));
7159 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7161 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7165 * gtk_widget_modify_bg:
7166 * @widget: a #GtkWidget
7167 * @state: the state for which to set the background color
7168 * @color: (allow-none): the color to assign (does not need to be allocated),
7169 * or %NULL to undo the effect of previous calls to
7170 * of gtk_widget_modify_bg().
7172 * Sets the background color for a widget in a particular state.
7173 * All other style values are left untouched. See also
7174 * gtk_widget_modify_style().
7176 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7177 * draw on their parent container's window and thus may not draw any
7178 * background themselves. This is the case for e.g. #GtkLabel. To modify
7179 * the background of such widgets, you have to set the background color
7180 * on their parent; if you want to set the background of a rectangular
7181 * area around a label, try placing the label in a #GtkEventBox widget
7182 * and setting the background color on that.
7185 gtk_widget_modify_bg (GtkWidget *widget,
7187 const GdkColor *color)
7189 g_return_if_fail (GTK_IS_WIDGET (widget));
7190 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7192 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7196 * gtk_widget_modify_text:
7197 * @widget: a #GtkWidget
7198 * @state: the state for which to set the text color
7199 * @color: (allow-none): the color to assign (does not need to be allocated),
7200 * or %NULL to undo the effect of previous calls to
7201 * of gtk_widget_modify_text().
7203 * Sets the text color for a widget in a particular state. All other
7204 * style values are left untouched. The text color is the foreground
7205 * color used along with the base color (see gtk_widget_modify_base())
7206 * for widgets such as #GtkEntry and #GtkTextView. See also
7207 * gtk_widget_modify_style().
7210 gtk_widget_modify_text (GtkWidget *widget,
7212 const GdkColor *color)
7214 g_return_if_fail (GTK_IS_WIDGET (widget));
7215 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7217 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7221 * gtk_widget_modify_base:
7222 * @widget: a #GtkWidget
7223 * @state: the state for which to set the base color
7224 * @color: (allow-none): the color to assign (does not need to be allocated),
7225 * or %NULL to undo the effect of previous calls to
7226 * of gtk_widget_modify_base().
7228 * Sets the base color for a widget in a particular state.
7229 * All other style values are left untouched. The base color
7230 * is the background color used along with the text color
7231 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7232 * and #GtkTextView. See also gtk_widget_modify_style().
7234 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7235 * draw on their parent container's window and thus may not draw any
7236 * background themselves. This is the case for e.g. #GtkLabel. To modify
7237 * the background of such widgets, you have to set the base color on their
7238 * parent; if you want to set the background of a rectangular area around
7239 * a label, try placing the label in a #GtkEventBox widget and setting
7240 * the base color on that.
7243 gtk_widget_modify_base (GtkWidget *widget,
7245 const GdkColor *color)
7247 g_return_if_fail (GTK_IS_WIDGET (widget));
7248 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7250 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7254 modify_color_property (GtkWidget *widget,
7255 GtkRcStyle *rc_style,
7257 const GdkColor *color)
7259 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7260 GQuark property_name = g_quark_from_string (name);
7264 GtkRcProperty rc_property = {0};
7267 rc_property.type_name = type_name;
7268 rc_property.property_name = property_name;
7269 rc_property.origin = NULL;
7271 color_name = gdk_color_to_string (color);
7272 g_value_init (&rc_property.value, G_TYPE_STRING);
7273 g_value_take_string (&rc_property.value, color_name);
7275 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7277 g_value_unset (&rc_property.value);
7280 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7284 * gtk_widget_modify_cursor:
7285 * @widget: a #GtkWidget
7286 * @primary: the color to use for primary cursor (does not need to be
7287 * allocated), or %NULL to undo the effect of previous calls to
7288 * of gtk_widget_modify_cursor().
7289 * @secondary: the color to use for secondary cursor (does not need to be
7290 * allocated), or %NULL to undo the effect of previous calls to
7291 * of gtk_widget_modify_cursor().
7293 * Sets the cursor color to use in a widget, overriding the
7294 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7295 * style properties. All other style values are left untouched.
7296 * See also gtk_widget_modify_style().
7301 gtk_widget_modify_cursor (GtkWidget *widget,
7302 const GdkColor *primary,
7303 const GdkColor *secondary)
7305 GtkRcStyle *rc_style;
7307 g_return_if_fail (GTK_IS_WIDGET (widget));
7309 rc_style = gtk_widget_get_modifier_style (widget);
7311 modify_color_property (widget, rc_style, "cursor-color", primary);
7312 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7314 gtk_widget_modify_style (widget, rc_style);
7318 * gtk_widget_modify_font:
7319 * @widget: a #GtkWidget
7320 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7321 * the effect of previous calls to gtk_widget_modify_font().
7323 * Sets the font to use for a widget. All other style values are left
7324 * untouched. See also gtk_widget_modify_style().
7327 gtk_widget_modify_font (GtkWidget *widget,
7328 PangoFontDescription *font_desc)
7330 GtkRcStyle *rc_style;
7332 g_return_if_fail (GTK_IS_WIDGET (widget));
7334 rc_style = gtk_widget_get_modifier_style (widget);
7336 if (rc_style->font_desc)
7337 pango_font_description_free (rc_style->font_desc);
7340 rc_style->font_desc = pango_font_description_copy (font_desc);
7342 rc_style->font_desc = NULL;
7344 gtk_widget_modify_style (widget, rc_style);
7348 gtk_widget_real_direction_changed (GtkWidget *widget,
7349 GtkTextDirection previous_direction)
7351 gtk_widget_queue_resize (widget);
7355 gtk_widget_real_style_set (GtkWidget *widget,
7356 GtkStyle *previous_style)
7358 GtkWidgetPrivate *priv = widget->priv;
7360 if (gtk_widget_get_realized (widget) &&
7361 gtk_widget_get_has_window (widget))
7362 gtk_style_set_background (priv->style, priv->window, priv->state);
7366 gtk_widget_set_style_internal (GtkWidget *widget,
7368 gboolean initial_emission)
7370 GtkWidgetPrivate *priv = widget->priv;
7372 g_object_ref (widget);
7373 g_object_freeze_notify (G_OBJECT (widget));
7375 if (priv->style != style)
7377 GtkStyle *previous_style;
7379 if (gtk_widget_get_realized (widget))
7381 gtk_widget_reset_shapes (widget);
7382 gtk_style_detach (priv->style);
7385 previous_style = priv->style;
7386 priv->style = style;
7387 g_object_ref (priv->style);
7389 if (gtk_widget_get_realized (widget))
7390 priv->style = gtk_style_attach (priv->style, priv->window);
7392 gtk_widget_update_pango_context (widget);
7393 g_signal_emit (widget,
7394 widget_signals[STYLE_SET],
7396 initial_emission ? NULL : previous_style);
7397 g_object_unref (previous_style);
7399 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7400 gtk_widget_queue_resize (widget);
7402 else if (initial_emission)
7404 gtk_widget_update_pango_context (widget);
7405 g_signal_emit (widget,
7406 widget_signals[STYLE_SET],
7410 g_object_notify (G_OBJECT (widget), "style");
7411 g_object_thaw_notify (G_OBJECT (widget));
7412 g_object_unref (widget);
7416 GtkWidget *previous_toplevel;
7417 GdkScreen *previous_screen;
7418 GdkScreen *new_screen;
7419 } HierarchyChangedInfo;
7422 do_screen_change (GtkWidget *widget,
7423 GdkScreen *old_screen,
7424 GdkScreen *new_screen)
7426 if (old_screen != new_screen)
7430 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7432 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7435 _gtk_tooltip_hide (widget);
7436 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7441 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7442 gpointer client_data)
7444 GtkWidgetPrivate *priv = widget->priv;
7445 HierarchyChangedInfo *info = client_data;
7446 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7447 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7449 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7451 g_object_ref (widget);
7454 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7456 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7458 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7459 do_screen_change (widget, info->previous_screen, info->new_screen);
7461 if (GTK_IS_CONTAINER (widget))
7462 gtk_container_forall (GTK_CONTAINER (widget),
7463 gtk_widget_propagate_hierarchy_changed_recurse,
7466 g_object_unref (widget);
7471 * _gtk_widget_propagate_hierarchy_changed:
7472 * @widget: a #GtkWidget
7473 * @previous_toplevel: Previous toplevel
7475 * Propagates changes in the anchored state to a widget and all
7476 * children, unsetting or setting the %ANCHORED flag, and
7477 * emitting #GtkWidget::hierarchy-changed.
7480 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7481 GtkWidget *previous_toplevel)
7483 GtkWidgetPrivate *priv = widget->priv;
7484 HierarchyChangedInfo info;
7486 info.previous_toplevel = previous_toplevel;
7487 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7489 if (gtk_widget_is_toplevel (widget) ||
7490 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7491 info.new_screen = gtk_widget_get_screen (widget);
7493 info.new_screen = NULL;
7495 if (info.previous_screen)
7496 g_object_ref (info.previous_screen);
7497 if (previous_toplevel)
7498 g_object_ref (previous_toplevel);
7500 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7502 if (previous_toplevel)
7503 g_object_unref (previous_toplevel);
7504 if (info.previous_screen)
7505 g_object_unref (info.previous_screen);
7509 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7510 gpointer client_data)
7512 HierarchyChangedInfo *info = client_data;
7514 g_object_ref (widget);
7516 do_screen_change (widget, info->previous_screen, info->new_screen);
7518 if (GTK_IS_CONTAINER (widget))
7519 gtk_container_forall (GTK_CONTAINER (widget),
7520 gtk_widget_propagate_screen_changed_recurse,
7523 g_object_unref (widget);
7527 * gtk_widget_is_composited:
7528 * @widget: a #GtkWidget
7530 * Whether @widget can rely on having its alpha channel
7531 * drawn correctly. On X11 this function returns whether a
7532 * compositing manager is running for @widget's screen.
7534 * Please note that the semantics of this call will change
7535 * in the future if used on a widget that has a composited
7536 * window in its hierarchy (as set by gdk_window_set_composited()).
7538 * Return value: %TRUE if the widget can rely on its alpha
7539 * channel being drawn correctly.
7544 gtk_widget_is_composited (GtkWidget *widget)
7548 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7550 screen = gtk_widget_get_screen (widget);
7552 return gdk_screen_is_composited (screen);
7556 propagate_composited_changed (GtkWidget *widget,
7559 if (GTK_IS_CONTAINER (widget))
7561 gtk_container_forall (GTK_CONTAINER (widget),
7562 propagate_composited_changed,
7566 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7570 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7572 propagate_composited_changed (widget, NULL);
7576 * _gtk_widget_propagate_screen_changed:
7577 * @widget: a #GtkWidget
7578 * @previous_screen: Previous screen
7580 * Propagates changes in the screen for a widget to all
7581 * children, emitting #GtkWidget::screen-changed.
7584 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7585 GdkScreen *previous_screen)
7587 HierarchyChangedInfo info;
7589 info.previous_screen = previous_screen;
7590 info.new_screen = gtk_widget_get_screen (widget);
7592 if (previous_screen)
7593 g_object_ref (previous_screen);
7595 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7597 if (previous_screen)
7598 g_object_unref (previous_screen);
7602 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7604 if (gtk_widget_has_rc_style (widget))
7605 gtk_widget_reset_rc_style (widget);
7607 if (GTK_IS_CONTAINER (widget))
7608 gtk_container_forall (GTK_CONTAINER (widget),
7609 reset_rc_styles_recurse,
7615 * gtk_widget_reset_rc_styles:
7616 * @widget: a #GtkWidget.
7618 * Reset the styles of @widget and all descendents, so when
7619 * they are looked up again, they get the correct values
7620 * for the currently loaded RC file settings.
7622 * This function is not useful for applications.
7625 gtk_widget_reset_rc_styles (GtkWidget *widget)
7627 g_return_if_fail (GTK_IS_WIDGET (widget));
7629 reset_rc_styles_recurse (widget, NULL);
7633 * gtk_widget_get_default_style:
7635 * Returns the default style used by all widgets initially.
7637 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7638 * by GTK+ and should not be modified or freed.
7641 gtk_widget_get_default_style (void)
7643 if (!gtk_default_style)
7645 gtk_default_style = gtk_style_new ();
7646 g_object_ref (gtk_default_style);
7649 return gtk_default_style;
7652 static PangoContext *
7653 gtk_widget_peek_pango_context (GtkWidget *widget)
7655 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7659 * gtk_widget_get_pango_context:
7660 * @widget: a #GtkWidget
7662 * Gets a #PangoContext with the appropriate font map, font description,
7663 * and base direction for this widget. Unlike the context returned
7664 * by gtk_widget_create_pango_context(), this context is owned by
7665 * the widget (it can be used until the screen for the widget changes
7666 * or the widget is removed from its toplevel), and will be updated to
7667 * match any changes to the widget's attributes.
7669 * If you create and keep a #PangoLayout using this context, you must
7670 * deal with changes to the context by calling pango_layout_context_changed()
7671 * on the layout in response to the #GtkWidget::style-set and
7672 * #GtkWidget::direction-changed signals for the widget.
7674 * Return value: (transfer none): the #PangoContext for the widget.
7677 gtk_widget_get_pango_context (GtkWidget *widget)
7679 PangoContext *context;
7681 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7683 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7686 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7687 g_object_set_qdata_full (G_OBJECT (widget),
7688 quark_pango_context,
7697 update_pango_context (GtkWidget *widget,
7698 PangoContext *context)
7700 GtkWidgetPrivate *priv = widget->priv;
7702 pango_context_set_font_description (context, priv->style->font_desc);
7703 pango_context_set_base_dir (context,
7704 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7705 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7709 gtk_widget_update_pango_context (GtkWidget *widget)
7711 PangoContext *context = gtk_widget_peek_pango_context (widget);
7717 update_pango_context (widget, context);
7719 screen = gtk_widget_get_screen_unchecked (widget);
7722 pango_cairo_context_set_resolution (context,
7723 gdk_screen_get_resolution (screen));
7724 pango_cairo_context_set_font_options (context,
7725 gdk_screen_get_font_options (screen));
7731 * gtk_widget_create_pango_context:
7732 * @widget: a #GtkWidget
7734 * Creates a new #PangoContext with the appropriate font map,
7735 * font description, and base direction for drawing text for
7736 * this widget. See also gtk_widget_get_pango_context().
7738 * Return value: the new #PangoContext
7741 gtk_widget_create_pango_context (GtkWidget *widget)
7744 PangoContext *context;
7746 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7748 screen = gtk_widget_get_screen_unchecked (widget);
7751 GTK_NOTE (MULTIHEAD,
7752 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7754 screen = gdk_screen_get_default ();
7757 context = gdk_pango_context_get_for_screen (screen);
7759 update_pango_context (widget, context);
7760 pango_context_set_language (context, gtk_get_default_language ());
7766 * gtk_widget_create_pango_layout:
7767 * @widget: a #GtkWidget
7768 * @text: text to set on the layout (can be %NULL)
7770 * Creates a new #PangoLayout with the appropriate font map,
7771 * font description, and base direction for drawing text for
7774 * If you keep a #PangoLayout created in this way around, in order to
7775 * notify the layout of changes to the base direction or font of this
7776 * widget, you must call pango_layout_context_changed() in response to
7777 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7780 * Return value: the new #PangoLayout
7783 gtk_widget_create_pango_layout (GtkWidget *widget,
7786 PangoLayout *layout;
7787 PangoContext *context;
7789 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7791 context = gtk_widget_get_pango_context (widget);
7792 layout = pango_layout_new (context);
7795 pango_layout_set_text (layout, text, -1);
7801 * gtk_widget_render_icon:
7802 * @widget: a #GtkWidget
7803 * @stock_id: a stock ID
7804 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7805 * render at the size of the source and don't scale (if there are
7806 * multiple source sizes, GTK+ picks one of the available sizes).
7807 * @detail: (allow-none): render detail to pass to theme engine
7809 * A convenience function that uses the theme engine and RC file
7810 * settings for @widget to look up @stock_id and render it to
7811 * a pixbuf. @stock_id should be a stock icon ID such as
7812 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7813 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7814 * identifies the widget or code doing the rendering, so that
7815 * theme engines can special-case rendering for that widget or code.
7817 * The pixels in the returned #GdkPixbuf are shared with the rest of
7818 * the application and should not be modified. The pixbuf should be freed
7819 * after use with g_object_unref().
7821 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7824 gtk_widget_render_icon (GtkWidget *widget,
7825 const gchar *stock_id,
7827 const gchar *detail)
7829 GtkWidgetPrivate *priv;
7830 GtkIconSet *icon_set;
7833 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7834 g_return_val_if_fail (stock_id != NULL, NULL);
7835 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7837 priv = widget->priv;
7839 gtk_widget_ensure_style (widget);
7841 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7843 if (icon_set == NULL)
7846 retval = gtk_icon_set_render_icon (icon_set,
7848 gtk_widget_get_direction (widget),
7849 gtk_widget_get_state (widget),
7858 * gtk_widget_set_parent_window:
7859 * @widget: a #GtkWidget.
7860 * @parent_window: the new parent window.
7862 * Sets a non default parent window for @widget.
7865 gtk_widget_set_parent_window (GtkWidget *widget,
7866 GdkWindow *parent_window)
7868 GdkWindow *old_parent_window;
7870 g_return_if_fail (GTK_IS_WIDGET (widget));
7872 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7873 quark_parent_window);
7875 if (parent_window != old_parent_window)
7877 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7879 if (old_parent_window)
7880 g_object_unref (old_parent_window);
7882 g_object_ref (parent_window);
7887 * gtk_widget_get_parent_window:
7888 * @widget: a #GtkWidget.
7890 * Gets @widget's parent window.
7892 * Returns: (transfer none): the parent window of @widget.
7895 gtk_widget_get_parent_window (GtkWidget *widget)
7897 GtkWidgetPrivate *priv;
7898 GdkWindow *parent_window;
7900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7902 priv = widget->priv;
7904 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7906 return (parent_window != NULL) ? parent_window :
7907 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
7912 * gtk_widget_set_child_visible:
7913 * @widget: a #GtkWidget
7914 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7916 * Sets whether @widget should be mapped along with its when its parent
7917 * is mapped and @widget has been shown with gtk_widget_show().
7919 * The child visibility can be set for widget before it is added to
7920 * a container with gtk_widget_set_parent(), to avoid mapping
7921 * children unnecessary before immediately unmapping them. However
7922 * it will be reset to its default state of %TRUE when the widget
7923 * is removed from a container.
7925 * Note that changing the child visibility of a widget does not
7926 * queue a resize on the widget. Most of the time, the size of
7927 * a widget is computed from all visible children, whether or
7928 * not they are mapped. If this is not the case, the container
7929 * can queue a resize itself.
7931 * This function is only useful for container implementations and
7932 * never should be called by an application.
7935 gtk_widget_set_child_visible (GtkWidget *widget,
7936 gboolean is_visible)
7938 GtkWidgetPrivate *priv;
7940 g_return_if_fail (GTK_IS_WIDGET (widget));
7941 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7943 priv = widget->priv;
7945 g_object_ref (widget);
7948 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7951 GtkWidget *toplevel;
7953 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7955 toplevel = gtk_widget_get_toplevel (widget);
7956 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7957 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7960 if (priv->parent && gtk_widget_get_realized (priv->parent))
7962 if (gtk_widget_get_mapped (priv->parent) &&
7963 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7964 gtk_widget_get_visible (widget))
7965 gtk_widget_map (widget);
7967 gtk_widget_unmap (widget);
7970 g_object_unref (widget);
7974 * gtk_widget_get_child_visible:
7975 * @widget: a #GtkWidget
7977 * Gets the value set with gtk_widget_set_child_visible().
7978 * If you feel a need to use this function, your code probably
7979 * needs reorganization.
7981 * This function is only useful for container implementations and
7982 * never should be called by an application.
7984 * Return value: %TRUE if the widget is mapped with the parent.
7987 gtk_widget_get_child_visible (GtkWidget *widget)
7989 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7991 return GTK_WIDGET_CHILD_VISIBLE (widget);
7995 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7997 GtkWidget *toplevel;
7999 toplevel = gtk_widget_get_toplevel (widget);
8001 if (gtk_widget_is_toplevel (toplevel))
8003 if (GTK_IS_WINDOW (toplevel))
8004 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8005 else if (GTK_IS_INVISIBLE (toplevel))
8006 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8013 * gtk_widget_get_screen:
8014 * @widget: a #GtkWidget
8016 * Get the #GdkScreen from the toplevel window associated with
8017 * this widget. This function can only be called after the widget
8018 * has been added to a widget hierarchy with a #GtkWindow
8021 * In general, you should only create screen specific
8022 * resources when a widget has been realized, and you should
8023 * free those resources when the widget is unrealized.
8025 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8030 gtk_widget_get_screen (GtkWidget *widget)
8034 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8036 screen = gtk_widget_get_screen_unchecked (widget);
8043 g_warning (G_STRLOC ": Can't get associated screen"
8044 " for a widget unless it is inside a toplevel GtkWindow\n"
8045 " widget type is %s associated top level type is %s",
8046 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8047 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8049 return gdk_screen_get_default ();
8054 * gtk_widget_has_screen:
8055 * @widget: a #GtkWidget
8057 * Checks whether there is a #GdkScreen is associated with
8058 * this widget. All toplevel widgets have an associated
8059 * screen, and all widgets added into a hierarchy with a toplevel
8060 * window at the top.
8062 * Return value: %TRUE if there is a #GdkScreen associcated
8068 gtk_widget_has_screen (GtkWidget *widget)
8070 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8072 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8076 * gtk_widget_get_display:
8077 * @widget: a #GtkWidget
8079 * Get the #GdkDisplay for the toplevel window associated with
8080 * this widget. This function can only be called after the widget
8081 * has been added to a widget hierarchy with a #GtkWindow at the top.
8083 * In general, you should only create display specific
8084 * resources when a widget has been realized, and you should
8085 * free those resources when the widget is unrealized.
8087 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8092 gtk_widget_get_display (GtkWidget *widget)
8094 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8096 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8100 * gtk_widget_get_root_window:
8101 * @widget: a #GtkWidget
8103 * Get the root window where this widget is located. This function can
8104 * only be called after the widget has been added to a widget
8105 * hierarchy with #GtkWindow at the top.
8107 * The root window is useful for such purposes as creating a popup
8108 * #GdkWindow associated with the window. In general, you should only
8109 * create display specific resources when a widget has been realized,
8110 * and you should free those resources when the widget is unrealized.
8112 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8117 gtk_widget_get_root_window (GtkWidget *widget)
8119 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8121 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8125 * gtk_widget_child_focus:
8126 * @widget: a #GtkWidget
8127 * @direction: direction of focus movement
8129 * This function is used by custom widget implementations; if you're
8130 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8131 * to a particular widget, and gtk_container_set_focus_chain() to
8132 * change the focus tab order. So you may want to investigate those
8133 * functions instead.
8135 * gtk_widget_child_focus() is called by containers as the user moves
8136 * around the window using keyboard shortcuts. @direction indicates
8137 * what kind of motion is taking place (up, down, left, right, tab
8138 * forward, tab backward). gtk_widget_child_focus() emits the
8139 * #GtkWidget::focus signal; widgets override the default handler
8140 * for this signal in order to implement appropriate focus behavior.
8142 * The default ::focus handler for a widget should return %TRUE if
8143 * moving in @direction left the focus on a focusable location inside
8144 * that widget, and %FALSE if moving in @direction moved the focus
8145 * outside the widget. If returning %TRUE, widgets normally
8146 * call gtk_widget_grab_focus() to place the focus accordingly;
8147 * if returning %FALSE, they don't modify the current focus location.
8149 * Return value: %TRUE if focus ended up inside @widget
8152 gtk_widget_child_focus (GtkWidget *widget,
8153 GtkDirectionType direction)
8155 gboolean return_val;
8157 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8159 if (!gtk_widget_get_visible (widget) ||
8160 !gtk_widget_is_sensitive (widget))
8163 /* child widgets must set CAN_FOCUS, containers
8164 * don't have to though.
8166 if (!GTK_IS_CONTAINER (widget) &&
8167 !gtk_widget_get_can_focus (widget))
8170 g_signal_emit (widget,
8171 widget_signals[FOCUS],
8173 direction, &return_val);
8179 * gtk_widget_keynav_failed:
8180 * @widget: a #GtkWidget
8181 * @direction: direction of focus movement
8183 * This function should be called whenever keyboard navigation within
8184 * a single widget hits a boundary. The function emits the
8185 * #GtkWidget::keynav-failed signal on the widget and its return
8186 * value should be interpreted in a way similar to the return value of
8187 * gtk_widget_child_focus():
8189 * When %TRUE is returned, stay in the widget, the failed keyboard
8190 * navigation is Ok and/or there is nowhere we can/should move the
8193 * When %FALSE is returned, the caller should continue with keyboard
8194 * navigation outside the widget, e.g. by calling
8195 * gtk_widget_child_focus() on the widget's toplevel.
8197 * The default ::keynav-failed handler returns %TRUE for
8198 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8199 * values of #GtkDirectionType, it looks at the
8200 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8201 * if the setting is %TRUE. This way the entire user interface
8202 * becomes cursor-navigatable on input devices such as mobile phones
8203 * which only have cursor keys but no tab key.
8205 * Whenever the default handler returns %TRUE, it also calls
8206 * gtk_widget_error_bell() to notify the user of the failed keyboard
8209 * A use case for providing an own implementation of ::keynav-failed
8210 * (either by connecting to it or by overriding it) would be a row of
8211 * #GtkEntry widgets where the user should be able to navigate the
8212 * entire row with the cursor keys, as e.g. known from user interfaces
8213 * that require entering license keys.
8215 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8216 * if the emitting widget should try to handle the keyboard
8217 * navigation attempt in its parent container(s).
8222 gtk_widget_keynav_failed (GtkWidget *widget,
8223 GtkDirectionType direction)
8225 gboolean return_val;
8227 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8229 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8230 direction, &return_val);
8236 * gtk_widget_error_bell:
8237 * @widget: a #GtkWidget
8239 * Notifies the user about an input-related error on this widget.
8240 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8241 * gdk_window_beep(), otherwise it does nothing.
8243 * Note that the effect of gdk_window_beep() can be configured in many
8244 * ways, depending on the windowing backend and the desktop environment
8245 * or window manager that is used.
8250 gtk_widget_error_bell (GtkWidget *widget)
8252 GtkWidgetPrivate *priv;
8253 GtkSettings* settings;
8256 g_return_if_fail (GTK_IS_WIDGET (widget));
8258 priv = widget->priv;
8260 settings = gtk_widget_get_settings (widget);
8264 g_object_get (settings,
8265 "gtk-error-bell", &beep,
8268 if (beep && priv->window)
8269 gdk_window_beep (priv->window);
8273 gtk_widget_set_usize_internal (GtkWidget *widget,
8277 GtkWidgetAuxInfo *aux_info;
8278 gboolean changed = FALSE;
8280 g_object_freeze_notify (G_OBJECT (widget));
8282 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8284 if (width > -2 && aux_info->width != width)
8286 g_object_notify (G_OBJECT (widget), "width-request");
8287 aux_info->width = width;
8290 if (height > -2 && aux_info->height != height)
8292 g_object_notify (G_OBJECT (widget), "height-request");
8293 aux_info->height = height;
8297 if (gtk_widget_get_visible (widget) && changed)
8298 gtk_widget_queue_resize (widget);
8300 g_object_thaw_notify (G_OBJECT (widget));
8304 * gtk_widget_set_size_request:
8305 * @widget: a #GtkWidget
8306 * @width: width @widget should request, or -1 to unset
8307 * @height: height @widget should request, or -1 to unset
8309 * Sets the minimum size of a widget; that is, the widget's size
8310 * request will be @width by @height. You can use this function to
8311 * force a widget to be either larger or smaller than it normally
8314 * In most cases, gtk_window_set_default_size() is a better choice for
8315 * toplevel windows than this function; setting the default size will
8316 * still allow users to shrink the window. Setting the size request
8317 * will force them to leave the window at least as large as the size
8318 * request. When dealing with window sizes,
8319 * gtk_window_set_geometry_hints() can be a useful function as well.
8321 * Note the inherent danger of setting any fixed size - themes,
8322 * translations into other languages, different fonts, and user action
8323 * can all change the appropriate size for a given widget. So, it's
8324 * basically impossible to hardcode a size that will always be
8327 * The size request of a widget is the smallest size a widget can
8328 * accept while still functioning well and drawing itself correctly.
8329 * However in some strange cases a widget may be allocated less than
8330 * its requested size, and in many cases a widget may be allocated more
8331 * space than it requested.
8333 * If the size request in a given direction is -1 (unset), then
8334 * the "natural" size request of the widget will be used instead.
8336 * Widgets can't actually be allocated a size less than 1 by 1, but
8337 * you can pass 0,0 to this function to mean "as small as possible."
8339 * The size request set here does not include any margin from the
8340 * #GtkWidget properties margin-left, margin-right, margin-top, and
8341 * margin-bottom, but it does include pretty much all other padding
8342 * or border properties set by any subclass of #GtkWidget.
8345 gtk_widget_set_size_request (GtkWidget *widget,
8349 g_return_if_fail (GTK_IS_WIDGET (widget));
8350 g_return_if_fail (width >= -1);
8351 g_return_if_fail (height >= -1);
8358 gtk_widget_set_usize_internal (widget, width, height);
8363 * gtk_widget_get_size_request:
8364 * @widget: a #GtkWidget
8365 * @width: (out) (allow-none): return location for width, or %NULL
8366 * @height: (out) (allow-none): return location for height, or %NULL
8368 * Gets the size request that was explicitly set for the widget using
8369 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8370 * @height indicates that that dimension has not been set explicitly
8371 * and the natural requisition of the widget will be used intead. See
8372 * gtk_widget_set_size_request(). To get the size a widget will
8373 * actually use, call gtk_widget_size_request() instead of
8377 gtk_widget_get_size_request (GtkWidget *widget,
8381 const GtkWidgetAuxInfo *aux_info;
8383 g_return_if_fail (GTK_IS_WIDGET (widget));
8385 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8388 *width = aux_info->width;
8391 *height = aux_info->height;
8395 * gtk_widget_set_events:
8396 * @widget: a #GtkWidget
8397 * @events: event mask
8399 * Sets the event mask (see #GdkEventMask) for a widget. The event
8400 * mask determines which events a widget will receive. Keep in mind
8401 * that different widgets have different default event masks, and by
8402 * changing the event mask you may disrupt a widget's functionality,
8403 * so be careful. This function must be called while a widget is
8404 * unrealized. Consider gtk_widget_add_events() for widgets that are
8405 * already realized, or if you want to preserve the existing event
8406 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8407 * to get events on those widgets, place them inside a #GtkEventBox
8408 * and receive events on the event box.
8411 gtk_widget_set_events (GtkWidget *widget,
8414 g_return_if_fail (GTK_IS_WIDGET (widget));
8415 g_return_if_fail (!gtk_widget_get_realized (widget));
8417 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8418 GINT_TO_POINTER (events));
8419 g_object_notify (G_OBJECT (widget), "events");
8423 * gtk_widget_set_device_events:
8424 * @widget: a #GtkWidget
8425 * @device: a #GdkDevice
8426 * @events: event mask
8428 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8429 * mask determines which events a widget will receive from @device. Keep
8430 * in mind that different widgets have different default event masks, and by
8431 * changing the event mask you may disrupt a widget's functionality,
8432 * so be careful. This function must be called while a widget is
8433 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8434 * already realized, or if you want to preserve the existing event
8435 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8436 * to get events on those widgets, place them inside a #GtkEventBox
8437 * and receive events on the event box.
8442 gtk_widget_set_device_events (GtkWidget *widget,
8444 GdkEventMask events)
8446 GHashTable *device_events;
8448 g_return_if_fail (GTK_IS_WIDGET (widget));
8449 g_return_if_fail (GDK_IS_DEVICE (device));
8450 g_return_if_fail (!gtk_widget_get_realized (widget));
8452 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8454 if (G_UNLIKELY (!device_events))
8456 device_events = g_hash_table_new (NULL, NULL);
8457 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8458 (GDestroyNotify) g_hash_table_unref);
8461 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8465 gtk_widget_add_events_internal_list (GtkWidget *widget,
8472 for (l = window_list; l != NULL; l = l->next)
8474 GdkWindow *window = l->data;
8477 gdk_window_get_user_data (window, &user_data);
8478 if (user_data == widget)
8483 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8485 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8487 children = gdk_window_get_children (window);
8488 gtk_widget_add_events_internal_list (widget, device, events, children);
8489 g_list_free (children);
8495 gtk_widget_add_events_internal (GtkWidget *widget,
8499 GtkWidgetPrivate *priv = widget->priv;
8502 if (!gtk_widget_get_has_window (widget))
8503 window_list = gdk_window_get_children (priv->window);
8505 window_list = g_list_prepend (NULL, priv->window);
8507 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8509 g_list_free (window_list);
8513 * gtk_widget_add_events:
8514 * @widget: a #GtkWidget
8515 * @events: an event mask, see #GdkEventMask
8517 * Adds the events in the bitfield @events to the event mask for
8518 * @widget. See gtk_widget_set_events() for details.
8521 gtk_widget_add_events (GtkWidget *widget,
8526 g_return_if_fail (GTK_IS_WIDGET (widget));
8528 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8529 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8530 GINT_TO_POINTER (old_events | events));
8532 if (gtk_widget_get_realized (widget))
8533 gtk_widget_add_events_internal (widget, NULL, events);
8535 g_object_notify (G_OBJECT (widget), "events");
8539 * gtk_widget_add_device_events:
8540 * @widget: a #GtkWidget
8541 * @device: a #GdkDevice
8542 * @events: an event mask, see #GdkEventMask
8544 * Adds the device events in the bitfield @events to the event mask for
8545 * @widget. See gtk_widget_set_device_events() for details.
8550 gtk_widget_add_device_events (GtkWidget *widget,
8552 GdkEventMask events)
8554 GdkEventMask old_events;
8555 GHashTable *device_events;
8557 g_return_if_fail (GTK_IS_WIDGET (widget));
8558 g_return_if_fail (GDK_IS_DEVICE (device));
8560 old_events = gtk_widget_get_device_events (widget, device);
8562 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8564 if (G_UNLIKELY (!device_events))
8566 device_events = g_hash_table_new (NULL, NULL);
8567 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8568 (GDestroyNotify) g_hash_table_unref);
8571 g_hash_table_insert (device_events, device,
8572 GUINT_TO_POINTER (old_events | events));
8574 if (gtk_widget_get_realized (widget))
8575 gtk_widget_add_events_internal (widget, device, events);
8577 g_object_notify (G_OBJECT (widget), "events");
8581 * gtk_widget_set_extension_events:
8582 * @widget: a #GtkWidget
8583 * @mode: bitfield of extension events to receive
8585 * Sets the extension events mask to @mode. See #GdkExtensionMode
8586 * and gdk_input_set_extension_events().
8589 gtk_widget_set_extension_events (GtkWidget *widget,
8590 GdkExtensionMode mode)
8592 g_return_if_fail (GTK_IS_WIDGET (widget));
8594 if (gtk_widget_get_realized (widget))
8595 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8597 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8598 GINT_TO_POINTER (mode));
8599 g_object_notify (G_OBJECT (widget), "extension-events");
8603 * gtk_widget_get_toplevel:
8604 * @widget: a #GtkWidget
8606 * This function returns the topmost widget in the container hierarchy
8607 * @widget is a part of. If @widget has no parent widgets, it will be
8608 * returned as the topmost widget. No reference will be added to the
8609 * returned widget; it should not be unreferenced.
8611 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8612 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8614 * %NULL if @widget wasn't inside a toplevel window, and if the
8615 * window was inside a #GtkWindow-derived widget which was in turn
8616 * inside the toplevel #GtkWindow. While the second case may
8617 * seem unlikely, it actually happens when a #GtkPlug is embedded
8618 * inside a #GtkSocket within the same application.
8620 * To reliably find the toplevel #GtkWindow, use
8621 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8622 * is set on the result.
8624 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8625 * if (gtk_widget_is_toplevel (toplevel))
8627 * /* Perform action on toplevel. */
8631 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8632 * if there's no ancestor.
8635 gtk_widget_get_toplevel (GtkWidget *widget)
8637 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8639 while (widget->priv->parent)
8640 widget = widget->priv->parent;
8646 * gtk_widget_get_ancestor:
8647 * @widget: a #GtkWidget
8648 * @widget_type: ancestor type
8650 * Gets the first ancestor of @widget with type @widget_type. For example,
8651 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8652 * the first #GtkBox that's an ancestor of @widget. No reference will be
8653 * added to the returned widget; it should not be unreferenced. See note
8654 * about checking for a toplevel #GtkWindow in the docs for
8655 * gtk_widget_get_toplevel().
8657 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8658 * considers @widget to be an ancestor of itself.
8660 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8663 gtk_widget_get_ancestor (GtkWidget *widget,
8666 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8668 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8669 widget = widget->priv->parent;
8671 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8678 * gtk_widget_get_colormap:
8679 * @widget: a #GtkWidget
8681 * Gets the colormap that will be used to render @widget. No reference will
8682 * be added to the returned colormap; it should not be unreferenced.
8684 * Return value: (transfer none): the colormap used by @widget
8687 gtk_widget_get_colormap (GtkWidget *widget)
8689 GtkWidgetPrivate *priv;
8690 GdkColormap *colormap;
8691 GtkWidget *tmp_widget;
8693 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8695 priv = widget->priv;
8699 colormap = gdk_drawable_get_colormap (priv->window);
8700 /* If window was destroyed previously, we'll get NULL here */
8705 tmp_widget = widget;
8708 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8712 tmp_widget= tmp_widget->priv->parent;
8715 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8719 * gtk_widget_get_visual:
8720 * @widget: a #GtkWidget
8722 * Gets the visual that will be used to render @widget.
8724 * Return value: (transfer none): the visual for @widget
8727 gtk_widget_get_visual (GtkWidget *widget)
8729 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8731 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8735 * gtk_widget_get_settings:
8736 * @widget: a #GtkWidget
8738 * Gets the settings object holding the settings (global property
8739 * settings, RC file information, etc) used for this widget.
8741 * Note that this function can only be called when the #GtkWidget
8742 * is attached to a toplevel, since the settings object is specific
8743 * to a particular #GdkScreen.
8745 * Return value: (transfer none): the relevant #GtkSettings object
8748 gtk_widget_get_settings (GtkWidget *widget)
8750 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8752 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8756 * gtk_widget_set_colormap:
8757 * @widget: a #GtkWidget
8758 * @colormap: a colormap
8760 * Sets the colormap for the widget to the given value. Widget must not
8761 * have been previously realized. This probably should only be used
8762 * from an <function>init()</function> function (i.e. from the constructor
8766 gtk_widget_set_colormap (GtkWidget *widget,
8767 GdkColormap *colormap)
8769 g_return_if_fail (GTK_IS_WIDGET (widget));
8770 g_return_if_fail (!gtk_widget_get_realized (widget));
8771 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8773 g_object_ref (colormap);
8775 g_object_set_qdata_full (G_OBJECT (widget),
8782 * gtk_widget_get_events:
8783 * @widget: a #GtkWidget
8785 * Returns the event mask for the widget (a bitfield containing flags
8786 * from the #GdkEventMask enumeration). These are the events that the widget
8789 * Return value: event mask for @widget
8792 gtk_widget_get_events (GtkWidget *widget)
8794 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8796 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8800 * gtk_widget_get_device_events:
8801 * @widget: a #GtkWidget
8802 * @device: a #GdkDevice
8804 * Returns the events mask for the widget corresponding to an specific device. These
8805 * are the events that the widget will receive when @device operates on it.
8807 * Returns: device event mask for @widget
8812 gtk_widget_get_device_events (GtkWidget *widget,
8815 GHashTable *device_events;
8817 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8818 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8820 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8825 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8829 * gtk_widget_get_extension_events:
8830 * @widget: a #GtkWidget
8832 * Retrieves the extension events the widget will receive; see
8833 * gdk_input_set_extension_events().
8835 * Return value: extension events for @widget
8838 gtk_widget_get_extension_events (GtkWidget *widget)
8840 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8842 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8846 * gtk_widget_get_pointer:
8847 * @widget: a #GtkWidget
8848 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8849 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8851 * Obtains the location of the mouse pointer in widget coordinates.
8852 * Widget coordinates are a bit odd; for historical reasons, they are
8853 * defined as @widget->window coordinates for widgets that are not
8854 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8855 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8858 gtk_widget_get_pointer (GtkWidget *widget,
8862 GtkWidgetPrivate *priv;
8864 g_return_if_fail (GTK_IS_WIDGET (widget));
8866 priv = widget->priv;
8873 if (gtk_widget_get_realized (widget))
8875 gdk_window_get_pointer (priv->window, x, y, NULL);
8877 if (!gtk_widget_get_has_window (widget))
8880 *x -= priv->allocation.x;
8882 *y -= priv->allocation.y;
8888 * gtk_widget_is_ancestor:
8889 * @widget: a #GtkWidget
8890 * @ancestor: another #GtkWidget
8892 * Determines whether @widget is somewhere inside @ancestor, possibly with
8893 * intermediate containers.
8895 * Return value: %TRUE if @ancestor contains @widget as a child,
8896 * grandchild, great grandchild, etc.
8899 gtk_widget_is_ancestor (GtkWidget *widget,
8900 GtkWidget *ancestor)
8902 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8903 g_return_val_if_fail (ancestor != NULL, FALSE);
8907 if (widget->priv->parent == ancestor)
8909 widget = widget->priv->parent;
8915 static GQuark quark_composite_name = 0;
8918 * gtk_widget_set_composite_name:
8919 * @widget: a #GtkWidget.
8920 * @name: the name to set
8922 * Sets a widgets composite name. The widget must be
8923 * a composite child of its parent; see gtk_widget_push_composite_child().
8926 gtk_widget_set_composite_name (GtkWidget *widget,
8929 g_return_if_fail (GTK_IS_WIDGET (widget));
8930 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8931 g_return_if_fail (name != NULL);
8933 if (!quark_composite_name)
8934 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8936 g_object_set_qdata_full (G_OBJECT (widget),
8937 quark_composite_name,
8943 * gtk_widget_get_composite_name:
8944 * @widget: a #GtkWidget
8946 * Obtains the composite name of a widget.
8948 * Returns: the composite name of @widget, or %NULL if @widget is not
8949 * a composite child. The string should be freed when it is no
8953 gtk_widget_get_composite_name (GtkWidget *widget)
8955 GtkWidgetPrivate *priv;
8957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8959 priv = widget->priv;
8961 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
8962 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
8969 * gtk_widget_push_composite_child:
8971 * Makes all newly-created widgets as composite children until
8972 * the corresponding gtk_widget_pop_composite_child() call.
8974 * A composite child is a child that's an implementation detail of the
8975 * container it's inside and should not be visible to people using the
8976 * container. Composite children aren't treated differently by GTK (but
8977 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8978 * builders might want to treat them in a different way.
8980 * Here is a simple example:
8982 * gtk_widget_push_composite_child ();
8983 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8984 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8985 * gtk_widget_pop_composite_child ();
8986 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8987 * GTK_WIDGET (scrolled_window));
8988 * g_object_ref (scrolled_window->hscrollbar);
8992 gtk_widget_push_composite_child (void)
8994 composite_child_stack++;
8998 * gtk_widget_pop_composite_child:
9000 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9003 gtk_widget_pop_composite_child (void)
9005 if (composite_child_stack)
9006 composite_child_stack--;
9010 * gtk_widget_push_colormap:
9011 * @cmap: a #GdkColormap
9013 * Pushes @cmap onto a global stack of colormaps; the topmost
9014 * colormap on the stack will be used to create all widgets.
9015 * Remove @cmap with gtk_widget_pop_colormap(). There's little
9016 * reason to use this function.
9019 gtk_widget_push_colormap (GdkColormap *cmap)
9021 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
9023 colormap_stack = g_slist_prepend (colormap_stack, cmap);
9027 * gtk_widget_pop_colormap:
9029 * Removes a colormap pushed with gtk_widget_push_colormap().
9032 gtk_widget_pop_colormap (void)
9035 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
9039 * gtk_widget_set_default_colormap:
9040 * @colormap: a #GdkColormap
9042 * Sets the default colormap to use when creating widgets.
9043 * gtk_widget_push_colormap() is a better function to use if
9044 * you only want to affect a few widgets, rather than all widgets.
9047 gtk_widget_set_default_colormap (GdkColormap *colormap)
9049 g_return_if_fail (GDK_IS_COLORMAP (colormap));
9051 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
9056 * gtk_widget_get_default_colormap:
9058 * Obtains the default colormap used to create widgets.
9060 * Return value: (transfer none): default widget colormap
9063 gtk_widget_get_default_colormap (void)
9065 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
9069 * gtk_widget_get_default_visual:
9071 * Obtains the visual of the default colormap. Not really useful;
9072 * used to be useful before gdk_colormap_get_visual() existed.
9074 * Return value: (transfer none): visual of the default colormap
9077 gtk_widget_get_default_visual (void)
9079 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
9083 gtk_widget_emit_direction_changed (GtkWidget *widget,
9084 GtkTextDirection old_dir)
9086 gtk_widget_update_pango_context (widget);
9088 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9092 * gtk_widget_set_direction:
9093 * @widget: a #GtkWidget
9094 * @dir: the new direction
9096 * Sets the reading direction on a particular widget. This direction
9097 * controls the primary direction for widgets containing text,
9098 * and also the direction in which the children of a container are
9099 * packed. The ability to set the direction is present in order
9100 * so that correct localization into languages with right-to-left
9101 * reading directions can be done. Generally, applications will
9102 * let the default reading direction present, except for containers
9103 * where the containers are arranged in an order that is explicitely
9104 * visual rather than logical (such as buttons for text justification).
9106 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9107 * set by gtk_widget_set_default_direction() will be used.
9110 gtk_widget_set_direction (GtkWidget *widget,
9111 GtkTextDirection dir)
9113 GtkTextDirection old_dir;
9115 g_return_if_fail (GTK_IS_WIDGET (widget));
9116 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9118 old_dir = gtk_widget_get_direction (widget);
9120 if (dir == GTK_TEXT_DIR_NONE)
9121 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9124 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9125 if (dir == GTK_TEXT_DIR_LTR)
9126 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9128 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9131 if (old_dir != gtk_widget_get_direction (widget))
9132 gtk_widget_emit_direction_changed (widget, old_dir);
9136 * gtk_widget_get_direction:
9137 * @widget: a #GtkWidget
9139 * Gets the reading direction for a particular widget. See
9140 * gtk_widget_set_direction().
9142 * Return value: the reading direction for the widget.
9145 gtk_widget_get_direction (GtkWidget *widget)
9147 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9149 if (GTK_WIDGET_DIRECTION_SET (widget))
9150 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9152 return gtk_default_direction;
9156 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9158 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9160 g_object_ref (widget);
9162 if (!GTK_WIDGET_DIRECTION_SET (widget))
9163 gtk_widget_emit_direction_changed (widget, old_dir);
9165 if (GTK_IS_CONTAINER (widget))
9166 gtk_container_forall (GTK_CONTAINER (widget),
9167 gtk_widget_set_default_direction_recurse,
9170 g_object_unref (widget);
9174 * gtk_widget_set_default_direction:
9175 * @dir: the new default direction. This cannot be
9176 * %GTK_TEXT_DIR_NONE.
9178 * Sets the default reading direction for widgets where the
9179 * direction has not been explicitly set by gtk_widget_set_direction().
9182 gtk_widget_set_default_direction (GtkTextDirection dir)
9184 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9186 if (dir != gtk_default_direction)
9188 GList *toplevels, *tmp_list;
9189 GtkTextDirection old_dir = gtk_default_direction;
9191 gtk_default_direction = dir;
9193 tmp_list = toplevels = gtk_window_list_toplevels ();
9194 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9198 gtk_widget_set_default_direction_recurse (tmp_list->data,
9199 GUINT_TO_POINTER (old_dir));
9200 g_object_unref (tmp_list->data);
9201 tmp_list = tmp_list->next;
9204 g_list_free (toplevels);
9209 * gtk_widget_get_default_direction:
9211 * Obtains the current default reading direction. See
9212 * gtk_widget_set_default_direction().
9214 * Return value: the current default direction.
9217 gtk_widget_get_default_direction (void)
9219 return gtk_default_direction;
9223 gtk_widget_dispose (GObject *object)
9225 GtkWidget *widget = GTK_WIDGET (object);
9226 GtkWidgetPrivate *priv = widget->priv;
9229 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9230 else if (gtk_widget_get_visible (widget))
9231 gtk_widget_hide (widget);
9233 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9234 if (gtk_widget_get_realized (widget))
9235 gtk_widget_unrealize (widget);
9237 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9241 gtk_widget_real_destroy (GtkObject *object)
9243 /* gtk_object_destroy() will already hold a refcount on object */
9244 GtkWidget *widget = GTK_WIDGET (object);
9245 GtkWidgetPrivate *priv = widget->priv;
9247 /* wipe accelerator closures (keep order) */
9248 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9249 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9251 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9252 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9254 gtk_grab_remove (widget);
9256 g_object_unref (priv->style);
9257 priv->style = gtk_widget_get_default_style ();
9258 g_object_ref (priv->style);
9260 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9264 gtk_widget_finalize (GObject *object)
9266 GtkWidget *widget = GTK_WIDGET (object);
9267 GtkWidgetPrivate *priv = widget->priv;
9268 GtkWidgetAuxInfo *aux_info;
9269 GtkAccessible *accessible;
9271 gtk_grab_remove (widget);
9273 g_object_unref (priv->style);
9276 g_free (priv->name);
9278 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9280 gtk_widget_aux_info_destroy (aux_info);
9282 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9284 g_object_unref (accessible);
9286 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9289 /*****************************************
9290 * gtk_widget_real_map:
9295 *****************************************/
9298 gtk_widget_real_map (GtkWidget *widget)
9300 GtkWidgetPrivate *priv = widget->priv;
9302 g_assert (gtk_widget_get_realized (widget));
9304 if (!gtk_widget_get_mapped (widget))
9306 gtk_widget_set_mapped (widget, TRUE);
9308 if (gtk_widget_get_has_window (widget))
9309 gdk_window_show (priv->window);
9313 /*****************************************
9314 * gtk_widget_real_unmap:
9319 *****************************************/
9322 gtk_widget_real_unmap (GtkWidget *widget)
9324 GtkWidgetPrivate *priv = widget->priv;
9326 if (gtk_widget_get_mapped (widget))
9328 gtk_widget_set_mapped (widget, FALSE);
9330 if (gtk_widget_get_has_window (widget))
9331 gdk_window_hide (priv->window);
9335 /*****************************************
9336 * gtk_widget_real_realize:
9341 *****************************************/
9344 gtk_widget_real_realize (GtkWidget *widget)
9346 GtkWidgetPrivate *priv = widget->priv;
9348 g_assert (!gtk_widget_get_has_window (widget));
9350 gtk_widget_set_realized (widget, TRUE);
9353 priv->window = gtk_widget_get_parent_window (widget);
9354 g_object_ref (priv->window);
9356 priv->style = gtk_style_attach (priv->style, priv->window);
9359 /*****************************************
9360 * gtk_widget_real_unrealize:
9365 *****************************************/
9368 gtk_widget_real_unrealize (GtkWidget *widget)
9370 GtkWidgetPrivate *priv = widget->priv;
9372 if (gtk_widget_get_mapped (widget))
9373 gtk_widget_real_unmap (widget);
9375 gtk_widget_set_mapped (widget, FALSE);
9377 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9380 /* We must do unrealize child widget BEFORE container widget.
9381 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9382 * So, unrealizing container widget bofore its children causes the problem
9383 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9386 if (GTK_IS_CONTAINER (widget))
9387 gtk_container_forall (GTK_CONTAINER (widget),
9388 (GtkCallback) gtk_widget_unrealize,
9391 gtk_style_detach (priv->style);
9392 if (gtk_widget_get_has_window (widget))
9394 gdk_window_set_user_data (priv->window, NULL);
9395 gdk_window_destroy (priv->window);
9396 priv->window = NULL;
9400 g_object_unref (priv->window);
9401 priv->window = NULL;
9404 gtk_selection_remove_all (widget);
9406 gtk_widget_set_realized (widget, FALSE);
9410 gtk_widget_real_size_request (GtkWidget *widget,
9411 GtkRequisition *requisition)
9413 requisition->width = 0;
9414 requisition->height = 0;
9418 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9419 GtkOrientation orientation,
9424 const GtkWidgetAuxInfo *aux_info;
9426 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9428 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9429 aux_info->width > 0)
9431 *minimum_size = MAX (*minimum_size, aux_info->width);
9433 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9434 aux_info->height > 0)
9436 *minimum_size = MAX (*minimum_size, aux_info->height);
9439 /* Fix it if set_size_request made natural size smaller than min size.
9440 * This would also silently fix broken widgets, but we warn about them
9441 * in gtksizerequest.c when calling their size request vfuncs.
9443 *natural_size = MAX (*natural_size, *minimum_size);
9445 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9447 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9448 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9452 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9453 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9458 * _gtk_widget_peek_colormap:
9460 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
9462 * Return value: the currently pushed colormap, or %NULL if there is none.
9465 _gtk_widget_peek_colormap (void)
9468 return (GdkColormap*) colormap_stack->data;
9473 * _gtk_widget_peek_request_cache:
9475 * Returns the address of the widget's request cache (strictly for
9476 * internal use in gtksizerequest.c)
9478 * Return value: the address of @widget's size request cache.
9481 _gtk_widget_peek_request_cache (GtkWidget *widget)
9483 /* Don't bother slowing things down with the return_if_fail guards here */
9484 return &widget->priv->requests;
9488 * _gtk_widget_set_device_window:
9489 * @widget: a #GtkWidget.
9490 * @device: a #GdkDevice.
9491 * @window: the new device window.
9493 * Sets pointer window for @widget and @device. Does not ref @window.
9494 * Actually stores it on the #GdkScreen, but you don't need to know that.
9497 _gtk_widget_set_device_window (GtkWidget *widget,
9501 GtkWidgetPrivate *priv;
9503 GHashTable *device_window;
9505 g_return_if_fail (GTK_IS_WIDGET (widget));
9506 g_return_if_fail (GDK_IS_DEVICE (device));
9507 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9509 priv = widget->priv;
9511 if (!gtk_widget_get_realized (widget))
9514 screen = gdk_drawable_get_screen (priv->window);
9515 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9517 if (G_UNLIKELY (!device_window))
9519 device_window = g_hash_table_new (NULL, NULL);
9520 g_object_set_qdata_full (G_OBJECT (screen),
9521 quark_pointer_window,
9523 (GDestroyNotify) g_hash_table_destroy);
9527 g_hash_table_insert (device_window, device, window);
9529 g_hash_table_remove (device_window, device);
9533 * _gtk_widget_get_device_window:
9534 * @widget: a #GtkWidget.
9535 * @device: a #GdkDevice.
9537 * Return value: the device window set on the #GdkScreen @widget is attached
9541 _gtk_widget_get_device_window (GtkWidget *widget,
9544 GtkWidgetPrivate *priv;
9546 GHashTable *device_window;
9550 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9551 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9553 priv = widget->priv;
9555 if (!gtk_widget_get_realized (widget))
9558 screen = gdk_drawable_get_screen (priv->window);
9559 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9561 if (G_UNLIKELY (!device_window))
9564 window = g_hash_table_lookup (device_window, device);
9569 gdk_window_get_user_data (window, (gpointer *) &w);
9578 * _gtk_widget_list_devices:
9579 * @widget: a #GtkWidget.
9581 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9582 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9586 _gtk_widget_list_devices (GtkWidget *widget)
9588 GtkWidgetPrivate *priv;
9590 GHashTableIter iter;
9591 GHashTable *device_window;
9592 GList *devices = NULL;
9593 gpointer key, value;
9595 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9597 priv = widget->priv;
9599 if (!gtk_widget_get_realized (widget))
9602 screen = gdk_drawable_get_screen (priv->window);
9603 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9605 if (G_UNLIKELY (!device_window))
9608 g_hash_table_iter_init (&iter, device_window);
9610 while (g_hash_table_iter_next (&iter, &key, &value))
9612 GdkDevice *device = key;
9613 GdkWindow *window = value;
9618 gdk_window_get_user_data (window, (gpointer *) &w);
9621 devices = g_list_prepend (devices, device);
9629 synth_crossing (GtkWidget *widget,
9633 GdkCrossingMode mode,
9634 GdkNotifyType detail)
9638 event = gdk_event_new (type);
9640 event->crossing.window = g_object_ref (window);
9641 event->crossing.send_event = TRUE;
9642 event->crossing.subwindow = g_object_ref (window);
9643 event->crossing.time = GDK_CURRENT_TIME;
9644 event->crossing.x = event->crossing.y = 0;
9645 event->crossing.x_root = event->crossing.y_root = 0;
9646 event->crossing.mode = mode;
9647 event->crossing.detail = detail;
9648 event->crossing.focus = FALSE;
9649 event->crossing.state = 0;
9650 gdk_event_set_device (event, device);
9653 widget = gtk_get_event_widget (event);
9656 gtk_widget_event_internal (widget, event);
9658 gdk_event_free (event);
9662 * _gtk_widget_synthesize_crossing:
9663 * @from: the #GtkWidget the virtual pointer is leaving.
9664 * @to: the #GtkWidget the virtual pointer is moving to.
9665 * @mode: the #GdkCrossingMode to place on the synthesized events.
9667 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9669 * The real pointer window is the window that most recently received an enter notify
9670 * event. Windows that don't select for crossing events can't become the real
9671 * poiner window. The real pointer widget that owns the real pointer window. The
9672 * effective pointer window is the same as the real pointer window unless the real
9673 * pointer widget is either insensitive or there is a grab on a widget that is not
9674 * an ancestor of the real pointer widget (in which case the effective pointer
9675 * window should be the root window).
9677 * When the effective pointer window is the same as the real poiner window, we
9678 * receive crossing events from the windowing system. When the effective pointer
9679 * window changes to become different from the real pointer window we synthesize
9680 * crossing events, attempting to follow X protocol rules:
9682 * When the root window becomes the effective pointer window:
9683 * - leave notify on real pointer window, detail Ancestor
9684 * - leave notify on all of its ancestors, detail Virtual
9685 * - enter notify on root window, detail Inferior
9687 * When the root window ceases to be the effective pointer window:
9688 * - leave notify on root window, detail Inferior
9689 * - enter notify on all ancestors of real pointer window, detail Virtual
9690 * - enter notify on real pointer window, detail Ancestor
9693 _gtk_widget_synthesize_crossing (GtkWidget *from,
9696 GdkCrossingMode mode)
9698 GdkWindow *from_window = NULL, *to_window = NULL;
9700 g_return_if_fail (from != NULL || to != NULL);
9704 from_window = _gtk_widget_get_device_window (from, device);
9707 from_window = from->priv->window;
9712 to_window = _gtk_widget_get_device_window (to, device);
9715 to_window = to->priv->window;
9718 if (from_window == NULL && to_window == NULL)
9720 else if (from_window != NULL && to_window == NULL)
9722 GList *from_ancestors = NULL, *list;
9723 GdkWindow *from_ancestor = from_window;
9725 while (from_ancestor != NULL)
9727 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9728 if (from_ancestor == NULL)
9730 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9733 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9734 device, mode, GDK_NOTIFY_ANCESTOR);
9735 for (list = g_list_last (from_ancestors); list; list = list->prev)
9737 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9738 device, mode, GDK_NOTIFY_VIRTUAL);
9741 /* XXX: enter/inferior on root window? */
9743 g_list_free (from_ancestors);
9745 else if (from_window == NULL && to_window != NULL)
9747 GList *to_ancestors = NULL, *list;
9748 GdkWindow *to_ancestor = to_window;
9750 while (to_ancestor != NULL)
9752 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9753 if (to_ancestor == NULL)
9755 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9758 /* XXX: leave/inferior on root window? */
9760 for (list = to_ancestors; list; list = list->next)
9762 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9763 device, mode, GDK_NOTIFY_VIRTUAL);
9765 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9766 device, mode, GDK_NOTIFY_ANCESTOR);
9768 g_list_free (to_ancestors);
9770 else if (from_window == to_window)
9774 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9775 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9777 while (from_ancestor != NULL || to_ancestor != NULL)
9779 if (from_ancestor != NULL)
9781 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9782 if (from_ancestor == to_window)
9785 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9787 if (to_ancestor != NULL)
9789 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9790 if (to_ancestor == from_window)
9793 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9796 if (to_ancestor == from_window)
9798 if (mode != GDK_CROSSING_GTK_UNGRAB)
9799 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9800 device, mode, GDK_NOTIFY_INFERIOR);
9801 for (list = to_ancestors; list; list = list->next)
9802 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9803 device, mode, GDK_NOTIFY_VIRTUAL);
9804 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9805 device, mode, GDK_NOTIFY_ANCESTOR);
9807 else if (from_ancestor == to_window)
9809 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9810 device, mode, GDK_NOTIFY_ANCESTOR);
9811 for (list = g_list_last (from_ancestors); list; list = list->prev)
9813 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9814 device, mode, GDK_NOTIFY_VIRTUAL);
9816 if (mode != GDK_CROSSING_GTK_GRAB)
9817 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9818 device, mode, GDK_NOTIFY_INFERIOR);
9822 while (from_ancestors != NULL && to_ancestors != NULL
9823 && from_ancestors->data == to_ancestors->data)
9825 from_ancestors = g_list_delete_link (from_ancestors,
9827 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9830 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9831 device, mode, GDK_NOTIFY_NONLINEAR);
9833 for (list = g_list_last (from_ancestors); list; list = list->prev)
9835 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9836 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9838 for (list = to_ancestors; list; list = list->next)
9840 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9841 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9843 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9844 device, mode, GDK_NOTIFY_NONLINEAR);
9846 g_list_free (from_ancestors);
9847 g_list_free (to_ancestors);
9852 gtk_widget_propagate_state (GtkWidget *widget,
9855 GtkWidgetPrivate *priv = widget->priv;
9856 guint8 old_state = gtk_widget_get_state (widget);
9857 guint8 old_saved_state = priv->saved_state;
9859 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9860 * parent_sensitive==TRUE on a sensitive widget
9864 if (data->parent_sensitive)
9865 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9867 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9869 if (gtk_widget_is_sensitive (widget))
9871 if (data->state_restoration)
9872 priv->state = priv->saved_state;
9874 priv->state = data->state;
9878 if (!data->state_restoration)
9880 if (data->state != GTK_STATE_INSENSITIVE)
9881 priv->saved_state = data->state;
9883 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9884 priv->saved_state = gtk_widget_get_state (widget);
9885 priv->state = GTK_STATE_INSENSITIVE;
9888 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9892 window = gtk_widget_get_toplevel (widget);
9893 if (window && gtk_widget_is_toplevel (window))
9894 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9897 if (old_state != gtk_widget_get_state (widget) ||
9898 old_saved_state != priv->saved_state)
9900 g_object_ref (widget);
9902 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9903 gtk_grab_remove (widget);
9905 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9907 if (!GTK_WIDGET_SHADOWED (widget))
9909 GList *event_windows = NULL;
9912 devices = _gtk_widget_list_devices (widget);
9914 for (d = devices; d; d = d->next)
9920 window = _gtk_widget_get_device_window (widget, device);
9922 /* Do not propagate more than once to the
9923 * same window if non-multidevice aware.
9925 if (!gdk_window_get_support_multidevice (window) &&
9926 g_list_find (event_windows, window))
9929 if (!gtk_widget_is_sensitive (widget))
9930 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9931 GDK_CROSSING_STATE_CHANGED);
9932 else if (old_state == GTK_STATE_INSENSITIVE)
9933 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9934 GDK_CROSSING_STATE_CHANGED);
9936 event_windows = g_list_prepend (event_windows, window);
9939 g_list_free (event_windows);
9940 g_list_free (devices);
9943 if (GTK_IS_CONTAINER (widget))
9945 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9946 if (data->use_forall)
9947 gtk_container_forall (GTK_CONTAINER (widget),
9948 (GtkCallback) gtk_widget_propagate_state,
9951 gtk_container_foreach (GTK_CONTAINER (widget),
9952 (GtkCallback) gtk_widget_propagate_state,
9955 g_object_unref (widget);
9959 static const GtkWidgetAuxInfo default_aux_info = {
9967 * _gtk_widget_get_aux_info:
9968 * @widget: a #GtkWidget
9969 * @create: if %TRUE, create the structure if it doesn't exist
9971 * Get the #GtkWidgetAuxInfo structure for the widget.
9973 * Return value: the #GtkAuxInfo structure for the widget, or
9974 * %NULL if @create is %FALSE and one doesn't already exist.
9977 _gtk_widget_get_aux_info (GtkWidget *widget,
9980 GtkWidgetAuxInfo *aux_info;
9982 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9983 if (!aux_info && create)
9985 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9987 *aux_info = default_aux_info;
9989 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9995 static const GtkWidgetAuxInfo*
9996 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
9998 GtkWidgetAuxInfo *aux_info;
10000 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10001 if (aux_info == NULL)
10003 return &default_aux_info;
10011 /*****************************************
10012 * gtk_widget_aux_info_destroy:
10017 *****************************************/
10020 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10022 g_slice_free (GtkWidgetAuxInfo, aux_info);
10026 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
10028 g_object_unref (info->shape_mask);
10029 g_slice_free (GtkWidgetShapeInfo, info);
10033 * gtk_widget_shape_combine_mask:
10034 * @widget: a #GtkWidget
10035 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
10036 * @offset_x: X position of shape mask with respect to @window
10037 * @offset_y: Y position of shape mask with respect to @window
10039 * Sets a shape for this widget's GDK window. This allows for
10040 * transparent windows etc., see gdk_window_shape_combine_mask()
10041 * for more information.
10044 gtk_widget_shape_combine_mask (GtkWidget *widget,
10045 GdkBitmap *shape_mask,
10049 GtkWidgetPrivate *priv;
10050 GtkWidgetShapeInfo* shape_info;
10052 g_return_if_fail (GTK_IS_WIDGET (widget));
10053 /* set_shape doesn't work on widgets without gdk window */
10054 g_return_if_fail (gtk_widget_get_has_window (widget));
10056 priv = widget->priv;
10060 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10063 gdk_window_shape_combine_mask (priv->window, NULL, 0, 0);
10065 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10069 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10071 shape_info = g_slice_new (GtkWidgetShapeInfo);
10072 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
10073 (GDestroyNotify) gtk_widget_shape_info_destroy);
10075 shape_info->shape_mask = g_object_ref (shape_mask);
10076 shape_info->offset_x = offset_x;
10077 shape_info->offset_y = offset_y;
10079 /* set shape if widget has a gdk window already.
10080 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10083 gdk_window_shape_combine_mask (priv->window, shape_mask,
10084 offset_x, offset_y);
10089 * gtk_widget_input_shape_combine_mask:
10090 * @widget: a #GtkWidget
10091 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
10092 * @offset_x: X position of shape mask with respect to @window
10093 * @offset_y: Y position of shape mask with respect to @window
10095 * Sets an input shape for this widget's GDK window. This allows for
10096 * windows which react to mouse click in a nonrectangular region, see
10097 * gdk_window_input_shape_combine_mask() for more information.
10102 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
10103 GdkBitmap *shape_mask,
10107 GtkWidgetPrivate *priv;
10108 GtkWidgetShapeInfo* shape_info;
10110 g_return_if_fail (GTK_IS_WIDGET (widget));
10111 /* set_shape doesn't work on widgets without gdk window */
10112 g_return_if_fail (gtk_widget_get_has_window (widget));
10114 priv = widget->priv;
10119 gdk_window_input_shape_combine_mask (priv->window, NULL, 0, 0);
10121 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10125 shape_info = g_slice_new (GtkWidgetShapeInfo);
10126 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10128 (GDestroyNotify) gtk_widget_shape_info_destroy);
10130 shape_info->shape_mask = g_object_ref (shape_mask);
10131 shape_info->offset_x = offset_x;
10132 shape_info->offset_y = offset_y;
10134 /* set shape if widget has a gdk window already.
10135 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10138 gdk_window_input_shape_combine_mask (priv->window, shape_mask,
10139 offset_x, offset_y);
10145 gtk_reset_shapes_recurse (GtkWidget *widget,
10151 gdk_window_get_user_data (window, &data);
10152 if (data != widget)
10155 gdk_window_shape_combine_mask (window, NULL, 0, 0);
10156 for (list = gdk_window_peek_children (window); list; list = list->next)
10157 gtk_reset_shapes_recurse (widget, list->data);
10161 * gtk_widget_reset_shapes:
10162 * @widget: a #GtkWidget
10164 * Recursively resets the shape on this widget and its descendants.
10167 gtk_widget_reset_shapes (GtkWidget *widget)
10169 GtkWidgetPrivate *priv;
10171 g_return_if_fail (GTK_IS_WIDGET (widget));
10172 g_return_if_fail (gtk_widget_get_realized (widget));
10174 priv = widget->priv;
10176 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10177 gtk_reset_shapes_recurse (widget, priv->window);
10181 expose_window (GdkWindow *window)
10184 GList *l, *children;
10185 gpointer user_data;
10186 gboolean is_double_buffered;
10188 gdk_window_get_user_data (window, &user_data);
10191 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
10193 is_double_buffered = FALSE;
10195 event.expose.type = GDK_EXPOSE;
10196 event.expose.window = g_object_ref (window);
10197 event.expose.send_event = FALSE;
10198 event.expose.count = 0;
10199 event.expose.area.x = 0;
10200 event.expose.area.y = 0;
10201 gdk_drawable_get_size (GDK_DRAWABLE (window),
10202 &event.expose.area.width,
10203 &event.expose.area.height);
10204 event.expose.region = cairo_region_create_rectangle (&event.expose.area);
10206 /* If this is not double buffered, force a double buffer so that
10207 redirection works. */
10208 if (!is_double_buffered)
10209 gdk_window_begin_paint_region (window, event.expose.region);
10211 gtk_main_do_event (&event);
10213 if (!is_double_buffered)
10214 gdk_window_end_paint (window);
10216 children = gdk_window_peek_children (window);
10217 for (l = children; l != NULL; l = l->next)
10219 GdkWindow *child = l->data;
10221 /* Don't expose input-only windows */
10222 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
10223 expose_window (l->data);
10226 g_object_unref (window);
10230 * gtk_widget_get_snapshot:
10231 * @widget: a #GtkWidget
10232 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
10234 * Create a #GdkPixmap of the contents of the widget and its children.
10236 * Works even if the widget is obscured. The depth and visual of the
10237 * resulting pixmap is dependent on the widget being snapshot and likely
10238 * differs from those of a target widget displaying the pixmap.
10239 * The function gdk_pixbuf_get_from_drawable() can be used to convert
10240 * the pixmap to a visual independant representation.
10242 * The snapshot area used by this function is the @widget's allocation plus
10243 * any extra space occupied by additional windows belonging to this widget
10244 * (such as the arrows of a spin button).
10245 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
10247 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
10248 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
10249 * interpreted widget relative. If width or height of @clip_rect are 0 or
10250 * negative, the width or height of the resulting pixmap will be shrunken
10251 * by the respective amount.
10252 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
10253 * chop off 5 pixels at each side of the snapshot pixmap.
10254 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
10255 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
10256 * can be used to preserve the auto-grown snapshot area and use @clip_rect
10257 * as a pure output parameter.
10259 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
10261 * Return value: #GdkPixmap snapshot of the widget
10266 gtk_widget_get_snapshot (GtkWidget *widget,
10267 GdkRectangle *clip_rect)
10269 GtkWidgetPrivate *priv;
10270 int x, y, width, height;
10271 GdkWindow *parent_window = NULL;
10273 GList *windows = NULL, *list;
10275 priv = widget->priv;
10277 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10278 if (!gtk_widget_get_visible (widget))
10281 /* the widget (and parent_window) must be realized to be drawable */
10282 if (priv->parent && !gtk_widget_get_realized (priv->parent))
10283 gtk_widget_realize (priv->parent);
10284 if (!gtk_widget_get_realized (widget))
10285 gtk_widget_realize (widget);
10287 /* determine snapshot rectangle */
10288 x = priv->allocation.x;
10289 y = priv->allocation.y;
10290 width = priv->allocation.width;
10291 height = priv->allocation.height;
10293 if (priv->parent && gtk_widget_get_has_window (widget))
10295 /* grow snapshot rectangle to cover all widget windows */
10296 parent_window = gtk_widget_get_parent_window (widget);
10297 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
10299 GdkWindow *subwin = list->data;
10301 int wx, wy, ww, wh;
10302 gdk_window_get_user_data (subwin, &windata);
10303 if (windata != widget)
10305 windows = g_list_prepend (windows, subwin);
10306 gdk_window_get_position (subwin, &wx, &wy);
10307 gdk_drawable_get_size (subwin, &ww, &wh);
10308 /* grow snapshot rectangle by extra widget sub window */
10319 if (x + width < wx + ww)
10320 width += wx + ww - (x + width);
10321 if (y + height < wy + wh)
10322 height += wy + wh - (y + height);
10325 else if (!priv->parent)
10326 x = y = 0; /* toplevel */
10328 /* at this point, (x,y,width,height) is the parent_window relative
10329 * snapshot area covering all of widget's windows.
10332 /* shrink snapshot size by clip_rectangle */
10335 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
10336 clip.x = clip.x < 0 ? x : clip.x;
10337 clip.y = clip.y < 0 ? y : clip.y;
10338 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
10339 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
10342 /* offset clip_rect, so it's parent_window relative */
10343 if (clip_rect->x >= 0)
10344 clip.x += priv->allocation.x;
10345 if (clip_rect->y >= 0)
10346 clip.y += priv->allocation.y;
10348 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
10350 g_list_free (windows);
10351 clip_rect->width = clip_rect->height = 0;
10352 return NULL; /* empty snapshot area */
10356 width = snap.width;
10357 height = snap.height;
10360 /* render snapshot */
10361 pixmap = gdk_pixmap_new (priv->window, width, height, gdk_drawable_get_depth (priv->window));
10362 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
10364 GdkWindow *subwin = list->data;
10366 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
10367 continue; /* Input only window */
10368 gdk_window_get_position (subwin, &wx, &wy);
10369 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
10370 MAX (0, wx - x), MAX (0, wy - y), width, height);
10372 expose_window (subwin);
10374 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == priv->window */
10376 gdk_window_redirect_to_drawable (priv->window, pixmap, x, y, 0, 0, width, height);
10377 expose_window (priv->window);
10379 for (list = windows; list; list = list->next)
10380 gdk_window_remove_redirection (list->data);
10381 if (!windows) /* NO_WINDOW || toplevel */
10382 gdk_window_remove_redirection (priv->window);
10383 g_list_free (windows);
10385 /* return pixmap and snapshot rectangle coordinates */
10390 clip_rect->width = width;
10391 clip_rect->height = height;
10394 /* offset clip_rect from parent_window so it's widget relative */
10395 clip_rect->x -= priv->allocation.x;
10396 clip_rect->y -= priv->allocation.y;
10399 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
10400 G_OBJECT_TYPE_NAME (widget),
10401 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
10406 /* style properties
10410 * gtk_widget_class_install_style_property_parser:
10411 * @klass: a #GtkWidgetClass
10412 * @pspec: the #GParamSpec for the style property
10413 * @parser: the parser for the style property
10415 * Installs a style property on a widget class.
10418 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10420 GtkRcPropertyParser parser)
10422 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10423 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10424 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10425 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10427 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10429 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10430 G_OBJECT_CLASS_NAME (klass),
10435 g_param_spec_ref_sink (pspec);
10436 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10437 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10441 * gtk_widget_class_install_style_property:
10442 * @klass: a #GtkWidgetClass
10443 * @pspec: the #GParamSpec for the property
10445 * Installs a style property on a widget class. The parser for the
10446 * style property is determined by the value type of @pspec.
10449 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10452 GtkRcPropertyParser parser;
10454 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10455 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10457 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10459 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10463 * gtk_widget_class_find_style_property:
10464 * @klass: a #GtkWidgetClass
10465 * @property_name: the name of the style property to find
10466 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10467 * style property with that name.
10469 * Finds a style property of a widget class by name.
10474 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10475 const gchar *property_name)
10477 g_return_val_if_fail (property_name != NULL, NULL);
10479 return g_param_spec_pool_lookup (style_property_spec_pool,
10481 G_OBJECT_CLASS_TYPE (klass),
10486 * gtk_widget_class_list_style_properties:
10487 * @klass: a #GtkWidgetClass
10488 * @n_properties: location to return the number of style properties found
10489 * @returns: an newly allocated array of #GParamSpec*. The array must
10490 * be freed with g_free().
10492 * Returns all style properties of a widget class.
10497 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10498 guint *n_properties)
10500 GParamSpec **pspecs;
10503 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10504 G_OBJECT_CLASS_TYPE (klass),
10513 * gtk_widget_style_get_property:
10514 * @widget: a #GtkWidget
10515 * @property_name: the name of a style property
10516 * @value: location to return the property value
10518 * Gets the value of a style property of @widget.
10521 gtk_widget_style_get_property (GtkWidget *widget,
10522 const gchar *property_name,
10525 GtkWidgetPrivate *priv;
10528 g_return_if_fail (GTK_IS_WIDGET (widget));
10529 g_return_if_fail (property_name != NULL);
10530 g_return_if_fail (G_IS_VALUE (value));
10532 priv = widget->priv;
10534 g_object_ref (widget);
10535 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10537 G_OBJECT_TYPE (widget),
10540 g_warning ("%s: widget class `%s' has no property named `%s'",
10542 G_OBJECT_TYPE_NAME (widget),
10546 const GValue *peek_value;
10548 peek_value = _gtk_style_peek_property_value (priv->style,
10549 G_OBJECT_TYPE (widget),
10551 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10553 /* auto-conversion of the caller's value type
10555 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10556 g_value_copy (peek_value, value);
10557 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10558 g_value_transform (peek_value, value);
10560 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10562 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10563 G_VALUE_TYPE_NAME (value));
10565 g_object_unref (widget);
10569 * gtk_widget_style_get_valist:
10570 * @widget: a #GtkWidget
10571 * @first_property_name: the name of the first property to get
10572 * @var_args: a <type>va_list</type> of pairs of property names and
10573 * locations to return the property values, starting with the location
10574 * for @first_property_name.
10576 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10580 gtk_widget_style_get_valist (GtkWidget *widget,
10581 const gchar *first_property_name,
10584 GtkWidgetPrivate *priv;
10587 g_return_if_fail (GTK_IS_WIDGET (widget));
10589 priv = widget->priv;
10591 g_object_ref (widget);
10593 name = first_property_name;
10596 const GValue *peek_value;
10600 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10602 G_OBJECT_TYPE (widget),
10606 g_warning ("%s: widget class `%s' has no property named `%s'",
10608 G_OBJECT_TYPE_NAME (widget),
10612 /* style pspecs are always readable so we can spare that check here */
10614 peek_value = _gtk_style_peek_property_value (priv->style,
10615 G_OBJECT_TYPE (widget),
10617 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10618 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10621 g_warning ("%s: %s", G_STRLOC, error);
10626 name = va_arg (var_args, gchar*);
10629 g_object_unref (widget);
10633 * gtk_widget_style_get:
10634 * @widget: a #GtkWidget
10635 * @first_property_name: the name of the first property to get
10636 * @Varargs: pairs of property names and locations to
10637 * return the property values, starting with the location for
10638 * @first_property_name, terminated by %NULL.
10640 * Gets the values of a multiple style properties of @widget.
10643 gtk_widget_style_get (GtkWidget *widget,
10644 const gchar *first_property_name,
10649 g_return_if_fail (GTK_IS_WIDGET (widget));
10651 va_start (var_args, first_property_name);
10652 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10658 * @widget: a #GtkWidget
10659 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10660 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10661 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10663 * Obtains the full path to @widget. The path is simply the name of a
10664 * widget and all its parents in the container hierarchy, separated by
10665 * periods. The name of a widget comes from
10666 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10667 * in gtkrc configuration files. Widget names are the type of the
10668 * widget by default (e.g. "GtkButton") or can be set to an
10669 * application-specific value with gtk_widget_set_name(). By setting
10670 * the name of a widget, you allow users or theme authors to apply
10671 * styles to that specific widget in their gtkrc
10672 * file. @path_reversed_p fills in the path in reverse order,
10673 * i.e. starting with @widget's name instead of starting with the name
10674 * of @widget's outermost ancestor.
10677 gtk_widget_path (GtkWidget *widget,
10678 guint *path_length,
10680 gchar **path_reversed)
10682 static gchar *rev_path = NULL;
10683 static guint tmp_path_len = 0;
10686 g_return_if_fail (GTK_IS_WIDGET (widget));
10691 const gchar *string;
10696 string = gtk_widget_get_name (widget);
10697 l = strlen (string);
10698 while (tmp_path_len <= len + l + 1)
10700 tmp_path_len += INIT_PATH_SIZE;
10701 rev_path = g_realloc (rev_path, tmp_path_len);
10703 s = string + l - 1;
10704 d = rev_path + len;
10705 while (s >= string)
10709 widget = widget->priv->parent;
10712 rev_path[len++] = '.';
10714 rev_path[len++] = 0;
10719 *path_length = len - 1;
10721 *path_reversed = g_strdup (rev_path);
10724 *path = g_strdup (rev_path);
10725 g_strreverse (*path);
10730 * gtk_widget_class_path:
10731 * @widget: a #GtkWidget
10732 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10733 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10734 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10737 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10738 * never uses a custom name set with gtk_widget_set_name().
10742 gtk_widget_class_path (GtkWidget *widget,
10743 guint *path_length,
10745 gchar **path_reversed)
10747 static gchar *rev_path = NULL;
10748 static guint tmp_path_len = 0;
10751 g_return_if_fail (GTK_IS_WIDGET (widget));
10756 const gchar *string;
10761 string = g_type_name (G_OBJECT_TYPE (widget));
10762 l = strlen (string);
10763 while (tmp_path_len <= len + l + 1)
10765 tmp_path_len += INIT_PATH_SIZE;
10766 rev_path = g_realloc (rev_path, tmp_path_len);
10768 s = string + l - 1;
10769 d = rev_path + len;
10770 while (s >= string)
10774 widget = widget->priv->parent;
10777 rev_path[len++] = '.';
10779 rev_path[len++] = 0;
10784 *path_length = len - 1;
10786 *path_reversed = g_strdup (rev_path);
10789 *path = g_strdup (rev_path);
10790 g_strreverse (*path);
10795 * gtk_requisition_new:
10797 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10799 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10800 * be freed with gtk_requisition_free().
10805 gtk_requisition_new (void)
10807 return g_slice_new0 (GtkRequisition);
10811 * gtk_requisition_copy:
10812 * @requisition: a #GtkRequisition
10814 * Copies a #GtkRequisition.
10816 * Returns: a copy of @requisition
10819 gtk_requisition_copy (const GtkRequisition *requisition)
10821 return g_slice_dup (GtkRequisition, requisition);
10825 * gtk_requisition_free:
10826 * @requisition: a #GtkRequisition
10828 * Frees a #GtkRequisition.
10831 gtk_requisition_free (GtkRequisition *requisition)
10833 g_slice_free (GtkRequisition, requisition);
10836 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10837 gtk_requisition_copy,
10838 gtk_requisition_free)
10841 * gtk_widget_get_accessible:
10842 * @widget: a #GtkWidget
10844 * Returns the accessible object that describes the widget to an
10845 * assistive technology.
10847 * If no accessibility library is loaded (i.e. no ATK implementation library is
10848 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10849 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10850 * if no class-specific #AtkObject implementation is available for the widget
10851 * instance in question, it will inherit an #AtkObject implementation from the
10852 * first ancestor class for which such an implementation is defined.
10854 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10855 * library contains more information about accessible objects and their uses.
10857 * Returns: (transfer none): the #AtkObject associated with @widget
10860 gtk_widget_get_accessible (GtkWidget *widget)
10862 GtkWidgetClass *klass;
10864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10866 klass = GTK_WIDGET_GET_CLASS (widget);
10868 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10870 return klass->get_accessible (widget);
10874 gtk_widget_real_get_accessible (GtkWidget *widget)
10876 AtkObject* accessible;
10878 accessible = g_object_get_qdata (G_OBJECT (widget),
10879 quark_accessible_object);
10882 AtkObjectFactory *factory;
10883 AtkRegistry *default_registry;
10885 default_registry = atk_get_default_registry ();
10886 factory = atk_registry_get_factory (default_registry,
10887 G_TYPE_FROM_INSTANCE (widget));
10889 atk_object_factory_create_accessible (factory,
10890 G_OBJECT (widget));
10891 g_object_set_qdata (G_OBJECT (widget),
10892 quark_accessible_object,
10899 * Initialize a AtkImplementorIface instance's virtual pointers as
10900 * appropriate to this implementor's class (GtkWidget).
10903 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10905 iface->ref_accessible = gtk_widget_ref_accessible;
10909 gtk_widget_ref_accessible (AtkImplementor *implementor)
10911 AtkObject *accessible;
10913 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10915 g_object_ref (accessible);
10920 * GtkBuildable implementation
10922 static GQuark quark_builder_has_default = 0;
10923 static GQuark quark_builder_has_focus = 0;
10924 static GQuark quark_builder_atk_relations = 0;
10925 static GQuark quark_builder_set_name = 0;
10928 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10930 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10931 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10932 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10933 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10935 iface->set_name = gtk_widget_buildable_set_name;
10936 iface->get_name = gtk_widget_buildable_get_name;
10937 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10938 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10939 iface->parser_finished = gtk_widget_buildable_parser_finished;
10940 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10941 iface->custom_finished = gtk_widget_buildable_custom_finished;
10945 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10948 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10949 g_strdup (name), g_free);
10952 static const gchar *
10953 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10955 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10959 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10960 GtkBuilder *builder,
10961 const gchar *childname)
10963 if (strcmp (childname, "accessible") == 0)
10964 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10970 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10971 GtkBuilder *builder,
10973 const GValue *value)
10975 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10976 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10977 GINT_TO_POINTER (TRUE));
10978 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10979 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10980 GINT_TO_POINTER (TRUE));
10982 g_object_set_property (G_OBJECT (buildable), name, value);
10987 gchar *action_name;
10988 GString *description;
10990 gboolean translatable;
11000 free_action (AtkActionData *data, gpointer user_data)
11002 g_free (data->action_name);
11003 g_string_free (data->description, TRUE);
11004 g_free (data->context);
11005 g_slice_free (AtkActionData, data);
11009 free_relation (AtkRelationData *data, gpointer user_data)
11011 g_free (data->target);
11012 g_free (data->type);
11013 g_slice_free (AtkRelationData, data);
11017 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11018 GtkBuilder *builder)
11020 GSList *atk_relations;
11022 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11023 gtk_widget_grab_default (GTK_WIDGET (buildable));
11024 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11025 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11027 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11028 quark_builder_atk_relations);
11031 AtkObject *accessible;
11032 AtkRelationSet *relation_set;
11035 AtkRelationType relation_type;
11036 AtkObject *target_accessible;
11038 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11039 relation_set = atk_object_ref_relation_set (accessible);
11041 for (l = atk_relations; l; l = l->next)
11043 AtkRelationData *relation = (AtkRelationData*)l->data;
11045 target = gtk_builder_get_object (builder, relation->target);
11048 g_warning ("Target object %s in <relation> does not exist",
11052 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11053 g_assert (target_accessible != NULL);
11055 relation_type = atk_relation_type_for_name (relation->type);
11056 if (relation_type == ATK_RELATION_NULL)
11058 g_warning ("<relation> type %s not found",
11062 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11063 target_accessible);
11065 g_object_unref (relation_set);
11067 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11068 g_slist_free (atk_relations);
11069 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11078 } AccessibilitySubParserData;
11081 accessibility_start_element (GMarkupParseContext *context,
11082 const gchar *element_name,
11083 const gchar **names,
11084 const gchar **values,
11085 gpointer user_data,
11088 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11090 gint line_number, char_number;
11092 if (strcmp (element_name, "relation") == 0)
11094 gchar *target = NULL;
11095 gchar *type = NULL;
11096 AtkRelationData *relation;
11098 for (i = 0; names[i]; i++)
11100 if (strcmp (names[i], "target") == 0)
11101 target = g_strdup (values[i]);
11102 else if (strcmp (names[i], "type") == 0)
11103 type = g_strdup (values[i]);
11106 g_markup_parse_context_get_position (context,
11109 g_set_error (error,
11111 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11112 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11114 line_number, char_number, names[i], "relation");
11121 if (!target || !type)
11123 g_markup_parse_context_get_position (context,
11126 g_set_error (error,
11128 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11129 "%s:%d:%d <%s> requires attribute \"%s\"",
11131 line_number, char_number, "relation",
11132 type ? "target" : "type");
11138 relation = g_slice_new (AtkRelationData);
11139 relation->target = target;
11140 relation->type = type;
11142 data->relations = g_slist_prepend (data->relations, relation);
11144 else if (strcmp (element_name, "action") == 0)
11146 const gchar *action_name = NULL;
11147 const gchar *description = NULL;
11148 const gchar *msg_context = NULL;
11149 gboolean translatable = FALSE;
11150 AtkActionData *action;
11152 for (i = 0; names[i]; i++)
11154 if (strcmp (names[i], "action_name") == 0)
11155 action_name = values[i];
11156 else if (strcmp (names[i], "description") == 0)
11157 description = values[i];
11158 else if (strcmp (names[i], "translatable") == 0)
11160 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11163 else if (strcmp (names[i], "comments") == 0)
11165 /* do nothing, comments are for translators */
11167 else if (strcmp (names[i], "context") == 0)
11168 msg_context = values[i];
11171 g_markup_parse_context_get_position (context,
11174 g_set_error (error,
11176 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11177 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11179 line_number, char_number, names[i], "action");
11186 g_markup_parse_context_get_position (context,
11189 g_set_error (error,
11191 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11192 "%s:%d:%d <%s> requires attribute \"%s\"",
11194 line_number, char_number, "action",
11199 action = g_slice_new (AtkActionData);
11200 action->action_name = g_strdup (action_name);
11201 action->description = g_string_new (description);
11202 action->context = g_strdup (msg_context);
11203 action->translatable = translatable;
11205 data->actions = g_slist_prepend (data->actions, action);
11207 else if (strcmp (element_name, "accessibility") == 0)
11210 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11214 accessibility_text (GMarkupParseContext *context,
11217 gpointer user_data,
11220 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11222 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11224 AtkActionData *action = data->actions->data;
11226 g_string_append_len (action->description, text, text_len);
11230 static const GMarkupParser accessibility_parser =
11232 accessibility_start_element,
11234 accessibility_text,
11243 } AccelGroupParserData;
11246 accel_group_start_element (GMarkupParseContext *context,
11247 const gchar *element_name,
11248 const gchar **names,
11249 const gchar **values,
11250 gpointer user_data,
11255 guint modifiers = 0;
11256 gchar *signal = NULL;
11257 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11259 for (i = 0; names[i]; i++)
11261 if (strcmp (names[i], "key") == 0)
11262 key = gdk_keyval_from_name (values[i]);
11263 else if (strcmp (names[i], "modifiers") == 0)
11265 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11271 else if (strcmp (names[i], "signal") == 0)
11272 signal = g_strdup (values[i]);
11275 if (key == 0 || signal == NULL)
11277 g_warning ("<accelerator> requires key and signal attributes");
11280 parser_data->key = key;
11281 parser_data->modifiers = modifiers;
11282 parser_data->signal = signal;
11285 static const GMarkupParser accel_group_parser =
11287 accel_group_start_element,
11291 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11292 GtkBuilder *builder,
11294 const gchar *tagname,
11295 GMarkupParser *parser,
11298 g_assert (buildable);
11300 if (strcmp (tagname, "accelerator") == 0)
11302 AccelGroupParserData *parser_data;
11304 parser_data = g_slice_new0 (AccelGroupParserData);
11305 parser_data->object = g_object_ref (buildable);
11306 *parser = accel_group_parser;
11307 *data = parser_data;
11310 if (strcmp (tagname, "accessibility") == 0)
11312 AccessibilitySubParserData *parser_data;
11314 parser_data = g_slice_new0 (AccessibilitySubParserData);
11315 *parser = accessibility_parser;
11316 *data = parser_data;
11323 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11324 GtkWidget *toplevel,
11325 gpointer user_data)
11327 AccelGroupParserData *accel_data;
11328 GSList *accel_groups;
11329 GtkAccelGroup *accel_group;
11331 g_return_if_fail (GTK_IS_WIDGET (widget));
11332 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11333 g_return_if_fail (user_data != NULL);
11335 accel_data = (AccelGroupParserData*)user_data;
11336 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11337 if (g_slist_length (accel_groups) == 0)
11339 accel_group = gtk_accel_group_new ();
11340 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11344 g_assert (g_slist_length (accel_groups) == 1);
11345 accel_group = g_slist_nth_data (accel_groups, 0);
11348 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11349 accel_data->signal,
11352 accel_data->modifiers,
11353 GTK_ACCEL_VISIBLE);
11355 g_object_unref (accel_data->object);
11356 g_free (accel_data->signal);
11357 g_slice_free (AccelGroupParserData, accel_data);
11361 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11362 GtkBuilder *builder,
11364 const gchar *tagname,
11365 gpointer user_data)
11367 AccelGroupParserData *accel_data;
11368 AccessibilitySubParserData *a11y_data;
11369 GtkWidget *toplevel;
11371 if (strcmp (tagname, "accelerator") == 0)
11373 accel_data = (AccelGroupParserData*)user_data;
11374 g_assert (accel_data->object);
11376 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11378 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11380 else if (strcmp (tagname, "accessibility") == 0)
11382 a11y_data = (AccessibilitySubParserData*)user_data;
11384 if (a11y_data->actions)
11386 AtkObject *accessible;
11391 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11393 action = ATK_ACTION (accessible);
11394 n_actions = atk_action_get_n_actions (action);
11396 for (l = a11y_data->actions; l; l = l->next)
11398 AtkActionData *action_data = (AtkActionData*)l->data;
11400 for (i = 0; i < n_actions; i++)
11401 if (strcmp (atk_action_get_name (action, i),
11402 action_data->action_name) == 0)
11407 gchar *description;
11409 if (action_data->translatable && action_data->description->len)
11410 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11411 action_data->context,
11412 action_data->description->str);
11414 description = action_data->description->str;
11416 atk_action_set_description (action, i, description);
11420 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11421 g_slist_free (a11y_data->actions);
11424 if (a11y_data->relations)
11425 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11426 a11y_data->relations);
11428 g_slice_free (AccessibilitySubParserData, a11y_data);
11433 * GtkSizeRequest implementation
11436 gtk_widget_real_get_width (GtkSizeRequest *widget,
11437 gint *minimum_size,
11438 gint *natural_size)
11448 gtk_widget_real_get_height (GtkSizeRequest *widget,
11449 gint *minimum_size,
11450 gint *natural_size)
11460 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11462 gint *minimum_height,
11463 gint *natural_height)
11465 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11469 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11471 gint *minimum_width,
11472 gint *natural_width)
11474 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11478 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11480 iface->get_width = gtk_widget_real_get_width;
11481 iface->get_height = gtk_widget_real_get_height;
11482 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11483 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
11487 gtk_widget_get_h_align (GtkWidget *widget)
11489 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11490 return _gtk_widget_get_aux_info_or_defaults (widget)->h_align;
11494 gtk_widget_set_h_align (GtkWidget *widget,
11497 GtkWidgetAuxInfo *aux_info;
11499 g_return_if_fail (GTK_IS_WIDGET (widget));
11501 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11503 if (aux_info->h_align == align)
11506 aux_info->h_align = align;
11507 gtk_widget_queue_resize (widget);
11508 g_object_notify (G_OBJECT (widget), "h-align");
11512 gtk_widget_get_v_align (GtkWidget *widget)
11514 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11515 return _gtk_widget_get_aux_info_or_defaults (widget)->v_align;
11519 gtk_widget_set_v_align (GtkWidget *widget,
11522 GtkWidgetAuxInfo *aux_info;
11524 g_return_if_fail (GTK_IS_WIDGET (widget));
11526 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11528 if (aux_info->v_align == align)
11531 aux_info->v_align = align;
11532 gtk_widget_queue_resize (widget);
11533 g_object_notify (G_OBJECT (widget), "v-align");
11537 gtk_widget_get_margin_left (GtkWidget *widget)
11539 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11541 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11545 gtk_widget_set_margin_left (GtkWidget *widget,
11548 GtkWidgetAuxInfo *aux_info;
11550 g_return_if_fail (GTK_IS_WIDGET (widget));
11551 g_return_if_fail (margin <= G_MAXINT16);
11553 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11555 if (aux_info->margin.left == margin)
11558 aux_info->margin.left = margin;
11559 gtk_widget_queue_resize (widget);
11560 g_object_notify (G_OBJECT (widget), "margin-left");
11564 gtk_widget_get_margin_right (GtkWidget *widget)
11566 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11568 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11572 gtk_widget_set_margin_right (GtkWidget *widget,
11575 GtkWidgetAuxInfo *aux_info;
11577 g_return_if_fail (GTK_IS_WIDGET (widget));
11578 g_return_if_fail (margin <= G_MAXINT16);
11580 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11582 if (aux_info->margin.right == margin)
11585 aux_info->margin.right = margin;
11586 gtk_widget_queue_resize (widget);
11587 g_object_notify (G_OBJECT (widget), "margin-right");
11591 gtk_widget_get_margin_top (GtkWidget *widget)
11593 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11595 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11599 gtk_widget_set_margin_top (GtkWidget *widget,
11602 GtkWidgetAuxInfo *aux_info;
11604 g_return_if_fail (GTK_IS_WIDGET (widget));
11605 g_return_if_fail (margin <= G_MAXINT16);
11607 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11609 if (aux_info->margin.top == margin)
11612 aux_info->margin.top = margin;
11613 gtk_widget_queue_resize (widget);
11614 g_object_notify (G_OBJECT (widget), "margin-top");
11618 gtk_widget_get_margin_bottom (GtkWidget *widget)
11620 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11622 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11626 gtk_widget_set_margin_bottom (GtkWidget *widget,
11629 GtkWidgetAuxInfo *aux_info;
11631 g_return_if_fail (GTK_IS_WIDGET (widget));
11632 g_return_if_fail (margin <= G_MAXINT16);
11634 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11636 if (aux_info->margin.bottom == margin)
11639 aux_info->margin.bottom = margin;
11640 gtk_widget_queue_resize (widget);
11641 g_object_notify (G_OBJECT (widget), "margin-bottom");
11645 * gtk_widget_get_clipboard:
11646 * @widget: a #GtkWidget
11647 * @selection: a #GdkAtom which identifies the clipboard
11648 * to use. %GDK_SELECTION_CLIPBOARD gives the
11649 * default clipboard. Another common value
11650 * is %GDK_SELECTION_PRIMARY, which gives
11651 * the primary X selection.
11653 * Returns the clipboard object for the given selection to
11654 * be used with @widget. @widget must have a #GdkDisplay
11655 * associated with it, so must be attached to a toplevel
11658 * Return value: (transfer none): the appropriate clipboard object. If no
11659 * clipboard already exists, a new one will
11660 * be created. Once a clipboard object has
11661 * been created, it is persistent for all time.
11666 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11668 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11669 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11671 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11676 * gtk_widget_list_mnemonic_labels:
11677 * @widget: a #GtkWidget
11679 * Returns a newly allocated list of the widgets, normally labels, for
11680 * which this widget is the target of a mnemonic (see for example,
11681 * gtk_label_set_mnemonic_widget()).
11683 * The widgets in the list are not individually referenced. If you
11684 * want to iterate through the list and perform actions involving
11685 * callbacks that might destroy the widgets, you
11686 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11687 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11688 * widgets afterwards.
11690 * Return value: (element-type GtkWidget) (transfer container): the list of
11691 * mnemonic labels; free this list
11692 * with g_list_free() when you are done with it.
11697 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11699 GList *list = NULL;
11702 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11704 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11705 list = g_list_prepend (list, l->data);
11711 * gtk_widget_add_mnemonic_label:
11712 * @widget: a #GtkWidget
11713 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11715 * Adds a widget to the list of mnemonic labels for
11716 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11717 * list of mnemonic labels for the widget is cleared when the
11718 * widget is destroyed, so the caller must make sure to update
11719 * its internal state at this point as well, by using a connection
11720 * to the #GtkWidget::destroy signal or a weak notifier.
11725 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11728 GSList *old_list, *new_list;
11730 g_return_if_fail (GTK_IS_WIDGET (widget));
11731 g_return_if_fail (GTK_IS_WIDGET (label));
11733 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11734 new_list = g_slist_prepend (old_list, label);
11736 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11737 new_list, (GDestroyNotify) g_slist_free);
11741 * gtk_widget_remove_mnemonic_label:
11742 * @widget: a #GtkWidget
11743 * @label: a #GtkWidget that was previously set as a mnemnic label for
11744 * @widget with gtk_widget_add_mnemonic_label().
11746 * Removes a widget from the list of mnemonic labels for
11747 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11748 * must have previously been added to the list with
11749 * gtk_widget_add_mnemonic_label().
11754 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11757 GSList *old_list, *new_list;
11759 g_return_if_fail (GTK_IS_WIDGET (widget));
11760 g_return_if_fail (GTK_IS_WIDGET (label));
11762 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11763 new_list = g_slist_remove (old_list, label);
11766 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11767 new_list, (GDestroyNotify) g_slist_free);
11771 * gtk_widget_get_no_show_all:
11772 * @widget: a #GtkWidget
11774 * Returns the current value of the GtkWidget:no-show-all property,
11775 * which determines whether calls to gtk_widget_show_all() and
11776 * gtk_widget_hide_all() will affect this widget.
11778 * Return value: the current value of the "no-show-all" property.
11783 gtk_widget_get_no_show_all (GtkWidget *widget)
11785 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11787 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11791 * gtk_widget_set_no_show_all:
11792 * @widget: a #GtkWidget
11793 * @no_show_all: the new value for the "no-show-all" property
11795 * Sets the #GtkWidget:no-show-all property, which determines whether
11796 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11799 * This is mostly for use in constructing widget hierarchies with externally
11800 * controlled visibility, see #GtkUIManager.
11805 gtk_widget_set_no_show_all (GtkWidget *widget,
11806 gboolean no_show_all)
11808 g_return_if_fail (GTK_IS_WIDGET (widget));
11810 no_show_all = (no_show_all != FALSE);
11812 if (no_show_all == gtk_widget_get_no_show_all (widget))
11816 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11818 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11820 g_object_notify (G_OBJECT (widget), "no-show-all");
11825 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11826 gboolean has_tooltip,
11829 GtkWidgetPrivate *priv = widget->priv;
11830 gboolean priv_has_tooltip;
11832 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11833 quark_has_tooltip));
11835 if (priv_has_tooltip != has_tooltip || force)
11837 priv_has_tooltip = has_tooltip;
11839 if (priv_has_tooltip)
11841 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11842 gdk_window_set_events (priv->window,
11843 gdk_window_get_events (priv->window) |
11844 GDK_LEAVE_NOTIFY_MASK |
11845 GDK_POINTER_MOTION_MASK |
11846 GDK_POINTER_MOTION_HINT_MASK);
11848 if (gtk_widget_get_has_window (widget))
11849 gtk_widget_add_events (widget,
11850 GDK_LEAVE_NOTIFY_MASK |
11851 GDK_POINTER_MOTION_MASK |
11852 GDK_POINTER_MOTION_HINT_MASK);
11855 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11856 GUINT_TO_POINTER (priv_has_tooltip));
11861 * gtk_widget_set_tooltip_window:
11862 * @widget: a #GtkWidget
11863 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11865 * Replaces the default, usually yellow, window used for displaying
11866 * tooltips with @custom_window. GTK+ will take care of showing and
11867 * hiding @custom_window at the right moment, to behave likewise as
11868 * the default tooltip window. If @custom_window is %NULL, the default
11869 * tooltip window will be used.
11871 * If the custom window should have the default theming it needs to
11872 * have the name "gtk-tooltip", see gtk_widget_set_name().
11877 gtk_widget_set_tooltip_window (GtkWidget *widget,
11878 GtkWindow *custom_window)
11880 gboolean has_tooltip;
11881 gchar *tooltip_markup;
11883 g_return_if_fail (GTK_IS_WIDGET (widget));
11884 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11886 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11889 g_object_ref (custom_window);
11891 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11892 custom_window, g_object_unref);
11894 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11895 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11897 if (has_tooltip && gtk_widget_get_visible (widget))
11898 gtk_widget_queue_tooltip_query (widget);
11902 * gtk_widget_get_tooltip_window:
11903 * @widget: a #GtkWidget
11905 * Returns the #GtkWindow of the current tooltip. This can be the
11906 * GtkWindow created by default, or the custom tooltip window set
11907 * using gtk_widget_set_tooltip_window().
11909 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11914 gtk_widget_get_tooltip_window (GtkWidget *widget)
11916 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11918 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11922 * gtk_widget_trigger_tooltip_query:
11923 * @widget: a #GtkWidget
11925 * Triggers a tooltip query on the display where the toplevel of @widget
11926 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11932 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11934 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11937 static guint tooltip_query_id;
11938 static GSList *tooltip_query_displays;
11941 tooltip_query_idle (gpointer data)
11943 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11944 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11945 g_slist_free (tooltip_query_displays);
11947 tooltip_query_displays = NULL;
11948 tooltip_query_id = 0;
11954 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11956 GdkDisplay *display;
11958 display = gtk_widget_get_display (widget);
11960 if (!g_slist_find (tooltip_query_displays, display))
11961 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11963 if (tooltip_query_id == 0)
11964 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11968 * gtk_widget_set_tooltip_text:
11969 * @widget: a #GtkWidget
11970 * @text: the contents of the tooltip for @widget
11972 * Sets @text as the contents of the tooltip. This function will take
11973 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11974 * handler for the GtkWidget::query-tooltip signal.
11976 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11981 gtk_widget_set_tooltip_text (GtkWidget *widget,
11984 g_return_if_fail (GTK_IS_WIDGET (widget));
11986 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11990 * gtk_widget_get_tooltip_text:
11991 * @widget: a #GtkWidget
11993 * Gets the contents of the tooltip for @widget.
11995 * Return value: the tooltip text, or %NULL. You should free the
11996 * returned string with g_free() when done.
12001 gtk_widget_get_tooltip_text (GtkWidget *widget)
12003 gchar *text = NULL;
12005 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12007 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12013 * gtk_widget_set_tooltip_markup:
12014 * @widget: a #GtkWidget
12015 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12017 * Sets @markup as the contents of the tooltip, which is marked up with
12018 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12020 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
12021 * and of the default handler for the GtkWidget::query-tooltip signal.
12023 * See also the GtkWidget:tooltip-markup property and
12024 * gtk_tooltip_set_markup().
12029 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12030 const gchar *markup)
12032 g_return_if_fail (GTK_IS_WIDGET (widget));
12034 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12038 * gtk_widget_get_tooltip_markup:
12039 * @widget: a #GtkWidget
12041 * Gets the contents of the tooltip for @widget.
12043 * Return value: the tooltip text, or %NULL. You should free the
12044 * returned string with g_free() when done.
12049 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12051 gchar *text = NULL;
12053 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12055 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12061 * gtk_widget_set_has_tooltip:
12062 * @widget: a #GtkWidget
12063 * @has_tooltip: whether or not @widget has a tooltip.
12065 * Sets the has-tooltip property on @widget to @has_tooltip. See
12066 * GtkWidget:has-tooltip for more information.
12071 gtk_widget_set_has_tooltip (GtkWidget *widget,
12072 gboolean has_tooltip)
12074 g_return_if_fail (GTK_IS_WIDGET (widget));
12076 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12080 * gtk_widget_get_has_tooltip:
12081 * @widget: a #GtkWidget
12083 * Returns the current value of the has-tooltip property. See
12084 * GtkWidget:has-tooltip for more information.
12086 * Return value: current value of has-tooltip on @widget.
12091 gtk_widget_get_has_tooltip (GtkWidget *widget)
12093 gboolean has_tooltip = FALSE;
12095 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12097 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12099 return has_tooltip;
12103 * gtk_widget_get_allocation:
12104 * @widget: a #GtkWidget
12105 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12107 * Retrieves the widget's allocation.
12112 gtk_widget_get_allocation (GtkWidget *widget,
12113 GtkAllocation *allocation)
12115 GtkWidgetPrivate *priv;
12117 g_return_if_fail (GTK_IS_WIDGET (widget));
12118 g_return_if_fail (allocation != NULL);
12120 priv = widget->priv;
12122 *allocation = priv->allocation;
12126 * gtk_widget_set_allocation:
12127 * @widget: a #GtkWidget
12128 * @allocation: a pointer to a #GtkAllocation to copy from
12130 * Sets the widget's allocation. This should not be used
12131 * directly, but from within a widget's size_allocate method.
12136 gtk_widget_set_allocation (GtkWidget *widget,
12137 const GtkAllocation *allocation)
12139 GtkWidgetPrivate *priv;
12141 g_return_if_fail (GTK_IS_WIDGET (widget));
12142 g_return_if_fail (allocation != NULL);
12144 priv = widget->priv;
12146 priv->allocation = *allocation;
12150 * gtk_widget_get_requisition:
12151 * @widget: a #GtkWidget
12152 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12154 * Retrieves the widget's requisition.
12156 * This function should only be used by widget implementations in
12157 * order to figure whether the widget's requisition has actually
12158 * changed after some internal state change (so that they can call
12159 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12161 * Normally, gtk_widget_size_request() should be used.
12165 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12166 * removed, If you need to cache sizes across requests and allocations,
12167 * add an explicit cache to the widget in question instead.
12170 gtk_widget_get_requisition (GtkWidget *widget,
12171 GtkRequisition *requisition)
12173 g_return_if_fail (GTK_IS_WIDGET (widget));
12174 g_return_if_fail (requisition != NULL);
12176 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12180 * gtk_widget_set_window:
12181 * @widget: a #GtkWidget
12182 * @window: a #GdkWindow
12184 * Sets a widget's window. This function should only be used in a
12185 * widget's GtkWidget::realize() implementation. The %window passed is
12186 * usually either new window created with gdk_window_new(), or the
12187 * window of its parent widget as returned by
12188 * gtk_widget_get_parent_window().
12190 * Widgets must indicate whether they will create their own #GdkWindow
12191 * by calling gtk_widget_set_has_window(). This is usually done in the
12192 * widget's init() function.
12194 * <note><para>This function does not add any reference to @window.</para></note>
12199 gtk_widget_set_window (GtkWidget *widget,
12202 GtkWidgetPrivate *priv;
12204 g_return_if_fail (GTK_IS_WIDGET (widget));
12205 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12207 priv = widget->priv;
12209 if (priv->window != window)
12211 priv->window = window;
12212 g_object_notify (G_OBJECT (widget), "window");
12217 * gtk_widget_get_window:
12218 * @widget: a #GtkWidget
12220 * Returns the widget's window if it is realized, %NULL otherwise
12222 * Return value: (transfer none): @widget's window.
12227 gtk_widget_get_window (GtkWidget *widget)
12229 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12231 return widget->priv->window;
12235 * gtk_widget_get_support_multidevice:
12236 * @widget: a #GtkWidget
12238 * Returns %TRUE if @widget is multiple pointer aware. See
12239 * gtk_widget_set_support_multidevice() for more information.
12241 * Returns: %TRUE is @widget is multidevice aware.
12244 gtk_widget_get_support_multidevice (GtkWidget *widget)
12246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12248 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12252 * gtk_widget_set_support_multidevice:
12253 * @widget: a #GtkWidget
12254 * @support_multidevice: %TRUE to support input from multiple devices.
12256 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12257 * @widget will start receiving multiple, per device enter/leave events. Note
12258 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12259 * gdk_window_set_support_multidevice() will have to be called manually on them.
12264 gtk_widget_set_support_multidevice (GtkWidget *widget,
12265 gboolean support_multidevice)
12267 GtkWidgetPrivate *priv;
12269 g_return_if_fail (GTK_IS_WIDGET (widget));
12271 priv = widget->priv;
12273 if (support_multidevice)
12275 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12276 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12280 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12281 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12284 if (gtk_widget_get_realized (widget))
12285 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12289 _gtk_widget_set_has_focus (GtkWidget *widget,
12290 gboolean has_focus)
12293 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12295 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12299 * gtk_widget_send_focus_change:
12300 * @widget: a #GtkWidget
12301 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12303 * Sends the focus change @event to @widget
12305 * This function is not meant to be used by applications. The only time it
12306 * should be used is when it is necessary for a #GtkWidget to assign focus
12307 * to a widget that is semantically owned by the first widget even though
12308 * it's not a direct child - for instance, a search entry in a floating
12309 * window similar to the quick search in #GtkTreeView.
12311 * An example of its usage is:
12314 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12316 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12317 * fevent->focus_change.in = TRUE;
12318 * fevent->focus_change.window = gtk_widget_get_window (widget);
12319 * if (fevent->focus_change.window != NULL)
12320 * g_object_ref (fevent->focus_change.window);
12322 * gtk_widget_send_focus_change (widget, fevent);
12324 * gdk_event_free (event);
12327 * Return value: the return value from the event signal emission: %TRUE
12328 * if the event was handled, and %FALSE otherwise
12333 gtk_widget_send_focus_change (GtkWidget *widget,
12338 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12339 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12341 g_object_ref (widget);
12343 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12345 res = gtk_widget_event (widget, event);
12347 g_object_notify (G_OBJECT (widget), "has-focus");
12349 g_object_unref (widget);