1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup.h"
44 #include "gtkwidget.h"
45 #include "gtkwindow.h"
46 #include "gtkbindings.h"
47 #include "gtkprivate.h"
49 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
50 #include <gobject/gvaluecollector.h>
51 #include <gobject/gobjectnotifyqueue.c>
52 #include "gdk/gdkkeysyms.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
63 * @Short_description: Base class for all widgets
66 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
67 * widget lifecycle, states and style.
69 * <refsect2 id="style-properties">
71 * <structname>GtkWidget</structname> introduces <firstterm>style
72 * properties</firstterm> - these are basically object properties that are stored
73 * not on the object, but in the style object associated to the widget. Style
74 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
75 * This mechanism is used for configuring such things as the location of the
76 * scrollbar arrows through the theme, giving theme authors more control over the
77 * look of applications without the need to write a theme engine in C.
80 * Use gtk_widget_class_install_style_property() to install style properties for
81 * a widget class, gtk_widget_class_find_style_property() or
82 * gtk_widget_class_list_style_properties() to get information about existing
83 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
84 * gtk_widget_style_get_valist() to obtain the value of a style property.
87 * <refsect2 id="GtkWidget-BUILDER-UI">
88 * <title>GtkWidget as GtkBuildable</title>
90 * The GtkWidget implementation of the GtkBuildable interface supports a
91 * custom <accelerator> element, which has attributes named key,
92 * modifiers and signal and allows to specify accelerators.
95 * <title>A UI definition fragment specifying an accelerator</title>
96 * <programlisting><![CDATA[
97 * <object class="GtkButton">
98 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
100 * ]]></programlisting>
103 * In addition to accelerators, <structname>GtkWidget</structname> also support a
104 * custom <accessible> element, which supports actions and relations.
105 * Properties on the accessible implementation of an object can be set by accessing the
106 * internal child "accessible" of a <structname>GtkWidget</structname>.
109 * <title>A UI definition fragment specifying an accessible</title>
110 * <programlisting><![CDATA[
111 * <object class="GtkButton" id="label1"/>
112 * <property name="label">I am a Label for a Button</property>
114 * <object class="GtkButton" id="button1">
116 * <action action_name="click" translatable="yes">Click the button.</action>
117 * <relation target="label1" type="labelled-by"/>
119 * <child internal-child="accessible">
120 * <object class="AtkObject" id="a11y-button1">
121 * <property name="AtkObject::name">Clickable Button</property>
125 * ]]></programlisting>
130 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
131 #define INIT_PATH_SIZE (512)
133 struct _GtkWidgetPrivate
135 /* The state of the widget. There are actually only
136 * 5 widget states (defined in "gtkenums.h")
141 /* The saved state of the widget. When a widget's state
142 * is changed to GTK_STATE_INSENSITIVE via
143 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
144 * the old state is kept around in this field. The state
145 * will be restored once the widget gets sensitive again.
147 guint saved_state : 3;
149 /* unused bits in our 32-bit block */
152 /* The widget's name. If the widget does not have a name
153 * (the name is NULL), then its name (as returned by
154 * "gtk_widget_get_name") is its class's name.
155 * Among other things, the widget name is used to determine
156 * the style to use for a widget.
160 /* The style for the widget. The style contains the
161 * colors the widget should be drawn in for each state
162 * along with graphics contexts used to draw with and
163 * the font to use for text.
167 /* The widget's allocated size.
169 GtkAllocation allocation;
171 /* The widget's window or its parent window if it does
172 * not have a window. (Which will be indicated by the
173 * GTK_NO_WINDOW flag being set).
177 /* The widget's parent.
205 BUTTON_RELEASE_EVENT,
220 PROPERTY_NOTIFY_EVENT,
221 SELECTION_CLEAR_EVENT,
222 SELECTION_REQUEST_EVENT,
223 SELECTION_NOTIFY_EVENT,
238 VISIBILITY_NOTIFY_EVENT,
242 ACCEL_CLOSURES_CHANGED,
268 PROP_RECEIVES_DEFAULT,
269 PROP_COMPOSITE_CHILD,
272 PROP_EXTENSION_EVENTS,
281 typedef struct _GtkStateData GtkStateData;
286 guint state_restoration : 1;
287 guint parent_sensitive : 1;
288 guint use_forall : 1;
291 /* --- prototypes --- */
292 static void gtk_widget_class_init (GtkWidgetClass *klass);
293 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
294 static void gtk_widget_init (GtkWidget *widget);
295 static void gtk_widget_set_property (GObject *object,
299 static void gtk_widget_get_property (GObject *object,
303 static void gtk_widget_dispose (GObject *object);
304 static void gtk_widget_real_destroy (GtkObject *object);
305 static void gtk_widget_finalize (GObject *object);
306 static void gtk_widget_real_show (GtkWidget *widget);
307 static void gtk_widget_real_hide (GtkWidget *widget);
308 static void gtk_widget_real_map (GtkWidget *widget);
309 static void gtk_widget_real_unmap (GtkWidget *widget);
310 static void gtk_widget_real_realize (GtkWidget *widget);
311 static void gtk_widget_real_unrealize (GtkWidget *widget);
312 static void gtk_widget_real_size_request (GtkWidget *widget,
313 GtkRequisition *requisition);
314 static void gtk_widget_real_size_allocate (GtkWidget *widget,
315 GtkAllocation *allocation);
316 static void gtk_widget_real_style_set (GtkWidget *widget,
317 GtkStyle *previous_style);
318 static void gtk_widget_real_direction_changed(GtkWidget *widget,
319 GtkTextDirection previous_direction);
321 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
322 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
325 gboolean keyboard_tip,
326 GtkTooltip *tooltip);
327 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
328 GtkWidgetHelpType help_type);
330 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
332 GParamSpec **pspecs);
333 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
335 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
337 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
338 GdkEventFocus *event);
339 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
340 GdkEventFocus *event);
341 static gboolean gtk_widget_real_focus (GtkWidget *widget,
342 GtkDirectionType direction);
343 static void gtk_widget_real_move_focus (GtkWidget *widget,
344 GtkDirectionType direction);
345 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
346 GtkDirectionType direction);
347 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
348 static void gtk_widget_update_pango_context (GtkWidget *widget);
349 static void gtk_widget_propagate_state (GtkWidget *widget,
351 static void gtk_widget_reset_rc_style (GtkWidget *widget);
352 static void gtk_widget_set_style_internal (GtkWidget *widget,
354 gboolean initial_emission);
355 static gint gtk_widget_event_internal (GtkWidget *widget,
357 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
358 gboolean group_cycling);
359 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
360 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
361 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
362 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
363 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
364 cairo_region_t *region);
365 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
366 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
367 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
370 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
371 gboolean has_tooltip,
373 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
374 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
376 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
377 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
379 const gchar *childname);
380 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
383 const GValue *value);
384 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
387 const gchar *tagname,
388 GMarkupParser *parser,
390 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
393 const gchar *tagname,
395 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
396 GtkBuilder *builder);
398 static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
399 static void gtk_widget_real_get_width (GtkSizeRequest *widget,
402 static void gtk_widget_real_get_height (GtkSizeRequest *widget,
406 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
408 static void gtk_widget_set_usize_internal (GtkWidget *widget,
412 static void gtk_widget_add_events_internal (GtkWidget *widget,
416 /* --- variables --- */
417 static gpointer gtk_widget_parent_class = NULL;
418 static guint widget_signals[LAST_SIGNAL] = { 0 };
419 static GtkStyle *gtk_default_style = NULL;
420 static GSList *colormap_stack = NULL;
421 static guint composite_child_stack = 0;
422 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
423 static GParamSpecPool *style_property_spec_pool = NULL;
425 static GQuark quark_property_parser = 0;
426 static GQuark quark_aux_info = 0;
427 static GQuark quark_accel_path = 0;
428 static GQuark quark_accel_closures = 0;
429 static GQuark quark_event_mask = 0;
430 static GQuark quark_device_event_mask = 0;
431 static GQuark quark_extension_event_mode = 0;
432 static GQuark quark_parent_window = 0;
433 static GQuark quark_pointer_window = 0;
434 static GQuark quark_shape_info = 0;
435 static GQuark quark_input_shape_info = 0;
436 static GQuark quark_colormap = 0;
437 static GQuark quark_pango_context = 0;
438 static GQuark quark_rc_style = 0;
439 static GQuark quark_accessible_object = 0;
440 static GQuark quark_mnemonic_labels = 0;
441 static GQuark quark_tooltip_markup = 0;
442 static GQuark quark_has_tooltip = 0;
443 static GQuark quark_tooltip_window = 0;
444 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
445 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
447 /* --- functions --- */
449 gtk_widget_get_type (void)
451 static GType widget_type = 0;
453 if (G_UNLIKELY (widget_type == 0))
455 const GTypeInfo widget_info =
457 sizeof (GtkWidgetClass),
458 NULL, /* base_init */
459 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
460 (GClassInitFunc) gtk_widget_class_init,
461 NULL, /* class_finalize */
462 NULL, /* class_init */
465 (GInstanceInitFunc) gtk_widget_init,
466 NULL, /* value_table */
469 const GInterfaceInfo accessibility_info =
471 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
472 (GInterfaceFinalizeFunc) NULL,
473 NULL /* interface data */
476 const GInterfaceInfo buildable_info =
478 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
479 (GInterfaceFinalizeFunc) NULL,
480 NULL /* interface data */
483 const GInterfaceInfo layout_info =
485 (GInterfaceInitFunc) gtk_widget_size_request_init,
486 (GInterfaceFinalizeFunc) NULL,
487 NULL /* interface data */
490 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
491 &widget_info, G_TYPE_FLAG_ABSTRACT);
493 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
494 &accessibility_info) ;
495 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
497 g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
505 child_property_notify_dispatcher (GObject *object,
509 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
513 gtk_widget_class_init (GtkWidgetClass *klass)
515 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
516 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
517 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
518 GtkBindingSet *binding_set;
520 gtk_widget_parent_class = g_type_class_peek_parent (klass);
522 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
523 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
524 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
525 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
526 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
527 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
528 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
529 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
530 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
531 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
532 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
533 quark_colormap = g_quark_from_static_string ("gtk-colormap");
534 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
535 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
536 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
537 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
538 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
539 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
540 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
542 style_property_spec_pool = g_param_spec_pool_new (FALSE);
543 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
544 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
545 cpn_context.dispatcher = child_property_notify_dispatcher;
546 _gtk_widget_child_property_notify_context = &cpn_context;
548 gobject_class->dispose = gtk_widget_dispose;
549 gobject_class->finalize = gtk_widget_finalize;
550 gobject_class->set_property = gtk_widget_set_property;
551 gobject_class->get_property = gtk_widget_get_property;
553 object_class->destroy = gtk_widget_real_destroy;
555 klass->activate_signal = 0;
556 klass->set_scroll_adjustments_signal = 0;
557 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
558 klass->show = gtk_widget_real_show;
559 klass->show_all = gtk_widget_show;
560 klass->hide = gtk_widget_real_hide;
561 klass->hide_all = gtk_widget_hide;
562 klass->map = gtk_widget_real_map;
563 klass->unmap = gtk_widget_real_unmap;
564 klass->realize = gtk_widget_real_realize;
565 klass->unrealize = gtk_widget_real_unrealize;
566 klass->size_request = gtk_widget_real_size_request;
567 klass->size_allocate = gtk_widget_real_size_allocate;
568 klass->state_changed = NULL;
569 klass->parent_set = NULL;
570 klass->hierarchy_changed = NULL;
571 klass->style_set = gtk_widget_real_style_set;
572 klass->direction_changed = gtk_widget_real_direction_changed;
573 klass->grab_notify = NULL;
574 klass->child_notify = NULL;
575 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
576 klass->grab_focus = gtk_widget_real_grab_focus;
577 klass->focus = gtk_widget_real_focus;
579 klass->button_press_event = NULL;
580 klass->button_release_event = NULL;
581 klass->motion_notify_event = NULL;
582 klass->delete_event = NULL;
583 klass->destroy_event = NULL;
584 klass->expose_event = NULL;
585 klass->key_press_event = gtk_widget_real_key_press_event;
586 klass->key_release_event = gtk_widget_real_key_release_event;
587 klass->enter_notify_event = NULL;
588 klass->leave_notify_event = NULL;
589 klass->configure_event = NULL;
590 klass->focus_in_event = gtk_widget_real_focus_in_event;
591 klass->focus_out_event = gtk_widget_real_focus_out_event;
592 klass->map_event = NULL;
593 klass->unmap_event = NULL;
594 klass->window_state_event = NULL;
595 klass->property_notify_event = _gtk_selection_property_notify;
596 klass->selection_clear_event = _gtk_selection_clear;
597 klass->selection_request_event = _gtk_selection_request;
598 klass->selection_notify_event = _gtk_selection_notify;
599 klass->selection_received = NULL;
600 klass->proximity_in_event = NULL;
601 klass->proximity_out_event = NULL;
602 klass->drag_begin = NULL;
603 klass->drag_end = NULL;
604 klass->drag_data_delete = NULL;
605 klass->drag_leave = NULL;
606 klass->drag_motion = NULL;
607 klass->drag_drop = NULL;
608 klass->drag_data_received = NULL;
609 klass->screen_changed = NULL;
610 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
611 klass->grab_broken_event = NULL;
612 klass->query_tooltip = gtk_widget_real_query_tooltip;
614 klass->show_help = gtk_widget_real_show_help;
616 /* Accessibility support */
617 klass->get_accessible = gtk_widget_real_get_accessible;
619 klass->no_expose_event = NULL;
621 g_object_class_install_property (gobject_class,
623 g_param_spec_string ("name",
625 P_("The name of the widget"),
627 GTK_PARAM_READWRITE));
628 g_object_class_install_property (gobject_class,
630 g_param_spec_object ("parent",
632 P_("The parent widget of this widget. Must be a Container widget"),
634 GTK_PARAM_READWRITE));
636 g_object_class_install_property (gobject_class,
638 g_param_spec_int ("width-request",
640 P_("Override for width request of the widget, or -1 if natural request should be used"),
644 GTK_PARAM_READWRITE));
645 g_object_class_install_property (gobject_class,
647 g_param_spec_int ("height-request",
648 P_("Height request"),
649 P_("Override for height request of the widget, or -1 if natural request should be used"),
653 GTK_PARAM_READWRITE));
654 g_object_class_install_property (gobject_class,
656 g_param_spec_boolean ("visible",
658 P_("Whether the widget is visible"),
660 GTK_PARAM_READWRITE));
661 g_object_class_install_property (gobject_class,
663 g_param_spec_boolean ("sensitive",
665 P_("Whether the widget responds to input"),
667 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
670 g_param_spec_boolean ("app-paintable",
671 P_("Application paintable"),
672 P_("Whether the application will paint directly on the widget"),
674 GTK_PARAM_READWRITE));
675 g_object_class_install_property (gobject_class,
677 g_param_spec_boolean ("can-focus",
679 P_("Whether the widget can accept the input focus"),
681 GTK_PARAM_READWRITE));
682 g_object_class_install_property (gobject_class,
684 g_param_spec_boolean ("has-focus",
686 P_("Whether the widget has the input focus"),
688 GTK_PARAM_READWRITE));
689 g_object_class_install_property (gobject_class,
691 g_param_spec_boolean ("is-focus",
693 P_("Whether the widget is the focus widget within the toplevel"),
695 GTK_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class,
698 g_param_spec_boolean ("can-default",
700 P_("Whether the widget can be the default widget"),
702 GTK_PARAM_READWRITE));
703 g_object_class_install_property (gobject_class,
705 g_param_spec_boolean ("has-default",
707 P_("Whether the widget is the default widget"),
709 GTK_PARAM_READWRITE));
710 g_object_class_install_property (gobject_class,
711 PROP_RECEIVES_DEFAULT,
712 g_param_spec_boolean ("receives-default",
713 P_("Receives default"),
714 P_("If TRUE, the widget will receive the default action when it is focused"),
716 GTK_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class,
718 PROP_COMPOSITE_CHILD,
719 g_param_spec_boolean ("composite-child",
720 P_("Composite child"),
721 P_("Whether the widget is part of a composite widget"),
723 GTK_PARAM_READABLE));
724 g_object_class_install_property (gobject_class,
726 g_param_spec_object ("style",
728 P_("The style of the widget, which contains information about how it will look (colors etc)"),
730 GTK_PARAM_READWRITE));
731 g_object_class_install_property (gobject_class,
733 g_param_spec_flags ("events",
735 P_("The event mask that decides what kind of GdkEvents this widget gets"),
738 GTK_PARAM_READWRITE));
739 g_object_class_install_property (gobject_class,
740 PROP_EXTENSION_EVENTS,
741 g_param_spec_enum ("extension-events",
742 P_("Extension events"),
743 P_("The mask that decides what kind of extension events this widget gets"),
744 GDK_TYPE_EXTENSION_MODE,
745 GDK_EXTENSION_EVENTS_NONE,
746 GTK_PARAM_READWRITE));
747 g_object_class_install_property (gobject_class,
749 g_param_spec_boolean ("no-show-all",
751 P_("Whether gtk_widget_show_all() should not affect this widget"),
753 GTK_PARAM_READWRITE));
756 * GtkWidget:has-tooltip:
758 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
759 * A value of %TRUE indicates that @widget can have a tooltip, in this case
760 * the widget will be queried using #GtkWidget::query-tooltip to determine
761 * whether it will provide a tooltip or not.
763 * Note that setting this property to %TRUE for the first time will change
764 * the event masks of the GdkWindows of this widget to include leave-notify
765 * and motion-notify events. This cannot and will not be undone when the
766 * property is set to %FALSE again.
770 g_object_class_install_property (gobject_class,
772 g_param_spec_boolean ("has-tooltip",
774 P_("Whether this widget has a tooltip"),
776 GTK_PARAM_READWRITE));
778 * GtkWidget:tooltip-text:
780 * Sets the text of tooltip to be the given string.
782 * Also see gtk_tooltip_set_text().
784 * This is a convenience property which will take care of getting the
785 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
786 * will automatically be set to %TRUE and there will be taken care of
787 * #GtkWidget::query-tooltip in the default signal handler.
791 g_object_class_install_property (gobject_class,
793 g_param_spec_string ("tooltip-text",
795 P_("The contents of the tooltip for this widget"),
797 GTK_PARAM_READWRITE));
799 * GtkWidget:tooltip-markup:
801 * Sets the text of tooltip to be the given string, which is marked up
802 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
803 * Also see gtk_tooltip_set_markup().
805 * This is a convenience property which will take care of getting the
806 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
807 * will automatically be set to %TRUE and there will be taken care of
808 * #GtkWidget::query-tooltip in the default signal handler.
812 g_object_class_install_property (gobject_class,
814 g_param_spec_string ("tooltip-markup",
815 P_("Tooltip markup"),
816 P_("The contents of the tooltip for this widget"),
818 GTK_PARAM_READWRITE));
823 * The widget's window if it is realized, %NULL otherwise.
827 g_object_class_install_property (gobject_class,
829 g_param_spec_object ("window",
831 P_("The widget's window if it is realized"),
833 GTK_PARAM_READABLE));
836 * GtkWidget:double-buffered
838 * Whether the widget is double buffered.
842 g_object_class_install_property (gobject_class,
843 PROP_DOUBLE_BUFFERED,
844 g_param_spec_boolean ("double-buffered",
845 P_("Double Buffered"),
846 P_("Whether the widget is double buffered"),
848 GTK_PARAM_READWRITE));
852 * @widget: the object which received the signal.
854 widget_signals[SHOW] =
855 g_signal_new (I_("show"),
856 G_TYPE_FROM_CLASS (gobject_class),
858 G_STRUCT_OFFSET (GtkWidgetClass, show),
860 _gtk_marshal_VOID__VOID,
865 * @widget: the object which received the signal.
867 widget_signals[HIDE] =
868 g_signal_new (I_("hide"),
869 G_TYPE_FROM_CLASS (gobject_class),
871 G_STRUCT_OFFSET (GtkWidgetClass, hide),
873 _gtk_marshal_VOID__VOID,
878 * @widget: the object which received the signal.
880 widget_signals[MAP] =
881 g_signal_new (I_("map"),
882 G_TYPE_FROM_CLASS (gobject_class),
884 G_STRUCT_OFFSET (GtkWidgetClass, map),
886 _gtk_marshal_VOID__VOID,
891 * @widget: the object which received the signal.
893 widget_signals[UNMAP] =
894 g_signal_new (I_("unmap"),
895 G_TYPE_FROM_CLASS (gobject_class),
897 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
899 _gtk_marshal_VOID__VOID,
903 * GtkWidget::realize:
904 * @widget: the object which received the signal.
906 widget_signals[REALIZE] =
907 g_signal_new (I_("realize"),
908 G_TYPE_FROM_CLASS (gobject_class),
910 G_STRUCT_OFFSET (GtkWidgetClass, realize),
912 _gtk_marshal_VOID__VOID,
916 * GtkWidget::unrealize:
917 * @widget: the object which received the signal.
919 widget_signals[UNREALIZE] =
920 g_signal_new (I_("unrealize"),
921 G_TYPE_FROM_CLASS (gobject_class),
923 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
925 _gtk_marshal_VOID__VOID,
929 * GtkWidget::size-request:
930 * @widget: the object which received the signal.
933 widget_signals[SIZE_REQUEST] =
934 g_signal_new (I_("size-request"),
935 G_TYPE_FROM_CLASS (gobject_class),
937 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
939 _gtk_marshal_VOID__BOXED,
941 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
944 * GtkWidget::size-allocate:
945 * @widget: the object which received the signal.
948 widget_signals[SIZE_ALLOCATE] =
949 g_signal_new (I_("size-allocate"),
950 G_TYPE_FROM_CLASS (gobject_class),
952 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
954 _gtk_marshal_VOID__BOXED,
956 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
959 * GtkWidget::state-changed:
960 * @widget: the object which received the signal.
961 * @state: the previous state
963 * The ::state-changed signal is emitted when the widget state changes.
964 * See gtk_widget_get_state().
966 widget_signals[STATE_CHANGED] =
967 g_signal_new (I_("state-changed"),
968 G_TYPE_FROM_CLASS (gobject_class),
970 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
972 _gtk_marshal_VOID__ENUM,
974 GTK_TYPE_STATE_TYPE);
977 * GtkWidget::parent-set:
978 * @widget: the object on which the signal is emitted
979 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
980 * just got its initial parent.
982 * The ::parent-set signal is emitted when a new parent
983 * has been set on a widget.
985 widget_signals[PARENT_SET] =
986 g_signal_new (I_("parent-set"),
987 G_TYPE_FROM_CLASS (gobject_class),
989 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
991 _gtk_marshal_VOID__OBJECT,
996 * GtkWidget::hierarchy-changed:
997 * @widget: the object on which the signal is emitted
998 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
999 * if the widget was previously unanchored
1001 * The ::hierarchy-changed signal is emitted when the
1002 * anchored state of a widget changes. A widget is
1003 * <firstterm>anchored</firstterm> when its toplevel
1004 * ancestor is a #GtkWindow. This signal is emitted when
1005 * a widget changes from un-anchored to anchored or vice-versa.
1007 widget_signals[HIERARCHY_CHANGED] =
1008 g_signal_new (I_("hierarchy-changed"),
1009 G_TYPE_FROM_CLASS (gobject_class),
1011 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1013 _gtk_marshal_VOID__OBJECT,
1018 * GtkWidget::style-set:
1019 * @widget: the object on which the signal is emitted
1020 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1021 * just got its initial style
1023 * The ::style-set signal is emitted when a new style has been set
1024 * on a widget. Note that style-modifying functions like
1025 * gtk_widget_modify_base() also cause this signal to be emitted.
1027 widget_signals[STYLE_SET] =
1028 g_signal_new (I_("style-set"),
1029 G_TYPE_FROM_CLASS (gobject_class),
1031 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1033 _gtk_marshal_VOID__OBJECT,
1037 * GtkWidget::direction-changed:
1038 * @widget: the object on which the signal is emitted
1039 * @previous_direction: the previous text direction of @widget
1041 * The ::direction-changed signal is emitted when the text direction
1042 * of a widget changes.
1044 widget_signals[DIRECTION_CHANGED] =
1045 g_signal_new (I_("direction-changed"),
1046 G_TYPE_FROM_CLASS (gobject_class),
1048 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1050 _gtk_marshal_VOID__ENUM,
1052 GTK_TYPE_TEXT_DIRECTION);
1055 * GtkWidget::grab-notify:
1056 * @widget: the object which received the signal
1057 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1058 * if it becomes unshadowed
1060 * The ::grab-notify signal is emitted when a widget becomes
1061 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1062 * another widget, or when it becomes unshadowed due to a grab
1065 * A widget is shadowed by a gtk_grab_add() when the topmost
1066 * grab widget in the grab stack of its window group is not
1069 widget_signals[GRAB_NOTIFY] =
1070 g_signal_new (I_("grab-notify"),
1071 G_TYPE_FROM_CLASS (gobject_class),
1073 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1075 _gtk_marshal_VOID__BOOLEAN,
1080 * GtkWidget::child-notify:
1081 * @widget: the object which received the signal
1082 * @pspec: the #GParamSpec of the changed child property
1084 * The ::child-notify signal is emitted for each
1085 * <link linkend="child-properties">child property</link> that has
1086 * changed on an object. The signal's detail holds the property name.
1088 widget_signals[CHILD_NOTIFY] =
1089 g_signal_new (I_("child-notify"),
1090 G_TYPE_FROM_CLASS (gobject_class),
1091 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1092 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1094 g_cclosure_marshal_VOID__PARAM,
1099 * GtkWidget::mnemonic-activate:
1100 * @widget: the object which received the signal.
1103 widget_signals[MNEMONIC_ACTIVATE] =
1104 g_signal_new (I_("mnemonic-activate"),
1105 G_TYPE_FROM_CLASS (gobject_class),
1107 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1108 _gtk_boolean_handled_accumulator, NULL,
1109 _gtk_marshal_BOOLEAN__BOOLEAN,
1114 * GtkWidget::grab-focus:
1115 * @widget: the object which received the signal.
1117 widget_signals[GRAB_FOCUS] =
1118 g_signal_new (I_("grab-focus"),
1119 G_TYPE_FROM_CLASS (gobject_class),
1120 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1121 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1123 _gtk_marshal_VOID__VOID,
1128 * @widget: the object which received the signal.
1131 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1133 widget_signals[FOCUS] =
1134 g_signal_new (I_("focus"),
1135 G_TYPE_FROM_CLASS (object_class),
1137 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1138 _gtk_boolean_handled_accumulator, NULL,
1139 _gtk_marshal_BOOLEAN__ENUM,
1141 GTK_TYPE_DIRECTION_TYPE);
1144 * GtkWidget::move-focus:
1145 * @widget: the object which received the signal.
1148 widget_signals[MOVE_FOCUS] =
1149 g_signal_new_class_handler (I_("move-focus"),
1150 G_TYPE_FROM_CLASS (object_class),
1151 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1152 G_CALLBACK (gtk_widget_real_move_focus),
1154 _gtk_marshal_VOID__ENUM,
1157 GTK_TYPE_DIRECTION_TYPE);
1160 * @widget: the object which received the signal.
1161 * @event: the #GdkEvent which triggered this signal
1163 * The GTK+ main loop will emit three signals for each GDK event delivered
1164 * to a widget: one generic ::event signal, another, more specific,
1165 * signal that matches the type of event delivered (e.g.
1166 * #GtkWidget::key-press-event) and finally a generic
1167 * #GtkWidget::event-after signal.
1169 * Returns: %TRUE to stop other handlers from being invoked for the event
1170 * and to cancel the emission of the second specific ::event signal.
1171 * %FALSE to propagate the event further and to allow the emission of
1172 * the second signal. The ::event-after signal is emitted regardless of
1175 widget_signals[EVENT] =
1176 g_signal_new (I_("event"),
1177 G_TYPE_FROM_CLASS (gobject_class),
1179 G_STRUCT_OFFSET (GtkWidgetClass, event),
1180 _gtk_boolean_handled_accumulator, NULL,
1181 _gtk_marshal_BOOLEAN__BOXED,
1183 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1186 * GtkWidget::event-after:
1187 * @widget: the object which received the signal.
1188 * @event: the #GdkEvent which triggered this signal
1190 * After the emission of the #GtkWidget::event signal and (optionally)
1191 * the second more specific signal, ::event-after will be emitted
1192 * regardless of the previous two signals handlers return values.
1195 widget_signals[EVENT_AFTER] =
1196 g_signal_new (I_("event-after"),
1197 G_TYPE_FROM_CLASS (gobject_class),
1201 _gtk_marshal_VOID__BOXED,
1203 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1206 * GtkWidget::button-press-event:
1207 * @widget: the object which received the signal.
1208 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1211 * The ::button-press-event signal will be emitted when a button
1212 * (typically from a mouse) is pressed.
1214 * To receive this signal, the #GdkWindow associated to the
1215 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1217 * This signal will be sent to the grab widget if there is one.
1219 * Returns: %TRUE to stop other handlers from being invoked for the event.
1220 * %FALSE to propagate the event further.
1222 widget_signals[BUTTON_PRESS_EVENT] =
1223 g_signal_new (I_("button-press-event"),
1224 G_TYPE_FROM_CLASS (gobject_class),
1226 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1227 _gtk_boolean_handled_accumulator, NULL,
1228 _gtk_marshal_BOOLEAN__BOXED,
1230 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1233 * GtkWidget::button-release-event:
1234 * @widget: the object which received the signal.
1235 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1238 * The ::button-release-event signal will be emitted when a button
1239 * (typically from a mouse) is released.
1241 * To receive this signal, the #GdkWindow associated to the
1242 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1244 * This signal will be sent to the grab widget if there is one.
1246 * Returns: %TRUE to stop other handlers from being invoked for the event.
1247 * %FALSE to propagate the event further.
1249 widget_signals[BUTTON_RELEASE_EVENT] =
1250 g_signal_new (I_("button-release-event"),
1251 G_TYPE_FROM_CLASS (gobject_class),
1253 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1254 _gtk_boolean_handled_accumulator, NULL,
1255 _gtk_marshal_BOOLEAN__BOXED,
1257 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1260 * GtkWidget::scroll-event:
1261 * @widget: the object which received the signal.
1262 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1265 * The ::scroll-event signal is emitted when a button in the 4 to 7
1266 * range is pressed. Wheel mice are usually configured to generate
1267 * button press events for buttons 4 and 5 when the wheel is turned.
1269 * To receive this signal, the #GdkWindow associated to the widget needs
1270 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1272 * This signal will be sent to the grab widget if there is one.
1274 * Returns: %TRUE to stop other handlers from being invoked for the event.
1275 * %FALSE to propagate the event further.
1277 widget_signals[SCROLL_EVENT] =
1278 g_signal_new (I_("scroll-event"),
1279 G_TYPE_FROM_CLASS (gobject_class),
1281 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1282 _gtk_boolean_handled_accumulator, NULL,
1283 _gtk_marshal_BOOLEAN__BOXED,
1285 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1287 * GtkWidget::motion-notify-event:
1288 * @widget: the object which received the signal.
1289 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1292 * The ::motion-notify-event signal is emitted when the pointer moves
1293 * over the widget's #GdkWindow.
1295 * To receive this signal, the #GdkWindow associated to the widget
1296 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1298 * This signal will be sent to the grab widget if there is one.
1300 * Returns: %TRUE to stop other handlers from being invoked for the event.
1301 * %FALSE to propagate the event further.
1303 widget_signals[MOTION_NOTIFY_EVENT] =
1304 g_signal_new (I_("motion-notify-event"),
1305 G_TYPE_FROM_CLASS (gobject_class),
1307 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1308 _gtk_boolean_handled_accumulator, NULL,
1309 _gtk_marshal_BOOLEAN__BOXED,
1311 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1314 * GtkWidget::composited-changed:
1315 * @widget: the object on which the signal is emitted
1317 * The ::composited-changed signal is emitted when the composited
1318 * status of @widget<!-- -->s screen changes.
1319 * See gdk_screen_is_composited().
1321 widget_signals[COMPOSITED_CHANGED] =
1322 g_signal_new (I_("composited-changed"),
1323 G_TYPE_FROM_CLASS (gobject_class),
1324 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1325 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1327 _gtk_marshal_VOID__VOID,
1331 * GtkWidget::keynav-failed:
1332 * @widget: the object which received the signal
1333 * @direction: the direction of movement
1335 * Gets emitted if keyboard navigation fails.
1336 * See gtk_widget_keynav_failed() for details.
1338 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1339 * if the emitting widget should try to handle the keyboard
1340 * navigation attempt in its parent container(s).
1344 widget_signals[KEYNAV_FAILED] =
1345 g_signal_new_class_handler (I_("keynav-failed"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_CALLBACK (gtk_widget_real_keynav_failed),
1349 _gtk_boolean_handled_accumulator, NULL,
1350 _gtk_marshal_BOOLEAN__ENUM,
1352 GTK_TYPE_DIRECTION_TYPE);
1355 * GtkWidget::delete-event:
1356 * @widget: the object which received the signal
1357 * @event: the event which triggered this signal
1359 * The ::delete-event signal is emitted if a user requests that
1360 * a toplevel window is closed. The default handler for this signal
1361 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1362 * this signal will cause the window to be hidden instead, so that
1363 * it can later be shown again without reconstructing it.
1365 * Returns: %TRUE to stop other handlers from being invoked for the event.
1366 * %FALSE to propagate the event further.
1368 widget_signals[DELETE_EVENT] =
1369 g_signal_new (I_("delete-event"),
1370 G_TYPE_FROM_CLASS (gobject_class),
1372 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1373 _gtk_boolean_handled_accumulator, NULL,
1374 _gtk_marshal_BOOLEAN__BOXED,
1376 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1379 * GtkWidget::destroy-event:
1380 * @widget: the object which received the signal.
1381 * @event: the event which triggered this signal
1383 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1384 * You rarely get this signal, because most widgets disconnect themselves
1385 * from their window before they destroy it, so no widget owns the
1386 * window at destroy time.
1388 * To receive this signal, the #GdkWindow associated to the widget needs
1389 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1390 * automatically for all new windows.
1392 * Returns: %TRUE to stop other handlers from being invoked for the event.
1393 * %FALSE to propagate the event further.
1395 widget_signals[DESTROY_EVENT] =
1396 g_signal_new (I_("destroy-event"),
1397 G_TYPE_FROM_CLASS (gobject_class),
1399 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1400 _gtk_boolean_handled_accumulator, NULL,
1401 _gtk_marshal_BOOLEAN__BOXED,
1403 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1406 * GtkWidget::expose-event:
1407 * @widget: the object which received the signal.
1408 * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
1411 * The ::expose-event signal is emitted when an area of a previously
1412 * obscured #GdkWindow is made visible and needs to be redrawn.
1413 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1416 * To receive this signal, the #GdkWindow associated to the widget needs
1417 * to enable the #GDK_EXPOSURE_MASK mask.
1419 * Returns: %TRUE to stop other handlers from being invoked for the event.
1420 * %FALSE to propagate the event further.
1422 widget_signals[EXPOSE_EVENT] =
1423 g_signal_new (I_("expose-event"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1427 _gtk_boolean_handled_accumulator, NULL,
1428 _gtk_marshal_BOOLEAN__BOXED,
1430 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1433 * GtkWidget::key-press-event:
1434 * @widget: the object which received the signal
1435 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1437 * The ::key-press-event signal is emitted when a key is pressed.
1439 * To receive this signal, the #GdkWindow associated to the widget needs
1440 * to enable the #GDK_KEY_PRESS_MASK mask.
1442 * This signal will be sent to the grab widget if there is one.
1444 * Returns: %TRUE to stop other handlers from being invoked for the event.
1445 * %FALSE to propagate the event further.
1447 widget_signals[KEY_PRESS_EVENT] =
1448 g_signal_new (I_("key-press-event"),
1449 G_TYPE_FROM_CLASS (gobject_class),
1451 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1452 _gtk_boolean_handled_accumulator, NULL,
1453 _gtk_marshal_BOOLEAN__BOXED,
1455 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1458 * GtkWidget::key-release-event:
1459 * @widget: the object which received the signal
1460 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1462 * The ::key-release-event signal is emitted when a key is pressed.
1464 * To receive this signal, the #GdkWindow associated to the widget needs
1465 * to enable the #GDK_KEY_RELEASE_MASK mask.
1467 * This signal will be sent to the grab widget if there is one.
1469 * Returns: %TRUE to stop other handlers from being invoked for the event.
1470 * %FALSE to propagate the event further.
1472 widget_signals[KEY_RELEASE_EVENT] =
1473 g_signal_new (I_("key-release-event"),
1474 G_TYPE_FROM_CLASS (gobject_class),
1476 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1477 _gtk_boolean_handled_accumulator, NULL,
1478 _gtk_marshal_BOOLEAN__BOXED,
1480 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1483 * GtkWidget::enter-notify-event:
1484 * @widget: the object which received the signal
1485 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1488 * The ::enter-notify-event will be emitted when the pointer enters
1489 * the @widget's window.
1491 * To receive this signal, the #GdkWindow associated to the widget needs
1492 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1494 * This signal will be sent to the grab widget if there is one.
1496 * Returns: %TRUE to stop other handlers from being invoked for the event.
1497 * %FALSE to propagate the event further.
1499 widget_signals[ENTER_NOTIFY_EVENT] =
1500 g_signal_new (I_("enter-notify-event"),
1501 G_TYPE_FROM_CLASS (gobject_class),
1503 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1504 _gtk_boolean_handled_accumulator, NULL,
1505 _gtk_marshal_BOOLEAN__BOXED,
1507 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1510 * GtkWidget::leave-notify-event:
1511 * @widget: the object which received the signal
1512 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1515 * The ::leave-notify-event will be emitted when the pointer leaves
1516 * the @widget's window.
1518 * To receive this signal, the #GdkWindow associated to the widget needs
1519 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1521 * This signal will be sent to the grab widget if there is one.
1523 * Returns: %TRUE to stop other handlers from being invoked for the event.
1524 * %FALSE to propagate the event further.
1526 widget_signals[LEAVE_NOTIFY_EVENT] =
1527 g_signal_new (I_("leave-notify-event"),
1528 G_TYPE_FROM_CLASS (gobject_class),
1530 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1531 _gtk_boolean_handled_accumulator, NULL,
1532 _gtk_marshal_BOOLEAN__BOXED,
1534 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1537 * GtkWidget::configure-event
1538 * @widget: the object which received the signal
1539 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1542 * The ::configure-event signal will be emitted when the size, position or
1543 * stacking of the @widget's window has changed.
1545 * To receive this signal, the #GdkWindow associated to the widget needs
1546 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1547 * automatically for all new windows.
1549 * Returns: %TRUE to stop other handlers from being invoked for the event.
1550 * %FALSE to propagate the event further.
1552 widget_signals[CONFIGURE_EVENT] =
1553 g_signal_new (I_("configure-event"),
1554 G_TYPE_FROM_CLASS (gobject_class),
1556 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1557 _gtk_boolean_handled_accumulator, NULL,
1558 _gtk_marshal_BOOLEAN__BOXED,
1560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1563 * GtkWidget::focus-in-event
1564 * @widget: the object which received the signal
1565 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1568 * The ::focus-in-event signal will be emitted when the keyboard focus
1569 * enters the @widget's window.
1571 * To receive this signal, the #GdkWindow associated to the widget needs
1572 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1574 * Returns: %TRUE to stop other handlers from being invoked for the event.
1575 * %FALSE to propagate the event further.
1577 widget_signals[FOCUS_IN_EVENT] =
1578 g_signal_new (I_("focus-in-event"),
1579 G_TYPE_FROM_CLASS (gobject_class),
1581 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1582 _gtk_boolean_handled_accumulator, NULL,
1583 _gtk_marshal_BOOLEAN__BOXED,
1585 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1588 * GtkWidget::focus-out-event
1589 * @widget: the object which received the signal
1590 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1593 * The ::focus-out-event signal will be emitted when the keyboard focus
1594 * leaves the @widget's window.
1596 * To receive this signal, the #GdkWindow associated to the widget needs
1597 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1599 * Returns: %TRUE to stop other handlers from being invoked for the event.
1600 * %FALSE to propagate the event further.
1602 widget_signals[FOCUS_OUT_EVENT] =
1603 g_signal_new (I_("focus-out-event"),
1604 G_TYPE_FROM_CLASS (gobject_class),
1606 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1607 _gtk_boolean_handled_accumulator, NULL,
1608 _gtk_marshal_BOOLEAN__BOXED,
1610 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1613 * GtkWidget::map-event
1614 * @widget: the object which received the signal
1615 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1617 * The ::map-event signal will be emitted when the @widget's window is
1618 * mapped. A window is mapped when it becomes visible on the screen.
1620 * To receive this signal, the #GdkWindow associated to the widget needs
1621 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1622 * automatically for all new windows.
1624 * Returns: %TRUE to stop other handlers from being invoked for the event.
1625 * %FALSE to propagate the event further.
1627 widget_signals[MAP_EVENT] =
1628 g_signal_new (I_("map-event"),
1629 G_TYPE_FROM_CLASS (gobject_class),
1631 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1632 _gtk_boolean_handled_accumulator, NULL,
1633 _gtk_marshal_BOOLEAN__BOXED,
1635 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1638 * GtkWidget::unmap-event
1639 * @widget: the object which received the signal
1640 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1642 * The ::unmap-event signal may be emitted when the @widget's window is
1643 * unmapped. A window is unmapped when it becomes invisible on the screen.
1645 * For performance reasons GTK+ may not emit ::unmap-event, so one
1646 * should always also implement ::unrealize in order to release
1647 * resources and disconnect signal handlers.
1649 * To receive this signal, the #GdkWindow associated to the widget needs
1650 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1651 * automatically for all new windows.
1653 * Returns: %TRUE to stop other handlers from being invoked for the event.
1654 * %FALSE to propagate the event further.
1656 widget_signals[UNMAP_EVENT] =
1657 g_signal_new (I_("unmap-event"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1661 _gtk_boolean_handled_accumulator, NULL,
1662 _gtk_marshal_BOOLEAN__BOXED,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkWidget::property-notify-event
1668 * @widget: the object which received the signal
1669 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1672 * The ::property-notify-event signal will be emitted when a property on
1673 * the @widget's window has been changed or deleted.
1675 * To receive this signal, the #GdkWindow associated to the widget needs
1676 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1678 * Returns: %TRUE to stop other handlers from being invoked for the event.
1679 * %FALSE to propagate the event further.
1681 widget_signals[PROPERTY_NOTIFY_EVENT] =
1682 g_signal_new (I_("property-notify-event"),
1683 G_TYPE_FROM_CLASS (gobject_class),
1685 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1686 _gtk_boolean_handled_accumulator, NULL,
1687 _gtk_marshal_BOOLEAN__BOXED,
1689 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1692 * GtkWidget::selection-clear-event
1693 * @widget: the object which received the signal
1694 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1697 * The ::selection-clear-event signal will be emitted when the
1698 * the @widget's window has lost ownership of a selection.
1700 * Returns: %TRUE to stop other handlers from being invoked for the event.
1701 * %FALSE to propagate the event further.
1703 widget_signals[SELECTION_CLEAR_EVENT] =
1704 g_signal_new (I_("selection-clear-event"),
1705 G_TYPE_FROM_CLASS (gobject_class),
1707 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1708 _gtk_boolean_handled_accumulator, NULL,
1709 _gtk_marshal_BOOLEAN__BOXED,
1711 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1714 * GtkWidget::selection-request-event
1715 * @widget: the object which received the signal
1716 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1719 * The ::selection-request-event signal will be emitted when
1720 * another client requests ownership of the selection owned by
1721 * the @widget's window.
1723 * Returns: %TRUE to stop other handlers from being invoked for the event.
1724 * %FALSE to propagate the event further.
1726 widget_signals[SELECTION_REQUEST_EVENT] =
1727 g_signal_new (I_("selection-request-event"),
1728 G_TYPE_FROM_CLASS (gobject_class),
1730 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1731 _gtk_boolean_handled_accumulator, NULL,
1732 _gtk_marshal_BOOLEAN__BOXED,
1734 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1737 * GtkWidget::selection-notify-event:
1738 * @widget: the object which received the signal.
1741 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1743 widget_signals[SELECTION_NOTIFY_EVENT] =
1744 g_signal_new (I_("selection-notify-event"),
1745 G_TYPE_FROM_CLASS (gobject_class),
1747 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1748 _gtk_boolean_handled_accumulator, NULL,
1749 _gtk_marshal_BOOLEAN__BOXED,
1751 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1754 * GtkWidget::selection-received:
1755 * @widget: the object which received the signal.
1759 widget_signals[SELECTION_RECEIVED] =
1760 g_signal_new (I_("selection-received"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1763 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1765 _gtk_marshal_VOID__BOXED_UINT,
1767 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1771 * GtkWidget::selection-get:
1772 * @widget: the object which received the signal.
1777 widget_signals[SELECTION_GET] =
1778 g_signal_new (I_("selection-get"),
1779 G_TYPE_FROM_CLASS (gobject_class),
1781 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1783 _gtk_marshal_VOID__BOXED_UINT_UINT,
1785 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1790 * GtkWidget::proximity-in-event
1791 * @widget: the object which received the signal
1792 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1795 * To receive this signal the #GdkWindow associated to the widget needs
1796 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1798 * This signal will be sent to the grab widget if there is one.
1800 * Returns: %TRUE to stop other handlers from being invoked for the event.
1801 * %FALSE to propagate the event further.
1803 widget_signals[PROXIMITY_IN_EVENT] =
1804 g_signal_new (I_("proximity-in-event"),
1805 G_TYPE_FROM_CLASS (gobject_class),
1807 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 _gtk_marshal_BOOLEAN__BOXED,
1811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1814 * GtkWidget::proximity-out-event
1815 * @widget: the object which received the signal
1816 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1819 * To receive this signal the #GdkWindow associated to the widget needs
1820 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1822 * This signal will be sent to the grab widget if there is one.
1824 * Returns: %TRUE to stop other handlers from being invoked for the event.
1825 * %FALSE to propagate the event further.
1827 widget_signals[PROXIMITY_OUT_EVENT] =
1828 g_signal_new (I_("proximity-out-event"),
1829 G_TYPE_FROM_CLASS (gobject_class),
1831 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1832 _gtk_boolean_handled_accumulator, NULL,
1833 _gtk_marshal_BOOLEAN__BOXED,
1835 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1838 * GtkWidget::drag-leave:
1839 * @widget: the object which received the signal.
1840 * @drag_context: the drag context
1841 * @time: the timestamp of the motion event
1843 * The ::drag-leave signal is emitted on the drop site when the cursor
1844 * leaves the widget. A typical reason to connect to this signal is to
1845 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1846 * with gtk_drag_unhighlight()
1848 widget_signals[DRAG_LEAVE] =
1849 g_signal_new (I_("drag-leave"),
1850 G_TYPE_FROM_CLASS (gobject_class),
1852 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1854 _gtk_marshal_VOID__OBJECT_UINT,
1856 GDK_TYPE_DRAG_CONTEXT,
1860 * GtkWidget::drag-begin:
1861 * @widget: the object which received the signal
1862 * @drag_context: the drag context
1864 * The ::drag-begin signal is emitted on the drag source when a drag is
1865 * started. A typical reason to connect to this signal is to set up a
1866 * custom drag icon with gtk_drag_source_set_icon().
1868 * Note that some widgets set up a drag icon in the default handler of
1869 * this signal, so you may have to use g_signal_connect_after() to
1870 * override what the default handler did.
1872 widget_signals[DRAG_BEGIN] =
1873 g_signal_new (I_("drag-begin"),
1874 G_TYPE_FROM_CLASS (gobject_class),
1876 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1878 _gtk_marshal_VOID__OBJECT,
1880 GDK_TYPE_DRAG_CONTEXT);
1883 * GtkWidget::drag-end:
1884 * @widget: the object which received the signal
1885 * @drag_context: the drag context
1887 * The ::drag-end signal is emitted on the drag source when a drag is
1888 * finished. A typical reason to connect to this signal is to undo
1889 * things done in #GtkWidget::drag-begin.
1891 widget_signals[DRAG_END] =
1892 g_signal_new (I_("drag-end"),
1893 G_TYPE_FROM_CLASS (gobject_class),
1895 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1897 _gtk_marshal_VOID__OBJECT,
1899 GDK_TYPE_DRAG_CONTEXT);
1902 * GtkWidget::drag-data-delete:
1903 * @widget: the object which received the signal
1904 * @drag_context: the drag context
1906 * The ::drag-data-delete signal is emitted on the drag source when a drag
1907 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1908 * handler is responsible for deleting the data that has been dropped. What
1909 * "delete" means depends on the context of the drag operation.
1911 widget_signals[DRAG_DATA_DELETE] =
1912 g_signal_new (I_("drag-data-delete"),
1913 G_TYPE_FROM_CLASS (gobject_class),
1915 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1917 _gtk_marshal_VOID__OBJECT,
1919 GDK_TYPE_DRAG_CONTEXT);
1922 * GtkWidget::drag-failed:
1923 * @widget: the object which received the signal
1924 * @drag_context: the drag context
1925 * @result: the result of the drag operation
1927 * The ::drag-failed signal is emitted on the drag source when a drag has
1928 * failed. The signal handler may hook custom code to handle a failed DND
1929 * operation based on the type of error, it returns %TRUE is the failure has
1930 * been already handled (not showing the default "drag operation failed"
1931 * animation), otherwise it returns %FALSE.
1933 * Return value: %TRUE if the failed drag operation has been already handled.
1937 widget_signals[DRAG_FAILED] =
1938 g_signal_new (I_("drag-failed"),
1939 G_TYPE_FROM_CLASS (gobject_class),
1941 0, _gtk_boolean_handled_accumulator, NULL,
1942 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1944 GDK_TYPE_DRAG_CONTEXT,
1945 GTK_TYPE_DRAG_RESULT);
1948 * GtkWidget::drag-motion:
1949 * @widget: the object which received the signal
1950 * @drag_context: the drag context
1951 * @x: the x coordinate of the current cursor position
1952 * @y: the y coordinate of the current cursor position
1953 * @time: the timestamp of the motion event
1954 * @returns: whether the cursor position is in a drop zone
1956 * The drag-motion signal is emitted on the drop site when the user
1957 * moves the cursor over the widget during a drag. The signal handler
1958 * must determine whether the cursor position is in a drop zone or not.
1959 * If it is not in a drop zone, it returns %FALSE and no further processing
1960 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1961 * handler is responsible for providing the necessary information for
1962 * displaying feedback to the user, by calling gdk_drag_status().
1964 * If the decision whether the drop will be accepted or rejected can't be
1965 * made based solely on the cursor position and the type of the data, the
1966 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1967 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1968 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1969 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1970 * when using the drag-motion signal that way.
1972 * Also note that there is no drag-enter signal. The drag receiver has to
1973 * keep track of whether he has received any drag-motion signals since the
1974 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1975 * an "enter" signal. Upon an "enter", the handler will typically highlight
1976 * the drop site with gtk_drag_highlight().
1979 * drag_motion (GtkWidget *widget,
1980 * GdkDragContext *context,
1987 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1989 * if (!private_data->drag_highlight)
1991 * private_data->drag_highlight = 1;
1992 * gtk_drag_highlight (widget);
1995 * target = gtk_drag_dest_find_target (widget, context, NULL);
1996 * if (target == GDK_NONE)
1997 * gdk_drag_status (context, 0, time);
2000 * private_data->pending_status = context->suggested_action;
2001 * gtk_drag_get_data (widget, context, target, time);
2008 * drag_data_received (GtkWidget *widget,
2009 * GdkDragContext *context,
2012 * GtkSelectionData *selection_data,
2016 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2018 * if (private_data->suggested_action)
2020 * private_data->suggested_action = 0;
2022 * /* We are getting this data due to a request in drag_motion,
2023 * * rather than due to a request in drag_drop, so we are just
2024 * * supposed to call gdk_drag_status (), not actually paste in
2027 * str = gtk_selection_data_get_text (selection_data);
2028 * if (!data_is_acceptable (str))
2029 * gdk_drag_status (context, 0, time);
2031 * gdk_drag_status (context, private_data->suggested_action, time);
2035 * /* accept the drop */
2040 widget_signals[DRAG_MOTION] =
2041 g_signal_new (I_("drag-motion"),
2042 G_TYPE_FROM_CLASS (gobject_class),
2044 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2045 _gtk_boolean_handled_accumulator, NULL,
2046 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2048 GDK_TYPE_DRAG_CONTEXT,
2054 * GtkWidget::drag-drop:
2055 * @widget: the object which received the signal
2056 * @drag_context: the drag context
2057 * @x: the x coordinate of the current cursor position
2058 * @y: the y coordinate of the current cursor position
2059 * @time: the timestamp of the motion event
2060 * @returns: whether the cursor position is in a drop zone
2062 * The ::drag-drop signal is emitted on the drop site when the user drops
2063 * the data onto the widget. The signal handler must determine whether
2064 * the cursor position is in a drop zone or not. If it is not in a drop
2065 * zone, it returns %FALSE and no further processing is necessary.
2066 * Otherwise, the handler returns %TRUE. In this case, the handler must
2067 * ensure that gtk_drag_finish() is called to let the source know that
2068 * the drop is done. The call to gtk_drag_finish() can be done either
2069 * directly or in a #GtkWidget::drag-data-received handler which gets
2070 * triggered by calling gtk_drag_get_data() to receive the data for one
2071 * or more of the supported targets.
2073 widget_signals[DRAG_DROP] =
2074 g_signal_new (I_("drag-drop"),
2075 G_TYPE_FROM_CLASS (gobject_class),
2077 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2078 _gtk_boolean_handled_accumulator, NULL,
2079 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2081 GDK_TYPE_DRAG_CONTEXT,
2087 * GtkWidget::drag-data-get:
2088 * @widget: the object which received the signal
2089 * @drag_context: the drag context
2090 * @data: the #GtkSelectionData to be filled with the dragged data
2091 * @info: the info that has been registered with the target in the
2093 * @time: the timestamp at which the data was requested
2095 * The ::drag-data-get signal is emitted on the drag source when the drop
2096 * site requests the data which is dragged. It is the responsibility of
2097 * the signal handler to fill @data with the data in the format which
2098 * is indicated by @info. See gtk_selection_data_set() and
2099 * gtk_selection_data_set_text().
2101 widget_signals[DRAG_DATA_GET] =
2102 g_signal_new (I_("drag-data-get"),
2103 G_TYPE_FROM_CLASS (gobject_class),
2105 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2107 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2109 GDK_TYPE_DRAG_CONTEXT,
2110 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2115 * GtkWidget::drag-data-received:
2116 * @widget: the object which received the signal
2117 * @drag_context: the drag context
2118 * @x: where the drop happened
2119 * @y: where the drop happened
2120 * @data: the received data
2121 * @info: the info that has been registered with the target in the
2123 * @time: the timestamp at which the data was received
2125 * The ::drag-data-received signal is emitted on the drop site when the
2126 * dragged data has been received. If the data was received in order to
2127 * determine whether the drop will be accepted, the handler is expected
2128 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2129 * If the data was received in response to a #GtkWidget::drag-drop signal
2130 * (and this is the last target to be received), the handler for this
2131 * signal is expected to process the received data and then call
2132 * gtk_drag_finish(), setting the @success parameter depending on whether
2133 * the data was processed successfully.
2135 * The handler may inspect and modify @drag_context->action before calling
2136 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2137 * following example:
2140 * drag_data_received (GtkWidget *widget,
2141 * GdkDragContext *drag_context,
2144 * GtkSelectionData *data,
2148 * if ((data->length >= 0) && (data->format == 8))
2150 * if (drag_context->action == GDK_ACTION_ASK)
2152 * GtkWidget *dialog;
2155 * dialog = gtk_message_dialog_new (NULL,
2156 * GTK_DIALOG_MODAL |
2157 * GTK_DIALOG_DESTROY_WITH_PARENT,
2159 * GTK_BUTTONS_YES_NO,
2160 * "Move the data ?\n");
2161 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2162 * gtk_widget_destroy (dialog);
2164 * if (response == GTK_RESPONSE_YES)
2165 * drag_context->action = GDK_ACTION_MOVE;
2167 * drag_context->action = GDK_ACTION_COPY;
2170 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2174 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2178 widget_signals[DRAG_DATA_RECEIVED] =
2179 g_signal_new (I_("drag-data-received"),
2180 G_TYPE_FROM_CLASS (gobject_class),
2182 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2184 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2186 GDK_TYPE_DRAG_CONTEXT,
2189 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2194 * GtkWidget::visibility-notify-event:
2195 * @widget: the object which received the signal
2196 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2197 * triggered this signal.
2199 * The ::visibility-notify-event will be emitted when the @widget's window
2200 * is obscured or unobscured.
2202 * To receive this signal the #GdkWindow associated to the widget needs
2203 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2205 * Returns: %TRUE to stop other handlers from being invoked for the event.
2206 * %FALSE to propagate the event further.
2208 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2209 g_signal_new (I_("visibility-notify-event"),
2210 G_TYPE_FROM_CLASS (gobject_class),
2212 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2213 _gtk_boolean_handled_accumulator, NULL,
2214 _gtk_marshal_BOOLEAN__BOXED,
2216 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2219 * GtkWidget::client-event:
2220 * @widget: the object which received the signal
2221 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2224 * The ::client-event will be emitted when the @widget's window
2225 * receives a message (via a ClientMessage event) from another
2228 * Returns: %TRUE to stop other handlers from being invoked for
2229 * the event. %FALSE to propagate the event further.
2231 widget_signals[CLIENT_EVENT] =
2232 g_signal_new (I_("client-event"),
2233 G_TYPE_FROM_CLASS (gobject_class),
2235 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2236 _gtk_boolean_handled_accumulator, NULL,
2237 _gtk_marshal_BOOLEAN__BOXED,
2239 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 * GtkWidget::no-expose-event:
2243 * @widget: the object which received the signal
2244 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2247 * The ::no-expose-event will be emitted when the @widget's window is
2248 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2249 * If the source window was partially obscured #GdkEventExpose events will
2250 * be generated for those areas.
2252 * Returns: %TRUE to stop other handlers from being invoked for the event.
2253 * %FALSE to propagate the event further.
2255 widget_signals[NO_EXPOSE_EVENT] =
2256 g_signal_new (I_("no-expose-event"),
2257 G_TYPE_FROM_CLASS (gobject_class),
2259 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2260 _gtk_boolean_handled_accumulator, NULL,
2261 _gtk_marshal_BOOLEAN__BOXED,
2263 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2266 * GtkWidget::window-state-event:
2267 * @widget: the object which received the signal
2268 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2269 * triggered this signal.
2271 * The ::window-state-event will be emitted when the state of the
2272 * toplevel window associated to the @widget changes.
2274 * To receive this signal the #GdkWindow associated to the widget
2275 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2276 * this mask automatically for all new windows.
2278 * Returns: %TRUE to stop other handlers from being invoked for the
2279 * event. %FALSE to propagate the event further.
2281 widget_signals[WINDOW_STATE_EVENT] =
2282 g_signal_new (I_("window-state-event"),
2283 G_TYPE_FROM_CLASS (gobject_class),
2285 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2286 _gtk_boolean_handled_accumulator, NULL,
2287 _gtk_marshal_BOOLEAN__BOXED,
2289 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2292 * GtkWidget::damage-event:
2293 * @widget: the object which received the signal
2294 * @event: the #GdkEventExpose event
2296 * Emitted when a redirected window belonging to @widget gets drawn into.
2297 * The region/area members of the event shows what area of the redirected
2298 * drawable was drawn into.
2300 * Returns: %TRUE to stop other handlers from being invoked for the event.
2301 * %FALSE to propagate the event further.
2305 widget_signals[DAMAGE_EVENT] =
2306 g_signal_new (I_("damage-event"),
2307 G_TYPE_FROM_CLASS (gobject_class),
2310 _gtk_boolean_handled_accumulator, NULL,
2311 _gtk_marshal_BOOLEAN__BOXED,
2313 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2315 * GtkWidget::grab-broken-event:
2316 * @widget: the object which received the signal
2317 * @event: the #GdkEventGrabBroken event
2319 * Emitted when a pointer or keyboard grab on a window belonging
2320 * to @widget gets broken.
2322 * On X11, this happens when the grab window becomes unviewable
2323 * (i.e. it or one of its ancestors is unmapped), or if the same
2324 * application grabs the pointer or keyboard again.
2326 * Returns: %TRUE to stop other handlers from being invoked for
2327 * the event. %FALSE to propagate the event further.
2331 widget_signals[GRAB_BROKEN] =
2332 g_signal_new (I_("grab-broken-event"),
2333 G_TYPE_FROM_CLASS (gobject_class),
2335 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2336 _gtk_boolean_handled_accumulator, NULL,
2337 _gtk_marshal_BOOLEAN__BOXED,
2339 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2341 * GtkWidget::query-tooltip:
2342 * @widget: the object which received the signal
2343 * @x: the x coordinate of the cursor position where the request has
2344 * been emitted, relative to @widget->window
2345 * @y: the y coordinate of the cursor position where the request has
2346 * been emitted, relative to @widget->window
2347 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2348 * @tooltip: a #GtkTooltip
2350 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2351 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2352 * focus in keyboard mode.
2354 * Using the given coordinates, the signal handler should determine
2355 * whether a tooltip should be shown for @widget. If this is the case
2356 * %TRUE should be returned, %FALSE otherwise. Note that if
2357 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2358 * should not be used.
2360 * The signal handler is free to manipulate @tooltip with the therefore
2361 * destined function calls.
2363 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2367 widget_signals[QUERY_TOOLTIP] =
2368 g_signal_new (I_("query-tooltip"),
2369 G_TYPE_FROM_CLASS (gobject_class),
2371 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2372 _gtk_boolean_handled_accumulator, NULL,
2373 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2381 * GtkWidget::popup-menu
2382 * @widget: the object which received the signal
2384 * This signal gets emitted whenever a widget should pop up a context
2385 * menu. This usually happens through the standard key binding mechanism;
2386 * by pressing a certain key while a widget is focused, the user can cause
2387 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2388 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2389 * for an example of how to use this signal.
2391 * Returns: %TRUE if a menu was activated
2393 widget_signals[POPUP_MENU] =
2394 g_signal_new (I_("popup-menu"),
2395 G_TYPE_FROM_CLASS (gobject_class),
2396 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2397 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2398 _gtk_boolean_handled_accumulator, NULL,
2399 _gtk_marshal_BOOLEAN__VOID,
2403 * GtkWidget::show-help:
2404 * @widget: the object which received the signal.
2407 widget_signals[SHOW_HELP] =
2408 g_signal_new (I_("show-help"),
2409 G_TYPE_FROM_CLASS (gobject_class),
2410 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2411 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2412 _gtk_boolean_handled_accumulator, NULL,
2413 _gtk_marshal_BOOLEAN__ENUM,
2415 GTK_TYPE_WIDGET_HELP_TYPE);
2418 * GtkWidget::accel-closures-changed:
2419 * @widget: the object which received the signal.
2421 widget_signals[ACCEL_CLOSURES_CHANGED] =
2422 g_signal_new (I_("accel-closures-changed"),
2423 G_TYPE_FROM_CLASS (gobject_class),
2427 _gtk_marshal_VOID__VOID,
2431 * GtkWidget::screen-changed:
2432 * @widget: the object on which the signal is emitted
2433 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2434 * widget was not associated with a screen before
2436 * The ::screen-changed signal gets emitted when the
2437 * screen of a widget has changed.
2439 widget_signals[SCREEN_CHANGED] =
2440 g_signal_new (I_("screen-changed"),
2441 G_TYPE_FROM_CLASS (gobject_class),
2443 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2445 _gtk_marshal_VOID__OBJECT,
2450 * GtkWidget::can-activate-accel:
2451 * @widget: the object which received the signal
2452 * @signal_id: the ID of a signal installed on @widget
2454 * Determines whether an accelerator that activates the signal
2455 * identified by @signal_id can currently be activated.
2456 * This signal is present to allow applications and derived
2457 * widgets to override the default #GtkWidget handling
2458 * for determining whether an accelerator can be activated.
2460 * Returns: %TRUE if the signal can be activated.
2462 widget_signals[CAN_ACTIVATE_ACCEL] =
2463 g_signal_new (I_("can-activate-accel"),
2464 G_TYPE_FROM_CLASS (gobject_class),
2466 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2467 _gtk_boolean_handled_accumulator, NULL,
2468 _gtk_marshal_BOOLEAN__UINT,
2469 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2471 binding_set = gtk_binding_set_by_class (klass);
2472 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2474 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2477 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2479 GTK_TYPE_WIDGET_HELP_TYPE,
2480 GTK_WIDGET_HELP_TOOLTIP);
2481 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2483 GTK_TYPE_WIDGET_HELP_TYPE,
2484 GTK_WIDGET_HELP_TOOLTIP);
2485 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2487 GTK_TYPE_WIDGET_HELP_TYPE,
2488 GTK_WIDGET_HELP_WHATS_THIS);
2489 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2491 GTK_TYPE_WIDGET_HELP_TYPE,
2492 GTK_WIDGET_HELP_WHATS_THIS);
2494 gtk_widget_class_install_style_property (klass,
2495 g_param_spec_boolean ("interior-focus",
2496 P_("Interior Focus"),
2497 P_("Whether to draw the focus indicator inside widgets"),
2499 GTK_PARAM_READABLE));
2501 gtk_widget_class_install_style_property (klass,
2502 g_param_spec_int ("focus-line-width",
2503 P_("Focus linewidth"),
2504 P_("Width, in pixels, of the focus indicator line"),
2506 GTK_PARAM_READABLE));
2508 gtk_widget_class_install_style_property (klass,
2509 g_param_spec_string ("focus-line-pattern",
2510 P_("Focus line dash pattern"),
2511 P_("Dash pattern used to draw the focus indicator"),
2513 GTK_PARAM_READABLE));
2514 gtk_widget_class_install_style_property (klass,
2515 g_param_spec_int ("focus-padding",
2516 P_("Focus padding"),
2517 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2519 GTK_PARAM_READABLE));
2520 gtk_widget_class_install_style_property (klass,
2521 g_param_spec_boxed ("cursor-color",
2523 P_("Color with which to draw insertion cursor"),
2525 GTK_PARAM_READABLE));
2526 gtk_widget_class_install_style_property (klass,
2527 g_param_spec_boxed ("secondary-cursor-color",
2528 P_("Secondary cursor color"),
2529 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2531 GTK_PARAM_READABLE));
2532 gtk_widget_class_install_style_property (klass,
2533 g_param_spec_float ("cursor-aspect-ratio",
2534 P_("Cursor line aspect ratio"),
2535 P_("Aspect ratio with which to draw insertion cursor"),
2537 GTK_PARAM_READABLE));
2539 gtk_widget_class_install_style_property (klass,
2540 g_param_spec_boolean ("window-dragging",
2541 P_("Window dragging"),
2542 P_("Whether windows can be dragged by clicking on empty areas"),
2544 GTK_PARAM_READABLE));
2547 * GtkWidget:link-color:
2549 * The "link-color" style property defines the color of unvisited links.
2553 gtk_widget_class_install_style_property (klass,
2554 g_param_spec_boxed ("link-color",
2555 P_("Unvisited Link Color"),
2556 P_("Color of unvisited links"),
2558 GTK_PARAM_READABLE));
2561 * GtkWidget:visited-link-color:
2563 * The "visited-link-color" style property defines the color of visited links.
2567 gtk_widget_class_install_style_property (klass,
2568 g_param_spec_boxed ("visited-link-color",
2569 P_("Visited Link Color"),
2570 P_("Color of visited links"),
2572 GTK_PARAM_READABLE));
2575 * GtkWidget:wide-separators:
2577 * The "wide-separators" style property defines whether separators have
2578 * configurable width and should be drawn using a box instead of a line.
2582 gtk_widget_class_install_style_property (klass,
2583 g_param_spec_boolean ("wide-separators",
2584 P_("Wide Separators"),
2585 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2587 GTK_PARAM_READABLE));
2590 * GtkWidget:separator-width:
2592 * The "separator-width" style property defines the width of separators.
2593 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2597 gtk_widget_class_install_style_property (klass,
2598 g_param_spec_int ("separator-width",
2599 P_("Separator Width"),
2600 P_("The width of separators if wide-separators is TRUE"),
2602 GTK_PARAM_READABLE));
2605 * GtkWidget:separator-height:
2607 * The "separator-height" style property defines the height of separators.
2608 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2612 gtk_widget_class_install_style_property (klass,
2613 g_param_spec_int ("separator-height",
2614 P_("Separator Height"),
2615 P_("The height of separators if \"wide-separators\" is TRUE"),
2617 GTK_PARAM_READABLE));
2620 * GtkWidget:scroll-arrow-hlength:
2622 * The "scroll-arrow-hlength" style property defines the length of
2623 * horizontal scroll arrows.
2627 gtk_widget_class_install_style_property (klass,
2628 g_param_spec_int ("scroll-arrow-hlength",
2629 P_("Horizontal Scroll Arrow Length"),
2630 P_("The length of horizontal scroll arrows"),
2632 GTK_PARAM_READABLE));
2635 * GtkWidget:scroll-arrow-vlength:
2637 * The "scroll-arrow-vlength" style property defines the length of
2638 * vertical scroll arrows.
2642 gtk_widget_class_install_style_property (klass,
2643 g_param_spec_int ("scroll-arrow-vlength",
2644 P_("Vertical Scroll Arrow Length"),
2645 P_("The length of vertical scroll arrows"),
2647 GTK_PARAM_READABLE));
2649 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2653 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2657 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2658 for (node = list; node; node = node->next)
2660 GParamSpec *pspec = node->data;
2662 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2663 g_param_spec_unref (pspec);
2669 gtk_widget_set_property (GObject *object,
2671 const GValue *value,
2674 GtkWidget *widget = GTK_WIDGET (object);
2679 gchar *tooltip_markup;
2680 const gchar *tooltip_text;
2681 GtkWindow *tooltip_window;
2684 gtk_widget_set_name (widget, g_value_get_string (value));
2687 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2689 case PROP_WIDTH_REQUEST:
2690 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2692 case PROP_HEIGHT_REQUEST:
2693 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2696 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2698 case PROP_SENSITIVE:
2699 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2701 case PROP_APP_PAINTABLE:
2702 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2704 case PROP_CAN_FOCUS:
2705 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2707 case PROP_HAS_FOCUS:
2708 if (g_value_get_boolean (value))
2709 gtk_widget_grab_focus (widget);
2712 if (g_value_get_boolean (value))
2713 gtk_widget_grab_focus (widget);
2715 case PROP_CAN_DEFAULT:
2716 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2718 case PROP_HAS_DEFAULT:
2719 if (g_value_get_boolean (value))
2720 gtk_widget_grab_default (widget);
2722 case PROP_RECEIVES_DEFAULT:
2723 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2726 gtk_widget_set_style (widget, g_value_get_object (value));
2729 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2730 gtk_widget_set_events (widget, g_value_get_flags (value));
2732 case PROP_EXTENSION_EVENTS:
2733 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2735 case PROP_NO_SHOW_ALL:
2736 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2738 case PROP_HAS_TOOLTIP:
2739 gtk_widget_real_set_has_tooltip (widget,
2740 g_value_get_boolean (value), FALSE);
2742 case PROP_TOOLTIP_MARKUP:
2743 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2744 tooltip_markup = g_value_dup_string (value);
2746 /* Treat an empty string as a NULL string,
2747 * because an empty string would be useless for a tooltip:
2749 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2751 g_free (tooltip_markup);
2752 tooltip_markup = NULL;
2755 g_object_set_qdata_full (object, quark_tooltip_markup,
2756 tooltip_markup, g_free);
2758 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2759 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2760 if (gtk_widget_get_visible (widget))
2761 gtk_widget_queue_tooltip_query (widget);
2763 case PROP_TOOLTIP_TEXT:
2764 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2766 tooltip_text = g_value_get_string (value);
2768 /* Treat an empty string as a NULL string,
2769 * because an empty string would be useless for a tooltip:
2771 if (tooltip_text && (strlen (tooltip_text) == 0))
2772 tooltip_text = NULL;
2774 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2776 g_object_set_qdata_full (object, quark_tooltip_markup,
2777 tooltip_markup, g_free);
2779 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2780 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2781 if (gtk_widget_get_visible (widget))
2782 gtk_widget_queue_tooltip_query (widget);
2784 case PROP_DOUBLE_BUFFERED:
2785 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2788 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2794 gtk_widget_get_property (GObject *object,
2799 GtkWidget *widget = GTK_WIDGET (object);
2800 GtkWidgetPrivate *priv = widget->priv;
2809 g_value_set_string (value, priv->name);
2811 g_value_set_static_string (value, "");
2814 g_value_set_object (value, priv->parent);
2816 case PROP_WIDTH_REQUEST:
2819 gtk_widget_get_size_request (widget, &w, NULL);
2820 g_value_set_int (value, w);
2823 case PROP_HEIGHT_REQUEST:
2826 gtk_widget_get_size_request (widget, NULL, &h);
2827 g_value_set_int (value, h);
2831 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2833 case PROP_SENSITIVE:
2834 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2836 case PROP_APP_PAINTABLE:
2837 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2839 case PROP_CAN_FOCUS:
2840 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2842 case PROP_HAS_FOCUS:
2843 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2846 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2848 case PROP_CAN_DEFAULT:
2849 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2851 case PROP_HAS_DEFAULT:
2852 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2854 case PROP_RECEIVES_DEFAULT:
2855 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2857 case PROP_COMPOSITE_CHILD:
2858 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2861 g_value_set_object (value, gtk_widget_get_style (widget));
2864 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2865 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2867 case PROP_EXTENSION_EVENTS:
2868 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2869 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2871 case PROP_NO_SHOW_ALL:
2872 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2874 case PROP_HAS_TOOLTIP:
2875 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2877 case PROP_TOOLTIP_TEXT:
2879 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2882 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2883 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2885 g_value_take_string (value, text);
2888 case PROP_TOOLTIP_MARKUP:
2889 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2892 g_value_set_object (value, gtk_widget_get_window (widget));
2894 case PROP_DOUBLE_BUFFERED:
2895 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2898 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2904 gtk_widget_init (GtkWidget *widget)
2906 GtkWidgetPrivate *priv;
2908 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
2911 priv = widget->priv;
2913 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2914 priv->state = GTK_STATE_NORMAL;
2915 priv->saved_state = GTK_STATE_NORMAL;
2917 priv->allocation.x = -1;
2918 priv->allocation.y = -1;
2919 priv->allocation.width = 1;
2920 priv->allocation.height = 1;
2921 priv->window = NULL;
2922 priv->parent = NULL;
2924 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2925 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2926 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2927 gtk_widget_set_double_buffered (widget, TRUE);
2929 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2930 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
2931 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
2932 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2934 priv->style = gtk_widget_get_default_style ();
2935 g_object_ref (priv->style);
2940 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2942 GParamSpec **pspecs)
2944 GtkWidgetPrivate *priv = widget->priv;
2945 GtkWidget *container = priv->parent;
2948 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
2949 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2953 * gtk_widget_freeze_child_notify:
2954 * @widget: a #GtkWidget
2956 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2957 * signals are queued until gtk_widget_thaw_child_notify() is called
2960 * This is the analogue of g_object_freeze_notify() for child properties.
2963 gtk_widget_freeze_child_notify (GtkWidget *widget)
2965 g_return_if_fail (GTK_IS_WIDGET (widget));
2967 if (!G_OBJECT (widget)->ref_count)
2970 g_object_ref (widget);
2971 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2972 g_object_unref (widget);
2976 * gtk_widget_child_notify:
2977 * @widget: a #GtkWidget
2978 * @child_property: the name of a child property installed on the
2979 * class of @widget<!-- -->'s parent
2981 * Emits a #GtkWidget::child-notify signal for the
2982 * <link linkend="child-properties">child property</link> @child_property
2985 * This is the analogue of g_object_notify() for child properties.
2988 gtk_widget_child_notify (GtkWidget *widget,
2989 const gchar *child_property)
2991 GtkWidgetPrivate *priv = widget->priv;
2994 g_return_if_fail (GTK_IS_WIDGET (widget));
2995 g_return_if_fail (child_property != NULL);
2996 if (!G_OBJECT (widget)->ref_count || !priv->parent)
2999 g_object_ref (widget);
3000 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3002 G_OBJECT_TYPE (priv->parent),
3005 g_warning ("%s: container class `%s' has no child property named `%s'",
3007 G_OBJECT_TYPE_NAME (priv->parent),
3011 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3013 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3014 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3016 g_object_unref (widget);
3020 * gtk_widget_thaw_child_notify:
3021 * @widget: a #GtkWidget
3023 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3024 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3028 gtk_widget_thaw_child_notify (GtkWidget *widget)
3030 GObjectNotifyQueue *nqueue;
3032 g_return_if_fail (GTK_IS_WIDGET (widget));
3034 if (!G_OBJECT (widget)->ref_count)
3037 g_object_ref (widget);
3038 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3039 if (!nqueue || !nqueue->freeze_count)
3040 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3041 G_OBJECT_TYPE_NAME (widget), widget);
3043 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3044 g_object_unref (widget);
3050 * @type: type ID of the widget to create
3051 * @first_property_name: name of first property to set
3052 * @Varargs: value of first property, followed by more properties,
3055 * This is a convenience function for creating a widget and setting
3056 * its properties in one go. For example you might write:
3057 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3058 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3059 * g_object_new(), but returns a widget so you don't have to
3060 * cast the object yourself.
3062 * Return value: a new #GtkWidget of type @widget_type
3065 gtk_widget_new (GType type,
3066 const gchar *first_property_name,
3072 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3074 va_start (var_args, first_property_name);
3075 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3082 gtk_widget_queue_draw_child (GtkWidget *widget)
3084 GtkWidgetPrivate *priv = widget->priv;
3087 parent = priv->parent;
3088 if (parent && gtk_widget_is_drawable (parent))
3089 gtk_widget_queue_draw_area (parent,
3092 priv->allocation.width,
3093 priv->allocation.height);
3097 * gtk_widget_unparent:
3098 * @widget: a #GtkWidget
3100 * This function is only for use in widget implementations.
3101 * Should be called by implementations of the remove method
3102 * on #GtkContainer, to dissociate a child from the container.
3105 gtk_widget_unparent (GtkWidget *widget)
3107 GtkWidgetPrivate *priv;
3108 GObjectNotifyQueue *nqueue;
3109 GtkWidget *toplevel;
3110 GtkWidget *old_parent;
3112 g_return_if_fail (GTK_IS_WIDGET (widget));
3114 priv = widget->priv;
3116 if (priv->parent == NULL)
3119 /* keep this function in sync with gtk_menu_detach()
3122 g_object_freeze_notify (G_OBJECT (widget));
3123 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3125 toplevel = gtk_widget_get_toplevel (widget);
3126 if (gtk_widget_is_toplevel (toplevel))
3127 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3129 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3130 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3132 /* If we are unanchoring the child, we save around the toplevel
3133 * to emit hierarchy changed
3135 if (GTK_WIDGET_ANCHORED (priv->parent))
3136 g_object_ref (toplevel);
3140 gtk_widget_queue_draw_child (widget);
3142 /* Reset the width and height here, to force reallocation if we
3143 * get added back to a new parent. This won't work if our new
3144 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3145 * (would 0x0 be OK here?)
3147 priv->allocation.width = 1;
3148 priv->allocation.height = 1;
3150 if (gtk_widget_get_realized (widget))
3152 if (GTK_WIDGET_IN_REPARENT (widget))
3153 gtk_widget_unmap (widget);
3155 gtk_widget_unrealize (widget);
3158 /* Removing a widget from a container restores the child visible
3159 * flag to the default state, so it doesn't affect the child
3160 * in the next parent.
3162 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3164 old_parent = priv->parent;
3165 priv->parent = NULL;
3166 gtk_widget_set_parent_window (widget, NULL);
3167 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3170 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3171 g_object_unref (toplevel);
3174 g_object_notify (G_OBJECT (widget), "parent");
3175 g_object_thaw_notify (G_OBJECT (widget));
3177 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3178 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3179 g_object_unref (widget);
3183 * gtk_widget_destroy:
3184 * @widget: a #GtkWidget
3186 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3187 * you don't have to cast the widget to #GtkObject. When a widget is
3188 * destroyed, it will break any references it holds to other objects.
3189 * If the widget is inside a container, the widget will be removed
3190 * from the container. If the widget is a toplevel (derived from
3191 * #GtkWindow), it will be removed from the list of toplevels, and the
3192 * reference GTK+ holds to it will be removed. Removing a
3193 * widget from its container or the list of toplevels results in the
3194 * widget being finalized, unless you've added additional references
3195 * to the widget with g_object_ref().
3197 * In most cases, only toplevel widgets (windows) require explicit
3198 * destruction, because when you destroy a toplevel its children will
3199 * be destroyed as well.
3202 gtk_widget_destroy (GtkWidget *widget)
3204 g_return_if_fail (GTK_IS_WIDGET (widget));
3206 gtk_object_destroy ((GtkObject*) widget);
3210 * gtk_widget_destroyed:
3211 * @widget: a #GtkWidget
3212 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3214 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3215 * %NULL. It's intended to be used as a callback connected to the
3216 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3217 * as a signal handler, and pass the address of your widget variable
3218 * as user data. Then when the widget is destroyed, the variable will
3219 * be set to %NULL. Useful for example to avoid multiple copies
3220 * of the same dialog.
3223 gtk_widget_destroyed (GtkWidget *widget,
3224 GtkWidget **widget_pointer)
3226 /* Don't make any assumptions about the
3228 * Even check widget_pointer.
3231 *widget_pointer = NULL;
3236 * @widget: a #GtkWidget
3238 * Flags a widget to be displayed. Any widget that isn't shown will
3239 * not appear on the screen. If you want to show all the widgets in a
3240 * container, it's easier to call gtk_widget_show_all() on the
3241 * container, instead of individually showing the widgets.
3243 * Remember that you have to show the containers containing a widget,
3244 * in addition to the widget itself, before it will appear onscreen.
3246 * When a toplevel container is shown, it is immediately realized and
3247 * mapped; other shown widgets are realized and mapped when their
3248 * toplevel container is realized and mapped.
3251 gtk_widget_show (GtkWidget *widget)
3253 g_return_if_fail (GTK_IS_WIDGET (widget));
3255 if (!gtk_widget_get_visible (widget))
3257 g_object_ref (widget);
3258 if (!gtk_widget_is_toplevel (widget))
3259 gtk_widget_queue_resize (widget);
3260 g_signal_emit (widget, widget_signals[SHOW], 0);
3261 g_object_notify (G_OBJECT (widget), "visible");
3262 g_object_unref (widget);
3267 gtk_widget_real_show (GtkWidget *widget)
3269 GtkWidgetPrivate *priv = widget->priv;
3271 if (!gtk_widget_get_visible (widget))
3273 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3276 gtk_widget_get_mapped (priv->parent) &&
3277 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3278 !gtk_widget_get_mapped (widget))
3279 gtk_widget_map (widget);
3284 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3287 g_signal_handlers_disconnect_by_func (widget,
3288 gtk_widget_show_map_callback,
3293 * gtk_widget_show_now:
3294 * @widget: a #GtkWidget
3296 * Shows a widget. If the widget is an unmapped toplevel widget
3297 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3298 * loop and wait for the window to actually be mapped. Be careful;
3299 * because the main loop is running, anything can happen during
3303 gtk_widget_show_now (GtkWidget *widget)
3307 g_return_if_fail (GTK_IS_WIDGET (widget));
3309 /* make sure we will get event */
3310 if (!gtk_widget_get_mapped (widget) &&
3311 gtk_widget_is_toplevel (widget))
3313 gtk_widget_show (widget);
3315 g_signal_connect (widget, "map-event",
3316 G_CALLBACK (gtk_widget_show_map_callback),
3320 gtk_main_iteration ();
3323 gtk_widget_show (widget);
3328 * @widget: a #GtkWidget
3330 * Reverses the effects of gtk_widget_show(), causing the widget to be
3331 * hidden (invisible to the user).
3334 gtk_widget_hide (GtkWidget *widget)
3336 g_return_if_fail (GTK_IS_WIDGET (widget));
3338 if (gtk_widget_get_visible (widget))
3340 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3342 g_object_ref (widget);
3343 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3344 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3346 g_signal_emit (widget, widget_signals[HIDE], 0);
3347 if (!gtk_widget_is_toplevel (widget))
3348 gtk_widget_queue_resize (widget);
3349 g_object_notify (G_OBJECT (widget), "visible");
3350 g_object_unref (widget);
3355 gtk_widget_real_hide (GtkWidget *widget)
3357 if (gtk_widget_get_visible (widget))
3359 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3361 if (gtk_widget_get_mapped (widget))
3362 gtk_widget_unmap (widget);
3367 * gtk_widget_hide_on_delete:
3368 * @widget: a #GtkWidget
3370 * Utility function; intended to be connected to the #GtkWidget::delete-event
3371 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3372 * argument, then returns %TRUE. If connected to ::delete-event, the
3373 * result is that clicking the close button for a window (on the
3374 * window frame, top right corner usually) will hide but not destroy
3375 * the window. By default, GTK+ destroys windows when ::delete-event
3378 * Return value: %TRUE
3381 gtk_widget_hide_on_delete (GtkWidget *widget)
3383 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3385 gtk_widget_hide (widget);
3391 * gtk_widget_show_all:
3392 * @widget: a #GtkWidget
3394 * Recursively shows a widget, and any child widgets (if the widget is
3398 gtk_widget_show_all (GtkWidget *widget)
3400 GtkWidgetClass *class;
3402 g_return_if_fail (GTK_IS_WIDGET (widget));
3404 if (gtk_widget_get_no_show_all (widget))
3407 class = GTK_WIDGET_GET_CLASS (widget);
3409 if (class->show_all)
3410 class->show_all (widget);
3414 * gtk_widget_hide_all:
3415 * @widget: a #GtkWidget
3417 * Recursively hides a widget and any child widgets.
3420 gtk_widget_hide_all (GtkWidget *widget)
3422 GtkWidgetClass *class;
3424 g_return_if_fail (GTK_IS_WIDGET (widget));
3426 if (gtk_widget_get_no_show_all (widget))
3429 class = GTK_WIDGET_GET_CLASS (widget);
3431 if (class->hide_all)
3432 class->hide_all (widget);
3437 * @widget: a #GtkWidget
3439 * This function is only for use in widget implementations. Causes
3440 * a widget to be mapped if it isn't already.
3443 gtk_widget_map (GtkWidget *widget)
3445 GtkWidgetPrivate *priv;
3447 g_return_if_fail (GTK_IS_WIDGET (widget));
3448 g_return_if_fail (gtk_widget_get_visible (widget));
3449 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3451 priv = widget->priv;
3453 if (!gtk_widget_get_mapped (widget))
3455 if (!gtk_widget_get_realized (widget))
3456 gtk_widget_realize (widget);
3458 g_signal_emit (widget, widget_signals[MAP], 0);
3460 if (!gtk_widget_get_has_window (widget))
3461 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3467 * @widget: a #GtkWidget
3469 * This function is only for use in widget implementations. Causes
3470 * a widget to be unmapped if it's currently mapped.
3473 gtk_widget_unmap (GtkWidget *widget)
3475 GtkWidgetPrivate *priv;
3477 g_return_if_fail (GTK_IS_WIDGET (widget));
3479 priv = widget->priv;
3481 if (gtk_widget_get_mapped (widget))
3483 if (!gtk_widget_get_has_window (widget))
3484 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3485 _gtk_tooltip_hide (widget);
3486 g_signal_emit (widget, widget_signals[UNMAP], 0);
3491 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3492 GdkExtensionMode mode,
3495 GtkWidgetPrivate *priv = widget->priv;
3496 GList *free_list = NULL;
3499 if (window_list == NULL)
3501 if (gtk_widget_get_has_window (widget))
3502 window_list = g_list_prepend (NULL, priv->window);
3504 window_list = gdk_window_get_children (priv->window);
3506 free_list = window_list;
3509 for (l = window_list; l != NULL; l = l->next)
3511 GdkWindow *window = l->data;
3514 gdk_window_get_user_data (window, &user_data);
3515 if (user_data == widget)
3519 gdk_input_set_extension_events (window,
3520 gdk_window_get_events (window),
3523 children = gdk_window_get_children (window);
3526 gtk_widget_set_extension_events_internal (widget, mode, children);
3527 g_list_free (children);
3533 g_list_free (free_list);
3537 _gtk_widget_enable_device_events (GtkWidget *widget)
3539 GHashTable *device_events;
3540 GHashTableIter iter;
3541 gpointer key, value;
3543 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3548 g_hash_table_iter_init (&iter, device_events);
3550 while (g_hash_table_iter_next (&iter, &key, &value))
3553 GdkEventMask event_mask;
3556 event_mask = GPOINTER_TO_UINT (value);
3557 gtk_widget_add_events_internal (widget, device, event_mask);
3562 * gtk_widget_realize:
3563 * @widget: a #GtkWidget
3565 * Creates the GDK (windowing system) resources associated with a
3566 * widget. For example, @widget->window will be created when a widget
3567 * is realized. Normally realization happens implicitly; if you show
3568 * a widget and all its parent containers, then the widget will be
3569 * realized and mapped automatically.
3571 * Realizing a widget requires all
3572 * the widget's parent widgets to be realized; calling
3573 * gtk_widget_realize() realizes the widget's parents in addition to
3574 * @widget itself. If a widget is not yet inside a toplevel window
3575 * when you realize it, bad things will happen.
3577 * This function is primarily used in widget implementations, and
3578 * isn't very useful otherwise. Many times when you think you might
3579 * need it, a better approach is to connect to a signal that will be
3580 * called after the widget is realized automatically, such as
3581 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3582 * GtkWidget::realize signal.
3585 gtk_widget_realize (GtkWidget *widget)
3587 GtkWidgetPrivate *priv;
3588 GdkExtensionMode mode;
3589 GtkWidgetShapeInfo *shape_info;
3591 g_return_if_fail (GTK_IS_WIDGET (widget));
3592 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3593 GTK_IS_INVISIBLE (widget));
3595 priv = widget->priv;
3597 if (!gtk_widget_get_realized (widget))
3600 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3601 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3604 if (priv->parent == NULL &&
3605 !gtk_widget_is_toplevel (widget))
3606 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3607 "inside a toplevel window is not going to work very well. "
3608 "Widgets must be inside a toplevel container before realizing them.");
3610 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3611 gtk_widget_realize (priv->parent);
3613 gtk_widget_ensure_style (widget);
3615 g_signal_emit (widget, widget_signals[REALIZE], 0);
3617 gtk_widget_real_set_has_tooltip (widget,
3618 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3621 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3623 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3624 gdk_window_shape_combine_mask (priv->window,
3625 shape_info->shape_mask,
3626 shape_info->offset_x,
3627 shape_info->offset_y);
3630 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3632 gdk_window_input_shape_combine_mask (priv->window,
3633 shape_info->shape_mask,
3634 shape_info->offset_x,
3635 shape_info->offset_y);
3637 mode = gtk_widget_get_extension_events (widget);
3638 if (mode != GDK_EXTENSION_EVENTS_NONE)
3639 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3641 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3642 gdk_window_set_support_multidevice (priv->window, TRUE);
3644 _gtk_widget_enable_device_events (widget);
3649 * gtk_widget_unrealize:
3650 * @widget: a #GtkWidget
3652 * This function is only useful in widget implementations.
3653 * Causes a widget to be unrealized (frees all GDK resources
3654 * associated with the widget, such as @widget->window).
3657 gtk_widget_unrealize (GtkWidget *widget)
3659 g_return_if_fail (GTK_IS_WIDGET (widget));
3661 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3662 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3664 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3665 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3667 if (gtk_widget_get_realized (widget))
3669 g_object_ref (widget);
3670 _gtk_tooltip_hide (widget);
3671 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3672 gtk_widget_set_realized (widget, FALSE);
3673 gtk_widget_set_mapped (widget, FALSE);
3674 g_object_unref (widget);
3678 /*****************************************
3680 *****************************************/
3683 * gtk_widget_queue_draw_area:
3684 * @widget: a #GtkWidget
3685 * @x: x coordinate of upper-left corner of rectangle to redraw
3686 * @y: y coordinate of upper-left corner of rectangle to redraw
3687 * @width: width of region to draw
3688 * @height: height of region to draw
3690 * Invalidates the rectangular area of @widget defined by @x, @y,
3691 * @width and @height by calling gdk_window_invalidate_rect() on the
3692 * widget's window and all its child windows. Once the main loop
3693 * becomes idle (after the current batch of events has been processed,
3694 * roughly), the window will receive expose events for the union of
3695 * all regions that have been invalidated.
3697 * Normally you would only use this function in widget
3698 * implementations. You might also use it, or
3699 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3700 * #GtkDrawingArea or some portion thereof.
3702 * Frequently you can just call gdk_window_invalidate_rect() or
3703 * gdk_window_invalidate_region() instead of this function. Those
3704 * functions will invalidate only a single window, instead of the
3705 * widget and all its children.
3707 * The advantage of adding to the invalidated region compared to
3708 * simply drawing immediately is efficiency; using an invalid region
3709 * ensures that you only have to redraw one time.
3712 gtk_widget_queue_draw_area (GtkWidget *widget,
3718 GtkWidgetPrivate *priv;
3719 GdkRectangle invalid_rect;
3722 g_return_if_fail (GTK_IS_WIDGET (widget));
3724 priv = widget->priv;
3726 if (!gtk_widget_get_realized (widget))
3729 /* Just return if the widget or one of its ancestors isn't mapped */
3730 for (w = widget; w != NULL; w = w->priv->parent)
3731 if (!gtk_widget_get_mapped (w))
3734 /* Find the correct widget */
3736 if (gtk_widget_get_has_window (widget))
3740 /* Translate widget relative to window-relative */
3742 gint wx, wy, wwidth, wheight;
3744 gdk_window_get_position (priv->window, &wx, &wy);
3745 x -= wx - priv->allocation.x;
3746 y -= wy - priv->allocation.y;
3748 gdk_drawable_get_size (priv->window, &wwidth, &wheight);
3750 if (x + width <= 0 || y + height <= 0 ||
3751 x >= wwidth || y >= wheight)
3762 if (x + width > wwidth)
3764 if (y + height > wheight)
3765 height = wheight - y;
3771 invalid_rect.width = width;
3772 invalid_rect.height = height;
3774 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
3778 * gtk_widget_queue_draw:
3779 * @widget: a #GtkWidget
3781 * Equivalent to calling gtk_widget_queue_draw_area() for the
3782 * entire area of a widget.
3785 gtk_widget_queue_draw (GtkWidget *widget)
3789 g_return_if_fail (GTK_IS_WIDGET (widget));
3791 gtk_widget_get_allocation (widget, &rect);
3793 if (!gtk_widget_get_has_window (widget))
3794 gtk_widget_queue_draw_area (widget,
3795 rect.x, rect.y, rect.width, rect.height);
3797 gtk_widget_queue_draw_area (widget,
3798 0, 0, rect.width, rect.height);
3802 * gtk_widget_queue_resize:
3803 * @widget: a #GtkWidget
3805 * This function is only for use in widget implementations.
3806 * Flags a widget to have its size renegotiated; should
3807 * be called when a widget for some reason has a new size request.
3808 * For example, when you change the text in a #GtkLabel, #GtkLabel
3809 * queues a resize to ensure there's enough space for the new text.
3812 gtk_widget_queue_resize (GtkWidget *widget)
3814 g_return_if_fail (GTK_IS_WIDGET (widget));
3816 if (gtk_widget_get_realized (widget))
3817 gtk_widget_queue_shallow_draw (widget);
3819 _gtk_size_group_queue_resize (widget);
3823 * gtk_widget_queue_resize_no_redraw:
3824 * @widget: a #GtkWidget
3826 * This function works like gtk_widget_queue_resize(),
3827 * except that the widget is not invalidated.
3832 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3834 g_return_if_fail (GTK_IS_WIDGET (widget));
3836 _gtk_size_group_queue_resize (widget);
3840 * gtk_widget_size_request:
3841 * @widget: a #GtkWidget
3842 * @requisition: (out): a #GtkRequisition to be filled in
3844 * This function is typically used when implementing a #GtkContainer
3845 * subclass. Obtains the preferred size of a widget. The container
3846 * uses this information to arrange its child widgets and decide what
3847 * size allocations to give them with gtk_widget_size_allocate().
3849 * You can also call this function from an application, with some
3850 * caveats. Most notably, getting a size request requires the widget
3851 * to be associated with a screen, because font information may be
3852 * needed. Multihead-aware applications should keep this in mind.
3854 * Also remember that the size request is not necessarily the size
3855 * a widget will actually be allocated.
3857 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
3860 gtk_widget_size_request (GtkWidget *widget,
3861 GtkRequisition *requisition)
3863 g_return_if_fail (GTK_IS_WIDGET (widget));
3865 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
3869 * gtk_widget_get_child_requisition:
3870 * @widget: a #GtkWidget
3871 * @requisition: (out): a #GtkRequisition to be filled in
3873 * This function is only for use in widget implementations. Obtains
3874 * @widget->requisition, unless someone has forced a particular
3875 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3876 * in which case it returns that geometry instead of the widget's
3879 * This function differs from gtk_widget_size_request() in that
3880 * it retrieves the last size request value from @widget->requisition,
3881 * while gtk_widget_size_request() actually calls the "size_request" method
3882 * on @widget to compute the size request and fill in @widget->requisition,
3883 * and only then returns @widget->requisition.
3885 * Because this function does not call the "size_request" method, it
3886 * can only be used when you know that @widget->requisition is
3887 * up-to-date, that is, gtk_widget_size_request() has been called
3888 * since the last time a resize was queued. In general, only container
3889 * implementations have this information; applications should use
3890 * gtk_widget_size_request().
3893 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
3896 gtk_widget_get_child_requisition (GtkWidget *widget,
3897 GtkRequisition *requisition)
3899 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
3903 invalidate_predicate (GdkWindow *window,
3908 gdk_window_get_user_data (window, &user_data);
3910 return (user_data == data);
3913 /* Invalidate @region in widget->window and all children
3914 * of widget->window owned by widget. @region is in the
3915 * same coordinates as widget->allocation and will be
3916 * modified by this call.
3919 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3920 cairo_region_t *region)
3922 GtkWidgetPrivate *priv = widget->priv;
3924 if (!gtk_widget_get_realized (widget))
3927 if (gtk_widget_get_has_window (widget) && priv->parent)
3931 gdk_window_get_position (priv->window, &x, &y);
3932 cairo_region_translate (region, -x, -y);
3935 gdk_window_invalidate_maybe_recurse (priv->window, region,
3936 invalidate_predicate, widget);
3940 * gtk_widget_queue_shallow_draw:
3941 * @widget: a #GtkWidget
3943 * Like gtk_widget_queue_draw(), but only windows owned
3944 * by @widget are invalidated.
3947 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3950 cairo_region_t *region;
3952 if (!gtk_widget_get_realized (widget))
3955 gtk_widget_get_allocation (widget, &rect);
3957 region = cairo_region_create_rectangle (&rect);
3958 gtk_widget_invalidate_widget_windows (widget, region);
3959 cairo_region_destroy (region);
3963 * gtk_widget_size_allocate:
3964 * @widget: a #GtkWidget
3965 * @allocation: (inout): position and size to be allocated to @widget
3967 * This function is only used by #GtkContainer subclasses, to assign a size
3968 * and position to their child widgets.
3971 gtk_widget_size_allocate (GtkWidget *widget,
3972 GtkAllocation *allocation)
3974 GtkWidgetPrivate *priv;
3975 GdkRectangle real_allocation;
3976 GdkRectangle old_allocation;
3977 gboolean alloc_needed;
3978 gboolean size_changed;
3979 gboolean position_changed;
3981 priv = widget->priv;
3983 g_return_if_fail (GTK_IS_WIDGET (widget));
3985 #ifdef G_ENABLE_DEBUG
3986 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
3997 parent = gtk_widget_get_parent (parent);
4000 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4001 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4002 2 * depth, " ", name,
4003 allocation->width, allocation->height);
4005 #endif /* G_ENABLE_DEBUG */
4007 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4008 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4009 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4010 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4012 old_allocation = priv->allocation;
4013 real_allocation = *allocation;
4015 if (real_allocation.width < 0 || real_allocation.height < 0)
4017 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4018 real_allocation.width,
4019 real_allocation.height);
4022 real_allocation.width = MAX (real_allocation.width, 1);
4023 real_allocation.height = MAX (real_allocation.height, 1);
4025 size_changed = (old_allocation.width != real_allocation.width ||
4026 old_allocation.height != real_allocation.height);
4027 position_changed = (old_allocation.x != real_allocation.x ||
4028 old_allocation.y != real_allocation.y);
4030 if (!alloc_needed && !size_changed && !position_changed)
4033 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4035 if (gtk_widget_get_mapped (widget))
4037 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4039 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4041 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4042 cairo_region_union_rectangle (invalidate, &old_allocation);
4044 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4045 cairo_region_destroy (invalidate);
4050 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4052 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4054 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4055 cairo_region_union_rectangle (invalidate, &old_allocation);
4057 gtk_widget_invalidate_widget_windows (widget, invalidate);
4058 cairo_region_destroy (invalidate);
4063 if ((size_changed || position_changed) && priv->parent &&
4064 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4066 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4067 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4068 cairo_region_destroy (invalidate);
4073 * gtk_widget_common_ancestor:
4074 * @widget_a: a #GtkWidget
4075 * @widget_b: a #GtkWidget
4077 * Find the common ancestor of @widget_a and @widget_b that
4078 * is closest to the two widgets.
4080 * Return value: the closest common ancestor of @widget_a and
4081 * @widget_b or %NULL if @widget_a and @widget_b do not
4082 * share a common ancestor.
4085 gtk_widget_common_ancestor (GtkWidget *widget_a,
4086 GtkWidget *widget_b)
4088 GtkWidget *parent_a;
4089 GtkWidget *parent_b;
4093 parent_a = widget_a;
4094 while (parent_a->priv->parent)
4096 parent_a = parent_a->priv->parent;
4100 parent_b = widget_b;
4101 while (parent_b->priv->parent)
4103 parent_b = parent_b->priv->parent;
4107 if (parent_a != parent_b)
4110 while (depth_a > depth_b)
4112 widget_a = widget_a->priv->parent;
4116 while (depth_b > depth_a)
4118 widget_b = widget_b->priv->parent;
4122 while (widget_a != widget_b)
4124 widget_a = widget_a->priv->parent;
4125 widget_b = widget_b->priv->parent;
4132 * gtk_widget_translate_coordinates:
4133 * @src_widget: a #GtkWidget
4134 * @dest_widget: a #GtkWidget
4135 * @src_x: X position relative to @src_widget
4136 * @src_y: Y position relative to @src_widget
4137 * @dest_x: (out): location to store X position relative to @dest_widget
4138 * @dest_y: (out): location to store Y position relative to @dest_widget
4140 * Translate coordinates relative to @src_widget's allocation to coordinates
4141 * relative to @dest_widget's allocations. In order to perform this
4142 * operation, both widgets must be realized, and must share a common
4145 * Return value: %FALSE if either widget was not realized, or there
4146 * was no common ancestor. In this case, nothing is stored in
4147 * *@dest_x and *@dest_y. Otherwise %TRUE.
4150 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4151 GtkWidget *dest_widget,
4157 GtkWidgetPrivate *src_priv = src_widget->priv;
4158 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4159 GtkWidget *ancestor;
4161 GList *dest_list = NULL;
4163 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4164 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4166 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4167 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4170 /* Translate from allocation relative to window relative */
4171 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4174 gdk_window_get_position (src_priv->window, &wx, &wy);
4176 src_x -= wx - src_priv->allocation.x;
4177 src_y -= wy - src_priv->allocation.y;
4181 src_x += src_priv->allocation.x;
4182 src_y += src_priv->allocation.y;
4185 /* Translate to the common ancestor */
4186 window = src_priv->window;
4187 while (window != ancestor->priv->window)
4191 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4196 window = gdk_window_get_effective_parent (window);
4198 if (!window) /* Handle GtkHandleBox */
4203 window = dest_priv->window;
4204 while (window != ancestor->priv->window)
4206 dest_list = g_list_prepend (dest_list, window);
4208 window = gdk_window_get_effective_parent (window);
4210 if (!window) /* Handle GtkHandleBox */
4212 g_list_free (dest_list);
4221 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4226 dest_list = g_list_remove (dest_list, dest_list->data);
4229 /* Translate from window relative to allocation relative */
4230 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4233 gdk_window_get_position (dest_priv->window, &wx, &wy);
4235 src_x += wx - dest_priv->allocation.x;
4236 src_y += wy - dest_priv->allocation.y;
4240 src_x -= dest_priv->allocation.x;
4241 src_y -= dest_priv->allocation.y;
4253 gtk_widget_real_size_allocate (GtkWidget *widget,
4254 GtkAllocation *allocation)
4256 GtkWidgetPrivate *priv = widget->priv;
4258 priv->allocation = *allocation;
4260 if (gtk_widget_get_realized (widget) &&
4261 gtk_widget_get_has_window (widget))
4263 gdk_window_move_resize (priv->window,
4264 allocation->x, allocation->y,
4265 allocation->width, allocation->height);
4270 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4273 GtkWidgetPrivate *priv = widget->priv;
4275 /* widgets must be onscreen for accels to take effect */
4276 return gtk_widget_is_sensitive (widget) &&
4277 gtk_widget_is_drawable (widget) &&
4278 gdk_window_is_viewable (priv->window);
4282 * gtk_widget_can_activate_accel:
4283 * @widget: a #GtkWidget
4284 * @signal_id: the ID of a signal installed on @widget
4286 * Determines whether an accelerator that activates the signal
4287 * identified by @signal_id can currently be activated.
4288 * This is done by emitting the #GtkWidget::can-activate-accel
4289 * signal on @widget; if the signal isn't overridden by a
4290 * handler or in a derived widget, then the default check is
4291 * that the widget must be sensitive, and the widget and all
4292 * its ancestors mapped.
4294 * Return value: %TRUE if the accelerator can be activated.
4299 gtk_widget_can_activate_accel (GtkWidget *widget,
4302 gboolean can_activate = FALSE;
4303 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4304 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4305 return can_activate;
4314 closure_accel_activate (GClosure *closure,
4315 GValue *return_value,
4316 guint n_param_values,
4317 const GValue *param_values,
4318 gpointer invocation_hint,
4319 gpointer marshal_data)
4321 AccelClosure *aclosure = (AccelClosure*) closure;
4322 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4325 g_signal_emit (closure->data, aclosure->signal_id, 0);
4327 /* whether accelerator was handled */
4328 g_value_set_boolean (return_value, can_activate);
4332 closures_destroy (gpointer data)
4334 GSList *slist, *closures = data;
4336 for (slist = closures; slist; slist = slist->next)
4338 g_closure_invalidate (slist->data);
4339 g_closure_unref (slist->data);
4341 g_slist_free (closures);
4345 widget_new_accel_closure (GtkWidget *widget,
4348 AccelClosure *aclosure;
4349 GClosure *closure = NULL;
4350 GSList *slist, *closures;
4352 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4353 for (slist = closures; slist; slist = slist->next)
4354 if (!gtk_accel_group_from_accel_closure (slist->data))
4356 /* reuse this closure */
4357 closure = slist->data;
4362 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4363 closures = g_slist_prepend (closures, g_closure_ref (closure));
4364 g_closure_sink (closure);
4365 g_closure_set_marshal (closure, closure_accel_activate);
4367 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4369 aclosure = (AccelClosure*) closure;
4370 g_assert (closure->data == widget);
4371 g_assert (closure->marshal == closure_accel_activate);
4372 aclosure->signal_id = signal_id;
4378 * gtk_widget_add_accelerator
4379 * @widget: widget to install an accelerator on
4380 * @accel_signal: widget signal to emit on accelerator activation
4381 * @accel_group: accel group for this widget, added to its toplevel
4382 * @accel_key: GDK keyval of the accelerator
4383 * @accel_mods: modifier key combination of the accelerator
4384 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4386 * Installs an accelerator for this @widget in @accel_group that causes
4387 * @accel_signal to be emitted if the accelerator is activated.
4388 * The @accel_group needs to be added to the widget's toplevel via
4389 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4390 * Accelerators added through this function are not user changeable during
4391 * runtime. If you want to support accelerators that can be changed by the
4392 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4393 * gtk_menu_item_set_accel_path() instead.
4396 gtk_widget_add_accelerator (GtkWidget *widget,
4397 const gchar *accel_signal,
4398 GtkAccelGroup *accel_group,
4400 GdkModifierType accel_mods,
4401 GtkAccelFlags accel_flags)
4406 g_return_if_fail (GTK_IS_WIDGET (widget));
4407 g_return_if_fail (accel_signal != NULL);
4408 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4410 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4411 if (!query.signal_id ||
4412 !(query.signal_flags & G_SIGNAL_ACTION) ||
4413 query.return_type != G_TYPE_NONE ||
4416 /* hmm, should be elaborate enough */
4417 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4418 G_OBJECT_TYPE_NAME (widget), accel_signal);
4422 closure = widget_new_accel_closure (widget, query.signal_id);
4424 g_object_ref (widget);
4426 /* install the accelerator. since we don't map this onto an accel_path,
4427 * the accelerator will automatically be locked.
4429 gtk_accel_group_connect (accel_group,
4432 accel_flags | GTK_ACCEL_LOCKED,
4435 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4437 g_object_unref (widget);
4441 * gtk_widget_remove_accelerator:
4442 * @widget: widget to install an accelerator on
4443 * @accel_group: accel group for this widget
4444 * @accel_key: GDK keyval of the accelerator
4445 * @accel_mods: modifier key combination of the accelerator
4446 * @returns: whether an accelerator was installed and could be removed
4448 * Removes an accelerator from @widget, previously installed with
4449 * gtk_widget_add_accelerator().
4452 gtk_widget_remove_accelerator (GtkWidget *widget,
4453 GtkAccelGroup *accel_group,
4455 GdkModifierType accel_mods)
4457 GtkAccelGroupEntry *ag_entry;
4458 GList *slist, *clist;
4461 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4462 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4464 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4465 clist = gtk_widget_list_accel_closures (widget);
4466 for (slist = clist; slist; slist = slist->next)
4470 for (i = 0; i < n; i++)
4471 if (slist->data == (gpointer) ag_entry[i].closure)
4473 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4475 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4477 g_list_free (clist);
4482 g_list_free (clist);
4484 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4485 accel_key, accel_mods, accel_group,
4486 G_OBJECT_TYPE_NAME (widget), widget);
4492 * gtk_widget_list_accel_closures
4493 * @widget: widget to list accelerator closures for
4494 * @returns: a newly allocated #GList of closures
4496 * Lists the closures used by @widget for accelerator group connections
4497 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4498 * The closures can be used to monitor accelerator changes on @widget,
4499 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4500 * #GtkAccelGroup of a closure which can be found out with
4501 * gtk_accel_group_from_accel_closure().
4504 gtk_widget_list_accel_closures (GtkWidget *widget)
4507 GList *clist = NULL;
4509 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4511 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4512 if (gtk_accel_group_from_accel_closure (slist->data))
4513 clist = g_list_prepend (clist, slist->data);
4519 GtkAccelGroup *accel_group;
4524 destroy_accel_path (gpointer data)
4526 AccelPath *apath = data;
4528 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4530 /* closures_destroy takes care of unrefing the closure */
4531 g_object_unref (apath->accel_group);
4533 g_slice_free (AccelPath, apath);
4538 * gtk_widget_set_accel_path:
4539 * @widget: a #GtkWidget
4540 * @accel_path: (allow-none): path used to look up the accelerator
4541 * @accel_group: (allow-none): a #GtkAccelGroup.
4543 * Given an accelerator group, @accel_group, and an accelerator path,
4544 * @accel_path, sets up an accelerator in @accel_group so whenever the
4545 * key binding that is defined for @accel_path is pressed, @widget
4546 * will be activated. This removes any accelerators (for any
4547 * accelerator group) installed by previous calls to
4548 * gtk_widget_set_accel_path(). Associating accelerators with
4549 * paths allows them to be modified by the user and the modifications
4550 * to be saved for future use. (See gtk_accel_map_save().)
4552 * This function is a low level function that would most likely
4553 * be used by a menu creation system like #GtkUIManager. If you
4554 * use #GtkUIManager, setting up accelerator paths will be done
4557 * Even when you you aren't using #GtkUIManager, if you only want to
4558 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4559 * provides a somewhat more convenient interface.
4561 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4562 * pass a static string, you can save some memory by interning it first with
4563 * g_intern_static_string().
4566 gtk_widget_set_accel_path (GtkWidget *widget,
4567 const gchar *accel_path,
4568 GtkAccelGroup *accel_group)
4572 g_return_if_fail (GTK_IS_WIDGET (widget));
4573 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4577 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4578 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4580 gtk_accel_map_add_entry (accel_path, 0, 0);
4581 apath = g_slice_new (AccelPath);
4582 apath->accel_group = g_object_ref (accel_group);
4583 apath->path_quark = g_quark_from_string (accel_path);
4584 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4589 /* also removes possible old settings */
4590 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4593 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4595 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4599 _gtk_widget_get_accel_path (GtkWidget *widget,
4604 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4606 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4608 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4609 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4613 * gtk_widget_mnemonic_activate:
4614 * @widget: a #GtkWidget
4615 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4617 * Emits the #GtkWidget::mnemonic-activate signal.
4619 * The default handler for this signal activates the @widget if
4620 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4623 * Returns: %TRUE if the signal has been handled
4626 gtk_widget_mnemonic_activate (GtkWidget *widget,
4627 gboolean group_cycling)
4631 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4633 group_cycling = group_cycling != FALSE;
4634 if (!gtk_widget_is_sensitive (widget))
4637 g_signal_emit (widget,
4638 widget_signals[MNEMONIC_ACTIVATE],
4646 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4647 gboolean group_cycling)
4649 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4650 gtk_widget_activate (widget);
4651 else if (gtk_widget_get_can_focus (widget))
4652 gtk_widget_grab_focus (widget);
4655 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4656 G_OBJECT_TYPE_NAME (widget));
4657 gtk_widget_error_bell (widget);
4663 gtk_widget_real_key_press_event (GtkWidget *widget,
4666 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4670 gtk_widget_real_key_release_event (GtkWidget *widget,
4673 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4677 gtk_widget_real_focus_in_event (GtkWidget *widget,
4678 GdkEventFocus *event)
4680 gtk_widget_queue_shallow_draw (widget);
4686 gtk_widget_real_focus_out_event (GtkWidget *widget,
4687 GdkEventFocus *event)
4689 gtk_widget_queue_shallow_draw (widget);
4694 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4695 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4699 * @widget: a #GtkWidget
4700 * @event: a #GdkEvent
4702 * Rarely-used function. This function is used to emit
4703 * the event signals on a widget (those signals should never
4704 * be emitted without using this function to do so).
4705 * If you want to synthesize an event though, don't use this function;
4706 * instead, use gtk_main_do_event() so the event will behave as if
4707 * it were in the event queue. Don't synthesize expose events; instead,
4708 * use gdk_window_invalidate_rect() to invalidate a region of the
4711 * Return value: return from the event signal emission (%TRUE if
4712 * the event was handled)
4715 gtk_widget_event (GtkWidget *widget,
4718 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4719 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4721 if (event->type == GDK_EXPOSE)
4723 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4724 "the same effect, call gdk_window_invalidate_rect/region(), "
4725 "followed by gdk_window_process_updates().");
4729 return gtk_widget_event_internal (widget, event);
4734 * gtk_widget_send_expose:
4735 * @widget: a #GtkWidget
4736 * @event: a expose #GdkEvent
4738 * Very rarely-used function. This function is used to emit
4739 * an expose event signals on a widget. This function is not
4740 * normally used directly. The only time it is used is when
4741 * propagating an expose event to a child %NO_WINDOW widget, and
4742 * that is normally done using gtk_container_propagate_expose().
4744 * If you want to force an area of a window to be redrawn,
4745 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4746 * To cause the redraw to be done immediately, follow that call
4747 * with a call to gdk_window_process_updates().
4749 * Return value: return from the event signal emission (%TRUE if
4750 * the event was handled)
4753 gtk_widget_send_expose (GtkWidget *widget,
4756 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4757 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4758 g_return_val_if_fail (event != NULL, TRUE);
4759 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4761 return gtk_widget_event_internal (widget, event);
4765 event_window_is_still_viewable (GdkEvent *event)
4767 /* Some programs, such as gnome-theme-manager, fake widgets
4768 * into exposing onto a pixmap by sending expose events with
4769 * event->window pointing to a pixmap
4771 if (GDK_IS_PIXMAP (event->any.window))
4772 return event->type == GDK_EXPOSE;
4774 /* Check that we think the event's window is viewable before
4775 * delivering the event, to prevent suprises. We do this here
4776 * at the last moment, since the event may have been queued
4777 * up behind other events, held over a recursive main loop, etc.
4779 switch (event->type)
4782 case GDK_MOTION_NOTIFY:
4783 case GDK_BUTTON_PRESS:
4784 case GDK_2BUTTON_PRESS:
4785 case GDK_3BUTTON_PRESS:
4787 case GDK_ENTER_NOTIFY:
4788 case GDK_PROXIMITY_IN:
4790 return event->any.window && gdk_window_is_viewable (event->any.window);
4793 /* The following events are the second half of paired events;
4794 * we always deliver them to deal with widgets that clean up
4795 * on the second half.
4797 case GDK_BUTTON_RELEASE:
4798 case GDK_KEY_RELEASE:
4799 case GDK_LEAVE_NOTIFY:
4800 case GDK_PROXIMITY_OUT:
4804 /* Remaining events would make sense on an not-viewable window,
4805 * or don't have an associated window.
4812 gtk_widget_event_internal (GtkWidget *widget,
4815 gboolean return_val = FALSE;
4817 /* We check only once for is-still-visible; if someone
4818 * hides the window in on of the signals on the widget,
4819 * they are responsible for returning TRUE to terminate
4822 if (!event_window_is_still_viewable (event))
4825 g_object_ref (widget);
4827 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4828 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4833 switch (event->type)
4838 case GDK_BUTTON_PRESS:
4839 case GDK_2BUTTON_PRESS:
4840 case GDK_3BUTTON_PRESS:
4841 signal_num = BUTTON_PRESS_EVENT;
4844 signal_num = SCROLL_EVENT;
4846 case GDK_BUTTON_RELEASE:
4847 signal_num = BUTTON_RELEASE_EVENT;
4849 case GDK_MOTION_NOTIFY:
4850 signal_num = MOTION_NOTIFY_EVENT;
4853 signal_num = DELETE_EVENT;
4856 signal_num = DESTROY_EVENT;
4857 _gtk_tooltip_hide (widget);
4860 signal_num = KEY_PRESS_EVENT;
4862 case GDK_KEY_RELEASE:
4863 signal_num = KEY_RELEASE_EVENT;
4865 case GDK_ENTER_NOTIFY:
4866 signal_num = ENTER_NOTIFY_EVENT;
4868 case GDK_LEAVE_NOTIFY:
4869 signal_num = LEAVE_NOTIFY_EVENT;
4871 case GDK_FOCUS_CHANGE:
4872 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4873 if (event->focus_change.in)
4874 _gtk_tooltip_focus_in (widget);
4876 _gtk_tooltip_focus_out (widget);
4879 signal_num = CONFIGURE_EVENT;
4882 signal_num = MAP_EVENT;
4885 signal_num = UNMAP_EVENT;
4887 case GDK_WINDOW_STATE:
4888 signal_num = WINDOW_STATE_EVENT;
4890 case GDK_PROPERTY_NOTIFY:
4891 signal_num = PROPERTY_NOTIFY_EVENT;
4893 case GDK_SELECTION_CLEAR:
4894 signal_num = SELECTION_CLEAR_EVENT;
4896 case GDK_SELECTION_REQUEST:
4897 signal_num = SELECTION_REQUEST_EVENT;
4899 case GDK_SELECTION_NOTIFY:
4900 signal_num = SELECTION_NOTIFY_EVENT;
4902 case GDK_PROXIMITY_IN:
4903 signal_num = PROXIMITY_IN_EVENT;
4905 case GDK_PROXIMITY_OUT:
4906 signal_num = PROXIMITY_OUT_EVENT;
4909 signal_num = NO_EXPOSE_EVENT;
4911 case GDK_CLIENT_EVENT:
4912 signal_num = CLIENT_EVENT;
4915 signal_num = EXPOSE_EVENT;
4917 case GDK_VISIBILITY_NOTIFY:
4918 signal_num = VISIBILITY_NOTIFY_EVENT;
4920 case GDK_GRAB_BROKEN:
4921 signal_num = GRAB_BROKEN;
4924 signal_num = DAMAGE_EVENT;
4927 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4931 if (signal_num != -1)
4932 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4934 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4935 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4939 g_object_unref (widget);
4945 * gtk_widget_activate:
4946 * @widget: a #GtkWidget that's activatable
4948 * For widgets that can be "activated" (buttons, menu items, etc.)
4949 * this function activates them. Activation is what happens when you
4950 * press Enter on a widget during key navigation. If @widget isn't
4951 * activatable, the function returns %FALSE.
4953 * Return value: %TRUE if the widget was activatable
4956 gtk_widget_activate (GtkWidget *widget)
4958 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4960 if (WIDGET_CLASS (widget)->activate_signal)
4962 /* FIXME: we should eventually check the signals signature here */
4963 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4972 * gtk_widget_set_scroll_adjustments:
4973 * @widget: a #GtkWidget
4974 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
4975 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
4977 * For widgets that support scrolling, sets the scroll adjustments and
4978 * returns %TRUE. For widgets that don't support scrolling, does
4979 * nothing and returns %FALSE. Widgets that don't support scrolling
4980 * can be scrolled by placing them in a #GtkViewport, which does
4981 * support scrolling.
4983 * Return value: %TRUE if the widget supports scrolling
4986 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4987 GtkAdjustment *hadjustment,
4988 GtkAdjustment *vadjustment)
4993 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4996 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4998 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5000 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5004 g_signal_query (signal_id, &query);
5005 if (!query.signal_id ||
5006 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5007 query.return_type != G_TYPE_NONE ||
5008 query.n_params != 2 ||
5009 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5010 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5012 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5013 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5017 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5022 gtk_widget_reparent_subwindows (GtkWidget *widget,
5023 GdkWindow *new_window)
5025 GtkWidgetPrivate *priv = widget->priv;
5027 if (!gtk_widget_get_has_window (widget))
5029 GList *children = gdk_window_get_children (priv->window);
5032 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5034 GdkWindow *window = tmp_list->data;
5037 gdk_window_get_user_data (window, &child);
5038 while (child && child != widget)
5039 child = ((GtkWidget*) child)->priv->parent;
5042 gdk_window_reparent (window, new_window, 0, 0);
5045 g_list_free (children);
5050 GList *tmp_list, *children;
5052 parent = gdk_window_get_parent (priv->window);
5055 gdk_window_reparent (priv->window, new_window, 0, 0);
5058 children = gdk_window_get_children (parent);
5060 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5062 GdkWindow *window = tmp_list->data;
5065 gdk_window_get_user_data (window, &child);
5067 if (child == widget)
5068 gdk_window_reparent (window, new_window, 0, 0);
5071 g_list_free (children);
5077 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5078 gpointer client_data)
5080 GtkWidgetPrivate *priv = widget->priv;
5082 g_assert (client_data != NULL);
5084 if (!gtk_widget_get_has_window (widget))
5087 g_object_unref (priv->window);
5088 priv->window = (GdkWindow*) client_data;
5090 g_object_ref (priv->window);
5092 if (GTK_IS_CONTAINER (widget))
5093 gtk_container_forall (GTK_CONTAINER (widget),
5094 gtk_widget_reparent_fixup_child,
5100 * gtk_widget_reparent:
5101 * @widget: a #GtkWidget
5102 * @new_parent: a #GtkContainer to move the widget into
5104 * Moves a widget from one #GtkContainer to another, handling reference
5105 * count issues to avoid destroying the widget.
5108 gtk_widget_reparent (GtkWidget *widget,
5109 GtkWidget *new_parent)
5111 GtkWidgetPrivate *priv;
5113 g_return_if_fail (GTK_IS_WIDGET (widget));
5114 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5115 priv = widget->priv;
5116 g_return_if_fail (priv->parent != NULL);
5118 if (priv->parent != new_parent)
5120 /* First try to see if we can get away without unrealizing
5121 * the widget as we reparent it. if so we set a flag so
5122 * that gtk_widget_unparent doesn't unrealize widget
5124 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5125 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5127 g_object_ref (widget);
5128 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5129 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5130 g_object_unref (widget);
5132 if (GTK_WIDGET_IN_REPARENT (widget))
5134 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5136 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5137 gtk_widget_reparent_fixup_child (widget,
5138 gtk_widget_get_parent_window (widget));
5141 g_object_notify (G_OBJECT (widget), "parent");
5146 * gtk_widget_intersect:
5147 * @widget: a #GtkWidget
5148 * @area: a rectangle
5149 * @intersection: rectangle to store intersection of @widget and @area
5151 * Computes the intersection of a @widget's area and @area, storing
5152 * the intersection in @intersection, and returns %TRUE if there was
5153 * an intersection. @intersection may be %NULL if you're only
5154 * interested in whether there was an intersection.
5156 * Return value: %TRUE if there was an intersection
5159 gtk_widget_intersect (GtkWidget *widget,
5160 const GdkRectangle *area,
5161 GdkRectangle *intersection)
5163 GtkWidgetPrivate *priv;
5168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5169 g_return_val_if_fail (area != NULL, FALSE);
5171 priv = widget->priv;
5174 dest = intersection;
5178 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5180 if (return_val && intersection && gtk_widget_get_has_window (widget))
5182 intersection->x -= priv->allocation.x;
5183 intersection->y -= priv->allocation.y;
5190 * gtk_widget_region_intersect:
5191 * @widget: a #GtkWidget
5192 * @region: a #cairo_region_t, in the same coordinate system as
5193 * @widget->allocation. That is, relative to @widget->window
5194 * for %NO_WINDOW widgets; relative to the parent window
5195 * of @widget->window for widgets with their own window.
5196 * @returns: A newly allocated region holding the intersection of @widget
5197 * and @region. The coordinates of the return value are
5198 * relative to @widget->window for %NO_WINDOW widgets, and
5199 * relative to the parent window of @widget->window for
5200 * widgets with their own window.
5202 * Computes the intersection of a @widget's area and @region, returning
5203 * the intersection. The result may be empty, use cairo_region_is_empty() to
5207 gtk_widget_region_intersect (GtkWidget *widget,
5208 const cairo_region_t *region)
5211 cairo_region_t *dest;
5213 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5214 g_return_val_if_fail (region != NULL, NULL);
5216 gtk_widget_get_allocation (widget, &rect);
5218 dest = cairo_region_create_rectangle (&rect);
5220 cairo_region_intersect (dest, region);
5226 * _gtk_widget_grab_notify:
5227 * @widget: a #GtkWidget
5228 * @was_grabbed: whether a grab is now in effect
5230 * Emits the #GtkWidget::grab-notify signal on @widget.
5235 _gtk_widget_grab_notify (GtkWidget *widget,
5236 gboolean was_grabbed)
5238 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5242 * gtk_widget_grab_focus:
5243 * @widget: a #GtkWidget
5245 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5246 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5247 * something like #GtkFrame won't work.
5249 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5250 * gtk_widget_set_can_focus() to modify that flag.
5252 * The widget also needs to be realized and mapped. This is indicated by the
5253 * related signals. Grabbing the focus immediately after creating the widget
5254 * will likely fail and cause critical warnings.
5257 gtk_widget_grab_focus (GtkWidget *widget)
5259 g_return_if_fail (GTK_IS_WIDGET (widget));
5261 if (!gtk_widget_is_sensitive (widget))
5264 g_object_ref (widget);
5265 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5266 g_object_notify (G_OBJECT (widget), "has-focus");
5267 g_object_unref (widget);
5271 reset_focus_recurse (GtkWidget *widget,
5274 if (GTK_IS_CONTAINER (widget))
5276 GtkContainer *container;
5278 container = GTK_CONTAINER (widget);
5279 gtk_container_set_focus_child (container, NULL);
5281 gtk_container_foreach (container,
5282 reset_focus_recurse,
5288 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5290 if (gtk_widget_get_can_focus (focus_widget))
5292 GtkWidgetPrivate *priv;
5293 GtkWidget *toplevel;
5296 /* clear the current focus setting, break if the current widget
5297 * is the focus widget's parent, since containers above that will
5298 * be set by the next loop.
5300 toplevel = gtk_widget_get_toplevel (focus_widget);
5301 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5303 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5304 priv = widget->priv;
5306 if (widget == focus_widget)
5308 /* We call _gtk_window_internal_set_focus() here so that the
5309 * toplevel window can request the focus if necessary.
5310 * This is needed when the toplevel is a GtkPlug
5312 if (!gtk_widget_has_focus (widget))
5313 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5320 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5322 widget = widget->priv->parent;
5323 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5327 else if (toplevel != focus_widget)
5329 /* gtk_widget_grab_focus() operates on a tree without window...
5330 * actually, this is very questionable behaviour.
5333 gtk_container_foreach (GTK_CONTAINER (toplevel),
5334 reset_focus_recurse,
5338 /* now propagate the new focus up the widget tree and finally
5339 * set it on the window
5341 widget = focus_widget;
5342 while (widget->priv->parent)
5344 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5345 widget = widget->priv->parent;
5347 if (GTK_IS_WINDOW (widget))
5348 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5353 gtk_widget_real_query_tooltip (GtkWidget *widget,
5356 gboolean keyboard_tip,
5357 GtkTooltip *tooltip)
5359 gchar *tooltip_markup;
5360 gboolean has_tooltip;
5362 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5363 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5365 if (has_tooltip && tooltip_markup)
5367 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5375 gtk_widget_real_show_help (GtkWidget *widget,
5376 GtkWidgetHelpType help_type)
5378 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5380 _gtk_tooltip_toggle_keyboard_mode (widget);
5389 gtk_widget_real_focus (GtkWidget *widget,
5390 GtkDirectionType direction)
5392 if (!gtk_widget_get_can_focus (widget))
5395 if (!gtk_widget_is_focus (widget))
5397 gtk_widget_grab_focus (widget);
5405 gtk_widget_real_move_focus (GtkWidget *widget,
5406 GtkDirectionType direction)
5408 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5410 if (GTK_IS_WINDOW (toplevel) &&
5411 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5413 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5419 gtk_widget_real_keynav_failed (GtkWidget *widget,
5420 GtkDirectionType direction)
5422 gboolean cursor_only;
5426 case GTK_DIR_TAB_FORWARD:
5427 case GTK_DIR_TAB_BACKWARD:
5434 g_object_get (gtk_widget_get_settings (widget),
5435 "gtk-keynav-cursor-only", &cursor_only,
5442 gtk_widget_error_bell (widget);
5448 * gtk_widget_set_can_focus:
5449 * @widget: a #GtkWidget
5450 * @can_focus: whether or not @widget can own the input focus.
5452 * Specifies whether @widget can own the input focus. See
5453 * gtk_widget_grab_focus() for actually setting the input focus on a
5459 gtk_widget_set_can_focus (GtkWidget *widget,
5462 g_return_if_fail (GTK_IS_WIDGET (widget));
5464 if (can_focus != gtk_widget_get_can_focus (widget))
5467 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5469 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5471 gtk_widget_queue_resize (widget);
5472 g_object_notify (G_OBJECT (widget), "can-focus");
5477 * gtk_widget_get_can_focus:
5478 * @widget: a #GtkWidget
5480 * Determines whether @widget can own the input focus. See
5481 * gtk_widget_set_can_focus().
5483 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5488 gtk_widget_get_can_focus (GtkWidget *widget)
5490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5492 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5496 * gtk_widget_has_focus:
5497 * @widget: a #GtkWidget
5499 * Determines if the widget has the global input focus. See
5500 * gtk_widget_is_focus() for the difference between having the global
5501 * input focus, and only having the focus within a toplevel.
5503 * Return value: %TRUE if the widget has the global input focus.
5508 gtk_widget_has_focus (GtkWidget *widget)
5510 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5512 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5516 * gtk_widget_is_focus:
5517 * @widget: a #GtkWidget
5519 * Determines if the widget is the focus widget within its
5520 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5521 * necessarily set; %HAS_FOCUS will only be set if the
5522 * toplevel widget additionally has the global input focus.)
5524 * Return value: %TRUE if the widget is the focus widget.
5527 gtk_widget_is_focus (GtkWidget *widget)
5529 GtkWidget *toplevel;
5531 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5533 toplevel = gtk_widget_get_toplevel (widget);
5535 if (GTK_IS_WINDOW (toplevel))
5536 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
5542 * gtk_widget_set_can_default:
5543 * @widget: a #GtkWidget
5544 * @can_default: whether or not @widget can be a default widget.
5546 * Specifies whether @widget can be a default widget. See
5547 * gtk_widget_grab_default() for details about the meaning of
5553 gtk_widget_set_can_default (GtkWidget *widget,
5554 gboolean can_default)
5556 g_return_if_fail (GTK_IS_WIDGET (widget));
5558 if (can_default != gtk_widget_get_can_default (widget))
5561 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5563 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5565 gtk_widget_queue_resize (widget);
5566 g_object_notify (G_OBJECT (widget), "can-default");
5571 * gtk_widget_get_can_default:
5572 * @widget: a #GtkWidget
5574 * Determines whether @widget can be a default widget. See
5575 * gtk_widget_set_can_default().
5577 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5582 gtk_widget_get_can_default (GtkWidget *widget)
5584 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5586 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5590 * gtk_widget_has_default:
5591 * @widget: a #GtkWidget
5593 * Determines whether @widget is the current default widget within its
5594 * toplevel. See gtk_widget_set_can_default().
5596 * Return value: %TRUE if @widget is the current default widget within
5597 * its toplevel, %FALSE otherwise
5602 gtk_widget_has_default (GtkWidget *widget)
5604 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5606 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5610 _gtk_widget_set_has_default (GtkWidget *widget,
5611 gboolean has_default)
5614 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5616 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5620 * gtk_widget_grab_default:
5621 * @widget: a #GtkWidget
5623 * Causes @widget to become the default widget. @widget must have the
5624 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5625 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5626 * %TRUE)</literal>. The default widget is activated when
5627 * the user presses Enter in a window. Default widgets must be
5628 * activatable, that is, gtk_widget_activate() should affect them. Note
5629 * that #GtkEntry widgets require the "activates-default" property
5630 * set to %TRUE before they activate the default widget when Enter
5631 * is pressed and the #GtkEntry is focused.
5634 gtk_widget_grab_default (GtkWidget *widget)
5638 g_return_if_fail (GTK_IS_WIDGET (widget));
5639 g_return_if_fail (gtk_widget_get_can_default (widget));
5641 window = gtk_widget_get_toplevel (widget);
5643 if (window && gtk_widget_is_toplevel (window))
5644 gtk_window_set_default (GTK_WINDOW (window), widget);
5646 g_warning (G_STRLOC ": widget not within a GtkWindow");
5650 * gtk_widget_set_receives_default:
5651 * @widget: a #GtkWidget
5652 * @receives_default: whether or not @widget can be a default widget.
5654 * Specifies whether @widget will be treated as the default widget
5655 * within its toplevel when it has the focus, even if another widget
5658 * See gtk_widget_grab_default() for details about the meaning of
5664 gtk_widget_set_receives_default (GtkWidget *widget,
5665 gboolean receives_default)
5667 g_return_if_fail (GTK_IS_WIDGET (widget));
5669 if (receives_default != gtk_widget_get_receives_default (widget))
5671 if (receives_default)
5672 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5674 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5676 g_object_notify (G_OBJECT (widget), "receives-default");
5681 * gtk_widget_get_receives_default:
5682 * @widget: a #GtkWidget
5684 * Determines whether @widget is alyways treated as default widget
5685 * withing its toplevel when it has the focus, even if another widget
5688 * See gtk_widget_set_receives_default().
5690 * Return value: %TRUE if @widget acts as default widget when focussed,
5696 gtk_widget_get_receives_default (GtkWidget *widget)
5698 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5700 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5704 * gtk_widget_has_grab:
5705 * @widget: a #GtkWidget
5707 * Determines whether the widget is currently grabbing events, so it
5708 * is the only widget receiving input events (keyboard and mouse).
5710 * See also gtk_grab_add().
5712 * Return value: %TRUE if the widget is in the grab_widgets stack
5717 gtk_widget_has_grab (GtkWidget *widget)
5719 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5721 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5725 _gtk_widget_set_has_grab (GtkWidget *widget,
5729 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
5731 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
5735 * gtk_widget_device_is_shadowed:
5736 * @widget: a #GtkWidget
5737 * @device: a #GdkDevice
5739 * Returns %TRUE if @device has been shadowed by a GTK+
5740 * device grab on another widget, so it would stop sending
5741 * events to @widget. This may be used in the
5742 * #GtkWidget::grab-notify signal to check for specific
5743 * devices. See gtk_device_grab_add().
5745 * Returns: %TRUE if there is an ongoing grab on @device
5746 * by another #GtkWidget than @widget.
5751 gtk_widget_device_is_shadowed (GtkWidget *widget,
5754 GtkWindowGroup *group;
5755 GtkWidget *grab_widget, *toplevel;
5757 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5758 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
5760 if (!gtk_widget_get_realized (widget))
5763 toplevel = gtk_widget_get_toplevel (widget);
5765 if (GTK_IS_WINDOW (toplevel))
5766 group = gtk_window_get_group (GTK_WINDOW (toplevel));
5768 group = gtk_window_get_group (NULL);
5770 grab_widget = gtk_window_group_get_current_device_grab (group, device);
5772 /* Widget not inside the hierarchy of grab_widget */
5774 widget != grab_widget &&
5775 !gtk_widget_is_ancestor (widget, grab_widget))
5780 grab_widget = group->grabs->data;
5782 if (widget != grab_widget &&
5783 !gtk_widget_is_ancestor (widget, grab_widget))
5791 * gtk_widget_set_name:
5792 * @widget: a #GtkWidget
5793 * @name: name for the widget
5795 * Widgets can be named, which allows you to refer to them from a
5796 * gtkrc file. You can apply a style to widgets with a particular name
5797 * in the gtkrc file. See the documentation for gtkrc files (on the
5798 * same page as the docs for #GtkRcStyle).
5800 * Note that widget names are separated by periods in paths (see
5801 * gtk_widget_path()), so names with embedded periods may cause confusion.
5804 gtk_widget_set_name (GtkWidget *widget,
5807 GtkWidgetPrivate *priv;
5810 g_return_if_fail (GTK_IS_WIDGET (widget));
5812 priv = widget->priv;
5814 new_name = g_strdup (name);
5815 g_free (priv->name);
5816 priv->name = new_name;
5818 if (gtk_widget_has_rc_style (widget))
5819 gtk_widget_reset_rc_style (widget);
5821 g_object_notify (G_OBJECT (widget), "name");
5825 * gtk_widget_get_name:
5826 * @widget: a #GtkWidget
5828 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5829 * significance of widget names.
5831 * Return value: name of the widget. This string is owned by GTK+ and
5832 * should not be modified or freed
5834 G_CONST_RETURN gchar*
5835 gtk_widget_get_name (GtkWidget *widget)
5837 GtkWidgetPrivate *priv;
5839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5841 priv = widget->priv;
5845 return G_OBJECT_TYPE_NAME (widget);
5849 * gtk_widget_set_state:
5850 * @widget: a #GtkWidget
5851 * @state: new state for @widget
5853 * This function is for use in widget implementations. Sets the state
5854 * of a widget (insensitive, prelighted, etc.) Usually you should set
5855 * the state using wrapper functions such as gtk_widget_set_sensitive().
5858 gtk_widget_set_state (GtkWidget *widget,
5861 GtkWidgetPrivate *priv;
5863 g_return_if_fail (GTK_IS_WIDGET (widget));
5865 priv = widget->priv;
5867 if (state == gtk_widget_get_state (widget))
5870 if (state == GTK_STATE_INSENSITIVE)
5871 gtk_widget_set_sensitive (widget, FALSE);
5877 data.state_restoration = FALSE;
5878 data.use_forall = FALSE;
5880 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
5882 data.parent_sensitive = TRUE;
5884 gtk_widget_propagate_state (widget, &data);
5886 if (gtk_widget_is_drawable (widget))
5887 gtk_widget_queue_draw (widget);
5892 * gtk_widget_get_state:
5893 * @widget: a #GtkWidget
5895 * Returns the widget's state. See gtk_widget_set_state().
5897 * Returns: the state of @widget.
5902 gtk_widget_get_state (GtkWidget *widget)
5904 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5906 return widget->priv->state;
5910 * gtk_widget_set_visible:
5911 * @widget: a #GtkWidget
5912 * @visible: whether the widget should be shown or not
5914 * Sets the visibility state of @widget. Note that setting this to
5915 * %TRUE doesn't mean the widget is actually viewable, see
5916 * gtk_widget_get_visible().
5918 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5919 * but is nicer to use when the visibility of the widget depends on
5925 gtk_widget_set_visible (GtkWidget *widget,
5928 g_return_if_fail (GTK_IS_WIDGET (widget));
5930 if (visible != gtk_widget_get_visible (widget))
5933 gtk_widget_show (widget);
5935 gtk_widget_hide (widget);
5940 * gtk_widget_get_visible:
5941 * @widget: a #GtkWidget
5943 * Determines whether the widget is visible. Note that this doesn't
5944 * take into account whether the widget's parent is also visible
5945 * or the widget is obscured in any way.
5947 * See gtk_widget_set_visible().
5949 * Return value: %TRUE if the widget is visible
5954 gtk_widget_get_visible (GtkWidget *widget)
5956 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5958 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5962 * gtk_widget_set_has_window:
5963 * @widget: a #GtkWidget
5964 * @has_window: whether or not @widget has a window.
5966 * Specifies whether @widget has a #GdkWindow of its own. Note that
5967 * all realized widgets have a non-%NULL "window" pointer
5968 * (gtk_widget_get_window() never returns a %NULL window when a widget
5969 * is realized), but for many of them it's actually the #GdkWindow of
5970 * one of its parent widgets. Widgets that do not create a %window for
5971 * themselves in GtkWidget::realize() must announce this by
5972 * calling this function with @has_window = %FALSE.
5974 * This function should only be called by widget implementations,
5975 * and they should call it in their init() function.
5980 gtk_widget_set_has_window (GtkWidget *widget,
5981 gboolean has_window)
5983 g_return_if_fail (GTK_IS_WIDGET (widget));
5986 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5988 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5992 * gtk_widget_get_has_window:
5993 * @widget: a #GtkWidget
5995 * Determines whether @widget has a #GdkWindow of its own. See
5996 * gtk_widget_set_has_window().
5998 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6003 gtk_widget_get_has_window (GtkWidget *widget)
6005 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6007 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6011 * gtk_widget_is_toplevel:
6012 * @widget: a #GtkWidget
6014 * Determines whether @widget is a toplevel widget. Currently only
6015 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6016 * widgets have no parent widget.
6018 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6023 gtk_widget_is_toplevel (GtkWidget *widget)
6025 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6027 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6031 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6032 gboolean is_toplevel)
6035 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6037 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6041 * gtk_widget_is_drawable:
6042 * @widget: a #GtkWidget
6044 * Determines whether @widget can be drawn to. A widget can be drawn
6045 * to if it is mapped and visible.
6047 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6052 gtk_widget_is_drawable (GtkWidget *widget)
6054 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6056 return (gtk_widget_get_visible (widget) &&
6057 gtk_widget_get_mapped (widget));
6061 * gtk_widget_get_realized:
6062 * @widget: a #GtkWidget
6064 * Determines whether @widget is realized.
6066 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6071 gtk_widget_get_realized (GtkWidget *widget)
6073 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6075 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6079 * gtk_widget_set_realized:
6080 * @widget: a #GtkWidget
6081 * @realized: %TRUE to mark the widget as realized
6083 * Marks the widget as being realized.
6085 * This function should only ever be called in a derived widget's
6086 * "realize" or "unrealize" implementation.
6091 gtk_widget_set_realized (GtkWidget *widget,
6094 g_return_if_fail (GTK_IS_WIDGET (widget));
6097 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6099 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6103 * gtk_widget_get_mapped:
6104 * @widget: a #GtkWidget
6106 * Whether the widget is mapped.
6108 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6113 gtk_widget_get_mapped (GtkWidget *widget)
6115 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6117 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6121 * gtk_widget_set_mapped:
6122 * @widget: a #GtkWidget
6123 * @mapped: %TRUE to mark the widget as mapped
6125 * Marks the widget as being realized.
6127 * This function should only ever be called in a derived widget's
6128 * "map" or "unmap" implementation.
6133 gtk_widget_set_mapped (GtkWidget *widget,
6136 g_return_if_fail (GTK_IS_WIDGET (widget));
6139 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6141 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6145 * gtk_widget_set_app_paintable:
6146 * @widget: a #GtkWidget
6147 * @app_paintable: %TRUE if the application will paint on the widget
6149 * Sets whether the application intends to draw on the widget in
6150 * an #GtkWidget::expose-event handler.
6152 * This is a hint to the widget and does not affect the behavior of
6153 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6154 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6155 * the effect is to suppress default themed drawing of the widget's
6156 * background. (Children of the widget will still be drawn.) The application
6157 * is then entirely responsible for drawing the widget background.
6159 * Note that the background is still drawn when the widget is mapped.
6160 * If this is not suitable (e.g. because you want to make a transparent
6161 * window using an RGBA visual), you can work around this by doing:
6163 * gtk_widget_realize (window);
6164 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6165 * gtk_widget_show (window);
6169 gtk_widget_set_app_paintable (GtkWidget *widget,
6170 gboolean app_paintable)
6172 g_return_if_fail (GTK_IS_WIDGET (widget));
6174 app_paintable = (app_paintable != FALSE);
6176 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6179 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6181 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6183 if (gtk_widget_is_drawable (widget))
6184 gtk_widget_queue_draw (widget);
6186 g_object_notify (G_OBJECT (widget), "app-paintable");
6191 * gtk_widget_get_app_paintable:
6192 * @widget: a #GtkWidget
6194 * Determines whether the application intends to draw on the widget in
6195 * an #GtkWidget::expose-event handler.
6197 * See gtk_widget_set_app_paintable()
6199 * Return value: %TRUE if the widget is app paintable
6204 gtk_widget_get_app_paintable (GtkWidget *widget)
6206 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6208 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6212 * gtk_widget_set_double_buffered:
6213 * @widget: a #GtkWidget
6214 * @double_buffered: %TRUE to double-buffer a widget
6216 * Widgets are double buffered by default; you can use this function
6217 * to turn off the buffering. "Double buffered" simply means that
6218 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6219 * automatically around expose events sent to the
6220 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6221 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6222 * buffer to the screen. The result is that users see the window
6223 * update in one smooth step, and don't see individual graphics
6224 * primitives being rendered.
6226 * In very simple terms, double buffered widgets don't flicker,
6227 * so you would only use this function to turn off double buffering
6228 * if you had special needs and really knew what you were doing.
6230 * Note: if you turn off double-buffering, you have to handle
6231 * expose events, since even the clearing to the background color or
6232 * pixmap will not happen automatically (as it is done in
6233 * gdk_window_begin_paint()).
6236 gtk_widget_set_double_buffered (GtkWidget *widget,
6237 gboolean double_buffered)
6239 g_return_if_fail (GTK_IS_WIDGET (widget));
6241 double_buffered = (double_buffered != FALSE);
6243 if (double_buffered != gtk_widget_get_double_buffered (widget))
6245 if (double_buffered)
6246 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6248 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6250 g_object_notify (G_OBJECT (widget), "double-buffered");
6255 * gtk_widget_get_double_buffered:
6256 * @widget: a #GtkWidget
6258 * Determines whether the widget is double buffered.
6260 * See gtk_widget_set_double_buffered()
6262 * Return value: %TRUE if the widget is double buffered
6267 gtk_widget_get_double_buffered (GtkWidget *widget)
6269 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6271 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6275 * gtk_widget_set_redraw_on_allocate:
6276 * @widget: a #GtkWidget
6277 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6278 * when it is allocated to a new size. Otherwise, only the
6279 * new portion of the widget will be redrawn.
6281 * Sets whether the entire widget is queued for drawing when its size
6282 * allocation changes. By default, this setting is %TRUE and
6283 * the entire widget is redrawn on every size change. If your widget
6284 * leaves the upper left unchanged when made bigger, turning this
6285 * setting off will improve performance.
6287 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6288 * off all allocation on resizing: the widget will not even redraw if
6289 * its position changes; this is to allow containers that don't draw
6290 * anything to avoid excess invalidations. If you set this flag on a
6291 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6292 * you are responsible for invalidating both the old and new allocation
6293 * of the widget when the widget is moved and responsible for invalidating
6294 * regions newly when the widget increases size.
6297 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6298 gboolean redraw_on_allocate)
6300 g_return_if_fail (GTK_IS_WIDGET (widget));
6302 if (redraw_on_allocate)
6303 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6305 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6309 * gtk_widget_set_sensitive:
6310 * @widget: a #GtkWidget
6311 * @sensitive: %TRUE to make the widget sensitive
6313 * Sets the sensitivity of a widget. A widget is sensitive if the user
6314 * can interact with it. Insensitive widgets are "grayed out" and the
6315 * user can't interact with them. Insensitive widgets are known as
6316 * "inactive", "disabled", or "ghosted" in some other toolkits.
6319 gtk_widget_set_sensitive (GtkWidget *widget,
6322 GtkWidgetPrivate *priv;
6325 g_return_if_fail (GTK_IS_WIDGET (widget));
6327 priv = widget->priv;
6329 sensitive = (sensitive != FALSE);
6331 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6336 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6337 data.state = priv->saved_state;
6341 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6342 data.state = gtk_widget_get_state (widget);
6344 data.state_restoration = TRUE;
6345 data.use_forall = TRUE;
6348 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6350 data.parent_sensitive = TRUE;
6352 gtk_widget_propagate_state (widget, &data);
6353 if (gtk_widget_is_drawable (widget))
6354 gtk_widget_queue_draw (widget);
6356 g_object_notify (G_OBJECT (widget), "sensitive");
6360 * gtk_widget_get_sensitive:
6361 * @widget: a #GtkWidget
6363 * Returns the widget's sensitivity (in the sense of returning
6364 * the value that has been set using gtk_widget_set_sensitive()).
6366 * The effective sensitivity of a widget is however determined by both its
6367 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6369 * Returns: %TRUE if the widget is sensitive
6374 gtk_widget_get_sensitive (GtkWidget *widget)
6376 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6378 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6382 * gtk_widget_is_sensitive:
6383 * @widget: a #GtkWidget
6385 * Returns the widget's effective sensitivity, which means
6386 * it is sensitive itself and also its parent widget is sensntive
6388 * Returns: %TRUE if the widget is effectively sensitive
6393 gtk_widget_is_sensitive (GtkWidget *widget)
6395 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6397 return (gtk_widget_get_sensitive (widget) &&
6398 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6402 * gtk_widget_set_parent:
6403 * @widget: a #GtkWidget
6404 * @parent: parent container
6406 * This function is useful only when implementing subclasses of
6408 * Sets the container as the parent of @widget, and takes care of
6409 * some details such as updating the state and style of the child
6410 * to reflect its new location. The opposite function is
6411 * gtk_widget_unparent().
6414 gtk_widget_set_parent (GtkWidget *widget,
6417 GtkWidgetPrivate *priv;
6420 g_return_if_fail (GTK_IS_WIDGET (widget));
6421 g_return_if_fail (GTK_IS_WIDGET (parent));
6422 g_return_if_fail (widget != parent);
6424 priv = widget->priv;
6426 if (priv->parent != NULL)
6428 g_warning ("Can't set a parent on widget which has a parent\n");
6431 if (gtk_widget_is_toplevel (widget))
6433 g_warning ("Can't set a parent on a toplevel widget\n");
6437 /* keep this function in sync with gtk_menu_attach_to_widget()
6440 g_object_ref_sink (widget);
6441 priv->parent = parent;
6443 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6444 data.state = gtk_widget_get_state (parent);
6446 data.state = gtk_widget_get_state (widget);
6447 data.state_restoration = FALSE;
6448 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6449 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6451 gtk_widget_propagate_state (widget, &data);
6453 gtk_widget_reset_rc_styles (widget);
6455 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6456 if (GTK_WIDGET_ANCHORED (priv->parent))
6457 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6458 g_object_notify (G_OBJECT (widget), "parent");
6460 /* Enforce realized/mapped invariants
6462 if (gtk_widget_get_realized (priv->parent))
6463 gtk_widget_realize (widget);
6465 if (gtk_widget_get_visible (priv->parent) &&
6466 gtk_widget_get_visible (widget))
6468 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6469 gtk_widget_get_mapped (priv->parent))
6470 gtk_widget_map (widget);
6472 gtk_widget_queue_resize (widget);
6477 * gtk_widget_get_parent:
6478 * @widget: a #GtkWidget
6480 * Returns the parent container of @widget.
6482 * Return value: (transfer none): the parent container of @widget, or %NULL
6485 gtk_widget_get_parent (GtkWidget *widget)
6487 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6489 return widget->priv->parent;
6492 /*****************************************
6494 * see docs/styles.txt
6495 *****************************************/
6498 * gtk_widget_style_attach:
6499 * @widget: a #GtkWidget
6501 * This function attaches the widget's #GtkStyle to the widget's
6502 * #GdkWindow. It is a replacement for
6505 * widget->style = gtk_style_attach (widget->style, widget->window);
6508 * and should only ever be called in a derived widget's "realize"
6509 * implementation which does not chain up to its parent class'
6510 * "realize" implementation, because one of the parent classes
6511 * (finally #GtkWidget) would attach the style itself.
6516 gtk_widget_style_attach (GtkWidget *widget)
6518 GtkWidgetPrivate *priv;
6520 g_return_if_fail (GTK_IS_WIDGET (widget));
6521 g_return_if_fail (gtk_widget_get_realized (widget));
6523 priv = widget->priv;
6525 priv->style = gtk_style_attach (priv->style, priv->window);
6529 * gtk_widget_has_rc_style:
6530 * @widget: a #GtkWidget
6532 * Determines if the widget style has been looked up through the rc mechanism.
6534 * Returns: %TRUE if the widget has been looked up through the rc
6535 * mechanism, %FALSE otherwise.
6540 gtk_widget_has_rc_style (GtkWidget *widget)
6542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6544 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6548 * gtk_widget_set_style:
6549 * @widget: a #GtkWidget
6550 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6551 * gtk_widget_set_style() and go back to the default style
6553 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6554 * want to use this function; it interacts badly with themes, because
6555 * themes work by replacing the #GtkStyle. Instead, use
6556 * gtk_widget_modify_style().
6559 gtk_widget_set_style (GtkWidget *widget,
6562 g_return_if_fail (GTK_IS_WIDGET (widget));
6566 gboolean initial_emission;
6568 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6570 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6571 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6573 gtk_widget_set_style_internal (widget, style, initial_emission);
6577 if (GTK_WIDGET_USER_STYLE (widget))
6578 gtk_widget_reset_rc_style (widget);
6583 * gtk_widget_ensure_style:
6584 * @widget: a #GtkWidget
6586 * Ensures that @widget has a style (@widget->style). Not a very useful
6587 * function; most of the time, if you want the style, the widget is
6588 * realized, and realized widgets are guaranteed to have a style
6592 gtk_widget_ensure_style (GtkWidget *widget)
6594 g_return_if_fail (GTK_IS_WIDGET (widget));
6596 if (!GTK_WIDGET_USER_STYLE (widget) &&
6597 !gtk_widget_has_rc_style (widget))
6598 gtk_widget_reset_rc_style (widget);
6601 /* Look up the RC style for this widget, unsetting any user style that
6602 * may be in effect currently
6605 gtk_widget_reset_rc_style (GtkWidget *widget)
6607 GtkWidgetPrivate *priv = widget->priv;
6608 GtkStyle *new_style = NULL;
6609 gboolean initial_emission;
6611 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6613 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6614 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6616 if (gtk_widget_has_screen (widget))
6617 new_style = gtk_rc_get_style (widget);
6619 new_style = gtk_widget_get_default_style ();
6621 if (initial_emission || new_style != priv->style)
6622 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6626 * gtk_widget_get_style:
6627 * @widget: a #GtkWidget
6629 * Simply an accessor function that returns @widget->style.
6631 * Return value: (transfer none): the widget's #GtkStyle
6634 gtk_widget_get_style (GtkWidget *widget)
6636 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6638 return widget->priv->style;
6642 * gtk_widget_modify_style:
6643 * @widget: a #GtkWidget
6644 * @style: the #GtkRcStyle holding the style modifications
6646 * Modifies style values on the widget. Modifications made using this
6647 * technique take precedence over style values set via an RC file,
6648 * however, they will be overriden if a style is explicitely set on
6649 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6650 * is designed so each field can either be set or unset, so it is
6651 * possible, using this function, to modify some style values and
6652 * leave the others unchanged.
6654 * Note that modifications made with this function are not cumulative
6655 * with previous calls to gtk_widget_modify_style() or with such
6656 * functions as gtk_widget_modify_fg(). If you wish to retain
6657 * previous values, you must first call gtk_widget_get_modifier_style(),
6658 * make your modifications to the returned style, then call
6659 * gtk_widget_modify_style() with that style. On the other hand,
6660 * if you first call gtk_widget_modify_style(), subsequent calls
6661 * to such functions gtk_widget_modify_fg() will have a cumulative
6662 * effect with the initial modifications.
6665 gtk_widget_modify_style (GtkWidget *widget,
6668 g_return_if_fail (GTK_IS_WIDGET (widget));
6669 g_return_if_fail (GTK_IS_RC_STYLE (style));
6671 g_object_set_qdata_full (G_OBJECT (widget),
6673 gtk_rc_style_copy (style),
6674 (GDestroyNotify) g_object_unref);
6676 /* note that "style" may be invalid here if it was the old
6677 * modifier style and the only reference was our own.
6680 if (gtk_widget_has_rc_style (widget))
6681 gtk_widget_reset_rc_style (widget);
6685 * gtk_widget_get_modifier_style:
6686 * @widget: a #GtkWidget
6688 * Returns the current modifier style for the widget. (As set by
6689 * gtk_widget_modify_style().) If no style has previously set, a new
6690 * #GtkRcStyle will be created with all values unset, and set as the
6691 * modifier style for the widget. If you make changes to this rc
6692 * style, you must call gtk_widget_modify_style(), passing in the
6693 * returned rc style, to make sure that your changes take effect.
6695 * Caution: passing the style back to gtk_widget_modify_style() will
6696 * normally end up destroying it, because gtk_widget_modify_style() copies
6697 * the passed-in style and sets the copy as the new modifier style,
6698 * thus dropping any reference to the old modifier style. Add a reference
6699 * to the modifier style if you want to keep it alive.
6701 * Return value: (transfer none): the modifier style for the widget. This rc style is
6702 * owned by the widget. If you want to keep a pointer to value this
6703 * around, you must add a refcount using g_object_ref().
6706 gtk_widget_get_modifier_style (GtkWidget *widget)
6708 GtkRcStyle *rc_style;
6710 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6712 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6716 rc_style = gtk_rc_style_new ();
6717 g_object_set_qdata_full (G_OBJECT (widget),
6720 (GDestroyNotify) g_object_unref);
6727 gtk_widget_modify_color_component (GtkWidget *widget,
6728 GtkRcFlags component,
6730 const GdkColor *color)
6732 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6739 rc_style->fg[state] = *color;
6742 rc_style->bg[state] = *color;
6745 rc_style->text[state] = *color;
6748 rc_style->base[state] = *color;
6751 g_assert_not_reached();
6754 rc_style->color_flags[state] |= component;
6757 rc_style->color_flags[state] &= ~component;
6759 gtk_widget_modify_style (widget, rc_style);
6763 * gtk_widget_modify_symbolic_color:
6764 * @widget: a #GtkWidget
6765 * @name: the name of the symbolic color to modify
6766 * @color: (allow-none): the color to assign (does not need to be allocated),
6767 * or %NULL to undo the effect of previous calls to
6768 * of gtk_widget_modify_symbolic_color().
6770 * Sets a symbolic color for a widget.
6771 * All other style values are left untouched. See also
6772 * gtk_widget_modify_style().
6777 gtk_widget_modify_symbolic_color (GtkWidget *widget,
6779 const GdkColor *color)
6781 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6783 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
6785 gtk_widget_modify_style (widget, rc_style);
6789 * gtk_widget_modify_fg:
6790 * @widget: a #GtkWidget
6791 * @state: the state for which to set the foreground color
6792 * @color: (allow-none): the color to assign (does not need to be allocated),
6793 * or %NULL to undo the effect of previous calls to
6794 * of gtk_widget_modify_fg().
6796 * Sets the foreground color for a widget in a particular state.
6797 * All other style values are left untouched. See also
6798 * gtk_widget_modify_style().
6801 gtk_widget_modify_fg (GtkWidget *widget,
6803 const GdkColor *color)
6805 g_return_if_fail (GTK_IS_WIDGET (widget));
6806 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6808 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6812 * gtk_widget_modify_bg:
6813 * @widget: a #GtkWidget
6814 * @state: the state for which to set the background color
6815 * @color: (allow-none): the color to assign (does not need to be allocated),
6816 * or %NULL to undo the effect of previous calls to
6817 * of gtk_widget_modify_bg().
6819 * Sets the background color for a widget in a particular state.
6820 * All other style values are left untouched. See also
6821 * gtk_widget_modify_style().
6823 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6824 * draw on their parent container's window and thus may not draw any
6825 * background themselves. This is the case for e.g. #GtkLabel. To modify
6826 * the background of such widgets, you have to set the background color
6827 * on their parent; if you want to set the background of a rectangular
6828 * area around a label, try placing the label in a #GtkEventBox widget
6829 * and setting the background color on that.
6832 gtk_widget_modify_bg (GtkWidget *widget,
6834 const GdkColor *color)
6836 g_return_if_fail (GTK_IS_WIDGET (widget));
6837 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6839 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6843 * gtk_widget_modify_text:
6844 * @widget: a #GtkWidget
6845 * @state: the state for which to set the text color
6846 * @color: (allow-none): the color to assign (does not need to be allocated),
6847 * or %NULL to undo the effect of previous calls to
6848 * of gtk_widget_modify_text().
6850 * Sets the text color for a widget in a particular state. All other
6851 * style values are left untouched. The text color is the foreground
6852 * color used along with the base color (see gtk_widget_modify_base())
6853 * for widgets such as #GtkEntry and #GtkTextView. See also
6854 * gtk_widget_modify_style().
6857 gtk_widget_modify_text (GtkWidget *widget,
6859 const GdkColor *color)
6861 g_return_if_fail (GTK_IS_WIDGET (widget));
6862 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6864 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6868 * gtk_widget_modify_base:
6869 * @widget: a #GtkWidget
6870 * @state: the state for which to set the base color
6871 * @color: (allow-none): the color to assign (does not need to be allocated),
6872 * or %NULL to undo the effect of previous calls to
6873 * of gtk_widget_modify_base().
6875 * Sets the base color for a widget in a particular state.
6876 * All other style values are left untouched. The base color
6877 * is the background color used along with the text color
6878 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6879 * and #GtkTextView. See also gtk_widget_modify_style().
6881 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6882 * draw on their parent container's window and thus may not draw any
6883 * background themselves. This is the case for e.g. #GtkLabel. To modify
6884 * the background of such widgets, you have to set the base color on their
6885 * parent; if you want to set the background of a rectangular area around
6886 * a label, try placing the label in a #GtkEventBox widget and setting
6887 * the base color on that.
6890 gtk_widget_modify_base (GtkWidget *widget,
6892 const GdkColor *color)
6894 g_return_if_fail (GTK_IS_WIDGET (widget));
6895 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6897 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6901 modify_color_property (GtkWidget *widget,
6902 GtkRcStyle *rc_style,
6904 const GdkColor *color)
6906 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6907 GQuark property_name = g_quark_from_string (name);
6911 GtkRcProperty rc_property = {0};
6914 rc_property.type_name = type_name;
6915 rc_property.property_name = property_name;
6916 rc_property.origin = NULL;
6918 color_name = gdk_color_to_string (color);
6919 g_value_init (&rc_property.value, G_TYPE_STRING);
6920 g_value_take_string (&rc_property.value, color_name);
6922 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6924 g_value_unset (&rc_property.value);
6927 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6931 * gtk_widget_modify_cursor:
6932 * @widget: a #GtkWidget
6933 * @primary: the color to use for primary cursor (does not need to be
6934 * allocated), or %NULL to undo the effect of previous calls to
6935 * of gtk_widget_modify_cursor().
6936 * @secondary: the color to use for secondary cursor (does not need to be
6937 * allocated), or %NULL to undo the effect of previous calls to
6938 * of gtk_widget_modify_cursor().
6940 * Sets the cursor color to use in a widget, overriding the
6941 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6942 * style properties. All other style values are left untouched.
6943 * See also gtk_widget_modify_style().
6948 gtk_widget_modify_cursor (GtkWidget *widget,
6949 const GdkColor *primary,
6950 const GdkColor *secondary)
6952 GtkRcStyle *rc_style;
6954 g_return_if_fail (GTK_IS_WIDGET (widget));
6956 rc_style = gtk_widget_get_modifier_style (widget);
6958 modify_color_property (widget, rc_style, "cursor-color", primary);
6959 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6961 gtk_widget_modify_style (widget, rc_style);
6965 * gtk_widget_modify_font:
6966 * @widget: a #GtkWidget
6967 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6968 * the effect of previous calls to gtk_widget_modify_font().
6970 * Sets the font to use for a widget. All other style values are left
6971 * untouched. See also gtk_widget_modify_style().
6974 gtk_widget_modify_font (GtkWidget *widget,
6975 PangoFontDescription *font_desc)
6977 GtkRcStyle *rc_style;
6979 g_return_if_fail (GTK_IS_WIDGET (widget));
6981 rc_style = gtk_widget_get_modifier_style (widget);
6983 if (rc_style->font_desc)
6984 pango_font_description_free (rc_style->font_desc);
6987 rc_style->font_desc = pango_font_description_copy (font_desc);
6989 rc_style->font_desc = NULL;
6991 gtk_widget_modify_style (widget, rc_style);
6995 gtk_widget_real_direction_changed (GtkWidget *widget,
6996 GtkTextDirection previous_direction)
6998 gtk_widget_queue_resize (widget);
7002 gtk_widget_real_style_set (GtkWidget *widget,
7003 GtkStyle *previous_style)
7005 GtkWidgetPrivate *priv = widget->priv;
7007 if (gtk_widget_get_realized (widget) &&
7008 gtk_widget_get_has_window (widget))
7009 gtk_style_set_background (priv->style, priv->window, priv->state);
7013 gtk_widget_set_style_internal (GtkWidget *widget,
7015 gboolean initial_emission)
7017 GtkWidgetPrivate *priv = widget->priv;
7019 g_object_ref (widget);
7020 g_object_freeze_notify (G_OBJECT (widget));
7022 if (priv->style != style)
7024 GtkStyle *previous_style;
7026 if (gtk_widget_get_realized (widget))
7028 gtk_widget_reset_shapes (widget);
7029 gtk_style_detach (priv->style);
7032 previous_style = priv->style;
7033 priv->style = style;
7034 g_object_ref (priv->style);
7036 if (gtk_widget_get_realized (widget))
7037 priv->style = gtk_style_attach (priv->style, priv->window);
7039 gtk_widget_update_pango_context (widget);
7040 g_signal_emit (widget,
7041 widget_signals[STYLE_SET],
7043 initial_emission ? NULL : previous_style);
7044 g_object_unref (previous_style);
7046 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7047 gtk_widget_queue_resize (widget);
7049 else if (initial_emission)
7051 gtk_widget_update_pango_context (widget);
7052 g_signal_emit (widget,
7053 widget_signals[STYLE_SET],
7057 g_object_notify (G_OBJECT (widget), "style");
7058 g_object_thaw_notify (G_OBJECT (widget));
7059 g_object_unref (widget);
7063 GtkWidget *previous_toplevel;
7064 GdkScreen *previous_screen;
7065 GdkScreen *new_screen;
7066 } HierarchyChangedInfo;
7069 do_screen_change (GtkWidget *widget,
7070 GdkScreen *old_screen,
7071 GdkScreen *new_screen)
7073 if (old_screen != new_screen)
7077 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7079 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7082 _gtk_tooltip_hide (widget);
7083 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7088 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7089 gpointer client_data)
7091 GtkWidgetPrivate *priv = widget->priv;
7092 HierarchyChangedInfo *info = client_data;
7093 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7094 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7096 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7098 g_object_ref (widget);
7101 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7103 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7105 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7106 do_screen_change (widget, info->previous_screen, info->new_screen);
7108 if (GTK_IS_CONTAINER (widget))
7109 gtk_container_forall (GTK_CONTAINER (widget),
7110 gtk_widget_propagate_hierarchy_changed_recurse,
7113 g_object_unref (widget);
7118 * _gtk_widget_propagate_hierarchy_changed:
7119 * @widget: a #GtkWidget
7120 * @previous_toplevel: Previous toplevel
7122 * Propagates changes in the anchored state to a widget and all
7123 * children, unsetting or setting the %ANCHORED flag, and
7124 * emitting #GtkWidget::hierarchy-changed.
7127 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7128 GtkWidget *previous_toplevel)
7130 GtkWidgetPrivate *priv = widget->priv;
7131 HierarchyChangedInfo info;
7133 info.previous_toplevel = previous_toplevel;
7134 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7136 if (gtk_widget_is_toplevel (widget) ||
7137 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7138 info.new_screen = gtk_widget_get_screen (widget);
7140 info.new_screen = NULL;
7142 if (info.previous_screen)
7143 g_object_ref (info.previous_screen);
7144 if (previous_toplevel)
7145 g_object_ref (previous_toplevel);
7147 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7149 if (previous_toplevel)
7150 g_object_unref (previous_toplevel);
7151 if (info.previous_screen)
7152 g_object_unref (info.previous_screen);
7156 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7157 gpointer client_data)
7159 HierarchyChangedInfo *info = client_data;
7161 g_object_ref (widget);
7163 do_screen_change (widget, info->previous_screen, info->new_screen);
7165 if (GTK_IS_CONTAINER (widget))
7166 gtk_container_forall (GTK_CONTAINER (widget),
7167 gtk_widget_propagate_screen_changed_recurse,
7170 g_object_unref (widget);
7174 * gtk_widget_is_composited:
7175 * @widget: a #GtkWidget
7177 * Whether @widget can rely on having its alpha channel
7178 * drawn correctly. On X11 this function returns whether a
7179 * compositing manager is running for @widget's screen.
7181 * Please note that the semantics of this call will change
7182 * in the future if used on a widget that has a composited
7183 * window in its hierarchy (as set by gdk_window_set_composited()).
7185 * Return value: %TRUE if the widget can rely on its alpha
7186 * channel being drawn correctly.
7191 gtk_widget_is_composited (GtkWidget *widget)
7195 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7197 screen = gtk_widget_get_screen (widget);
7199 return gdk_screen_is_composited (screen);
7203 propagate_composited_changed (GtkWidget *widget,
7206 if (GTK_IS_CONTAINER (widget))
7208 gtk_container_forall (GTK_CONTAINER (widget),
7209 propagate_composited_changed,
7213 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7217 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7219 propagate_composited_changed (widget, NULL);
7223 * _gtk_widget_propagate_screen_changed:
7224 * @widget: a #GtkWidget
7225 * @previous_screen: Previous screen
7227 * Propagates changes in the screen for a widget to all
7228 * children, emitting #GtkWidget::screen-changed.
7231 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7232 GdkScreen *previous_screen)
7234 HierarchyChangedInfo info;
7236 info.previous_screen = previous_screen;
7237 info.new_screen = gtk_widget_get_screen (widget);
7239 if (previous_screen)
7240 g_object_ref (previous_screen);
7242 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7244 if (previous_screen)
7245 g_object_unref (previous_screen);
7249 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7251 if (gtk_widget_has_rc_style (widget))
7252 gtk_widget_reset_rc_style (widget);
7254 if (GTK_IS_CONTAINER (widget))
7255 gtk_container_forall (GTK_CONTAINER (widget),
7256 reset_rc_styles_recurse,
7262 * gtk_widget_reset_rc_styles:
7263 * @widget: a #GtkWidget.
7265 * Reset the styles of @widget and all descendents, so when
7266 * they are looked up again, they get the correct values
7267 * for the currently loaded RC file settings.
7269 * This function is not useful for applications.
7272 gtk_widget_reset_rc_styles (GtkWidget *widget)
7274 g_return_if_fail (GTK_IS_WIDGET (widget));
7276 reset_rc_styles_recurse (widget, NULL);
7280 * gtk_widget_get_default_style:
7282 * Returns the default style used by all widgets initially.
7284 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7285 * by GTK+ and should not be modified or freed.
7288 gtk_widget_get_default_style (void)
7290 if (!gtk_default_style)
7292 gtk_default_style = gtk_style_new ();
7293 g_object_ref (gtk_default_style);
7296 return gtk_default_style;
7299 static PangoContext *
7300 gtk_widget_peek_pango_context (GtkWidget *widget)
7302 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7306 * gtk_widget_get_pango_context:
7307 * @widget: a #GtkWidget
7309 * Gets a #PangoContext with the appropriate font map, font description,
7310 * and base direction for this widget. Unlike the context returned
7311 * by gtk_widget_create_pango_context(), this context is owned by
7312 * the widget (it can be used until the screen for the widget changes
7313 * or the widget is removed from its toplevel), and will be updated to
7314 * match any changes to the widget's attributes.
7316 * If you create and keep a #PangoLayout using this context, you must
7317 * deal with changes to the context by calling pango_layout_context_changed()
7318 * on the layout in response to the #GtkWidget::style-set and
7319 * #GtkWidget::direction-changed signals for the widget.
7321 * Return value: (transfer none): the #PangoContext for the widget.
7324 gtk_widget_get_pango_context (GtkWidget *widget)
7326 PangoContext *context;
7328 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7330 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7333 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7334 g_object_set_qdata_full (G_OBJECT (widget),
7335 quark_pango_context,
7344 update_pango_context (GtkWidget *widget,
7345 PangoContext *context)
7347 GtkWidgetPrivate *priv = widget->priv;
7349 pango_context_set_font_description (context, priv->style->font_desc);
7350 pango_context_set_base_dir (context,
7351 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7352 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7356 gtk_widget_update_pango_context (GtkWidget *widget)
7358 PangoContext *context = gtk_widget_peek_pango_context (widget);
7364 update_pango_context (widget, context);
7366 screen = gtk_widget_get_screen_unchecked (widget);
7369 pango_cairo_context_set_resolution (context,
7370 gdk_screen_get_resolution (screen));
7371 pango_cairo_context_set_font_options (context,
7372 gdk_screen_get_font_options (screen));
7378 * gtk_widget_create_pango_context:
7379 * @widget: a #GtkWidget
7381 * Creates a new #PangoContext with the appropriate font map,
7382 * font description, and base direction for drawing text for
7383 * this widget. See also gtk_widget_get_pango_context().
7385 * Return value: the new #PangoContext
7388 gtk_widget_create_pango_context (GtkWidget *widget)
7391 PangoContext *context;
7393 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7395 screen = gtk_widget_get_screen_unchecked (widget);
7398 GTK_NOTE (MULTIHEAD,
7399 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7401 screen = gdk_screen_get_default ();
7404 context = gdk_pango_context_get_for_screen (screen);
7406 update_pango_context (widget, context);
7407 pango_context_set_language (context, gtk_get_default_language ());
7413 * gtk_widget_create_pango_layout:
7414 * @widget: a #GtkWidget
7415 * @text: text to set on the layout (can be %NULL)
7417 * Creates a new #PangoLayout with the appropriate font map,
7418 * font description, and base direction for drawing text for
7421 * If you keep a #PangoLayout created in this way around, in order to
7422 * notify the layout of changes to the base direction or font of this
7423 * widget, you must call pango_layout_context_changed() in response to
7424 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7427 * Return value: the new #PangoLayout
7430 gtk_widget_create_pango_layout (GtkWidget *widget,
7433 PangoLayout *layout;
7434 PangoContext *context;
7436 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7438 context = gtk_widget_get_pango_context (widget);
7439 layout = pango_layout_new (context);
7442 pango_layout_set_text (layout, text, -1);
7448 * gtk_widget_render_icon:
7449 * @widget: a #GtkWidget
7450 * @stock_id: a stock ID
7451 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7452 * render at the size of the source and don't scale (if there are
7453 * multiple source sizes, GTK+ picks one of the available sizes).
7454 * @detail: (allow-none): render detail to pass to theme engine
7456 * A convenience function that uses the theme engine and RC file
7457 * settings for @widget to look up @stock_id and render it to
7458 * a pixbuf. @stock_id should be a stock icon ID such as
7459 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7460 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7461 * identifies the widget or code doing the rendering, so that
7462 * theme engines can special-case rendering for that widget or code.
7464 * The pixels in the returned #GdkPixbuf are shared with the rest of
7465 * the application and should not be modified. The pixbuf should be freed
7466 * after use with g_object_unref().
7468 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7471 gtk_widget_render_icon (GtkWidget *widget,
7472 const gchar *stock_id,
7474 const gchar *detail)
7476 GtkWidgetPrivate *priv;
7477 GtkIconSet *icon_set;
7480 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7481 g_return_val_if_fail (stock_id != NULL, NULL);
7482 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7484 priv = widget->priv;
7486 gtk_widget_ensure_style (widget);
7488 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7490 if (icon_set == NULL)
7493 retval = gtk_icon_set_render_icon (icon_set,
7495 gtk_widget_get_direction (widget),
7496 gtk_widget_get_state (widget),
7505 * gtk_widget_set_parent_window:
7506 * @widget: a #GtkWidget.
7507 * @parent_window: the new parent window.
7509 * Sets a non default parent window for @widget.
7512 gtk_widget_set_parent_window (GtkWidget *widget,
7513 GdkWindow *parent_window)
7515 GdkWindow *old_parent_window;
7517 g_return_if_fail (GTK_IS_WIDGET (widget));
7519 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7520 quark_parent_window);
7522 if (parent_window != old_parent_window)
7524 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7526 if (old_parent_window)
7527 g_object_unref (old_parent_window);
7529 g_object_ref (parent_window);
7534 * gtk_widget_get_parent_window:
7535 * @widget: a #GtkWidget.
7537 * Gets @widget's parent window.
7539 * Returns: (transfer none): the parent window of @widget.
7542 gtk_widget_get_parent_window (GtkWidget *widget)
7544 GtkWidgetPrivate *priv;
7545 GdkWindow *parent_window;
7547 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7549 priv = widget->priv;
7551 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7553 return (parent_window != NULL) ? parent_window :
7554 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
7559 * gtk_widget_set_child_visible:
7560 * @widget: a #GtkWidget
7561 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7563 * Sets whether @widget should be mapped along with its when its parent
7564 * is mapped and @widget has been shown with gtk_widget_show().
7566 * The child visibility can be set for widget before it is added to
7567 * a container with gtk_widget_set_parent(), to avoid mapping
7568 * children unnecessary before immediately unmapping them. However
7569 * it will be reset to its default state of %TRUE when the widget
7570 * is removed from a container.
7572 * Note that changing the child visibility of a widget does not
7573 * queue a resize on the widget. Most of the time, the size of
7574 * a widget is computed from all visible children, whether or
7575 * not they are mapped. If this is not the case, the container
7576 * can queue a resize itself.
7578 * This function is only useful for container implementations and
7579 * never should be called by an application.
7582 gtk_widget_set_child_visible (GtkWidget *widget,
7583 gboolean is_visible)
7585 GtkWidgetPrivate *priv;
7587 g_return_if_fail (GTK_IS_WIDGET (widget));
7588 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7590 priv = widget->priv;
7592 g_object_ref (widget);
7595 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7598 GtkWidget *toplevel;
7600 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7602 toplevel = gtk_widget_get_toplevel (widget);
7603 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7604 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7607 if (priv->parent && gtk_widget_get_realized (priv->parent))
7609 if (gtk_widget_get_mapped (priv->parent) &&
7610 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7611 gtk_widget_get_visible (widget))
7612 gtk_widget_map (widget);
7614 gtk_widget_unmap (widget);
7617 g_object_unref (widget);
7621 * gtk_widget_get_child_visible:
7622 * @widget: a #GtkWidget
7624 * Gets the value set with gtk_widget_set_child_visible().
7625 * If you feel a need to use this function, your code probably
7626 * needs reorganization.
7628 * This function is only useful for container implementations and
7629 * never should be called by an application.
7631 * Return value: %TRUE if the widget is mapped with the parent.
7634 gtk_widget_get_child_visible (GtkWidget *widget)
7636 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7638 return GTK_WIDGET_CHILD_VISIBLE (widget);
7642 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7644 GtkWidget *toplevel;
7646 toplevel = gtk_widget_get_toplevel (widget);
7648 if (gtk_widget_is_toplevel (toplevel))
7650 if (GTK_IS_WINDOW (toplevel))
7651 return gtk_window_get_screen (GTK_WINDOW (toplevel));
7652 else if (GTK_IS_INVISIBLE (toplevel))
7653 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
7660 * gtk_widget_get_screen:
7661 * @widget: a #GtkWidget
7663 * Get the #GdkScreen from the toplevel window associated with
7664 * this widget. This function can only be called after the widget
7665 * has been added to a widget hierarchy with a #GtkWindow
7668 * In general, you should only create screen specific
7669 * resources when a widget has been realized, and you should
7670 * free those resources when the widget is unrealized.
7672 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7677 gtk_widget_get_screen (GtkWidget *widget)
7681 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7683 screen = gtk_widget_get_screen_unchecked (widget);
7690 g_warning (G_STRLOC ": Can't get associated screen"
7691 " for a widget unless it is inside a toplevel GtkWindow\n"
7692 " widget type is %s associated top level type is %s",
7693 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7694 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7696 return gdk_screen_get_default ();
7701 * gtk_widget_has_screen:
7702 * @widget: a #GtkWidget
7704 * Checks whether there is a #GdkScreen is associated with
7705 * this widget. All toplevel widgets have an associated
7706 * screen, and all widgets added into a hierarchy with a toplevel
7707 * window at the top.
7709 * Return value: %TRUE if there is a #GdkScreen associcated
7715 gtk_widget_has_screen (GtkWidget *widget)
7717 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7719 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7723 * gtk_widget_get_display:
7724 * @widget: a #GtkWidget
7726 * Get the #GdkDisplay for the toplevel window associated with
7727 * this widget. This function can only be called after the widget
7728 * has been added to a widget hierarchy with a #GtkWindow at the top.
7730 * In general, you should only create display specific
7731 * resources when a widget has been realized, and you should
7732 * free those resources when the widget is unrealized.
7734 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7739 gtk_widget_get_display (GtkWidget *widget)
7741 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7743 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7747 * gtk_widget_get_root_window:
7748 * @widget: a #GtkWidget
7750 * Get the root window where this widget is located. This function can
7751 * only be called after the widget has been added to a widget
7752 * hierarchy with #GtkWindow at the top.
7754 * The root window is useful for such purposes as creating a popup
7755 * #GdkWindow associated with the window. In general, you should only
7756 * create display specific resources when a widget has been realized,
7757 * and you should free those resources when the widget is unrealized.
7759 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7764 gtk_widget_get_root_window (GtkWidget *widget)
7766 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7768 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7772 * gtk_widget_child_focus:
7773 * @widget: a #GtkWidget
7774 * @direction: direction of focus movement
7776 * This function is used by custom widget implementations; if you're
7777 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7778 * to a particular widget, and gtk_container_set_focus_chain() to
7779 * change the focus tab order. So you may want to investigate those
7780 * functions instead.
7782 * gtk_widget_child_focus() is called by containers as the user moves
7783 * around the window using keyboard shortcuts. @direction indicates
7784 * what kind of motion is taking place (up, down, left, right, tab
7785 * forward, tab backward). gtk_widget_child_focus() emits the
7786 * #GtkWidget::focus signal; widgets override the default handler
7787 * for this signal in order to implement appropriate focus behavior.
7789 * The default ::focus handler for a widget should return %TRUE if
7790 * moving in @direction left the focus on a focusable location inside
7791 * that widget, and %FALSE if moving in @direction moved the focus
7792 * outside the widget. If returning %TRUE, widgets normally
7793 * call gtk_widget_grab_focus() to place the focus accordingly;
7794 * if returning %FALSE, they don't modify the current focus location.
7796 * Return value: %TRUE if focus ended up inside @widget
7799 gtk_widget_child_focus (GtkWidget *widget,
7800 GtkDirectionType direction)
7802 gboolean return_val;
7804 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7806 if (!gtk_widget_get_visible (widget) ||
7807 !gtk_widget_is_sensitive (widget))
7810 /* child widgets must set CAN_FOCUS, containers
7811 * don't have to though.
7813 if (!GTK_IS_CONTAINER (widget) &&
7814 !gtk_widget_get_can_focus (widget))
7817 g_signal_emit (widget,
7818 widget_signals[FOCUS],
7820 direction, &return_val);
7826 * gtk_widget_keynav_failed:
7827 * @widget: a #GtkWidget
7828 * @direction: direction of focus movement
7830 * This function should be called whenever keyboard navigation within
7831 * a single widget hits a boundary. The function emits the
7832 * #GtkWidget::keynav-failed signal on the widget and its return
7833 * value should be interpreted in a way similar to the return value of
7834 * gtk_widget_child_focus():
7836 * When %TRUE is returned, stay in the widget, the failed keyboard
7837 * navigation is Ok and/or there is nowhere we can/should move the
7840 * When %FALSE is returned, the caller should continue with keyboard
7841 * navigation outside the widget, e.g. by calling
7842 * gtk_widget_child_focus() on the widget's toplevel.
7844 * The default ::keynav-failed handler returns %TRUE for
7845 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7846 * values of #GtkDirectionType, it looks at the
7847 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7848 * if the setting is %TRUE. This way the entire user interface
7849 * becomes cursor-navigatable on input devices such as mobile phones
7850 * which only have cursor keys but no tab key.
7852 * Whenever the default handler returns %TRUE, it also calls
7853 * gtk_widget_error_bell() to notify the user of the failed keyboard
7856 * A use case for providing an own implementation of ::keynav-failed
7857 * (either by connecting to it or by overriding it) would be a row of
7858 * #GtkEntry widgets where the user should be able to navigate the
7859 * entire row with the cursor keys, as e.g. known from user interfaces
7860 * that require entering license keys.
7862 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7863 * if the emitting widget should try to handle the keyboard
7864 * navigation attempt in its parent container(s).
7869 gtk_widget_keynav_failed (GtkWidget *widget,
7870 GtkDirectionType direction)
7872 gboolean return_val;
7874 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7876 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7877 direction, &return_val);
7883 * gtk_widget_error_bell:
7884 * @widget: a #GtkWidget
7886 * Notifies the user about an input-related error on this widget.
7887 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7888 * gdk_window_beep(), otherwise it does nothing.
7890 * Note that the effect of gdk_window_beep() can be configured in many
7891 * ways, depending on the windowing backend and the desktop environment
7892 * or window manager that is used.
7897 gtk_widget_error_bell (GtkWidget *widget)
7899 GtkWidgetPrivate *priv;
7900 GtkSettings* settings;
7903 g_return_if_fail (GTK_IS_WIDGET (widget));
7905 priv = widget->priv;
7907 settings = gtk_widget_get_settings (widget);
7911 g_object_get (settings,
7912 "gtk-error-bell", &beep,
7915 if (beep && priv->window)
7916 gdk_window_beep (priv->window);
7920 gtk_widget_set_usize_internal (GtkWidget *widget,
7924 GtkWidgetAuxInfo *aux_info;
7925 gboolean changed = FALSE;
7927 g_object_freeze_notify (G_OBJECT (widget));
7929 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7931 if (width > -2 && aux_info->width != width)
7933 g_object_notify (G_OBJECT (widget), "width-request");
7934 aux_info->width = width;
7937 if (height > -2 && aux_info->height != height)
7939 g_object_notify (G_OBJECT (widget), "height-request");
7940 aux_info->height = height;
7944 if (gtk_widget_get_visible (widget) && changed)
7945 gtk_widget_queue_resize (widget);
7947 g_object_thaw_notify (G_OBJECT (widget));
7951 * gtk_widget_set_size_request:
7952 * @widget: a #GtkWidget
7953 * @width: width @widget should request, or -1 to unset
7954 * @height: height @widget should request, or -1 to unset
7956 * Sets the minimum size of a widget; that is, the widget's size
7957 * request will be @width by @height. You can use this function to
7958 * force a widget to be either larger or smaller than it normally
7961 * In most cases, gtk_window_set_default_size() is a better choice for
7962 * toplevel windows than this function; setting the default size will
7963 * still allow users to shrink the window. Setting the size request
7964 * will force them to leave the window at least as large as the size
7965 * request. When dealing with window sizes,
7966 * gtk_window_set_geometry_hints() can be a useful function as well.
7968 * Note the inherent danger of setting any fixed size - themes,
7969 * translations into other languages, different fonts, and user action
7970 * can all change the appropriate size for a given widget. So, it's
7971 * basically impossible to hardcode a size that will always be
7974 * The size request of a widget is the smallest size a widget can
7975 * accept while still functioning well and drawing itself correctly.
7976 * However in some strange cases a widget may be allocated less than
7977 * its requested size, and in many cases a widget may be allocated more
7978 * space than it requested.
7980 * If the size request in a given direction is -1 (unset), then
7981 * the "natural" size request of the widget will be used instead.
7983 * Widgets can't actually be allocated a size less than 1 by 1, but
7984 * you can pass 0,0 to this function to mean "as small as possible."
7987 gtk_widget_set_size_request (GtkWidget *widget,
7991 g_return_if_fail (GTK_IS_WIDGET (widget));
7992 g_return_if_fail (width >= -1);
7993 g_return_if_fail (height >= -1);
8000 gtk_widget_set_usize_internal (widget, width, height);
8005 * gtk_widget_get_size_request:
8006 * @widget: a #GtkWidget
8007 * @width: (out) (allow-none): return location for width, or %NULL
8008 * @height: (out) (allow-none): return location for height, or %NULL
8010 * Gets the size request that was explicitly set for the widget using
8011 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8012 * @height indicates that that dimension has not been set explicitly
8013 * and the natural requisition of the widget will be used intead. See
8014 * gtk_widget_set_size_request(). To get the size a widget will
8015 * actually use, call gtk_widget_size_request() instead of
8019 gtk_widget_get_size_request (GtkWidget *widget,
8023 GtkWidgetAuxInfo *aux_info;
8025 g_return_if_fail (GTK_IS_WIDGET (widget));
8027 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
8030 *width = aux_info ? aux_info->width : -1;
8033 *height = aux_info ? aux_info->height : -1;
8037 * gtk_widget_set_events:
8038 * @widget: a #GtkWidget
8039 * @events: event mask
8041 * Sets the event mask (see #GdkEventMask) for a widget. The event
8042 * mask determines which events a widget will receive. Keep in mind
8043 * that different widgets have different default event masks, and by
8044 * changing the event mask you may disrupt a widget's functionality,
8045 * so be careful. This function must be called while a widget is
8046 * unrealized. Consider gtk_widget_add_events() for widgets that are
8047 * already realized, or if you want to preserve the existing event
8048 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8049 * to get events on those widgets, place them inside a #GtkEventBox
8050 * and receive events on the event box.
8053 gtk_widget_set_events (GtkWidget *widget,
8056 g_return_if_fail (GTK_IS_WIDGET (widget));
8057 g_return_if_fail (!gtk_widget_get_realized (widget));
8059 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8060 GINT_TO_POINTER (events));
8061 g_object_notify (G_OBJECT (widget), "events");
8065 * gtk_widget_set_device_events:
8066 * @widget: a #GtkWidget
8067 * @device: a #GdkDevice
8068 * @events: event mask
8070 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8071 * mask determines which events a widget will receive from @device. Keep
8072 * in mind that different widgets have different default event masks, and by
8073 * changing the event mask you may disrupt a widget's functionality,
8074 * so be careful. This function must be called while a widget is
8075 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8076 * already realized, or if you want to preserve the existing event
8077 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8078 * to get events on those widgets, place them inside a #GtkEventBox
8079 * and receive events on the event box.
8084 gtk_widget_set_device_events (GtkWidget *widget,
8086 GdkEventMask events)
8088 GHashTable *device_events;
8090 g_return_if_fail (GTK_IS_WIDGET (widget));
8091 g_return_if_fail (GDK_IS_DEVICE (device));
8092 g_return_if_fail (!gtk_widget_get_realized (widget));
8094 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8096 if (G_UNLIKELY (!device_events))
8098 device_events = g_hash_table_new (NULL, NULL);
8099 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8100 (GDestroyNotify) g_hash_table_unref);
8103 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8107 gtk_widget_add_events_internal_list (GtkWidget *widget,
8114 for (l = window_list; l != NULL; l = l->next)
8116 GdkWindow *window = l->data;
8119 gdk_window_get_user_data (window, &user_data);
8120 if (user_data == widget)
8125 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8127 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8129 children = gdk_window_get_children (window);
8130 gtk_widget_add_events_internal_list (widget, device, events, children);
8131 g_list_free (children);
8137 gtk_widget_add_events_internal (GtkWidget *widget,
8141 GtkWidgetPrivate *priv = widget->priv;
8144 if (!gtk_widget_get_has_window (widget))
8145 window_list = gdk_window_get_children (priv->window);
8147 window_list = g_list_prepend (NULL, priv->window);
8149 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8151 g_list_free (window_list);
8155 * gtk_widget_add_events:
8156 * @widget: a #GtkWidget
8157 * @events: an event mask, see #GdkEventMask
8159 * Adds the events in the bitfield @events to the event mask for
8160 * @widget. See gtk_widget_set_events() for details.
8163 gtk_widget_add_events (GtkWidget *widget,
8168 g_return_if_fail (GTK_IS_WIDGET (widget));
8170 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8171 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8172 GINT_TO_POINTER (old_events | events));
8174 if (gtk_widget_get_realized (widget))
8175 gtk_widget_add_events_internal (widget, NULL, events);
8177 g_object_notify (G_OBJECT (widget), "events");
8181 * gtk_widget_add_device_events:
8182 * @widget: a #GtkWidget
8183 * @device: a #GdkDevice
8184 * @events: an event mask, see #GdkEventMask
8186 * Adds the device events in the bitfield @events to the event mask for
8187 * @widget. See gtk_widget_set_device_events() for details.
8192 gtk_widget_add_device_events (GtkWidget *widget,
8194 GdkEventMask events)
8196 GdkEventMask old_events;
8197 GHashTable *device_events;
8199 g_return_if_fail (GTK_IS_WIDGET (widget));
8200 g_return_if_fail (GDK_IS_DEVICE (device));
8202 old_events = gtk_widget_get_device_events (widget, device);
8204 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8206 if (G_UNLIKELY (!device_events))
8208 device_events = g_hash_table_new (NULL, NULL);
8209 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8210 (GDestroyNotify) g_hash_table_unref);
8213 g_hash_table_insert (device_events, device,
8214 GUINT_TO_POINTER (old_events | events));
8216 if (gtk_widget_get_realized (widget))
8217 gtk_widget_add_events_internal (widget, device, events);
8219 g_object_notify (G_OBJECT (widget), "events");
8223 * gtk_widget_set_extension_events:
8224 * @widget: a #GtkWidget
8225 * @mode: bitfield of extension events to receive
8227 * Sets the extension events mask to @mode. See #GdkExtensionMode
8228 * and gdk_input_set_extension_events().
8231 gtk_widget_set_extension_events (GtkWidget *widget,
8232 GdkExtensionMode mode)
8234 g_return_if_fail (GTK_IS_WIDGET (widget));
8236 if (gtk_widget_get_realized (widget))
8237 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8239 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8240 GINT_TO_POINTER (mode));
8241 g_object_notify (G_OBJECT (widget), "extension-events");
8245 * gtk_widget_get_toplevel:
8246 * @widget: a #GtkWidget
8248 * This function returns the topmost widget in the container hierarchy
8249 * @widget is a part of. If @widget has no parent widgets, it will be
8250 * returned as the topmost widget. No reference will be added to the
8251 * returned widget; it should not be unreferenced.
8253 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8254 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8256 * %NULL if @widget wasn't inside a toplevel window, and if the
8257 * window was inside a #GtkWindow-derived widget which was in turn
8258 * inside the toplevel #GtkWindow. While the second case may
8259 * seem unlikely, it actually happens when a #GtkPlug is embedded
8260 * inside a #GtkSocket within the same application.
8262 * To reliably find the toplevel #GtkWindow, use
8263 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8264 * is set on the result.
8266 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8267 * if (gtk_widget_is_toplevel (toplevel))
8269 * /* Perform action on toplevel. */
8273 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8274 * if there's no ancestor.
8277 gtk_widget_get_toplevel (GtkWidget *widget)
8279 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8281 while (widget->priv->parent)
8282 widget = widget->priv->parent;
8288 * gtk_widget_get_ancestor:
8289 * @widget: a #GtkWidget
8290 * @widget_type: ancestor type
8292 * Gets the first ancestor of @widget with type @widget_type. For example,
8293 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8294 * the first #GtkBox that's an ancestor of @widget. No reference will be
8295 * added to the returned widget; it should not be unreferenced. See note
8296 * about checking for a toplevel #GtkWindow in the docs for
8297 * gtk_widget_get_toplevel().
8299 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8300 * considers @widget to be an ancestor of itself.
8302 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8305 gtk_widget_get_ancestor (GtkWidget *widget,
8308 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8310 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8311 widget = widget->priv->parent;
8313 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8320 * gtk_widget_get_colormap:
8321 * @widget: a #GtkWidget
8323 * Gets the colormap that will be used to render @widget. No reference will
8324 * be added to the returned colormap; it should not be unreferenced.
8326 * Return value: (transfer none): the colormap used by @widget
8329 gtk_widget_get_colormap (GtkWidget *widget)
8331 GtkWidgetPrivate *priv;
8332 GdkColormap *colormap;
8333 GtkWidget *tmp_widget;
8335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8337 priv = widget->priv;
8341 colormap = gdk_drawable_get_colormap (priv->window);
8342 /* If window was destroyed previously, we'll get NULL here */
8347 tmp_widget = widget;
8350 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8354 tmp_widget= tmp_widget->priv->parent;
8357 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8361 * gtk_widget_get_visual:
8362 * @widget: a #GtkWidget
8364 * Gets the visual that will be used to render @widget.
8366 * Return value: (transfer none): the visual for @widget
8369 gtk_widget_get_visual (GtkWidget *widget)
8371 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8373 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8377 * gtk_widget_get_settings:
8378 * @widget: a #GtkWidget
8380 * Gets the settings object holding the settings (global property
8381 * settings, RC file information, etc) used for this widget.
8383 * Note that this function can only be called when the #GtkWidget
8384 * is attached to a toplevel, since the settings object is specific
8385 * to a particular #GdkScreen.
8387 * Return value: (transfer none): the relevant #GtkSettings object
8390 gtk_widget_get_settings (GtkWidget *widget)
8392 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8394 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8398 * gtk_widget_set_colormap:
8399 * @widget: a #GtkWidget
8400 * @colormap: a colormap
8402 * Sets the colormap for the widget to the given value. Widget must not
8403 * have been previously realized. This probably should only be used
8404 * from an <function>init()</function> function (i.e. from the constructor
8408 gtk_widget_set_colormap (GtkWidget *widget,
8409 GdkColormap *colormap)
8411 g_return_if_fail (GTK_IS_WIDGET (widget));
8412 g_return_if_fail (!gtk_widget_get_realized (widget));
8413 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8415 g_object_ref (colormap);
8417 g_object_set_qdata_full (G_OBJECT (widget),
8424 * gtk_widget_get_events:
8425 * @widget: a #GtkWidget
8427 * Returns the event mask for the widget (a bitfield containing flags
8428 * from the #GdkEventMask enumeration). These are the events that the widget
8431 * Return value: event mask for @widget
8434 gtk_widget_get_events (GtkWidget *widget)
8436 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8438 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8442 * gtk_widget_get_device_events:
8443 * @widget: a #GtkWidget
8444 * @device: a #GdkDevice
8446 * Returns the events mask for the widget corresponding to an specific device. These
8447 * are the events that the widget will receive when @device operates on it.
8449 * Returns: device event mask for @widget
8454 gtk_widget_get_device_events (GtkWidget *widget,
8457 GHashTable *device_events;
8459 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8460 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8462 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8467 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8471 * gtk_widget_get_extension_events:
8472 * @widget: a #GtkWidget
8474 * Retrieves the extension events the widget will receive; see
8475 * gdk_input_set_extension_events().
8477 * Return value: extension events for @widget
8480 gtk_widget_get_extension_events (GtkWidget *widget)
8482 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8484 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8488 * gtk_widget_get_pointer:
8489 * @widget: a #GtkWidget
8490 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8491 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8493 * Obtains the location of the mouse pointer in widget coordinates.
8494 * Widget coordinates are a bit odd; for historical reasons, they are
8495 * defined as @widget->window coordinates for widgets that are not
8496 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8497 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8500 gtk_widget_get_pointer (GtkWidget *widget,
8504 GtkWidgetPrivate *priv;
8506 g_return_if_fail (GTK_IS_WIDGET (widget));
8508 priv = widget->priv;
8515 if (gtk_widget_get_realized (widget))
8517 gdk_window_get_pointer (priv->window, x, y, NULL);
8519 if (!gtk_widget_get_has_window (widget))
8522 *x -= priv->allocation.x;
8524 *y -= priv->allocation.y;
8530 * gtk_widget_is_ancestor:
8531 * @widget: a #GtkWidget
8532 * @ancestor: another #GtkWidget
8534 * Determines whether @widget is somewhere inside @ancestor, possibly with
8535 * intermediate containers.
8537 * Return value: %TRUE if @ancestor contains @widget as a child,
8538 * grandchild, great grandchild, etc.
8541 gtk_widget_is_ancestor (GtkWidget *widget,
8542 GtkWidget *ancestor)
8544 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8545 g_return_val_if_fail (ancestor != NULL, FALSE);
8549 if (widget->priv->parent == ancestor)
8551 widget = widget->priv->parent;
8557 static GQuark quark_composite_name = 0;
8560 * gtk_widget_set_composite_name:
8561 * @widget: a #GtkWidget.
8562 * @name: the name to set
8564 * Sets a widgets composite name. The widget must be
8565 * a composite child of its parent; see gtk_widget_push_composite_child().
8568 gtk_widget_set_composite_name (GtkWidget *widget,
8571 g_return_if_fail (GTK_IS_WIDGET (widget));
8572 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8573 g_return_if_fail (name != NULL);
8575 if (!quark_composite_name)
8576 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8578 g_object_set_qdata_full (G_OBJECT (widget),
8579 quark_composite_name,
8585 * gtk_widget_get_composite_name:
8586 * @widget: a #GtkWidget
8588 * Obtains the composite name of a widget.
8590 * Returns: the composite name of @widget, or %NULL if @widget is not
8591 * a composite child. The string should be freed when it is no
8595 gtk_widget_get_composite_name (GtkWidget *widget)
8597 GtkWidgetPrivate *priv;
8599 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8601 priv = widget->priv;
8603 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
8604 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
8611 * gtk_widget_push_composite_child:
8613 * Makes all newly-created widgets as composite children until
8614 * the corresponding gtk_widget_pop_composite_child() call.
8616 * A composite child is a child that's an implementation detail of the
8617 * container it's inside and should not be visible to people using the
8618 * container. Composite children aren't treated differently by GTK (but
8619 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8620 * builders might want to treat them in a different way.
8622 * Here is a simple example:
8624 * gtk_widget_push_composite_child ();
8625 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8626 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8627 * gtk_widget_pop_composite_child ();
8628 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8629 * GTK_WIDGET (scrolled_window));
8630 * g_object_ref (scrolled_window->hscrollbar);
8634 gtk_widget_push_composite_child (void)
8636 composite_child_stack++;
8640 * gtk_widget_pop_composite_child:
8642 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8645 gtk_widget_pop_composite_child (void)
8647 if (composite_child_stack)
8648 composite_child_stack--;
8652 * gtk_widget_push_colormap:
8653 * @cmap: a #GdkColormap
8655 * Pushes @cmap onto a global stack of colormaps; the topmost
8656 * colormap on the stack will be used to create all widgets.
8657 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8658 * reason to use this function.
8661 gtk_widget_push_colormap (GdkColormap *cmap)
8663 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8665 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8669 * gtk_widget_pop_colormap:
8671 * Removes a colormap pushed with gtk_widget_push_colormap().
8674 gtk_widget_pop_colormap (void)
8677 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8681 * gtk_widget_set_default_colormap:
8682 * @colormap: a #GdkColormap
8684 * Sets the default colormap to use when creating widgets.
8685 * gtk_widget_push_colormap() is a better function to use if
8686 * you only want to affect a few widgets, rather than all widgets.
8689 gtk_widget_set_default_colormap (GdkColormap *colormap)
8691 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8693 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8698 * gtk_widget_get_default_colormap:
8700 * Obtains the default colormap used to create widgets.
8702 * Return value: (transfer none): default widget colormap
8705 gtk_widget_get_default_colormap (void)
8707 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8711 * gtk_widget_get_default_visual:
8713 * Obtains the visual of the default colormap. Not really useful;
8714 * used to be useful before gdk_colormap_get_visual() existed.
8716 * Return value: (transfer none): visual of the default colormap
8719 gtk_widget_get_default_visual (void)
8721 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8725 gtk_widget_emit_direction_changed (GtkWidget *widget,
8726 GtkTextDirection old_dir)
8728 gtk_widget_update_pango_context (widget);
8730 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8734 * gtk_widget_set_direction:
8735 * @widget: a #GtkWidget
8736 * @dir: the new direction
8738 * Sets the reading direction on a particular widget. This direction
8739 * controls the primary direction for widgets containing text,
8740 * and also the direction in which the children of a container are
8741 * packed. The ability to set the direction is present in order
8742 * so that correct localization into languages with right-to-left
8743 * reading directions can be done. Generally, applications will
8744 * let the default reading direction present, except for containers
8745 * where the containers are arranged in an order that is explicitely
8746 * visual rather than logical (such as buttons for text justification).
8748 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8749 * set by gtk_widget_set_default_direction() will be used.
8752 gtk_widget_set_direction (GtkWidget *widget,
8753 GtkTextDirection dir)
8755 GtkTextDirection old_dir;
8757 g_return_if_fail (GTK_IS_WIDGET (widget));
8758 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8760 old_dir = gtk_widget_get_direction (widget);
8762 if (dir == GTK_TEXT_DIR_NONE)
8763 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8766 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8767 if (dir == GTK_TEXT_DIR_LTR)
8768 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8770 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8773 if (old_dir != gtk_widget_get_direction (widget))
8774 gtk_widget_emit_direction_changed (widget, old_dir);
8778 * gtk_widget_get_direction:
8779 * @widget: a #GtkWidget
8781 * Gets the reading direction for a particular widget. See
8782 * gtk_widget_set_direction().
8784 * Return value: the reading direction for the widget.
8787 gtk_widget_get_direction (GtkWidget *widget)
8789 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8791 if (GTK_WIDGET_DIRECTION_SET (widget))
8792 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8794 return gtk_default_direction;
8798 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8800 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8802 g_object_ref (widget);
8804 if (!GTK_WIDGET_DIRECTION_SET (widget))
8805 gtk_widget_emit_direction_changed (widget, old_dir);
8807 if (GTK_IS_CONTAINER (widget))
8808 gtk_container_forall (GTK_CONTAINER (widget),
8809 gtk_widget_set_default_direction_recurse,
8812 g_object_unref (widget);
8816 * gtk_widget_set_default_direction:
8817 * @dir: the new default direction. This cannot be
8818 * %GTK_TEXT_DIR_NONE.
8820 * Sets the default reading direction for widgets where the
8821 * direction has not been explicitly set by gtk_widget_set_direction().
8824 gtk_widget_set_default_direction (GtkTextDirection dir)
8826 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8828 if (dir != gtk_default_direction)
8830 GList *toplevels, *tmp_list;
8831 GtkTextDirection old_dir = gtk_default_direction;
8833 gtk_default_direction = dir;
8835 tmp_list = toplevels = gtk_window_list_toplevels ();
8836 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8840 gtk_widget_set_default_direction_recurse (tmp_list->data,
8841 GUINT_TO_POINTER (old_dir));
8842 g_object_unref (tmp_list->data);
8843 tmp_list = tmp_list->next;
8846 g_list_free (toplevels);
8851 * gtk_widget_get_default_direction:
8853 * Obtains the current default reading direction. See
8854 * gtk_widget_set_default_direction().
8856 * Return value: the current default direction.
8859 gtk_widget_get_default_direction (void)
8861 return gtk_default_direction;
8865 gtk_widget_dispose (GObject *object)
8867 GtkWidget *widget = GTK_WIDGET (object);
8868 GtkWidgetPrivate *priv = widget->priv;
8871 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
8872 else if (gtk_widget_get_visible (widget))
8873 gtk_widget_hide (widget);
8875 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8876 if (gtk_widget_get_realized (widget))
8877 gtk_widget_unrealize (widget);
8879 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8883 gtk_widget_real_destroy (GtkObject *object)
8885 /* gtk_object_destroy() will already hold a refcount on object */
8886 GtkWidget *widget = GTK_WIDGET (object);
8887 GtkWidgetPrivate *priv = widget->priv;
8889 /* wipe accelerator closures (keep order) */
8890 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8891 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8893 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8894 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8896 gtk_grab_remove (widget);
8898 g_object_unref (priv->style);
8899 priv->style = gtk_widget_get_default_style ();
8900 g_object_ref (priv->style);
8902 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8906 gtk_widget_finalize (GObject *object)
8908 GtkWidget *widget = GTK_WIDGET (object);
8909 GtkWidgetPrivate *priv = widget->priv;
8910 GtkWidgetAuxInfo *aux_info;
8911 GtkAccessible *accessible;
8913 gtk_grab_remove (widget);
8915 g_object_unref (priv->style);
8918 g_free (priv->name);
8920 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8922 gtk_widget_aux_info_destroy (aux_info);
8924 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8926 g_object_unref (accessible);
8928 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8931 /*****************************************
8932 * gtk_widget_real_map:
8937 *****************************************/
8940 gtk_widget_real_map (GtkWidget *widget)
8942 GtkWidgetPrivate *priv = widget->priv;
8944 g_assert (gtk_widget_get_realized (widget));
8946 if (!gtk_widget_get_mapped (widget))
8948 gtk_widget_set_mapped (widget, TRUE);
8950 if (gtk_widget_get_has_window (widget))
8951 gdk_window_show (priv->window);
8955 /*****************************************
8956 * gtk_widget_real_unmap:
8961 *****************************************/
8964 gtk_widget_real_unmap (GtkWidget *widget)
8966 GtkWidgetPrivate *priv = widget->priv;
8968 if (gtk_widget_get_mapped (widget))
8970 gtk_widget_set_mapped (widget, FALSE);
8972 if (gtk_widget_get_has_window (widget))
8973 gdk_window_hide (priv->window);
8977 /*****************************************
8978 * gtk_widget_real_realize:
8983 *****************************************/
8986 gtk_widget_real_realize (GtkWidget *widget)
8988 GtkWidgetPrivate *priv = widget->priv;
8990 g_assert (!gtk_widget_get_has_window (widget));
8992 gtk_widget_set_realized (widget, TRUE);
8995 priv->window = gtk_widget_get_parent_window (widget);
8996 g_object_ref (priv->window);
8998 priv->style = gtk_style_attach (priv->style, priv->window);
9001 /*****************************************
9002 * gtk_widget_real_unrealize:
9007 *****************************************/
9010 gtk_widget_real_unrealize (GtkWidget *widget)
9012 GtkWidgetPrivate *priv = widget->priv;
9014 if (gtk_widget_get_mapped (widget))
9015 gtk_widget_real_unmap (widget);
9017 gtk_widget_set_mapped (widget, FALSE);
9019 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9022 /* We must do unrealize child widget BEFORE container widget.
9023 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9024 * So, unrealizing container widget bofore its children causes the problem
9025 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9028 if (GTK_IS_CONTAINER (widget))
9029 gtk_container_forall (GTK_CONTAINER (widget),
9030 (GtkCallback) gtk_widget_unrealize,
9033 gtk_style_detach (priv->style);
9034 if (gtk_widget_get_has_window (widget))
9036 gdk_window_set_user_data (priv->window, NULL);
9037 gdk_window_destroy (priv->window);
9038 priv->window = NULL;
9042 g_object_unref (priv->window);
9043 priv->window = NULL;
9046 gtk_selection_remove_all (widget);
9048 gtk_widget_set_realized (widget, FALSE);
9052 gtk_widget_real_size_request (GtkWidget *widget,
9053 GtkRequisition *requisition)
9055 requisition->width = 0;
9056 requisition->height = 0;
9060 * _gtk_widget_peek_colormap:
9062 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
9064 * Return value: the currently pushed colormap, or %NULL if there is none.
9067 _gtk_widget_peek_colormap (void)
9070 return (GdkColormap*) colormap_stack->data;
9075 * _gtk_widget_set_device_window:
9076 * @widget: a #GtkWidget.
9077 * @device: a #GdkDevice.
9078 * @window: the new device window.
9080 * Sets pointer window for @widget and @device. Does not ref @window.
9081 * Actually stores it on the #GdkScreen, but you don't need to know that.
9084 _gtk_widget_set_device_window (GtkWidget *widget,
9088 GtkWidgetPrivate *priv;
9090 GHashTable *device_window;
9092 g_return_if_fail (GTK_IS_WIDGET (widget));
9093 g_return_if_fail (GDK_IS_DEVICE (device));
9094 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9096 priv = widget->priv;
9098 if (!gtk_widget_get_realized (widget))
9101 screen = gdk_drawable_get_screen (priv->window);
9102 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9104 if (G_UNLIKELY (!device_window))
9106 device_window = g_hash_table_new (NULL, NULL);
9107 g_object_set_qdata_full (G_OBJECT (screen),
9108 quark_pointer_window,
9110 (GDestroyNotify) g_hash_table_destroy);
9114 g_hash_table_insert (device_window, device, window);
9116 g_hash_table_remove (device_window, device);
9120 * _gtk_widget_get_device_window:
9121 * @widget: a #GtkWidget.
9122 * @device: a #GdkDevice.
9124 * Return value: the device window set on the #GdkScreen @widget is attached
9128 _gtk_widget_get_device_window (GtkWidget *widget,
9131 GtkWidgetPrivate *priv;
9133 GHashTable *device_window;
9137 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9138 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9140 priv = widget->priv;
9142 if (!gtk_widget_get_realized (widget))
9145 screen = gdk_drawable_get_screen (priv->window);
9146 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9148 if (G_UNLIKELY (!device_window))
9151 window = g_hash_table_lookup (device_window, device);
9156 gdk_window_get_user_data (window, (gpointer *) &w);
9165 * _gtk_widget_list_devices:
9166 * @widget: a #GtkWidget.
9168 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9169 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9173 _gtk_widget_list_devices (GtkWidget *widget)
9175 GtkWidgetPrivate *priv;
9177 GHashTableIter iter;
9178 GHashTable *device_window;
9179 GList *devices = NULL;
9180 gpointer key, value;
9182 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9184 priv = widget->priv;
9186 if (!gtk_widget_get_realized (widget))
9189 screen = gdk_drawable_get_screen (priv->window);
9190 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9192 if (G_UNLIKELY (!device_window))
9195 g_hash_table_iter_init (&iter, device_window);
9197 while (g_hash_table_iter_next (&iter, &key, &value))
9199 GdkDevice *device = key;
9200 GdkWindow *window = value;
9205 gdk_window_get_user_data (window, (gpointer *) &w);
9208 devices = g_list_prepend (devices, device);
9216 synth_crossing (GtkWidget *widget,
9220 GdkCrossingMode mode,
9221 GdkNotifyType detail)
9225 event = gdk_event_new (type);
9227 event->crossing.window = g_object_ref (window);
9228 event->crossing.send_event = TRUE;
9229 event->crossing.subwindow = g_object_ref (window);
9230 event->crossing.time = GDK_CURRENT_TIME;
9231 event->crossing.x = event->crossing.y = 0;
9232 event->crossing.x_root = event->crossing.y_root = 0;
9233 event->crossing.mode = mode;
9234 event->crossing.detail = detail;
9235 event->crossing.focus = FALSE;
9236 event->crossing.state = 0;
9237 gdk_event_set_device (event, device);
9240 widget = gtk_get_event_widget (event);
9243 gtk_widget_event_internal (widget, event);
9245 gdk_event_free (event);
9249 * _gtk_widget_synthesize_crossing:
9250 * @from: the #GtkWidget the virtual pointer is leaving.
9251 * @to: the #GtkWidget the virtual pointer is moving to.
9252 * @mode: the #GdkCrossingMode to place on the synthesized events.
9254 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9256 * The real pointer window is the window that most recently received an enter notify
9257 * event. Windows that don't select for crossing events can't become the real
9258 * poiner window. The real pointer widget that owns the real pointer window. The
9259 * effective pointer window is the same as the real pointer window unless the real
9260 * pointer widget is either insensitive or there is a grab on a widget that is not
9261 * an ancestor of the real pointer widget (in which case the effective pointer
9262 * window should be the root window).
9264 * When the effective pointer window is the same as the real poiner window, we
9265 * receive crossing events from the windowing system. When the effective pointer
9266 * window changes to become different from the real pointer window we synthesize
9267 * crossing events, attempting to follow X protocol rules:
9269 * When the root window becomes the effective pointer window:
9270 * - leave notify on real pointer window, detail Ancestor
9271 * - leave notify on all of its ancestors, detail Virtual
9272 * - enter notify on root window, detail Inferior
9274 * When the root window ceases to be the effective pointer window:
9275 * - leave notify on root window, detail Inferior
9276 * - enter notify on all ancestors of real pointer window, detail Virtual
9277 * - enter notify on real pointer window, detail Ancestor
9280 _gtk_widget_synthesize_crossing (GtkWidget *from,
9283 GdkCrossingMode mode)
9285 GdkWindow *from_window = NULL, *to_window = NULL;
9287 g_return_if_fail (from != NULL || to != NULL);
9291 from_window = _gtk_widget_get_device_window (from, device);
9294 from_window = from->priv->window;
9299 to_window = _gtk_widget_get_device_window (to, device);
9302 to_window = to->priv->window;
9305 if (from_window == NULL && to_window == NULL)
9307 else if (from_window != NULL && to_window == NULL)
9309 GList *from_ancestors = NULL, *list;
9310 GdkWindow *from_ancestor = from_window;
9312 while (from_ancestor != NULL)
9314 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9315 if (from_ancestor == NULL)
9317 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9320 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9321 device, mode, GDK_NOTIFY_ANCESTOR);
9322 for (list = g_list_last (from_ancestors); list; list = list->prev)
9324 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9325 device, mode, GDK_NOTIFY_VIRTUAL);
9328 /* XXX: enter/inferior on root window? */
9330 g_list_free (from_ancestors);
9332 else if (from_window == NULL && to_window != NULL)
9334 GList *to_ancestors = NULL, *list;
9335 GdkWindow *to_ancestor = to_window;
9337 while (to_ancestor != NULL)
9339 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9340 if (to_ancestor == NULL)
9342 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9345 /* XXX: leave/inferior on root window? */
9347 for (list = to_ancestors; list; list = list->next)
9349 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9350 device, mode, GDK_NOTIFY_VIRTUAL);
9352 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9353 device, mode, GDK_NOTIFY_ANCESTOR);
9355 g_list_free (to_ancestors);
9357 else if (from_window == to_window)
9361 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9362 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9364 while (from_ancestor != NULL || to_ancestor != NULL)
9366 if (from_ancestor != NULL)
9368 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9369 if (from_ancestor == to_window)
9372 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9374 if (to_ancestor != NULL)
9376 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9377 if (to_ancestor == from_window)
9380 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9383 if (to_ancestor == from_window)
9385 if (mode != GDK_CROSSING_GTK_UNGRAB)
9386 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9387 device, mode, GDK_NOTIFY_INFERIOR);
9388 for (list = to_ancestors; list; list = list->next)
9389 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9390 device, mode, GDK_NOTIFY_VIRTUAL);
9391 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9392 device, mode, GDK_NOTIFY_ANCESTOR);
9394 else if (from_ancestor == to_window)
9396 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9397 device, mode, GDK_NOTIFY_ANCESTOR);
9398 for (list = g_list_last (from_ancestors); list; list = list->prev)
9400 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9401 device, mode, GDK_NOTIFY_VIRTUAL);
9403 if (mode != GDK_CROSSING_GTK_GRAB)
9404 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9405 device, mode, GDK_NOTIFY_INFERIOR);
9409 while (from_ancestors != NULL && to_ancestors != NULL
9410 && from_ancestors->data == to_ancestors->data)
9412 from_ancestors = g_list_delete_link (from_ancestors,
9414 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9417 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9418 device, mode, GDK_NOTIFY_NONLINEAR);
9420 for (list = g_list_last (from_ancestors); list; list = list->prev)
9422 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9423 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9425 for (list = to_ancestors; list; list = list->next)
9427 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9428 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9430 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9431 device, mode, GDK_NOTIFY_NONLINEAR);
9433 g_list_free (from_ancestors);
9434 g_list_free (to_ancestors);
9439 gtk_widget_propagate_state (GtkWidget *widget,
9442 GtkWidgetPrivate *priv = widget->priv;
9443 guint8 old_state = gtk_widget_get_state (widget);
9444 guint8 old_saved_state = priv->saved_state;
9446 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9447 * parent_sensitive==TRUE on a sensitive widget
9451 if (data->parent_sensitive)
9452 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9454 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9456 if (gtk_widget_is_sensitive (widget))
9458 if (data->state_restoration)
9459 priv->state = priv->saved_state;
9461 priv->state = data->state;
9465 if (!data->state_restoration)
9467 if (data->state != GTK_STATE_INSENSITIVE)
9468 priv->saved_state = data->state;
9470 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9471 priv->saved_state = gtk_widget_get_state (widget);
9472 priv->state = GTK_STATE_INSENSITIVE;
9475 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9479 window = gtk_widget_get_toplevel (widget);
9480 if (window && gtk_widget_is_toplevel (window))
9481 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9484 if (old_state != gtk_widget_get_state (widget) ||
9485 old_saved_state != priv->saved_state)
9487 g_object_ref (widget);
9489 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9490 gtk_grab_remove (widget);
9492 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9494 if (!GTK_WIDGET_SHADOWED (widget))
9496 GList *event_windows = NULL;
9499 devices = _gtk_widget_list_devices (widget);
9501 for (d = devices; d; d = d->next)
9507 window = _gtk_widget_get_device_window (widget, device);
9509 /* Do not propagate more than once to the
9510 * same window if non-multidevice aware.
9512 if (!gdk_window_get_support_multidevice (window) &&
9513 g_list_find (event_windows, window))
9516 if (!gtk_widget_is_sensitive (widget))
9517 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9518 GDK_CROSSING_STATE_CHANGED);
9519 else if (old_state == GTK_STATE_INSENSITIVE)
9520 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9521 GDK_CROSSING_STATE_CHANGED);
9523 event_windows = g_list_prepend (event_windows, window);
9526 g_list_free (event_windows);
9527 g_list_free (devices);
9530 if (GTK_IS_CONTAINER (widget))
9532 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9533 if (data->use_forall)
9534 gtk_container_forall (GTK_CONTAINER (widget),
9535 (GtkCallback) gtk_widget_propagate_state,
9538 gtk_container_foreach (GTK_CONTAINER (widget),
9539 (GtkCallback) gtk_widget_propagate_state,
9542 g_object_unref (widget);
9547 * _gtk_widget_get_aux_info:
9548 * @widget: a #GtkWidget
9549 * @create: if %TRUE, create the structure if it doesn't exist
9551 * Get the #GtkWidgetAuxInfo structure for the widget.
9553 * Return value: the #GtkAuxInfo structure for the widget, or
9554 * %NULL if @create is %FALSE and one doesn't already exist.
9557 _gtk_widget_get_aux_info (GtkWidget *widget,
9560 GtkWidgetAuxInfo *aux_info;
9562 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9563 if (!aux_info && create)
9565 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9567 aux_info->width = -1;
9568 aux_info->height = -1;
9570 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9577 /*****************************************
9578 * gtk_widget_aux_info_destroy:
9583 *****************************************/
9586 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9588 g_slice_free (GtkWidgetAuxInfo, aux_info);
9592 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9594 g_object_unref (info->shape_mask);
9595 g_slice_free (GtkWidgetShapeInfo, info);
9599 * gtk_widget_shape_combine_mask:
9600 * @widget: a #GtkWidget
9601 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9602 * @offset_x: X position of shape mask with respect to @window
9603 * @offset_y: Y position of shape mask with respect to @window
9605 * Sets a shape for this widget's GDK window. This allows for
9606 * transparent windows etc., see gdk_window_shape_combine_mask()
9607 * for more information.
9610 gtk_widget_shape_combine_mask (GtkWidget *widget,
9611 GdkBitmap *shape_mask,
9615 GtkWidgetPrivate *priv;
9616 GtkWidgetShapeInfo* shape_info;
9618 g_return_if_fail (GTK_IS_WIDGET (widget));
9619 /* set_shape doesn't work on widgets without gdk window */
9620 g_return_if_fail (gtk_widget_get_has_window (widget));
9622 priv = widget->priv;
9626 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9629 gdk_window_shape_combine_mask (priv->window, NULL, 0, 0);
9631 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9635 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9637 shape_info = g_slice_new (GtkWidgetShapeInfo);
9638 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9639 (GDestroyNotify) gtk_widget_shape_info_destroy);
9641 shape_info->shape_mask = g_object_ref (shape_mask);
9642 shape_info->offset_x = offset_x;
9643 shape_info->offset_y = offset_y;
9645 /* set shape if widget has a gdk window already.
9646 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9649 gdk_window_shape_combine_mask (priv->window, shape_mask,
9650 offset_x, offset_y);
9655 * gtk_widget_input_shape_combine_mask:
9656 * @widget: a #GtkWidget
9657 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9658 * @offset_x: X position of shape mask with respect to @window
9659 * @offset_y: Y position of shape mask with respect to @window
9661 * Sets an input shape for this widget's GDK window. This allows for
9662 * windows which react to mouse click in a nonrectangular region, see
9663 * gdk_window_input_shape_combine_mask() for more information.
9668 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9669 GdkBitmap *shape_mask,
9673 GtkWidgetPrivate *priv;
9674 GtkWidgetShapeInfo* shape_info;
9676 g_return_if_fail (GTK_IS_WIDGET (widget));
9677 /* set_shape doesn't work on widgets without gdk window */
9678 g_return_if_fail (gtk_widget_get_has_window (widget));
9680 priv = widget->priv;
9685 gdk_window_input_shape_combine_mask (priv->window, NULL, 0, 0);
9687 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9691 shape_info = g_slice_new (GtkWidgetShapeInfo);
9692 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9694 (GDestroyNotify) gtk_widget_shape_info_destroy);
9696 shape_info->shape_mask = g_object_ref (shape_mask);
9697 shape_info->offset_x = offset_x;
9698 shape_info->offset_y = offset_y;
9700 /* set shape if widget has a gdk window already.
9701 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9704 gdk_window_input_shape_combine_mask (priv->window, shape_mask,
9705 offset_x, offset_y);
9711 gtk_reset_shapes_recurse (GtkWidget *widget,
9717 gdk_window_get_user_data (window, &data);
9721 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9722 for (list = gdk_window_peek_children (window); list; list = list->next)
9723 gtk_reset_shapes_recurse (widget, list->data);
9727 * gtk_widget_reset_shapes:
9728 * @widget: a #GtkWidget
9730 * Recursively resets the shape on this widget and its descendants.
9733 gtk_widget_reset_shapes (GtkWidget *widget)
9735 GtkWidgetPrivate *priv;
9737 g_return_if_fail (GTK_IS_WIDGET (widget));
9738 g_return_if_fail (gtk_widget_get_realized (widget));
9740 priv = widget->priv;
9742 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9743 gtk_reset_shapes_recurse (widget, priv->window);
9747 expose_window (GdkWindow *window)
9750 GList *l, *children;
9752 gboolean is_double_buffered;
9754 gdk_window_get_user_data (window, &user_data);
9757 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9759 is_double_buffered = FALSE;
9761 event.expose.type = GDK_EXPOSE;
9762 event.expose.window = g_object_ref (window);
9763 event.expose.send_event = FALSE;
9764 event.expose.count = 0;
9765 event.expose.area.x = 0;
9766 event.expose.area.y = 0;
9767 gdk_drawable_get_size (GDK_DRAWABLE (window),
9768 &event.expose.area.width,
9769 &event.expose.area.height);
9770 event.expose.region = cairo_region_create_rectangle (&event.expose.area);
9772 /* If this is not double buffered, force a double buffer so that
9773 redirection works. */
9774 if (!is_double_buffered)
9775 gdk_window_begin_paint_region (window, event.expose.region);
9777 gtk_main_do_event (&event);
9779 if (!is_double_buffered)
9780 gdk_window_end_paint (window);
9782 children = gdk_window_peek_children (window);
9783 for (l = children; l != NULL; l = l->next)
9785 GdkWindow *child = l->data;
9787 /* Don't expose input-only windows */
9788 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9789 expose_window (l->data);
9792 g_object_unref (window);
9796 * gtk_widget_get_snapshot:
9797 * @widget: a #GtkWidget
9798 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9800 * Create a #GdkPixmap of the contents of the widget and its children.
9802 * Works even if the widget is obscured. The depth and visual of the
9803 * resulting pixmap is dependent on the widget being snapshot and likely
9804 * differs from those of a target widget displaying the pixmap.
9805 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9806 * the pixmap to a visual independant representation.
9808 * The snapshot area used by this function is the @widget's allocation plus
9809 * any extra space occupied by additional windows belonging to this widget
9810 * (such as the arrows of a spin button).
9811 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9813 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9814 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9815 * interpreted widget relative. If width or height of @clip_rect are 0 or
9816 * negative, the width or height of the resulting pixmap will be shrunken
9817 * by the respective amount.
9818 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9819 * chop off 5 pixels at each side of the snapshot pixmap.
9820 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9821 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9822 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9823 * as a pure output parameter.
9825 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9827 * Return value: #GdkPixmap snapshot of the widget
9832 gtk_widget_get_snapshot (GtkWidget *widget,
9833 GdkRectangle *clip_rect)
9835 GtkWidgetPrivate *priv;
9836 int x, y, width, height;
9837 GdkWindow *parent_window = NULL;
9839 GList *windows = NULL, *list;
9841 priv = widget->priv;
9843 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9844 if (!gtk_widget_get_visible (widget))
9847 /* the widget (and parent_window) must be realized to be drawable */
9848 if (priv->parent && !gtk_widget_get_realized (priv->parent))
9849 gtk_widget_realize (priv->parent);
9850 if (!gtk_widget_get_realized (widget))
9851 gtk_widget_realize (widget);
9853 /* determine snapshot rectangle */
9854 x = priv->allocation.x;
9855 y = priv->allocation.y;
9856 width = priv->allocation.width;
9857 height = priv->allocation.height;
9859 if (priv->parent && gtk_widget_get_has_window (widget))
9861 /* grow snapshot rectangle to cover all widget windows */
9862 parent_window = gtk_widget_get_parent_window (widget);
9863 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9865 GdkWindow *subwin = list->data;
9868 gdk_window_get_user_data (subwin, &windata);
9869 if (windata != widget)
9871 windows = g_list_prepend (windows, subwin);
9872 gdk_window_get_position (subwin, &wx, &wy);
9873 gdk_drawable_get_size (subwin, &ww, &wh);
9874 /* grow snapshot rectangle by extra widget sub window */
9885 if (x + width < wx + ww)
9886 width += wx + ww - (x + width);
9887 if (y + height < wy + wh)
9888 height += wy + wh - (y + height);
9891 else if (!priv->parent)
9892 x = y = 0; /* toplevel */
9894 /* at this point, (x,y,width,height) is the parent_window relative
9895 * snapshot area covering all of widget's windows.
9898 /* shrink snapshot size by clip_rectangle */
9901 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9902 clip.x = clip.x < 0 ? x : clip.x;
9903 clip.y = clip.y < 0 ? y : clip.y;
9904 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9905 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9908 /* offset clip_rect, so it's parent_window relative */
9909 if (clip_rect->x >= 0)
9910 clip.x += priv->allocation.x;
9911 if (clip_rect->y >= 0)
9912 clip.y += priv->allocation.y;
9914 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9916 g_list_free (windows);
9917 clip_rect->width = clip_rect->height = 0;
9918 return NULL; /* empty snapshot area */
9923 height = snap.height;
9926 /* render snapshot */
9927 pixmap = gdk_pixmap_new (priv->window, width, height, gdk_drawable_get_depth (priv->window));
9928 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9930 GdkWindow *subwin = list->data;
9932 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9933 continue; /* Input only window */
9934 gdk_window_get_position (subwin, &wx, &wy);
9935 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9936 MAX (0, wx - x), MAX (0, wy - y), width, height);
9938 expose_window (subwin);
9940 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == priv->window */
9942 gdk_window_redirect_to_drawable (priv->window, pixmap, x, y, 0, 0, width, height);
9943 expose_window (priv->window);
9945 for (list = windows; list; list = list->next)
9946 gdk_window_remove_redirection (list->data);
9947 if (!windows) /* NO_WINDOW || toplevel */
9948 gdk_window_remove_redirection (priv->window);
9949 g_list_free (windows);
9951 /* return pixmap and snapshot rectangle coordinates */
9956 clip_rect->width = width;
9957 clip_rect->height = height;
9960 /* offset clip_rect from parent_window so it's widget relative */
9961 clip_rect->x -= priv->allocation.x;
9962 clip_rect->y -= priv->allocation.y;
9965 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9966 G_OBJECT_TYPE_NAME (widget),
9967 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9976 * gtk_widget_class_install_style_property_parser:
9977 * @klass: a #GtkWidgetClass
9978 * @pspec: the #GParamSpec for the style property
9979 * @parser: the parser for the style property
9981 * Installs a style property on a widget class.
9984 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9986 GtkRcPropertyParser parser)
9988 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9989 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9990 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9991 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9993 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9995 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9996 G_OBJECT_CLASS_NAME (klass),
10001 g_param_spec_ref_sink (pspec);
10002 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10003 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10007 * gtk_widget_class_install_style_property:
10008 * @klass: a #GtkWidgetClass
10009 * @pspec: the #GParamSpec for the property
10011 * Installs a style property on a widget class. The parser for the
10012 * style property is determined by the value type of @pspec.
10015 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10018 GtkRcPropertyParser parser;
10020 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10021 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10023 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10025 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10029 * gtk_widget_class_find_style_property:
10030 * @klass: a #GtkWidgetClass
10031 * @property_name: the name of the style property to find
10032 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10033 * style property with that name.
10035 * Finds a style property of a widget class by name.
10040 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10041 const gchar *property_name)
10043 g_return_val_if_fail (property_name != NULL, NULL);
10045 return g_param_spec_pool_lookup (style_property_spec_pool,
10047 G_OBJECT_CLASS_TYPE (klass),
10052 * gtk_widget_class_list_style_properties:
10053 * @klass: a #GtkWidgetClass
10054 * @n_properties: location to return the number of style properties found
10055 * @returns: an newly allocated array of #GParamSpec*. The array must
10056 * be freed with g_free().
10058 * Returns all style properties of a widget class.
10063 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10064 guint *n_properties)
10066 GParamSpec **pspecs;
10069 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10070 G_OBJECT_CLASS_TYPE (klass),
10079 * gtk_widget_style_get_property:
10080 * @widget: a #GtkWidget
10081 * @property_name: the name of a style property
10082 * @value: location to return the property value
10084 * Gets the value of a style property of @widget.
10087 gtk_widget_style_get_property (GtkWidget *widget,
10088 const gchar *property_name,
10091 GtkWidgetPrivate *priv;
10094 g_return_if_fail (GTK_IS_WIDGET (widget));
10095 g_return_if_fail (property_name != NULL);
10096 g_return_if_fail (G_IS_VALUE (value));
10098 priv = widget->priv;
10100 g_object_ref (widget);
10101 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10103 G_OBJECT_TYPE (widget),
10106 g_warning ("%s: widget class `%s' has no property named `%s'",
10108 G_OBJECT_TYPE_NAME (widget),
10112 const GValue *peek_value;
10114 peek_value = _gtk_style_peek_property_value (priv->style,
10115 G_OBJECT_TYPE (widget),
10117 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10119 /* auto-conversion of the caller's value type
10121 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10122 g_value_copy (peek_value, value);
10123 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10124 g_value_transform (peek_value, value);
10126 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10128 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10129 G_VALUE_TYPE_NAME (value));
10131 g_object_unref (widget);
10135 * gtk_widget_style_get_valist:
10136 * @widget: a #GtkWidget
10137 * @first_property_name: the name of the first property to get
10138 * @var_args: a <type>va_list</type> of pairs of property names and
10139 * locations to return the property values, starting with the location
10140 * for @first_property_name.
10142 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10146 gtk_widget_style_get_valist (GtkWidget *widget,
10147 const gchar *first_property_name,
10150 GtkWidgetPrivate *priv;
10153 g_return_if_fail (GTK_IS_WIDGET (widget));
10155 priv = widget->priv;
10157 g_object_ref (widget);
10159 name = first_property_name;
10162 const GValue *peek_value;
10166 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10168 G_OBJECT_TYPE (widget),
10172 g_warning ("%s: widget class `%s' has no property named `%s'",
10174 G_OBJECT_TYPE_NAME (widget),
10178 /* style pspecs are always readable so we can spare that check here */
10180 peek_value = _gtk_style_peek_property_value (priv->style,
10181 G_OBJECT_TYPE (widget),
10183 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10184 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10187 g_warning ("%s: %s", G_STRLOC, error);
10192 name = va_arg (var_args, gchar*);
10195 g_object_unref (widget);
10199 * gtk_widget_style_get:
10200 * @widget: a #GtkWidget
10201 * @first_property_name: the name of the first property to get
10202 * @Varargs: pairs of property names and locations to
10203 * return the property values, starting with the location for
10204 * @first_property_name, terminated by %NULL.
10206 * Gets the values of a multiple style properties of @widget.
10209 gtk_widget_style_get (GtkWidget *widget,
10210 const gchar *first_property_name,
10215 g_return_if_fail (GTK_IS_WIDGET (widget));
10217 va_start (var_args, first_property_name);
10218 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10224 * @widget: a #GtkWidget
10225 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10226 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10227 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10229 * Obtains the full path to @widget. The path is simply the name of a
10230 * widget and all its parents in the container hierarchy, separated by
10231 * periods. The name of a widget comes from
10232 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10233 * in gtkrc configuration files. Widget names are the type of the
10234 * widget by default (e.g. "GtkButton") or can be set to an
10235 * application-specific value with gtk_widget_set_name(). By setting
10236 * the name of a widget, you allow users or theme authors to apply
10237 * styles to that specific widget in their gtkrc
10238 * file. @path_reversed_p fills in the path in reverse order,
10239 * i.e. starting with @widget's name instead of starting with the name
10240 * of @widget's outermost ancestor.
10243 gtk_widget_path (GtkWidget *widget,
10244 guint *path_length,
10246 gchar **path_reversed)
10248 static gchar *rev_path = NULL;
10249 static guint tmp_path_len = 0;
10252 g_return_if_fail (GTK_IS_WIDGET (widget));
10257 const gchar *string;
10262 string = gtk_widget_get_name (widget);
10263 l = strlen (string);
10264 while (tmp_path_len <= len + l + 1)
10266 tmp_path_len += INIT_PATH_SIZE;
10267 rev_path = g_realloc (rev_path, tmp_path_len);
10269 s = string + l - 1;
10270 d = rev_path + len;
10271 while (s >= string)
10275 widget = widget->priv->parent;
10278 rev_path[len++] = '.';
10280 rev_path[len++] = 0;
10285 *path_length = len - 1;
10287 *path_reversed = g_strdup (rev_path);
10290 *path = g_strdup (rev_path);
10291 g_strreverse (*path);
10296 * gtk_widget_class_path:
10297 * @widget: a #GtkWidget
10298 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10299 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10300 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10303 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10304 * never uses a custom name set with gtk_widget_set_name().
10308 gtk_widget_class_path (GtkWidget *widget,
10309 guint *path_length,
10311 gchar **path_reversed)
10313 static gchar *rev_path = NULL;
10314 static guint tmp_path_len = 0;
10317 g_return_if_fail (GTK_IS_WIDGET (widget));
10322 const gchar *string;
10327 string = g_type_name (G_OBJECT_TYPE (widget));
10328 l = strlen (string);
10329 while (tmp_path_len <= len + l + 1)
10331 tmp_path_len += INIT_PATH_SIZE;
10332 rev_path = g_realloc (rev_path, tmp_path_len);
10334 s = string + l - 1;
10335 d = rev_path + len;
10336 while (s >= string)
10340 widget = widget->priv->parent;
10343 rev_path[len++] = '.';
10345 rev_path[len++] = 0;
10350 *path_length = len - 1;
10352 *path_reversed = g_strdup (rev_path);
10355 *path = g_strdup (rev_path);
10356 g_strreverse (*path);
10361 * gtk_requisition_new:
10363 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10365 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10366 * be freed with gtk_requisition_free().
10371 gtk_requisition_new (void)
10373 return g_slice_new0 (GtkRequisition);
10377 * gtk_requisition_copy:
10378 * @requisition: a #GtkRequisition
10380 * Copies a #GtkRequisition.
10382 * Returns: a copy of @requisition
10385 gtk_requisition_copy (const GtkRequisition *requisition)
10387 return g_slice_dup (GtkRequisition, requisition);
10391 * gtk_requisition_free:
10392 * @requisition: a #GtkRequisition
10394 * Frees a #GtkRequisition.
10397 gtk_requisition_free (GtkRequisition *requisition)
10399 g_slice_free (GtkRequisition, requisition);
10402 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10403 gtk_requisition_copy,
10404 gtk_requisition_free)
10407 * gtk_widget_get_accessible:
10408 * @widget: a #GtkWidget
10410 * Returns the accessible object that describes the widget to an
10411 * assistive technology.
10413 * If no accessibility library is loaded (i.e. no ATK implementation library is
10414 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10415 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10416 * if no class-specific #AtkObject implementation is available for the widget
10417 * instance in question, it will inherit an #AtkObject implementation from the
10418 * first ancestor class for which such an implementation is defined.
10420 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10421 * library contains more information about accessible objects and their uses.
10423 * Returns: (transfer none): the #AtkObject associated with @widget
10426 gtk_widget_get_accessible (GtkWidget *widget)
10428 GtkWidgetClass *klass;
10430 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10432 klass = GTK_WIDGET_GET_CLASS (widget);
10434 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10436 return klass->get_accessible (widget);
10440 gtk_widget_real_get_accessible (GtkWidget *widget)
10442 AtkObject* accessible;
10444 accessible = g_object_get_qdata (G_OBJECT (widget),
10445 quark_accessible_object);
10448 AtkObjectFactory *factory;
10449 AtkRegistry *default_registry;
10451 default_registry = atk_get_default_registry ();
10452 factory = atk_registry_get_factory (default_registry,
10453 G_TYPE_FROM_INSTANCE (widget));
10455 atk_object_factory_create_accessible (factory,
10456 G_OBJECT (widget));
10457 g_object_set_qdata (G_OBJECT (widget),
10458 quark_accessible_object,
10465 * Initialize a AtkImplementorIface instance's virtual pointers as
10466 * appropriate to this implementor's class (GtkWidget).
10469 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10471 iface->ref_accessible = gtk_widget_ref_accessible;
10475 gtk_widget_ref_accessible (AtkImplementor *implementor)
10477 AtkObject *accessible;
10479 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10481 g_object_ref (accessible);
10486 * GtkBuildable implementation
10488 static GQuark quark_builder_has_default = 0;
10489 static GQuark quark_builder_has_focus = 0;
10490 static GQuark quark_builder_atk_relations = 0;
10491 static GQuark quark_builder_set_name = 0;
10494 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10496 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10497 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10498 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10499 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10501 iface->set_name = gtk_widget_buildable_set_name;
10502 iface->get_name = gtk_widget_buildable_get_name;
10503 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10504 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10505 iface->parser_finished = gtk_widget_buildable_parser_finished;
10506 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10507 iface->custom_finished = gtk_widget_buildable_custom_finished;
10511 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10514 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10515 g_strdup (name), g_free);
10518 static const gchar *
10519 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10521 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10525 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10526 GtkBuilder *builder,
10527 const gchar *childname)
10529 if (strcmp (childname, "accessible") == 0)
10530 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10536 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10537 GtkBuilder *builder,
10539 const GValue *value)
10541 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10542 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10543 GINT_TO_POINTER (TRUE));
10544 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10545 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10546 GINT_TO_POINTER (TRUE));
10548 g_object_set_property (G_OBJECT (buildable), name, value);
10553 gchar *action_name;
10554 GString *description;
10556 gboolean translatable;
10566 free_action (AtkActionData *data, gpointer user_data)
10568 g_free (data->action_name);
10569 g_string_free (data->description, TRUE);
10570 g_free (data->context);
10571 g_slice_free (AtkActionData, data);
10575 free_relation (AtkRelationData *data, gpointer user_data)
10577 g_free (data->target);
10578 g_free (data->type);
10579 g_slice_free (AtkRelationData, data);
10583 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10584 GtkBuilder *builder)
10586 GSList *atk_relations;
10588 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10589 gtk_widget_grab_default (GTK_WIDGET (buildable));
10590 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10591 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10593 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10594 quark_builder_atk_relations);
10597 AtkObject *accessible;
10598 AtkRelationSet *relation_set;
10601 AtkRelationType relation_type;
10602 AtkObject *target_accessible;
10604 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10605 relation_set = atk_object_ref_relation_set (accessible);
10607 for (l = atk_relations; l; l = l->next)
10609 AtkRelationData *relation = (AtkRelationData*)l->data;
10611 target = gtk_builder_get_object (builder, relation->target);
10614 g_warning ("Target object %s in <relation> does not exist",
10618 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10619 g_assert (target_accessible != NULL);
10621 relation_type = atk_relation_type_for_name (relation->type);
10622 if (relation_type == ATK_RELATION_NULL)
10624 g_warning ("<relation> type %s not found",
10628 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10629 target_accessible);
10631 g_object_unref (relation_set);
10633 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10634 g_slist_free (atk_relations);
10635 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10644 } AccessibilitySubParserData;
10647 accessibility_start_element (GMarkupParseContext *context,
10648 const gchar *element_name,
10649 const gchar **names,
10650 const gchar **values,
10651 gpointer user_data,
10654 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10656 gint line_number, char_number;
10658 if (strcmp (element_name, "relation") == 0)
10660 gchar *target = NULL;
10661 gchar *type = NULL;
10662 AtkRelationData *relation;
10664 for (i = 0; names[i]; i++)
10666 if (strcmp (names[i], "target") == 0)
10667 target = g_strdup (values[i]);
10668 else if (strcmp (names[i], "type") == 0)
10669 type = g_strdup (values[i]);
10672 g_markup_parse_context_get_position (context,
10675 g_set_error (error,
10677 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10678 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10680 line_number, char_number, names[i], "relation");
10687 if (!target || !type)
10689 g_markup_parse_context_get_position (context,
10692 g_set_error (error,
10694 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10695 "%s:%d:%d <%s> requires attribute \"%s\"",
10697 line_number, char_number, "relation",
10698 type ? "target" : "type");
10704 relation = g_slice_new (AtkRelationData);
10705 relation->target = target;
10706 relation->type = type;
10708 data->relations = g_slist_prepend (data->relations, relation);
10710 else if (strcmp (element_name, "action") == 0)
10712 const gchar *action_name = NULL;
10713 const gchar *description = NULL;
10714 const gchar *msg_context = NULL;
10715 gboolean translatable = FALSE;
10716 AtkActionData *action;
10718 for (i = 0; names[i]; i++)
10720 if (strcmp (names[i], "action_name") == 0)
10721 action_name = values[i];
10722 else if (strcmp (names[i], "description") == 0)
10723 description = values[i];
10724 else if (strcmp (names[i], "translatable") == 0)
10726 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10729 else if (strcmp (names[i], "comments") == 0)
10731 /* do nothing, comments are for translators */
10733 else if (strcmp (names[i], "context") == 0)
10734 msg_context = values[i];
10737 g_markup_parse_context_get_position (context,
10740 g_set_error (error,
10742 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10743 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10745 line_number, char_number, names[i], "action");
10752 g_markup_parse_context_get_position (context,
10755 g_set_error (error,
10757 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10758 "%s:%d:%d <%s> requires attribute \"%s\"",
10760 line_number, char_number, "action",
10765 action = g_slice_new (AtkActionData);
10766 action->action_name = g_strdup (action_name);
10767 action->description = g_string_new (description);
10768 action->context = g_strdup (msg_context);
10769 action->translatable = translatable;
10771 data->actions = g_slist_prepend (data->actions, action);
10773 else if (strcmp (element_name, "accessibility") == 0)
10776 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10780 accessibility_text (GMarkupParseContext *context,
10783 gpointer user_data,
10786 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10788 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10790 AtkActionData *action = data->actions->data;
10792 g_string_append_len (action->description, text, text_len);
10796 static const GMarkupParser accessibility_parser =
10798 accessibility_start_element,
10800 accessibility_text,
10809 } AccelGroupParserData;
10812 accel_group_start_element (GMarkupParseContext *context,
10813 const gchar *element_name,
10814 const gchar **names,
10815 const gchar **values,
10816 gpointer user_data,
10821 guint modifiers = 0;
10822 gchar *signal = NULL;
10823 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10825 for (i = 0; names[i]; i++)
10827 if (strcmp (names[i], "key") == 0)
10828 key = gdk_keyval_from_name (values[i]);
10829 else if (strcmp (names[i], "modifiers") == 0)
10831 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10837 else if (strcmp (names[i], "signal") == 0)
10838 signal = g_strdup (values[i]);
10841 if (key == 0 || signal == NULL)
10843 g_warning ("<accelerator> requires key and signal attributes");
10846 parser_data->key = key;
10847 parser_data->modifiers = modifiers;
10848 parser_data->signal = signal;
10851 static const GMarkupParser accel_group_parser =
10853 accel_group_start_element,
10857 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10858 GtkBuilder *builder,
10860 const gchar *tagname,
10861 GMarkupParser *parser,
10864 g_assert (buildable);
10866 if (strcmp (tagname, "accelerator") == 0)
10868 AccelGroupParserData *parser_data;
10870 parser_data = g_slice_new0 (AccelGroupParserData);
10871 parser_data->object = g_object_ref (buildable);
10872 *parser = accel_group_parser;
10873 *data = parser_data;
10876 if (strcmp (tagname, "accessibility") == 0)
10878 AccessibilitySubParserData *parser_data;
10880 parser_data = g_slice_new0 (AccessibilitySubParserData);
10881 *parser = accessibility_parser;
10882 *data = parser_data;
10889 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10890 GtkWidget *toplevel,
10891 gpointer user_data)
10893 AccelGroupParserData *accel_data;
10894 GSList *accel_groups;
10895 GtkAccelGroup *accel_group;
10897 g_return_if_fail (GTK_IS_WIDGET (widget));
10898 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10899 g_return_if_fail (user_data != NULL);
10901 accel_data = (AccelGroupParserData*)user_data;
10902 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10903 if (g_slist_length (accel_groups) == 0)
10905 accel_group = gtk_accel_group_new ();
10906 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10910 g_assert (g_slist_length (accel_groups) == 1);
10911 accel_group = g_slist_nth_data (accel_groups, 0);
10914 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10915 accel_data->signal,
10918 accel_data->modifiers,
10919 GTK_ACCEL_VISIBLE);
10921 g_object_unref (accel_data->object);
10922 g_free (accel_data->signal);
10923 g_slice_free (AccelGroupParserData, accel_data);
10927 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10928 GtkBuilder *builder,
10930 const gchar *tagname,
10931 gpointer user_data)
10933 AccelGroupParserData *accel_data;
10934 AccessibilitySubParserData *a11y_data;
10935 GtkWidget *toplevel;
10937 if (strcmp (tagname, "accelerator") == 0)
10939 accel_data = (AccelGroupParserData*)user_data;
10940 g_assert (accel_data->object);
10942 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10944 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10946 else if (strcmp (tagname, "accessibility") == 0)
10948 a11y_data = (AccessibilitySubParserData*)user_data;
10950 if (a11y_data->actions)
10952 AtkObject *accessible;
10957 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10959 action = ATK_ACTION (accessible);
10960 n_actions = atk_action_get_n_actions (action);
10962 for (l = a11y_data->actions; l; l = l->next)
10964 AtkActionData *action_data = (AtkActionData*)l->data;
10966 for (i = 0; i < n_actions; i++)
10967 if (strcmp (atk_action_get_name (action, i),
10968 action_data->action_name) == 0)
10973 gchar *description;
10975 if (action_data->translatable && action_data->description->len)
10976 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10977 action_data->context,
10978 action_data->description->str);
10980 description = action_data->description->str;
10982 atk_action_set_description (action, i, description);
10986 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10987 g_slist_free (a11y_data->actions);
10990 if (a11y_data->relations)
10991 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10992 a11y_data->relations);
10994 g_slice_free (AccessibilitySubParserData, a11y_data);
10999 * GtkSizeRequest implementation
11002 gtk_widget_real_get_width (GtkSizeRequest *widget,
11003 gint *minimum_size,
11004 gint *natural_size)
11014 gtk_widget_real_get_height (GtkSizeRequest *widget,
11015 gint *minimum_size,
11016 gint *natural_size)
11026 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11028 gint *minimum_height,
11029 gint *natural_height)
11031 gtk_size_request_get_height (layout, minimum_height, natural_height);
11035 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11037 gint *minimum_width,
11038 gint *natural_width)
11040 gtk_size_request_get_width (layout, minimum_width, natural_width);
11044 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11046 iface->get_width = gtk_widget_real_get_width;
11047 iface->get_height = gtk_widget_real_get_height;
11048 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11049 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
11054 * gtk_widget_get_clipboard:
11055 * @widget: a #GtkWidget
11056 * @selection: a #GdkAtom which identifies the clipboard
11057 * to use. %GDK_SELECTION_CLIPBOARD gives the
11058 * default clipboard. Another common value
11059 * is %GDK_SELECTION_PRIMARY, which gives
11060 * the primary X selection.
11062 * Returns the clipboard object for the given selection to
11063 * be used with @widget. @widget must have a #GdkDisplay
11064 * associated with it, so must be attached to a toplevel
11067 * Return value: (transfer none): the appropriate clipboard object. If no
11068 * clipboard already exists, a new one will
11069 * be created. Once a clipboard object has
11070 * been created, it is persistent for all time.
11075 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11077 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11078 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11080 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11085 * gtk_widget_list_mnemonic_labels:
11086 * @widget: a #GtkWidget
11088 * Returns a newly allocated list of the widgets, normally labels, for
11089 * which this widget is the target of a mnemonic (see for example,
11090 * gtk_label_set_mnemonic_widget()).
11092 * The widgets in the list are not individually referenced. If you
11093 * want to iterate through the list and perform actions involving
11094 * callbacks that might destroy the widgets, you
11095 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11096 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11097 * widgets afterwards.
11099 * Return value: (element-type GtkWidget) (transfer container): the list of
11100 * mnemonic labels; free this list
11101 * with g_list_free() when you are done with it.
11106 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11108 GList *list = NULL;
11111 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11113 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11114 list = g_list_prepend (list, l->data);
11120 * gtk_widget_add_mnemonic_label:
11121 * @widget: a #GtkWidget
11122 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11124 * Adds a widget to the list of mnemonic labels for
11125 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11126 * list of mnemonic labels for the widget is cleared when the
11127 * widget is destroyed, so the caller must make sure to update
11128 * its internal state at this point as well, by using a connection
11129 * to the #GtkWidget::destroy signal or a weak notifier.
11134 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11137 GSList *old_list, *new_list;
11139 g_return_if_fail (GTK_IS_WIDGET (widget));
11140 g_return_if_fail (GTK_IS_WIDGET (label));
11142 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11143 new_list = g_slist_prepend (old_list, label);
11145 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11146 new_list, (GDestroyNotify) g_slist_free);
11150 * gtk_widget_remove_mnemonic_label:
11151 * @widget: a #GtkWidget
11152 * @label: a #GtkWidget that was previously set as a mnemnic label for
11153 * @widget with gtk_widget_add_mnemonic_label().
11155 * Removes a widget from the list of mnemonic labels for
11156 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11157 * must have previously been added to the list with
11158 * gtk_widget_add_mnemonic_label().
11163 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11166 GSList *old_list, *new_list;
11168 g_return_if_fail (GTK_IS_WIDGET (widget));
11169 g_return_if_fail (GTK_IS_WIDGET (label));
11171 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11172 new_list = g_slist_remove (old_list, label);
11175 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11176 new_list, (GDestroyNotify) g_slist_free);
11180 * gtk_widget_get_no_show_all:
11181 * @widget: a #GtkWidget
11183 * Returns the current value of the GtkWidget:no-show-all property,
11184 * which determines whether calls to gtk_widget_show_all() and
11185 * gtk_widget_hide_all() will affect this widget.
11187 * Return value: the current value of the "no-show-all" property.
11192 gtk_widget_get_no_show_all (GtkWidget *widget)
11194 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11196 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11200 * gtk_widget_set_no_show_all:
11201 * @widget: a #GtkWidget
11202 * @no_show_all: the new value for the "no-show-all" property
11204 * Sets the #GtkWidget:no-show-all property, which determines whether
11205 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11208 * This is mostly for use in constructing widget hierarchies with externally
11209 * controlled visibility, see #GtkUIManager.
11214 gtk_widget_set_no_show_all (GtkWidget *widget,
11215 gboolean no_show_all)
11217 g_return_if_fail (GTK_IS_WIDGET (widget));
11219 no_show_all = (no_show_all != FALSE);
11221 if (no_show_all == gtk_widget_get_no_show_all (widget))
11225 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11227 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11229 g_object_notify (G_OBJECT (widget), "no-show-all");
11234 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11235 gboolean has_tooltip,
11238 GtkWidgetPrivate *priv = widget->priv;
11239 gboolean priv_has_tooltip;
11241 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11242 quark_has_tooltip));
11244 if (priv_has_tooltip != has_tooltip || force)
11246 priv_has_tooltip = has_tooltip;
11248 if (priv_has_tooltip)
11250 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11251 gdk_window_set_events (priv->window,
11252 gdk_window_get_events (priv->window) |
11253 GDK_LEAVE_NOTIFY_MASK |
11254 GDK_POINTER_MOTION_MASK |
11255 GDK_POINTER_MOTION_HINT_MASK);
11257 if (gtk_widget_get_has_window (widget))
11258 gtk_widget_add_events (widget,
11259 GDK_LEAVE_NOTIFY_MASK |
11260 GDK_POINTER_MOTION_MASK |
11261 GDK_POINTER_MOTION_HINT_MASK);
11264 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11265 GUINT_TO_POINTER (priv_has_tooltip));
11270 * gtk_widget_set_tooltip_window:
11271 * @widget: a #GtkWidget
11272 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11274 * Replaces the default, usually yellow, window used for displaying
11275 * tooltips with @custom_window. GTK+ will take care of showing and
11276 * hiding @custom_window at the right moment, to behave likewise as
11277 * the default tooltip window. If @custom_window is %NULL, the default
11278 * tooltip window will be used.
11280 * If the custom window should have the default theming it needs to
11281 * have the name "gtk-tooltip", see gtk_widget_set_name().
11286 gtk_widget_set_tooltip_window (GtkWidget *widget,
11287 GtkWindow *custom_window)
11289 gboolean has_tooltip;
11290 gchar *tooltip_markup;
11292 g_return_if_fail (GTK_IS_WIDGET (widget));
11293 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11295 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11298 g_object_ref (custom_window);
11300 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11301 custom_window, g_object_unref);
11303 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11304 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11306 if (has_tooltip && gtk_widget_get_visible (widget))
11307 gtk_widget_queue_tooltip_query (widget);
11311 * gtk_widget_get_tooltip_window:
11312 * @widget: a #GtkWidget
11314 * Returns the #GtkWindow of the current tooltip. This can be the
11315 * GtkWindow created by default, or the custom tooltip window set
11316 * using gtk_widget_set_tooltip_window().
11318 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11323 gtk_widget_get_tooltip_window (GtkWidget *widget)
11325 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11327 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11331 * gtk_widget_trigger_tooltip_query:
11332 * @widget: a #GtkWidget
11334 * Triggers a tooltip query on the display where the toplevel of @widget
11335 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11341 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11343 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11346 static guint tooltip_query_id;
11347 static GSList *tooltip_query_displays;
11350 tooltip_query_idle (gpointer data)
11352 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11353 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11354 g_slist_free (tooltip_query_displays);
11356 tooltip_query_displays = NULL;
11357 tooltip_query_id = 0;
11363 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11365 GdkDisplay *display;
11367 display = gtk_widget_get_display (widget);
11369 if (!g_slist_find (tooltip_query_displays, display))
11370 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11372 if (tooltip_query_id == 0)
11373 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11377 * gtk_widget_set_tooltip_text:
11378 * @widget: a #GtkWidget
11379 * @text: the contents of the tooltip for @widget
11381 * Sets @text as the contents of the tooltip. This function will take
11382 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11383 * handler for the GtkWidget::query-tooltip signal.
11385 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11390 gtk_widget_set_tooltip_text (GtkWidget *widget,
11393 g_return_if_fail (GTK_IS_WIDGET (widget));
11395 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11399 * gtk_widget_get_tooltip_text:
11400 * @widget: a #GtkWidget
11402 * Gets the contents of the tooltip for @widget.
11404 * Return value: the tooltip text, or %NULL. You should free the
11405 * returned string with g_free() when done.
11410 gtk_widget_get_tooltip_text (GtkWidget *widget)
11412 gchar *text = NULL;
11414 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11416 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11422 * gtk_widget_set_tooltip_markup:
11423 * @widget: a #GtkWidget
11424 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11426 * Sets @markup as the contents of the tooltip, which is marked up with
11427 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11429 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11430 * and of the default handler for the GtkWidget::query-tooltip signal.
11432 * See also the GtkWidget:tooltip-markup property and
11433 * gtk_tooltip_set_markup().
11438 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11439 const gchar *markup)
11441 g_return_if_fail (GTK_IS_WIDGET (widget));
11443 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11447 * gtk_widget_get_tooltip_markup:
11448 * @widget: a #GtkWidget
11450 * Gets the contents of the tooltip for @widget.
11452 * Return value: the tooltip text, or %NULL. You should free the
11453 * returned string with g_free() when done.
11458 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11460 gchar *text = NULL;
11462 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11464 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11470 * gtk_widget_set_has_tooltip:
11471 * @widget: a #GtkWidget
11472 * @has_tooltip: whether or not @widget has a tooltip.
11474 * Sets the has-tooltip property on @widget to @has_tooltip. See
11475 * GtkWidget:has-tooltip for more information.
11480 gtk_widget_set_has_tooltip (GtkWidget *widget,
11481 gboolean has_tooltip)
11483 g_return_if_fail (GTK_IS_WIDGET (widget));
11485 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11489 * gtk_widget_get_has_tooltip:
11490 * @widget: a #GtkWidget
11492 * Returns the current value of the has-tooltip property. See
11493 * GtkWidget:has-tooltip for more information.
11495 * Return value: current value of has-tooltip on @widget.
11500 gtk_widget_get_has_tooltip (GtkWidget *widget)
11502 gboolean has_tooltip = FALSE;
11504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11506 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11508 return has_tooltip;
11512 * gtk_widget_get_allocation:
11513 * @widget: a #GtkWidget
11514 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11516 * Retrieves the widget's allocation.
11521 gtk_widget_get_allocation (GtkWidget *widget,
11522 GtkAllocation *allocation)
11524 GtkWidgetPrivate *priv;
11526 g_return_if_fail (GTK_IS_WIDGET (widget));
11527 g_return_if_fail (allocation != NULL);
11529 priv = widget->priv;
11531 *allocation = priv->allocation;
11535 * gtk_widget_set_allocation:
11536 * @widget: a #GtkWidget
11537 * @allocation: a pointer to a #GtkAllocation to copy from
11539 * Sets the widget's allocation. This should not be used
11540 * directly, but from within a widget's size_allocate method.
11545 gtk_widget_set_allocation (GtkWidget *widget,
11546 const GtkAllocation *allocation)
11548 GtkWidgetPrivate *priv;
11550 g_return_if_fail (GTK_IS_WIDGET (widget));
11551 g_return_if_fail (allocation != NULL);
11553 priv = widget->priv;
11555 priv->allocation = *allocation;
11559 * gtk_widget_get_requisition:
11560 * @widget: a #GtkWidget
11561 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11563 * Retrieves the widget's requisition.
11565 * This function should only be used by widget implementations in
11566 * order to figure whether the widget's requisition has actually
11567 * changed after some internal state change (so that they can call
11568 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11570 * Normally, gtk_widget_size_request() should be used.
11574 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
11575 * removed, If you need to cache sizes across requests and allocations,
11576 * add an explicit cache to the widget in question instead.
11579 gtk_widget_get_requisition (GtkWidget *widget,
11580 GtkRequisition *requisition)
11582 g_return_if_fail (GTK_IS_WIDGET (widget));
11583 g_return_if_fail (requisition != NULL);
11585 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
11589 * gtk_widget_set_window:
11590 * @widget: a #GtkWidget
11591 * @window: a #GdkWindow
11593 * Sets a widget's window. This function should only be used in a
11594 * widget's GtkWidget::realize() implementation. The %window passed is
11595 * usually either new window created with gdk_window_new(), or the
11596 * window of its parent widget as returned by
11597 * gtk_widget_get_parent_window().
11599 * Widgets must indicate whether they will create their own #GdkWindow
11600 * by calling gtk_widget_set_has_window(). This is usually done in the
11601 * widget's init() function.
11606 gtk_widget_set_window (GtkWidget *widget,
11609 GtkWidgetPrivate *priv;
11611 g_return_if_fail (GTK_IS_WIDGET (widget));
11612 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11614 priv = widget->priv;
11616 if (priv->window != window)
11618 priv->window = window;
11619 g_object_notify (G_OBJECT (widget), "window");
11624 * gtk_widget_get_window:
11625 * @widget: a #GtkWidget
11627 * Returns the widget's window if it is realized, %NULL otherwise
11629 * Return value: (transfer none): @widget's window.
11634 gtk_widget_get_window (GtkWidget *widget)
11636 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11638 return widget->priv->window;
11642 * gtk_widget_get_support_multidevice:
11643 * @widget: a #GtkWidget
11645 * Returns %TRUE if @widget is multiple pointer aware. See
11646 * gtk_widget_set_support_multidevice() for more information.
11648 * Returns: %TRUE is @widget is multidevice aware.
11651 gtk_widget_get_support_multidevice (GtkWidget *widget)
11653 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11655 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
11659 * gtk_widget_set_support_multidevice:
11660 * @widget: a #GtkWidget
11661 * @support_multidevice: %TRUE to support input from multiple devices.
11663 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
11664 * @widget will start receiving multiple, per device enter/leave events. Note
11665 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
11666 * gdk_window_set_support_multidevice() will have to be called manually on them.
11671 gtk_widget_set_support_multidevice (GtkWidget *widget,
11672 gboolean support_multidevice)
11674 GtkWidgetPrivate *priv;
11676 g_return_if_fail (GTK_IS_WIDGET (widget));
11678 priv = widget->priv;
11680 if (support_multidevice)
11682 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
11683 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
11687 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
11688 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
11691 if (gtk_widget_get_realized (widget))
11692 gdk_window_set_support_multidevice (priv->window, support_multidevice);
11696 _gtk_widget_set_has_focus (GtkWidget *widget,
11697 gboolean has_focus)
11700 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
11702 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
11706 * gtk_widget_send_focus_change:
11707 * @widget: a #GtkWidget
11708 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
11710 * Sends the focus change @event to @widget
11712 * This function is not meant to be used by applications. The only time it
11713 * should be used is when it is necessary for a #GtkWidget to assign focus
11714 * to a widget that is semantically owned by the first widget even though
11715 * it's not a direct child - for instance, a search entry in a floating
11716 * window similar to the quick search in #GtkTreeView.
11718 * An example of its usage is:
11721 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
11723 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
11724 * fevent->focus_change.in = TRUE;
11725 * fevent->focus_change.window = gtk_widget_get_window (widget);
11726 * if (fevent->focus_change.window != NULL)
11727 * g_object_ref (fevent->focus_change.window);
11729 * gtk_widget_send_focus_change (widget, fevent);
11731 * gdk_event_free (event);
11734 * Return value: the return value from the event signal emission: %TRUE
11735 * if the event was handled, and %FALSE otherwise
11740 gtk_widget_send_focus_change (GtkWidget *widget,
11745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11746 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
11748 g_object_ref (widget);
11750 _gtk_widget_set_has_focus (widget, event->focus_change.in);
11752 res = gtk_widget_event (widget, event);
11754 g_object_notify (G_OBJECT (widget), "has-focus");
11756 g_object_unref (widget);