1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup.h"
44 #include "gtkwidget.h"
45 #include "gtkwindow.h"
46 #include "gtkbindings.h"
47 #include "gtkprivate.h"
49 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
50 #include <gobject/gvaluecollector.h>
51 #include <gobject/gobjectnotifyqueue.c>
52 #include <cairo-gobject.h>
53 #include "gdk/gdkkeysyms.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
64 * @Short_description: Base class for all widgets
67 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
68 * widget lifecycle, states and style.
70 * <refsect2 id="style-properties">
72 * <structname>GtkWidget</structname> introduces <firstterm>style
73 * properties</firstterm> - these are basically object properties that are stored
74 * not on the object, but in the style object associated to the widget. Style
75 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
76 * This mechanism is used for configuring such things as the location of the
77 * scrollbar arrows through the theme, giving theme authors more control over the
78 * look of applications without the need to write a theme engine in C.
81 * Use gtk_widget_class_install_style_property() to install style properties for
82 * a widget class, gtk_widget_class_find_style_property() or
83 * gtk_widget_class_list_style_properties() to get information about existing
84 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
85 * gtk_widget_style_get_valist() to obtain the value of a style property.
88 * <refsect2 id="GtkWidget-BUILDER-UI">
89 * <title>GtkWidget as GtkBuildable</title>
91 * The GtkWidget implementation of the GtkBuildable interface supports a
92 * custom <accelerator> element, which has attributes named key,
93 * modifiers and signal and allows to specify accelerators.
96 * <title>A UI definition fragment specifying an accelerator</title>
97 * <programlisting><![CDATA[
98 * <object class="GtkButton">
99 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
101 * ]]></programlisting>
104 * In addition to accelerators, <structname>GtkWidget</structname> also support a
105 * custom <accessible> element, which supports actions and relations.
106 * Properties on the accessible implementation of an object can be set by accessing the
107 * internal child "accessible" of a <structname>GtkWidget</structname>.
110 * <title>A UI definition fragment specifying an accessible</title>
111 * <programlisting><![CDATA[
112 * <object class="GtkButton" id="label1"/>
113 * <property name="label">I am a Label for a Button</property>
115 * <object class="GtkButton" id="button1">
117 * <action action_name="click" translatable="yes">Click the button.</action>
118 * <relation target="label1" type="labelled-by"/>
120 * <child internal-child="accessible">
121 * <object class="AtkObject" id="a11y-button1">
122 * <property name="AtkObject::name">Clickable Button</property>
126 * ]]></programlisting>
131 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
132 #define INIT_PATH_SIZE (512)
134 struct _GtkWidgetPrivate
136 /* The state of the widget. There are actually only
137 * 5 widget states (defined in "gtkenums.h")
142 /* The saved state of the widget. When a widget's state
143 * is changed to GTK_STATE_INSENSITIVE via
144 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
145 * the old state is kept around in this field. The state
146 * will be restored once the widget gets sensitive again.
148 guint saved_state : 3;
150 /* unused bits in our 32-bit block */
153 guint in_destruction : 1;
155 /* The widget's name. If the widget does not have a name
156 * (the name is NULL), then its name (as returned by
157 * "gtk_widget_get_name") is its class's name.
158 * Among other things, the widget name is used to determine
159 * the style to use for a widget.
163 /* The style for the widget. The style contains the
164 * colors the widget should be drawn in for each state
165 * along with graphics contexts used to draw with and
166 * the font to use for text.
170 /* The widget's allocated size.
172 GtkAllocation allocation;
174 /* The widget's requested sizes */
175 SizeRequestCache requests;
177 /* The widget's window or its parent window if it does
178 * not have a window. (Which will be indicated by the
179 * GTK_NO_WINDOW flag being set).
183 /* The widget's parent.
213 BUTTON_RELEASE_EVENT,
228 PROPERTY_NOTIFY_EVENT,
229 SELECTION_CLEAR_EVENT,
230 SELECTION_REQUEST_EVENT,
231 SELECTION_NOTIFY_EVENT,
246 VISIBILITY_NOTIFY_EVENT,
250 ACCEL_CLOSURES_CHANGED,
276 PROP_RECEIVES_DEFAULT,
277 PROP_COMPOSITE_CHILD,
280 PROP_EXTENSION_EVENTS,
286 PROP_DOUBLE_BUFFERED,
296 typedef struct _GtkStateData GtkStateData;
301 guint state_restoration : 1;
302 guint parent_sensitive : 1;
303 guint use_forall : 1;
306 /* --- prototypes --- */
307 static void gtk_widget_class_init (GtkWidgetClass *klass);
308 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
309 static void gtk_widget_init (GtkWidget *widget);
310 static void gtk_widget_set_property (GObject *object,
314 static void gtk_widget_get_property (GObject *object,
318 static void gtk_widget_dispose (GObject *object);
319 static void gtk_widget_real_destroy (GtkObject *object);
320 static void gtk_widget_finalize (GObject *object);
321 static void gtk_widget_real_show (GtkWidget *widget);
322 static void gtk_widget_real_hide (GtkWidget *widget);
323 static void gtk_widget_real_map (GtkWidget *widget);
324 static void gtk_widget_real_unmap (GtkWidget *widget);
325 static void gtk_widget_real_realize (GtkWidget *widget);
326 static void gtk_widget_real_unrealize (GtkWidget *widget);
327 static void gtk_widget_real_size_request (GtkWidget *widget,
328 GtkRequisition *requisition);
329 static void gtk_widget_real_size_allocate (GtkWidget *widget,
330 GtkAllocation *allocation);
331 static void gtk_widget_real_style_set (GtkWidget *widget,
332 GtkStyle *previous_style);
333 static void gtk_widget_real_direction_changed(GtkWidget *widget,
334 GtkTextDirection previous_direction);
336 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
337 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
340 gboolean keyboard_tip,
341 GtkTooltip *tooltip);
342 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
343 GtkWidgetHelpType help_type);
345 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
347 GParamSpec **pspecs);
348 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
350 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
352 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
353 GdkEventFocus *event);
354 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
355 GdkEventFocus *event);
356 static gboolean gtk_widget_real_focus (GtkWidget *widget,
357 GtkDirectionType direction);
358 static void gtk_widget_real_move_focus (GtkWidget *widget,
359 GtkDirectionType direction);
360 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
361 GtkDirectionType direction);
362 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
363 static void gtk_widget_update_pango_context (GtkWidget *widget);
364 static void gtk_widget_propagate_state (GtkWidget *widget,
366 static void gtk_widget_reset_rc_style (GtkWidget *widget);
367 static void gtk_widget_set_style_internal (GtkWidget *widget,
369 gboolean initial_emission);
370 static gint gtk_widget_event_internal (GtkWidget *widget,
372 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
373 gboolean group_cycling);
374 static void gtk_widget_real_get_width (GtkWidget *widget,
377 static void gtk_widget_real_get_height (GtkWidget *widget,
380 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
382 gint *minimum_height,
383 gint *natural_height);
384 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
387 gint *natural_width);
388 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
389 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
390 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
391 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
392 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
393 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
394 cairo_region_t *region);
395 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
396 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
397 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
400 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
401 gboolean has_tooltip,
403 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
404 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
406 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
407 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
409 const gchar *childname);
410 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
413 const GValue *value);
414 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
417 const gchar *tagname,
418 GMarkupParser *parser,
420 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
423 const gchar *tagname,
425 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
426 GtkBuilder *builder);
428 static void gtk_widget_real_get_width (GtkWidget *widget,
431 static void gtk_widget_real_get_height (GtkWidget *widget,
435 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
438 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
439 GtkOrientation orientation,
443 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
444 GtkAllocation *allocation);
446 static void gtk_widget_set_usize_internal (GtkWidget *widget,
450 static void gtk_widget_add_events_internal (GtkWidget *widget,
454 /* --- variables --- */
455 static gpointer gtk_widget_parent_class = NULL;
456 static guint widget_signals[LAST_SIGNAL] = { 0 };
457 static GtkStyle *gtk_default_style = NULL;
458 static guint composite_child_stack = 0;
459 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
460 static GParamSpecPool *style_property_spec_pool = NULL;
462 static GQuark quark_property_parser = 0;
463 static GQuark quark_aux_info = 0;
464 static GQuark quark_accel_path = 0;
465 static GQuark quark_accel_closures = 0;
466 static GQuark quark_event_mask = 0;
467 static GQuark quark_device_event_mask = 0;
468 static GQuark quark_extension_event_mode = 0;
469 static GQuark quark_parent_window = 0;
470 static GQuark quark_pointer_window = 0;
471 static GQuark quark_shape_info = 0;
472 static GQuark quark_input_shape_info = 0;
473 static GQuark quark_pango_context = 0;
474 static GQuark quark_rc_style = 0;
475 static GQuark quark_accessible_object = 0;
476 static GQuark quark_mnemonic_labels = 0;
477 static GQuark quark_tooltip_markup = 0;
478 static GQuark quark_has_tooltip = 0;
479 static GQuark quark_tooltip_window = 0;
480 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
481 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
483 /* --- functions --- */
485 gtk_widget_get_type (void)
487 static GType widget_type = 0;
489 if (G_UNLIKELY (widget_type == 0))
491 const GTypeInfo widget_info =
493 sizeof (GtkWidgetClass),
494 NULL, /* base_init */
495 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
496 (GClassInitFunc) gtk_widget_class_init,
497 NULL, /* class_finalize */
498 NULL, /* class_init */
501 (GInstanceInitFunc) gtk_widget_init,
502 NULL, /* value_table */
505 const GInterfaceInfo accessibility_info =
507 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
508 (GInterfaceFinalizeFunc) NULL,
509 NULL /* interface data */
512 const GInterfaceInfo buildable_info =
514 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
515 (GInterfaceFinalizeFunc) NULL,
516 NULL /* interface data */
519 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
520 &widget_info, G_TYPE_FLAG_ABSTRACT);
522 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
523 &accessibility_info) ;
524 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
532 child_property_notify_dispatcher (GObject *object,
536 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
539 /* We guard against the draw signal callbacks modifying the state of the
540 * cairo context by surounding it with save/restore.
541 * Maybe we should also cairo_new_path() just to be sure?
544 gtk_widget_draw_marshaller (GClosure *closure,
545 GValue *return_value,
546 guint n_param_values,
547 const GValue *param_values,
548 gpointer invocation_hint,
549 gpointer marshal_data)
551 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
555 _gtk_marshal_BOOLEAN__BOXED (closure,
566 gtk_widget_class_init (GtkWidgetClass *klass)
568 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
569 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
570 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
571 GtkBindingSet *binding_set;
573 gtk_widget_parent_class = g_type_class_peek_parent (klass);
575 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
576 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
577 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
578 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
579 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
580 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
581 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
582 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
583 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
584 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
585 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
586 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
587 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
588 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
589 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
590 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
591 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
592 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
594 style_property_spec_pool = g_param_spec_pool_new (FALSE);
595 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
596 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
597 cpn_context.dispatcher = child_property_notify_dispatcher;
598 _gtk_widget_child_property_notify_context = &cpn_context;
600 gobject_class->dispose = gtk_widget_dispose;
601 gobject_class->finalize = gtk_widget_finalize;
602 gobject_class->set_property = gtk_widget_set_property;
603 gobject_class->get_property = gtk_widget_get_property;
605 object_class->destroy = gtk_widget_real_destroy;
607 klass->activate_signal = 0;
608 klass->set_scroll_adjustments_signal = 0;
609 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
610 klass->show = gtk_widget_real_show;
611 klass->show_all = gtk_widget_show;
612 klass->hide = gtk_widget_real_hide;
613 klass->hide_all = gtk_widget_hide;
614 klass->map = gtk_widget_real_map;
615 klass->unmap = gtk_widget_real_unmap;
616 klass->realize = gtk_widget_real_realize;
617 klass->unrealize = gtk_widget_real_unrealize;
618 klass->size_request = gtk_widget_real_size_request;
619 klass->size_allocate = gtk_widget_real_size_allocate;
620 klass->get_preferred_width = gtk_widget_real_get_width;
621 klass->get_preferred_height = gtk_widget_real_get_height;
622 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
623 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
624 klass->state_changed = NULL;
625 klass->parent_set = NULL;
626 klass->hierarchy_changed = NULL;
627 klass->style_set = gtk_widget_real_style_set;
628 klass->direction_changed = gtk_widget_real_direction_changed;
629 klass->grab_notify = NULL;
630 klass->child_notify = NULL;
632 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
633 klass->grab_focus = gtk_widget_real_grab_focus;
634 klass->focus = gtk_widget_real_focus;
636 klass->button_press_event = NULL;
637 klass->button_release_event = NULL;
638 klass->motion_notify_event = NULL;
639 klass->delete_event = NULL;
640 klass->destroy_event = NULL;
641 klass->key_press_event = gtk_widget_real_key_press_event;
642 klass->key_release_event = gtk_widget_real_key_release_event;
643 klass->enter_notify_event = NULL;
644 klass->leave_notify_event = NULL;
645 klass->configure_event = NULL;
646 klass->focus_in_event = gtk_widget_real_focus_in_event;
647 klass->focus_out_event = gtk_widget_real_focus_out_event;
648 klass->map_event = NULL;
649 klass->unmap_event = NULL;
650 klass->window_state_event = NULL;
651 klass->property_notify_event = _gtk_selection_property_notify;
652 klass->selection_clear_event = _gtk_selection_clear;
653 klass->selection_request_event = _gtk_selection_request;
654 klass->selection_notify_event = _gtk_selection_notify;
655 klass->selection_received = NULL;
656 klass->proximity_in_event = NULL;
657 klass->proximity_out_event = NULL;
658 klass->drag_begin = NULL;
659 klass->drag_end = NULL;
660 klass->drag_data_delete = NULL;
661 klass->drag_leave = NULL;
662 klass->drag_motion = NULL;
663 klass->drag_drop = NULL;
664 klass->drag_data_received = NULL;
665 klass->screen_changed = NULL;
666 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
667 klass->grab_broken_event = NULL;
668 klass->query_tooltip = gtk_widget_real_query_tooltip;
670 klass->show_help = gtk_widget_real_show_help;
672 /* Accessibility support */
673 klass->get_accessible = gtk_widget_real_get_accessible;
675 klass->no_expose_event = NULL;
677 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
678 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
680 g_object_class_install_property (gobject_class,
682 g_param_spec_string ("name",
684 P_("The name of the widget"),
686 GTK_PARAM_READWRITE));
687 g_object_class_install_property (gobject_class,
689 g_param_spec_object ("parent",
691 P_("The parent widget of this widget. Must be a Container widget"),
693 GTK_PARAM_READWRITE));
695 g_object_class_install_property (gobject_class,
697 g_param_spec_int ("width-request",
699 P_("Override for width request of the widget, or -1 if natural request should be used"),
703 GTK_PARAM_READWRITE));
704 g_object_class_install_property (gobject_class,
706 g_param_spec_int ("height-request",
707 P_("Height request"),
708 P_("Override for height request of the widget, or -1 if natural request should be used"),
712 GTK_PARAM_READWRITE));
713 g_object_class_install_property (gobject_class,
715 g_param_spec_boolean ("visible",
717 P_("Whether the widget is visible"),
719 GTK_PARAM_READWRITE));
720 g_object_class_install_property (gobject_class,
722 g_param_spec_boolean ("sensitive",
724 P_("Whether the widget responds to input"),
726 GTK_PARAM_READWRITE));
727 g_object_class_install_property (gobject_class,
729 g_param_spec_boolean ("app-paintable",
730 P_("Application paintable"),
731 P_("Whether the application will paint directly on the widget"),
733 GTK_PARAM_READWRITE));
734 g_object_class_install_property (gobject_class,
736 g_param_spec_boolean ("can-focus",
738 P_("Whether the widget can accept the input focus"),
740 GTK_PARAM_READWRITE));
741 g_object_class_install_property (gobject_class,
743 g_param_spec_boolean ("has-focus",
745 P_("Whether the widget has the input focus"),
747 GTK_PARAM_READWRITE));
748 g_object_class_install_property (gobject_class,
750 g_param_spec_boolean ("is-focus",
752 P_("Whether the widget is the focus widget within the toplevel"),
754 GTK_PARAM_READWRITE));
755 g_object_class_install_property (gobject_class,
757 g_param_spec_boolean ("can-default",
759 P_("Whether the widget can be the default widget"),
761 GTK_PARAM_READWRITE));
762 g_object_class_install_property (gobject_class,
764 g_param_spec_boolean ("has-default",
766 P_("Whether the widget is the default widget"),
768 GTK_PARAM_READWRITE));
769 g_object_class_install_property (gobject_class,
770 PROP_RECEIVES_DEFAULT,
771 g_param_spec_boolean ("receives-default",
772 P_("Receives default"),
773 P_("If TRUE, the widget will receive the default action when it is focused"),
775 GTK_PARAM_READWRITE));
776 g_object_class_install_property (gobject_class,
777 PROP_COMPOSITE_CHILD,
778 g_param_spec_boolean ("composite-child",
779 P_("Composite child"),
780 P_("Whether the widget is part of a composite widget"),
782 GTK_PARAM_READABLE));
783 g_object_class_install_property (gobject_class,
785 g_param_spec_object ("style",
787 P_("The style of the widget, which contains information about how it will look (colors etc)"),
789 GTK_PARAM_READWRITE));
790 g_object_class_install_property (gobject_class,
792 g_param_spec_flags ("events",
794 P_("The event mask that decides what kind of GdkEvents this widget gets"),
797 GTK_PARAM_READWRITE));
798 g_object_class_install_property (gobject_class,
799 PROP_EXTENSION_EVENTS,
800 g_param_spec_enum ("extension-events",
801 P_("Extension events"),
802 P_("The mask that decides what kind of extension events this widget gets"),
803 GDK_TYPE_EXTENSION_MODE,
804 GDK_EXTENSION_EVENTS_NONE,
805 GTK_PARAM_READWRITE));
806 g_object_class_install_property (gobject_class,
808 g_param_spec_boolean ("no-show-all",
810 P_("Whether gtk_widget_show_all() should not affect this widget"),
812 GTK_PARAM_READWRITE));
815 * GtkWidget:has-tooltip:
817 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
818 * A value of %TRUE indicates that @widget can have a tooltip, in this case
819 * the widget will be queried using #GtkWidget::query-tooltip to determine
820 * whether it will provide a tooltip or not.
822 * Note that setting this property to %TRUE for the first time will change
823 * the event masks of the GdkWindows of this widget to include leave-notify
824 * and motion-notify events. This cannot and will not be undone when the
825 * property is set to %FALSE again.
829 g_object_class_install_property (gobject_class,
831 g_param_spec_boolean ("has-tooltip",
833 P_("Whether this widget has a tooltip"),
835 GTK_PARAM_READWRITE));
837 * GtkWidget:tooltip-text:
839 * Sets the text of tooltip to be the given string.
841 * Also see gtk_tooltip_set_text().
843 * This is a convenience property which will take care of getting the
844 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
845 * will automatically be set to %TRUE and there will be taken care of
846 * #GtkWidget::query-tooltip in the default signal handler.
850 g_object_class_install_property (gobject_class,
852 g_param_spec_string ("tooltip-text",
854 P_("The contents of the tooltip for this widget"),
856 GTK_PARAM_READWRITE));
858 * GtkWidget:tooltip-markup:
860 * Sets the text of tooltip to be the given string, which is marked up
861 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
862 * Also see gtk_tooltip_set_markup().
864 * This is a convenience property which will take care of getting the
865 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
866 * will automatically be set to %TRUE and there will be taken care of
867 * #GtkWidget::query-tooltip in the default signal handler.
871 g_object_class_install_property (gobject_class,
873 g_param_spec_string ("tooltip-markup",
874 P_("Tooltip markup"),
875 P_("The contents of the tooltip for this widget"),
877 GTK_PARAM_READWRITE));
882 * The widget's window if it is realized, %NULL otherwise.
886 g_object_class_install_property (gobject_class,
888 g_param_spec_object ("window",
890 P_("The widget's window if it is realized"),
892 GTK_PARAM_READABLE));
895 * GtkWidget:double-buffered
897 * Whether the widget is double buffered.
901 g_object_class_install_property (gobject_class,
902 PROP_DOUBLE_BUFFERED,
903 g_param_spec_boolean ("double-buffered",
904 P_("Double Buffered"),
905 P_("Whether the widget is double buffered"),
907 GTK_PARAM_READWRITE));
912 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
916 g_object_class_install_property (gobject_class,
918 g_param_spec_enum ("halign",
919 P_("Horizontal Alignment"),
920 P_("How to position in extra horizontal space"),
923 GTK_PARAM_READWRITE));
928 * How to distribute vertical space if widget gets extra space, see #GtkAlign
932 g_object_class_install_property (gobject_class,
934 g_param_spec_enum ("valign",
935 P_("Vertical Alignment"),
936 P_("How to position in extra vertical space"),
939 GTK_PARAM_READWRITE));
942 * GtkWidget:margin-left
944 * Margin on left side of widget.
946 * This property adds margin outside of the widget's normal size
947 * request, the margin will be added in addition to the size from
948 * gtk_widget_set_size_request() for example.
952 g_object_class_install_property (gobject_class,
954 g_param_spec_int ("margin-left",
955 P_("Margin on Left"),
956 P_("Pixels of extra space on the left side"),
960 GTK_PARAM_READWRITE));
963 * GtkWidget:margin-right
965 * Margin on right side of widget.
967 * This property adds margin outside of the widget's normal size
968 * request, the margin will be added in addition to the size from
969 * gtk_widget_set_size_request() for example.
973 g_object_class_install_property (gobject_class,
975 g_param_spec_int ("margin-right",
976 P_("Margin on Right"),
977 P_("Pixels of extra space on the right side"),
981 GTK_PARAM_READWRITE));
984 * GtkWidget:margin-top
986 * Margin on top side of widget.
988 * This property adds margin outside of the widget's normal size
989 * request, the margin will be added in addition to the size from
990 * gtk_widget_set_size_request() for example.
994 g_object_class_install_property (gobject_class,
996 g_param_spec_int ("margin-top",
998 P_("Pixels of extra space on the top side"),
1002 GTK_PARAM_READWRITE));
1005 * GtkWidget:margin-bottom
1007 * Margin on bottom side of widget.
1009 * This property adds margin outside of the widget's normal size
1010 * request, the margin will be added in addition to the size from
1011 * gtk_widget_set_size_request() for example.
1015 g_object_class_install_property (gobject_class,
1017 g_param_spec_int ("margin-bottom",
1018 P_("Margin on Bottom"),
1019 P_("Pixels of extra space on the bottom side"),
1023 GTK_PARAM_READWRITE));
1028 * Sets all four sides' margin at once. If read, returns max
1029 * margin on any side.
1033 g_object_class_install_property (gobject_class,
1035 g_param_spec_int ("margin",
1037 P_("Pixels of extra space on all four sides"),
1041 GTK_PARAM_READWRITE));
1044 * GtkWidget::destroy:
1045 * @object: the object which received the signal
1047 * Signals that all holders of a reference to the widget should release
1048 * the reference that they hold. May result in finalization of the widget
1049 * if all references are released.
1051 widget_signals[DESTROY] =
1052 g_signal_new (I_("destroy"),
1053 G_TYPE_FROM_CLASS (gobject_class),
1054 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1055 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1057 _gtk_marshal_VOID__VOID,
1062 * @widget: the object which received the signal.
1064 widget_signals[SHOW] =
1065 g_signal_new (I_("show"),
1066 G_TYPE_FROM_CLASS (gobject_class),
1068 G_STRUCT_OFFSET (GtkWidgetClass, show),
1070 _gtk_marshal_VOID__VOID,
1075 * @widget: the object which received the signal.
1077 widget_signals[HIDE] =
1078 g_signal_new (I_("hide"),
1079 G_TYPE_FROM_CLASS (gobject_class),
1081 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1083 _gtk_marshal_VOID__VOID,
1088 * @widget: the object which received the signal.
1090 widget_signals[MAP] =
1091 g_signal_new (I_("map"),
1092 G_TYPE_FROM_CLASS (gobject_class),
1094 G_STRUCT_OFFSET (GtkWidgetClass, map),
1096 _gtk_marshal_VOID__VOID,
1101 * @widget: the object which received the signal.
1103 widget_signals[UNMAP] =
1104 g_signal_new (I_("unmap"),
1105 G_TYPE_FROM_CLASS (gobject_class),
1107 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1109 _gtk_marshal_VOID__VOID,
1113 * GtkWidget::realize:
1114 * @widget: the object which received the signal.
1116 widget_signals[REALIZE] =
1117 g_signal_new (I_("realize"),
1118 G_TYPE_FROM_CLASS (gobject_class),
1120 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1122 _gtk_marshal_VOID__VOID,
1126 * GtkWidget::unrealize:
1127 * @widget: the object which received the signal.
1129 widget_signals[UNREALIZE] =
1130 g_signal_new (I_("unrealize"),
1131 G_TYPE_FROM_CLASS (gobject_class),
1133 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1135 _gtk_marshal_VOID__VOID,
1139 * GtkWidget::size-request:
1140 * @widget: the object which received the signal.
1143 widget_signals[SIZE_REQUEST] =
1144 g_signal_new (I_("size-request"),
1145 G_TYPE_FROM_CLASS (gobject_class),
1147 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1149 _gtk_marshal_VOID__BOXED,
1151 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1154 * GtkWidget::size-allocate:
1155 * @widget: the object which received the signal.
1158 widget_signals[SIZE_ALLOCATE] =
1159 g_signal_new (I_("size-allocate"),
1160 G_TYPE_FROM_CLASS (gobject_class),
1162 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1164 _gtk_marshal_VOID__BOXED,
1166 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1169 * GtkWidget::state-changed:
1170 * @widget: the object which received the signal.
1171 * @state: the previous state
1173 * The ::state-changed signal is emitted when the widget state changes.
1174 * See gtk_widget_get_state().
1176 widget_signals[STATE_CHANGED] =
1177 g_signal_new (I_("state-changed"),
1178 G_TYPE_FROM_CLASS (gobject_class),
1180 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1182 _gtk_marshal_VOID__ENUM,
1184 GTK_TYPE_STATE_TYPE);
1187 * GtkWidget::parent-set:
1188 * @widget: the object on which the signal is emitted
1189 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1190 * just got its initial parent.
1192 * The ::parent-set signal is emitted when a new parent
1193 * has been set on a widget.
1195 widget_signals[PARENT_SET] =
1196 g_signal_new (I_("parent-set"),
1197 G_TYPE_FROM_CLASS (gobject_class),
1199 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1201 _gtk_marshal_VOID__OBJECT,
1206 * GtkWidget::hierarchy-changed:
1207 * @widget: the object on which the signal is emitted
1208 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1209 * if the widget was previously unanchored
1211 * The ::hierarchy-changed signal is emitted when the
1212 * anchored state of a widget changes. A widget is
1213 * <firstterm>anchored</firstterm> when its toplevel
1214 * ancestor is a #GtkWindow. This signal is emitted when
1215 * a widget changes from un-anchored to anchored or vice-versa.
1217 widget_signals[HIERARCHY_CHANGED] =
1218 g_signal_new (I_("hierarchy-changed"),
1219 G_TYPE_FROM_CLASS (gobject_class),
1221 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1223 _gtk_marshal_VOID__OBJECT,
1228 * GtkWidget::style-set:
1229 * @widget: the object on which the signal is emitted
1230 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1231 * just got its initial style
1233 * The ::style-set signal is emitted when a new style has been set
1234 * on a widget. Note that style-modifying functions like
1235 * gtk_widget_modify_base() also cause this signal to be emitted.
1237 widget_signals[STYLE_SET] =
1238 g_signal_new (I_("style-set"),
1239 G_TYPE_FROM_CLASS (gobject_class),
1241 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1243 _gtk_marshal_VOID__OBJECT,
1247 * GtkWidget::direction-changed:
1248 * @widget: the object on which the signal is emitted
1249 * @previous_direction: the previous text direction of @widget
1251 * The ::direction-changed signal is emitted when the text direction
1252 * of a widget changes.
1254 widget_signals[DIRECTION_CHANGED] =
1255 g_signal_new (I_("direction-changed"),
1256 G_TYPE_FROM_CLASS (gobject_class),
1258 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1260 _gtk_marshal_VOID__ENUM,
1262 GTK_TYPE_TEXT_DIRECTION);
1265 * GtkWidget::grab-notify:
1266 * @widget: the object which received the signal
1267 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1268 * if it becomes unshadowed
1270 * The ::grab-notify signal is emitted when a widget becomes
1271 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1272 * another widget, or when it becomes unshadowed due to a grab
1275 * A widget is shadowed by a gtk_grab_add() when the topmost
1276 * grab widget in the grab stack of its window group is not
1279 widget_signals[GRAB_NOTIFY] =
1280 g_signal_new (I_("grab-notify"),
1281 G_TYPE_FROM_CLASS (gobject_class),
1283 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1285 _gtk_marshal_VOID__BOOLEAN,
1290 * GtkWidget::child-notify:
1291 * @widget: the object which received the signal
1292 * @pspec: the #GParamSpec of the changed child property
1294 * The ::child-notify signal is emitted for each
1295 * <link linkend="child-properties">child property</link> that has
1296 * changed on an object. The signal's detail holds the property name.
1298 widget_signals[CHILD_NOTIFY] =
1299 g_signal_new (I_("child-notify"),
1300 G_TYPE_FROM_CLASS (gobject_class),
1301 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1302 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1304 g_cclosure_marshal_VOID__PARAM,
1310 * @widget: the object which received the signal
1311 * @cr: the cairo context to draw to
1312 * @width: width of the widget
1313 * @height: height of the widget
1315 * This signal is emitted when a widget is supposed to render itself.
1316 * The @widget's top left corner must be painted at the origin of
1317 * the passed in context and be sized in the given @width and @height.
1319 * Signal handlers connected to this signal can modify the cairo
1320 * context passed as @cr in any way they like and don't need to
1321 * restore it. The signal emission takes care of calling cairo_save()
1322 * before and cairo_restore() after invoking the handler.
1324 widget_signals[DRAW] =
1325 g_signal_new (I_("draw"),
1326 G_TYPE_FROM_CLASS (gobject_class),
1328 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1329 _gtk_boolean_handled_accumulator, NULL,
1330 gtk_widget_draw_marshaller,
1332 CAIRO_GOBJECT_TYPE_CONTEXT);
1335 * GtkWidget::mnemonic-activate:
1336 * @widget: the object which received the signal.
1339 widget_signals[MNEMONIC_ACTIVATE] =
1340 g_signal_new (I_("mnemonic-activate"),
1341 G_TYPE_FROM_CLASS (gobject_class),
1343 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1344 _gtk_boolean_handled_accumulator, NULL,
1345 _gtk_marshal_BOOLEAN__BOOLEAN,
1350 * GtkWidget::grab-focus:
1351 * @widget: the object which received the signal.
1353 widget_signals[GRAB_FOCUS] =
1354 g_signal_new (I_("grab-focus"),
1355 G_TYPE_FROM_CLASS (gobject_class),
1356 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1357 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1359 _gtk_marshal_VOID__VOID,
1364 * @widget: the object which received the signal.
1367 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1369 widget_signals[FOCUS] =
1370 g_signal_new (I_("focus"),
1371 G_TYPE_FROM_CLASS (object_class),
1373 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1374 _gtk_boolean_handled_accumulator, NULL,
1375 _gtk_marshal_BOOLEAN__ENUM,
1377 GTK_TYPE_DIRECTION_TYPE);
1380 * GtkWidget::move-focus:
1381 * @widget: the object which received the signal.
1384 widget_signals[MOVE_FOCUS] =
1385 g_signal_new_class_handler (I_("move-focus"),
1386 G_TYPE_FROM_CLASS (object_class),
1387 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1388 G_CALLBACK (gtk_widget_real_move_focus),
1390 _gtk_marshal_VOID__ENUM,
1393 GTK_TYPE_DIRECTION_TYPE);
1396 * @widget: the object which received the signal.
1397 * @event: the #GdkEvent which triggered this signal
1399 * The GTK+ main loop will emit three signals for each GDK event delivered
1400 * to a widget: one generic ::event signal, another, more specific,
1401 * signal that matches the type of event delivered (e.g.
1402 * #GtkWidget::key-press-event) and finally a generic
1403 * #GtkWidget::event-after signal.
1405 * Returns: %TRUE to stop other handlers from being invoked for the event
1406 * and to cancel the emission of the second specific ::event signal.
1407 * %FALSE to propagate the event further and to allow the emission of
1408 * the second signal. The ::event-after signal is emitted regardless of
1411 widget_signals[EVENT] =
1412 g_signal_new (I_("event"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1415 G_STRUCT_OFFSET (GtkWidgetClass, event),
1416 _gtk_boolean_handled_accumulator, NULL,
1417 _gtk_marshal_BOOLEAN__BOXED,
1419 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1422 * GtkWidget::event-after:
1423 * @widget: the object which received the signal.
1424 * @event: the #GdkEvent which triggered this signal
1426 * After the emission of the #GtkWidget::event signal and (optionally)
1427 * the second more specific signal, ::event-after will be emitted
1428 * regardless of the previous two signals handlers return values.
1431 widget_signals[EVENT_AFTER] =
1432 g_signal_new (I_("event-after"),
1433 G_TYPE_FROM_CLASS (gobject_class),
1437 _gtk_marshal_VOID__BOXED,
1439 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1442 * GtkWidget::button-press-event:
1443 * @widget: the object which received the signal.
1444 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1447 * The ::button-press-event signal will be emitted when a button
1448 * (typically from a mouse) is pressed.
1450 * To receive this signal, the #GdkWindow associated to the
1451 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1453 * This signal will be sent to the grab widget if there is one.
1455 * Returns: %TRUE to stop other handlers from being invoked for the event.
1456 * %FALSE to propagate the event further.
1458 widget_signals[BUTTON_PRESS_EVENT] =
1459 g_signal_new (I_("button-press-event"),
1460 G_TYPE_FROM_CLASS (gobject_class),
1462 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1463 _gtk_boolean_handled_accumulator, NULL,
1464 _gtk_marshal_BOOLEAN__BOXED,
1466 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1469 * GtkWidget::button-release-event:
1470 * @widget: the object which received the signal.
1471 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1474 * The ::button-release-event signal will be emitted when a button
1475 * (typically from a mouse) is released.
1477 * To receive this signal, the #GdkWindow associated to the
1478 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1480 * This signal will be sent to the grab widget if there is one.
1482 * Returns: %TRUE to stop other handlers from being invoked for the event.
1483 * %FALSE to propagate the event further.
1485 widget_signals[BUTTON_RELEASE_EVENT] =
1486 g_signal_new (I_("button-release-event"),
1487 G_TYPE_FROM_CLASS (gobject_class),
1489 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1490 _gtk_boolean_handled_accumulator, NULL,
1491 _gtk_marshal_BOOLEAN__BOXED,
1493 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1496 * GtkWidget::scroll-event:
1497 * @widget: the object which received the signal.
1498 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1501 * The ::scroll-event signal is emitted when a button in the 4 to 7
1502 * range is pressed. Wheel mice are usually configured to generate
1503 * button press events for buttons 4 and 5 when the wheel is turned.
1505 * To receive this signal, the #GdkWindow associated to the widget needs
1506 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1508 * This signal will be sent to the grab widget if there is one.
1510 * Returns: %TRUE to stop other handlers from being invoked for the event.
1511 * %FALSE to propagate the event further.
1513 widget_signals[SCROLL_EVENT] =
1514 g_signal_new (I_("scroll-event"),
1515 G_TYPE_FROM_CLASS (gobject_class),
1517 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1518 _gtk_boolean_handled_accumulator, NULL,
1519 _gtk_marshal_BOOLEAN__BOXED,
1521 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1523 * GtkWidget::motion-notify-event:
1524 * @widget: the object which received the signal.
1525 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1528 * The ::motion-notify-event signal is emitted when the pointer moves
1529 * over the widget's #GdkWindow.
1531 * To receive this signal, the #GdkWindow associated to the widget
1532 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1534 * This signal will be sent to the grab widget if there is one.
1536 * Returns: %TRUE to stop other handlers from being invoked for the event.
1537 * %FALSE to propagate the event further.
1539 widget_signals[MOTION_NOTIFY_EVENT] =
1540 g_signal_new (I_("motion-notify-event"),
1541 G_TYPE_FROM_CLASS (gobject_class),
1543 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1544 _gtk_boolean_handled_accumulator, NULL,
1545 _gtk_marshal_BOOLEAN__BOXED,
1547 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1550 * GtkWidget::composited-changed:
1551 * @widget: the object on which the signal is emitted
1553 * The ::composited-changed signal is emitted when the composited
1554 * status of @widget<!-- -->s screen changes.
1555 * See gdk_screen_is_composited().
1557 widget_signals[COMPOSITED_CHANGED] =
1558 g_signal_new (I_("composited-changed"),
1559 G_TYPE_FROM_CLASS (gobject_class),
1560 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1561 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1563 _gtk_marshal_VOID__VOID,
1567 * GtkWidget::keynav-failed:
1568 * @widget: the object which received the signal
1569 * @direction: the direction of movement
1571 * Gets emitted if keyboard navigation fails.
1572 * See gtk_widget_keynav_failed() for details.
1574 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1575 * if the emitting widget should try to handle the keyboard
1576 * navigation attempt in its parent container(s).
1580 widget_signals[KEYNAV_FAILED] =
1581 g_signal_new_class_handler (I_("keynav-failed"),
1582 G_TYPE_FROM_CLASS (gobject_class),
1584 G_CALLBACK (gtk_widget_real_keynav_failed),
1585 _gtk_boolean_handled_accumulator, NULL,
1586 _gtk_marshal_BOOLEAN__ENUM,
1588 GTK_TYPE_DIRECTION_TYPE);
1591 * GtkWidget::delete-event:
1592 * @widget: the object which received the signal
1593 * @event: the event which triggered this signal
1595 * The ::delete-event signal is emitted if a user requests that
1596 * a toplevel window is closed. The default handler for this signal
1597 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1598 * this signal will cause the window to be hidden instead, so that
1599 * it can later be shown again without reconstructing it.
1601 * Returns: %TRUE to stop other handlers from being invoked for the event.
1602 * %FALSE to propagate the event further.
1604 widget_signals[DELETE_EVENT] =
1605 g_signal_new (I_("delete-event"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1608 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1609 _gtk_boolean_handled_accumulator, NULL,
1610 _gtk_marshal_BOOLEAN__BOXED,
1612 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1615 * GtkWidget::destroy-event:
1616 * @widget: the object which received the signal.
1617 * @event: the event which triggered this signal
1619 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1620 * You rarely get this signal, because most widgets disconnect themselves
1621 * from their window before they destroy it, so no widget owns the
1622 * window at destroy time.
1624 * To receive this signal, the #GdkWindow associated to the widget needs
1625 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1626 * automatically for all new windows.
1628 * Returns: %TRUE to stop other handlers from being invoked for the event.
1629 * %FALSE to propagate the event further.
1631 widget_signals[DESTROY_EVENT] =
1632 g_signal_new (I_("destroy-event"),
1633 G_TYPE_FROM_CLASS (gobject_class),
1635 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1636 _gtk_boolean_handled_accumulator, NULL,
1637 _gtk_marshal_BOOLEAN__BOXED,
1639 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1642 * GtkWidget::key-press-event:
1643 * @widget: the object which received the signal
1644 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1646 * The ::key-press-event signal is emitted when a key is pressed.
1648 * To receive this signal, the #GdkWindow associated to the widget needs
1649 * to enable the #GDK_KEY_PRESS_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[KEY_PRESS_EVENT] =
1657 g_signal_new (I_("key-press-event"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1661 _gtk_boolean_handled_accumulator, NULL,
1662 _gtk_marshal_BOOLEAN__BOXED,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkWidget::key-release-event:
1668 * @widget: the object which received the signal
1669 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1671 * The ::key-release-event signal is emitted when a key is pressed.
1673 * To receive this signal, the #GdkWindow associated to the widget needs
1674 * to enable the #GDK_KEY_RELEASE_MASK mask.
1676 * This signal will be sent to the grab widget if there is one.
1678 * Returns: %TRUE to stop other handlers from being invoked for the event.
1679 * %FALSE to propagate the event further.
1681 widget_signals[KEY_RELEASE_EVENT] =
1682 g_signal_new (I_("key-release-event"),
1683 G_TYPE_FROM_CLASS (gobject_class),
1685 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1686 _gtk_boolean_handled_accumulator, NULL,
1687 _gtk_marshal_BOOLEAN__BOXED,
1689 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1692 * GtkWidget::enter-notify-event:
1693 * @widget: the object which received the signal
1694 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1697 * The ::enter-notify-event will be emitted when the pointer enters
1698 * the @widget's window.
1700 * To receive this signal, the #GdkWindow associated to the widget needs
1701 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1703 * This signal will be sent to the grab widget if there is one.
1705 * Returns: %TRUE to stop other handlers from being invoked for the event.
1706 * %FALSE to propagate the event further.
1708 widget_signals[ENTER_NOTIFY_EVENT] =
1709 g_signal_new (I_("enter-notify-event"),
1710 G_TYPE_FROM_CLASS (gobject_class),
1712 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1713 _gtk_boolean_handled_accumulator, NULL,
1714 _gtk_marshal_BOOLEAN__BOXED,
1716 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1719 * GtkWidget::leave-notify-event:
1720 * @widget: the object which received the signal
1721 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1724 * The ::leave-notify-event will be emitted when the pointer leaves
1725 * the @widget's window.
1727 * To receive this signal, the #GdkWindow associated to the widget needs
1728 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1730 * This signal will be sent to the grab widget if there is one.
1732 * Returns: %TRUE to stop other handlers from being invoked for the event.
1733 * %FALSE to propagate the event further.
1735 widget_signals[LEAVE_NOTIFY_EVENT] =
1736 g_signal_new (I_("leave-notify-event"),
1737 G_TYPE_FROM_CLASS (gobject_class),
1739 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1740 _gtk_boolean_handled_accumulator, NULL,
1741 _gtk_marshal_BOOLEAN__BOXED,
1743 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1746 * GtkWidget::configure-event
1747 * @widget: the object which received the signal
1748 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1751 * The ::configure-event signal will be emitted when the size, position or
1752 * stacking of the @widget's window has changed.
1754 * To receive this signal, the #GdkWindow associated to the widget needs
1755 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1756 * automatically for all new windows.
1758 * Returns: %TRUE to stop other handlers from being invoked for the event.
1759 * %FALSE to propagate the event further.
1761 widget_signals[CONFIGURE_EVENT] =
1762 g_signal_new (I_("configure-event"),
1763 G_TYPE_FROM_CLASS (gobject_class),
1765 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1766 _gtk_boolean_handled_accumulator, NULL,
1767 _gtk_marshal_BOOLEAN__BOXED,
1769 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1772 * GtkWidget::focus-in-event
1773 * @widget: the object which received the signal
1774 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1777 * The ::focus-in-event signal will be emitted when the keyboard focus
1778 * enters the @widget's window.
1780 * To receive this signal, the #GdkWindow associated to the widget needs
1781 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1783 * Returns: %TRUE to stop other handlers from being invoked for the event.
1784 * %FALSE to propagate the event further.
1786 widget_signals[FOCUS_IN_EVENT] =
1787 g_signal_new (I_("focus-in-event"),
1788 G_TYPE_FROM_CLASS (gobject_class),
1790 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1791 _gtk_boolean_handled_accumulator, NULL,
1792 _gtk_marshal_BOOLEAN__BOXED,
1794 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1797 * GtkWidget::focus-out-event
1798 * @widget: the object which received the signal
1799 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1802 * The ::focus-out-event signal will be emitted when the keyboard focus
1803 * leaves the @widget's window.
1805 * To receive this signal, the #GdkWindow associated to the widget needs
1806 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1808 * Returns: %TRUE to stop other handlers from being invoked for the event.
1809 * %FALSE to propagate the event further.
1811 widget_signals[FOCUS_OUT_EVENT] =
1812 g_signal_new (I_("focus-out-event"),
1813 G_TYPE_FROM_CLASS (gobject_class),
1815 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1816 _gtk_boolean_handled_accumulator, NULL,
1817 _gtk_marshal_BOOLEAN__BOXED,
1819 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1822 * GtkWidget::map-event
1823 * @widget: the object which received the signal
1824 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1826 * The ::map-event signal will be emitted when the @widget's window is
1827 * mapped. A window is mapped when it becomes visible on the screen.
1829 * To receive this signal, the #GdkWindow associated to the widget needs
1830 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1831 * automatically for all new windows.
1833 * Returns: %TRUE to stop other handlers from being invoked for the event.
1834 * %FALSE to propagate the event further.
1836 widget_signals[MAP_EVENT] =
1837 g_signal_new (I_("map-event"),
1838 G_TYPE_FROM_CLASS (gobject_class),
1840 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1841 _gtk_boolean_handled_accumulator, NULL,
1842 _gtk_marshal_BOOLEAN__BOXED,
1844 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1847 * GtkWidget::unmap-event
1848 * @widget: the object which received the signal
1849 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1851 * The ::unmap-event signal may be emitted when the @widget's window is
1852 * unmapped. A window is unmapped when it becomes invisible on the screen.
1854 * For performance reasons GTK+ may not emit ::unmap-event, so one
1855 * should always also implement ::unrealize in order to release
1856 * resources and disconnect signal handlers.
1858 * To receive this signal, the #GdkWindow associated to the widget needs
1859 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1860 * automatically for all new windows.
1862 * Returns: %TRUE to stop other handlers from being invoked for the event.
1863 * %FALSE to propagate the event further.
1865 widget_signals[UNMAP_EVENT] =
1866 g_signal_new (I_("unmap-event"),
1867 G_TYPE_FROM_CLASS (gobject_class),
1869 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1870 _gtk_boolean_handled_accumulator, NULL,
1871 _gtk_marshal_BOOLEAN__BOXED,
1873 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1876 * GtkWidget::property-notify-event
1877 * @widget: the object which received the signal
1878 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1881 * The ::property-notify-event signal will be emitted when a property on
1882 * the @widget's window has been changed or deleted.
1884 * To receive this signal, the #GdkWindow associated to the widget needs
1885 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1887 * Returns: %TRUE to stop other handlers from being invoked for the event.
1888 * %FALSE to propagate the event further.
1890 widget_signals[PROPERTY_NOTIFY_EVENT] =
1891 g_signal_new (I_("property-notify-event"),
1892 G_TYPE_FROM_CLASS (gobject_class),
1894 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1895 _gtk_boolean_handled_accumulator, NULL,
1896 _gtk_marshal_BOOLEAN__BOXED,
1898 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1901 * GtkWidget::selection-clear-event
1902 * @widget: the object which received the signal
1903 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1906 * The ::selection-clear-event signal will be emitted when the
1907 * the @widget's window has lost ownership of a selection.
1909 * Returns: %TRUE to stop other handlers from being invoked for the event.
1910 * %FALSE to propagate the event further.
1912 widget_signals[SELECTION_CLEAR_EVENT] =
1913 g_signal_new (I_("selection-clear-event"),
1914 G_TYPE_FROM_CLASS (gobject_class),
1916 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1917 _gtk_boolean_handled_accumulator, NULL,
1918 _gtk_marshal_BOOLEAN__BOXED,
1920 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1923 * GtkWidget::selection-request-event
1924 * @widget: the object which received the signal
1925 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1928 * The ::selection-request-event signal will be emitted when
1929 * another client requests ownership of the selection owned by
1930 * the @widget's window.
1932 * Returns: %TRUE to stop other handlers from being invoked for the event.
1933 * %FALSE to propagate the event further.
1935 widget_signals[SELECTION_REQUEST_EVENT] =
1936 g_signal_new (I_("selection-request-event"),
1937 G_TYPE_FROM_CLASS (gobject_class),
1939 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1940 _gtk_boolean_handled_accumulator, NULL,
1941 _gtk_marshal_BOOLEAN__BOXED,
1943 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1946 * GtkWidget::selection-notify-event:
1947 * @widget: the object which received the signal.
1950 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1952 widget_signals[SELECTION_NOTIFY_EVENT] =
1953 g_signal_new (I_("selection-notify-event"),
1954 G_TYPE_FROM_CLASS (gobject_class),
1956 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1957 _gtk_boolean_handled_accumulator, NULL,
1958 _gtk_marshal_BOOLEAN__BOXED,
1960 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1963 * GtkWidget::selection-received:
1964 * @widget: the object which received the signal.
1968 widget_signals[SELECTION_RECEIVED] =
1969 g_signal_new (I_("selection-received"),
1970 G_TYPE_FROM_CLASS (gobject_class),
1972 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1974 _gtk_marshal_VOID__BOXED_UINT,
1976 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1980 * GtkWidget::selection-get:
1981 * @widget: the object which received the signal.
1986 widget_signals[SELECTION_GET] =
1987 g_signal_new (I_("selection-get"),
1988 G_TYPE_FROM_CLASS (gobject_class),
1990 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1992 _gtk_marshal_VOID__BOXED_UINT_UINT,
1994 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1999 * GtkWidget::proximity-in-event
2000 * @widget: the object which received the signal
2001 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2004 * To receive this signal the #GdkWindow associated to the widget needs
2005 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2007 * This signal will be sent to the grab widget if there is one.
2009 * Returns: %TRUE to stop other handlers from being invoked for the event.
2010 * %FALSE to propagate the event further.
2012 widget_signals[PROXIMITY_IN_EVENT] =
2013 g_signal_new (I_("proximity-in-event"),
2014 G_TYPE_FROM_CLASS (gobject_class),
2016 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2017 _gtk_boolean_handled_accumulator, NULL,
2018 _gtk_marshal_BOOLEAN__BOXED,
2020 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2023 * GtkWidget::proximity-out-event
2024 * @widget: the object which received the signal
2025 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2028 * To receive this signal the #GdkWindow associated to the widget needs
2029 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2031 * This signal will be sent to the grab widget if there is one.
2033 * Returns: %TRUE to stop other handlers from being invoked for the event.
2034 * %FALSE to propagate the event further.
2036 widget_signals[PROXIMITY_OUT_EVENT] =
2037 g_signal_new (I_("proximity-out-event"),
2038 G_TYPE_FROM_CLASS (gobject_class),
2040 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2041 _gtk_boolean_handled_accumulator, NULL,
2042 _gtk_marshal_BOOLEAN__BOXED,
2044 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2047 * GtkWidget::drag-leave:
2048 * @widget: the object which received the signal.
2049 * @drag_context: the drag context
2050 * @time: the timestamp of the motion event
2052 * The ::drag-leave signal is emitted on the drop site when the cursor
2053 * leaves the widget. A typical reason to connect to this signal is to
2054 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2055 * with gtk_drag_unhighlight()
2057 widget_signals[DRAG_LEAVE] =
2058 g_signal_new (I_("drag-leave"),
2059 G_TYPE_FROM_CLASS (gobject_class),
2061 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2063 _gtk_marshal_VOID__OBJECT_UINT,
2065 GDK_TYPE_DRAG_CONTEXT,
2069 * GtkWidget::drag-begin:
2070 * @widget: the object which received the signal
2071 * @drag_context: the drag context
2073 * The ::drag-begin signal is emitted on the drag source when a drag is
2074 * started. A typical reason to connect to this signal is to set up a
2075 * custom drag icon with gtk_drag_source_set_icon().
2077 * Note that some widgets set up a drag icon in the default handler of
2078 * this signal, so you may have to use g_signal_connect_after() to
2079 * override what the default handler did.
2081 widget_signals[DRAG_BEGIN] =
2082 g_signal_new (I_("drag-begin"),
2083 G_TYPE_FROM_CLASS (gobject_class),
2085 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2087 _gtk_marshal_VOID__OBJECT,
2089 GDK_TYPE_DRAG_CONTEXT);
2092 * GtkWidget::drag-end:
2093 * @widget: the object which received the signal
2094 * @drag_context: the drag context
2096 * The ::drag-end signal is emitted on the drag source when a drag is
2097 * finished. A typical reason to connect to this signal is to undo
2098 * things done in #GtkWidget::drag-begin.
2100 widget_signals[DRAG_END] =
2101 g_signal_new (I_("drag-end"),
2102 G_TYPE_FROM_CLASS (gobject_class),
2104 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2106 _gtk_marshal_VOID__OBJECT,
2108 GDK_TYPE_DRAG_CONTEXT);
2111 * GtkWidget::drag-data-delete:
2112 * @widget: the object which received the signal
2113 * @drag_context: the drag context
2115 * The ::drag-data-delete signal is emitted on the drag source when a drag
2116 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2117 * handler is responsible for deleting the data that has been dropped. What
2118 * "delete" means depends on the context of the drag operation.
2120 widget_signals[DRAG_DATA_DELETE] =
2121 g_signal_new (I_("drag-data-delete"),
2122 G_TYPE_FROM_CLASS (gobject_class),
2124 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2126 _gtk_marshal_VOID__OBJECT,
2128 GDK_TYPE_DRAG_CONTEXT);
2131 * GtkWidget::drag-failed:
2132 * @widget: the object which received the signal
2133 * @drag_context: the drag context
2134 * @result: the result of the drag operation
2136 * The ::drag-failed signal is emitted on the drag source when a drag has
2137 * failed. The signal handler may hook custom code to handle a failed DND
2138 * operation based on the type of error, it returns %TRUE is the failure has
2139 * been already handled (not showing the default "drag operation failed"
2140 * animation), otherwise it returns %FALSE.
2142 * Return value: %TRUE if the failed drag operation has been already handled.
2146 widget_signals[DRAG_FAILED] =
2147 g_signal_new (I_("drag-failed"),
2148 G_TYPE_FROM_CLASS (gobject_class),
2150 0, _gtk_boolean_handled_accumulator, NULL,
2151 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2153 GDK_TYPE_DRAG_CONTEXT,
2154 GTK_TYPE_DRAG_RESULT);
2157 * GtkWidget::drag-motion:
2158 * @widget: the object which received the signal
2159 * @drag_context: the drag context
2160 * @x: the x coordinate of the current cursor position
2161 * @y: the y coordinate of the current cursor position
2162 * @time: the timestamp of the motion event
2163 * @returns: whether the cursor position is in a drop zone
2165 * The drag-motion signal is emitted on the drop site when the user
2166 * moves the cursor over the widget during a drag. The signal handler
2167 * must determine whether the cursor position is in a drop zone or not.
2168 * If it is not in a drop zone, it returns %FALSE and no further processing
2169 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2170 * handler is responsible for providing the necessary information for
2171 * displaying feedback to the user, by calling gdk_drag_status().
2173 * If the decision whether the drop will be accepted or rejected can't be
2174 * made based solely on the cursor position and the type of the data, the
2175 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2176 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2177 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2178 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2179 * when using the drag-motion signal that way.
2181 * Also note that there is no drag-enter signal. The drag receiver has to
2182 * keep track of whether he has received any drag-motion signals since the
2183 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2184 * an "enter" signal. Upon an "enter", the handler will typically highlight
2185 * the drop site with gtk_drag_highlight().
2188 * drag_motion (GtkWidget *widget,
2189 * GdkDragContext *context,
2196 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2198 * if (!private_data->drag_highlight)
2200 * private_data->drag_highlight = 1;
2201 * gtk_drag_highlight (widget);
2204 * target = gtk_drag_dest_find_target (widget, context, NULL);
2205 * if (target == GDK_NONE)
2206 * gdk_drag_status (context, 0, time);
2209 * private_data->pending_status = context->suggested_action;
2210 * gtk_drag_get_data (widget, context, target, time);
2217 * drag_data_received (GtkWidget *widget,
2218 * GdkDragContext *context,
2221 * GtkSelectionData *selection_data,
2225 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2227 * if (private_data->suggested_action)
2229 * private_data->suggested_action = 0;
2231 * /* We are getting this data due to a request in drag_motion,
2232 * * rather than due to a request in drag_drop, so we are just
2233 * * supposed to call gdk_drag_status (), not actually paste in
2236 * str = gtk_selection_data_get_text (selection_data);
2237 * if (!data_is_acceptable (str))
2238 * gdk_drag_status (context, 0, time);
2240 * gdk_drag_status (context, private_data->suggested_action, time);
2244 * /* accept the drop */
2249 widget_signals[DRAG_MOTION] =
2250 g_signal_new (I_("drag-motion"),
2251 G_TYPE_FROM_CLASS (gobject_class),
2253 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2254 _gtk_boolean_handled_accumulator, NULL,
2255 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2257 GDK_TYPE_DRAG_CONTEXT,
2263 * GtkWidget::drag-drop:
2264 * @widget: the object which received the signal
2265 * @drag_context: the drag context
2266 * @x: the x coordinate of the current cursor position
2267 * @y: the y coordinate of the current cursor position
2268 * @time: the timestamp of the motion event
2269 * @returns: whether the cursor position is in a drop zone
2271 * The ::drag-drop signal is emitted on the drop site when the user drops
2272 * the data onto the widget. The signal handler must determine whether
2273 * the cursor position is in a drop zone or not. If it is not in a drop
2274 * zone, it returns %FALSE and no further processing is necessary.
2275 * Otherwise, the handler returns %TRUE. In this case, the handler must
2276 * ensure that gtk_drag_finish() is called to let the source know that
2277 * the drop is done. The call to gtk_drag_finish() can be done either
2278 * directly or in a #GtkWidget::drag-data-received handler which gets
2279 * triggered by calling gtk_drag_get_data() to receive the data for one
2280 * or more of the supported targets.
2282 widget_signals[DRAG_DROP] =
2283 g_signal_new (I_("drag-drop"),
2284 G_TYPE_FROM_CLASS (gobject_class),
2286 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2287 _gtk_boolean_handled_accumulator, NULL,
2288 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2290 GDK_TYPE_DRAG_CONTEXT,
2296 * GtkWidget::drag-data-get:
2297 * @widget: the object which received the signal
2298 * @drag_context: the drag context
2299 * @data: the #GtkSelectionData to be filled with the dragged data
2300 * @info: the info that has been registered with the target in the
2302 * @time: the timestamp at which the data was requested
2304 * The ::drag-data-get signal is emitted on the drag source when the drop
2305 * site requests the data which is dragged. It is the responsibility of
2306 * the signal handler to fill @data with the data in the format which
2307 * is indicated by @info. See gtk_selection_data_set() and
2308 * gtk_selection_data_set_text().
2310 widget_signals[DRAG_DATA_GET] =
2311 g_signal_new (I_("drag-data-get"),
2312 G_TYPE_FROM_CLASS (gobject_class),
2314 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2316 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2318 GDK_TYPE_DRAG_CONTEXT,
2319 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2324 * GtkWidget::drag-data-received:
2325 * @widget: the object which received the signal
2326 * @drag_context: the drag context
2327 * @x: where the drop happened
2328 * @y: where the drop happened
2329 * @data: the received data
2330 * @info: the info that has been registered with the target in the
2332 * @time: the timestamp at which the data was received
2334 * The ::drag-data-received signal is emitted on the drop site when the
2335 * dragged data has been received. If the data was received in order to
2336 * determine whether the drop will be accepted, the handler is expected
2337 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2338 * If the data was received in response to a #GtkWidget::drag-drop signal
2339 * (and this is the last target to be received), the handler for this
2340 * signal is expected to process the received data and then call
2341 * gtk_drag_finish(), setting the @success parameter depending on whether
2342 * the data was processed successfully.
2344 * The handler may inspect and modify @drag_context->action before calling
2345 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2346 * following example:
2349 * drag_data_received (GtkWidget *widget,
2350 * GdkDragContext *drag_context,
2353 * GtkSelectionData *data,
2357 * if ((data->length >= 0) && (data->format == 8))
2359 * if (drag_context->action == GDK_ACTION_ASK)
2361 * GtkWidget *dialog;
2364 * dialog = gtk_message_dialog_new (NULL,
2365 * GTK_DIALOG_MODAL |
2366 * GTK_DIALOG_DESTROY_WITH_PARENT,
2368 * GTK_BUTTONS_YES_NO,
2369 * "Move the data ?\n");
2370 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2371 * gtk_widget_destroy (dialog);
2373 * if (response == GTK_RESPONSE_YES)
2374 * drag_context->action = GDK_ACTION_MOVE;
2376 * drag_context->action = GDK_ACTION_COPY;
2379 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2383 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2387 widget_signals[DRAG_DATA_RECEIVED] =
2388 g_signal_new (I_("drag-data-received"),
2389 G_TYPE_FROM_CLASS (gobject_class),
2391 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2393 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2395 GDK_TYPE_DRAG_CONTEXT,
2398 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2403 * GtkWidget::visibility-notify-event:
2404 * @widget: the object which received the signal
2405 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2406 * triggered this signal.
2408 * The ::visibility-notify-event will be emitted when the @widget's window
2409 * is obscured or unobscured.
2411 * To receive this signal the #GdkWindow associated to the widget needs
2412 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2414 * Returns: %TRUE to stop other handlers from being invoked for the event.
2415 * %FALSE to propagate the event further.
2417 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2418 g_signal_new (I_("visibility-notify-event"),
2419 G_TYPE_FROM_CLASS (gobject_class),
2421 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2422 _gtk_boolean_handled_accumulator, NULL,
2423 _gtk_marshal_BOOLEAN__BOXED,
2425 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2428 * GtkWidget::client-event:
2429 * @widget: the object which received the signal
2430 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2433 * The ::client-event will be emitted when the @widget's window
2434 * receives a message (via a ClientMessage event) from another
2437 * Returns: %TRUE to stop other handlers from being invoked for
2438 * the event. %FALSE to propagate the event further.
2440 widget_signals[CLIENT_EVENT] =
2441 g_signal_new (I_("client-event"),
2442 G_TYPE_FROM_CLASS (gobject_class),
2444 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2445 _gtk_boolean_handled_accumulator, NULL,
2446 _gtk_marshal_BOOLEAN__BOXED,
2448 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2451 * GtkWidget::no-expose-event:
2452 * @widget: the object which received the signal
2453 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2456 * The ::no-expose-event will be emitted when the @widget's window is
2457 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2458 * If the source window was partially obscured #GdkEventExpose events will
2459 * be generated for those areas.
2461 * Returns: %TRUE to stop other handlers from being invoked for the event.
2462 * %FALSE to propagate the event further.
2464 widget_signals[NO_EXPOSE_EVENT] =
2465 g_signal_new (I_("no-expose-event"),
2466 G_TYPE_FROM_CLASS (gobject_class),
2468 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2469 _gtk_boolean_handled_accumulator, NULL,
2470 _gtk_marshal_BOOLEAN__BOXED,
2472 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2475 * GtkWidget::window-state-event:
2476 * @widget: the object which received the signal
2477 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2478 * triggered this signal.
2480 * The ::window-state-event will be emitted when the state of the
2481 * toplevel window associated to the @widget changes.
2483 * To receive this signal the #GdkWindow associated to the widget
2484 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2485 * this mask automatically for all new windows.
2487 * Returns: %TRUE to stop other handlers from being invoked for the
2488 * event. %FALSE to propagate the event further.
2490 widget_signals[WINDOW_STATE_EVENT] =
2491 g_signal_new (I_("window-state-event"),
2492 G_TYPE_FROM_CLASS (gobject_class),
2494 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2495 _gtk_boolean_handled_accumulator, NULL,
2496 _gtk_marshal_BOOLEAN__BOXED,
2498 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2501 * GtkWidget::damage-event:
2502 * @widget: the object which received the signal
2503 * @event: the #GdkEventExpose event
2505 * Emitted when a redirected window belonging to @widget gets drawn into.
2506 * The region/area members of the event shows what area of the redirected
2507 * drawable was drawn into.
2509 * Returns: %TRUE to stop other handlers from being invoked for the event.
2510 * %FALSE to propagate the event further.
2514 widget_signals[DAMAGE_EVENT] =
2515 g_signal_new (I_("damage-event"),
2516 G_TYPE_FROM_CLASS (gobject_class),
2519 _gtk_boolean_handled_accumulator, NULL,
2520 _gtk_marshal_BOOLEAN__BOXED,
2522 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2524 * GtkWidget::grab-broken-event:
2525 * @widget: the object which received the signal
2526 * @event: the #GdkEventGrabBroken event
2528 * Emitted when a pointer or keyboard grab on a window belonging
2529 * to @widget gets broken.
2531 * On X11, this happens when the grab window becomes unviewable
2532 * (i.e. it or one of its ancestors is unmapped), or if the same
2533 * application grabs the pointer or keyboard again.
2535 * Returns: %TRUE to stop other handlers from being invoked for
2536 * the event. %FALSE to propagate the event further.
2540 widget_signals[GRAB_BROKEN] =
2541 g_signal_new (I_("grab-broken-event"),
2542 G_TYPE_FROM_CLASS (gobject_class),
2544 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2545 _gtk_boolean_handled_accumulator, NULL,
2546 _gtk_marshal_BOOLEAN__BOXED,
2548 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2550 * GtkWidget::query-tooltip:
2551 * @widget: the object which received the signal
2552 * @x: the x coordinate of the cursor position where the request has
2553 * been emitted, relative to @widget->window
2554 * @y: the y coordinate of the cursor position where the request has
2555 * been emitted, relative to @widget->window
2556 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2557 * @tooltip: a #GtkTooltip
2559 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2560 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2561 * focus in keyboard mode.
2563 * Using the given coordinates, the signal handler should determine
2564 * whether a tooltip should be shown for @widget. If this is the case
2565 * %TRUE should be returned, %FALSE otherwise. Note that if
2566 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2567 * should not be used.
2569 * The signal handler is free to manipulate @tooltip with the therefore
2570 * destined function calls.
2572 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2576 widget_signals[QUERY_TOOLTIP] =
2577 g_signal_new (I_("query-tooltip"),
2578 G_TYPE_FROM_CLASS (gobject_class),
2580 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2581 _gtk_boolean_handled_accumulator, NULL,
2582 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2590 * GtkWidget::popup-menu
2591 * @widget: the object which received the signal
2593 * This signal gets emitted whenever a widget should pop up a context
2594 * menu. This usually happens through the standard key binding mechanism;
2595 * by pressing a certain key while a widget is focused, the user can cause
2596 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2597 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2598 * for an example of how to use this signal.
2600 * Returns: %TRUE if a menu was activated
2602 widget_signals[POPUP_MENU] =
2603 g_signal_new (I_("popup-menu"),
2604 G_TYPE_FROM_CLASS (gobject_class),
2605 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2606 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2607 _gtk_boolean_handled_accumulator, NULL,
2608 _gtk_marshal_BOOLEAN__VOID,
2612 * GtkWidget::show-help:
2613 * @widget: the object which received the signal.
2616 widget_signals[SHOW_HELP] =
2617 g_signal_new (I_("show-help"),
2618 G_TYPE_FROM_CLASS (gobject_class),
2619 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2620 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2621 _gtk_boolean_handled_accumulator, NULL,
2622 _gtk_marshal_BOOLEAN__ENUM,
2624 GTK_TYPE_WIDGET_HELP_TYPE);
2627 * GtkWidget::accel-closures-changed:
2628 * @widget: the object which received the signal.
2630 widget_signals[ACCEL_CLOSURES_CHANGED] =
2631 g_signal_new (I_("accel-closures-changed"),
2632 G_TYPE_FROM_CLASS (gobject_class),
2636 _gtk_marshal_VOID__VOID,
2640 * GtkWidget::screen-changed:
2641 * @widget: the object on which the signal is emitted
2642 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2643 * widget was not associated with a screen before
2645 * The ::screen-changed signal gets emitted when the
2646 * screen of a widget has changed.
2648 widget_signals[SCREEN_CHANGED] =
2649 g_signal_new (I_("screen-changed"),
2650 G_TYPE_FROM_CLASS (gobject_class),
2652 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2654 _gtk_marshal_VOID__OBJECT,
2659 * GtkWidget::can-activate-accel:
2660 * @widget: the object which received the signal
2661 * @signal_id: the ID of a signal installed on @widget
2663 * Determines whether an accelerator that activates the signal
2664 * identified by @signal_id can currently be activated.
2665 * This signal is present to allow applications and derived
2666 * widgets to override the default #GtkWidget handling
2667 * for determining whether an accelerator can be activated.
2669 * Returns: %TRUE if the signal can be activated.
2671 widget_signals[CAN_ACTIVATE_ACCEL] =
2672 g_signal_new (I_("can-activate-accel"),
2673 G_TYPE_FROM_CLASS (gobject_class),
2675 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2676 _gtk_boolean_handled_accumulator, NULL,
2677 _gtk_marshal_BOOLEAN__UINT,
2678 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2680 binding_set = gtk_binding_set_by_class (klass);
2681 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2683 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2686 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2688 GTK_TYPE_WIDGET_HELP_TYPE,
2689 GTK_WIDGET_HELP_TOOLTIP);
2690 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2692 GTK_TYPE_WIDGET_HELP_TYPE,
2693 GTK_WIDGET_HELP_TOOLTIP);
2694 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2696 GTK_TYPE_WIDGET_HELP_TYPE,
2697 GTK_WIDGET_HELP_WHATS_THIS);
2698 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2700 GTK_TYPE_WIDGET_HELP_TYPE,
2701 GTK_WIDGET_HELP_WHATS_THIS);
2703 gtk_widget_class_install_style_property (klass,
2704 g_param_spec_boolean ("interior-focus",
2705 P_("Interior Focus"),
2706 P_("Whether to draw the focus indicator inside widgets"),
2708 GTK_PARAM_READABLE));
2710 gtk_widget_class_install_style_property (klass,
2711 g_param_spec_int ("focus-line-width",
2712 P_("Focus linewidth"),
2713 P_("Width, in pixels, of the focus indicator line"),
2715 GTK_PARAM_READABLE));
2717 gtk_widget_class_install_style_property (klass,
2718 g_param_spec_string ("focus-line-pattern",
2719 P_("Focus line dash pattern"),
2720 P_("Dash pattern used to draw the focus indicator"),
2722 GTK_PARAM_READABLE));
2723 gtk_widget_class_install_style_property (klass,
2724 g_param_spec_int ("focus-padding",
2725 P_("Focus padding"),
2726 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2728 GTK_PARAM_READABLE));
2729 gtk_widget_class_install_style_property (klass,
2730 g_param_spec_boxed ("cursor-color",
2732 P_("Color with which to draw insertion cursor"),
2734 GTK_PARAM_READABLE));
2735 gtk_widget_class_install_style_property (klass,
2736 g_param_spec_boxed ("secondary-cursor-color",
2737 P_("Secondary cursor color"),
2738 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2740 GTK_PARAM_READABLE));
2741 gtk_widget_class_install_style_property (klass,
2742 g_param_spec_float ("cursor-aspect-ratio",
2743 P_("Cursor line aspect ratio"),
2744 P_("Aspect ratio with which to draw insertion cursor"),
2746 GTK_PARAM_READABLE));
2748 gtk_widget_class_install_style_property (klass,
2749 g_param_spec_boolean ("window-dragging",
2750 P_("Window dragging"),
2751 P_("Whether windows can be dragged by clicking on empty areas"),
2753 GTK_PARAM_READABLE));
2756 * GtkWidget:link-color:
2758 * The "link-color" style property defines the color of unvisited links.
2762 gtk_widget_class_install_style_property (klass,
2763 g_param_spec_boxed ("link-color",
2764 P_("Unvisited Link Color"),
2765 P_("Color of unvisited links"),
2767 GTK_PARAM_READABLE));
2770 * GtkWidget:visited-link-color:
2772 * The "visited-link-color" style property defines the color of visited links.
2776 gtk_widget_class_install_style_property (klass,
2777 g_param_spec_boxed ("visited-link-color",
2778 P_("Visited Link Color"),
2779 P_("Color of visited links"),
2781 GTK_PARAM_READABLE));
2784 * GtkWidget:wide-separators:
2786 * The "wide-separators" style property defines whether separators have
2787 * configurable width and should be drawn using a box instead of a line.
2791 gtk_widget_class_install_style_property (klass,
2792 g_param_spec_boolean ("wide-separators",
2793 P_("Wide Separators"),
2794 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2796 GTK_PARAM_READABLE));
2799 * GtkWidget:separator-width:
2801 * The "separator-width" style property defines the width of separators.
2802 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2806 gtk_widget_class_install_style_property (klass,
2807 g_param_spec_int ("separator-width",
2808 P_("Separator Width"),
2809 P_("The width of separators if wide-separators is TRUE"),
2811 GTK_PARAM_READABLE));
2814 * GtkWidget:separator-height:
2816 * The "separator-height" style property defines the height of separators.
2817 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2821 gtk_widget_class_install_style_property (klass,
2822 g_param_spec_int ("separator-height",
2823 P_("Separator Height"),
2824 P_("The height of separators if \"wide-separators\" is TRUE"),
2826 GTK_PARAM_READABLE));
2829 * GtkWidget:scroll-arrow-hlength:
2831 * The "scroll-arrow-hlength" style property defines the length of
2832 * horizontal scroll arrows.
2836 gtk_widget_class_install_style_property (klass,
2837 g_param_spec_int ("scroll-arrow-hlength",
2838 P_("Horizontal Scroll Arrow Length"),
2839 P_("The length of horizontal scroll arrows"),
2841 GTK_PARAM_READABLE));
2844 * GtkWidget:scroll-arrow-vlength:
2846 * The "scroll-arrow-vlength" style property defines the length of
2847 * vertical scroll arrows.
2851 gtk_widget_class_install_style_property (klass,
2852 g_param_spec_int ("scroll-arrow-vlength",
2853 P_("Vertical Scroll Arrow Length"),
2854 P_("The length of vertical scroll arrows"),
2856 GTK_PARAM_READABLE));
2858 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2862 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2866 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2867 for (node = list; node; node = node->next)
2869 GParamSpec *pspec = node->data;
2871 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2872 g_param_spec_unref (pspec);
2878 gtk_widget_set_property (GObject *object,
2880 const GValue *value,
2883 GtkWidget *widget = GTK_WIDGET (object);
2888 gchar *tooltip_markup;
2889 const gchar *tooltip_text;
2890 GtkWindow *tooltip_window;
2893 gtk_widget_set_name (widget, g_value_get_string (value));
2896 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2898 case PROP_WIDTH_REQUEST:
2899 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2901 case PROP_HEIGHT_REQUEST:
2902 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2905 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2907 case PROP_SENSITIVE:
2908 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2910 case PROP_APP_PAINTABLE:
2911 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2913 case PROP_CAN_FOCUS:
2914 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2916 case PROP_HAS_FOCUS:
2917 if (g_value_get_boolean (value))
2918 gtk_widget_grab_focus (widget);
2921 if (g_value_get_boolean (value))
2922 gtk_widget_grab_focus (widget);
2924 case PROP_CAN_DEFAULT:
2925 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2927 case PROP_HAS_DEFAULT:
2928 if (g_value_get_boolean (value))
2929 gtk_widget_grab_default (widget);
2931 case PROP_RECEIVES_DEFAULT:
2932 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2935 gtk_widget_set_style (widget, g_value_get_object (value));
2938 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2939 gtk_widget_set_events (widget, g_value_get_flags (value));
2941 case PROP_EXTENSION_EVENTS:
2942 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2944 case PROP_NO_SHOW_ALL:
2945 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2947 case PROP_HAS_TOOLTIP:
2948 gtk_widget_real_set_has_tooltip (widget,
2949 g_value_get_boolean (value), FALSE);
2951 case PROP_TOOLTIP_MARKUP:
2952 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2953 tooltip_markup = g_value_dup_string (value);
2955 /* Treat an empty string as a NULL string,
2956 * because an empty string would be useless for a tooltip:
2958 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2960 g_free (tooltip_markup);
2961 tooltip_markup = NULL;
2964 g_object_set_qdata_full (object, quark_tooltip_markup,
2965 tooltip_markup, g_free);
2967 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2968 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2969 if (gtk_widget_get_visible (widget))
2970 gtk_widget_queue_tooltip_query (widget);
2972 case PROP_TOOLTIP_TEXT:
2973 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2975 tooltip_text = g_value_get_string (value);
2977 /* Treat an empty string as a NULL string,
2978 * because an empty string would be useless for a tooltip:
2980 if (tooltip_text && (strlen (tooltip_text) == 0))
2981 tooltip_text = NULL;
2983 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2985 g_object_set_qdata_full (object, quark_tooltip_markup,
2986 tooltip_markup, g_free);
2988 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2989 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2990 if (gtk_widget_get_visible (widget))
2991 gtk_widget_queue_tooltip_query (widget);
2993 case PROP_DOUBLE_BUFFERED:
2994 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2997 gtk_widget_set_halign (widget, g_value_get_enum (value));
3000 gtk_widget_set_valign (widget, g_value_get_enum (value));
3002 case PROP_MARGIN_LEFT:
3003 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3005 case PROP_MARGIN_RIGHT:
3006 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3008 case PROP_MARGIN_TOP:
3009 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3011 case PROP_MARGIN_BOTTOM:
3012 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3015 g_object_freeze_notify (G_OBJECT (widget));
3016 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3017 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3018 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3019 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3020 g_object_thaw_notify (G_OBJECT (widget));
3023 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3029 gtk_widget_get_property (GObject *object,
3034 GtkWidget *widget = GTK_WIDGET (object);
3035 GtkWidgetPrivate *priv = widget->priv;
3044 g_value_set_string (value, priv->name);
3046 g_value_set_static_string (value, "");
3049 g_value_set_object (value, priv->parent);
3051 case PROP_WIDTH_REQUEST:
3054 gtk_widget_get_size_request (widget, &w, NULL);
3055 g_value_set_int (value, w);
3058 case PROP_HEIGHT_REQUEST:
3061 gtk_widget_get_size_request (widget, NULL, &h);
3062 g_value_set_int (value, h);
3066 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3068 case PROP_SENSITIVE:
3069 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3071 case PROP_APP_PAINTABLE:
3072 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3074 case PROP_CAN_FOCUS:
3075 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3077 case PROP_HAS_FOCUS:
3078 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3081 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3083 case PROP_CAN_DEFAULT:
3084 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3086 case PROP_HAS_DEFAULT:
3087 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3089 case PROP_RECEIVES_DEFAULT:
3090 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3092 case PROP_COMPOSITE_CHILD:
3093 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3096 g_value_set_object (value, gtk_widget_get_style (widget));
3099 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3100 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3102 case PROP_EXTENSION_EVENTS:
3103 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3104 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3106 case PROP_NO_SHOW_ALL:
3107 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3109 case PROP_HAS_TOOLTIP:
3110 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3112 case PROP_TOOLTIP_TEXT:
3114 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3117 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3118 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3120 g_value_take_string (value, text);
3123 case PROP_TOOLTIP_MARKUP:
3124 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3127 g_value_set_object (value, gtk_widget_get_window (widget));
3129 case PROP_DOUBLE_BUFFERED:
3130 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3133 g_value_set_enum (value, gtk_widget_get_halign (widget));
3136 g_value_set_enum (value, gtk_widget_get_valign (widget));
3138 case PROP_MARGIN_LEFT:
3139 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3141 case PROP_MARGIN_RIGHT:
3142 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3144 case PROP_MARGIN_TOP:
3145 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3147 case PROP_MARGIN_BOTTOM:
3148 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3152 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3153 if (aux_info == NULL)
3155 g_value_set_int (value, 0);
3159 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3160 aux_info->margin.right),
3161 MAX (aux_info->margin.top,
3162 aux_info->margin.bottom)));
3167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3173 gtk_widget_init (GtkWidget *widget)
3175 GtkWidgetPrivate *priv;
3177 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3180 priv = widget->priv;
3182 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3183 priv->state = GTK_STATE_NORMAL;
3184 priv->saved_state = GTK_STATE_NORMAL;
3186 priv->allocation.x = -1;
3187 priv->allocation.y = -1;
3188 priv->allocation.width = 1;
3189 priv->allocation.height = 1;
3190 priv->window = NULL;
3191 priv->parent = NULL;
3193 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3194 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3195 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3196 gtk_widget_set_double_buffered (widget, TRUE);
3198 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3199 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3200 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3201 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3203 priv->style = gtk_widget_get_default_style ();
3204 g_object_ref (priv->style);
3209 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3211 GParamSpec **pspecs)
3213 GtkWidgetPrivate *priv = widget->priv;
3214 GtkWidget *container = priv->parent;
3217 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3218 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3222 * gtk_widget_freeze_child_notify:
3223 * @widget: a #GtkWidget
3225 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3226 * signals are queued until gtk_widget_thaw_child_notify() is called
3229 * This is the analogue of g_object_freeze_notify() for child properties.
3232 gtk_widget_freeze_child_notify (GtkWidget *widget)
3234 g_return_if_fail (GTK_IS_WIDGET (widget));
3236 if (!G_OBJECT (widget)->ref_count)
3239 g_object_ref (widget);
3240 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3241 g_object_unref (widget);
3245 * gtk_widget_child_notify:
3246 * @widget: a #GtkWidget
3247 * @child_property: the name of a child property installed on the
3248 * class of @widget<!-- -->'s parent
3250 * Emits a #GtkWidget::child-notify signal for the
3251 * <link linkend="child-properties">child property</link> @child_property
3254 * This is the analogue of g_object_notify() for child properties.
3257 gtk_widget_child_notify (GtkWidget *widget,
3258 const gchar *child_property)
3260 GtkWidgetPrivate *priv = widget->priv;
3263 g_return_if_fail (GTK_IS_WIDGET (widget));
3264 g_return_if_fail (child_property != NULL);
3265 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3268 g_object_ref (widget);
3269 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3271 G_OBJECT_TYPE (priv->parent),
3274 g_warning ("%s: container class `%s' has no child property named `%s'",
3276 G_OBJECT_TYPE_NAME (priv->parent),
3280 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3282 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3283 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3285 g_object_unref (widget);
3289 * gtk_widget_thaw_child_notify:
3290 * @widget: a #GtkWidget
3292 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3293 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3297 gtk_widget_thaw_child_notify (GtkWidget *widget)
3299 GObjectNotifyQueue *nqueue;
3301 g_return_if_fail (GTK_IS_WIDGET (widget));
3303 if (!G_OBJECT (widget)->ref_count)
3306 g_object_ref (widget);
3307 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3308 if (!nqueue || !nqueue->freeze_count)
3309 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3310 G_OBJECT_TYPE_NAME (widget), widget);
3312 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3313 g_object_unref (widget);
3319 * @type: type ID of the widget to create
3320 * @first_property_name: name of first property to set
3321 * @Varargs: value of first property, followed by more properties,
3324 * This is a convenience function for creating a widget and setting
3325 * its properties in one go. For example you might write:
3326 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3327 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3328 * g_object_new(), but returns a widget so you don't have to
3329 * cast the object yourself.
3331 * Return value: a new #GtkWidget of type @widget_type
3334 gtk_widget_new (GType type,
3335 const gchar *first_property_name,
3341 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3343 va_start (var_args, first_property_name);
3344 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3351 gtk_widget_queue_draw_child (GtkWidget *widget)
3353 GtkWidgetPrivate *priv = widget->priv;
3356 parent = priv->parent;
3357 if (parent && gtk_widget_is_drawable (parent))
3358 gtk_widget_queue_draw_area (parent,
3361 priv->allocation.width,
3362 priv->allocation.height);
3366 * gtk_widget_unparent:
3367 * @widget: a #GtkWidget
3369 * This function is only for use in widget implementations.
3370 * Should be called by implementations of the remove method
3371 * on #GtkContainer, to dissociate a child from the container.
3374 gtk_widget_unparent (GtkWidget *widget)
3376 GtkWidgetPrivate *priv;
3377 GObjectNotifyQueue *nqueue;
3378 GtkWidget *toplevel;
3379 GtkWidget *old_parent;
3381 g_return_if_fail (GTK_IS_WIDGET (widget));
3383 priv = widget->priv;
3385 if (priv->parent == NULL)
3388 /* keep this function in sync with gtk_menu_detach()
3391 g_object_freeze_notify (G_OBJECT (widget));
3392 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3394 toplevel = gtk_widget_get_toplevel (widget);
3395 if (gtk_widget_is_toplevel (toplevel))
3396 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3398 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3399 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3401 /* If we are unanchoring the child, we save around the toplevel
3402 * to emit hierarchy changed
3404 if (GTK_WIDGET_ANCHORED (priv->parent))
3405 g_object_ref (toplevel);
3409 gtk_widget_queue_draw_child (widget);
3411 /* Reset the width and height here, to force reallocation if we
3412 * get added back to a new parent. This won't work if our new
3413 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3414 * (would 0x0 be OK here?)
3416 priv->allocation.width = 1;
3417 priv->allocation.height = 1;
3419 if (gtk_widget_get_realized (widget))
3421 if (GTK_WIDGET_IN_REPARENT (widget))
3422 gtk_widget_unmap (widget);
3424 gtk_widget_unrealize (widget);
3427 /* Removing a widget from a container restores the child visible
3428 * flag to the default state, so it doesn't affect the child
3429 * in the next parent.
3431 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3433 old_parent = priv->parent;
3434 priv->parent = NULL;
3435 gtk_widget_set_parent_window (widget, NULL);
3436 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3439 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3440 g_object_unref (toplevel);
3443 g_object_notify (G_OBJECT (widget), "parent");
3444 g_object_thaw_notify (G_OBJECT (widget));
3446 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3447 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3448 g_object_unref (widget);
3452 * gtk_widget_destroy:
3453 * @widget: a #GtkWidget
3455 * Destroys a widget.
3458 * destroyed, it will break any references it holds to other objects.
3459 * If the widget is inside a container, the widget will be removed
3460 * from the container. If the widget is a toplevel (derived from
3461 * #GtkWindow), it will be removed from the list of toplevels, and the
3462 * reference GTK+ holds to it will be removed. Removing a
3463 * widget from its container or the list of toplevels results in the
3464 * widget being finalized, unless you've added additional references
3465 * to the widget with g_object_ref().
3467 * In most cases, only toplevel widgets (windows) require explicit
3468 * destruction, because when you destroy a toplevel its children will
3469 * be destroyed as well.
3472 gtk_widget_destroy (GtkWidget *widget)
3474 g_return_if_fail (GTK_IS_WIDGET (widget));
3476 if (!widget->priv->in_destruction)
3477 g_object_run_dispose (G_OBJECT (widget));
3481 * gtk_widget_destroyed:
3482 * @widget: a #GtkWidget
3483 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3485 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3486 * %NULL. It's intended to be used as a callback connected to the
3487 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3488 * as a signal handler, and pass the address of your widget variable
3489 * as user data. Then when the widget is destroyed, the variable will
3490 * be set to %NULL. Useful for example to avoid multiple copies
3491 * of the same dialog.
3494 gtk_widget_destroyed (GtkWidget *widget,
3495 GtkWidget **widget_pointer)
3497 /* Don't make any assumptions about the
3499 * Even check widget_pointer.
3502 *widget_pointer = NULL;
3507 * @widget: a #GtkWidget
3509 * Flags a widget to be displayed. Any widget that isn't shown will
3510 * not appear on the screen. If you want to show all the widgets in a
3511 * container, it's easier to call gtk_widget_show_all() on the
3512 * container, instead of individually showing the widgets.
3514 * Remember that you have to show the containers containing a widget,
3515 * in addition to the widget itself, before it will appear onscreen.
3517 * When a toplevel container is shown, it is immediately realized and
3518 * mapped; other shown widgets are realized and mapped when their
3519 * toplevel container is realized and mapped.
3522 gtk_widget_show (GtkWidget *widget)
3524 g_return_if_fail (GTK_IS_WIDGET (widget));
3526 if (!gtk_widget_get_visible (widget))
3528 g_object_ref (widget);
3529 if (!gtk_widget_is_toplevel (widget))
3530 gtk_widget_queue_resize (widget);
3531 g_signal_emit (widget, widget_signals[SHOW], 0);
3532 g_object_notify (G_OBJECT (widget), "visible");
3533 g_object_unref (widget);
3538 gtk_widget_real_show (GtkWidget *widget)
3540 GtkWidgetPrivate *priv = widget->priv;
3542 if (!gtk_widget_get_visible (widget))
3544 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3547 gtk_widget_get_mapped (priv->parent) &&
3548 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3549 !gtk_widget_get_mapped (widget))
3550 gtk_widget_map (widget);
3555 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3558 g_signal_handlers_disconnect_by_func (widget,
3559 gtk_widget_show_map_callback,
3564 * gtk_widget_show_now:
3565 * @widget: a #GtkWidget
3567 * Shows a widget. If the widget is an unmapped toplevel widget
3568 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3569 * loop and wait for the window to actually be mapped. Be careful;
3570 * because the main loop is running, anything can happen during
3574 gtk_widget_show_now (GtkWidget *widget)
3578 g_return_if_fail (GTK_IS_WIDGET (widget));
3580 /* make sure we will get event */
3581 if (!gtk_widget_get_mapped (widget) &&
3582 gtk_widget_is_toplevel (widget))
3584 gtk_widget_show (widget);
3586 g_signal_connect (widget, "map-event",
3587 G_CALLBACK (gtk_widget_show_map_callback),
3591 gtk_main_iteration ();
3594 gtk_widget_show (widget);
3599 * @widget: a #GtkWidget
3601 * Reverses the effects of gtk_widget_show(), causing the widget to be
3602 * hidden (invisible to the user).
3605 gtk_widget_hide (GtkWidget *widget)
3607 g_return_if_fail (GTK_IS_WIDGET (widget));
3609 if (gtk_widget_get_visible (widget))
3611 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3613 g_object_ref (widget);
3614 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3615 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3617 g_signal_emit (widget, widget_signals[HIDE], 0);
3618 if (!gtk_widget_is_toplevel (widget))
3619 gtk_widget_queue_resize (widget);
3620 g_object_notify (G_OBJECT (widget), "visible");
3621 g_object_unref (widget);
3626 gtk_widget_real_hide (GtkWidget *widget)
3628 if (gtk_widget_get_visible (widget))
3630 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3632 if (gtk_widget_get_mapped (widget))
3633 gtk_widget_unmap (widget);
3638 * gtk_widget_hide_on_delete:
3639 * @widget: a #GtkWidget
3641 * Utility function; intended to be connected to the #GtkWidget::delete-event
3642 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3643 * argument, then returns %TRUE. If connected to ::delete-event, the
3644 * result is that clicking the close button for a window (on the
3645 * window frame, top right corner usually) will hide but not destroy
3646 * the window. By default, GTK+ destroys windows when ::delete-event
3649 * Return value: %TRUE
3652 gtk_widget_hide_on_delete (GtkWidget *widget)
3654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3656 gtk_widget_hide (widget);
3662 * gtk_widget_show_all:
3663 * @widget: a #GtkWidget
3665 * Recursively shows a widget, and any child widgets (if the widget is
3669 gtk_widget_show_all (GtkWidget *widget)
3671 GtkWidgetClass *class;
3673 g_return_if_fail (GTK_IS_WIDGET (widget));
3675 if (gtk_widget_get_no_show_all (widget))
3678 class = GTK_WIDGET_GET_CLASS (widget);
3680 if (class->show_all)
3681 class->show_all (widget);
3685 * gtk_widget_hide_all:
3686 * @widget: a #GtkWidget
3688 * Recursively hides a widget and any child widgets.
3691 gtk_widget_hide_all (GtkWidget *widget)
3693 GtkWidgetClass *class;
3695 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 if (gtk_widget_get_no_show_all (widget))
3700 class = GTK_WIDGET_GET_CLASS (widget);
3702 if (class->hide_all)
3703 class->hide_all (widget);
3708 * @widget: a #GtkWidget
3710 * This function is only for use in widget implementations. Causes
3711 * a widget to be mapped if it isn't already.
3714 gtk_widget_map (GtkWidget *widget)
3716 GtkWidgetPrivate *priv;
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3719 g_return_if_fail (gtk_widget_get_visible (widget));
3720 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3722 priv = widget->priv;
3724 if (!gtk_widget_get_mapped (widget))
3726 if (!gtk_widget_get_realized (widget))
3727 gtk_widget_realize (widget);
3729 g_signal_emit (widget, widget_signals[MAP], 0);
3731 if (!gtk_widget_get_has_window (widget))
3732 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3738 * @widget: a #GtkWidget
3740 * This function is only for use in widget implementations. Causes
3741 * a widget to be unmapped if it's currently mapped.
3744 gtk_widget_unmap (GtkWidget *widget)
3746 GtkWidgetPrivate *priv;
3748 g_return_if_fail (GTK_IS_WIDGET (widget));
3750 priv = widget->priv;
3752 if (gtk_widget_get_mapped (widget))
3754 if (!gtk_widget_get_has_window (widget))
3755 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3756 _gtk_tooltip_hide (widget);
3757 g_signal_emit (widget, widget_signals[UNMAP], 0);
3762 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3763 GdkExtensionMode mode,
3766 GtkWidgetPrivate *priv = widget->priv;
3767 GList *free_list = NULL;
3770 if (window_list == NULL)
3772 if (gtk_widget_get_has_window (widget))
3773 window_list = g_list_prepend (NULL, priv->window);
3775 window_list = gdk_window_get_children (priv->window);
3777 free_list = window_list;
3780 for (l = window_list; l != NULL; l = l->next)
3782 GdkWindow *window = l->data;
3785 gdk_window_get_user_data (window, &user_data);
3786 if (user_data == widget)
3790 gdk_input_set_extension_events (window,
3791 gdk_window_get_events (window),
3794 children = gdk_window_get_children (window);
3797 gtk_widget_set_extension_events_internal (widget, mode, children);
3798 g_list_free (children);
3804 g_list_free (free_list);
3808 _gtk_widget_enable_device_events (GtkWidget *widget)
3810 GHashTable *device_events;
3811 GHashTableIter iter;
3812 gpointer key, value;
3814 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3819 g_hash_table_iter_init (&iter, device_events);
3821 while (g_hash_table_iter_next (&iter, &key, &value))
3824 GdkEventMask event_mask;
3827 event_mask = GPOINTER_TO_UINT (value);
3828 gtk_widget_add_events_internal (widget, device, event_mask);
3833 * gtk_widget_realize:
3834 * @widget: a #GtkWidget
3836 * Creates the GDK (windowing system) resources associated with a
3837 * widget. For example, @widget->window will be created when a widget
3838 * is realized. Normally realization happens implicitly; if you show
3839 * a widget and all its parent containers, then the widget will be
3840 * realized and mapped automatically.
3842 * Realizing a widget requires all
3843 * the widget's parent widgets to be realized; calling
3844 * gtk_widget_realize() realizes the widget's parents in addition to
3845 * @widget itself. If a widget is not yet inside a toplevel window
3846 * when you realize it, bad things will happen.
3848 * This function is primarily used in widget implementations, and
3849 * isn't very useful otherwise. Many times when you think you might
3850 * need it, a better approach is to connect to a signal that will be
3851 * called after the widget is realized automatically, such as
3852 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3853 * GtkWidget::realize signal.
3856 gtk_widget_realize (GtkWidget *widget)
3858 GtkWidgetPrivate *priv;
3859 GdkExtensionMode mode;
3860 cairo_region_t *region;
3862 g_return_if_fail (GTK_IS_WIDGET (widget));
3863 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3864 GTK_IS_INVISIBLE (widget));
3866 priv = widget->priv;
3868 if (!gtk_widget_get_realized (widget))
3871 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3872 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3875 if (priv->parent == NULL &&
3876 !gtk_widget_is_toplevel (widget))
3877 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3878 "inside a toplevel window is not going to work very well. "
3879 "Widgets must be inside a toplevel container before realizing them.");
3881 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3882 gtk_widget_realize (priv->parent);
3884 gtk_widget_ensure_style (widget);
3886 g_signal_emit (widget, widget_signals[REALIZE], 0);
3888 gtk_widget_real_set_has_tooltip (widget,
3889 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3892 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3894 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3895 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3898 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3900 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3902 mode = gtk_widget_get_extension_events (widget);
3903 if (mode != GDK_EXTENSION_EVENTS_NONE)
3904 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3906 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3907 gdk_window_set_support_multidevice (priv->window, TRUE);
3909 _gtk_widget_enable_device_events (widget);
3914 * gtk_widget_unrealize:
3915 * @widget: a #GtkWidget
3917 * This function is only useful in widget implementations.
3918 * Causes a widget to be unrealized (frees all GDK resources
3919 * associated with the widget, such as @widget->window).
3922 gtk_widget_unrealize (GtkWidget *widget)
3924 g_return_if_fail (GTK_IS_WIDGET (widget));
3926 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3927 gtk_widget_shape_combine_region (widget, NULL);
3929 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3930 gtk_widget_input_shape_combine_region (widget, NULL);
3932 if (gtk_widget_get_realized (widget))
3934 g_object_ref (widget);
3935 _gtk_tooltip_hide (widget);
3936 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3937 gtk_widget_set_realized (widget, FALSE);
3938 gtk_widget_set_mapped (widget, FALSE);
3939 g_object_unref (widget);
3943 /*****************************************
3945 *****************************************/
3948 * gtk_widget_queue_draw_area:
3949 * @widget: a #GtkWidget
3950 * @x: x coordinate of upper-left corner of rectangle to redraw
3951 * @y: y coordinate of upper-left corner of rectangle to redraw
3952 * @width: width of region to draw
3953 * @height: height of region to draw
3955 * Invalidates the rectangular area of @widget defined by @x, @y,
3956 * @width and @height by calling gdk_window_invalidate_rect() on the
3957 * widget's window and all its child windows. Once the main loop
3958 * becomes idle (after the current batch of events has been processed,
3959 * roughly), the window will receive expose events for the union of
3960 * all regions that have been invalidated.
3962 * Normally you would only use this function in widget
3963 * implementations. You might also use it, or
3964 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3965 * #GtkDrawingArea or some portion thereof.
3967 * Frequently you can just call gdk_window_invalidate_rect() or
3968 * gdk_window_invalidate_region() instead of this function. Those
3969 * functions will invalidate only a single window, instead of the
3970 * widget and all its children.
3972 * The advantage of adding to the invalidated region compared to
3973 * simply drawing immediately is efficiency; using an invalid region
3974 * ensures that you only have to redraw one time.
3977 gtk_widget_queue_draw_area (GtkWidget *widget,
3983 GtkWidgetPrivate *priv;
3984 GdkRectangle invalid_rect;
3987 g_return_if_fail (GTK_IS_WIDGET (widget));
3989 priv = widget->priv;
3991 if (!gtk_widget_get_realized (widget))
3994 /* Just return if the widget or one of its ancestors isn't mapped */
3995 for (w = widget; w != NULL; w = w->priv->parent)
3996 if (!gtk_widget_get_mapped (w))
3999 /* Find the correct widget */
4001 if (gtk_widget_get_has_window (widget))
4005 /* Translate widget relative to window-relative */
4007 gint wx, wy, wwidth, wheight;
4009 gdk_window_get_position (priv->window, &wx, &wy);
4010 x -= wx - priv->allocation.x;
4011 y -= wy - priv->allocation.y;
4013 wwidth = gdk_window_get_width (priv->window);
4014 wheight = gdk_window_get_height (priv->window);
4016 if (x + width <= 0 || y + height <= 0 ||
4017 x >= wwidth || y >= wheight)
4028 if (x + width > wwidth)
4030 if (y + height > wheight)
4031 height = wheight - y;
4037 invalid_rect.width = width;
4038 invalid_rect.height = height;
4040 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4044 * gtk_widget_queue_draw:
4045 * @widget: a #GtkWidget
4047 * Equivalent to calling gtk_widget_queue_draw_area() for the
4048 * entire area of a widget.
4051 gtk_widget_queue_draw (GtkWidget *widget)
4055 g_return_if_fail (GTK_IS_WIDGET (widget));
4057 gtk_widget_get_allocation (widget, &rect);
4059 if (!gtk_widget_get_has_window (widget))
4060 gtk_widget_queue_draw_area (widget,
4061 rect.x, rect.y, rect.width, rect.height);
4063 gtk_widget_queue_draw_area (widget,
4064 0, 0, rect.width, rect.height);
4068 * gtk_widget_queue_resize:
4069 * @widget: a #GtkWidget
4071 * This function is only for use in widget implementations.
4072 * Flags a widget to have its size renegotiated; should
4073 * be called when a widget for some reason has a new size request.
4074 * For example, when you change the text in a #GtkLabel, #GtkLabel
4075 * queues a resize to ensure there's enough space for the new text.
4078 gtk_widget_queue_resize (GtkWidget *widget)
4080 g_return_if_fail (GTK_IS_WIDGET (widget));
4082 if (gtk_widget_get_realized (widget))
4083 gtk_widget_queue_shallow_draw (widget);
4085 _gtk_size_group_queue_resize (widget);
4089 * gtk_widget_queue_resize_no_redraw:
4090 * @widget: a #GtkWidget
4092 * This function works like gtk_widget_queue_resize(),
4093 * except that the widget is not invalidated.
4098 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4100 g_return_if_fail (GTK_IS_WIDGET (widget));
4102 _gtk_size_group_queue_resize (widget);
4106 * gtk_widget_size_request:
4107 * @widget: a #GtkWidget
4108 * @requisition: (out): a #GtkRequisition to be filled in
4110 * This function is typically used when implementing a #GtkContainer
4111 * subclass. Obtains the preferred size of a widget. The container
4112 * uses this information to arrange its child widgets and decide what
4113 * size allocations to give them with gtk_widget_size_allocate().
4115 * You can also call this function from an application, with some
4116 * caveats. Most notably, getting a size request requires the widget
4117 * to be associated with a screen, because font information may be
4118 * needed. Multihead-aware applications should keep this in mind.
4120 * Also remember that the size request is not necessarily the size
4121 * a widget will actually be allocated.
4123 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4126 gtk_widget_size_request (GtkWidget *widget,
4127 GtkRequisition *requisition)
4129 g_return_if_fail (GTK_IS_WIDGET (widget));
4131 gtk_widget_get_preferred_size (widget, requisition, NULL);
4135 * gtk_widget_get_child_requisition:
4136 * @widget: a #GtkWidget
4137 * @requisition: (out): a #GtkRequisition to be filled in
4139 * This function is only for use in widget implementations. Obtains
4140 * @widget->requisition, unless someone has forced a particular
4141 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4142 * in which case it returns that geometry instead of the widget's
4145 * This function differs from gtk_widget_size_request() in that
4146 * it retrieves the last size request value from @widget->requisition,
4147 * while gtk_widget_size_request() actually calls the "size_request" method
4148 * on @widget to compute the size request and fill in @widget->requisition,
4149 * and only then returns @widget->requisition.
4151 * Because this function does not call the "size_request" method, it
4152 * can only be used when you know that @widget->requisition is
4153 * up-to-date, that is, gtk_widget_size_request() has been called
4154 * since the last time a resize was queued. In general, only container
4155 * implementations have this information; applications should use
4156 * gtk_widget_size_request().
4159 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4162 gtk_widget_get_child_requisition (GtkWidget *widget,
4163 GtkRequisition *requisition)
4165 gtk_widget_get_preferred_size (widget, requisition, NULL);
4169 invalidate_predicate (GdkWindow *window,
4174 gdk_window_get_user_data (window, &user_data);
4176 return (user_data == data);
4179 /* Invalidate @region in widget->window and all children
4180 * of widget->window owned by widget. @region is in the
4181 * same coordinates as widget->allocation and will be
4182 * modified by this call.
4185 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4186 cairo_region_t *region)
4188 GtkWidgetPrivate *priv = widget->priv;
4190 if (!gtk_widget_get_realized (widget))
4193 if (gtk_widget_get_has_window (widget) && priv->parent)
4197 gdk_window_get_position (priv->window, &x, &y);
4198 cairo_region_translate (region, -x, -y);
4201 gdk_window_invalidate_maybe_recurse (priv->window, region,
4202 invalidate_predicate, widget);
4206 * gtk_widget_queue_shallow_draw:
4207 * @widget: a #GtkWidget
4209 * Like gtk_widget_queue_draw(), but only windows owned
4210 * by @widget are invalidated.
4213 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4216 cairo_region_t *region;
4218 if (!gtk_widget_get_realized (widget))
4221 gtk_widget_get_allocation (widget, &rect);
4223 region = cairo_region_create_rectangle (&rect);
4224 gtk_widget_invalidate_widget_windows (widget, region);
4225 cairo_region_destroy (region);
4229 * gtk_widget_size_allocate:
4230 * @widget: a #GtkWidget
4231 * @allocation: (inout): position and size to be allocated to @widget
4233 * This function is only used by #GtkContainer subclasses, to assign a size
4234 * and position to their child widgets.
4236 * In this function, the allocation may be adjusted. It will be forced
4237 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4238 * method on the child will be used to adjust the allocation. Standard
4239 * adjustments include removing the widget's margins, and applying the
4240 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4243 gtk_widget_size_allocate (GtkWidget *widget,
4244 GtkAllocation *allocation)
4246 GtkWidgetPrivate *priv;
4247 GdkRectangle real_allocation;
4248 GdkRectangle old_allocation;
4249 GdkRectangle adjusted_allocation;
4250 gboolean alloc_needed;
4251 gboolean size_changed;
4252 gboolean position_changed;
4254 priv = widget->priv;
4256 g_return_if_fail (GTK_IS_WIDGET (widget));
4258 #ifdef G_ENABLE_DEBUG
4259 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4270 parent = gtk_widget_get_parent (parent);
4273 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4274 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4275 2 * depth, " ", name,
4276 allocation->width, allocation->height);
4278 #endif /* G_ENABLE_DEBUG */
4280 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4281 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4282 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4283 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4285 old_allocation = priv->allocation;
4286 real_allocation = *allocation;
4288 adjusted_allocation = real_allocation;
4289 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4291 if (adjusted_allocation.x < real_allocation.x ||
4292 adjusted_allocation.y < real_allocation.y ||
4293 (adjusted_allocation.x + adjusted_allocation.width) >
4294 (real_allocation.x + real_allocation.width) ||
4295 (adjusted_allocation.y + adjusted_allocation.height >
4296 real_allocation.y + real_allocation.height))
4298 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",
4299 G_OBJECT_TYPE_NAME (widget), widget,
4300 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4301 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4302 adjusted_allocation = real_allocation; /* veto it */
4306 real_allocation = adjusted_allocation;
4309 if (real_allocation.width < 0 || real_allocation.height < 0)
4311 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4312 real_allocation.width,
4313 real_allocation.height);
4316 real_allocation.width = MAX (real_allocation.width, 1);
4317 real_allocation.height = MAX (real_allocation.height, 1);
4319 size_changed = (old_allocation.width != real_allocation.width ||
4320 old_allocation.height != real_allocation.height);
4321 position_changed = (old_allocation.x != real_allocation.x ||
4322 old_allocation.y != real_allocation.y);
4324 if (!alloc_needed && !size_changed && !position_changed)
4327 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4329 if (gtk_widget_get_mapped (widget))
4331 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4333 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4335 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4336 cairo_region_union_rectangle (invalidate, &old_allocation);
4338 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4339 cairo_region_destroy (invalidate);
4344 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4346 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4348 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4349 cairo_region_union_rectangle (invalidate, &old_allocation);
4351 gtk_widget_invalidate_widget_windows (widget, invalidate);
4352 cairo_region_destroy (invalidate);
4357 if ((size_changed || position_changed) && priv->parent &&
4358 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4360 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4361 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4362 cairo_region_destroy (invalidate);
4367 * gtk_widget_common_ancestor:
4368 * @widget_a: a #GtkWidget
4369 * @widget_b: a #GtkWidget
4371 * Find the common ancestor of @widget_a and @widget_b that
4372 * is closest to the two widgets.
4374 * Return value: the closest common ancestor of @widget_a and
4375 * @widget_b or %NULL if @widget_a and @widget_b do not
4376 * share a common ancestor.
4379 gtk_widget_common_ancestor (GtkWidget *widget_a,
4380 GtkWidget *widget_b)
4382 GtkWidget *parent_a;
4383 GtkWidget *parent_b;
4387 parent_a = widget_a;
4388 while (parent_a->priv->parent)
4390 parent_a = parent_a->priv->parent;
4394 parent_b = widget_b;
4395 while (parent_b->priv->parent)
4397 parent_b = parent_b->priv->parent;
4401 if (parent_a != parent_b)
4404 while (depth_a > depth_b)
4406 widget_a = widget_a->priv->parent;
4410 while (depth_b > depth_a)
4412 widget_b = widget_b->priv->parent;
4416 while (widget_a != widget_b)
4418 widget_a = widget_a->priv->parent;
4419 widget_b = widget_b->priv->parent;
4426 * gtk_widget_translate_coordinates:
4427 * @src_widget: a #GtkWidget
4428 * @dest_widget: a #GtkWidget
4429 * @src_x: X position relative to @src_widget
4430 * @src_y: Y position relative to @src_widget
4431 * @dest_x: (out): location to store X position relative to @dest_widget
4432 * @dest_y: (out): location to store Y position relative to @dest_widget
4434 * Translate coordinates relative to @src_widget's allocation to coordinates
4435 * relative to @dest_widget's allocations. In order to perform this
4436 * operation, both widgets must be realized, and must share a common
4439 * Return value: %FALSE if either widget was not realized, or there
4440 * was no common ancestor. In this case, nothing is stored in
4441 * *@dest_x and *@dest_y. Otherwise %TRUE.
4444 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4445 GtkWidget *dest_widget,
4451 GtkWidgetPrivate *src_priv = src_widget->priv;
4452 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4453 GtkWidget *ancestor;
4455 GList *dest_list = NULL;
4457 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4458 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4460 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4461 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4464 /* Translate from allocation relative to window relative */
4465 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4468 gdk_window_get_position (src_priv->window, &wx, &wy);
4470 src_x -= wx - src_priv->allocation.x;
4471 src_y -= wy - src_priv->allocation.y;
4475 src_x += src_priv->allocation.x;
4476 src_y += src_priv->allocation.y;
4479 /* Translate to the common ancestor */
4480 window = src_priv->window;
4481 while (window != ancestor->priv->window)
4485 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4490 window = gdk_window_get_effective_parent (window);
4492 if (!window) /* Handle GtkHandleBox */
4497 window = dest_priv->window;
4498 while (window != ancestor->priv->window)
4500 dest_list = g_list_prepend (dest_list, window);
4502 window = gdk_window_get_effective_parent (window);
4504 if (!window) /* Handle GtkHandleBox */
4506 g_list_free (dest_list);
4515 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4520 dest_list = g_list_remove (dest_list, dest_list->data);
4523 /* Translate from window relative to allocation relative */
4524 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4527 gdk_window_get_position (dest_priv->window, &wx, &wy);
4529 src_x += wx - dest_priv->allocation.x;
4530 src_y += wy - dest_priv->allocation.y;
4534 src_x -= dest_priv->allocation.x;
4535 src_y -= dest_priv->allocation.y;
4547 gtk_widget_real_size_allocate (GtkWidget *widget,
4548 GtkAllocation *allocation)
4550 GtkWidgetPrivate *priv = widget->priv;
4552 priv->allocation = *allocation;
4554 if (gtk_widget_get_realized (widget) &&
4555 gtk_widget_get_has_window (widget))
4557 gdk_window_move_resize (priv->window,
4558 allocation->x, allocation->y,
4559 allocation->width, allocation->height);
4564 get_span_inside_border (GtkWidget *widget,
4568 int allocated_outside_size,
4569 int natural_inside_size,
4570 int *coord_inside_p,
4573 int inside_allocated;
4577 inside_allocated = allocated_outside_size - start_pad - end_pad;
4579 content_size = natural_inside_size;
4580 if (content_size > inside_allocated)
4582 /* didn't get full natural size */
4583 content_size = inside_allocated;
4586 coord = size = 0; /* silence compiler */
4589 case GTK_ALIGN_FILL:
4591 size = inside_allocated;
4593 case GTK_ALIGN_START:
4595 size = content_size;
4598 coord = allocated_outside_size - end_pad - content_size;
4599 size = content_size;
4601 case GTK_ALIGN_CENTER:
4602 coord = start_pad + (inside_allocated - content_size) / 2;
4603 size = content_size;
4608 *coord_inside_p = coord;
4611 *size_inside_p = size;
4615 get_span_inside_border_horizontal (GtkWidget *widget,
4616 const GtkWidgetAuxInfo *aux_info,
4617 int allocated_outside_width,
4618 int natural_inside_width,
4620 int *width_inside_p)
4622 get_span_inside_border (widget,
4624 aux_info->margin.left,
4625 aux_info->margin.right,
4626 allocated_outside_width,
4627 natural_inside_width,
4633 get_span_inside_border_vertical (GtkWidget *widget,
4634 const GtkWidgetAuxInfo *aux_info,
4635 int allocated_outside_height,
4636 int natural_inside_height,
4638 int *height_inside_p)
4640 get_span_inside_border (widget,
4642 aux_info->margin.top,
4643 aux_info->margin.bottom,
4644 allocated_outside_height,
4645 natural_inside_height,
4651 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4652 GtkAllocation *allocation)
4654 const GtkWidgetAuxInfo *aux_info;
4655 GtkRequisition min, natural;
4658 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4660 gtk_widget_get_preferred_size (widget, &min, &natural);
4662 get_span_inside_border_horizontal (widget,
4667 get_span_inside_border_vertical (widget,
4675 allocation->width = w;
4676 allocation->height = h;
4680 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4683 GtkWidgetPrivate *priv = widget->priv;
4685 /* widgets must be onscreen for accels to take effect */
4686 return gtk_widget_is_sensitive (widget) &&
4687 gtk_widget_is_drawable (widget) &&
4688 gdk_window_is_viewable (priv->window);
4692 * gtk_widget_can_activate_accel:
4693 * @widget: a #GtkWidget
4694 * @signal_id: the ID of a signal installed on @widget
4696 * Determines whether an accelerator that activates the signal
4697 * identified by @signal_id can currently be activated.
4698 * This is done by emitting the #GtkWidget::can-activate-accel
4699 * signal on @widget; if the signal isn't overridden by a
4700 * handler or in a derived widget, then the default check is
4701 * that the widget must be sensitive, and the widget and all
4702 * its ancestors mapped.
4704 * Return value: %TRUE if the accelerator can be activated.
4709 gtk_widget_can_activate_accel (GtkWidget *widget,
4712 gboolean can_activate = FALSE;
4713 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4714 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4715 return can_activate;
4724 closure_accel_activate (GClosure *closure,
4725 GValue *return_value,
4726 guint n_param_values,
4727 const GValue *param_values,
4728 gpointer invocation_hint,
4729 gpointer marshal_data)
4731 AccelClosure *aclosure = (AccelClosure*) closure;
4732 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4735 g_signal_emit (closure->data, aclosure->signal_id, 0);
4737 /* whether accelerator was handled */
4738 g_value_set_boolean (return_value, can_activate);
4742 closures_destroy (gpointer data)
4744 GSList *slist, *closures = data;
4746 for (slist = closures; slist; slist = slist->next)
4748 g_closure_invalidate (slist->data);
4749 g_closure_unref (slist->data);
4751 g_slist_free (closures);
4755 widget_new_accel_closure (GtkWidget *widget,
4758 AccelClosure *aclosure;
4759 GClosure *closure = NULL;
4760 GSList *slist, *closures;
4762 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4763 for (slist = closures; slist; slist = slist->next)
4764 if (!gtk_accel_group_from_accel_closure (slist->data))
4766 /* reuse this closure */
4767 closure = slist->data;
4772 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4773 closures = g_slist_prepend (closures, g_closure_ref (closure));
4774 g_closure_sink (closure);
4775 g_closure_set_marshal (closure, closure_accel_activate);
4777 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4779 aclosure = (AccelClosure*) closure;
4780 g_assert (closure->data == widget);
4781 g_assert (closure->marshal == closure_accel_activate);
4782 aclosure->signal_id = signal_id;
4788 * gtk_widget_add_accelerator
4789 * @widget: widget to install an accelerator on
4790 * @accel_signal: widget signal to emit on accelerator activation
4791 * @accel_group: accel group for this widget, added to its toplevel
4792 * @accel_key: GDK keyval of the accelerator
4793 * @accel_mods: modifier key combination of the accelerator
4794 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4796 * Installs an accelerator for this @widget in @accel_group that causes
4797 * @accel_signal to be emitted if the accelerator is activated.
4798 * The @accel_group needs to be added to the widget's toplevel via
4799 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4800 * Accelerators added through this function are not user changeable during
4801 * runtime. If you want to support accelerators that can be changed by the
4802 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4803 * gtk_menu_item_set_accel_path() instead.
4806 gtk_widget_add_accelerator (GtkWidget *widget,
4807 const gchar *accel_signal,
4808 GtkAccelGroup *accel_group,
4810 GdkModifierType accel_mods,
4811 GtkAccelFlags accel_flags)
4816 g_return_if_fail (GTK_IS_WIDGET (widget));
4817 g_return_if_fail (accel_signal != NULL);
4818 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4820 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4821 if (!query.signal_id ||
4822 !(query.signal_flags & G_SIGNAL_ACTION) ||
4823 query.return_type != G_TYPE_NONE ||
4826 /* hmm, should be elaborate enough */
4827 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4828 G_OBJECT_TYPE_NAME (widget), accel_signal);
4832 closure = widget_new_accel_closure (widget, query.signal_id);
4834 g_object_ref (widget);
4836 /* install the accelerator. since we don't map this onto an accel_path,
4837 * the accelerator will automatically be locked.
4839 gtk_accel_group_connect (accel_group,
4842 accel_flags | GTK_ACCEL_LOCKED,
4845 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4847 g_object_unref (widget);
4851 * gtk_widget_remove_accelerator:
4852 * @widget: widget to install an accelerator on
4853 * @accel_group: accel group for this widget
4854 * @accel_key: GDK keyval of the accelerator
4855 * @accel_mods: modifier key combination of the accelerator
4856 * @returns: whether an accelerator was installed and could be removed
4858 * Removes an accelerator from @widget, previously installed with
4859 * gtk_widget_add_accelerator().
4862 gtk_widget_remove_accelerator (GtkWidget *widget,
4863 GtkAccelGroup *accel_group,
4865 GdkModifierType accel_mods)
4867 GtkAccelGroupEntry *ag_entry;
4868 GList *slist, *clist;
4871 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4872 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4874 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4875 clist = gtk_widget_list_accel_closures (widget);
4876 for (slist = clist; slist; slist = slist->next)
4880 for (i = 0; i < n; i++)
4881 if (slist->data == (gpointer) ag_entry[i].closure)
4883 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4885 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4887 g_list_free (clist);
4892 g_list_free (clist);
4894 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4895 accel_key, accel_mods, accel_group,
4896 G_OBJECT_TYPE_NAME (widget), widget);
4902 * gtk_widget_list_accel_closures:
4903 * @widget: widget to list accelerator closures for
4905 * Lists the closures used by @widget for accelerator group connections
4906 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4907 * The closures can be used to monitor accelerator changes on @widget,
4908 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4909 * #GtkAccelGroup of a closure which can be found out with
4910 * gtk_accel_group_from_accel_closure().
4912 * Return value: (transfer container) (element-type GClosure):
4913 * a newly allocated #GList of closures
4916 gtk_widget_list_accel_closures (GtkWidget *widget)
4919 GList *clist = NULL;
4921 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4923 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4924 if (gtk_accel_group_from_accel_closure (slist->data))
4925 clist = g_list_prepend (clist, slist->data);
4931 GtkAccelGroup *accel_group;
4936 destroy_accel_path (gpointer data)
4938 AccelPath *apath = data;
4940 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4942 /* closures_destroy takes care of unrefing the closure */
4943 g_object_unref (apath->accel_group);
4945 g_slice_free (AccelPath, apath);
4950 * gtk_widget_set_accel_path:
4951 * @widget: a #GtkWidget
4952 * @accel_path: (allow-none): path used to look up the accelerator
4953 * @accel_group: (allow-none): a #GtkAccelGroup.
4955 * Given an accelerator group, @accel_group, and an accelerator path,
4956 * @accel_path, sets up an accelerator in @accel_group so whenever the
4957 * key binding that is defined for @accel_path is pressed, @widget
4958 * will be activated. This removes any accelerators (for any
4959 * accelerator group) installed by previous calls to
4960 * gtk_widget_set_accel_path(). Associating accelerators with
4961 * paths allows them to be modified by the user and the modifications
4962 * to be saved for future use. (See gtk_accel_map_save().)
4964 * This function is a low level function that would most likely
4965 * be used by a menu creation system like #GtkUIManager. If you
4966 * use #GtkUIManager, setting up accelerator paths will be done
4969 * Even when you you aren't using #GtkUIManager, if you only want to
4970 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4971 * provides a somewhat more convenient interface.
4973 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4974 * pass a static string, you can save some memory by interning it first with
4975 * g_intern_static_string().
4978 gtk_widget_set_accel_path (GtkWidget *widget,
4979 const gchar *accel_path,
4980 GtkAccelGroup *accel_group)
4984 g_return_if_fail (GTK_IS_WIDGET (widget));
4985 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4989 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4990 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4992 gtk_accel_map_add_entry (accel_path, 0, 0);
4993 apath = g_slice_new (AccelPath);
4994 apath->accel_group = g_object_ref (accel_group);
4995 apath->path_quark = g_quark_from_string (accel_path);
4996 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5001 /* also removes possible old settings */
5002 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5005 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5007 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5011 _gtk_widget_get_accel_path (GtkWidget *widget,
5016 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5018 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5020 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5021 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5025 * gtk_widget_mnemonic_activate:
5026 * @widget: a #GtkWidget
5027 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5029 * Emits the #GtkWidget::mnemonic-activate signal.
5031 * The default handler for this signal activates the @widget if
5032 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5035 * Returns: %TRUE if the signal has been handled
5038 gtk_widget_mnemonic_activate (GtkWidget *widget,
5039 gboolean group_cycling)
5043 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5045 group_cycling = group_cycling != FALSE;
5046 if (!gtk_widget_is_sensitive (widget))
5049 g_signal_emit (widget,
5050 widget_signals[MNEMONIC_ACTIVATE],
5058 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5059 gboolean group_cycling)
5061 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5062 gtk_widget_activate (widget);
5063 else if (gtk_widget_get_can_focus (widget))
5064 gtk_widget_grab_focus (widget);
5067 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5068 G_OBJECT_TYPE_NAME (widget));
5069 gtk_widget_error_bell (widget);
5074 static const cairo_user_data_key_t event_key;
5077 _gtk_cairo_get_event (cairo_t *cr)
5079 g_return_val_if_fail (cr != NULL, NULL);
5081 return cairo_get_user_data (cr, &event_key);
5085 gtk_cairo_set_event (cairo_t *cr,
5086 GdkEventExpose *event)
5088 cairo_set_user_data (cr, &event_key, event, NULL);
5092 * gtk_cairo_should_draw_window:
5093 * @cr: a cairo context
5094 * @window: the window to check
5096 * This function is supposed to be called in GtkWidget::draw
5097 * implementations for widgets that support multiple windows.
5098 * @cr must be untransformed from invoking of the draw function.
5099 * This function will return %TRUE if the contents of the given
5100 * @window are supposed to be drawn and %FALSE otherwise. Note
5101 * that when the drawing was not initiated by the windowing
5102 * system this function will return %TRUE for all windows, so
5103 * you need to draw the bottommost window first. Also, do not
5104 * use "else if" statements to check which window should be drawn.
5106 * Returns: %TRUE if @window should be drawn
5109 gtk_cairo_should_draw_window (cairo_t *cr,
5112 GdkEventExpose *event;
5114 g_return_val_if_fail (cr != NULL, FALSE);
5115 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5117 event = _gtk_cairo_get_event (cr);
5119 return event == NULL ||
5120 event->window == window;
5123 /* code shared by gtk_container_propagate_draw() and
5127 _gtk_widget_draw_internal (GtkWidget *widget,
5129 gboolean clip_to_size)
5131 if (!gtk_widget_is_drawable (widget))
5136 cairo_rectangle (cr,
5138 widget->priv->allocation.width,
5139 widget->priv->allocation.height);
5143 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5147 g_signal_emit (widget, widget_signals[DRAW],
5155 * @widget: the widget to draw. It must be drawable (see
5156 * gtk_widget_is_drawable()) and a size must have been allocated.
5157 * @cr: a cairo context to draw to
5159 * Draws @widget to @cr. The top left corner of the widget will be
5160 * drawn to the currently set origin point of @cr.
5162 * You should pass a cairo context as @cr argument that is in an
5163 * original state. Otherwise the resulting drawing is undefined. For
5164 * example changing the operator using cairo_set_operator() or the
5165 * line width using cairo_set_line_width() might have unwanted side
5167 * You may however change the context's transform matrix - like with
5168 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5169 * region with cairo_clip() prior to calling this function. Also, it
5170 * is fine to modify the context with cairo_save() and
5171 * cairo_push_group() prior to calling this function.
5173 * <note><para>Special purpose widgets may contain special code for
5174 * rendering to the screen and might appear differently on screen
5175 * and when rendered using gtk_widget_draw().</para></note>
5178 gtk_widget_draw (GtkWidget *widget,
5181 GdkEventExpose *tmp_event;
5183 g_return_if_fail (GTK_IS_WIDGET (widget));
5184 g_return_if_fail (!GTK_WIDGET_ALLOC_NEEDED (widget));
5185 g_return_if_fail (cr != NULL);
5188 /* We have to reset the event here so that draw functions can call
5189 * gtk_widget_draw() on random other widgets and get the desired
5190 * effect: Drawing all contents, not just the current window.
5192 tmp_event = _gtk_cairo_get_event (cr);
5193 gtk_cairo_set_event (cr, NULL);
5195 _gtk_widget_draw_internal (widget, cr, TRUE);
5197 gtk_cairo_set_event (cr, tmp_event);
5202 gtk_widget_real_key_press_event (GtkWidget *widget,
5205 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5209 gtk_widget_real_key_release_event (GtkWidget *widget,
5212 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5216 gtk_widget_real_focus_in_event (GtkWidget *widget,
5217 GdkEventFocus *event)
5219 gtk_widget_queue_shallow_draw (widget);
5225 gtk_widget_real_focus_out_event (GtkWidget *widget,
5226 GdkEventFocus *event)
5228 gtk_widget_queue_shallow_draw (widget);
5233 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5234 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5238 * @widget: a #GtkWidget
5239 * @event: a #GdkEvent
5241 * Rarely-used function. This function is used to emit
5242 * the event signals on a widget (those signals should never
5243 * be emitted without using this function to do so).
5244 * If you want to synthesize an event though, don't use this function;
5245 * instead, use gtk_main_do_event() so the event will behave as if
5246 * it were in the event queue. Don't synthesize expose events; instead,
5247 * use gdk_window_invalidate_rect() to invalidate a region of the
5250 * Return value: return from the event signal emission (%TRUE if
5251 * the event was handled)
5254 gtk_widget_event (GtkWidget *widget,
5257 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5258 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5260 if (event->type == GDK_EXPOSE)
5262 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5263 "the same effect, call gdk_window_invalidate_rect/region(), "
5264 "followed by gdk_window_process_updates().");
5268 return gtk_widget_event_internal (widget, event);
5271 /* Returns TRUE if a translation should be done */
5273 gtk_widget_get_translation_to_window (GtkWidget *widget,
5278 GdkWindow *w, *widget_window;
5280 if (!gtk_widget_get_has_window (widget))
5282 *x = -widget->priv->allocation.x;
5283 *y = -widget->priv->allocation.y;
5291 widget_window = gtk_widget_get_window (widget);
5293 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5296 gdk_window_get_position (w, &wx, &wy);
5313 * gtk_cairo_transform_to_window:
5314 * @cr: the cairo context to transform
5315 * @widget: the widget the context is currently centered for
5316 * @window: the window to transform the context to
5318 * Transforms the given cairo context @cr that from @widget-relative
5319 * coordinates to @window-relative coordinates.
5320 * If the @widget's window is not an ancestor of @window, no
5321 * modification will be applied.
5323 * This is the inverse to the transformation GTK applies when
5324 * preparing an expose event to be emitted with the GtkWidget::draw
5325 * signal. It is intended to help porting multiwindow widgets from
5326 * GTK 2 to the rendering architecture of GTK 3.
5329 gtk_cairo_transform_to_window (cairo_t *cr,
5335 g_return_if_fail (cr != NULL);
5336 g_return_if_fail (GTK_IS_WIDGET (widget));
5337 g_return_if_fail (GDK_IS_WINDOW (window));
5339 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5340 cairo_translate (cr, x, y);
5344 * gtk_widget_send_expose:
5345 * @widget: a #GtkWidget
5346 * @event: a expose #GdkEvent
5348 * Very rarely-used function. This function is used to emit
5349 * an expose event signals on a widget. This function is not
5350 * normally used directly. The only time it is used is when
5351 * propagating an expose event to a child %NO_WINDOW widget, and
5352 * that is normally done using gtk_container_propagate_expose().
5354 * If you want to force an area of a window to be redrawn,
5355 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5356 * To cause the redraw to be done immediately, follow that call
5357 * with a call to gdk_window_process_updates().
5359 * Return value: return from the event signal emission (%TRUE if
5360 * the event was handled)
5363 gtk_widget_send_expose (GtkWidget *widget,
5366 gboolean result = FALSE;
5371 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5372 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5373 g_return_val_if_fail (event != NULL, TRUE);
5374 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5376 cr = gdk_cairo_create (event->expose.window);
5377 gtk_cairo_set_event (cr, &event->expose);
5379 gdk_cairo_region (cr, event->expose.region);
5382 do_clip = gtk_widget_get_translation_to_window (widget,
5383 event->expose.window,
5385 cairo_translate (cr, -x, -y);
5387 _gtk_widget_draw_internal (widget, cr, do_clip);
5389 /* unset here, so if someone keeps a reference to cr we
5390 * don't leak the window. */
5391 gtk_cairo_set_event (cr, NULL);
5398 event_window_is_still_viewable (GdkEvent *event)
5400 /* Check that we think the event's window is viewable before
5401 * delivering the event, to prevent suprises. We do this here
5402 * at the last moment, since the event may have been queued
5403 * up behind other events, held over a recursive main loop, etc.
5405 switch (event->type)
5408 case GDK_MOTION_NOTIFY:
5409 case GDK_BUTTON_PRESS:
5410 case GDK_2BUTTON_PRESS:
5411 case GDK_3BUTTON_PRESS:
5413 case GDK_ENTER_NOTIFY:
5414 case GDK_PROXIMITY_IN:
5416 return event->any.window && gdk_window_is_viewable (event->any.window);
5419 /* The following events are the second half of paired events;
5420 * we always deliver them to deal with widgets that clean up
5421 * on the second half.
5423 case GDK_BUTTON_RELEASE:
5424 case GDK_KEY_RELEASE:
5425 case GDK_LEAVE_NOTIFY:
5426 case GDK_PROXIMITY_OUT:
5430 /* Remaining events would make sense on an not-viewable window,
5431 * or don't have an associated window.
5438 gtk_widget_event_internal (GtkWidget *widget,
5441 gboolean return_val = FALSE;
5443 /* We check only once for is-still-visible; if someone
5444 * hides the window in on of the signals on the widget,
5445 * they are responsible for returning TRUE to terminate
5448 if (!event_window_is_still_viewable (event))
5451 g_object_ref (widget);
5453 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5454 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5459 switch (event->type)
5464 case GDK_BUTTON_PRESS:
5465 case GDK_2BUTTON_PRESS:
5466 case GDK_3BUTTON_PRESS:
5467 signal_num = BUTTON_PRESS_EVENT;
5470 signal_num = SCROLL_EVENT;
5472 case GDK_BUTTON_RELEASE:
5473 signal_num = BUTTON_RELEASE_EVENT;
5475 case GDK_MOTION_NOTIFY:
5476 signal_num = MOTION_NOTIFY_EVENT;
5479 signal_num = DELETE_EVENT;
5482 signal_num = DESTROY_EVENT;
5483 _gtk_tooltip_hide (widget);
5486 signal_num = KEY_PRESS_EVENT;
5488 case GDK_KEY_RELEASE:
5489 signal_num = KEY_RELEASE_EVENT;
5491 case GDK_ENTER_NOTIFY:
5492 signal_num = ENTER_NOTIFY_EVENT;
5494 case GDK_LEAVE_NOTIFY:
5495 signal_num = LEAVE_NOTIFY_EVENT;
5497 case GDK_FOCUS_CHANGE:
5498 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5499 if (event->focus_change.in)
5500 _gtk_tooltip_focus_in (widget);
5502 _gtk_tooltip_focus_out (widget);
5505 signal_num = CONFIGURE_EVENT;
5508 signal_num = MAP_EVENT;
5511 signal_num = UNMAP_EVENT;
5513 case GDK_WINDOW_STATE:
5514 signal_num = WINDOW_STATE_EVENT;
5516 case GDK_PROPERTY_NOTIFY:
5517 signal_num = PROPERTY_NOTIFY_EVENT;
5519 case GDK_SELECTION_CLEAR:
5520 signal_num = SELECTION_CLEAR_EVENT;
5522 case GDK_SELECTION_REQUEST:
5523 signal_num = SELECTION_REQUEST_EVENT;
5525 case GDK_SELECTION_NOTIFY:
5526 signal_num = SELECTION_NOTIFY_EVENT;
5528 case GDK_PROXIMITY_IN:
5529 signal_num = PROXIMITY_IN_EVENT;
5531 case GDK_PROXIMITY_OUT:
5532 signal_num = PROXIMITY_OUT_EVENT;
5535 signal_num = NO_EXPOSE_EVENT;
5537 case GDK_CLIENT_EVENT:
5538 signal_num = CLIENT_EVENT;
5541 signal_num = EXPOSE_EVENT;
5543 case GDK_VISIBILITY_NOTIFY:
5544 signal_num = VISIBILITY_NOTIFY_EVENT;
5546 case GDK_GRAB_BROKEN:
5547 signal_num = GRAB_BROKEN;
5550 signal_num = DAMAGE_EVENT;
5553 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5557 if (signal_num != -1)
5558 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5560 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5561 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5565 g_object_unref (widget);
5571 * gtk_widget_activate:
5572 * @widget: a #GtkWidget that's activatable
5574 * For widgets that can be "activated" (buttons, menu items, etc.)
5575 * this function activates them. Activation is what happens when you
5576 * press Enter on a widget during key navigation. If @widget isn't
5577 * activatable, the function returns %FALSE.
5579 * Return value: %TRUE if the widget was activatable
5582 gtk_widget_activate (GtkWidget *widget)
5584 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5586 if (WIDGET_CLASS (widget)->activate_signal)
5588 /* FIXME: we should eventually check the signals signature here */
5589 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5598 * gtk_widget_set_scroll_adjustments:
5599 * @widget: a #GtkWidget
5600 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5601 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5603 * For widgets that support scrolling, sets the scroll adjustments and
5604 * returns %TRUE. For widgets that don't support scrolling, does
5605 * nothing and returns %FALSE. Widgets that don't support scrolling
5606 * can be scrolled by placing them in a #GtkViewport, which does
5607 * support scrolling.
5609 * Return value: %TRUE if the widget supports scrolling
5612 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5613 GtkAdjustment *hadjustment,
5614 GtkAdjustment *vadjustment)
5619 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5622 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5624 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5626 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5630 g_signal_query (signal_id, &query);
5631 if (!query.signal_id ||
5632 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5633 query.return_type != G_TYPE_NONE ||
5634 query.n_params != 2 ||
5635 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5636 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5638 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5639 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5643 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5648 gtk_widget_reparent_subwindows (GtkWidget *widget,
5649 GdkWindow *new_window)
5651 GtkWidgetPrivate *priv = widget->priv;
5653 if (!gtk_widget_get_has_window (widget))
5655 GList *children = gdk_window_get_children (priv->window);
5658 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5660 GdkWindow *window = tmp_list->data;
5663 gdk_window_get_user_data (window, &child);
5664 while (child && child != widget)
5665 child = ((GtkWidget*) child)->priv->parent;
5668 gdk_window_reparent (window, new_window, 0, 0);
5671 g_list_free (children);
5676 GList *tmp_list, *children;
5678 parent = gdk_window_get_parent (priv->window);
5681 gdk_window_reparent (priv->window, new_window, 0, 0);
5684 children = gdk_window_get_children (parent);
5686 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5688 GdkWindow *window = tmp_list->data;
5691 gdk_window_get_user_data (window, &child);
5693 if (child == widget)
5694 gdk_window_reparent (window, new_window, 0, 0);
5697 g_list_free (children);
5703 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5704 gpointer client_data)
5706 GtkWidgetPrivate *priv = widget->priv;
5708 g_assert (client_data != NULL);
5710 if (!gtk_widget_get_has_window (widget))
5713 g_object_unref (priv->window);
5714 priv->window = (GdkWindow*) client_data;
5716 g_object_ref (priv->window);
5718 if (GTK_IS_CONTAINER (widget))
5719 gtk_container_forall (GTK_CONTAINER (widget),
5720 gtk_widget_reparent_fixup_child,
5726 * gtk_widget_reparent:
5727 * @widget: a #GtkWidget
5728 * @new_parent: a #GtkContainer to move the widget into
5730 * Moves a widget from one #GtkContainer to another, handling reference
5731 * count issues to avoid destroying the widget.
5734 gtk_widget_reparent (GtkWidget *widget,
5735 GtkWidget *new_parent)
5737 GtkWidgetPrivate *priv;
5739 g_return_if_fail (GTK_IS_WIDGET (widget));
5740 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5741 priv = widget->priv;
5742 g_return_if_fail (priv->parent != NULL);
5744 if (priv->parent != new_parent)
5746 /* First try to see if we can get away without unrealizing
5747 * the widget as we reparent it. if so we set a flag so
5748 * that gtk_widget_unparent doesn't unrealize widget
5750 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5751 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5753 g_object_ref (widget);
5754 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5755 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5756 g_object_unref (widget);
5758 if (GTK_WIDGET_IN_REPARENT (widget))
5760 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5762 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5763 gtk_widget_reparent_fixup_child (widget,
5764 gtk_widget_get_parent_window (widget));
5767 g_object_notify (G_OBJECT (widget), "parent");
5772 * gtk_widget_intersect:
5773 * @widget: a #GtkWidget
5774 * @area: a rectangle
5775 * @intersection: rectangle to store intersection of @widget and @area
5777 * Computes the intersection of a @widget's area and @area, storing
5778 * the intersection in @intersection, and returns %TRUE if there was
5779 * an intersection. @intersection may be %NULL if you're only
5780 * interested in whether there was an intersection.
5782 * Return value: %TRUE if there was an intersection
5785 gtk_widget_intersect (GtkWidget *widget,
5786 const GdkRectangle *area,
5787 GdkRectangle *intersection)
5789 GtkWidgetPrivate *priv;
5794 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5795 g_return_val_if_fail (area != NULL, FALSE);
5797 priv = widget->priv;
5800 dest = intersection;
5804 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5806 if (return_val && intersection && gtk_widget_get_has_window (widget))
5808 intersection->x -= priv->allocation.x;
5809 intersection->y -= priv->allocation.y;
5816 * gtk_widget_region_intersect:
5817 * @widget: a #GtkWidget
5818 * @region: a #cairo_region_t, in the same coordinate system as
5819 * @widget->allocation. That is, relative to @widget->window
5820 * for %NO_WINDOW widgets; relative to the parent window
5821 * of @widget->window for widgets with their own window.
5822 * @returns: A newly allocated region holding the intersection of @widget
5823 * and @region. The coordinates of the return value are
5824 * relative to @widget->window for %NO_WINDOW widgets, and
5825 * relative to the parent window of @widget->window for
5826 * widgets with their own window.
5828 * Computes the intersection of a @widget's area and @region, returning
5829 * the intersection. The result may be empty, use cairo_region_is_empty() to
5833 gtk_widget_region_intersect (GtkWidget *widget,
5834 const cairo_region_t *region)
5837 cairo_region_t *dest;
5839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5840 g_return_val_if_fail (region != NULL, NULL);
5842 gtk_widget_get_allocation (widget, &rect);
5844 dest = cairo_region_create_rectangle (&rect);
5846 cairo_region_intersect (dest, region);
5852 * _gtk_widget_grab_notify:
5853 * @widget: a #GtkWidget
5854 * @was_grabbed: whether a grab is now in effect
5856 * Emits the #GtkWidget::grab-notify signal on @widget.
5861 _gtk_widget_grab_notify (GtkWidget *widget,
5862 gboolean was_grabbed)
5864 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5868 * gtk_widget_grab_focus:
5869 * @widget: a #GtkWidget
5871 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5872 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5873 * something like #GtkFrame won't work.
5875 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5876 * gtk_widget_set_can_focus() to modify that flag.
5878 * The widget also needs to be realized and mapped. This is indicated by the
5879 * related signals. Grabbing the focus immediately after creating the widget
5880 * will likely fail and cause critical warnings.
5883 gtk_widget_grab_focus (GtkWidget *widget)
5885 g_return_if_fail (GTK_IS_WIDGET (widget));
5887 if (!gtk_widget_is_sensitive (widget))
5890 g_object_ref (widget);
5891 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5892 g_object_notify (G_OBJECT (widget), "has-focus");
5893 g_object_unref (widget);
5897 reset_focus_recurse (GtkWidget *widget,
5900 if (GTK_IS_CONTAINER (widget))
5902 GtkContainer *container;
5904 container = GTK_CONTAINER (widget);
5905 gtk_container_set_focus_child (container, NULL);
5907 gtk_container_foreach (container,
5908 reset_focus_recurse,
5914 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5916 if (gtk_widget_get_can_focus (focus_widget))
5918 GtkWidget *toplevel;
5921 /* clear the current focus setting, break if the current widget
5922 * is the focus widget's parent, since containers above that will
5923 * be set by the next loop.
5925 toplevel = gtk_widget_get_toplevel (focus_widget);
5926 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5928 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5930 if (widget == focus_widget)
5932 /* We call _gtk_window_internal_set_focus() here so that the
5933 * toplevel window can request the focus if necessary.
5934 * This is needed when the toplevel is a GtkPlug
5936 if (!gtk_widget_has_focus (widget))
5937 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5944 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5946 widget = widget->priv->parent;
5947 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5951 else if (toplevel != focus_widget)
5953 /* gtk_widget_grab_focus() operates on a tree without window...
5954 * actually, this is very questionable behaviour.
5957 gtk_container_foreach (GTK_CONTAINER (toplevel),
5958 reset_focus_recurse,
5962 /* now propagate the new focus up the widget tree and finally
5963 * set it on the window
5965 widget = focus_widget;
5966 while (widget->priv->parent)
5968 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5969 widget = widget->priv->parent;
5971 if (GTK_IS_WINDOW (widget))
5972 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5977 gtk_widget_real_query_tooltip (GtkWidget *widget,
5980 gboolean keyboard_tip,
5981 GtkTooltip *tooltip)
5983 gchar *tooltip_markup;
5984 gboolean has_tooltip;
5986 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5987 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5989 if (has_tooltip && tooltip_markup)
5991 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5999 gtk_widget_real_show_help (GtkWidget *widget,
6000 GtkWidgetHelpType help_type)
6002 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6004 _gtk_tooltip_toggle_keyboard_mode (widget);
6013 gtk_widget_real_focus (GtkWidget *widget,
6014 GtkDirectionType direction)
6016 if (!gtk_widget_get_can_focus (widget))
6019 if (!gtk_widget_is_focus (widget))
6021 gtk_widget_grab_focus (widget);
6029 gtk_widget_real_move_focus (GtkWidget *widget,
6030 GtkDirectionType direction)
6032 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6034 if (GTK_IS_WINDOW (toplevel) &&
6035 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
6037 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
6043 gtk_widget_real_keynav_failed (GtkWidget *widget,
6044 GtkDirectionType direction)
6046 gboolean cursor_only;
6050 case GTK_DIR_TAB_FORWARD:
6051 case GTK_DIR_TAB_BACKWARD:
6058 g_object_get (gtk_widget_get_settings (widget),
6059 "gtk-keynav-cursor-only", &cursor_only,
6066 gtk_widget_error_bell (widget);
6072 * gtk_widget_set_can_focus:
6073 * @widget: a #GtkWidget
6074 * @can_focus: whether or not @widget can own the input focus.
6076 * Specifies whether @widget can own the input focus. See
6077 * gtk_widget_grab_focus() for actually setting the input focus on a
6083 gtk_widget_set_can_focus (GtkWidget *widget,
6086 g_return_if_fail (GTK_IS_WIDGET (widget));
6088 if (can_focus != gtk_widget_get_can_focus (widget))
6091 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
6093 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
6095 gtk_widget_queue_resize (widget);
6096 g_object_notify (G_OBJECT (widget), "can-focus");
6101 * gtk_widget_get_can_focus:
6102 * @widget: a #GtkWidget
6104 * Determines whether @widget can own the input focus. See
6105 * gtk_widget_set_can_focus().
6107 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6112 gtk_widget_get_can_focus (GtkWidget *widget)
6114 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6116 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
6120 * gtk_widget_has_focus:
6121 * @widget: a #GtkWidget
6123 * Determines if the widget has the global input focus. See
6124 * gtk_widget_is_focus() for the difference between having the global
6125 * input focus, and only having the focus within a toplevel.
6127 * Return value: %TRUE if the widget has the global input focus.
6132 gtk_widget_has_focus (GtkWidget *widget)
6134 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6136 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
6140 * gtk_widget_is_focus:
6141 * @widget: a #GtkWidget
6143 * Determines if the widget is the focus widget within its
6144 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6145 * necessarily set; %HAS_FOCUS will only be set if the
6146 * toplevel widget additionally has the global input focus.)
6148 * Return value: %TRUE if the widget is the focus widget.
6151 gtk_widget_is_focus (GtkWidget *widget)
6153 GtkWidget *toplevel;
6155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6157 toplevel = gtk_widget_get_toplevel (widget);
6159 if (GTK_IS_WINDOW (toplevel))
6160 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6166 * gtk_widget_set_can_default:
6167 * @widget: a #GtkWidget
6168 * @can_default: whether or not @widget can be a default widget.
6170 * Specifies whether @widget can be a default widget. See
6171 * gtk_widget_grab_default() for details about the meaning of
6177 gtk_widget_set_can_default (GtkWidget *widget,
6178 gboolean can_default)
6180 g_return_if_fail (GTK_IS_WIDGET (widget));
6182 if (can_default != gtk_widget_get_can_default (widget))
6185 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
6187 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
6189 gtk_widget_queue_resize (widget);
6190 g_object_notify (G_OBJECT (widget), "can-default");
6195 * gtk_widget_get_can_default:
6196 * @widget: a #GtkWidget
6198 * Determines whether @widget can be a default widget. See
6199 * gtk_widget_set_can_default().
6201 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6206 gtk_widget_get_can_default (GtkWidget *widget)
6208 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6210 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6214 * gtk_widget_has_default:
6215 * @widget: a #GtkWidget
6217 * Determines whether @widget is the current default widget within its
6218 * toplevel. See gtk_widget_set_can_default().
6220 * Return value: %TRUE if @widget is the current default widget within
6221 * its toplevel, %FALSE otherwise
6226 gtk_widget_has_default (GtkWidget *widget)
6228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6230 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6234 _gtk_widget_set_has_default (GtkWidget *widget,
6235 gboolean has_default)
6238 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6240 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6244 * gtk_widget_grab_default:
6245 * @widget: a #GtkWidget
6247 * Causes @widget to become the default widget. @widget must have the
6248 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6249 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6250 * %TRUE)</literal>. The default widget is activated when
6251 * the user presses Enter in a window. Default widgets must be
6252 * activatable, that is, gtk_widget_activate() should affect them. Note
6253 * that #GtkEntry widgets require the "activates-default" property
6254 * set to %TRUE before they activate the default widget when Enter
6255 * is pressed and the #GtkEntry is focused.
6258 gtk_widget_grab_default (GtkWidget *widget)
6262 g_return_if_fail (GTK_IS_WIDGET (widget));
6263 g_return_if_fail (gtk_widget_get_can_default (widget));
6265 window = gtk_widget_get_toplevel (widget);
6267 if (window && gtk_widget_is_toplevel (window))
6268 gtk_window_set_default (GTK_WINDOW (window), widget);
6270 g_warning (G_STRLOC ": widget not within a GtkWindow");
6274 * gtk_widget_set_receives_default:
6275 * @widget: a #GtkWidget
6276 * @receives_default: whether or not @widget can be a default widget.
6278 * Specifies whether @widget will be treated as the default widget
6279 * within its toplevel when it has the focus, even if another widget
6282 * See gtk_widget_grab_default() for details about the meaning of
6288 gtk_widget_set_receives_default (GtkWidget *widget,
6289 gboolean receives_default)
6291 g_return_if_fail (GTK_IS_WIDGET (widget));
6293 if (receives_default != gtk_widget_get_receives_default (widget))
6295 if (receives_default)
6296 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6298 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6300 g_object_notify (G_OBJECT (widget), "receives-default");
6305 * gtk_widget_get_receives_default:
6306 * @widget: a #GtkWidget
6308 * Determines whether @widget is alyways treated as default widget
6309 * withing its toplevel when it has the focus, even if another widget
6312 * See gtk_widget_set_receives_default().
6314 * Return value: %TRUE if @widget acts as default widget when focussed,
6320 gtk_widget_get_receives_default (GtkWidget *widget)
6322 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6324 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6328 * gtk_widget_has_grab:
6329 * @widget: a #GtkWidget
6331 * Determines whether the widget is currently grabbing events, so it
6332 * is the only widget receiving input events (keyboard and mouse).
6334 * See also gtk_grab_add().
6336 * Return value: %TRUE if the widget is in the grab_widgets stack
6341 gtk_widget_has_grab (GtkWidget *widget)
6343 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6345 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6349 _gtk_widget_set_has_grab (GtkWidget *widget,
6353 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6355 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6359 * gtk_widget_device_is_shadowed:
6360 * @widget: a #GtkWidget
6361 * @device: a #GdkDevice
6363 * Returns %TRUE if @device has been shadowed by a GTK+
6364 * device grab on another widget, so it would stop sending
6365 * events to @widget. This may be used in the
6366 * #GtkWidget::grab-notify signal to check for specific
6367 * devices. See gtk_device_grab_add().
6369 * Returns: %TRUE if there is an ongoing grab on @device
6370 * by another #GtkWidget than @widget.
6375 gtk_widget_device_is_shadowed (GtkWidget *widget,
6378 GtkWindowGroup *group;
6379 GtkWidget *grab_widget, *toplevel;
6381 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6382 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6384 if (!gtk_widget_get_realized (widget))
6387 toplevel = gtk_widget_get_toplevel (widget);
6389 if (GTK_IS_WINDOW (toplevel))
6390 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6392 group = gtk_window_get_group (NULL);
6394 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6396 /* Widget not inside the hierarchy of grab_widget */
6398 widget != grab_widget &&
6399 !gtk_widget_is_ancestor (widget, grab_widget))
6402 grab_widget = gtk_window_group_get_current_grab (group);
6403 if (grab_widget && widget != grab_widget &&
6404 !gtk_widget_is_ancestor (widget, grab_widget))
6411 * gtk_widget_set_name:
6412 * @widget: a #GtkWidget
6413 * @name: name for the widget
6415 * Widgets can be named, which allows you to refer to them from a
6416 * gtkrc file. You can apply a style to widgets with a particular name
6417 * in the gtkrc file. See the documentation for gtkrc files (on the
6418 * same page as the docs for #GtkRcStyle).
6420 * Note that widget names are separated by periods in paths (see
6421 * gtk_widget_path()), so names with embedded periods may cause confusion.
6424 gtk_widget_set_name (GtkWidget *widget,
6427 GtkWidgetPrivate *priv;
6430 g_return_if_fail (GTK_IS_WIDGET (widget));
6432 priv = widget->priv;
6434 new_name = g_strdup (name);
6435 g_free (priv->name);
6436 priv->name = new_name;
6438 if (gtk_widget_has_rc_style (widget))
6439 gtk_widget_reset_rc_style (widget);
6441 g_object_notify (G_OBJECT (widget), "name");
6445 * gtk_widget_get_name:
6446 * @widget: a #GtkWidget
6448 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6449 * significance of widget names.
6451 * Return value: name of the widget. This string is owned by GTK+ and
6452 * should not be modified or freed
6454 G_CONST_RETURN gchar*
6455 gtk_widget_get_name (GtkWidget *widget)
6457 GtkWidgetPrivate *priv;
6459 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6461 priv = widget->priv;
6465 return G_OBJECT_TYPE_NAME (widget);
6469 * gtk_widget_set_state:
6470 * @widget: a #GtkWidget
6471 * @state: new state for @widget
6473 * This function is for use in widget implementations. Sets the state
6474 * of a widget (insensitive, prelighted, etc.) Usually you should set
6475 * the state using wrapper functions such as gtk_widget_set_sensitive().
6478 gtk_widget_set_state (GtkWidget *widget,
6481 GtkWidgetPrivate *priv;
6483 g_return_if_fail (GTK_IS_WIDGET (widget));
6485 priv = widget->priv;
6487 if (state == gtk_widget_get_state (widget))
6490 if (state == GTK_STATE_INSENSITIVE)
6491 gtk_widget_set_sensitive (widget, FALSE);
6497 data.state_restoration = FALSE;
6498 data.use_forall = FALSE;
6500 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6502 data.parent_sensitive = TRUE;
6504 gtk_widget_propagate_state (widget, &data);
6506 if (gtk_widget_is_drawable (widget))
6507 gtk_widget_queue_draw (widget);
6512 * gtk_widget_get_state:
6513 * @widget: a #GtkWidget
6515 * Returns the widget's state. See gtk_widget_set_state().
6517 * Returns: the state of @widget.
6522 gtk_widget_get_state (GtkWidget *widget)
6524 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6526 return widget->priv->state;
6530 * gtk_widget_set_visible:
6531 * @widget: a #GtkWidget
6532 * @visible: whether the widget should be shown or not
6534 * Sets the visibility state of @widget. Note that setting this to
6535 * %TRUE doesn't mean the widget is actually viewable, see
6536 * gtk_widget_get_visible().
6538 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6539 * but is nicer to use when the visibility of the widget depends on
6545 gtk_widget_set_visible (GtkWidget *widget,
6548 g_return_if_fail (GTK_IS_WIDGET (widget));
6550 if (visible != gtk_widget_get_visible (widget))
6553 gtk_widget_show (widget);
6555 gtk_widget_hide (widget);
6560 * gtk_widget_get_visible:
6561 * @widget: a #GtkWidget
6563 * Determines whether the widget is visible. Note that this doesn't
6564 * take into account whether the widget's parent is also visible
6565 * or the widget is obscured in any way.
6567 * See gtk_widget_set_visible().
6569 * Return value: %TRUE if the widget is visible
6574 gtk_widget_get_visible (GtkWidget *widget)
6576 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6578 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6582 * gtk_widget_set_has_window:
6583 * @widget: a #GtkWidget
6584 * @has_window: whether or not @widget has a window.
6586 * Specifies whether @widget has a #GdkWindow of its own. Note that
6587 * all realized widgets have a non-%NULL "window" pointer
6588 * (gtk_widget_get_window() never returns a %NULL window when a widget
6589 * is realized), but for many of them it's actually the #GdkWindow of
6590 * one of its parent widgets. Widgets that do not create a %window for
6591 * themselves in GtkWidget::realize() must announce this by
6592 * calling this function with @has_window = %FALSE.
6594 * This function should only be called by widget implementations,
6595 * and they should call it in their init() function.
6600 gtk_widget_set_has_window (GtkWidget *widget,
6601 gboolean has_window)
6603 g_return_if_fail (GTK_IS_WIDGET (widget));
6606 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6608 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6612 * gtk_widget_get_has_window:
6613 * @widget: a #GtkWidget
6615 * Determines whether @widget has a #GdkWindow of its own. See
6616 * gtk_widget_set_has_window().
6618 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6623 gtk_widget_get_has_window (GtkWidget *widget)
6625 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6627 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6631 * gtk_widget_is_toplevel:
6632 * @widget: a #GtkWidget
6634 * Determines whether @widget is a toplevel widget. Currently only
6635 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6636 * widgets have no parent widget.
6638 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6643 gtk_widget_is_toplevel (GtkWidget *widget)
6645 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6647 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6651 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6652 gboolean is_toplevel)
6655 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6657 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6661 * gtk_widget_is_drawable:
6662 * @widget: a #GtkWidget
6664 * Determines whether @widget can be drawn to. A widget can be drawn
6665 * to if it is mapped and visible.
6667 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6672 gtk_widget_is_drawable (GtkWidget *widget)
6674 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6676 return (gtk_widget_get_visible (widget) &&
6677 gtk_widget_get_mapped (widget));
6681 * gtk_widget_get_realized:
6682 * @widget: a #GtkWidget
6684 * Determines whether @widget is realized.
6686 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6691 gtk_widget_get_realized (GtkWidget *widget)
6693 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6695 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6699 * gtk_widget_set_realized:
6700 * @widget: a #GtkWidget
6701 * @realized: %TRUE to mark the widget as realized
6703 * Marks the widget as being realized.
6705 * This function should only ever be called in a derived widget's
6706 * "realize" or "unrealize" implementation.
6711 gtk_widget_set_realized (GtkWidget *widget,
6714 g_return_if_fail (GTK_IS_WIDGET (widget));
6717 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6719 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6723 * gtk_widget_get_mapped:
6724 * @widget: a #GtkWidget
6726 * Whether the widget is mapped.
6728 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6733 gtk_widget_get_mapped (GtkWidget *widget)
6735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6737 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6741 * gtk_widget_set_mapped:
6742 * @widget: a #GtkWidget
6743 * @mapped: %TRUE to mark the widget as mapped
6745 * Marks the widget as being realized.
6747 * This function should only ever be called in a derived widget's
6748 * "map" or "unmap" implementation.
6753 gtk_widget_set_mapped (GtkWidget *widget,
6756 g_return_if_fail (GTK_IS_WIDGET (widget));
6759 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6761 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6765 * gtk_widget_set_app_paintable:
6766 * @widget: a #GtkWidget
6767 * @app_paintable: %TRUE if the application will paint on the widget
6769 * Sets whether the application intends to draw on the widget in
6770 * an #GtkWidget::draw handler.
6772 * This is a hint to the widget and does not affect the behavior of
6773 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6774 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6775 * the effect is to suppress default themed drawing of the widget's
6776 * background. (Children of the widget will still be drawn.) The application
6777 * is then entirely responsible for drawing the widget background.
6779 * Note that the background is still drawn when the widget is mapped.
6782 gtk_widget_set_app_paintable (GtkWidget *widget,
6783 gboolean app_paintable)
6785 g_return_if_fail (GTK_IS_WIDGET (widget));
6787 app_paintable = (app_paintable != FALSE);
6789 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6792 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6794 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6796 if (gtk_widget_is_drawable (widget))
6797 gtk_widget_queue_draw (widget);
6799 g_object_notify (G_OBJECT (widget), "app-paintable");
6804 * gtk_widget_get_app_paintable:
6805 * @widget: a #GtkWidget
6807 * Determines whether the application intends to draw on the widget in
6808 * an #GtkWidget::draw handler.
6810 * See gtk_widget_set_app_paintable()
6812 * Return value: %TRUE if the widget is app paintable
6817 gtk_widget_get_app_paintable (GtkWidget *widget)
6819 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6821 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6825 * gtk_widget_set_double_buffered:
6826 * @widget: a #GtkWidget
6827 * @double_buffered: %TRUE to double-buffer a widget
6829 * Widgets are double buffered by default; you can use this function
6830 * to turn off the buffering. "Double buffered" simply means that
6831 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6832 * automatically around expose events sent to the
6833 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6834 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6835 * buffer to the screen. The result is that users see the window
6836 * update in one smooth step, and don't see individual graphics
6837 * primitives being rendered.
6839 * In very simple terms, double buffered widgets don't flicker,
6840 * so you would only use this function to turn off double buffering
6841 * if you had special needs and really knew what you were doing.
6843 * Note: if you turn off double-buffering, you have to handle
6844 * expose events, since even the clearing to the background color or
6845 * pixmap will not happen automatically (as it is done in
6846 * gdk_window_begin_paint()).
6849 gtk_widget_set_double_buffered (GtkWidget *widget,
6850 gboolean double_buffered)
6852 g_return_if_fail (GTK_IS_WIDGET (widget));
6854 double_buffered = (double_buffered != FALSE);
6856 if (double_buffered != gtk_widget_get_double_buffered (widget))
6858 if (double_buffered)
6859 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6861 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6863 g_object_notify (G_OBJECT (widget), "double-buffered");
6868 * gtk_widget_get_double_buffered:
6869 * @widget: a #GtkWidget
6871 * Determines whether the widget is double buffered.
6873 * See gtk_widget_set_double_buffered()
6875 * Return value: %TRUE if the widget is double buffered
6880 gtk_widget_get_double_buffered (GtkWidget *widget)
6882 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6884 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6888 * gtk_widget_set_redraw_on_allocate:
6889 * @widget: a #GtkWidget
6890 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6891 * when it is allocated to a new size. Otherwise, only the
6892 * new portion of the widget will be redrawn.
6894 * Sets whether the entire widget is queued for drawing when its size
6895 * allocation changes. By default, this setting is %TRUE and
6896 * the entire widget is redrawn on every size change. If your widget
6897 * leaves the upper left unchanged when made bigger, turning this
6898 * setting off will improve performance.
6900 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6901 * off all allocation on resizing: the widget will not even redraw if
6902 * its position changes; this is to allow containers that don't draw
6903 * anything to avoid excess invalidations. If you set this flag on a
6904 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6905 * you are responsible for invalidating both the old and new allocation
6906 * of the widget when the widget is moved and responsible for invalidating
6907 * regions newly when the widget increases size.
6910 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6911 gboolean redraw_on_allocate)
6913 g_return_if_fail (GTK_IS_WIDGET (widget));
6915 if (redraw_on_allocate)
6916 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6918 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6922 * gtk_widget_set_sensitive:
6923 * @widget: a #GtkWidget
6924 * @sensitive: %TRUE to make the widget sensitive
6926 * Sets the sensitivity of a widget. A widget is sensitive if the user
6927 * can interact with it. Insensitive widgets are "grayed out" and the
6928 * user can't interact with them. Insensitive widgets are known as
6929 * "inactive", "disabled", or "ghosted" in some other toolkits.
6932 gtk_widget_set_sensitive (GtkWidget *widget,
6935 GtkWidgetPrivate *priv;
6938 g_return_if_fail (GTK_IS_WIDGET (widget));
6940 priv = widget->priv;
6942 sensitive = (sensitive != FALSE);
6944 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6949 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6950 data.state = priv->saved_state;
6954 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6955 data.state = gtk_widget_get_state (widget);
6957 data.state_restoration = TRUE;
6958 data.use_forall = TRUE;
6961 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6963 data.parent_sensitive = TRUE;
6965 gtk_widget_propagate_state (widget, &data);
6966 if (gtk_widget_is_drawable (widget))
6967 gtk_widget_queue_draw (widget);
6969 g_object_notify (G_OBJECT (widget), "sensitive");
6973 * gtk_widget_get_sensitive:
6974 * @widget: a #GtkWidget
6976 * Returns the widget's sensitivity (in the sense of returning
6977 * the value that has been set using gtk_widget_set_sensitive()).
6979 * The effective sensitivity of a widget is however determined by both its
6980 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6982 * Returns: %TRUE if the widget is sensitive
6987 gtk_widget_get_sensitive (GtkWidget *widget)
6989 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6991 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6995 * gtk_widget_is_sensitive:
6996 * @widget: a #GtkWidget
6998 * Returns the widget's effective sensitivity, which means
6999 * it is sensitive itself and also its parent widget is sensntive
7001 * Returns: %TRUE if the widget is effectively sensitive
7006 gtk_widget_is_sensitive (GtkWidget *widget)
7008 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7010 return (gtk_widget_get_sensitive (widget) &&
7011 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
7015 * gtk_widget_set_parent:
7016 * @widget: a #GtkWidget
7017 * @parent: parent container
7019 * This function is useful only when implementing subclasses of
7021 * Sets the container as the parent of @widget, and takes care of
7022 * some details such as updating the state and style of the child
7023 * to reflect its new location. The opposite function is
7024 * gtk_widget_unparent().
7027 gtk_widget_set_parent (GtkWidget *widget,
7030 GtkWidgetPrivate *priv;
7033 g_return_if_fail (GTK_IS_WIDGET (widget));
7034 g_return_if_fail (GTK_IS_WIDGET (parent));
7035 g_return_if_fail (widget != parent);
7037 priv = widget->priv;
7039 if (priv->parent != NULL)
7041 g_warning ("Can't set a parent on widget which has a parent\n");
7044 if (gtk_widget_is_toplevel (widget))
7046 g_warning ("Can't set a parent on a toplevel widget\n");
7050 /* keep this function in sync with gtk_menu_attach_to_widget()
7053 g_object_ref_sink (widget);
7054 priv->parent = parent;
7056 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7057 data.state = gtk_widget_get_state (parent);
7059 data.state = gtk_widget_get_state (widget);
7060 data.state_restoration = FALSE;
7061 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7062 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7064 gtk_widget_propagate_state (widget, &data);
7066 gtk_widget_reset_rc_styles (widget);
7068 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7069 if (GTK_WIDGET_ANCHORED (priv->parent))
7070 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7071 g_object_notify (G_OBJECT (widget), "parent");
7073 /* Enforce realized/mapped invariants
7075 if (gtk_widget_get_realized (priv->parent))
7076 gtk_widget_realize (widget);
7078 if (gtk_widget_get_visible (priv->parent) &&
7079 gtk_widget_get_visible (widget))
7081 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
7082 gtk_widget_get_mapped (priv->parent))
7083 gtk_widget_map (widget);
7085 gtk_widget_queue_resize (widget);
7090 * gtk_widget_get_parent:
7091 * @widget: a #GtkWidget
7093 * Returns the parent container of @widget.
7095 * Return value: (transfer none): the parent container of @widget, or %NULL
7098 gtk_widget_get_parent (GtkWidget *widget)
7100 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7102 return widget->priv->parent;
7105 /*****************************************
7107 * see docs/styles.txt
7108 *****************************************/
7111 * gtk_widget_style_attach:
7112 * @widget: a #GtkWidget
7114 * This function attaches the widget's #GtkStyle to the widget's
7115 * #GdkWindow. It is a replacement for
7118 * widget->style = gtk_style_attach (widget->style, widget->window);
7121 * and should only ever be called in a derived widget's "realize"
7122 * implementation which does not chain up to its parent class'
7123 * "realize" implementation, because one of the parent classes
7124 * (finally #GtkWidget) would attach the style itself.
7129 gtk_widget_style_attach (GtkWidget *widget)
7131 GtkWidgetPrivate *priv;
7133 g_return_if_fail (GTK_IS_WIDGET (widget));
7134 g_return_if_fail (gtk_widget_get_realized (widget));
7136 priv = widget->priv;
7138 priv->style = gtk_style_attach (priv->style, priv->window);
7142 * gtk_widget_has_rc_style:
7143 * @widget: a #GtkWidget
7145 * Determines if the widget style has been looked up through the rc mechanism.
7147 * Returns: %TRUE if the widget has been looked up through the rc
7148 * mechanism, %FALSE otherwise.
7153 gtk_widget_has_rc_style (GtkWidget *widget)
7155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7157 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
7161 * gtk_widget_set_style:
7162 * @widget: a #GtkWidget
7163 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7164 * gtk_widget_set_style() and go back to the default style
7166 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7167 * want to use this function; it interacts badly with themes, because
7168 * themes work by replacing the #GtkStyle. Instead, use
7169 * gtk_widget_modify_style().
7172 gtk_widget_set_style (GtkWidget *widget,
7175 g_return_if_fail (GTK_IS_WIDGET (widget));
7179 gboolean initial_emission;
7181 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7183 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
7184 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
7186 gtk_widget_set_style_internal (widget, style, initial_emission);
7190 if (GTK_WIDGET_USER_STYLE (widget))
7191 gtk_widget_reset_rc_style (widget);
7196 * gtk_widget_ensure_style:
7197 * @widget: a #GtkWidget
7199 * Ensures that @widget has a style (@widget->style). Not a very useful
7200 * function; most of the time, if you want the style, the widget is
7201 * realized, and realized widgets are guaranteed to have a style
7205 gtk_widget_ensure_style (GtkWidget *widget)
7207 g_return_if_fail (GTK_IS_WIDGET (widget));
7209 if (!GTK_WIDGET_USER_STYLE (widget) &&
7210 !gtk_widget_has_rc_style (widget))
7211 gtk_widget_reset_rc_style (widget);
7214 /* Look up the RC style for this widget, unsetting any user style that
7215 * may be in effect currently
7218 gtk_widget_reset_rc_style (GtkWidget *widget)
7220 GtkWidgetPrivate *priv = widget->priv;
7221 GtkStyle *new_style = NULL;
7222 gboolean initial_emission;
7224 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7226 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7227 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7229 if (gtk_widget_has_screen (widget))
7230 new_style = gtk_rc_get_style (widget);
7232 new_style = gtk_widget_get_default_style ();
7234 if (initial_emission || new_style != priv->style)
7235 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7239 * gtk_widget_get_style:
7240 * @widget: a #GtkWidget
7242 * Simply an accessor function that returns @widget->style.
7244 * Return value: (transfer none): the widget's #GtkStyle
7247 gtk_widget_get_style (GtkWidget *widget)
7249 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7251 return widget->priv->style;
7255 * gtk_widget_modify_style:
7256 * @widget: a #GtkWidget
7257 * @style: the #GtkRcStyle holding the style modifications
7259 * Modifies style values on the widget. Modifications made using this
7260 * technique take precedence over style values set via an RC file,
7261 * however, they will be overriden if a style is explicitely set on
7262 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7263 * is designed so each field can either be set or unset, so it is
7264 * possible, using this function, to modify some style values and
7265 * leave the others unchanged.
7267 * Note that modifications made with this function are not cumulative
7268 * with previous calls to gtk_widget_modify_style() or with such
7269 * functions as gtk_widget_modify_fg(). If you wish to retain
7270 * previous values, you must first call gtk_widget_get_modifier_style(),
7271 * make your modifications to the returned style, then call
7272 * gtk_widget_modify_style() with that style. On the other hand,
7273 * if you first call gtk_widget_modify_style(), subsequent calls
7274 * to such functions gtk_widget_modify_fg() will have a cumulative
7275 * effect with the initial modifications.
7278 gtk_widget_modify_style (GtkWidget *widget,
7281 g_return_if_fail (GTK_IS_WIDGET (widget));
7282 g_return_if_fail (GTK_IS_RC_STYLE (style));
7284 g_object_set_qdata_full (G_OBJECT (widget),
7286 gtk_rc_style_copy (style),
7287 (GDestroyNotify) g_object_unref);
7289 /* note that "style" may be invalid here if it was the old
7290 * modifier style and the only reference was our own.
7293 if (gtk_widget_has_rc_style (widget))
7294 gtk_widget_reset_rc_style (widget);
7298 * gtk_widget_get_modifier_style:
7299 * @widget: a #GtkWidget
7301 * Returns the current modifier style for the widget. (As set by
7302 * gtk_widget_modify_style().) If no style has previously set, a new
7303 * #GtkRcStyle will be created with all values unset, and set as the
7304 * modifier style for the widget. If you make changes to this rc
7305 * style, you must call gtk_widget_modify_style(), passing in the
7306 * returned rc style, to make sure that your changes take effect.
7308 * Caution: passing the style back to gtk_widget_modify_style() will
7309 * normally end up destroying it, because gtk_widget_modify_style() copies
7310 * the passed-in style and sets the copy as the new modifier style,
7311 * thus dropping any reference to the old modifier style. Add a reference
7312 * to the modifier style if you want to keep it alive.
7314 * Return value: (transfer none): the modifier style for the widget. This rc style is
7315 * owned by the widget. If you want to keep a pointer to value this
7316 * around, you must add a refcount using g_object_ref().
7319 gtk_widget_get_modifier_style (GtkWidget *widget)
7321 GtkRcStyle *rc_style;
7323 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7325 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7329 rc_style = gtk_rc_style_new ();
7330 g_object_set_qdata_full (G_OBJECT (widget),
7333 (GDestroyNotify) g_object_unref);
7340 gtk_widget_modify_color_component (GtkWidget *widget,
7341 GtkRcFlags component,
7343 const GdkColor *color)
7345 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7352 rc_style->fg[state] = *color;
7355 rc_style->bg[state] = *color;
7358 rc_style->text[state] = *color;
7361 rc_style->base[state] = *color;
7364 g_assert_not_reached();
7367 rc_style->color_flags[state] |= component;
7370 rc_style->color_flags[state] &= ~component;
7372 gtk_widget_modify_style (widget, rc_style);
7376 * gtk_widget_modify_symbolic_color:
7377 * @widget: a #GtkWidget
7378 * @name: the name of the symbolic color to modify
7379 * @color: (allow-none): the color to assign (does not need to be allocated),
7380 * or %NULL to undo the effect of previous calls to
7381 * of gtk_widget_modify_symbolic_color().
7383 * Sets a symbolic color for a widget.
7384 * All other style values are left untouched. See also
7385 * gtk_widget_modify_style().
7390 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7392 const GdkColor *color)
7394 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7396 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7398 gtk_widget_modify_style (widget, rc_style);
7402 * gtk_widget_modify_fg:
7403 * @widget: a #GtkWidget
7404 * @state: the state for which to set the foreground color
7405 * @color: (allow-none): the color to assign (does not need to be allocated),
7406 * or %NULL to undo the effect of previous calls to
7407 * of gtk_widget_modify_fg().
7409 * Sets the foreground color for a widget in a particular state.
7410 * All other style values are left untouched. See also
7411 * gtk_widget_modify_style().
7414 gtk_widget_modify_fg (GtkWidget *widget,
7416 const GdkColor *color)
7418 g_return_if_fail (GTK_IS_WIDGET (widget));
7419 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7421 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7425 * gtk_widget_modify_bg:
7426 * @widget: a #GtkWidget
7427 * @state: the state for which to set the background color
7428 * @color: (allow-none): the color to assign (does not need to be allocated),
7429 * or %NULL to undo the effect of previous calls to
7430 * of gtk_widget_modify_bg().
7432 * Sets the background color for a widget in a particular state.
7433 * All other style values are left untouched. See also
7434 * gtk_widget_modify_style().
7436 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7437 * draw on their parent container's window and thus may not draw any
7438 * background themselves. This is the case for e.g. #GtkLabel. To modify
7439 * the background of such widgets, you have to set the background color
7440 * on their parent; if you want to set the background of a rectangular
7441 * area around a label, try placing the label in a #GtkEventBox widget
7442 * and setting the background color on that.
7445 gtk_widget_modify_bg (GtkWidget *widget,
7447 const GdkColor *color)
7449 g_return_if_fail (GTK_IS_WIDGET (widget));
7450 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7452 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7456 * gtk_widget_modify_text:
7457 * @widget: a #GtkWidget
7458 * @state: the state for which to set the text color
7459 * @color: (allow-none): the color to assign (does not need to be allocated),
7460 * or %NULL to undo the effect of previous calls to
7461 * of gtk_widget_modify_text().
7463 * Sets the text color for a widget in a particular state. All other
7464 * style values are left untouched. The text color is the foreground
7465 * color used along with the base color (see gtk_widget_modify_base())
7466 * for widgets such as #GtkEntry and #GtkTextView. See also
7467 * gtk_widget_modify_style().
7470 gtk_widget_modify_text (GtkWidget *widget,
7472 const GdkColor *color)
7474 g_return_if_fail (GTK_IS_WIDGET (widget));
7475 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7477 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7481 * gtk_widget_modify_base:
7482 * @widget: a #GtkWidget
7483 * @state: the state for which to set the base color
7484 * @color: (allow-none): the color to assign (does not need to be allocated),
7485 * or %NULL to undo the effect of previous calls to
7486 * of gtk_widget_modify_base().
7488 * Sets the base color for a widget in a particular state.
7489 * All other style values are left untouched. The base color
7490 * is the background color used along with the text color
7491 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7492 * and #GtkTextView. See also gtk_widget_modify_style().
7494 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7495 * draw on their parent container's window and thus may not draw any
7496 * background themselves. This is the case for e.g. #GtkLabel. To modify
7497 * the background of such widgets, you have to set the base color on their
7498 * parent; if you want to set the background of a rectangular area around
7499 * a label, try placing the label in a #GtkEventBox widget and setting
7500 * the base color on that.
7503 gtk_widget_modify_base (GtkWidget *widget,
7505 const GdkColor *color)
7507 g_return_if_fail (GTK_IS_WIDGET (widget));
7508 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7510 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7514 modify_color_property (GtkWidget *widget,
7515 GtkRcStyle *rc_style,
7517 const GdkColor *color)
7519 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7520 GQuark property_name = g_quark_from_string (name);
7524 GtkRcProperty rc_property = {0};
7527 rc_property.type_name = type_name;
7528 rc_property.property_name = property_name;
7529 rc_property.origin = NULL;
7531 color_name = gdk_color_to_string (color);
7532 g_value_init (&rc_property.value, G_TYPE_STRING);
7533 g_value_take_string (&rc_property.value, color_name);
7535 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7537 g_value_unset (&rc_property.value);
7540 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7544 * gtk_widget_modify_cursor:
7545 * @widget: a #GtkWidget
7546 * @primary: the color to use for primary cursor (does not need to be
7547 * allocated), or %NULL to undo the effect of previous calls to
7548 * of gtk_widget_modify_cursor().
7549 * @secondary: the color to use for secondary cursor (does not need to be
7550 * allocated), or %NULL to undo the effect of previous calls to
7551 * of gtk_widget_modify_cursor().
7553 * Sets the cursor color to use in a widget, overriding the
7554 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7555 * style properties. All other style values are left untouched.
7556 * See also gtk_widget_modify_style().
7561 gtk_widget_modify_cursor (GtkWidget *widget,
7562 const GdkColor *primary,
7563 const GdkColor *secondary)
7565 GtkRcStyle *rc_style;
7567 g_return_if_fail (GTK_IS_WIDGET (widget));
7569 rc_style = gtk_widget_get_modifier_style (widget);
7571 modify_color_property (widget, rc_style, "cursor-color", primary);
7572 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7574 gtk_widget_modify_style (widget, rc_style);
7578 * gtk_widget_modify_font:
7579 * @widget: a #GtkWidget
7580 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7581 * the effect of previous calls to gtk_widget_modify_font().
7583 * Sets the font to use for a widget. All other style values are left
7584 * untouched. See also gtk_widget_modify_style().
7587 gtk_widget_modify_font (GtkWidget *widget,
7588 PangoFontDescription *font_desc)
7590 GtkRcStyle *rc_style;
7592 g_return_if_fail (GTK_IS_WIDGET (widget));
7594 rc_style = gtk_widget_get_modifier_style (widget);
7596 if (rc_style->font_desc)
7597 pango_font_description_free (rc_style->font_desc);
7600 rc_style->font_desc = pango_font_description_copy (font_desc);
7602 rc_style->font_desc = NULL;
7604 gtk_widget_modify_style (widget, rc_style);
7608 gtk_widget_real_direction_changed (GtkWidget *widget,
7609 GtkTextDirection previous_direction)
7611 gtk_widget_queue_resize (widget);
7615 gtk_widget_real_style_set (GtkWidget *widget,
7616 GtkStyle *previous_style)
7618 GtkWidgetPrivate *priv = widget->priv;
7620 if (gtk_widget_get_realized (widget) &&
7621 gtk_widget_get_has_window (widget))
7622 gtk_style_set_background (priv->style, priv->window, priv->state);
7626 gtk_widget_set_style_internal (GtkWidget *widget,
7628 gboolean initial_emission)
7630 GtkWidgetPrivate *priv = widget->priv;
7632 g_object_ref (widget);
7633 g_object_freeze_notify (G_OBJECT (widget));
7635 if (priv->style != style)
7637 GtkStyle *previous_style;
7639 if (gtk_widget_get_realized (widget))
7641 gtk_widget_reset_shapes (widget);
7642 gtk_style_detach (priv->style);
7645 previous_style = priv->style;
7646 priv->style = style;
7647 g_object_ref (priv->style);
7649 if (gtk_widget_get_realized (widget))
7650 priv->style = gtk_style_attach (priv->style, priv->window);
7652 gtk_widget_update_pango_context (widget);
7653 g_signal_emit (widget,
7654 widget_signals[STYLE_SET],
7656 initial_emission ? NULL : previous_style);
7657 g_object_unref (previous_style);
7659 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7660 gtk_widget_queue_resize (widget);
7662 else if (initial_emission)
7664 gtk_widget_update_pango_context (widget);
7665 g_signal_emit (widget,
7666 widget_signals[STYLE_SET],
7670 g_object_notify (G_OBJECT (widget), "style");
7671 g_object_thaw_notify (G_OBJECT (widget));
7672 g_object_unref (widget);
7676 GtkWidget *previous_toplevel;
7677 GdkScreen *previous_screen;
7678 GdkScreen *new_screen;
7679 } HierarchyChangedInfo;
7682 do_screen_change (GtkWidget *widget,
7683 GdkScreen *old_screen,
7684 GdkScreen *new_screen)
7686 if (old_screen != new_screen)
7690 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7692 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7695 _gtk_tooltip_hide (widget);
7696 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7701 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7702 gpointer client_data)
7704 GtkWidgetPrivate *priv = widget->priv;
7705 HierarchyChangedInfo *info = client_data;
7706 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7707 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7709 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7711 g_object_ref (widget);
7714 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7716 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7718 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7719 do_screen_change (widget, info->previous_screen, info->new_screen);
7721 if (GTK_IS_CONTAINER (widget))
7722 gtk_container_forall (GTK_CONTAINER (widget),
7723 gtk_widget_propagate_hierarchy_changed_recurse,
7726 g_object_unref (widget);
7731 * _gtk_widget_propagate_hierarchy_changed:
7732 * @widget: a #GtkWidget
7733 * @previous_toplevel: Previous toplevel
7735 * Propagates changes in the anchored state to a widget and all
7736 * children, unsetting or setting the %ANCHORED flag, and
7737 * emitting #GtkWidget::hierarchy-changed.
7740 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7741 GtkWidget *previous_toplevel)
7743 GtkWidgetPrivate *priv = widget->priv;
7744 HierarchyChangedInfo info;
7746 info.previous_toplevel = previous_toplevel;
7747 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7749 if (gtk_widget_is_toplevel (widget) ||
7750 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7751 info.new_screen = gtk_widget_get_screen (widget);
7753 info.new_screen = NULL;
7755 if (info.previous_screen)
7756 g_object_ref (info.previous_screen);
7757 if (previous_toplevel)
7758 g_object_ref (previous_toplevel);
7760 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7762 if (previous_toplevel)
7763 g_object_unref (previous_toplevel);
7764 if (info.previous_screen)
7765 g_object_unref (info.previous_screen);
7769 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7770 gpointer client_data)
7772 HierarchyChangedInfo *info = client_data;
7774 g_object_ref (widget);
7776 do_screen_change (widget, info->previous_screen, info->new_screen);
7778 if (GTK_IS_CONTAINER (widget))
7779 gtk_container_forall (GTK_CONTAINER (widget),
7780 gtk_widget_propagate_screen_changed_recurse,
7783 g_object_unref (widget);
7787 * gtk_widget_is_composited:
7788 * @widget: a #GtkWidget
7790 * Whether @widget can rely on having its alpha channel
7791 * drawn correctly. On X11 this function returns whether a
7792 * compositing manager is running for @widget's screen.
7794 * Please note that the semantics of this call will change
7795 * in the future if used on a widget that has a composited
7796 * window in its hierarchy (as set by gdk_window_set_composited()).
7798 * Return value: %TRUE if the widget can rely on its alpha
7799 * channel being drawn correctly.
7804 gtk_widget_is_composited (GtkWidget *widget)
7808 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7810 screen = gtk_widget_get_screen (widget);
7812 return gdk_screen_is_composited (screen);
7816 propagate_composited_changed (GtkWidget *widget,
7819 if (GTK_IS_CONTAINER (widget))
7821 gtk_container_forall (GTK_CONTAINER (widget),
7822 propagate_composited_changed,
7826 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7830 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7832 propagate_composited_changed (widget, NULL);
7836 * _gtk_widget_propagate_screen_changed:
7837 * @widget: a #GtkWidget
7838 * @previous_screen: Previous screen
7840 * Propagates changes in the screen for a widget to all
7841 * children, emitting #GtkWidget::screen-changed.
7844 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7845 GdkScreen *previous_screen)
7847 HierarchyChangedInfo info;
7849 info.previous_screen = previous_screen;
7850 info.new_screen = gtk_widget_get_screen (widget);
7852 if (previous_screen)
7853 g_object_ref (previous_screen);
7855 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7857 if (previous_screen)
7858 g_object_unref (previous_screen);
7862 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7864 if (gtk_widget_has_rc_style (widget))
7865 gtk_widget_reset_rc_style (widget);
7867 if (GTK_IS_CONTAINER (widget))
7868 gtk_container_forall (GTK_CONTAINER (widget),
7869 reset_rc_styles_recurse,
7875 * gtk_widget_reset_rc_styles:
7876 * @widget: a #GtkWidget.
7878 * Reset the styles of @widget and all descendents, so when
7879 * they are looked up again, they get the correct values
7880 * for the currently loaded RC file settings.
7882 * This function is not useful for applications.
7885 gtk_widget_reset_rc_styles (GtkWidget *widget)
7887 g_return_if_fail (GTK_IS_WIDGET (widget));
7889 reset_rc_styles_recurse (widget, NULL);
7893 * gtk_widget_get_default_style:
7895 * Returns the default style used by all widgets initially.
7897 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7898 * by GTK+ and should not be modified or freed.
7901 gtk_widget_get_default_style (void)
7903 if (!gtk_default_style)
7905 gtk_default_style = gtk_style_new ();
7906 g_object_ref (gtk_default_style);
7909 return gtk_default_style;
7912 static PangoContext *
7913 gtk_widget_peek_pango_context (GtkWidget *widget)
7915 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7919 * gtk_widget_get_pango_context:
7920 * @widget: a #GtkWidget
7922 * Gets a #PangoContext with the appropriate font map, font description,
7923 * and base direction for this widget. Unlike the context returned
7924 * by gtk_widget_create_pango_context(), this context is owned by
7925 * the widget (it can be used until the screen for the widget changes
7926 * or the widget is removed from its toplevel), and will be updated to
7927 * match any changes to the widget's attributes.
7929 * If you create and keep a #PangoLayout using this context, you must
7930 * deal with changes to the context by calling pango_layout_context_changed()
7931 * on the layout in response to the #GtkWidget::style-set and
7932 * #GtkWidget::direction-changed signals for the widget.
7934 * Return value: (transfer none): the #PangoContext for the widget.
7937 gtk_widget_get_pango_context (GtkWidget *widget)
7939 PangoContext *context;
7941 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7943 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7946 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7947 g_object_set_qdata_full (G_OBJECT (widget),
7948 quark_pango_context,
7957 update_pango_context (GtkWidget *widget,
7958 PangoContext *context)
7960 GtkWidgetPrivate *priv = widget->priv;
7962 pango_context_set_font_description (context, priv->style->font_desc);
7963 pango_context_set_base_dir (context,
7964 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7965 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7969 gtk_widget_update_pango_context (GtkWidget *widget)
7971 PangoContext *context = gtk_widget_peek_pango_context (widget);
7977 update_pango_context (widget, context);
7979 screen = gtk_widget_get_screen_unchecked (widget);
7982 pango_cairo_context_set_resolution (context,
7983 gdk_screen_get_resolution (screen));
7984 pango_cairo_context_set_font_options (context,
7985 gdk_screen_get_font_options (screen));
7991 * gtk_widget_create_pango_context:
7992 * @widget: a #GtkWidget
7994 * Creates a new #PangoContext with the appropriate font map,
7995 * font description, and base direction for drawing text for
7996 * this widget. See also gtk_widget_get_pango_context().
7998 * Return value: (transfer full): the new #PangoContext
8001 gtk_widget_create_pango_context (GtkWidget *widget)
8004 PangoContext *context;
8006 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8008 screen = gtk_widget_get_screen_unchecked (widget);
8011 GTK_NOTE (MULTIHEAD,
8012 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8014 screen = gdk_screen_get_default ();
8017 context = gdk_pango_context_get_for_screen (screen);
8019 update_pango_context (widget, context);
8020 pango_context_set_language (context, gtk_get_default_language ());
8026 * gtk_widget_create_pango_layout:
8027 * @widget: a #GtkWidget
8028 * @text: text to set on the layout (can be %NULL)
8030 * Creates a new #PangoLayout with the appropriate font map,
8031 * font description, and base direction for drawing text for
8034 * If you keep a #PangoLayout created in this way around, in order to
8035 * notify the layout of changes to the base direction or font of this
8036 * widget, you must call pango_layout_context_changed() in response to
8037 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8040 * Return value: (transfer full): the new #PangoLayout
8043 gtk_widget_create_pango_layout (GtkWidget *widget,
8046 PangoLayout *layout;
8047 PangoContext *context;
8049 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8051 context = gtk_widget_get_pango_context (widget);
8052 layout = pango_layout_new (context);
8055 pango_layout_set_text (layout, text, -1);
8061 * gtk_widget_render_icon:
8062 * @widget: a #GtkWidget
8063 * @stock_id: a stock ID
8064 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8065 * render at the size of the source and don't scale (if there are
8066 * multiple source sizes, GTK+ picks one of the available sizes).
8067 * @detail: (allow-none): render detail to pass to theme engine
8069 * A convenience function that uses the theme engine and RC file
8070 * settings for @widget to look up @stock_id and render it to
8071 * a pixbuf. @stock_id should be a stock icon ID such as
8072 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8073 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8074 * identifies the widget or code doing the rendering, so that
8075 * theme engines can special-case rendering for that widget or code.
8077 * The pixels in the returned #GdkPixbuf are shared with the rest of
8078 * the application and should not be modified. The pixbuf should be freed
8079 * after use with g_object_unref().
8081 * Return value: (transfer full): a new pixbuf, or %NULL if the
8082 * stock ID wasn't known
8085 gtk_widget_render_icon (GtkWidget *widget,
8086 const gchar *stock_id,
8088 const gchar *detail)
8090 GtkWidgetPrivate *priv;
8091 GtkIconSet *icon_set;
8094 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8095 g_return_val_if_fail (stock_id != NULL, NULL);
8096 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8098 priv = widget->priv;
8100 gtk_widget_ensure_style (widget);
8102 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8104 if (icon_set == NULL)
8107 retval = gtk_icon_set_render_icon (icon_set,
8109 gtk_widget_get_direction (widget),
8110 gtk_widget_get_state (widget),
8119 * gtk_widget_set_parent_window:
8120 * @widget: a #GtkWidget.
8121 * @parent_window: the new parent window.
8123 * Sets a non default parent window for @widget.
8126 gtk_widget_set_parent_window (GtkWidget *widget,
8127 GdkWindow *parent_window)
8129 GdkWindow *old_parent_window;
8131 g_return_if_fail (GTK_IS_WIDGET (widget));
8133 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8134 quark_parent_window);
8136 if (parent_window != old_parent_window)
8138 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8140 if (old_parent_window)
8141 g_object_unref (old_parent_window);
8143 g_object_ref (parent_window);
8148 * gtk_widget_get_parent_window:
8149 * @widget: a #GtkWidget.
8151 * Gets @widget's parent window.
8153 * Returns: (transfer none): the parent window of @widget.
8156 gtk_widget_get_parent_window (GtkWidget *widget)
8158 GtkWidgetPrivate *priv;
8159 GdkWindow *parent_window;
8161 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8163 priv = widget->priv;
8165 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8167 return (parent_window != NULL) ? parent_window :
8168 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8173 * gtk_widget_set_child_visible:
8174 * @widget: a #GtkWidget
8175 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8177 * Sets whether @widget should be mapped along with its when its parent
8178 * is mapped and @widget has been shown with gtk_widget_show().
8180 * The child visibility can be set for widget before it is added to
8181 * a container with gtk_widget_set_parent(), to avoid mapping
8182 * children unnecessary before immediately unmapping them. However
8183 * it will be reset to its default state of %TRUE when the widget
8184 * is removed from a container.
8186 * Note that changing the child visibility of a widget does not
8187 * queue a resize on the widget. Most of the time, the size of
8188 * a widget is computed from all visible children, whether or
8189 * not they are mapped. If this is not the case, the container
8190 * can queue a resize itself.
8192 * This function is only useful for container implementations and
8193 * never should be called by an application.
8196 gtk_widget_set_child_visible (GtkWidget *widget,
8197 gboolean is_visible)
8199 GtkWidgetPrivate *priv;
8201 g_return_if_fail (GTK_IS_WIDGET (widget));
8202 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8204 priv = widget->priv;
8206 g_object_ref (widget);
8209 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8212 GtkWidget *toplevel;
8214 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8216 toplevel = gtk_widget_get_toplevel (widget);
8217 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8218 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8221 if (priv->parent && gtk_widget_get_realized (priv->parent))
8223 if (gtk_widget_get_mapped (priv->parent) &&
8224 GTK_WIDGET_CHILD_VISIBLE (widget) &&
8225 gtk_widget_get_visible (widget))
8226 gtk_widget_map (widget);
8228 gtk_widget_unmap (widget);
8231 g_object_unref (widget);
8235 * gtk_widget_get_child_visible:
8236 * @widget: a #GtkWidget
8238 * Gets the value set with gtk_widget_set_child_visible().
8239 * If you feel a need to use this function, your code probably
8240 * needs reorganization.
8242 * This function is only useful for container implementations and
8243 * never should be called by an application.
8245 * Return value: %TRUE if the widget is mapped with the parent.
8248 gtk_widget_get_child_visible (GtkWidget *widget)
8250 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8252 return GTK_WIDGET_CHILD_VISIBLE (widget);
8256 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8258 GtkWidget *toplevel;
8260 toplevel = gtk_widget_get_toplevel (widget);
8262 if (gtk_widget_is_toplevel (toplevel))
8264 if (GTK_IS_WINDOW (toplevel))
8265 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8266 else if (GTK_IS_INVISIBLE (toplevel))
8267 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8274 * gtk_widget_get_screen:
8275 * @widget: a #GtkWidget
8277 * Get the #GdkScreen from the toplevel window associated with
8278 * this widget. This function can only be called after the widget
8279 * has been added to a widget hierarchy with a #GtkWindow
8282 * In general, you should only create screen specific
8283 * resources when a widget has been realized, and you should
8284 * free those resources when the widget is unrealized.
8286 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8291 gtk_widget_get_screen (GtkWidget *widget)
8295 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8297 screen = gtk_widget_get_screen_unchecked (widget);
8304 g_warning (G_STRLOC ": Can't get associated screen"
8305 " for a widget unless it is inside a toplevel GtkWindow\n"
8306 " widget type is %s associated top level type is %s",
8307 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8308 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8310 return gdk_screen_get_default ();
8315 * gtk_widget_has_screen:
8316 * @widget: a #GtkWidget
8318 * Checks whether there is a #GdkScreen is associated with
8319 * this widget. All toplevel widgets have an associated
8320 * screen, and all widgets added into a hierarchy with a toplevel
8321 * window at the top.
8323 * Return value: %TRUE if there is a #GdkScreen associcated
8329 gtk_widget_has_screen (GtkWidget *widget)
8331 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8333 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8337 * gtk_widget_get_display:
8338 * @widget: a #GtkWidget
8340 * Get the #GdkDisplay for the toplevel window associated with
8341 * this widget. This function can only be called after the widget
8342 * has been added to a widget hierarchy with a #GtkWindow at the top.
8344 * In general, you should only create display specific
8345 * resources when a widget has been realized, and you should
8346 * free those resources when the widget is unrealized.
8348 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8353 gtk_widget_get_display (GtkWidget *widget)
8355 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8357 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8361 * gtk_widget_get_root_window:
8362 * @widget: a #GtkWidget
8364 * Get the root window where this widget is located. This function can
8365 * only be called after the widget has been added to a widget
8366 * hierarchy with #GtkWindow at the top.
8368 * The root window is useful for such purposes as creating a popup
8369 * #GdkWindow associated with the window. In general, you should only
8370 * create display specific resources when a widget has been realized,
8371 * and you should free those resources when the widget is unrealized.
8373 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8378 gtk_widget_get_root_window (GtkWidget *widget)
8380 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8382 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8386 * gtk_widget_child_focus:
8387 * @widget: a #GtkWidget
8388 * @direction: direction of focus movement
8390 * This function is used by custom widget implementations; if you're
8391 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8392 * to a particular widget, and gtk_container_set_focus_chain() to
8393 * change the focus tab order. So you may want to investigate those
8394 * functions instead.
8396 * gtk_widget_child_focus() is called by containers as the user moves
8397 * around the window using keyboard shortcuts. @direction indicates
8398 * what kind of motion is taking place (up, down, left, right, tab
8399 * forward, tab backward). gtk_widget_child_focus() emits the
8400 * #GtkWidget::focus signal; widgets override the default handler
8401 * for this signal in order to implement appropriate focus behavior.
8403 * The default ::focus handler for a widget should return %TRUE if
8404 * moving in @direction left the focus on a focusable location inside
8405 * that widget, and %FALSE if moving in @direction moved the focus
8406 * outside the widget. If returning %TRUE, widgets normally
8407 * call gtk_widget_grab_focus() to place the focus accordingly;
8408 * if returning %FALSE, they don't modify the current focus location.
8410 * Return value: %TRUE if focus ended up inside @widget
8413 gtk_widget_child_focus (GtkWidget *widget,
8414 GtkDirectionType direction)
8416 gboolean return_val;
8418 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8420 if (!gtk_widget_get_visible (widget) ||
8421 !gtk_widget_is_sensitive (widget))
8424 /* child widgets must set CAN_FOCUS, containers
8425 * don't have to though.
8427 if (!GTK_IS_CONTAINER (widget) &&
8428 !gtk_widget_get_can_focus (widget))
8431 g_signal_emit (widget,
8432 widget_signals[FOCUS],
8434 direction, &return_val);
8440 * gtk_widget_keynav_failed:
8441 * @widget: a #GtkWidget
8442 * @direction: direction of focus movement
8444 * This function should be called whenever keyboard navigation within
8445 * a single widget hits a boundary. The function emits the
8446 * #GtkWidget::keynav-failed signal on the widget and its return
8447 * value should be interpreted in a way similar to the return value of
8448 * gtk_widget_child_focus():
8450 * When %TRUE is returned, stay in the widget, the failed keyboard
8451 * navigation is Ok and/or there is nowhere we can/should move the
8454 * When %FALSE is returned, the caller should continue with keyboard
8455 * navigation outside the widget, e.g. by calling
8456 * gtk_widget_child_focus() on the widget's toplevel.
8458 * The default ::keynav-failed handler returns %TRUE for
8459 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8460 * values of #GtkDirectionType, it looks at the
8461 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8462 * if the setting is %TRUE. This way the entire user interface
8463 * becomes cursor-navigatable on input devices such as mobile phones
8464 * which only have cursor keys but no tab key.
8466 * Whenever the default handler returns %TRUE, it also calls
8467 * gtk_widget_error_bell() to notify the user of the failed keyboard
8470 * A use case for providing an own implementation of ::keynav-failed
8471 * (either by connecting to it or by overriding it) would be a row of
8472 * #GtkEntry widgets where the user should be able to navigate the
8473 * entire row with the cursor keys, as e.g. known from user interfaces
8474 * that require entering license keys.
8476 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8477 * if the emitting widget should try to handle the keyboard
8478 * navigation attempt in its parent container(s).
8483 gtk_widget_keynav_failed (GtkWidget *widget,
8484 GtkDirectionType direction)
8486 gboolean return_val;
8488 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8490 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8491 direction, &return_val);
8497 * gtk_widget_error_bell:
8498 * @widget: a #GtkWidget
8500 * Notifies the user about an input-related error on this widget.
8501 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8502 * gdk_window_beep(), otherwise it does nothing.
8504 * Note that the effect of gdk_window_beep() can be configured in many
8505 * ways, depending on the windowing backend and the desktop environment
8506 * or window manager that is used.
8511 gtk_widget_error_bell (GtkWidget *widget)
8513 GtkWidgetPrivate *priv;
8514 GtkSettings* settings;
8517 g_return_if_fail (GTK_IS_WIDGET (widget));
8519 priv = widget->priv;
8521 settings = gtk_widget_get_settings (widget);
8525 g_object_get (settings,
8526 "gtk-error-bell", &beep,
8529 if (beep && priv->window)
8530 gdk_window_beep (priv->window);
8534 gtk_widget_set_usize_internal (GtkWidget *widget,
8538 GtkWidgetAuxInfo *aux_info;
8539 gboolean changed = FALSE;
8541 g_object_freeze_notify (G_OBJECT (widget));
8543 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8545 if (width > -2 && aux_info->width != width)
8547 g_object_notify (G_OBJECT (widget), "width-request");
8548 aux_info->width = width;
8551 if (height > -2 && aux_info->height != height)
8553 g_object_notify (G_OBJECT (widget), "height-request");
8554 aux_info->height = height;
8558 if (gtk_widget_get_visible (widget) && changed)
8559 gtk_widget_queue_resize (widget);
8561 g_object_thaw_notify (G_OBJECT (widget));
8565 * gtk_widget_set_size_request:
8566 * @widget: a #GtkWidget
8567 * @width: width @widget should request, or -1 to unset
8568 * @height: height @widget should request, or -1 to unset
8570 * Sets the minimum size of a widget; that is, the widget's size
8571 * request will be @width by @height. You can use this function to
8572 * force a widget to be either larger or smaller than it normally
8575 * In most cases, gtk_window_set_default_size() is a better choice for
8576 * toplevel windows than this function; setting the default size will
8577 * still allow users to shrink the window. Setting the size request
8578 * will force them to leave the window at least as large as the size
8579 * request. When dealing with window sizes,
8580 * gtk_window_set_geometry_hints() can be a useful function as well.
8582 * Note the inherent danger of setting any fixed size - themes,
8583 * translations into other languages, different fonts, and user action
8584 * can all change the appropriate size for a given widget. So, it's
8585 * basically impossible to hardcode a size that will always be
8588 * The size request of a widget is the smallest size a widget can
8589 * accept while still functioning well and drawing itself correctly.
8590 * However in some strange cases a widget may be allocated less than
8591 * its requested size, and in many cases a widget may be allocated more
8592 * space than it requested.
8594 * If the size request in a given direction is -1 (unset), then
8595 * the "natural" size request of the widget will be used instead.
8597 * Widgets can't actually be allocated a size less than 1 by 1, but
8598 * you can pass 0,0 to this function to mean "as small as possible."
8600 * The size request set here does not include any margin from the
8601 * #GtkWidget properties margin-left, margin-right, margin-top, and
8602 * margin-bottom, but it does include pretty much all other padding
8603 * or border properties set by any subclass of #GtkWidget.
8606 gtk_widget_set_size_request (GtkWidget *widget,
8610 g_return_if_fail (GTK_IS_WIDGET (widget));
8611 g_return_if_fail (width >= -1);
8612 g_return_if_fail (height >= -1);
8619 gtk_widget_set_usize_internal (widget, width, height);
8624 * gtk_widget_get_size_request:
8625 * @widget: a #GtkWidget
8626 * @width: (out) (allow-none): return location for width, or %NULL
8627 * @height: (out) (allow-none): return location for height, or %NULL
8629 * Gets the size request that was explicitly set for the widget using
8630 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8631 * @height indicates that that dimension has not been set explicitly
8632 * and the natural requisition of the widget will be used intead. See
8633 * gtk_widget_set_size_request(). To get the size a widget will
8634 * actually request, call gtk_size_request_get_preferred_size() instead of
8638 gtk_widget_get_size_request (GtkWidget *widget,
8642 const GtkWidgetAuxInfo *aux_info;
8644 g_return_if_fail (GTK_IS_WIDGET (widget));
8646 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8649 *width = aux_info->width;
8652 *height = aux_info->height;
8656 * gtk_widget_set_events:
8657 * @widget: a #GtkWidget
8658 * @events: event mask
8660 * Sets the event mask (see #GdkEventMask) for a widget. The event
8661 * mask determines which events a widget will receive. Keep in mind
8662 * that different widgets have different default event masks, and by
8663 * changing the event mask you may disrupt a widget's functionality,
8664 * so be careful. This function must be called while a widget is
8665 * unrealized. Consider gtk_widget_add_events() for widgets that are
8666 * already realized, or if you want to preserve the existing event
8667 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8668 * to get events on those widgets, place them inside a #GtkEventBox
8669 * and receive events on the event box.
8672 gtk_widget_set_events (GtkWidget *widget,
8675 g_return_if_fail (GTK_IS_WIDGET (widget));
8676 g_return_if_fail (!gtk_widget_get_realized (widget));
8678 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8679 GINT_TO_POINTER (events));
8680 g_object_notify (G_OBJECT (widget), "events");
8684 * gtk_widget_set_device_events:
8685 * @widget: a #GtkWidget
8686 * @device: a #GdkDevice
8687 * @events: event mask
8689 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8690 * mask determines which events a widget will receive from @device. Keep
8691 * in mind that different widgets have different default event masks, and by
8692 * changing the event mask you may disrupt a widget's functionality,
8693 * so be careful. This function must be called while a widget is
8694 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8695 * already realized, or if you want to preserve the existing event
8696 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8697 * to get events on those widgets, place them inside a #GtkEventBox
8698 * and receive events on the event box.
8703 gtk_widget_set_device_events (GtkWidget *widget,
8705 GdkEventMask events)
8707 GHashTable *device_events;
8709 g_return_if_fail (GTK_IS_WIDGET (widget));
8710 g_return_if_fail (GDK_IS_DEVICE (device));
8711 g_return_if_fail (!gtk_widget_get_realized (widget));
8713 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8715 if (G_UNLIKELY (!device_events))
8717 device_events = g_hash_table_new (NULL, NULL);
8718 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8719 (GDestroyNotify) g_hash_table_unref);
8722 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8726 gtk_widget_add_events_internal_list (GtkWidget *widget,
8733 for (l = window_list; l != NULL; l = l->next)
8735 GdkWindow *window = l->data;
8738 gdk_window_get_user_data (window, &user_data);
8739 if (user_data == widget)
8744 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8746 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8748 children = gdk_window_get_children (window);
8749 gtk_widget_add_events_internal_list (widget, device, events, children);
8750 g_list_free (children);
8756 gtk_widget_add_events_internal (GtkWidget *widget,
8760 GtkWidgetPrivate *priv = widget->priv;
8763 if (!gtk_widget_get_has_window (widget))
8764 window_list = gdk_window_get_children (priv->window);
8766 window_list = g_list_prepend (NULL, priv->window);
8768 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8770 g_list_free (window_list);
8774 * gtk_widget_add_events:
8775 * @widget: a #GtkWidget
8776 * @events: an event mask, see #GdkEventMask
8778 * Adds the events in the bitfield @events to the event mask for
8779 * @widget. See gtk_widget_set_events() for details.
8782 gtk_widget_add_events (GtkWidget *widget,
8787 g_return_if_fail (GTK_IS_WIDGET (widget));
8789 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8790 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8791 GINT_TO_POINTER (old_events | events));
8793 if (gtk_widget_get_realized (widget))
8794 gtk_widget_add_events_internal (widget, NULL, events);
8796 g_object_notify (G_OBJECT (widget), "events");
8800 * gtk_widget_add_device_events:
8801 * @widget: a #GtkWidget
8802 * @device: a #GdkDevice
8803 * @events: an event mask, see #GdkEventMask
8805 * Adds the device events in the bitfield @events to the event mask for
8806 * @widget. See gtk_widget_set_device_events() for details.
8811 gtk_widget_add_device_events (GtkWidget *widget,
8813 GdkEventMask events)
8815 GdkEventMask old_events;
8816 GHashTable *device_events;
8818 g_return_if_fail (GTK_IS_WIDGET (widget));
8819 g_return_if_fail (GDK_IS_DEVICE (device));
8821 old_events = gtk_widget_get_device_events (widget, device);
8823 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8825 if (G_UNLIKELY (!device_events))
8827 device_events = g_hash_table_new (NULL, NULL);
8828 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8829 (GDestroyNotify) g_hash_table_unref);
8832 g_hash_table_insert (device_events, device,
8833 GUINT_TO_POINTER (old_events | events));
8835 if (gtk_widget_get_realized (widget))
8836 gtk_widget_add_events_internal (widget, device, events);
8838 g_object_notify (G_OBJECT (widget), "events");
8842 * gtk_widget_set_extension_events:
8843 * @widget: a #GtkWidget
8844 * @mode: bitfield of extension events to receive
8846 * Sets the extension events mask to @mode. See #GdkExtensionMode
8847 * and gdk_input_set_extension_events().
8850 gtk_widget_set_extension_events (GtkWidget *widget,
8851 GdkExtensionMode mode)
8853 g_return_if_fail (GTK_IS_WIDGET (widget));
8855 if (gtk_widget_get_realized (widget))
8856 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8858 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8859 GINT_TO_POINTER (mode));
8860 g_object_notify (G_OBJECT (widget), "extension-events");
8864 * gtk_widget_get_toplevel:
8865 * @widget: a #GtkWidget
8867 * This function returns the topmost widget in the container hierarchy
8868 * @widget is a part of. If @widget has no parent widgets, it will be
8869 * returned as the topmost widget. No reference will be added to the
8870 * returned widget; it should not be unreferenced.
8872 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8873 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8875 * %NULL if @widget wasn't inside a toplevel window, and if the
8876 * window was inside a #GtkWindow-derived widget which was in turn
8877 * inside the toplevel #GtkWindow. While the second case may
8878 * seem unlikely, it actually happens when a #GtkPlug is embedded
8879 * inside a #GtkSocket within the same application.
8881 * To reliably find the toplevel #GtkWindow, use
8882 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8883 * is set on the result.
8885 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8886 * if (gtk_widget_is_toplevel (toplevel))
8888 * /* Perform action on toplevel. */
8892 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8893 * if there's no ancestor.
8896 gtk_widget_get_toplevel (GtkWidget *widget)
8898 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8900 while (widget->priv->parent)
8901 widget = widget->priv->parent;
8907 * gtk_widget_get_ancestor:
8908 * @widget: a #GtkWidget
8909 * @widget_type: ancestor type
8911 * Gets the first ancestor of @widget with type @widget_type. For example,
8912 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8913 * the first #GtkBox that's an ancestor of @widget. No reference will be
8914 * added to the returned widget; it should not be unreferenced. See note
8915 * about checking for a toplevel #GtkWindow in the docs for
8916 * gtk_widget_get_toplevel().
8918 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8919 * considers @widget to be an ancestor of itself.
8921 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8924 gtk_widget_get_ancestor (GtkWidget *widget,
8927 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8929 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8930 widget = widget->priv->parent;
8932 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8939 * gtk_widget_get_visual:
8940 * @widget: a #GtkWidget
8942 * Gets the visual that will be used to render @widget.
8944 * Return value: (transfer none): the visual for @widget
8947 gtk_widget_get_visual (GtkWidget *widget)
8951 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8953 for (w = widget; w != NULL; w = w->priv->parent)
8955 if (gtk_widget_get_has_window (w) &&
8957 return gdk_window_get_visual (w->priv->window);
8959 if (GTK_IS_WINDOW (w))
8960 return _gtk_window_get_visual (GTK_WINDOW (w));
8963 return gdk_screen_get_system_visual (gdk_screen_get_default ());
8967 * gtk_widget_get_settings:
8968 * @widget: a #GtkWidget
8970 * Gets the settings object holding the settings (global property
8971 * settings, RC file information, etc) used for this widget.
8973 * Note that this function can only be called when the #GtkWidget
8974 * is attached to a toplevel, since the settings object is specific
8975 * to a particular #GdkScreen.
8977 * Return value: (transfer none): the relevant #GtkSettings object
8980 gtk_widget_get_settings (GtkWidget *widget)
8982 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8984 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8988 * gtk_widget_get_events:
8989 * @widget: a #GtkWidget
8991 * Returns the event mask for the widget (a bitfield containing flags
8992 * from the #GdkEventMask enumeration). These are the events that the widget
8995 * Return value: event mask for @widget
8998 gtk_widget_get_events (GtkWidget *widget)
9000 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9002 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9006 * gtk_widget_get_device_events:
9007 * @widget: a #GtkWidget
9008 * @device: a #GdkDevice
9010 * Returns the events mask for the widget corresponding to an specific device. These
9011 * are the events that the widget will receive when @device operates on it.
9013 * Returns: device event mask for @widget
9018 gtk_widget_get_device_events (GtkWidget *widget,
9021 GHashTable *device_events;
9023 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9024 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9026 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9031 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9035 * gtk_widget_get_extension_events:
9036 * @widget: a #GtkWidget
9038 * Retrieves the extension events the widget will receive; see
9039 * gdk_input_set_extension_events().
9041 * Return value: extension events for @widget
9044 gtk_widget_get_extension_events (GtkWidget *widget)
9046 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9048 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9052 * gtk_widget_get_pointer:
9053 * @widget: a #GtkWidget
9054 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9055 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9057 * Obtains the location of the mouse pointer in widget coordinates.
9058 * Widget coordinates are a bit odd; for historical reasons, they are
9059 * defined as @widget->window coordinates for widgets that are not
9060 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9061 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9064 gtk_widget_get_pointer (GtkWidget *widget,
9068 GtkWidgetPrivate *priv;
9070 g_return_if_fail (GTK_IS_WIDGET (widget));
9072 priv = widget->priv;
9079 if (gtk_widget_get_realized (widget))
9081 gdk_window_get_pointer (priv->window, x, y, NULL);
9083 if (!gtk_widget_get_has_window (widget))
9086 *x -= priv->allocation.x;
9088 *y -= priv->allocation.y;
9094 * gtk_widget_is_ancestor:
9095 * @widget: a #GtkWidget
9096 * @ancestor: another #GtkWidget
9098 * Determines whether @widget is somewhere inside @ancestor, possibly with
9099 * intermediate containers.
9101 * Return value: %TRUE if @ancestor contains @widget as a child,
9102 * grandchild, great grandchild, etc.
9105 gtk_widget_is_ancestor (GtkWidget *widget,
9106 GtkWidget *ancestor)
9108 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9109 g_return_val_if_fail (ancestor != NULL, FALSE);
9113 if (widget->priv->parent == ancestor)
9115 widget = widget->priv->parent;
9121 static GQuark quark_composite_name = 0;
9124 * gtk_widget_set_composite_name:
9125 * @widget: a #GtkWidget.
9126 * @name: the name to set
9128 * Sets a widgets composite name. The widget must be
9129 * a composite child of its parent; see gtk_widget_push_composite_child().
9132 gtk_widget_set_composite_name (GtkWidget *widget,
9135 g_return_if_fail (GTK_IS_WIDGET (widget));
9136 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
9137 g_return_if_fail (name != NULL);
9139 if (!quark_composite_name)
9140 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9142 g_object_set_qdata_full (G_OBJECT (widget),
9143 quark_composite_name,
9149 * gtk_widget_get_composite_name:
9150 * @widget: a #GtkWidget
9152 * Obtains the composite name of a widget.
9154 * Returns: the composite name of @widget, or %NULL if @widget is not
9155 * a composite child. The string should be freed when it is no
9159 gtk_widget_get_composite_name (GtkWidget *widget)
9161 GtkWidgetPrivate *priv;
9163 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9165 priv = widget->priv;
9167 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
9168 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9175 * gtk_widget_push_composite_child:
9177 * Makes all newly-created widgets as composite children until
9178 * the corresponding gtk_widget_pop_composite_child() call.
9180 * A composite child is a child that's an implementation detail of the
9181 * container it's inside and should not be visible to people using the
9182 * container. Composite children aren't treated differently by GTK (but
9183 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9184 * builders might want to treat them in a different way.
9186 * Here is a simple example:
9188 * gtk_widget_push_composite_child ();
9189 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9190 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9191 * gtk_widget_pop_composite_child ();
9192 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9193 * GTK_WIDGET (scrolled_window));
9194 * g_object_ref (scrolled_window->hscrollbar);
9198 gtk_widget_push_composite_child (void)
9200 composite_child_stack++;
9204 * gtk_widget_pop_composite_child:
9206 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9209 gtk_widget_pop_composite_child (void)
9211 if (composite_child_stack)
9212 composite_child_stack--;
9216 gtk_widget_emit_direction_changed (GtkWidget *widget,
9217 GtkTextDirection old_dir)
9219 gtk_widget_update_pango_context (widget);
9221 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9225 * gtk_widget_set_direction:
9226 * @widget: a #GtkWidget
9227 * @dir: the new direction
9229 * Sets the reading direction on a particular widget. This direction
9230 * controls the primary direction for widgets containing text,
9231 * and also the direction in which the children of a container are
9232 * packed. The ability to set the direction is present in order
9233 * so that correct localization into languages with right-to-left
9234 * reading directions can be done. Generally, applications will
9235 * let the default reading direction present, except for containers
9236 * where the containers are arranged in an order that is explicitely
9237 * visual rather than logical (such as buttons for text justification).
9239 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9240 * set by gtk_widget_set_default_direction() will be used.
9243 gtk_widget_set_direction (GtkWidget *widget,
9244 GtkTextDirection dir)
9246 GtkTextDirection old_dir;
9248 g_return_if_fail (GTK_IS_WIDGET (widget));
9249 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9251 old_dir = gtk_widget_get_direction (widget);
9253 if (dir == GTK_TEXT_DIR_NONE)
9254 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9257 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9258 if (dir == GTK_TEXT_DIR_LTR)
9259 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9261 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9264 if (old_dir != gtk_widget_get_direction (widget))
9265 gtk_widget_emit_direction_changed (widget, old_dir);
9269 * gtk_widget_get_direction:
9270 * @widget: a #GtkWidget
9272 * Gets the reading direction for a particular widget. See
9273 * gtk_widget_set_direction().
9275 * Return value: the reading direction for the widget.
9278 gtk_widget_get_direction (GtkWidget *widget)
9280 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9282 if (GTK_WIDGET_DIRECTION_SET (widget))
9283 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9285 return gtk_default_direction;
9289 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9291 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9293 g_object_ref (widget);
9295 if (!GTK_WIDGET_DIRECTION_SET (widget))
9296 gtk_widget_emit_direction_changed (widget, old_dir);
9298 if (GTK_IS_CONTAINER (widget))
9299 gtk_container_forall (GTK_CONTAINER (widget),
9300 gtk_widget_set_default_direction_recurse,
9303 g_object_unref (widget);
9307 * gtk_widget_set_default_direction:
9308 * @dir: the new default direction. This cannot be
9309 * %GTK_TEXT_DIR_NONE.
9311 * Sets the default reading direction for widgets where the
9312 * direction has not been explicitly set by gtk_widget_set_direction().
9315 gtk_widget_set_default_direction (GtkTextDirection dir)
9317 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9319 if (dir != gtk_default_direction)
9321 GList *toplevels, *tmp_list;
9322 GtkTextDirection old_dir = gtk_default_direction;
9324 gtk_default_direction = dir;
9326 tmp_list = toplevels = gtk_window_list_toplevels ();
9327 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9331 gtk_widget_set_default_direction_recurse (tmp_list->data,
9332 GUINT_TO_POINTER (old_dir));
9333 g_object_unref (tmp_list->data);
9334 tmp_list = tmp_list->next;
9337 g_list_free (toplevels);
9342 * gtk_widget_get_default_direction:
9344 * Obtains the current default reading direction. See
9345 * gtk_widget_set_default_direction().
9347 * Return value: the current default direction.
9350 gtk_widget_get_default_direction (void)
9352 return gtk_default_direction;
9356 gtk_widget_dispose (GObject *object)
9358 GtkWidget *widget = GTK_WIDGET (object);
9359 GtkWidgetPrivate *priv = widget->priv;
9362 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9363 else if (gtk_widget_get_visible (widget))
9364 gtk_widget_hide (widget);
9366 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9367 if (gtk_widget_get_realized (widget))
9368 gtk_widget_unrealize (widget);
9370 if (!priv->in_destruction)
9372 priv->in_destruction = TRUE;
9373 g_signal_emit (object, widget_signals[DESTROY], 0);
9374 priv->in_destruction = FALSE;
9377 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9381 gtk_widget_real_destroy (GtkObject *object)
9383 /* gtk_object_destroy() will already hold a refcount on object */
9384 GtkWidget *widget = GTK_WIDGET (object);
9385 GtkWidgetPrivate *priv = widget->priv;
9387 /* wipe accelerator closures (keep order) */
9388 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9389 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9391 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9392 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9394 gtk_grab_remove (widget);
9396 g_object_unref (priv->style);
9397 priv->style = gtk_widget_get_default_style ();
9398 g_object_ref (priv->style);
9402 gtk_widget_finalize (GObject *object)
9404 GtkWidget *widget = GTK_WIDGET (object);
9405 GtkWidgetPrivate *priv = widget->priv;
9406 GtkWidgetAuxInfo *aux_info;
9407 GtkAccessible *accessible;
9409 gtk_grab_remove (widget);
9411 g_object_unref (priv->style);
9414 g_free (priv->name);
9416 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9418 gtk_widget_aux_info_destroy (aux_info);
9420 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9422 g_object_unref (accessible);
9424 if (g_object_is_floating (object))
9425 g_warning ("A floating object was finalized. This means that someone\n"
9426 "called g_object_unref() on an object that had only a floating\n"
9427 "reference; the initial floating reference is not owned by anyone\n"
9428 "and must be removed with g_object_ref_sink().");
9430 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9433 /*****************************************
9434 * gtk_widget_real_map:
9439 *****************************************/
9442 gtk_widget_real_map (GtkWidget *widget)
9444 GtkWidgetPrivate *priv = widget->priv;
9446 g_assert (gtk_widget_get_realized (widget));
9448 if (!gtk_widget_get_mapped (widget))
9450 gtk_widget_set_mapped (widget, TRUE);
9452 if (gtk_widget_get_has_window (widget))
9453 gdk_window_show (priv->window);
9457 /*****************************************
9458 * gtk_widget_real_unmap:
9463 *****************************************/
9466 gtk_widget_real_unmap (GtkWidget *widget)
9468 GtkWidgetPrivate *priv = widget->priv;
9470 if (gtk_widget_get_mapped (widget))
9472 gtk_widget_set_mapped (widget, FALSE);
9474 if (gtk_widget_get_has_window (widget))
9475 gdk_window_hide (priv->window);
9479 /*****************************************
9480 * gtk_widget_real_realize:
9485 *****************************************/
9488 gtk_widget_real_realize (GtkWidget *widget)
9490 GtkWidgetPrivate *priv = widget->priv;
9492 g_assert (!gtk_widget_get_has_window (widget));
9494 gtk_widget_set_realized (widget, TRUE);
9497 priv->window = gtk_widget_get_parent_window (widget);
9498 g_object_ref (priv->window);
9500 priv->style = gtk_style_attach (priv->style, priv->window);
9503 /*****************************************
9504 * gtk_widget_real_unrealize:
9509 *****************************************/
9512 gtk_widget_real_unrealize (GtkWidget *widget)
9514 GtkWidgetPrivate *priv = widget->priv;
9516 if (gtk_widget_get_mapped (widget))
9517 gtk_widget_real_unmap (widget);
9519 gtk_widget_set_mapped (widget, FALSE);
9521 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9524 /* We must do unrealize child widget BEFORE container widget.
9525 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9526 * So, unrealizing container widget bofore its children causes the problem
9527 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9530 if (GTK_IS_CONTAINER (widget))
9531 gtk_container_forall (GTK_CONTAINER (widget),
9532 (GtkCallback) gtk_widget_unrealize,
9535 gtk_style_detach (priv->style);
9536 if (gtk_widget_get_has_window (widget))
9538 gdk_window_set_user_data (priv->window, NULL);
9539 gdk_window_destroy (priv->window);
9540 priv->window = NULL;
9544 g_object_unref (priv->window);
9545 priv->window = NULL;
9548 gtk_selection_remove_all (widget);
9550 gtk_widget_set_realized (widget, FALSE);
9554 gtk_widget_real_size_request (GtkWidget *widget,
9555 GtkRequisition *requisition)
9557 requisition->width = 0;
9558 requisition->height = 0;
9562 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9563 GtkOrientation orientation,
9568 const GtkWidgetAuxInfo *aux_info;
9570 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9572 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9573 aux_info->width > 0)
9575 *minimum_size = MAX (*minimum_size, aux_info->width);
9577 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9578 aux_info->height > 0)
9580 *minimum_size = MAX (*minimum_size, aux_info->height);
9583 /* Fix it if set_size_request made natural size smaller than min size.
9584 * This would also silently fix broken widgets, but we warn about them
9585 * in gtksizerequest.c when calling their size request vfuncs.
9587 *natural_size = MAX (*natural_size, *minimum_size);
9589 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9591 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9592 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9596 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9597 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9602 * _gtk_widget_peek_request_cache:
9604 * Returns the address of the widget's request cache (strictly for
9605 * internal use in gtksizerequest.c)
9607 * Return value: the address of @widget's size request cache.
9610 _gtk_widget_peek_request_cache (GtkWidget *widget)
9612 /* Don't bother slowing things down with the return_if_fail guards here */
9613 return &widget->priv->requests;
9617 * _gtk_widget_set_device_window:
9618 * @widget: a #GtkWidget.
9619 * @device: a #GdkDevice.
9620 * @window: the new device window.
9622 * Sets pointer window for @widget and @device. Does not ref @window.
9623 * Actually stores it on the #GdkScreen, but you don't need to know that.
9626 _gtk_widget_set_device_window (GtkWidget *widget,
9630 GtkWidgetPrivate *priv;
9632 GHashTable *device_window;
9634 g_return_if_fail (GTK_IS_WIDGET (widget));
9635 g_return_if_fail (GDK_IS_DEVICE (device));
9636 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9638 priv = widget->priv;
9640 if (!gtk_widget_get_realized (widget))
9643 screen = gdk_window_get_screen (priv->window);
9644 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9646 if (G_UNLIKELY (!device_window))
9648 device_window = g_hash_table_new (NULL, NULL);
9649 g_object_set_qdata_full (G_OBJECT (screen),
9650 quark_pointer_window,
9652 (GDestroyNotify) g_hash_table_destroy);
9656 g_hash_table_insert (device_window, device, window);
9658 g_hash_table_remove (device_window, device);
9662 * _gtk_widget_get_device_window:
9663 * @widget: a #GtkWidget.
9664 * @device: a #GdkDevice.
9666 * Return value: the device window set on the #GdkScreen @widget is attached
9670 _gtk_widget_get_device_window (GtkWidget *widget,
9673 GtkWidgetPrivate *priv;
9675 GHashTable *device_window;
9679 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9680 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9682 priv = widget->priv;
9684 if (!gtk_widget_get_realized (widget))
9687 screen = gdk_window_get_screen (priv->window);
9688 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9690 if (G_UNLIKELY (!device_window))
9693 window = g_hash_table_lookup (device_window, device);
9698 gdk_window_get_user_data (window, (gpointer *) &w);
9707 * _gtk_widget_list_devices:
9708 * @widget: a #GtkWidget.
9710 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9711 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9715 _gtk_widget_list_devices (GtkWidget *widget)
9717 GtkWidgetPrivate *priv;
9719 GHashTableIter iter;
9720 GHashTable *device_window;
9721 GList *devices = NULL;
9722 gpointer key, value;
9724 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9726 priv = widget->priv;
9728 if (!gtk_widget_get_realized (widget))
9731 screen = gdk_window_get_screen (priv->window);
9732 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9734 if (G_UNLIKELY (!device_window))
9737 g_hash_table_iter_init (&iter, device_window);
9739 while (g_hash_table_iter_next (&iter, &key, &value))
9741 GdkDevice *device = key;
9742 GdkWindow *window = value;
9747 gdk_window_get_user_data (window, (gpointer *) &w);
9750 devices = g_list_prepend (devices, device);
9758 synth_crossing (GtkWidget *widget,
9762 GdkCrossingMode mode,
9763 GdkNotifyType detail)
9767 event = gdk_event_new (type);
9769 event->crossing.window = g_object_ref (window);
9770 event->crossing.send_event = TRUE;
9771 event->crossing.subwindow = g_object_ref (window);
9772 event->crossing.time = GDK_CURRENT_TIME;
9773 event->crossing.x = event->crossing.y = 0;
9774 event->crossing.x_root = event->crossing.y_root = 0;
9775 event->crossing.mode = mode;
9776 event->crossing.detail = detail;
9777 event->crossing.focus = FALSE;
9778 event->crossing.state = 0;
9779 gdk_event_set_device (event, device);
9782 widget = gtk_get_event_widget (event);
9785 gtk_widget_event_internal (widget, event);
9787 gdk_event_free (event);
9791 * _gtk_widget_synthesize_crossing:
9792 * @from: the #GtkWidget the virtual pointer is leaving.
9793 * @to: the #GtkWidget the virtual pointer is moving to.
9794 * @mode: the #GdkCrossingMode to place on the synthesized events.
9796 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9798 * The real pointer window is the window that most recently received an enter notify
9799 * event. Windows that don't select for crossing events can't become the real
9800 * poiner window. The real pointer widget that owns the real pointer window. The
9801 * effective pointer window is the same as the real pointer window unless the real
9802 * pointer widget is either insensitive or there is a grab on a widget that is not
9803 * an ancestor of the real pointer widget (in which case the effective pointer
9804 * window should be the root window).
9806 * When the effective pointer window is the same as the real poiner window, we
9807 * receive crossing events from the windowing system. When the effective pointer
9808 * window changes to become different from the real pointer window we synthesize
9809 * crossing events, attempting to follow X protocol rules:
9811 * When the root window becomes the effective pointer window:
9812 * - leave notify on real pointer window, detail Ancestor
9813 * - leave notify on all of its ancestors, detail Virtual
9814 * - enter notify on root window, detail Inferior
9816 * When the root window ceases to be the effective pointer window:
9817 * - leave notify on root window, detail Inferior
9818 * - enter notify on all ancestors of real pointer window, detail Virtual
9819 * - enter notify on real pointer window, detail Ancestor
9822 _gtk_widget_synthesize_crossing (GtkWidget *from,
9825 GdkCrossingMode mode)
9827 GdkWindow *from_window = NULL, *to_window = NULL;
9829 g_return_if_fail (from != NULL || to != NULL);
9833 from_window = _gtk_widget_get_device_window (from, device);
9836 from_window = from->priv->window;
9841 to_window = _gtk_widget_get_device_window (to, device);
9844 to_window = to->priv->window;
9847 if (from_window == NULL && to_window == NULL)
9849 else if (from_window != NULL && to_window == NULL)
9851 GList *from_ancestors = NULL, *list;
9852 GdkWindow *from_ancestor = from_window;
9854 while (from_ancestor != NULL)
9856 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9857 if (from_ancestor == NULL)
9859 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9862 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9863 device, mode, GDK_NOTIFY_ANCESTOR);
9864 for (list = g_list_last (from_ancestors); list; list = list->prev)
9866 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9867 device, mode, GDK_NOTIFY_VIRTUAL);
9870 /* XXX: enter/inferior on root window? */
9872 g_list_free (from_ancestors);
9874 else if (from_window == NULL && to_window != NULL)
9876 GList *to_ancestors = NULL, *list;
9877 GdkWindow *to_ancestor = to_window;
9879 while (to_ancestor != NULL)
9881 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9882 if (to_ancestor == NULL)
9884 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9887 /* XXX: leave/inferior on root window? */
9889 for (list = to_ancestors; list; list = list->next)
9891 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9892 device, mode, GDK_NOTIFY_VIRTUAL);
9894 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9895 device, mode, GDK_NOTIFY_ANCESTOR);
9897 g_list_free (to_ancestors);
9899 else if (from_window == to_window)
9903 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9904 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9906 while (from_ancestor != NULL || to_ancestor != NULL)
9908 if (from_ancestor != NULL)
9910 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9911 if (from_ancestor == to_window)
9914 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9916 if (to_ancestor != NULL)
9918 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9919 if (to_ancestor == from_window)
9922 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9925 if (to_ancestor == from_window)
9927 if (mode != GDK_CROSSING_GTK_UNGRAB)
9928 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9929 device, mode, GDK_NOTIFY_INFERIOR);
9930 for (list = to_ancestors; list; list = list->next)
9931 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9932 device, mode, GDK_NOTIFY_VIRTUAL);
9933 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9934 device, mode, GDK_NOTIFY_ANCESTOR);
9936 else if (from_ancestor == to_window)
9938 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9939 device, mode, GDK_NOTIFY_ANCESTOR);
9940 for (list = g_list_last (from_ancestors); list; list = list->prev)
9942 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9943 device, mode, GDK_NOTIFY_VIRTUAL);
9945 if (mode != GDK_CROSSING_GTK_GRAB)
9946 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9947 device, mode, GDK_NOTIFY_INFERIOR);
9951 while (from_ancestors != NULL && to_ancestors != NULL
9952 && from_ancestors->data == to_ancestors->data)
9954 from_ancestors = g_list_delete_link (from_ancestors,
9956 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9959 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9960 device, mode, GDK_NOTIFY_NONLINEAR);
9962 for (list = g_list_last (from_ancestors); list; list = list->prev)
9964 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9965 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9967 for (list = to_ancestors; list; list = list->next)
9969 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9970 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9972 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9973 device, mode, GDK_NOTIFY_NONLINEAR);
9975 g_list_free (from_ancestors);
9976 g_list_free (to_ancestors);
9981 gtk_widget_propagate_state (GtkWidget *widget,
9984 GtkWidgetPrivate *priv = widget->priv;
9985 guint8 old_state = gtk_widget_get_state (widget);
9986 guint8 old_saved_state = priv->saved_state;
9988 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9989 * parent_sensitive==TRUE on a sensitive widget
9993 if (data->parent_sensitive)
9994 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9996 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9998 if (gtk_widget_is_sensitive (widget))
10000 if (data->state_restoration)
10001 priv->state = priv->saved_state;
10003 priv->state = data->state;
10007 if (!data->state_restoration)
10009 if (data->state != GTK_STATE_INSENSITIVE)
10010 priv->saved_state = data->state;
10012 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10013 priv->saved_state = gtk_widget_get_state (widget);
10014 priv->state = GTK_STATE_INSENSITIVE;
10017 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10021 window = gtk_widget_get_toplevel (widget);
10022 if (window && gtk_widget_is_toplevel (window))
10023 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10026 if (old_state != gtk_widget_get_state (widget) ||
10027 old_saved_state != priv->saved_state)
10029 g_object_ref (widget);
10031 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10032 gtk_grab_remove (widget);
10034 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10036 if (!GTK_WIDGET_SHADOWED (widget))
10038 GList *event_windows = NULL;
10039 GList *devices, *d;
10041 devices = _gtk_widget_list_devices (widget);
10043 for (d = devices; d; d = d->next)
10049 window = _gtk_widget_get_device_window (widget, device);
10051 /* Do not propagate more than once to the
10052 * same window if non-multidevice aware.
10054 if (!gdk_window_get_support_multidevice (window) &&
10055 g_list_find (event_windows, window))
10058 if (!gtk_widget_is_sensitive (widget))
10059 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10060 GDK_CROSSING_STATE_CHANGED);
10061 else if (old_state == GTK_STATE_INSENSITIVE)
10062 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10063 GDK_CROSSING_STATE_CHANGED);
10065 event_windows = g_list_prepend (event_windows, window);
10068 g_list_free (event_windows);
10069 g_list_free (devices);
10072 if (GTK_IS_CONTAINER (widget))
10074 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10075 if (data->use_forall)
10076 gtk_container_forall (GTK_CONTAINER (widget),
10077 (GtkCallback) gtk_widget_propagate_state,
10080 gtk_container_foreach (GTK_CONTAINER (widget),
10081 (GtkCallback) gtk_widget_propagate_state,
10084 g_object_unref (widget);
10088 static const GtkWidgetAuxInfo default_aux_info = {
10096 * _gtk_widget_get_aux_info:
10097 * @widget: a #GtkWidget
10098 * @create: if %TRUE, create the structure if it doesn't exist
10100 * Get the #GtkWidgetAuxInfo structure for the widget.
10102 * Return value: the #GtkAuxInfo structure for the widget, or
10103 * %NULL if @create is %FALSE and one doesn't already exist.
10106 _gtk_widget_get_aux_info (GtkWidget *widget,
10109 GtkWidgetAuxInfo *aux_info;
10111 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10112 if (!aux_info && create)
10114 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10116 *aux_info = default_aux_info;
10118 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10124 static const GtkWidgetAuxInfo*
10125 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10127 GtkWidgetAuxInfo *aux_info;
10129 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10130 if (aux_info == NULL)
10132 return &default_aux_info;
10140 /*****************************************
10141 * gtk_widget_aux_info_destroy:
10146 *****************************************/
10149 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10151 g_slice_free (GtkWidgetAuxInfo, aux_info);
10155 * gtk_widget_shape_combine_region:
10156 * @widget: a #GtkWidget
10157 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10159 * Sets a shape for this widget's GDK window. This allows for
10160 * transparent windows etc., see gdk_window_shape_combine_region()
10161 * for more information.
10166 gtk_widget_shape_combine_region (GtkWidget *widget,
10167 cairo_region_t *region)
10169 GtkWidgetPrivate *priv;
10171 g_return_if_fail (GTK_IS_WIDGET (widget));
10172 /* set_shape doesn't work on widgets without gdk window */
10173 g_return_if_fail (gtk_widget_get_has_window (widget));
10175 priv = widget->priv;
10177 if (region == NULL)
10179 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10182 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10184 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10188 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10190 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10191 cairo_region_copy (region),
10192 (GDestroyNotify) cairo_region_destroy);
10194 /* set shape if widget has a gdk window already.
10195 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10198 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10203 * gtk_widget_input_shape_combine_region:
10204 * @widget: a #GtkWidget
10205 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10207 * Sets an input shape for this widget's GDK window. This allows for
10208 * windows which react to mouse click in a nonrectangular region, see
10209 * gdk_window_input_shape_combine_region() for more information.
10214 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10215 cairo_region_t *region)
10217 GtkWidgetPrivate *priv;
10219 g_return_if_fail (GTK_IS_WIDGET (widget));
10220 /* set_shape doesn't work on widgets without gdk window */
10221 g_return_if_fail (gtk_widget_get_has_window (widget));
10223 priv = widget->priv;
10225 if (region == NULL)
10228 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10230 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10234 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10235 cairo_region_copy (region),
10236 (GDestroyNotify) cairo_region_destroy);
10238 /* set shape if widget has a gdk window already.
10239 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10242 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10248 gtk_reset_shapes_recurse (GtkWidget *widget,
10254 gdk_window_get_user_data (window, &data);
10255 if (data != widget)
10258 gdk_window_shape_combine_region (window, NULL, 0, 0);
10259 for (list = gdk_window_peek_children (window); list; list = list->next)
10260 gtk_reset_shapes_recurse (widget, list->data);
10264 * gtk_widget_reset_shapes:
10265 * @widget: a #GtkWidget
10267 * Recursively resets the shape on this widget and its descendants.
10270 gtk_widget_reset_shapes (GtkWidget *widget)
10272 GtkWidgetPrivate *priv;
10274 g_return_if_fail (GTK_IS_WIDGET (widget));
10275 g_return_if_fail (gtk_widget_get_realized (widget));
10277 priv = widget->priv;
10279 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10280 gtk_reset_shapes_recurse (widget, priv->window);
10283 /* style properties
10287 * gtk_widget_class_install_style_property_parser:
10288 * @klass: a #GtkWidgetClass
10289 * @pspec: the #GParamSpec for the style property
10290 * @parser: the parser for the style property
10292 * Installs a style property on a widget class.
10295 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10297 GtkRcPropertyParser parser)
10299 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10300 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10301 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10302 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10304 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10306 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10307 G_OBJECT_CLASS_NAME (klass),
10312 g_param_spec_ref_sink (pspec);
10313 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10314 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10318 * gtk_widget_class_install_style_property:
10319 * @klass: a #GtkWidgetClass
10320 * @pspec: the #GParamSpec for the property
10322 * Installs a style property on a widget class. The parser for the
10323 * style property is determined by the value type of @pspec.
10326 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10329 GtkRcPropertyParser parser;
10331 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10332 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10334 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10336 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10340 * gtk_widget_class_find_style_property:
10341 * @klass: a #GtkWidgetClass
10342 * @property_name: the name of the style property to find
10343 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10344 * style property with that name.
10346 * Finds a style property of a widget class by name.
10351 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10352 const gchar *property_name)
10354 g_return_val_if_fail (property_name != NULL, NULL);
10356 return g_param_spec_pool_lookup (style_property_spec_pool,
10358 G_OBJECT_CLASS_TYPE (klass),
10363 * gtk_widget_class_list_style_properties:
10364 * @klass: a #GtkWidgetClass
10365 * @n_properties: location to return the number of style properties found
10366 * @returns: an newly allocated array of #GParamSpec*. The array must
10367 * be freed with g_free().
10369 * Returns all style properties of a widget class.
10374 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10375 guint *n_properties)
10377 GParamSpec **pspecs;
10380 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10381 G_OBJECT_CLASS_TYPE (klass),
10390 * gtk_widget_style_get_property:
10391 * @widget: a #GtkWidget
10392 * @property_name: the name of a style property
10393 * @value: location to return the property value
10395 * Gets the value of a style property of @widget.
10398 gtk_widget_style_get_property (GtkWidget *widget,
10399 const gchar *property_name,
10402 GtkWidgetPrivate *priv;
10405 g_return_if_fail (GTK_IS_WIDGET (widget));
10406 g_return_if_fail (property_name != NULL);
10407 g_return_if_fail (G_IS_VALUE (value));
10409 priv = widget->priv;
10411 g_object_ref (widget);
10412 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10414 G_OBJECT_TYPE (widget),
10417 g_warning ("%s: widget class `%s' has no property named `%s'",
10419 G_OBJECT_TYPE_NAME (widget),
10423 const GValue *peek_value;
10425 peek_value = _gtk_style_peek_property_value (priv->style,
10426 G_OBJECT_TYPE (widget),
10428 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10430 /* auto-conversion of the caller's value type
10432 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10433 g_value_copy (peek_value, value);
10434 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10435 g_value_transform (peek_value, value);
10437 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10439 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10440 G_VALUE_TYPE_NAME (value));
10442 g_object_unref (widget);
10446 * gtk_widget_style_get_valist:
10447 * @widget: a #GtkWidget
10448 * @first_property_name: the name of the first property to get
10449 * @var_args: a <type>va_list</type> of pairs of property names and
10450 * locations to return the property values, starting with the location
10451 * for @first_property_name.
10453 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10457 gtk_widget_style_get_valist (GtkWidget *widget,
10458 const gchar *first_property_name,
10461 GtkWidgetPrivate *priv;
10464 g_return_if_fail (GTK_IS_WIDGET (widget));
10466 priv = widget->priv;
10468 g_object_ref (widget);
10470 name = first_property_name;
10473 const GValue *peek_value;
10477 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10479 G_OBJECT_TYPE (widget),
10483 g_warning ("%s: widget class `%s' has no property named `%s'",
10485 G_OBJECT_TYPE_NAME (widget),
10489 /* style pspecs are always readable so we can spare that check here */
10491 peek_value = _gtk_style_peek_property_value (priv->style,
10492 G_OBJECT_TYPE (widget),
10494 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10495 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10498 g_warning ("%s: %s", G_STRLOC, error);
10503 name = va_arg (var_args, gchar*);
10506 g_object_unref (widget);
10510 * gtk_widget_style_get:
10511 * @widget: a #GtkWidget
10512 * @first_property_name: the name of the first property to get
10513 * @Varargs: pairs of property names and locations to
10514 * return the property values, starting with the location for
10515 * @first_property_name, terminated by %NULL.
10517 * Gets the values of a multiple style properties of @widget.
10520 gtk_widget_style_get (GtkWidget *widget,
10521 const gchar *first_property_name,
10526 g_return_if_fail (GTK_IS_WIDGET (widget));
10528 va_start (var_args, first_property_name);
10529 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10535 * @widget: a #GtkWidget
10536 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10537 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10538 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10540 * Obtains the full path to @widget. The path is simply the name of a
10541 * widget and all its parents in the container hierarchy, separated by
10542 * periods. The name of a widget comes from
10543 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10544 * in gtkrc configuration files. Widget names are the type of the
10545 * widget by default (e.g. "GtkButton") or can be set to an
10546 * application-specific value with gtk_widget_set_name(). By setting
10547 * the name of a widget, you allow users or theme authors to apply
10548 * styles to that specific widget in their gtkrc
10549 * file. @path_reversed_p fills in the path in reverse order,
10550 * i.e. starting with @widget's name instead of starting with the name
10551 * of @widget's outermost ancestor.
10554 gtk_widget_path (GtkWidget *widget,
10555 guint *path_length,
10557 gchar **path_reversed)
10559 static gchar *rev_path = NULL;
10560 static guint tmp_path_len = 0;
10563 g_return_if_fail (GTK_IS_WIDGET (widget));
10568 const gchar *string;
10573 string = gtk_widget_get_name (widget);
10574 l = strlen (string);
10575 while (tmp_path_len <= len + l + 1)
10577 tmp_path_len += INIT_PATH_SIZE;
10578 rev_path = g_realloc (rev_path, tmp_path_len);
10580 s = string + l - 1;
10581 d = rev_path + len;
10582 while (s >= string)
10586 widget = widget->priv->parent;
10589 rev_path[len++] = '.';
10591 rev_path[len++] = 0;
10596 *path_length = len - 1;
10598 *path_reversed = g_strdup (rev_path);
10601 *path = g_strdup (rev_path);
10602 g_strreverse (*path);
10607 * gtk_widget_class_path:
10608 * @widget: a #GtkWidget
10609 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10610 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10611 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10614 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10615 * never uses a custom name set with gtk_widget_set_name().
10619 gtk_widget_class_path (GtkWidget *widget,
10620 guint *path_length,
10622 gchar **path_reversed)
10624 static gchar *rev_path = NULL;
10625 static guint tmp_path_len = 0;
10628 g_return_if_fail (GTK_IS_WIDGET (widget));
10633 const gchar *string;
10638 string = g_type_name (G_OBJECT_TYPE (widget));
10639 l = strlen (string);
10640 while (tmp_path_len <= len + l + 1)
10642 tmp_path_len += INIT_PATH_SIZE;
10643 rev_path = g_realloc (rev_path, tmp_path_len);
10645 s = string + l - 1;
10646 d = rev_path + len;
10647 while (s >= string)
10651 widget = widget->priv->parent;
10654 rev_path[len++] = '.';
10656 rev_path[len++] = 0;
10661 *path_length = len - 1;
10663 *path_reversed = g_strdup (rev_path);
10666 *path = g_strdup (rev_path);
10667 g_strreverse (*path);
10672 * gtk_requisition_new:
10674 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10676 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10677 * be freed with gtk_requisition_free().
10682 gtk_requisition_new (void)
10684 return g_slice_new0 (GtkRequisition);
10688 * gtk_requisition_copy:
10689 * @requisition: a #GtkRequisition
10691 * Copies a #GtkRequisition.
10693 * Returns: a copy of @requisition
10696 gtk_requisition_copy (const GtkRequisition *requisition)
10698 return g_slice_dup (GtkRequisition, requisition);
10702 * gtk_requisition_free:
10703 * @requisition: a #GtkRequisition
10705 * Frees a #GtkRequisition.
10708 gtk_requisition_free (GtkRequisition *requisition)
10710 g_slice_free (GtkRequisition, requisition);
10713 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10714 gtk_requisition_copy,
10715 gtk_requisition_free)
10718 * gtk_widget_get_accessible:
10719 * @widget: a #GtkWidget
10721 * Returns the accessible object that describes the widget to an
10722 * assistive technology.
10724 * If no accessibility library is loaded (i.e. no ATK implementation library is
10725 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10726 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10727 * if no class-specific #AtkObject implementation is available for the widget
10728 * instance in question, it will inherit an #AtkObject implementation from the
10729 * first ancestor class for which such an implementation is defined.
10731 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10732 * library contains more information about accessible objects and their uses.
10734 * Returns: (transfer none): the #AtkObject associated with @widget
10737 gtk_widget_get_accessible (GtkWidget *widget)
10739 GtkWidgetClass *klass;
10741 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10743 klass = GTK_WIDGET_GET_CLASS (widget);
10745 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10747 return klass->get_accessible (widget);
10751 gtk_widget_real_get_accessible (GtkWidget *widget)
10753 AtkObject* accessible;
10755 accessible = g_object_get_qdata (G_OBJECT (widget),
10756 quark_accessible_object);
10759 AtkObjectFactory *factory;
10760 AtkRegistry *default_registry;
10762 default_registry = atk_get_default_registry ();
10763 factory = atk_registry_get_factory (default_registry,
10764 G_TYPE_FROM_INSTANCE (widget));
10766 atk_object_factory_create_accessible (factory,
10767 G_OBJECT (widget));
10768 g_object_set_qdata (G_OBJECT (widget),
10769 quark_accessible_object,
10776 * Initialize a AtkImplementorIface instance's virtual pointers as
10777 * appropriate to this implementor's class (GtkWidget).
10780 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10782 iface->ref_accessible = gtk_widget_ref_accessible;
10786 gtk_widget_ref_accessible (AtkImplementor *implementor)
10788 AtkObject *accessible;
10790 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10792 g_object_ref (accessible);
10797 * GtkBuildable implementation
10799 static GQuark quark_builder_has_default = 0;
10800 static GQuark quark_builder_has_focus = 0;
10801 static GQuark quark_builder_atk_relations = 0;
10802 static GQuark quark_builder_set_name = 0;
10805 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10807 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10808 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10809 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10810 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10812 iface->set_name = gtk_widget_buildable_set_name;
10813 iface->get_name = gtk_widget_buildable_get_name;
10814 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10815 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10816 iface->parser_finished = gtk_widget_buildable_parser_finished;
10817 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10818 iface->custom_finished = gtk_widget_buildable_custom_finished;
10822 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10825 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10826 g_strdup (name), g_free);
10829 static const gchar *
10830 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10832 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10836 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10837 GtkBuilder *builder,
10838 const gchar *childname)
10840 if (strcmp (childname, "accessible") == 0)
10841 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10847 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10848 GtkBuilder *builder,
10850 const GValue *value)
10852 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10853 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10854 GINT_TO_POINTER (TRUE));
10855 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10856 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10857 GINT_TO_POINTER (TRUE));
10859 g_object_set_property (G_OBJECT (buildable), name, value);
10864 gchar *action_name;
10865 GString *description;
10867 gboolean translatable;
10877 free_action (AtkActionData *data, gpointer user_data)
10879 g_free (data->action_name);
10880 g_string_free (data->description, TRUE);
10881 g_free (data->context);
10882 g_slice_free (AtkActionData, data);
10886 free_relation (AtkRelationData *data, gpointer user_data)
10888 g_free (data->target);
10889 g_free (data->type);
10890 g_slice_free (AtkRelationData, data);
10894 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10895 GtkBuilder *builder)
10897 GSList *atk_relations;
10899 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10900 gtk_widget_grab_default (GTK_WIDGET (buildable));
10901 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10902 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10904 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10905 quark_builder_atk_relations);
10908 AtkObject *accessible;
10909 AtkRelationSet *relation_set;
10912 AtkRelationType relation_type;
10913 AtkObject *target_accessible;
10915 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10916 relation_set = atk_object_ref_relation_set (accessible);
10918 for (l = atk_relations; l; l = l->next)
10920 AtkRelationData *relation = (AtkRelationData*)l->data;
10922 target = gtk_builder_get_object (builder, relation->target);
10925 g_warning ("Target object %s in <relation> does not exist",
10929 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10930 g_assert (target_accessible != NULL);
10932 relation_type = atk_relation_type_for_name (relation->type);
10933 if (relation_type == ATK_RELATION_NULL)
10935 g_warning ("<relation> type %s not found",
10939 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10940 target_accessible);
10942 g_object_unref (relation_set);
10944 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10945 g_slist_free (atk_relations);
10946 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10955 } AccessibilitySubParserData;
10958 accessibility_start_element (GMarkupParseContext *context,
10959 const gchar *element_name,
10960 const gchar **names,
10961 const gchar **values,
10962 gpointer user_data,
10965 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10967 gint line_number, char_number;
10969 if (strcmp (element_name, "relation") == 0)
10971 gchar *target = NULL;
10972 gchar *type = NULL;
10973 AtkRelationData *relation;
10975 for (i = 0; names[i]; i++)
10977 if (strcmp (names[i], "target") == 0)
10978 target = g_strdup (values[i]);
10979 else if (strcmp (names[i], "type") == 0)
10980 type = g_strdup (values[i]);
10983 g_markup_parse_context_get_position (context,
10986 g_set_error (error,
10988 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10989 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10991 line_number, char_number, names[i], "relation");
10998 if (!target || !type)
11000 g_markup_parse_context_get_position (context,
11003 g_set_error (error,
11005 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11006 "%s:%d:%d <%s> requires attribute \"%s\"",
11008 line_number, char_number, "relation",
11009 type ? "target" : "type");
11015 relation = g_slice_new (AtkRelationData);
11016 relation->target = target;
11017 relation->type = type;
11019 data->relations = g_slist_prepend (data->relations, relation);
11021 else if (strcmp (element_name, "action") == 0)
11023 const gchar *action_name = NULL;
11024 const gchar *description = NULL;
11025 const gchar *msg_context = NULL;
11026 gboolean translatable = FALSE;
11027 AtkActionData *action;
11029 for (i = 0; names[i]; i++)
11031 if (strcmp (names[i], "action_name") == 0)
11032 action_name = values[i];
11033 else if (strcmp (names[i], "description") == 0)
11034 description = values[i];
11035 else if (strcmp (names[i], "translatable") == 0)
11037 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11040 else if (strcmp (names[i], "comments") == 0)
11042 /* do nothing, comments are for translators */
11044 else if (strcmp (names[i], "context") == 0)
11045 msg_context = values[i];
11048 g_markup_parse_context_get_position (context,
11051 g_set_error (error,
11053 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11054 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11056 line_number, char_number, names[i], "action");
11063 g_markup_parse_context_get_position (context,
11066 g_set_error (error,
11068 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11069 "%s:%d:%d <%s> requires attribute \"%s\"",
11071 line_number, char_number, "action",
11076 action = g_slice_new (AtkActionData);
11077 action->action_name = g_strdup (action_name);
11078 action->description = g_string_new (description);
11079 action->context = g_strdup (msg_context);
11080 action->translatable = translatable;
11082 data->actions = g_slist_prepend (data->actions, action);
11084 else if (strcmp (element_name, "accessibility") == 0)
11087 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11091 accessibility_text (GMarkupParseContext *context,
11094 gpointer user_data,
11097 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11099 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11101 AtkActionData *action = data->actions->data;
11103 g_string_append_len (action->description, text, text_len);
11107 static const GMarkupParser accessibility_parser =
11109 accessibility_start_element,
11111 accessibility_text,
11120 } AccelGroupParserData;
11123 accel_group_start_element (GMarkupParseContext *context,
11124 const gchar *element_name,
11125 const gchar **names,
11126 const gchar **values,
11127 gpointer user_data,
11132 guint modifiers = 0;
11133 gchar *signal = NULL;
11134 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11136 for (i = 0; names[i]; i++)
11138 if (strcmp (names[i], "key") == 0)
11139 key = gdk_keyval_from_name (values[i]);
11140 else if (strcmp (names[i], "modifiers") == 0)
11142 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11148 else if (strcmp (names[i], "signal") == 0)
11149 signal = g_strdup (values[i]);
11152 if (key == 0 || signal == NULL)
11154 g_warning ("<accelerator> requires key and signal attributes");
11157 parser_data->key = key;
11158 parser_data->modifiers = modifiers;
11159 parser_data->signal = signal;
11162 static const GMarkupParser accel_group_parser =
11164 accel_group_start_element,
11168 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11169 GtkBuilder *builder,
11171 const gchar *tagname,
11172 GMarkupParser *parser,
11175 g_assert (buildable);
11177 if (strcmp (tagname, "accelerator") == 0)
11179 AccelGroupParserData *parser_data;
11181 parser_data = g_slice_new0 (AccelGroupParserData);
11182 parser_data->object = g_object_ref (buildable);
11183 *parser = accel_group_parser;
11184 *data = parser_data;
11187 if (strcmp (tagname, "accessibility") == 0)
11189 AccessibilitySubParserData *parser_data;
11191 parser_data = g_slice_new0 (AccessibilitySubParserData);
11192 *parser = accessibility_parser;
11193 *data = parser_data;
11200 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11201 GtkWidget *toplevel,
11202 gpointer user_data)
11204 AccelGroupParserData *accel_data;
11205 GSList *accel_groups;
11206 GtkAccelGroup *accel_group;
11208 g_return_if_fail (GTK_IS_WIDGET (widget));
11209 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11210 g_return_if_fail (user_data != NULL);
11212 accel_data = (AccelGroupParserData*)user_data;
11213 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11214 if (g_slist_length (accel_groups) == 0)
11216 accel_group = gtk_accel_group_new ();
11217 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11221 g_assert (g_slist_length (accel_groups) == 1);
11222 accel_group = g_slist_nth_data (accel_groups, 0);
11225 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11226 accel_data->signal,
11229 accel_data->modifiers,
11230 GTK_ACCEL_VISIBLE);
11232 g_object_unref (accel_data->object);
11233 g_free (accel_data->signal);
11234 g_slice_free (AccelGroupParserData, accel_data);
11238 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11239 GtkBuilder *builder,
11241 const gchar *tagname,
11242 gpointer user_data)
11244 AccelGroupParserData *accel_data;
11245 AccessibilitySubParserData *a11y_data;
11246 GtkWidget *toplevel;
11248 if (strcmp (tagname, "accelerator") == 0)
11250 accel_data = (AccelGroupParserData*)user_data;
11251 g_assert (accel_data->object);
11253 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11255 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11257 else if (strcmp (tagname, "accessibility") == 0)
11259 a11y_data = (AccessibilitySubParserData*)user_data;
11261 if (a11y_data->actions)
11263 AtkObject *accessible;
11268 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11270 action = ATK_ACTION (accessible);
11271 n_actions = atk_action_get_n_actions (action);
11273 for (l = a11y_data->actions; l; l = l->next)
11275 AtkActionData *action_data = (AtkActionData*)l->data;
11277 for (i = 0; i < n_actions; i++)
11278 if (strcmp (atk_action_get_name (action, i),
11279 action_data->action_name) == 0)
11284 gchar *description;
11286 if (action_data->translatable && action_data->description->len)
11287 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11288 action_data->context,
11289 action_data->description->str);
11291 description = action_data->description->str;
11293 atk_action_set_description (action, i, description);
11297 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11298 g_slist_free (a11y_data->actions);
11301 if (a11y_data->relations)
11302 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11303 a11y_data->relations);
11305 g_slice_free (AccessibilitySubParserData, a11y_data);
11310 gtk_widget_real_get_width (GtkWidget *widget,
11311 gint *minimum_size,
11312 gint *natural_size)
11322 gtk_widget_real_get_height (GtkWidget *widget,
11323 gint *minimum_size,
11324 gint *natural_size)
11334 gtk_widget_real_get_height_for_width (GtkWidget *widget,
11336 gint *minimum_height,
11337 gint *natural_height)
11339 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
11343 gtk_widget_real_get_width_for_height (GtkWidget *widget,
11345 gint *minimum_width,
11346 gint *natural_width)
11348 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
11352 * gtk_widget_get_halign:
11353 * @widget: a #GtkWidget
11355 * Gets the value of the #GtkWidget:halign property.
11357 * Returns: the horizontal alignment of @widget
11360 gtk_widget_get_halign (GtkWidget *widget)
11362 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11363 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11367 * gtk_widget_set_halign:
11368 * @widget: a #GtkWidget
11369 * @align: the horizontal alignment
11371 * Sets the horizontal alignment of @widget.
11372 * See the #GtkWidget:halign property.
11375 gtk_widget_set_halign (GtkWidget *widget,
11378 GtkWidgetAuxInfo *aux_info;
11380 g_return_if_fail (GTK_IS_WIDGET (widget));
11382 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11384 if (aux_info->halign == align)
11387 aux_info->halign = align;
11388 gtk_widget_queue_resize (widget);
11389 g_object_notify (G_OBJECT (widget), "halign");
11393 * gtk_widget_get_valign:
11394 * @widget: a #GtkWidget
11396 * Gets the value of the #GtkWidget:valign property.
11398 * Returns: the vertical alignment of @widget
11401 gtk_widget_get_valign (GtkWidget *widget)
11403 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11404 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11408 * gtk_widget_set_valign:
11409 * @widget: a #GtkWidget
11410 * @align: the vertical alignment
11412 * Sets the vertical alignment of @widget.
11413 * See the #GtkWidget:valign property.
11416 gtk_widget_set_valign (GtkWidget *widget,
11419 GtkWidgetAuxInfo *aux_info;
11421 g_return_if_fail (GTK_IS_WIDGET (widget));
11423 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11425 if (aux_info->valign == align)
11428 aux_info->valign = align;
11429 gtk_widget_queue_resize (widget);
11430 g_object_notify (G_OBJECT (widget), "valign");
11434 * gtk_widget_get_margin_left:
11435 * @widget: a #GtkWidget
11437 * Gets the value of the #GtkWidget:margin-left property.
11439 * Returns: The left margin of @widget
11442 gtk_widget_get_margin_left (GtkWidget *widget)
11444 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11446 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11450 * gtk_widget_set_margin_left:
11451 * @widget: a #GtkWidget
11452 * @margin: the left margin
11454 * Sets the left margin of @widget.
11455 * See the #GtkWidget:margin-left property.
11458 gtk_widget_set_margin_left (GtkWidget *widget,
11461 GtkWidgetAuxInfo *aux_info;
11463 g_return_if_fail (GTK_IS_WIDGET (widget));
11464 g_return_if_fail (margin <= G_MAXINT16);
11466 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11468 if (aux_info->margin.left == margin)
11471 aux_info->margin.left = margin;
11472 gtk_widget_queue_resize (widget);
11473 g_object_notify (G_OBJECT (widget), "margin-left");
11477 * gtk_widget_get_margin_right:
11478 * @widget: a #GtkWidget
11480 * Gets the value of the #GtkWidget:margin-right property.
11482 * Returns: The left margin of @widget
11485 gtk_widget_get_margin_right (GtkWidget *widget)
11487 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11489 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11493 * gtk_widget_set_margin_right:
11494 * @widget: a #GtkWidget
11495 * @margin: the right margin
11497 * Sets the right margin of @widget.
11498 * See the #GtkWidget:margin-right property.
11501 gtk_widget_set_margin_right (GtkWidget *widget,
11504 GtkWidgetAuxInfo *aux_info;
11506 g_return_if_fail (GTK_IS_WIDGET (widget));
11507 g_return_if_fail (margin <= G_MAXINT16);
11509 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11511 if (aux_info->margin.right == margin)
11514 aux_info->margin.right = margin;
11515 gtk_widget_queue_resize (widget);
11516 g_object_notify (G_OBJECT (widget), "margin-right");
11520 * gtk_widget_get_margin_top:
11521 * @widget: a #GtkWidget
11523 * Gets the value of the #GtkWidget:margin-top property.
11525 * Returns: The top margin of @widget
11528 gtk_widget_get_margin_top (GtkWidget *widget)
11530 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11532 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11536 * gtk_widget_set_margin_top:
11537 * @widget: a #GtkWidget
11538 * @margin: the top margin
11540 * Sets the top margin of @widget.
11541 * See the #GtkWidget:margin-top property.
11544 gtk_widget_set_margin_top (GtkWidget *widget,
11547 GtkWidgetAuxInfo *aux_info;
11549 g_return_if_fail (GTK_IS_WIDGET (widget));
11550 g_return_if_fail (margin <= G_MAXINT16);
11552 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11554 if (aux_info->margin.top == margin)
11557 aux_info->margin.top = margin;
11558 gtk_widget_queue_resize (widget);
11559 g_object_notify (G_OBJECT (widget), "margin-top");
11563 * gtk_widget_get_margin_bottom:
11564 * @widget: a #GtkWidget
11566 * Gets the value of the #GtkWidget:margin-bottom property.
11568 * Returns: The bottom margin of @widget
11571 gtk_widget_get_margin_bottom (GtkWidget *widget)
11573 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11575 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11579 * gtk_widget_set_margin_bottom:
11580 * @widget: a #GtkWidget
11581 * @margin: the bottom margin
11583 * Sets the bottom margin of @widget.
11584 * See the #GtkWidget:margin-bottom property.
11587 gtk_widget_set_margin_bottom (GtkWidget *widget,
11590 GtkWidgetAuxInfo *aux_info;
11592 g_return_if_fail (GTK_IS_WIDGET (widget));
11593 g_return_if_fail (margin <= G_MAXINT16);
11595 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11597 if (aux_info->margin.bottom == margin)
11600 aux_info->margin.bottom = margin;
11601 gtk_widget_queue_resize (widget);
11602 g_object_notify (G_OBJECT (widget), "margin-bottom");
11606 * gtk_widget_get_clipboard:
11607 * @widget: a #GtkWidget
11608 * @selection: a #GdkAtom which identifies the clipboard
11609 * to use. %GDK_SELECTION_CLIPBOARD gives the
11610 * default clipboard. Another common value
11611 * is %GDK_SELECTION_PRIMARY, which gives
11612 * the primary X selection.
11614 * Returns the clipboard object for the given selection to
11615 * be used with @widget. @widget must have a #GdkDisplay
11616 * associated with it, so must be attached to a toplevel
11619 * Return value: (transfer none): the appropriate clipboard object. If no
11620 * clipboard already exists, a new one will
11621 * be created. Once a clipboard object has
11622 * been created, it is persistent for all time.
11627 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11629 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11630 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11632 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11637 * gtk_widget_list_mnemonic_labels:
11638 * @widget: a #GtkWidget
11640 * Returns a newly allocated list of the widgets, normally labels, for
11641 * which this widget is the target of a mnemonic (see for example,
11642 * gtk_label_set_mnemonic_widget()).
11644 * The widgets in the list are not individually referenced. If you
11645 * want to iterate through the list and perform actions involving
11646 * callbacks that might destroy the widgets, you
11647 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11648 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11649 * widgets afterwards.
11651 * Return value: (element-type GtkWidget) (transfer container): the list of
11652 * mnemonic labels; free this list
11653 * with g_list_free() when you are done with it.
11658 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11660 GList *list = NULL;
11663 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11665 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11666 list = g_list_prepend (list, l->data);
11672 * gtk_widget_add_mnemonic_label:
11673 * @widget: a #GtkWidget
11674 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11676 * Adds a widget to the list of mnemonic labels for
11677 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11678 * list of mnemonic labels for the widget is cleared when the
11679 * widget is destroyed, so the caller must make sure to update
11680 * its internal state at this point as well, by using a connection
11681 * to the #GtkWidget::destroy signal or a weak notifier.
11686 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11689 GSList *old_list, *new_list;
11691 g_return_if_fail (GTK_IS_WIDGET (widget));
11692 g_return_if_fail (GTK_IS_WIDGET (label));
11694 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11695 new_list = g_slist_prepend (old_list, label);
11697 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11698 new_list, (GDestroyNotify) g_slist_free);
11702 * gtk_widget_remove_mnemonic_label:
11703 * @widget: a #GtkWidget
11704 * @label: a #GtkWidget that was previously set as a mnemnic label for
11705 * @widget with gtk_widget_add_mnemonic_label().
11707 * Removes a widget from the list of mnemonic labels for
11708 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11709 * must have previously been added to the list with
11710 * gtk_widget_add_mnemonic_label().
11715 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11718 GSList *old_list, *new_list;
11720 g_return_if_fail (GTK_IS_WIDGET (widget));
11721 g_return_if_fail (GTK_IS_WIDGET (label));
11723 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11724 new_list = g_slist_remove (old_list, label);
11727 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11728 new_list, (GDestroyNotify) g_slist_free);
11732 * gtk_widget_get_no_show_all:
11733 * @widget: a #GtkWidget
11735 * Returns the current value of the GtkWidget:no-show-all property,
11736 * which determines whether calls to gtk_widget_show_all() and
11737 * gtk_widget_hide_all() will affect this widget.
11739 * Return value: the current value of the "no-show-all" property.
11744 gtk_widget_get_no_show_all (GtkWidget *widget)
11746 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11748 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11752 * gtk_widget_set_no_show_all:
11753 * @widget: a #GtkWidget
11754 * @no_show_all: the new value for the "no-show-all" property
11756 * Sets the #GtkWidget:no-show-all property, which determines whether
11757 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11760 * This is mostly for use in constructing widget hierarchies with externally
11761 * controlled visibility, see #GtkUIManager.
11766 gtk_widget_set_no_show_all (GtkWidget *widget,
11767 gboolean no_show_all)
11769 g_return_if_fail (GTK_IS_WIDGET (widget));
11771 no_show_all = (no_show_all != FALSE);
11773 if (no_show_all == gtk_widget_get_no_show_all (widget))
11777 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11779 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11781 g_object_notify (G_OBJECT (widget), "no-show-all");
11786 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11787 gboolean has_tooltip,
11790 GtkWidgetPrivate *priv = widget->priv;
11791 gboolean priv_has_tooltip;
11793 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11794 quark_has_tooltip));
11796 if (priv_has_tooltip != has_tooltip || force)
11798 priv_has_tooltip = has_tooltip;
11800 if (priv_has_tooltip)
11802 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11803 gdk_window_set_events (priv->window,
11804 gdk_window_get_events (priv->window) |
11805 GDK_LEAVE_NOTIFY_MASK |
11806 GDK_POINTER_MOTION_MASK |
11807 GDK_POINTER_MOTION_HINT_MASK);
11809 if (gtk_widget_get_has_window (widget))
11810 gtk_widget_add_events (widget,
11811 GDK_LEAVE_NOTIFY_MASK |
11812 GDK_POINTER_MOTION_MASK |
11813 GDK_POINTER_MOTION_HINT_MASK);
11816 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11817 GUINT_TO_POINTER (priv_has_tooltip));
11822 * gtk_widget_set_tooltip_window:
11823 * @widget: a #GtkWidget
11824 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11826 * Replaces the default, usually yellow, window used for displaying
11827 * tooltips with @custom_window. GTK+ will take care of showing and
11828 * hiding @custom_window at the right moment, to behave likewise as
11829 * the default tooltip window. If @custom_window is %NULL, the default
11830 * tooltip window will be used.
11832 * If the custom window should have the default theming it needs to
11833 * have the name "gtk-tooltip", see gtk_widget_set_name().
11838 gtk_widget_set_tooltip_window (GtkWidget *widget,
11839 GtkWindow *custom_window)
11841 gboolean has_tooltip;
11842 gchar *tooltip_markup;
11844 g_return_if_fail (GTK_IS_WIDGET (widget));
11845 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11847 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11850 g_object_ref (custom_window);
11852 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11853 custom_window, g_object_unref);
11855 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11856 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11858 if (has_tooltip && gtk_widget_get_visible (widget))
11859 gtk_widget_queue_tooltip_query (widget);
11863 * gtk_widget_get_tooltip_window:
11864 * @widget: a #GtkWidget
11866 * Returns the #GtkWindow of the current tooltip. This can be the
11867 * GtkWindow created by default, or the custom tooltip window set
11868 * using gtk_widget_set_tooltip_window().
11870 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11875 gtk_widget_get_tooltip_window (GtkWidget *widget)
11877 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11879 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11883 * gtk_widget_trigger_tooltip_query:
11884 * @widget: a #GtkWidget
11886 * Triggers a tooltip query on the display where the toplevel of @widget
11887 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11893 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11895 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11898 static guint tooltip_query_id;
11899 static GSList *tooltip_query_displays;
11902 tooltip_query_idle (gpointer data)
11904 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11905 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11906 g_slist_free (tooltip_query_displays);
11908 tooltip_query_displays = NULL;
11909 tooltip_query_id = 0;
11915 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11917 GdkDisplay *display;
11919 display = gtk_widget_get_display (widget);
11921 if (!g_slist_find (tooltip_query_displays, display))
11922 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11924 if (tooltip_query_id == 0)
11925 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11929 * gtk_widget_set_tooltip_text:
11930 * @widget: a #GtkWidget
11931 * @text: the contents of the tooltip for @widget
11933 * Sets @text as the contents of the tooltip. This function will take
11934 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11935 * handler for the GtkWidget::query-tooltip signal.
11937 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11942 gtk_widget_set_tooltip_text (GtkWidget *widget,
11945 g_return_if_fail (GTK_IS_WIDGET (widget));
11947 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11951 * gtk_widget_get_tooltip_text:
11952 * @widget: a #GtkWidget
11954 * Gets the contents of the tooltip for @widget.
11956 * Return value: the tooltip text, or %NULL. You should free the
11957 * returned string with g_free() when done.
11962 gtk_widget_get_tooltip_text (GtkWidget *widget)
11964 gchar *text = NULL;
11966 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11968 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11974 * gtk_widget_set_tooltip_markup:
11975 * @widget: a #GtkWidget
11976 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11978 * Sets @markup as the contents of the tooltip, which is marked up with
11979 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11981 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11982 * and of the default handler for the GtkWidget::query-tooltip signal.
11984 * See also the GtkWidget:tooltip-markup property and
11985 * gtk_tooltip_set_markup().
11990 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11991 const gchar *markup)
11993 g_return_if_fail (GTK_IS_WIDGET (widget));
11995 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11999 * gtk_widget_get_tooltip_markup:
12000 * @widget: a #GtkWidget
12002 * Gets the contents of the tooltip for @widget.
12004 * Return value: the tooltip text, or %NULL. You should free the
12005 * returned string with g_free() when done.
12010 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12012 gchar *text = NULL;
12014 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12016 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12022 * gtk_widget_set_has_tooltip:
12023 * @widget: a #GtkWidget
12024 * @has_tooltip: whether or not @widget has a tooltip.
12026 * Sets the has-tooltip property on @widget to @has_tooltip. See
12027 * GtkWidget:has-tooltip for more information.
12032 gtk_widget_set_has_tooltip (GtkWidget *widget,
12033 gboolean has_tooltip)
12035 g_return_if_fail (GTK_IS_WIDGET (widget));
12037 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12041 * gtk_widget_get_has_tooltip:
12042 * @widget: a #GtkWidget
12044 * Returns the current value of the has-tooltip property. See
12045 * GtkWidget:has-tooltip for more information.
12047 * Return value: current value of has-tooltip on @widget.
12052 gtk_widget_get_has_tooltip (GtkWidget *widget)
12054 gboolean has_tooltip = FALSE;
12056 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12058 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12060 return has_tooltip;
12064 * gtk_widget_get_allocation:
12065 * @widget: a #GtkWidget
12066 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12068 * Retrieves the widget's allocation.
12070 * Note, when implementing a #GtkContainer: a widget's allocation will
12071 * be its "adjusted" allocation, that is, the widget's parent
12072 * container typically calls gtk_widget_size_allocate() with an
12073 * allocation, and that allocation is then adjusted (to handle margin
12074 * and alignment for example) before assignment to the widget.
12075 * gtk_widget_get_allocation() returns the adjusted allocation that
12076 * was actually assigned to the widget. The adjusted allocation is
12077 * guaranteed to be completely contained within the
12078 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12079 * is guaranteed that its children stay inside the assigned bounds,
12080 * but not that they have exactly the bounds the container assigned.
12081 * There is no way to get the original allocation assigned by
12082 * gtk_widget_size_allocate(), since it isn't stored; if a container
12083 * implementation needs that information it will have to track it itself.
12088 gtk_widget_get_allocation (GtkWidget *widget,
12089 GtkAllocation *allocation)
12091 GtkWidgetPrivate *priv;
12093 g_return_if_fail (GTK_IS_WIDGET (widget));
12094 g_return_if_fail (allocation != NULL);
12096 priv = widget->priv;
12098 *allocation = priv->allocation;
12102 * gtk_widget_set_allocation:
12103 * @widget: a #GtkWidget
12104 * @allocation: a pointer to a #GtkAllocation to copy from
12106 * Sets the widget's allocation. This should not be used
12107 * directly, but from within a widget's size_allocate method.
12109 * The allocation set should be the "adjusted" or actual
12110 * allocation. If you're implementing a #GtkContainer, you want to use
12111 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12112 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12113 * allocation inside gtk_widget_size_allocate() to create an adjusted
12119 gtk_widget_set_allocation (GtkWidget *widget,
12120 const GtkAllocation *allocation)
12122 GtkWidgetPrivate *priv;
12124 g_return_if_fail (GTK_IS_WIDGET (widget));
12125 g_return_if_fail (allocation != NULL);
12127 priv = widget->priv;
12129 priv->allocation = *allocation;
12133 * gtk_widget_get_allocated_width:
12134 * @widget: the widget to query
12136 * Returns the width that has currently been allocated to @widget.
12137 * This function is intended to be used when implementing handlers
12138 * for the GtkWidget::draw function.
12140 * Returns: the width of the @widget
12143 gtk_widget_get_allocated_width (GtkWidget *widget)
12145 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12147 return widget->priv->allocation.width;
12151 * gtk_widget_get_allocated_height:
12152 * @widget: the widget to query
12154 * Returns the height that has currently been allocated to @widget.
12155 * This function is intended to be used when implementing handlers
12156 * for the GtkWidget::draw function.
12158 * Returns: the height of the @widget
12161 gtk_widget_get_allocated_height (GtkWidget *widget)
12163 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12165 return widget->priv->allocation.height;
12169 * gtk_widget_get_requisition:
12170 * @widget: a #GtkWidget
12171 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12173 * Retrieves the widget's requisition.
12175 * This function should only be used by widget implementations in
12176 * order to figure whether the widget's requisition has actually
12177 * changed after some internal state change (so that they can call
12178 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12180 * Normally, gtk_widget_size_request() should be used.
12184 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12185 * removed, If you need to cache sizes across requests and allocations,
12186 * add an explicit cache to the widget in question instead.
12189 gtk_widget_get_requisition (GtkWidget *widget,
12190 GtkRequisition *requisition)
12192 g_return_if_fail (GTK_IS_WIDGET (widget));
12193 g_return_if_fail (requisition != NULL);
12195 gtk_widget_get_preferred_size (widget, requisition, NULL);
12199 * gtk_widget_set_window:
12200 * @widget: a #GtkWidget
12201 * @window: a #GdkWindow
12203 * Sets a widget's window. This function should only be used in a
12204 * widget's GtkWidget::realize() implementation. The %window passed is
12205 * usually either new window created with gdk_window_new(), or the
12206 * window of its parent widget as returned by
12207 * gtk_widget_get_parent_window().
12209 * Widgets must indicate whether they will create their own #GdkWindow
12210 * by calling gtk_widget_set_has_window(). This is usually done in the
12211 * widget's init() function.
12213 * <note><para>This function does not add any reference to @window.</para></note>
12218 gtk_widget_set_window (GtkWidget *widget,
12221 GtkWidgetPrivate *priv;
12223 g_return_if_fail (GTK_IS_WIDGET (widget));
12224 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12226 priv = widget->priv;
12228 if (priv->window != window)
12230 priv->window = window;
12231 g_object_notify (G_OBJECT (widget), "window");
12236 * gtk_widget_get_window:
12237 * @widget: a #GtkWidget
12239 * Returns the widget's window if it is realized, %NULL otherwise
12241 * Return value: (transfer none): @widget's window.
12246 gtk_widget_get_window (GtkWidget *widget)
12248 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12250 return widget->priv->window;
12254 * gtk_widget_get_support_multidevice:
12255 * @widget: a #GtkWidget
12257 * Returns %TRUE if @widget is multiple pointer aware. See
12258 * gtk_widget_set_support_multidevice() for more information.
12260 * Returns: %TRUE is @widget is multidevice aware.
12263 gtk_widget_get_support_multidevice (GtkWidget *widget)
12265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12267 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12271 * gtk_widget_set_support_multidevice:
12272 * @widget: a #GtkWidget
12273 * @support_multidevice: %TRUE to support input from multiple devices.
12275 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12276 * @widget will start receiving multiple, per device enter/leave events. Note
12277 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12278 * gdk_window_set_support_multidevice() will have to be called manually on them.
12283 gtk_widget_set_support_multidevice (GtkWidget *widget,
12284 gboolean support_multidevice)
12286 GtkWidgetPrivate *priv;
12288 g_return_if_fail (GTK_IS_WIDGET (widget));
12290 priv = widget->priv;
12292 if (support_multidevice)
12294 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12295 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12299 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12300 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12303 if (gtk_widget_get_realized (widget))
12304 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12308 _gtk_widget_set_has_focus (GtkWidget *widget,
12309 gboolean has_focus)
12312 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12314 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12318 * gtk_widget_send_focus_change:
12319 * @widget: a #GtkWidget
12320 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12322 * Sends the focus change @event to @widget
12324 * This function is not meant to be used by applications. The only time it
12325 * should be used is when it is necessary for a #GtkWidget to assign focus
12326 * to a widget that is semantically owned by the first widget even though
12327 * it's not a direct child - for instance, a search entry in a floating
12328 * window similar to the quick search in #GtkTreeView.
12330 * An example of its usage is:
12333 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12335 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12336 * fevent->focus_change.in = TRUE;
12337 * fevent->focus_change.window = gtk_widget_get_window (widget);
12338 * if (fevent->focus_change.window != NULL)
12339 * g_object_ref (fevent->focus_change.window);
12341 * gtk_widget_send_focus_change (widget, fevent);
12343 * gdk_event_free (event);
12346 * Return value: the return value from the event signal emission: %TRUE
12347 * if the event was handled, and %FALSE otherwise
12352 gtk_widget_send_focus_change (GtkWidget *widget,
12357 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12358 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12360 g_object_ref (widget);
12362 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12364 res = gtk_widget_event (widget, event);
12366 g_object_notify (G_OBJECT (widget), "has-focus");
12368 g_object_unref (widget);