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)
157 BUTTON_RELEASE_EVENT,
172 PROPERTY_NOTIFY_EVENT,
173 SELECTION_CLEAR_EVENT,
174 SELECTION_REQUEST_EVENT,
175 SELECTION_NOTIFY_EVENT,
190 VISIBILITY_NOTIFY_EVENT,
194 ACCEL_CLOSURES_CHANGED,
220 PROP_RECEIVES_DEFAULT,
221 PROP_COMPOSITE_CHILD,
224 PROP_EXTENSION_EVENTS,
233 typedef struct _GtkStateData GtkStateData;
238 guint state_restoration : 1;
239 guint parent_sensitive : 1;
240 guint use_forall : 1;
243 /* --- prototypes --- */
244 static void gtk_widget_class_init (GtkWidgetClass *klass);
245 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
246 static void gtk_widget_init (GtkWidget *widget);
247 static void gtk_widget_set_property (GObject *object,
251 static void gtk_widget_get_property (GObject *object,
255 static void gtk_widget_dispose (GObject *object);
256 static void gtk_widget_real_destroy (GtkObject *object);
257 static void gtk_widget_finalize (GObject *object);
258 static void gtk_widget_real_show (GtkWidget *widget);
259 static void gtk_widget_real_hide (GtkWidget *widget);
260 static void gtk_widget_real_map (GtkWidget *widget);
261 static void gtk_widget_real_unmap (GtkWidget *widget);
262 static void gtk_widget_real_realize (GtkWidget *widget);
263 static void gtk_widget_real_unrealize (GtkWidget *widget);
264 static void gtk_widget_real_size_request (GtkWidget *widget,
265 GtkRequisition *requisition);
266 static void gtk_widget_real_size_allocate (GtkWidget *widget,
267 GtkAllocation *allocation);
268 static void gtk_widget_real_style_set (GtkWidget *widget,
269 GtkStyle *previous_style);
270 static void gtk_widget_real_direction_changed(GtkWidget *widget,
271 GtkTextDirection previous_direction);
273 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
274 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
277 gboolean keyboard_tip,
278 GtkTooltip *tooltip);
279 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
280 GtkWidgetHelpType help_type);
282 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
284 GParamSpec **pspecs);
285 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
287 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
289 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
290 GdkEventFocus *event);
291 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
292 GdkEventFocus *event);
293 static gboolean gtk_widget_real_focus (GtkWidget *widget,
294 GtkDirectionType direction);
295 static void gtk_widget_real_move_focus (GtkWidget *widget,
296 GtkDirectionType direction);
297 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
298 GtkDirectionType direction);
299 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
300 static void gtk_widget_update_pango_context (GtkWidget *widget);
301 static void gtk_widget_propagate_state (GtkWidget *widget,
303 static void gtk_widget_reset_rc_style (GtkWidget *widget);
304 static void gtk_widget_set_style_internal (GtkWidget *widget,
306 gboolean initial_emission);
307 static gint gtk_widget_event_internal (GtkWidget *widget,
309 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
310 gboolean group_cycling);
311 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
312 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
313 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
314 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
315 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
316 cairo_region_t *region);
317 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
318 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
319 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
322 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
323 gboolean has_tooltip,
325 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
326 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
328 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
329 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
331 const gchar *childname);
332 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
335 const GValue *value);
336 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
339 const gchar *tagname,
340 GMarkupParser *parser,
342 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
345 const gchar *tagname,
347 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
348 GtkBuilder *builder);
350 static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
351 static void gtk_widget_real_get_width (GtkSizeRequest *widget,
354 static void gtk_widget_real_get_height (GtkSizeRequest *widget,
358 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
360 static void gtk_widget_set_usize_internal (GtkWidget *widget,
363 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
366 static void gtk_widget_add_events_internal (GtkWidget *widget,
370 /* --- variables --- */
371 static gpointer gtk_widget_parent_class = NULL;
372 static guint widget_signals[LAST_SIGNAL] = { 0 };
373 static GtkStyle *gtk_default_style = NULL;
374 static GSList *colormap_stack = NULL;
375 static guint composite_child_stack = 0;
376 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
377 static GParamSpecPool *style_property_spec_pool = NULL;
379 static GQuark quark_property_parser = 0;
380 static GQuark quark_aux_info = 0;
381 static GQuark quark_accel_path = 0;
382 static GQuark quark_accel_closures = 0;
383 static GQuark quark_event_mask = 0;
384 static GQuark quark_device_event_mask = 0;
385 static GQuark quark_extension_event_mode = 0;
386 static GQuark quark_parent_window = 0;
387 static GQuark quark_pointer_window = 0;
388 static GQuark quark_shape_info = 0;
389 static GQuark quark_input_shape_info = 0;
390 static GQuark quark_colormap = 0;
391 static GQuark quark_pango_context = 0;
392 static GQuark quark_rc_style = 0;
393 static GQuark quark_accessible_object = 0;
394 static GQuark quark_mnemonic_labels = 0;
395 static GQuark quark_tooltip_markup = 0;
396 static GQuark quark_has_tooltip = 0;
397 static GQuark quark_tooltip_window = 0;
398 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
399 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
401 /* --- functions --- */
403 gtk_widget_get_type (void)
405 static GType widget_type = 0;
407 if (G_UNLIKELY (widget_type == 0))
409 const GTypeInfo widget_info =
411 sizeof (GtkWidgetClass),
412 NULL, /* base_init */
413 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
414 (GClassInitFunc) gtk_widget_class_init,
415 NULL, /* class_finalize */
416 NULL, /* class_init */
419 (GInstanceInitFunc) gtk_widget_init,
420 NULL, /* value_table */
423 const GInterfaceInfo accessibility_info =
425 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
426 (GInterfaceFinalizeFunc) NULL,
427 NULL /* interface data */
430 const GInterfaceInfo buildable_info =
432 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
433 (GInterfaceFinalizeFunc) NULL,
434 NULL /* interface data */
437 const GInterfaceInfo layout_info =
439 (GInterfaceInitFunc) gtk_widget_size_request_init,
440 (GInterfaceFinalizeFunc) NULL,
441 NULL /* interface data */
444 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
445 &widget_info, G_TYPE_FLAG_ABSTRACT);
447 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
448 &accessibility_info) ;
449 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
451 g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
459 child_property_notify_dispatcher (GObject *object,
463 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
467 gtk_widget_class_init (GtkWidgetClass *klass)
469 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
470 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
471 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
472 GtkBindingSet *binding_set;
474 gtk_widget_parent_class = g_type_class_peek_parent (klass);
476 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
477 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
478 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
479 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
480 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
481 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
482 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
483 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
484 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
485 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
486 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
487 quark_colormap = g_quark_from_static_string ("gtk-colormap");
488 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
489 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
490 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
491 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
492 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
493 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
494 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
496 style_property_spec_pool = g_param_spec_pool_new (FALSE);
497 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
498 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
499 cpn_context.dispatcher = child_property_notify_dispatcher;
500 _gtk_widget_child_property_notify_context = &cpn_context;
502 gobject_class->dispose = gtk_widget_dispose;
503 gobject_class->finalize = gtk_widget_finalize;
504 gobject_class->set_property = gtk_widget_set_property;
505 gobject_class->get_property = gtk_widget_get_property;
507 object_class->destroy = gtk_widget_real_destroy;
509 klass->activate_signal = 0;
510 klass->set_scroll_adjustments_signal = 0;
511 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
512 klass->show = gtk_widget_real_show;
513 klass->show_all = gtk_widget_show;
514 klass->hide = gtk_widget_real_hide;
515 klass->hide_all = gtk_widget_hide;
516 klass->map = gtk_widget_real_map;
517 klass->unmap = gtk_widget_real_unmap;
518 klass->realize = gtk_widget_real_realize;
519 klass->unrealize = gtk_widget_real_unrealize;
520 klass->size_request = gtk_widget_real_size_request;
521 klass->size_allocate = gtk_widget_real_size_allocate;
522 klass->state_changed = NULL;
523 klass->parent_set = NULL;
524 klass->hierarchy_changed = NULL;
525 klass->style_set = gtk_widget_real_style_set;
526 klass->direction_changed = gtk_widget_real_direction_changed;
527 klass->grab_notify = NULL;
528 klass->child_notify = NULL;
529 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
530 klass->grab_focus = gtk_widget_real_grab_focus;
531 klass->focus = gtk_widget_real_focus;
533 klass->button_press_event = NULL;
534 klass->button_release_event = NULL;
535 klass->motion_notify_event = NULL;
536 klass->delete_event = NULL;
537 klass->destroy_event = NULL;
538 klass->expose_event = NULL;
539 klass->key_press_event = gtk_widget_real_key_press_event;
540 klass->key_release_event = gtk_widget_real_key_release_event;
541 klass->enter_notify_event = NULL;
542 klass->leave_notify_event = NULL;
543 klass->configure_event = NULL;
544 klass->focus_in_event = gtk_widget_real_focus_in_event;
545 klass->focus_out_event = gtk_widget_real_focus_out_event;
546 klass->map_event = NULL;
547 klass->unmap_event = NULL;
548 klass->window_state_event = NULL;
549 klass->property_notify_event = _gtk_selection_property_notify;
550 klass->selection_clear_event = _gtk_selection_clear;
551 klass->selection_request_event = _gtk_selection_request;
552 klass->selection_notify_event = _gtk_selection_notify;
553 klass->selection_received = NULL;
554 klass->proximity_in_event = NULL;
555 klass->proximity_out_event = NULL;
556 klass->drag_begin = NULL;
557 klass->drag_end = NULL;
558 klass->drag_data_delete = NULL;
559 klass->drag_leave = NULL;
560 klass->drag_motion = NULL;
561 klass->drag_drop = NULL;
562 klass->drag_data_received = NULL;
563 klass->screen_changed = NULL;
564 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
565 klass->grab_broken_event = NULL;
566 klass->query_tooltip = gtk_widget_real_query_tooltip;
568 klass->show_help = gtk_widget_real_show_help;
570 /* Accessibility support */
571 klass->get_accessible = gtk_widget_real_get_accessible;
573 klass->no_expose_event = NULL;
575 g_object_class_install_property (gobject_class,
577 g_param_spec_string ("name",
579 P_("The name of the widget"),
581 GTK_PARAM_READWRITE));
582 g_object_class_install_property (gobject_class,
584 g_param_spec_object ("parent",
586 P_("The parent widget of this widget. Must be a Container widget"),
588 GTK_PARAM_READWRITE));
590 g_object_class_install_property (gobject_class,
592 g_param_spec_int ("width-request",
594 P_("Override for width request of the widget, or -1 if natural request should be used"),
598 GTK_PARAM_READWRITE));
599 g_object_class_install_property (gobject_class,
601 g_param_spec_int ("height-request",
602 P_("Height request"),
603 P_("Override for height request of the widget, or -1 if natural request should be used"),
607 GTK_PARAM_READWRITE));
608 g_object_class_install_property (gobject_class,
610 g_param_spec_boolean ("visible",
612 P_("Whether the widget is visible"),
614 GTK_PARAM_READWRITE));
615 g_object_class_install_property (gobject_class,
617 g_param_spec_boolean ("sensitive",
619 P_("Whether the widget responds to input"),
621 GTK_PARAM_READWRITE));
622 g_object_class_install_property (gobject_class,
624 g_param_spec_boolean ("app-paintable",
625 P_("Application paintable"),
626 P_("Whether the application will paint directly on the widget"),
628 GTK_PARAM_READWRITE));
629 g_object_class_install_property (gobject_class,
631 g_param_spec_boolean ("can-focus",
633 P_("Whether the widget can accept the input focus"),
635 GTK_PARAM_READWRITE));
636 g_object_class_install_property (gobject_class,
638 g_param_spec_boolean ("has-focus",
640 P_("Whether the widget has the input focus"),
642 GTK_PARAM_READWRITE));
643 g_object_class_install_property (gobject_class,
645 g_param_spec_boolean ("is-focus",
647 P_("Whether the widget is the focus widget within the toplevel"),
649 GTK_PARAM_READWRITE));
650 g_object_class_install_property (gobject_class,
652 g_param_spec_boolean ("can-default",
654 P_("Whether the widget can be the default widget"),
656 GTK_PARAM_READWRITE));
657 g_object_class_install_property (gobject_class,
659 g_param_spec_boolean ("has-default",
661 P_("Whether the widget is the default widget"),
663 GTK_PARAM_READWRITE));
664 g_object_class_install_property (gobject_class,
665 PROP_RECEIVES_DEFAULT,
666 g_param_spec_boolean ("receives-default",
667 P_("Receives default"),
668 P_("If TRUE, the widget will receive the default action when it is focused"),
670 GTK_PARAM_READWRITE));
671 g_object_class_install_property (gobject_class,
672 PROP_COMPOSITE_CHILD,
673 g_param_spec_boolean ("composite-child",
674 P_("Composite child"),
675 P_("Whether the widget is part of a composite widget"),
677 GTK_PARAM_READABLE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_object ("style",
682 P_("The style of the widget, which contains information about how it will look (colors etc)"),
684 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
687 g_param_spec_flags ("events",
689 P_("The event mask that decides what kind of GdkEvents this widget gets"),
692 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
694 PROP_EXTENSION_EVENTS,
695 g_param_spec_enum ("extension-events",
696 P_("Extension events"),
697 P_("The mask that decides what kind of extension events this widget gets"),
698 GDK_TYPE_EXTENSION_MODE,
699 GDK_EXTENSION_EVENTS_NONE,
700 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_boolean ("no-show-all",
705 P_("Whether gtk_widget_show_all() should not affect this widget"),
707 GTK_PARAM_READWRITE));
710 * GtkWidget:has-tooltip:
712 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
713 * A value of %TRUE indicates that @widget can have a tooltip, in this case
714 * the widget will be queried using #GtkWidget::query-tooltip to determine
715 * whether it will provide a tooltip or not.
717 * Note that setting this property to %TRUE for the first time will change
718 * the event masks of the GdkWindows of this widget to include leave-notify
719 * and motion-notify events. This cannot and will not be undone when the
720 * property is set to %FALSE again.
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("has-tooltip",
728 P_("Whether this widget has a tooltip"),
730 GTK_PARAM_READWRITE));
732 * GtkWidget:tooltip-text:
734 * Sets the text of tooltip to be the given string.
736 * Also see gtk_tooltip_set_text().
738 * This is a convenience property which will take care of getting the
739 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
740 * will automatically be set to %TRUE and there will be taken care of
741 * #GtkWidget::query-tooltip in the default signal handler.
745 g_object_class_install_property (gobject_class,
747 g_param_spec_string ("tooltip-text",
749 P_("The contents of the tooltip for this widget"),
751 GTK_PARAM_READWRITE));
753 * GtkWidget:tooltip-markup:
755 * Sets the text of tooltip to be the given string, which is marked up
756 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
757 * Also see gtk_tooltip_set_markup().
759 * This is a convenience property which will take care of getting the
760 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
761 * will automatically be set to %TRUE and there will be taken care of
762 * #GtkWidget::query-tooltip in the default signal handler.
766 g_object_class_install_property (gobject_class,
768 g_param_spec_string ("tooltip-markup",
769 P_("Tooltip markup"),
770 P_("The contents of the tooltip for this widget"),
772 GTK_PARAM_READWRITE));
777 * The widget's window if it is realized, %NULL otherwise.
781 g_object_class_install_property (gobject_class,
783 g_param_spec_object ("window",
785 P_("The widget's window if it is realized"),
787 GTK_PARAM_READABLE));
790 * GtkWidget:double-buffered
792 * Whether or not the widget is double buffered.
796 g_object_class_install_property (gobject_class,
797 PROP_DOUBLE_BUFFERED,
798 g_param_spec_boolean ("double-buffered",
799 P_("Double Buffered"),
800 P_("Whether or not the widget is double buffered"),
802 GTK_PARAM_READWRITE));
806 * @widget: the object which received the signal.
808 widget_signals[SHOW] =
809 g_signal_new (I_("show"),
810 G_TYPE_FROM_CLASS (gobject_class),
812 G_STRUCT_OFFSET (GtkWidgetClass, show),
814 _gtk_marshal_VOID__VOID,
819 * @widget: the object which received the signal.
821 widget_signals[HIDE] =
822 g_signal_new (I_("hide"),
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkWidgetClass, hide),
827 _gtk_marshal_VOID__VOID,
832 * @widget: the object which received the signal.
834 widget_signals[MAP] =
835 g_signal_new (I_("map"),
836 G_TYPE_FROM_CLASS (gobject_class),
838 G_STRUCT_OFFSET (GtkWidgetClass, map),
840 _gtk_marshal_VOID__VOID,
845 * @widget: the object which received the signal.
847 widget_signals[UNMAP] =
848 g_signal_new (I_("unmap"),
849 G_TYPE_FROM_CLASS (gobject_class),
851 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
853 _gtk_marshal_VOID__VOID,
857 * GtkWidget::realize:
858 * @widget: the object which received the signal.
860 widget_signals[REALIZE] =
861 g_signal_new (I_("realize"),
862 G_TYPE_FROM_CLASS (gobject_class),
864 G_STRUCT_OFFSET (GtkWidgetClass, realize),
866 _gtk_marshal_VOID__VOID,
870 * GtkWidget::unrealize:
871 * @widget: the object which received the signal.
873 widget_signals[UNREALIZE] =
874 g_signal_new (I_("unrealize"),
875 G_TYPE_FROM_CLASS (gobject_class),
877 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
879 _gtk_marshal_VOID__VOID,
883 * GtkWidget::size-request:
884 * @widget: the object which received the signal.
887 widget_signals[SIZE_REQUEST] =
888 g_signal_new (I_("size-request"),
889 G_TYPE_FROM_CLASS (gobject_class),
891 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
893 _gtk_marshal_VOID__BOXED,
895 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
898 * GtkWidget::size-allocate:
899 * @widget: the object which received the signal.
902 widget_signals[SIZE_ALLOCATE] =
903 g_signal_new (I_("size-allocate"),
904 G_TYPE_FROM_CLASS (gobject_class),
906 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
908 _gtk_marshal_VOID__BOXED,
910 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
913 * GtkWidget::state-changed:
914 * @widget: the object which received the signal.
915 * @state: the previous state
917 * The ::state-changed signal is emitted when the widget state changes.
918 * See gtk_widget_get_state().
920 widget_signals[STATE_CHANGED] =
921 g_signal_new (I_("state-changed"),
922 G_TYPE_FROM_CLASS (gobject_class),
924 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
926 _gtk_marshal_VOID__ENUM,
928 GTK_TYPE_STATE_TYPE);
931 * GtkWidget::parent-set:
932 * @widget: the object on which the signal is emitted
933 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
934 * just got its initial parent.
936 * The ::parent-set signal is emitted when a new parent
937 * has been set on a widget.
939 widget_signals[PARENT_SET] =
940 g_signal_new (I_("parent-set"),
941 G_TYPE_FROM_CLASS (gobject_class),
943 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
945 _gtk_marshal_VOID__OBJECT,
950 * GtkWidget::hierarchy-changed:
951 * @widget: the object on which the signal is emitted
952 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
953 * if the widget was previously unanchored
955 * The ::hierarchy-changed signal is emitted when the
956 * anchored state of a widget changes. A widget is
957 * <firstterm>anchored</firstterm> when its toplevel
958 * ancestor is a #GtkWindow. This signal is emitted when
959 * a widget changes from un-anchored to anchored or vice-versa.
961 widget_signals[HIERARCHY_CHANGED] =
962 g_signal_new (I_("hierarchy-changed"),
963 G_TYPE_FROM_CLASS (gobject_class),
965 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
967 _gtk_marshal_VOID__OBJECT,
972 * GtkWidget::style-set:
973 * @widget: the object on which the signal is emitted
974 * @previous_style: (allow-none): the previous style, or %NULL if the widget
975 * just got its initial style
977 * The ::style-set signal is emitted when a new style has been set
978 * on a widget. Note that style-modifying functions like
979 * gtk_widget_modify_base() also cause this signal to be emitted.
981 widget_signals[STYLE_SET] =
982 g_signal_new (I_("style-set"),
983 G_TYPE_FROM_CLASS (gobject_class),
985 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
987 _gtk_marshal_VOID__OBJECT,
991 * GtkWidget::direction-changed:
992 * @widget: the object on which the signal is emitted
993 * @previous_direction: the previous text direction of @widget
995 * The ::direction-changed signal is emitted when the text direction
996 * of a widget changes.
998 widget_signals[DIRECTION_CHANGED] =
999 g_signal_new (I_("direction-changed"),
1000 G_TYPE_FROM_CLASS (gobject_class),
1002 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1004 _gtk_marshal_VOID__ENUM,
1006 GTK_TYPE_TEXT_DIRECTION);
1009 * GtkWidget::grab-notify:
1010 * @widget: the object which received the signal
1011 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1012 * if it becomes unshadowed
1014 * The ::grab-notify signal is emitted when a widget becomes
1015 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1016 * another widget, or when it becomes unshadowed due to a grab
1019 * A widget is shadowed by a gtk_grab_add() when the topmost
1020 * grab widget in the grab stack of its window group is not
1023 widget_signals[GRAB_NOTIFY] =
1024 g_signal_new (I_("grab-notify"),
1025 G_TYPE_FROM_CLASS (gobject_class),
1027 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1029 _gtk_marshal_VOID__BOOLEAN,
1034 * GtkWidget::child-notify:
1035 * @widget: the object which received the signal
1036 * @pspec: the #GParamSpec of the changed child property
1038 * The ::child-notify signal is emitted for each
1039 * <link linkend="child-properties">child property</link> that has
1040 * changed on an object. The signal's detail holds the property name.
1042 widget_signals[CHILD_NOTIFY] =
1043 g_signal_new (I_("child-notify"),
1044 G_TYPE_FROM_CLASS (gobject_class),
1045 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1046 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1048 g_cclosure_marshal_VOID__PARAM,
1053 * GtkWidget::mnemonic-activate:
1054 * @widget: the object which received the signal.
1057 widget_signals[MNEMONIC_ACTIVATE] =
1058 g_signal_new (I_("mnemonic-activate"),
1059 G_TYPE_FROM_CLASS (gobject_class),
1061 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1062 _gtk_boolean_handled_accumulator, NULL,
1063 _gtk_marshal_BOOLEAN__BOOLEAN,
1068 * GtkWidget::grab-focus:
1069 * @widget: the object which received the signal.
1071 widget_signals[GRAB_FOCUS] =
1072 g_signal_new (I_("grab-focus"),
1073 G_TYPE_FROM_CLASS (gobject_class),
1074 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1075 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1077 _gtk_marshal_VOID__VOID,
1082 * @widget: the object which received the signal.
1085 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1087 widget_signals[FOCUS] =
1088 g_signal_new (I_("focus"),
1089 G_TYPE_FROM_CLASS (object_class),
1091 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1092 _gtk_boolean_handled_accumulator, NULL,
1093 _gtk_marshal_BOOLEAN__ENUM,
1095 GTK_TYPE_DIRECTION_TYPE);
1098 * GtkWidget::move-focus:
1099 * @widget: the object which received the signal.
1102 widget_signals[MOVE_FOCUS] =
1103 g_signal_new_class_handler (I_("move-focus"),
1104 G_TYPE_FROM_CLASS (object_class),
1105 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1106 G_CALLBACK (gtk_widget_real_move_focus),
1108 _gtk_marshal_VOID__ENUM,
1111 GTK_TYPE_DIRECTION_TYPE);
1114 * @widget: the object which received the signal.
1115 * @event: the #GdkEvent which triggered this signal
1117 * The GTK+ main loop will emit three signals for each GDK event delivered
1118 * to a widget: one generic ::event signal, another, more specific,
1119 * signal that matches the type of event delivered (e.g.
1120 * #GtkWidget::key-press-event) and finally a generic
1121 * #GtkWidget::event-after signal.
1123 * Returns: %TRUE to stop other handlers from being invoked for the event
1124 * and to cancel the emission of the second specific ::event signal.
1125 * %FALSE to propagate the event further and to allow the emission of
1126 * the second signal. The ::event-after signal is emitted regardless of
1129 widget_signals[EVENT] =
1130 g_signal_new (I_("event"),
1131 G_TYPE_FROM_CLASS (gobject_class),
1133 G_STRUCT_OFFSET (GtkWidgetClass, event),
1134 _gtk_boolean_handled_accumulator, NULL,
1135 _gtk_marshal_BOOLEAN__BOXED,
1137 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1140 * GtkWidget::event-after:
1141 * @widget: the object which received the signal.
1142 * @event: the #GdkEvent which triggered this signal
1144 * After the emission of the #GtkWidget::event signal and (optionally)
1145 * the second more specific signal, ::event-after will be emitted
1146 * regardless of the previous two signals handlers return values.
1149 widget_signals[EVENT_AFTER] =
1150 g_signal_new (I_("event-after"),
1151 G_TYPE_FROM_CLASS (gobject_class),
1155 _gtk_marshal_VOID__BOXED,
1157 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1160 * GtkWidget::button-press-event:
1161 * @widget: the object which received the signal.
1162 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1165 * The ::button-press-event signal will be emitted when a button
1166 * (typically from a mouse) is pressed.
1168 * To receive this signal, the #GdkWindow associated to the
1169 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1171 * This signal will be sent to the grab widget if there is one.
1173 * Returns: %TRUE to stop other handlers from being invoked for the event.
1174 * %FALSE to propagate the event further.
1176 widget_signals[BUTTON_PRESS_EVENT] =
1177 g_signal_new (I_("button-press-event"),
1178 G_TYPE_FROM_CLASS (gobject_class),
1180 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1181 _gtk_boolean_handled_accumulator, NULL,
1182 _gtk_marshal_BOOLEAN__BOXED,
1184 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1187 * GtkWidget::button-release-event:
1188 * @widget: the object which received the signal.
1189 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1192 * The ::button-release-event signal will be emitted when a button
1193 * (typically from a mouse) is released.
1195 * To receive this signal, the #GdkWindow associated to the
1196 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1198 * This signal will be sent to the grab widget if there is one.
1200 * Returns: %TRUE to stop other handlers from being invoked for the event.
1201 * %FALSE to propagate the event further.
1203 widget_signals[BUTTON_RELEASE_EVENT] =
1204 g_signal_new (I_("button-release-event"),
1205 G_TYPE_FROM_CLASS (gobject_class),
1207 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1208 _gtk_boolean_handled_accumulator, NULL,
1209 _gtk_marshal_BOOLEAN__BOXED,
1211 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1214 * GtkWidget::scroll-event:
1215 * @widget: the object which received the signal.
1216 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1219 * The ::scroll-event signal is emitted when a button in the 4 to 7
1220 * range is pressed. Wheel mice are usually configured to generate
1221 * button press events for buttons 4 and 5 when the wheel is turned.
1223 * To receive this signal, the #GdkWindow associated to the widget needs
1224 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1226 * This signal will be sent to the grab widget if there is one.
1228 * Returns: %TRUE to stop other handlers from being invoked for the event.
1229 * %FALSE to propagate the event further.
1231 widget_signals[SCROLL_EVENT] =
1232 g_signal_new (I_("scroll-event"),
1233 G_TYPE_FROM_CLASS (gobject_class),
1235 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1236 _gtk_boolean_handled_accumulator, NULL,
1237 _gtk_marshal_BOOLEAN__BOXED,
1239 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1241 * GtkWidget::motion-notify-event:
1242 * @widget: the object which received the signal.
1243 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1246 * The ::motion-notify-event signal is emitted when the pointer moves
1247 * over the widget's #GdkWindow.
1249 * To receive this signal, the #GdkWindow associated to the widget
1250 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1252 * This signal will be sent to the grab widget if there is one.
1254 * Returns: %TRUE to stop other handlers from being invoked for the event.
1255 * %FALSE to propagate the event further.
1257 widget_signals[MOTION_NOTIFY_EVENT] =
1258 g_signal_new (I_("motion-notify-event"),
1259 G_TYPE_FROM_CLASS (gobject_class),
1261 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1262 _gtk_boolean_handled_accumulator, NULL,
1263 _gtk_marshal_BOOLEAN__BOXED,
1265 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1268 * GtkWidget::composited-changed:
1269 * @widget: the object on which the signal is emitted
1271 * The ::composited-changed signal is emitted when the composited
1272 * status of @widget<!-- -->s screen changes.
1273 * See gdk_screen_is_composited().
1275 widget_signals[COMPOSITED_CHANGED] =
1276 g_signal_new (I_("composited-changed"),
1277 G_TYPE_FROM_CLASS (gobject_class),
1278 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1279 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1281 _gtk_marshal_VOID__VOID,
1285 * GtkWidget::keynav-failed:
1286 * @widget: the object which received the signal
1287 * @direction: the direction of movement
1289 * Gets emitted if keyboard navigation fails.
1290 * See gtk_widget_keynav_failed() for details.
1292 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1293 * if the emitting widget should try to handle the keyboard
1294 * navigation attempt in its parent container(s).
1298 widget_signals[KEYNAV_FAILED] =
1299 g_signal_new_class_handler (I_("keynav-failed"),
1300 G_TYPE_FROM_CLASS (gobject_class),
1302 G_CALLBACK (gtk_widget_real_keynav_failed),
1303 _gtk_boolean_handled_accumulator, NULL,
1304 _gtk_marshal_BOOLEAN__ENUM,
1306 GTK_TYPE_DIRECTION_TYPE);
1309 * GtkWidget::delete-event:
1310 * @widget: the object which received the signal
1311 * @event: the event which triggered this signal
1313 * The ::delete-event signal is emitted if a user requests that
1314 * a toplevel window is closed. The default handler for this signal
1315 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1316 * this signal will cause the window to be hidden instead, so that
1317 * it can later be shown again without reconstructing it.
1319 * Returns: %TRUE to stop other handlers from being invoked for the event.
1320 * %FALSE to propagate the event further.
1322 widget_signals[DELETE_EVENT] =
1323 g_signal_new (I_("delete-event"),
1324 G_TYPE_FROM_CLASS (gobject_class),
1326 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1327 _gtk_boolean_handled_accumulator, NULL,
1328 _gtk_marshal_BOOLEAN__BOXED,
1330 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1333 * GtkWidget::destroy-event:
1334 * @widget: the object which received the signal.
1335 * @event: the event which triggered this signal
1337 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1338 * You rarely get this signal, because most widgets disconnect themselves
1339 * from their window before they destroy it, so no widget owns the
1340 * window at destroy time.
1342 * To receive this signal, the #GdkWindow associated to the widget needs
1343 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1344 * automatically for all new windows.
1346 * Returns: %TRUE to stop other handlers from being invoked for the event.
1347 * %FALSE to propagate the event further.
1349 widget_signals[DESTROY_EVENT] =
1350 g_signal_new (I_("destroy-event"),
1351 G_TYPE_FROM_CLASS (gobject_class),
1353 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1354 _gtk_boolean_handled_accumulator, NULL,
1355 _gtk_marshal_BOOLEAN__BOXED,
1357 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1360 * GtkWidget::expose-event:
1361 * @widget: the object which received the signal.
1362 * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
1365 * The ::expose-event signal is emitted when an area of a previously
1366 * obscured #GdkWindow is made visible and needs to be redrawn.
1367 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1370 * To receive this signal, the #GdkWindow associated to the widget needs
1371 * to enable the #GDK_EXPOSURE_MASK mask.
1373 * Returns: %TRUE to stop other handlers from being invoked for the event.
1374 * %FALSE to propagate the event further.
1376 widget_signals[EXPOSE_EVENT] =
1377 g_signal_new (I_("expose-event"),
1378 G_TYPE_FROM_CLASS (gobject_class),
1380 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1381 _gtk_boolean_handled_accumulator, NULL,
1382 _gtk_marshal_BOOLEAN__BOXED,
1384 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1387 * GtkWidget::key-press-event:
1388 * @widget: the object which received the signal
1389 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1391 * The ::key-press-event signal is emitted when a key is pressed.
1393 * To receive this signal, the #GdkWindow associated to the widget needs
1394 * to enable the #GDK_KEY_PRESS_MASK mask.
1396 * This signal will be sent to the grab widget if there is one.
1398 * Returns: %TRUE to stop other handlers from being invoked for the event.
1399 * %FALSE to propagate the event further.
1401 widget_signals[KEY_PRESS_EVENT] =
1402 g_signal_new (I_("key-press-event"),
1403 G_TYPE_FROM_CLASS (gobject_class),
1405 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1406 _gtk_boolean_handled_accumulator, NULL,
1407 _gtk_marshal_BOOLEAN__BOXED,
1409 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1412 * GtkWidget::key-release-event:
1413 * @widget: the object which received the signal
1414 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1416 * The ::key-release-event signal is emitted when a key is pressed.
1418 * To receive this signal, the #GdkWindow associated to the widget needs
1419 * to enable the #GDK_KEY_RELEASE_MASK mask.
1421 * This signal will be sent to the grab widget if there is one.
1423 * Returns: %TRUE to stop other handlers from being invoked for the event.
1424 * %FALSE to propagate the event further.
1426 widget_signals[KEY_RELEASE_EVENT] =
1427 g_signal_new (I_("key-release-event"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1431 _gtk_boolean_handled_accumulator, NULL,
1432 _gtk_marshal_BOOLEAN__BOXED,
1434 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1437 * GtkWidget::enter-notify-event:
1438 * @widget: the object which received the signal
1439 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1442 * The ::enter-notify-event will be emitted when the pointer enters
1443 * the @widget's window.
1445 * To receive this signal, the #GdkWindow associated to the widget needs
1446 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1448 * This signal will be sent to the grab widget if there is one.
1450 * Returns: %TRUE to stop other handlers from being invoked for the event.
1451 * %FALSE to propagate the event further.
1453 widget_signals[ENTER_NOTIFY_EVENT] =
1454 g_signal_new (I_("enter-notify-event"),
1455 G_TYPE_FROM_CLASS (gobject_class),
1457 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1458 _gtk_boolean_handled_accumulator, NULL,
1459 _gtk_marshal_BOOLEAN__BOXED,
1461 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1464 * GtkWidget::leave-notify-event:
1465 * @widget: the object which received the signal
1466 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1469 * The ::leave-notify-event will be emitted when the pointer leaves
1470 * the @widget's window.
1472 * To receive this signal, the #GdkWindow associated to the widget needs
1473 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1475 * This signal will be sent to the grab widget if there is one.
1477 * Returns: %TRUE to stop other handlers from being invoked for the event.
1478 * %FALSE to propagate the event further.
1480 widget_signals[LEAVE_NOTIFY_EVENT] =
1481 g_signal_new (I_("leave-notify-event"),
1482 G_TYPE_FROM_CLASS (gobject_class),
1484 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1485 _gtk_boolean_handled_accumulator, NULL,
1486 _gtk_marshal_BOOLEAN__BOXED,
1488 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1491 * GtkWidget::configure-event
1492 * @widget: the object which received the signal
1493 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1496 * The ::configure-event signal will be emitted when the size, position or
1497 * stacking of the @widget's window has changed.
1499 * To receive this signal, the #GdkWindow associated to the widget needs
1500 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1501 * automatically for all new windows.
1503 * Returns: %TRUE to stop other handlers from being invoked for the event.
1504 * %FALSE to propagate the event further.
1506 widget_signals[CONFIGURE_EVENT] =
1507 g_signal_new (I_("configure-event"),
1508 G_TYPE_FROM_CLASS (gobject_class),
1510 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1511 _gtk_boolean_handled_accumulator, NULL,
1512 _gtk_marshal_BOOLEAN__BOXED,
1514 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1517 * GtkWidget::focus-in-event
1518 * @widget: the object which received the signal
1519 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1522 * The ::focus-in-event signal will be emitted when the keyboard focus
1523 * enters the @widget's window.
1525 * To receive this signal, the #GdkWindow associated to the widget needs
1526 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1528 * Returns: %TRUE to stop other handlers from being invoked for the event.
1529 * %FALSE to propagate the event further.
1531 widget_signals[FOCUS_IN_EVENT] =
1532 g_signal_new (I_("focus-in-event"),
1533 G_TYPE_FROM_CLASS (gobject_class),
1535 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1536 _gtk_boolean_handled_accumulator, NULL,
1537 _gtk_marshal_BOOLEAN__BOXED,
1539 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1542 * GtkWidget::focus-out-event
1543 * @widget: the object which received the signal
1544 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1547 * The ::focus-out-event signal will be emitted when the keyboard focus
1548 * leaves the @widget's window.
1550 * To receive this signal, the #GdkWindow associated to the widget needs
1551 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1553 * Returns: %TRUE to stop other handlers from being invoked for the event.
1554 * %FALSE to propagate the event further.
1556 widget_signals[FOCUS_OUT_EVENT] =
1557 g_signal_new (I_("focus-out-event"),
1558 G_TYPE_FROM_CLASS (gobject_class),
1560 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1561 _gtk_boolean_handled_accumulator, NULL,
1562 _gtk_marshal_BOOLEAN__BOXED,
1564 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1567 * GtkWidget::map-event
1568 * @widget: the object which received the signal
1569 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1571 * The ::map-event signal will be emitted when the @widget's window is
1572 * mapped. A window is mapped when it becomes visible on the screen.
1574 * To receive this signal, the #GdkWindow associated to the widget needs
1575 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1576 * automatically for all new windows.
1578 * Returns: %TRUE to stop other handlers from being invoked for the event.
1579 * %FALSE to propagate the event further.
1581 widget_signals[MAP_EVENT] =
1582 g_signal_new (I_("map-event"),
1583 G_TYPE_FROM_CLASS (gobject_class),
1585 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1586 _gtk_boolean_handled_accumulator, NULL,
1587 _gtk_marshal_BOOLEAN__BOXED,
1589 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1592 * GtkWidget::unmap-event
1593 * @widget: the object which received the signal
1594 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1596 * The ::unmap-event signal may be emitted when the @widget's window is
1597 * unmapped. A window is unmapped when it becomes invisible on the screen.
1599 * For performance reasons GTK+ may not emit ::unmap-event, so one
1600 * should always also implement ::unrealize in order to release
1601 * resources and disconnect signal handlers.
1603 * To receive this signal, the #GdkWindow associated to the widget needs
1604 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1605 * automatically for all new windows.
1607 * Returns: %TRUE to stop other handlers from being invoked for the event.
1608 * %FALSE to propagate the event further.
1610 widget_signals[UNMAP_EVENT] =
1611 g_signal_new (I_("unmap-event"),
1612 G_TYPE_FROM_CLASS (gobject_class),
1614 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1615 _gtk_boolean_handled_accumulator, NULL,
1616 _gtk_marshal_BOOLEAN__BOXED,
1618 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1621 * GtkWidget::property-notify-event
1622 * @widget: the object which received the signal
1623 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1626 * The ::property-notify-event signal will be emitted when a property on
1627 * the @widget's window has been changed or deleted.
1629 * To receive this signal, the #GdkWindow associated to the widget needs
1630 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1632 * Returns: %TRUE to stop other handlers from being invoked for the event.
1633 * %FALSE to propagate the event further.
1635 widget_signals[PROPERTY_NOTIFY_EVENT] =
1636 g_signal_new (I_("property-notify-event"),
1637 G_TYPE_FROM_CLASS (gobject_class),
1639 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1640 _gtk_boolean_handled_accumulator, NULL,
1641 _gtk_marshal_BOOLEAN__BOXED,
1643 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1646 * GtkWidget::selection-clear-event
1647 * @widget: the object which received the signal
1648 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1651 * The ::selection-clear-event signal will be emitted when the
1652 * the @widget's window has lost ownership of a selection.
1654 * Returns: %TRUE to stop other handlers from being invoked for the event.
1655 * %FALSE to propagate the event further.
1657 widget_signals[SELECTION_CLEAR_EVENT] =
1658 g_signal_new (I_("selection-clear-event"),
1659 G_TYPE_FROM_CLASS (gobject_class),
1661 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1662 _gtk_boolean_handled_accumulator, NULL,
1663 _gtk_marshal_BOOLEAN__BOXED,
1665 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1668 * GtkWidget::selection-request-event
1669 * @widget: the object which received the signal
1670 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1673 * The ::selection-request-event signal will be emitted when
1674 * another client requests ownership of the selection owned by
1675 * the @widget's window.
1677 * Returns: %TRUE to stop other handlers from being invoked for the event.
1678 * %FALSE to propagate the event further.
1680 widget_signals[SELECTION_REQUEST_EVENT] =
1681 g_signal_new (I_("selection-request-event"),
1682 G_TYPE_FROM_CLASS (gobject_class),
1684 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1685 _gtk_boolean_handled_accumulator, NULL,
1686 _gtk_marshal_BOOLEAN__BOXED,
1688 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1691 * GtkWidget::selection-notify-event:
1692 * @widget: the object which received the signal.
1695 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1697 widget_signals[SELECTION_NOTIFY_EVENT] =
1698 g_signal_new (I_("selection-notify-event"),
1699 G_TYPE_FROM_CLASS (gobject_class),
1701 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1702 _gtk_boolean_handled_accumulator, NULL,
1703 _gtk_marshal_BOOLEAN__BOXED,
1705 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1708 * GtkWidget::selection-received:
1709 * @widget: the object which received the signal.
1713 widget_signals[SELECTION_RECEIVED] =
1714 g_signal_new (I_("selection-received"),
1715 G_TYPE_FROM_CLASS (gobject_class),
1717 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1719 _gtk_marshal_VOID__BOXED_UINT,
1721 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1725 * GtkWidget::selection-get:
1726 * @widget: the object which received the signal.
1731 widget_signals[SELECTION_GET] =
1732 g_signal_new (I_("selection-get"),
1733 G_TYPE_FROM_CLASS (gobject_class),
1735 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1737 _gtk_marshal_VOID__BOXED_UINT_UINT,
1739 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1744 * GtkWidget::proximity-in-event
1745 * @widget: the object which received the signal
1746 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1749 * To receive this signal the #GdkWindow associated to the widget needs
1750 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1752 * This signal will be sent to the grab widget if there is one.
1754 * Returns: %TRUE to stop other handlers from being invoked for the event.
1755 * %FALSE to propagate the event further.
1757 widget_signals[PROXIMITY_IN_EVENT] =
1758 g_signal_new (I_("proximity-in-event"),
1759 G_TYPE_FROM_CLASS (gobject_class),
1761 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1762 _gtk_boolean_handled_accumulator, NULL,
1763 _gtk_marshal_BOOLEAN__BOXED,
1765 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1768 * GtkWidget::proximity-out-event
1769 * @widget: the object which received the signal
1770 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1773 * To receive this signal the #GdkWindow associated to the widget needs
1774 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1776 * This signal will be sent to the grab widget if there is one.
1778 * Returns: %TRUE to stop other handlers from being invoked for the event.
1779 * %FALSE to propagate the event further.
1781 widget_signals[PROXIMITY_OUT_EVENT] =
1782 g_signal_new (I_("proximity-out-event"),
1783 G_TYPE_FROM_CLASS (gobject_class),
1785 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1786 _gtk_boolean_handled_accumulator, NULL,
1787 _gtk_marshal_BOOLEAN__BOXED,
1789 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1792 * GtkWidget::drag-leave:
1793 * @widget: the object which received the signal.
1794 * @drag_context: the drag context
1795 * @time: the timestamp of the motion event
1797 * The ::drag-leave signal is emitted on the drop site when the cursor
1798 * leaves the widget. A typical reason to connect to this signal is to
1799 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1800 * with gtk_drag_unhighlight()
1802 widget_signals[DRAG_LEAVE] =
1803 g_signal_new (I_("drag-leave"),
1804 G_TYPE_FROM_CLASS (gobject_class),
1806 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1808 _gtk_marshal_VOID__OBJECT_UINT,
1810 GDK_TYPE_DRAG_CONTEXT,
1814 * GtkWidget::drag-begin:
1815 * @widget: the object which received the signal
1816 * @drag_context: the drag context
1818 * The ::drag-begin signal is emitted on the drag source when a drag is
1819 * started. A typical reason to connect to this signal is to set up a
1820 * custom drag icon with gtk_drag_source_set_icon().
1822 * Note that some widgets set up a drag icon in the default handler of
1823 * this signal, so you may have to use g_signal_connect_after() to
1824 * override what the default handler did.
1826 widget_signals[DRAG_BEGIN] =
1827 g_signal_new (I_("drag-begin"),
1828 G_TYPE_FROM_CLASS (gobject_class),
1830 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1832 _gtk_marshal_VOID__OBJECT,
1834 GDK_TYPE_DRAG_CONTEXT);
1837 * GtkWidget::drag-end:
1838 * @widget: the object which received the signal
1839 * @drag_context: the drag context
1841 * The ::drag-end signal is emitted on the drag source when a drag is
1842 * finished. A typical reason to connect to this signal is to undo
1843 * things done in #GtkWidget::drag-begin.
1845 widget_signals[DRAG_END] =
1846 g_signal_new (I_("drag-end"),
1847 G_TYPE_FROM_CLASS (gobject_class),
1849 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1851 _gtk_marshal_VOID__OBJECT,
1853 GDK_TYPE_DRAG_CONTEXT);
1856 * GtkWidget::drag-data-delete:
1857 * @widget: the object which received the signal
1858 * @drag_context: the drag context
1860 * The ::drag-data-delete signal is emitted on the drag source when a drag
1861 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1862 * handler is responsible for deleting the data that has been dropped. What
1863 * "delete" means depends on the context of the drag operation.
1865 widget_signals[DRAG_DATA_DELETE] =
1866 g_signal_new (I_("drag-data-delete"),
1867 G_TYPE_FROM_CLASS (gobject_class),
1869 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1871 _gtk_marshal_VOID__OBJECT,
1873 GDK_TYPE_DRAG_CONTEXT);
1876 * GtkWidget::drag-failed:
1877 * @widget: the object which received the signal
1878 * @drag_context: the drag context
1879 * @result: the result of the drag operation
1881 * The ::drag-failed signal is emitted on the drag source when a drag has
1882 * failed. The signal handler may hook custom code to handle a failed DND
1883 * operation based on the type of error, it returns %TRUE is the failure has
1884 * been already handled (not showing the default "drag operation failed"
1885 * animation), otherwise it returns %FALSE.
1887 * Return value: %TRUE if the failed drag operation has been already handled.
1891 widget_signals[DRAG_FAILED] =
1892 g_signal_new (I_("drag-failed"),
1893 G_TYPE_FROM_CLASS (gobject_class),
1895 0, _gtk_boolean_handled_accumulator, NULL,
1896 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1898 GDK_TYPE_DRAG_CONTEXT,
1899 GTK_TYPE_DRAG_RESULT);
1902 * GtkWidget::drag-motion:
1903 * @widget: the object which received the signal
1904 * @drag_context: the drag context
1905 * @x: the x coordinate of the current cursor position
1906 * @y: the y coordinate of the current cursor position
1907 * @time: the timestamp of the motion event
1908 * @returns: whether the cursor position is in a drop zone
1910 * The drag-motion signal is emitted on the drop site when the user
1911 * moves the cursor over the widget during a drag. The signal handler
1912 * must determine whether the cursor position is in a drop zone or not.
1913 * If it is not in a drop zone, it returns %FALSE and no further processing
1914 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1915 * handler is responsible for providing the necessary information for
1916 * displaying feedback to the user, by calling gdk_drag_status().
1918 * If the decision whether the drop will be accepted or rejected can't be
1919 * made based solely on the cursor position and the type of the data, the
1920 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1921 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1922 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1923 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1924 * when using the drag-motion signal that way.
1926 * Also note that there is no drag-enter signal. The drag receiver has to
1927 * keep track of whether he has received any drag-motion signals since the
1928 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1929 * an "enter" signal. Upon an "enter", the handler will typically highlight
1930 * the drop site with gtk_drag_highlight().
1933 * drag_motion (GtkWidget *widget,
1934 * GdkDragContext *context,
1941 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1943 * if (!private_data->drag_highlight)
1945 * private_data->drag_highlight = 1;
1946 * gtk_drag_highlight (widget);
1949 * target = gtk_drag_dest_find_target (widget, context, NULL);
1950 * if (target == GDK_NONE)
1951 * gdk_drag_status (context, 0, time);
1954 * private_data->pending_status = context->suggested_action;
1955 * gtk_drag_get_data (widget, context, target, time);
1962 * drag_data_received (GtkWidget *widget,
1963 * GdkDragContext *context,
1966 * GtkSelectionData *selection_data,
1970 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1972 * if (private_data->suggested_action)
1974 * private_data->suggested_action = 0;
1976 * /* We are getting this data due to a request in drag_motion,
1977 * * rather than due to a request in drag_drop, so we are just
1978 * * supposed to call gdk_drag_status (), not actually paste in
1981 * str = gtk_selection_data_get_text (selection_data);
1982 * if (!data_is_acceptable (str))
1983 * gdk_drag_status (context, 0, time);
1985 * gdk_drag_status (context, private_data->suggested_action, time);
1989 * /* accept the drop */
1994 widget_signals[DRAG_MOTION] =
1995 g_signal_new (I_("drag-motion"),
1996 G_TYPE_FROM_CLASS (gobject_class),
1998 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1999 _gtk_boolean_handled_accumulator, NULL,
2000 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2002 GDK_TYPE_DRAG_CONTEXT,
2008 * GtkWidget::drag-drop:
2009 * @widget: the object which received the signal
2010 * @drag_context: the drag context
2011 * @x: the x coordinate of the current cursor position
2012 * @y: the y coordinate of the current cursor position
2013 * @time: the timestamp of the motion event
2014 * @returns: whether the cursor position is in a drop zone
2016 * The ::drag-drop signal is emitted on the drop site when the user drops
2017 * the data onto the widget. The signal handler must determine whether
2018 * the cursor position is in a drop zone or not. If it is not in a drop
2019 * zone, it returns %FALSE and no further processing is necessary.
2020 * Otherwise, the handler returns %TRUE. In this case, the handler must
2021 * ensure that gtk_drag_finish() is called to let the source know that
2022 * the drop is done. The call to gtk_drag_finish() can be done either
2023 * directly or in a #GtkWidget::drag-data-received handler which gets
2024 * triggered by calling gtk_drag_get_data() to receive the data for one
2025 * or more of the supported targets.
2027 widget_signals[DRAG_DROP] =
2028 g_signal_new (I_("drag-drop"),
2029 G_TYPE_FROM_CLASS (gobject_class),
2031 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2032 _gtk_boolean_handled_accumulator, NULL,
2033 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2035 GDK_TYPE_DRAG_CONTEXT,
2041 * GtkWidget::drag-data-get:
2042 * @widget: the object which received the signal
2043 * @drag_context: the drag context
2044 * @data: the #GtkSelectionData to be filled with the dragged data
2045 * @info: the info that has been registered with the target in the
2047 * @time: the timestamp at which the data was requested
2049 * The ::drag-data-get signal is emitted on the drag source when the drop
2050 * site requests the data which is dragged. It is the responsibility of
2051 * the signal handler to fill @data with the data in the format which
2052 * is indicated by @info. See gtk_selection_data_set() and
2053 * gtk_selection_data_set_text().
2055 widget_signals[DRAG_DATA_GET] =
2056 g_signal_new (I_("drag-data-get"),
2057 G_TYPE_FROM_CLASS (gobject_class),
2059 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2061 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2063 GDK_TYPE_DRAG_CONTEXT,
2064 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2069 * GtkWidget::drag-data-received:
2070 * @widget: the object which received the signal
2071 * @drag_context: the drag context
2072 * @x: where the drop happened
2073 * @y: where the drop happened
2074 * @data: the received data
2075 * @info: the info that has been registered with the target in the
2077 * @time: the timestamp at which the data was received
2079 * The ::drag-data-received signal is emitted on the drop site when the
2080 * dragged data has been received. If the data was received in order to
2081 * determine whether the drop will be accepted, the handler is expected
2082 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2083 * If the data was received in response to a #GtkWidget::drag-drop signal
2084 * (and this is the last target to be received), the handler for this
2085 * signal is expected to process the received data and then call
2086 * gtk_drag_finish(), setting the @success parameter depending on whether
2087 * the data was processed successfully.
2089 * The handler may inspect and modify @drag_context->action before calling
2090 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2091 * following example:
2094 * drag_data_received (GtkWidget *widget,
2095 * GdkDragContext *drag_context,
2098 * GtkSelectionData *data,
2102 * if ((data->length >= 0) && (data->format == 8))
2104 * if (drag_context->action == GDK_ACTION_ASK)
2106 * GtkWidget *dialog;
2109 * dialog = gtk_message_dialog_new (NULL,
2110 * GTK_DIALOG_MODAL |
2111 * GTK_DIALOG_DESTROY_WITH_PARENT,
2113 * GTK_BUTTONS_YES_NO,
2114 * "Move the data ?\n");
2115 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2116 * gtk_widget_destroy (dialog);
2118 * if (response == GTK_RESPONSE_YES)
2119 * drag_context->action = GDK_ACTION_MOVE;
2121 * drag_context->action = GDK_ACTION_COPY;
2124 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2128 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2132 widget_signals[DRAG_DATA_RECEIVED] =
2133 g_signal_new (I_("drag-data-received"),
2134 G_TYPE_FROM_CLASS (gobject_class),
2136 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2138 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2140 GDK_TYPE_DRAG_CONTEXT,
2143 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2148 * GtkWidget::visibility-notify-event:
2149 * @widget: the object which received the signal
2150 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2151 * triggered this signal.
2153 * The ::visibility-notify-event will be emitted when the @widget's window
2154 * is obscured or unobscured.
2156 * To receive this signal the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2159 * Returns: %TRUE to stop other handlers from being invoked for the event.
2160 * %FALSE to propagate the event further.
2162 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2163 g_signal_new (I_("visibility-notify-event"),
2164 G_TYPE_FROM_CLASS (gobject_class),
2166 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2167 _gtk_boolean_handled_accumulator, NULL,
2168 _gtk_marshal_BOOLEAN__BOXED,
2170 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2173 * GtkWidget::client-event:
2174 * @widget: the object which received the signal
2175 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2178 * The ::client-event will be emitted when the @widget's window
2179 * receives a message (via a ClientMessage event) from another
2182 * Returns: %TRUE to stop other handlers from being invoked for
2183 * the event. %FALSE to propagate the event further.
2185 widget_signals[CLIENT_EVENT] =
2186 g_signal_new (I_("client-event"),
2187 G_TYPE_FROM_CLASS (gobject_class),
2189 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2190 _gtk_boolean_handled_accumulator, NULL,
2191 _gtk_marshal_BOOLEAN__BOXED,
2193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2196 * GtkWidget::no-expose-event:
2197 * @widget: the object which received the signal
2198 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2201 * The ::no-expose-event will be emitted when the @widget's window is
2202 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable())
2203 * which was completely unobscured. If the source
2204 * window was partially obscured #GdkEventExpose events will be generated
2207 * Returns: %TRUE to stop other handlers from being invoked for the event.
2208 * %FALSE to propagate the event further.
2210 widget_signals[NO_EXPOSE_EVENT] =
2211 g_signal_new (I_("no-expose-event"),
2212 G_TYPE_FROM_CLASS (gobject_class),
2214 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2215 _gtk_boolean_handled_accumulator, NULL,
2216 _gtk_marshal_BOOLEAN__BOXED,
2218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 * GtkWidget::window-state-event:
2222 * @widget: the object which received the signal
2223 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2224 * triggered this signal.
2226 * The ::window-state-event will be emitted when the state of the
2227 * toplevel window associated to the @widget changes.
2229 * To receive this signal the #GdkWindow associated to the widget
2230 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2231 * this mask automatically for all new windows.
2233 * Returns: %TRUE to stop other handlers from being invoked for the
2234 * event. %FALSE to propagate the event further.
2236 widget_signals[WINDOW_STATE_EVENT] =
2237 g_signal_new (I_("window-state-event"),
2238 G_TYPE_FROM_CLASS (gobject_class),
2240 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2241 _gtk_boolean_handled_accumulator, NULL,
2242 _gtk_marshal_BOOLEAN__BOXED,
2244 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2247 * GtkWidget::damage-event:
2248 * @widget: the object which received the signal
2249 * @event: the #GdkEventExpose event
2251 * Emitted when a redirected window belonging to @widget gets drawn into.
2252 * The region/area members of the event shows what area of the redirected
2253 * drawable was drawn into.
2255 * Returns: %TRUE to stop other handlers from being invoked for the event.
2256 * %FALSE to propagate the event further.
2260 widget_signals[DAMAGE_EVENT] =
2261 g_signal_new (I_("damage-event"),
2262 G_TYPE_FROM_CLASS (gobject_class),
2265 _gtk_boolean_handled_accumulator, NULL,
2266 _gtk_marshal_BOOLEAN__BOXED,
2268 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2270 * GtkWidget::grab-broken-event:
2271 * @widget: the object which received the signal
2272 * @event: the #GdkEventGrabBroken event
2274 * Emitted when a pointer or keyboard grab on a window belonging
2275 * to @widget gets broken.
2277 * On X11, this happens when the grab window becomes unviewable
2278 * (i.e. it or one of its ancestors is unmapped), or if the same
2279 * application grabs the pointer or keyboard again.
2281 * Returns: %TRUE to stop other handlers from being invoked for
2282 * the event. %FALSE to propagate the event further.
2286 widget_signals[GRAB_BROKEN] =
2287 g_signal_new (I_("grab-broken-event"),
2288 G_TYPE_FROM_CLASS (gobject_class),
2290 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2291 _gtk_boolean_handled_accumulator, NULL,
2292 _gtk_marshal_BOOLEAN__BOXED,
2294 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2296 * GtkWidget::query-tooltip:
2297 * @widget: the object which received the signal
2298 * @x: the x coordinate of the cursor position where the request has
2299 * been emitted, relative to @widget->window
2300 * @y: the y coordinate of the cursor position where the request has
2301 * been emitted, relative to @widget->window
2302 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2303 * @tooltip: a #GtkTooltip
2305 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2306 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2307 * focus in keyboard mode.
2309 * Using the given coordinates, the signal handler should determine
2310 * whether a tooltip should be shown for @widget. If this is the case
2311 * %TRUE should be returned, %FALSE otherwise. Note that if
2312 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2313 * should not be used.
2315 * The signal handler is free to manipulate @tooltip with the therefore
2316 * destined function calls.
2318 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2322 widget_signals[QUERY_TOOLTIP] =
2323 g_signal_new (I_("query-tooltip"),
2324 G_TYPE_FROM_CLASS (gobject_class),
2326 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2327 _gtk_boolean_handled_accumulator, NULL,
2328 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2336 * GtkWidget::popup-menu
2337 * @widget: the object which received the signal
2339 * This signal gets emitted whenever a widget should pop up a context
2340 * menu. This usually happens through the standard key binding mechanism;
2341 * by pressing a certain key while a widget is focused, the user can cause
2342 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2343 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2344 * for an example of how to use this signal.
2346 * Returns: %TRUE if a menu was activated
2348 widget_signals[POPUP_MENU] =
2349 g_signal_new (I_("popup-menu"),
2350 G_TYPE_FROM_CLASS (gobject_class),
2351 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2352 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2353 _gtk_boolean_handled_accumulator, NULL,
2354 _gtk_marshal_BOOLEAN__VOID,
2358 * GtkWidget::show-help:
2359 * @widget: the object which received the signal.
2362 widget_signals[SHOW_HELP] =
2363 g_signal_new (I_("show-help"),
2364 G_TYPE_FROM_CLASS (gobject_class),
2365 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2366 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2367 _gtk_boolean_handled_accumulator, NULL,
2368 _gtk_marshal_BOOLEAN__ENUM,
2370 GTK_TYPE_WIDGET_HELP_TYPE);
2373 * GtkWidget::accel-closures-changed:
2374 * @widget: the object which received the signal.
2376 widget_signals[ACCEL_CLOSURES_CHANGED] =
2377 g_signal_new (I_("accel-closures-changed"),
2378 G_TYPE_FROM_CLASS (gobject_class),
2382 _gtk_marshal_VOID__VOID,
2386 * GtkWidget::screen-changed:
2387 * @widget: the object on which the signal is emitted
2388 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2389 * widget was not associated with a screen before
2391 * The ::screen-changed signal gets emitted when the
2392 * screen of a widget has changed.
2394 widget_signals[SCREEN_CHANGED] =
2395 g_signal_new (I_("screen-changed"),
2396 G_TYPE_FROM_CLASS (gobject_class),
2398 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2400 _gtk_marshal_VOID__OBJECT,
2405 * GtkWidget::can-activate-accel:
2406 * @widget: the object which received the signal
2407 * @signal_id: the ID of a signal installed on @widget
2409 * Determines whether an accelerator that activates the signal
2410 * identified by @signal_id can currently be activated.
2411 * This signal is present to allow applications and derived
2412 * widgets to override the default #GtkWidget handling
2413 * for determining whether an accelerator can be activated.
2415 * Returns: %TRUE if the signal can be activated.
2417 widget_signals[CAN_ACTIVATE_ACCEL] =
2418 g_signal_new (I_("can-activate-accel"),
2419 G_TYPE_FROM_CLASS (gobject_class),
2421 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2422 _gtk_boolean_handled_accumulator, NULL,
2423 _gtk_marshal_BOOLEAN__UINT,
2424 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2426 binding_set = gtk_binding_set_by_class (klass);
2427 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2429 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2432 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2434 GTK_TYPE_WIDGET_HELP_TYPE,
2435 GTK_WIDGET_HELP_TOOLTIP);
2436 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2438 GTK_TYPE_WIDGET_HELP_TYPE,
2439 GTK_WIDGET_HELP_TOOLTIP);
2440 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2442 GTK_TYPE_WIDGET_HELP_TYPE,
2443 GTK_WIDGET_HELP_WHATS_THIS);
2444 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2446 GTK_TYPE_WIDGET_HELP_TYPE,
2447 GTK_WIDGET_HELP_WHATS_THIS);
2449 gtk_widget_class_install_style_property (klass,
2450 g_param_spec_boolean ("interior-focus",
2451 P_("Interior Focus"),
2452 P_("Whether to draw the focus indicator inside widgets"),
2454 GTK_PARAM_READABLE));
2456 gtk_widget_class_install_style_property (klass,
2457 g_param_spec_int ("focus-line-width",
2458 P_("Focus linewidth"),
2459 P_("Width, in pixels, of the focus indicator line"),
2461 GTK_PARAM_READABLE));
2463 gtk_widget_class_install_style_property (klass,
2464 g_param_spec_string ("focus-line-pattern",
2465 P_("Focus line dash pattern"),
2466 P_("Dash pattern used to draw the focus indicator"),
2468 GTK_PARAM_READABLE));
2469 gtk_widget_class_install_style_property (klass,
2470 g_param_spec_int ("focus-padding",
2471 P_("Focus padding"),
2472 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2474 GTK_PARAM_READABLE));
2475 gtk_widget_class_install_style_property (klass,
2476 g_param_spec_boxed ("cursor-color",
2478 P_("Color with which to draw insertion cursor"),
2480 GTK_PARAM_READABLE));
2481 gtk_widget_class_install_style_property (klass,
2482 g_param_spec_boxed ("secondary-cursor-color",
2483 P_("Secondary cursor color"),
2484 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2486 GTK_PARAM_READABLE));
2487 gtk_widget_class_install_style_property (klass,
2488 g_param_spec_float ("cursor-aspect-ratio",
2489 P_("Cursor line aspect ratio"),
2490 P_("Aspect ratio with which to draw insertion cursor"),
2492 GTK_PARAM_READABLE));
2495 * GtkWidget:draw-border:
2497 * The "draw-border" style property defines the size of areas outside
2498 * the widget's allocation to draw.
2502 gtk_widget_class_install_style_property (klass,
2503 g_param_spec_boxed ("draw-border",
2505 P_("Size of areas outside the widget's allocation to draw"),
2507 GTK_PARAM_READABLE));
2510 * GtkWidget:link-color:
2512 * The "link-color" style property defines the color of unvisited links.
2516 gtk_widget_class_install_style_property (klass,
2517 g_param_spec_boxed ("link-color",
2518 P_("Unvisited Link Color"),
2519 P_("Color of unvisited links"),
2521 GTK_PARAM_READABLE));
2524 * GtkWidget:visited-link-color:
2526 * The "visited-link-color" style property defines the color of visited links.
2530 gtk_widget_class_install_style_property (klass,
2531 g_param_spec_boxed ("visited-link-color",
2532 P_("Visited Link Color"),
2533 P_("Color of visited links"),
2535 GTK_PARAM_READABLE));
2538 * GtkWidget:wide-separators:
2540 * The "wide-separators" style property defines whether separators have
2541 * configurable width and should be drawn using a box instead of a line.
2545 gtk_widget_class_install_style_property (klass,
2546 g_param_spec_boolean ("wide-separators",
2547 P_("Wide Separators"),
2548 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2550 GTK_PARAM_READABLE));
2553 * GtkWidget:separator-width:
2555 * The "separator-width" style property defines the width of separators.
2556 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2560 gtk_widget_class_install_style_property (klass,
2561 g_param_spec_int ("separator-width",
2562 P_("Separator Width"),
2563 P_("The width of separators if wide-separators is TRUE"),
2565 GTK_PARAM_READABLE));
2568 * GtkWidget:separator-height:
2570 * The "separator-height" style property defines the height of separators.
2571 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2575 gtk_widget_class_install_style_property (klass,
2576 g_param_spec_int ("separator-height",
2577 P_("Separator Height"),
2578 P_("The height of separators if \"wide-separators\" is TRUE"),
2580 GTK_PARAM_READABLE));
2583 * GtkWidget:scroll-arrow-hlength:
2585 * The "scroll-arrow-hlength" style property defines the length of
2586 * horizontal scroll arrows.
2590 gtk_widget_class_install_style_property (klass,
2591 g_param_spec_int ("scroll-arrow-hlength",
2592 P_("Horizontal Scroll Arrow Length"),
2593 P_("The length of horizontal scroll arrows"),
2595 GTK_PARAM_READABLE));
2598 * GtkWidget:scroll-arrow-vlength:
2600 * The "scroll-arrow-vlength" style property defines the length of
2601 * vertical scroll arrows.
2605 gtk_widget_class_install_style_property (klass,
2606 g_param_spec_int ("scroll-arrow-vlength",
2607 P_("Vertical Scroll Arrow Length"),
2608 P_("The length of vertical scroll arrows"),
2610 GTK_PARAM_READABLE));
2614 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2618 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2619 for (node = list; node; node = node->next)
2621 GParamSpec *pspec = node->data;
2623 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2624 g_param_spec_unref (pspec);
2630 gtk_widget_set_property (GObject *object,
2632 const GValue *value,
2635 GtkWidget *widget = GTK_WIDGET (object);
2640 gchar *tooltip_markup;
2641 const gchar *tooltip_text;
2642 GtkWindow *tooltip_window;
2645 gtk_widget_set_name (widget, g_value_get_string (value));
2648 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2650 case PROP_WIDTH_REQUEST:
2651 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2653 case PROP_HEIGHT_REQUEST:
2654 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2657 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2659 case PROP_SENSITIVE:
2660 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2662 case PROP_APP_PAINTABLE:
2663 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2665 case PROP_CAN_FOCUS:
2666 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2668 case PROP_HAS_FOCUS:
2669 if (g_value_get_boolean (value))
2670 gtk_widget_grab_focus (widget);
2673 if (g_value_get_boolean (value))
2674 gtk_widget_grab_focus (widget);
2676 case PROP_CAN_DEFAULT:
2677 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2679 case PROP_HAS_DEFAULT:
2680 if (g_value_get_boolean (value))
2681 gtk_widget_grab_default (widget);
2683 case PROP_RECEIVES_DEFAULT:
2684 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2687 gtk_widget_set_style (widget, g_value_get_object (value));
2690 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2691 gtk_widget_set_events (widget, g_value_get_flags (value));
2693 case PROP_EXTENSION_EVENTS:
2694 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2696 case PROP_NO_SHOW_ALL:
2697 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2699 case PROP_HAS_TOOLTIP:
2700 gtk_widget_real_set_has_tooltip (widget,
2701 g_value_get_boolean (value), FALSE);
2703 case PROP_TOOLTIP_MARKUP:
2704 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2705 tooltip_markup = g_value_dup_string (value);
2707 /* Treat an empty string as a NULL string,
2708 * because an empty string would be useless for a tooltip:
2710 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2712 g_free (tooltip_markup);
2713 tooltip_markup = NULL;
2716 g_object_set_qdata_full (object, quark_tooltip_markup,
2717 tooltip_markup, g_free);
2719 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2720 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2721 if (gtk_widget_get_visible (widget))
2722 gtk_widget_queue_tooltip_query (widget);
2724 case PROP_TOOLTIP_TEXT:
2725 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2727 tooltip_text = g_value_get_string (value);
2729 /* Treat an empty string as a NULL string,
2730 * because an empty string would be useless for a tooltip:
2732 if (tooltip_text && (strlen (tooltip_text) == 0))
2733 tooltip_text = NULL;
2735 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2737 g_object_set_qdata_full (object, quark_tooltip_markup,
2738 tooltip_markup, g_free);
2740 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2741 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2742 if (gtk_widget_get_visible (widget))
2743 gtk_widget_queue_tooltip_query (widget);
2745 case PROP_DOUBLE_BUFFERED:
2746 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2749 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2755 gtk_widget_get_property (GObject *object,
2760 GtkWidget *widget = GTK_WIDGET (object);
2769 g_value_set_string (value, widget->name);
2771 g_value_set_static_string (value, "");
2774 g_value_set_object (value, widget->parent);
2776 case PROP_WIDTH_REQUEST:
2779 gtk_widget_get_size_request (widget, &w, NULL);
2780 g_value_set_int (value, w);
2783 case PROP_HEIGHT_REQUEST:
2786 gtk_widget_get_size_request (widget, NULL, &h);
2787 g_value_set_int (value, h);
2791 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2793 case PROP_SENSITIVE:
2794 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2796 case PROP_APP_PAINTABLE:
2797 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2799 case PROP_CAN_FOCUS:
2800 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2802 case PROP_HAS_FOCUS:
2803 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2806 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2808 case PROP_CAN_DEFAULT:
2809 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2811 case PROP_HAS_DEFAULT:
2812 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2814 case PROP_RECEIVES_DEFAULT:
2815 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2817 case PROP_COMPOSITE_CHILD:
2818 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2821 g_value_set_object (value, gtk_widget_get_style (widget));
2824 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2825 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2827 case PROP_EXTENSION_EVENTS:
2828 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2829 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2831 case PROP_NO_SHOW_ALL:
2832 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2834 case PROP_HAS_TOOLTIP:
2835 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2837 case PROP_TOOLTIP_TEXT:
2839 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2842 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2843 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2845 g_value_take_string (value, text);
2848 case PROP_TOOLTIP_MARKUP:
2849 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2852 g_value_set_object (value, gtk_widget_get_window (widget));
2854 case PROP_DOUBLE_BUFFERED:
2855 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2858 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2864 gtk_widget_init (GtkWidget *widget)
2866 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2867 widget->state = GTK_STATE_NORMAL;
2868 widget->saved_state = GTK_STATE_NORMAL;
2869 widget->name = NULL;
2870 widget->requisition.width = 0;
2871 widget->requisition.height = 0;
2872 widget->allocation.x = -1;
2873 widget->allocation.y = -1;
2874 widget->allocation.width = 1;
2875 widget->allocation.height = 1;
2876 widget->window = NULL;
2877 widget->parent = NULL;
2879 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2880 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2881 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2882 gtk_widget_set_double_buffered (widget, TRUE);
2884 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2885 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2886 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
2887 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
2888 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2890 widget->style = gtk_widget_get_default_style ();
2891 g_object_ref (widget->style);
2896 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2898 GParamSpec **pspecs)
2900 GtkWidget *container = widget->parent;
2903 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2904 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2908 * gtk_widget_freeze_child_notify:
2909 * @widget: a #GtkWidget
2911 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2912 * signals are queued until gtk_widget_thaw_child_notify() is called
2915 * This is the analogue of g_object_freeze_notify() for child properties.
2918 gtk_widget_freeze_child_notify (GtkWidget *widget)
2920 g_return_if_fail (GTK_IS_WIDGET (widget));
2922 if (!G_OBJECT (widget)->ref_count)
2925 g_object_ref (widget);
2926 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2927 g_object_unref (widget);
2931 * gtk_widget_child_notify:
2932 * @widget: a #GtkWidget
2933 * @child_property: the name of a child property installed on the
2934 * class of @widget<!-- -->'s parent
2936 * Emits a #GtkWidget::child-notify signal for the
2937 * <link linkend="child-properties">child property</link> @child_property
2940 * This is the analogue of g_object_notify() for child properties.
2943 gtk_widget_child_notify (GtkWidget *widget,
2944 const gchar *child_property)
2948 g_return_if_fail (GTK_IS_WIDGET (widget));
2949 g_return_if_fail (child_property != NULL);
2950 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2953 g_object_ref (widget);
2954 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2956 G_OBJECT_TYPE (widget->parent),
2959 g_warning ("%s: container class `%s' has no child property named `%s'",
2961 G_OBJECT_TYPE_NAME (widget->parent),
2965 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2967 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2968 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2970 g_object_unref (widget);
2974 * gtk_widget_thaw_child_notify:
2975 * @widget: a #GtkWidget
2977 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2978 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2982 gtk_widget_thaw_child_notify (GtkWidget *widget)
2984 GObjectNotifyQueue *nqueue;
2986 g_return_if_fail (GTK_IS_WIDGET (widget));
2988 if (!G_OBJECT (widget)->ref_count)
2991 g_object_ref (widget);
2992 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2993 if (!nqueue || !nqueue->freeze_count)
2994 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2995 G_OBJECT_TYPE_NAME (widget), widget);
2997 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2998 g_object_unref (widget);
3004 * @type: type ID of the widget to create
3005 * @first_property_name: name of first property to set
3006 * @Varargs: value of first property, followed by more properties,
3009 * This is a convenience function for creating a widget and setting
3010 * its properties in one go. For example you might write:
3011 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3012 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3013 * g_object_new(), but returns a widget so you don't have to
3014 * cast the object yourself.
3016 * Return value: a new #GtkWidget of type @widget_type
3019 gtk_widget_new (GType type,
3020 const gchar *first_property_name,
3026 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3028 va_start (var_args, first_property_name);
3029 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3036 gtk_widget_queue_draw_child (GtkWidget *widget)
3040 parent = widget->parent;
3041 if (parent && gtk_widget_is_drawable (parent))
3042 gtk_widget_queue_draw_area (parent,
3043 widget->allocation.x,
3044 widget->allocation.y,
3045 widget->allocation.width,
3046 widget->allocation.height);
3050 * gtk_widget_unparent:
3051 * @widget: a #GtkWidget
3053 * This function is only for use in widget implementations.
3054 * Should be called by implementations of the remove method
3055 * on #GtkContainer, to dissociate a child from the container.
3058 gtk_widget_unparent (GtkWidget *widget)
3060 GObjectNotifyQueue *nqueue;
3061 GtkWidget *toplevel;
3062 GtkWidget *old_parent;
3064 g_return_if_fail (GTK_IS_WIDGET (widget));
3065 if (widget->parent == NULL)
3068 /* keep this function in sync with gtk_menu_detach()
3071 g_object_freeze_notify (G_OBJECT (widget));
3072 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3074 toplevel = gtk_widget_get_toplevel (widget);
3075 if (gtk_widget_is_toplevel (toplevel))
3076 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3078 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3079 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3081 /* If we are unanchoring the child, we save around the toplevel
3082 * to emit hierarchy changed
3084 if (GTK_WIDGET_ANCHORED (widget->parent))
3085 g_object_ref (toplevel);
3089 gtk_widget_queue_draw_child (widget);
3091 /* Reset the width and height here, to force reallocation if we
3092 * get added back to a new parent. This won't work if our new
3093 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3094 * (would 0x0 be OK here?)
3096 widget->allocation.width = 1;
3097 widget->allocation.height = 1;
3099 if (gtk_widget_get_realized (widget))
3101 if (GTK_WIDGET_IN_REPARENT (widget))
3102 gtk_widget_unmap (widget);
3104 gtk_widget_unrealize (widget);
3107 /* Removing a widget from a container restores the child visible
3108 * flag to the default state, so it doesn't affect the child
3109 * in the next parent.
3111 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3113 old_parent = widget->parent;
3114 widget->parent = NULL;
3115 gtk_widget_set_parent_window (widget, NULL);
3116 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3119 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3120 g_object_unref (toplevel);
3123 g_object_notify (G_OBJECT (widget), "parent");
3124 g_object_thaw_notify (G_OBJECT (widget));
3125 if (!widget->parent)
3126 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3127 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3128 g_object_unref (widget);
3132 * gtk_widget_destroy:
3133 * @widget: a #GtkWidget
3135 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3136 * you don't have to cast the widget to #GtkObject. When a widget is
3137 * destroyed, it will break any references it holds to other objects.
3138 * If the widget is inside a container, the widget will be removed
3139 * from the container. If the widget is a toplevel (derived from
3140 * #GtkWindow), it will be removed from the list of toplevels, and the
3141 * reference GTK+ holds to it will be removed. Removing a
3142 * widget from its container or the list of toplevels results in the
3143 * widget being finalized, unless you've added additional references
3144 * to the widget with g_object_ref().
3146 * In most cases, only toplevel widgets (windows) require explicit
3147 * destruction, because when you destroy a toplevel its children will
3148 * be destroyed as well.
3151 gtk_widget_destroy (GtkWidget *widget)
3153 g_return_if_fail (GTK_IS_WIDGET (widget));
3155 gtk_object_destroy ((GtkObject*) widget);
3159 * gtk_widget_destroyed:
3160 * @widget: a #GtkWidget
3161 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3163 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3164 * %NULL. It's intended to be used as a callback connected to the
3165 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3166 * as a signal handler, and pass the address of your widget variable
3167 * as user data. Then when the widget is destroyed, the variable will
3168 * be set to %NULL. Useful for example to avoid multiple copies
3169 * of the same dialog.
3172 gtk_widget_destroyed (GtkWidget *widget,
3173 GtkWidget **widget_pointer)
3175 /* Don't make any assumptions about the
3177 * Even check widget_pointer.
3180 *widget_pointer = NULL;
3185 * @widget: a #GtkWidget
3187 * Flags a widget to be displayed. Any widget that isn't shown will
3188 * not appear on the screen. If you want to show all the widgets in a
3189 * container, it's easier to call gtk_widget_show_all() on the
3190 * container, instead of individually showing the widgets.
3192 * Remember that you have to show the containers containing a widget,
3193 * in addition to the widget itself, before it will appear onscreen.
3195 * When a toplevel container is shown, it is immediately realized and
3196 * mapped; other shown widgets are realized and mapped when their
3197 * toplevel container is realized and mapped.
3200 gtk_widget_show (GtkWidget *widget)
3202 g_return_if_fail (GTK_IS_WIDGET (widget));
3204 if (!gtk_widget_get_visible (widget))
3206 g_object_ref (widget);
3207 if (!gtk_widget_is_toplevel (widget))
3208 gtk_widget_queue_resize (widget);
3209 g_signal_emit (widget, widget_signals[SHOW], 0);
3210 g_object_notify (G_OBJECT (widget), "visible");
3211 g_object_unref (widget);
3216 gtk_widget_real_show (GtkWidget *widget)
3218 if (!gtk_widget_get_visible (widget))
3220 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3222 if (widget->parent &&
3223 gtk_widget_get_mapped (widget->parent) &&
3224 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3225 !gtk_widget_get_mapped (widget))
3226 gtk_widget_map (widget);
3231 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3234 g_signal_handlers_disconnect_by_func (widget,
3235 gtk_widget_show_map_callback,
3240 * gtk_widget_show_now:
3241 * @widget: a #GtkWidget
3243 * Shows a widget. If the widget is an unmapped toplevel widget
3244 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3245 * loop and wait for the window to actually be mapped. Be careful;
3246 * because the main loop is running, anything can happen during
3250 gtk_widget_show_now (GtkWidget *widget)
3254 g_return_if_fail (GTK_IS_WIDGET (widget));
3256 /* make sure we will get event */
3257 if (!gtk_widget_get_mapped (widget) &&
3258 gtk_widget_is_toplevel (widget))
3260 gtk_widget_show (widget);
3262 g_signal_connect (widget, "map-event",
3263 G_CALLBACK (gtk_widget_show_map_callback),
3267 gtk_main_iteration ();
3270 gtk_widget_show (widget);
3275 * @widget: a #GtkWidget
3277 * Reverses the effects of gtk_widget_show(), causing the widget to be
3278 * hidden (invisible to the user).
3281 gtk_widget_hide (GtkWidget *widget)
3283 g_return_if_fail (GTK_IS_WIDGET (widget));
3285 if (gtk_widget_get_visible (widget))
3287 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3289 g_object_ref (widget);
3290 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3291 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3293 g_signal_emit (widget, widget_signals[HIDE], 0);
3294 if (!gtk_widget_is_toplevel (widget))
3295 gtk_widget_queue_resize (widget);
3296 g_object_notify (G_OBJECT (widget), "visible");
3297 g_object_unref (widget);
3302 gtk_widget_real_hide (GtkWidget *widget)
3304 if (gtk_widget_get_visible (widget))
3306 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3308 if (gtk_widget_get_mapped (widget))
3309 gtk_widget_unmap (widget);
3314 * gtk_widget_hide_on_delete:
3315 * @widget: a #GtkWidget
3317 * Utility function; intended to be connected to the #GtkWidget::delete-event
3318 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3319 * argument, then returns %TRUE. If connected to ::delete-event, the
3320 * result is that clicking the close button for a window (on the
3321 * window frame, top right corner usually) will hide but not destroy
3322 * the window. By default, GTK+ destroys windows when ::delete-event
3325 * Return value: %TRUE
3328 gtk_widget_hide_on_delete (GtkWidget *widget)
3330 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3332 gtk_widget_hide (widget);
3338 * gtk_widget_show_all:
3339 * @widget: a #GtkWidget
3341 * Recursively shows a widget, and any child widgets (if the widget is
3345 gtk_widget_show_all (GtkWidget *widget)
3347 GtkWidgetClass *class;
3349 g_return_if_fail (GTK_IS_WIDGET (widget));
3351 if (gtk_widget_get_no_show_all (widget))
3354 class = GTK_WIDGET_GET_CLASS (widget);
3356 if (class->show_all)
3357 class->show_all (widget);
3361 * gtk_widget_hide_all:
3362 * @widget: a #GtkWidget
3364 * Recursively hides a widget and any child widgets.
3367 gtk_widget_hide_all (GtkWidget *widget)
3369 GtkWidgetClass *class;
3371 g_return_if_fail (GTK_IS_WIDGET (widget));
3373 if (gtk_widget_get_no_show_all (widget))
3376 class = GTK_WIDGET_GET_CLASS (widget);
3378 if (class->hide_all)
3379 class->hide_all (widget);
3384 * @widget: a #GtkWidget
3386 * This function is only for use in widget implementations. Causes
3387 * a widget to be mapped if it isn't already.
3390 gtk_widget_map (GtkWidget *widget)
3392 g_return_if_fail (GTK_IS_WIDGET (widget));
3393 g_return_if_fail (gtk_widget_get_visible (widget));
3394 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3396 if (!gtk_widget_get_mapped (widget))
3398 if (!gtk_widget_get_realized (widget))
3399 gtk_widget_realize (widget);
3401 g_signal_emit (widget, widget_signals[MAP], 0);
3403 if (!gtk_widget_get_has_window (widget))
3404 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3410 * @widget: a #GtkWidget
3412 * This function is only for use in widget implementations. Causes
3413 * a widget to be unmapped if it's currently mapped.
3416 gtk_widget_unmap (GtkWidget *widget)
3418 g_return_if_fail (GTK_IS_WIDGET (widget));
3420 if (gtk_widget_get_mapped (widget))
3422 if (!gtk_widget_get_has_window (widget))
3423 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3424 _gtk_tooltip_hide (widget);
3425 g_signal_emit (widget, widget_signals[UNMAP], 0);
3430 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3431 GdkExtensionMode mode,
3434 GList *free_list = NULL;
3437 if (window_list == NULL)
3439 if (gtk_widget_get_has_window (widget))
3440 window_list = g_list_prepend (NULL, widget->window);
3442 window_list = gdk_window_get_children (widget->window);
3444 free_list = window_list;
3447 for (l = window_list; l != NULL; l = l->next)
3449 GdkWindow *window = l->data;
3452 gdk_window_get_user_data (window, &user_data);
3453 if (user_data == widget)
3457 gdk_input_set_extension_events (window,
3458 gdk_window_get_events (window),
3461 children = gdk_window_get_children (window);
3464 gtk_widget_set_extension_events_internal (widget, mode, children);
3465 g_list_free (children);
3471 g_list_free (free_list);
3475 _gtk_widget_enable_device_events (GtkWidget *widget)
3477 GHashTable *device_events;
3478 GHashTableIter iter;
3479 gpointer key, value;
3481 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3486 g_hash_table_iter_init (&iter, device_events);
3488 while (g_hash_table_iter_next (&iter, &key, &value))
3491 GdkEventMask event_mask;
3494 event_mask = GPOINTER_TO_UINT (value);
3495 gtk_widget_add_events_internal (widget, device, event_mask);
3500 * gtk_widget_realize:
3501 * @widget: a #GtkWidget
3503 * Creates the GDK (windowing system) resources associated with a
3504 * widget. For example, @widget->window will be created when a widget
3505 * is realized. Normally realization happens implicitly; if you show
3506 * a widget and all its parent containers, then the widget will be
3507 * realized and mapped automatically.
3509 * Realizing a widget requires all
3510 * the widget's parent widgets to be realized; calling
3511 * gtk_widget_realize() realizes the widget's parents in addition to
3512 * @widget itself. If a widget is not yet inside a toplevel window
3513 * when you realize it, bad things will happen.
3515 * This function is primarily used in widget implementations, and
3516 * isn't very useful otherwise. Many times when you think you might
3517 * need it, a better approach is to connect to a signal that will be
3518 * called after the widget is realized automatically, such as
3519 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3520 * GtkWidget::realize signal.
3523 gtk_widget_realize (GtkWidget *widget)
3525 GdkExtensionMode mode;
3526 GtkWidgetShapeInfo *shape_info;
3528 g_return_if_fail (GTK_IS_WIDGET (widget));
3529 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3530 GTK_IS_INVISIBLE (widget));
3532 if (!gtk_widget_get_realized (widget))
3535 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3536 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3539 if (widget->parent == NULL &&
3540 !gtk_widget_is_toplevel (widget))
3541 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3542 "inside a toplevel window is not going to work very well. "
3543 "Widgets must be inside a toplevel container before realizing them.");
3545 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3546 gtk_widget_realize (widget->parent);
3548 gtk_widget_ensure_style (widget);
3550 g_signal_emit (widget, widget_signals[REALIZE], 0);
3552 gtk_widget_real_set_has_tooltip (widget,
3553 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3556 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3558 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3559 gdk_window_shape_combine_mask (widget->window,
3560 shape_info->shape_mask,
3561 shape_info->offset_x,
3562 shape_info->offset_y);
3565 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3567 gdk_window_input_shape_combine_mask (widget->window,
3568 shape_info->shape_mask,
3569 shape_info->offset_x,
3570 shape_info->offset_y);
3572 mode = gtk_widget_get_extension_events (widget);
3573 if (mode != GDK_EXTENSION_EVENTS_NONE)
3574 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3576 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3577 gdk_window_set_support_multidevice (widget->window, TRUE);
3579 _gtk_widget_enable_device_events (widget);
3584 * gtk_widget_unrealize:
3585 * @widget: a #GtkWidget
3587 * This function is only useful in widget implementations.
3588 * Causes a widget to be unrealized (frees all GDK resources
3589 * associated with the widget, such as @widget->window).
3592 gtk_widget_unrealize (GtkWidget *widget)
3594 g_return_if_fail (GTK_IS_WIDGET (widget));
3596 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3597 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3599 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3600 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3602 if (gtk_widget_get_realized (widget))
3604 g_object_ref (widget);
3605 _gtk_tooltip_hide (widget);
3606 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3607 gtk_widget_set_realized (widget, FALSE);
3608 gtk_widget_set_mapped (widget, FALSE);
3609 g_object_unref (widget);
3613 /*****************************************
3615 *****************************************/
3618 * gtk_widget_queue_draw_area:
3619 * @widget: a #GtkWidget
3620 * @x: x coordinate of upper-left corner of rectangle to redraw
3621 * @y: y coordinate of upper-left corner of rectangle to redraw
3622 * @width: width of region to draw
3623 * @height: height of region to draw
3625 * Invalidates the rectangular area of @widget defined by @x, @y,
3626 * @width and @height by calling gdk_window_invalidate_rect() on the
3627 * widget's window and all its child windows. Once the main loop
3628 * becomes idle (after the current batch of events has been processed,
3629 * roughly), the window will receive expose events for the union of
3630 * all regions that have been invalidated.
3632 * Normally you would only use this function in widget
3633 * implementations. You might also use it, or
3634 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3635 * #GtkDrawingArea or some portion thereof.
3637 * Frequently you can just call gdk_window_invalidate_rect() or
3638 * gdk_window_invalidate_region() instead of this function. Those
3639 * functions will invalidate only a single window, instead of the
3640 * widget and all its children.
3642 * The advantage of adding to the invalidated region compared to
3643 * simply drawing immediately is efficiency; using an invalid region
3644 * ensures that you only have to redraw one time.
3647 gtk_widget_queue_draw_area (GtkWidget *widget,
3653 GdkRectangle invalid_rect;
3656 g_return_if_fail (GTK_IS_WIDGET (widget));
3658 if (!gtk_widget_get_realized (widget))
3661 /* Just return if the widget or one of its ancestors isn't mapped */
3662 for (w = widget; w != NULL; w = w->parent)
3663 if (!gtk_widget_get_mapped (w))
3666 /* Find the correct widget */
3668 if (gtk_widget_get_has_window (widget))
3672 /* Translate widget relative to window-relative */
3674 gint wx, wy, wwidth, wheight;
3676 gdk_window_get_position (widget->window, &wx, &wy);
3677 x -= wx - widget->allocation.x;
3678 y -= wy - widget->allocation.y;
3680 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3682 if (x + width <= 0 || y + height <= 0 ||
3683 x >= wwidth || y >= wheight)
3694 if (x + width > wwidth)
3696 if (y + height > wheight)
3697 height = wheight - y;
3703 invalid_rect.width = width;
3704 invalid_rect.height = height;
3706 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3710 widget_add_child_draw_rectangle (GtkWidget *widget,
3713 GdkRectangle child_rect;
3715 if (!gtk_widget_get_mapped (widget) ||
3716 widget->window != widget->parent->window)
3719 gtk_widget_get_draw_rectangle (widget, &child_rect);
3720 gdk_rectangle_union (rect, &child_rect, rect);
3724 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3727 if (!gtk_widget_get_has_window (widget))
3729 GtkBorder *draw_border = NULL;
3731 *rect = widget->allocation;
3733 gtk_widget_style_get (widget,
3734 "draw-border", &draw_border,
3738 rect->x -= draw_border->left;
3739 rect->y -= draw_border->top;
3740 rect->width += draw_border->left + draw_border->right;
3741 rect->height += draw_border->top + draw_border->bottom;
3743 gtk_border_free (draw_border);
3746 if (GTK_IS_CONTAINER (widget))
3747 gtk_container_forall (GTK_CONTAINER (widget),
3748 (GtkCallback)widget_add_child_draw_rectangle,
3755 rect->width = widget->allocation.width;
3756 rect->height = widget->allocation.height;
3761 * gtk_widget_queue_draw:
3762 * @widget: a #GtkWidget
3764 * Equivalent to calling gtk_widget_queue_draw_area() for the
3765 * entire area of a widget.
3768 gtk_widget_queue_draw (GtkWidget *widget)
3772 g_return_if_fail (GTK_IS_WIDGET (widget));
3774 gtk_widget_get_draw_rectangle (widget, &rect);
3776 gtk_widget_queue_draw_area (widget,
3778 rect.width, rect.height);
3782 * gtk_widget_queue_resize:
3783 * @widget: a #GtkWidget
3785 * This function is only for use in widget implementations.
3786 * Flags a widget to have its size renegotiated; should
3787 * be called when a widget for some reason has a new size request.
3788 * For example, when you change the text in a #GtkLabel, #GtkLabel
3789 * queues a resize to ensure there's enough space for the new text.
3792 gtk_widget_queue_resize (GtkWidget *widget)
3794 g_return_if_fail (GTK_IS_WIDGET (widget));
3796 if (gtk_widget_get_realized (widget))
3797 gtk_widget_queue_shallow_draw (widget);
3799 _gtk_size_group_queue_resize (widget);
3803 * gtk_widget_queue_resize_no_redraw:
3804 * @widget: a #GtkWidget
3806 * This function works like gtk_widget_queue_resize(),
3807 * except that the widget is not invalidated.
3812 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3814 g_return_if_fail (GTK_IS_WIDGET (widget));
3816 _gtk_size_group_queue_resize (widget);
3820 * gtk_widget_size_request:
3821 * @widget: a #GtkWidget
3822 * @requisition: (out): a #GtkRequisition to be filled in
3824 * This function is typically used when implementing a #GtkContainer
3825 * subclass. Obtains the preferred size of a widget. The container
3826 * uses this information to arrange its child widgets and decide what
3827 * size allocations to give them with gtk_widget_size_allocate().
3829 * You can also call this function from an application, with some
3830 * caveats. Most notably, getting a size request requires the widget
3831 * to be associated with a screen, because font information may be
3832 * needed. Multihead-aware applications should keep this in mind.
3834 * Also remember that the size request is not necessarily the size
3835 * a widget will actually be allocated.
3837 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
3840 gtk_widget_size_request (GtkWidget *widget,
3841 GtkRequisition *requisition)
3843 g_return_if_fail (GTK_IS_WIDGET (widget));
3845 #ifdef G_ENABLE_DEBUG
3846 if (requisition == &widget->requisition)
3847 g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
3848 "to widget->requisition. gtk_widget_set_usize() may not work properly.");
3849 #endif /* G_ENABLE_DEBUG */
3851 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
3855 * gtk_widget_get_child_requisition:
3856 * @widget: a #GtkWidget
3857 * @requisition: (out): a #GtkRequisition to be filled in
3859 * This function is only for use in widget implementations. Obtains
3860 * @widget->requisition, unless someone has forced a particular
3861 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3862 * in which case it returns that geometry instead of the widget's
3865 * This function differs from gtk_widget_size_request() in that
3866 * it retrieves the last size request value from @widget->requisition,
3867 * while gtk_widget_size_request() actually calls the "size_request" method
3868 * on @widget to compute the size request and fill in @widget->requisition,
3869 * and only then returns @widget->requisition.
3871 * Because this function does not call the "size_request" method, it
3872 * can only be used when you know that @widget->requisition is
3873 * up-to-date, that is, gtk_widget_size_request() has been called
3874 * since the last time a resize was queued. In general, only container
3875 * implementations have this information; applications should use
3876 * gtk_widget_size_request().
3879 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
3882 gtk_widget_get_child_requisition (GtkWidget *widget,
3883 GtkRequisition *requisition)
3885 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
3889 invalidate_predicate (GdkWindow *window,
3894 gdk_window_get_user_data (window, &user_data);
3896 return (user_data == data);
3899 /* Invalidate @region in widget->window and all children
3900 * of widget->window owned by widget. @region is in the
3901 * same coordinates as widget->allocation and will be
3902 * modified by this call.
3905 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3906 cairo_region_t *region)
3908 if (!gtk_widget_get_realized (widget))
3911 if (gtk_widget_get_has_window (widget) && widget->parent)
3915 gdk_window_get_position (widget->window, &x, &y);
3916 cairo_region_translate (region, -x, -y);
3919 gdk_window_invalidate_maybe_recurse (widget->window, region,
3920 invalidate_predicate, widget);
3924 * gtk_widget_queue_shallow_draw:
3925 * @widget: a #GtkWidget
3927 * Like gtk_widget_queue_draw(), but only windows owned
3928 * by @widget are invalidated.
3931 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3934 cairo_region_t *region;
3936 if (!gtk_widget_get_realized (widget))
3939 gtk_widget_get_draw_rectangle (widget, &rect);
3941 /* get_draw_rectangle() gives us window coordinates, we
3942 * need to convert to the coordinates that widget->allocation
3945 if (gtk_widget_get_has_window (widget) && widget->parent)
3949 gdk_window_get_position (widget->window, &wx, &wy);
3955 region = cairo_region_create_rectangle (&rect);
3956 gtk_widget_invalidate_widget_windows (widget, region);
3957 cairo_region_destroy (region);
3961 * gtk_widget_size_allocate:
3962 * @widget: a #GtkWidget
3963 * @allocation: (inout): position and size to be allocated to @widget
3965 * This function is only used by #GtkContainer subclasses, to assign a size
3966 * and position to their child widgets.
3969 gtk_widget_size_allocate (GtkWidget *widget,
3970 GtkAllocation *allocation)
3972 GtkWidgetAuxInfo *aux_info;
3973 GdkRectangle real_allocation;
3974 GdkRectangle old_allocation;
3975 gboolean alloc_needed;
3976 gboolean size_changed;
3977 gboolean position_changed;
3979 g_return_if_fail (GTK_IS_WIDGET (widget));
3981 #ifdef G_ENABLE_DEBUG
3982 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3993 parent = gtk_widget_get_parent (parent);
3996 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3997 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3998 2 * depth, " ", name,
3999 allocation->width, allocation->height);
4001 #endif /* G_ENABLE_DEBUG */
4003 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4004 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4005 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4007 old_allocation = widget->allocation;
4008 real_allocation = *allocation;
4009 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4013 if (aux_info->x_set)
4014 real_allocation.x = aux_info->x;
4015 if (aux_info->y_set)
4016 real_allocation.y = aux_info->y;
4019 if (real_allocation.width < 0 || real_allocation.height < 0)
4021 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4022 real_allocation.width,
4023 real_allocation.height);
4026 real_allocation.width = MAX (real_allocation.width, 1);
4027 real_allocation.height = MAX (real_allocation.height, 1);
4029 size_changed = (old_allocation.width != real_allocation.width ||
4030 old_allocation.height != real_allocation.height);
4031 position_changed = (old_allocation.x != real_allocation.x ||
4032 old_allocation.y != real_allocation.y);
4034 if (!alloc_needed && !size_changed && !position_changed)
4037 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4039 if (gtk_widget_get_mapped (widget))
4041 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4043 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4045 cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->allocation);
4046 cairo_region_union_rectangle (invalidate, &old_allocation);
4048 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4049 cairo_region_destroy (invalidate);
4054 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4056 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4058 cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->allocation);
4059 cairo_region_union_rectangle (invalidate, &old_allocation);
4061 gtk_widget_invalidate_widget_windows (widget, invalidate);
4062 cairo_region_destroy (invalidate);
4067 if ((size_changed || position_changed) && widget->parent &&
4068 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4070 cairo_region_t *invalidate = cairo_region_create_rectangle (&widget->parent->allocation);
4071 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4072 cairo_region_destroy (invalidate);
4077 * gtk_widget_common_ancestor:
4078 * @widget_a: a #GtkWidget
4079 * @widget_b: a #GtkWidget
4081 * Find the common ancestor of @widget_a and @widget_b that
4082 * is closest to the two widgets.
4084 * Return value: the closest common ancestor of @widget_a and
4085 * @widget_b or %NULL if @widget_a and @widget_b do not
4086 * share a common ancestor.
4089 gtk_widget_common_ancestor (GtkWidget *widget_a,
4090 GtkWidget *widget_b)
4092 GtkWidget *parent_a;
4093 GtkWidget *parent_b;
4097 parent_a = widget_a;
4098 while (parent_a->parent)
4100 parent_a = parent_a->parent;
4104 parent_b = widget_b;
4105 while (parent_b->parent)
4107 parent_b = parent_b->parent;
4111 if (parent_a != parent_b)
4114 while (depth_a > depth_b)
4116 widget_a = widget_a->parent;
4120 while (depth_b > depth_a)
4122 widget_b = widget_b->parent;
4126 while (widget_a != widget_b)
4128 widget_a = widget_a->parent;
4129 widget_b = widget_b->parent;
4136 * gtk_widget_translate_coordinates:
4137 * @src_widget: a #GtkWidget
4138 * @dest_widget: a #GtkWidget
4139 * @src_x: X position relative to @src_widget
4140 * @src_y: Y position relative to @src_widget
4141 * @dest_x: (out): location to store X position relative to @dest_widget
4142 * @dest_y: (out): location to store Y position relative to @dest_widget
4144 * Translate coordinates relative to @src_widget's allocation to coordinates
4145 * relative to @dest_widget's allocations. In order to perform this
4146 * operation, both widgets must be realized, and must share a common
4149 * Return value: %FALSE if either widget was not realized, or there
4150 * was no common ancestor. In this case, nothing is stored in
4151 * *@dest_x and *@dest_y. Otherwise %TRUE.
4154 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4155 GtkWidget *dest_widget,
4161 GtkWidget *ancestor;
4163 GList *dest_list = NULL;
4165 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4166 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4168 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4169 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4172 /* Translate from allocation relative to window relative */
4173 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4176 gdk_window_get_position (src_widget->window, &wx, &wy);
4178 src_x -= wx - src_widget->allocation.x;
4179 src_y -= wy - src_widget->allocation.y;
4183 src_x += src_widget->allocation.x;
4184 src_y += src_widget->allocation.y;
4187 /* Translate to the common ancestor */
4188 window = src_widget->window;
4189 while (window != ancestor->window)
4193 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4198 window = gdk_window_get_effective_parent (window);
4200 if (!window) /* Handle GtkHandleBox */
4205 window = dest_widget->window;
4206 while (window != ancestor->window)
4208 dest_list = g_list_prepend (dest_list, window);
4210 window = gdk_window_get_effective_parent (window);
4212 if (!window) /* Handle GtkHandleBox */
4214 g_list_free (dest_list);
4223 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4228 dest_list = g_list_remove (dest_list, dest_list->data);
4231 /* Translate from window relative to allocation relative */
4232 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4235 gdk_window_get_position (dest_widget->window, &wx, &wy);
4237 src_x += wx - dest_widget->allocation.x;
4238 src_y += wy - dest_widget->allocation.y;
4242 src_x -= dest_widget->allocation.x;
4243 src_y -= dest_widget->allocation.y;
4255 gtk_widget_real_size_allocate (GtkWidget *widget,
4256 GtkAllocation *allocation)
4258 widget->allocation = *allocation;
4260 if (gtk_widget_get_realized (widget) &&
4261 gtk_widget_get_has_window (widget))
4263 gdk_window_move_resize (widget->window,
4264 allocation->x, allocation->y,
4265 allocation->width, allocation->height);
4270 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4273 /* widgets must be onscreen for accels to take effect */
4274 return gtk_widget_is_sensitive (widget) &&
4275 gtk_widget_is_drawable (widget) &&
4276 gdk_window_is_viewable (widget->window);
4280 * gtk_widget_can_activate_accel:
4281 * @widget: a #GtkWidget
4282 * @signal_id: the ID of a signal installed on @widget
4284 * Determines whether an accelerator that activates the signal
4285 * identified by @signal_id can currently be activated.
4286 * This is done by emitting the #GtkWidget::can-activate-accel
4287 * signal on @widget; if the signal isn't overridden by a
4288 * handler or in a derived widget, then the default check is
4289 * that the widget must be sensitive, and the widget and all
4290 * its ancestors mapped.
4292 * Return value: %TRUE if the accelerator can be activated.
4297 gtk_widget_can_activate_accel (GtkWidget *widget,
4300 gboolean can_activate = FALSE;
4301 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4302 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4303 return can_activate;
4312 closure_accel_activate (GClosure *closure,
4313 GValue *return_value,
4314 guint n_param_values,
4315 const GValue *param_values,
4316 gpointer invocation_hint,
4317 gpointer marshal_data)
4319 AccelClosure *aclosure = (AccelClosure*) closure;
4320 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4323 g_signal_emit (closure->data, aclosure->signal_id, 0);
4325 /* whether accelerator was handled */
4326 g_value_set_boolean (return_value, can_activate);
4330 closures_destroy (gpointer data)
4332 GSList *slist, *closures = data;
4334 for (slist = closures; slist; slist = slist->next)
4336 g_closure_invalidate (slist->data);
4337 g_closure_unref (slist->data);
4339 g_slist_free (closures);
4343 widget_new_accel_closure (GtkWidget *widget,
4346 AccelClosure *aclosure;
4347 GClosure *closure = NULL;
4348 GSList *slist, *closures;
4350 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4351 for (slist = closures; slist; slist = slist->next)
4352 if (!gtk_accel_group_from_accel_closure (slist->data))
4354 /* reuse this closure */
4355 closure = slist->data;
4360 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4361 closures = g_slist_prepend (closures, g_closure_ref (closure));
4362 g_closure_sink (closure);
4363 g_closure_set_marshal (closure, closure_accel_activate);
4365 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4367 aclosure = (AccelClosure*) closure;
4368 g_assert (closure->data == widget);
4369 g_assert (closure->marshal == closure_accel_activate);
4370 aclosure->signal_id = signal_id;
4376 * gtk_widget_add_accelerator
4377 * @widget: widget to install an accelerator on
4378 * @accel_signal: widget signal to emit on accelerator activation
4379 * @accel_group: accel group for this widget, added to its toplevel
4380 * @accel_key: GDK keyval of the accelerator
4381 * @accel_mods: modifier key combination of the accelerator
4382 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4384 * Installs an accelerator for this @widget in @accel_group that causes
4385 * @accel_signal to be emitted if the accelerator is activated.
4386 * The @accel_group needs to be added to the widget's toplevel via
4387 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4388 * Accelerators added through this function are not user changeable during
4389 * runtime. If you want to support accelerators that can be changed by the
4390 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4391 * gtk_menu_item_set_accel_path() instead.
4394 gtk_widget_add_accelerator (GtkWidget *widget,
4395 const gchar *accel_signal,
4396 GtkAccelGroup *accel_group,
4398 GdkModifierType accel_mods,
4399 GtkAccelFlags accel_flags)
4404 g_return_if_fail (GTK_IS_WIDGET (widget));
4405 g_return_if_fail (accel_signal != NULL);
4406 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4408 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4409 if (!query.signal_id ||
4410 !(query.signal_flags & G_SIGNAL_ACTION) ||
4411 query.return_type != G_TYPE_NONE ||
4414 /* hmm, should be elaborate enough */
4415 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4416 G_OBJECT_TYPE_NAME (widget), accel_signal);
4420 closure = widget_new_accel_closure (widget, query.signal_id);
4422 g_object_ref (widget);
4424 /* install the accelerator. since we don't map this onto an accel_path,
4425 * the accelerator will automatically be locked.
4427 gtk_accel_group_connect (accel_group,
4430 accel_flags | GTK_ACCEL_LOCKED,
4433 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4435 g_object_unref (widget);
4439 * gtk_widget_remove_accelerator:
4440 * @widget: widget to install an accelerator on
4441 * @accel_group: accel group for this widget
4442 * @accel_key: GDK keyval of the accelerator
4443 * @accel_mods: modifier key combination of the accelerator
4444 * @returns: whether an accelerator was installed and could be removed
4446 * Removes an accelerator from @widget, previously installed with
4447 * gtk_widget_add_accelerator().
4450 gtk_widget_remove_accelerator (GtkWidget *widget,
4451 GtkAccelGroup *accel_group,
4453 GdkModifierType accel_mods)
4455 GtkAccelGroupEntry *ag_entry;
4456 GList *slist, *clist;
4459 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4460 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4462 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4463 clist = gtk_widget_list_accel_closures (widget);
4464 for (slist = clist; slist; slist = slist->next)
4468 for (i = 0; i < n; i++)
4469 if (slist->data == (gpointer) ag_entry[i].closure)
4471 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4473 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4475 g_list_free (clist);
4480 g_list_free (clist);
4482 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4483 accel_key, accel_mods, accel_group,
4484 G_OBJECT_TYPE_NAME (widget), widget);
4490 * gtk_widget_list_accel_closures
4491 * @widget: widget to list accelerator closures for
4492 * @returns: a newly allocated #GList of closures
4494 * Lists the closures used by @widget for accelerator group connections
4495 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4496 * The closures can be used to monitor accelerator changes on @widget,
4497 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4498 * #GtkAccelGroup of a closure which can be found out with
4499 * gtk_accel_group_from_accel_closure().
4502 gtk_widget_list_accel_closures (GtkWidget *widget)
4505 GList *clist = NULL;
4507 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4509 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4510 if (gtk_accel_group_from_accel_closure (slist->data))
4511 clist = g_list_prepend (clist, slist->data);
4517 GtkAccelGroup *accel_group;
4522 destroy_accel_path (gpointer data)
4524 AccelPath *apath = data;
4526 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4528 /* closures_destroy takes care of unrefing the closure */
4529 g_object_unref (apath->accel_group);
4531 g_slice_free (AccelPath, apath);
4536 * gtk_widget_set_accel_path:
4537 * @widget: a #GtkWidget
4538 * @accel_path: (allow-none): path used to look up the accelerator
4539 * @accel_group: (allow-none): a #GtkAccelGroup.
4541 * Given an accelerator group, @accel_group, and an accelerator path,
4542 * @accel_path, sets up an accelerator in @accel_group so whenever the
4543 * key binding that is defined for @accel_path is pressed, @widget
4544 * will be activated. This removes any accelerators (for any
4545 * accelerator group) installed by previous calls to
4546 * gtk_widget_set_accel_path(). Associating accelerators with
4547 * paths allows them to be modified by the user and the modifications
4548 * to be saved for future use. (See gtk_accel_map_save().)
4550 * This function is a low level function that would most likely
4551 * be used by a menu creation system like #GtkUIManager. If you
4552 * use #GtkUIManager, setting up accelerator paths will be done
4555 * Even when you you aren't using #GtkUIManager, if you only want to
4556 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4557 * provides a somewhat more convenient interface.
4559 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4560 * pass a static string, you can save some memory by interning it first with
4561 * g_intern_static_string().
4564 gtk_widget_set_accel_path (GtkWidget *widget,
4565 const gchar *accel_path,
4566 GtkAccelGroup *accel_group)
4570 g_return_if_fail (GTK_IS_WIDGET (widget));
4571 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4575 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4576 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4578 gtk_accel_map_add_entry (accel_path, 0, 0);
4579 apath = g_slice_new (AccelPath);
4580 apath->accel_group = g_object_ref (accel_group);
4581 apath->path_quark = g_quark_from_string (accel_path);
4582 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4587 /* also removes possible old settings */
4588 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4591 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4593 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4597 _gtk_widget_get_accel_path (GtkWidget *widget,
4602 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4604 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4606 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4607 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4611 * gtk_widget_mnemonic_activate:
4612 * @widget: a #GtkWidget
4613 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4615 * Emits the #GtkWidget::mnemonic-activate signal.
4617 * The default handler for this signal activates the @widget if
4618 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4621 * Returns: %TRUE if the signal has been handled
4624 gtk_widget_mnemonic_activate (GtkWidget *widget,
4625 gboolean group_cycling)
4629 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4631 group_cycling = group_cycling != FALSE;
4632 if (!gtk_widget_is_sensitive (widget))
4635 g_signal_emit (widget,
4636 widget_signals[MNEMONIC_ACTIVATE],
4644 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4645 gboolean group_cycling)
4647 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4648 gtk_widget_activate (widget);
4649 else if (gtk_widget_get_can_focus (widget))
4650 gtk_widget_grab_focus (widget);
4653 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4654 G_OBJECT_TYPE_NAME (widget));
4655 gtk_widget_error_bell (widget);
4661 gtk_widget_real_key_press_event (GtkWidget *widget,
4664 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4668 gtk_widget_real_key_release_event (GtkWidget *widget,
4671 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4675 gtk_widget_real_focus_in_event (GtkWidget *widget,
4676 GdkEventFocus *event)
4678 gtk_widget_queue_shallow_draw (widget);
4684 gtk_widget_real_focus_out_event (GtkWidget *widget,
4685 GdkEventFocus *event)
4687 gtk_widget_queue_shallow_draw (widget);
4692 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4693 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4697 * @widget: a #GtkWidget
4698 * @event: a #GdkEvent
4700 * Rarely-used function. This function is used to emit
4701 * the event signals on a widget (those signals should never
4702 * be emitted without using this function to do so).
4703 * If you want to synthesize an event though, don't use this function;
4704 * instead, use gtk_main_do_event() so the event will behave as if
4705 * it were in the event queue. Don't synthesize expose events; instead,
4706 * use gdk_window_invalidate_rect() to invalidate a region of the
4709 * Return value: return from the event signal emission (%TRUE if
4710 * the event was handled)
4713 gtk_widget_event (GtkWidget *widget,
4716 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4717 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4719 if (event->type == GDK_EXPOSE)
4721 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4722 "the same effect, call gdk_window_invalidate_rect/region(), "
4723 "followed by gdk_window_process_updates().");
4727 return gtk_widget_event_internal (widget, event);
4732 * gtk_widget_send_expose:
4733 * @widget: a #GtkWidget
4734 * @event: a expose #GdkEvent
4736 * Very rarely-used function. This function is used to emit
4737 * an expose event signals on a widget. This function is not
4738 * normally used directly. The only time it is used is when
4739 * propagating an expose event to a child %NO_WINDOW widget, and
4740 * that is normally done using gtk_container_propagate_expose().
4742 * If you want to force an area of a window to be redrawn,
4743 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4744 * To cause the redraw to be done immediately, follow that call
4745 * with a call to gdk_window_process_updates().
4747 * Return value: return from the event signal emission (%TRUE if
4748 * the event was handled)
4751 gtk_widget_send_expose (GtkWidget *widget,
4754 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4755 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4756 g_return_val_if_fail (event != NULL, TRUE);
4757 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4759 return gtk_widget_event_internal (widget, event);
4763 event_window_is_still_viewable (GdkEvent *event)
4765 /* Some programs, such as gnome-theme-manager, fake widgets
4766 * into exposing onto a pixmap by sending expose events with
4767 * event->window pointing to a pixmap
4769 if (GDK_IS_PIXMAP (event->any.window))
4770 return event->type == GDK_EXPOSE;
4772 /* Check that we think the event's window is viewable before
4773 * delivering the event, to prevent suprises. We do this here
4774 * at the last moment, since the event may have been queued
4775 * up behind other events, held over a recursive main loop, etc.
4777 switch (event->type)
4780 case GDK_MOTION_NOTIFY:
4781 case GDK_BUTTON_PRESS:
4782 case GDK_2BUTTON_PRESS:
4783 case GDK_3BUTTON_PRESS:
4785 case GDK_ENTER_NOTIFY:
4786 case GDK_PROXIMITY_IN:
4788 return event->any.window && gdk_window_is_viewable (event->any.window);
4791 /* The following events are the second half of paired events;
4792 * we always deliver them to deal with widgets that clean up
4793 * on the second half.
4795 case GDK_BUTTON_RELEASE:
4796 case GDK_KEY_RELEASE:
4797 case GDK_LEAVE_NOTIFY:
4798 case GDK_PROXIMITY_OUT:
4802 /* Remaining events would make sense on an not-viewable window,
4803 * or don't have an associated window.
4810 gtk_widget_event_internal (GtkWidget *widget,
4813 gboolean return_val = FALSE;
4815 /* We check only once for is-still-visible; if someone
4816 * hides the window in on of the signals on the widget,
4817 * they are responsible for returning TRUE to terminate
4820 if (!event_window_is_still_viewable (event))
4823 g_object_ref (widget);
4825 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4826 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4831 switch (event->type)
4836 case GDK_BUTTON_PRESS:
4837 case GDK_2BUTTON_PRESS:
4838 case GDK_3BUTTON_PRESS:
4839 signal_num = BUTTON_PRESS_EVENT;
4842 signal_num = SCROLL_EVENT;
4844 case GDK_BUTTON_RELEASE:
4845 signal_num = BUTTON_RELEASE_EVENT;
4847 case GDK_MOTION_NOTIFY:
4848 signal_num = MOTION_NOTIFY_EVENT;
4851 signal_num = DELETE_EVENT;
4854 signal_num = DESTROY_EVENT;
4855 _gtk_tooltip_hide (widget);
4858 signal_num = KEY_PRESS_EVENT;
4860 case GDK_KEY_RELEASE:
4861 signal_num = KEY_RELEASE_EVENT;
4863 case GDK_ENTER_NOTIFY:
4864 signal_num = ENTER_NOTIFY_EVENT;
4866 case GDK_LEAVE_NOTIFY:
4867 signal_num = LEAVE_NOTIFY_EVENT;
4869 case GDK_FOCUS_CHANGE:
4870 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4871 if (event->focus_change.in)
4872 _gtk_tooltip_focus_in (widget);
4874 _gtk_tooltip_focus_out (widget);
4877 signal_num = CONFIGURE_EVENT;
4880 signal_num = MAP_EVENT;
4883 signal_num = UNMAP_EVENT;
4885 case GDK_WINDOW_STATE:
4886 signal_num = WINDOW_STATE_EVENT;
4888 case GDK_PROPERTY_NOTIFY:
4889 signal_num = PROPERTY_NOTIFY_EVENT;
4891 case GDK_SELECTION_CLEAR:
4892 signal_num = SELECTION_CLEAR_EVENT;
4894 case GDK_SELECTION_REQUEST:
4895 signal_num = SELECTION_REQUEST_EVENT;
4897 case GDK_SELECTION_NOTIFY:
4898 signal_num = SELECTION_NOTIFY_EVENT;
4900 case GDK_PROXIMITY_IN:
4901 signal_num = PROXIMITY_IN_EVENT;
4903 case GDK_PROXIMITY_OUT:
4904 signal_num = PROXIMITY_OUT_EVENT;
4907 signal_num = NO_EXPOSE_EVENT;
4909 case GDK_CLIENT_EVENT:
4910 signal_num = CLIENT_EVENT;
4913 signal_num = EXPOSE_EVENT;
4915 case GDK_VISIBILITY_NOTIFY:
4916 signal_num = VISIBILITY_NOTIFY_EVENT;
4918 case GDK_GRAB_BROKEN:
4919 signal_num = GRAB_BROKEN;
4922 signal_num = DAMAGE_EVENT;
4925 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4929 if (signal_num != -1)
4930 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4932 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4933 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4937 g_object_unref (widget);
4943 * gtk_widget_activate:
4944 * @widget: a #GtkWidget that's activatable
4946 * For widgets that can be "activated" (buttons, menu items, etc.)
4947 * this function activates them. Activation is what happens when you
4948 * press Enter on a widget during key navigation. If @widget isn't
4949 * activatable, the function returns %FALSE.
4951 * Return value: %TRUE if the widget was activatable
4954 gtk_widget_activate (GtkWidget *widget)
4956 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4958 if (WIDGET_CLASS (widget)->activate_signal)
4960 /* FIXME: we should eventually check the signals signature here */
4961 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4970 * gtk_widget_set_scroll_adjustments:
4971 * @widget: a #GtkWidget
4972 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
4973 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
4975 * For widgets that support scrolling, sets the scroll adjustments and
4976 * returns %TRUE. For widgets that don't support scrolling, does
4977 * nothing and returns %FALSE. Widgets that don't support scrolling
4978 * can be scrolled by placing them in a #GtkViewport, which does
4979 * support scrolling.
4981 * Return value: %TRUE if the widget supports scrolling
4984 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4985 GtkAdjustment *hadjustment,
4986 GtkAdjustment *vadjustment)
4991 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4994 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4996 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4998 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5002 g_signal_query (signal_id, &query);
5003 if (!query.signal_id ||
5004 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5005 query.return_type != G_TYPE_NONE ||
5006 query.n_params != 2 ||
5007 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5008 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5010 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5011 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5015 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5020 gtk_widget_reparent_subwindows (GtkWidget *widget,
5021 GdkWindow *new_window)
5023 if (!gtk_widget_get_has_window (widget))
5025 GList *children = gdk_window_get_children (widget->window);
5028 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5030 GdkWindow *window = tmp_list->data;
5033 gdk_window_get_user_data (window, &child);
5034 while (child && child != widget)
5035 child = ((GtkWidget*) child)->parent;
5038 gdk_window_reparent (window, new_window, 0, 0);
5041 g_list_free (children);
5046 GList *tmp_list, *children;
5048 parent = gdk_window_get_parent (widget->window);
5051 gdk_window_reparent (widget->window, new_window, 0, 0);
5054 children = gdk_window_get_children (parent);
5056 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5058 GdkWindow *window = tmp_list->data;
5061 gdk_window_get_user_data (window, &child);
5063 if (child == widget)
5064 gdk_window_reparent (window, new_window, 0, 0);
5067 g_list_free (children);
5073 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5074 gpointer client_data)
5076 g_assert (client_data != NULL);
5078 if (!gtk_widget_get_has_window (widget))
5081 g_object_unref (widget->window);
5082 widget->window = (GdkWindow*) client_data;
5084 g_object_ref (widget->window);
5086 if (GTK_IS_CONTAINER (widget))
5087 gtk_container_forall (GTK_CONTAINER (widget),
5088 gtk_widget_reparent_fixup_child,
5094 * gtk_widget_reparent:
5095 * @widget: a #GtkWidget
5096 * @new_parent: a #GtkContainer to move the widget into
5098 * Moves a widget from one #GtkContainer to another, handling reference
5099 * count issues to avoid destroying the widget.
5102 gtk_widget_reparent (GtkWidget *widget,
5103 GtkWidget *new_parent)
5105 g_return_if_fail (GTK_IS_WIDGET (widget));
5106 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5107 g_return_if_fail (widget->parent != NULL);
5109 if (widget->parent != new_parent)
5111 /* First try to see if we can get away without unrealizing
5112 * the widget as we reparent it. if so we set a flag so
5113 * that gtk_widget_unparent doesn't unrealize widget
5115 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5116 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5118 g_object_ref (widget);
5119 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5120 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5121 g_object_unref (widget);
5123 if (GTK_WIDGET_IN_REPARENT (widget))
5125 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5127 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5128 gtk_widget_reparent_fixup_child (widget,
5129 gtk_widget_get_parent_window (widget));
5132 g_object_notify (G_OBJECT (widget), "parent");
5137 * gtk_widget_intersect:
5138 * @widget: a #GtkWidget
5139 * @area: a rectangle
5140 * @intersection: rectangle to store intersection of @widget and @area
5142 * Computes the intersection of a @widget's area and @area, storing
5143 * the intersection in @intersection, and returns %TRUE if there was
5144 * an intersection. @intersection may be %NULL if you're only
5145 * interested in whether there was an intersection.
5147 * Return value: %TRUE if there was an intersection
5150 gtk_widget_intersect (GtkWidget *widget,
5151 const GdkRectangle *area,
5152 GdkRectangle *intersection)
5158 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5159 g_return_val_if_fail (area != NULL, FALSE);
5162 dest = intersection;
5166 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5168 if (return_val && intersection && gtk_widget_get_has_window (widget))
5170 intersection->x -= widget->allocation.x;
5171 intersection->y -= widget->allocation.y;
5178 * gtk_widget_region_intersect:
5179 * @widget: a #GtkWidget
5180 * @region: a #cairo_region_t, in the same coordinate system as
5181 * @widget->allocation. That is, relative to @widget->window
5182 * for %NO_WINDOW widgets; relative to the parent window
5183 * of @widget->window for widgets with their own window.
5184 * @returns: A newly allocated region holding the intersection of @widget
5185 * and @region. The coordinates of the return value are
5186 * relative to @widget->window for %NO_WINDOW widgets, and
5187 * relative to the parent window of @widget->window for
5188 * widgets with their own window.
5190 * Computes the intersection of a @widget's area and @region, returning
5191 * the intersection. The result may be empty, use cairo_region_is_empty() to
5195 gtk_widget_region_intersect (GtkWidget *widget,
5196 const cairo_region_t *region)
5199 cairo_region_t *dest;
5201 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5202 g_return_val_if_fail (region != NULL, NULL);
5204 gtk_widget_get_draw_rectangle (widget, &rect);
5206 dest = cairo_region_create_rectangle (&rect);
5208 cairo_region_intersect (dest, region);
5214 * _gtk_widget_grab_notify:
5215 * @widget: a #GtkWidget
5216 * @was_grabbed: whether a grab is now in effect
5218 * Emits the #GtkWidget::grab-notify signal on @widget.
5223 _gtk_widget_grab_notify (GtkWidget *widget,
5224 gboolean was_grabbed)
5226 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5230 * gtk_widget_grab_focus:
5231 * @widget: a #GtkWidget
5233 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5234 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5235 * something like #GtkFrame won't work.
5237 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5238 * gtk_widget_set_can_focus() to modify that flag.
5241 gtk_widget_grab_focus (GtkWidget *widget)
5243 g_return_if_fail (GTK_IS_WIDGET (widget));
5245 if (!gtk_widget_is_sensitive (widget))
5248 g_object_ref (widget);
5249 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5250 g_object_notify (G_OBJECT (widget), "has-focus");
5251 g_object_unref (widget);
5255 reset_focus_recurse (GtkWidget *widget,
5258 if (GTK_IS_CONTAINER (widget))
5260 GtkContainer *container;
5262 container = GTK_CONTAINER (widget);
5263 gtk_container_set_focus_child (container, NULL);
5265 gtk_container_foreach (container,
5266 reset_focus_recurse,
5272 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5274 if (gtk_widget_get_can_focus (focus_widget))
5276 GtkWidget *toplevel;
5279 /* clear the current focus setting, break if the current widget
5280 * is the focus widget's parent, since containers above that will
5281 * be set by the next loop.
5283 toplevel = gtk_widget_get_toplevel (focus_widget);
5284 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5286 widget = GTK_WINDOW (toplevel)->focus_widget;
5288 if (widget == focus_widget)
5290 /* We call _gtk_window_internal_set_focus() here so that the
5291 * toplevel window can request the focus if necessary.
5292 * This is needed when the toplevel is a GtkPlug
5294 if (!gtk_widget_has_focus (widget))
5295 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5302 while (widget->parent && widget->parent != focus_widget->parent)
5304 widget = widget->parent;
5305 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5309 else if (toplevel != focus_widget)
5311 /* gtk_widget_grab_focus() operates on a tree without window...
5312 * actually, this is very questionable behaviour.
5315 gtk_container_foreach (GTK_CONTAINER (toplevel),
5316 reset_focus_recurse,
5320 /* now propagate the new focus up the widget tree and finally
5321 * set it on the window
5323 widget = focus_widget;
5324 while (widget->parent)
5326 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5327 widget = widget->parent;
5329 if (GTK_IS_WINDOW (widget))
5330 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5335 gtk_widget_real_query_tooltip (GtkWidget *widget,
5338 gboolean keyboard_tip,
5339 GtkTooltip *tooltip)
5341 gchar *tooltip_markup;
5342 gboolean has_tooltip;
5344 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5345 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5347 if (has_tooltip && tooltip_markup)
5349 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5357 gtk_widget_real_show_help (GtkWidget *widget,
5358 GtkWidgetHelpType help_type)
5360 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5362 _gtk_tooltip_toggle_keyboard_mode (widget);
5371 gtk_widget_real_focus (GtkWidget *widget,
5372 GtkDirectionType direction)
5374 if (!gtk_widget_get_can_focus (widget))
5377 if (!gtk_widget_is_focus (widget))
5379 gtk_widget_grab_focus (widget);
5387 gtk_widget_real_move_focus (GtkWidget *widget,
5388 GtkDirectionType direction)
5390 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5392 if (GTK_IS_WINDOW (toplevel) &&
5393 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5395 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5401 gtk_widget_real_keynav_failed (GtkWidget *widget,
5402 GtkDirectionType direction)
5404 gboolean cursor_only;
5408 case GTK_DIR_TAB_FORWARD:
5409 case GTK_DIR_TAB_BACKWARD:
5416 g_object_get (gtk_widget_get_settings (widget),
5417 "gtk-keynav-cursor-only", &cursor_only,
5424 gtk_widget_error_bell (widget);
5430 * gtk_widget_set_can_focus:
5431 * @widget: a #GtkWidget
5432 * @can_focus: whether or not @widget can own the input focus.
5434 * Specifies whether @widget can own the input focus. See
5435 * gtk_widget_grab_focus() for actually setting the input focus on a
5441 gtk_widget_set_can_focus (GtkWidget *widget,
5444 g_return_if_fail (GTK_IS_WIDGET (widget));
5446 if (can_focus != gtk_widget_get_can_focus (widget))
5449 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5451 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5453 gtk_widget_queue_resize (widget);
5454 g_object_notify (G_OBJECT (widget), "can-focus");
5459 * gtk_widget_get_can_focus:
5460 * @widget: a #GtkWidget
5462 * Determines whether @widget can own the input focus. See
5463 * gtk_widget_set_can_focus().
5465 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5470 gtk_widget_get_can_focus (GtkWidget *widget)
5472 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5474 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5478 * gtk_widget_has_focus:
5479 * @widget: a #GtkWidget
5481 * Determines if the widget has the global input focus. See
5482 * gtk_widget_is_focus() for the difference between having the global
5483 * input focus, and only having the focus within a toplevel.
5485 * Return value: %TRUE if the widget has the global input focus.
5490 gtk_widget_has_focus (GtkWidget *widget)
5492 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5494 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5498 * gtk_widget_is_focus:
5499 * @widget: a #GtkWidget
5501 * Determines if the widget is the focus widget within its
5502 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5503 * necessarily set; %HAS_FOCUS will only be set if the
5504 * toplevel widget additionally has the global input focus.)
5506 * Return value: %TRUE if the widget is the focus widget.
5509 gtk_widget_is_focus (GtkWidget *widget)
5511 GtkWidget *toplevel;
5513 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5515 toplevel = gtk_widget_get_toplevel (widget);
5517 if (GTK_IS_WINDOW (toplevel))
5518 return widget == GTK_WINDOW (toplevel)->focus_widget;
5524 * gtk_widget_set_can_default:
5525 * @widget: a #GtkWidget
5526 * @can_default: whether or not @widget can be a default widget.
5528 * Specifies whether @widget can be a default widget. See
5529 * gtk_widget_grab_default() for details about the meaning of
5535 gtk_widget_set_can_default (GtkWidget *widget,
5536 gboolean can_default)
5538 g_return_if_fail (GTK_IS_WIDGET (widget));
5540 if (can_default != gtk_widget_get_can_default (widget))
5543 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5545 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5547 gtk_widget_queue_resize (widget);
5548 g_object_notify (G_OBJECT (widget), "can-default");
5553 * gtk_widget_get_can_default:
5554 * @widget: a #GtkWidget
5556 * Determines whether @widget can be a default widget. See
5557 * gtk_widget_set_can_default().
5559 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5564 gtk_widget_get_can_default (GtkWidget *widget)
5566 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5568 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5572 * gtk_widget_has_default:
5573 * @widget: a #GtkWidget
5575 * Determines whether @widget is the current default widget within its
5576 * toplevel. See gtk_widget_set_can_default().
5578 * Return value: %TRUE if @widget is the current default widget within
5579 * its toplevel, %FALSE otherwise
5584 gtk_widget_has_default (GtkWidget *widget)
5586 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5588 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5592 _gtk_widget_set_has_default (GtkWidget *widget,
5593 gboolean has_default)
5596 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5598 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5602 * gtk_widget_grab_default:
5603 * @widget: a #GtkWidget
5605 * Causes @widget to become the default widget. @widget must have the
5606 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5607 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5608 * %TRUE)</literal>. The default widget is activated when
5609 * the user presses Enter in a window. Default widgets must be
5610 * activatable, that is, gtk_widget_activate() should affect them.
5613 gtk_widget_grab_default (GtkWidget *widget)
5617 g_return_if_fail (GTK_IS_WIDGET (widget));
5618 g_return_if_fail (gtk_widget_get_can_default (widget));
5620 window = gtk_widget_get_toplevel (widget);
5622 if (window && gtk_widget_is_toplevel (window))
5623 gtk_window_set_default (GTK_WINDOW (window), widget);
5625 g_warning (G_STRLOC ": widget not within a GtkWindow");
5629 * gtk_widget_set_receives_default:
5630 * @widget: a #GtkWidget
5631 * @receives_default: whether or not @widget can be a default widget.
5633 * Specifies whether @widget will be treated as the default widget
5634 * within its toplevel when it has the focus, even if another widget
5637 * See gtk_widget_grab_default() for details about the meaning of
5643 gtk_widget_set_receives_default (GtkWidget *widget,
5644 gboolean receives_default)
5646 g_return_if_fail (GTK_IS_WIDGET (widget));
5648 if (receives_default != gtk_widget_get_receives_default (widget))
5650 if (receives_default)
5651 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5653 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5655 g_object_notify (G_OBJECT (widget), "receives-default");
5660 * gtk_widget_get_receives_default:
5661 * @widget: a #GtkWidget
5663 * Determines whether @widget is alyways treated as default widget
5664 * withing its toplevel when it has the focus, even if another widget
5667 * See gtk_widget_set_receives_default().
5669 * Return value: %TRUE if @widget acts as default widget when focussed,
5675 gtk_widget_get_receives_default (GtkWidget *widget)
5677 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5679 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5683 * gtk_widget_has_grab:
5684 * @widget: a #GtkWidget
5686 * Determines whether the widget is currently grabbing events, so it
5687 * is the only widget receiving input events (keyboard and mouse).
5689 * See also gtk_grab_add().
5691 * Return value: %TRUE if the widget is in the grab_widgets stack
5696 gtk_widget_has_grab (GtkWidget *widget)
5698 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5700 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5704 _gtk_widget_set_has_grab (GtkWidget *widget,
5708 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
5710 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
5714 * gtk_widget_device_is_shadowed:
5715 * @widget: a #GtkWidget
5716 * @device: a #GdkDevice
5718 * Returns %TRUE if @device has been shadowed by a GTK+
5719 * device grab on another widget, so it would stop sending
5720 * events to @widget. This may be used in the
5721 * #GtkWidget::grab-notify signal to check for specific
5722 * devices. See gtk_device_grab_add().
5724 * Returns: %TRUE if there is an ongoing grab on @device
5725 * by another #GtkWidget than @widget.
5730 gtk_widget_device_is_shadowed (GtkWidget *widget,
5733 GtkWindowGroup *group;
5734 GtkWidget *grab_widget, *toplevel;
5736 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5737 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
5739 if (!gtk_widget_get_realized (widget))
5742 toplevel = gtk_widget_get_toplevel (widget);
5744 if (GTK_IS_WINDOW (toplevel))
5745 group = gtk_window_get_group (GTK_WINDOW (toplevel));
5747 group = gtk_window_get_group (NULL);
5749 grab_widget = gtk_window_group_get_current_device_grab (group, device);
5751 /* Widget not inside the hierarchy of grab_widget */
5753 widget != grab_widget &&
5754 !gtk_widget_is_ancestor (widget, grab_widget))
5759 grab_widget = group->grabs->data;
5761 if (widget != grab_widget &&
5762 !gtk_widget_is_ancestor (widget, grab_widget))
5770 * gtk_widget_set_name:
5771 * @widget: a #GtkWidget
5772 * @name: name for the widget
5774 * Widgets can be named, which allows you to refer to them from a
5775 * gtkrc file. You can apply a style to widgets with a particular name
5776 * in the gtkrc file. See the documentation for gtkrc files (on the
5777 * same page as the docs for #GtkRcStyle).
5779 * Note that widget names are separated by periods in paths (see
5780 * gtk_widget_path()), so names with embedded periods may cause confusion.
5783 gtk_widget_set_name (GtkWidget *widget,
5788 g_return_if_fail (GTK_IS_WIDGET (widget));
5790 new_name = g_strdup (name);
5791 g_free (widget->name);
5792 widget->name = new_name;
5794 if (gtk_widget_has_rc_style (widget))
5795 gtk_widget_reset_rc_style (widget);
5797 g_object_notify (G_OBJECT (widget), "name");
5801 * gtk_widget_get_name:
5802 * @widget: a #GtkWidget
5804 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5805 * significance of widget names.
5807 * Return value: name of the widget. This string is owned by GTK+ and
5808 * should not be modified or freed
5810 G_CONST_RETURN gchar*
5811 gtk_widget_get_name (GtkWidget *widget)
5813 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5816 return widget->name;
5817 return G_OBJECT_TYPE_NAME (widget);
5821 * gtk_widget_set_state:
5822 * @widget: a #GtkWidget
5823 * @state: new state for @widget
5825 * This function is for use in widget implementations. Sets the state
5826 * of a widget (insensitive, prelighted, etc.) Usually you should set
5827 * the state using wrapper functions such as gtk_widget_set_sensitive().
5830 gtk_widget_set_state (GtkWidget *widget,
5833 g_return_if_fail (GTK_IS_WIDGET (widget));
5835 if (state == gtk_widget_get_state (widget))
5838 if (state == GTK_STATE_INSENSITIVE)
5839 gtk_widget_set_sensitive (widget, FALSE);
5845 data.state_restoration = FALSE;
5846 data.use_forall = FALSE;
5848 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5850 data.parent_sensitive = TRUE;
5852 gtk_widget_propagate_state (widget, &data);
5854 if (gtk_widget_is_drawable (widget))
5855 gtk_widget_queue_draw (widget);
5860 * gtk_widget_get_state:
5861 * @widget: a #GtkWidget
5863 * Returns the widget's state. See gtk_widget_set_state().
5865 * Returns: the state of @widget.
5870 gtk_widget_get_state (GtkWidget *widget)
5872 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5874 return widget->state;
5878 * gtk_widget_set_visible:
5879 * @widget: a #GtkWidget
5880 * @visible: whether the widget should be shown or not
5882 * Sets the visibility state of @widget. Note that setting this to
5883 * %TRUE doesn't mean the widget is actually viewable, see
5884 * gtk_widget_get_visible().
5886 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5887 * but is nicer to use when the visibility of the widget depends on
5893 gtk_widget_set_visible (GtkWidget *widget,
5896 g_return_if_fail (GTK_IS_WIDGET (widget));
5898 if (visible != gtk_widget_get_visible (widget))
5901 gtk_widget_show (widget);
5903 gtk_widget_hide (widget);
5908 * gtk_widget_get_visible:
5909 * @widget: a #GtkWidget
5911 * Determines whether the widget is visible. Note that this doesn't
5912 * take into account whether the widget's parent is also visible
5913 * or the widget is obscured in any way.
5915 * See gtk_widget_set_visible().
5917 * Return value: %TRUE if the widget is visible
5922 gtk_widget_get_visible (GtkWidget *widget)
5924 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5926 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5930 * gtk_widget_set_has_window:
5931 * @widget: a #GtkWidget
5932 * @has_window: whether or not @widget has a window.
5934 * Specifies whether @widget has a #GdkWindow of its own. Note that
5935 * all realized widgets have a non-%NULL "window" pointer
5936 * (gtk_widget_get_window() never returns a %NULL window when a widget
5937 * is realized), but for many of them it's actually the #GdkWindow of
5938 * one of its parent widgets. Widgets that create a %window for
5939 * themselves in GtkWidget::realize() however must announce this by
5940 * calling this function with @has_window = %TRUE.
5942 * This function should only be called by widget implementations,
5943 * and they should call it in their init() function.
5948 gtk_widget_set_has_window (GtkWidget *widget,
5949 gboolean has_window)
5951 g_return_if_fail (GTK_IS_WIDGET (widget));
5954 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5956 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5960 * gtk_widget_get_has_window:
5961 * @widget: a #GtkWidget
5963 * Determines whether @widget has a #GdkWindow of its own. See
5964 * gtk_widget_set_has_window().
5966 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5971 gtk_widget_get_has_window (GtkWidget *widget)
5973 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5975 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5979 * gtk_widget_is_toplevel:
5980 * @widget: a #GtkWidget
5982 * Determines whether @widget is a toplevel widget. Currently only
5983 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5984 * widgets have no parent widget.
5986 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5991 gtk_widget_is_toplevel (GtkWidget *widget)
5993 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5995 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5999 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6000 gboolean is_toplevel)
6003 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6005 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6009 * gtk_widget_is_drawable:
6010 * @widget: a #GtkWidget
6012 * Determines whether @widget can be drawn to. A widget can be drawn
6013 * to if it is mapped and visible.
6015 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6020 gtk_widget_is_drawable (GtkWidget *widget)
6022 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6024 return (gtk_widget_get_visible (widget) &&
6025 gtk_widget_get_mapped (widget));
6029 * gtk_widget_get_realized:
6030 * @widget: a #GtkWidget
6032 * Determines whether @widget is realized.
6034 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6039 gtk_widget_get_realized (GtkWidget *widget)
6041 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6043 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6047 * gtk_widget_set_realized:
6048 * @widget: a #GtkWidget
6049 * @realized: %TRUE to mark the widget as realized
6051 * Marks the widget as being realized.
6053 * This function should only ever be called in a derived widget's
6054 * "realize" or "unrealize" implementation.
6059 gtk_widget_set_realized (GtkWidget *widget,
6062 g_return_if_fail (GTK_IS_WIDGET (widget));
6065 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6067 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6071 * gtk_widget_get_mapped:
6072 * @widget: a #GtkWidget
6074 * Whether the widget is mapped.
6076 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6081 gtk_widget_get_mapped (GtkWidget *widget)
6083 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6085 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6089 * gtk_widget_set_mapped:
6090 * @widget: a #GtkWidget
6091 * @mapped: %TRUE to mark the widget as mapped
6093 * Marks the widget as being realized.
6095 * This function should only ever be called in a derived widget's
6096 * "map" or "unmap" implementation.
6101 gtk_widget_set_mapped (GtkWidget *widget,
6104 g_return_if_fail (GTK_IS_WIDGET (widget));
6107 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6109 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6113 * gtk_widget_set_app_paintable:
6114 * @widget: a #GtkWidget
6115 * @app_paintable: %TRUE if the application will paint on the widget
6117 * Sets whether the application intends to draw on the widget in
6118 * an #GtkWidget::expose-event handler.
6120 * This is a hint to the widget and does not affect the behavior of
6121 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6122 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6123 * the effect is to suppress default themed drawing of the widget's
6124 * background. (Children of the widget will still be drawn.) The application
6125 * is then entirely responsible for drawing the widget background.
6127 * Note that the background is still drawn when the widget is mapped.
6128 * If this is not suitable (e.g. because you want to make a transparent
6129 * window using an RGBA visual), you can work around this by doing:
6131 * gtk_widget_realize (window);
6132 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6133 * gtk_widget_show (window);
6137 gtk_widget_set_app_paintable (GtkWidget *widget,
6138 gboolean app_paintable)
6140 g_return_if_fail (GTK_IS_WIDGET (widget));
6142 app_paintable = (app_paintable != FALSE);
6144 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6147 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6149 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6151 if (gtk_widget_is_drawable (widget))
6152 gtk_widget_queue_draw (widget);
6154 g_object_notify (G_OBJECT (widget), "app-paintable");
6159 * gtk_widget_get_app_paintable:
6160 * @widget: a #GtkWidget
6162 * Determines whether the application intends to draw on the widget in
6163 * an #GtkWidget::expose-event handler.
6165 * See gtk_widget_set_app_paintable()
6167 * Return value: %TRUE if the widget is app paintable
6172 gtk_widget_get_app_paintable (GtkWidget *widget)
6174 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6176 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6180 * gtk_widget_set_double_buffered:
6181 * @widget: a #GtkWidget
6182 * @double_buffered: %TRUE to double-buffer a widget
6184 * Widgets are double buffered by default; you can use this function
6185 * to turn off the buffering. "Double buffered" simply means that
6186 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6187 * automatically around expose events sent to the
6188 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6189 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6190 * buffer to the screen. The result is that users see the window
6191 * update in one smooth step, and don't see individual graphics
6192 * primitives being rendered.
6194 * In very simple terms, double buffered widgets don't flicker,
6195 * so you would only use this function to turn off double buffering
6196 * if you had special needs and really knew what you were doing.
6198 * Note: if you turn off double-buffering, you have to handle
6199 * expose events, since even the clearing to the background color or
6200 * pixmap will not happen automatically (as it is done in
6201 * gdk_window_begin_paint()).
6204 gtk_widget_set_double_buffered (GtkWidget *widget,
6205 gboolean double_buffered)
6207 g_return_if_fail (GTK_IS_WIDGET (widget));
6209 double_buffered = (double_buffered != FALSE);
6211 if (double_buffered != gtk_widget_get_double_buffered (widget))
6213 if (double_buffered)
6214 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6216 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6218 g_object_notify (G_OBJECT (widget), "double-buffered");
6223 * gtk_widget_get_double_buffered:
6224 * @widget: a #GtkWidget
6226 * Determines whether the widget is double buffered.
6228 * See gtk_widget_set_double_buffered()
6230 * Return value: %TRUE if the widget is double buffered
6235 gtk_widget_get_double_buffered (GtkWidget *widget)
6237 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6239 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6243 * gtk_widget_set_redraw_on_allocate:
6244 * @widget: a #GtkWidget
6245 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6246 * when it is allocated to a new size. Otherwise, only the
6247 * new portion of the widget will be redrawn.
6249 * Sets whether the entire widget is queued for drawing when its size
6250 * allocation changes. By default, this setting is %TRUE and
6251 * the entire widget is redrawn on every size change. If your widget
6252 * leaves the upper left unchanged when made bigger, turning this
6253 * setting off will improve performance.
6255 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6256 * off all allocation on resizing: the widget will not even redraw if
6257 * its position changes; this is to allow containers that don't draw
6258 * anything to avoid excess invalidations. If you set this flag on a
6259 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6260 * you are responsible for invalidating both the old and new allocation
6261 * of the widget when the widget is moved and responsible for invalidating
6262 * regions newly when the widget increases size.
6265 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6266 gboolean redraw_on_allocate)
6268 g_return_if_fail (GTK_IS_WIDGET (widget));
6270 if (redraw_on_allocate)
6271 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6273 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6277 * gtk_widget_set_sensitive:
6278 * @widget: a #GtkWidget
6279 * @sensitive: %TRUE to make the widget sensitive
6281 * Sets the sensitivity of a widget. A widget is sensitive if the user
6282 * can interact with it. Insensitive widgets are "grayed out" and the
6283 * user can't interact with them. Insensitive widgets are known as
6284 * "inactive", "disabled", or "ghosted" in some other toolkits.
6287 gtk_widget_set_sensitive (GtkWidget *widget,
6292 g_return_if_fail (GTK_IS_WIDGET (widget));
6294 sensitive = (sensitive != FALSE);
6296 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6301 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6302 data.state = widget->saved_state;
6306 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6307 data.state = gtk_widget_get_state (widget);
6309 data.state_restoration = TRUE;
6310 data.use_forall = TRUE;
6313 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6315 data.parent_sensitive = TRUE;
6317 gtk_widget_propagate_state (widget, &data);
6318 if (gtk_widget_is_drawable (widget))
6319 gtk_widget_queue_draw (widget);
6321 g_object_notify (G_OBJECT (widget), "sensitive");
6325 * gtk_widget_get_sensitive:
6326 * @widget: a #GtkWidget
6328 * Returns the widget's sensitivity (in the sense of returning
6329 * the value that has been set using gtk_widget_set_sensitive()).
6331 * The effective sensitivity of a widget is however determined by both its
6332 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6334 * Returns: %TRUE if the widget is sensitive
6339 gtk_widget_get_sensitive (GtkWidget *widget)
6341 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6343 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6347 * gtk_widget_is_sensitive:
6348 * @widget: a #GtkWidget
6350 * Returns the widget's effective sensitivity, which means
6351 * it is sensitive itself and also its parent widget is sensntive
6353 * Returns: %TRUE if the widget is effectively sensitive
6358 gtk_widget_is_sensitive (GtkWidget *widget)
6360 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6362 return (gtk_widget_get_sensitive (widget) &&
6363 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6367 * gtk_widget_set_parent:
6368 * @widget: a #GtkWidget
6369 * @parent: parent container
6371 * This function is useful only when implementing subclasses of
6373 * Sets the container as the parent of @widget, and takes care of
6374 * some details such as updating the state and style of the child
6375 * to reflect its new location. The opposite function is
6376 * gtk_widget_unparent().
6379 gtk_widget_set_parent (GtkWidget *widget,
6384 g_return_if_fail (GTK_IS_WIDGET (widget));
6385 g_return_if_fail (GTK_IS_WIDGET (parent));
6386 g_return_if_fail (widget != parent);
6387 if (widget->parent != NULL)
6389 g_warning ("Can't set a parent on widget which has a parent\n");
6392 if (gtk_widget_is_toplevel (widget))
6394 g_warning ("Can't set a parent on a toplevel widget\n");
6398 /* keep this function in sync with gtk_menu_attach_to_widget()
6401 g_object_ref_sink (widget);
6402 widget->parent = parent;
6404 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6405 data.state = gtk_widget_get_state (parent);
6407 data.state = gtk_widget_get_state (widget);
6408 data.state_restoration = FALSE;
6409 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6410 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6412 gtk_widget_propagate_state (widget, &data);
6414 gtk_widget_reset_rc_styles (widget);
6416 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6417 if (GTK_WIDGET_ANCHORED (widget->parent))
6418 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6419 g_object_notify (G_OBJECT (widget), "parent");
6421 /* Enforce realized/mapped invariants
6423 if (gtk_widget_get_realized (widget->parent))
6424 gtk_widget_realize (widget);
6426 if (gtk_widget_get_visible (widget->parent) &&
6427 gtk_widget_get_visible (widget))
6429 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6430 gtk_widget_get_mapped (widget->parent))
6431 gtk_widget_map (widget);
6433 gtk_widget_queue_resize (widget);
6438 * gtk_widget_get_parent:
6439 * @widget: a #GtkWidget
6441 * Returns the parent container of @widget.
6443 * Return value: (transfer none): the parent container of @widget, or %NULL
6446 gtk_widget_get_parent (GtkWidget *widget)
6448 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6450 return widget->parent;
6453 /*****************************************
6455 * see docs/styles.txt
6456 *****************************************/
6459 * gtk_widget_style_attach:
6460 * @widget: a #GtkWidget
6462 * This function attaches the widget's #GtkStyle to the widget's
6463 * #GdkWindow. It is a replacement for
6466 * widget->style = gtk_style_attach (widget->style, widget->window);
6469 * and should only ever be called in a derived widget's "realize"
6470 * implementation which does not chain up to its parent class'
6471 * "realize" implementation, because one of the parent classes
6472 * (finally #GtkWidget) would attach the style itself.
6477 gtk_widget_style_attach (GtkWidget *widget)
6479 g_return_if_fail (GTK_IS_WIDGET (widget));
6480 g_return_if_fail (gtk_widget_get_realized (widget));
6482 widget->style = gtk_style_attach (widget->style, widget->window);
6486 * gtk_widget_has_rc_style:
6487 * @widget: a #GtkWidget
6489 * Determines if the widget style has been looked up through the rc mechanism.
6491 * Returns: %TRUE if the widget has been looked up through the rc
6492 * mechanism, %FALSE otherwise.
6497 gtk_widget_has_rc_style (GtkWidget *widget)
6499 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6501 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6505 * gtk_widget_set_style:
6506 * @widget: a #GtkWidget
6507 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6508 * gtk_widget_set_style() and go back to the default style
6510 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6511 * want to use this function; it interacts badly with themes, because
6512 * themes work by replacing the #GtkStyle. Instead, use
6513 * gtk_widget_modify_style().
6516 gtk_widget_set_style (GtkWidget *widget,
6519 g_return_if_fail (GTK_IS_WIDGET (widget));
6523 gboolean initial_emission;
6525 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6527 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6528 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6530 gtk_widget_set_style_internal (widget, style, initial_emission);
6534 if (GTK_WIDGET_USER_STYLE (widget))
6535 gtk_widget_reset_rc_style (widget);
6540 * gtk_widget_ensure_style:
6541 * @widget: a #GtkWidget
6543 * Ensures that @widget has a style (@widget->style). Not a very useful
6544 * function; most of the time, if you want the style, the widget is
6545 * realized, and realized widgets are guaranteed to have a style
6549 gtk_widget_ensure_style (GtkWidget *widget)
6551 g_return_if_fail (GTK_IS_WIDGET (widget));
6553 if (!GTK_WIDGET_USER_STYLE (widget) &&
6554 !gtk_widget_has_rc_style (widget))
6555 gtk_widget_reset_rc_style (widget);
6558 /* Look up the RC style for this widget, unsetting any user style that
6559 * may be in effect currently
6562 gtk_widget_reset_rc_style (GtkWidget *widget)
6564 GtkStyle *new_style = NULL;
6565 gboolean initial_emission;
6567 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6569 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6570 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6572 if (gtk_widget_has_screen (widget))
6573 new_style = gtk_rc_get_style (widget);
6575 new_style = gtk_widget_get_default_style ();
6577 if (initial_emission || new_style != widget->style)
6578 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6582 * gtk_widget_get_style:
6583 * @widget: a #GtkWidget
6585 * Simply an accessor function that returns @widget->style.
6587 * Return value: (transfer none): the widget's #GtkStyle
6590 gtk_widget_get_style (GtkWidget *widget)
6592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6594 return widget->style;
6598 * gtk_widget_modify_style:
6599 * @widget: a #GtkWidget
6600 * @style: the #GtkRcStyle holding the style modifications
6602 * Modifies style values on the widget. Modifications made using this
6603 * technique take precedence over style values set via an RC file,
6604 * however, they will be overriden if a style is explicitely set on
6605 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6606 * is designed so each field can either be set or unset, so it is
6607 * possible, using this function, to modify some style values and
6608 * leave the others unchanged.
6610 * Note that modifications made with this function are not cumulative
6611 * with previous calls to gtk_widget_modify_style() or with such
6612 * functions as gtk_widget_modify_fg(). If you wish to retain
6613 * previous values, you must first call gtk_widget_get_modifier_style(),
6614 * make your modifications to the returned style, then call
6615 * gtk_widget_modify_style() with that style. On the other hand,
6616 * if you first call gtk_widget_modify_style(), subsequent calls
6617 * to such functions gtk_widget_modify_fg() will have a cumulative
6618 * effect with the initial modifications.
6621 gtk_widget_modify_style (GtkWidget *widget,
6624 g_return_if_fail (GTK_IS_WIDGET (widget));
6625 g_return_if_fail (GTK_IS_RC_STYLE (style));
6627 g_object_set_qdata_full (G_OBJECT (widget),
6629 gtk_rc_style_copy (style),
6630 (GDestroyNotify) g_object_unref);
6632 /* note that "style" may be invalid here if it was the old
6633 * modifier style and the only reference was our own.
6636 if (gtk_widget_has_rc_style (widget))
6637 gtk_widget_reset_rc_style (widget);
6641 * gtk_widget_get_modifier_style:
6642 * @widget: a #GtkWidget
6644 * Returns the current modifier style for the widget. (As set by
6645 * gtk_widget_modify_style().) If no style has previously set, a new
6646 * #GtkRcStyle will be created with all values unset, and set as the
6647 * modifier style for the widget. If you make changes to this rc
6648 * style, you must call gtk_widget_modify_style(), passing in the
6649 * returned rc style, to make sure that your changes take effect.
6651 * Caution: passing the style back to gtk_widget_modify_style() will
6652 * normally end up destroying it, because gtk_widget_modify_style() copies
6653 * the passed-in style and sets the copy as the new modifier style,
6654 * thus dropping any reference to the old modifier style. Add a reference
6655 * to the modifier style if you want to keep it alive.
6657 * Return value: (transfer none): the modifier style for the widget. This rc style is
6658 * owned by the widget. If you want to keep a pointer to value this
6659 * around, you must add a refcount using g_object_ref().
6662 gtk_widget_get_modifier_style (GtkWidget *widget)
6664 GtkRcStyle *rc_style;
6666 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6668 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6672 rc_style = gtk_rc_style_new ();
6673 g_object_set_qdata_full (G_OBJECT (widget),
6676 (GDestroyNotify) g_object_unref);
6683 gtk_widget_modify_color_component (GtkWidget *widget,
6684 GtkRcFlags component,
6686 const GdkColor *color)
6688 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6695 rc_style->fg[state] = *color;
6698 rc_style->bg[state] = *color;
6701 rc_style->text[state] = *color;
6704 rc_style->base[state] = *color;
6707 g_assert_not_reached();
6710 rc_style->color_flags[state] |= component;
6713 rc_style->color_flags[state] &= ~component;
6715 gtk_widget_modify_style (widget, rc_style);
6719 * gtk_widget_modify_symbolic_color:
6720 * @widget: a #GtkWidget
6721 * @name: the name of the symbolic color to modify
6722 * @color: (allow-none): the color to assign (does not need to be allocated),
6723 * or %NULL to undo the effect of previous calls to
6724 * of gtk_widget_modify_symbolic_color().
6726 * Sets a symbolic color for a widget.
6727 * All other style values are left untouched. See also
6728 * gtk_widget_modify_style().
6733 gtk_widget_modify_symbolic_color (GtkWidget *widget,
6735 const GdkColor *color)
6737 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6739 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
6741 gtk_widget_modify_style (widget, rc_style);
6745 * gtk_widget_modify_fg:
6746 * @widget: a #GtkWidget
6747 * @state: the state for which to set the foreground color
6748 * @color: (allow-none): the color to assign (does not need to be allocated),
6749 * or %NULL to undo the effect of previous calls to
6750 * of gtk_widget_modify_fg().
6752 * Sets the foreground color for a widget in a particular state.
6753 * All other style values are left untouched. See also
6754 * gtk_widget_modify_style().
6757 gtk_widget_modify_fg (GtkWidget *widget,
6759 const GdkColor *color)
6761 g_return_if_fail (GTK_IS_WIDGET (widget));
6762 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6764 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6768 * gtk_widget_modify_bg:
6769 * @widget: a #GtkWidget
6770 * @state: the state for which to set the background color
6771 * @color: (allow-none): the color to assign (does not need to be allocated),
6772 * or %NULL to undo the effect of previous calls to
6773 * of gtk_widget_modify_bg().
6775 * Sets the background color for a widget in a particular state.
6776 * All other style values are left untouched. See also
6777 * gtk_widget_modify_style().
6779 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6780 * draw on their parent container's window and thus may not draw any
6781 * background themselves. This is the case for e.g. #GtkLabel. To modify
6782 * the background of such widgets, you have to set the background color
6783 * on their parent; if you want to set the background of a rectangular
6784 * area around a label, try placing the label in a #GtkEventBox widget
6785 * and setting the background color on that.
6788 gtk_widget_modify_bg (GtkWidget *widget,
6790 const GdkColor *color)
6792 g_return_if_fail (GTK_IS_WIDGET (widget));
6793 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6795 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6799 * gtk_widget_modify_text:
6800 * @widget: a #GtkWidget
6801 * @state: the state for which to set the text color
6802 * @color: (allow-none): the color to assign (does not need to be allocated),
6803 * or %NULL to undo the effect of previous calls to
6804 * of gtk_widget_modify_text().
6806 * Sets the text color for a widget in a particular state. All other
6807 * style values are left untouched. The text color is the foreground
6808 * color used along with the base color (see gtk_widget_modify_base())
6809 * for widgets such as #GtkEntry and #GtkTextView. See also
6810 * gtk_widget_modify_style().
6813 gtk_widget_modify_text (GtkWidget *widget,
6815 const GdkColor *color)
6817 g_return_if_fail (GTK_IS_WIDGET (widget));
6818 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6820 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6824 * gtk_widget_modify_base:
6825 * @widget: a #GtkWidget
6826 * @state: the state for which to set the base color
6827 * @color: (allow-none): the color to assign (does not need to be allocated),
6828 * or %NULL to undo the effect of previous calls to
6829 * of gtk_widget_modify_base().
6831 * Sets the base color for a widget in a particular state.
6832 * All other style values are left untouched. The base color
6833 * is the background color used along with the text color
6834 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6835 * and #GtkTextView. See also gtk_widget_modify_style().
6837 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6838 * draw on their parent container's window and thus may not draw any
6839 * background themselves. This is the case for e.g. #GtkLabel. To modify
6840 * the background of such widgets, you have to set the base color on their
6841 * parent; if you want to set the background of a rectangular area around
6842 * a label, try placing the label in a #GtkEventBox widget and setting
6843 * the base color on that.
6846 gtk_widget_modify_base (GtkWidget *widget,
6848 const GdkColor *color)
6850 g_return_if_fail (GTK_IS_WIDGET (widget));
6851 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6853 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6857 modify_color_property (GtkWidget *widget,
6858 GtkRcStyle *rc_style,
6860 const GdkColor *color)
6862 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6863 GQuark property_name = g_quark_from_string (name);
6867 GtkRcProperty rc_property = {0};
6870 rc_property.type_name = type_name;
6871 rc_property.property_name = property_name;
6872 rc_property.origin = NULL;
6874 color_name = gdk_color_to_string (color);
6875 g_value_init (&rc_property.value, G_TYPE_STRING);
6876 g_value_take_string (&rc_property.value, color_name);
6878 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6880 g_value_unset (&rc_property.value);
6883 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6887 * gtk_widget_modify_cursor:
6888 * @widget: a #GtkWidget
6889 * @primary: the color to use for primary cursor (does not need to be
6890 * allocated), or %NULL to undo the effect of previous calls to
6891 * of gtk_widget_modify_cursor().
6892 * @secondary: the color to use for secondary cursor (does not need to be
6893 * allocated), or %NULL to undo the effect of previous calls to
6894 * of gtk_widget_modify_cursor().
6896 * Sets the cursor color to use in a widget, overriding the
6897 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6898 * style properties. All other style values are left untouched.
6899 * See also gtk_widget_modify_style().
6904 gtk_widget_modify_cursor (GtkWidget *widget,
6905 const GdkColor *primary,
6906 const GdkColor *secondary)
6908 GtkRcStyle *rc_style;
6910 g_return_if_fail (GTK_IS_WIDGET (widget));
6912 rc_style = gtk_widget_get_modifier_style (widget);
6914 modify_color_property (widget, rc_style, "cursor-color", primary);
6915 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6917 gtk_widget_modify_style (widget, rc_style);
6921 * gtk_widget_modify_font:
6922 * @widget: a #GtkWidget
6923 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6924 * the effect of previous calls to gtk_widget_modify_font().
6926 * Sets the font to use for a widget. All other style values are left
6927 * untouched. See also gtk_widget_modify_style().
6930 gtk_widget_modify_font (GtkWidget *widget,
6931 PangoFontDescription *font_desc)
6933 GtkRcStyle *rc_style;
6935 g_return_if_fail (GTK_IS_WIDGET (widget));
6937 rc_style = gtk_widget_get_modifier_style (widget);
6939 if (rc_style->font_desc)
6940 pango_font_description_free (rc_style->font_desc);
6943 rc_style->font_desc = pango_font_description_copy (font_desc);
6945 rc_style->font_desc = NULL;
6947 gtk_widget_modify_style (widget, rc_style);
6951 gtk_widget_real_direction_changed (GtkWidget *widget,
6952 GtkTextDirection previous_direction)
6954 gtk_widget_queue_resize (widget);
6958 gtk_widget_real_style_set (GtkWidget *widget,
6959 GtkStyle *previous_style)
6961 if (gtk_widget_get_realized (widget) &&
6962 gtk_widget_get_has_window (widget))
6963 gtk_style_set_background (widget->style, widget->window, widget->state);
6967 gtk_widget_set_style_internal (GtkWidget *widget,
6969 gboolean initial_emission)
6971 g_object_ref (widget);
6972 g_object_freeze_notify (G_OBJECT (widget));
6974 if (widget->style != style)
6976 GtkStyle *previous_style;
6978 if (gtk_widget_get_realized (widget))
6980 gtk_widget_reset_shapes (widget);
6981 gtk_style_detach (widget->style);
6984 previous_style = widget->style;
6985 widget->style = style;
6986 g_object_ref (widget->style);
6988 if (gtk_widget_get_realized (widget))
6989 widget->style = gtk_style_attach (widget->style, widget->window);
6991 gtk_widget_update_pango_context (widget);
6992 g_signal_emit (widget,
6993 widget_signals[STYLE_SET],
6995 initial_emission ? NULL : previous_style);
6996 g_object_unref (previous_style);
6998 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6999 gtk_widget_queue_resize (widget);
7001 else if (initial_emission)
7003 gtk_widget_update_pango_context (widget);
7004 g_signal_emit (widget,
7005 widget_signals[STYLE_SET],
7009 g_object_notify (G_OBJECT (widget), "style");
7010 g_object_thaw_notify (G_OBJECT (widget));
7011 g_object_unref (widget);
7015 GtkWidget *previous_toplevel;
7016 GdkScreen *previous_screen;
7017 GdkScreen *new_screen;
7018 } HierarchyChangedInfo;
7021 do_screen_change (GtkWidget *widget,
7022 GdkScreen *old_screen,
7023 GdkScreen *new_screen)
7025 if (old_screen != new_screen)
7029 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7031 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7034 _gtk_tooltip_hide (widget);
7035 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7040 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7041 gpointer client_data)
7043 HierarchyChangedInfo *info = client_data;
7044 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7045 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
7047 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7049 g_object_ref (widget);
7052 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7054 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7056 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7057 do_screen_change (widget, info->previous_screen, info->new_screen);
7059 if (GTK_IS_CONTAINER (widget))
7060 gtk_container_forall (GTK_CONTAINER (widget),
7061 gtk_widget_propagate_hierarchy_changed_recurse,
7064 g_object_unref (widget);
7069 * _gtk_widget_propagate_hierarchy_changed:
7070 * @widget: a #GtkWidget
7071 * @previous_toplevel: Previous toplevel
7073 * Propagates changes in the anchored state to a widget and all
7074 * children, unsetting or setting the %ANCHORED flag, and
7075 * emitting #GtkWidget::hierarchy-changed.
7078 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7079 GtkWidget *previous_toplevel)
7081 HierarchyChangedInfo info;
7083 info.previous_toplevel = previous_toplevel;
7084 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7086 if (gtk_widget_is_toplevel (widget) ||
7087 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7088 info.new_screen = gtk_widget_get_screen (widget);
7090 info.new_screen = NULL;
7092 if (info.previous_screen)
7093 g_object_ref (info.previous_screen);
7094 if (previous_toplevel)
7095 g_object_ref (previous_toplevel);
7097 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7099 if (previous_toplevel)
7100 g_object_unref (previous_toplevel);
7101 if (info.previous_screen)
7102 g_object_unref (info.previous_screen);
7106 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7107 gpointer client_data)
7109 HierarchyChangedInfo *info = client_data;
7111 g_object_ref (widget);
7113 do_screen_change (widget, info->previous_screen, info->new_screen);
7115 if (GTK_IS_CONTAINER (widget))
7116 gtk_container_forall (GTK_CONTAINER (widget),
7117 gtk_widget_propagate_screen_changed_recurse,
7120 g_object_unref (widget);
7124 * gtk_widget_is_composited:
7125 * @widget: a #GtkWidget
7127 * Whether @widget can rely on having its alpha channel
7128 * drawn correctly. On X11 this function returns whether a
7129 * compositing manager is running for @widget's screen.
7131 * Please note that the semantics of this call will change
7132 * in the future if used on a widget that has a composited
7133 * window in its hierarchy (as set by gdk_window_set_composited()).
7135 * Return value: %TRUE if the widget can rely on its alpha
7136 * channel being drawn correctly.
7141 gtk_widget_is_composited (GtkWidget *widget)
7145 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7147 screen = gtk_widget_get_screen (widget);
7149 return gdk_screen_is_composited (screen);
7153 propagate_composited_changed (GtkWidget *widget,
7156 if (GTK_IS_CONTAINER (widget))
7158 gtk_container_forall (GTK_CONTAINER (widget),
7159 propagate_composited_changed,
7163 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7167 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7169 propagate_composited_changed (widget, NULL);
7173 * _gtk_widget_propagate_screen_changed:
7174 * @widget: a #GtkWidget
7175 * @previous_screen: Previous screen
7177 * Propagates changes in the screen for a widget to all
7178 * children, emitting #GtkWidget::screen-changed.
7181 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7182 GdkScreen *previous_screen)
7184 HierarchyChangedInfo info;
7186 info.previous_screen = previous_screen;
7187 info.new_screen = gtk_widget_get_screen (widget);
7189 if (previous_screen)
7190 g_object_ref (previous_screen);
7192 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7194 if (previous_screen)
7195 g_object_unref (previous_screen);
7199 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7201 if (gtk_widget_has_rc_style (widget))
7202 gtk_widget_reset_rc_style (widget);
7204 if (GTK_IS_CONTAINER (widget))
7205 gtk_container_forall (GTK_CONTAINER (widget),
7206 reset_rc_styles_recurse,
7212 * gtk_widget_reset_rc_styles:
7213 * @widget: a #GtkWidget.
7215 * Reset the styles of @widget and all descendents, so when
7216 * they are looked up again, they get the correct values
7217 * for the currently loaded RC file settings.
7219 * This function is not useful for applications.
7222 gtk_widget_reset_rc_styles (GtkWidget *widget)
7224 g_return_if_fail (GTK_IS_WIDGET (widget));
7226 reset_rc_styles_recurse (widget, NULL);
7230 * gtk_widget_get_default_style:
7232 * Returns the default style used by all widgets initially.
7234 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7235 * by GTK+ and should not be modified or freed.
7238 gtk_widget_get_default_style (void)
7240 if (!gtk_default_style)
7242 gtk_default_style = gtk_style_new ();
7243 g_object_ref (gtk_default_style);
7246 return gtk_default_style;
7249 static PangoContext *
7250 gtk_widget_peek_pango_context (GtkWidget *widget)
7252 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7256 * gtk_widget_get_pango_context:
7257 * @widget: a #GtkWidget
7259 * Gets a #PangoContext with the appropriate font map, font description,
7260 * and base direction for this widget. Unlike the context returned
7261 * by gtk_widget_create_pango_context(), this context is owned by
7262 * the widget (it can be used until the screen for the widget changes
7263 * or the widget is removed from its toplevel), and will be updated to
7264 * match any changes to the widget's attributes.
7266 * If you create and keep a #PangoLayout using this context, you must
7267 * deal with changes to the context by calling pango_layout_context_changed()
7268 * on the layout in response to the #GtkWidget::style-set and
7269 * #GtkWidget::direction-changed signals for the widget.
7271 * Return value: (transfer none): the #PangoContext for the widget.
7274 gtk_widget_get_pango_context (GtkWidget *widget)
7276 PangoContext *context;
7278 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7280 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7283 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7284 g_object_set_qdata_full (G_OBJECT (widget),
7285 quark_pango_context,
7294 update_pango_context (GtkWidget *widget,
7295 PangoContext *context)
7297 pango_context_set_font_description (context, widget->style->font_desc);
7298 pango_context_set_base_dir (context,
7299 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7300 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7304 gtk_widget_update_pango_context (GtkWidget *widget)
7306 PangoContext *context = gtk_widget_peek_pango_context (widget);
7312 update_pango_context (widget, context);
7314 screen = gtk_widget_get_screen_unchecked (widget);
7317 pango_cairo_context_set_resolution (context,
7318 gdk_screen_get_resolution (screen));
7319 pango_cairo_context_set_font_options (context,
7320 gdk_screen_get_font_options (screen));
7326 * gtk_widget_create_pango_context:
7327 * @widget: a #GtkWidget
7329 * Creates a new #PangoContext with the appropriate font map,
7330 * font description, and base direction for drawing text for
7331 * this widget. See also gtk_widget_get_pango_context().
7333 * Return value: the new #PangoContext
7336 gtk_widget_create_pango_context (GtkWidget *widget)
7339 PangoContext *context;
7341 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7343 screen = gtk_widget_get_screen_unchecked (widget);
7346 GTK_NOTE (MULTIHEAD,
7347 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7349 screen = gdk_screen_get_default ();
7352 context = gdk_pango_context_get_for_screen (screen);
7354 update_pango_context (widget, context);
7355 pango_context_set_language (context, gtk_get_default_language ());
7361 * gtk_widget_create_pango_layout:
7362 * @widget: a #GtkWidget
7363 * @text: text to set on the layout (can be %NULL)
7365 * Creates a new #PangoLayout with the appropriate font map,
7366 * font description, and base direction for drawing text for
7369 * If you keep a #PangoLayout created in this way around, in order to
7370 * notify the layout of changes to the base direction or font of this
7371 * widget, you must call pango_layout_context_changed() in response to
7372 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7375 * Return value: the new #PangoLayout
7378 gtk_widget_create_pango_layout (GtkWidget *widget,
7381 PangoLayout *layout;
7382 PangoContext *context;
7384 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7386 context = gtk_widget_get_pango_context (widget);
7387 layout = pango_layout_new (context);
7390 pango_layout_set_text (layout, text, -1);
7396 * gtk_widget_render_icon:
7397 * @widget: a #GtkWidget
7398 * @stock_id: a stock ID
7399 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7400 * render at the size of the source and don't scale (if there are
7401 * multiple source sizes, GTK+ picks one of the available sizes).
7402 * @detail: (allow-none): render detail to pass to theme engine
7404 * A convenience function that uses the theme engine and RC file
7405 * settings for @widget to look up @stock_id and render it to
7406 * a pixbuf. @stock_id should be a stock icon ID such as
7407 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7408 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7409 * identifies the widget or code doing the rendering, so that
7410 * theme engines can special-case rendering for that widget or code.
7412 * The pixels in the returned #GdkPixbuf are shared with the rest of
7413 * the application and should not be modified. The pixbuf should be freed
7414 * after use with g_object_unref().
7416 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7419 gtk_widget_render_icon (GtkWidget *widget,
7420 const gchar *stock_id,
7422 const gchar *detail)
7424 GtkIconSet *icon_set;
7427 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7428 g_return_val_if_fail (stock_id != NULL, NULL);
7429 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7431 gtk_widget_ensure_style (widget);
7433 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7435 if (icon_set == NULL)
7438 retval = gtk_icon_set_render_icon (icon_set,
7440 gtk_widget_get_direction (widget),
7441 gtk_widget_get_state (widget),
7450 * gtk_widget_set_parent_window:
7451 * @widget: a #GtkWidget.
7452 * @parent_window: the new parent window.
7454 * Sets a non default parent window for @widget.
7457 gtk_widget_set_parent_window (GtkWidget *widget,
7458 GdkWindow *parent_window)
7460 GdkWindow *old_parent_window;
7462 g_return_if_fail (GTK_IS_WIDGET (widget));
7464 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7465 quark_parent_window);
7467 if (parent_window != old_parent_window)
7469 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7471 if (old_parent_window)
7472 g_object_unref (old_parent_window);
7474 g_object_ref (parent_window);
7479 * gtk_widget_get_parent_window:
7480 * @widget: a #GtkWidget.
7482 * Gets @widget's parent window.
7484 * Returns: (transfer none): the parent window of @widget.
7487 gtk_widget_get_parent_window (GtkWidget *widget)
7489 GdkWindow *parent_window;
7491 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7493 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7495 return (parent_window != NULL) ? parent_window :
7496 (widget->parent != NULL) ? widget->parent->window : NULL;
7501 * gtk_widget_set_child_visible:
7502 * @widget: a #GtkWidget
7503 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7505 * Sets whether @widget should be mapped along with its when its parent
7506 * is mapped and @widget has been shown with gtk_widget_show().
7508 * The child visibility can be set for widget before it is added to
7509 * a container with gtk_widget_set_parent(), to avoid mapping
7510 * children unnecessary before immediately unmapping them. However
7511 * it will be reset to its default state of %TRUE when the widget
7512 * is removed from a container.
7514 * Note that changing the child visibility of a widget does not
7515 * queue a resize on the widget. Most of the time, the size of
7516 * a widget is computed from all visible children, whether or
7517 * not they are mapped. If this is not the case, the container
7518 * can queue a resize itself.
7520 * This function is only useful for container implementations and
7521 * never should be called by an application.
7524 gtk_widget_set_child_visible (GtkWidget *widget,
7525 gboolean is_visible)
7527 g_return_if_fail (GTK_IS_WIDGET (widget));
7528 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7530 g_object_ref (widget);
7533 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7536 GtkWidget *toplevel;
7538 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7540 toplevel = gtk_widget_get_toplevel (widget);
7541 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7542 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7545 if (widget->parent && gtk_widget_get_realized (widget->parent))
7547 if (gtk_widget_get_mapped (widget->parent) &&
7548 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7549 gtk_widget_get_visible (widget))
7550 gtk_widget_map (widget);
7552 gtk_widget_unmap (widget);
7555 g_object_unref (widget);
7559 * gtk_widget_get_child_visible:
7560 * @widget: a #GtkWidget
7562 * Gets the value set with gtk_widget_set_child_visible().
7563 * If you feel a need to use this function, your code probably
7564 * needs reorganization.
7566 * This function is only useful for container implementations and
7567 * never should be called by an application.
7569 * Return value: %TRUE if the widget is mapped with the parent.
7572 gtk_widget_get_child_visible (GtkWidget *widget)
7574 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7576 return GTK_WIDGET_CHILD_VISIBLE (widget);
7580 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7582 GtkWidget *toplevel;
7584 toplevel = gtk_widget_get_toplevel (widget);
7586 if (gtk_widget_is_toplevel (toplevel))
7588 if (GTK_IS_WINDOW (toplevel))
7589 return GTK_WINDOW (toplevel)->screen;
7590 else if (GTK_IS_INVISIBLE (toplevel))
7591 return GTK_INVISIBLE (widget)->screen;
7598 * gtk_widget_get_screen:
7599 * @widget: a #GtkWidget
7601 * Get the #GdkScreen from the toplevel window associated with
7602 * this widget. This function can only be called after the widget
7603 * has been added to a widget hierarchy with a #GtkWindow
7606 * In general, you should only create screen specific
7607 * resources when a widget has been realized, and you should
7608 * free those resources when the widget is unrealized.
7610 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7615 gtk_widget_get_screen (GtkWidget *widget)
7619 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7621 screen = gtk_widget_get_screen_unchecked (widget);
7628 g_warning (G_STRLOC ": Can't get associated screen"
7629 " for a widget unless it is inside a toplevel GtkWindow\n"
7630 " widget type is %s associated top level type is %s",
7631 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7632 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7634 return gdk_screen_get_default ();
7639 * gtk_widget_has_screen:
7640 * @widget: a #GtkWidget
7642 * Checks whether there is a #GdkScreen is associated with
7643 * this widget. All toplevel widgets have an associated
7644 * screen, and all widgets added into a hierarchy with a toplevel
7645 * window at the top.
7647 * Return value: %TRUE if there is a #GdkScreen associcated
7653 gtk_widget_has_screen (GtkWidget *widget)
7655 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7657 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7661 * gtk_widget_get_display:
7662 * @widget: a #GtkWidget
7664 * Get the #GdkDisplay for the toplevel window associated with
7665 * this widget. This function can only be called after the widget
7666 * has been added to a widget hierarchy with a #GtkWindow at the top.
7668 * In general, you should only create display 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 #GdkDisplay for the toplevel for this widget.
7677 gtk_widget_get_display (GtkWidget *widget)
7679 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7681 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7685 * gtk_widget_get_root_window:
7686 * @widget: a #GtkWidget
7688 * Get the root window where this widget is located. This function can
7689 * only be called after the widget has been added to a widget
7690 * hierarchy with #GtkWindow at the top.
7692 * The root window is useful for such purposes as creating a popup
7693 * #GdkWindow associated with the window. In general, you should only
7694 * create display specific resources when a widget has been realized,
7695 * and you should free those resources when the widget is unrealized.
7697 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7702 gtk_widget_get_root_window (GtkWidget *widget)
7704 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7706 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7710 * gtk_widget_child_focus:
7711 * @widget: a #GtkWidget
7712 * @direction: direction of focus movement
7714 * This function is used by custom widget implementations; if you're
7715 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7716 * to a particular widget, and gtk_container_set_focus_chain() to
7717 * change the focus tab order. So you may want to investigate those
7718 * functions instead.
7720 * gtk_widget_child_focus() is called by containers as the user moves
7721 * around the window using keyboard shortcuts. @direction indicates
7722 * what kind of motion is taking place (up, down, left, right, tab
7723 * forward, tab backward). gtk_widget_child_focus() emits the
7724 * #GtkWidget::focus signal; widgets override the default handler
7725 * for this signal in order to implement appropriate focus behavior.
7727 * The default ::focus handler for a widget should return %TRUE if
7728 * moving in @direction left the focus on a focusable location inside
7729 * that widget, and %FALSE if moving in @direction moved the focus
7730 * outside the widget. If returning %TRUE, widgets normally
7731 * call gtk_widget_grab_focus() to place the focus accordingly;
7732 * if returning %FALSE, they don't modify the current focus location.
7734 * Return value: %TRUE if focus ended up inside @widget
7737 gtk_widget_child_focus (GtkWidget *widget,
7738 GtkDirectionType direction)
7740 gboolean return_val;
7742 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7744 if (!gtk_widget_get_visible (widget) ||
7745 !gtk_widget_is_sensitive (widget))
7748 /* child widgets must set CAN_FOCUS, containers
7749 * don't have to though.
7751 if (!GTK_IS_CONTAINER (widget) &&
7752 !gtk_widget_get_can_focus (widget))
7755 g_signal_emit (widget,
7756 widget_signals[FOCUS],
7758 direction, &return_val);
7764 * gtk_widget_keynav_failed:
7765 * @widget: a #GtkWidget
7766 * @direction: direction of focus movement
7768 * This function should be called whenever keyboard navigation within
7769 * a single widget hits a boundary. The function emits the
7770 * #GtkWidget::keynav-failed signal on the widget and its return
7771 * value should be interpreted in a way similar to the return value of
7772 * gtk_widget_child_focus():
7774 * When %TRUE is returned, stay in the widget, the failed keyboard
7775 * navigation is Ok and/or there is nowhere we can/should move the
7778 * When %FALSE is returned, the caller should continue with keyboard
7779 * navigation outside the widget, e.g. by calling
7780 * gtk_widget_child_focus() on the widget's toplevel.
7782 * The default ::keynav-failed handler returns %TRUE for
7783 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7784 * values of #GtkDirectionType, it looks at the
7785 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7786 * if the setting is %TRUE. This way the entire user interface
7787 * becomes cursor-navigatable on input devices such as mobile phones
7788 * which only have cursor keys but no tab key.
7790 * Whenever the default handler returns %TRUE, it also calls
7791 * gtk_widget_error_bell() to notify the user of the failed keyboard
7794 * A use case for providing an own implementation of ::keynav-failed
7795 * (either by connecting to it or by overriding it) would be a row of
7796 * #GtkEntry widgets where the user should be able to navigate the
7797 * entire row with the cursor keys, as e.g. known from user interfaces
7798 * that require entering license keys.
7800 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7801 * if the emitting widget should try to handle the keyboard
7802 * navigation attempt in its parent container(s).
7807 gtk_widget_keynav_failed (GtkWidget *widget,
7808 GtkDirectionType direction)
7810 gboolean return_val;
7812 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7814 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7815 direction, &return_val);
7821 * gtk_widget_error_bell:
7822 * @widget: a #GtkWidget
7824 * Notifies the user about an input-related error on this widget.
7825 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7826 * gdk_window_beep(), otherwise it does nothing.
7828 * Note that the effect of gdk_window_beep() can be configured in many
7829 * ways, depending on the windowing backend and the desktop environment
7830 * or window manager that is used.
7835 gtk_widget_error_bell (GtkWidget *widget)
7837 GtkSettings* settings;
7840 g_return_if_fail (GTK_IS_WIDGET (widget));
7842 settings = gtk_widget_get_settings (widget);
7846 g_object_get (settings,
7847 "gtk-error-bell", &beep,
7850 if (beep && widget->window)
7851 gdk_window_beep (widget->window);
7855 gtk_widget_set_usize_internal (GtkWidget *widget,
7859 GtkWidgetAuxInfo *aux_info;
7860 gboolean changed = FALSE;
7862 g_object_freeze_notify (G_OBJECT (widget));
7864 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7866 if (width > -2 && aux_info->width != width)
7868 g_object_notify (G_OBJECT (widget), "width-request");
7869 aux_info->width = width;
7872 if (height > -2 && aux_info->height != height)
7874 g_object_notify (G_OBJECT (widget), "height-request");
7875 aux_info->height = height;
7879 if (gtk_widget_get_visible (widget) && changed)
7880 gtk_widget_queue_resize (widget);
7882 g_object_thaw_notify (G_OBJECT (widget));
7886 * gtk_widget_set_size_request:
7887 * @widget: a #GtkWidget
7888 * @width: width @widget should request, or -1 to unset
7889 * @height: height @widget should request, or -1 to unset
7891 * Sets the minimum size of a widget; that is, the widget's size
7892 * request will be @width by @height. You can use this function to
7893 * force a widget to be either larger or smaller than it normally
7896 * In most cases, gtk_window_set_default_size() is a better choice for
7897 * toplevel windows than this function; setting the default size will
7898 * still allow users to shrink the window. Setting the size request
7899 * will force them to leave the window at least as large as the size
7900 * request. When dealing with window sizes,
7901 * gtk_window_set_geometry_hints() can be a useful function as well.
7903 * Note the inherent danger of setting any fixed size - themes,
7904 * translations into other languages, different fonts, and user action
7905 * can all change the appropriate size for a given widget. So, it's
7906 * basically impossible to hardcode a size that will always be
7909 * The size request of a widget is the smallest size a widget can
7910 * accept while still functioning well and drawing itself correctly.
7911 * However in some strange cases a widget may be allocated less than
7912 * its requested size, and in many cases a widget may be allocated more
7913 * space than it requested.
7915 * If the size request in a given direction is -1 (unset), then
7916 * the "natural" size request of the widget will be used instead.
7918 * Widgets can't actually be allocated a size less than 1 by 1, but
7919 * you can pass 0,0 to this function to mean "as small as possible."
7922 gtk_widget_set_size_request (GtkWidget *widget,
7926 g_return_if_fail (GTK_IS_WIDGET (widget));
7927 g_return_if_fail (width >= -1);
7928 g_return_if_fail (height >= -1);
7935 gtk_widget_set_usize_internal (widget, width, height);
7940 * gtk_widget_get_size_request:
7941 * @widget: a #GtkWidget
7942 * @width: (out) (allow-none): return location for width, or %NULL
7943 * @height: (out) (allow-none): return location for height, or %NULL
7945 * Gets the size request that was explicitly set for the widget using
7946 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7947 * @height indicates that that dimension has not been set explicitly
7948 * and the natural requisition of the widget will be used intead. See
7949 * gtk_widget_set_size_request(). To get the size a widget will
7950 * actually use, call gtk_widget_size_request() instead of
7954 gtk_widget_get_size_request (GtkWidget *widget,
7958 GtkWidgetAuxInfo *aux_info;
7960 g_return_if_fail (GTK_IS_WIDGET (widget));
7962 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7965 *width = aux_info ? aux_info->width : -1;
7968 *height = aux_info ? aux_info->height : -1;
7972 * gtk_widget_set_events:
7973 * @widget: a #GtkWidget
7974 * @events: event mask
7976 * Sets the event mask (see #GdkEventMask) for a widget. The event
7977 * mask determines which events a widget will receive. Keep in mind
7978 * that different widgets have different default event masks, and by
7979 * changing the event mask you may disrupt a widget's functionality,
7980 * so be careful. This function must be called while a widget is
7981 * unrealized. Consider gtk_widget_add_events() for widgets that are
7982 * already realized, or if you want to preserve the existing event
7983 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7984 * to get events on those widgets, place them inside a #GtkEventBox
7985 * and receive events on the event box.
7988 gtk_widget_set_events (GtkWidget *widget,
7991 g_return_if_fail (GTK_IS_WIDGET (widget));
7992 g_return_if_fail (!gtk_widget_get_realized (widget));
7994 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7995 GINT_TO_POINTER (events));
7996 g_object_notify (G_OBJECT (widget), "events");
8000 * gtk_widget_set_device_events:
8001 * @widget: a #GtkWidget
8002 * @device: a #GdkDevice
8003 * @events: event mask
8005 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8006 * mask determines which events a widget will receive from @device. Keep
8007 * in mind that different widgets have different default event masks, and by
8008 * changing the event mask you may disrupt a widget's functionality,
8009 * so be careful. This function must be called while a widget is
8010 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8011 * already realized, or if you want to preserve the existing event
8012 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8013 * to get events on those widgets, place them inside a #GtkEventBox
8014 * and receive events on the event box.
8019 gtk_widget_set_device_events (GtkWidget *widget,
8021 GdkEventMask events)
8023 GHashTable *device_events;
8025 g_return_if_fail (GTK_IS_WIDGET (widget));
8026 g_return_if_fail (GDK_IS_DEVICE (device));
8027 g_return_if_fail (!gtk_widget_get_realized (widget));
8029 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8031 if (G_UNLIKELY (!device_events))
8033 device_events = g_hash_table_new (NULL, NULL);
8034 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8035 (GDestroyNotify) g_hash_table_unref);
8038 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8042 gtk_widget_add_events_internal_list (GtkWidget *widget,
8049 for (l = window_list; l != NULL; l = l->next)
8051 GdkWindow *window = l->data;
8054 gdk_window_get_user_data (window, &user_data);
8055 if (user_data == widget)
8060 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8062 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8064 children = gdk_window_get_children (window);
8065 gtk_widget_add_events_internal_list (widget, device, events, children);
8066 g_list_free (children);
8072 gtk_widget_add_events_internal (GtkWidget *widget,
8078 if (!gtk_widget_get_has_window (widget))
8079 window_list = gdk_window_get_children (widget->window);
8081 window_list = g_list_prepend (NULL, widget->window);
8083 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8085 g_list_free (window_list);
8089 * gtk_widget_add_events:
8090 * @widget: a #GtkWidget
8091 * @events: an event mask, see #GdkEventMask
8093 * Adds the events in the bitfield @events to the event mask for
8094 * @widget. See gtk_widget_set_events() for details.
8097 gtk_widget_add_events (GtkWidget *widget,
8102 g_return_if_fail (GTK_IS_WIDGET (widget));
8104 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8105 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8106 GINT_TO_POINTER (old_events | events));
8108 if (gtk_widget_get_realized (widget))
8109 gtk_widget_add_events_internal (widget, NULL, events);
8111 g_object_notify (G_OBJECT (widget), "events");
8115 * gtk_widget_add_device_events:
8116 * @widget: a #GtkWidget
8117 * @device: a #GdkDevice
8118 * @events: an event mask, see #GdkEventMask
8120 * Adds the device events in the bitfield @events to the event mask for
8121 * @widget. See gtk_widget_set_device_events() for details.
8126 gtk_widget_add_device_events (GtkWidget *widget,
8128 GdkEventMask events)
8130 GdkEventMask old_events;
8131 GHashTable *device_events;
8133 g_return_if_fail (GTK_IS_WIDGET (widget));
8134 g_return_if_fail (GDK_IS_DEVICE (device));
8136 old_events = gtk_widget_get_device_events (widget, device);
8138 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8140 if (G_UNLIKELY (!device_events))
8142 device_events = g_hash_table_new (NULL, NULL);
8143 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8144 (GDestroyNotify) g_hash_table_unref);
8147 g_hash_table_insert (device_events, device,
8148 GUINT_TO_POINTER (old_events | events));
8150 if (gtk_widget_get_realized (widget))
8151 gtk_widget_add_events_internal (widget, device, events);
8153 g_object_notify (G_OBJECT (widget), "events");
8157 * gtk_widget_set_extension_events:
8158 * @widget: a #GtkWidget
8159 * @mode: bitfield of extension events to receive
8161 * Sets the extension events mask to @mode. See #GdkExtensionMode
8162 * and gdk_input_set_extension_events().
8165 gtk_widget_set_extension_events (GtkWidget *widget,
8166 GdkExtensionMode mode)
8168 g_return_if_fail (GTK_IS_WIDGET (widget));
8170 if (gtk_widget_get_realized (widget))
8171 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8173 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8174 GINT_TO_POINTER (mode));
8175 g_object_notify (G_OBJECT (widget), "extension-events");
8179 * gtk_widget_get_toplevel:
8180 * @widget: a #GtkWidget
8182 * This function returns the topmost widget in the container hierarchy
8183 * @widget is a part of. If @widget has no parent widgets, it will be
8184 * returned as the topmost widget. No reference will be added to the
8185 * returned widget; it should not be unreferenced.
8187 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8188 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8190 * %NULL if @widget wasn't inside a toplevel window, and if the
8191 * window was inside a #GtkWindow-derived widget which was in turn
8192 * inside the toplevel #GtkWindow. While the second case may
8193 * seem unlikely, it actually happens when a #GtkPlug is embedded
8194 * inside a #GtkSocket within the same application.
8196 * To reliably find the toplevel #GtkWindow, use
8197 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8198 * is set on the result.
8200 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8201 * if (gtk_widget_is_toplevel (toplevel))
8203 * /* Perform action on toplevel. */
8207 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8208 * if there's no ancestor.
8211 gtk_widget_get_toplevel (GtkWidget *widget)
8213 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8215 while (widget->parent)
8216 widget = widget->parent;
8222 * gtk_widget_get_ancestor:
8223 * @widget: a #GtkWidget
8224 * @widget_type: ancestor type
8226 * Gets the first ancestor of @widget with type @widget_type. For example,
8227 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8228 * the first #GtkBox that's an ancestor of @widget. No reference will be
8229 * added to the returned widget; it should not be unreferenced. See note
8230 * about checking for a toplevel #GtkWindow in the docs for
8231 * gtk_widget_get_toplevel().
8233 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8234 * considers @widget to be an ancestor of itself.
8236 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8239 gtk_widget_get_ancestor (GtkWidget *widget,
8242 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8244 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8245 widget = widget->parent;
8247 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8254 * gtk_widget_get_colormap:
8255 * @widget: a #GtkWidget
8257 * Gets the colormap that will be used to render @widget. No reference will
8258 * be added to the returned colormap; it should not be unreferenced.
8260 * Return value: (transfer none): the colormap used by @widget
8263 gtk_widget_get_colormap (GtkWidget *widget)
8265 GdkColormap *colormap;
8266 GtkWidget *tmp_widget;
8268 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8272 colormap = gdk_drawable_get_colormap (widget->window);
8273 /* If window was destroyed previously, we'll get NULL here */
8278 tmp_widget = widget;
8281 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8285 tmp_widget= tmp_widget->parent;
8288 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8292 * gtk_widget_get_visual:
8293 * @widget: a #GtkWidget
8295 * Gets the visual that will be used to render @widget.
8297 * Return value: (transfer none): the visual for @widget
8300 gtk_widget_get_visual (GtkWidget *widget)
8302 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8304 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8308 * gtk_widget_get_settings:
8309 * @widget: a #GtkWidget
8311 * Gets the settings object holding the settings (global property
8312 * settings, RC file information, etc) used for this widget.
8314 * Note that this function can only be called when the #GtkWidget
8315 * is attached to a toplevel, since the settings object is specific
8316 * to a particular #GdkScreen.
8318 * Return value: (transfer none): the relevant #GtkSettings object
8321 gtk_widget_get_settings (GtkWidget *widget)
8323 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8325 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8329 * gtk_widget_set_colormap:
8330 * @widget: a #GtkWidget
8331 * @colormap: a colormap
8333 * Sets the colormap for the widget to the given value. Widget must not
8334 * have been previously realized. This probably should only be used
8335 * from an <function>init()</function> function (i.e. from the constructor
8339 gtk_widget_set_colormap (GtkWidget *widget,
8340 GdkColormap *colormap)
8342 g_return_if_fail (GTK_IS_WIDGET (widget));
8343 g_return_if_fail (!gtk_widget_get_realized (widget));
8344 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8346 g_object_ref (colormap);
8348 g_object_set_qdata_full (G_OBJECT (widget),
8355 * gtk_widget_get_events:
8356 * @widget: a #GtkWidget
8358 * Returns the event mask for the widget (a bitfield containing flags
8359 * from the #GdkEventMask enumeration). These are the events that the widget
8362 * Return value: event mask for @widget
8365 gtk_widget_get_events (GtkWidget *widget)
8367 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8369 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8373 * gtk_widget_get_device_events:
8374 * @widget: a #GtkWidget
8375 * @device: a #GdkDevice
8377 * Returns the events mask for the widget corresponding to an specific device. These
8378 * are the events that the widget will receive when @device operates on it.
8380 * Returns: device event mask for @widget
8385 gtk_widget_get_device_events (GtkWidget *widget,
8388 GHashTable *device_events;
8390 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8391 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8393 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8398 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8402 * gtk_widget_get_extension_events:
8403 * @widget: a #GtkWidget
8405 * Retrieves the extension events the widget will receive; see
8406 * gdk_input_set_extension_events().
8408 * Return value: extension events for @widget
8411 gtk_widget_get_extension_events (GtkWidget *widget)
8413 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8415 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8419 * gtk_widget_get_pointer:
8420 * @widget: a #GtkWidget
8421 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8422 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8424 * Obtains the location of the mouse pointer in widget coordinates.
8425 * Widget coordinates are a bit odd; for historical reasons, they are
8426 * defined as @widget->window coordinates for widgets that are not
8427 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8428 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8431 gtk_widget_get_pointer (GtkWidget *widget,
8435 g_return_if_fail (GTK_IS_WIDGET (widget));
8442 if (gtk_widget_get_realized (widget))
8444 gdk_window_get_pointer (widget->window, x, y, NULL);
8446 if (!gtk_widget_get_has_window (widget))
8449 *x -= widget->allocation.x;
8451 *y -= widget->allocation.y;
8457 * gtk_widget_is_ancestor:
8458 * @widget: a #GtkWidget
8459 * @ancestor: another #GtkWidget
8461 * Determines whether @widget is somewhere inside @ancestor, possibly with
8462 * intermediate containers.
8464 * Return value: %TRUE if @ancestor contains @widget as a child,
8465 * grandchild, great grandchild, etc.
8468 gtk_widget_is_ancestor (GtkWidget *widget,
8469 GtkWidget *ancestor)
8471 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8472 g_return_val_if_fail (ancestor != NULL, FALSE);
8476 if (widget->parent == ancestor)
8478 widget = widget->parent;
8484 static GQuark quark_composite_name = 0;
8487 * gtk_widget_set_composite_name:
8488 * @widget: a #GtkWidget.
8489 * @name: the name to set
8491 * Sets a widgets composite name. The widget must be
8492 * a composite child of its parent; see gtk_widget_push_composite_child().
8495 gtk_widget_set_composite_name (GtkWidget *widget,
8498 g_return_if_fail (GTK_IS_WIDGET (widget));
8499 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8500 g_return_if_fail (name != NULL);
8502 if (!quark_composite_name)
8503 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8505 g_object_set_qdata_full (G_OBJECT (widget),
8506 quark_composite_name,
8512 * gtk_widget_get_composite_name:
8513 * @widget: a #GtkWidget
8515 * Obtains the composite name of a widget.
8517 * Returns: the composite name of @widget, or %NULL if @widget is not
8518 * a composite child. The string should be freed when it is no
8522 gtk_widget_get_composite_name (GtkWidget *widget)
8524 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8526 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8527 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8534 * gtk_widget_push_composite_child:
8536 * Makes all newly-created widgets as composite children until
8537 * the corresponding gtk_widget_pop_composite_child() call.
8539 * A composite child is a child that's an implementation detail of the
8540 * container it's inside and should not be visible to people using the
8541 * container. Composite children aren't treated differently by GTK (but
8542 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8543 * builders might want to treat them in a different way.
8545 * Here is a simple example:
8547 * gtk_widget_push_composite_child ();
8548 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8549 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8550 * gtk_widget_pop_composite_child ();
8551 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8552 * GTK_WIDGET (scrolled_window));
8553 * g_object_ref (scrolled_window->hscrollbar);
8557 gtk_widget_push_composite_child (void)
8559 composite_child_stack++;
8563 * gtk_widget_pop_composite_child:
8565 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8568 gtk_widget_pop_composite_child (void)
8570 if (composite_child_stack)
8571 composite_child_stack--;
8575 * gtk_widget_push_colormap:
8576 * @cmap: a #GdkColormap
8578 * Pushes @cmap onto a global stack of colormaps; the topmost
8579 * colormap on the stack will be used to create all widgets.
8580 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8581 * reason to use this function.
8584 gtk_widget_push_colormap (GdkColormap *cmap)
8586 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8588 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8592 * gtk_widget_pop_colormap:
8594 * Removes a colormap pushed with gtk_widget_push_colormap().
8597 gtk_widget_pop_colormap (void)
8600 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8604 * gtk_widget_set_default_colormap:
8605 * @colormap: a #GdkColormap
8607 * Sets the default colormap to use when creating widgets.
8608 * gtk_widget_push_colormap() is a better function to use if
8609 * you only want to affect a few widgets, rather than all widgets.
8612 gtk_widget_set_default_colormap (GdkColormap *colormap)
8614 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8616 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8621 * gtk_widget_get_default_colormap:
8623 * Obtains the default colormap used to create widgets.
8625 * Return value: (transfer none): default widget colormap
8628 gtk_widget_get_default_colormap (void)
8630 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8634 * gtk_widget_get_default_visual:
8636 * Obtains the visual of the default colormap. Not really useful;
8637 * used to be useful before gdk_colormap_get_visual() existed.
8639 * Return value: (transfer none): visual of the default colormap
8642 gtk_widget_get_default_visual (void)
8644 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8648 gtk_widget_emit_direction_changed (GtkWidget *widget,
8649 GtkTextDirection old_dir)
8651 gtk_widget_update_pango_context (widget);
8653 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8657 * gtk_widget_set_direction:
8658 * @widget: a #GtkWidget
8659 * @dir: the new direction
8661 * Sets the reading direction on a particular widget. This direction
8662 * controls the primary direction for widgets containing text,
8663 * and also the direction in which the children of a container are
8664 * packed. The ability to set the direction is present in order
8665 * so that correct localization into languages with right-to-left
8666 * reading directions can be done. Generally, applications will
8667 * let the default reading direction present, except for containers
8668 * where the containers are arranged in an order that is explicitely
8669 * visual rather than logical (such as buttons for text justification).
8671 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8672 * set by gtk_widget_set_default_direction() will be used.
8675 gtk_widget_set_direction (GtkWidget *widget,
8676 GtkTextDirection dir)
8678 GtkTextDirection old_dir;
8680 g_return_if_fail (GTK_IS_WIDGET (widget));
8681 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8683 old_dir = gtk_widget_get_direction (widget);
8685 if (dir == GTK_TEXT_DIR_NONE)
8686 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8689 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8690 if (dir == GTK_TEXT_DIR_LTR)
8691 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8693 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8696 if (old_dir != gtk_widget_get_direction (widget))
8697 gtk_widget_emit_direction_changed (widget, old_dir);
8701 * gtk_widget_get_direction:
8702 * @widget: a #GtkWidget
8704 * Gets the reading direction for a particular widget. See
8705 * gtk_widget_set_direction().
8707 * Return value: the reading direction for the widget.
8710 gtk_widget_get_direction (GtkWidget *widget)
8712 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8714 if (GTK_WIDGET_DIRECTION_SET (widget))
8715 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8717 return gtk_default_direction;
8721 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8723 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8725 g_object_ref (widget);
8727 if (!GTK_WIDGET_DIRECTION_SET (widget))
8728 gtk_widget_emit_direction_changed (widget, old_dir);
8730 if (GTK_IS_CONTAINER (widget))
8731 gtk_container_forall (GTK_CONTAINER (widget),
8732 gtk_widget_set_default_direction_recurse,
8735 g_object_unref (widget);
8739 * gtk_widget_set_default_direction:
8740 * @dir: the new default direction. This cannot be
8741 * %GTK_TEXT_DIR_NONE.
8743 * Sets the default reading direction for widgets where the
8744 * direction has not been explicitly set by gtk_widget_set_direction().
8747 gtk_widget_set_default_direction (GtkTextDirection dir)
8749 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8751 if (dir != gtk_default_direction)
8753 GList *toplevels, *tmp_list;
8754 GtkTextDirection old_dir = gtk_default_direction;
8756 gtk_default_direction = dir;
8758 tmp_list = toplevels = gtk_window_list_toplevels ();
8759 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8763 gtk_widget_set_default_direction_recurse (tmp_list->data,
8764 GUINT_TO_POINTER (old_dir));
8765 g_object_unref (tmp_list->data);
8766 tmp_list = tmp_list->next;
8769 g_list_free (toplevels);
8774 * gtk_widget_get_default_direction:
8776 * Obtains the current default reading direction. See
8777 * gtk_widget_set_default_direction().
8779 * Return value: the current default direction.
8782 gtk_widget_get_default_direction (void)
8784 return gtk_default_direction;
8788 gtk_widget_dispose (GObject *object)
8790 GtkWidget *widget = GTK_WIDGET (object);
8793 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8794 else if (gtk_widget_get_visible (widget))
8795 gtk_widget_hide (widget);
8797 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8798 if (gtk_widget_get_realized (widget))
8799 gtk_widget_unrealize (widget);
8801 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8805 gtk_widget_real_destroy (GtkObject *object)
8807 /* gtk_object_destroy() will already hold a refcount on object */
8808 GtkWidget *widget = GTK_WIDGET (object);
8810 /* wipe accelerator closures (keep order) */
8811 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8812 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8814 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8815 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8817 gtk_grab_remove (widget);
8819 g_object_unref (widget->style);
8820 widget->style = gtk_widget_get_default_style ();
8821 g_object_ref (widget->style);
8823 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8827 gtk_widget_finalize (GObject *object)
8829 GtkWidget *widget = GTK_WIDGET (object);
8830 GtkWidgetAuxInfo *aux_info;
8831 GtkAccessible *accessible;
8833 gtk_grab_remove (widget);
8835 g_object_unref (widget->style);
8836 widget->style = NULL;
8838 g_free (widget->name);
8840 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8842 gtk_widget_aux_info_destroy (aux_info);
8844 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8846 g_object_unref (accessible);
8848 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8851 /*****************************************
8852 * gtk_widget_real_map:
8857 *****************************************/
8860 gtk_widget_real_map (GtkWidget *widget)
8862 g_assert (gtk_widget_get_realized (widget));
8864 if (!gtk_widget_get_mapped (widget))
8866 gtk_widget_set_mapped (widget, TRUE);
8868 if (gtk_widget_get_has_window (widget))
8869 gdk_window_show (widget->window);
8873 /*****************************************
8874 * gtk_widget_real_unmap:
8879 *****************************************/
8882 gtk_widget_real_unmap (GtkWidget *widget)
8884 if (gtk_widget_get_mapped (widget))
8886 gtk_widget_set_mapped (widget, FALSE);
8888 if (gtk_widget_get_has_window (widget))
8889 gdk_window_hide (widget->window);
8893 /*****************************************
8894 * gtk_widget_real_realize:
8899 *****************************************/
8902 gtk_widget_real_realize (GtkWidget *widget)
8904 g_assert (!gtk_widget_get_has_window (widget));
8906 gtk_widget_set_realized (widget, TRUE);
8909 widget->window = gtk_widget_get_parent_window (widget);
8910 g_object_ref (widget->window);
8912 widget->style = gtk_style_attach (widget->style, widget->window);
8915 /*****************************************
8916 * gtk_widget_real_unrealize:
8921 *****************************************/
8924 gtk_widget_real_unrealize (GtkWidget *widget)
8926 if (gtk_widget_get_mapped (widget))
8927 gtk_widget_real_unmap (widget);
8929 gtk_widget_set_mapped (widget, FALSE);
8931 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8934 /* We must do unrealize child widget BEFORE container widget.
8935 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8936 * So, unrealizing container widget bofore its children causes the problem
8937 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8940 if (GTK_IS_CONTAINER (widget))
8941 gtk_container_forall (GTK_CONTAINER (widget),
8942 (GtkCallback) gtk_widget_unrealize,
8945 gtk_style_detach (widget->style);
8946 if (gtk_widget_get_has_window (widget))
8948 gdk_window_set_user_data (widget->window, NULL);
8949 gdk_window_destroy (widget->window);
8950 widget->window = NULL;
8954 g_object_unref (widget->window);
8955 widget->window = NULL;
8958 gtk_selection_remove_all (widget);
8960 gtk_widget_set_realized (widget, FALSE);
8964 gtk_widget_real_size_request (GtkWidget *widget,
8965 GtkRequisition *requisition)
8967 requisition->width = widget->requisition.width;
8968 requisition->height = widget->requisition.height;
8972 * _gtk_widget_peek_colormap:
8974 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8976 * Return value: the currently pushed colormap, or %NULL if there is none.
8979 _gtk_widget_peek_colormap (void)
8982 return (GdkColormap*) colormap_stack->data;
8987 * _gtk_widget_set_device_window:
8988 * @widget: a #GtkWidget.
8989 * @device: a #GdkDevice.
8990 * @window: the new device window.
8992 * Sets pointer window for @widget and @device. Does not ref @window.
8993 * Actually stores it on the #GdkScreen, but you don't need to know that.
8996 _gtk_widget_set_device_window (GtkWidget *widget,
9001 GHashTable *device_window;
9003 g_return_if_fail (GTK_IS_WIDGET (widget));
9004 g_return_if_fail (GDK_IS_DEVICE (device));
9005 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9007 if (!gtk_widget_get_realized (widget))
9010 screen = gdk_drawable_get_screen (widget->window);
9011 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9013 if (G_UNLIKELY (!device_window))
9015 device_window = g_hash_table_new (NULL, NULL);
9016 g_object_set_qdata_full (G_OBJECT (screen),
9017 quark_pointer_window,
9019 (GDestroyNotify) g_hash_table_destroy);
9023 g_hash_table_insert (device_window, device, window);
9025 g_hash_table_remove (device_window, device);
9029 * _gtk_widget_get_device_window:
9030 * @widget: a #GtkWidget.
9031 * @device: a #GdkDevice.
9033 * Return value: the device window set on the #GdkScreen @widget is attached
9037 _gtk_widget_get_device_window (GtkWidget *widget,
9041 GHashTable *device_window;
9045 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9046 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9048 if (!gtk_widget_get_realized (widget))
9051 screen = gdk_drawable_get_screen (widget->window);
9052 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9054 if (G_UNLIKELY (!device_window))
9057 window = g_hash_table_lookup (device_window, device);
9062 gdk_window_get_user_data (window, (gpointer *) &w);
9071 * _gtk_widget_list_devices:
9072 * @widget: a #GtkWidget.
9074 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9075 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9079 _gtk_widget_list_devices (GtkWidget *widget)
9082 GHashTableIter iter;
9083 GHashTable *device_window;
9084 GList *devices = NULL;
9085 gpointer key, value;
9087 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9089 if (!gtk_widget_get_realized (widget))
9092 screen = gdk_drawable_get_screen (widget->window);
9093 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9095 if (G_UNLIKELY (!device_window))
9098 g_hash_table_iter_init (&iter, device_window);
9100 while (g_hash_table_iter_next (&iter, &key, &value))
9102 GdkDevice *device = key;
9103 GdkWindow *window = value;
9108 gdk_window_get_user_data (window, (gpointer *) &w);
9111 devices = g_list_prepend (devices, device);
9119 synth_crossing (GtkWidget *widget,
9123 GdkCrossingMode mode,
9124 GdkNotifyType detail)
9128 event = gdk_event_new (type);
9130 event->crossing.window = g_object_ref (window);
9131 event->crossing.send_event = TRUE;
9132 event->crossing.subwindow = g_object_ref (window);
9133 event->crossing.time = GDK_CURRENT_TIME;
9134 event->crossing.x = event->crossing.y = 0;
9135 event->crossing.x_root = event->crossing.y_root = 0;
9136 event->crossing.mode = mode;
9137 event->crossing.detail = detail;
9138 event->crossing.focus = FALSE;
9139 event->crossing.state = 0;
9140 gdk_event_set_device (event, device);
9143 widget = gtk_get_event_widget (event);
9146 gtk_widget_event_internal (widget, event);
9148 gdk_event_free (event);
9152 * _gtk_widget_synthesize_crossing:
9153 * @from: the #GtkWidget the virtual pointer is leaving.
9154 * @to: the #GtkWidget the virtual pointer is moving to.
9155 * @mode: the #GdkCrossingMode to place on the synthesized events.
9157 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9159 * The real pointer window is the window that most recently received an enter notify
9160 * event. Windows that don't select for crossing events can't become the real
9161 * poiner window. The real pointer widget that owns the real pointer window. The
9162 * effective pointer window is the same as the real pointer window unless the real
9163 * pointer widget is either insensitive or there is a grab on a widget that is not
9164 * an ancestor of the real pointer widget (in which case the effective pointer
9165 * window should be the root window).
9167 * When the effective pointer window is the same as the real poiner window, we
9168 * receive crossing events from the windowing system. When the effective pointer
9169 * window changes to become different from the real pointer window we synthesize
9170 * crossing events, attempting to follow X protocol rules:
9172 * When the root window becomes the effective pointer window:
9173 * - leave notify on real pointer window, detail Ancestor
9174 * - leave notify on all of its ancestors, detail Virtual
9175 * - enter notify on root window, detail Inferior
9177 * When the root window ceases to be the effective pointer window:
9178 * - leave notify on root window, detail Inferior
9179 * - enter notify on all ancestors of real pointer window, detail Virtual
9180 * - enter notify on real pointer window, detail Ancestor
9183 _gtk_widget_synthesize_crossing (GtkWidget *from,
9186 GdkCrossingMode mode)
9188 GdkWindow *from_window = NULL, *to_window = NULL;
9190 g_return_if_fail (from != NULL || to != NULL);
9194 from_window = _gtk_widget_get_device_window (from, device);
9197 from_window = from->window;
9202 to_window = _gtk_widget_get_device_window (to, device);
9205 to_window = to->window;
9208 if (from_window == NULL && to_window == NULL)
9210 else if (from_window != NULL && to_window == NULL)
9212 GList *from_ancestors = NULL, *list;
9213 GdkWindow *from_ancestor = from_window;
9215 while (from_ancestor != NULL)
9217 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9218 if (from_ancestor == NULL)
9220 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9223 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9224 device, mode, GDK_NOTIFY_ANCESTOR);
9225 for (list = g_list_last (from_ancestors); list; list = list->prev)
9227 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9228 device, mode, GDK_NOTIFY_VIRTUAL);
9231 /* XXX: enter/inferior on root window? */
9233 g_list_free (from_ancestors);
9235 else if (from_window == NULL && to_window != NULL)
9237 GList *to_ancestors = NULL, *list;
9238 GdkWindow *to_ancestor = to_window;
9240 while (to_ancestor != NULL)
9242 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9243 if (to_ancestor == NULL)
9245 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9248 /* XXX: leave/inferior on root window? */
9250 for (list = to_ancestors; list; list = list->next)
9252 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9253 device, mode, GDK_NOTIFY_VIRTUAL);
9255 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9256 device, mode, GDK_NOTIFY_ANCESTOR);
9258 g_list_free (to_ancestors);
9260 else if (from_window == to_window)
9264 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9265 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9267 while (from_ancestor != NULL || to_ancestor != NULL)
9269 if (from_ancestor != NULL)
9271 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9272 if (from_ancestor == to_window)
9275 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9277 if (to_ancestor != NULL)
9279 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9280 if (to_ancestor == from_window)
9283 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9286 if (to_ancestor == from_window)
9288 if (mode != GDK_CROSSING_GTK_UNGRAB)
9289 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9290 device, mode, GDK_NOTIFY_INFERIOR);
9291 for (list = to_ancestors; list; list = list->next)
9292 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9293 device, mode, GDK_NOTIFY_VIRTUAL);
9294 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9295 device, mode, GDK_NOTIFY_ANCESTOR);
9297 else if (from_ancestor == to_window)
9299 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9300 device, mode, GDK_NOTIFY_ANCESTOR);
9301 for (list = g_list_last (from_ancestors); list; list = list->prev)
9303 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9304 device, mode, GDK_NOTIFY_VIRTUAL);
9306 if (mode != GDK_CROSSING_GTK_GRAB)
9307 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9308 device, mode, GDK_NOTIFY_INFERIOR);
9312 while (from_ancestors != NULL && to_ancestors != NULL
9313 && from_ancestors->data == to_ancestors->data)
9315 from_ancestors = g_list_delete_link (from_ancestors,
9317 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9320 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9321 device, mode, GDK_NOTIFY_NONLINEAR);
9323 for (list = g_list_last (from_ancestors); list; list = list->prev)
9325 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9326 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9328 for (list = to_ancestors; list; list = list->next)
9330 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9331 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9333 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9334 device, mode, GDK_NOTIFY_NONLINEAR);
9336 g_list_free (from_ancestors);
9337 g_list_free (to_ancestors);
9342 gtk_widget_propagate_state (GtkWidget *widget,
9345 guint8 old_state = gtk_widget_get_state (widget);
9346 guint8 old_saved_state = widget->saved_state;
9348 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9349 * parent_sensitive==TRUE on a sensitive widget
9353 if (data->parent_sensitive)
9354 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9356 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9358 if (gtk_widget_is_sensitive (widget))
9360 if (data->state_restoration)
9361 widget->state = widget->saved_state;
9363 widget->state = data->state;
9367 if (!data->state_restoration)
9369 if (data->state != GTK_STATE_INSENSITIVE)
9370 widget->saved_state = data->state;
9372 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9373 widget->saved_state = gtk_widget_get_state (widget);
9374 widget->state = GTK_STATE_INSENSITIVE;
9377 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9381 window = gtk_widget_get_toplevel (widget);
9382 if (window && gtk_widget_is_toplevel (window))
9383 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9386 if (old_state != gtk_widget_get_state (widget) ||
9387 old_saved_state != widget->saved_state)
9389 g_object_ref (widget);
9391 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9392 gtk_grab_remove (widget);
9394 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9396 if (!GTK_WIDGET_SHADOWED (widget))
9398 GList *event_windows = NULL;
9401 devices = _gtk_widget_list_devices (widget);
9403 for (d = devices; d; d = d->next)
9409 window = _gtk_widget_get_device_window (widget, device);
9411 /* Do not propagate more than once to the
9412 * same window if non-multidevice aware.
9414 if (!gdk_window_get_support_multidevice (window) &&
9415 g_list_find (event_windows, window))
9418 if (!gtk_widget_is_sensitive (widget))
9419 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9420 GDK_CROSSING_STATE_CHANGED);
9421 else if (old_state == GTK_STATE_INSENSITIVE)
9422 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9423 GDK_CROSSING_STATE_CHANGED);
9425 event_windows = g_list_prepend (event_windows, window);
9428 g_list_free (event_windows);
9429 g_list_free (devices);
9432 if (GTK_IS_CONTAINER (widget))
9434 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9435 if (data->use_forall)
9436 gtk_container_forall (GTK_CONTAINER (widget),
9437 (GtkCallback) gtk_widget_propagate_state,
9440 gtk_container_foreach (GTK_CONTAINER (widget),
9441 (GtkCallback) gtk_widget_propagate_state,
9444 g_object_unref (widget);
9449 * _gtk_widget_get_aux_info:
9450 * @widget: a #GtkWidget
9451 * @create: if %TRUE, create the structure if it doesn't exist
9453 * Get the #GtkWidgetAuxInfo structure for the widget.
9455 * Return value: the #GtkAuxInfo structure for the widget, or
9456 * %NULL if @create is %FALSE and one doesn't already exist.
9459 _gtk_widget_get_aux_info (GtkWidget *widget,
9462 GtkWidgetAuxInfo *aux_info;
9464 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9465 if (!aux_info && create)
9467 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9469 aux_info->width = -1;
9470 aux_info->height = -1;
9472 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9479 /*****************************************
9480 * gtk_widget_aux_info_destroy:
9485 *****************************************/
9488 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9490 g_slice_free (GtkWidgetAuxInfo, aux_info);
9494 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9496 g_object_unref (info->shape_mask);
9497 g_slice_free (GtkWidgetShapeInfo, info);
9501 * gtk_widget_shape_combine_mask:
9502 * @widget: a #GtkWidget
9503 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9504 * @offset_x: X position of shape mask with respect to @window
9505 * @offset_y: Y position of shape mask with respect to @window
9507 * Sets a shape for this widget's GDK window. This allows for
9508 * transparent windows etc., see gdk_window_shape_combine_mask()
9509 * for more information.
9512 gtk_widget_shape_combine_mask (GtkWidget *widget,
9513 GdkBitmap *shape_mask,
9517 GtkWidgetShapeInfo* shape_info;
9519 g_return_if_fail (GTK_IS_WIDGET (widget));
9520 /* set_shape doesn't work on widgets without gdk window */
9521 g_return_if_fail (gtk_widget_get_has_window (widget));
9525 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9528 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9530 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9534 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9536 shape_info = g_slice_new (GtkWidgetShapeInfo);
9537 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9538 (GDestroyNotify) gtk_widget_shape_info_destroy);
9540 shape_info->shape_mask = g_object_ref (shape_mask);
9541 shape_info->offset_x = offset_x;
9542 shape_info->offset_y = offset_y;
9544 /* set shape if widget has a gdk window already.
9545 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9548 gdk_window_shape_combine_mask (widget->window, shape_mask,
9549 offset_x, offset_y);
9554 * gtk_widget_input_shape_combine_mask:
9555 * @widget: a #GtkWidget
9556 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9557 * @offset_x: X position of shape mask with respect to @window
9558 * @offset_y: Y position of shape mask with respect to @window
9560 * Sets an input shape for this widget's GDK window. This allows for
9561 * windows which react to mouse click in a nonrectangular region, see
9562 * gdk_window_input_shape_combine_mask() for more information.
9567 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9568 GdkBitmap *shape_mask,
9572 GtkWidgetShapeInfo* shape_info;
9574 g_return_if_fail (GTK_IS_WIDGET (widget));
9575 /* set_shape doesn't work on widgets without gdk window */
9576 g_return_if_fail (gtk_widget_get_has_window (widget));
9581 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9583 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9587 shape_info = g_slice_new (GtkWidgetShapeInfo);
9588 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9590 (GDestroyNotify) gtk_widget_shape_info_destroy);
9592 shape_info->shape_mask = g_object_ref (shape_mask);
9593 shape_info->offset_x = offset_x;
9594 shape_info->offset_y = offset_y;
9596 /* set shape if widget has a gdk window already.
9597 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9600 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9601 offset_x, offset_y);
9607 gtk_reset_shapes_recurse (GtkWidget *widget,
9613 gdk_window_get_user_data (window, &data);
9617 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9618 for (list = gdk_window_peek_children (window); list; list = list->next)
9619 gtk_reset_shapes_recurse (widget, list->data);
9623 * gtk_widget_reset_shapes:
9624 * @widget: a #GtkWidget
9626 * Recursively resets the shape on this widget and its descendants.
9629 gtk_widget_reset_shapes (GtkWidget *widget)
9631 g_return_if_fail (GTK_IS_WIDGET (widget));
9632 g_return_if_fail (gtk_widget_get_realized (widget));
9634 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9635 gtk_reset_shapes_recurse (widget, widget->window);
9639 expose_window (GdkWindow *window)
9642 GList *l, *children;
9644 gboolean is_double_buffered;
9646 gdk_window_get_user_data (window, &user_data);
9649 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9651 is_double_buffered = FALSE;
9653 event.expose.type = GDK_EXPOSE;
9654 event.expose.window = g_object_ref (window);
9655 event.expose.send_event = FALSE;
9656 event.expose.count = 0;
9657 event.expose.area.x = 0;
9658 event.expose.area.y = 0;
9659 gdk_drawable_get_size (GDK_DRAWABLE (window),
9660 &event.expose.area.width,
9661 &event.expose.area.height);
9662 event.expose.region = cairo_region_create_rectangle (&event.expose.area);
9664 /* If this is not double buffered, force a double buffer so that
9665 redirection works. */
9666 if (!is_double_buffered)
9667 gdk_window_begin_paint_region (window, event.expose.region);
9669 gtk_main_do_event (&event);
9671 if (!is_double_buffered)
9672 gdk_window_end_paint (window);
9674 children = gdk_window_peek_children (window);
9675 for (l = children; l != NULL; l = l->next)
9677 GdkWindow *child = l->data;
9679 /* Don't expose input-only windows */
9680 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9681 expose_window (l->data);
9684 g_object_unref (window);
9688 * gtk_widget_get_snapshot:
9689 * @widget: a #GtkWidget
9690 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9692 * Create a #GdkPixmap of the contents of the widget and its children.
9694 * Works even if the widget is obscured. The depth and visual of the
9695 * resulting pixmap is dependent on the widget being snapshot and likely
9696 * differs from those of a target widget displaying the pixmap.
9697 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9698 * the pixmap to a visual independant representation.
9700 * The snapshot area used by this function is the @widget's allocation plus
9701 * any extra space occupied by additional windows belonging to this widget
9702 * (such as the arrows of a spin button).
9703 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9705 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9706 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9707 * interpreted widget relative. If width or height of @clip_rect are 0 or
9708 * negative, the width or height of the resulting pixmap will be shrunken
9709 * by the respective amount.
9710 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9711 * chop off 5 pixels at each side of the snapshot pixmap.
9712 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9713 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9714 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9715 * as a pure output parameter.
9717 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9719 * Return value: #GdkPixmap snapshot of the widget
9724 gtk_widget_get_snapshot (GtkWidget *widget,
9725 GdkRectangle *clip_rect)
9727 int x, y, width, height;
9728 GdkWindow *parent_window = NULL;
9730 GList *windows = NULL, *list;
9732 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9733 if (!gtk_widget_get_visible (widget))
9736 /* the widget (and parent_window) must be realized to be drawable */
9737 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9738 gtk_widget_realize (widget->parent);
9739 if (!gtk_widget_get_realized (widget))
9740 gtk_widget_realize (widget);
9742 /* determine snapshot rectangle */
9743 x = widget->allocation.x;
9744 y = widget->allocation.y;
9745 width = widget->allocation.width;
9746 height = widget->allocation.height;
9748 if (widget->parent && gtk_widget_get_has_window (widget))
9750 /* grow snapshot rectangle to cover all widget windows */
9751 parent_window = gtk_widget_get_parent_window (widget);
9752 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9754 GdkWindow *subwin = list->data;
9757 gdk_window_get_user_data (subwin, &windata);
9758 if (windata != widget)
9760 windows = g_list_prepend (windows, subwin);
9761 gdk_window_get_position (subwin, &wx, &wy);
9762 gdk_drawable_get_size (subwin, &ww, &wh);
9763 /* grow snapshot rectangle by extra widget sub window */
9774 if (x + width < wx + ww)
9775 width += wx + ww - (x + width);
9776 if (y + height < wy + wh)
9777 height += wy + wh - (y + height);
9780 else if (!widget->parent)
9781 x = y = 0; /* toplevel */
9783 /* at this point, (x,y,width,height) is the parent_window relative
9784 * snapshot area covering all of widget's windows.
9787 /* shrink snapshot size by clip_rectangle */
9790 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9791 clip.x = clip.x < 0 ? x : clip.x;
9792 clip.y = clip.y < 0 ? y : clip.y;
9793 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9794 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9797 /* offset clip_rect, so it's parent_window relative */
9798 if (clip_rect->x >= 0)
9799 clip.x += widget->allocation.x;
9800 if (clip_rect->y >= 0)
9801 clip.y += widget->allocation.y;
9803 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9805 g_list_free (windows);
9806 clip_rect->width = clip_rect->height = 0;
9807 return NULL; /* empty snapshot area */
9812 height = snap.height;
9815 /* render snapshot */
9816 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9817 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9819 GdkWindow *subwin = list->data;
9821 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9822 continue; /* Input only window */
9823 gdk_window_get_position (subwin, &wx, &wy);
9824 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9825 MAX (0, wx - x), MAX (0, wy - y), width, height);
9827 expose_window (subwin);
9829 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9831 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9832 expose_window (widget->window);
9834 for (list = windows; list; list = list->next)
9835 gdk_window_remove_redirection (list->data);
9836 if (!windows) /* NO_WINDOW || toplevel */
9837 gdk_window_remove_redirection (widget->window);
9838 g_list_free (windows);
9840 /* return pixmap and snapshot rectangle coordinates */
9845 clip_rect->width = width;
9846 clip_rect->height = height;
9849 /* offset clip_rect from parent_window so it's widget relative */
9850 clip_rect->x -= widget->allocation.x;
9851 clip_rect->y -= widget->allocation.y;
9854 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9855 G_OBJECT_TYPE_NAME (widget),
9856 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9865 * gtk_widget_class_install_style_property_parser:
9866 * @klass: a #GtkWidgetClass
9867 * @pspec: the #GParamSpec for the style property
9868 * @parser: the parser for the style property
9870 * Installs a style property on a widget class.
9873 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9875 GtkRcPropertyParser parser)
9877 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9878 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9879 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9880 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9882 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9884 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9885 G_OBJECT_CLASS_NAME (klass),
9890 g_param_spec_ref_sink (pspec);
9891 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9892 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9896 * gtk_widget_class_install_style_property:
9897 * @klass: a #GtkWidgetClass
9898 * @pspec: the #GParamSpec for the property
9900 * Installs a style property on a widget class. The parser for the
9901 * style property is determined by the value type of @pspec.
9904 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9907 GtkRcPropertyParser parser;
9909 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9910 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9912 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9914 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9918 * gtk_widget_class_find_style_property:
9919 * @klass: a #GtkWidgetClass
9920 * @property_name: the name of the style property to find
9921 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9922 * style property with that name.
9924 * Finds a style property of a widget class by name.
9929 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9930 const gchar *property_name)
9932 g_return_val_if_fail (property_name != NULL, NULL);
9934 return g_param_spec_pool_lookup (style_property_spec_pool,
9936 G_OBJECT_CLASS_TYPE (klass),
9941 * gtk_widget_class_list_style_properties:
9942 * @klass: a #GtkWidgetClass
9943 * @n_properties: location to return the number of style properties found
9944 * @returns: an newly allocated array of #GParamSpec*. The array must
9945 * be freed with g_free().
9947 * Returns all style properties of a widget class.
9952 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9953 guint *n_properties)
9955 GParamSpec **pspecs;
9958 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9959 G_OBJECT_CLASS_TYPE (klass),
9968 * gtk_widget_style_get_property:
9969 * @widget: a #GtkWidget
9970 * @property_name: the name of a style property
9971 * @value: location to return the property value
9973 * Gets the value of a style property of @widget.
9976 gtk_widget_style_get_property (GtkWidget *widget,
9977 const gchar *property_name,
9982 g_return_if_fail (GTK_IS_WIDGET (widget));
9983 g_return_if_fail (property_name != NULL);
9984 g_return_if_fail (G_IS_VALUE (value));
9986 g_object_ref (widget);
9987 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9989 G_OBJECT_TYPE (widget),
9992 g_warning ("%s: widget class `%s' has no property named `%s'",
9994 G_OBJECT_TYPE_NAME (widget),
9998 const GValue *peek_value;
10000 peek_value = _gtk_style_peek_property_value (widget->style,
10001 G_OBJECT_TYPE (widget),
10003 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10005 /* auto-conversion of the caller's value type
10007 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10008 g_value_copy (peek_value, value);
10009 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10010 g_value_transform (peek_value, value);
10012 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10014 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10015 G_VALUE_TYPE_NAME (value));
10017 g_object_unref (widget);
10021 * gtk_widget_style_get_valist:
10022 * @widget: a #GtkWidget
10023 * @first_property_name: the name of the first property to get
10024 * @var_args: a <type>va_list</type> of pairs of property names and
10025 * locations to return the property values, starting with the location
10026 * for @first_property_name.
10028 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10032 gtk_widget_style_get_valist (GtkWidget *widget,
10033 const gchar *first_property_name,
10038 g_return_if_fail (GTK_IS_WIDGET (widget));
10040 g_object_ref (widget);
10042 name = first_property_name;
10045 const GValue *peek_value;
10049 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10051 G_OBJECT_TYPE (widget),
10055 g_warning ("%s: widget class `%s' has no property named `%s'",
10057 G_OBJECT_TYPE_NAME (widget),
10061 /* style pspecs are always readable so we can spare that check here */
10063 peek_value = _gtk_style_peek_property_value (widget->style,
10064 G_OBJECT_TYPE (widget),
10066 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10067 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10070 g_warning ("%s: %s", G_STRLOC, error);
10075 name = va_arg (var_args, gchar*);
10078 g_object_unref (widget);
10082 * gtk_widget_style_get:
10083 * @widget: a #GtkWidget
10084 * @first_property_name: the name of the first property to get
10085 * @Varargs: pairs of property names and locations to
10086 * return the property values, starting with the location for
10087 * @first_property_name, terminated by %NULL.
10089 * Gets the values of a multiple style properties of @widget.
10092 gtk_widget_style_get (GtkWidget *widget,
10093 const gchar *first_property_name,
10098 g_return_if_fail (GTK_IS_WIDGET (widget));
10100 va_start (var_args, first_property_name);
10101 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10107 * @widget: a #GtkWidget
10108 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10109 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10110 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10112 * Obtains the full path to @widget. The path is simply the name of a
10113 * widget and all its parents in the container hierarchy, separated by
10114 * periods. The name of a widget comes from
10115 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10116 * in gtkrc configuration files. Widget names are the type of the
10117 * widget by default (e.g. "GtkButton") or can be set to an
10118 * application-specific value with gtk_widget_set_name(). By setting
10119 * the name of a widget, you allow users or theme authors to apply
10120 * styles to that specific widget in their gtkrc
10121 * file. @path_reversed_p fills in the path in reverse order,
10122 * i.e. starting with @widget's name instead of starting with the name
10123 * of @widget's outermost ancestor.
10126 gtk_widget_path (GtkWidget *widget,
10127 guint *path_length,
10129 gchar **path_reversed)
10131 static gchar *rev_path = NULL;
10132 static guint tmp_path_len = 0;
10135 g_return_if_fail (GTK_IS_WIDGET (widget));
10140 const gchar *string;
10145 string = gtk_widget_get_name (widget);
10146 l = strlen (string);
10147 while (tmp_path_len <= len + l + 1)
10149 tmp_path_len += INIT_PATH_SIZE;
10150 rev_path = g_realloc (rev_path, tmp_path_len);
10152 s = string + l - 1;
10153 d = rev_path + len;
10154 while (s >= string)
10158 widget = widget->parent;
10161 rev_path[len++] = '.';
10163 rev_path[len++] = 0;
10168 *path_length = len - 1;
10170 *path_reversed = g_strdup (rev_path);
10173 *path = g_strdup (rev_path);
10174 g_strreverse (*path);
10179 * gtk_widget_class_path:
10180 * @widget: a #GtkWidget
10181 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10182 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10183 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10186 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10187 * never uses a custom name set with gtk_widget_set_name().
10191 gtk_widget_class_path (GtkWidget *widget,
10192 guint *path_length,
10194 gchar **path_reversed)
10196 static gchar *rev_path = NULL;
10197 static guint tmp_path_len = 0;
10200 g_return_if_fail (GTK_IS_WIDGET (widget));
10205 const gchar *string;
10210 string = g_type_name (G_OBJECT_TYPE (widget));
10211 l = strlen (string);
10212 while (tmp_path_len <= len + l + 1)
10214 tmp_path_len += INIT_PATH_SIZE;
10215 rev_path = g_realloc (rev_path, tmp_path_len);
10217 s = string + l - 1;
10218 d = rev_path + len;
10219 while (s >= string)
10223 widget = widget->parent;
10226 rev_path[len++] = '.';
10228 rev_path[len++] = 0;
10233 *path_length = len - 1;
10235 *path_reversed = g_strdup (rev_path);
10238 *path = g_strdup (rev_path);
10239 g_strreverse (*path);
10244 * gtk_requisition_copy:
10245 * @requisition: a #GtkRequisition
10247 * Copies a #GtkRequisition.
10249 * Returns: a copy of @requisition
10252 gtk_requisition_copy (const GtkRequisition *requisition)
10254 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10258 * gtk_requisition_free:
10259 * @requisition: a #GtkRequisition
10261 * Frees a #GtkRequisition.
10264 gtk_requisition_free (GtkRequisition *requisition)
10266 g_free (requisition);
10270 gtk_requisition_get_type (void)
10272 static GType our_type = 0;
10275 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10276 (GBoxedCopyFunc) gtk_requisition_copy,
10277 (GBoxedFreeFunc) gtk_requisition_free);
10283 * gtk_widget_get_accessible:
10284 * @widget: a #GtkWidget
10286 * Returns the accessible object that describes the widget to an
10287 * assistive technology.
10289 * If no accessibility library is loaded (i.e. no ATK implementation library is
10290 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10291 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10292 * if no class-specific #AtkObject implementation is available for the widget
10293 * instance in question, it will inherit an #AtkObject implementation from the
10294 * first ancestor class for which such an implementation is defined.
10296 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10297 * library contains more information about accessible objects and their uses.
10299 * Returns: (transfer none): the #AtkObject associated with @widget
10302 gtk_widget_get_accessible (GtkWidget *widget)
10304 GtkWidgetClass *klass;
10306 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10308 klass = GTK_WIDGET_GET_CLASS (widget);
10310 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10312 return klass->get_accessible (widget);
10316 gtk_widget_real_get_accessible (GtkWidget *widget)
10318 AtkObject* accessible;
10320 accessible = g_object_get_qdata (G_OBJECT (widget),
10321 quark_accessible_object);
10324 AtkObjectFactory *factory;
10325 AtkRegistry *default_registry;
10327 default_registry = atk_get_default_registry ();
10328 factory = atk_registry_get_factory (default_registry,
10329 G_TYPE_FROM_INSTANCE (widget));
10331 atk_object_factory_create_accessible (factory,
10332 G_OBJECT (widget));
10333 g_object_set_qdata (G_OBJECT (widget),
10334 quark_accessible_object,
10341 * Initialize a AtkImplementorIface instance's virtual pointers as
10342 * appropriate to this implementor's class (GtkWidget).
10345 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10347 iface->ref_accessible = gtk_widget_ref_accessible;
10351 gtk_widget_ref_accessible (AtkImplementor *implementor)
10353 AtkObject *accessible;
10355 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10357 g_object_ref (accessible);
10362 * GtkBuildable implementation
10364 static GQuark quark_builder_has_default = 0;
10365 static GQuark quark_builder_has_focus = 0;
10366 static GQuark quark_builder_atk_relations = 0;
10367 static GQuark quark_builder_set_name = 0;
10370 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10372 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10373 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10374 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10375 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10377 iface->set_name = gtk_widget_buildable_set_name;
10378 iface->get_name = gtk_widget_buildable_get_name;
10379 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10380 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10381 iface->parser_finished = gtk_widget_buildable_parser_finished;
10382 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10383 iface->custom_finished = gtk_widget_buildable_custom_finished;
10387 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10390 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10391 g_strdup (name), g_free);
10394 static const gchar *
10395 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10397 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10401 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10402 GtkBuilder *builder,
10403 const gchar *childname)
10405 if (strcmp (childname, "accessible") == 0)
10406 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10412 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10413 GtkBuilder *builder,
10415 const GValue *value)
10417 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10418 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10419 GINT_TO_POINTER (TRUE));
10420 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10421 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10422 GINT_TO_POINTER (TRUE));
10424 g_object_set_property (G_OBJECT (buildable), name, value);
10429 gchar *action_name;
10430 GString *description;
10432 gboolean translatable;
10442 free_action (AtkActionData *data, gpointer user_data)
10444 g_free (data->action_name);
10445 g_string_free (data->description, TRUE);
10446 g_free (data->context);
10447 g_slice_free (AtkActionData, data);
10451 free_relation (AtkRelationData *data, gpointer user_data)
10453 g_free (data->target);
10454 g_free (data->type);
10455 g_slice_free (AtkRelationData, data);
10459 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10460 GtkBuilder *builder)
10462 GSList *atk_relations;
10464 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10465 gtk_widget_grab_default (GTK_WIDGET (buildable));
10466 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10467 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10469 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10470 quark_builder_atk_relations);
10473 AtkObject *accessible;
10474 AtkRelationSet *relation_set;
10477 AtkRelationType relation_type;
10478 AtkObject *target_accessible;
10480 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10481 relation_set = atk_object_ref_relation_set (accessible);
10483 for (l = atk_relations; l; l = l->next)
10485 AtkRelationData *relation = (AtkRelationData*)l->data;
10487 target = gtk_builder_get_object (builder, relation->target);
10490 g_warning ("Target object %s in <relation> does not exist",
10494 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10495 g_assert (target_accessible != NULL);
10497 relation_type = atk_relation_type_for_name (relation->type);
10498 if (relation_type == ATK_RELATION_NULL)
10500 g_warning ("<relation> type %s not found",
10504 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10505 target_accessible);
10507 g_object_unref (relation_set);
10509 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10510 g_slist_free (atk_relations);
10511 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10520 } AccessibilitySubParserData;
10523 accessibility_start_element (GMarkupParseContext *context,
10524 const gchar *element_name,
10525 const gchar **names,
10526 const gchar **values,
10527 gpointer user_data,
10530 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10532 gint line_number, char_number;
10534 if (strcmp (element_name, "relation") == 0)
10536 gchar *target = NULL;
10537 gchar *type = NULL;
10538 AtkRelationData *relation;
10540 for (i = 0; names[i]; i++)
10542 if (strcmp (names[i], "target") == 0)
10543 target = g_strdup (values[i]);
10544 else if (strcmp (names[i], "type") == 0)
10545 type = g_strdup (values[i]);
10548 g_markup_parse_context_get_position (context,
10551 g_set_error (error,
10553 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10554 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10556 line_number, char_number, names[i], "relation");
10563 if (!target || !type)
10565 g_markup_parse_context_get_position (context,
10568 g_set_error (error,
10570 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10571 "%s:%d:%d <%s> requires attribute \"%s\"",
10573 line_number, char_number, "relation",
10574 type ? "target" : "type");
10580 relation = g_slice_new (AtkRelationData);
10581 relation->target = target;
10582 relation->type = type;
10584 data->relations = g_slist_prepend (data->relations, relation);
10586 else if (strcmp (element_name, "action") == 0)
10588 const gchar *action_name = NULL;
10589 const gchar *description = NULL;
10590 const gchar *msg_context = NULL;
10591 gboolean translatable = FALSE;
10592 AtkActionData *action;
10594 for (i = 0; names[i]; i++)
10596 if (strcmp (names[i], "action_name") == 0)
10597 action_name = values[i];
10598 else if (strcmp (names[i], "description") == 0)
10599 description = values[i];
10600 else if (strcmp (names[i], "translatable") == 0)
10602 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10605 else if (strcmp (names[i], "comments") == 0)
10607 /* do nothing, comments are for translators */
10609 else if (strcmp (names[i], "context") == 0)
10610 msg_context = values[i];
10613 g_markup_parse_context_get_position (context,
10616 g_set_error (error,
10618 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10619 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10621 line_number, char_number, names[i], "action");
10628 g_markup_parse_context_get_position (context,
10631 g_set_error (error,
10633 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10634 "%s:%d:%d <%s> requires attribute \"%s\"",
10636 line_number, char_number, "action",
10641 action = g_slice_new (AtkActionData);
10642 action->action_name = g_strdup (action_name);
10643 action->description = g_string_new (description);
10644 action->context = g_strdup (msg_context);
10645 action->translatable = translatable;
10647 data->actions = g_slist_prepend (data->actions, action);
10649 else if (strcmp (element_name, "accessibility") == 0)
10652 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10656 accessibility_text (GMarkupParseContext *context,
10659 gpointer user_data,
10662 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10664 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10666 AtkActionData *action = data->actions->data;
10668 g_string_append_len (action->description, text, text_len);
10672 static const GMarkupParser accessibility_parser =
10674 accessibility_start_element,
10676 accessibility_text,
10685 } AccelGroupParserData;
10688 accel_group_start_element (GMarkupParseContext *context,
10689 const gchar *element_name,
10690 const gchar **names,
10691 const gchar **values,
10692 gpointer user_data,
10697 guint modifiers = 0;
10698 gchar *signal = NULL;
10699 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10701 for (i = 0; names[i]; i++)
10703 if (strcmp (names[i], "key") == 0)
10704 key = gdk_keyval_from_name (values[i]);
10705 else if (strcmp (names[i], "modifiers") == 0)
10707 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10713 else if (strcmp (names[i], "signal") == 0)
10714 signal = g_strdup (values[i]);
10717 if (key == 0 || signal == NULL)
10719 g_warning ("<accelerator> requires key and signal attributes");
10722 parser_data->key = key;
10723 parser_data->modifiers = modifiers;
10724 parser_data->signal = signal;
10727 static const GMarkupParser accel_group_parser =
10729 accel_group_start_element,
10733 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10734 GtkBuilder *builder,
10736 const gchar *tagname,
10737 GMarkupParser *parser,
10740 g_assert (buildable);
10742 if (strcmp (tagname, "accelerator") == 0)
10744 AccelGroupParserData *parser_data;
10746 parser_data = g_slice_new0 (AccelGroupParserData);
10747 parser_data->object = g_object_ref (buildable);
10748 *parser = accel_group_parser;
10749 *data = parser_data;
10752 if (strcmp (tagname, "accessibility") == 0)
10754 AccessibilitySubParserData *parser_data;
10756 parser_data = g_slice_new0 (AccessibilitySubParserData);
10757 *parser = accessibility_parser;
10758 *data = parser_data;
10765 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10766 GtkWidget *toplevel,
10767 gpointer user_data)
10769 AccelGroupParserData *accel_data;
10770 GSList *accel_groups;
10771 GtkAccelGroup *accel_group;
10773 g_return_if_fail (GTK_IS_WIDGET (widget));
10774 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10775 g_return_if_fail (user_data != NULL);
10777 accel_data = (AccelGroupParserData*)user_data;
10778 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10779 if (g_slist_length (accel_groups) == 0)
10781 accel_group = gtk_accel_group_new ();
10782 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10786 g_assert (g_slist_length (accel_groups) == 1);
10787 accel_group = g_slist_nth_data (accel_groups, 0);
10790 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10791 accel_data->signal,
10794 accel_data->modifiers,
10795 GTK_ACCEL_VISIBLE);
10797 g_object_unref (accel_data->object);
10798 g_free (accel_data->signal);
10799 g_slice_free (AccelGroupParserData, accel_data);
10803 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10804 GtkBuilder *builder,
10806 const gchar *tagname,
10807 gpointer user_data)
10809 AccelGroupParserData *accel_data;
10810 AccessibilitySubParserData *a11y_data;
10811 GtkWidget *toplevel;
10813 if (strcmp (tagname, "accelerator") == 0)
10815 accel_data = (AccelGroupParserData*)user_data;
10816 g_assert (accel_data->object);
10818 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10820 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10822 else if (strcmp (tagname, "accessibility") == 0)
10824 a11y_data = (AccessibilitySubParserData*)user_data;
10826 if (a11y_data->actions)
10828 AtkObject *accessible;
10833 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10835 action = ATK_ACTION (accessible);
10836 n_actions = atk_action_get_n_actions (action);
10838 for (l = a11y_data->actions; l; l = l->next)
10840 AtkActionData *action_data = (AtkActionData*)l->data;
10842 for (i = 0; i < n_actions; i++)
10843 if (strcmp (atk_action_get_name (action, i),
10844 action_data->action_name) == 0)
10849 gchar *description;
10851 if (action_data->translatable && action_data->description->len)
10852 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10853 action_data->context,
10854 action_data->description->str);
10856 description = action_data->description->str;
10858 atk_action_set_description (action, i, description);
10862 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10863 g_slist_free (a11y_data->actions);
10866 if (a11y_data->relations)
10867 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10868 a11y_data->relations);
10870 g_slice_free (AccessibilitySubParserData, a11y_data);
10875 * GtkSizeRequest implementation
10878 gtk_widget_real_get_width (GtkSizeRequest *widget,
10879 gint *minimum_size,
10880 gint *natural_size)
10882 /* Set the initial values so that unimplemented classes will fall back
10883 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10886 *minimum_size = GTK_WIDGET (widget)->requisition.width;
10889 *natural_size = GTK_WIDGET (widget)->requisition.width;
10893 gtk_widget_real_get_height (GtkSizeRequest *widget,
10894 gint *minimum_size,
10895 gint *natural_size)
10897 /* Set the initial values so that unimplemented classes will fall back
10898 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10901 *minimum_size = GTK_WIDGET (widget)->requisition.height;
10904 *natural_size = GTK_WIDGET (widget)->requisition.height;
10908 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
10910 gint *minimum_height,
10911 gint *natural_height)
10913 gtk_size_request_get_height (layout, minimum_height, natural_height);
10917 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
10919 gint *minimum_width,
10920 gint *natural_width)
10922 gtk_size_request_get_width (layout, minimum_width, natural_width);
10926 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
10928 iface->get_width = gtk_widget_real_get_width;
10929 iface->get_height = gtk_widget_real_get_height;
10930 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
10931 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
10936 * gtk_widget_get_clipboard:
10937 * @widget: a #GtkWidget
10938 * @selection: a #GdkAtom which identifies the clipboard
10939 * to use. %GDK_SELECTION_CLIPBOARD gives the
10940 * default clipboard. Another common value
10941 * is %GDK_SELECTION_PRIMARY, which gives
10942 * the primary X selection.
10944 * Returns the clipboard object for the given selection to
10945 * be used with @widget. @widget must have a #GdkDisplay
10946 * associated with it, so must be attached to a toplevel
10949 * Return value: (transfer none): the appropriate clipboard object. If no
10950 * clipboard already exists, a new one will
10951 * be created. Once a clipboard object has
10952 * been created, it is persistent for all time.
10957 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10959 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10960 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10962 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10967 * gtk_widget_list_mnemonic_labels:
10968 * @widget: a #GtkWidget
10970 * Returns a newly allocated list of the widgets, normally labels, for
10971 * which this widget is the target of a mnemonic (see for example,
10972 * gtk_label_set_mnemonic_widget()).
10974 * The widgets in the list are not individually referenced. If you
10975 * want to iterate through the list and perform actions involving
10976 * callbacks that might destroy the widgets, you
10977 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10978 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10979 * widgets afterwards.
10981 * Return value: (element-type GtkWidget) (transfer container): the list of
10982 * mnemonic labels; free this list
10983 * with g_list_free() when you are done with it.
10988 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10990 GList *list = NULL;
10993 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10995 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10996 list = g_list_prepend (list, l->data);
11002 * gtk_widget_add_mnemonic_label:
11003 * @widget: a #GtkWidget
11004 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11006 * Adds a widget to the list of mnemonic labels for
11007 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11008 * list of mnemonic labels for the widget is cleared when the
11009 * widget is destroyed, so the caller must make sure to update
11010 * its internal state at this point as well, by using a connection
11011 * to the #GtkWidget::destroy signal or a weak notifier.
11016 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11019 GSList *old_list, *new_list;
11021 g_return_if_fail (GTK_IS_WIDGET (widget));
11022 g_return_if_fail (GTK_IS_WIDGET (label));
11024 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11025 new_list = g_slist_prepend (old_list, label);
11027 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11028 new_list, (GDestroyNotify) g_slist_free);
11032 * gtk_widget_remove_mnemonic_label:
11033 * @widget: a #GtkWidget
11034 * @label: a #GtkWidget that was previously set as a mnemnic label for
11035 * @widget with gtk_widget_add_mnemonic_label().
11037 * Removes a widget from the list of mnemonic labels for
11038 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11039 * must have previously been added to the list with
11040 * gtk_widget_add_mnemonic_label().
11045 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11048 GSList *old_list, *new_list;
11050 g_return_if_fail (GTK_IS_WIDGET (widget));
11051 g_return_if_fail (GTK_IS_WIDGET (label));
11053 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11054 new_list = g_slist_remove (old_list, label);
11057 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11058 new_list, (GDestroyNotify) g_slist_free);
11062 * gtk_widget_get_no_show_all:
11063 * @widget: a #GtkWidget
11065 * Returns the current value of the GtkWidget:no-show-all property,
11066 * which determines whether calls to gtk_widget_show_all() and
11067 * gtk_widget_hide_all() will affect this widget.
11069 * Return value: the current value of the "no-show-all" property.
11074 gtk_widget_get_no_show_all (GtkWidget *widget)
11076 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11078 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11082 * gtk_widget_set_no_show_all:
11083 * @widget: a #GtkWidget
11084 * @no_show_all: the new value for the "no-show-all" property
11086 * Sets the #GtkWidget:no-show-all property, which determines whether
11087 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11090 * This is mostly for use in constructing widget hierarchies with externally
11091 * controlled visibility, see #GtkUIManager.
11096 gtk_widget_set_no_show_all (GtkWidget *widget,
11097 gboolean no_show_all)
11099 g_return_if_fail (GTK_IS_WIDGET (widget));
11101 no_show_all = (no_show_all != FALSE);
11103 if (no_show_all == gtk_widget_get_no_show_all (widget))
11107 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11109 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11111 g_object_notify (G_OBJECT (widget), "no-show-all");
11116 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11117 gboolean has_tooltip,
11120 gboolean priv_has_tooltip;
11122 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11123 quark_has_tooltip));
11125 if (priv_has_tooltip != has_tooltip || force)
11127 priv_has_tooltip = has_tooltip;
11129 if (priv_has_tooltip)
11131 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11132 gdk_window_set_events (widget->window,
11133 gdk_window_get_events (widget->window) |
11134 GDK_LEAVE_NOTIFY_MASK |
11135 GDK_POINTER_MOTION_MASK |
11136 GDK_POINTER_MOTION_HINT_MASK);
11138 if (gtk_widget_get_has_window (widget))
11139 gtk_widget_add_events (widget,
11140 GDK_LEAVE_NOTIFY_MASK |
11141 GDK_POINTER_MOTION_MASK |
11142 GDK_POINTER_MOTION_HINT_MASK);
11145 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11146 GUINT_TO_POINTER (priv_has_tooltip));
11151 * gtk_widget_set_tooltip_window:
11152 * @widget: a #GtkWidget
11153 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11155 * Replaces the default, usually yellow, window used for displaying
11156 * tooltips with @custom_window. GTK+ will take care of showing and
11157 * hiding @custom_window at the right moment, to behave likewise as
11158 * the default tooltip window. If @custom_window is %NULL, the default
11159 * tooltip window will be used.
11161 * If the custom window should have the default theming it needs to
11162 * have the name "gtk-tooltip", see gtk_widget_set_name().
11167 gtk_widget_set_tooltip_window (GtkWidget *widget,
11168 GtkWindow *custom_window)
11170 gboolean has_tooltip;
11171 gchar *tooltip_markup;
11173 g_return_if_fail (GTK_IS_WIDGET (widget));
11174 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11176 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11179 g_object_ref (custom_window);
11181 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11182 custom_window, g_object_unref);
11184 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11185 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11187 if (has_tooltip && gtk_widget_get_visible (widget))
11188 gtk_widget_queue_tooltip_query (widget);
11192 * gtk_widget_get_tooltip_window:
11193 * @widget: a #GtkWidget
11195 * Returns the #GtkWindow of the current tooltip. This can be the
11196 * GtkWindow created by default, or the custom tooltip window set
11197 * using gtk_widget_set_tooltip_window().
11199 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11204 gtk_widget_get_tooltip_window (GtkWidget *widget)
11206 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11208 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11212 * gtk_widget_trigger_tooltip_query:
11213 * @widget: a #GtkWidget
11215 * Triggers a tooltip query on the display where the toplevel of @widget
11216 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11222 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11224 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11227 static guint tooltip_query_id;
11228 static GSList *tooltip_query_displays;
11231 tooltip_query_idle (gpointer data)
11233 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11234 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11235 g_slist_free (tooltip_query_displays);
11237 tooltip_query_displays = NULL;
11238 tooltip_query_id = 0;
11244 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11246 GdkDisplay *display;
11248 display = gtk_widget_get_display (widget);
11250 if (!g_slist_find (tooltip_query_displays, display))
11251 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11253 if (tooltip_query_id == 0)
11254 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11258 * gtk_widget_set_tooltip_text:
11259 * @widget: a #GtkWidget
11260 * @text: the contents of the tooltip for @widget
11262 * Sets @text as the contents of the tooltip. This function will take
11263 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11264 * handler for the GtkWidget::query-tooltip signal.
11266 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11271 gtk_widget_set_tooltip_text (GtkWidget *widget,
11274 g_return_if_fail (GTK_IS_WIDGET (widget));
11276 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11280 * gtk_widget_get_tooltip_text:
11281 * @widget: a #GtkWidget
11283 * Gets the contents of the tooltip for @widget.
11285 * Return value: the tooltip text, or %NULL. You should free the
11286 * returned string with g_free() when done.
11291 gtk_widget_get_tooltip_text (GtkWidget *widget)
11293 gchar *text = NULL;
11295 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11297 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11303 * gtk_widget_set_tooltip_markup:
11304 * @widget: a #GtkWidget
11305 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11307 * Sets @markup as the contents of the tooltip, which is marked up with
11308 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11310 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11311 * and of the default handler for the GtkWidget::query-tooltip signal.
11313 * See also the GtkWidget:tooltip-markup property and
11314 * gtk_tooltip_set_markup().
11319 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11320 const gchar *markup)
11322 g_return_if_fail (GTK_IS_WIDGET (widget));
11324 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11328 * gtk_widget_get_tooltip_markup:
11329 * @widget: a #GtkWidget
11331 * Gets the contents of the tooltip for @widget.
11333 * Return value: the tooltip text, or %NULL. You should free the
11334 * returned string with g_free() when done.
11339 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11341 gchar *text = NULL;
11343 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11345 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11351 * gtk_widget_set_has_tooltip:
11352 * @widget: a #GtkWidget
11353 * @has_tooltip: whether or not @widget has a tooltip.
11355 * Sets the has-tooltip property on @widget to @has_tooltip. See
11356 * GtkWidget:has-tooltip for more information.
11361 gtk_widget_set_has_tooltip (GtkWidget *widget,
11362 gboolean has_tooltip)
11364 g_return_if_fail (GTK_IS_WIDGET (widget));
11366 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11370 * gtk_widget_get_has_tooltip:
11371 * @widget: a #GtkWidget
11373 * Returns the current value of the has-tooltip property. See
11374 * GtkWidget:has-tooltip for more information.
11376 * Return value: current value of has-tooltip on @widget.
11381 gtk_widget_get_has_tooltip (GtkWidget *widget)
11383 gboolean has_tooltip = FALSE;
11385 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11387 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11389 return has_tooltip;
11393 * gtk_widget_get_allocation:
11394 * @widget: a #GtkWidget
11395 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11397 * Retrieves the widget's allocation.
11402 gtk_widget_get_allocation (GtkWidget *widget,
11403 GtkAllocation *allocation)
11405 g_return_if_fail (GTK_IS_WIDGET (widget));
11406 g_return_if_fail (allocation != NULL);
11408 *allocation = widget->allocation;
11412 * gtk_widget_set_allocation:
11413 * @widget: a #GtkWidget
11414 * @allocation: a pointer to a #GtkAllocation to copy from
11416 * Sets the widget's allocation. This should not be used
11417 * directly, but from within a widget's size_allocate method.
11422 gtk_widget_set_allocation (GtkWidget *widget,
11423 const GtkAllocation *allocation)
11425 g_return_if_fail (GTK_IS_WIDGET (widget));
11426 g_return_if_fail (allocation != NULL);
11428 widget->allocation = *allocation;
11432 * gtk_widget_get_requisition:
11433 * @widget: a #GtkWidget
11434 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11436 * Retrieves the widget's requisition.
11438 * This function should only be used by widget implementations in
11439 * order to figure whether the widget's requisition has actually
11440 * changed after some internal state change (so that they can call
11441 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11443 * Normally, gtk_widget_size_request() should be used.
11448 gtk_widget_get_requisition (GtkWidget *widget,
11449 GtkRequisition *requisition)
11451 g_return_if_fail (GTK_IS_WIDGET (widget));
11452 g_return_if_fail (requisition != NULL);
11454 *requisition = widget->requisition;
11458 * gtk_widget_set_window:
11459 * @widget: a #GtkWidget
11460 * @window: a #GdkWindow
11462 * Sets a widget's window. This function should only be used in a
11463 * widget's GtkWidget::realize() implementation. The %window passed is
11464 * usually either new window created with gdk_window_new(), or the
11465 * window of its parent widget as returned by
11466 * gtk_widget_get_parent_window().
11468 * Widgets must indicate whether they will create their own #GdkWindow
11469 * by calling gtk_widget_set_has_window(). This is usually done in the
11470 * widget's init() function.
11475 gtk_widget_set_window (GtkWidget *widget,
11478 g_return_if_fail (GTK_IS_WIDGET (widget));
11479 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11481 if (widget->window != window)
11483 widget->window = window;
11484 g_object_notify (G_OBJECT (widget), "window");
11489 * gtk_widget_get_window:
11490 * @widget: a #GtkWidget
11492 * Returns the widget's window if it is realized, %NULL otherwise
11494 * Return value: (transfer none): @widget's window.
11499 gtk_widget_get_window (GtkWidget *widget)
11501 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11503 return widget->window;
11507 * gtk_widget_get_support_multidevice:
11508 * @widget: a #GtkWidget
11510 * Returns %TRUE if @widget is multiple pointer aware. See
11511 * gtk_widget_set_support_multidevice() for more information.
11513 * Returns: %TRUE is @widget is multidevice aware.
11516 gtk_widget_get_support_multidevice (GtkWidget *widget)
11518 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11520 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
11524 * gtk_widget_set_support_multidevice:
11525 * @widget: a #GtkWidget
11526 * @support_multidevice: %TRUE to support input from multiple devices.
11528 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
11529 * @widget will start receiving multiple, per device enter/leave events. Note
11530 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
11531 * gdk_window_set_support_multidevice() will have to be called manually on them.
11536 gtk_widget_set_support_multidevice (GtkWidget *widget,
11537 gboolean support_multidevice)
11539 g_return_if_fail (GTK_IS_WIDGET (widget));
11541 if (support_multidevice)
11543 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
11544 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
11548 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
11549 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
11552 if (gtk_widget_get_realized (widget))
11553 gdk_window_set_support_multidevice (widget->window, support_multidevice);
11557 _gtk_widget_set_has_focus (GtkWidget *widget,
11558 gboolean has_focus)
11561 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
11563 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
11567 * gtk_widget_send_focus_change:
11568 * @widget: a #GtkWidget
11569 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
11571 * Sends the focus change @event to @widget
11573 * This function is not meant to be used by applications. The only time it
11574 * should be used is when it is necessary for a #GtkWidget to assign focus
11575 * to a widget that is semantically owned by the first widget even though
11576 * it's not a direct child - for instance, a search entry in a floating
11577 * window similar to the quick search in #GtkTreeView.
11579 * An example of its usage is:
11582 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
11584 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
11585 * fevent->focus_change.in = TRUE;
11586 * fevent->focus_change.window = gtk_widget_get_window (widget);
11587 * if (fevent->focus_change.window != NULL)
11588 * g_object_ref (fevent->focus_change.window);
11590 * gtk_widget_send_focus_change (widget, fevent);
11592 * gdk_event_free (event);
11595 * Return value: the return value from the event signal emission: %TRUE
11596 * if the event was handled, and %FALSE otherwise
11601 gtk_widget_send_focus_change (GtkWidget *widget,
11606 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11607 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
11609 g_object_ref (widget);
11611 _gtk_widget_set_has_focus (widget, event->focus_change.in);
11613 res = gtk_widget_event (widget, event);
11615 g_object_notify (G_OBJECT (widget), "has-focus");
11617 g_object_unref (widget);