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/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
56 #include "gtkextendedlayout.h"
61 * @Short_description: Base class for all widgets
64 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
65 * widget lifecycle, states and style.
67 * <refsect2 id="style-properties">
69 * <structname>GtkWidget</structname> introduces <firstterm>style
70 * properties</firstterm> - these are basically object properties that are stored
71 * not on the object, but in the style object associated to the widget. Style
72 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
73 * This mechanism is used for configuring such things as the location of the
74 * scrollbar arrows through the theme, giving theme authors more control over the
75 * look of applications without the need to write a theme engine in C.
78 * Use gtk_widget_class_install_style_property() to install style properties for
79 * a widget class, gtk_widget_class_find_style_property() or
80 * gtk_widget_class_list_style_properties() to get information about existing
81 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
82 * gtk_widget_style_get_valist() to obtain the value of a style property.
85 * <refsect2 id="GtkWidget-BUILDER-UI">
86 * <title>GtkWidget as GtkBuildable</title>
88 * The GtkWidget implementation of the GtkBuildable interface supports a
89 * custom <accelerator> element, which has attributes named key,
90 * modifiers and signal and allows to specify accelerators.
93 * <title>A UI definition fragment specifying an accelerator</title>
94 * <programlisting><![CDATA[
95 * <object class="GtkButton">
96 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
98 * ]]></programlisting>
101 * In addition to accelerators, <structname>GtkWidget</structname> also support a
102 * custom <accessible> element, which supports actions and relations.
103 * Properties on the accessible implementation of an object can be set by accessing the
104 * internal child "accessible" of a <structname>GtkWidget</structname>.
107 * <title>A UI definition fragment specifying an accessible</title>
108 * <programlisting><![CDATA[
109 * <object class="GtkButton" id="label1"/>
110 * <property name="label">I am a Label for a Button</property>
112 * <object class="GtkButton" id="button1">
114 * <action action_name="click" translatable="yes">Click the button.</action>
115 * <relation target="label1" type="labelled-by"/>
117 * <child internal-child="accessible">
118 * <object class="AtkObject" id="a11y-button1">
119 * <property name="AtkObject::name">Clickable Button</property>
123 * ]]></programlisting>
128 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
129 #define INIT_PATH_SIZE (512)
155 BUTTON_RELEASE_EVENT,
170 PROPERTY_NOTIFY_EVENT,
171 SELECTION_CLEAR_EVENT,
172 SELECTION_REQUEST_EVENT,
173 SELECTION_NOTIFY_EVENT,
188 VISIBILITY_NOTIFY_EVENT,
192 ACCEL_CLOSURES_CHANGED,
218 PROP_RECEIVES_DEFAULT,
219 PROP_COMPOSITE_CHILD,
222 PROP_EXTENSION_EVENTS,
231 typedef struct _GtkStateData GtkStateData;
236 guint state_restoration : 1;
237 guint parent_sensitive : 1;
238 guint use_forall : 1;
241 /* --- prototypes --- */
242 static void gtk_widget_class_init (GtkWidgetClass *klass);
243 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
244 static void gtk_widget_init (GtkWidget *widget);
245 static void gtk_widget_set_property (GObject *object,
249 static void gtk_widget_get_property (GObject *object,
253 static void gtk_widget_dispose (GObject *object);
254 static void gtk_widget_real_destroy (GtkObject *object);
255 static void gtk_widget_finalize (GObject *object);
256 static void gtk_widget_real_show (GtkWidget *widget);
257 static void gtk_widget_real_hide (GtkWidget *widget);
258 static void gtk_widget_real_map (GtkWidget *widget);
259 static void gtk_widget_real_unmap (GtkWidget *widget);
260 static void gtk_widget_real_realize (GtkWidget *widget);
261 static void gtk_widget_real_unrealize (GtkWidget *widget);
262 static void gtk_widget_real_size_request (GtkWidget *widget,
263 GtkRequisition *requisition);
264 static void gtk_widget_real_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static void gtk_widget_real_style_set (GtkWidget *widget,
267 GtkStyle *previous_style);
268 static void gtk_widget_real_direction_changed(GtkWidget *widget,
269 GtkTextDirection previous_direction);
271 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
272 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
275 gboolean keyboard_tip,
276 GtkTooltip *tooltip);
277 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
278 GtkWidgetHelpType help_type);
280 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
282 GParamSpec **pspecs);
283 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
285 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
287 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
288 GdkEventFocus *event);
289 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
290 GdkEventFocus *event);
291 static gboolean gtk_widget_real_focus (GtkWidget *widget,
292 GtkDirectionType direction);
293 static void gtk_widget_real_move_focus (GtkWidget *widget,
294 GtkDirectionType direction);
295 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
296 GtkDirectionType direction);
297 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
298 static void gtk_widget_update_pango_context (GtkWidget *widget);
299 static void gtk_widget_propagate_state (GtkWidget *widget,
301 static void gtk_widget_reset_rc_style (GtkWidget *widget);
302 static void gtk_widget_set_style_internal (GtkWidget *widget,
304 gboolean initial_emission);
305 static gint gtk_widget_event_internal (GtkWidget *widget,
307 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
308 gboolean group_cycling);
309 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
310 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
311 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
312 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
313 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
315 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
316 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
317 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
320 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
321 gboolean has_tooltip,
323 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
324 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
326 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
327 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
329 const gchar *childname);
330 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
333 const GValue *value);
334 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
337 const gchar *tagname,
338 GMarkupParser *parser,
340 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
343 const gchar *tagname,
345 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
346 GtkBuilder *builder);
348 static void gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface);
349 static void gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
352 static void gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
356 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
358 static void gtk_widget_set_usize_internal (GtkWidget *widget,
361 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
365 /* --- variables --- */
366 static gpointer gtk_widget_parent_class = NULL;
367 static guint widget_signals[LAST_SIGNAL] = { 0 };
368 static GtkStyle *gtk_default_style = NULL;
369 static GSList *colormap_stack = NULL;
370 static guint composite_child_stack = 0;
371 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
372 static GParamSpecPool *style_property_spec_pool = NULL;
374 static GQuark quark_property_parser = 0;
375 static GQuark quark_aux_info = 0;
376 static GQuark quark_accel_path = 0;
377 static GQuark quark_accel_closures = 0;
378 static GQuark quark_event_mask = 0;
379 static GQuark quark_device_event_mask = 0;
380 static GQuark quark_extension_event_mode = 0;
381 static GQuark quark_parent_window = 0;
382 static GQuark quark_pointer_window = 0;
383 static GQuark quark_shape_info = 0;
384 static GQuark quark_input_shape_info = 0;
385 static GQuark quark_colormap = 0;
386 static GQuark quark_pango_context = 0;
387 static GQuark quark_rc_style = 0;
388 static GQuark quark_accessible_object = 0;
389 static GQuark quark_mnemonic_labels = 0;
390 static GQuark quark_tooltip_markup = 0;
391 static GQuark quark_has_tooltip = 0;
392 static GQuark quark_tooltip_window = 0;
393 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
394 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
396 /* --- functions --- */
398 gtk_widget_get_type (void)
400 static GType widget_type = 0;
402 if (G_UNLIKELY (widget_type == 0))
404 const GTypeInfo widget_info =
406 sizeof (GtkWidgetClass),
407 NULL, /* base_init */
408 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
409 (GClassInitFunc) gtk_widget_class_init,
410 NULL, /* class_finalize */
411 NULL, /* class_init */
414 (GInstanceInitFunc) gtk_widget_init,
415 NULL, /* value_table */
418 const GInterfaceInfo accessibility_info =
420 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
421 (GInterfaceFinalizeFunc) NULL,
422 NULL /* interface data */
425 const GInterfaceInfo buildable_info =
427 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
428 (GInterfaceFinalizeFunc) NULL,
429 NULL /* interface data */
432 const GInterfaceInfo layout_info =
434 (GInterfaceInitFunc) gtk_widget_extended_layout_init,
435 (GInterfaceFinalizeFunc) NULL,
436 NULL /* interface data */
439 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
440 &widget_info, G_TYPE_FLAG_ABSTRACT);
442 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
443 &accessibility_info) ;
444 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
446 g_type_add_interface_static (widget_type, GTK_TYPE_EXTENDED_LAYOUT,
454 child_property_notify_dispatcher (GObject *object,
458 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
462 gtk_widget_class_init (GtkWidgetClass *klass)
464 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
465 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
466 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
467 GtkBindingSet *binding_set;
469 gtk_widget_parent_class = g_type_class_peek_parent (klass);
471 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
472 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
473 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
474 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
475 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
476 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
477 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
478 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
479 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
480 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
481 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
482 quark_colormap = g_quark_from_static_string ("gtk-colormap");
483 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
484 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
485 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
486 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
487 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
488 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
489 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
491 style_property_spec_pool = g_param_spec_pool_new (FALSE);
492 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
493 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
494 cpn_context.dispatcher = child_property_notify_dispatcher;
495 _gtk_widget_child_property_notify_context = &cpn_context;
497 gobject_class->dispose = gtk_widget_dispose;
498 gobject_class->finalize = gtk_widget_finalize;
499 gobject_class->set_property = gtk_widget_set_property;
500 gobject_class->get_property = gtk_widget_get_property;
502 object_class->destroy = gtk_widget_real_destroy;
504 klass->activate_signal = 0;
505 klass->set_scroll_adjustments_signal = 0;
506 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
507 klass->show = gtk_widget_real_show;
508 klass->show_all = gtk_widget_show;
509 klass->hide = gtk_widget_real_hide;
510 klass->hide_all = gtk_widget_hide;
511 klass->map = gtk_widget_real_map;
512 klass->unmap = gtk_widget_real_unmap;
513 klass->realize = gtk_widget_real_realize;
514 klass->unrealize = gtk_widget_real_unrealize;
515 klass->size_request = gtk_widget_real_size_request;
516 klass->size_allocate = gtk_widget_real_size_allocate;
517 klass->state_changed = NULL;
518 klass->parent_set = NULL;
519 klass->hierarchy_changed = NULL;
520 klass->style_set = gtk_widget_real_style_set;
521 klass->direction_changed = gtk_widget_real_direction_changed;
522 klass->grab_notify = NULL;
523 klass->child_notify = NULL;
524 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
525 klass->grab_focus = gtk_widget_real_grab_focus;
526 klass->focus = gtk_widget_real_focus;
528 klass->button_press_event = NULL;
529 klass->button_release_event = NULL;
530 klass->motion_notify_event = NULL;
531 klass->delete_event = NULL;
532 klass->destroy_event = NULL;
533 klass->expose_event = NULL;
534 klass->key_press_event = gtk_widget_real_key_press_event;
535 klass->key_release_event = gtk_widget_real_key_release_event;
536 klass->enter_notify_event = NULL;
537 klass->leave_notify_event = NULL;
538 klass->configure_event = NULL;
539 klass->focus_in_event = gtk_widget_real_focus_in_event;
540 klass->focus_out_event = gtk_widget_real_focus_out_event;
541 klass->map_event = NULL;
542 klass->unmap_event = NULL;
543 klass->window_state_event = NULL;
544 klass->property_notify_event = _gtk_selection_property_notify;
545 klass->selection_clear_event = _gtk_selection_clear;
546 klass->selection_request_event = _gtk_selection_request;
547 klass->selection_notify_event = _gtk_selection_notify;
548 klass->selection_received = NULL;
549 klass->proximity_in_event = NULL;
550 klass->proximity_out_event = NULL;
551 klass->drag_begin = NULL;
552 klass->drag_end = NULL;
553 klass->drag_data_delete = NULL;
554 klass->drag_leave = NULL;
555 klass->drag_motion = NULL;
556 klass->drag_drop = NULL;
557 klass->drag_data_received = NULL;
558 klass->screen_changed = NULL;
559 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
560 klass->grab_broken_event = NULL;
561 klass->query_tooltip = gtk_widget_real_query_tooltip;
563 klass->show_help = gtk_widget_real_show_help;
565 /* Accessibility support */
566 klass->get_accessible = gtk_widget_real_get_accessible;
568 klass->no_expose_event = NULL;
570 g_object_class_install_property (gobject_class,
572 g_param_spec_string ("name",
574 P_("The name of the widget"),
576 GTK_PARAM_READWRITE));
577 g_object_class_install_property (gobject_class,
579 g_param_spec_object ("parent",
581 P_("The parent widget of this widget. Must be a Container widget"),
583 GTK_PARAM_READWRITE));
585 g_object_class_install_property (gobject_class,
587 g_param_spec_int ("width-request",
589 P_("Override for width request of the widget, or -1 if natural request should be used"),
593 GTK_PARAM_READWRITE));
594 g_object_class_install_property (gobject_class,
596 g_param_spec_int ("height-request",
597 P_("Height request"),
598 P_("Override for height request of the widget, or -1 if natural request should be used"),
602 GTK_PARAM_READWRITE));
603 g_object_class_install_property (gobject_class,
605 g_param_spec_boolean ("visible",
607 P_("Whether the widget is visible"),
609 GTK_PARAM_READWRITE));
610 g_object_class_install_property (gobject_class,
612 g_param_spec_boolean ("sensitive",
614 P_("Whether the widget responds to input"),
616 GTK_PARAM_READWRITE));
617 g_object_class_install_property (gobject_class,
619 g_param_spec_boolean ("app-paintable",
620 P_("Application paintable"),
621 P_("Whether the application will paint directly on the widget"),
623 GTK_PARAM_READWRITE));
624 g_object_class_install_property (gobject_class,
626 g_param_spec_boolean ("can-focus",
628 P_("Whether the widget can accept the input focus"),
630 GTK_PARAM_READWRITE));
631 g_object_class_install_property (gobject_class,
633 g_param_spec_boolean ("has-focus",
635 P_("Whether the widget has the input focus"),
637 GTK_PARAM_READWRITE));
638 g_object_class_install_property (gobject_class,
640 g_param_spec_boolean ("is-focus",
642 P_("Whether the widget is the focus widget within the toplevel"),
644 GTK_PARAM_READWRITE));
645 g_object_class_install_property (gobject_class,
647 g_param_spec_boolean ("can-default",
649 P_("Whether the widget can be the default widget"),
651 GTK_PARAM_READWRITE));
652 g_object_class_install_property (gobject_class,
654 g_param_spec_boolean ("has-default",
656 P_("Whether the widget is the default widget"),
658 GTK_PARAM_READWRITE));
659 g_object_class_install_property (gobject_class,
660 PROP_RECEIVES_DEFAULT,
661 g_param_spec_boolean ("receives-default",
662 P_("Receives default"),
663 P_("If TRUE, the widget will receive the default action when it is focused"),
665 GTK_PARAM_READWRITE));
666 g_object_class_install_property (gobject_class,
667 PROP_COMPOSITE_CHILD,
668 g_param_spec_boolean ("composite-child",
669 P_("Composite child"),
670 P_("Whether the widget is part of a composite widget"),
672 GTK_PARAM_READABLE));
673 g_object_class_install_property (gobject_class,
675 g_param_spec_object ("style",
677 P_("The style of the widget, which contains information about how it will look (colors etc)"),
679 GTK_PARAM_READWRITE));
680 g_object_class_install_property (gobject_class,
682 g_param_spec_flags ("events",
684 P_("The event mask that decides what kind of GdkEvents this widget gets"),
687 GTK_PARAM_READWRITE));
688 g_object_class_install_property (gobject_class,
689 PROP_EXTENSION_EVENTS,
690 g_param_spec_enum ("extension-events",
691 P_("Extension events"),
692 P_("The mask that decides what kind of extension events this widget gets"),
693 GDK_TYPE_EXTENSION_MODE,
694 GDK_EXTENSION_EVENTS_NONE,
695 GTK_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class,
698 g_param_spec_boolean ("no-show-all",
700 P_("Whether gtk_widget_show_all() should not affect this widget"),
702 GTK_PARAM_READWRITE));
705 * GtkWidget:has-tooltip:
707 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
708 * A value of %TRUE indicates that @widget can have a tooltip, in this case
709 * the widget will be queried using #GtkWidget::query-tooltip to determine
710 * whether it will provide a tooltip or not.
712 * Note that setting this property to %TRUE for the first time will change
713 * the event masks of the GdkWindows of this widget to include leave-notify
714 * and motion-notify events. This cannot and will not be undone when the
715 * property is set to %FALSE again.
719 g_object_class_install_property (gobject_class,
721 g_param_spec_boolean ("has-tooltip",
723 P_("Whether this widget has a tooltip"),
725 GTK_PARAM_READWRITE));
727 * GtkWidget:tooltip-text:
729 * Sets the text of tooltip to be the given string.
731 * Also see gtk_tooltip_set_text().
733 * This is a convenience property which will take care of getting the
734 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
735 * will automatically be set to %TRUE and there will be taken care of
736 * #GtkWidget::query-tooltip in the default signal handler.
740 g_object_class_install_property (gobject_class,
742 g_param_spec_string ("tooltip-text",
744 P_("The contents of the tooltip for this widget"),
746 GTK_PARAM_READWRITE));
748 * GtkWidget:tooltip-markup:
750 * Sets the text of tooltip to be the given string, which is marked up
751 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
752 * Also see gtk_tooltip_set_markup().
754 * This is a convenience property which will take care of getting the
755 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
756 * will automatically be set to %TRUE and there will be taken care of
757 * #GtkWidget::query-tooltip in the default signal handler.
761 g_object_class_install_property (gobject_class,
763 g_param_spec_string ("tooltip-markup",
764 P_("Tooltip markup"),
765 P_("The contents of the tooltip for this widget"),
767 GTK_PARAM_READWRITE));
772 * The widget's window if it is realized, %NULL otherwise.
776 g_object_class_install_property (gobject_class,
778 g_param_spec_object ("window",
780 P_("The widget's window if it is realized"),
782 GTK_PARAM_READABLE));
785 * GtkWidget:double-buffered
787 * Whether or not the widget is double buffered.
791 g_object_class_install_property (gobject_class,
792 PROP_DOUBLE_BUFFERED,
793 g_param_spec_boolean ("double-buffered",
794 P_("Double Buffered"),
795 P_("Whether or not the widget is double buffered"),
797 GTK_PARAM_READWRITE));
801 * @widget: the object which received the signal.
803 widget_signals[SHOW] =
804 g_signal_new (I_("show"),
805 G_TYPE_FROM_CLASS (gobject_class),
807 G_STRUCT_OFFSET (GtkWidgetClass, show),
809 _gtk_marshal_VOID__VOID,
814 * @widget: the object which received the signal.
816 widget_signals[HIDE] =
817 g_signal_new (I_("hide"),
818 G_TYPE_FROM_CLASS (gobject_class),
820 G_STRUCT_OFFSET (GtkWidgetClass, hide),
822 _gtk_marshal_VOID__VOID,
827 * @widget: the object which received the signal.
829 widget_signals[MAP] =
830 g_signal_new (I_("map"),
831 G_TYPE_FROM_CLASS (gobject_class),
833 G_STRUCT_OFFSET (GtkWidgetClass, map),
835 _gtk_marshal_VOID__VOID,
840 * @widget: the object which received the signal.
842 widget_signals[UNMAP] =
843 g_signal_new (I_("unmap"),
844 G_TYPE_FROM_CLASS (gobject_class),
846 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
848 _gtk_marshal_VOID__VOID,
852 * GtkWidget::realize:
853 * @widget: the object which received the signal.
855 widget_signals[REALIZE] =
856 g_signal_new (I_("realize"),
857 G_TYPE_FROM_CLASS (gobject_class),
859 G_STRUCT_OFFSET (GtkWidgetClass, realize),
861 _gtk_marshal_VOID__VOID,
865 * GtkWidget::unrealize:
866 * @widget: the object which received the signal.
868 widget_signals[UNREALIZE] =
869 g_signal_new (I_("unrealize"),
870 G_TYPE_FROM_CLASS (gobject_class),
872 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
874 _gtk_marshal_VOID__VOID,
878 * GtkWidget::size-request:
879 * @widget: the object which received the signal.
882 widget_signals[SIZE_REQUEST] =
883 g_signal_new (I_("size-request"),
884 G_TYPE_FROM_CLASS (gobject_class),
886 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
888 _gtk_marshal_VOID__BOXED,
890 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
893 * GtkWidget::size-allocate:
894 * @widget: the object which received the signal.
897 widget_signals[SIZE_ALLOCATE] =
898 g_signal_new (I_("size-allocate"),
899 G_TYPE_FROM_CLASS (gobject_class),
901 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
903 _gtk_marshal_VOID__BOXED,
905 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
908 * GtkWidget::state-changed:
909 * @widget: the object which received the signal.
910 * @state: the previous state
912 * The ::state-changed signal is emitted when the widget state changes.
913 * See gtk_widget_get_state().
915 widget_signals[STATE_CHANGED] =
916 g_signal_new (I_("state-changed"),
917 G_TYPE_FROM_CLASS (gobject_class),
919 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
921 _gtk_marshal_VOID__ENUM,
923 GTK_TYPE_STATE_TYPE);
926 * GtkWidget::parent-set:
927 * @widget: the object on which the signal is emitted
928 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
929 * just got its initial parent.
931 * The ::parent-set signal is emitted when a new parent
932 * has been set on a widget.
934 widget_signals[PARENT_SET] =
935 g_signal_new (I_("parent-set"),
936 G_TYPE_FROM_CLASS (gobject_class),
938 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
940 _gtk_marshal_VOID__OBJECT,
945 * GtkWidget::hierarchy-changed:
946 * @widget: the object on which the signal is emitted
947 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
948 * if the widget was previously unanchored
950 * The ::hierarchy-changed signal is emitted when the
951 * anchored state of a widget changes. A widget is
952 * <firstterm>anchored</firstterm> when its toplevel
953 * ancestor is a #GtkWindow. This signal is emitted when
954 * a widget changes from un-anchored to anchored or vice-versa.
956 widget_signals[HIERARCHY_CHANGED] =
957 g_signal_new (I_("hierarchy-changed"),
958 G_TYPE_FROM_CLASS (gobject_class),
960 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
962 _gtk_marshal_VOID__OBJECT,
967 * GtkWidget::style-set:
968 * @widget: the object on which the signal is emitted
969 * @previous_style: (allow-none): the previous style, or %NULL if the widget
970 * just got its initial style
972 * The ::style-set signal is emitted when a new style has been set
973 * on a widget. Note that style-modifying functions like
974 * gtk_widget_modify_base() also cause this signal to be emitted.
976 widget_signals[STYLE_SET] =
977 g_signal_new (I_("style-set"),
978 G_TYPE_FROM_CLASS (gobject_class),
980 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
982 _gtk_marshal_VOID__OBJECT,
986 * GtkWidget::direction-changed:
987 * @widget: the object on which the signal is emitted
988 * @previous_direction: the previous text direction of @widget
990 * The ::direction-changed signal is emitted when the text direction
991 * of a widget changes.
993 widget_signals[DIRECTION_CHANGED] =
994 g_signal_new (I_("direction-changed"),
995 G_TYPE_FROM_CLASS (gobject_class),
997 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
999 _gtk_marshal_VOID__ENUM,
1001 GTK_TYPE_TEXT_DIRECTION);
1004 * GtkWidget::grab-notify:
1005 * @widget: the object which received the signal
1006 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1007 * if it becomes unshadowed
1009 * The ::grab-notify signal is emitted when a widget becomes
1010 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1011 * another widget, or when it becomes unshadowed due to a grab
1014 * A widget is shadowed by a gtk_grab_add() when the topmost
1015 * grab widget in the grab stack of its window group is not
1018 widget_signals[GRAB_NOTIFY] =
1019 g_signal_new (I_("grab-notify"),
1020 G_TYPE_FROM_CLASS (gobject_class),
1022 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1024 _gtk_marshal_VOID__BOOLEAN,
1029 * GtkWidget::child-notify:
1030 * @widget: the object which received the signal
1031 * @pspec: the #GParamSpec of the changed child property
1033 * The ::child-notify signal is emitted for each
1034 * <link linkend="child-properties">child property</link> that has
1035 * changed on an object. The signal's detail holds the property name.
1037 widget_signals[CHILD_NOTIFY] =
1038 g_signal_new (I_("child-notify"),
1039 G_TYPE_FROM_CLASS (gobject_class),
1040 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1041 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1043 g_cclosure_marshal_VOID__PARAM,
1048 * GtkWidget::mnemonic-activate:
1049 * @widget: the object which received the signal.
1052 widget_signals[MNEMONIC_ACTIVATE] =
1053 g_signal_new (I_("mnemonic-activate"),
1054 G_TYPE_FROM_CLASS (gobject_class),
1056 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1057 _gtk_boolean_handled_accumulator, NULL,
1058 _gtk_marshal_BOOLEAN__BOOLEAN,
1063 * GtkWidget::grab-focus:
1064 * @widget: the object which received the signal.
1066 widget_signals[GRAB_FOCUS] =
1067 g_signal_new (I_("grab-focus"),
1068 G_TYPE_FROM_CLASS (gobject_class),
1069 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1070 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1072 _gtk_marshal_VOID__VOID,
1077 * @widget: the object which received the signal.
1080 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1082 widget_signals[FOCUS] =
1083 g_signal_new (I_("focus"),
1084 G_TYPE_FROM_CLASS (object_class),
1086 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1087 _gtk_boolean_handled_accumulator, NULL,
1088 _gtk_marshal_BOOLEAN__ENUM,
1090 GTK_TYPE_DIRECTION_TYPE);
1093 * GtkWidget::move-focus:
1094 * @widget: the object which received the signal.
1097 widget_signals[MOVE_FOCUS] =
1098 g_signal_new_class_handler (I_("move-focus"),
1099 G_TYPE_FROM_CLASS (object_class),
1100 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1101 G_CALLBACK (gtk_widget_real_move_focus),
1103 _gtk_marshal_VOID__ENUM,
1106 GTK_TYPE_DIRECTION_TYPE);
1109 * @widget: the object which received the signal.
1110 * @event: the #GdkEvent which triggered this signal
1112 * The GTK+ main loop will emit three signals for each GDK event delivered
1113 * to a widget: one generic ::event signal, another, more specific,
1114 * signal that matches the type of event delivered (e.g.
1115 * #GtkWidget::key-press-event) and finally a generic
1116 * #GtkWidget::event-after signal.
1118 * Returns: %TRUE to stop other handlers from being invoked for the event
1119 * and to cancel the emission of the second specific ::event signal.
1120 * %FALSE to propagate the event further and to allow the emission of
1121 * the second signal. The ::event-after signal is emitted regardless of
1124 widget_signals[EVENT] =
1125 g_signal_new (I_("event"),
1126 G_TYPE_FROM_CLASS (gobject_class),
1128 G_STRUCT_OFFSET (GtkWidgetClass, event),
1129 _gtk_boolean_handled_accumulator, NULL,
1130 _gtk_marshal_BOOLEAN__BOXED,
1132 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1135 * GtkWidget::event-after:
1136 * @widget: the object which received the signal.
1137 * @event: the #GdkEvent which triggered this signal
1139 * After the emission of the #GtkWidget::event signal and (optionally)
1140 * the second more specific signal, ::event-after will be emitted
1141 * regardless of the previous two signals handlers return values.
1144 widget_signals[EVENT_AFTER] =
1145 g_signal_new (I_("event-after"),
1146 G_TYPE_FROM_CLASS (gobject_class),
1150 _gtk_marshal_VOID__BOXED,
1152 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1155 * GtkWidget::button-press-event:
1156 * @widget: the object which received the signal.
1157 * @event: the #GdkEventButton which triggered this signal
1159 * The ::button-press-event signal will be emitted when a button
1160 * (typically from a mouse) is pressed.
1162 * To receive this signal, the #GdkWindow associated to the
1163 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1165 * This signal will be sent to the grab widget if there is one.
1167 * Returns: %TRUE to stop other handlers from being invoked for the event.
1168 * %FALSE to propagate the event further.
1170 widget_signals[BUTTON_PRESS_EVENT] =
1171 g_signal_new (I_("button-press-event"),
1172 G_TYPE_FROM_CLASS (gobject_class),
1174 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1175 _gtk_boolean_handled_accumulator, NULL,
1176 _gtk_marshal_BOOLEAN__BOXED,
1178 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1181 * GtkWidget::button-release-event:
1182 * @widget: the object which received the signal.
1183 * @event: the #GdkEventButton which triggered this signal
1185 * The ::button-release-event signal will be emitted when a button
1186 * (typically from a mouse) is released.
1188 * To receive this signal, the #GdkWindow associated to the
1189 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1191 * This signal will be sent to the grab widget if there is one.
1193 * Returns: %TRUE to stop other handlers from being invoked for the event.
1194 * %FALSE to propagate the event further.
1196 widget_signals[BUTTON_RELEASE_EVENT] =
1197 g_signal_new (I_("button-release-event"),
1198 G_TYPE_FROM_CLASS (gobject_class),
1200 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1201 _gtk_boolean_handled_accumulator, NULL,
1202 _gtk_marshal_BOOLEAN__BOXED,
1204 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1207 * GtkWidget::scroll-event:
1208 * @widget: the object which received the signal.
1209 * @event: the #GdkEventScroll which triggered this signal
1211 * The ::scroll-event signal is emitted when a button in the 4 to 7
1212 * range is pressed. Wheel mice are usually configured to generate
1213 * button press events for buttons 4 and 5 when the wheel is turned.
1215 * To receive this signal, the #GdkWindow associated to the widget needs
1216 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1218 * This signal will be sent to the grab widget if there is one.
1220 * Returns: %TRUE to stop other handlers from being invoked for the event.
1221 * %FALSE to propagate the event further.
1223 widget_signals[SCROLL_EVENT] =
1224 g_signal_new (I_("scroll-event"),
1225 G_TYPE_FROM_CLASS (gobject_class),
1227 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1228 _gtk_boolean_handled_accumulator, NULL,
1229 _gtk_marshal_BOOLEAN__BOXED,
1231 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1233 * GtkWidget::motion-notify-event:
1234 * @widget: the object which received the signal.
1235 * @event: the #GdkEventMotion which triggered this signal
1237 * The ::motion-notify-event signal is emitted when the pointer moves
1238 * over the widget's #GdkWindow.
1240 * To receive this signal, the #GdkWindow associated to the widget
1241 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1243 * This signal will be sent to the grab widget if there is one.
1245 * Returns: %TRUE to stop other handlers from being invoked for the event.
1246 * %FALSE to propagate the event further.
1248 widget_signals[MOTION_NOTIFY_EVENT] =
1249 g_signal_new (I_("motion-notify-event"),
1250 G_TYPE_FROM_CLASS (gobject_class),
1252 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1253 _gtk_boolean_handled_accumulator, NULL,
1254 _gtk_marshal_BOOLEAN__BOXED,
1256 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1259 * GtkWidget::composited-changed:
1260 * @widget: the object on which the signal is emitted
1262 * The ::composited-changed signal is emitted when the composited
1263 * status of @widget<!-- -->s screen changes.
1264 * See gdk_screen_is_composited().
1266 widget_signals[COMPOSITED_CHANGED] =
1267 g_signal_new (I_("composited-changed"),
1268 G_TYPE_FROM_CLASS (gobject_class),
1269 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1270 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1272 _gtk_marshal_VOID__VOID,
1276 * GtkWidget::keynav-failed:
1277 * @widget: the object which received the signal
1278 * @direction: the direction of movement
1280 * Gets emitted if keyboard navigation fails.
1281 * See gtk_widget_keynav_failed() for details.
1283 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1284 * if the emitting widget should try to handle the keyboard
1285 * navigation attempt in its parent container(s).
1289 widget_signals[KEYNAV_FAILED] =
1290 g_signal_new_class_handler (I_("keynav-failed"),
1291 G_TYPE_FROM_CLASS (gobject_class),
1293 G_CALLBACK (gtk_widget_real_keynav_failed),
1294 _gtk_boolean_handled_accumulator, NULL,
1295 _gtk_marshal_BOOLEAN__ENUM,
1297 GTK_TYPE_DIRECTION_TYPE);
1300 * GtkWidget::delete-event:
1301 * @widget: the object which received the signal
1302 * @event: the event which triggered this signal
1304 * The ::delete-event signal is emitted if a user requests that
1305 * a toplevel window is closed. The default handler for this signal
1306 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1307 * this signal will cause the window to be hidden instead, so that
1308 * it can later be shown again without reconstructing it.
1310 * Returns: %TRUE to stop other handlers from being invoked for the event.
1311 * %FALSE to propagate the event further.
1313 widget_signals[DELETE_EVENT] =
1314 g_signal_new (I_("delete-event"),
1315 G_TYPE_FROM_CLASS (gobject_class),
1317 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1318 _gtk_boolean_handled_accumulator, NULL,
1319 _gtk_marshal_BOOLEAN__BOXED,
1321 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1324 * GtkWidget::destroy-event:
1325 * @widget: the object which received the signal.
1326 * @event: the event which triggered this signal
1328 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1329 * You rarely get this signal, because most widgets disconnect themselves
1330 * from their window before they destroy it, so no widget owns the
1331 * window at destroy time.
1333 * To receive this signal, the #GdkWindow associated to the widget needs
1334 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1335 * automatically for all new windows.
1337 * Returns: %TRUE to stop other handlers from being invoked for the event.
1338 * %FALSE to propagate the event further.
1340 widget_signals[DESTROY_EVENT] =
1341 g_signal_new (I_("destroy-event"),
1342 G_TYPE_FROM_CLASS (gobject_class),
1344 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1345 _gtk_boolean_handled_accumulator, NULL,
1346 _gtk_marshal_BOOLEAN__BOXED,
1348 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1351 * GtkWidget::expose-event:
1352 * @widget: the object which received the signal.
1353 * @event: the #GdkEventExpose which triggered this signal
1355 * The ::expose-event signal is emitted when an area of a previously
1356 * obscured #GdkWindow is made visible and needs to be redrawn.
1357 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1360 * To receive this signal, the #GdkWindow associated to the widget needs
1361 * to enable the #GDK_EXPOSURE_MASK mask.
1363 * Returns: %TRUE to stop other handlers from being invoked for the event.
1364 * %FALSE to propagate the event further.
1366 widget_signals[EXPOSE_EVENT] =
1367 g_signal_new (I_("expose-event"),
1368 G_TYPE_FROM_CLASS (gobject_class),
1370 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1371 _gtk_boolean_handled_accumulator, NULL,
1372 _gtk_marshal_BOOLEAN__BOXED,
1374 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1377 * GtkWidget::key-press-event:
1378 * @widget: the object which received the signal
1379 * @event: the #GdkEventKey which triggered this signal
1381 * The ::key-press-event signal is emitted when a key is pressed.
1383 * To receive this signal, the #GdkWindow associated to the widget needs
1384 * to enable the #GDK_KEY_PRESS_MASK mask.
1386 * This signal will be sent to the grab widget if there is one.
1388 * Returns: %TRUE to stop other handlers from being invoked for the event.
1389 * %FALSE to propagate the event further.
1391 widget_signals[KEY_PRESS_EVENT] =
1392 g_signal_new (I_("key-press-event"),
1393 G_TYPE_FROM_CLASS (gobject_class),
1395 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1396 _gtk_boolean_handled_accumulator, NULL,
1397 _gtk_marshal_BOOLEAN__BOXED,
1399 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1402 * GtkWidget::key-release-event:
1403 * @widget: the object which received the signal
1404 * @event: the #GdkEventKey which triggered this signal
1406 * The ::key-release-event signal is emitted when a key is pressed.
1408 * To receive this signal, the #GdkWindow associated to the widget needs
1409 * to enable the #GDK_KEY_RELEASE_MASK mask.
1411 * This signal will be sent to the grab widget if there is one.
1413 * Returns: %TRUE to stop other handlers from being invoked for the event.
1414 * %FALSE to propagate the event further.
1416 widget_signals[KEY_RELEASE_EVENT] =
1417 g_signal_new (I_("key-release-event"),
1418 G_TYPE_FROM_CLASS (gobject_class),
1420 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1421 _gtk_boolean_handled_accumulator, NULL,
1422 _gtk_marshal_BOOLEAN__BOXED,
1424 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1427 * GtkWidget::enter-notify-event:
1428 * @widget: the object which received the signal
1429 * @event: the #GdkEventCrossing which triggered this signal
1431 * The ::enter-notify-event will be emitted when the pointer enters
1432 * the @widget's window.
1434 * To receive this signal, the #GdkWindow associated to the widget needs
1435 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1437 * This signal will be sent to the grab widget if there is one.
1439 * Returns: %TRUE to stop other handlers from being invoked for the event.
1440 * %FALSE to propagate the event further.
1442 widget_signals[ENTER_NOTIFY_EVENT] =
1443 g_signal_new (I_("enter-notify-event"),
1444 G_TYPE_FROM_CLASS (gobject_class),
1446 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1447 _gtk_boolean_handled_accumulator, NULL,
1448 _gtk_marshal_BOOLEAN__BOXED,
1450 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1453 * GtkWidget::leave-notify-event:
1454 * @widget: the object which received the signal
1455 * @event: the #GdkEventCrossing which triggered this signal
1457 * The ::leave-notify-event will be emitted when the pointer leaves
1458 * the @widget's window.
1460 * To receive this signal, the #GdkWindow associated to the widget needs
1461 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1463 * This signal will be sent to the grab widget if there is one.
1465 * Returns: %TRUE to stop other handlers from being invoked for the event.
1466 * %FALSE to propagate the event further.
1468 widget_signals[LEAVE_NOTIFY_EVENT] =
1469 g_signal_new (I_("leave-notify-event"),
1470 G_TYPE_FROM_CLASS (gobject_class),
1472 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1473 _gtk_boolean_handled_accumulator, NULL,
1474 _gtk_marshal_BOOLEAN__BOXED,
1476 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1479 * GtkWidget::configure-event
1480 * @widget: the object which received the signal
1481 * @event: the #GdkEventConfigure which triggered this signal
1483 * The ::configure-event signal will be emitted when the size, position or
1484 * stacking of the @widget's window has changed.
1486 * To receive this signal, the #GdkWindow associated to the widget needs
1487 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1488 * automatically for all new windows.
1490 * Returns: %TRUE to stop other handlers from being invoked for the event.
1491 * %FALSE to propagate the event further.
1493 widget_signals[CONFIGURE_EVENT] =
1494 g_signal_new (I_("configure-event"),
1495 G_TYPE_FROM_CLASS (gobject_class),
1497 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1498 _gtk_boolean_handled_accumulator, NULL,
1499 _gtk_marshal_BOOLEAN__BOXED,
1501 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1504 * GtkWidget::focus-in-event
1505 * @widget: the object which received the signal
1506 * @event: the #GdkEventFocus which triggered this signal
1508 * The ::focus-in-event signal will be emitted when the keyboard focus
1509 * enters the @widget's window.
1511 * To receive this signal, the #GdkWindow associated to the widget needs
1512 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1514 * Returns: %TRUE to stop other handlers from being invoked for the event.
1515 * %FALSE to propagate the event further.
1517 widget_signals[FOCUS_IN_EVENT] =
1518 g_signal_new (I_("focus-in-event"),
1519 G_TYPE_FROM_CLASS (gobject_class),
1521 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1522 _gtk_boolean_handled_accumulator, NULL,
1523 _gtk_marshal_BOOLEAN__BOXED,
1525 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1528 * GtkWidget::focus-out-event
1529 * @widget: the object which received the signal
1530 * @event: the #GdkEventFocus which triggered this signal
1532 * The ::focus-out-event signal will be emitted when the keyboard focus
1533 * leaves the @widget's window.
1535 * To receive this signal, the #GdkWindow associated to the widget needs
1536 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1538 * Returns: %TRUE to stop other handlers from being invoked for the event.
1539 * %FALSE to propagate the event further.
1541 widget_signals[FOCUS_OUT_EVENT] =
1542 g_signal_new (I_("focus-out-event"),
1543 G_TYPE_FROM_CLASS (gobject_class),
1545 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1546 _gtk_boolean_handled_accumulator, NULL,
1547 _gtk_marshal_BOOLEAN__BOXED,
1549 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1552 * GtkWidget::map-event
1553 * @widget: the object which received the signal
1554 * @event: the #GdkEventAny which triggered this signal
1556 * The ::map-event signal will be emitted when the @widget's window is
1557 * mapped. A window is mapped when it becomes visible on the screen.
1559 * To receive this signal, the #GdkWindow associated to the widget needs
1560 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1561 * automatically for all new windows.
1563 * Returns: %TRUE to stop other handlers from being invoked for the event.
1564 * %FALSE to propagate the event further.
1566 widget_signals[MAP_EVENT] =
1567 g_signal_new (I_("map-event"),
1568 G_TYPE_FROM_CLASS (gobject_class),
1570 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1571 _gtk_boolean_handled_accumulator, NULL,
1572 _gtk_marshal_BOOLEAN__BOXED,
1574 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1577 * GtkWidget::unmap-event
1578 * @widget: the object which received the signal
1579 * @event: the #GdkEventAny which triggered this signal
1581 * The ::unmap-event signal may be emitted when the @widget's window is
1582 * unmapped. A window is unmapped when it becomes invisible on the screen.
1584 * For performance reasons GTK+ may not emit ::unmap-event, so one
1585 * should always also implement ::unrealize in order to release
1586 * resources and disconnect signal handlers.
1588 * To receive this signal, the #GdkWindow associated to the widget needs
1589 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1590 * automatically for all new windows.
1592 * Returns: %TRUE to stop other handlers from being invoked for the event.
1593 * %FALSE to propagate the event further.
1595 widget_signals[UNMAP_EVENT] =
1596 g_signal_new (I_("unmap-event"),
1597 G_TYPE_FROM_CLASS (gobject_class),
1599 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1600 _gtk_boolean_handled_accumulator, NULL,
1601 _gtk_marshal_BOOLEAN__BOXED,
1603 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1606 * GtkWidget::property-notify-event
1607 * @widget: the object which received the signal
1608 * @event: the #GdkEventProperty which triggered this signal
1610 * The ::property-notify-event signal will be emitted when a property on
1611 * the @widget's window has been changed or deleted.
1613 * To receive this signal, the #GdkWindow associated to the widget needs
1614 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1616 * Returns: %TRUE to stop other handlers from being invoked for the event.
1617 * %FALSE to propagate the event further.
1619 widget_signals[PROPERTY_NOTIFY_EVENT] =
1620 g_signal_new (I_("property-notify-event"),
1621 G_TYPE_FROM_CLASS (gobject_class),
1623 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1624 _gtk_boolean_handled_accumulator, NULL,
1625 _gtk_marshal_BOOLEAN__BOXED,
1627 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1630 * GtkWidget::selection-clear-event
1631 * @widget: the object which received the signal
1632 * @event: the #GdkEventSelection which triggered this signal
1634 * The ::selection-clear-event signal will be emitted when the
1635 * the @widget's window has lost ownership of a selection.
1637 * Returns: %TRUE to stop other handlers from being invoked for the event.
1638 * %FALSE to propagate the event further.
1640 widget_signals[SELECTION_CLEAR_EVENT] =
1641 g_signal_new (I_("selection-clear-event"),
1642 G_TYPE_FROM_CLASS (gobject_class),
1644 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1645 _gtk_boolean_handled_accumulator, NULL,
1646 _gtk_marshal_BOOLEAN__BOXED,
1648 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1651 * GtkWidget::selection-request-event
1652 * @widget: the object which received the signal
1653 * @event: the #GdkEventSelection which triggered this signal
1655 * The ::selection-request-event signal will be emitted when
1656 * another client requests ownership of the selection owned by
1657 * the @widget's window.
1659 * Returns: %TRUE to stop other handlers from being invoked for the event.
1660 * %FALSE to propagate the event further.
1662 widget_signals[SELECTION_REQUEST_EVENT] =
1663 g_signal_new (I_("selection-request-event"),
1664 G_TYPE_FROM_CLASS (gobject_class),
1666 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1667 _gtk_boolean_handled_accumulator, NULL,
1668 _gtk_marshal_BOOLEAN__BOXED,
1670 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1673 * GtkWidget::selection-notify-event:
1674 * @widget: the object which received the signal.
1677 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1679 widget_signals[SELECTION_NOTIFY_EVENT] =
1680 g_signal_new (I_("selection-notify-event"),
1681 G_TYPE_FROM_CLASS (gobject_class),
1683 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1684 _gtk_boolean_handled_accumulator, NULL,
1685 _gtk_marshal_BOOLEAN__BOXED,
1687 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1690 * GtkWidget::selection-received:
1691 * @widget: the object which received the signal.
1695 widget_signals[SELECTION_RECEIVED] =
1696 g_signal_new (I_("selection-received"),
1697 G_TYPE_FROM_CLASS (gobject_class),
1699 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1701 _gtk_marshal_VOID__BOXED_UINT,
1703 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1707 * GtkWidget::selection-get:
1708 * @widget: the object which received the signal.
1713 widget_signals[SELECTION_GET] =
1714 g_signal_new (I_("selection-get"),
1715 G_TYPE_FROM_CLASS (gobject_class),
1717 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1719 _gtk_marshal_VOID__BOXED_UINT_UINT,
1721 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1726 * GtkWidget::proximity-in-event
1727 * @widget: the object which received the signal
1728 * @event: the #GdkEventProximity which triggered this signal
1730 * To receive this signal the #GdkWindow associated to the widget needs
1731 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1733 * This signal will be sent to the grab widget if there is one.
1735 * Returns: %TRUE to stop other handlers from being invoked for the event.
1736 * %FALSE to propagate the event further.
1738 widget_signals[PROXIMITY_IN_EVENT] =
1739 g_signal_new (I_("proximity-in-event"),
1740 G_TYPE_FROM_CLASS (gobject_class),
1742 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1743 _gtk_boolean_handled_accumulator, NULL,
1744 _gtk_marshal_BOOLEAN__BOXED,
1746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1749 * GtkWidget::proximity-out-event
1750 * @widget: the object which received the signal
1751 * @event: the #GdkEventProximity which triggered this signal
1753 * To receive this signal the #GdkWindow associated to the widget needs
1754 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1756 * This signal will be sent to the grab widget if there is one.
1758 * Returns: %TRUE to stop other handlers from being invoked for the event.
1759 * %FALSE to propagate the event further.
1761 widget_signals[PROXIMITY_OUT_EVENT] =
1762 g_signal_new (I_("proximity-out-event"),
1763 G_TYPE_FROM_CLASS (gobject_class),
1765 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1766 _gtk_boolean_handled_accumulator, NULL,
1767 _gtk_marshal_BOOLEAN__BOXED,
1769 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1772 * GtkWidget::drag-leave:
1773 * @widget: the object which received the signal.
1774 * @drag_context: the drag context
1775 * @time: the timestamp of the motion event
1777 * The ::drag-leave signal is emitted on the drop site when the cursor
1778 * leaves the widget. A typical reason to connect to this signal is to
1779 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1780 * with gtk_drag_unhighlight()
1782 widget_signals[DRAG_LEAVE] =
1783 g_signal_new (I_("drag-leave"),
1784 G_TYPE_FROM_CLASS (gobject_class),
1786 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1788 _gtk_marshal_VOID__OBJECT_UINT,
1790 GDK_TYPE_DRAG_CONTEXT,
1794 * GtkWidget::drag-begin:
1795 * @widget: the object which received the signal
1796 * @drag_context: the drag context
1798 * The ::drag-begin signal is emitted on the drag source when a drag is
1799 * started. A typical reason to connect to this signal is to set up a
1800 * custom drag icon with gtk_drag_source_set_icon().
1802 * Note that some widgets set up a drag icon in the default handler of
1803 * this signal, so you may have to use g_signal_connect_after() to
1804 * override what the default handler did.
1806 widget_signals[DRAG_BEGIN] =
1807 g_signal_new (I_("drag-begin"),
1808 G_TYPE_FROM_CLASS (gobject_class),
1810 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1812 _gtk_marshal_VOID__OBJECT,
1814 GDK_TYPE_DRAG_CONTEXT);
1817 * GtkWidget::drag-end:
1818 * @widget: the object which received the signal
1819 * @drag_context: the drag context
1821 * The ::drag-end signal is emitted on the drag source when a drag is
1822 * finished. A typical reason to connect to this signal is to undo
1823 * things done in #GtkWidget::drag-begin.
1825 widget_signals[DRAG_END] =
1826 g_signal_new (I_("drag-end"),
1827 G_TYPE_FROM_CLASS (gobject_class),
1829 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1831 _gtk_marshal_VOID__OBJECT,
1833 GDK_TYPE_DRAG_CONTEXT);
1836 * GtkWidget::drag-data-delete:
1837 * @widget: the object which received the signal
1838 * @drag_context: the drag context
1840 * The ::drag-data-delete signal is emitted on the drag source when a drag
1841 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1842 * handler is responsible for deleting the data that has been dropped. What
1843 * "delete" means depends on the context of the drag operation.
1845 widget_signals[DRAG_DATA_DELETE] =
1846 g_signal_new (I_("drag-data-delete"),
1847 G_TYPE_FROM_CLASS (gobject_class),
1849 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1851 _gtk_marshal_VOID__OBJECT,
1853 GDK_TYPE_DRAG_CONTEXT);
1856 * GtkWidget::drag-failed:
1857 * @widget: the object which received the signal
1858 * @drag_context: the drag context
1859 * @result: the result of the drag operation
1861 * The ::drag-failed signal is emitted on the drag source when a drag has
1862 * failed. The signal handler may hook custom code to handle a failed DND
1863 * operation based on the type of error, it returns %TRUE is the failure has
1864 * been already handled (not showing the default "drag operation failed"
1865 * animation), otherwise it returns %FALSE.
1867 * Return value: %TRUE if the failed drag operation has been already handled.
1871 widget_signals[DRAG_FAILED] =
1872 g_signal_new (I_("drag-failed"),
1873 G_TYPE_FROM_CLASS (gobject_class),
1875 0, _gtk_boolean_handled_accumulator, NULL,
1876 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1878 GDK_TYPE_DRAG_CONTEXT,
1879 GTK_TYPE_DRAG_RESULT);
1882 * GtkWidget::drag-motion:
1883 * @widget: the object which received the signal
1884 * @drag_context: the drag context
1885 * @x: the x coordinate of the current cursor position
1886 * @y: the y coordinate of the current cursor position
1887 * @time: the timestamp of the motion event
1888 * @returns: whether the cursor position is in a drop zone
1890 * The drag-motion signal is emitted on the drop site when the user
1891 * moves the cursor over the widget during a drag. The signal handler
1892 * must determine whether the cursor position is in a drop zone or not.
1893 * If it is not in a drop zone, it returns %FALSE and no further processing
1894 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1895 * handler is responsible for providing the necessary information for
1896 * displaying feedback to the user, by calling gdk_drag_status().
1898 * If the decision whether the drop will be accepted or rejected can't be
1899 * made based solely on the cursor position and the type of the data, the
1900 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1901 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1902 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1903 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1904 * when using the drag-motion signal that way.
1906 * Also note that there is no drag-enter signal. The drag receiver has to
1907 * keep track of whether he has received any drag-motion signals since the
1908 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1909 * an "enter" signal. Upon an "enter", the handler will typically highlight
1910 * the drop site with gtk_drag_highlight().
1913 * drag_motion (GtkWidget *widget,
1914 * GdkDragContext *context,
1921 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1923 * if (!private_data->drag_highlight)
1925 * private_data->drag_highlight = 1;
1926 * gtk_drag_highlight (widget);
1929 * target = gtk_drag_dest_find_target (widget, context, NULL);
1930 * if (target == GDK_NONE)
1931 * gdk_drag_status (context, 0, time);
1934 * private_data->pending_status = context->suggested_action;
1935 * gtk_drag_get_data (widget, context, target, time);
1942 * drag_data_received (GtkWidget *widget,
1943 * GdkDragContext *context,
1946 * GtkSelectionData *selection_data,
1950 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1952 * if (private_data->suggested_action)
1954 * private_data->suggested_action = 0;
1956 * /* We are getting this data due to a request in drag_motion,
1957 * * rather than due to a request in drag_drop, so we are just
1958 * * supposed to call gdk_drag_status (), not actually paste in
1961 * str = gtk_selection_data_get_text (selection_data);
1962 * if (!data_is_acceptable (str))
1963 * gdk_drag_status (context, 0, time);
1965 * gdk_drag_status (context, private_data->suggested_action, time);
1969 * /* accept the drop */
1974 widget_signals[DRAG_MOTION] =
1975 g_signal_new (I_("drag-motion"),
1976 G_TYPE_FROM_CLASS (gobject_class),
1978 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1979 _gtk_boolean_handled_accumulator, NULL,
1980 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1982 GDK_TYPE_DRAG_CONTEXT,
1988 * GtkWidget::drag-drop:
1989 * @widget: the object which received the signal
1990 * @drag_context: the drag context
1991 * @x: the x coordinate of the current cursor position
1992 * @y: the y coordinate of the current cursor position
1993 * @time: the timestamp of the motion event
1994 * @returns: whether the cursor position is in a drop zone
1996 * The ::drag-drop signal is emitted on the drop site when the user drops
1997 * the data onto the widget. The signal handler must determine whether
1998 * the cursor position is in a drop zone or not. If it is not in a drop
1999 * zone, it returns %FALSE and no further processing is necessary.
2000 * Otherwise, the handler returns %TRUE. In this case, the handler must
2001 * ensure that gtk_drag_finish() is called to let the source know that
2002 * the drop is done. The call to gtk_drag_finish() can be done either
2003 * directly or in a #GtkWidget::drag-data-received handler which gets
2004 * triggered by calling gtk_drag_get_data() to receive the data for one
2005 * or more of the supported targets.
2007 widget_signals[DRAG_DROP] =
2008 g_signal_new (I_("drag-drop"),
2009 G_TYPE_FROM_CLASS (gobject_class),
2011 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2012 _gtk_boolean_handled_accumulator, NULL,
2013 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2015 GDK_TYPE_DRAG_CONTEXT,
2021 * GtkWidget::drag-data-get:
2022 * @widget: the object which received the signal
2023 * @drag_context: the drag context
2024 * @data: the #GtkSelectionData to be filled with the dragged data
2025 * @info: the info that has been registered with the target in the
2027 * @time: the timestamp at which the data was requested
2029 * The ::drag-data-get signal is emitted on the drag source when the drop
2030 * site requests the data which is dragged. It is the responsibility of
2031 * the signal handler to fill @data with the data in the format which
2032 * is indicated by @info. See gtk_selection_data_set() and
2033 * gtk_selection_data_set_text().
2035 widget_signals[DRAG_DATA_GET] =
2036 g_signal_new (I_("drag-data-get"),
2037 G_TYPE_FROM_CLASS (gobject_class),
2039 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2041 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2043 GDK_TYPE_DRAG_CONTEXT,
2044 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2049 * GtkWidget::drag-data-received:
2050 * @widget: the object which received the signal
2051 * @drag_context: the drag context
2052 * @x: where the drop happened
2053 * @y: where the drop happened
2054 * @data: the received data
2055 * @info: the info that has been registered with the target in the
2057 * @time: the timestamp at which the data was received
2059 * The ::drag-data-received signal is emitted on the drop site when the
2060 * dragged data has been received. If the data was received in order to
2061 * determine whether the drop will be accepted, the handler is expected
2062 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2063 * If the data was received in response to a #GtkWidget::drag-drop signal
2064 * (and this is the last target to be received), the handler for this
2065 * signal is expected to process the received data and then call
2066 * gtk_drag_finish(), setting the @success parameter depending on whether
2067 * the data was processed successfully.
2069 * The handler may inspect and modify @drag_context->action before calling
2070 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2071 * following example:
2074 * drag_data_received (GtkWidget *widget,
2075 * GdkDragContext *drag_context,
2078 * GtkSelectionData *data,
2082 * if ((data->length >= 0) && (data->format == 8))
2084 * if (drag_context->action == GDK_ACTION_ASK)
2086 * GtkWidget *dialog;
2089 * dialog = gtk_message_dialog_new (NULL,
2090 * GTK_DIALOG_MODAL |
2091 * GTK_DIALOG_DESTROY_WITH_PARENT,
2093 * GTK_BUTTONS_YES_NO,
2094 * "Move the data ?\n");
2095 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2096 * gtk_widget_destroy (dialog);
2098 * if (response == GTK_RESPONSE_YES)
2099 * drag_context->action = GDK_ACTION_MOVE;
2101 * drag_context->action = GDK_ACTION_COPY;
2104 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2108 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2112 widget_signals[DRAG_DATA_RECEIVED] =
2113 g_signal_new (I_("drag-data-received"),
2114 G_TYPE_FROM_CLASS (gobject_class),
2116 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2118 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2120 GDK_TYPE_DRAG_CONTEXT,
2123 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2128 * GtkWidget::visibility-notify-event:
2129 * @widget: the object which received the signal
2130 * @event: the #GdkEventVisibility which triggered this signal
2132 * The ::visibility-notify-event will be emitted when the @widget's window
2133 * is obscured or unobscured.
2135 * To receive this signal the #GdkWindow associated to the widget needs
2136 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2138 * Returns: %TRUE to stop other handlers from being invoked for the event.
2139 * %FALSE to propagate the event further.
2141 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2142 g_signal_new (I_("visibility-notify-event"),
2143 G_TYPE_FROM_CLASS (gobject_class),
2145 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2146 _gtk_boolean_handled_accumulator, NULL,
2147 _gtk_marshal_BOOLEAN__BOXED,
2149 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2152 * GtkWidget::client-event:
2153 * @widget: the object which received the signal
2154 * @event: the #GdkEventClient which triggered this signal
2156 * The ::client-event will be emitted when the @widget's window
2157 * receives a message (via a ClientMessage event) from another
2160 * Returns: %TRUE to stop other handlers from being invoked for
2161 * the event. %FALSE to propagate the event further.
2163 widget_signals[CLIENT_EVENT] =
2164 g_signal_new (I_("client-event"),
2165 G_TYPE_FROM_CLASS (gobject_class),
2167 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2174 * GtkWidget::no-expose-event:
2175 * @widget: the object which received the signal
2176 * @event: the #GdkEventNoExpose which triggered this signal
2178 * The ::no-expose-event will be emitted when the @widget's window is
2179 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable())
2180 * which was completely unobscured. If the source
2181 * window was partially obscured #GdkEventExpose events will be generated
2184 * Returns: %TRUE to stop other handlers from being invoked for the event.
2185 * %FALSE to propagate the event further.
2187 widget_signals[NO_EXPOSE_EVENT] =
2188 g_signal_new (I_("no-expose-event"),
2189 G_TYPE_FROM_CLASS (gobject_class),
2191 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2192 _gtk_boolean_handled_accumulator, NULL,
2193 _gtk_marshal_BOOLEAN__BOXED,
2195 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2198 * GtkWidget::window-state-event:
2199 * @widget: the object which received the signal
2200 * @event: the #GdkEventWindowState which triggered this signal
2202 * The ::window-state-event will be emitted when the state of the
2203 * toplevel window associated to the @widget changes.
2205 * To receive this signal the #GdkWindow associated to the widget
2206 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2207 * this mask automatically for all new windows.
2209 * Returns: %TRUE to stop other handlers from being invoked for the
2210 * event. %FALSE to propagate the event further.
2212 widget_signals[WINDOW_STATE_EVENT] =
2213 g_signal_new (I_("window-state-event"),
2214 G_TYPE_FROM_CLASS (gobject_class),
2216 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2217 _gtk_boolean_handled_accumulator, NULL,
2218 _gtk_marshal_BOOLEAN__BOXED,
2220 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2223 * GtkWidget::damage-event:
2224 * @widget: the object which received the signal
2225 * @event: the #GdkEventExpose event
2227 * Emitted when a redirected window belonging to @widget gets drawn into.
2228 * The region/area members of the event shows what area of the redirected
2229 * drawable was drawn into.
2231 * Returns: %TRUE to stop other handlers from being invoked for the event.
2232 * %FALSE to propagate the event further.
2236 widget_signals[DAMAGE_EVENT] =
2237 g_signal_new (I_("damage-event"),
2238 G_TYPE_FROM_CLASS (gobject_class),
2241 _gtk_boolean_handled_accumulator, NULL,
2242 _gtk_marshal_BOOLEAN__BOXED,
2244 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2246 * GtkWidget::grab-broken-event:
2247 * @widget: the object which received the signal
2248 * @event: the #GdkEventGrabBroken event
2250 * Emitted when a pointer or keyboard grab on a window belonging
2251 * to @widget gets broken.
2253 * On X11, this happens when the grab window becomes unviewable
2254 * (i.e. it or one of its ancestors is unmapped), or if the same
2255 * application grabs the pointer or keyboard again.
2257 * Returns: %TRUE to stop other handlers from being invoked for
2258 * the event. %FALSE to propagate the event further.
2262 widget_signals[GRAB_BROKEN] =
2263 g_signal_new (I_("grab-broken-event"),
2264 G_TYPE_FROM_CLASS (gobject_class),
2266 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2267 _gtk_boolean_handled_accumulator, NULL,
2268 _gtk_marshal_BOOLEAN__BOXED,
2270 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2272 * GtkWidget::query-tooltip:
2273 * @widget: the object which received the signal
2274 * @x: the x coordinate of the cursor position where the request has
2275 * been emitted, relative to @widget->window
2276 * @y: the y coordinate of the cursor position where the request has
2277 * been emitted, relative to @widget->window
2278 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2279 * @tooltip: a #GtkTooltip
2281 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2282 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2283 * focus in keyboard mode.
2285 * Using the given coordinates, the signal handler should determine
2286 * whether a tooltip should be shown for @widget. If this is the case
2287 * %TRUE should be returned, %FALSE otherwise. Note that if
2288 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2289 * should not be used.
2291 * The signal handler is free to manipulate @tooltip with the therefore
2292 * destined function calls.
2294 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2298 widget_signals[QUERY_TOOLTIP] =
2299 g_signal_new (I_("query-tooltip"),
2300 G_TYPE_FROM_CLASS (gobject_class),
2302 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2303 _gtk_boolean_handled_accumulator, NULL,
2304 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2312 * GtkWidget::popup-menu
2313 * @widget: the object which received the signal
2315 * This signal gets emitted whenever a widget should pop up a context
2316 * menu. This usually happens through the standard key binding mechanism;
2317 * by pressing a certain key while a widget is focused, the user can cause
2318 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2319 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2320 * for an example of how to use this signal.
2322 * Returns: %TRUE if a menu was activated
2324 widget_signals[POPUP_MENU] =
2325 g_signal_new (I_("popup-menu"),
2326 G_TYPE_FROM_CLASS (gobject_class),
2327 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2328 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2329 _gtk_boolean_handled_accumulator, NULL,
2330 _gtk_marshal_BOOLEAN__VOID,
2334 * GtkWidget::show-help:
2335 * @widget: the object which received the signal.
2338 widget_signals[SHOW_HELP] =
2339 g_signal_new (I_("show-help"),
2340 G_TYPE_FROM_CLASS (gobject_class),
2341 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2342 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2343 _gtk_boolean_handled_accumulator, NULL,
2344 _gtk_marshal_BOOLEAN__ENUM,
2346 GTK_TYPE_WIDGET_HELP_TYPE);
2349 * GtkWidget::accel-closures-changed:
2350 * @widget: the object which received the signal.
2352 widget_signals[ACCEL_CLOSURES_CHANGED] =
2353 g_signal_new (I_("accel-closures-changed"),
2354 G_TYPE_FROM_CLASS (gobject_class),
2358 _gtk_marshal_VOID__VOID,
2362 * GtkWidget::screen-changed:
2363 * @widget: the object on which the signal is emitted
2364 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2365 * widget was not associated with a screen before
2367 * The ::screen-changed signal gets emitted when the
2368 * screen of a widget has changed.
2370 widget_signals[SCREEN_CHANGED] =
2371 g_signal_new (I_("screen-changed"),
2372 G_TYPE_FROM_CLASS (gobject_class),
2374 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2376 _gtk_marshal_VOID__OBJECT,
2381 * GtkWidget::can-activate-accel:
2382 * @widget: the object which received the signal
2383 * @signal_id: the ID of a signal installed on @widget
2385 * Determines whether an accelerator that activates the signal
2386 * identified by @signal_id can currently be activated.
2387 * This signal is present to allow applications and derived
2388 * widgets to override the default #GtkWidget handling
2389 * for determining whether an accelerator can be activated.
2391 * Returns: %TRUE if the signal can be activated.
2393 widget_signals[CAN_ACTIVATE_ACCEL] =
2394 g_signal_new (I_("can-activate-accel"),
2395 G_TYPE_FROM_CLASS (gobject_class),
2397 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2398 _gtk_boolean_handled_accumulator, NULL,
2399 _gtk_marshal_BOOLEAN__UINT,
2400 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2402 binding_set = gtk_binding_set_by_class (klass);
2403 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2405 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2408 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2410 GTK_TYPE_WIDGET_HELP_TYPE,
2411 GTK_WIDGET_HELP_TOOLTIP);
2412 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2414 GTK_TYPE_WIDGET_HELP_TYPE,
2415 GTK_WIDGET_HELP_TOOLTIP);
2416 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2418 GTK_TYPE_WIDGET_HELP_TYPE,
2419 GTK_WIDGET_HELP_WHATS_THIS);
2420 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2422 GTK_TYPE_WIDGET_HELP_TYPE,
2423 GTK_WIDGET_HELP_WHATS_THIS);
2425 gtk_widget_class_install_style_property (klass,
2426 g_param_spec_boolean ("interior-focus",
2427 P_("Interior Focus"),
2428 P_("Whether to draw the focus indicator inside widgets"),
2430 GTK_PARAM_READABLE));
2432 gtk_widget_class_install_style_property (klass,
2433 g_param_spec_int ("focus-line-width",
2434 P_("Focus linewidth"),
2435 P_("Width, in pixels, of the focus indicator line"),
2437 GTK_PARAM_READABLE));
2439 gtk_widget_class_install_style_property (klass,
2440 g_param_spec_string ("focus-line-pattern",
2441 P_("Focus line dash pattern"),
2442 P_("Dash pattern used to draw the focus indicator"),
2444 GTK_PARAM_READABLE));
2445 gtk_widget_class_install_style_property (klass,
2446 g_param_spec_int ("focus-padding",
2447 P_("Focus padding"),
2448 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2450 GTK_PARAM_READABLE));
2451 gtk_widget_class_install_style_property (klass,
2452 g_param_spec_boxed ("cursor-color",
2454 P_("Color with which to draw insertion cursor"),
2456 GTK_PARAM_READABLE));
2457 gtk_widget_class_install_style_property (klass,
2458 g_param_spec_boxed ("secondary-cursor-color",
2459 P_("Secondary cursor color"),
2460 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2462 GTK_PARAM_READABLE));
2463 gtk_widget_class_install_style_property (klass,
2464 g_param_spec_float ("cursor-aspect-ratio",
2465 P_("Cursor line aspect ratio"),
2466 P_("Aspect ratio with which to draw insertion cursor"),
2468 GTK_PARAM_READABLE));
2471 * GtkWidget:draw-border:
2473 * The "draw-border" style property defines the size of areas outside
2474 * the widget's allocation to draw.
2478 gtk_widget_class_install_style_property (klass,
2479 g_param_spec_boxed ("draw-border",
2481 P_("Size of areas outside the widget's allocation to draw"),
2483 GTK_PARAM_READABLE));
2486 * GtkWidget:link-color:
2488 * The "link-color" style property defines the color of unvisited links.
2492 gtk_widget_class_install_style_property (klass,
2493 g_param_spec_boxed ("link-color",
2494 P_("Unvisited Link Color"),
2495 P_("Color of unvisited links"),
2497 GTK_PARAM_READABLE));
2500 * GtkWidget:visited-link-color:
2502 * The "visited-link-color" style property defines the color of visited links.
2506 gtk_widget_class_install_style_property (klass,
2507 g_param_spec_boxed ("visited-link-color",
2508 P_("Visited Link Color"),
2509 P_("Color of visited links"),
2511 GTK_PARAM_READABLE));
2514 * GtkWidget:wide-separators:
2516 * The "wide-separators" style property defines whether separators have
2517 * configurable width and should be drawn using a box instead of a line.
2521 gtk_widget_class_install_style_property (klass,
2522 g_param_spec_boolean ("wide-separators",
2523 P_("Wide Separators"),
2524 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2526 GTK_PARAM_READABLE));
2529 * GtkWidget:separator-width:
2531 * The "separator-width" style property defines the width of separators.
2532 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2536 gtk_widget_class_install_style_property (klass,
2537 g_param_spec_int ("separator-width",
2538 P_("Separator Width"),
2539 P_("The width of separators if wide-separators is TRUE"),
2541 GTK_PARAM_READABLE));
2544 * GtkWidget:separator-height:
2546 * The "separator-height" style property defines the height of separators.
2547 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2551 gtk_widget_class_install_style_property (klass,
2552 g_param_spec_int ("separator-height",
2553 P_("Separator Height"),
2554 P_("The height of separators if \"wide-separators\" is TRUE"),
2556 GTK_PARAM_READABLE));
2559 * GtkWidget:scroll-arrow-hlength:
2561 * The "scroll-arrow-hlength" style property defines the length of
2562 * horizontal scroll arrows.
2566 gtk_widget_class_install_style_property (klass,
2567 g_param_spec_int ("scroll-arrow-hlength",
2568 P_("Horizontal Scroll Arrow Length"),
2569 P_("The length of horizontal scroll arrows"),
2571 GTK_PARAM_READABLE));
2574 * GtkWidget:scroll-arrow-vlength:
2576 * The "scroll-arrow-vlength" style property defines the length of
2577 * vertical scroll arrows.
2581 gtk_widget_class_install_style_property (klass,
2582 g_param_spec_int ("scroll-arrow-vlength",
2583 P_("Vertical Scroll Arrow Length"),
2584 P_("The length of vertical scroll arrows"),
2586 GTK_PARAM_READABLE));
2590 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2594 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2595 for (node = list; node; node = node->next)
2597 GParamSpec *pspec = node->data;
2599 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2600 g_param_spec_unref (pspec);
2606 gtk_widget_set_property (GObject *object,
2608 const GValue *value,
2611 GtkWidget *widget = GTK_WIDGET (object);
2616 gchar *tooltip_markup;
2617 const gchar *tooltip_text;
2618 GtkWindow *tooltip_window;
2621 gtk_widget_set_name (widget, g_value_get_string (value));
2624 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2626 case PROP_WIDTH_REQUEST:
2627 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2629 case PROP_HEIGHT_REQUEST:
2630 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2633 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2635 case PROP_SENSITIVE:
2636 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2638 case PROP_APP_PAINTABLE:
2639 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2641 case PROP_CAN_FOCUS:
2642 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2644 case PROP_HAS_FOCUS:
2645 if (g_value_get_boolean (value))
2646 gtk_widget_grab_focus (widget);
2649 if (g_value_get_boolean (value))
2650 gtk_widget_grab_focus (widget);
2652 case PROP_CAN_DEFAULT:
2653 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2655 case PROP_HAS_DEFAULT:
2656 if (g_value_get_boolean (value))
2657 gtk_widget_grab_default (widget);
2659 case PROP_RECEIVES_DEFAULT:
2660 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2663 gtk_widget_set_style (widget, g_value_get_object (value));
2666 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2667 gtk_widget_set_events (widget, g_value_get_flags (value));
2669 case PROP_EXTENSION_EVENTS:
2670 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2672 case PROP_NO_SHOW_ALL:
2673 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2675 case PROP_HAS_TOOLTIP:
2676 gtk_widget_real_set_has_tooltip (widget,
2677 g_value_get_boolean (value), FALSE);
2679 case PROP_TOOLTIP_MARKUP:
2680 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2681 tooltip_markup = g_value_dup_string (value);
2683 /* Treat an empty string as a NULL string,
2684 * because an empty string would be useless for a tooltip:
2686 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2688 g_free (tooltip_markup);
2689 tooltip_markup = NULL;
2692 g_object_set_qdata_full (object, quark_tooltip_markup,
2693 tooltip_markup, g_free);
2695 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2696 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2697 if (gtk_widget_get_visible (widget))
2698 gtk_widget_queue_tooltip_query (widget);
2700 case PROP_TOOLTIP_TEXT:
2701 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2703 tooltip_text = g_value_get_string (value);
2705 /* Treat an empty string as a NULL string,
2706 * because an empty string would be useless for a tooltip:
2708 if (tooltip_text && (strlen (tooltip_text) == 0))
2709 tooltip_text = NULL;
2711 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2713 g_object_set_qdata_full (object, quark_tooltip_markup,
2714 tooltip_markup, g_free);
2716 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2717 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2718 if (gtk_widget_get_visible (widget))
2719 gtk_widget_queue_tooltip_query (widget);
2721 case PROP_DOUBLE_BUFFERED:
2722 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2725 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2731 gtk_widget_get_property (GObject *object,
2736 GtkWidget *widget = GTK_WIDGET (object);
2745 g_value_set_string (value, widget->name);
2747 g_value_set_static_string (value, "");
2750 g_value_set_object (value, widget->parent);
2752 case PROP_WIDTH_REQUEST:
2755 gtk_widget_get_size_request (widget, &w, NULL);
2756 g_value_set_int (value, w);
2759 case PROP_HEIGHT_REQUEST:
2762 gtk_widget_get_size_request (widget, NULL, &h);
2763 g_value_set_int (value, h);
2767 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2769 case PROP_SENSITIVE:
2770 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2772 case PROP_APP_PAINTABLE:
2773 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2775 case PROP_CAN_FOCUS:
2776 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2778 case PROP_HAS_FOCUS:
2779 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2782 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2784 case PROP_CAN_DEFAULT:
2785 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2787 case PROP_HAS_DEFAULT:
2788 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2790 case PROP_RECEIVES_DEFAULT:
2791 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2793 case PROP_COMPOSITE_CHILD:
2794 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2797 g_value_set_object (value, gtk_widget_get_style (widget));
2800 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2801 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2803 case PROP_EXTENSION_EVENTS:
2804 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2805 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2807 case PROP_NO_SHOW_ALL:
2808 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2810 case PROP_HAS_TOOLTIP:
2811 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2813 case PROP_TOOLTIP_TEXT:
2815 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2818 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2819 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2821 g_value_take_string (value, text);
2824 case PROP_TOOLTIP_MARKUP:
2825 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2828 g_value_set_object (value, gtk_widget_get_window (widget));
2830 case PROP_DOUBLE_BUFFERED:
2831 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2834 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2840 gtk_widget_init (GtkWidget *widget)
2842 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2843 widget->state = GTK_STATE_NORMAL;
2844 widget->saved_state = GTK_STATE_NORMAL;
2845 widget->name = NULL;
2846 widget->requisition.width = 0;
2847 widget->requisition.height = 0;
2848 widget->allocation.x = -1;
2849 widget->allocation.y = -1;
2850 widget->allocation.width = 1;
2851 widget->allocation.height = 1;
2852 widget->window = NULL;
2853 widget->parent = NULL;
2855 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2856 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2857 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2858 gtk_widget_set_double_buffered (widget, TRUE);
2860 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2861 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2862 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
2863 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
2864 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2866 widget->style = gtk_widget_get_default_style ();
2867 g_object_ref (widget->style);
2872 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2874 GParamSpec **pspecs)
2876 GtkWidget *container = widget->parent;
2879 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2880 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2884 * gtk_widget_freeze_child_notify:
2885 * @widget: a #GtkWidget
2887 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2888 * signals are queued until gtk_widget_thaw_child_notify() is called
2891 * This is the analogue of g_object_freeze_notify() for child properties.
2894 gtk_widget_freeze_child_notify (GtkWidget *widget)
2896 g_return_if_fail (GTK_IS_WIDGET (widget));
2898 if (!G_OBJECT (widget)->ref_count)
2901 g_object_ref (widget);
2902 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2903 g_object_unref (widget);
2907 * gtk_widget_child_notify:
2908 * @widget: a #GtkWidget
2909 * @child_property: the name of a child property installed on the
2910 * class of @widget<!-- -->'s parent
2912 * Emits a #GtkWidget::child-notify signal for the
2913 * <link linkend="child-properties">child property</link> @child_property
2916 * This is the analogue of g_object_notify() for child properties.
2919 gtk_widget_child_notify (GtkWidget *widget,
2920 const gchar *child_property)
2924 g_return_if_fail (GTK_IS_WIDGET (widget));
2925 g_return_if_fail (child_property != NULL);
2926 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2929 g_object_ref (widget);
2930 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2932 G_OBJECT_TYPE (widget->parent),
2935 g_warning ("%s: container class `%s' has no child property named `%s'",
2937 G_OBJECT_TYPE_NAME (widget->parent),
2941 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2943 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2944 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2946 g_object_unref (widget);
2950 * gtk_widget_thaw_child_notify:
2951 * @widget: a #GtkWidget
2953 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2954 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2958 gtk_widget_thaw_child_notify (GtkWidget *widget)
2960 GObjectNotifyQueue *nqueue;
2962 g_return_if_fail (GTK_IS_WIDGET (widget));
2964 if (!G_OBJECT (widget)->ref_count)
2967 g_object_ref (widget);
2968 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2969 if (!nqueue || !nqueue->freeze_count)
2970 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2971 G_OBJECT_TYPE_NAME (widget), widget);
2973 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2974 g_object_unref (widget);
2980 * @type: type ID of the widget to create
2981 * @first_property_name: name of first property to set
2982 * @Varargs: value of first property, followed by more properties,
2985 * This is a convenience function for creating a widget and setting
2986 * its properties in one go. For example you might write:
2987 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2988 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2989 * g_object_new(), but returns a widget so you don't have to
2990 * cast the object yourself.
2992 * Return value: a new #GtkWidget of type @widget_type
2995 gtk_widget_new (GType type,
2996 const gchar *first_property_name,
3002 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3004 va_start (var_args, first_property_name);
3005 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3012 gtk_widget_queue_draw_child (GtkWidget *widget)
3016 parent = widget->parent;
3017 if (parent && gtk_widget_is_drawable (parent))
3018 gtk_widget_queue_draw_area (parent,
3019 widget->allocation.x,
3020 widget->allocation.y,
3021 widget->allocation.width,
3022 widget->allocation.height);
3026 * gtk_widget_unparent:
3027 * @widget: a #GtkWidget
3029 * This function is only for use in widget implementations.
3030 * Should be called by implementations of the remove method
3031 * on #GtkContainer, to dissociate a child from the container.
3034 gtk_widget_unparent (GtkWidget *widget)
3036 GObjectNotifyQueue *nqueue;
3037 GtkWidget *toplevel;
3038 GtkWidget *old_parent;
3040 g_return_if_fail (GTK_IS_WIDGET (widget));
3041 if (widget->parent == NULL)
3044 /* keep this function in sync with gtk_menu_detach()
3047 g_object_freeze_notify (G_OBJECT (widget));
3048 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3050 toplevel = gtk_widget_get_toplevel (widget);
3051 if (gtk_widget_is_toplevel (toplevel))
3052 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3054 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3055 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3057 /* If we are unanchoring the child, we save around the toplevel
3058 * to emit hierarchy changed
3060 if (GTK_WIDGET_ANCHORED (widget->parent))
3061 g_object_ref (toplevel);
3065 gtk_widget_queue_draw_child (widget);
3067 /* Reset the width and height here, to force reallocation if we
3068 * get added back to a new parent. This won't work if our new
3069 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3070 * (would 0x0 be OK here?)
3072 widget->allocation.width = 1;
3073 widget->allocation.height = 1;
3075 if (gtk_widget_get_realized (widget))
3077 if (GTK_WIDGET_IN_REPARENT (widget))
3078 gtk_widget_unmap (widget);
3080 gtk_widget_unrealize (widget);
3083 /* Removing a widget from a container restores the child visible
3084 * flag to the default state, so it doesn't affect the child
3085 * in the next parent.
3087 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3089 old_parent = widget->parent;
3090 widget->parent = NULL;
3091 gtk_widget_set_parent_window (widget, NULL);
3092 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3095 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3096 g_object_unref (toplevel);
3099 g_object_notify (G_OBJECT (widget), "parent");
3100 g_object_thaw_notify (G_OBJECT (widget));
3101 if (!widget->parent)
3102 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3103 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3104 g_object_unref (widget);
3108 * gtk_widget_destroy:
3109 * @widget: a #GtkWidget
3111 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3112 * you don't have to cast the widget to #GtkObject. When a widget is
3113 * destroyed, it will break any references it holds to other objects.
3114 * If the widget is inside a container, the widget will be removed
3115 * from the container. If the widget is a toplevel (derived from
3116 * #GtkWindow), it will be removed from the list of toplevels, and the
3117 * reference GTK+ holds to it will be removed. Removing a
3118 * widget from its container or the list of toplevels results in the
3119 * widget being finalized, unless you've added additional references
3120 * to the widget with g_object_ref().
3122 * In most cases, only toplevel widgets (windows) require explicit
3123 * destruction, because when you destroy a toplevel its children will
3124 * be destroyed as well.
3127 gtk_widget_destroy (GtkWidget *widget)
3129 g_return_if_fail (GTK_IS_WIDGET (widget));
3131 gtk_object_destroy ((GtkObject*) widget);
3135 * gtk_widget_destroyed:
3136 * @widget: a #GtkWidget
3137 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3139 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3140 * %NULL. It's intended to be used as a callback connected to the
3141 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3142 * as a signal handler, and pass the address of your widget variable
3143 * as user data. Then when the widget is destroyed, the variable will
3144 * be set to %NULL. Useful for example to avoid multiple copies
3145 * of the same dialog.
3148 gtk_widget_destroyed (GtkWidget *widget,
3149 GtkWidget **widget_pointer)
3151 /* Don't make any assumptions about the
3153 * Even check widget_pointer.
3156 *widget_pointer = NULL;
3161 * @widget: a #GtkWidget
3163 * Flags a widget to be displayed. Any widget that isn't shown will
3164 * not appear on the screen. If you want to show all the widgets in a
3165 * container, it's easier to call gtk_widget_show_all() on the
3166 * container, instead of individually showing the widgets.
3168 * Remember that you have to show the containers containing a widget,
3169 * in addition to the widget itself, before it will appear onscreen.
3171 * When a toplevel container is shown, it is immediately realized and
3172 * mapped; other shown widgets are realized and mapped when their
3173 * toplevel container is realized and mapped.
3176 gtk_widget_show (GtkWidget *widget)
3178 g_return_if_fail (GTK_IS_WIDGET (widget));
3180 if (!gtk_widget_get_visible (widget))
3182 g_object_ref (widget);
3183 if (!gtk_widget_is_toplevel (widget))
3184 gtk_widget_queue_resize (widget);
3185 g_signal_emit (widget, widget_signals[SHOW], 0);
3186 g_object_notify (G_OBJECT (widget), "visible");
3187 g_object_unref (widget);
3192 gtk_widget_real_show (GtkWidget *widget)
3194 if (!gtk_widget_get_visible (widget))
3196 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3198 if (widget->parent &&
3199 gtk_widget_get_mapped (widget->parent) &&
3200 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3201 !gtk_widget_get_mapped (widget))
3202 gtk_widget_map (widget);
3207 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3210 g_signal_handlers_disconnect_by_func (widget,
3211 gtk_widget_show_map_callback,
3216 * gtk_widget_show_now:
3217 * @widget: a #GtkWidget
3219 * Shows a widget. If the widget is an unmapped toplevel widget
3220 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3221 * loop and wait for the window to actually be mapped. Be careful;
3222 * because the main loop is running, anything can happen during
3226 gtk_widget_show_now (GtkWidget *widget)
3230 g_return_if_fail (GTK_IS_WIDGET (widget));
3232 /* make sure we will get event */
3233 if (!gtk_widget_get_mapped (widget) &&
3234 gtk_widget_is_toplevel (widget))
3236 gtk_widget_show (widget);
3238 g_signal_connect (widget, "map-event",
3239 G_CALLBACK (gtk_widget_show_map_callback),
3243 gtk_main_iteration ();
3246 gtk_widget_show (widget);
3251 * @widget: a #GtkWidget
3253 * Reverses the effects of gtk_widget_show(), causing the widget to be
3254 * hidden (invisible to the user).
3257 gtk_widget_hide (GtkWidget *widget)
3259 g_return_if_fail (GTK_IS_WIDGET (widget));
3261 if (gtk_widget_get_visible (widget))
3263 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3265 g_object_ref (widget);
3266 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3267 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3269 g_signal_emit (widget, widget_signals[HIDE], 0);
3270 if (!gtk_widget_is_toplevel (widget))
3271 gtk_widget_queue_resize (widget);
3272 g_object_notify (G_OBJECT (widget), "visible");
3273 g_object_unref (widget);
3278 gtk_widget_real_hide (GtkWidget *widget)
3280 if (gtk_widget_get_visible (widget))
3282 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3284 if (gtk_widget_get_mapped (widget))
3285 gtk_widget_unmap (widget);
3290 * gtk_widget_hide_on_delete:
3291 * @widget: a #GtkWidget
3293 * Utility function; intended to be connected to the #GtkWidget::delete-event
3294 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3295 * argument, then returns %TRUE. If connected to ::delete-event, the
3296 * result is that clicking the close button for a window (on the
3297 * window frame, top right corner usually) will hide but not destroy
3298 * the window. By default, GTK+ destroys windows when ::delete-event
3301 * Return value: %TRUE
3304 gtk_widget_hide_on_delete (GtkWidget *widget)
3306 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3308 gtk_widget_hide (widget);
3314 * gtk_widget_show_all:
3315 * @widget: a #GtkWidget
3317 * Recursively shows a widget, and any child widgets (if the widget is
3321 gtk_widget_show_all (GtkWidget *widget)
3323 GtkWidgetClass *class;
3325 g_return_if_fail (GTK_IS_WIDGET (widget));
3327 if (gtk_widget_get_no_show_all (widget))
3330 class = GTK_WIDGET_GET_CLASS (widget);
3332 if (class->show_all)
3333 class->show_all (widget);
3337 * gtk_widget_hide_all:
3338 * @widget: a #GtkWidget
3340 * Recursively hides a widget and any child widgets.
3343 gtk_widget_hide_all (GtkWidget *widget)
3345 GtkWidgetClass *class;
3347 g_return_if_fail (GTK_IS_WIDGET (widget));
3349 if (gtk_widget_get_no_show_all (widget))
3352 class = GTK_WIDGET_GET_CLASS (widget);
3354 if (class->hide_all)
3355 class->hide_all (widget);
3360 * @widget: a #GtkWidget
3362 * This function is only for use in widget implementations. Causes
3363 * a widget to be mapped if it isn't already.
3366 gtk_widget_map (GtkWidget *widget)
3368 g_return_if_fail (GTK_IS_WIDGET (widget));
3369 g_return_if_fail (gtk_widget_get_visible (widget));
3370 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3372 if (!gtk_widget_get_mapped (widget))
3374 if (!gtk_widget_get_realized (widget))
3375 gtk_widget_realize (widget);
3377 g_signal_emit (widget, widget_signals[MAP], 0);
3379 if (!gtk_widget_get_has_window (widget))
3380 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3386 * @widget: a #GtkWidget
3388 * This function is only for use in widget implementations. Causes
3389 * a widget to be unmapped if it's currently mapped.
3392 gtk_widget_unmap (GtkWidget *widget)
3394 g_return_if_fail (GTK_IS_WIDGET (widget));
3396 if (gtk_widget_get_mapped (widget))
3398 if (!gtk_widget_get_has_window (widget))
3399 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3400 _gtk_tooltip_hide (widget);
3401 g_signal_emit (widget, widget_signals[UNMAP], 0);
3406 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3407 GdkExtensionMode mode,
3410 GList *free_list = NULL;
3413 if (window_list == NULL)
3415 if (gtk_widget_get_has_window (widget))
3416 window_list = g_list_prepend (NULL, widget->window);
3418 window_list = gdk_window_get_children (widget->window);
3420 free_list = window_list;
3423 for (l = window_list; l != NULL; l = l->next)
3425 GdkWindow *window = l->data;
3428 gdk_window_get_user_data (window, &user_data);
3429 if (user_data == widget)
3433 gdk_input_set_extension_events (window,
3434 gdk_window_get_events (window),
3437 children = gdk_window_get_children (window);
3440 gtk_widget_set_extension_events_internal (widget, mode, children);
3441 g_list_free (children);
3447 g_list_free (free_list);
3451 * gtk_widget_realize:
3452 * @widget: a #GtkWidget
3454 * Creates the GDK (windowing system) resources associated with a
3455 * widget. For example, @widget->window will be created when a widget
3456 * is realized. Normally realization happens implicitly; if you show
3457 * a widget and all its parent containers, then the widget will be
3458 * realized and mapped automatically.
3460 * Realizing a widget requires all
3461 * the widget's parent widgets to be realized; calling
3462 * gtk_widget_realize() realizes the widget's parents in addition to
3463 * @widget itself. If a widget is not yet inside a toplevel window
3464 * when you realize it, bad things will happen.
3466 * This function is primarily used in widget implementations, and
3467 * isn't very useful otherwise. Many times when you think you might
3468 * need it, a better approach is to connect to a signal that will be
3469 * called after the widget is realized automatically, such as
3470 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3471 * GtkWidget::realize signal.
3474 gtk_widget_realize (GtkWidget *widget)
3476 GdkExtensionMode mode;
3477 GtkWidgetShapeInfo *shape_info;
3479 g_return_if_fail (GTK_IS_WIDGET (widget));
3480 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3481 GTK_IS_INVISIBLE (widget));
3483 if (!gtk_widget_get_realized (widget))
3486 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3487 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3490 if (widget->parent == NULL &&
3491 !gtk_widget_is_toplevel (widget))
3492 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3493 "inside a toplevel window is not going to work very well. "
3494 "Widgets must be inside a toplevel container before realizing them.");
3496 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3497 gtk_widget_realize (widget->parent);
3499 gtk_widget_ensure_style (widget);
3501 g_signal_emit (widget, widget_signals[REALIZE], 0);
3503 gtk_widget_real_set_has_tooltip (widget,
3504 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3507 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3509 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3510 gdk_window_shape_combine_mask (widget->window,
3511 shape_info->shape_mask,
3512 shape_info->offset_x,
3513 shape_info->offset_y);
3516 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3518 gdk_window_input_shape_combine_mask (widget->window,
3519 shape_info->shape_mask,
3520 shape_info->offset_x,
3521 shape_info->offset_y);
3523 mode = gtk_widget_get_extension_events (widget);
3524 if (mode != GDK_EXTENSION_EVENTS_NONE)
3525 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3527 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3528 gdk_window_set_support_multidevice (widget->window, TRUE);
3533 * gtk_widget_unrealize:
3534 * @widget: a #GtkWidget
3536 * This function is only useful in widget implementations.
3537 * Causes a widget to be unrealized (frees all GDK resources
3538 * associated with the widget, such as @widget->window).
3541 gtk_widget_unrealize (GtkWidget *widget)
3543 g_return_if_fail (GTK_IS_WIDGET (widget));
3545 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3546 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3548 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3549 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3551 if (gtk_widget_get_realized (widget))
3553 g_object_ref (widget);
3554 _gtk_tooltip_hide (widget);
3555 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3556 gtk_widget_set_realized (widget, FALSE);
3557 gtk_widget_set_mapped (widget, FALSE);
3558 g_object_unref (widget);
3562 /*****************************************
3564 *****************************************/
3567 * gtk_widget_queue_draw_area:
3568 * @widget: a #GtkWidget
3569 * @x: x coordinate of upper-left corner of rectangle to redraw
3570 * @y: y coordinate of upper-left corner of rectangle to redraw
3571 * @width: width of region to draw
3572 * @height: height of region to draw
3574 * Invalidates the rectangular area of @widget defined by @x, @y,
3575 * @width and @height by calling gdk_window_invalidate_rect() on the
3576 * widget's window and all its child windows. Once the main loop
3577 * becomes idle (after the current batch of events has been processed,
3578 * roughly), the window will receive expose events for the union of
3579 * all regions that have been invalidated.
3581 * Normally you would only use this function in widget
3582 * implementations. You might also use it, or
3583 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3584 * #GtkDrawingArea or some portion thereof.
3586 * Frequently you can just call gdk_window_invalidate_rect() or
3587 * gdk_window_invalidate_region() instead of this function. Those
3588 * functions will invalidate only a single window, instead of the
3589 * widget and all its children.
3591 * The advantage of adding to the invalidated region compared to
3592 * simply drawing immediately is efficiency; using an invalid region
3593 * ensures that you only have to redraw one time.
3596 gtk_widget_queue_draw_area (GtkWidget *widget,
3602 GdkRectangle invalid_rect;
3605 g_return_if_fail (GTK_IS_WIDGET (widget));
3607 if (!gtk_widget_get_realized (widget))
3610 /* Just return if the widget or one of its ancestors isn't mapped */
3611 for (w = widget; w != NULL; w = w->parent)
3612 if (!gtk_widget_get_mapped (w))
3615 /* Find the correct widget */
3617 if (gtk_widget_get_has_window (widget))
3621 /* Translate widget relative to window-relative */
3623 gint wx, wy, wwidth, wheight;
3625 gdk_window_get_position (widget->window, &wx, &wy);
3626 x -= wx - widget->allocation.x;
3627 y -= wy - widget->allocation.y;
3629 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3631 if (x + width <= 0 || y + height <= 0 ||
3632 x >= wwidth || y >= wheight)
3643 if (x + width > wwidth)
3645 if (y + height > wheight)
3646 height = wheight - y;
3652 invalid_rect.width = width;
3653 invalid_rect.height = height;
3655 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3659 widget_add_child_draw_rectangle (GtkWidget *widget,
3662 GdkRectangle child_rect;
3664 if (!gtk_widget_get_mapped (widget) ||
3665 widget->window != widget->parent->window)
3668 gtk_widget_get_draw_rectangle (widget, &child_rect);
3669 gdk_rectangle_union (rect, &child_rect, rect);
3673 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3676 if (!gtk_widget_get_has_window (widget))
3678 GtkBorder *draw_border = NULL;
3680 *rect = widget->allocation;
3682 gtk_widget_style_get (widget,
3683 "draw-border", &draw_border,
3687 rect->x -= draw_border->left;
3688 rect->y -= draw_border->top;
3689 rect->width += draw_border->left + draw_border->right;
3690 rect->height += draw_border->top + draw_border->bottom;
3692 gtk_border_free (draw_border);
3695 if (GTK_IS_CONTAINER (widget))
3696 gtk_container_forall (GTK_CONTAINER (widget),
3697 (GtkCallback)widget_add_child_draw_rectangle,
3704 rect->width = widget->allocation.width;
3705 rect->height = widget->allocation.height;
3710 * gtk_widget_queue_draw:
3711 * @widget: a #GtkWidget
3713 * Equivalent to calling gtk_widget_queue_draw_area() for the
3714 * entire area of a widget.
3717 gtk_widget_queue_draw (GtkWidget *widget)
3721 g_return_if_fail (GTK_IS_WIDGET (widget));
3723 gtk_widget_get_draw_rectangle (widget, &rect);
3725 gtk_widget_queue_draw_area (widget,
3727 rect.width, rect.height);
3731 * gtk_widget_queue_resize:
3732 * @widget: a #GtkWidget
3734 * This function is only for use in widget implementations.
3735 * Flags a widget to have its size renegotiated; should
3736 * be called when a widget for some reason has a new size request.
3737 * For example, when you change the text in a #GtkLabel, #GtkLabel
3738 * queues a resize to ensure there's enough space for the new text.
3741 gtk_widget_queue_resize (GtkWidget *widget)
3743 g_return_if_fail (GTK_IS_WIDGET (widget));
3745 if (gtk_widget_get_realized (widget))
3746 gtk_widget_queue_shallow_draw (widget);
3748 _gtk_size_group_queue_resize (widget);
3752 * gtk_widget_queue_resize_no_redraw:
3753 * @widget: a #GtkWidget
3755 * This function works like gtk_widget_queue_resize(),
3756 * except that the widget is not invalidated.
3761 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3763 g_return_if_fail (GTK_IS_WIDGET (widget));
3765 _gtk_size_group_queue_resize (widget);
3769 * gtk_widget_size_request:
3770 * @widget: a #GtkWidget
3771 * @requisition: (out): a #GtkRequisition to be filled in
3773 * This function is typically used when implementing a #GtkContainer
3774 * subclass. Obtains the preferred size of a widget. The container
3775 * uses this information to arrange its child widgets and decide what
3776 * size allocations to give them with gtk_widget_size_allocate().
3778 * You can also call this function from an application, with some
3779 * caveats. Most notably, getting a size request requires the widget
3780 * to be associated with a screen, because font information may be
3781 * needed. Multihead-aware applications should keep this in mind.
3783 * Also remember that the size request is not necessarily the size
3784 * a widget will actually be allocated.
3786 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3789 gtk_widget_size_request (GtkWidget *widget,
3790 GtkRequisition *requisition)
3792 g_return_if_fail (GTK_IS_WIDGET (widget));
3794 #ifdef G_ENABLE_DEBUG
3795 if (requisition == &widget->requisition)
3796 g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
3797 "to widget->requisition. gtk_widget_set_usize() may not work properly.");
3798 #endif /* G_ENABLE_DEBUG */
3800 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget), FALSE, requisition, NULL);
3804 * gtk_widget_get_child_requisition:
3805 * @widget: a #GtkWidget
3806 * @requisition: (out): a #GtkRequisition to be filled in
3808 * This function is only for use in widget implementations. Obtains
3809 * @widget->requisition, unless someone has forced a particular
3810 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3811 * in which case it returns that geometry instead of the widget's
3814 * This function differs from gtk_widget_size_request() in that
3815 * it retrieves the last size request value from @widget->requisition,
3816 * while gtk_widget_size_request() actually calls the "size_request" method
3817 * on @widget to compute the size request and fill in @widget->requisition,
3818 * and only then returns @widget->requisition.
3820 * Because this function does not call the "size_request" method, it
3821 * can only be used when you know that @widget->requisition is
3822 * up-to-date, that is, gtk_widget_size_request() has been called
3823 * since the last time a resize was queued. In general, only container
3824 * implementations have this information; applications should use
3825 * gtk_widget_size_request().
3828 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3831 gtk_widget_get_child_requisition (GtkWidget *widget,
3832 GtkRequisition *requisition)
3834 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget), FALSE, requisition, NULL);
3838 invalidate_predicate (GdkWindow *window,
3843 gdk_window_get_user_data (window, &user_data);
3845 return (user_data == data);
3848 /* Invalidate @region in widget->window and all children
3849 * of widget->window owned by widget. @region is in the
3850 * same coordinates as widget->allocation and will be
3851 * modified by this call.
3854 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3857 if (!gtk_widget_get_realized (widget))
3860 if (gtk_widget_get_has_window (widget) && widget->parent)
3864 gdk_window_get_position (widget->window, &x, &y);
3865 gdk_region_offset (region, -x, -y);
3868 gdk_window_invalidate_maybe_recurse (widget->window, region,
3869 invalidate_predicate, widget);
3873 * gtk_widget_queue_shallow_draw:
3874 * @widget: a #GtkWidget
3876 * Like gtk_widget_queue_draw(), but only windows owned
3877 * by @widget are invalidated.
3880 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3885 if (!gtk_widget_get_realized (widget))
3888 gtk_widget_get_draw_rectangle (widget, &rect);
3890 /* get_draw_rectangle() gives us window coordinates, we
3891 * need to convert to the coordinates that widget->allocation
3894 if (gtk_widget_get_has_window (widget) && widget->parent)
3898 gdk_window_get_position (widget->window, &wx, &wy);
3904 region = gdk_region_rectangle (&rect);
3905 gtk_widget_invalidate_widget_windows (widget, region);
3906 gdk_region_destroy (region);
3910 * gtk_widget_size_allocate:
3911 * @widget: a #GtkWidget
3912 * @allocation: (inout): position and size to be allocated to @widget
3914 * This function is only used by #GtkContainer subclasses, to assign a size
3915 * and position to their child widgets.
3918 gtk_widget_size_allocate (GtkWidget *widget,
3919 GtkAllocation *allocation)
3921 GtkWidgetAuxInfo *aux_info;
3922 GdkRectangle real_allocation;
3923 GdkRectangle old_allocation;
3924 gboolean alloc_needed;
3925 gboolean size_changed;
3926 gboolean position_changed;
3928 g_return_if_fail (GTK_IS_WIDGET (widget));
3930 #ifdef G_ENABLE_DEBUG
3931 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3942 parent = gtk_widget_get_parent (parent);
3945 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3946 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3947 2 * depth, " ", name,
3948 allocation->width, allocation->height);
3950 #endif /* G_ENABLE_DEBUG */
3952 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3953 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3954 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3956 old_allocation = widget->allocation;
3957 real_allocation = *allocation;
3958 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3962 if (aux_info->x_set)
3963 real_allocation.x = aux_info->x;
3964 if (aux_info->y_set)
3965 real_allocation.y = aux_info->y;
3968 if (real_allocation.width < 0 || real_allocation.height < 0)
3970 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3971 real_allocation.width,
3972 real_allocation.height);
3975 real_allocation.width = MAX (real_allocation.width, 1);
3976 real_allocation.height = MAX (real_allocation.height, 1);
3978 size_changed = (old_allocation.width != real_allocation.width ||
3979 old_allocation.height != real_allocation.height);
3980 position_changed = (old_allocation.x != real_allocation.x ||
3981 old_allocation.y != real_allocation.y);
3983 if (!alloc_needed && !size_changed && !position_changed)
3986 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3988 if (gtk_widget_get_mapped (widget))
3990 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3992 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3994 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3995 gdk_region_union_with_rect (invalidate, &old_allocation);
3997 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3998 gdk_region_destroy (invalidate);
4003 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4005 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4007 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4008 gdk_region_union_with_rect (invalidate, &old_allocation);
4010 gtk_widget_invalidate_widget_windows (widget, invalidate);
4011 gdk_region_destroy (invalidate);
4016 if ((size_changed || position_changed) && widget->parent &&
4017 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4019 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4020 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4021 gdk_region_destroy (invalidate);
4026 * gtk_widget_common_ancestor:
4027 * @widget_a: a #GtkWidget
4028 * @widget_b: a #GtkWidget
4030 * Find the common ancestor of @widget_a and @widget_b that
4031 * is closest to the two widgets.
4033 * Return value: the closest common ancestor of @widget_a and
4034 * @widget_b or %NULL if @widget_a and @widget_b do not
4035 * share a common ancestor.
4038 gtk_widget_common_ancestor (GtkWidget *widget_a,
4039 GtkWidget *widget_b)
4041 GtkWidget *parent_a;
4042 GtkWidget *parent_b;
4046 parent_a = widget_a;
4047 while (parent_a->parent)
4049 parent_a = parent_a->parent;
4053 parent_b = widget_b;
4054 while (parent_b->parent)
4056 parent_b = parent_b->parent;
4060 if (parent_a != parent_b)
4063 while (depth_a > depth_b)
4065 widget_a = widget_a->parent;
4069 while (depth_b > depth_a)
4071 widget_b = widget_b->parent;
4075 while (widget_a != widget_b)
4077 widget_a = widget_a->parent;
4078 widget_b = widget_b->parent;
4085 * gtk_widget_translate_coordinates:
4086 * @src_widget: a #GtkWidget
4087 * @dest_widget: a #GtkWidget
4088 * @src_x: X position relative to @src_widget
4089 * @src_y: Y position relative to @src_widget
4090 * @dest_x: (out): location to store X position relative to @dest_widget
4091 * @dest_y: (out): location to store Y position relative to @dest_widget
4093 * Translate coordinates relative to @src_widget's allocation to coordinates
4094 * relative to @dest_widget's allocations. In order to perform this
4095 * operation, both widgets must be realized, and must share a common
4098 * Return value: %FALSE if either widget was not realized, or there
4099 * was no common ancestor. In this case, nothing is stored in
4100 * *@dest_x and *@dest_y. Otherwise %TRUE.
4103 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4104 GtkWidget *dest_widget,
4110 GtkWidget *ancestor;
4112 GList *dest_list = NULL;
4114 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4115 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4117 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4118 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4121 /* Translate from allocation relative to window relative */
4122 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4125 gdk_window_get_position (src_widget->window, &wx, &wy);
4127 src_x -= wx - src_widget->allocation.x;
4128 src_y -= wy - src_widget->allocation.y;
4132 src_x += src_widget->allocation.x;
4133 src_y += src_widget->allocation.y;
4136 /* Translate to the common ancestor */
4137 window = src_widget->window;
4138 while (window != ancestor->window)
4142 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4147 window = gdk_window_get_effective_parent (window);
4149 if (!window) /* Handle GtkHandleBox */
4154 window = dest_widget->window;
4155 while (window != ancestor->window)
4157 dest_list = g_list_prepend (dest_list, window);
4159 window = gdk_window_get_effective_parent (window);
4161 if (!window) /* Handle GtkHandleBox */
4163 g_list_free (dest_list);
4172 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4177 dest_list = g_list_remove (dest_list, dest_list->data);
4180 /* Translate from window relative to allocation relative */
4181 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4184 gdk_window_get_position (dest_widget->window, &wx, &wy);
4186 src_x += wx - dest_widget->allocation.x;
4187 src_y += wy - dest_widget->allocation.y;
4191 src_x -= dest_widget->allocation.x;
4192 src_y -= dest_widget->allocation.y;
4204 gtk_widget_real_size_allocate (GtkWidget *widget,
4205 GtkAllocation *allocation)
4207 widget->allocation = *allocation;
4209 if (gtk_widget_get_realized (widget) &&
4210 gtk_widget_get_has_window (widget))
4212 gdk_window_move_resize (widget->window,
4213 allocation->x, allocation->y,
4214 allocation->width, allocation->height);
4219 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4222 /* widgets must be onscreen for accels to take effect */
4223 return gtk_widget_is_sensitive (widget) &&
4224 gtk_widget_is_drawable (widget) &&
4225 gdk_window_is_viewable (widget->window);
4229 * gtk_widget_can_activate_accel:
4230 * @widget: a #GtkWidget
4231 * @signal_id: the ID of a signal installed on @widget
4233 * Determines whether an accelerator that activates the signal
4234 * identified by @signal_id can currently be activated.
4235 * This is done by emitting the #GtkWidget::can-activate-accel
4236 * signal on @widget; if the signal isn't overridden by a
4237 * handler or in a derived widget, then the default check is
4238 * that the widget must be sensitive, and the widget and all
4239 * its ancestors mapped.
4241 * Return value: %TRUE if the accelerator can be activated.
4246 gtk_widget_can_activate_accel (GtkWidget *widget,
4249 gboolean can_activate = FALSE;
4250 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4251 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4252 return can_activate;
4261 closure_accel_activate (GClosure *closure,
4262 GValue *return_value,
4263 guint n_param_values,
4264 const GValue *param_values,
4265 gpointer invocation_hint,
4266 gpointer marshal_data)
4268 AccelClosure *aclosure = (AccelClosure*) closure;
4269 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4272 g_signal_emit (closure->data, aclosure->signal_id, 0);
4274 /* whether accelerator was handled */
4275 g_value_set_boolean (return_value, can_activate);
4279 closures_destroy (gpointer data)
4281 GSList *slist, *closures = data;
4283 for (slist = closures; slist; slist = slist->next)
4285 g_closure_invalidate (slist->data);
4286 g_closure_unref (slist->data);
4288 g_slist_free (closures);
4292 widget_new_accel_closure (GtkWidget *widget,
4295 AccelClosure *aclosure;
4296 GClosure *closure = NULL;
4297 GSList *slist, *closures;
4299 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4300 for (slist = closures; slist; slist = slist->next)
4301 if (!gtk_accel_group_from_accel_closure (slist->data))
4303 /* reuse this closure */
4304 closure = slist->data;
4309 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4310 closures = g_slist_prepend (closures, g_closure_ref (closure));
4311 g_closure_sink (closure);
4312 g_closure_set_marshal (closure, closure_accel_activate);
4314 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4316 aclosure = (AccelClosure*) closure;
4317 g_assert (closure->data == widget);
4318 g_assert (closure->marshal == closure_accel_activate);
4319 aclosure->signal_id = signal_id;
4325 * gtk_widget_add_accelerator
4326 * @widget: widget to install an accelerator on
4327 * @accel_signal: widget signal to emit on accelerator activation
4328 * @accel_group: accel group for this widget, added to its toplevel
4329 * @accel_key: GDK keyval of the accelerator
4330 * @accel_mods: modifier key combination of the accelerator
4331 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4333 * Installs an accelerator for this @widget in @accel_group that causes
4334 * @accel_signal to be emitted if the accelerator is activated.
4335 * The @accel_group needs to be added to the widget's toplevel via
4336 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4337 * Accelerators added through this function are not user changeable during
4338 * runtime. If you want to support accelerators that can be changed by the
4339 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4340 * gtk_menu_item_set_accel_path() instead.
4343 gtk_widget_add_accelerator (GtkWidget *widget,
4344 const gchar *accel_signal,
4345 GtkAccelGroup *accel_group,
4347 GdkModifierType accel_mods,
4348 GtkAccelFlags accel_flags)
4353 g_return_if_fail (GTK_IS_WIDGET (widget));
4354 g_return_if_fail (accel_signal != NULL);
4355 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4357 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4358 if (!query.signal_id ||
4359 !(query.signal_flags & G_SIGNAL_ACTION) ||
4360 query.return_type != G_TYPE_NONE ||
4363 /* hmm, should be elaborate enough */
4364 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4365 G_OBJECT_TYPE_NAME (widget), accel_signal);
4369 closure = widget_new_accel_closure (widget, query.signal_id);
4371 g_object_ref (widget);
4373 /* install the accelerator. since we don't map this onto an accel_path,
4374 * the accelerator will automatically be locked.
4376 gtk_accel_group_connect (accel_group,
4379 accel_flags | GTK_ACCEL_LOCKED,
4382 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4384 g_object_unref (widget);
4388 * gtk_widget_remove_accelerator:
4389 * @widget: widget to install an accelerator on
4390 * @accel_group: accel group for this widget
4391 * @accel_key: GDK keyval of the accelerator
4392 * @accel_mods: modifier key combination of the accelerator
4393 * @returns: whether an accelerator was installed and could be removed
4395 * Removes an accelerator from @widget, previously installed with
4396 * gtk_widget_add_accelerator().
4399 gtk_widget_remove_accelerator (GtkWidget *widget,
4400 GtkAccelGroup *accel_group,
4402 GdkModifierType accel_mods)
4404 GtkAccelGroupEntry *ag_entry;
4405 GList *slist, *clist;
4408 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4409 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4411 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4412 clist = gtk_widget_list_accel_closures (widget);
4413 for (slist = clist; slist; slist = slist->next)
4417 for (i = 0; i < n; i++)
4418 if (slist->data == (gpointer) ag_entry[i].closure)
4420 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4422 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4424 g_list_free (clist);
4429 g_list_free (clist);
4431 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4432 accel_key, accel_mods, accel_group,
4433 G_OBJECT_TYPE_NAME (widget), widget);
4439 * gtk_widget_list_accel_closures
4440 * @widget: widget to list accelerator closures for
4441 * @returns: a newly allocated #GList of closures
4443 * Lists the closures used by @widget for accelerator group connections
4444 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4445 * The closures can be used to monitor accelerator changes on @widget,
4446 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4447 * #GtkAccelGroup of a closure which can be found out with
4448 * gtk_accel_group_from_accel_closure().
4451 gtk_widget_list_accel_closures (GtkWidget *widget)
4454 GList *clist = NULL;
4456 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4458 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4459 if (gtk_accel_group_from_accel_closure (slist->data))
4460 clist = g_list_prepend (clist, slist->data);
4466 GtkAccelGroup *accel_group;
4471 destroy_accel_path (gpointer data)
4473 AccelPath *apath = data;
4475 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4477 /* closures_destroy takes care of unrefing the closure */
4478 g_object_unref (apath->accel_group);
4480 g_slice_free (AccelPath, apath);
4485 * gtk_widget_set_accel_path:
4486 * @widget: a #GtkWidget
4487 * @accel_path: (allow-none): path used to look up the accelerator
4488 * @accel_group: (allow-none): a #GtkAccelGroup.
4490 * Given an accelerator group, @accel_group, and an accelerator path,
4491 * @accel_path, sets up an accelerator in @accel_group so whenever the
4492 * key binding that is defined for @accel_path is pressed, @widget
4493 * will be activated. This removes any accelerators (for any
4494 * accelerator group) installed by previous calls to
4495 * gtk_widget_set_accel_path(). Associating accelerators with
4496 * paths allows them to be modified by the user and the modifications
4497 * to be saved for future use. (See gtk_accel_map_save().)
4499 * This function is a low level function that would most likely
4500 * be used by a menu creation system like #GtkUIManager. If you
4501 * use #GtkUIManager, setting up accelerator paths will be done
4504 * Even when you you aren't using #GtkUIManager, if you only want to
4505 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4506 * provides a somewhat more convenient interface.
4508 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4509 * pass a static string, you can save some memory by interning it first with
4510 * g_intern_static_string().
4513 gtk_widget_set_accel_path (GtkWidget *widget,
4514 const gchar *accel_path,
4515 GtkAccelGroup *accel_group)
4519 g_return_if_fail (GTK_IS_WIDGET (widget));
4520 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4524 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4525 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4527 gtk_accel_map_add_entry (accel_path, 0, 0);
4528 apath = g_slice_new (AccelPath);
4529 apath->accel_group = g_object_ref (accel_group);
4530 apath->path_quark = g_quark_from_string (accel_path);
4531 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4536 /* also removes possible old settings */
4537 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4540 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4542 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4546 _gtk_widget_get_accel_path (GtkWidget *widget,
4551 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4553 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4555 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4556 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4560 * gtk_widget_mnemonic_activate:
4561 * @widget: a #GtkWidget
4562 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4564 * Emits the #GtkWidget::mnemonic-activate signal.
4566 * The default handler for this signal activates the @widget if
4567 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4570 * Returns: %TRUE if the signal has been handled
4573 gtk_widget_mnemonic_activate (GtkWidget *widget,
4574 gboolean group_cycling)
4578 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4580 group_cycling = group_cycling != FALSE;
4581 if (!gtk_widget_is_sensitive (widget))
4584 g_signal_emit (widget,
4585 widget_signals[MNEMONIC_ACTIVATE],
4593 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4594 gboolean group_cycling)
4596 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4597 gtk_widget_activate (widget);
4598 else if (gtk_widget_get_can_focus (widget))
4599 gtk_widget_grab_focus (widget);
4602 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4603 G_OBJECT_TYPE_NAME (widget));
4604 gtk_widget_error_bell (widget);
4610 gtk_widget_real_key_press_event (GtkWidget *widget,
4613 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4617 gtk_widget_real_key_release_event (GtkWidget *widget,
4620 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4624 gtk_widget_real_focus_in_event (GtkWidget *widget,
4625 GdkEventFocus *event)
4627 gtk_widget_queue_shallow_draw (widget);
4633 gtk_widget_real_focus_out_event (GtkWidget *widget,
4634 GdkEventFocus *event)
4636 gtk_widget_queue_shallow_draw (widget);
4641 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4642 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4646 * @widget: a #GtkWidget
4647 * @event: a #GdkEvent
4649 * Rarely-used function. This function is used to emit
4650 * the event signals on a widget (those signals should never
4651 * be emitted without using this function to do so).
4652 * If you want to synthesize an event though, don't use this function;
4653 * instead, use gtk_main_do_event() so the event will behave as if
4654 * it were in the event queue. Don't synthesize expose events; instead,
4655 * use gdk_window_invalidate_rect() to invalidate a region of the
4658 * Return value: return from the event signal emission (%TRUE if
4659 * the event was handled)
4662 gtk_widget_event (GtkWidget *widget,
4665 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4666 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4668 if (event->type == GDK_EXPOSE)
4670 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4671 "the same effect, call gdk_window_invalidate_rect/region(), "
4672 "followed by gdk_window_process_updates().");
4676 return gtk_widget_event_internal (widget, event);
4681 * gtk_widget_send_expose:
4682 * @widget: a #GtkWidget
4683 * @event: a expose #GdkEvent
4685 * Very rarely-used function. This function is used to emit
4686 * an expose event signals on a widget. This function is not
4687 * normally used directly. The only time it is used is when
4688 * propagating an expose event to a child %NO_WINDOW widget, and
4689 * that is normally done using gtk_container_propagate_expose().
4691 * If you want to force an area of a window to be redrawn,
4692 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4693 * To cause the redraw to be done immediately, follow that call
4694 * with a call to gdk_window_process_updates().
4696 * Return value: return from the event signal emission (%TRUE if
4697 * the event was handled)
4700 gtk_widget_send_expose (GtkWidget *widget,
4703 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4704 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4705 g_return_val_if_fail (event != NULL, TRUE);
4706 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4708 return gtk_widget_event_internal (widget, event);
4712 event_window_is_still_viewable (GdkEvent *event)
4714 /* Some programs, such as gnome-theme-manager, fake widgets
4715 * into exposing onto a pixmap by sending expose events with
4716 * event->window pointing to a pixmap
4718 if (GDK_IS_PIXMAP (event->any.window))
4719 return event->type == GDK_EXPOSE;
4721 /* Check that we think the event's window is viewable before
4722 * delivering the event, to prevent suprises. We do this here
4723 * at the last moment, since the event may have been queued
4724 * up behind other events, held over a recursive main loop, etc.
4726 switch (event->type)
4729 case GDK_MOTION_NOTIFY:
4730 case GDK_BUTTON_PRESS:
4731 case GDK_2BUTTON_PRESS:
4732 case GDK_3BUTTON_PRESS:
4734 case GDK_ENTER_NOTIFY:
4735 case GDK_PROXIMITY_IN:
4737 return event->any.window && gdk_window_is_viewable (event->any.window);
4740 /* The following events are the second half of paired events;
4741 * we always deliver them to deal with widgets that clean up
4742 * on the second half.
4744 case GDK_BUTTON_RELEASE:
4745 case GDK_KEY_RELEASE:
4746 case GDK_LEAVE_NOTIFY:
4747 case GDK_PROXIMITY_OUT:
4751 /* Remaining events would make sense on an not-viewable window,
4752 * or don't have an associated window.
4759 gtk_widget_event_internal (GtkWidget *widget,
4762 gboolean return_val = FALSE;
4764 /* We check only once for is-still-visible; if someone
4765 * hides the window in on of the signals on the widget,
4766 * they are responsible for returning TRUE to terminate
4769 if (!event_window_is_still_viewable (event))
4772 g_object_ref (widget);
4774 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4775 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4780 switch (event->type)
4785 case GDK_BUTTON_PRESS:
4786 case GDK_2BUTTON_PRESS:
4787 case GDK_3BUTTON_PRESS:
4788 signal_num = BUTTON_PRESS_EVENT;
4791 signal_num = SCROLL_EVENT;
4793 case GDK_BUTTON_RELEASE:
4794 signal_num = BUTTON_RELEASE_EVENT;
4796 case GDK_MOTION_NOTIFY:
4797 signal_num = MOTION_NOTIFY_EVENT;
4800 signal_num = DELETE_EVENT;
4803 signal_num = DESTROY_EVENT;
4804 _gtk_tooltip_hide (widget);
4807 signal_num = KEY_PRESS_EVENT;
4809 case GDK_KEY_RELEASE:
4810 signal_num = KEY_RELEASE_EVENT;
4812 case GDK_ENTER_NOTIFY:
4813 signal_num = ENTER_NOTIFY_EVENT;
4815 case GDK_LEAVE_NOTIFY:
4816 signal_num = LEAVE_NOTIFY_EVENT;
4818 case GDK_FOCUS_CHANGE:
4819 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4820 if (event->focus_change.in)
4821 _gtk_tooltip_focus_in (widget);
4823 _gtk_tooltip_focus_out (widget);
4826 signal_num = CONFIGURE_EVENT;
4829 signal_num = MAP_EVENT;
4832 signal_num = UNMAP_EVENT;
4834 case GDK_WINDOW_STATE:
4835 signal_num = WINDOW_STATE_EVENT;
4837 case GDK_PROPERTY_NOTIFY:
4838 signal_num = PROPERTY_NOTIFY_EVENT;
4840 case GDK_SELECTION_CLEAR:
4841 signal_num = SELECTION_CLEAR_EVENT;
4843 case GDK_SELECTION_REQUEST:
4844 signal_num = SELECTION_REQUEST_EVENT;
4846 case GDK_SELECTION_NOTIFY:
4847 signal_num = SELECTION_NOTIFY_EVENT;
4849 case GDK_PROXIMITY_IN:
4850 signal_num = PROXIMITY_IN_EVENT;
4852 case GDK_PROXIMITY_OUT:
4853 signal_num = PROXIMITY_OUT_EVENT;
4856 signal_num = NO_EXPOSE_EVENT;
4858 case GDK_CLIENT_EVENT:
4859 signal_num = CLIENT_EVENT;
4862 signal_num = EXPOSE_EVENT;
4864 case GDK_VISIBILITY_NOTIFY:
4865 signal_num = VISIBILITY_NOTIFY_EVENT;
4867 case GDK_GRAB_BROKEN:
4868 signal_num = GRAB_BROKEN;
4871 signal_num = DAMAGE_EVENT;
4874 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4878 if (signal_num != -1)
4879 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4881 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4882 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4886 g_object_unref (widget);
4892 * gtk_widget_activate:
4893 * @widget: a #GtkWidget that's activatable
4895 * For widgets that can be "activated" (buttons, menu items, etc.)
4896 * this function activates them. Activation is what happens when you
4897 * press Enter on a widget during key navigation. If @widget isn't
4898 * activatable, the function returns %FALSE.
4900 * Return value: %TRUE if the widget was activatable
4903 gtk_widget_activate (GtkWidget *widget)
4905 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4907 if (WIDGET_CLASS (widget)->activate_signal)
4909 /* FIXME: we should eventually check the signals signature here */
4910 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4919 * gtk_widget_set_scroll_adjustments:
4920 * @widget: a #GtkWidget
4921 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
4922 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
4924 * For widgets that support scrolling, sets the scroll adjustments and
4925 * returns %TRUE. For widgets that don't support scrolling, does
4926 * nothing and returns %FALSE. Widgets that don't support scrolling
4927 * can be scrolled by placing them in a #GtkViewport, which does
4928 * support scrolling.
4930 * Return value: %TRUE if the widget supports scrolling
4933 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4934 GtkAdjustment *hadjustment,
4935 GtkAdjustment *vadjustment)
4940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4943 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4945 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4947 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
4951 g_signal_query (signal_id, &query);
4952 if (!query.signal_id ||
4953 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
4954 query.return_type != G_TYPE_NONE ||
4955 query.n_params != 2 ||
4956 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
4957 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
4959 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
4960 G_OBJECT_TYPE_NAME (widget), query.signal_name);
4964 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
4969 gtk_widget_reparent_subwindows (GtkWidget *widget,
4970 GdkWindow *new_window)
4972 if (!gtk_widget_get_has_window (widget))
4974 GList *children = gdk_window_get_children (widget->window);
4977 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4979 GdkWindow *window = tmp_list->data;
4982 gdk_window_get_user_data (window, &child);
4983 while (child && child != widget)
4984 child = ((GtkWidget*) child)->parent;
4987 gdk_window_reparent (window, new_window, 0, 0);
4990 g_list_free (children);
4995 GList *tmp_list, *children;
4997 parent = gdk_window_get_parent (widget->window);
5000 gdk_window_reparent (widget->window, new_window, 0, 0);
5003 children = gdk_window_get_children (parent);
5005 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5007 GdkWindow *window = tmp_list->data;
5010 gdk_window_get_user_data (window, &child);
5012 if (child == widget)
5013 gdk_window_reparent (window, new_window, 0, 0);
5016 g_list_free (children);
5022 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5023 gpointer client_data)
5025 g_assert (client_data != NULL);
5027 if (!gtk_widget_get_has_window (widget))
5030 g_object_unref (widget->window);
5031 widget->window = (GdkWindow*) client_data;
5033 g_object_ref (widget->window);
5035 if (GTK_IS_CONTAINER (widget))
5036 gtk_container_forall (GTK_CONTAINER (widget),
5037 gtk_widget_reparent_fixup_child,
5043 * gtk_widget_reparent:
5044 * @widget: a #GtkWidget
5045 * @new_parent: a #GtkContainer to move the widget into
5047 * Moves a widget from one #GtkContainer to another, handling reference
5048 * count issues to avoid destroying the widget.
5051 gtk_widget_reparent (GtkWidget *widget,
5052 GtkWidget *new_parent)
5054 g_return_if_fail (GTK_IS_WIDGET (widget));
5055 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5056 g_return_if_fail (widget->parent != NULL);
5058 if (widget->parent != new_parent)
5060 /* First try to see if we can get away without unrealizing
5061 * the widget as we reparent it. if so we set a flag so
5062 * that gtk_widget_unparent doesn't unrealize widget
5064 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5065 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5067 g_object_ref (widget);
5068 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5069 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5070 g_object_unref (widget);
5072 if (GTK_WIDGET_IN_REPARENT (widget))
5074 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5076 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5077 gtk_widget_reparent_fixup_child (widget,
5078 gtk_widget_get_parent_window (widget));
5081 g_object_notify (G_OBJECT (widget), "parent");
5086 * gtk_widget_intersect:
5087 * @widget: a #GtkWidget
5088 * @area: a rectangle
5089 * @intersection: rectangle to store intersection of @widget and @area
5091 * Computes the intersection of a @widget's area and @area, storing
5092 * the intersection in @intersection, and returns %TRUE if there was
5093 * an intersection. @intersection may be %NULL if you're only
5094 * interested in whether there was an intersection.
5096 * Return value: %TRUE if there was an intersection
5099 gtk_widget_intersect (GtkWidget *widget,
5100 const GdkRectangle *area,
5101 GdkRectangle *intersection)
5107 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5108 g_return_val_if_fail (area != NULL, FALSE);
5111 dest = intersection;
5115 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5117 if (return_val && intersection && gtk_widget_get_has_window (widget))
5119 intersection->x -= widget->allocation.x;
5120 intersection->y -= widget->allocation.y;
5127 * gtk_widget_region_intersect:
5128 * @widget: a #GtkWidget
5129 * @region: a #GdkRegion, in the same coordinate system as
5130 * @widget->allocation. That is, relative to @widget->window
5131 * for %NO_WINDOW widgets; relative to the parent window
5132 * of @widget->window for widgets with their own window.
5133 * @returns: A newly allocated region holding the intersection of @widget
5134 * and @region. The coordinates of the return value are
5135 * relative to @widget->window for %NO_WINDOW widgets, and
5136 * relative to the parent window of @widget->window for
5137 * widgets with their own window.
5139 * Computes the intersection of a @widget's area and @region, returning
5140 * the intersection. The result may be empty, use gdk_region_empty() to
5144 gtk_widget_region_intersect (GtkWidget *widget,
5145 const GdkRegion *region)
5150 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5151 g_return_val_if_fail (region != NULL, NULL);
5153 gtk_widget_get_draw_rectangle (widget, &rect);
5155 dest = gdk_region_rectangle (&rect);
5157 gdk_region_intersect (dest, region);
5163 * _gtk_widget_grab_notify:
5164 * @widget: a #GtkWidget
5165 * @was_grabbed: whether a grab is now in effect
5167 * Emits the #GtkWidget::grab-notify signal on @widget.
5172 _gtk_widget_grab_notify (GtkWidget *widget,
5173 gboolean was_grabbed)
5175 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5179 * gtk_widget_grab_focus:
5180 * @widget: a #GtkWidget
5182 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5183 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5184 * something like #GtkFrame won't work.
5186 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5187 * gtk_widget_set_can_focus() to modify that flag.
5190 gtk_widget_grab_focus (GtkWidget *widget)
5192 g_return_if_fail (GTK_IS_WIDGET (widget));
5194 if (!gtk_widget_is_sensitive (widget))
5197 g_object_ref (widget);
5198 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5199 g_object_notify (G_OBJECT (widget), "has-focus");
5200 g_object_unref (widget);
5204 reset_focus_recurse (GtkWidget *widget,
5207 if (GTK_IS_CONTAINER (widget))
5209 GtkContainer *container;
5211 container = GTK_CONTAINER (widget);
5212 gtk_container_set_focus_child (container, NULL);
5214 gtk_container_foreach (container,
5215 reset_focus_recurse,
5221 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5223 if (gtk_widget_get_can_focus (focus_widget))
5225 GtkWidget *toplevel;
5228 /* clear the current focus setting, break if the current widget
5229 * is the focus widget's parent, since containers above that will
5230 * be set by the next loop.
5232 toplevel = gtk_widget_get_toplevel (focus_widget);
5233 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5235 widget = GTK_WINDOW (toplevel)->focus_widget;
5237 if (widget == focus_widget)
5239 /* We call _gtk_window_internal_set_focus() here so that the
5240 * toplevel window can request the focus if necessary.
5241 * This is needed when the toplevel is a GtkPlug
5243 if (!gtk_widget_has_focus (widget))
5244 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5251 while (widget->parent && widget->parent != focus_widget->parent)
5253 widget = widget->parent;
5254 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5258 else if (toplevel != focus_widget)
5260 /* gtk_widget_grab_focus() operates on a tree without window...
5261 * actually, this is very questionable behaviour.
5264 gtk_container_foreach (GTK_CONTAINER (toplevel),
5265 reset_focus_recurse,
5269 /* now propagate the new focus up the widget tree and finally
5270 * set it on the window
5272 widget = focus_widget;
5273 while (widget->parent)
5275 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5276 widget = widget->parent;
5278 if (GTK_IS_WINDOW (widget))
5279 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5284 gtk_widget_real_query_tooltip (GtkWidget *widget,
5287 gboolean keyboard_tip,
5288 GtkTooltip *tooltip)
5290 gchar *tooltip_markup;
5291 gboolean has_tooltip;
5293 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5294 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5296 if (has_tooltip && tooltip_markup)
5298 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5306 gtk_widget_real_show_help (GtkWidget *widget,
5307 GtkWidgetHelpType help_type)
5309 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5311 _gtk_tooltip_toggle_keyboard_mode (widget);
5320 gtk_widget_real_focus (GtkWidget *widget,
5321 GtkDirectionType direction)
5323 if (!gtk_widget_get_can_focus (widget))
5326 if (!gtk_widget_is_focus (widget))
5328 gtk_widget_grab_focus (widget);
5336 gtk_widget_real_move_focus (GtkWidget *widget,
5337 GtkDirectionType direction)
5339 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5341 if (GTK_IS_WINDOW (toplevel) &&
5342 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5344 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5350 gtk_widget_real_keynav_failed (GtkWidget *widget,
5351 GtkDirectionType direction)
5353 gboolean cursor_only;
5357 case GTK_DIR_TAB_FORWARD:
5358 case GTK_DIR_TAB_BACKWARD:
5365 g_object_get (gtk_widget_get_settings (widget),
5366 "gtk-keynav-cursor-only", &cursor_only,
5373 gtk_widget_error_bell (widget);
5379 * gtk_widget_set_can_focus:
5380 * @widget: a #GtkWidget
5381 * @can_focus: whether or not @widget can own the input focus.
5383 * Specifies whether @widget can own the input focus. See
5384 * gtk_widget_grab_focus() for actually setting the input focus on a
5390 gtk_widget_set_can_focus (GtkWidget *widget,
5393 g_return_if_fail (GTK_IS_WIDGET (widget));
5395 if (can_focus != gtk_widget_get_can_focus (widget))
5398 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5400 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5402 gtk_widget_queue_resize (widget);
5403 g_object_notify (G_OBJECT (widget), "can-focus");
5408 * gtk_widget_get_can_focus:
5409 * @widget: a #GtkWidget
5411 * Determines whether @widget can own the input focus. See
5412 * gtk_widget_set_can_focus().
5414 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5419 gtk_widget_get_can_focus (GtkWidget *widget)
5421 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5423 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5427 * gtk_widget_has_focus:
5428 * @widget: a #GtkWidget
5430 * Determines if the widget has the global input focus. See
5431 * gtk_widget_is_focus() for the difference between having the global
5432 * input focus, and only having the focus within a toplevel.
5434 * Return value: %TRUE if the widget has the global input focus.
5439 gtk_widget_has_focus (GtkWidget *widget)
5441 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5443 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5447 * gtk_widget_is_focus:
5448 * @widget: a #GtkWidget
5450 * Determines if the widget is the focus widget within its
5451 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5452 * necessarily set; %HAS_FOCUS will only be set if the
5453 * toplevel widget additionally has the global input focus.)
5455 * Return value: %TRUE if the widget is the focus widget.
5458 gtk_widget_is_focus (GtkWidget *widget)
5460 GtkWidget *toplevel;
5462 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5464 toplevel = gtk_widget_get_toplevel (widget);
5466 if (GTK_IS_WINDOW (toplevel))
5467 return widget == GTK_WINDOW (toplevel)->focus_widget;
5473 * gtk_widget_set_can_default:
5474 * @widget: a #GtkWidget
5475 * @can_default: whether or not @widget can be a default widget.
5477 * Specifies whether @widget can be a default widget. See
5478 * gtk_widget_grab_default() for details about the meaning of
5484 gtk_widget_set_can_default (GtkWidget *widget,
5485 gboolean can_default)
5487 g_return_if_fail (GTK_IS_WIDGET (widget));
5489 if (can_default != gtk_widget_get_can_default (widget))
5492 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5494 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5496 gtk_widget_queue_resize (widget);
5497 g_object_notify (G_OBJECT (widget), "can-default");
5502 * gtk_widget_get_can_default:
5503 * @widget: a #GtkWidget
5505 * Determines whether @widget can be a default widget. See
5506 * gtk_widget_set_can_default().
5508 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5513 gtk_widget_get_can_default (GtkWidget *widget)
5515 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5517 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5521 * gtk_widget_has_default:
5522 * @widget: a #GtkWidget
5524 * Determines whether @widget is the current default widget within its
5525 * toplevel. See gtk_widget_set_can_default().
5527 * Return value: %TRUE if @widget is the current default widget within
5528 * its toplevel, %FALSE otherwise
5533 gtk_widget_has_default (GtkWidget *widget)
5535 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5537 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5541 _gtk_widget_set_has_default (GtkWidget *widget,
5542 gboolean has_default)
5545 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5547 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5551 * gtk_widget_grab_default:
5552 * @widget: a #GtkWidget
5554 * Causes @widget to become the default widget. @widget must have the
5555 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5556 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5557 * %TRUE)</literal>. The default widget is activated when
5558 * the user presses Enter in a window. Default widgets must be
5559 * activatable, that is, gtk_widget_activate() should affect them.
5562 gtk_widget_grab_default (GtkWidget *widget)
5566 g_return_if_fail (GTK_IS_WIDGET (widget));
5567 g_return_if_fail (gtk_widget_get_can_default (widget));
5569 window = gtk_widget_get_toplevel (widget);
5571 if (window && gtk_widget_is_toplevel (window))
5572 gtk_window_set_default (GTK_WINDOW (window), widget);
5574 g_warning (G_STRLOC ": widget not within a GtkWindow");
5578 * gtk_widget_set_receives_default:
5579 * @widget: a #GtkWidget
5580 * @receives_default: whether or not @widget can be a default widget.
5582 * Specifies whether @widget will be treated as the default widget
5583 * within its toplevel when it has the focus, even if another widget
5586 * See gtk_widget_grab_default() for details about the meaning of
5592 gtk_widget_set_receives_default (GtkWidget *widget,
5593 gboolean receives_default)
5595 g_return_if_fail (GTK_IS_WIDGET (widget));
5597 if (receives_default != gtk_widget_get_receives_default (widget))
5599 if (receives_default)
5600 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5602 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5604 g_object_notify (G_OBJECT (widget), "receives-default");
5609 * gtk_widget_get_receives_default:
5610 * @widget: a #GtkWidget
5612 * Determines whether @widget is alyways treated as default widget
5613 * withing its toplevel when it has the focus, even if another widget
5616 * See gtk_widget_set_receives_default().
5618 * Return value: %TRUE if @widget acts as default widget when focussed,
5624 gtk_widget_get_receives_default (GtkWidget *widget)
5626 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5628 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5632 * gtk_widget_has_grab:
5633 * @widget: a #GtkWidget
5635 * Determines whether the widget is currently grabbing events, so it
5636 * is the only widget receiving input events (keyboard and mouse).
5638 * See also gtk_grab_add().
5640 * Return value: %TRUE if the widget is in the grab_widgets stack
5645 gtk_widget_has_grab (GtkWidget *widget)
5647 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5649 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5653 _gtk_widget_set_has_grab (GtkWidget *widget,
5657 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
5659 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
5663 * gtk_widget_device_is_shadowed:
5664 * @widget: a #GtkWidget
5665 * @device: a #GdkDevice
5667 * Returns %TRUE if @device has been shadowed by a GTK+
5668 * device grab on another widget, so it would stop sending
5669 * events to @widget. This may be used in the
5670 * #GtkWidget::grab-notify signal to check for specific
5671 * devices. See gtk_device_grab_add().
5673 * Returns: %TRUE if there is an ongoing grab on @device
5674 * by another #GtkWidget than @widget.
5679 gtk_widget_device_is_shadowed (GtkWidget *widget,
5682 GtkWindowGroup *group;
5683 GtkWidget *grab_widget, *toplevel;
5685 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5686 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
5688 if (!gtk_widget_get_realized (widget))
5691 toplevel = gtk_widget_get_toplevel (widget);
5693 if (GTK_IS_WINDOW (toplevel))
5694 group = gtk_window_get_group (GTK_WINDOW (toplevel));
5696 group = gtk_window_get_group (NULL);
5698 grab_widget = gtk_window_group_get_current_device_grab (group, device);
5700 /* Widget not inside the hierarchy of grab_widget */
5702 widget != grab_widget &&
5703 !gtk_widget_is_ancestor (widget, grab_widget))
5708 grab_widget = group->grabs->data;
5710 if (widget != grab_widget &&
5711 !gtk_widget_is_ancestor (widget, grab_widget))
5719 * gtk_widget_set_name:
5720 * @widget: a #GtkWidget
5721 * @name: name for the widget
5723 * Widgets can be named, which allows you to refer to them from a
5724 * gtkrc file. You can apply a style to widgets with a particular name
5725 * in the gtkrc file. See the documentation for gtkrc files (on the
5726 * same page as the docs for #GtkRcStyle).
5728 * Note that widget names are separated by periods in paths (see
5729 * gtk_widget_path()), so names with embedded periods may cause confusion.
5732 gtk_widget_set_name (GtkWidget *widget,
5737 g_return_if_fail (GTK_IS_WIDGET (widget));
5739 new_name = g_strdup (name);
5740 g_free (widget->name);
5741 widget->name = new_name;
5743 if (gtk_widget_has_rc_style (widget))
5744 gtk_widget_reset_rc_style (widget);
5746 g_object_notify (G_OBJECT (widget), "name");
5750 * gtk_widget_get_name:
5751 * @widget: a #GtkWidget
5753 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5754 * significance of widget names.
5756 * Return value: name of the widget. This string is owned by GTK+ and
5757 * should not be modified or freed
5759 G_CONST_RETURN gchar*
5760 gtk_widget_get_name (GtkWidget *widget)
5762 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5765 return widget->name;
5766 return G_OBJECT_TYPE_NAME (widget);
5770 * gtk_widget_set_state:
5771 * @widget: a #GtkWidget
5772 * @state: new state for @widget
5774 * This function is for use in widget implementations. Sets the state
5775 * of a widget (insensitive, prelighted, etc.) Usually you should set
5776 * the state using wrapper functions such as gtk_widget_set_sensitive().
5779 gtk_widget_set_state (GtkWidget *widget,
5782 g_return_if_fail (GTK_IS_WIDGET (widget));
5784 if (state == gtk_widget_get_state (widget))
5787 if (state == GTK_STATE_INSENSITIVE)
5788 gtk_widget_set_sensitive (widget, FALSE);
5794 data.state_restoration = FALSE;
5795 data.use_forall = FALSE;
5797 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5799 data.parent_sensitive = TRUE;
5801 gtk_widget_propagate_state (widget, &data);
5803 if (gtk_widget_is_drawable (widget))
5804 gtk_widget_queue_draw (widget);
5809 * gtk_widget_get_state:
5810 * @widget: a #GtkWidget
5812 * Returns the widget's state. See gtk_widget_set_state().
5814 * Returns: the state of @widget.
5819 gtk_widget_get_state (GtkWidget *widget)
5821 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5823 return widget->state;
5827 * gtk_widget_set_visible:
5828 * @widget: a #GtkWidget
5829 * @visible: whether the widget should be shown or not
5831 * Sets the visibility state of @widget. Note that setting this to
5832 * %TRUE doesn't mean the widget is actually viewable, see
5833 * gtk_widget_get_visible().
5835 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5836 * but is nicer to use when the visibility of the widget depends on
5842 gtk_widget_set_visible (GtkWidget *widget,
5845 g_return_if_fail (GTK_IS_WIDGET (widget));
5847 if (visible != gtk_widget_get_visible (widget))
5850 gtk_widget_show (widget);
5852 gtk_widget_hide (widget);
5857 * gtk_widget_get_visible:
5858 * @widget: a #GtkWidget
5860 * Determines whether the widget is visible. Note that this doesn't
5861 * take into account whether the widget's parent is also visible
5862 * or the widget is obscured in any way.
5864 * See gtk_widget_set_visible().
5866 * Return value: %TRUE if the widget is visible
5871 gtk_widget_get_visible (GtkWidget *widget)
5873 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5875 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5879 * gtk_widget_set_has_window:
5880 * @widget: a #GtkWidget
5881 * @has_window: whether or not @widget has a window.
5883 * Specifies whether @widget has a #GdkWindow of its own. Note that
5884 * all realized widgets have a non-%NULL "window" pointer
5885 * (gtk_widget_get_window() never returns a %NULL window when a widget
5886 * is realized), but for many of them it's actually the #GdkWindow of
5887 * one of its parent widgets. Widgets that create a %window for
5888 * themselves in GtkWidget::realize() however must announce this by
5889 * calling this function with @has_window = %TRUE.
5891 * This function should only be called by widget implementations,
5892 * and they should call it in their init() function.
5897 gtk_widget_set_has_window (GtkWidget *widget,
5898 gboolean has_window)
5900 g_return_if_fail (GTK_IS_WIDGET (widget));
5903 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5905 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5909 * gtk_widget_get_has_window:
5910 * @widget: a #GtkWidget
5912 * Determines whether @widget has a #GdkWindow of its own. See
5913 * gtk_widget_set_has_window().
5915 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5920 gtk_widget_get_has_window (GtkWidget *widget)
5922 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5924 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5928 * gtk_widget_is_toplevel:
5929 * @widget: a #GtkWidget
5931 * Determines whether @widget is a toplevel widget. Currently only
5932 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5933 * widgets have no parent widget.
5935 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5940 gtk_widget_is_toplevel (GtkWidget *widget)
5942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5944 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5948 _gtk_widget_set_is_toplevel (GtkWidget *widget,
5949 gboolean is_toplevel)
5952 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
5954 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
5958 * gtk_widget_is_drawable:
5959 * @widget: a #GtkWidget
5961 * Determines whether @widget can be drawn to. A widget can be drawn
5962 * to if it is mapped and visible.
5964 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5969 gtk_widget_is_drawable (GtkWidget *widget)
5971 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5973 return (gtk_widget_get_visible (widget) &&
5974 gtk_widget_get_mapped (widget));
5978 * gtk_widget_get_realized:
5979 * @widget: a #GtkWidget
5981 * Determines whether @widget is realized.
5983 * Return value: %TRUE if @widget is realized, %FALSE otherwise
5988 gtk_widget_get_realized (GtkWidget *widget)
5990 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5992 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
5996 * gtk_widget_set_realized:
5997 * @widget: a #GtkWidget
5998 * @realized: %TRUE to mark the widget as realized
6000 * Marks the widget as being realized.
6002 * This function should only ever be called in a derived widget's
6003 * "realize" or "unrealize" implementation.
6008 gtk_widget_set_realized (GtkWidget *widget,
6011 g_return_if_fail (GTK_IS_WIDGET (widget));
6014 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6016 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6020 * gtk_widget_get_mapped:
6021 * @widget: a #GtkWidget
6023 * Whether the widget is mapped.
6025 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6030 gtk_widget_get_mapped (GtkWidget *widget)
6032 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6034 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6038 * gtk_widget_set_mapped:
6039 * @widget: a #GtkWidget
6040 * @mapped: %TRUE to mark the widget as mapped
6042 * Marks the widget as being realized.
6044 * This function should only ever be called in a derived widget's
6045 * "map" or "unmap" implementation.
6050 gtk_widget_set_mapped (GtkWidget *widget,
6053 g_return_if_fail (GTK_IS_WIDGET (widget));
6056 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6058 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6062 * gtk_widget_set_app_paintable:
6063 * @widget: a #GtkWidget
6064 * @app_paintable: %TRUE if the application will paint on the widget
6066 * Sets whether the application intends to draw on the widget in
6067 * an #GtkWidget::expose-event handler.
6069 * This is a hint to the widget and does not affect the behavior of
6070 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6071 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6072 * the effect is to suppress default themed drawing of the widget's
6073 * background. (Children of the widget will still be drawn.) The application
6074 * is then entirely responsible for drawing the widget background.
6076 * Note that the background is still drawn when the widget is mapped.
6077 * If this is not suitable (e.g. because you want to make a transparent
6078 * window using an RGBA visual), you can work around this by doing:
6080 * gtk_widget_realize (window);
6081 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6082 * gtk_widget_show (window);
6086 gtk_widget_set_app_paintable (GtkWidget *widget,
6087 gboolean app_paintable)
6089 g_return_if_fail (GTK_IS_WIDGET (widget));
6091 app_paintable = (app_paintable != FALSE);
6093 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6096 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6098 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6100 if (gtk_widget_is_drawable (widget))
6101 gtk_widget_queue_draw (widget);
6103 g_object_notify (G_OBJECT (widget), "app-paintable");
6108 * gtk_widget_get_app_paintable:
6109 * @widget: a #GtkWidget
6111 * Determines whether the application intends to draw on the widget in
6112 * an #GtkWidget::expose-event handler.
6114 * See gtk_widget_set_app_paintable()
6116 * Return value: %TRUE if the widget is app paintable
6121 gtk_widget_get_app_paintable (GtkWidget *widget)
6123 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6125 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6129 * gtk_widget_set_double_buffered:
6130 * @widget: a #GtkWidget
6131 * @double_buffered: %TRUE to double-buffer a widget
6133 * Widgets are double buffered by default; you can use this function
6134 * to turn off the buffering. "Double buffered" simply means that
6135 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6136 * automatically around expose events sent to the
6137 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6138 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6139 * buffer to the screen. The result is that users see the window
6140 * update in one smooth step, and don't see individual graphics
6141 * primitives being rendered.
6143 * In very simple terms, double buffered widgets don't flicker,
6144 * so you would only use this function to turn off double buffering
6145 * if you had special needs and really knew what you were doing.
6147 * Note: if you turn off double-buffering, you have to handle
6148 * expose events, since even the clearing to the background color or
6149 * pixmap will not happen automatically (as it is done in
6150 * gdk_window_begin_paint()).
6153 gtk_widget_set_double_buffered (GtkWidget *widget,
6154 gboolean double_buffered)
6156 g_return_if_fail (GTK_IS_WIDGET (widget));
6158 double_buffered = (double_buffered != FALSE);
6160 if (double_buffered != gtk_widget_get_double_buffered (widget))
6162 if (double_buffered)
6163 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6165 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6167 g_object_notify (G_OBJECT (widget), "double-buffered");
6172 * gtk_widget_get_double_buffered:
6173 * @widget: a #GtkWidget
6175 * Determines whether the widget is double buffered.
6177 * See gtk_widget_set_double_buffered()
6179 * Return value: %TRUE if the widget is double buffered
6184 gtk_widget_get_double_buffered (GtkWidget *widget)
6186 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6188 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6192 * gtk_widget_set_redraw_on_allocate:
6193 * @widget: a #GtkWidget
6194 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6195 * when it is allocated to a new size. Otherwise, only the
6196 * new portion of the widget will be redrawn.
6198 * Sets whether the entire widget is queued for drawing when its size
6199 * allocation changes. By default, this setting is %TRUE and
6200 * the entire widget is redrawn on every size change. If your widget
6201 * leaves the upper left unchanged when made bigger, turning this
6202 * setting off will improve performance.
6204 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6205 * off all allocation on resizing: the widget will not even redraw if
6206 * its position changes; this is to allow containers that don't draw
6207 * anything to avoid excess invalidations. If you set this flag on a
6208 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6209 * you are responsible for invalidating both the old and new allocation
6210 * of the widget when the widget is moved and responsible for invalidating
6211 * regions newly when the widget increases size.
6214 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6215 gboolean redraw_on_allocate)
6217 g_return_if_fail (GTK_IS_WIDGET (widget));
6219 if (redraw_on_allocate)
6220 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6222 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6226 * gtk_widget_set_sensitive:
6227 * @widget: a #GtkWidget
6228 * @sensitive: %TRUE to make the widget sensitive
6230 * Sets the sensitivity of a widget. A widget is sensitive if the user
6231 * can interact with it. Insensitive widgets are "grayed out" and the
6232 * user can't interact with them. Insensitive widgets are known as
6233 * "inactive", "disabled", or "ghosted" in some other toolkits.
6236 gtk_widget_set_sensitive (GtkWidget *widget,
6241 g_return_if_fail (GTK_IS_WIDGET (widget));
6243 sensitive = (sensitive != FALSE);
6245 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6250 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6251 data.state = widget->saved_state;
6255 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6256 data.state = gtk_widget_get_state (widget);
6258 data.state_restoration = TRUE;
6259 data.use_forall = TRUE;
6262 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6264 data.parent_sensitive = TRUE;
6266 gtk_widget_propagate_state (widget, &data);
6267 if (gtk_widget_is_drawable (widget))
6268 gtk_widget_queue_draw (widget);
6270 g_object_notify (G_OBJECT (widget), "sensitive");
6274 * gtk_widget_get_sensitive:
6275 * @widget: a #GtkWidget
6277 * Returns the widget's sensitivity (in the sense of returning
6278 * the value that has been set using gtk_widget_set_sensitive()).
6280 * The effective sensitivity of a widget is however determined by both its
6281 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6283 * Returns: %TRUE if the widget is sensitive
6288 gtk_widget_get_sensitive (GtkWidget *widget)
6290 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6292 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6296 * gtk_widget_is_sensitive:
6297 * @widget: a #GtkWidget
6299 * Returns the widget's effective sensitivity, which means
6300 * it is sensitive itself and also its parent widget is sensntive
6302 * Returns: %TRUE if the widget is effectively sensitive
6307 gtk_widget_is_sensitive (GtkWidget *widget)
6309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6311 return (gtk_widget_get_sensitive (widget) &&
6312 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6316 * gtk_widget_set_parent:
6317 * @widget: a #GtkWidget
6318 * @parent: parent container
6320 * This function is useful only when implementing subclasses of
6322 * Sets the container as the parent of @widget, and takes care of
6323 * some details such as updating the state and style of the child
6324 * to reflect its new location. The opposite function is
6325 * gtk_widget_unparent().
6328 gtk_widget_set_parent (GtkWidget *widget,
6333 g_return_if_fail (GTK_IS_WIDGET (widget));
6334 g_return_if_fail (GTK_IS_WIDGET (parent));
6335 g_return_if_fail (widget != parent);
6336 if (widget->parent != NULL)
6338 g_warning ("Can't set a parent on widget which has a parent\n");
6341 if (gtk_widget_is_toplevel (widget))
6343 g_warning ("Can't set a parent on a toplevel widget\n");
6347 /* keep this function in sync with gtk_menu_attach_to_widget()
6350 g_object_ref_sink (widget);
6351 widget->parent = parent;
6353 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6354 data.state = gtk_widget_get_state (parent);
6356 data.state = gtk_widget_get_state (widget);
6357 data.state_restoration = FALSE;
6358 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6359 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6361 gtk_widget_propagate_state (widget, &data);
6363 gtk_widget_reset_rc_styles (widget);
6365 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6366 if (GTK_WIDGET_ANCHORED (widget->parent))
6367 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6368 g_object_notify (G_OBJECT (widget), "parent");
6370 /* Enforce realized/mapped invariants
6372 if (gtk_widget_get_realized (widget->parent))
6373 gtk_widget_realize (widget);
6375 if (gtk_widget_get_visible (widget->parent) &&
6376 gtk_widget_get_visible (widget))
6378 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6379 gtk_widget_get_mapped (widget->parent))
6380 gtk_widget_map (widget);
6382 gtk_widget_queue_resize (widget);
6387 * gtk_widget_get_parent:
6388 * @widget: a #GtkWidget
6390 * Returns the parent container of @widget.
6392 * Return value: (transfer none): the parent container of @widget, or %NULL
6395 gtk_widget_get_parent (GtkWidget *widget)
6397 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6399 return widget->parent;
6402 /*****************************************
6404 * see docs/styles.txt
6405 *****************************************/
6408 * gtk_widget_style_attach:
6409 * @widget: a #GtkWidget
6411 * This function attaches the widget's #GtkStyle to the widget's
6412 * #GdkWindow. It is a replacement for
6415 * widget->style = gtk_style_attach (widget->style, widget->window);
6418 * and should only ever be called in a derived widget's "realize"
6419 * implementation which does not chain up to its parent class'
6420 * "realize" implementation, because one of the parent classes
6421 * (finally #GtkWidget) would attach the style itself.
6426 gtk_widget_style_attach (GtkWidget *widget)
6428 g_return_if_fail (GTK_IS_WIDGET (widget));
6429 g_return_if_fail (gtk_widget_get_realized (widget));
6431 widget->style = gtk_style_attach (widget->style, widget->window);
6435 * gtk_widget_has_rc_style:
6436 * @widget: a #GtkWidget
6438 * Determines if the widget style has been looked up through the rc mechanism.
6440 * Returns: %TRUE if the widget has been looked up through the rc
6441 * mechanism, %FALSE otherwise.
6446 gtk_widget_has_rc_style (GtkWidget *widget)
6448 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6450 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6454 * gtk_widget_set_style:
6455 * @widget: a #GtkWidget
6456 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6457 * gtk_widget_set_style() and go back to the default style
6459 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6460 * want to use this function; it interacts badly with themes, because
6461 * themes work by replacing the #GtkStyle. Instead, use
6462 * gtk_widget_modify_style().
6465 gtk_widget_set_style (GtkWidget *widget,
6468 g_return_if_fail (GTK_IS_WIDGET (widget));
6472 gboolean initial_emission;
6474 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6476 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6477 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6479 gtk_widget_set_style_internal (widget, style, initial_emission);
6483 if (GTK_WIDGET_USER_STYLE (widget))
6484 gtk_widget_reset_rc_style (widget);
6489 * gtk_widget_ensure_style:
6490 * @widget: a #GtkWidget
6492 * Ensures that @widget has a style (@widget->style). Not a very useful
6493 * function; most of the time, if you want the style, the widget is
6494 * realized, and realized widgets are guaranteed to have a style
6498 gtk_widget_ensure_style (GtkWidget *widget)
6500 g_return_if_fail (GTK_IS_WIDGET (widget));
6502 if (!GTK_WIDGET_USER_STYLE (widget) &&
6503 !gtk_widget_has_rc_style (widget))
6504 gtk_widget_reset_rc_style (widget);
6507 /* Look up the RC style for this widget, unsetting any user style that
6508 * may be in effect currently
6511 gtk_widget_reset_rc_style (GtkWidget *widget)
6513 GtkStyle *new_style = NULL;
6514 gboolean initial_emission;
6516 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6518 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6519 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6521 if (gtk_widget_has_screen (widget))
6522 new_style = gtk_rc_get_style (widget);
6524 new_style = gtk_widget_get_default_style ();
6526 if (initial_emission || new_style != widget->style)
6527 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6531 * gtk_widget_get_style:
6532 * @widget: a #GtkWidget
6534 * Simply an accessor function that returns @widget->style.
6536 * Return value: (transfer none): the widget's #GtkStyle
6539 gtk_widget_get_style (GtkWidget *widget)
6541 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6543 return widget->style;
6547 * gtk_widget_modify_style:
6548 * @widget: a #GtkWidget
6549 * @style: the #GtkRcStyle holding the style modifications
6551 * Modifies style values on the widget. Modifications made using this
6552 * technique take precedence over style values set via an RC file,
6553 * however, they will be overriden if a style is explicitely set on
6554 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6555 * is designed so each field can either be set or unset, so it is
6556 * possible, using this function, to modify some style values and
6557 * leave the others unchanged.
6559 * Note that modifications made with this function are not cumulative
6560 * with previous calls to gtk_widget_modify_style() or with such
6561 * functions as gtk_widget_modify_fg(). If you wish to retain
6562 * previous values, you must first call gtk_widget_get_modifier_style(),
6563 * make your modifications to the returned style, then call
6564 * gtk_widget_modify_style() with that style. On the other hand,
6565 * if you first call gtk_widget_modify_style(), subsequent calls
6566 * to such functions gtk_widget_modify_fg() will have a cumulative
6567 * effect with the initial modifications.
6570 gtk_widget_modify_style (GtkWidget *widget,
6573 g_return_if_fail (GTK_IS_WIDGET (widget));
6574 g_return_if_fail (GTK_IS_RC_STYLE (style));
6576 g_object_set_qdata_full (G_OBJECT (widget),
6578 gtk_rc_style_copy (style),
6579 (GDestroyNotify) g_object_unref);
6581 /* note that "style" may be invalid here if it was the old
6582 * modifier style and the only reference was our own.
6585 if (gtk_widget_has_rc_style (widget))
6586 gtk_widget_reset_rc_style (widget);
6590 * gtk_widget_get_modifier_style:
6591 * @widget: a #GtkWidget
6593 * Returns the current modifier style for the widget. (As set by
6594 * gtk_widget_modify_style().) If no style has previously set, a new
6595 * #GtkRcStyle will be created with all values unset, and set as the
6596 * modifier style for the widget. If you make changes to this rc
6597 * style, you must call gtk_widget_modify_style(), passing in the
6598 * returned rc style, to make sure that your changes take effect.
6600 * Caution: passing the style back to gtk_widget_modify_style() will
6601 * normally end up destroying it, because gtk_widget_modify_style() copies
6602 * the passed-in style and sets the copy as the new modifier style,
6603 * thus dropping any reference to the old modifier style. Add a reference
6604 * to the modifier style if you want to keep it alive.
6606 * Return value: (transfer none): the modifier style for the widget. This rc style is
6607 * owned by the widget. If you want to keep a pointer to value this
6608 * around, you must add a refcount using g_object_ref().
6611 gtk_widget_get_modifier_style (GtkWidget *widget)
6613 GtkRcStyle *rc_style;
6615 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6617 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6621 rc_style = gtk_rc_style_new ();
6622 g_object_set_qdata_full (G_OBJECT (widget),
6625 (GDestroyNotify) g_object_unref);
6632 gtk_widget_modify_color_component (GtkWidget *widget,
6633 GtkRcFlags component,
6635 const GdkColor *color)
6637 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6644 rc_style->fg[state] = *color;
6647 rc_style->bg[state] = *color;
6650 rc_style->text[state] = *color;
6653 rc_style->base[state] = *color;
6656 g_assert_not_reached();
6659 rc_style->color_flags[state] |= component;
6662 rc_style->color_flags[state] &= ~component;
6664 gtk_widget_modify_style (widget, rc_style);
6668 * gtk_widget_modify_symbolic_color:
6669 * @widget: a #GtkWidget
6670 * @name: the name of the symbolic color to modify
6671 * @color: (allow-none): the color to assign (does not need to be allocated),
6672 * or %NULL to undo the effect of previous calls to
6673 * of gtk_widget_modify_symbolic_color().
6675 * Sets a symbolic color for a widget.
6676 * All other style values are left untouched. See also
6677 * gtk_widget_modify_style().
6682 gtk_widget_modify_symbolic_color (GtkWidget *widget,
6684 const GdkColor *color)
6686 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6688 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
6690 gtk_widget_modify_style (widget, rc_style);
6694 * gtk_widget_modify_fg:
6695 * @widget: a #GtkWidget
6696 * @state: the state for which to set the foreground color
6697 * @color: (allow-none): the color to assign (does not need to be allocated),
6698 * or %NULL to undo the effect of previous calls to
6699 * of gtk_widget_modify_fg().
6701 * Sets the foreground color for a widget in a particular state.
6702 * All other style values are left untouched. See also
6703 * gtk_widget_modify_style().
6706 gtk_widget_modify_fg (GtkWidget *widget,
6708 const GdkColor *color)
6710 g_return_if_fail (GTK_IS_WIDGET (widget));
6711 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6713 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6717 * gtk_widget_modify_bg:
6718 * @widget: a #GtkWidget
6719 * @state: the state for which to set the background color
6720 * @color: (allow-none): the color to assign (does not need to be allocated),
6721 * or %NULL to undo the effect of previous calls to
6722 * of gtk_widget_modify_bg().
6724 * Sets the background color for a widget in a particular state.
6725 * All other style values are left untouched. See also
6726 * gtk_widget_modify_style().
6728 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6729 * draw on their parent container's window and thus may not draw any
6730 * background themselves. This is the case for e.g. #GtkLabel. To modify
6731 * the background of such widgets, you have to set the background color
6732 * on their parent; if you want to set the background of a rectangular
6733 * area around a label, try placing the label in a #GtkEventBox widget
6734 * and setting the background color on that.
6737 gtk_widget_modify_bg (GtkWidget *widget,
6739 const GdkColor *color)
6741 g_return_if_fail (GTK_IS_WIDGET (widget));
6742 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6744 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6748 * gtk_widget_modify_text:
6749 * @widget: a #GtkWidget
6750 * @state: the state for which to set the text color
6751 * @color: (allow-none): the color to assign (does not need to be allocated),
6752 * or %NULL to undo the effect of previous calls to
6753 * of gtk_widget_modify_text().
6755 * Sets the text color for a widget in a particular state. All other
6756 * style values are left untouched. The text color is the foreground
6757 * color used along with the base color (see gtk_widget_modify_base())
6758 * for widgets such as #GtkEntry and #GtkTextView. See also
6759 * gtk_widget_modify_style().
6762 gtk_widget_modify_text (GtkWidget *widget,
6764 const GdkColor *color)
6766 g_return_if_fail (GTK_IS_WIDGET (widget));
6767 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6769 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6773 * gtk_widget_modify_base:
6774 * @widget: a #GtkWidget
6775 * @state: the state for which to set the base color
6776 * @color: (allow-none): the color to assign (does not need to be allocated),
6777 * or %NULL to undo the effect of previous calls to
6778 * of gtk_widget_modify_base().
6780 * Sets the base color for a widget in a particular state.
6781 * All other style values are left untouched. The base color
6782 * is the background color used along with the text color
6783 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6784 * and #GtkTextView. See also gtk_widget_modify_style().
6786 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6787 * draw on their parent container's window and thus may not draw any
6788 * background themselves. This is the case for e.g. #GtkLabel. To modify
6789 * the background of such widgets, you have to set the base color on their
6790 * parent; if you want to set the background of a rectangular area around
6791 * a label, try placing the label in a #GtkEventBox widget and setting
6792 * the base color on that.
6795 gtk_widget_modify_base (GtkWidget *widget,
6797 const GdkColor *color)
6799 g_return_if_fail (GTK_IS_WIDGET (widget));
6800 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6802 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6806 modify_color_property (GtkWidget *widget,
6807 GtkRcStyle *rc_style,
6809 const GdkColor *color)
6811 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6812 GQuark property_name = g_quark_from_string (name);
6816 GtkRcProperty rc_property = {0};
6819 rc_property.type_name = type_name;
6820 rc_property.property_name = property_name;
6821 rc_property.origin = NULL;
6823 color_name = gdk_color_to_string (color);
6824 g_value_init (&rc_property.value, G_TYPE_STRING);
6825 g_value_take_string (&rc_property.value, color_name);
6827 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6829 g_value_unset (&rc_property.value);
6832 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6836 * gtk_widget_modify_cursor:
6837 * @widget: a #GtkWidget
6838 * @primary: the color to use for primary cursor (does not need to be
6839 * allocated), or %NULL to undo the effect of previous calls to
6840 * of gtk_widget_modify_cursor().
6841 * @secondary: the color to use for secondary cursor (does not need to be
6842 * allocated), or %NULL to undo the effect of previous calls to
6843 * of gtk_widget_modify_cursor().
6845 * Sets the cursor color to use in a widget, overriding the
6846 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6847 * style properties. All other style values are left untouched.
6848 * See also gtk_widget_modify_style().
6853 gtk_widget_modify_cursor (GtkWidget *widget,
6854 const GdkColor *primary,
6855 const GdkColor *secondary)
6857 GtkRcStyle *rc_style;
6859 g_return_if_fail (GTK_IS_WIDGET (widget));
6861 rc_style = gtk_widget_get_modifier_style (widget);
6863 modify_color_property (widget, rc_style, "cursor-color", primary);
6864 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6866 gtk_widget_modify_style (widget, rc_style);
6870 * gtk_widget_modify_font:
6871 * @widget: a #GtkWidget
6872 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6873 * the effect of previous calls to gtk_widget_modify_font().
6875 * Sets the font to use for a widget. All other style values are left
6876 * untouched. See also gtk_widget_modify_style().
6879 gtk_widget_modify_font (GtkWidget *widget,
6880 PangoFontDescription *font_desc)
6882 GtkRcStyle *rc_style;
6884 g_return_if_fail (GTK_IS_WIDGET (widget));
6886 rc_style = gtk_widget_get_modifier_style (widget);
6888 if (rc_style->font_desc)
6889 pango_font_description_free (rc_style->font_desc);
6892 rc_style->font_desc = pango_font_description_copy (font_desc);
6894 rc_style->font_desc = NULL;
6896 gtk_widget_modify_style (widget, rc_style);
6900 gtk_widget_real_direction_changed (GtkWidget *widget,
6901 GtkTextDirection previous_direction)
6903 gtk_widget_queue_resize (widget);
6907 gtk_widget_real_style_set (GtkWidget *widget,
6908 GtkStyle *previous_style)
6910 if (gtk_widget_get_realized (widget) &&
6911 gtk_widget_get_has_window (widget))
6912 gtk_style_set_background (widget->style, widget->window, widget->state);
6916 gtk_widget_set_style_internal (GtkWidget *widget,
6918 gboolean initial_emission)
6920 g_object_ref (widget);
6921 g_object_freeze_notify (G_OBJECT (widget));
6923 if (widget->style != style)
6925 GtkStyle *previous_style;
6927 if (gtk_widget_get_realized (widget))
6929 gtk_widget_reset_shapes (widget);
6930 gtk_style_detach (widget->style);
6933 previous_style = widget->style;
6934 widget->style = style;
6935 g_object_ref (widget->style);
6937 if (gtk_widget_get_realized (widget))
6938 widget->style = gtk_style_attach (widget->style, widget->window);
6940 gtk_widget_update_pango_context (widget);
6941 g_signal_emit (widget,
6942 widget_signals[STYLE_SET],
6944 initial_emission ? NULL : previous_style);
6945 g_object_unref (previous_style);
6947 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6948 gtk_widget_queue_resize (widget);
6950 else if (initial_emission)
6952 gtk_widget_update_pango_context (widget);
6953 g_signal_emit (widget,
6954 widget_signals[STYLE_SET],
6958 g_object_notify (G_OBJECT (widget), "style");
6959 g_object_thaw_notify (G_OBJECT (widget));
6960 g_object_unref (widget);
6964 GtkWidget *previous_toplevel;
6965 GdkScreen *previous_screen;
6966 GdkScreen *new_screen;
6967 } HierarchyChangedInfo;
6970 do_screen_change (GtkWidget *widget,
6971 GdkScreen *old_screen,
6972 GdkScreen *new_screen)
6974 if (old_screen != new_screen)
6978 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6980 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6983 _gtk_tooltip_hide (widget);
6984 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6989 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6990 gpointer client_data)
6992 HierarchyChangedInfo *info = client_data;
6993 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
6994 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6996 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6998 g_object_ref (widget);
7001 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7003 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7005 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7006 do_screen_change (widget, info->previous_screen, info->new_screen);
7008 if (GTK_IS_CONTAINER (widget))
7009 gtk_container_forall (GTK_CONTAINER (widget),
7010 gtk_widget_propagate_hierarchy_changed_recurse,
7013 g_object_unref (widget);
7018 * _gtk_widget_propagate_hierarchy_changed:
7019 * @widget: a #GtkWidget
7020 * @previous_toplevel: Previous toplevel
7022 * Propagates changes in the anchored state to a widget and all
7023 * children, unsetting or setting the %ANCHORED flag, and
7024 * emitting #GtkWidget::hierarchy-changed.
7027 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7028 GtkWidget *previous_toplevel)
7030 HierarchyChangedInfo info;
7032 info.previous_toplevel = previous_toplevel;
7033 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7035 if (gtk_widget_is_toplevel (widget) ||
7036 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7037 info.new_screen = gtk_widget_get_screen (widget);
7039 info.new_screen = NULL;
7041 if (info.previous_screen)
7042 g_object_ref (info.previous_screen);
7043 if (previous_toplevel)
7044 g_object_ref (previous_toplevel);
7046 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7048 if (previous_toplevel)
7049 g_object_unref (previous_toplevel);
7050 if (info.previous_screen)
7051 g_object_unref (info.previous_screen);
7055 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7056 gpointer client_data)
7058 HierarchyChangedInfo *info = client_data;
7060 g_object_ref (widget);
7062 do_screen_change (widget, info->previous_screen, info->new_screen);
7064 if (GTK_IS_CONTAINER (widget))
7065 gtk_container_forall (GTK_CONTAINER (widget),
7066 gtk_widget_propagate_screen_changed_recurse,
7069 g_object_unref (widget);
7073 * gtk_widget_is_composited:
7074 * @widget: a #GtkWidget
7076 * Whether @widget can rely on having its alpha channel
7077 * drawn correctly. On X11 this function returns whether a
7078 * compositing manager is running for @widget's screen.
7080 * Please note that the semantics of this call will change
7081 * in the future if used on a widget that has a composited
7082 * window in its hierarchy (as set by gdk_window_set_composited()).
7084 * Return value: %TRUE if the widget can rely on its alpha
7085 * channel being drawn correctly.
7090 gtk_widget_is_composited (GtkWidget *widget)
7094 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7096 screen = gtk_widget_get_screen (widget);
7098 return gdk_screen_is_composited (screen);
7102 propagate_composited_changed (GtkWidget *widget,
7105 if (GTK_IS_CONTAINER (widget))
7107 gtk_container_forall (GTK_CONTAINER (widget),
7108 propagate_composited_changed,
7112 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7116 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7118 propagate_composited_changed (widget, NULL);
7122 * _gtk_widget_propagate_screen_changed:
7123 * @widget: a #GtkWidget
7124 * @previous_screen: Previous screen
7126 * Propagates changes in the screen for a widget to all
7127 * children, emitting #GtkWidget::screen-changed.
7130 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7131 GdkScreen *previous_screen)
7133 HierarchyChangedInfo info;
7135 info.previous_screen = previous_screen;
7136 info.new_screen = gtk_widget_get_screen (widget);
7138 if (previous_screen)
7139 g_object_ref (previous_screen);
7141 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7143 if (previous_screen)
7144 g_object_unref (previous_screen);
7148 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7150 if (gtk_widget_has_rc_style (widget))
7151 gtk_widget_reset_rc_style (widget);
7153 if (GTK_IS_CONTAINER (widget))
7154 gtk_container_forall (GTK_CONTAINER (widget),
7155 reset_rc_styles_recurse,
7161 * gtk_widget_reset_rc_styles:
7162 * @widget: a #GtkWidget.
7164 * Reset the styles of @widget and all descendents, so when
7165 * they are looked up again, they get the correct values
7166 * for the currently loaded RC file settings.
7168 * This function is not useful for applications.
7171 gtk_widget_reset_rc_styles (GtkWidget *widget)
7173 g_return_if_fail (GTK_IS_WIDGET (widget));
7175 reset_rc_styles_recurse (widget, NULL);
7179 * gtk_widget_get_default_style:
7181 * Returns the default style used by all widgets initially.
7183 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7184 * by GTK+ and should not be modified or freed.
7187 gtk_widget_get_default_style (void)
7189 if (!gtk_default_style)
7191 gtk_default_style = gtk_style_new ();
7192 g_object_ref (gtk_default_style);
7195 return gtk_default_style;
7198 static PangoContext *
7199 gtk_widget_peek_pango_context (GtkWidget *widget)
7201 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7205 * gtk_widget_get_pango_context:
7206 * @widget: a #GtkWidget
7208 * Gets a #PangoContext with the appropriate font map, font description,
7209 * and base direction for this widget. Unlike the context returned
7210 * by gtk_widget_create_pango_context(), this context is owned by
7211 * the widget (it can be used until the screen for the widget changes
7212 * or the widget is removed from its toplevel), and will be updated to
7213 * match any changes to the widget's attributes.
7215 * If you create and keep a #PangoLayout using this context, you must
7216 * deal with changes to the context by calling pango_layout_context_changed()
7217 * on the layout in response to the #GtkWidget::style-set and
7218 * #GtkWidget::direction-changed signals for the widget.
7220 * Return value: (transfer none): the #PangoContext for the widget.
7223 gtk_widget_get_pango_context (GtkWidget *widget)
7225 PangoContext *context;
7227 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7229 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7232 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7233 g_object_set_qdata_full (G_OBJECT (widget),
7234 quark_pango_context,
7243 update_pango_context (GtkWidget *widget,
7244 PangoContext *context)
7246 pango_context_set_font_description (context, widget->style->font_desc);
7247 pango_context_set_base_dir (context,
7248 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7249 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7253 gtk_widget_update_pango_context (GtkWidget *widget)
7255 PangoContext *context = gtk_widget_peek_pango_context (widget);
7261 update_pango_context (widget, context);
7263 screen = gtk_widget_get_screen_unchecked (widget);
7266 pango_cairo_context_set_resolution (context,
7267 gdk_screen_get_resolution (screen));
7268 pango_cairo_context_set_font_options (context,
7269 gdk_screen_get_font_options (screen));
7275 * gtk_widget_create_pango_context:
7276 * @widget: a #GtkWidget
7278 * Creates a new #PangoContext with the appropriate font map,
7279 * font description, and base direction for drawing text for
7280 * this widget. See also gtk_widget_get_pango_context().
7282 * Return value: the new #PangoContext
7285 gtk_widget_create_pango_context (GtkWidget *widget)
7288 PangoContext *context;
7290 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7292 screen = gtk_widget_get_screen_unchecked (widget);
7295 GTK_NOTE (MULTIHEAD,
7296 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7298 screen = gdk_screen_get_default ();
7301 context = gdk_pango_context_get_for_screen (screen);
7303 update_pango_context (widget, context);
7304 pango_context_set_language (context, gtk_get_default_language ());
7310 * gtk_widget_create_pango_layout:
7311 * @widget: a #GtkWidget
7312 * @text: text to set on the layout (can be %NULL)
7314 * Creates a new #PangoLayout with the appropriate font map,
7315 * font description, and base direction for drawing text for
7318 * If you keep a #PangoLayout created in this way around, in order to
7319 * notify the layout of changes to the base direction or font of this
7320 * widget, you must call pango_layout_context_changed() in response to
7321 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7324 * Return value: the new #PangoLayout
7327 gtk_widget_create_pango_layout (GtkWidget *widget,
7330 PangoLayout *layout;
7331 PangoContext *context;
7333 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7335 context = gtk_widget_get_pango_context (widget);
7336 layout = pango_layout_new (context);
7339 pango_layout_set_text (layout, text, -1);
7345 * gtk_widget_render_icon:
7346 * @widget: a #GtkWidget
7347 * @stock_id: a stock ID
7348 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7349 * render at the size of the source and don't scale (if there are
7350 * multiple source sizes, GTK+ picks one of the available sizes).
7351 * @detail: (allow-none): render detail to pass to theme engine
7353 * A convenience function that uses the theme engine and RC file
7354 * settings for @widget to look up @stock_id and render it to
7355 * a pixbuf. @stock_id should be a stock icon ID such as
7356 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7357 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7358 * identifies the widget or code doing the rendering, so that
7359 * theme engines can special-case rendering for that widget or code.
7361 * The pixels in the returned #GdkPixbuf are shared with the rest of
7362 * the application and should not be modified. The pixbuf should be freed
7363 * after use with g_object_unref().
7365 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7368 gtk_widget_render_icon (GtkWidget *widget,
7369 const gchar *stock_id,
7371 const gchar *detail)
7373 GtkIconSet *icon_set;
7376 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7377 g_return_val_if_fail (stock_id != NULL, NULL);
7378 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7380 gtk_widget_ensure_style (widget);
7382 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7384 if (icon_set == NULL)
7387 retval = gtk_icon_set_render_icon (icon_set,
7389 gtk_widget_get_direction (widget),
7390 gtk_widget_get_state (widget),
7399 * gtk_widget_set_parent_window:
7400 * @widget: a #GtkWidget.
7401 * @parent_window: the new parent window.
7403 * Sets a non default parent window for @widget.
7406 gtk_widget_set_parent_window (GtkWidget *widget,
7407 GdkWindow *parent_window)
7409 GdkWindow *old_parent_window;
7411 g_return_if_fail (GTK_IS_WIDGET (widget));
7413 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7414 quark_parent_window);
7416 if (parent_window != old_parent_window)
7418 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7420 if (old_parent_window)
7421 g_object_unref (old_parent_window);
7423 g_object_ref (parent_window);
7428 * gtk_widget_get_parent_window:
7429 * @widget: a #GtkWidget.
7431 * Gets @widget's parent window.
7433 * Returns: (transfer none): the parent window of @widget.
7436 gtk_widget_get_parent_window (GtkWidget *widget)
7438 GdkWindow *parent_window;
7440 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7442 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7444 return (parent_window != NULL) ? parent_window :
7445 (widget->parent != NULL) ? widget->parent->window : NULL;
7450 * gtk_widget_set_child_visible:
7451 * @widget: a #GtkWidget
7452 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7454 * Sets whether @widget should be mapped along with its when its parent
7455 * is mapped and @widget has been shown with gtk_widget_show().
7457 * The child visibility can be set for widget before it is added to
7458 * a container with gtk_widget_set_parent(), to avoid mapping
7459 * children unnecessary before immediately unmapping them. However
7460 * it will be reset to its default state of %TRUE when the widget
7461 * is removed from a container.
7463 * Note that changing the child visibility of a widget does not
7464 * queue a resize on the widget. Most of the time, the size of
7465 * a widget is computed from all visible children, whether or
7466 * not they are mapped. If this is not the case, the container
7467 * can queue a resize itself.
7469 * This function is only useful for container implementations and
7470 * never should be called by an application.
7473 gtk_widget_set_child_visible (GtkWidget *widget,
7474 gboolean is_visible)
7476 g_return_if_fail (GTK_IS_WIDGET (widget));
7477 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7479 g_object_ref (widget);
7482 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7485 GtkWidget *toplevel;
7487 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7489 toplevel = gtk_widget_get_toplevel (widget);
7490 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7491 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7494 if (widget->parent && gtk_widget_get_realized (widget->parent))
7496 if (gtk_widget_get_mapped (widget->parent) &&
7497 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7498 gtk_widget_get_visible (widget))
7499 gtk_widget_map (widget);
7501 gtk_widget_unmap (widget);
7504 g_object_unref (widget);
7508 * gtk_widget_get_child_visible:
7509 * @widget: a #GtkWidget
7511 * Gets the value set with gtk_widget_set_child_visible().
7512 * If you feel a need to use this function, your code probably
7513 * needs reorganization.
7515 * This function is only useful for container implementations and
7516 * never should be called by an application.
7518 * Return value: %TRUE if the widget is mapped with the parent.
7521 gtk_widget_get_child_visible (GtkWidget *widget)
7523 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7525 return GTK_WIDGET_CHILD_VISIBLE (widget);
7529 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7531 GtkWidget *toplevel;
7533 toplevel = gtk_widget_get_toplevel (widget);
7535 if (gtk_widget_is_toplevel (toplevel))
7537 if (GTK_IS_WINDOW (toplevel))
7538 return GTK_WINDOW (toplevel)->screen;
7539 else if (GTK_IS_INVISIBLE (toplevel))
7540 return GTK_INVISIBLE (widget)->screen;
7547 * gtk_widget_get_screen:
7548 * @widget: a #GtkWidget
7550 * Get the #GdkScreen from the toplevel window associated with
7551 * this widget. This function can only be called after the widget
7552 * has been added to a widget hierarchy with a #GtkWindow
7555 * In general, you should only create screen specific
7556 * resources when a widget has been realized, and you should
7557 * free those resources when the widget is unrealized.
7559 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7564 gtk_widget_get_screen (GtkWidget *widget)
7568 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7570 screen = gtk_widget_get_screen_unchecked (widget);
7577 g_warning (G_STRLOC ": Can't get associated screen"
7578 " for a widget unless it is inside a toplevel GtkWindow\n"
7579 " widget type is %s associated top level type is %s",
7580 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7581 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7583 return gdk_screen_get_default ();
7588 * gtk_widget_has_screen:
7589 * @widget: a #GtkWidget
7591 * Checks whether there is a #GdkScreen is associated with
7592 * this widget. All toplevel widgets have an associated
7593 * screen, and all widgets added into a hierarchy with a toplevel
7594 * window at the top.
7596 * Return value: %TRUE if there is a #GdkScreen associcated
7602 gtk_widget_has_screen (GtkWidget *widget)
7604 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7606 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7610 * gtk_widget_get_display:
7611 * @widget: a #GtkWidget
7613 * Get the #GdkDisplay for the toplevel window associated with
7614 * this widget. This function can only be called after the widget
7615 * has been added to a widget hierarchy with a #GtkWindow at the top.
7617 * In general, you should only create display specific
7618 * resources when a widget has been realized, and you should
7619 * free those resources when the widget is unrealized.
7621 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7626 gtk_widget_get_display (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7630 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7634 * gtk_widget_get_root_window:
7635 * @widget: a #GtkWidget
7637 * Get the root window where this widget is located. This function can
7638 * only be called after the widget has been added to a widget
7639 * hierarchy with #GtkWindow at the top.
7641 * The root window is useful for such purposes as creating a popup
7642 * #GdkWindow associated with the window. In general, you should only
7643 * create display specific resources when a widget has been realized,
7644 * and you should free those resources when the widget is unrealized.
7646 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7651 gtk_widget_get_root_window (GtkWidget *widget)
7653 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7655 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7659 * gtk_widget_child_focus:
7660 * @widget: a #GtkWidget
7661 * @direction: direction of focus movement
7663 * This function is used by custom widget implementations; if you're
7664 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7665 * to a particular widget, and gtk_container_set_focus_chain() to
7666 * change the focus tab order. So you may want to investigate those
7667 * functions instead.
7669 * gtk_widget_child_focus() is called by containers as the user moves
7670 * around the window using keyboard shortcuts. @direction indicates
7671 * what kind of motion is taking place (up, down, left, right, tab
7672 * forward, tab backward). gtk_widget_child_focus() emits the
7673 * #GtkWidget::focus signal; widgets override the default handler
7674 * for this signal in order to implement appropriate focus behavior.
7676 * The default ::focus handler for a widget should return %TRUE if
7677 * moving in @direction left the focus on a focusable location inside
7678 * that widget, and %FALSE if moving in @direction moved the focus
7679 * outside the widget. If returning %TRUE, widgets normally
7680 * call gtk_widget_grab_focus() to place the focus accordingly;
7681 * if returning %FALSE, they don't modify the current focus location.
7683 * This function replaces gtk_container_focus() from GTK+ 1.2.
7684 * It was necessary to check that the child was visible, sensitive,
7685 * and focusable before calling gtk_container_focus().
7686 * gtk_widget_child_focus() returns %FALSE if the widget is not
7687 * currently in a focusable state, so there's no need for those checks.
7689 * Return value: %TRUE if focus ended up inside @widget
7692 gtk_widget_child_focus (GtkWidget *widget,
7693 GtkDirectionType direction)
7695 gboolean return_val;
7697 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7699 if (!gtk_widget_get_visible (widget) ||
7700 !gtk_widget_is_sensitive (widget))
7703 /* child widgets must set CAN_FOCUS, containers
7704 * don't have to though.
7706 if (!GTK_IS_CONTAINER (widget) &&
7707 !gtk_widget_get_can_focus (widget))
7710 g_signal_emit (widget,
7711 widget_signals[FOCUS],
7713 direction, &return_val);
7719 * gtk_widget_keynav_failed:
7720 * @widget: a #GtkWidget
7721 * @direction: direction of focus movement
7723 * This function should be called whenever keyboard navigation within
7724 * a single widget hits a boundary. The function emits the
7725 * #GtkWidget::keynav-failed signal on the widget and its return
7726 * value should be interpreted in a way similar to the return value of
7727 * gtk_widget_child_focus():
7729 * When %TRUE is returned, stay in the widget, the failed keyboard
7730 * navigation is Ok and/or there is nowhere we can/should move the
7733 * When %FALSE is returned, the caller should continue with keyboard
7734 * navigation outside the widget, e.g. by calling
7735 * gtk_widget_child_focus() on the widget's toplevel.
7737 * The default ::keynav-failed handler returns %TRUE for
7738 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7739 * values of #GtkDirectionType, it looks at the
7740 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7741 * if the setting is %TRUE. This way the entire user interface
7742 * becomes cursor-navigatable on input devices such as mobile phones
7743 * which only have cursor keys but no tab key.
7745 * Whenever the default handler returns %TRUE, it also calls
7746 * gtk_widget_error_bell() to notify the user of the failed keyboard
7749 * A use case for providing an own implementation of ::keynav-failed
7750 * (either by connecting to it or by overriding it) would be a row of
7751 * #GtkEntry widgets where the user should be able to navigate the
7752 * entire row with the cursor keys, as e.g. known from user interfaces
7753 * that require entering license keys.
7755 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7756 * if the emitting widget should try to handle the keyboard
7757 * navigation attempt in its parent container(s).
7762 gtk_widget_keynav_failed (GtkWidget *widget,
7763 GtkDirectionType direction)
7765 gboolean return_val;
7767 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7769 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7770 direction, &return_val);
7776 * gtk_widget_error_bell:
7777 * @widget: a #GtkWidget
7779 * Notifies the user about an input-related error on this widget.
7780 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7781 * gdk_window_beep(), otherwise it does nothing.
7783 * Note that the effect of gdk_window_beep() can be configured in many
7784 * ways, depending on the windowing backend and the desktop environment
7785 * or window manager that is used.
7790 gtk_widget_error_bell (GtkWidget *widget)
7792 GtkSettings* settings;
7795 g_return_if_fail (GTK_IS_WIDGET (widget));
7797 settings = gtk_widget_get_settings (widget);
7801 g_object_get (settings,
7802 "gtk-error-bell", &beep,
7805 if (beep && widget->window)
7806 gdk_window_beep (widget->window);
7810 gtk_widget_set_usize_internal (GtkWidget *widget,
7814 GtkWidgetAuxInfo *aux_info;
7815 gboolean changed = FALSE;
7817 g_object_freeze_notify (G_OBJECT (widget));
7819 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7821 if (width > -2 && aux_info->width != width)
7823 g_object_notify (G_OBJECT (widget), "width-request");
7824 aux_info->width = width;
7827 if (height > -2 && aux_info->height != height)
7829 g_object_notify (G_OBJECT (widget), "height-request");
7830 aux_info->height = height;
7834 if (gtk_widget_get_visible (widget) && changed)
7835 gtk_widget_queue_resize (widget);
7837 g_object_thaw_notify (G_OBJECT (widget));
7841 * gtk_widget_set_size_request:
7842 * @widget: a #GtkWidget
7843 * @width: width @widget should request, or -1 to unset
7844 * @height: height @widget should request, or -1 to unset
7846 * Sets the minimum size of a widget; that is, the widget's size
7847 * request will be @width by @height. You can use this function to
7848 * force a widget to be either larger or smaller than it normally
7851 * In most cases, gtk_window_set_default_size() is a better choice for
7852 * toplevel windows than this function; setting the default size will
7853 * still allow users to shrink the window. Setting the size request
7854 * will force them to leave the window at least as large as the size
7855 * request. When dealing with window sizes,
7856 * gtk_window_set_geometry_hints() can be a useful function as well.
7858 * Note the inherent danger of setting any fixed size - themes,
7859 * translations into other languages, different fonts, and user action
7860 * can all change the appropriate size for a given widget. So, it's
7861 * basically impossible to hardcode a size that will always be
7864 * The size request of a widget is the smallest size a widget can
7865 * accept while still functioning well and drawing itself correctly.
7866 * However in some strange cases a widget may be allocated less than
7867 * its requested size, and in many cases a widget may be allocated more
7868 * space than it requested.
7870 * If the size request in a given direction is -1 (unset), then
7871 * the "natural" size request of the widget will be used instead.
7873 * Widgets can't actually be allocated a size less than 1 by 1, but
7874 * you can pass 0,0 to this function to mean "as small as possible."
7877 gtk_widget_set_size_request (GtkWidget *widget,
7881 g_return_if_fail (GTK_IS_WIDGET (widget));
7882 g_return_if_fail (width >= -1);
7883 g_return_if_fail (height >= -1);
7890 gtk_widget_set_usize_internal (widget, width, height);
7895 * gtk_widget_get_size_request:
7896 * @widget: a #GtkWidget
7897 * @width: (allow-none): (out): return location for width, or %NULL
7898 * @height: (allow-none): (out): return location for height, or %NULL
7900 * Gets the size request that was explicitly set for the widget using
7901 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7902 * @height indicates that that dimension has not been set explicitly
7903 * and the natural requisition of the widget will be used intead. See
7904 * gtk_widget_set_size_request(). To get the size a widget will
7905 * actually use, call gtk_widget_size_request() instead of
7909 gtk_widget_get_size_request (GtkWidget *widget,
7913 GtkWidgetAuxInfo *aux_info;
7915 g_return_if_fail (GTK_IS_WIDGET (widget));
7917 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7920 *width = aux_info ? aux_info->width : -1;
7923 *height = aux_info ? aux_info->height : -1;
7927 * gtk_widget_set_events:
7928 * @widget: a #GtkWidget
7929 * @events: event mask
7931 * Sets the event mask (see #GdkEventMask) for a widget. The event
7932 * mask determines which events a widget will receive. Keep in mind
7933 * that different widgets have different default event masks, and by
7934 * changing the event mask you may disrupt a widget's functionality,
7935 * so be careful. This function must be called while a widget is
7936 * unrealized. Consider gtk_widget_add_events() for widgets that are
7937 * already realized, or if you want to preserve the existing event
7938 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7939 * to get events on those widgets, place them inside a #GtkEventBox
7940 * and receive events on the event box.
7943 gtk_widget_set_events (GtkWidget *widget,
7946 g_return_if_fail (GTK_IS_WIDGET (widget));
7947 g_return_if_fail (!gtk_widget_get_realized (widget));
7949 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7950 GINT_TO_POINTER (events));
7951 g_object_notify (G_OBJECT (widget), "events");
7955 * gtk_widget_set_device_events:
7956 * @widget: a #GtkWidget
7957 * @device: a #GdkDevice
7958 * @events: event mask
7960 * Sets the device event mask (see #GdkEventMask) for a widget. The event
7961 * mask determines which events a widget will receive from @device. Keep
7962 * in mind that different widgets have different default event masks, and by
7963 * changing the event mask you may disrupt a widget's functionality,
7964 * so be careful. This function must be called while a widget is
7965 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
7966 * already realized, or if you want to preserve the existing event
7967 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7968 * to get events on those widgets, place them inside a #GtkEventBox
7969 * and receive events on the event box.
7974 gtk_widget_set_device_events (GtkWidget *widget,
7976 GdkEventMask events)
7978 GHashTable *device_events;
7980 g_return_if_fail (GTK_IS_WIDGET (widget));
7981 g_return_if_fail (GDK_IS_DEVICE (device));
7982 g_return_if_fail (!gtk_widget_get_realized (widget));
7984 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
7986 if (G_UNLIKELY (!device_events))
7988 device_events = g_hash_table_new (NULL, NULL);
7989 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
7990 (GDestroyNotify) g_hash_table_unref);
7993 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
7997 gtk_widget_add_events_internal (GtkWidget *widget,
8004 for (l = window_list; l != NULL; l = l->next)
8006 GdkWindow *window = l->data;
8009 gdk_window_get_user_data (window, &user_data);
8010 if (user_data == widget)
8015 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8017 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8019 children = gdk_window_get_children (window);
8020 gtk_widget_add_events_internal (widget, device, events, children);
8021 g_list_free (children);
8027 * gtk_widget_add_events:
8028 * @widget: a #GtkWidget
8029 * @events: an event mask, see #GdkEventMask
8031 * Adds the events in the bitfield @events to the event mask for
8032 * @widget. See gtk_widget_set_events() for details.
8035 gtk_widget_add_events (GtkWidget *widget,
8040 g_return_if_fail (GTK_IS_WIDGET (widget));
8042 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8043 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8044 GINT_TO_POINTER (old_events | events));
8046 if (gtk_widget_get_realized (widget))
8050 if (!gtk_widget_get_has_window (widget))
8051 window_list = gdk_window_get_children (widget->window);
8053 window_list = g_list_prepend (NULL, widget->window);
8055 gtk_widget_add_events_internal (widget, NULL, events, window_list);
8057 g_list_free (window_list);
8060 g_object_notify (G_OBJECT (widget), "events");
8064 * gtk_widget_add_device_events:
8065 * @widget: a #GtkWidget
8066 * @device: a #GdkDevice
8067 * @events: an event mask, see #GdkEventMask
8069 * Adds the device events in the bitfield @events to the event mask for
8070 * @widget. See gtk_widget_set_device_events() for details.
8075 gtk_widget_add_device_events (GtkWidget *widget,
8077 GdkEventMask events)
8079 GdkEventMask old_events;
8080 GHashTable *device_events;
8082 g_return_if_fail (GTK_IS_WIDGET (widget));
8083 g_return_if_fail (GDK_IS_DEVICE (device));
8085 old_events = gtk_widget_get_device_events (widget, device);
8087 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8089 if (G_UNLIKELY (!device_events))
8091 device_events = g_hash_table_new (NULL, NULL);
8092 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8093 (GDestroyNotify) g_hash_table_unref);
8096 g_hash_table_insert (device_events, device,
8097 GUINT_TO_POINTER (old_events | events));
8099 if (gtk_widget_get_realized (widget))
8103 if (!gtk_widget_get_has_window (widget))
8104 window_list = gdk_window_get_children (widget->window);
8106 window_list = g_list_prepend (NULL, widget->window);
8108 gtk_widget_add_events_internal (widget, device, events, window_list);
8110 g_list_free (window_list);
8113 g_object_notify (G_OBJECT (widget), "events");
8117 * gtk_widget_set_extension_events:
8118 * @widget: a #GtkWidget
8119 * @mode: bitfield of extension events to receive
8121 * Sets the extension events mask to @mode. See #GdkExtensionMode
8122 * and gdk_input_set_extension_events().
8125 gtk_widget_set_extension_events (GtkWidget *widget,
8126 GdkExtensionMode mode)
8128 g_return_if_fail (GTK_IS_WIDGET (widget));
8130 if (gtk_widget_get_realized (widget))
8131 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8133 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8134 GINT_TO_POINTER (mode));
8135 g_object_notify (G_OBJECT (widget), "extension-events");
8139 * gtk_widget_get_toplevel:
8140 * @widget: a #GtkWidget
8142 * This function returns the topmost widget in the container hierarchy
8143 * @widget is a part of. If @widget has no parent widgets, it will be
8144 * returned as the topmost widget. No reference will be added to the
8145 * returned widget; it should not be unreferenced.
8147 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8148 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8150 * %NULL if @widget wasn't inside a toplevel window, and if the
8151 * window was inside a #GtkWindow-derived widget which was in turn
8152 * inside the toplevel #GtkWindow. While the second case may
8153 * seem unlikely, it actually happens when a #GtkPlug is embedded
8154 * inside a #GtkSocket within the same application.
8156 * To reliably find the toplevel #GtkWindow, use
8157 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8158 * is set on the result.
8160 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8161 * if (gtk_widget_is_toplevel (toplevel))
8163 * /* Perform action on toplevel. */
8167 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8168 * if there's no ancestor.
8171 gtk_widget_get_toplevel (GtkWidget *widget)
8173 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8175 while (widget->parent)
8176 widget = widget->parent;
8182 * gtk_widget_get_ancestor:
8183 * @widget: a #GtkWidget
8184 * @widget_type: ancestor type
8186 * Gets the first ancestor of @widget with type @widget_type. For example,
8187 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8188 * the first #GtkBox that's an ancestor of @widget. No reference will be
8189 * added to the returned widget; it should not be unreferenced. See note
8190 * about checking for a toplevel #GtkWindow in the docs for
8191 * gtk_widget_get_toplevel().
8193 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8194 * considers @widget to be an ancestor of itself.
8196 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8199 gtk_widget_get_ancestor (GtkWidget *widget,
8202 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8204 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8205 widget = widget->parent;
8207 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8214 * gtk_widget_get_colormap:
8215 * @widget: a #GtkWidget
8217 * Gets the colormap that will be used to render @widget. No reference will
8218 * be added to the returned colormap; it should not be unreferenced.
8220 * Return value: (transfer none): the colormap used by @widget
8223 gtk_widget_get_colormap (GtkWidget *widget)
8225 GdkColormap *colormap;
8226 GtkWidget *tmp_widget;
8228 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8232 colormap = gdk_drawable_get_colormap (widget->window);
8233 /* If window was destroyed previously, we'll get NULL here */
8238 tmp_widget = widget;
8241 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8245 tmp_widget= tmp_widget->parent;
8248 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8252 * gtk_widget_get_visual:
8253 * @widget: a #GtkWidget
8255 * Gets the visual that will be used to render @widget.
8257 * Return value: (transfer none): the visual for @widget
8260 gtk_widget_get_visual (GtkWidget *widget)
8262 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8264 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8268 * gtk_widget_get_settings:
8269 * @widget: a #GtkWidget
8271 * Gets the settings object holding the settings (global property
8272 * settings, RC file information, etc) used for this widget.
8274 * Note that this function can only be called when the #GtkWidget
8275 * is attached to a toplevel, since the settings object is specific
8276 * to a particular #GdkScreen.
8278 * Return value: (transfer none): the relevant #GtkSettings object
8281 gtk_widget_get_settings (GtkWidget *widget)
8283 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8285 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8289 * gtk_widget_set_colormap:
8290 * @widget: a #GtkWidget
8291 * @colormap: a colormap
8293 * Sets the colormap for the widget to the given value. Widget must not
8294 * have been previously realized. This probably should only be used
8295 * from an <function>init()</function> function (i.e. from the constructor
8299 gtk_widget_set_colormap (GtkWidget *widget,
8300 GdkColormap *colormap)
8302 g_return_if_fail (GTK_IS_WIDGET (widget));
8303 g_return_if_fail (!gtk_widget_get_realized (widget));
8304 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8306 g_object_ref (colormap);
8308 g_object_set_qdata_full (G_OBJECT (widget),
8315 * gtk_widget_get_events:
8316 * @widget: a #GtkWidget
8318 * Returns the event mask for the widget (a bitfield containing flags
8319 * from the #GdkEventMask enumeration). These are the events that the widget
8322 * Return value: event mask for @widget
8325 gtk_widget_get_events (GtkWidget *widget)
8327 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8329 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8333 * gtk_widget_get_device_events:
8334 * @widget: a #GtkWidget
8335 * @device: a #GdkDevice
8337 * Returns the events mask for the widget corresponding to an specific device. These
8338 * are the events that the widget will receive when @device operates on it.
8340 * Returns: device event mask for @widget
8345 gtk_widget_get_device_events (GtkWidget *widget,
8348 GHashTable *device_events;
8350 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8351 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8353 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8358 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8362 * gtk_widget_get_extension_events:
8363 * @widget: a #GtkWidget
8365 * Retrieves the extension events the widget will receive; see
8366 * gdk_input_set_extension_events().
8368 * Return value: extension events for @widget
8371 gtk_widget_get_extension_events (GtkWidget *widget)
8373 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8375 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8379 * gtk_widget_get_pointer:
8380 * @widget: a #GtkWidget
8381 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8382 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8384 * Obtains the location of the mouse pointer in widget coordinates.
8385 * Widget coordinates are a bit odd; for historical reasons, they are
8386 * defined as @widget->window coordinates for widgets that are not
8387 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8388 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8391 gtk_widget_get_pointer (GtkWidget *widget,
8395 g_return_if_fail (GTK_IS_WIDGET (widget));
8402 if (gtk_widget_get_realized (widget))
8404 gdk_window_get_pointer (widget->window, x, y, NULL);
8406 if (!gtk_widget_get_has_window (widget))
8409 *x -= widget->allocation.x;
8411 *y -= widget->allocation.y;
8417 * gtk_widget_is_ancestor:
8418 * @widget: a #GtkWidget
8419 * @ancestor: another #GtkWidget
8421 * Determines whether @widget is somewhere inside @ancestor, possibly with
8422 * intermediate containers.
8424 * Return value: %TRUE if @ancestor contains @widget as a child,
8425 * grandchild, great grandchild, etc.
8428 gtk_widget_is_ancestor (GtkWidget *widget,
8429 GtkWidget *ancestor)
8431 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8432 g_return_val_if_fail (ancestor != NULL, FALSE);
8436 if (widget->parent == ancestor)
8438 widget = widget->parent;
8444 static GQuark quark_composite_name = 0;
8447 * gtk_widget_set_composite_name:
8448 * @widget: a #GtkWidget.
8449 * @name: the name to set
8451 * Sets a widgets composite name. The widget must be
8452 * a composite child of its parent; see gtk_widget_push_composite_child().
8455 gtk_widget_set_composite_name (GtkWidget *widget,
8458 g_return_if_fail (GTK_IS_WIDGET (widget));
8459 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8460 g_return_if_fail (name != NULL);
8462 if (!quark_composite_name)
8463 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8465 g_object_set_qdata_full (G_OBJECT (widget),
8466 quark_composite_name,
8472 * gtk_widget_get_composite_name:
8473 * @widget: a #GtkWidget
8475 * Obtains the composite name of a widget.
8477 * Returns: the composite name of @widget, or %NULL if @widget is not
8478 * a composite child. The string should be freed when it is no
8482 gtk_widget_get_composite_name (GtkWidget *widget)
8484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8486 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8487 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8494 * gtk_widget_push_composite_child:
8496 * Makes all newly-created widgets as composite children until
8497 * the corresponding gtk_widget_pop_composite_child() call.
8499 * A composite child is a child that's an implementation detail of the
8500 * container it's inside and should not be visible to people using the
8501 * container. Composite children aren't treated differently by GTK (but
8502 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8503 * builders might want to treat them in a different way.
8505 * Here is a simple example:
8507 * gtk_widget_push_composite_child ();
8508 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8509 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8510 * gtk_widget_pop_composite_child ();
8511 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8512 * GTK_WIDGET (scrolled_window));
8513 * g_object_ref (scrolled_window->hscrollbar);
8517 gtk_widget_push_composite_child (void)
8519 composite_child_stack++;
8523 * gtk_widget_pop_composite_child:
8525 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8528 gtk_widget_pop_composite_child (void)
8530 if (composite_child_stack)
8531 composite_child_stack--;
8535 * gtk_widget_push_colormap:
8536 * @cmap: a #GdkColormap
8538 * Pushes @cmap onto a global stack of colormaps; the topmost
8539 * colormap on the stack will be used to create all widgets.
8540 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8541 * reason to use this function.
8544 gtk_widget_push_colormap (GdkColormap *cmap)
8546 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8548 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8552 * gtk_widget_pop_colormap:
8554 * Removes a colormap pushed with gtk_widget_push_colormap().
8557 gtk_widget_pop_colormap (void)
8560 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8564 * gtk_widget_set_default_colormap:
8565 * @colormap: a #GdkColormap
8567 * Sets the default colormap to use when creating widgets.
8568 * gtk_widget_push_colormap() is a better function to use if
8569 * you only want to affect a few widgets, rather than all widgets.
8572 gtk_widget_set_default_colormap (GdkColormap *colormap)
8574 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8576 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8581 * gtk_widget_get_default_colormap:
8583 * Obtains the default colormap used to create widgets.
8585 * Return value: (transfer none): default widget colormap
8588 gtk_widget_get_default_colormap (void)
8590 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8594 * gtk_widget_get_default_visual:
8596 * Obtains the visual of the default colormap. Not really useful;
8597 * used to be useful before gdk_colormap_get_visual() existed.
8599 * Return value: (transfer none): visual of the default colormap
8602 gtk_widget_get_default_visual (void)
8604 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8608 gtk_widget_emit_direction_changed (GtkWidget *widget,
8609 GtkTextDirection old_dir)
8611 gtk_widget_update_pango_context (widget);
8613 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8617 * gtk_widget_set_direction:
8618 * @widget: a #GtkWidget
8619 * @dir: the new direction
8621 * Sets the reading direction on a particular widget. This direction
8622 * controls the primary direction for widgets containing text,
8623 * and also the direction in which the children of a container are
8624 * packed. The ability to set the direction is present in order
8625 * so that correct localization into languages with right-to-left
8626 * reading directions can be done. Generally, applications will
8627 * let the default reading direction present, except for containers
8628 * where the containers are arranged in an order that is explicitely
8629 * visual rather than logical (such as buttons for text justification).
8631 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8632 * set by gtk_widget_set_default_direction() will be used.
8635 gtk_widget_set_direction (GtkWidget *widget,
8636 GtkTextDirection dir)
8638 GtkTextDirection old_dir;
8640 g_return_if_fail (GTK_IS_WIDGET (widget));
8641 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8643 old_dir = gtk_widget_get_direction (widget);
8645 if (dir == GTK_TEXT_DIR_NONE)
8646 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8649 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8650 if (dir == GTK_TEXT_DIR_LTR)
8651 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8653 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8656 if (old_dir != gtk_widget_get_direction (widget))
8657 gtk_widget_emit_direction_changed (widget, old_dir);
8661 * gtk_widget_get_direction:
8662 * @widget: a #GtkWidget
8664 * Gets the reading direction for a particular widget. See
8665 * gtk_widget_set_direction().
8667 * Return value: the reading direction for the widget.
8670 gtk_widget_get_direction (GtkWidget *widget)
8672 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8674 if (GTK_WIDGET_DIRECTION_SET (widget))
8675 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8677 return gtk_default_direction;
8681 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8683 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8685 g_object_ref (widget);
8687 if (!GTK_WIDGET_DIRECTION_SET (widget))
8688 gtk_widget_emit_direction_changed (widget, old_dir);
8690 if (GTK_IS_CONTAINER (widget))
8691 gtk_container_forall (GTK_CONTAINER (widget),
8692 gtk_widget_set_default_direction_recurse,
8695 g_object_unref (widget);
8699 * gtk_widget_set_default_direction:
8700 * @dir: the new default direction. This cannot be
8701 * %GTK_TEXT_DIR_NONE.
8703 * Sets the default reading direction for widgets where the
8704 * direction has not been explicitly set by gtk_widget_set_direction().
8707 gtk_widget_set_default_direction (GtkTextDirection dir)
8709 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8711 if (dir != gtk_default_direction)
8713 GList *toplevels, *tmp_list;
8714 GtkTextDirection old_dir = gtk_default_direction;
8716 gtk_default_direction = dir;
8718 tmp_list = toplevels = gtk_window_list_toplevels ();
8719 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8723 gtk_widget_set_default_direction_recurse (tmp_list->data,
8724 GUINT_TO_POINTER (old_dir));
8725 g_object_unref (tmp_list->data);
8726 tmp_list = tmp_list->next;
8729 g_list_free (toplevels);
8734 * gtk_widget_get_default_direction:
8736 * Obtains the current default reading direction. See
8737 * gtk_widget_set_default_direction().
8739 * Return value: the current default direction.
8742 gtk_widget_get_default_direction (void)
8744 return gtk_default_direction;
8748 gtk_widget_dispose (GObject *object)
8750 GtkWidget *widget = GTK_WIDGET (object);
8753 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8754 else if (gtk_widget_get_visible (widget))
8755 gtk_widget_hide (widget);
8757 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8758 if (gtk_widget_get_realized (widget))
8759 gtk_widget_unrealize (widget);
8761 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8765 gtk_widget_real_destroy (GtkObject *object)
8767 /* gtk_object_destroy() will already hold a refcount on object */
8768 GtkWidget *widget = GTK_WIDGET (object);
8770 /* wipe accelerator closures (keep order) */
8771 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8772 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8774 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8775 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8777 gtk_grab_remove (widget);
8779 g_object_unref (widget->style);
8780 widget->style = gtk_widget_get_default_style ();
8781 g_object_ref (widget->style);
8783 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8787 gtk_widget_finalize (GObject *object)
8789 GtkWidget *widget = GTK_WIDGET (object);
8790 GtkWidgetAuxInfo *aux_info;
8791 GtkAccessible *accessible;
8793 gtk_grab_remove (widget);
8795 g_object_unref (widget->style);
8796 widget->style = NULL;
8798 g_free (widget->name);
8800 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8802 gtk_widget_aux_info_destroy (aux_info);
8804 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8806 g_object_unref (accessible);
8808 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8811 /*****************************************
8812 * gtk_widget_real_map:
8817 *****************************************/
8820 gtk_widget_real_map (GtkWidget *widget)
8822 g_assert (gtk_widget_get_realized (widget));
8824 if (!gtk_widget_get_mapped (widget))
8826 gtk_widget_set_mapped (widget, TRUE);
8828 if (gtk_widget_get_has_window (widget))
8829 gdk_window_show (widget->window);
8833 /*****************************************
8834 * gtk_widget_real_unmap:
8839 *****************************************/
8842 gtk_widget_real_unmap (GtkWidget *widget)
8844 if (gtk_widget_get_mapped (widget))
8846 gtk_widget_set_mapped (widget, FALSE);
8848 if (gtk_widget_get_has_window (widget))
8849 gdk_window_hide (widget->window);
8853 /*****************************************
8854 * gtk_widget_real_realize:
8859 *****************************************/
8862 gtk_widget_real_realize (GtkWidget *widget)
8864 g_assert (!gtk_widget_get_has_window (widget));
8866 gtk_widget_set_realized (widget, TRUE);
8869 widget->window = gtk_widget_get_parent_window (widget);
8870 g_object_ref (widget->window);
8872 widget->style = gtk_style_attach (widget->style, widget->window);
8875 /*****************************************
8876 * gtk_widget_real_unrealize:
8881 *****************************************/
8884 gtk_widget_real_unrealize (GtkWidget *widget)
8886 if (gtk_widget_get_mapped (widget))
8887 gtk_widget_real_unmap (widget);
8889 gtk_widget_set_mapped (widget, FALSE);
8891 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8894 /* We must do unrealize child widget BEFORE container widget.
8895 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8896 * So, unrealizing container widget bofore its children causes the problem
8897 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8900 if (GTK_IS_CONTAINER (widget))
8901 gtk_container_forall (GTK_CONTAINER (widget),
8902 (GtkCallback) gtk_widget_unrealize,
8905 gtk_style_detach (widget->style);
8906 if (gtk_widget_get_has_window (widget))
8908 gdk_window_set_user_data (widget->window, NULL);
8909 gdk_window_destroy (widget->window);
8910 widget->window = NULL;
8914 g_object_unref (widget->window);
8915 widget->window = NULL;
8918 gtk_selection_remove_all (widget);
8920 gtk_widget_set_realized (widget, FALSE);
8924 gtk_widget_real_size_request (GtkWidget *widget,
8925 GtkRequisition *requisition)
8927 requisition->width = widget->requisition.width;
8928 requisition->height = widget->requisition.height;
8932 * _gtk_widget_peek_colormap:
8934 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8936 * Return value: the currently pushed colormap, or %NULL if there is none.
8939 _gtk_widget_peek_colormap (void)
8942 return (GdkColormap*) colormap_stack->data;
8947 * _gtk_widget_set_device_window:
8948 * @widget: a #GtkWidget.
8949 * @device: a #GdkDevice.
8950 * @window: the new device window.
8952 * Sets pointer window for @widget and @device. Does not ref @window.
8953 * Actually stores it on the #GdkScreen, but you don't need to know that.
8956 _gtk_widget_set_device_window (GtkWidget *widget,
8961 GHashTable *device_window;
8963 g_return_if_fail (GTK_IS_WIDGET (widget));
8964 g_return_if_fail (GDK_IS_DEVICE (device));
8965 g_return_if_fail (!window || GDK_IS_WINDOW (window));
8967 if (!gtk_widget_get_realized (widget))
8970 screen = gdk_drawable_get_screen (widget->window);
8971 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8973 if (G_UNLIKELY (!device_window))
8975 device_window = g_hash_table_new (NULL, NULL);
8976 g_object_set_qdata_full (G_OBJECT (screen),
8977 quark_pointer_window,
8979 (GDestroyNotify) g_hash_table_destroy);
8983 g_hash_table_insert (device_window, device, window);
8985 g_hash_table_remove (device_window, device);
8989 * _gtk_widget_get_device_window:
8990 * @widget: a #GtkWidget.
8991 * @device: a #GdkDevice.
8993 * Return value: the device window set on the #GdkScreen @widget is attached
8997 _gtk_widget_get_device_window (GtkWidget *widget,
9001 GHashTable *device_window;
9005 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9006 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9008 if (!gtk_widget_get_realized (widget))
9011 screen = gdk_drawable_get_screen (widget->window);
9012 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9014 if (G_UNLIKELY (!device_window))
9017 window = g_hash_table_lookup (device_window, device);
9022 gdk_window_get_user_data (window, (gpointer *) &w);
9031 * _gtk_widget_list_devices:
9032 * @widget: a #GtkWidget.
9034 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9035 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9039 _gtk_widget_list_devices (GtkWidget *widget)
9042 GHashTableIter iter;
9043 GHashTable *device_window;
9044 GList *devices = NULL;
9045 gpointer key, value;
9047 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9049 if (!gtk_widget_get_realized (widget))
9052 screen = gdk_drawable_get_screen (widget->window);
9053 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9055 if (G_UNLIKELY (!device_window))
9058 g_hash_table_iter_init (&iter, device_window);
9060 while (g_hash_table_iter_next (&iter, &key, &value))
9062 GdkDevice *device = key;
9063 GdkWindow *window = value;
9068 gdk_window_get_user_data (window, (gpointer *) &w);
9071 devices = g_list_prepend (devices, device);
9079 synth_crossing (GtkWidget *widget,
9083 GdkCrossingMode mode,
9084 GdkNotifyType detail)
9088 event = gdk_event_new (type);
9090 event->crossing.window = g_object_ref (window);
9091 event->crossing.send_event = TRUE;
9092 event->crossing.subwindow = g_object_ref (window);
9093 event->crossing.time = GDK_CURRENT_TIME;
9094 event->crossing.x = event->crossing.y = 0;
9095 event->crossing.x_root = event->crossing.y_root = 0;
9096 event->crossing.mode = mode;
9097 event->crossing.detail = detail;
9098 event->crossing.focus = FALSE;
9099 event->crossing.state = 0;
9100 gdk_event_set_device (event, device);
9103 widget = gtk_get_event_widget (event);
9106 gtk_widget_event_internal (widget, event);
9108 gdk_event_free (event);
9112 * _gtk_widget_synthesize_crossing:
9113 * @from: the #GtkWidget the virtual pointer is leaving.
9114 * @to: the #GtkWidget the virtual pointer is moving to.
9115 * @mode: the #GdkCrossingMode to place on the synthesized events.
9117 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9119 * The real pointer window is the window that most recently received an enter notify
9120 * event. Windows that don't select for crossing events can't become the real
9121 * poiner window. The real pointer widget that owns the real pointer window. The
9122 * effective pointer window is the same as the real pointer window unless the real
9123 * pointer widget is either insensitive or there is a grab on a widget that is not
9124 * an ancestor of the real pointer widget (in which case the effective pointer
9125 * window should be the root window).
9127 * When the effective pointer window is the same as the real poiner window, we
9128 * receive crossing events from the windowing system. When the effective pointer
9129 * window changes to become different from the real pointer window we synthesize
9130 * crossing events, attempting to follow X protocol rules:
9132 * When the root window becomes the effective pointer window:
9133 * - leave notify on real pointer window, detail Ancestor
9134 * - leave notify on all of its ancestors, detail Virtual
9135 * - enter notify on root window, detail Inferior
9137 * When the root window ceases to be the effective pointer window:
9138 * - leave notify on root window, detail Inferior
9139 * - enter notify on all ancestors of real pointer window, detail Virtual
9140 * - enter notify on real pointer window, detail Ancestor
9143 _gtk_widget_synthesize_crossing (GtkWidget *from,
9146 GdkCrossingMode mode)
9148 GdkWindow *from_window = NULL, *to_window = NULL;
9150 g_return_if_fail (from != NULL || to != NULL);
9154 from_window = _gtk_widget_get_device_window (from, device);
9157 from_window = from->window;
9162 to_window = _gtk_widget_get_device_window (to, device);
9165 to_window = to->window;
9168 if (from_window == NULL && to_window == NULL)
9170 else if (from_window != NULL && to_window == NULL)
9172 GList *from_ancestors = NULL, *list;
9173 GdkWindow *from_ancestor = from_window;
9175 while (from_ancestor != NULL)
9177 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9178 if (from_ancestor == NULL)
9180 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9183 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9184 device, mode, GDK_NOTIFY_ANCESTOR);
9185 for (list = g_list_last (from_ancestors); list; list = list->prev)
9187 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9188 device, mode, GDK_NOTIFY_VIRTUAL);
9191 /* XXX: enter/inferior on root window? */
9193 g_list_free (from_ancestors);
9195 else if (from_window == NULL && to_window != NULL)
9197 GList *to_ancestors = NULL, *list;
9198 GdkWindow *to_ancestor = to_window;
9200 while (to_ancestor != NULL)
9202 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9203 if (to_ancestor == NULL)
9205 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9208 /* XXX: leave/inferior on root window? */
9210 for (list = to_ancestors; list; list = list->next)
9212 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9213 device, mode, GDK_NOTIFY_VIRTUAL);
9215 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9216 device, mode, GDK_NOTIFY_ANCESTOR);
9218 g_list_free (to_ancestors);
9220 else if (from_window == to_window)
9224 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9225 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9227 while (from_ancestor != NULL || to_ancestor != NULL)
9229 if (from_ancestor != NULL)
9231 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9232 if (from_ancestor == to_window)
9235 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9237 if (to_ancestor != NULL)
9239 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9240 if (to_ancestor == from_window)
9243 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9246 if (to_ancestor == from_window)
9248 if (mode != GDK_CROSSING_GTK_UNGRAB)
9249 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9250 device, mode, GDK_NOTIFY_INFERIOR);
9251 for (list = to_ancestors; list; list = list->next)
9252 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9253 device, mode, GDK_NOTIFY_VIRTUAL);
9254 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9255 device, mode, GDK_NOTIFY_ANCESTOR);
9257 else if (from_ancestor == to_window)
9259 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9260 device, mode, GDK_NOTIFY_ANCESTOR);
9261 for (list = g_list_last (from_ancestors); list; list = list->prev)
9263 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9264 device, mode, GDK_NOTIFY_VIRTUAL);
9266 if (mode != GDK_CROSSING_GTK_GRAB)
9267 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9268 device, mode, GDK_NOTIFY_INFERIOR);
9272 while (from_ancestors != NULL && to_ancestors != NULL
9273 && from_ancestors->data == to_ancestors->data)
9275 from_ancestors = g_list_delete_link (from_ancestors,
9277 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9280 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9281 device, mode, GDK_NOTIFY_NONLINEAR);
9283 for (list = g_list_last (from_ancestors); list; list = list->prev)
9285 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9286 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9288 for (list = to_ancestors; list; list = list->next)
9290 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9291 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9293 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9294 device, mode, GDK_NOTIFY_NONLINEAR);
9296 g_list_free (from_ancestors);
9297 g_list_free (to_ancestors);
9302 gtk_widget_propagate_state (GtkWidget *widget,
9305 guint8 old_state = gtk_widget_get_state (widget);
9306 guint8 old_saved_state = widget->saved_state;
9308 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9309 * parent_sensitive==TRUE on a sensitive widget
9313 if (data->parent_sensitive)
9314 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9316 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9318 if (gtk_widget_is_sensitive (widget))
9320 if (data->state_restoration)
9321 widget->state = widget->saved_state;
9323 widget->state = data->state;
9327 if (!data->state_restoration)
9329 if (data->state != GTK_STATE_INSENSITIVE)
9330 widget->saved_state = data->state;
9332 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9333 widget->saved_state = gtk_widget_get_state (widget);
9334 widget->state = GTK_STATE_INSENSITIVE;
9337 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9341 window = gtk_widget_get_toplevel (widget);
9342 if (window && gtk_widget_is_toplevel (window))
9343 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9346 if (old_state != gtk_widget_get_state (widget) ||
9347 old_saved_state != widget->saved_state)
9349 g_object_ref (widget);
9351 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9352 gtk_grab_remove (widget);
9354 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9356 if (!GTK_WIDGET_SHADOWED (widget))
9358 GList *event_windows = NULL;
9361 devices = _gtk_widget_list_devices (widget);
9363 for (d = devices; d; d = d->next)
9369 window = _gtk_widget_get_device_window (widget, device);
9371 /* Do not propagate more than once to the
9372 * same window if non-multidevice aware.
9374 if (!gdk_window_get_support_multidevice (window) &&
9375 g_list_find (event_windows, window))
9378 if (!gtk_widget_is_sensitive (widget))
9379 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9380 GDK_CROSSING_STATE_CHANGED);
9381 else if (old_state == GTK_STATE_INSENSITIVE)
9382 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9383 GDK_CROSSING_STATE_CHANGED);
9385 event_windows = g_list_prepend (event_windows, window);
9388 g_list_free (event_windows);
9389 g_list_free (devices);
9392 if (GTK_IS_CONTAINER (widget))
9394 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9395 if (data->use_forall)
9396 gtk_container_forall (GTK_CONTAINER (widget),
9397 (GtkCallback) gtk_widget_propagate_state,
9400 gtk_container_foreach (GTK_CONTAINER (widget),
9401 (GtkCallback) gtk_widget_propagate_state,
9404 g_object_unref (widget);
9409 * _gtk_widget_get_aux_info:
9410 * @widget: a #GtkWidget
9411 * @create: if %TRUE, create the structure if it doesn't exist
9413 * Get the #GtkWidgetAuxInfo structure for the widget.
9415 * Return value: the #GtkAuxInfo structure for the widget, or
9416 * %NULL if @create is %FALSE and one doesn't already exist.
9419 _gtk_widget_get_aux_info (GtkWidget *widget,
9422 GtkWidgetAuxInfo *aux_info;
9424 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9425 if (!aux_info && create)
9427 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9429 aux_info->width = -1;
9430 aux_info->height = -1;
9432 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9439 /*****************************************
9440 * gtk_widget_aux_info_destroy:
9445 *****************************************/
9448 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9450 g_slice_free (GtkWidgetAuxInfo, aux_info);
9454 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9456 g_object_unref (info->shape_mask);
9457 g_slice_free (GtkWidgetShapeInfo, info);
9461 * gtk_widget_shape_combine_mask:
9462 * @widget: a #GtkWidget
9463 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9464 * @offset_x: X position of shape mask with respect to @window
9465 * @offset_y: Y position of shape mask with respect to @window
9467 * Sets a shape for this widget's GDK window. This allows for
9468 * transparent windows etc., see gdk_window_shape_combine_mask()
9469 * for more information.
9472 gtk_widget_shape_combine_mask (GtkWidget *widget,
9473 GdkBitmap *shape_mask,
9477 GtkWidgetShapeInfo* shape_info;
9479 g_return_if_fail (GTK_IS_WIDGET (widget));
9480 /* set_shape doesn't work on widgets without gdk window */
9481 g_return_if_fail (gtk_widget_get_has_window (widget));
9485 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9488 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9490 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9494 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9496 shape_info = g_slice_new (GtkWidgetShapeInfo);
9497 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9498 (GDestroyNotify) gtk_widget_shape_info_destroy);
9500 shape_info->shape_mask = g_object_ref (shape_mask);
9501 shape_info->offset_x = offset_x;
9502 shape_info->offset_y = offset_y;
9504 /* set shape if widget has a gdk window already.
9505 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9508 gdk_window_shape_combine_mask (widget->window, shape_mask,
9509 offset_x, offset_y);
9514 * gtk_widget_input_shape_combine_mask:
9515 * @widget: a #GtkWidget
9516 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9517 * @offset_x: X position of shape mask with respect to @window
9518 * @offset_y: Y position of shape mask with respect to @window
9520 * Sets an input shape for this widget's GDK window. This allows for
9521 * windows which react to mouse click in a nonrectangular region, see
9522 * gdk_window_input_shape_combine_mask() for more information.
9527 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9528 GdkBitmap *shape_mask,
9532 GtkWidgetShapeInfo* shape_info;
9534 g_return_if_fail (GTK_IS_WIDGET (widget));
9535 /* set_shape doesn't work on widgets without gdk window */
9536 g_return_if_fail (gtk_widget_get_has_window (widget));
9541 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9543 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9547 shape_info = g_slice_new (GtkWidgetShapeInfo);
9548 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9550 (GDestroyNotify) gtk_widget_shape_info_destroy);
9552 shape_info->shape_mask = g_object_ref (shape_mask);
9553 shape_info->offset_x = offset_x;
9554 shape_info->offset_y = offset_y;
9556 /* set shape if widget has a gdk window already.
9557 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9560 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9561 offset_x, offset_y);
9567 gtk_reset_shapes_recurse (GtkWidget *widget,
9573 gdk_window_get_user_data (window, &data);
9577 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9578 for (list = gdk_window_peek_children (window); list; list = list->next)
9579 gtk_reset_shapes_recurse (widget, list->data);
9583 * gtk_widget_reset_shapes:
9584 * @widget: a #GtkWidget
9586 * Recursively resets the shape on this widget and its descendants.
9589 gtk_widget_reset_shapes (GtkWidget *widget)
9591 g_return_if_fail (GTK_IS_WIDGET (widget));
9592 g_return_if_fail (gtk_widget_get_realized (widget));
9594 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9595 gtk_reset_shapes_recurse (widget, widget->window);
9599 expose_window (GdkWindow *window)
9602 GList *l, *children;
9604 gboolean is_double_buffered;
9606 gdk_window_get_user_data (window, &user_data);
9609 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9611 is_double_buffered = FALSE;
9613 event.expose.type = GDK_EXPOSE;
9614 event.expose.window = g_object_ref (window);
9615 event.expose.send_event = FALSE;
9616 event.expose.count = 0;
9617 event.expose.area.x = 0;
9618 event.expose.area.y = 0;
9619 gdk_drawable_get_size (GDK_DRAWABLE (window),
9620 &event.expose.area.width,
9621 &event.expose.area.height);
9622 event.expose.region = gdk_region_rectangle (&event.expose.area);
9624 /* If this is not double buffered, force a double buffer so that
9625 redirection works. */
9626 if (!is_double_buffered)
9627 gdk_window_begin_paint_region (window, event.expose.region);
9629 gtk_main_do_event (&event);
9631 if (!is_double_buffered)
9632 gdk_window_end_paint (window);
9634 children = gdk_window_peek_children (window);
9635 for (l = children; l != NULL; l = l->next)
9637 GdkWindow *child = l->data;
9639 /* Don't expose input-only windows */
9640 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9641 expose_window (l->data);
9644 g_object_unref (window);
9648 * gtk_widget_get_snapshot:
9649 * @widget: a #GtkWidget
9650 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9652 * Create a #GdkPixmap of the contents of the widget and its children.
9654 * Works even if the widget is obscured. The depth and visual of the
9655 * resulting pixmap is dependent on the widget being snapshot and likely
9656 * differs from those of a target widget displaying the pixmap.
9657 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9658 * the pixmap to a visual independant representation.
9660 * The snapshot area used by this function is the @widget's allocation plus
9661 * any extra space occupied by additional windows belonging to this widget
9662 * (such as the arrows of a spin button).
9663 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9665 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9666 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9667 * interpreted widget relative. If width or height of @clip_rect are 0 or
9668 * negative, the width or height of the resulting pixmap will be shrunken
9669 * by the respective amount.
9670 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9671 * chop off 5 pixels at each side of the snapshot pixmap.
9672 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9673 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9674 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9675 * as a pure output parameter.
9677 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9679 * Return value: #GdkPixmap snapshot of the widget
9684 gtk_widget_get_snapshot (GtkWidget *widget,
9685 GdkRectangle *clip_rect)
9687 int x, y, width, height;
9688 GdkWindow *parent_window = NULL;
9690 GList *windows = NULL, *list;
9692 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9693 if (!gtk_widget_get_visible (widget))
9696 /* the widget (and parent_window) must be realized to be drawable */
9697 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9698 gtk_widget_realize (widget->parent);
9699 if (!gtk_widget_get_realized (widget))
9700 gtk_widget_realize (widget);
9702 /* determine snapshot rectangle */
9703 x = widget->allocation.x;
9704 y = widget->allocation.y;
9705 width = widget->allocation.width;
9706 height = widget->allocation.height;
9708 if (widget->parent && gtk_widget_get_has_window (widget))
9710 /* grow snapshot rectangle to cover all widget windows */
9711 parent_window = gtk_widget_get_parent_window (widget);
9712 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9714 GdkWindow *subwin = list->data;
9717 gdk_window_get_user_data (subwin, &windata);
9718 if (windata != widget)
9720 windows = g_list_prepend (windows, subwin);
9721 gdk_window_get_position (subwin, &wx, &wy);
9722 gdk_drawable_get_size (subwin, &ww, &wh);
9723 /* grow snapshot rectangle by extra widget sub window */
9734 if (x + width < wx + ww)
9735 width += wx + ww - (x + width);
9736 if (y + height < wy + wh)
9737 height += wy + wh - (y + height);
9740 else if (!widget->parent)
9741 x = y = 0; /* toplevel */
9743 /* at this point, (x,y,width,height) is the parent_window relative
9744 * snapshot area covering all of widget's windows.
9747 /* shrink snapshot size by clip_rectangle */
9750 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9751 clip.x = clip.x < 0 ? x : clip.x;
9752 clip.y = clip.y < 0 ? y : clip.y;
9753 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9754 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9757 /* offset clip_rect, so it's parent_window relative */
9758 if (clip_rect->x >= 0)
9759 clip.x += widget->allocation.x;
9760 if (clip_rect->y >= 0)
9761 clip.y += widget->allocation.y;
9763 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9765 g_list_free (windows);
9766 clip_rect->width = clip_rect->height = 0;
9767 return NULL; /* empty snapshot area */
9772 height = snap.height;
9775 /* render snapshot */
9776 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9777 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9779 GdkWindow *subwin = list->data;
9781 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9782 continue; /* Input only window */
9783 gdk_window_get_position (subwin, &wx, &wy);
9784 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9785 MAX (0, wx - x), MAX (0, wy - y), width, height);
9787 expose_window (subwin);
9789 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9791 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9792 expose_window (widget->window);
9794 for (list = windows; list; list = list->next)
9795 gdk_window_remove_redirection (list->data);
9796 if (!windows) /* NO_WINDOW || toplevel */
9797 gdk_window_remove_redirection (widget->window);
9798 g_list_free (windows);
9800 /* return pixmap and snapshot rectangle coordinates */
9805 clip_rect->width = width;
9806 clip_rect->height = height;
9809 /* offset clip_rect from parent_window so it's widget relative */
9810 clip_rect->x -= widget->allocation.x;
9811 clip_rect->y -= widget->allocation.y;
9814 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9815 G_OBJECT_TYPE_NAME (widget),
9816 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9825 * gtk_widget_class_install_style_property_parser:
9826 * @klass: a #GtkWidgetClass
9827 * @pspec: the #GParamSpec for the style property
9828 * @parser: the parser for the style property
9830 * Installs a style property on a widget class.
9833 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9835 GtkRcPropertyParser parser)
9837 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9838 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9839 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9840 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9842 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9844 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9845 G_OBJECT_CLASS_NAME (klass),
9850 g_param_spec_ref_sink (pspec);
9851 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9852 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9856 * gtk_widget_class_install_style_property:
9857 * @klass: a #GtkWidgetClass
9858 * @pspec: the #GParamSpec for the property
9860 * Installs a style property on a widget class. The parser for the
9861 * style property is determined by the value type of @pspec.
9864 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9867 GtkRcPropertyParser parser;
9869 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9870 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9872 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9874 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9878 * gtk_widget_class_find_style_property:
9879 * @klass: a #GtkWidgetClass
9880 * @property_name: the name of the style property to find
9881 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9882 * style property with that name.
9884 * Finds a style property of a widget class by name.
9889 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9890 const gchar *property_name)
9892 g_return_val_if_fail (property_name != NULL, NULL);
9894 return g_param_spec_pool_lookup (style_property_spec_pool,
9896 G_OBJECT_CLASS_TYPE (klass),
9901 * gtk_widget_class_list_style_properties:
9902 * @klass: a #GtkWidgetClass
9903 * @n_properties: location to return the number of style properties found
9904 * @returns: an newly allocated array of #GParamSpec*. The array must
9905 * be freed with g_free().
9907 * Returns all style properties of a widget class.
9912 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9913 guint *n_properties)
9915 GParamSpec **pspecs;
9918 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9919 G_OBJECT_CLASS_TYPE (klass),
9928 * gtk_widget_style_get_property:
9929 * @widget: a #GtkWidget
9930 * @property_name: the name of a style property
9931 * @value: location to return the property value
9933 * Gets the value of a style property of @widget.
9936 gtk_widget_style_get_property (GtkWidget *widget,
9937 const gchar *property_name,
9942 g_return_if_fail (GTK_IS_WIDGET (widget));
9943 g_return_if_fail (property_name != NULL);
9944 g_return_if_fail (G_IS_VALUE (value));
9946 g_object_ref (widget);
9947 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9949 G_OBJECT_TYPE (widget),
9952 g_warning ("%s: widget class `%s' has no property named `%s'",
9954 G_OBJECT_TYPE_NAME (widget),
9958 const GValue *peek_value;
9960 peek_value = _gtk_style_peek_property_value (widget->style,
9961 G_OBJECT_TYPE (widget),
9963 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9965 /* auto-conversion of the caller's value type
9967 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9968 g_value_copy (peek_value, value);
9969 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9970 g_value_transform (peek_value, value);
9972 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9974 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9975 G_VALUE_TYPE_NAME (value));
9977 g_object_unref (widget);
9981 * gtk_widget_style_get_valist:
9982 * @widget: a #GtkWidget
9983 * @first_property_name: the name of the first property to get
9984 * @var_args: a <type>va_list</type> of pairs of property names and
9985 * locations to return the property values, starting with the location
9986 * for @first_property_name.
9988 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9992 gtk_widget_style_get_valist (GtkWidget *widget,
9993 const gchar *first_property_name,
9998 g_return_if_fail (GTK_IS_WIDGET (widget));
10000 g_object_ref (widget);
10002 name = first_property_name;
10005 const GValue *peek_value;
10009 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10011 G_OBJECT_TYPE (widget),
10015 g_warning ("%s: widget class `%s' has no property named `%s'",
10017 G_OBJECT_TYPE_NAME (widget),
10021 /* style pspecs are always readable so we can spare that check here */
10023 peek_value = _gtk_style_peek_property_value (widget->style,
10024 G_OBJECT_TYPE (widget),
10026 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10027 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10030 g_warning ("%s: %s", G_STRLOC, error);
10035 name = va_arg (var_args, gchar*);
10038 g_object_unref (widget);
10042 * gtk_widget_style_get:
10043 * @widget: a #GtkWidget
10044 * @first_property_name: the name of the first property to get
10045 * @Varargs: pairs of property names and locations to
10046 * return the property values, starting with the location for
10047 * @first_property_name, terminated by %NULL.
10049 * Gets the values of a multiple style properties of @widget.
10052 gtk_widget_style_get (GtkWidget *widget,
10053 const gchar *first_property_name,
10058 g_return_if_fail (GTK_IS_WIDGET (widget));
10060 va_start (var_args, first_property_name);
10061 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10067 * @widget: a #GtkWidget
10068 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10069 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10070 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10072 * Obtains the full path to @widget. The path is simply the name of a
10073 * widget and all its parents in the container hierarchy, separated by
10074 * periods. The name of a widget comes from
10075 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10076 * in gtkrc configuration files. Widget names are the type of the
10077 * widget by default (e.g. "GtkButton") or can be set to an
10078 * application-specific value with gtk_widget_set_name(). By setting
10079 * the name of a widget, you allow users or theme authors to apply
10080 * styles to that specific widget in their gtkrc
10081 * file. @path_reversed_p fills in the path in reverse order,
10082 * i.e. starting with @widget's name instead of starting with the name
10083 * of @widget's outermost ancestor.
10086 gtk_widget_path (GtkWidget *widget,
10087 guint *path_length,
10089 gchar **path_reversed)
10091 static gchar *rev_path = NULL;
10092 static guint tmp_path_len = 0;
10095 g_return_if_fail (GTK_IS_WIDGET (widget));
10100 const gchar *string;
10105 string = gtk_widget_get_name (widget);
10106 l = strlen (string);
10107 while (tmp_path_len <= len + l + 1)
10109 tmp_path_len += INIT_PATH_SIZE;
10110 rev_path = g_realloc (rev_path, tmp_path_len);
10112 s = string + l - 1;
10113 d = rev_path + len;
10114 while (s >= string)
10118 widget = widget->parent;
10121 rev_path[len++] = '.';
10123 rev_path[len++] = 0;
10128 *path_length = len - 1;
10130 *path_reversed = g_strdup (rev_path);
10133 *path = g_strdup (rev_path);
10134 g_strreverse (*path);
10139 * gtk_widget_class_path:
10140 * @widget: a #GtkWidget
10141 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10142 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10143 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10146 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10147 * never uses a custom name set with gtk_widget_set_name().
10151 gtk_widget_class_path (GtkWidget *widget,
10152 guint *path_length,
10154 gchar **path_reversed)
10156 static gchar *rev_path = NULL;
10157 static guint tmp_path_len = 0;
10160 g_return_if_fail (GTK_IS_WIDGET (widget));
10165 const gchar *string;
10170 string = g_type_name (G_OBJECT_TYPE (widget));
10171 l = strlen (string);
10172 while (tmp_path_len <= len + l + 1)
10174 tmp_path_len += INIT_PATH_SIZE;
10175 rev_path = g_realloc (rev_path, tmp_path_len);
10177 s = string + l - 1;
10178 d = rev_path + len;
10179 while (s >= string)
10183 widget = widget->parent;
10186 rev_path[len++] = '.';
10188 rev_path[len++] = 0;
10193 *path_length = len - 1;
10195 *path_reversed = g_strdup (rev_path);
10198 *path = g_strdup (rev_path);
10199 g_strreverse (*path);
10204 * gtk_requisition_copy:
10205 * @requisition: a #GtkRequisition
10207 * Copies a #GtkRequisition.
10209 * Returns: a copy of @requisition
10212 gtk_requisition_copy (const GtkRequisition *requisition)
10214 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10218 * gtk_requisition_free:
10219 * @requisition: a #GtkRequisition
10221 * Frees a #GtkRequisition.
10224 gtk_requisition_free (GtkRequisition *requisition)
10226 g_free (requisition);
10230 gtk_requisition_get_type (void)
10232 static GType our_type = 0;
10235 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10236 (GBoxedCopyFunc) gtk_requisition_copy,
10237 (GBoxedFreeFunc) gtk_requisition_free);
10243 * gtk_widget_get_accessible:
10244 * @widget: a #GtkWidget
10246 * Returns the accessible object that describes the widget to an
10247 * assistive technology.
10249 * If no accessibility library is loaded (i.e. no ATK implementation library is
10250 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10251 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10252 * if no class-specific #AtkObject implementation is available for the widget
10253 * instance in question, it will inherit an #AtkObject implementation from the
10254 * first ancestor class for which such an implementation is defined.
10256 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10257 * library contains more information about accessible objects and their uses.
10259 * Returns: (transfer none): the #AtkObject associated with @widget
10262 gtk_widget_get_accessible (GtkWidget *widget)
10264 GtkWidgetClass *klass;
10266 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10268 klass = GTK_WIDGET_GET_CLASS (widget);
10270 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10272 return klass->get_accessible (widget);
10276 gtk_widget_real_get_accessible (GtkWidget *widget)
10278 AtkObject* accessible;
10280 accessible = g_object_get_qdata (G_OBJECT (widget),
10281 quark_accessible_object);
10284 AtkObjectFactory *factory;
10285 AtkRegistry *default_registry;
10287 default_registry = atk_get_default_registry ();
10288 factory = atk_registry_get_factory (default_registry,
10289 G_TYPE_FROM_INSTANCE (widget));
10291 atk_object_factory_create_accessible (factory,
10292 G_OBJECT (widget));
10293 g_object_set_qdata (G_OBJECT (widget),
10294 quark_accessible_object,
10301 * Initialize a AtkImplementorIface instance's virtual pointers as
10302 * appropriate to this implementor's class (GtkWidget).
10305 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10307 iface->ref_accessible = gtk_widget_ref_accessible;
10311 gtk_widget_ref_accessible (AtkImplementor *implementor)
10313 AtkObject *accessible;
10315 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10317 g_object_ref (accessible);
10322 * GtkBuildable implementation
10324 static GQuark quark_builder_has_default = 0;
10325 static GQuark quark_builder_has_focus = 0;
10326 static GQuark quark_builder_atk_relations = 0;
10327 static GQuark quark_builder_set_name = 0;
10330 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10332 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10333 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10334 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10335 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10337 iface->set_name = gtk_widget_buildable_set_name;
10338 iface->get_name = gtk_widget_buildable_get_name;
10339 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10340 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10341 iface->parser_finished = gtk_widget_buildable_parser_finished;
10342 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10343 iface->custom_finished = gtk_widget_buildable_custom_finished;
10347 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10350 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10351 g_strdup (name), g_free);
10354 static const gchar *
10355 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10357 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10361 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10362 GtkBuilder *builder,
10363 const gchar *childname)
10365 if (strcmp (childname, "accessible") == 0)
10366 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10372 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10373 GtkBuilder *builder,
10375 const GValue *value)
10377 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10378 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10379 GINT_TO_POINTER (TRUE));
10380 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10381 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10382 GINT_TO_POINTER (TRUE));
10384 g_object_set_property (G_OBJECT (buildable), name, value);
10389 gchar *action_name;
10390 GString *description;
10392 gboolean translatable;
10402 free_action (AtkActionData *data, gpointer user_data)
10404 g_free (data->action_name);
10405 g_string_free (data->description, TRUE);
10406 g_free (data->context);
10407 g_slice_free (AtkActionData, data);
10411 free_relation (AtkRelationData *data, gpointer user_data)
10413 g_free (data->target);
10414 g_free (data->type);
10415 g_slice_free (AtkRelationData, data);
10419 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10420 GtkBuilder *builder)
10422 GSList *atk_relations;
10424 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10425 gtk_widget_grab_default (GTK_WIDGET (buildable));
10426 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10427 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10429 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10430 quark_builder_atk_relations);
10433 AtkObject *accessible;
10434 AtkRelationSet *relation_set;
10437 AtkRelationType relation_type;
10438 AtkObject *target_accessible;
10440 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10441 relation_set = atk_object_ref_relation_set (accessible);
10443 for (l = atk_relations; l; l = l->next)
10445 AtkRelationData *relation = (AtkRelationData*)l->data;
10447 target = gtk_builder_get_object (builder, relation->target);
10450 g_warning ("Target object %s in <relation> does not exist",
10454 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10455 g_assert (target_accessible != NULL);
10457 relation_type = atk_relation_type_for_name (relation->type);
10458 if (relation_type == ATK_RELATION_NULL)
10460 g_warning ("<relation> type %s not found",
10464 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10465 target_accessible);
10467 g_object_unref (relation_set);
10469 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10470 g_slist_free (atk_relations);
10471 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10480 } AccessibilitySubParserData;
10483 accessibility_start_element (GMarkupParseContext *context,
10484 const gchar *element_name,
10485 const gchar **names,
10486 const gchar **values,
10487 gpointer user_data,
10490 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10492 gint line_number, char_number;
10494 if (strcmp (element_name, "relation") == 0)
10496 gchar *target = NULL;
10497 gchar *type = NULL;
10498 AtkRelationData *relation;
10500 for (i = 0; names[i]; i++)
10502 if (strcmp (names[i], "target") == 0)
10503 target = g_strdup (values[i]);
10504 else if (strcmp (names[i], "type") == 0)
10505 type = g_strdup (values[i]);
10508 g_markup_parse_context_get_position (context,
10511 g_set_error (error,
10513 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10514 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10516 line_number, char_number, names[i], "relation");
10523 if (!target || !type)
10525 g_markup_parse_context_get_position (context,
10528 g_set_error (error,
10530 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10531 "%s:%d:%d <%s> requires attribute \"%s\"",
10533 line_number, char_number, "relation",
10534 type ? "target" : "type");
10540 relation = g_slice_new (AtkRelationData);
10541 relation->target = target;
10542 relation->type = type;
10544 data->relations = g_slist_prepend (data->relations, relation);
10546 else if (strcmp (element_name, "action") == 0)
10548 const gchar *action_name = NULL;
10549 const gchar *description = NULL;
10550 const gchar *msg_context = NULL;
10551 gboolean translatable = FALSE;
10552 AtkActionData *action;
10554 for (i = 0; names[i]; i++)
10556 if (strcmp (names[i], "action_name") == 0)
10557 action_name = values[i];
10558 else if (strcmp (names[i], "description") == 0)
10559 description = values[i];
10560 else if (strcmp (names[i], "translatable") == 0)
10562 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10565 else if (strcmp (names[i], "comments") == 0)
10567 /* do nothing, comments are for translators */
10569 else if (strcmp (names[i], "context") == 0)
10570 msg_context = values[i];
10573 g_markup_parse_context_get_position (context,
10576 g_set_error (error,
10578 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10579 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10581 line_number, char_number, names[i], "action");
10588 g_markup_parse_context_get_position (context,
10591 g_set_error (error,
10593 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10594 "%s:%d:%d <%s> requires attribute \"%s\"",
10596 line_number, char_number, "action",
10601 action = g_slice_new (AtkActionData);
10602 action->action_name = g_strdup (action_name);
10603 action->description = g_string_new (description);
10604 action->context = g_strdup (msg_context);
10605 action->translatable = translatable;
10607 data->actions = g_slist_prepend (data->actions, action);
10609 else if (strcmp (element_name, "accessibility") == 0)
10612 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10616 accessibility_text (GMarkupParseContext *context,
10619 gpointer user_data,
10622 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10624 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10626 AtkActionData *action = data->actions->data;
10628 g_string_append_len (action->description, text, text_len);
10632 static const GMarkupParser accessibility_parser =
10634 accessibility_start_element,
10636 accessibility_text,
10645 } AccelGroupParserData;
10648 accel_group_start_element (GMarkupParseContext *context,
10649 const gchar *element_name,
10650 const gchar **names,
10651 const gchar **values,
10652 gpointer user_data,
10657 guint modifiers = 0;
10658 gchar *signal = NULL;
10659 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10661 for (i = 0; names[i]; i++)
10663 if (strcmp (names[i], "key") == 0)
10664 key = gdk_keyval_from_name (values[i]);
10665 else if (strcmp (names[i], "modifiers") == 0)
10667 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10673 else if (strcmp (names[i], "signal") == 0)
10674 signal = g_strdup (values[i]);
10677 if (key == 0 || signal == NULL)
10679 g_warning ("<accelerator> requires key and signal attributes");
10682 parser_data->key = key;
10683 parser_data->modifiers = modifiers;
10684 parser_data->signal = signal;
10687 static const GMarkupParser accel_group_parser =
10689 accel_group_start_element,
10693 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10694 GtkBuilder *builder,
10696 const gchar *tagname,
10697 GMarkupParser *parser,
10700 g_assert (buildable);
10702 if (strcmp (tagname, "accelerator") == 0)
10704 AccelGroupParserData *parser_data;
10706 parser_data = g_slice_new0 (AccelGroupParserData);
10707 parser_data->object = g_object_ref (buildable);
10708 *parser = accel_group_parser;
10709 *data = parser_data;
10712 if (strcmp (tagname, "accessibility") == 0)
10714 AccessibilitySubParserData *parser_data;
10716 parser_data = g_slice_new0 (AccessibilitySubParserData);
10717 *parser = accessibility_parser;
10718 *data = parser_data;
10725 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10726 GtkWidget *toplevel,
10727 gpointer user_data)
10729 AccelGroupParserData *accel_data;
10730 GSList *accel_groups;
10731 GtkAccelGroup *accel_group;
10733 g_return_if_fail (GTK_IS_WIDGET (widget));
10734 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10735 g_return_if_fail (user_data != NULL);
10737 accel_data = (AccelGroupParserData*)user_data;
10738 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10739 if (g_slist_length (accel_groups) == 0)
10741 accel_group = gtk_accel_group_new ();
10742 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10746 g_assert (g_slist_length (accel_groups) == 1);
10747 accel_group = g_slist_nth_data (accel_groups, 0);
10750 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10751 accel_data->signal,
10754 accel_data->modifiers,
10755 GTK_ACCEL_VISIBLE);
10757 g_object_unref (accel_data->object);
10758 g_free (accel_data->signal);
10759 g_slice_free (AccelGroupParserData, accel_data);
10763 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10764 GtkBuilder *builder,
10766 const gchar *tagname,
10767 gpointer user_data)
10769 AccelGroupParserData *accel_data;
10770 AccessibilitySubParserData *a11y_data;
10771 GtkWidget *toplevel;
10773 if (strcmp (tagname, "accelerator") == 0)
10775 accel_data = (AccelGroupParserData*)user_data;
10776 g_assert (accel_data->object);
10778 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10780 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10782 else if (strcmp (tagname, "accessibility") == 0)
10784 a11y_data = (AccessibilitySubParserData*)user_data;
10786 if (a11y_data->actions)
10788 AtkObject *accessible;
10793 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10795 action = ATK_ACTION (accessible);
10796 n_actions = atk_action_get_n_actions (action);
10798 for (l = a11y_data->actions; l; l = l->next)
10800 AtkActionData *action_data = (AtkActionData*)l->data;
10802 for (i = 0; i < n_actions; i++)
10803 if (strcmp (atk_action_get_name (action, i),
10804 action_data->action_name) == 0)
10809 gchar *description;
10811 if (action_data->translatable && action_data->description->len)
10812 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10813 action_data->context,
10814 action_data->description->str);
10816 description = action_data->description->str;
10818 atk_action_set_description (action, i, description);
10822 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10823 g_slist_free (a11y_data->actions);
10826 if (a11y_data->relations)
10827 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10828 a11y_data->relations);
10830 g_slice_free (AccessibilitySubParserData, a11y_data);
10835 * GtkExtendedLayout implementation
10838 gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
10839 gint *minimum_size,
10840 gint *natural_size)
10842 /* Set the initial values so that unimplemented classes will fall back
10843 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10846 *minimum_size = GTK_WIDGET (layout)->requisition.width;
10849 *natural_size = GTK_WIDGET (layout)->requisition.width;
10853 gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
10854 gint *minimum_size,
10855 gint *natural_size)
10857 /* Set the initial values so that unimplemented classes will fall back
10858 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10861 *minimum_size = GTK_WIDGET (layout)->requisition.height;
10864 *natural_size = GTK_WIDGET (layout)->requisition.height;
10868 gtk_widget_real_get_height_for_width (GtkExtendedLayout *layout,
10870 gint *minimum_height,
10871 gint *natural_height)
10873 gtk_extended_layout_get_desired_height (layout, minimum_height, natural_height);
10877 gtk_widget_real_get_width_for_height (GtkExtendedLayout *layout,
10879 gint *minimum_width,
10880 gint *natural_width)
10882 gtk_extended_layout_get_desired_width (layout, minimum_width, natural_width);
10886 gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface)
10888 iface->get_desired_width = gtk_widget_real_get_desired_width;
10889 iface->get_desired_height = gtk_widget_real_get_desired_height;
10890 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
10891 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
10896 * gtk_widget_get_clipboard:
10897 * @widget: a #GtkWidget
10898 * @selection: a #GdkAtom which identifies the clipboard
10899 * to use. %GDK_SELECTION_CLIPBOARD gives the
10900 * default clipboard. Another common value
10901 * is %GDK_SELECTION_PRIMARY, which gives
10902 * the primary X selection.
10904 * Returns the clipboard object for the given selection to
10905 * be used with @widget. @widget must have a #GdkDisplay
10906 * associated with it, so must be attached to a toplevel
10909 * Return value: (transfer none): the appropriate clipboard object. If no
10910 * clipboard already exists, a new one will
10911 * be created. Once a clipboard object has
10912 * been created, it is persistent for all time.
10917 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10920 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10922 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10927 * gtk_widget_list_mnemonic_labels:
10928 * @widget: a #GtkWidget
10930 * Returns a newly allocated list of the widgets, normally labels, for
10931 * which this widget is a the target of a mnemonic (see for example,
10932 * gtk_label_set_mnemonic_widget()).
10934 * The widgets in the list are not individually referenced. If you
10935 * want to iterate through the list and perform actions involving
10936 * callbacks that might destroy the widgets, you
10937 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10938 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10939 * widgets afterwards.
10941 * Return value: (element-type GtkWidget) (transfer container): the list of
10942 * mnemonic labels; free this list
10943 * with g_list_free() when you are done with it.
10948 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10950 GList *list = NULL;
10953 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10955 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10956 list = g_list_prepend (list, l->data);
10962 * gtk_widget_add_mnemonic_label:
10963 * @widget: a #GtkWidget
10964 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10966 * Adds a widget to the list of mnemonic labels for
10967 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10968 * list of mnemonic labels for the widget is cleared when the
10969 * widget is destroyed, so the caller must make sure to update
10970 * its internal state at this point as well, by using a connection
10971 * to the #GtkWidget::destroy signal or a weak notifier.
10976 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10979 GSList *old_list, *new_list;
10981 g_return_if_fail (GTK_IS_WIDGET (widget));
10982 g_return_if_fail (GTK_IS_WIDGET (label));
10984 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10985 new_list = g_slist_prepend (old_list, label);
10987 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10988 new_list, (GDestroyNotify) g_slist_free);
10992 * gtk_widget_remove_mnemonic_label:
10993 * @widget: a #GtkWidget
10994 * @label: a #GtkWidget that was previously set as a mnemnic label for
10995 * @widget with gtk_widget_add_mnemonic_label().
10997 * Removes a widget from the list of mnemonic labels for
10998 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10999 * must have previously been added to the list with
11000 * gtk_widget_add_mnemonic_label().
11005 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11008 GSList *old_list, *new_list;
11010 g_return_if_fail (GTK_IS_WIDGET (widget));
11011 g_return_if_fail (GTK_IS_WIDGET (label));
11013 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11014 new_list = g_slist_remove (old_list, label);
11017 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11018 new_list, (GDestroyNotify) g_slist_free);
11022 * gtk_widget_get_no_show_all:
11023 * @widget: a #GtkWidget
11025 * Returns the current value of the GtkWidget:no-show-all property,
11026 * which determines whether calls to gtk_widget_show_all() and
11027 * gtk_widget_hide_all() will affect this widget.
11029 * Return value: the current value of the "no-show-all" property.
11034 gtk_widget_get_no_show_all (GtkWidget *widget)
11036 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11038 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11042 * gtk_widget_set_no_show_all:
11043 * @widget: a #GtkWidget
11044 * @no_show_all: the new value for the "no-show-all" property
11046 * Sets the #GtkWidget:no-show-all property, which determines whether
11047 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11050 * This is mostly for use in constructing widget hierarchies with externally
11051 * controlled visibility, see #GtkUIManager.
11056 gtk_widget_set_no_show_all (GtkWidget *widget,
11057 gboolean no_show_all)
11059 g_return_if_fail (GTK_IS_WIDGET (widget));
11061 no_show_all = (no_show_all != FALSE);
11063 if (no_show_all == gtk_widget_get_no_show_all (widget))
11067 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11069 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11071 g_object_notify (G_OBJECT (widget), "no-show-all");
11076 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11077 gboolean has_tooltip,
11080 gboolean priv_has_tooltip;
11082 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11083 quark_has_tooltip));
11085 if (priv_has_tooltip != has_tooltip || force)
11087 priv_has_tooltip = has_tooltip;
11089 if (priv_has_tooltip)
11091 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11092 gdk_window_set_events (widget->window,
11093 gdk_window_get_events (widget->window) |
11094 GDK_LEAVE_NOTIFY_MASK |
11095 GDK_POINTER_MOTION_MASK |
11096 GDK_POINTER_MOTION_HINT_MASK);
11098 if (gtk_widget_get_has_window (widget))
11099 gtk_widget_add_events (widget,
11100 GDK_LEAVE_NOTIFY_MASK |
11101 GDK_POINTER_MOTION_MASK |
11102 GDK_POINTER_MOTION_HINT_MASK);
11105 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11106 GUINT_TO_POINTER (priv_has_tooltip));
11111 * gtk_widget_set_tooltip_window:
11112 * @widget: a #GtkWidget
11113 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11115 * Replaces the default, usually yellow, window used for displaying
11116 * tooltips with @custom_window. GTK+ will take care of showing and
11117 * hiding @custom_window at the right moment, to behave likewise as
11118 * the default tooltip window. If @custom_window is %NULL, the default
11119 * tooltip window will be used.
11121 * If the custom window should have the default theming it needs to
11122 * have the name "gtk-tooltip", see gtk_widget_set_name().
11127 gtk_widget_set_tooltip_window (GtkWidget *widget,
11128 GtkWindow *custom_window)
11130 gboolean has_tooltip;
11131 gchar *tooltip_markup;
11133 g_return_if_fail (GTK_IS_WIDGET (widget));
11134 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11136 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11139 g_object_ref (custom_window);
11141 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11142 custom_window, g_object_unref);
11144 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11145 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11147 if (has_tooltip && gtk_widget_get_visible (widget))
11148 gtk_widget_queue_tooltip_query (widget);
11152 * gtk_widget_get_tooltip_window:
11153 * @widget: a #GtkWidget
11155 * Returns the #GtkWindow of the current tooltip. This can be the
11156 * GtkWindow created by default, or the custom tooltip window set
11157 * using gtk_widget_set_tooltip_window().
11159 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11164 gtk_widget_get_tooltip_window (GtkWidget *widget)
11166 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11168 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11172 * gtk_widget_trigger_tooltip_query:
11173 * @widget: a #GtkWidget
11175 * Triggers a tooltip query on the display where the toplevel of @widget
11176 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11182 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11184 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11187 static guint tooltip_query_id;
11188 static GSList *tooltip_query_displays;
11191 tooltip_query_idle (gpointer data)
11193 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11194 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11195 g_slist_free (tooltip_query_displays);
11197 tooltip_query_displays = NULL;
11198 tooltip_query_id = 0;
11204 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11206 GdkDisplay *display;
11208 display = gtk_widget_get_display (widget);
11210 if (!g_slist_find (tooltip_query_displays, display))
11211 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11213 if (tooltip_query_id == 0)
11214 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11218 * gtk_widget_set_tooltip_text:
11219 * @widget: a #GtkWidget
11220 * @text: the contents of the tooltip for @widget
11222 * Sets @text as the contents of the tooltip. This function will take
11223 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11224 * handler for the GtkWidget::query-tooltip signal.
11226 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11231 gtk_widget_set_tooltip_text (GtkWidget *widget,
11234 g_return_if_fail (GTK_IS_WIDGET (widget));
11236 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11240 * gtk_widget_get_tooltip_text:
11241 * @widget: a #GtkWidget
11243 * Gets the contents of the tooltip for @widget.
11245 * Return value: the tooltip text, or %NULL. You should free the
11246 * returned string with g_free() when done.
11251 gtk_widget_get_tooltip_text (GtkWidget *widget)
11253 gchar *text = NULL;
11255 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11257 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11263 * gtk_widget_set_tooltip_markup:
11264 * @widget: a #GtkWidget
11265 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11267 * Sets @markup as the contents of the tooltip, which is marked up with
11268 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11270 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11271 * and of the default handler for the GtkWidget::query-tooltip signal.
11273 * See also the GtkWidget:tooltip-markup property and
11274 * gtk_tooltip_set_markup().
11279 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11280 const gchar *markup)
11282 g_return_if_fail (GTK_IS_WIDGET (widget));
11284 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11288 * gtk_widget_get_tooltip_markup:
11289 * @widget: a #GtkWidget
11291 * Gets the contents of the tooltip for @widget.
11293 * Return value: the tooltip text, or %NULL. You should free the
11294 * returned string with g_free() when done.
11299 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11301 gchar *text = NULL;
11303 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11305 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11311 * gtk_widget_set_has_tooltip:
11312 * @widget: a #GtkWidget
11313 * @has_tooltip: whether or not @widget has a tooltip.
11315 * Sets the has-tooltip property on @widget to @has_tooltip. See
11316 * GtkWidget:has-tooltip for more information.
11321 gtk_widget_set_has_tooltip (GtkWidget *widget,
11322 gboolean has_tooltip)
11324 g_return_if_fail (GTK_IS_WIDGET (widget));
11326 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11330 * gtk_widget_get_has_tooltip:
11331 * @widget: a #GtkWidget
11333 * Returns the current value of the has-tooltip property. See
11334 * GtkWidget:has-tooltip for more information.
11336 * Return value: current value of has-tooltip on @widget.
11341 gtk_widget_get_has_tooltip (GtkWidget *widget)
11343 gboolean has_tooltip = FALSE;
11345 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11347 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11349 return has_tooltip;
11353 * gtk_widget_get_allocation:
11354 * @widget: a #GtkWidget
11355 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11357 * Retrieves the widget's allocation.
11362 gtk_widget_get_allocation (GtkWidget *widget,
11363 GtkAllocation *allocation)
11365 g_return_if_fail (GTK_IS_WIDGET (widget));
11366 g_return_if_fail (allocation != NULL);
11368 *allocation = widget->allocation;
11372 * gtk_widget_set_allocation:
11373 * @widget: a #GtkWidget
11374 * @allocation: a pointer to a #GtkAllocation to copy from
11376 * Sets the widget's allocation. This should not be used
11377 * directly, but from within a widget's size_allocate method.
11382 gtk_widget_set_allocation (GtkWidget *widget,
11383 const GtkAllocation *allocation)
11385 g_return_if_fail (GTK_IS_WIDGET (widget));
11386 g_return_if_fail (allocation != NULL);
11388 widget->allocation = *allocation;
11392 * gtk_widget_get_requisition:
11393 * @widget: a #GtkWidget
11394 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11396 * Retrieves the widget's requisition.
11398 * This function should only be used by widget implementations in
11399 * order to figure whether the widget's requisition has actually
11400 * changed after some internal state change (so that they can call
11401 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11403 * Normally, gtk_widget_size_request() should be used.
11408 gtk_widget_get_requisition (GtkWidget *widget,
11409 GtkRequisition *requisition)
11411 g_return_if_fail (GTK_IS_WIDGET (widget));
11412 g_return_if_fail (requisition != NULL);
11414 *requisition = widget->requisition;
11418 * gtk_widget_set_window:
11419 * @widget: a #GtkWidget
11420 * @window: a #GdkWindow
11422 * Sets a widget's window. This function should only be used in a
11423 * widget's GtkWidget::realize() implementation. The %window passed is
11424 * usually either new window created with gdk_window_new(), or the
11425 * window of its parent widget as returned by
11426 * gtk_widget_get_parent_window().
11428 * Widgets must indicate whether they will create their own #GdkWindow
11429 * by calling gtk_widget_set_has_window(). This is usually done in the
11430 * widget's init() function.
11435 gtk_widget_set_window (GtkWidget *widget,
11438 g_return_if_fail (GTK_IS_WIDGET (widget));
11439 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11441 if (widget->window != window)
11443 widget->window = window;
11444 g_object_notify (G_OBJECT (widget), "window");
11449 * gtk_widget_get_window:
11450 * @widget: a #GtkWidget
11452 * Returns the widget's window if it is realized, %NULL otherwise
11454 * Return value: @widget's window.
11459 gtk_widget_get_window (GtkWidget *widget)
11461 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11463 return widget->window;
11467 * gtk_widget_get_support_multidevice:
11468 * @widget: a #GtkWidget
11470 * Returns %TRUE if @widget is multiple pointer aware. See
11471 * gtk_widget_set_support_multidevice() for more information.
11473 * Returns: %TRUE is @widget is multidevice aware.
11476 gtk_widget_get_support_multidevice (GtkWidget *widget)
11478 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11480 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
11484 * gtk_widget_set_support_multidevice:
11485 * @widget: a #GtkWidget
11486 * @support_multidevice: %TRUE to support input from multiple devices.
11488 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
11489 * @widget will start receiving multiple, per device enter/leave events. Note
11490 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
11491 * gdk_window_set_support_multidevice() will have to be called manually on them.
11496 gtk_widget_set_support_multidevice (GtkWidget *widget,
11497 gboolean support_multidevice)
11499 g_return_if_fail (GTK_IS_WIDGET (widget));
11501 if (support_multidevice)
11503 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
11504 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
11508 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
11509 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
11512 if (gtk_widget_get_realized (widget))
11513 gdk_window_set_support_multidevice (widget->window, support_multidevice);
11517 _gtk_widget_set_has_focus (GtkWidget *widget,
11518 gboolean has_focus)
11521 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
11523 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
11527 * gtk_widget_send_focus_change:
11528 * @widget: a #GtkWidget
11529 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
11531 * Sends the focus change @event to @widget
11533 * This function is not meant to be used by applications. The only time it
11534 * should be used is when it is necessary for a #GtkWidget to assign focus
11535 * to a widget that is semantically owned by the first widget even though
11536 * it's not a direct child - for instance, a search entry in a floating
11537 * window similar to the quick search in #GtkTreeView.
11539 * An example of its usage is:
11542 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
11544 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
11545 * fevent->focus_change.in = TRUE;
11546 * fevent->focus_change.window = gtk_widget_get_window (widget);
11547 * if (fevent->focus_change.window != NULL)
11548 * g_object_ref (fevent->focus_change.window);
11550 * gtk_widget_send_focus_change (widget, fevent);
11552 * gdk_event_free (event);
11555 * Return value: the return value from the event signal emission: %TRUE
11556 * if the event was handled, and %FALSE otherwise
11561 gtk_widget_send_focus_change (GtkWidget *widget,
11566 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11567 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
11569 g_object_ref (widget);
11571 _gtk_widget_set_has_focus (widget, event->focus_change.in);
11573 res = gtk_widget_event (widget, event);
11575 g_object_notify (G_OBJECT (widget), "has-focus");
11577 g_object_unref (widget);
11582 #define __GTK_WIDGET_C__
11583 #include "gtkaliasdef.c"