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.
66 * <refsect2 id="style-properties">
68 * <structname>GtkWidget</structname> introduces <firstterm>style
69 * properties</firstterm> - these are basically object properties that are stored
70 * not on the object, but in the style object associated to the widget. Style
71 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
72 * This mechanism is used for configuring such things as the location of the
73 * scrollbar arrows through the theme, giving theme authors more control over the
74 * look of applications without the need to write a theme engine in C.
77 * Use gtk_widget_class_install_style_property() to install style properties for
78 * a widget class, gtk_widget_class_find_style_property() or
79 * gtk_widget_class_list_style_properties() to get information about existing
80 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
81 * gtk_widget_style_get_valist() to obtain the value of a style property.
84 * <refsect2 id="GtkWidget-BUILDER-UI">
85 * <title>GtkWidget as GtkBuildable</title>
87 * The GtkWidget implementation of the GtkBuildable interface supports a
88 * custom <accelerator> element, which has attributes named key,
89 * modifiers and signal and allows to specify accelerators.
92 * <title>A UI definition fragment specifying an accelerator</title>
93 * <programlisting><![CDATA[
94 * <object class="GtkButton">
95 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
97 * ]]></programlisting>
100 * In addition to accelerators, <structname>GtkWidget</structname> also support a
101 * custom <accessible> element, which supports actions and relations.
102 * Properties on the accessible implementation of an object can be set by accessing the
103 * internal child "accessible" of a <structname>GtkWidget</structname>.
106 * <title>A UI definition fragment specifying an accessible</title>
107 * <programlisting><![CDATA[
108 * <object class="GtkButton" id="label1"/>
109 * <property name="label">I am a Label for a Button</property>
111 * <object class="GtkButton" id="button1">
113 * <action action_name="click" translatable="yes">Click the button.</action>
114 * <relation target="label1" type="labelled-by"/>
116 * <child internal-child="accessible">
117 * <object class="AtkObject" id="a11y-button1">
118 * <property name="AtkObject::name">Clickable Button</property>
122 * ]]></programlisting>
127 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
128 #define INIT_PATH_SIZE (512)
154 BUTTON_RELEASE_EVENT,
169 PROPERTY_NOTIFY_EVENT,
170 SELECTION_CLEAR_EVENT,
171 SELECTION_REQUEST_EVENT,
172 SELECTION_NOTIFY_EVENT,
187 VISIBILITY_NOTIFY_EVENT,
191 ACCEL_CLOSURES_CHANGED,
217 PROP_RECEIVES_DEFAULT,
218 PROP_COMPOSITE_CHILD,
221 PROP_EXTENSION_EVENTS,
230 typedef struct _GtkStateData GtkStateData;
235 guint state_restoration : 1;
236 guint parent_sensitive : 1;
237 guint use_forall : 1;
240 /* --- prototypes --- */
241 static void gtk_widget_class_init (GtkWidgetClass *klass);
242 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
243 static void gtk_widget_init (GtkWidget *widget);
244 static void gtk_widget_set_property (GObject *object,
248 static void gtk_widget_get_property (GObject *object,
252 static void gtk_widget_dispose (GObject *object);
253 static void gtk_widget_real_destroy (GtkObject *object);
254 static void gtk_widget_finalize (GObject *object);
255 static void gtk_widget_real_show (GtkWidget *widget);
256 static void gtk_widget_real_hide (GtkWidget *widget);
257 static void gtk_widget_real_map (GtkWidget *widget);
258 static void gtk_widget_real_unmap (GtkWidget *widget);
259 static void gtk_widget_real_realize (GtkWidget *widget);
260 static void gtk_widget_real_unrealize (GtkWidget *widget);
261 static void gtk_widget_real_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_widget_real_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_widget_real_style_set (GtkWidget *widget,
266 GtkStyle *previous_style);
267 static void gtk_widget_real_direction_changed(GtkWidget *widget,
268 GtkTextDirection previous_direction);
270 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
271 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
274 gboolean keyboard_tip,
275 GtkTooltip *tooltip);
276 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
277 GtkWidgetHelpType help_type);
279 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
281 GParamSpec **pspecs);
282 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
284 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
286 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
287 GdkEventFocus *event);
288 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
289 GdkEventFocus *event);
290 static gboolean gtk_widget_real_focus (GtkWidget *widget,
291 GtkDirectionType direction);
292 static void gtk_widget_real_move_focus (GtkWidget *widget,
293 GtkDirectionType direction);
294 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
295 GtkDirectionType direction);
296 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
297 static void gtk_widget_update_pango_context (GtkWidget *widget);
298 static void gtk_widget_propagate_state (GtkWidget *widget,
300 static void gtk_widget_reset_rc_style (GtkWidget *widget);
301 static void gtk_widget_set_style_internal (GtkWidget *widget,
303 gboolean initial_emission);
304 static gint gtk_widget_event_internal (GtkWidget *widget,
306 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
307 gboolean group_cycling);
308 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
309 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
310 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
311 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
312 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
314 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
315 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
316 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
319 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
320 gboolean has_tooltip,
322 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
323 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
325 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
326 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
328 const gchar *childname);
329 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
332 const GValue *value);
333 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
336 const gchar *tagname,
337 GMarkupParser *parser,
339 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
342 const gchar *tagname,
344 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
345 GtkBuilder *builder);
347 static void gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface);
348 static void gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
351 static void gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
355 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
357 static void gtk_widget_set_usize_internal (GtkWidget *widget,
360 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
364 /* --- variables --- */
365 static gpointer gtk_widget_parent_class = NULL;
366 static guint widget_signals[LAST_SIGNAL] = { 0 };
367 static GtkStyle *gtk_default_style = NULL;
368 static GSList *colormap_stack = NULL;
369 static guint composite_child_stack = 0;
370 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
371 static GParamSpecPool *style_property_spec_pool = NULL;
373 static GQuark quark_property_parser = 0;
374 static GQuark quark_aux_info = 0;
375 static GQuark quark_accel_path = 0;
376 static GQuark quark_accel_closures = 0;
377 static GQuark quark_event_mask = 0;
378 static GQuark quark_extension_event_mode = 0;
379 static GQuark quark_parent_window = 0;
380 static GQuark quark_pointer_window = 0;
381 static GQuark quark_shape_info = 0;
382 static GQuark quark_input_shape_info = 0;
383 static GQuark quark_colormap = 0;
384 static GQuark quark_pango_context = 0;
385 static GQuark quark_rc_style = 0;
386 static GQuark quark_accessible_object = 0;
387 static GQuark quark_mnemonic_labels = 0;
388 static GQuark quark_tooltip_markup = 0;
389 static GQuark quark_has_tooltip = 0;
390 static GQuark quark_tooltip_window = 0;
391 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
392 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
394 /* --- functions --- */
396 gtk_widget_get_type (void)
398 static GType widget_type = 0;
400 if (G_UNLIKELY (widget_type == 0))
402 const GTypeInfo widget_info =
404 sizeof (GtkWidgetClass),
405 NULL, /* base_init */
406 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
407 (GClassInitFunc) gtk_widget_class_init,
408 NULL, /* class_finalize */
409 NULL, /* class_init */
412 (GInstanceInitFunc) gtk_widget_init,
413 NULL, /* value_table */
416 const GInterfaceInfo accessibility_info =
418 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
419 (GInterfaceFinalizeFunc) NULL,
420 NULL /* interface data */
423 const GInterfaceInfo buildable_info =
425 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
426 (GInterfaceFinalizeFunc) NULL,
427 NULL /* interface data */
430 const GInterfaceInfo layout_info =
432 (GInterfaceInitFunc) gtk_widget_extended_layout_init,
433 (GInterfaceFinalizeFunc) NULL,
434 NULL /* interface data */
437 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
438 &widget_info, G_TYPE_FLAG_ABSTRACT);
440 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
441 &accessibility_info) ;
442 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
444 g_type_add_interface_static (widget_type, GTK_TYPE_EXTENDED_LAYOUT,
452 child_property_notify_dispatcher (GObject *object,
456 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
460 gtk_widget_class_init (GtkWidgetClass *klass)
462 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
463 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
464 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
465 GtkBindingSet *binding_set;
467 gtk_widget_parent_class = g_type_class_peek_parent (klass);
469 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
470 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
471 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
472 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
473 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
474 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
475 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
476 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
477 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
478 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
479 quark_colormap = g_quark_from_static_string ("gtk-colormap");
480 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
481 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
482 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
483 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
484 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
485 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
486 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
488 style_property_spec_pool = g_param_spec_pool_new (FALSE);
489 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
490 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
491 cpn_context.dispatcher = child_property_notify_dispatcher;
492 _gtk_widget_child_property_notify_context = &cpn_context;
494 gobject_class->dispose = gtk_widget_dispose;
495 gobject_class->finalize = gtk_widget_finalize;
496 gobject_class->set_property = gtk_widget_set_property;
497 gobject_class->get_property = gtk_widget_get_property;
499 object_class->destroy = gtk_widget_real_destroy;
501 klass->activate_signal = 0;
502 klass->set_scroll_adjustments_signal = 0;
503 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
504 klass->show = gtk_widget_real_show;
505 klass->show_all = gtk_widget_show;
506 klass->hide = gtk_widget_real_hide;
507 klass->hide_all = gtk_widget_hide;
508 klass->map = gtk_widget_real_map;
509 klass->unmap = gtk_widget_real_unmap;
510 klass->realize = gtk_widget_real_realize;
511 klass->unrealize = gtk_widget_real_unrealize;
512 klass->size_request = gtk_widget_real_size_request;
513 klass->size_allocate = gtk_widget_real_size_allocate;
514 klass->state_changed = NULL;
515 klass->parent_set = NULL;
516 klass->hierarchy_changed = NULL;
517 klass->style_set = gtk_widget_real_style_set;
518 klass->direction_changed = gtk_widget_real_direction_changed;
519 klass->grab_notify = NULL;
520 klass->child_notify = NULL;
521 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
522 klass->grab_focus = gtk_widget_real_grab_focus;
523 klass->focus = gtk_widget_real_focus;
525 klass->button_press_event = NULL;
526 klass->button_release_event = NULL;
527 klass->motion_notify_event = NULL;
528 klass->delete_event = NULL;
529 klass->destroy_event = NULL;
530 klass->expose_event = NULL;
531 klass->key_press_event = gtk_widget_real_key_press_event;
532 klass->key_release_event = gtk_widget_real_key_release_event;
533 klass->enter_notify_event = NULL;
534 klass->leave_notify_event = NULL;
535 klass->configure_event = NULL;
536 klass->focus_in_event = gtk_widget_real_focus_in_event;
537 klass->focus_out_event = gtk_widget_real_focus_out_event;
538 klass->map_event = NULL;
539 klass->unmap_event = NULL;
540 klass->window_state_event = NULL;
541 klass->property_notify_event = _gtk_selection_property_notify;
542 klass->selection_clear_event = gtk_selection_clear;
543 klass->selection_request_event = _gtk_selection_request;
544 klass->selection_notify_event = _gtk_selection_notify;
545 klass->selection_received = NULL;
546 klass->proximity_in_event = NULL;
547 klass->proximity_out_event = NULL;
548 klass->drag_begin = NULL;
549 klass->drag_end = NULL;
550 klass->drag_data_delete = NULL;
551 klass->drag_leave = NULL;
552 klass->drag_motion = NULL;
553 klass->drag_drop = NULL;
554 klass->drag_data_received = NULL;
555 klass->screen_changed = NULL;
556 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
557 klass->grab_broken_event = NULL;
558 klass->query_tooltip = gtk_widget_real_query_tooltip;
560 klass->show_help = gtk_widget_real_show_help;
562 /* Accessibility support */
563 klass->get_accessible = gtk_widget_real_get_accessible;
565 klass->no_expose_event = NULL;
567 g_object_class_install_property (gobject_class,
569 g_param_spec_string ("name",
571 P_("The name of the widget"),
573 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
576 g_param_spec_object ("parent",
578 P_("The parent widget of this widget. Must be a Container widget"),
580 GTK_PARAM_READWRITE));
582 g_object_class_install_property (gobject_class,
584 g_param_spec_int ("width-request",
586 P_("Override for width request of the widget, or -1 if natural request should be used"),
590 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_int ("height-request",
594 P_("Height request"),
595 P_("Override for height request of the widget, or -1 if natural request should be used"),
599 GTK_PARAM_READWRITE));
600 g_object_class_install_property (gobject_class,
602 g_param_spec_boolean ("visible",
604 P_("Whether the widget is visible"),
606 GTK_PARAM_READWRITE));
607 g_object_class_install_property (gobject_class,
609 g_param_spec_boolean ("sensitive",
611 P_("Whether the widget responds to input"),
613 GTK_PARAM_READWRITE));
614 g_object_class_install_property (gobject_class,
616 g_param_spec_boolean ("app-paintable",
617 P_("Application paintable"),
618 P_("Whether the application will paint directly on the widget"),
620 GTK_PARAM_READWRITE));
621 g_object_class_install_property (gobject_class,
623 g_param_spec_boolean ("can-focus",
625 P_("Whether the widget can accept the input focus"),
627 GTK_PARAM_READWRITE));
628 g_object_class_install_property (gobject_class,
630 g_param_spec_boolean ("has-focus",
632 P_("Whether the widget has the input focus"),
634 GTK_PARAM_READWRITE));
635 g_object_class_install_property (gobject_class,
637 g_param_spec_boolean ("is-focus",
639 P_("Whether the widget is the focus widget within the toplevel"),
641 GTK_PARAM_READWRITE));
642 g_object_class_install_property (gobject_class,
644 g_param_spec_boolean ("can-default",
646 P_("Whether the widget can be the default widget"),
648 GTK_PARAM_READWRITE));
649 g_object_class_install_property (gobject_class,
651 g_param_spec_boolean ("has-default",
653 P_("Whether the widget is the default widget"),
655 GTK_PARAM_READWRITE));
656 g_object_class_install_property (gobject_class,
657 PROP_RECEIVES_DEFAULT,
658 g_param_spec_boolean ("receives-default",
659 P_("Receives default"),
660 P_("If TRUE, the widget will receive the default action when it is focused"),
662 GTK_PARAM_READWRITE));
663 g_object_class_install_property (gobject_class,
664 PROP_COMPOSITE_CHILD,
665 g_param_spec_boolean ("composite-child",
666 P_("Composite child"),
667 P_("Whether the widget is part of a composite widget"),
669 GTK_PARAM_READABLE));
670 g_object_class_install_property (gobject_class,
672 g_param_spec_object ("style",
674 P_("The style of the widget, which contains information about how it will look (colors etc)"),
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_flags ("events",
681 P_("The event mask that decides what kind of GdkEvents this widget gets"),
684 GTK_PARAM_READWRITE));
685 g_object_class_install_property (gobject_class,
686 PROP_EXTENSION_EVENTS,
687 g_param_spec_enum ("extension-events",
688 P_("Extension events"),
689 P_("The mask that decides what kind of extension events this widget gets"),
690 GDK_TYPE_EXTENSION_MODE,
691 GDK_EXTENSION_EVENTS_NONE,
692 GTK_PARAM_READWRITE));
693 g_object_class_install_property (gobject_class,
695 g_param_spec_boolean ("no-show-all",
697 P_("Whether gtk_widget_show_all() should not affect this widget"),
699 GTK_PARAM_READWRITE));
702 * GtkWidget:has-tooltip:
704 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
705 * A value of %TRUE indicates that @widget can have a tooltip, in this case
706 * the widget will be queried using #GtkWidget::query-tooltip to determine
707 * whether it will provide a tooltip or not.
709 * Note that setting this property to %TRUE for the first time will change
710 * the event masks of the GdkWindows of this widget to include leave-notify
711 * and motion-notify events. This cannot and will not be undone when the
712 * property is set to %FALSE again.
716 g_object_class_install_property (gobject_class,
718 g_param_spec_boolean ("has-tooltip",
720 P_("Whether this widget has a tooltip"),
722 GTK_PARAM_READWRITE));
724 * GtkWidget:tooltip-text:
726 * Sets the text of tooltip to be the given string.
728 * Also see gtk_tooltip_set_text().
730 * This is a convenience property which will take care of getting the
731 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
732 * will automatically be set to %TRUE and there will be taken care of
733 * #GtkWidget::query-tooltip in the default signal handler.
737 g_object_class_install_property (gobject_class,
739 g_param_spec_string ("tooltip-text",
741 P_("The contents of the tooltip for this widget"),
743 GTK_PARAM_READWRITE));
745 * GtkWidget:tooltip-markup:
747 * Sets the text of tooltip to be the given string, which is marked up
748 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
749 * Also see gtk_tooltip_set_markup().
751 * This is a convenience property which will take care of getting the
752 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
753 * will automatically be set to %TRUE and there will be taken care of
754 * #GtkWidget::query-tooltip in the default signal handler.
758 g_object_class_install_property (gobject_class,
760 g_param_spec_string ("tooltip-markup",
761 P_("Tooltip markup"),
762 P_("The contents of the tooltip for this widget"),
764 GTK_PARAM_READWRITE));
769 * The widget's window if it is realized, %NULL otherwise.
773 g_object_class_install_property (gobject_class,
775 g_param_spec_object ("window",
777 P_("The widget's window if it is realized"),
779 GTK_PARAM_READABLE));
782 * GtkWidget:double-buffered
784 * Whether or not the widget is double buffered.
788 g_object_class_install_property (gobject_class,
789 PROP_DOUBLE_BUFFERED,
790 g_param_spec_boolean ("double-buffered",
791 P_("Double Buffered"),
792 P_("Whether or not the widget is double buffered"),
794 GTK_PARAM_READWRITE));
798 * @widget: the object which received the signal.
800 widget_signals[SHOW] =
801 g_signal_new (I_("show"),
802 G_TYPE_FROM_CLASS (gobject_class),
804 G_STRUCT_OFFSET (GtkWidgetClass, show),
806 _gtk_marshal_VOID__VOID,
811 * @widget: the object which received the signal.
813 widget_signals[HIDE] =
814 g_signal_new (I_("hide"),
815 G_TYPE_FROM_CLASS (gobject_class),
817 G_STRUCT_OFFSET (GtkWidgetClass, hide),
819 _gtk_marshal_VOID__VOID,
824 * @widget: the object which received the signal.
826 widget_signals[MAP] =
827 g_signal_new (I_("map"),
828 G_TYPE_FROM_CLASS (gobject_class),
830 G_STRUCT_OFFSET (GtkWidgetClass, map),
832 _gtk_marshal_VOID__VOID,
837 * @widget: the object which received the signal.
839 widget_signals[UNMAP] =
840 g_signal_new (I_("unmap"),
841 G_TYPE_FROM_CLASS (gobject_class),
843 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
845 _gtk_marshal_VOID__VOID,
849 * GtkWidget::realize:
850 * @widget: the object which received the signal.
852 widget_signals[REALIZE] =
853 g_signal_new (I_("realize"),
854 G_TYPE_FROM_CLASS (gobject_class),
856 G_STRUCT_OFFSET (GtkWidgetClass, realize),
858 _gtk_marshal_VOID__VOID,
862 * GtkWidget::unrealize:
863 * @widget: the object which received the signal.
865 widget_signals[UNREALIZE] =
866 g_signal_new (I_("unrealize"),
867 G_TYPE_FROM_CLASS (gobject_class),
869 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
871 _gtk_marshal_VOID__VOID,
875 * GtkWidget::size-request:
876 * @widget: the object which received the signal.
879 widget_signals[SIZE_REQUEST] =
880 g_signal_new (I_("size-request"),
881 G_TYPE_FROM_CLASS (gobject_class),
883 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
885 _gtk_marshal_VOID__BOXED,
887 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
890 * GtkWidget::size-allocate:
891 * @widget: the object which received the signal.
894 widget_signals[SIZE_ALLOCATE] =
895 g_signal_new (I_("size-allocate"),
896 G_TYPE_FROM_CLASS (gobject_class),
898 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
900 _gtk_marshal_VOID__BOXED,
902 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
905 * GtkWidget::state-changed:
906 * @widget: the object which received the signal.
907 * @state: the previous state
909 * The ::state-changed signal is emitted when the widget state changes.
910 * See gtk_widget_get_state().
912 widget_signals[STATE_CHANGED] =
913 g_signal_new (I_("state-changed"),
914 G_TYPE_FROM_CLASS (gobject_class),
916 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
918 _gtk_marshal_VOID__ENUM,
920 GTK_TYPE_STATE_TYPE);
923 * GtkWidget::parent-set:
924 * @widget: the object on which the signal is emitted
925 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
926 * just got its initial parent.
928 * The ::parent-set signal is emitted when a new parent
929 * has been set on a widget.
931 widget_signals[PARENT_SET] =
932 g_signal_new (I_("parent-set"),
933 G_TYPE_FROM_CLASS (gobject_class),
935 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
937 _gtk_marshal_VOID__OBJECT,
942 * GtkWidget::hierarchy-changed:
943 * @widget: the object on which the signal is emitted
944 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
945 * if the widget was previously unanchored
947 * The ::hierarchy-changed signal is emitted when the
948 * anchored state of a widget changes. A widget is
949 * <firstterm>anchored</firstterm> when its toplevel
950 * ancestor is a #GtkWindow. This signal is emitted when
951 * a widget changes from un-anchored to anchored or vice-versa.
953 widget_signals[HIERARCHY_CHANGED] =
954 g_signal_new (I_("hierarchy-changed"),
955 G_TYPE_FROM_CLASS (gobject_class),
957 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
959 _gtk_marshal_VOID__OBJECT,
964 * GtkWidget::style-set:
965 * @widget: the object on which the signal is emitted
966 * @previous_style: (allow-none): the previous style, or %NULL if the widget
967 * just got its initial style
969 * The ::style-set signal is emitted when a new style has been set
970 * on a widget. Note that style-modifying functions like
971 * gtk_widget_modify_base() also cause this signal to be emitted.
973 widget_signals[STYLE_SET] =
974 g_signal_new (I_("style-set"),
975 G_TYPE_FROM_CLASS (gobject_class),
977 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
979 _gtk_marshal_VOID__OBJECT,
983 * GtkWidget::direction-changed:
984 * @widget: the object on which the signal is emitted
985 * @previous_direction: the previous text direction of @widget
987 * The ::direction-changed signal is emitted when the text direction
988 * of a widget changes.
990 widget_signals[DIRECTION_CHANGED] =
991 g_signal_new (I_("direction-changed"),
992 G_TYPE_FROM_CLASS (gobject_class),
994 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
996 _gtk_marshal_VOID__ENUM,
998 GTK_TYPE_TEXT_DIRECTION);
1001 * GtkWidget::grab-notify:
1002 * @widget: the object which received the signal
1003 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1004 * if it becomes unshadowed
1006 * The ::grab-notify signal is emitted when a widget becomes
1007 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1008 * another widget, or when it becomes unshadowed due to a grab
1011 * A widget is shadowed by a gtk_grab_add() when the topmost
1012 * grab widget in the grab stack of its window group is not
1015 widget_signals[GRAB_NOTIFY] =
1016 g_signal_new (I_("grab-notify"),
1017 G_TYPE_FROM_CLASS (gobject_class),
1019 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1021 _gtk_marshal_VOID__BOOLEAN,
1026 * GtkWidget::child-notify:
1027 * @widget: the object which received the signal
1028 * @pspec: the #GParamSpec of the changed child property
1030 * The ::child-notify signal is emitted for each
1031 * <link linkend="child-properties">child property</link> that has
1032 * changed on an object. The signal's detail holds the property name.
1034 widget_signals[CHILD_NOTIFY] =
1035 g_signal_new (I_("child-notify"),
1036 G_TYPE_FROM_CLASS (gobject_class),
1037 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1038 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1040 g_cclosure_marshal_VOID__PARAM,
1045 * GtkWidget::mnemonic-activate:
1046 * @widget: the object which received the signal.
1049 widget_signals[MNEMONIC_ACTIVATE] =
1050 g_signal_new (I_("mnemonic-activate"),
1051 G_TYPE_FROM_CLASS (gobject_class),
1053 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1054 _gtk_boolean_handled_accumulator, NULL,
1055 _gtk_marshal_BOOLEAN__BOOLEAN,
1060 * GtkWidget::grab-focus:
1061 * @widget: the object which received the signal.
1063 widget_signals[GRAB_FOCUS] =
1064 g_signal_new (I_("grab-focus"),
1065 G_TYPE_FROM_CLASS (gobject_class),
1066 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1067 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1069 _gtk_marshal_VOID__VOID,
1074 * @widget: the object which received the signal.
1077 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1079 widget_signals[FOCUS] =
1080 g_signal_new (I_("focus"),
1081 G_TYPE_FROM_CLASS (object_class),
1083 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1084 _gtk_boolean_handled_accumulator, NULL,
1085 _gtk_marshal_BOOLEAN__ENUM,
1087 GTK_TYPE_DIRECTION_TYPE);
1090 * GtkWidget::move-focus:
1091 * @widget: the object which received the signal.
1094 widget_signals[MOVE_FOCUS] =
1095 g_signal_new_class_handler (I_("move-focus"),
1096 G_TYPE_FROM_CLASS (object_class),
1097 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1098 G_CALLBACK (gtk_widget_real_move_focus),
1100 _gtk_marshal_VOID__ENUM,
1103 GTK_TYPE_DIRECTION_TYPE);
1106 * @widget: the object which received the signal.
1107 * @event: the #GdkEvent which triggered this signal
1109 * The GTK+ main loop will emit three signals for each GDK event delivered
1110 * to a widget: one generic ::event signal, another, more specific,
1111 * signal that matches the type of event delivered (e.g.
1112 * #GtkWidget::key-press-event) and finally a generic
1113 * #GtkWidget::event-after signal.
1115 * Returns: %TRUE to stop other handlers from being invoked for the event
1116 * and to cancel the emission of the second specific ::event signal.
1117 * %FALSE to propagate the event further and to allow the emission of
1118 * the second signal. The ::event-after signal is emitted regardless of
1121 widget_signals[EVENT] =
1122 g_signal_new (I_("event"),
1123 G_TYPE_FROM_CLASS (gobject_class),
1125 G_STRUCT_OFFSET (GtkWidgetClass, event),
1126 _gtk_boolean_handled_accumulator, NULL,
1127 _gtk_marshal_BOOLEAN__BOXED,
1129 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1132 * GtkWidget::event-after:
1133 * @widget: the object which received the signal.
1134 * @event: the #GdkEvent which triggered this signal
1136 * After the emission of the #GtkWidget::event signal and (optionally)
1137 * the second more specific signal, ::event-after will be emitted
1138 * regardless of the previous two signals handlers return values.
1141 widget_signals[EVENT_AFTER] =
1142 g_signal_new (I_("event-after"),
1143 G_TYPE_FROM_CLASS (gobject_class),
1147 _gtk_marshal_VOID__BOXED,
1149 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1152 * GtkWidget::button-press-event:
1153 * @widget: the object which received the signal.
1154 * @event: the #GdkEventButton which triggered this signal
1156 * The ::button-press-event signal will be emitted when a button
1157 * (typically from a mouse) is pressed.
1159 * To receive this signal, the #GdkWindow associated to the
1160 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1162 * This signal will be sent to the grab widget if there is one.
1164 * Returns: %TRUE to stop other handlers from being invoked for the event.
1165 * %FALSE to propagate the event further.
1167 widget_signals[BUTTON_PRESS_EVENT] =
1168 g_signal_new (I_("button-press-event"),
1169 G_TYPE_FROM_CLASS (gobject_class),
1171 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1172 _gtk_boolean_handled_accumulator, NULL,
1173 _gtk_marshal_BOOLEAN__BOXED,
1175 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1178 * GtkWidget::button-release-event:
1179 * @widget: the object which received the signal.
1180 * @event: the #GdkEventButton which triggered this signal
1182 * The ::button-release-event signal will be emitted when a button
1183 * (typically from a mouse) is released.
1185 * To receive this signal, the #GdkWindow associated to the
1186 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1188 * This signal will be sent to the grab widget if there is one.
1190 * Returns: %TRUE to stop other handlers from being invoked for the event.
1191 * %FALSE to propagate the event further.
1193 widget_signals[BUTTON_RELEASE_EVENT] =
1194 g_signal_new (I_("button-release-event"),
1195 G_TYPE_FROM_CLASS (gobject_class),
1197 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1198 _gtk_boolean_handled_accumulator, NULL,
1199 _gtk_marshal_BOOLEAN__BOXED,
1201 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1204 * GtkWidget::scroll-event:
1205 * @widget: the object which received the signal.
1206 * @event: the #GdkEventScroll which triggered this signal
1208 * The ::scroll-event signal is emitted when a button in the 4 to 7
1209 * range is pressed. Wheel mice are usually configured to generate
1210 * button press events for buttons 4 and 5 when the wheel is turned.
1212 * To receive this signal, the #GdkWindow associated to the widget needs
1213 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1215 * This signal will be sent to the grab widget if there is one.
1217 * Returns: %TRUE to stop other handlers from being invoked for the event.
1218 * %FALSE to propagate the event further.
1220 widget_signals[SCROLL_EVENT] =
1221 g_signal_new (I_("scroll-event"),
1222 G_TYPE_FROM_CLASS (gobject_class),
1224 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1225 _gtk_boolean_handled_accumulator, NULL,
1226 _gtk_marshal_BOOLEAN__BOXED,
1228 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1230 * GtkWidget::motion-notify-event:
1231 * @widget: the object which received the signal.
1232 * @event: the #GdkEventMotion which triggered this signal
1234 * The ::motion-notify-event signal is emitted when the pointer moves
1235 * over the widget's #GdkWindow.
1237 * To receive this signal, the #GdkWindow associated to the widget
1238 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1240 * This signal will be sent to the grab widget if there is one.
1242 * Returns: %TRUE to stop other handlers from being invoked for the event.
1243 * %FALSE to propagate the event further.
1245 widget_signals[MOTION_NOTIFY_EVENT] =
1246 g_signal_new (I_("motion-notify-event"),
1247 G_TYPE_FROM_CLASS (gobject_class),
1249 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1250 _gtk_boolean_handled_accumulator, NULL,
1251 _gtk_marshal_BOOLEAN__BOXED,
1253 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1256 * GtkWidget::composited-changed:
1257 * @widget: the object on which the signal is emitted
1259 * The ::composited-changed signal is emitted when the composited
1260 * status of @widget<!-- -->s screen changes.
1261 * See gdk_screen_is_composited().
1263 widget_signals[COMPOSITED_CHANGED] =
1264 g_signal_new (I_("composited-changed"),
1265 G_TYPE_FROM_CLASS (gobject_class),
1266 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1267 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1269 _gtk_marshal_VOID__VOID,
1273 * GtkWidget::keynav-failed:
1274 * @widget: the object which received the signal
1275 * @direction: the direction of movement
1277 * Gets emitted if keyboard navigation fails.
1278 * See gtk_widget_keynav_failed() for details.
1280 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1281 * if the emitting widget should try to handle the keyboard
1282 * navigation attempt in its parent container(s).
1286 widget_signals[KEYNAV_FAILED] =
1287 g_signal_new_class_handler (I_("keynav-failed"),
1288 G_TYPE_FROM_CLASS (gobject_class),
1290 G_CALLBACK (gtk_widget_real_keynav_failed),
1291 _gtk_boolean_handled_accumulator, NULL,
1292 _gtk_marshal_BOOLEAN__ENUM,
1294 GTK_TYPE_DIRECTION_TYPE);
1297 * GtkWidget::delete-event:
1298 * @widget: the object which received the signal
1299 * @event: the event which triggered this signal
1301 * The ::delete-event signal is emitted if a user requests that
1302 * a toplevel window is closed. The default handler for this signal
1303 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1304 * this signal will cause the window to be hidden instead, so that
1305 * it can later be shown again without reconstructing it.
1307 * Returns: %TRUE to stop other handlers from being invoked for the event.
1308 * %FALSE to propagate the event further.
1310 widget_signals[DELETE_EVENT] =
1311 g_signal_new (I_("delete-event"),
1312 G_TYPE_FROM_CLASS (gobject_class),
1314 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1315 _gtk_boolean_handled_accumulator, NULL,
1316 _gtk_marshal_BOOLEAN__BOXED,
1318 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1321 * GtkWidget::destroy-event:
1322 * @widget: the object which received the signal.
1323 * @event: the event which triggered this signal
1325 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1326 * You rarely get this signal, because most widgets disconnect themselves
1327 * from their window before they destroy it, so no widget owns the
1328 * window at destroy time.
1330 * To receive this signal, the #GdkWindow associated to the widget needs
1331 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1332 * automatically for all new windows.
1334 * Returns: %TRUE to stop other handlers from being invoked for the event.
1335 * %FALSE to propagate the event further.
1337 widget_signals[DESTROY_EVENT] =
1338 g_signal_new (I_("destroy-event"),
1339 G_TYPE_FROM_CLASS (gobject_class),
1341 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1342 _gtk_boolean_handled_accumulator, NULL,
1343 _gtk_marshal_BOOLEAN__BOXED,
1345 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1348 * GtkWidget::expose-event:
1349 * @widget: the object which received the signal.
1350 * @event: the #GdkEventExpose which triggered this signal
1352 * The ::expose-event signal is emitted when an area of a previously
1353 * obscured #GdkWindow is made visible and needs to be redrawn.
1354 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1357 * To receive this signal, the #GdkWindow associated to the widget needs
1358 * to enable the #GDK_EXPOSURE_MASK mask.
1360 * Returns: %TRUE to stop other handlers from being invoked for the event.
1361 * %FALSE to propagate the event further.
1363 widget_signals[EXPOSE_EVENT] =
1364 g_signal_new (I_("expose-event"),
1365 G_TYPE_FROM_CLASS (gobject_class),
1367 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1368 _gtk_boolean_handled_accumulator, NULL,
1369 _gtk_marshal_BOOLEAN__BOXED,
1371 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1374 * GtkWidget::key-press-event:
1375 * @widget: the object which received the signal
1376 * @event: the #GdkEventKey which triggered this signal
1378 * The ::key-press-event signal is emitted when a key is pressed.
1380 * To receive this signal, the #GdkWindow associated to the widget needs
1381 * to enable the #GDK_KEY_PRESS_MASK mask.
1383 * This signal will be sent to the grab widget if there is one.
1385 * Returns: %TRUE to stop other handlers from being invoked for the event.
1386 * %FALSE to propagate the event further.
1388 widget_signals[KEY_PRESS_EVENT] =
1389 g_signal_new (I_("key-press-event"),
1390 G_TYPE_FROM_CLASS (gobject_class),
1392 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1393 _gtk_boolean_handled_accumulator, NULL,
1394 _gtk_marshal_BOOLEAN__BOXED,
1396 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1399 * GtkWidget::key-release-event:
1400 * @widget: the object which received the signal
1401 * @event: the #GdkEventKey which triggered this signal
1403 * The ::key-release-event signal is emitted when a key is pressed.
1405 * To receive this signal, the #GdkWindow associated to the widget needs
1406 * to enable the #GDK_KEY_RELEASE_MASK mask.
1408 * This signal will be sent to the grab widget if there is one.
1410 * Returns: %TRUE to stop other handlers from being invoked for the event.
1411 * %FALSE to propagate the event further.
1413 widget_signals[KEY_RELEASE_EVENT] =
1414 g_signal_new (I_("key-release-event"),
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1418 _gtk_boolean_handled_accumulator, NULL,
1419 _gtk_marshal_BOOLEAN__BOXED,
1421 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1424 * GtkWidget::enter-notify-event:
1425 * @widget: the object which received the signal
1426 * @event: the #GdkEventCrossing which triggered this signal
1428 * The ::enter-notify-event will be emitted when the pointer enters
1429 * the @widget's window.
1431 * To receive this signal, the #GdkWindow associated to the widget needs
1432 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1434 * This signal will be sent to the grab widget if there is one.
1436 * Returns: %TRUE to stop other handlers from being invoked for the event.
1437 * %FALSE to propagate the event further.
1439 widget_signals[ENTER_NOTIFY_EVENT] =
1440 g_signal_new (I_("enter-notify-event"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1444 _gtk_boolean_handled_accumulator, NULL,
1445 _gtk_marshal_BOOLEAN__BOXED,
1447 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1450 * GtkWidget::leave-notify-event:
1451 * @widget: the object which received the signal
1452 * @event: the #GdkEventCrossing which triggered this signal
1454 * The ::leave-notify-event will be emitted when the pointer leaves
1455 * the @widget's window.
1457 * To receive this signal, the #GdkWindow associated to the widget needs
1458 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1460 * This signal will be sent to the grab widget if there is one.
1462 * Returns: %TRUE to stop other handlers from being invoked for the event.
1463 * %FALSE to propagate the event further.
1465 widget_signals[LEAVE_NOTIFY_EVENT] =
1466 g_signal_new (I_("leave-notify-event"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1470 _gtk_boolean_handled_accumulator, NULL,
1471 _gtk_marshal_BOOLEAN__BOXED,
1473 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1476 * GtkWidget::configure-event
1477 * @widget: the object which received the signal
1478 * @event: the #GdkEventConfigure which triggered this signal
1480 * The ::configure-event signal will be emitted when the size, position or
1481 * stacking of the @widget's window has changed.
1483 * To receive this signal, the #GdkWindow associated to the widget needs
1484 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1485 * automatically for all new windows.
1487 * Returns: %TRUE to stop other handlers from being invoked for the event.
1488 * %FALSE to propagate the event further.
1490 widget_signals[CONFIGURE_EVENT] =
1491 g_signal_new (I_("configure-event"),
1492 G_TYPE_FROM_CLASS (gobject_class),
1494 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1495 _gtk_boolean_handled_accumulator, NULL,
1496 _gtk_marshal_BOOLEAN__BOXED,
1498 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1501 * GtkWidget::focus-in-event
1502 * @widget: the object which received the signal
1503 * @event: the #GdkEventFocus which triggered this signal
1505 * The ::focus-in-event signal will be emitted when the keyboard focus
1506 * enters the @widget's window.
1508 * To receive this signal, the #GdkWindow associated to the widget needs
1509 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1511 * Returns: %TRUE to stop other handlers from being invoked for the event.
1512 * %FALSE to propagate the event further.
1514 widget_signals[FOCUS_IN_EVENT] =
1515 g_signal_new (I_("focus-in-event"),
1516 G_TYPE_FROM_CLASS (gobject_class),
1518 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1519 _gtk_boolean_handled_accumulator, NULL,
1520 _gtk_marshal_BOOLEAN__BOXED,
1522 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1525 * GtkWidget::focus-out-event
1526 * @widget: the object which received the signal
1527 * @event: the #GdkEventFocus which triggered this signal
1529 * The ::focus-out-event signal will be emitted when the keyboard focus
1530 * leaves the @widget's window.
1532 * To receive this signal, the #GdkWindow associated to the widget needs
1533 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1535 * Returns: %TRUE to stop other handlers from being invoked for the event.
1536 * %FALSE to propagate the event further.
1538 widget_signals[FOCUS_OUT_EVENT] =
1539 g_signal_new (I_("focus-out-event"),
1540 G_TYPE_FROM_CLASS (gobject_class),
1542 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1543 _gtk_boolean_handled_accumulator, NULL,
1544 _gtk_marshal_BOOLEAN__BOXED,
1546 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1549 * GtkWidget::map-event
1550 * @widget: the object which received the signal
1551 * @event: the #GdkEventAny which triggered this signal
1553 * The ::map-event signal will be emitted when the @widget's window is
1554 * mapped. A window is mapped when it becomes visible on the screen.
1556 * To receive this signal, the #GdkWindow associated to the widget needs
1557 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1558 * automatically for all new windows.
1560 * Returns: %TRUE to stop other handlers from being invoked for the event.
1561 * %FALSE to propagate the event further.
1563 widget_signals[MAP_EVENT] =
1564 g_signal_new (I_("map-event"),
1565 G_TYPE_FROM_CLASS (gobject_class),
1567 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1568 _gtk_boolean_handled_accumulator, NULL,
1569 _gtk_marshal_BOOLEAN__BOXED,
1571 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1574 * GtkWidget::unmap-event
1575 * @widget: the object which received the signal
1576 * @event: the #GdkEventAny which triggered this signal
1578 * The ::unmap-event signal will be emitted when the @widget's window is
1579 * unmapped. A window is unmapped when it becomes invisible on the screen.
1581 * To receive this signal, the #GdkWindow associated to the widget needs
1582 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1583 * automatically for all new windows.
1585 * Returns: %TRUE to stop other handlers from being invoked for the event.
1586 * %FALSE to propagate the event further.
1588 widget_signals[UNMAP_EVENT] =
1589 g_signal_new (I_("unmap-event"),
1590 G_TYPE_FROM_CLASS (gobject_class),
1592 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1593 _gtk_boolean_handled_accumulator, NULL,
1594 _gtk_marshal_BOOLEAN__BOXED,
1596 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1599 * GtkWidget::property-notify-event
1600 * @widget: the object which received the signal
1601 * @event: the #GdkEventProperty which triggered this signal
1603 * The ::property-notify-event signal will be emitted when a property on
1604 * the @widget's window has been changed or deleted.
1606 * To receive this signal, the #GdkWindow associated to the widget needs
1607 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1609 * Returns: %TRUE to stop other handlers from being invoked for the event.
1610 * %FALSE to propagate the event further.
1612 widget_signals[PROPERTY_NOTIFY_EVENT] =
1613 g_signal_new (I_("property-notify-event"),
1614 G_TYPE_FROM_CLASS (gobject_class),
1616 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1617 _gtk_boolean_handled_accumulator, NULL,
1618 _gtk_marshal_BOOLEAN__BOXED,
1620 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1623 * GtkWidget::selection-clear-event
1624 * @widget: the object which received the signal
1625 * @event: the #GdkEventSelection which triggered this signal
1627 * The ::selection-clear-event signal will be emitted when the
1628 * the @widget's window has lost ownership of a selection.
1630 * Returns: %TRUE to stop other handlers from being invoked for the event.
1631 * %FALSE to propagate the event further.
1633 widget_signals[SELECTION_CLEAR_EVENT] =
1634 g_signal_new (I_("selection-clear-event"),
1635 G_TYPE_FROM_CLASS (gobject_class),
1637 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1638 _gtk_boolean_handled_accumulator, NULL,
1639 _gtk_marshal_BOOLEAN__BOXED,
1641 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1644 * GtkWidget::selection-request-event
1645 * @widget: the object which received the signal
1646 * @event: the #GdkEventSelection which triggered this signal
1648 * The ::selection-request-event signal will be emitted when
1649 * another client requests ownership of the selection owned by
1650 * the @widget's window.
1652 * Returns: %TRUE to stop other handlers from being invoked for the event.
1653 * %FALSE to propagate the event further.
1655 widget_signals[SELECTION_REQUEST_EVENT] =
1656 g_signal_new (I_("selection-request-event"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1659 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1660 _gtk_boolean_handled_accumulator, NULL,
1661 _gtk_marshal_BOOLEAN__BOXED,
1663 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1666 * GtkWidget::selection-notify-event:
1667 * @widget: the object which received the signal.
1670 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1672 widget_signals[SELECTION_NOTIFY_EVENT] =
1673 g_signal_new (I_("selection-notify-event"),
1674 G_TYPE_FROM_CLASS (gobject_class),
1676 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1677 _gtk_boolean_handled_accumulator, NULL,
1678 _gtk_marshal_BOOLEAN__BOXED,
1680 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1683 * GtkWidget::selection-received:
1684 * @widget: the object which received the signal.
1688 widget_signals[SELECTION_RECEIVED] =
1689 g_signal_new (I_("selection-received"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1692 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1694 _gtk_marshal_VOID__BOXED_UINT,
1696 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1700 * GtkWidget::selection-get:
1701 * @widget: the object which received the signal.
1706 widget_signals[SELECTION_GET] =
1707 g_signal_new (I_("selection-get"),
1708 G_TYPE_FROM_CLASS (gobject_class),
1710 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1712 _gtk_marshal_VOID__BOXED_UINT_UINT,
1714 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1719 * GtkWidget::proximity-in-event
1720 * @widget: the object which received the signal
1721 * @event: the #GdkEventProximity which triggered this signal
1723 * To receive this signal the #GdkWindow associated to the widget needs
1724 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1726 * This signal will be sent to the grab widget if there is one.
1728 * Returns: %TRUE to stop other handlers from being invoked for the event.
1729 * %FALSE to propagate the event further.
1731 widget_signals[PROXIMITY_IN_EVENT] =
1732 g_signal_new (I_("proximity-in-event"),
1733 G_TYPE_FROM_CLASS (gobject_class),
1735 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1736 _gtk_boolean_handled_accumulator, NULL,
1737 _gtk_marshal_BOOLEAN__BOXED,
1739 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1742 * GtkWidget::proximity-out-event
1743 * @widget: the object which received the signal
1744 * @event: the #GdkEventProximity which triggered this signal
1746 * To receive this signal the #GdkWindow associated to the widget needs
1747 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1749 * This signal will be sent to the grab widget if there is one.
1751 * Returns: %TRUE to stop other handlers from being invoked for the event.
1752 * %FALSE to propagate the event further.
1754 widget_signals[PROXIMITY_OUT_EVENT] =
1755 g_signal_new (I_("proximity-out-event"),
1756 G_TYPE_FROM_CLASS (gobject_class),
1758 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1759 _gtk_boolean_handled_accumulator, NULL,
1760 _gtk_marshal_BOOLEAN__BOXED,
1762 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1765 * GtkWidget::drag-leave:
1766 * @widget: the object which received the signal.
1767 * @drag_context: the drag context
1768 * @time: the timestamp of the motion event
1770 * The ::drag-leave signal is emitted on the drop site when the cursor
1771 * leaves the widget. A typical reason to connect to this signal is to
1772 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1773 * with gtk_drag_unhighlight()
1775 widget_signals[DRAG_LEAVE] =
1776 g_signal_new (I_("drag-leave"),
1777 G_TYPE_FROM_CLASS (gobject_class),
1779 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1781 _gtk_marshal_VOID__OBJECT_UINT,
1783 GDK_TYPE_DRAG_CONTEXT,
1787 * GtkWidget::drag-begin:
1788 * @widget: the object which received the signal
1789 * @drag_context: the drag context
1791 * The ::drag-begin signal is emitted on the drag source when a drag is
1792 * started. A typical reason to connect to this signal is to set up a
1793 * custom drag icon with gtk_drag_source_set_icon().
1795 * Note that some widgets set up a drag icon in the default handler of
1796 * this signal, so you may have to use g_signal_connect_after() to
1797 * override what the default handler did.
1799 widget_signals[DRAG_BEGIN] =
1800 g_signal_new (I_("drag-begin"),
1801 G_TYPE_FROM_CLASS (gobject_class),
1803 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1805 _gtk_marshal_VOID__OBJECT,
1807 GDK_TYPE_DRAG_CONTEXT);
1810 * GtkWidget::drag-end:
1811 * @widget: the object which received the signal
1812 * @drag_context: the drag context
1814 * The ::drag-end signal is emitted on the drag source when a drag is
1815 * finished. A typical reason to connect to this signal is to undo
1816 * things done in #GtkWidget::drag-begin.
1818 widget_signals[DRAG_END] =
1819 g_signal_new (I_("drag-end"),
1820 G_TYPE_FROM_CLASS (gobject_class),
1822 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1824 _gtk_marshal_VOID__OBJECT,
1826 GDK_TYPE_DRAG_CONTEXT);
1829 * GtkWidget::drag-data-delete:
1830 * @widget: the object which received the signal
1831 * @drag_context: the drag context
1833 * The ::drag-data-delete signal is emitted on the drag source when a drag
1834 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1835 * handler is responsible for deleting the data that has been dropped. What
1836 * "delete" means depends on the context of the drag operation.
1838 widget_signals[DRAG_DATA_DELETE] =
1839 g_signal_new (I_("drag-data-delete"),
1840 G_TYPE_FROM_CLASS (gobject_class),
1842 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1844 _gtk_marshal_VOID__OBJECT,
1846 GDK_TYPE_DRAG_CONTEXT);
1849 * GtkWidget::drag-failed:
1850 * @widget: the object which received the signal
1851 * @drag_context: the drag context
1852 * @result: the result of the drag operation
1854 * The ::drag-failed signal is emitted on the drag source when a drag has
1855 * failed. The signal handler may hook custom code to handle a failed DND
1856 * operation based on the type of error, it returns %TRUE is the failure has
1857 * been already handled (not showing the default "drag operation failed"
1858 * animation), otherwise it returns %FALSE.
1860 * Return value: %TRUE if the failed drag operation has been already handled.
1864 widget_signals[DRAG_FAILED] =
1865 g_signal_new (I_("drag-failed"),
1866 G_TYPE_FROM_CLASS (gobject_class),
1868 0, _gtk_boolean_handled_accumulator, NULL,
1869 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1871 GDK_TYPE_DRAG_CONTEXT,
1872 GTK_TYPE_DRAG_RESULT);
1875 * GtkWidget::drag-motion:
1876 * @widget: the object which received the signal
1877 * @drag_context: the drag context
1878 * @x: the x coordinate of the current cursor position
1879 * @y: the y coordinate of the current cursor position
1880 * @time: the timestamp of the motion event
1881 * @returns: whether the cursor position is in a drop zone
1883 * The drag-motion signal is emitted on the drop site when the user
1884 * moves the cursor over the widget during a drag. The signal handler
1885 * must determine whether the cursor position is in a drop zone or not.
1886 * If it is not in a drop zone, it returns %FALSE and no further processing
1887 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1888 * handler is responsible for providing the necessary information for
1889 * displaying feedback to the user, by calling gdk_drag_status().
1891 * If the decision whether the drop will be accepted or rejected can't be
1892 * made based solely on the cursor position and the type of the data, the
1893 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1894 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1895 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1896 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1897 * when using the drag-motion signal that way.
1899 * Also note that there is no drag-enter signal. The drag receiver has to
1900 * keep track of whether he has received any drag-motion signals since the
1901 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1902 * an "enter" signal. Upon an "enter", the handler will typically highlight
1903 * the drop site with gtk_drag_highlight().
1906 * drag_motion (GtkWidget *widget,
1907 * GdkDragContext *context,
1914 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1916 * if (!private_data->drag_highlight)
1918 * private_data->drag_highlight = 1;
1919 * gtk_drag_highlight (widget);
1922 * target = gtk_drag_dest_find_target (widget, context, NULL);
1923 * if (target == GDK_NONE)
1924 * gdk_drag_status (context, 0, time);
1927 * private_data->pending_status = context->suggested_action;
1928 * gtk_drag_get_data (widget, context, target, time);
1935 * drag_data_received (GtkWidget *widget,
1936 * GdkDragContext *context,
1939 * GtkSelectionData *selection_data,
1943 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1945 * if (private_data->suggested_action)
1947 * private_data->suggested_action = 0;
1949 * /* We are getting this data due to a request in drag_motion,
1950 * * rather than due to a request in drag_drop, so we are just
1951 * * supposed to call gdk_drag_status (), not actually paste in
1954 * str = gtk_selection_data_get_text (selection_data);
1955 * if (!data_is_acceptable (str))
1956 * gdk_drag_status (context, 0, time);
1958 * gdk_drag_status (context, private_data->suggested_action, time);
1962 * /* accept the drop */
1967 widget_signals[DRAG_MOTION] =
1968 g_signal_new (I_("drag-motion"),
1969 G_TYPE_FROM_CLASS (gobject_class),
1971 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1972 _gtk_boolean_handled_accumulator, NULL,
1973 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1975 GDK_TYPE_DRAG_CONTEXT,
1981 * GtkWidget::drag-drop:
1982 * @widget: the object which received the signal
1983 * @drag_context: the drag context
1984 * @x: the x coordinate of the current cursor position
1985 * @y: the y coordinate of the current cursor position
1986 * @time: the timestamp of the motion event
1987 * @returns: whether the cursor position is in a drop zone
1989 * The ::drag-drop signal is emitted on the drop site when the user drops
1990 * the data onto the widget. The signal handler must determine whether
1991 * the cursor position is in a drop zone or not. If it is not in a drop
1992 * zone, it returns %FALSE and no further processing is necessary.
1993 * Otherwise, the handler returns %TRUE. In this case, the handler must
1994 * ensure that gtk_drag_finish() is called to let the source know that
1995 * the drop is done. The call to gtk_drag_finish() can be done either
1996 * directly or in a #GtkWidget::drag-data-received handler which gets
1997 * triggered by calling gtk_drag_get_data() to receive the data for one
1998 * or more of the supported targets.
2000 widget_signals[DRAG_DROP] =
2001 g_signal_new (I_("drag-drop"),
2002 G_TYPE_FROM_CLASS (gobject_class),
2004 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2008 GDK_TYPE_DRAG_CONTEXT,
2014 * GtkWidget::drag-data-get:
2015 * @widget: the object which received the signal
2016 * @drag_context: the drag context
2017 * @data: the #GtkSelectionData to be filled with the dragged data
2018 * @info: the info that has been registered with the target in the
2020 * @time: the timestamp at which the data was requested
2022 * The ::drag-data-get signal is emitted on the drag source when the drop
2023 * site requests the data which is dragged. It is the responsibility of
2024 * the signal handler to fill @data with the data in the format which
2025 * is indicated by @info. See gtk_selection_data_set() and
2026 * gtk_selection_data_set_text().
2028 widget_signals[DRAG_DATA_GET] =
2029 g_signal_new (I_("drag-data-get"),
2030 G_TYPE_FROM_CLASS (gobject_class),
2032 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2034 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2036 GDK_TYPE_DRAG_CONTEXT,
2037 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2042 * GtkWidget::drag-data-received:
2043 * @widget: the object which received the signal
2044 * @drag_context: the drag context
2045 * @x: where the drop happened
2046 * @y: where the drop happened
2047 * @data: the received data
2048 * @info: the info that has been registered with the target in the
2050 * @time: the timestamp at which the data was received
2052 * The ::drag-data-received signal is emitted on the drop site when the
2053 * dragged data has been received. If the data was received in order to
2054 * determine whether the drop will be accepted, the handler is expected
2055 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2056 * If the data was received in response to a #GtkWidget::drag-drop signal
2057 * (and this is the last target to be received), the handler for this
2058 * signal is expected to process the received data and then call
2059 * gtk_drag_finish(), setting the @success parameter depending on whether
2060 * the data was processed successfully.
2062 * The handler may inspect and modify @drag_context->action before calling
2063 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2064 * following example:
2067 * drag_data_received (GtkWidget *widget,
2068 * GdkDragContext *drag_context,
2071 * GtkSelectionData *data,
2075 * if ((data->length >= 0) && (data->format == 8))
2077 * if (drag_context->action == GDK_ACTION_ASK)
2079 * GtkWidget *dialog;
2082 * dialog = gtk_message_dialog_new (NULL,
2083 * GTK_DIALOG_MODAL |
2084 * GTK_DIALOG_DESTROY_WITH_PARENT,
2086 * GTK_BUTTONS_YES_NO,
2087 * "Move the data ?\n");
2088 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2089 * gtk_widget_destroy (dialog);
2091 * if (response == GTK_RESPONSE_YES)
2092 * drag_context->action = GDK_ACTION_MOVE;
2094 * drag_context->action = GDK_ACTION_COPY;
2097 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2101 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2105 widget_signals[DRAG_DATA_RECEIVED] =
2106 g_signal_new (I_("drag-data-received"),
2107 G_TYPE_FROM_CLASS (gobject_class),
2109 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2111 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2113 GDK_TYPE_DRAG_CONTEXT,
2116 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2121 * GtkWidget::visibility-notify-event:
2122 * @widget: the object which received the signal
2123 * @event: the #GdkEventVisibility which triggered this signal
2125 * The ::visibility-notify-event will be emitted when the @widget's window
2126 * is obscured or unobscured.
2128 * To receive this signal the #GdkWindow associated to the widget needs
2129 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2131 * Returns: %TRUE to stop other handlers from being invoked for the event.
2132 * %FALSE to propagate the event further.
2134 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2135 g_signal_new (I_("visibility-notify-event"),
2136 G_TYPE_FROM_CLASS (gobject_class),
2138 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2139 _gtk_boolean_handled_accumulator, NULL,
2140 _gtk_marshal_BOOLEAN__BOXED,
2142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2145 * GtkWidget::client-event:
2146 * @widget: the object which received the signal
2147 * @event: the #GdkEventClient which triggered this signal
2149 * The ::client-event will be emitted when the @widget's window
2150 * receives a message (via a ClientMessage event) from another
2153 * Returns: %TRUE to stop other handlers from being invoked for
2154 * the event. %FALSE to propagate the event further.
2156 widget_signals[CLIENT_EVENT] =
2157 g_signal_new (I_("client-event"),
2158 G_TYPE_FROM_CLASS (gobject_class),
2160 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2161 _gtk_boolean_handled_accumulator, NULL,
2162 _gtk_marshal_BOOLEAN__BOXED,
2164 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2167 * GtkWidget::no-expose-event:
2168 * @widget: the object which received the signal
2169 * @event: the #GdkEventNoExpose which triggered this signal
2171 * The ::no-expose-event will be emitted when the @widget's window is
2172 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2173 * gdk_window_copy_area()) which was completely unobscured. If the source
2174 * window was partially obscured #GdkEventExpose events will be generated
2177 * Returns: %TRUE to stop other handlers from being invoked for the event.
2178 * %FALSE to propagate the event further.
2180 widget_signals[NO_EXPOSE_EVENT] =
2181 g_signal_new (I_("no-expose-event"),
2182 G_TYPE_FROM_CLASS (gobject_class),
2184 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2185 _gtk_boolean_handled_accumulator, NULL,
2186 _gtk_marshal_BOOLEAN__BOXED,
2188 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2191 * GtkWidget::window-state-event:
2192 * @widget: the object which received the signal
2193 * @event: the #GdkEventWindowState which triggered this signal
2195 * The ::window-state-event will be emitted when the state of the
2196 * toplevel window associated to the @widget changes.
2198 * To receive this signal the #GdkWindow associated to the widget
2199 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2200 * this mask automatically for all new windows.
2202 * Returns: %TRUE to stop other handlers from being invoked for the
2203 * event. %FALSE to propagate the event further.
2205 widget_signals[WINDOW_STATE_EVENT] =
2206 g_signal_new (I_("window-state-event"),
2207 G_TYPE_FROM_CLASS (gobject_class),
2209 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2216 * GtkWidget::damage-event:
2217 * @widget: the object which received the signal
2218 * @event: the #GdkEventExpose event
2220 * Emitted when a redirected window belonging to @widget gets drawn into.
2221 * The region/area members of the event shows what area of the redirected
2222 * drawable was drawn into.
2224 * Returns: %TRUE to stop other handlers from being invoked for the event.
2225 * %FALSE to propagate the event further.
2229 widget_signals[DAMAGE_EVENT] =
2230 g_signal_new (I_("damage-event"),
2231 G_TYPE_FROM_CLASS (gobject_class),
2234 _gtk_boolean_handled_accumulator, NULL,
2235 _gtk_marshal_BOOLEAN__BOXED,
2237 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2239 * GtkWidget::grab-broken-event:
2240 * @widget: the object which received the signal
2241 * @event: the #GdkEventGrabBroken event
2243 * Emitted when a pointer or keyboard grab on a window belonging
2244 * to @widget gets broken.
2246 * On X11, this happens when the grab window becomes unviewable
2247 * (i.e. it or one of its ancestors is unmapped), or if the same
2248 * application grabs the pointer or keyboard again.
2250 * Returns: %TRUE to stop other handlers from being invoked for
2251 * the event. %FALSE to propagate the event further.
2255 widget_signals[GRAB_BROKEN] =
2256 g_signal_new (I_("grab-broken-event"),
2257 G_TYPE_FROM_CLASS (gobject_class),
2259 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2260 _gtk_boolean_handled_accumulator, NULL,
2261 _gtk_marshal_BOOLEAN__BOXED,
2263 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2265 * GtkWidget::query-tooltip:
2266 * @widget: the object which received the signal
2267 * @x: the x coordinate of the cursor position where the request has
2268 * been emitted, relative to @widget->window
2269 * @y: the y coordinate of the cursor position where the request has
2270 * been emitted, relative to @widget->window
2271 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2272 * @tooltip: a #GtkTooltip
2274 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2275 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2276 * focus in keyboard mode.
2278 * Using the given coordinates, the signal handler should determine
2279 * whether a tooltip should be shown for @widget. If this is the case
2280 * %TRUE should be returned, %FALSE otherwise. Note that if
2281 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2282 * should not be used.
2284 * The signal handler is free to manipulate @tooltip with the therefore
2285 * destined function calls.
2287 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2291 widget_signals[QUERY_TOOLTIP] =
2292 g_signal_new (I_("query-tooltip"),
2293 G_TYPE_FROM_CLASS (gobject_class),
2295 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2296 _gtk_boolean_handled_accumulator, NULL,
2297 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2305 * GtkWidget::popup-menu
2306 * @widget: the object which received the signal
2308 * This signal gets emitted whenever a widget should pop up a context
2309 * menu. This usually happens through the standard key binding mechanism;
2310 * by pressing a certain key while a widget is focused, the user can cause
2311 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2312 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2313 * for an example of how to use this signal.
2315 * Returns: %TRUE if a menu was activated
2317 widget_signals[POPUP_MENU] =
2318 g_signal_new (I_("popup-menu"),
2319 G_TYPE_FROM_CLASS (gobject_class),
2320 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2321 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2322 _gtk_boolean_handled_accumulator, NULL,
2323 _gtk_marshal_BOOLEAN__VOID,
2327 * GtkWidget::show-help:
2328 * @widget: the object which received the signal.
2331 widget_signals[SHOW_HELP] =
2332 g_signal_new (I_("show-help"),
2333 G_TYPE_FROM_CLASS (gobject_class),
2334 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2335 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2336 _gtk_boolean_handled_accumulator, NULL,
2337 _gtk_marshal_BOOLEAN__ENUM,
2339 GTK_TYPE_WIDGET_HELP_TYPE);
2342 * GtkWidget::accel-closures-changed:
2343 * @widget: the object which received the signal.
2345 widget_signals[ACCEL_CLOSURES_CHANGED] =
2346 g_signal_new (I_("accel-closures-changed"),
2347 G_TYPE_FROM_CLASS (gobject_class),
2351 _gtk_marshal_VOID__VOID,
2355 * GtkWidget::screen-changed:
2356 * @widget: the object on which the signal is emitted
2357 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2358 * widget was not associated with a screen before
2360 * The ::screen-changed signal gets emitted when the
2361 * screen of a widget has changed.
2363 widget_signals[SCREEN_CHANGED] =
2364 g_signal_new (I_("screen-changed"),
2365 G_TYPE_FROM_CLASS (gobject_class),
2367 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2369 _gtk_marshal_VOID__OBJECT,
2374 * GtkWidget::can-activate-accel:
2375 * @widget: the object which received the signal
2376 * @signal_id: the ID of a signal installed on @widget
2378 * Determines whether an accelerator that activates the signal
2379 * identified by @signal_id can currently be activated.
2380 * This signal is present to allow applications and derived
2381 * widgets to override the default #GtkWidget handling
2382 * for determining whether an accelerator can be activated.
2384 * Returns: %TRUE if the signal can be activated.
2386 widget_signals[CAN_ACTIVATE_ACCEL] =
2387 g_signal_new (I_("can-activate-accel"),
2388 G_TYPE_FROM_CLASS (gobject_class),
2390 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2391 _gtk_boolean_handled_accumulator, NULL,
2392 _gtk_marshal_BOOLEAN__UINT,
2393 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2395 binding_set = gtk_binding_set_by_class (klass);
2396 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2398 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2401 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2403 GTK_TYPE_WIDGET_HELP_TYPE,
2404 GTK_WIDGET_HELP_TOOLTIP);
2405 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2407 GTK_TYPE_WIDGET_HELP_TYPE,
2408 GTK_WIDGET_HELP_TOOLTIP);
2409 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2411 GTK_TYPE_WIDGET_HELP_TYPE,
2412 GTK_WIDGET_HELP_WHATS_THIS);
2413 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2415 GTK_TYPE_WIDGET_HELP_TYPE,
2416 GTK_WIDGET_HELP_WHATS_THIS);
2418 gtk_widget_class_install_style_property (klass,
2419 g_param_spec_boolean ("interior-focus",
2420 P_("Interior Focus"),
2421 P_("Whether to draw the focus indicator inside widgets"),
2423 GTK_PARAM_READABLE));
2425 gtk_widget_class_install_style_property (klass,
2426 g_param_spec_int ("focus-line-width",
2427 P_("Focus linewidth"),
2428 P_("Width, in pixels, of the focus indicator line"),
2430 GTK_PARAM_READABLE));
2432 gtk_widget_class_install_style_property (klass,
2433 g_param_spec_string ("focus-line-pattern",
2434 P_("Focus line dash pattern"),
2435 P_("Dash pattern used to draw the focus indicator"),
2437 GTK_PARAM_READABLE));
2438 gtk_widget_class_install_style_property (klass,
2439 g_param_spec_int ("focus-padding",
2440 P_("Focus padding"),
2441 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2443 GTK_PARAM_READABLE));
2444 gtk_widget_class_install_style_property (klass,
2445 g_param_spec_boxed ("cursor-color",
2447 P_("Color with which to draw insertion cursor"),
2449 GTK_PARAM_READABLE));
2450 gtk_widget_class_install_style_property (klass,
2451 g_param_spec_boxed ("secondary-cursor-color",
2452 P_("Secondary cursor color"),
2453 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2455 GTK_PARAM_READABLE));
2456 gtk_widget_class_install_style_property (klass,
2457 g_param_spec_float ("cursor-aspect-ratio",
2458 P_("Cursor line aspect ratio"),
2459 P_("Aspect ratio with which to draw insertion cursor"),
2461 GTK_PARAM_READABLE));
2464 * GtkWidget:draw-border:
2466 * The "draw-border" style property defines the size of areas outside
2467 * the widget's allocation to draw.
2471 gtk_widget_class_install_style_property (klass,
2472 g_param_spec_boxed ("draw-border",
2474 P_("Size of areas outside the widget's allocation to draw"),
2476 GTK_PARAM_READABLE));
2479 * GtkWidget:link-color:
2481 * The "link-color" style property defines the color of unvisited links.
2485 gtk_widget_class_install_style_property (klass,
2486 g_param_spec_boxed ("link-color",
2487 P_("Unvisited Link Color"),
2488 P_("Color of unvisited links"),
2490 GTK_PARAM_READABLE));
2493 * GtkWidget:visited-link-color:
2495 * The "visited-link-color" style property defines the color of visited links.
2499 gtk_widget_class_install_style_property (klass,
2500 g_param_spec_boxed ("visited-link-color",
2501 P_("Visited Link Color"),
2502 P_("Color of visited links"),
2504 GTK_PARAM_READABLE));
2507 * GtkWidget:wide-separators:
2509 * The "wide-separators" style property defines whether separators have
2510 * configurable width and should be drawn using a box instead of a line.
2514 gtk_widget_class_install_style_property (klass,
2515 g_param_spec_boolean ("wide-separators",
2516 P_("Wide Separators"),
2517 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2519 GTK_PARAM_READABLE));
2522 * GtkWidget:separator-width:
2524 * The "separator-width" style property defines the width of separators.
2525 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2529 gtk_widget_class_install_style_property (klass,
2530 g_param_spec_int ("separator-width",
2531 P_("Separator Width"),
2532 P_("The width of separators if wide-separators is TRUE"),
2534 GTK_PARAM_READABLE));
2537 * GtkWidget:separator-height:
2539 * The "separator-height" style property defines the height of separators.
2540 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2544 gtk_widget_class_install_style_property (klass,
2545 g_param_spec_int ("separator-height",
2546 P_("Separator Height"),
2547 P_("The height of separators if \"wide-separators\" is TRUE"),
2549 GTK_PARAM_READABLE));
2552 * GtkWidget:scroll-arrow-hlength:
2554 * The "scroll-arrow-hlength" style property defines the length of
2555 * horizontal scroll arrows.
2559 gtk_widget_class_install_style_property (klass,
2560 g_param_spec_int ("scroll-arrow-hlength",
2561 P_("Horizontal Scroll Arrow Length"),
2562 P_("The length of horizontal scroll arrows"),
2564 GTK_PARAM_READABLE));
2567 * GtkWidget:scroll-arrow-vlength:
2569 * The "scroll-arrow-vlength" style property defines the length of
2570 * vertical scroll arrows.
2574 gtk_widget_class_install_style_property (klass,
2575 g_param_spec_int ("scroll-arrow-vlength",
2576 P_("Vertical Scroll Arrow Length"),
2577 P_("The length of vertical scroll arrows"),
2579 GTK_PARAM_READABLE));
2583 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2587 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2588 for (node = list; node; node = node->next)
2590 GParamSpec *pspec = node->data;
2592 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2593 g_param_spec_unref (pspec);
2599 gtk_widget_set_property (GObject *object,
2601 const GValue *value,
2604 GtkWidget *widget = GTK_WIDGET (object);
2609 gchar *tooltip_markup;
2610 const gchar *tooltip_text;
2611 GtkWindow *tooltip_window;
2614 gtk_widget_set_name (widget, g_value_get_string (value));
2617 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2619 case PROP_WIDTH_REQUEST:
2620 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2622 case PROP_HEIGHT_REQUEST:
2623 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2626 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2628 case PROP_SENSITIVE:
2629 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2631 case PROP_APP_PAINTABLE:
2632 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2634 case PROP_CAN_FOCUS:
2635 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2637 case PROP_HAS_FOCUS:
2638 if (g_value_get_boolean (value))
2639 gtk_widget_grab_focus (widget);
2642 if (g_value_get_boolean (value))
2643 gtk_widget_grab_focus (widget);
2645 case PROP_CAN_DEFAULT:
2646 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2648 case PROP_HAS_DEFAULT:
2649 if (g_value_get_boolean (value))
2650 gtk_widget_grab_default (widget);
2652 case PROP_RECEIVES_DEFAULT:
2653 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2656 gtk_widget_set_style (widget, g_value_get_object (value));
2659 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2660 gtk_widget_set_events (widget, g_value_get_flags (value));
2662 case PROP_EXTENSION_EVENTS:
2663 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2665 case PROP_NO_SHOW_ALL:
2666 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2668 case PROP_HAS_TOOLTIP:
2669 gtk_widget_real_set_has_tooltip (widget,
2670 g_value_get_boolean (value), FALSE);
2672 case PROP_TOOLTIP_MARKUP:
2673 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2674 tooltip_markup = g_value_dup_string (value);
2676 /* Treat an empty string as a NULL string,
2677 * because an empty string would be useless for a tooltip:
2679 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2681 g_free (tooltip_markup);
2682 tooltip_markup = NULL;
2685 g_object_set_qdata_full (object, quark_tooltip_markup,
2686 tooltip_markup, g_free);
2688 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2689 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2690 if (gtk_widget_get_visible (widget))
2691 gtk_widget_queue_tooltip_query (widget);
2693 case PROP_TOOLTIP_TEXT:
2694 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2696 tooltip_text = g_value_get_string (value);
2698 /* Treat an empty string as a NULL string,
2699 * because an empty string would be useless for a tooltip:
2701 if (tooltip_text && (strlen (tooltip_text) == 0))
2702 tooltip_text = NULL;
2704 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2706 g_object_set_qdata_full (object, quark_tooltip_markup,
2707 tooltip_markup, g_free);
2709 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2710 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2711 if (gtk_widget_get_visible (widget))
2712 gtk_widget_queue_tooltip_query (widget);
2714 case PROP_DOUBLE_BUFFERED:
2715 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2718 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2724 gtk_widget_get_property (GObject *object,
2729 GtkWidget *widget = GTK_WIDGET (object);
2738 g_value_set_string (value, widget->name);
2740 g_value_set_static_string (value, "");
2743 g_value_set_object (value, widget->parent);
2745 case PROP_WIDTH_REQUEST:
2748 gtk_widget_get_size_request (widget, &w, NULL);
2749 g_value_set_int (value, w);
2752 case PROP_HEIGHT_REQUEST:
2755 gtk_widget_get_size_request (widget, NULL, &h);
2756 g_value_set_int (value, h);
2760 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2762 case PROP_SENSITIVE:
2763 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2765 case PROP_APP_PAINTABLE:
2766 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2768 case PROP_CAN_FOCUS:
2769 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2771 case PROP_HAS_FOCUS:
2772 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2775 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2777 case PROP_CAN_DEFAULT:
2778 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2780 case PROP_HAS_DEFAULT:
2781 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2783 case PROP_RECEIVES_DEFAULT:
2784 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2786 case PROP_COMPOSITE_CHILD:
2787 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2790 g_value_set_object (value, gtk_widget_get_style (widget));
2793 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2794 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2796 case PROP_EXTENSION_EVENTS:
2797 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2798 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2800 case PROP_NO_SHOW_ALL:
2801 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2803 case PROP_HAS_TOOLTIP:
2804 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2806 case PROP_TOOLTIP_TEXT:
2808 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2811 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2812 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2814 g_value_take_string (value, text);
2817 case PROP_TOOLTIP_MARKUP:
2818 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2821 g_value_set_object (value, gtk_widget_get_window (widget));
2823 case PROP_DOUBLE_BUFFERED:
2824 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2827 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2833 gtk_widget_init (GtkWidget *widget)
2835 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2836 widget->state = GTK_STATE_NORMAL;
2837 widget->saved_state = GTK_STATE_NORMAL;
2838 widget->name = NULL;
2839 widget->requisition.width = 0;
2840 widget->requisition.height = 0;
2841 widget->allocation.x = -1;
2842 widget->allocation.y = -1;
2843 widget->allocation.width = 1;
2844 widget->allocation.height = 1;
2845 widget->window = NULL;
2846 widget->parent = NULL;
2848 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2849 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2850 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2851 gtk_widget_set_double_buffered (widget, TRUE);
2853 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2854 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2855 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
2856 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
2857 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2859 widget->style = gtk_widget_get_default_style ();
2860 g_object_ref (widget->style);
2865 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2867 GParamSpec **pspecs)
2869 GtkWidget *container = widget->parent;
2872 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2873 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2877 * gtk_widget_freeze_child_notify:
2878 * @widget: a #GtkWidget
2880 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2881 * signals are queued until gtk_widget_thaw_child_notify() is called
2884 * This is the analogue of g_object_freeze_notify() for child properties.
2887 gtk_widget_freeze_child_notify (GtkWidget *widget)
2889 g_return_if_fail (GTK_IS_WIDGET (widget));
2891 if (!G_OBJECT (widget)->ref_count)
2894 g_object_ref (widget);
2895 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2896 g_object_unref (widget);
2900 * gtk_widget_child_notify:
2901 * @widget: a #GtkWidget
2902 * @child_property: the name of a child property installed on the
2903 * class of @widget<!-- -->'s parent
2905 * Emits a #GtkWidget::child-notify signal for the
2906 * <link linkend="child-properties">child property</link> @child_property
2909 * This is the analogue of g_object_notify() for child properties.
2912 gtk_widget_child_notify (GtkWidget *widget,
2913 const gchar *child_property)
2917 g_return_if_fail (GTK_IS_WIDGET (widget));
2918 g_return_if_fail (child_property != NULL);
2919 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2922 g_object_ref (widget);
2923 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2925 G_OBJECT_TYPE (widget->parent),
2928 g_warning ("%s: container class `%s' has no child property named `%s'",
2930 G_OBJECT_TYPE_NAME (widget->parent),
2934 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2936 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2937 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2939 g_object_unref (widget);
2943 * gtk_widget_thaw_child_notify:
2944 * @widget: a #GtkWidget
2946 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2947 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2951 gtk_widget_thaw_child_notify (GtkWidget *widget)
2953 GObjectNotifyQueue *nqueue;
2955 g_return_if_fail (GTK_IS_WIDGET (widget));
2957 if (!G_OBJECT (widget)->ref_count)
2960 g_object_ref (widget);
2961 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2962 if (!nqueue || !nqueue->freeze_count)
2963 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2964 G_OBJECT_TYPE_NAME (widget), widget);
2966 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2967 g_object_unref (widget);
2973 * @type: type ID of the widget to create
2974 * @first_property_name: name of first property to set
2975 * @Varargs: value of first property, followed by more properties,
2978 * This is a convenience function for creating a widget and setting
2979 * its properties in one go. For example you might write:
2980 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2981 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2982 * g_object_new(), but returns a widget so you don't have to
2983 * cast the object yourself.
2985 * Return value: a new #GtkWidget of type @widget_type
2988 gtk_widget_new (GType type,
2989 const gchar *first_property_name,
2995 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2997 va_start (var_args, first_property_name);
2998 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3006 * @widget: a #GtkWidget
3007 * @first_property_name: name of first property to set
3008 * @Varargs: value of first property, followed by more properties,
3011 * Precursor of g_object_set().
3013 * Deprecated: 2.0: Use g_object_set() instead.
3016 gtk_widget_set (GtkWidget *widget,
3017 const gchar *first_property_name,
3022 g_return_if_fail (GTK_IS_WIDGET (widget));
3024 va_start (var_args, first_property_name);
3025 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3030 gtk_widget_queue_draw_child (GtkWidget *widget)
3034 parent = widget->parent;
3035 if (parent && gtk_widget_is_drawable (parent))
3036 gtk_widget_queue_draw_area (parent,
3037 widget->allocation.x,
3038 widget->allocation.y,
3039 widget->allocation.width,
3040 widget->allocation.height);
3044 * gtk_widget_unparent:
3045 * @widget: a #GtkWidget
3047 * This function is only for use in widget implementations.
3048 * Should be called by implementations of the remove method
3049 * on #GtkContainer, to dissociate a child from the container.
3052 gtk_widget_unparent (GtkWidget *widget)
3054 GObjectNotifyQueue *nqueue;
3055 GtkWidget *toplevel;
3056 GtkWidget *old_parent;
3058 g_return_if_fail (GTK_IS_WIDGET (widget));
3059 if (widget->parent == NULL)
3062 /* keep this function in sync with gtk_menu_detach()
3065 g_object_freeze_notify (G_OBJECT (widget));
3066 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3068 toplevel = gtk_widget_get_toplevel (widget);
3069 if (gtk_widget_is_toplevel (toplevel))
3070 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3072 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3073 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3075 /* If we are unanchoring the child, we save around the toplevel
3076 * to emit hierarchy changed
3078 if (GTK_WIDGET_ANCHORED (widget->parent))
3079 g_object_ref (toplevel);
3083 gtk_widget_queue_draw_child (widget);
3085 /* Reset the width and height here, to force reallocation if we
3086 * get added back to a new parent. This won't work if our new
3087 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3088 * (would 0x0 be OK here?)
3090 widget->allocation.width = 1;
3091 widget->allocation.height = 1;
3093 if (gtk_widget_get_realized (widget))
3095 if (GTK_WIDGET_IN_REPARENT (widget))
3096 gtk_widget_unmap (widget);
3098 gtk_widget_unrealize (widget);
3101 /* Removing a widget from a container restores the child visible
3102 * flag to the default state, so it doesn't affect the child
3103 * in the next parent.
3105 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3107 old_parent = widget->parent;
3108 widget->parent = NULL;
3109 gtk_widget_set_parent_window (widget, NULL);
3110 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3113 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3114 g_object_unref (toplevel);
3117 g_object_notify (G_OBJECT (widget), "parent");
3118 g_object_thaw_notify (G_OBJECT (widget));
3119 if (!widget->parent)
3120 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3121 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3122 g_object_unref (widget);
3126 * gtk_widget_destroy:
3127 * @widget: a #GtkWidget
3129 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3130 * you don't have to cast the widget to #GtkObject. When a widget is
3131 * destroyed, it will break any references it holds to other objects.
3132 * If the widget is inside a container, the widget will be removed
3133 * from the container. If the widget is a toplevel (derived from
3134 * #GtkWindow), it will be removed from the list of toplevels, and the
3135 * reference GTK+ holds to it will be removed. Removing a
3136 * widget from its container or the list of toplevels results in the
3137 * widget being finalized, unless you've added additional references
3138 * to the widget with g_object_ref().
3140 * In most cases, only toplevel widgets (windows) require explicit
3141 * destruction, because when you destroy a toplevel its children will
3142 * be destroyed as well.
3145 gtk_widget_destroy (GtkWidget *widget)
3147 g_return_if_fail (GTK_IS_WIDGET (widget));
3149 gtk_object_destroy ((GtkObject*) widget);
3153 * gtk_widget_destroyed:
3154 * @widget: a #GtkWidget
3155 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3157 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3158 * %NULL. It's intended to be used as a callback connected to the
3159 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3160 * as a signal handler, and pass the address of your widget variable
3161 * as user data. Then when the widget is destroyed, the variable will
3162 * be set to %NULL. Useful for example to avoid multiple copies
3163 * of the same dialog.
3166 gtk_widget_destroyed (GtkWidget *widget,
3167 GtkWidget **widget_pointer)
3169 /* Don't make any assumptions about the
3171 * Even check widget_pointer.
3174 *widget_pointer = NULL;
3179 * @widget: a #GtkWidget
3181 * Flags a widget to be displayed. Any widget that isn't shown will
3182 * not appear on the screen. If you want to show all the widgets in a
3183 * container, it's easier to call gtk_widget_show_all() on the
3184 * container, instead of individually showing the widgets.
3186 * Remember that you have to show the containers containing a widget,
3187 * in addition to the widget itself, before it will appear onscreen.
3189 * When a toplevel container is shown, it is immediately realized and
3190 * mapped; other shown widgets are realized and mapped when their
3191 * toplevel container is realized and mapped.
3194 gtk_widget_show (GtkWidget *widget)
3196 g_return_if_fail (GTK_IS_WIDGET (widget));
3198 if (!gtk_widget_get_visible (widget))
3200 g_object_ref (widget);
3201 if (!gtk_widget_is_toplevel (widget))
3202 gtk_widget_queue_resize (widget);
3203 g_signal_emit (widget, widget_signals[SHOW], 0);
3204 g_object_notify (G_OBJECT (widget), "visible");
3205 g_object_unref (widget);
3210 gtk_widget_real_show (GtkWidget *widget)
3212 if (!gtk_widget_get_visible (widget))
3214 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3216 if (widget->parent &&
3217 gtk_widget_get_mapped (widget->parent) &&
3218 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3219 !gtk_widget_get_mapped (widget))
3220 gtk_widget_map (widget);
3225 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3228 g_signal_handlers_disconnect_by_func (widget,
3229 gtk_widget_show_map_callback,
3234 * gtk_widget_show_now:
3235 * @widget: a #GtkWidget
3237 * Shows a widget. If the widget is an unmapped toplevel widget
3238 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3239 * loop and wait for the window to actually be mapped. Be careful;
3240 * because the main loop is running, anything can happen during
3244 gtk_widget_show_now (GtkWidget *widget)
3248 g_return_if_fail (GTK_IS_WIDGET (widget));
3250 /* make sure we will get event */
3251 if (!gtk_widget_get_mapped (widget) &&
3252 gtk_widget_is_toplevel (widget))
3254 gtk_widget_show (widget);
3256 g_signal_connect (widget, "map-event",
3257 G_CALLBACK (gtk_widget_show_map_callback),
3261 gtk_main_iteration ();
3264 gtk_widget_show (widget);
3269 * @widget: a #GtkWidget
3271 * Reverses the effects of gtk_widget_show(), causing the widget to be
3272 * hidden (invisible to the user).
3275 gtk_widget_hide (GtkWidget *widget)
3277 g_return_if_fail (GTK_IS_WIDGET (widget));
3279 if (gtk_widget_get_visible (widget))
3281 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3283 g_object_ref (widget);
3284 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3285 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3287 g_signal_emit (widget, widget_signals[HIDE], 0);
3288 if (!gtk_widget_is_toplevel (widget))
3289 gtk_widget_queue_resize (widget);
3290 g_object_notify (G_OBJECT (widget), "visible");
3291 g_object_unref (widget);
3296 gtk_widget_real_hide (GtkWidget *widget)
3298 if (gtk_widget_get_visible (widget))
3300 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3302 if (gtk_widget_get_mapped (widget))
3303 gtk_widget_unmap (widget);
3308 * gtk_widget_hide_on_delete:
3309 * @widget: a #GtkWidget
3311 * Utility function; intended to be connected to the #GtkWidget::delete-event
3312 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3313 * argument, then returns %TRUE. If connected to ::delete-event, the
3314 * result is that clicking the close button for a window (on the
3315 * window frame, top right corner usually) will hide but not destroy
3316 * the window. By default, GTK+ destroys windows when ::delete-event
3319 * Return value: %TRUE
3322 gtk_widget_hide_on_delete (GtkWidget *widget)
3324 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3326 gtk_widget_hide (widget);
3332 * gtk_widget_show_all:
3333 * @widget: a #GtkWidget
3335 * Recursively shows a widget, and any child widgets (if the widget is
3339 gtk_widget_show_all (GtkWidget *widget)
3341 GtkWidgetClass *class;
3343 g_return_if_fail (GTK_IS_WIDGET (widget));
3345 if (gtk_widget_get_no_show_all (widget))
3348 class = GTK_WIDGET_GET_CLASS (widget);
3350 if (class->show_all)
3351 class->show_all (widget);
3355 * gtk_widget_hide_all:
3356 * @widget: a #GtkWidget
3358 * Recursively hides a widget and any child widgets.
3361 gtk_widget_hide_all (GtkWidget *widget)
3363 GtkWidgetClass *class;
3365 g_return_if_fail (GTK_IS_WIDGET (widget));
3367 if (gtk_widget_get_no_show_all (widget))
3370 class = GTK_WIDGET_GET_CLASS (widget);
3372 if (class->hide_all)
3373 class->hide_all (widget);
3378 * @widget: a #GtkWidget
3380 * This function is only for use in widget implementations. Causes
3381 * a widget to be mapped if it isn't already.
3384 gtk_widget_map (GtkWidget *widget)
3386 g_return_if_fail (GTK_IS_WIDGET (widget));
3387 g_return_if_fail (gtk_widget_get_visible (widget));
3388 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3390 if (!gtk_widget_get_mapped (widget))
3392 if (!gtk_widget_get_realized (widget))
3393 gtk_widget_realize (widget);
3395 g_signal_emit (widget, widget_signals[MAP], 0);
3397 if (!gtk_widget_get_has_window (widget))
3398 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3404 * @widget: a #GtkWidget
3406 * This function is only for use in widget implementations. Causes
3407 * a widget to be unmapped if it's currently mapped.
3410 gtk_widget_unmap (GtkWidget *widget)
3412 g_return_if_fail (GTK_IS_WIDGET (widget));
3414 if (gtk_widget_get_mapped (widget))
3416 if (!gtk_widget_get_has_window (widget))
3417 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3418 _gtk_tooltip_hide (widget);
3419 g_signal_emit (widget, widget_signals[UNMAP], 0);
3424 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3425 GdkExtensionMode mode,
3428 GList *free_list = NULL;
3431 if (window_list == NULL)
3433 if (gtk_widget_get_has_window (widget))
3434 window_list = g_list_prepend (NULL, widget->window);
3436 window_list = gdk_window_get_children (widget->window);
3438 free_list = window_list;
3441 for (l = window_list; l != NULL; l = l->next)
3443 GdkWindow *window = l->data;
3446 gdk_window_get_user_data (window, &user_data);
3447 if (user_data == widget)
3451 gdk_input_set_extension_events (window,
3452 gdk_window_get_events (window),
3455 children = gdk_window_get_children (window);
3458 gtk_widget_set_extension_events_internal (widget, mode, children);
3459 g_list_free (children);
3465 g_list_free (free_list);
3469 * gtk_widget_realize:
3470 * @widget: a #GtkWidget
3472 * Creates the GDK (windowing system) resources associated with a
3473 * widget. For example, @widget->window will be created when a widget
3474 * is realized. Normally realization happens implicitly; if you show
3475 * a widget and all its parent containers, then the widget will be
3476 * realized and mapped automatically.
3478 * Realizing a widget requires all
3479 * the widget's parent widgets to be realized; calling
3480 * gtk_widget_realize() realizes the widget's parents in addition to
3481 * @widget itself. If a widget is not yet inside a toplevel window
3482 * when you realize it, bad things will happen.
3484 * This function is primarily used in widget implementations, and
3485 * isn't very useful otherwise. Many times when you think you might
3486 * need it, a better approach is to connect to a signal that will be
3487 * called after the widget is realized automatically, such as
3488 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3489 * GtkWidget::realize signal.
3492 gtk_widget_realize (GtkWidget *widget)
3494 GdkExtensionMode mode;
3495 GtkWidgetShapeInfo *shape_info;
3497 g_return_if_fail (GTK_IS_WIDGET (widget));
3498 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3499 GTK_IS_INVISIBLE (widget));
3501 if (!gtk_widget_get_realized (widget))
3504 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3505 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3508 if (widget->parent == NULL &&
3509 !gtk_widget_is_toplevel (widget))
3510 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3511 "inside a toplevel window is not going to work very well. "
3512 "Widgets must be inside a toplevel container before realizing them.");
3514 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3515 gtk_widget_realize (widget->parent);
3517 gtk_widget_ensure_style (widget);
3519 g_signal_emit (widget, widget_signals[REALIZE], 0);
3521 gtk_widget_real_set_has_tooltip (widget,
3522 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3525 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3527 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3528 gdk_window_shape_combine_mask (widget->window,
3529 shape_info->shape_mask,
3530 shape_info->offset_x,
3531 shape_info->offset_y);
3534 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3536 gdk_window_input_shape_combine_mask (widget->window,
3537 shape_info->shape_mask,
3538 shape_info->offset_x,
3539 shape_info->offset_y);
3541 mode = gtk_widget_get_extension_events (widget);
3542 if (mode != GDK_EXTENSION_EVENTS_NONE)
3543 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3548 * gtk_widget_unrealize:
3549 * @widget: a #GtkWidget
3551 * This function is only useful in widget implementations.
3552 * Causes a widget to be unrealized (frees all GDK resources
3553 * associated with the widget, such as @widget->window).
3556 gtk_widget_unrealize (GtkWidget *widget)
3558 g_return_if_fail (GTK_IS_WIDGET (widget));
3560 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3561 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3563 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3564 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3566 if (gtk_widget_get_realized (widget))
3568 g_object_ref (widget);
3569 _gtk_tooltip_hide (widget);
3570 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3571 gtk_widget_set_realized (widget, FALSE);
3572 gtk_widget_set_mapped (widget, FALSE);
3573 g_object_unref (widget);
3577 /*****************************************
3579 *****************************************/
3582 * gtk_widget_queue_draw_area:
3583 * @widget: a #GtkWidget
3584 * @x: x coordinate of upper-left corner of rectangle to redraw
3585 * @y: y coordinate of upper-left corner of rectangle to redraw
3586 * @width: width of region to draw
3587 * @height: height of region to draw
3589 * Invalidates the rectangular area of @widget defined by @x, @y,
3590 * @width and @height by calling gdk_window_invalidate_rect() on the
3591 * widget's window and all its child windows. Once the main loop
3592 * becomes idle (after the current batch of events has been processed,
3593 * roughly), the window will receive expose events for the union of
3594 * all regions that have been invalidated.
3596 * Normally you would only use this function in widget
3597 * implementations. You might also use it, or
3598 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3599 * #GtkDrawingArea or some portion thereof.
3601 * Frequently you can just call gdk_window_invalidate_rect() or
3602 * gdk_window_invalidate_region() instead of this function. Those
3603 * functions will invalidate only a single window, instead of the
3604 * widget and all its children.
3606 * The advantage of adding to the invalidated region compared to
3607 * simply drawing immediately is efficiency; using an invalid region
3608 * ensures that you only have to redraw one time.
3611 gtk_widget_queue_draw_area (GtkWidget *widget,
3617 GdkRectangle invalid_rect;
3620 g_return_if_fail (GTK_IS_WIDGET (widget));
3622 if (!gtk_widget_get_realized (widget))
3625 /* Just return if the widget or one of its ancestors isn't mapped */
3626 for (w = widget; w != NULL; w = w->parent)
3627 if (!gtk_widget_get_mapped (w))
3630 /* Find the correct widget */
3632 if (gtk_widget_get_has_window (widget))
3636 /* Translate widget relative to window-relative */
3638 gint wx, wy, wwidth, wheight;
3640 gdk_window_get_position (widget->window, &wx, &wy);
3641 x -= wx - widget->allocation.x;
3642 y -= wy - widget->allocation.y;
3644 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3646 if (x + width <= 0 || y + height <= 0 ||
3647 x >= wwidth || y >= wheight)
3658 if (x + width > wwidth)
3660 if (y + height > wheight)
3661 height = wheight - y;
3667 invalid_rect.width = width;
3668 invalid_rect.height = height;
3670 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3674 widget_add_child_draw_rectangle (GtkWidget *widget,
3677 GdkRectangle child_rect;
3679 if (!gtk_widget_get_mapped (widget) ||
3680 widget->window != widget->parent->window)
3683 gtk_widget_get_draw_rectangle (widget, &child_rect);
3684 gdk_rectangle_union (rect, &child_rect, rect);
3688 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3691 if (!gtk_widget_get_has_window (widget))
3693 GtkBorder *draw_border = NULL;
3695 *rect = widget->allocation;
3697 gtk_widget_style_get (widget,
3698 "draw-border", &draw_border,
3702 rect->x -= draw_border->left;
3703 rect->y -= draw_border->top;
3704 rect->width += draw_border->left + draw_border->right;
3705 rect->height += draw_border->top + draw_border->bottom;
3707 gtk_border_free (draw_border);
3710 if (GTK_IS_CONTAINER (widget))
3711 gtk_container_forall (GTK_CONTAINER (widget),
3712 (GtkCallback)widget_add_child_draw_rectangle,
3719 rect->width = widget->allocation.width;
3720 rect->height = widget->allocation.height;
3725 * gtk_widget_queue_draw:
3726 * @widget: a #GtkWidget
3728 * Equivalent to calling gtk_widget_queue_draw_area() for the
3729 * entire area of a widget.
3732 gtk_widget_queue_draw (GtkWidget *widget)
3736 g_return_if_fail (GTK_IS_WIDGET (widget));
3738 gtk_widget_get_draw_rectangle (widget, &rect);
3740 gtk_widget_queue_draw_area (widget,
3742 rect.width, rect.height);
3745 /* Invalidates the given area (allocation-relative-coordinates)
3746 * in all of the widget's windows
3749 * gtk_widget_queue_clear_area:
3750 * @widget: a #GtkWidget
3751 * @x: x coordinate of upper-left corner of rectangle to redraw
3752 * @y: y coordinate of upper-left corner of rectangle to redraw
3753 * @width: width of region to draw
3754 * @height: height of region to draw
3756 * This function is no longer different from
3757 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3758 * gtk_widget_queue_draw_area(). Originally
3759 * gtk_widget_queue_clear_area() would force a redraw of the
3760 * background for %GTK_NO_WINDOW widgets, and
3761 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3762 * the background will be redrawn.
3764 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3767 gtk_widget_queue_clear_area (GtkWidget *widget,
3773 g_return_if_fail (GTK_IS_WIDGET (widget));
3775 gtk_widget_queue_draw_area (widget, x, y, width, height);
3779 * gtk_widget_queue_clear:
3780 * @widget: a #GtkWidget
3782 * This function does the same as gtk_widget_queue_draw().
3784 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3787 gtk_widget_queue_clear (GtkWidget *widget)
3789 g_return_if_fail (GTK_IS_WIDGET (widget));
3791 gtk_widget_queue_draw (widget);
3795 * gtk_widget_queue_resize:
3796 * @widget: a #GtkWidget
3798 * This function is only for use in widget implementations.
3799 * Flags a widget to have its size renegotiated; should
3800 * be called when a widget for some reason has a new size request.
3801 * For example, when you change the text in a #GtkLabel, #GtkLabel
3802 * queues a resize to ensure there's enough space for the new text.
3805 gtk_widget_queue_resize (GtkWidget *widget)
3807 g_return_if_fail (GTK_IS_WIDGET (widget));
3809 if (gtk_widget_get_realized (widget))
3810 gtk_widget_queue_shallow_draw (widget);
3812 _gtk_size_group_queue_resize (widget);
3816 * gtk_widget_queue_resize_no_redraw:
3817 * @widget: a #GtkWidget
3819 * This function works like gtk_widget_queue_resize(),
3820 * except that the widget is not invalidated.
3825 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3827 g_return_if_fail (GTK_IS_WIDGET (widget));
3829 _gtk_size_group_queue_resize (widget);
3834 * @widget: a #GtkWidget
3835 * @area: area to draw
3837 * In GTK+ 1.2, this function would immediately render the
3838 * region @area of a widget, by invoking the virtual draw method of a
3839 * widget. In GTK+ 2.0, the draw method is gone, and instead
3840 * gtk_widget_draw() simply invalidates the specified region of the
3841 * widget, then updates the invalid region of the widget immediately.
3842 * Usually you don't want to update the region immediately for
3843 * performance reasons, so in general gtk_widget_queue_draw_area() is
3844 * a better choice if you want to draw a region of a widget.
3847 gtk_widget_draw (GtkWidget *widget,
3848 const GdkRectangle *area)
3850 g_return_if_fail (GTK_IS_WIDGET (widget));
3852 if (gtk_widget_is_drawable (widget))
3855 gtk_widget_queue_draw_area (widget,
3857 area->width, area->height);
3859 gtk_widget_queue_draw (widget);
3861 gdk_window_process_updates (widget->window, TRUE);
3866 * gtk_widget_size_request:
3867 * @widget: a #GtkWidget
3868 * @requisition: a #GtkRequisition to be filled in
3870 * This function is typically used when implementing a #GtkContainer
3871 * subclass. Obtains the preferred size of a widget. The container
3872 * uses this information to arrange its child widgets and decide what
3873 * size allocations to give them with gtk_widget_size_allocate().
3875 * You can also call this function from an application, with some
3876 * caveats. Most notably, getting a size request requires the widget
3877 * to be associated with a screen, because font information may be
3878 * needed. Multihead-aware applications should keep this in mind.
3880 * Also remember that the size request is not necessarily the size
3881 * a widget will actually be allocated.
3883 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3886 gtk_widget_size_request (GtkWidget *widget,
3887 GtkRequisition *requisition)
3889 g_return_if_fail (GTK_IS_WIDGET (widget));
3891 #ifdef G_ENABLE_DEBUG
3892 if (requisition == &widget->requisition)
3893 g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
3894 "to widget->requisition. gtk_widget_set_usize() may not work properly.");
3895 #endif /* G_ENABLE_DEBUG */
3897 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget), requisition, NULL);
3901 * gtk_widget_get_child_requisition:
3902 * @widget: a #GtkWidget
3903 * @requisition: a #GtkRequisition to be filled in
3905 * This function is only for use in widget implementations. Obtains
3906 * @widget->requisition, unless someone has forced a particular
3907 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3908 * in which case it returns that geometry instead of the widget's
3911 * This function differs from gtk_widget_size_request() in that
3912 * it retrieves the last size request value from @widget->requisition,
3913 * while gtk_widget_size_request() actually calls the "size_request" method
3914 * on @widget to compute the size request and fill in @widget->requisition,
3915 * and only then returns @widget->requisition.
3917 * Because this function does not call the "size_request" method, it
3918 * can only be used when you know that @widget->requisition is
3919 * up-to-date, that is, gtk_widget_size_request() has been called
3920 * since the last time a resize was queued. In general, only container
3921 * implementations have this information; applications should use
3922 * gtk_widget_size_request().
3925 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3928 gtk_widget_get_child_requisition (GtkWidget *widget,
3929 GtkRequisition *requisition)
3931 _gtk_size_group_get_child_requisition (widget, requisition);
3935 invalidate_predicate (GdkWindow *window,
3940 gdk_window_get_user_data (window, &user_data);
3942 return (user_data == data);
3945 /* Invalidate @region in widget->window and all children
3946 * of widget->window owned by widget. @region is in the
3947 * same coordinates as widget->allocation and will be
3948 * modified by this call.
3951 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3954 if (!gtk_widget_get_realized (widget))
3957 if (gtk_widget_get_has_window (widget) && widget->parent)
3961 gdk_window_get_position (widget->window, &x, &y);
3962 gdk_region_offset (region, -x, -y);
3965 gdk_window_invalidate_maybe_recurse (widget->window, region,
3966 invalidate_predicate, widget);
3970 * gtk_widget_queue_shallow_draw:
3971 * @widget: a #GtkWidget
3973 * Like gtk_widget_queue_draw(), but only windows owned
3974 * by @widget are invalidated.
3977 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3982 if (!gtk_widget_get_realized (widget))
3985 gtk_widget_get_draw_rectangle (widget, &rect);
3987 /* get_draw_rectangle() gives us window coordinates, we
3988 * need to convert to the coordinates that widget->allocation
3991 if (gtk_widget_get_has_window (widget) && widget->parent)
3995 gdk_window_get_position (widget->window, &wx, &wy);
4001 region = gdk_region_rectangle (&rect);
4002 gtk_widget_invalidate_widget_windows (widget, region);
4003 gdk_region_destroy (region);
4007 * gtk_widget_size_allocate:
4008 * @widget: a #GtkWidget
4009 * @allocation: position and size to be allocated to @widget
4011 * This function is only used by #GtkContainer subclasses, to assign a size
4012 * and position to their child widgets.
4015 gtk_widget_size_allocate (GtkWidget *widget,
4016 GtkAllocation *allocation)
4018 GtkWidgetAuxInfo *aux_info;
4019 GdkRectangle real_allocation;
4020 GdkRectangle old_allocation;
4021 gboolean alloc_needed;
4022 gboolean size_changed;
4023 gboolean position_changed;
4025 g_return_if_fail (GTK_IS_WIDGET (widget));
4027 #ifdef G_ENABLE_DEBUG
4028 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4039 parent = gtk_widget_get_parent (parent);
4042 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4043 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4044 2 * depth, " ", name,
4045 allocation->width, allocation->height);
4047 #endif /* G_ENABLE_DEBUG */
4049 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4050 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4051 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4053 old_allocation = widget->allocation;
4054 real_allocation = *allocation;
4055 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4059 if (aux_info->x_set)
4060 real_allocation.x = aux_info->x;
4061 if (aux_info->y_set)
4062 real_allocation.y = aux_info->y;
4065 if (real_allocation.width < 0 || real_allocation.height < 0)
4067 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4068 real_allocation.width,
4069 real_allocation.height);
4072 real_allocation.width = MAX (real_allocation.width, 1);
4073 real_allocation.height = MAX (real_allocation.height, 1);
4075 size_changed = (old_allocation.width != real_allocation.width ||
4076 old_allocation.height != real_allocation.height);
4077 position_changed = (old_allocation.x != real_allocation.x ||
4078 old_allocation.y != real_allocation.y);
4080 if (!alloc_needed && !size_changed && !position_changed)
4083 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4085 if (gtk_widget_get_mapped (widget))
4087 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4089 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4091 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4092 gdk_region_union_with_rect (invalidate, &old_allocation);
4094 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4095 gdk_region_destroy (invalidate);
4100 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4102 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4104 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4105 gdk_region_union_with_rect (invalidate, &old_allocation);
4107 gtk_widget_invalidate_widget_windows (widget, invalidate);
4108 gdk_region_destroy (invalidate);
4113 if ((size_changed || position_changed) && widget->parent &&
4114 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4116 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4117 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4118 gdk_region_destroy (invalidate);
4123 * gtk_widget_common_ancestor:
4124 * @widget_a: a #GtkWidget
4125 * @widget_b: a #GtkWidget
4127 * Find the common ancestor of @widget_a and @widget_b that
4128 * is closest to the two widgets.
4130 * Return value: the closest common ancestor of @widget_a and
4131 * @widget_b or %NULL if @widget_a and @widget_b do not
4132 * share a common ancestor.
4135 gtk_widget_common_ancestor (GtkWidget *widget_a,
4136 GtkWidget *widget_b)
4138 GtkWidget *parent_a;
4139 GtkWidget *parent_b;
4143 parent_a = widget_a;
4144 while (parent_a->parent)
4146 parent_a = parent_a->parent;
4150 parent_b = widget_b;
4151 while (parent_b->parent)
4153 parent_b = parent_b->parent;
4157 if (parent_a != parent_b)
4160 while (depth_a > depth_b)
4162 widget_a = widget_a->parent;
4166 while (depth_b > depth_a)
4168 widget_b = widget_b->parent;
4172 while (widget_a != widget_b)
4174 widget_a = widget_a->parent;
4175 widget_b = widget_b->parent;
4182 * gtk_widget_translate_coordinates:
4183 * @src_widget: a #GtkWidget
4184 * @dest_widget: a #GtkWidget
4185 * @src_x: X position relative to @src_widget
4186 * @src_y: Y position relative to @src_widget
4187 * @dest_x: (out): location to store X position relative to @dest_widget
4188 * @dest_y: (out): location to store Y position relative to @dest_widget
4190 * Translate coordinates relative to @src_widget's allocation to coordinates
4191 * relative to @dest_widget's allocations. In order to perform this
4192 * operation, both widgets must be realized, and must share a common
4195 * Return value: %FALSE if either widget was not realized, or there
4196 * was no common ancestor. In this case, nothing is stored in
4197 * *@dest_x and *@dest_y. Otherwise %TRUE.
4200 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4201 GtkWidget *dest_widget,
4207 GtkWidget *ancestor;
4210 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4211 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4213 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4214 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4217 /* Translate from allocation relative to window relative */
4218 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4221 gdk_window_get_position (src_widget->window, &wx, &wy);
4223 src_x -= wx - src_widget->allocation.x;
4224 src_y -= wy - src_widget->allocation.y;
4228 src_x += src_widget->allocation.x;
4229 src_y += src_widget->allocation.y;
4232 /* Translate to the common ancestor */
4233 window = src_widget->window;
4234 while (window != ancestor->window)
4238 gdk_window_get_position (window, &dx, &dy);
4243 window = gdk_window_get_parent (window);
4245 if (!window) /* Handle GtkHandleBox */
4250 window = dest_widget->window;
4251 while (window != ancestor->window)
4255 gdk_window_get_position (window, &dx, &dy);
4260 window = gdk_window_get_parent (window);
4262 if (!window) /* Handle GtkHandleBox */
4266 /* Translate from window relative to allocation relative */
4267 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4270 gdk_window_get_position (dest_widget->window, &wx, &wy);
4272 src_x += wx - dest_widget->allocation.x;
4273 src_y += wy - dest_widget->allocation.y;
4277 src_x -= dest_widget->allocation.x;
4278 src_y -= dest_widget->allocation.y;
4290 gtk_widget_real_size_allocate (GtkWidget *widget,
4291 GtkAllocation *allocation)
4293 widget->allocation = *allocation;
4295 if (gtk_widget_get_realized (widget) &&
4296 gtk_widget_get_has_window (widget))
4298 gdk_window_move_resize (widget->window,
4299 allocation->x, allocation->y,
4300 allocation->width, allocation->height);
4305 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4308 /* widgets must be onscreen for accels to take effect */
4309 return gtk_widget_is_sensitive (widget) &&
4310 gtk_widget_is_drawable (widget) &&
4311 gdk_window_is_viewable (widget->window);
4315 * gtk_widget_can_activate_accel:
4316 * @widget: a #GtkWidget
4317 * @signal_id: the ID of a signal installed on @widget
4319 * Determines whether an accelerator that activates the signal
4320 * identified by @signal_id can currently be activated.
4321 * This is done by emitting the #GtkWidget::can-activate-accel
4322 * signal on @widget; if the signal isn't overridden by a
4323 * handler or in a derived widget, then the default check is
4324 * that the widget must be sensitive, and the widget and all
4325 * its ancestors mapped.
4327 * Return value: %TRUE if the accelerator can be activated.
4332 gtk_widget_can_activate_accel (GtkWidget *widget,
4335 gboolean can_activate = FALSE;
4336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4337 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4338 return can_activate;
4347 closure_accel_activate (GClosure *closure,
4348 GValue *return_value,
4349 guint n_param_values,
4350 const GValue *param_values,
4351 gpointer invocation_hint,
4352 gpointer marshal_data)
4354 AccelClosure *aclosure = (AccelClosure*) closure;
4355 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4358 g_signal_emit (closure->data, aclosure->signal_id, 0);
4360 /* whether accelerator was handled */
4361 g_value_set_boolean (return_value, can_activate);
4365 closures_destroy (gpointer data)
4367 GSList *slist, *closures = data;
4369 for (slist = closures; slist; slist = slist->next)
4371 g_closure_invalidate (slist->data);
4372 g_closure_unref (slist->data);
4374 g_slist_free (closures);
4378 widget_new_accel_closure (GtkWidget *widget,
4381 AccelClosure *aclosure;
4382 GClosure *closure = NULL;
4383 GSList *slist, *closures;
4385 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4386 for (slist = closures; slist; slist = slist->next)
4387 if (!gtk_accel_group_from_accel_closure (slist->data))
4389 /* reuse this closure */
4390 closure = slist->data;
4395 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4396 closures = g_slist_prepend (closures, g_closure_ref (closure));
4397 g_closure_sink (closure);
4398 g_closure_set_marshal (closure, closure_accel_activate);
4400 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4402 aclosure = (AccelClosure*) closure;
4403 g_assert (closure->data == widget);
4404 g_assert (closure->marshal == closure_accel_activate);
4405 aclosure->signal_id = signal_id;
4411 * gtk_widget_add_accelerator
4412 * @widget: widget to install an accelerator on
4413 * @accel_signal: widget signal to emit on accelerator activation
4414 * @accel_group: accel group for this widget, added to its toplevel
4415 * @accel_key: GDK keyval of the accelerator
4416 * @accel_mods: modifier key combination of the accelerator
4417 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4419 * Installs an accelerator for this @widget in @accel_group that causes
4420 * @accel_signal to be emitted if the accelerator is activated.
4421 * The @accel_group needs to be added to the widget's toplevel via
4422 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4423 * Accelerators added through this function are not user changeable during
4424 * runtime. If you want to support accelerators that can be changed by the
4425 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4426 * gtk_menu_item_set_accel_path() instead.
4429 gtk_widget_add_accelerator (GtkWidget *widget,
4430 const gchar *accel_signal,
4431 GtkAccelGroup *accel_group,
4433 GdkModifierType accel_mods,
4434 GtkAccelFlags accel_flags)
4439 g_return_if_fail (GTK_IS_WIDGET (widget));
4440 g_return_if_fail (accel_signal != NULL);
4441 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4443 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4444 if (!query.signal_id ||
4445 !(query.signal_flags & G_SIGNAL_ACTION) ||
4446 query.return_type != G_TYPE_NONE ||
4449 /* hmm, should be elaborate enough */
4450 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4451 G_OBJECT_TYPE_NAME (widget), accel_signal);
4455 closure = widget_new_accel_closure (widget, query.signal_id);
4457 g_object_ref (widget);
4459 /* install the accelerator. since we don't map this onto an accel_path,
4460 * the accelerator will automatically be locked.
4462 gtk_accel_group_connect (accel_group,
4465 accel_flags | GTK_ACCEL_LOCKED,
4468 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4470 g_object_unref (widget);
4474 * gtk_widget_remove_accelerator:
4475 * @widget: widget to install an accelerator on
4476 * @accel_group: accel group for this widget
4477 * @accel_key: GDK keyval of the accelerator
4478 * @accel_mods: modifier key combination of the accelerator
4479 * @returns: whether an accelerator was installed and could be removed
4481 * Removes an accelerator from @widget, previously installed with
4482 * gtk_widget_add_accelerator().
4485 gtk_widget_remove_accelerator (GtkWidget *widget,
4486 GtkAccelGroup *accel_group,
4488 GdkModifierType accel_mods)
4490 GtkAccelGroupEntry *ag_entry;
4491 GList *slist, *clist;
4494 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4495 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4497 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4498 clist = gtk_widget_list_accel_closures (widget);
4499 for (slist = clist; slist; slist = slist->next)
4503 for (i = 0; i < n; i++)
4504 if (slist->data == (gpointer) ag_entry[i].closure)
4506 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4508 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4510 g_list_free (clist);
4515 g_list_free (clist);
4517 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4518 accel_key, accel_mods, accel_group,
4519 G_OBJECT_TYPE_NAME (widget), widget);
4525 * gtk_widget_list_accel_closures
4526 * @widget: widget to list accelerator closures for
4527 * @returns: a newly allocated #GList of closures
4529 * Lists the closures used by @widget for accelerator group connections
4530 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4531 * The closures can be used to monitor accelerator changes on @widget,
4532 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4533 * #GtkAccelGroup of a closure which can be found out with
4534 * gtk_accel_group_from_accel_closure().
4537 gtk_widget_list_accel_closures (GtkWidget *widget)
4540 GList *clist = NULL;
4542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4544 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4545 if (gtk_accel_group_from_accel_closure (slist->data))
4546 clist = g_list_prepend (clist, slist->data);
4552 GtkAccelGroup *accel_group;
4557 destroy_accel_path (gpointer data)
4559 AccelPath *apath = data;
4561 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4563 /* closures_destroy takes care of unrefing the closure */
4564 g_object_unref (apath->accel_group);
4566 g_slice_free (AccelPath, apath);
4571 * gtk_widget_set_accel_path:
4572 * @widget: a #GtkWidget
4573 * @accel_path: (allow-none): path used to look up the accelerator
4574 * @accel_group: (allow-none): a #GtkAccelGroup.
4576 * Given an accelerator group, @accel_group, and an accelerator path,
4577 * @accel_path, sets up an accelerator in @accel_group so whenever the
4578 * key binding that is defined for @accel_path is pressed, @widget
4579 * will be activated. This removes any accelerators (for any
4580 * accelerator group) installed by previous calls to
4581 * gtk_widget_set_accel_path(). Associating accelerators with
4582 * paths allows them to be modified by the user and the modifications
4583 * to be saved for future use. (See gtk_accel_map_save().)
4585 * This function is a low level function that would most likely
4586 * be used by a menu creation system like #GtkUIManager. If you
4587 * use #GtkUIManager, setting up accelerator paths will be done
4590 * Even when you you aren't using #GtkUIManager, if you only want to
4591 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4592 * provides a somewhat more convenient interface.
4594 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4595 * pass a static string, you can save some memory by interning it first with
4596 * g_intern_static_string().
4599 gtk_widget_set_accel_path (GtkWidget *widget,
4600 const gchar *accel_path,
4601 GtkAccelGroup *accel_group)
4605 g_return_if_fail (GTK_IS_WIDGET (widget));
4606 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4610 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4611 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4613 gtk_accel_map_add_entry (accel_path, 0, 0);
4614 apath = g_slice_new (AccelPath);
4615 apath->accel_group = g_object_ref (accel_group);
4616 apath->path_quark = g_quark_from_string (accel_path);
4617 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4622 /* also removes possible old settings */
4623 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4626 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4628 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4632 _gtk_widget_get_accel_path (GtkWidget *widget,
4637 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4639 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4641 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4642 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4646 * gtk_widget_mnemonic_activate:
4647 * @widget: a #GtkWidget
4648 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4650 * Emits the #GtkWidget::mnemonic-activate signal.
4652 * The default handler for this signal activates the @widget if
4653 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4656 * Returns: %TRUE if the signal has been handled
4659 gtk_widget_mnemonic_activate (GtkWidget *widget,
4660 gboolean group_cycling)
4664 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4666 group_cycling = group_cycling != FALSE;
4667 if (!gtk_widget_is_sensitive (widget))
4670 g_signal_emit (widget,
4671 widget_signals[MNEMONIC_ACTIVATE],
4679 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4680 gboolean group_cycling)
4682 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4683 gtk_widget_activate (widget);
4684 else if (gtk_widget_get_can_focus (widget))
4685 gtk_widget_grab_focus (widget);
4688 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4689 G_OBJECT_TYPE_NAME (widget));
4690 gtk_widget_error_bell (widget);
4696 gtk_widget_real_key_press_event (GtkWidget *widget,
4699 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4703 gtk_widget_real_key_release_event (GtkWidget *widget,
4706 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4710 gtk_widget_real_focus_in_event (GtkWidget *widget,
4711 GdkEventFocus *event)
4713 gtk_widget_queue_shallow_draw (widget);
4719 gtk_widget_real_focus_out_event (GtkWidget *widget,
4720 GdkEventFocus *event)
4722 gtk_widget_queue_shallow_draw (widget);
4727 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4728 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4732 * @widget: a #GtkWidget
4733 * @event: a #GdkEvent
4735 * Rarely-used function. This function is used to emit
4736 * the event signals on a widget (those signals should never
4737 * be emitted without using this function to do so).
4738 * If you want to synthesize an event though, don't use this function;
4739 * instead, use gtk_main_do_event() so the event will behave as if
4740 * it were in the event queue. Don't synthesize expose events; instead,
4741 * use gdk_window_invalidate_rect() to invalidate a region of the
4744 * Return value: return from the event signal emission (%TRUE if
4745 * the event was handled)
4748 gtk_widget_event (GtkWidget *widget,
4751 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4752 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4754 if (event->type == GDK_EXPOSE)
4756 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4757 "the same effect, call gdk_window_invalidate_rect/region(), "
4758 "followed by gdk_window_process_updates().");
4762 return gtk_widget_event_internal (widget, event);
4767 * gtk_widget_send_expose:
4768 * @widget: a #GtkWidget
4769 * @event: a expose #GdkEvent
4771 * Very rarely-used function. This function is used to emit
4772 * an expose event signals on a widget. This function is not
4773 * normally used directly. The only time it is used is when
4774 * propagating an expose event to a child %NO_WINDOW widget, and
4775 * that is normally done using gtk_container_propagate_expose().
4777 * If you want to force an area of a window to be redrawn,
4778 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4779 * To cause the redraw to be done immediately, follow that call
4780 * with a call to gdk_window_process_updates().
4782 * Return value: return from the event signal emission (%TRUE if
4783 * the event was handled)
4786 gtk_widget_send_expose (GtkWidget *widget,
4789 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4790 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4791 g_return_val_if_fail (event != NULL, TRUE);
4792 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4794 return gtk_widget_event_internal (widget, event);
4798 event_window_is_still_viewable (GdkEvent *event)
4800 /* Some programs, such as gnome-theme-manager, fake widgets
4801 * into exposing onto a pixmap by sending expose events with
4802 * event->window pointing to a pixmap
4804 if (GDK_IS_PIXMAP (event->any.window))
4805 return event->type == GDK_EXPOSE;
4807 /* Check that we think the event's window is viewable before
4808 * delivering the event, to prevent suprises. We do this here
4809 * at the last moment, since the event may have been queued
4810 * up behind other events, held over a recursive main loop, etc.
4812 switch (event->type)
4815 case GDK_MOTION_NOTIFY:
4816 case GDK_BUTTON_PRESS:
4817 case GDK_2BUTTON_PRESS:
4818 case GDK_3BUTTON_PRESS:
4820 case GDK_ENTER_NOTIFY:
4821 case GDK_PROXIMITY_IN:
4823 return event->any.window && gdk_window_is_viewable (event->any.window);
4826 /* The following events are the second half of paired events;
4827 * we always deliver them to deal with widgets that clean up
4828 * on the second half.
4830 case GDK_BUTTON_RELEASE:
4831 case GDK_KEY_RELEASE:
4832 case GDK_LEAVE_NOTIFY:
4833 case GDK_PROXIMITY_OUT:
4837 /* Remaining events would make sense on an not-viewable window,
4838 * or don't have an associated window.
4845 gtk_widget_event_internal (GtkWidget *widget,
4848 gboolean return_val = FALSE;
4850 /* We check only once for is-still-visible; if someone
4851 * hides the window in on of the signals on the widget,
4852 * they are responsible for returning TRUE to terminate
4855 if (!event_window_is_still_viewable (event))
4858 g_object_ref (widget);
4860 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4861 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4866 switch (event->type)
4871 case GDK_BUTTON_PRESS:
4872 case GDK_2BUTTON_PRESS:
4873 case GDK_3BUTTON_PRESS:
4874 signal_num = BUTTON_PRESS_EVENT;
4877 signal_num = SCROLL_EVENT;
4879 case GDK_BUTTON_RELEASE:
4880 signal_num = BUTTON_RELEASE_EVENT;
4882 case GDK_MOTION_NOTIFY:
4883 signal_num = MOTION_NOTIFY_EVENT;
4886 signal_num = DELETE_EVENT;
4889 signal_num = DESTROY_EVENT;
4890 _gtk_tooltip_hide (widget);
4893 signal_num = KEY_PRESS_EVENT;
4895 case GDK_KEY_RELEASE:
4896 signal_num = KEY_RELEASE_EVENT;
4898 case GDK_ENTER_NOTIFY:
4899 signal_num = ENTER_NOTIFY_EVENT;
4901 case GDK_LEAVE_NOTIFY:
4902 signal_num = LEAVE_NOTIFY_EVENT;
4904 case GDK_FOCUS_CHANGE:
4905 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4906 if (event->focus_change.in)
4907 _gtk_tooltip_focus_in (widget);
4909 _gtk_tooltip_focus_out (widget);
4912 signal_num = CONFIGURE_EVENT;
4915 signal_num = MAP_EVENT;
4918 signal_num = UNMAP_EVENT;
4920 case GDK_WINDOW_STATE:
4921 signal_num = WINDOW_STATE_EVENT;
4923 case GDK_PROPERTY_NOTIFY:
4924 signal_num = PROPERTY_NOTIFY_EVENT;
4926 case GDK_SELECTION_CLEAR:
4927 signal_num = SELECTION_CLEAR_EVENT;
4929 case GDK_SELECTION_REQUEST:
4930 signal_num = SELECTION_REQUEST_EVENT;
4932 case GDK_SELECTION_NOTIFY:
4933 signal_num = SELECTION_NOTIFY_EVENT;
4935 case GDK_PROXIMITY_IN:
4936 signal_num = PROXIMITY_IN_EVENT;
4938 case GDK_PROXIMITY_OUT:
4939 signal_num = PROXIMITY_OUT_EVENT;
4942 signal_num = NO_EXPOSE_EVENT;
4944 case GDK_CLIENT_EVENT:
4945 signal_num = CLIENT_EVENT;
4948 signal_num = EXPOSE_EVENT;
4950 case GDK_VISIBILITY_NOTIFY:
4951 signal_num = VISIBILITY_NOTIFY_EVENT;
4953 case GDK_GRAB_BROKEN:
4954 signal_num = GRAB_BROKEN;
4957 signal_num = DAMAGE_EVENT;
4960 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4964 if (signal_num != -1)
4965 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4967 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4968 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4972 g_object_unref (widget);
4978 * gtk_widget_activate:
4979 * @widget: a #GtkWidget that's activatable
4981 * For widgets that can be "activated" (buttons, menu items, etc.)
4982 * this function activates them. Activation is what happens when you
4983 * press Enter on a widget during key navigation. If @widget isn't
4984 * activatable, the function returns %FALSE.
4986 * Return value: %TRUE if the widget was activatable
4989 gtk_widget_activate (GtkWidget *widget)
4991 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4993 if (WIDGET_CLASS (widget)->activate_signal)
4995 /* FIXME: we should eventually check the signals signature here */
4996 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5005 * gtk_widget_set_scroll_adjustments:
5006 * @widget: a #GtkWidget
5007 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5008 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5010 * For widgets that support scrolling, sets the scroll adjustments and
5011 * returns %TRUE. For widgets that don't support scrolling, does
5012 * nothing and returns %FALSE. Widgets that don't support scrolling
5013 * can be scrolled by placing them in a #GtkViewport, which does
5014 * support scrolling.
5016 * Return value: %TRUE if the widget supports scrolling
5019 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5020 GtkAdjustment *hadjustment,
5021 GtkAdjustment *vadjustment)
5026 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5029 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5031 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5033 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5037 g_signal_query (signal_id, &query);
5038 if (!query.signal_id ||
5039 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5040 query.return_type != G_TYPE_NONE ||
5041 query.n_params != 2 ||
5042 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5043 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5045 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5046 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5050 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5055 gtk_widget_reparent_subwindows (GtkWidget *widget,
5056 GdkWindow *new_window)
5058 if (!gtk_widget_get_has_window (widget))
5060 GList *children = gdk_window_get_children (widget->window);
5063 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5065 GdkWindow *window = tmp_list->data;
5068 gdk_window_get_user_data (window, &child);
5069 while (child && child != widget)
5070 child = ((GtkWidget*) child)->parent;
5073 gdk_window_reparent (window, new_window, 0, 0);
5076 g_list_free (children);
5081 GList *tmp_list, *children;
5083 parent = gdk_window_get_parent (widget->window);
5086 gdk_window_reparent (widget->window, new_window, 0, 0);
5089 children = gdk_window_get_children (parent);
5091 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5093 GdkWindow *window = tmp_list->data;
5096 gdk_window_get_user_data (window, &child);
5098 if (child == widget)
5099 gdk_window_reparent (window, new_window, 0, 0);
5102 g_list_free (children);
5108 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5109 gpointer client_data)
5111 g_assert (client_data != NULL);
5113 if (!gtk_widget_get_has_window (widget))
5116 g_object_unref (widget->window);
5117 widget->window = (GdkWindow*) client_data;
5119 g_object_ref (widget->window);
5121 if (GTK_IS_CONTAINER (widget))
5122 gtk_container_forall (GTK_CONTAINER (widget),
5123 gtk_widget_reparent_fixup_child,
5129 * gtk_widget_reparent:
5130 * @widget: a #GtkWidget
5131 * @new_parent: a #GtkContainer to move the widget into
5133 * Moves a widget from one #GtkContainer to another, handling reference
5134 * count issues to avoid destroying the widget.
5137 gtk_widget_reparent (GtkWidget *widget,
5138 GtkWidget *new_parent)
5140 g_return_if_fail (GTK_IS_WIDGET (widget));
5141 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5142 g_return_if_fail (widget->parent != NULL);
5144 if (widget->parent != new_parent)
5146 /* First try to see if we can get away without unrealizing
5147 * the widget as we reparent it. if so we set a flag so
5148 * that gtk_widget_unparent doesn't unrealize widget
5150 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5151 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5153 g_object_ref (widget);
5154 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5155 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5156 g_object_unref (widget);
5158 if (GTK_WIDGET_IN_REPARENT (widget))
5160 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5162 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5163 gtk_widget_reparent_fixup_child (widget,
5164 gtk_widget_get_parent_window (widget));
5167 g_object_notify (G_OBJECT (widget), "parent");
5172 * gtk_widget_intersect:
5173 * @widget: a #GtkWidget
5174 * @area: a rectangle
5175 * @intersection: rectangle to store intersection of @widget and @area
5177 * Computes the intersection of a @widget's area and @area, storing
5178 * the intersection in @intersection, and returns %TRUE if there was
5179 * an intersection. @intersection may be %NULL if you're only
5180 * interested in whether there was an intersection.
5182 * Return value: %TRUE if there was an intersection
5185 gtk_widget_intersect (GtkWidget *widget,
5186 const GdkRectangle *area,
5187 GdkRectangle *intersection)
5193 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5194 g_return_val_if_fail (area != NULL, FALSE);
5197 dest = intersection;
5201 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5203 if (return_val && intersection && gtk_widget_get_has_window (widget))
5205 intersection->x -= widget->allocation.x;
5206 intersection->y -= widget->allocation.y;
5213 * gtk_widget_region_intersect:
5214 * @widget: a #GtkWidget
5215 * @region: a #GdkRegion, in the same coordinate system as
5216 * @widget->allocation. That is, relative to @widget->window
5217 * for %NO_WINDOW widgets; relative to the parent window
5218 * of @widget->window for widgets with their own window.
5219 * @returns: A newly allocated region holding the intersection of @widget
5220 * and @region. The coordinates of the return value are
5221 * relative to @widget->window for %NO_WINDOW widgets, and
5222 * relative to the parent window of @widget->window for
5223 * widgets with their own window.
5225 * Computes the intersection of a @widget's area and @region, returning
5226 * the intersection. The result may be empty, use gdk_region_empty() to
5230 gtk_widget_region_intersect (GtkWidget *widget,
5231 const GdkRegion *region)
5236 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5237 g_return_val_if_fail (region != NULL, NULL);
5239 gtk_widget_get_draw_rectangle (widget, &rect);
5241 dest = gdk_region_rectangle (&rect);
5243 gdk_region_intersect (dest, region);
5249 * _gtk_widget_grab_notify:
5250 * @widget: a #GtkWidget
5251 * @was_grabbed: whether a grab is now in effect
5253 * Emits the #GtkWidget::grab-notify signal on @widget.
5258 _gtk_widget_grab_notify (GtkWidget *widget,
5259 gboolean was_grabbed)
5261 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5265 * gtk_widget_grab_focus:
5266 * @widget: a #GtkWidget
5268 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5269 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5270 * something like #GtkFrame won't work.
5272 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5273 * gtk_widget_set_can_focus() to modify that flag.
5276 gtk_widget_grab_focus (GtkWidget *widget)
5278 g_return_if_fail (GTK_IS_WIDGET (widget));
5280 if (!gtk_widget_is_sensitive (widget))
5283 g_object_ref (widget);
5284 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5285 g_object_notify (G_OBJECT (widget), "has-focus");
5286 g_object_unref (widget);
5290 reset_focus_recurse (GtkWidget *widget,
5293 if (GTK_IS_CONTAINER (widget))
5295 GtkContainer *container;
5297 container = GTK_CONTAINER (widget);
5298 gtk_container_set_focus_child (container, NULL);
5300 gtk_container_foreach (container,
5301 reset_focus_recurse,
5307 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5309 if (gtk_widget_get_can_focus (focus_widget))
5311 GtkWidget *toplevel;
5314 /* clear the current focus setting, break if the current widget
5315 * is the focus widget's parent, since containers above that will
5316 * be set by the next loop.
5318 toplevel = gtk_widget_get_toplevel (focus_widget);
5319 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5321 widget = GTK_WINDOW (toplevel)->focus_widget;
5323 if (widget == focus_widget)
5325 /* We call _gtk_window_internal_set_focus() here so that the
5326 * toplevel window can request the focus if necessary.
5327 * This is needed when the toplevel is a GtkPlug
5329 if (!gtk_widget_has_focus (widget))
5330 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5337 while (widget->parent && widget->parent != focus_widget->parent)
5339 widget = widget->parent;
5340 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5344 else if (toplevel != focus_widget)
5346 /* gtk_widget_grab_focus() operates on a tree without window...
5347 * actually, this is very questionable behaviour.
5350 gtk_container_foreach (GTK_CONTAINER (toplevel),
5351 reset_focus_recurse,
5355 /* now propagate the new focus up the widget tree and finally
5356 * set it on the window
5358 widget = focus_widget;
5359 while (widget->parent)
5361 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5362 widget = widget->parent;
5364 if (GTK_IS_WINDOW (widget))
5365 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5370 gtk_widget_real_query_tooltip (GtkWidget *widget,
5373 gboolean keyboard_tip,
5374 GtkTooltip *tooltip)
5376 gchar *tooltip_markup;
5377 gboolean has_tooltip;
5379 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5380 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5382 if (has_tooltip && tooltip_markup)
5384 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5392 gtk_widget_real_show_help (GtkWidget *widget,
5393 GtkWidgetHelpType help_type)
5395 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5397 _gtk_tooltip_toggle_keyboard_mode (widget);
5406 gtk_widget_real_focus (GtkWidget *widget,
5407 GtkDirectionType direction)
5409 if (!gtk_widget_get_can_focus (widget))
5412 if (!gtk_widget_is_focus (widget))
5414 gtk_widget_grab_focus (widget);
5422 gtk_widget_real_move_focus (GtkWidget *widget,
5423 GtkDirectionType direction)
5425 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5427 if (GTK_IS_WINDOW (toplevel) &&
5428 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5430 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5436 gtk_widget_real_keynav_failed (GtkWidget *widget,
5437 GtkDirectionType direction)
5439 gboolean cursor_only;
5443 case GTK_DIR_TAB_FORWARD:
5444 case GTK_DIR_TAB_BACKWARD:
5451 g_object_get (gtk_widget_get_settings (widget),
5452 "gtk-keynav-cursor-only", &cursor_only,
5459 gtk_widget_error_bell (widget);
5465 * gtk_widget_set_can_focus:
5466 * @widget: a #GtkWidget
5467 * @can_focus: whether or not @widget can own the input focus.
5469 * Specifies whether @widget can own the input focus. See
5470 * gtk_widget_grab_focus() for actually setting the input focus on a
5476 gtk_widget_set_can_focus (GtkWidget *widget,
5479 g_return_if_fail (GTK_IS_WIDGET (widget));
5481 if (can_focus != gtk_widget_get_can_focus (widget))
5484 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5486 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5488 gtk_widget_queue_resize (widget);
5489 g_object_notify (G_OBJECT (widget), "can-focus");
5494 * gtk_widget_get_can_focus:
5495 * @widget: a #GtkWidget
5497 * Determines whether @widget can own the input focus. See
5498 * gtk_widget_set_can_focus().
5500 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5505 gtk_widget_get_can_focus (GtkWidget *widget)
5507 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5509 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5513 * gtk_widget_has_focus:
5514 * @widget: a #GtkWidget
5516 * Determines if the widget has the global input focus. See
5517 * gtk_widget_is_focus() for the difference between having the global
5518 * input focus, and only having the focus within a toplevel.
5520 * Return value: %TRUE if the widget has the global input focus.
5525 gtk_widget_has_focus (GtkWidget *widget)
5527 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5529 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5533 * gtk_widget_is_focus:
5534 * @widget: a #GtkWidget
5536 * Determines if the widget is the focus widget within its
5537 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5538 * necessarily set; %HAS_FOCUS will only be set if the
5539 * toplevel widget additionally has the global input focus.)
5541 * Return value: %TRUE if the widget is the focus widget.
5544 gtk_widget_is_focus (GtkWidget *widget)
5546 GtkWidget *toplevel;
5548 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5550 toplevel = gtk_widget_get_toplevel (widget);
5552 if (GTK_IS_WINDOW (toplevel))
5553 return widget == GTK_WINDOW (toplevel)->focus_widget;
5559 * gtk_widget_set_can_default:
5560 * @widget: a #GtkWidget
5561 * @can_default: whether or not @widget can be a default widget.
5563 * Specifies whether @widget can be a default widget. See
5564 * gtk_widget_grab_default() for details about the meaning of
5570 gtk_widget_set_can_default (GtkWidget *widget,
5571 gboolean can_default)
5573 g_return_if_fail (GTK_IS_WIDGET (widget));
5575 if (can_default != gtk_widget_get_can_default (widget))
5578 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5580 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5582 gtk_widget_queue_resize (widget);
5583 g_object_notify (G_OBJECT (widget), "can-default");
5588 * gtk_widget_get_can_default:
5589 * @widget: a #GtkWidget
5591 * Determines whether @widget can be a default widget. See
5592 * gtk_widget_set_can_default().
5594 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5599 gtk_widget_get_can_default (GtkWidget *widget)
5601 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5603 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5607 * gtk_widget_has_default:
5608 * @widget: a #GtkWidget
5610 * Determines whether @widget is the current default widget within its
5611 * toplevel. See gtk_widget_set_can_default().
5613 * Return value: %TRUE if @widget is the current default widget within
5614 * its toplevel, %FALSE otherwise
5619 gtk_widget_has_default (GtkWidget *widget)
5621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5623 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5627 * gtk_widget_grab_default:
5628 * @widget: a #GtkWidget
5630 * Causes @widget to become the default widget. @widget must have the
5631 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5632 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5633 * %TRUE)</literal>. The default widget is activated when
5634 * the user presses Enter in a window. Default widgets must be
5635 * activatable, that is, gtk_widget_activate() should affect them.
5638 gtk_widget_grab_default (GtkWidget *widget)
5642 g_return_if_fail (GTK_IS_WIDGET (widget));
5643 g_return_if_fail (gtk_widget_get_can_default (widget));
5645 window = gtk_widget_get_toplevel (widget);
5647 if (window && gtk_widget_is_toplevel (window))
5648 gtk_window_set_default (GTK_WINDOW (window), widget);
5650 g_warning (G_STRLOC ": widget not within a GtkWindow");
5654 * gtk_widget_set_receives_default:
5655 * @widget: a #GtkWidget
5656 * @receives_default: whether or not @widget can be a default widget.
5658 * Specifies whether @widget will be treated as the default widget
5659 * within its toplevel when it has the focus, even if another widget
5662 * See gtk_widget_grab_default() for details about the meaning of
5668 gtk_widget_set_receives_default (GtkWidget *widget,
5669 gboolean receives_default)
5671 g_return_if_fail (GTK_IS_WIDGET (widget));
5673 if (receives_default != gtk_widget_get_receives_default (widget))
5675 if (receives_default)
5676 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5678 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5680 g_object_notify (G_OBJECT (widget), "receives-default");
5685 * gtk_widget_get_receives_default:
5686 * @widget: a #GtkWidget
5688 * Determines whether @widget is alyways treated as default widget
5689 * withing its toplevel when it has the focus, even if another widget
5692 * See gtk_widget_set_receives_default().
5694 * Return value: %TRUE if @widget acts as default widget when focussed,
5700 gtk_widget_get_receives_default (GtkWidget *widget)
5702 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5704 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5708 * gtk_widget_has_grab:
5709 * @widget: a #GtkWidget
5711 * Determines whether the widget is currently grabbing events, so it
5712 * is the only widget receiving input events (keyboard and mouse).
5714 * See also gtk_grab_add().
5716 * Return value: %TRUE if the widget is in the grab_widgets stack
5721 gtk_widget_has_grab (GtkWidget *widget)
5723 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5725 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5729 * gtk_widget_set_name:
5730 * @widget: a #GtkWidget
5731 * @name: name for the widget
5733 * Widgets can be named, which allows you to refer to them from a
5734 * gtkrc file. You can apply a style to widgets with a particular name
5735 * in the gtkrc file. See the documentation for gtkrc files (on the
5736 * same page as the docs for #GtkRcStyle).
5738 * Note that widget names are separated by periods in paths (see
5739 * gtk_widget_path()), so names with embedded periods may cause confusion.
5742 gtk_widget_set_name (GtkWidget *widget,
5747 g_return_if_fail (GTK_IS_WIDGET (widget));
5749 new_name = g_strdup (name);
5750 g_free (widget->name);
5751 widget->name = new_name;
5753 if (gtk_widget_has_rc_style (widget))
5754 gtk_widget_reset_rc_style (widget);
5756 g_object_notify (G_OBJECT (widget), "name");
5760 * gtk_widget_get_name:
5761 * @widget: a #GtkWidget
5763 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5764 * significance of widget names.
5766 * Return value: name of the widget. This string is owned by GTK+ and
5767 * should not be modified or freed
5769 G_CONST_RETURN gchar*
5770 gtk_widget_get_name (GtkWidget *widget)
5772 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5775 return widget->name;
5776 return G_OBJECT_TYPE_NAME (widget);
5780 * gtk_widget_set_state:
5781 * @widget: a #GtkWidget
5782 * @state: new state for @widget
5784 * This function is for use in widget implementations. Sets the state
5785 * of a widget (insensitive, prelighted, etc.) Usually you should set
5786 * the state using wrapper functions such as gtk_widget_set_sensitive().
5789 gtk_widget_set_state (GtkWidget *widget,
5792 g_return_if_fail (GTK_IS_WIDGET (widget));
5794 if (state == gtk_widget_get_state (widget))
5797 if (state == GTK_STATE_INSENSITIVE)
5798 gtk_widget_set_sensitive (widget, FALSE);
5804 data.state_restoration = FALSE;
5805 data.use_forall = FALSE;
5807 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5809 data.parent_sensitive = TRUE;
5811 gtk_widget_propagate_state (widget, &data);
5813 if (gtk_widget_is_drawable (widget))
5814 gtk_widget_queue_draw (widget);
5819 * gtk_widget_get_state:
5820 * @widget: a #GtkWidget
5822 * Returns the widget's state. See gtk_widget_set_state().
5824 * Returns: the state of @widget.
5829 gtk_widget_get_state (GtkWidget *widget)
5831 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5833 return widget->state;
5837 * gtk_widget_set_visible:
5838 * @widget: a #GtkWidget
5839 * @visible: whether the widget should be shown or not
5841 * Sets the visibility state of @widget. Note that setting this to
5842 * %TRUE doesn't mean the widget is actually viewable, see
5843 * gtk_widget_get_visible().
5845 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5846 * but is nicer to use when the visibility of the widget depends on
5852 gtk_widget_set_visible (GtkWidget *widget,
5855 g_return_if_fail (GTK_IS_WIDGET (widget));
5857 if (visible != gtk_widget_get_visible (widget))
5860 gtk_widget_show (widget);
5862 gtk_widget_hide (widget);
5867 * gtk_widget_get_visible:
5868 * @widget: a #GtkWidget
5870 * Determines whether the widget is visible. Note that this doesn't
5871 * take into account whether the widget's parent is also visible
5872 * or the widget is obscured in any way.
5874 * See gtk_widget_set_visible().
5876 * Return value: %TRUE if the widget is visible
5881 gtk_widget_get_visible (GtkWidget *widget)
5883 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5885 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5889 * gtk_widget_set_has_window:
5890 * @widget: a #GtkWidget
5891 * @has_window: whether or not @widget has a window.
5893 * Specifies whether @widget has a #GdkWindow of its own. Note that
5894 * all realized widgets have a non-%NULL "window" pointer
5895 * (gtk_widget_get_window() never returns a %NULL window when a widget
5896 * is realized), but for many of them it's actually the #GdkWindow of
5897 * one of its parent widgets. Widgets that create a %window for
5898 * themselves in GtkWidget::realize() however must announce this by
5899 * calling this function with @has_window = %TRUE.
5901 * This function should only be called by widget implementations,
5902 * and they should call it in their init() function.
5907 gtk_widget_set_has_window (GtkWidget *widget,
5908 gboolean has_window)
5910 g_return_if_fail (GTK_IS_WIDGET (widget));
5913 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5915 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5919 * gtk_widget_get_has_window:
5920 * @widget: a #GtkWidget
5922 * Determines whether @widget has a #GdkWindow of its own. See
5923 * gtk_widget_set_has_window().
5925 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5930 gtk_widget_get_has_window (GtkWidget *widget)
5932 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5934 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5938 * gtk_widget_is_toplevel:
5939 * @widget: a #GtkWidget
5941 * Determines whether @widget is a toplevel widget. Currently only
5942 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5943 * widgets have no parent widget.
5945 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5950 gtk_widget_is_toplevel (GtkWidget *widget)
5952 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5954 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
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_fg:
6669 * @widget: a #GtkWidget
6670 * @state: the state for which to set the foreground color
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_fg().
6675 * Sets the foreground color for a widget in a particular state.
6676 * All other style values are left untouched. See also
6677 * gtk_widget_modify_style().
6680 gtk_widget_modify_fg (GtkWidget *widget,
6682 const GdkColor *color)
6684 g_return_if_fail (GTK_IS_WIDGET (widget));
6685 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6687 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6691 * gtk_widget_modify_bg:
6692 * @widget: a #GtkWidget
6693 * @state: the state for which to set the background color
6694 * @color: (allow-none): the color to assign (does not need to be allocated),
6695 * or %NULL to undo the effect of previous calls to
6696 * of gtk_widget_modify_bg().
6698 * Sets the background color for a widget in a particular state.
6699 * All other style values are left untouched. See also
6700 * gtk_widget_modify_style().
6702 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6703 * draw on their parent container's window and thus may not draw any
6704 * background themselves. This is the case for e.g. #GtkLabel. To modify
6705 * the background of such widgets, you have to set the background color
6706 * on their parent; if you want to set the background of a rectangular
6707 * area around a label, try placing the label in a #GtkEventBox widget
6708 * and setting the background color on that.
6711 gtk_widget_modify_bg (GtkWidget *widget,
6713 const GdkColor *color)
6715 g_return_if_fail (GTK_IS_WIDGET (widget));
6716 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6718 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6722 * gtk_widget_modify_text:
6723 * @widget: a #GtkWidget
6724 * @state: the state for which to set the text color
6725 * @color: (allow-none): the color to assign (does not need to be allocated),
6726 * or %NULL to undo the effect of previous calls to
6727 * of gtk_widget_modify_text().
6729 * Sets the text color for a widget in a particular state. All other
6730 * style values are left untouched. The text color is the foreground
6731 * color used along with the base color (see gtk_widget_modify_base())
6732 * for widgets such as #GtkEntry and #GtkTextView. See also
6733 * gtk_widget_modify_style().
6736 gtk_widget_modify_text (GtkWidget *widget,
6738 const GdkColor *color)
6740 g_return_if_fail (GTK_IS_WIDGET (widget));
6741 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6743 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6747 * gtk_widget_modify_base:
6748 * @widget: a #GtkWidget
6749 * @state: the state for which to set the base color
6750 * @color: (allow-none): the color to assign (does not need to be allocated),
6751 * or %NULL to undo the effect of previous calls to
6752 * of gtk_widget_modify_base().
6754 * Sets the base color for a widget in a particular state.
6755 * All other style values are left untouched. The base color
6756 * is the background color used along with the text color
6757 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6758 * and #GtkTextView. See also gtk_widget_modify_style().
6760 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6761 * draw on their parent container's window and thus may not draw any
6762 * background themselves. This is the case for e.g. #GtkLabel. To modify
6763 * the background of such widgets, you have to set the base color on their
6764 * parent; if you want to set the background of a rectangular area around
6765 * a label, try placing the label in a #GtkEventBox widget and setting
6766 * the base color on that.
6769 gtk_widget_modify_base (GtkWidget *widget,
6771 const GdkColor *color)
6773 g_return_if_fail (GTK_IS_WIDGET (widget));
6774 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6776 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6780 modify_color_property (GtkWidget *widget,
6781 GtkRcStyle *rc_style,
6783 const GdkColor *color)
6785 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6786 GQuark property_name = g_quark_from_string (name);
6790 GtkRcProperty rc_property = {0};
6793 rc_property.type_name = type_name;
6794 rc_property.property_name = property_name;
6795 rc_property.origin = NULL;
6797 color_name = gdk_color_to_string (color);
6798 g_value_init (&rc_property.value, G_TYPE_STRING);
6799 g_value_take_string (&rc_property.value, color_name);
6801 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6803 g_value_unset (&rc_property.value);
6806 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6810 * gtk_widget_modify_cursor:
6811 * @widget: a #GtkWidget
6812 * @primary: the color to use for primary cursor (does not need to be
6813 * allocated), or %NULL to undo the effect of previous calls to
6814 * of gtk_widget_modify_cursor().
6815 * @secondary: the color to use for secondary cursor (does not need to be
6816 * allocated), or %NULL to undo the effect of previous calls to
6817 * of gtk_widget_modify_cursor().
6819 * Sets the cursor color to use in a widget, overriding the
6820 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6821 * style properties. All other style values are left untouched.
6822 * See also gtk_widget_modify_style().
6827 gtk_widget_modify_cursor (GtkWidget *widget,
6828 const GdkColor *primary,
6829 const GdkColor *secondary)
6831 GtkRcStyle *rc_style;
6833 g_return_if_fail (GTK_IS_WIDGET (widget));
6835 rc_style = gtk_widget_get_modifier_style (widget);
6837 modify_color_property (widget, rc_style, "cursor-color", primary);
6838 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6840 gtk_widget_modify_style (widget, rc_style);
6844 * gtk_widget_modify_font:
6845 * @widget: a #GtkWidget
6846 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6847 * the effect of previous calls to gtk_widget_modify_font().
6849 * Sets the font to use for a widget. All other style values are left
6850 * untouched. See also gtk_widget_modify_style().
6853 gtk_widget_modify_font (GtkWidget *widget,
6854 PangoFontDescription *font_desc)
6856 GtkRcStyle *rc_style;
6858 g_return_if_fail (GTK_IS_WIDGET (widget));
6860 rc_style = gtk_widget_get_modifier_style (widget);
6862 if (rc_style->font_desc)
6863 pango_font_description_free (rc_style->font_desc);
6866 rc_style->font_desc = pango_font_description_copy (font_desc);
6868 rc_style->font_desc = NULL;
6870 gtk_widget_modify_style (widget, rc_style);
6874 gtk_widget_real_direction_changed (GtkWidget *widget,
6875 GtkTextDirection previous_direction)
6877 gtk_widget_queue_resize (widget);
6881 gtk_widget_real_style_set (GtkWidget *widget,
6882 GtkStyle *previous_style)
6884 if (gtk_widget_get_realized (widget) &&
6885 gtk_widget_get_has_window (widget))
6886 gtk_style_set_background (widget->style, widget->window, widget->state);
6890 gtk_widget_set_style_internal (GtkWidget *widget,
6892 gboolean initial_emission)
6894 g_object_ref (widget);
6895 g_object_freeze_notify (G_OBJECT (widget));
6897 if (widget->style != style)
6899 GtkStyle *previous_style;
6901 if (gtk_widget_get_realized (widget))
6903 gtk_widget_reset_shapes (widget);
6904 gtk_style_detach (widget->style);
6907 previous_style = widget->style;
6908 widget->style = style;
6909 g_object_ref (widget->style);
6911 if (gtk_widget_get_realized (widget))
6912 widget->style = gtk_style_attach (widget->style, widget->window);
6914 gtk_widget_update_pango_context (widget);
6915 g_signal_emit (widget,
6916 widget_signals[STYLE_SET],
6918 initial_emission ? NULL : previous_style);
6919 g_object_unref (previous_style);
6921 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6922 gtk_widget_queue_resize (widget);
6924 else if (initial_emission)
6926 gtk_widget_update_pango_context (widget);
6927 g_signal_emit (widget,
6928 widget_signals[STYLE_SET],
6932 g_object_notify (G_OBJECT (widget), "style");
6933 g_object_thaw_notify (G_OBJECT (widget));
6934 g_object_unref (widget);
6938 GtkWidget *previous_toplevel;
6939 GdkScreen *previous_screen;
6940 GdkScreen *new_screen;
6941 } HierarchyChangedInfo;
6944 do_screen_change (GtkWidget *widget,
6945 GdkScreen *old_screen,
6946 GdkScreen *new_screen)
6948 if (old_screen != new_screen)
6952 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6954 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6957 _gtk_tooltip_hide (widget);
6958 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6963 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6964 gpointer client_data)
6966 HierarchyChangedInfo *info = client_data;
6967 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
6968 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6970 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6972 g_object_ref (widget);
6975 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6977 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6979 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6980 do_screen_change (widget, info->previous_screen, info->new_screen);
6982 if (GTK_IS_CONTAINER (widget))
6983 gtk_container_forall (GTK_CONTAINER (widget),
6984 gtk_widget_propagate_hierarchy_changed_recurse,
6987 g_object_unref (widget);
6992 * _gtk_widget_propagate_hierarchy_changed:
6993 * @widget: a #GtkWidget
6994 * @previous_toplevel: Previous toplevel
6996 * Propagates changes in the anchored state to a widget and all
6997 * children, unsetting or setting the %ANCHORED flag, and
6998 * emitting #GtkWidget::hierarchy-changed.
7001 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7002 GtkWidget *previous_toplevel)
7004 HierarchyChangedInfo info;
7006 info.previous_toplevel = previous_toplevel;
7007 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7009 if (gtk_widget_is_toplevel (widget) ||
7010 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7011 info.new_screen = gtk_widget_get_screen (widget);
7013 info.new_screen = NULL;
7015 if (info.previous_screen)
7016 g_object_ref (info.previous_screen);
7017 if (previous_toplevel)
7018 g_object_ref (previous_toplevel);
7020 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7022 if (previous_toplevel)
7023 g_object_unref (previous_toplevel);
7024 if (info.previous_screen)
7025 g_object_unref (info.previous_screen);
7029 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7030 gpointer client_data)
7032 HierarchyChangedInfo *info = client_data;
7034 g_object_ref (widget);
7036 do_screen_change (widget, info->previous_screen, info->new_screen);
7038 if (GTK_IS_CONTAINER (widget))
7039 gtk_container_forall (GTK_CONTAINER (widget),
7040 gtk_widget_propagate_screen_changed_recurse,
7043 g_object_unref (widget);
7047 * gtk_widget_is_composited:
7048 * @widget: a #GtkWidget
7050 * Whether @widget can rely on having its alpha channel
7051 * drawn correctly. On X11 this function returns whether a
7052 * compositing manager is running for @widget's screen.
7054 * Please note that the semantics of this call will change
7055 * in the future if used on a widget that has a composited
7056 * window in its hierarchy (as set by gdk_window_set_composited()).
7058 * Return value: %TRUE if the widget can rely on its alpha
7059 * channel being drawn correctly.
7064 gtk_widget_is_composited (GtkWidget *widget)
7068 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7070 screen = gtk_widget_get_screen (widget);
7072 return gdk_screen_is_composited (screen);
7076 propagate_composited_changed (GtkWidget *widget,
7079 if (GTK_IS_CONTAINER (widget))
7081 gtk_container_forall (GTK_CONTAINER (widget),
7082 propagate_composited_changed,
7086 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7090 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7092 propagate_composited_changed (widget, NULL);
7096 * _gtk_widget_propagate_screen_changed:
7097 * @widget: a #GtkWidget
7098 * @previous_screen: Previous screen
7100 * Propagates changes in the screen for a widget to all
7101 * children, emitting #GtkWidget::screen-changed.
7104 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7105 GdkScreen *previous_screen)
7107 HierarchyChangedInfo info;
7109 info.previous_screen = previous_screen;
7110 info.new_screen = gtk_widget_get_screen (widget);
7112 if (previous_screen)
7113 g_object_ref (previous_screen);
7115 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7117 if (previous_screen)
7118 g_object_unref (previous_screen);
7122 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7124 if (gtk_widget_has_rc_style (widget))
7125 gtk_widget_reset_rc_style (widget);
7127 if (GTK_IS_CONTAINER (widget))
7128 gtk_container_forall (GTK_CONTAINER (widget),
7129 reset_rc_styles_recurse,
7135 * gtk_widget_reset_rc_styles:
7136 * @widget: a #GtkWidget.
7138 * Reset the styles of @widget and all descendents, so when
7139 * they are looked up again, they get the correct values
7140 * for the currently loaded RC file settings.
7142 * This function is not useful for applications.
7145 gtk_widget_reset_rc_styles (GtkWidget *widget)
7147 g_return_if_fail (GTK_IS_WIDGET (widget));
7149 reset_rc_styles_recurse (widget, NULL);
7153 * gtk_widget_get_default_style:
7155 * Returns the default style used by all widgets initially.
7157 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7158 * by GTK+ and should not be modified or freed.
7161 gtk_widget_get_default_style (void)
7163 if (!gtk_default_style)
7165 gtk_default_style = gtk_style_new ();
7166 g_object_ref (gtk_default_style);
7169 return gtk_default_style;
7172 static PangoContext *
7173 gtk_widget_peek_pango_context (GtkWidget *widget)
7175 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7179 * gtk_widget_get_pango_context:
7180 * @widget: a #GtkWidget
7182 * Gets a #PangoContext with the appropriate font map, font description,
7183 * and base direction for this widget. Unlike the context returned
7184 * by gtk_widget_create_pango_context(), this context is owned by
7185 * the widget (it can be used until the screen for the widget changes
7186 * or the widget is removed from its toplevel), and will be updated to
7187 * match any changes to the widget's attributes.
7189 * If you create and keep a #PangoLayout using this context, you must
7190 * deal with changes to the context by calling pango_layout_context_changed()
7191 * on the layout in response to the #GtkWidget::style-set and
7192 * #GtkWidget::direction-changed signals for the widget.
7194 * Return value: (transfer none): the #PangoContext for the widget.
7197 gtk_widget_get_pango_context (GtkWidget *widget)
7199 PangoContext *context;
7201 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7203 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7206 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7207 g_object_set_qdata_full (G_OBJECT (widget),
7208 quark_pango_context,
7217 update_pango_context (GtkWidget *widget,
7218 PangoContext *context)
7220 pango_context_set_font_description (context, widget->style->font_desc);
7221 pango_context_set_base_dir (context,
7222 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7223 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7227 gtk_widget_update_pango_context (GtkWidget *widget)
7229 PangoContext *context = gtk_widget_peek_pango_context (widget);
7235 update_pango_context (widget, context);
7237 screen = gtk_widget_get_screen_unchecked (widget);
7240 pango_cairo_context_set_resolution (context,
7241 gdk_screen_get_resolution (screen));
7242 pango_cairo_context_set_font_options (context,
7243 gdk_screen_get_font_options (screen));
7249 * gtk_widget_create_pango_context:
7250 * @widget: a #GtkWidget
7252 * Creates a new #PangoContext with the appropriate font map,
7253 * font description, and base direction for drawing text for
7254 * this widget. See also gtk_widget_get_pango_context().
7256 * Return value: the new #PangoContext
7259 gtk_widget_create_pango_context (GtkWidget *widget)
7262 PangoContext *context;
7264 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7266 screen = gtk_widget_get_screen_unchecked (widget);
7269 GTK_NOTE (MULTIHEAD,
7270 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7272 screen = gdk_screen_get_default ();
7275 context = gdk_pango_context_get_for_screen (screen);
7277 update_pango_context (widget, context);
7278 pango_context_set_language (context, gtk_get_default_language ());
7284 * gtk_widget_create_pango_layout:
7285 * @widget: a #GtkWidget
7286 * @text: text to set on the layout (can be %NULL)
7288 * Creates a new #PangoLayout with the appropriate font map,
7289 * font description, and base direction for drawing text for
7292 * If you keep a #PangoLayout created in this way around, in order to
7293 * notify the layout of changes to the base direction or font of this
7294 * widget, you must call pango_layout_context_changed() in response to
7295 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7298 * Return value: the new #PangoLayout
7301 gtk_widget_create_pango_layout (GtkWidget *widget,
7304 PangoLayout *layout;
7305 PangoContext *context;
7307 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7309 context = gtk_widget_get_pango_context (widget);
7310 layout = pango_layout_new (context);
7313 pango_layout_set_text (layout, text, -1);
7319 * gtk_widget_render_icon:
7320 * @widget: a #GtkWidget
7321 * @stock_id: a stock ID
7322 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7323 * render at the size of the source and don't scale (if there are
7324 * multiple source sizes, GTK+ picks one of the available sizes).
7325 * @detail: (allow-none): render detail to pass to theme engine
7327 * A convenience function that uses the theme engine and RC file
7328 * settings for @widget to look up @stock_id and render it to
7329 * a pixbuf. @stock_id should be a stock icon ID such as
7330 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7331 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7332 * identifies the widget or code doing the rendering, so that
7333 * theme engines can special-case rendering for that widget or code.
7335 * The pixels in the returned #GdkPixbuf are shared with the rest of
7336 * the application and should not be modified. The pixbuf should be freed
7337 * after use with g_object_unref().
7339 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7342 gtk_widget_render_icon (GtkWidget *widget,
7343 const gchar *stock_id,
7345 const gchar *detail)
7347 GtkIconSet *icon_set;
7350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7351 g_return_val_if_fail (stock_id != NULL, NULL);
7352 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7354 gtk_widget_ensure_style (widget);
7356 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7358 if (icon_set == NULL)
7361 retval = gtk_icon_set_render_icon (icon_set,
7363 gtk_widget_get_direction (widget),
7364 gtk_widget_get_state (widget),
7373 * gtk_widget_set_parent_window:
7374 * @widget: a #GtkWidget.
7375 * @parent_window: the new parent window.
7377 * Sets a non default parent window for @widget.
7380 gtk_widget_set_parent_window (GtkWidget *widget,
7381 GdkWindow *parent_window)
7383 GdkWindow *old_parent_window;
7385 g_return_if_fail (GTK_IS_WIDGET (widget));
7387 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7388 quark_parent_window);
7390 if (parent_window != old_parent_window)
7392 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7394 if (old_parent_window)
7395 g_object_unref (old_parent_window);
7397 g_object_ref (parent_window);
7402 * gtk_widget_get_parent_window:
7403 * @widget: a #GtkWidget.
7405 * Gets @widget's parent window.
7407 * Returns: (transfer none): the parent window of @widget.
7410 gtk_widget_get_parent_window (GtkWidget *widget)
7412 GdkWindow *parent_window;
7414 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7416 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7418 return (parent_window != NULL) ? parent_window :
7419 (widget->parent != NULL) ? widget->parent->window : NULL;
7424 * gtk_widget_set_child_visible:
7425 * @widget: a #GtkWidget
7426 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7428 * Sets whether @widget should be mapped along with its when its parent
7429 * is mapped and @widget has been shown with gtk_widget_show().
7431 * The child visibility can be set for widget before it is added to
7432 * a container with gtk_widget_set_parent(), to avoid mapping
7433 * children unnecessary before immediately unmapping them. However
7434 * it will be reset to its default state of %TRUE when the widget
7435 * is removed from a container.
7437 * Note that changing the child visibility of a widget does not
7438 * queue a resize on the widget. Most of the time, the size of
7439 * a widget is computed from all visible children, whether or
7440 * not they are mapped. If this is not the case, the container
7441 * can queue a resize itself.
7443 * This function is only useful for container implementations and
7444 * never should be called by an application.
7447 gtk_widget_set_child_visible (GtkWidget *widget,
7448 gboolean is_visible)
7450 g_return_if_fail (GTK_IS_WIDGET (widget));
7451 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7453 g_object_ref (widget);
7456 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7459 GtkWidget *toplevel;
7461 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7463 toplevel = gtk_widget_get_toplevel (widget);
7464 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7465 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7468 if (widget->parent && gtk_widget_get_realized (widget->parent))
7470 if (gtk_widget_get_mapped (widget->parent) &&
7471 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7472 gtk_widget_get_visible (widget))
7473 gtk_widget_map (widget);
7475 gtk_widget_unmap (widget);
7478 g_object_unref (widget);
7482 * gtk_widget_get_child_visible:
7483 * @widget: a #GtkWidget
7485 * Gets the value set with gtk_widget_set_child_visible().
7486 * If you feel a need to use this function, your code probably
7487 * needs reorganization.
7489 * This function is only useful for container implementations and
7490 * never should be called by an application.
7492 * Return value: %TRUE if the widget is mapped with the parent.
7495 gtk_widget_get_child_visible (GtkWidget *widget)
7497 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7499 return GTK_WIDGET_CHILD_VISIBLE (widget);
7503 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7505 GtkWidget *toplevel;
7507 toplevel = gtk_widget_get_toplevel (widget);
7509 if (gtk_widget_is_toplevel (toplevel))
7511 if (GTK_IS_WINDOW (toplevel))
7512 return GTK_WINDOW (toplevel)->screen;
7513 else if (GTK_IS_INVISIBLE (toplevel))
7514 return GTK_INVISIBLE (widget)->screen;
7521 * gtk_widget_get_screen:
7522 * @widget: a #GtkWidget
7524 * Get the #GdkScreen from the toplevel window associated with
7525 * this widget. This function can only be called after the widget
7526 * has been added to a widget hierarchy with a #GtkWindow
7529 * In general, you should only create screen specific
7530 * resources when a widget has been realized, and you should
7531 * free those resources when the widget is unrealized.
7533 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7538 gtk_widget_get_screen (GtkWidget *widget)
7542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7544 screen = gtk_widget_get_screen_unchecked (widget);
7551 g_warning (G_STRLOC ": Can't get associated screen"
7552 " for a widget unless it is inside a toplevel GtkWindow\n"
7553 " widget type is %s associated top level type is %s",
7554 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7555 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7557 return gdk_screen_get_default ();
7562 * gtk_widget_has_screen:
7563 * @widget: a #GtkWidget
7565 * Checks whether there is a #GdkScreen is associated with
7566 * this widget. All toplevel widgets have an associated
7567 * screen, and all widgets added into a hierarchy with a toplevel
7568 * window at the top.
7570 * Return value: %TRUE if there is a #GdkScreen associcated
7576 gtk_widget_has_screen (GtkWidget *widget)
7578 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7580 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7584 * gtk_widget_get_display:
7585 * @widget: a #GtkWidget
7587 * Get the #GdkDisplay for the toplevel window associated with
7588 * this widget. This function can only be called after the widget
7589 * has been added to a widget hierarchy with a #GtkWindow at the top.
7591 * In general, you should only create display specific
7592 * resources when a widget has been realized, and you should
7593 * free those resources when the widget is unrealized.
7595 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7600 gtk_widget_get_display (GtkWidget *widget)
7602 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7604 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7608 * gtk_widget_get_root_window:
7609 * @widget: a #GtkWidget
7611 * Get the root window where this widget is located. This function can
7612 * only be called after the widget has been added to a widget
7613 * hierarchy with #GtkWindow at the top.
7615 * The root window is useful for such purposes as creating a popup
7616 * #GdkWindow associated with the window. In general, you should only
7617 * create display specific resources when a widget has been realized,
7618 * and you should free those resources when the widget is unrealized.
7620 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7625 gtk_widget_get_root_window (GtkWidget *widget)
7627 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7629 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7633 * gtk_widget_child_focus:
7634 * @widget: a #GtkWidget
7635 * @direction: direction of focus movement
7637 * This function is used by custom widget implementations; if you're
7638 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7639 * to a particular widget, and gtk_container_set_focus_chain() to
7640 * change the focus tab order. So you may want to investigate those
7641 * functions instead.
7643 * gtk_widget_child_focus() is called by containers as the user moves
7644 * around the window using keyboard shortcuts. @direction indicates
7645 * what kind of motion is taking place (up, down, left, right, tab
7646 * forward, tab backward). gtk_widget_child_focus() emits the
7647 * #GtkWidget::focus signal; widgets override the default handler
7648 * for this signal in order to implement appropriate focus behavior.
7650 * The default ::focus handler for a widget should return %TRUE if
7651 * moving in @direction left the focus on a focusable location inside
7652 * that widget, and %FALSE if moving in @direction moved the focus
7653 * outside the widget. If returning %TRUE, widgets normally
7654 * call gtk_widget_grab_focus() to place the focus accordingly;
7655 * if returning %FALSE, they don't modify the current focus location.
7657 * This function replaces gtk_container_focus() from GTK+ 1.2.
7658 * It was necessary to check that the child was visible, sensitive,
7659 * and focusable before calling gtk_container_focus().
7660 * gtk_widget_child_focus() returns %FALSE if the widget is not
7661 * currently in a focusable state, so there's no need for those checks.
7663 * Return value: %TRUE if focus ended up inside @widget
7666 gtk_widget_child_focus (GtkWidget *widget,
7667 GtkDirectionType direction)
7669 gboolean return_val;
7671 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7673 if (!gtk_widget_get_visible (widget) ||
7674 !gtk_widget_is_sensitive (widget))
7677 /* child widgets must set CAN_FOCUS, containers
7678 * don't have to though.
7680 if (!GTK_IS_CONTAINER (widget) &&
7681 !gtk_widget_get_can_focus (widget))
7684 g_signal_emit (widget,
7685 widget_signals[FOCUS],
7687 direction, &return_val);
7693 * gtk_widget_keynav_failed:
7694 * @widget: a #GtkWidget
7695 * @direction: direction of focus movement
7697 * This function should be called whenever keyboard navigation within
7698 * a single widget hits a boundary. The function emits the
7699 * #GtkWidget::keynav-failed signal on the widget and its return
7700 * value should be interpreted in a way similar to the return value of
7701 * gtk_widget_child_focus():
7703 * When %TRUE is returned, stay in the widget, the failed keyboard
7704 * navigation is Ok and/or there is nowhere we can/should move the
7707 * When %FALSE is returned, the caller should continue with keyboard
7708 * navigation outside the widget, e.g. by calling
7709 * gtk_widget_child_focus() on the widget's toplevel.
7711 * The default ::keynav-failed handler returns %TRUE for
7712 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7713 * values of #GtkDirectionType, it looks at the
7714 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7715 * if the setting is %TRUE. This way the entire user interface
7716 * becomes cursor-navigatable on input devices such as mobile phones
7717 * which only have cursor keys but no tab key.
7719 * Whenever the default handler returns %TRUE, it also calls
7720 * gtk_widget_error_bell() to notify the user of the failed keyboard
7723 * A use case for providing an own implementation of ::keynav-failed
7724 * (either by connecting to it or by overriding it) would be a row of
7725 * #GtkEntry widgets where the user should be able to navigate the
7726 * entire row with the cursor keys, as e.g. known from user interfaces
7727 * that require entering license keys.
7729 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7730 * if the emitting widget should try to handle the keyboard
7731 * navigation attempt in its parent container(s).
7736 gtk_widget_keynav_failed (GtkWidget *widget,
7737 GtkDirectionType direction)
7739 gboolean return_val;
7741 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7743 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7744 direction, &return_val);
7750 * gtk_widget_error_bell:
7751 * @widget: a #GtkWidget
7753 * Notifies the user about an input-related error on this widget.
7754 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7755 * gdk_window_beep(), otherwise it does nothing.
7757 * Note that the effect of gdk_window_beep() can be configured in many
7758 * ways, depending on the windowing backend and the desktop environment
7759 * or window manager that is used.
7764 gtk_widget_error_bell (GtkWidget *widget)
7766 GtkSettings* settings;
7769 g_return_if_fail (GTK_IS_WIDGET (widget));
7771 settings = gtk_widget_get_settings (widget);
7775 g_object_get (settings,
7776 "gtk-error-bell", &beep,
7779 if (beep && widget->window)
7780 gdk_window_beep (widget->window);
7784 * gtk_widget_set_uposition:
7785 * @widget: a #GtkWidget
7786 * @x: x position; -1 to unset x; -2 to leave x unchanged
7787 * @y: y position; -1 to unset y; -2 to leave y unchanged
7790 * Sets the position of a widget. The funny "u" in the name comes from
7791 * the "user position" hint specified by the X Window System, and
7792 * exists for legacy reasons. This function doesn't work if a widget
7793 * is inside a container; it's only really useful on #GtkWindow.
7795 * Don't use this function to center dialogs over the main application
7796 * window; most window managers will do the centering on your behalf
7797 * if you call gtk_window_set_transient_for(), and it's really not
7798 * possible to get the centering to work correctly in all cases from
7799 * application code. But if you insist, use gtk_window_set_position()
7800 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7803 * Note that although @x and @y can be individually unset, the position
7804 * is not honoured unless both @x and @y are set.
7807 gtk_widget_set_uposition (GtkWidget *widget,
7811 /* FIXME this function is the only place that aux_info->x and
7812 * aux_info->y are even used I believe, and this function is
7813 * deprecated. Should be cleaned up.
7815 * (Actually, size_allocate uses them) -Yosh
7818 GtkWidgetAuxInfo *aux_info;
7820 g_return_if_fail (GTK_IS_WIDGET (widget));
7822 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7827 aux_info->x_set = FALSE;
7830 aux_info->x_set = TRUE;
7838 aux_info->y_set = FALSE;
7841 aux_info->y_set = TRUE;
7846 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7847 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7849 if (gtk_widget_get_visible (widget) && widget->parent)
7850 gtk_widget_size_allocate (widget, &widget->allocation);
7854 gtk_widget_set_usize_internal (GtkWidget *widget,
7858 GtkWidgetAuxInfo *aux_info;
7859 gboolean changed = FALSE;
7861 g_object_freeze_notify (G_OBJECT (widget));
7863 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7865 if (width > -2 && aux_info->width != width)
7867 g_object_notify (G_OBJECT (widget), "width-request");
7868 aux_info->width = width;
7871 if (height > -2 && aux_info->height != height)
7873 g_object_notify (G_OBJECT (widget), "height-request");
7874 aux_info->height = height;
7878 if (gtk_widget_get_visible (widget) && changed)
7879 gtk_widget_queue_resize (widget);
7881 g_object_thaw_notify (G_OBJECT (widget));
7885 * gtk_widget_set_usize:
7886 * @widget: a #GtkWidget
7887 * @width: minimum width, or -1 to unset
7888 * @height: minimum height, or -1 to unset
7890 * Sets the minimum size of a widget; that is, the widget's size
7891 * request will be @width by @height. You can use this function to
7892 * force a widget to be either larger or smaller than it is. The
7893 * strange "usize" name dates from the early days of GTK+, and derives
7894 * from X Window System terminology. In many cases,
7895 * gtk_window_set_default_size() is a better choice for toplevel
7896 * windows than this function; setting the default size will still
7897 * allow users to shrink the window. Setting the usize will force them
7898 * to leave the window at least as large as the usize. When dealing
7899 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7902 * Note the inherent danger of setting any fixed size - themes,
7903 * translations into other languages, different fonts, and user action
7904 * can all change the appropriate size for a given widget. So, it's
7905 * basically impossible to hardcode a size that will always be
7908 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7911 gtk_widget_set_usize (GtkWidget *widget,
7915 g_return_if_fail (GTK_IS_WIDGET (widget));
7917 gtk_widget_set_usize_internal (widget, width, height);
7921 * gtk_widget_set_size_request:
7922 * @widget: a #GtkWidget
7923 * @width: width @widget should request, or -1 to unset
7924 * @height: height @widget should request, or -1 to unset
7926 * Sets the minimum size of a widget; that is, the widget's size
7927 * request will be @width by @height. You can use this function to
7928 * force a widget to be either larger or smaller than it normally
7931 * In most cases, gtk_window_set_default_size() is a better choice for
7932 * toplevel windows than this function; setting the default size will
7933 * still allow users to shrink the window. Setting the size request
7934 * will force them to leave the window at least as large as the size
7935 * request. When dealing with window sizes,
7936 * gtk_window_set_geometry_hints() can be a useful function as well.
7938 * Note the inherent danger of setting any fixed size - themes,
7939 * translations into other languages, different fonts, and user action
7940 * can all change the appropriate size for a given widget. So, it's
7941 * basically impossible to hardcode a size that will always be
7944 * The size request of a widget is the smallest size a widget can
7945 * accept while still functioning well and drawing itself correctly.
7946 * However in some strange cases a widget may be allocated less than
7947 * its requested size, and in many cases a widget may be allocated more
7948 * space than it requested.
7950 * If the size request in a given direction is -1 (unset), then
7951 * the "natural" size request of the widget will be used instead.
7953 * Widgets can't actually be allocated a size less than 1 by 1, but
7954 * you can pass 0,0 to this function to mean "as small as possible."
7957 gtk_widget_set_size_request (GtkWidget *widget,
7961 g_return_if_fail (GTK_IS_WIDGET (widget));
7962 g_return_if_fail (width >= -1);
7963 g_return_if_fail (height >= -1);
7970 gtk_widget_set_usize_internal (widget, width, height);
7975 * gtk_widget_get_size_request:
7976 * @widget: a #GtkWidget
7977 * @width: (allow-none): (out): return location for width, or %NULL
7978 * @height: (allow-none): (out): return location for height, or %NULL
7980 * Gets the size request that was explicitly set for the widget using
7981 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7982 * @height indicates that that dimension has not been set explicitly
7983 * and the natural requisition of the widget will be used intead. See
7984 * gtk_widget_set_size_request(). To get the size a widget will
7985 * actually use, call gtk_widget_size_request() instead of
7989 gtk_widget_get_size_request (GtkWidget *widget,
7993 GtkWidgetAuxInfo *aux_info;
7995 g_return_if_fail (GTK_IS_WIDGET (widget));
7997 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
8000 *width = aux_info ? aux_info->width : -1;
8003 *height = aux_info ? aux_info->height : -1;
8007 * gtk_widget_set_events:
8008 * @widget: a #GtkWidget
8009 * @events: event mask
8011 * Sets the event mask (see #GdkEventMask) for a widget. The event
8012 * mask determines which events a widget will receive. Keep in mind
8013 * that different widgets have different default event masks, and by
8014 * changing the event mask you may disrupt a widget's functionality,
8015 * so be careful. This function must be called while a widget is
8016 * unrealized. Consider gtk_widget_add_events() for widgets that are
8017 * already realized, or if you want to preserve the existing event
8018 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8019 * to get events on those widgets, place them inside a #GtkEventBox
8020 * and receive events on the event box.
8023 gtk_widget_set_events (GtkWidget *widget,
8026 g_return_if_fail (GTK_IS_WIDGET (widget));
8027 g_return_if_fail (!gtk_widget_get_realized (widget));
8029 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8030 GINT_TO_POINTER (events));
8031 g_object_notify (G_OBJECT (widget), "events");
8035 gtk_widget_add_events_internal (GtkWidget *widget,
8041 for (l = window_list; l != NULL; l = l->next)
8043 GdkWindow *window = l->data;
8046 gdk_window_get_user_data (window, &user_data);
8047 if (user_data == widget)
8051 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8053 children = gdk_window_get_children (window);
8054 gtk_widget_add_events_internal (widget, events, children);
8055 g_list_free (children);
8061 * gtk_widget_add_events:
8062 * @widget: a #GtkWidget
8063 * @events: an event mask, see #GdkEventMask
8065 * Adds the events in the bitfield @events to the event mask for
8066 * @widget. See gtk_widget_set_events() for details.
8069 gtk_widget_add_events (GtkWidget *widget,
8074 g_return_if_fail (GTK_IS_WIDGET (widget));
8076 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8077 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8078 GINT_TO_POINTER (old_events | events));
8080 if (gtk_widget_get_realized (widget))
8084 if (!gtk_widget_get_has_window (widget))
8085 window_list = gdk_window_get_children (widget->window);
8087 window_list = g_list_prepend (NULL, widget->window);
8089 gtk_widget_add_events_internal (widget, events, window_list);
8091 g_list_free (window_list);
8094 g_object_notify (G_OBJECT (widget), "events");
8098 * gtk_widget_set_extension_events:
8099 * @widget: a #GtkWidget
8100 * @mode: bitfield of extension events to receive
8102 * Sets the extension events mask to @mode. See #GdkExtensionMode
8103 * and gdk_input_set_extension_events().
8106 gtk_widget_set_extension_events (GtkWidget *widget,
8107 GdkExtensionMode mode)
8109 g_return_if_fail (GTK_IS_WIDGET (widget));
8111 if (gtk_widget_get_realized (widget))
8112 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8114 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8115 GINT_TO_POINTER (mode));
8116 g_object_notify (G_OBJECT (widget), "extension-events");
8120 * gtk_widget_get_toplevel:
8121 * @widget: a #GtkWidget
8123 * This function returns the topmost widget in the container hierarchy
8124 * @widget is a part of. If @widget has no parent widgets, it will be
8125 * returned as the topmost widget. No reference will be added to the
8126 * returned widget; it should not be unreferenced.
8128 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8129 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8131 * %NULL if @widget wasn't inside a toplevel window, and if the
8132 * window was inside a #GtkWindow-derived widget which was in turn
8133 * inside the toplevel #GtkWindow. While the second case may
8134 * seem unlikely, it actually happens when a #GtkPlug is embedded
8135 * inside a #GtkSocket within the same application.
8137 * To reliably find the toplevel #GtkWindow, use
8138 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8139 * is set on the result.
8141 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8142 * if (gtk_widget_is_toplevel (toplevel))
8144 * /* Perform action on toplevel. */
8148 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8149 * if there's no ancestor.
8152 gtk_widget_get_toplevel (GtkWidget *widget)
8154 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8156 while (widget->parent)
8157 widget = widget->parent;
8163 * gtk_widget_get_ancestor:
8164 * @widget: a #GtkWidget
8165 * @widget_type: ancestor type
8167 * Gets the first ancestor of @widget with type @widget_type. For example,
8168 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8169 * the first #GtkBox that's an ancestor of @widget. No reference will be
8170 * added to the returned widget; it should not be unreferenced. See note
8171 * about checking for a toplevel #GtkWindow in the docs for
8172 * gtk_widget_get_toplevel().
8174 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8175 * considers @widget to be an ancestor of itself.
8177 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8180 gtk_widget_get_ancestor (GtkWidget *widget,
8183 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8185 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8186 widget = widget->parent;
8188 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8195 * gtk_widget_get_colormap:
8196 * @widget: a #GtkWidget
8198 * Gets the colormap that will be used to render @widget. No reference will
8199 * be added to the returned colormap; it should not be unreferenced.
8201 * Return value: (transfer none): the colormap used by @widget
8204 gtk_widget_get_colormap (GtkWidget *widget)
8206 GdkColormap *colormap;
8207 GtkWidget *tmp_widget;
8209 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8213 colormap = gdk_drawable_get_colormap (widget->window);
8214 /* If window was destroyed previously, we'll get NULL here */
8219 tmp_widget = widget;
8222 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8226 tmp_widget= tmp_widget->parent;
8229 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8233 * gtk_widget_get_visual:
8234 * @widget: a #GtkWidget
8236 * Gets the visual that will be used to render @widget.
8238 * Return value: (transfer none): the visual for @widget
8241 gtk_widget_get_visual (GtkWidget *widget)
8243 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8245 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8249 * gtk_widget_get_settings:
8250 * @widget: a #GtkWidget
8252 * Gets the settings object holding the settings (global property
8253 * settings, RC file information, etc) used for this widget.
8255 * Note that this function can only be called when the #GtkWidget
8256 * is attached to a toplevel, since the settings object is specific
8257 * to a particular #GdkScreen.
8259 * Return value: (transfer none): the relevant #GtkSettings object
8262 gtk_widget_get_settings (GtkWidget *widget)
8264 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8266 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8270 * gtk_widget_set_colormap:
8271 * @widget: a #GtkWidget
8272 * @colormap: a colormap
8274 * Sets the colormap for the widget to the given value. Widget must not
8275 * have been previously realized. This probably should only be used
8276 * from an <function>init()</function> function (i.e. from the constructor
8280 gtk_widget_set_colormap (GtkWidget *widget,
8281 GdkColormap *colormap)
8283 g_return_if_fail (GTK_IS_WIDGET (widget));
8284 g_return_if_fail (!gtk_widget_get_realized (widget));
8285 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8287 g_object_ref (colormap);
8289 g_object_set_qdata_full (G_OBJECT (widget),
8296 * gtk_widget_get_events:
8297 * @widget: a #GtkWidget
8299 * Returns the event mask for the widget (a bitfield containing flags
8300 * from the #GdkEventMask enumeration). These are the events that the widget
8303 * Return value: event mask for @widget
8306 gtk_widget_get_events (GtkWidget *widget)
8308 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8310 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8314 * gtk_widget_get_extension_events:
8315 * @widget: a #GtkWidget
8317 * Retrieves the extension events the widget will receive; see
8318 * gdk_input_set_extension_events().
8320 * Return value: extension events for @widget
8323 gtk_widget_get_extension_events (GtkWidget *widget)
8325 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8327 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8331 * gtk_widget_get_pointer:
8332 * @widget: a #GtkWidget
8333 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8334 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8336 * Obtains the location of the mouse pointer in widget coordinates.
8337 * Widget coordinates are a bit odd; for historical reasons, they are
8338 * defined as @widget->window coordinates for widgets that are not
8339 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8340 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8343 gtk_widget_get_pointer (GtkWidget *widget,
8347 g_return_if_fail (GTK_IS_WIDGET (widget));
8354 if (gtk_widget_get_realized (widget))
8356 gdk_window_get_pointer (widget->window, x, y, NULL);
8358 if (!gtk_widget_get_has_window (widget))
8361 *x -= widget->allocation.x;
8363 *y -= widget->allocation.y;
8369 * gtk_widget_is_ancestor:
8370 * @widget: a #GtkWidget
8371 * @ancestor: another #GtkWidget
8373 * Determines whether @widget is somewhere inside @ancestor, possibly with
8374 * intermediate containers.
8376 * Return value: %TRUE if @ancestor contains @widget as a child,
8377 * grandchild, great grandchild, etc.
8380 gtk_widget_is_ancestor (GtkWidget *widget,
8381 GtkWidget *ancestor)
8383 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8384 g_return_val_if_fail (ancestor != NULL, FALSE);
8388 if (widget->parent == ancestor)
8390 widget = widget->parent;
8396 static GQuark quark_composite_name = 0;
8399 * gtk_widget_set_composite_name:
8400 * @widget: a #GtkWidget.
8401 * @name: the name to set
8403 * Sets a widgets composite name. The widget must be
8404 * a composite child of its parent; see gtk_widget_push_composite_child().
8407 gtk_widget_set_composite_name (GtkWidget *widget,
8410 g_return_if_fail (GTK_IS_WIDGET (widget));
8411 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8412 g_return_if_fail (name != NULL);
8414 if (!quark_composite_name)
8415 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8417 g_object_set_qdata_full (G_OBJECT (widget),
8418 quark_composite_name,
8424 * gtk_widget_get_composite_name:
8425 * @widget: a #GtkWidget
8427 * Obtains the composite name of a widget.
8429 * Returns: the composite name of @widget, or %NULL if @widget is not
8430 * a composite child. The string should be freed when it is no
8434 gtk_widget_get_composite_name (GtkWidget *widget)
8436 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8438 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8439 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8446 * gtk_widget_push_composite_child:
8448 * Makes all newly-created widgets as composite children until
8449 * the corresponding gtk_widget_pop_composite_child() call.
8451 * A composite child is a child that's an implementation detail of the
8452 * container it's inside and should not be visible to people using the
8453 * container. Composite children aren't treated differently by GTK (but
8454 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8455 * builders might want to treat them in a different way.
8457 * Here is a simple example:
8459 * gtk_widget_push_composite_child ();
8460 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8461 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8462 * gtk_widget_pop_composite_child ();
8463 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8464 * GTK_WIDGET (scrolled_window));
8465 * g_object_ref (scrolled_window->hscrollbar);
8469 gtk_widget_push_composite_child (void)
8471 composite_child_stack++;
8475 * gtk_widget_pop_composite_child:
8477 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8480 gtk_widget_pop_composite_child (void)
8482 if (composite_child_stack)
8483 composite_child_stack--;
8487 * gtk_widget_push_colormap:
8488 * @cmap: a #GdkColormap
8490 * Pushes @cmap onto a global stack of colormaps; the topmost
8491 * colormap on the stack will be used to create all widgets.
8492 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8493 * reason to use this function.
8496 gtk_widget_push_colormap (GdkColormap *cmap)
8498 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8500 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8504 * gtk_widget_pop_colormap:
8506 * Removes a colormap pushed with gtk_widget_push_colormap().
8509 gtk_widget_pop_colormap (void)
8512 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8516 * gtk_widget_set_default_colormap:
8517 * @colormap: a #GdkColormap
8519 * Sets the default colormap to use when creating widgets.
8520 * gtk_widget_push_colormap() is a better function to use if
8521 * you only want to affect a few widgets, rather than all widgets.
8524 gtk_widget_set_default_colormap (GdkColormap *colormap)
8526 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8528 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8533 * gtk_widget_get_default_colormap:
8535 * Obtains the default colormap used to create widgets.
8537 * Return value: (transfer none): default widget colormap
8540 gtk_widget_get_default_colormap (void)
8542 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8546 * gtk_widget_get_default_visual:
8548 * Obtains the visual of the default colormap. Not really useful;
8549 * used to be useful before gdk_colormap_get_visual() existed.
8551 * Return value: (transfer none): visual of the default colormap
8554 gtk_widget_get_default_visual (void)
8556 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8560 gtk_widget_emit_direction_changed (GtkWidget *widget,
8561 GtkTextDirection old_dir)
8563 gtk_widget_update_pango_context (widget);
8565 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8569 * gtk_widget_set_direction:
8570 * @widget: a #GtkWidget
8571 * @dir: the new direction
8573 * Sets the reading direction on a particular widget. This direction
8574 * controls the primary direction for widgets containing text,
8575 * and also the direction in which the children of a container are
8576 * packed. The ability to set the direction is present in order
8577 * so that correct localization into languages with right-to-left
8578 * reading directions can be done. Generally, applications will
8579 * let the default reading direction present, except for containers
8580 * where the containers are arranged in an order that is explicitely
8581 * visual rather than logical (such as buttons for text justification).
8583 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8584 * set by gtk_widget_set_default_direction() will be used.
8587 gtk_widget_set_direction (GtkWidget *widget,
8588 GtkTextDirection dir)
8590 GtkTextDirection old_dir;
8592 g_return_if_fail (GTK_IS_WIDGET (widget));
8593 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8595 old_dir = gtk_widget_get_direction (widget);
8597 if (dir == GTK_TEXT_DIR_NONE)
8598 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8601 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8602 if (dir == GTK_TEXT_DIR_LTR)
8603 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8605 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8608 if (old_dir != gtk_widget_get_direction (widget))
8609 gtk_widget_emit_direction_changed (widget, old_dir);
8613 * gtk_widget_get_direction:
8614 * @widget: a #GtkWidget
8616 * Gets the reading direction for a particular widget. See
8617 * gtk_widget_set_direction().
8619 * Return value: the reading direction for the widget.
8622 gtk_widget_get_direction (GtkWidget *widget)
8624 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8626 if (GTK_WIDGET_DIRECTION_SET (widget))
8627 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8629 return gtk_default_direction;
8633 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8635 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8637 g_object_ref (widget);
8639 if (!GTK_WIDGET_DIRECTION_SET (widget))
8640 gtk_widget_emit_direction_changed (widget, old_dir);
8642 if (GTK_IS_CONTAINER (widget))
8643 gtk_container_forall (GTK_CONTAINER (widget),
8644 gtk_widget_set_default_direction_recurse,
8647 g_object_unref (widget);
8651 * gtk_widget_set_default_direction:
8652 * @dir: the new default direction. This cannot be
8653 * %GTK_TEXT_DIR_NONE.
8655 * Sets the default reading direction for widgets where the
8656 * direction has not been explicitly set by gtk_widget_set_direction().
8659 gtk_widget_set_default_direction (GtkTextDirection dir)
8661 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8663 if (dir != gtk_default_direction)
8665 GList *toplevels, *tmp_list;
8666 GtkTextDirection old_dir = gtk_default_direction;
8668 gtk_default_direction = dir;
8670 tmp_list = toplevels = gtk_window_list_toplevels ();
8671 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8675 gtk_widget_set_default_direction_recurse (tmp_list->data,
8676 GUINT_TO_POINTER (old_dir));
8677 g_object_unref (tmp_list->data);
8678 tmp_list = tmp_list->next;
8681 g_list_free (toplevels);
8686 * gtk_widget_get_default_direction:
8688 * Obtains the current default reading direction. See
8689 * gtk_widget_set_default_direction().
8691 * Return value: the current default direction.
8694 gtk_widget_get_default_direction (void)
8696 return gtk_default_direction;
8700 gtk_widget_dispose (GObject *object)
8702 GtkWidget *widget = GTK_WIDGET (object);
8705 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8706 else if (gtk_widget_get_visible (widget))
8707 gtk_widget_hide (widget);
8709 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8710 if (gtk_widget_get_realized (widget))
8711 gtk_widget_unrealize (widget);
8713 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8717 gtk_widget_real_destroy (GtkObject *object)
8719 /* gtk_object_destroy() will already hold a refcount on object */
8720 GtkWidget *widget = GTK_WIDGET (object);
8722 /* wipe accelerator closures (keep order) */
8723 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8724 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8726 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8727 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8729 gtk_grab_remove (widget);
8731 g_object_unref (widget->style);
8732 widget->style = gtk_widget_get_default_style ();
8733 g_object_ref (widget->style);
8735 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8739 gtk_widget_finalize (GObject *object)
8741 GtkWidget *widget = GTK_WIDGET (object);
8742 GtkWidgetAuxInfo *aux_info;
8743 GtkAccessible *accessible;
8745 gtk_grab_remove (widget);
8747 g_object_unref (widget->style);
8748 widget->style = NULL;
8750 g_free (widget->name);
8752 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8754 gtk_widget_aux_info_destroy (aux_info);
8756 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8758 g_object_unref (accessible);
8760 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8763 /*****************************************
8764 * gtk_widget_real_map:
8769 *****************************************/
8772 gtk_widget_real_map (GtkWidget *widget)
8774 g_assert (gtk_widget_get_realized (widget));
8776 if (!gtk_widget_get_mapped (widget))
8778 gtk_widget_set_mapped (widget, TRUE);
8780 if (gtk_widget_get_has_window (widget))
8781 gdk_window_show (widget->window);
8785 /*****************************************
8786 * gtk_widget_real_unmap:
8791 *****************************************/
8794 gtk_widget_real_unmap (GtkWidget *widget)
8796 if (gtk_widget_get_mapped (widget))
8798 gtk_widget_set_mapped (widget, FALSE);
8800 if (gtk_widget_get_has_window (widget))
8801 gdk_window_hide (widget->window);
8805 /*****************************************
8806 * gtk_widget_real_realize:
8811 *****************************************/
8814 gtk_widget_real_realize (GtkWidget *widget)
8816 g_assert (!gtk_widget_get_has_window (widget));
8818 gtk_widget_set_realized (widget, TRUE);
8821 widget->window = gtk_widget_get_parent_window (widget);
8822 g_object_ref (widget->window);
8824 widget->style = gtk_style_attach (widget->style, widget->window);
8827 /*****************************************
8828 * gtk_widget_real_unrealize:
8833 *****************************************/
8836 gtk_widget_real_unrealize (GtkWidget *widget)
8838 if (gtk_widget_get_mapped (widget))
8839 gtk_widget_real_unmap (widget);
8841 gtk_widget_set_mapped (widget, FALSE);
8843 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8846 /* We must do unrealize child widget BEFORE container widget.
8847 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8848 * So, unrealizing container widget bofore its children causes the problem
8849 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8852 if (GTK_IS_CONTAINER (widget))
8853 gtk_container_forall (GTK_CONTAINER (widget),
8854 (GtkCallback) gtk_widget_unrealize,
8857 gtk_style_detach (widget->style);
8858 if (gtk_widget_get_has_window (widget))
8860 gdk_window_set_user_data (widget->window, NULL);
8861 gdk_window_destroy (widget->window);
8862 widget->window = NULL;
8866 g_object_unref (widget->window);
8867 widget->window = NULL;
8870 gtk_selection_remove_all (widget);
8872 gtk_widget_set_realized (widget, FALSE);
8876 gtk_widget_real_size_request (GtkWidget *widget,
8877 GtkRequisition *requisition)
8879 requisition->width = widget->requisition.width;
8880 requisition->height = widget->requisition.height;
8884 * _gtk_widget_peek_colormap:
8886 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8888 * Return value: the currently pushed colormap, or %NULL if there is none.
8891 _gtk_widget_peek_colormap (void)
8894 return (GdkColormap*) colormap_stack->data;
8899 * _gtk_widget_set_pointer_window:
8900 * @widget: a #GtkWidget.
8901 * @pointer_window: the new pointer window.
8903 * Sets pointer window for @widget. Does not ref @pointer_window.
8904 * Actually stores it on the #GdkScreen, but you don't need to know that.
8907 _gtk_widget_set_pointer_window (GtkWidget *widget,
8908 GdkWindow *pointer_window)
8910 g_return_if_fail (GTK_IS_WIDGET (widget));
8912 if (gtk_widget_get_realized (widget))
8914 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8916 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8922 * _gtk_widget_get_pointer_window:
8923 * @widget: a #GtkWidget.
8925 * Return value: the pointer window set on the #GdkScreen @widget is attached
8929 _gtk_widget_get_pointer_window (GtkWidget *widget)
8931 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8933 if (gtk_widget_get_realized (widget))
8935 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8937 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8944 synth_crossing (GtkWidget *widget,
8947 GdkCrossingMode mode,
8948 GdkNotifyType detail)
8952 event = gdk_event_new (type);
8954 event->crossing.window = g_object_ref (window);
8955 event->crossing.send_event = TRUE;
8956 event->crossing.subwindow = g_object_ref (window);
8957 event->crossing.time = GDK_CURRENT_TIME;
8958 event->crossing.x = event->crossing.y = 0;
8959 event->crossing.x_root = event->crossing.y_root = 0;
8960 event->crossing.mode = mode;
8961 event->crossing.detail = detail;
8962 event->crossing.focus = FALSE;
8963 event->crossing.state = 0;
8966 widget = gtk_get_event_widget (event);
8969 gtk_widget_event_internal (widget, event);
8971 gdk_event_free (event);
8975 * _gtk_widget_is_pointer_widget:
8976 * @widget: a #GtkWidget
8978 * Returns %TRUE if the pointer window belongs to @widget.
8981 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8983 if (GTK_WIDGET_HAS_POINTER (widget))
8988 win = _gtk_widget_get_pointer_window (widget);
8991 gdk_window_get_user_data (win, (gpointer *)&wid);
9001 * _gtk_widget_synthesize_crossing:
9002 * @from: the #GtkWidget the virtual pointer is leaving.
9003 * @to: the #GtkWidget the virtual pointer is moving to.
9004 * @mode: the #GdkCrossingMode to place on the synthesized events.
9006 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9008 * The real pointer window is the window that most recently received an enter notify
9009 * event. Windows that don't select for crossing events can't become the real
9010 * poiner window. The real pointer widget that owns the real pointer window. The
9011 * effective pointer window is the same as the real pointer window unless the real
9012 * pointer widget is either insensitive or there is a grab on a widget that is not
9013 * an ancestor of the real pointer widget (in which case the effective pointer
9014 * window should be the root window).
9016 * When the effective pointer window is the same as the real poiner window, we
9017 * receive crossing events from the windowing system. When the effective pointer
9018 * window changes to become different from the real pointer window we synthesize
9019 * crossing events, attempting to follow X protocol rules:
9021 * When the root window becomes the effective pointer window:
9022 * - leave notify on real pointer window, detail Ancestor
9023 * - leave notify on all of its ancestors, detail Virtual
9024 * - enter notify on root window, detail Inferior
9026 * When the root window ceases to be the effective pointer window:
9027 * - leave notify on root window, detail Inferior
9028 * - enter notify on all ancestors of real pointer window, detail Virtual
9029 * - enter notify on real pointer window, detail Ancestor
9032 _gtk_widget_synthesize_crossing (GtkWidget *from,
9034 GdkCrossingMode mode)
9036 GdkWindow *from_window = NULL, *to_window = NULL;
9038 g_return_if_fail (from != NULL || to != NULL);
9041 from_window = GTK_WIDGET_HAS_POINTER (from)
9042 ? _gtk_widget_get_pointer_window (from) : from->window;
9044 to_window = GTK_WIDGET_HAS_POINTER (to)
9045 ? _gtk_widget_get_pointer_window (to) : to->window;
9047 if (from_window == NULL && to_window == NULL)
9049 else if (from_window != NULL && to_window == NULL)
9051 GList *from_ancestors = NULL, *list;
9052 GdkWindow *from_ancestor = from_window;
9054 while (from_ancestor != NULL)
9056 from_ancestor = gdk_window_get_parent (from_ancestor);
9057 if (from_ancestor == NULL)
9059 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9062 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9063 mode, GDK_NOTIFY_ANCESTOR);
9064 for (list = g_list_last (from_ancestors); list; list = list->prev)
9066 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9067 mode, GDK_NOTIFY_VIRTUAL);
9070 /* XXX: enter/inferior on root window? */
9072 g_list_free (from_ancestors);
9074 else if (from_window == NULL && to_window != NULL)
9076 GList *to_ancestors = NULL, *list;
9077 GdkWindow *to_ancestor = to_window;
9079 while (to_ancestor != NULL)
9081 to_ancestor = gdk_window_get_parent (to_ancestor);
9082 if (to_ancestor == NULL)
9084 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9087 /* XXX: leave/inferior on root window? */
9089 for (list = to_ancestors; list; list = list->next)
9091 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9092 mode, GDK_NOTIFY_VIRTUAL);
9094 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9095 mode, GDK_NOTIFY_ANCESTOR);
9097 g_list_free (to_ancestors);
9099 else if (from_window == to_window)
9103 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9104 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9106 while (from_ancestor != NULL || to_ancestor != NULL)
9108 if (from_ancestor != NULL)
9110 from_ancestor = gdk_window_get_parent (from_ancestor);
9111 if (from_ancestor == to_window)
9114 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9116 if (to_ancestor != NULL)
9118 to_ancestor = gdk_window_get_parent (to_ancestor);
9119 if (to_ancestor == from_window)
9122 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9125 if (to_ancestor == from_window)
9127 if (mode != GDK_CROSSING_GTK_UNGRAB)
9128 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9129 mode, GDK_NOTIFY_INFERIOR);
9130 for (list = to_ancestors; list; list = list->next)
9131 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9132 mode, GDK_NOTIFY_VIRTUAL);
9133 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9134 mode, GDK_NOTIFY_ANCESTOR);
9136 else if (from_ancestor == to_window)
9138 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9139 mode, GDK_NOTIFY_ANCESTOR);
9140 for (list = g_list_last (from_ancestors); list; list = list->prev)
9142 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9143 mode, GDK_NOTIFY_VIRTUAL);
9145 if (mode != GDK_CROSSING_GTK_GRAB)
9146 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9147 mode, GDK_NOTIFY_INFERIOR);
9151 while (from_ancestors != NULL && to_ancestors != NULL
9152 && from_ancestors->data == to_ancestors->data)
9154 from_ancestors = g_list_delete_link (from_ancestors,
9156 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9159 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9160 mode, GDK_NOTIFY_NONLINEAR);
9162 for (list = g_list_last (from_ancestors); list; list = list->prev)
9164 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9165 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9167 for (list = to_ancestors; list; list = list->next)
9169 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9170 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9172 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9173 mode, GDK_NOTIFY_NONLINEAR);
9175 g_list_free (from_ancestors);
9176 g_list_free (to_ancestors);
9181 gtk_widget_propagate_state (GtkWidget *widget,
9184 guint8 old_state = gtk_widget_get_state (widget);
9185 guint8 old_saved_state = widget->saved_state;
9187 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9188 * parent_sensitive==TRUE on a sensitive widget
9192 if (data->parent_sensitive)
9193 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9195 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9197 if (gtk_widget_is_sensitive (widget))
9199 if (data->state_restoration)
9200 widget->state = widget->saved_state;
9202 widget->state = data->state;
9206 if (!data->state_restoration)
9208 if (data->state != GTK_STATE_INSENSITIVE)
9209 widget->saved_state = data->state;
9211 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9212 widget->saved_state = gtk_widget_get_state (widget);
9213 widget->state = GTK_STATE_INSENSITIVE;
9216 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9220 window = gtk_widget_get_toplevel (widget);
9221 if (window && gtk_widget_is_toplevel (window))
9222 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9225 if (old_state != gtk_widget_get_state (widget) ||
9226 old_saved_state != widget->saved_state)
9228 g_object_ref (widget);
9230 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9231 gtk_grab_remove (widget);
9233 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9235 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9237 if (!gtk_widget_is_sensitive (widget))
9238 _gtk_widget_synthesize_crossing (widget, NULL,
9239 GDK_CROSSING_STATE_CHANGED);
9240 else if (old_state == GTK_STATE_INSENSITIVE)
9241 _gtk_widget_synthesize_crossing (NULL, widget,
9242 GDK_CROSSING_STATE_CHANGED);
9245 if (GTK_IS_CONTAINER (widget))
9247 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9248 if (data->use_forall)
9249 gtk_container_forall (GTK_CONTAINER (widget),
9250 (GtkCallback) gtk_widget_propagate_state,
9253 gtk_container_foreach (GTK_CONTAINER (widget),
9254 (GtkCallback) gtk_widget_propagate_state,
9257 g_object_unref (widget);
9262 * _gtk_widget_get_aux_info:
9263 * @widget: a #GtkWidget
9264 * @create: if %TRUE, create the structure if it doesn't exist
9266 * Get the #GtkWidgetAuxInfo structure for the widget.
9268 * Return value: the #GtkAuxInfo structure for the widget, or
9269 * %NULL if @create is %FALSE and one doesn't already exist.
9272 _gtk_widget_get_aux_info (GtkWidget *widget,
9275 GtkWidgetAuxInfo *aux_info;
9277 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9278 if (!aux_info && create)
9280 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9282 aux_info->width = -1;
9283 aux_info->height = -1;
9285 aux_info->cached_width_age = 1;
9286 aux_info->cached_height_age = 1;
9288 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9295 /*****************************************
9296 * gtk_widget_aux_info_destroy:
9301 *****************************************/
9304 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9306 g_slice_free (GtkWidgetAuxInfo, aux_info);
9310 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9312 g_object_unref (info->shape_mask);
9313 g_slice_free (GtkWidgetShapeInfo, info);
9317 * gtk_widget_shape_combine_mask:
9318 * @widget: a #GtkWidget
9319 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9320 * @offset_x: X position of shape mask with respect to @window
9321 * @offset_y: Y position of shape mask with respect to @window
9323 * Sets a shape for this widget's GDK window. This allows for
9324 * transparent windows etc., see gdk_window_shape_combine_mask()
9325 * for more information.
9328 gtk_widget_shape_combine_mask (GtkWidget *widget,
9329 GdkBitmap *shape_mask,
9333 GtkWidgetShapeInfo* shape_info;
9335 g_return_if_fail (GTK_IS_WIDGET (widget));
9336 /* set_shape doesn't work on widgets without gdk window */
9337 g_return_if_fail (gtk_widget_get_has_window (widget));
9341 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9344 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9346 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9350 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9352 shape_info = g_slice_new (GtkWidgetShapeInfo);
9353 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9354 (GDestroyNotify) gtk_widget_shape_info_destroy);
9356 shape_info->shape_mask = g_object_ref (shape_mask);
9357 shape_info->offset_x = offset_x;
9358 shape_info->offset_y = offset_y;
9360 /* set shape if widget has a gdk window already.
9361 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9364 gdk_window_shape_combine_mask (widget->window, shape_mask,
9365 offset_x, offset_y);
9370 * gtk_widget_input_shape_combine_mask:
9371 * @widget: a #GtkWidget
9372 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9373 * @offset_x: X position of shape mask with respect to @window
9374 * @offset_y: Y position of shape mask with respect to @window
9376 * Sets an input shape for this widget's GDK window. This allows for
9377 * windows which react to mouse click in a nonrectangular region, see
9378 * gdk_window_input_shape_combine_mask() for more information.
9383 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9384 GdkBitmap *shape_mask,
9388 GtkWidgetShapeInfo* shape_info;
9390 g_return_if_fail (GTK_IS_WIDGET (widget));
9391 /* set_shape doesn't work on widgets without gdk window */
9392 g_return_if_fail (gtk_widget_get_has_window (widget));
9397 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9399 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9403 shape_info = g_slice_new (GtkWidgetShapeInfo);
9404 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9406 (GDestroyNotify) gtk_widget_shape_info_destroy);
9408 shape_info->shape_mask = g_object_ref (shape_mask);
9409 shape_info->offset_x = offset_x;
9410 shape_info->offset_y = offset_y;
9412 /* set shape if widget has a gdk window already.
9413 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9416 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9417 offset_x, offset_y);
9423 gtk_reset_shapes_recurse (GtkWidget *widget,
9429 gdk_window_get_user_data (window, &data);
9433 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9434 for (list = gdk_window_peek_children (window); list; list = list->next)
9435 gtk_reset_shapes_recurse (widget, list->data);
9439 * gtk_widget_reset_shapes:
9440 * @widget: a #GtkWidget
9442 * Recursively resets the shape on this widget and its descendants.
9445 gtk_widget_reset_shapes (GtkWidget *widget)
9447 g_return_if_fail (GTK_IS_WIDGET (widget));
9448 g_return_if_fail (gtk_widget_get_realized (widget));
9450 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9451 gtk_reset_shapes_recurse (widget, widget->window);
9456 * @widget: a #GtkWidget
9458 * Adds a reference to a widget. This function is exactly the same
9459 * as calling g_object_ref(), and exists mostly for historical
9460 * reasons. It can still be convenient to avoid casting a widget
9461 * to a #GObject, it saves a small amount of typing.
9463 * Return value: the widget that was referenced
9465 * Deprecated: 2.12: Use g_object_ref() instead.
9468 gtk_widget_ref (GtkWidget *widget)
9470 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9472 return (GtkWidget*) g_object_ref ((GObject*) widget);
9477 * @widget: a #GtkWidget
9479 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9481 * Deprecated: 2.12: Use g_object_unref() instead.
9484 gtk_widget_unref (GtkWidget *widget)
9486 g_return_if_fail (GTK_IS_WIDGET (widget));
9488 g_object_unref ((GObject*) widget);
9492 expose_window (GdkWindow *window)
9495 GList *l, *children;
9497 gboolean is_double_buffered;
9499 gdk_window_get_user_data (window, &user_data);
9502 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9504 is_double_buffered = FALSE;
9506 event.expose.type = GDK_EXPOSE;
9507 event.expose.window = g_object_ref (window);
9508 event.expose.send_event = FALSE;
9509 event.expose.count = 0;
9510 event.expose.area.x = 0;
9511 event.expose.area.y = 0;
9512 gdk_drawable_get_size (GDK_DRAWABLE (window),
9513 &event.expose.area.width,
9514 &event.expose.area.height);
9515 event.expose.region = gdk_region_rectangle (&event.expose.area);
9517 /* If this is not double buffered, force a double buffer so that
9518 redirection works. */
9519 if (!is_double_buffered)
9520 gdk_window_begin_paint_region (window, event.expose.region);
9522 gtk_main_do_event (&event);
9524 if (!is_double_buffered)
9525 gdk_window_end_paint (window);
9527 children = gdk_window_peek_children (window);
9528 for (l = children; l != NULL; l = l->next)
9530 GdkWindow *child = l->data;
9532 /* Don't expose input-only windows */
9533 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9534 expose_window (l->data);
9537 g_object_unref (window);
9541 * gtk_widget_get_snapshot:
9542 * @widget: a #GtkWidget
9543 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9545 * Create a #GdkPixmap of the contents of the widget and its children.
9547 * Works even if the widget is obscured. The depth and visual of the
9548 * resulting pixmap is dependent on the widget being snapshot and likely
9549 * differs from those of a target widget displaying the pixmap.
9550 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9551 * the pixmap to a visual independant representation.
9553 * The snapshot area used by this function is the @widget's allocation plus
9554 * any extra space occupied by additional windows belonging to this widget
9555 * (such as the arrows of a spin button).
9556 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9558 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9559 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9560 * interpreted widget relative. If width or height of @clip_rect are 0 or
9561 * negative, the width or height of the resulting pixmap will be shrunken
9562 * by the respective amount.
9563 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9564 * chop off 5 pixels at each side of the snapshot pixmap.
9565 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9566 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9567 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9568 * as a pure output parameter.
9570 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9572 * Return value: #GdkPixmap snapshot of the widget
9577 gtk_widget_get_snapshot (GtkWidget *widget,
9578 GdkRectangle *clip_rect)
9580 int x, y, width, height;
9581 GdkWindow *parent_window = NULL;
9583 GList *windows = NULL, *list;
9585 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9586 if (!gtk_widget_get_visible (widget))
9589 /* the widget (and parent_window) must be realized to be drawable */
9590 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9591 gtk_widget_realize (widget->parent);
9592 if (!gtk_widget_get_realized (widget))
9593 gtk_widget_realize (widget);
9595 /* determine snapshot rectangle */
9596 x = widget->allocation.x;
9597 y = widget->allocation.y;
9598 width = widget->allocation.width;
9599 height = widget->allocation.height;
9601 if (widget->parent && gtk_widget_get_has_window (widget))
9603 /* grow snapshot rectangle to cover all widget windows */
9604 parent_window = gtk_widget_get_parent_window (widget);
9605 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9607 GdkWindow *subwin = list->data;
9610 gdk_window_get_user_data (subwin, &windata);
9611 if (windata != widget)
9613 windows = g_list_prepend (windows, subwin);
9614 gdk_window_get_position (subwin, &wx, &wy);
9615 gdk_drawable_get_size (subwin, &ww, &wh);
9616 /* grow snapshot rectangle by extra widget sub window */
9627 if (x + width < wx + ww)
9628 width += wx + ww - (x + width);
9629 if (y + height < wy + wh)
9630 height += wy + wh - (y + height);
9633 else if (!widget->parent)
9634 x = y = 0; /* toplevel */
9636 /* at this point, (x,y,width,height) is the parent_window relative
9637 * snapshot area covering all of widget's windows.
9640 /* shrink snapshot size by clip_rectangle */
9643 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9644 clip.x = clip.x < 0 ? x : clip.x;
9645 clip.y = clip.y < 0 ? y : clip.y;
9646 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9647 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9650 /* offset clip_rect, so it's parent_window relative */
9651 if (clip_rect->x >= 0)
9652 clip.x += widget->allocation.x;
9653 if (clip_rect->y >= 0)
9654 clip.y += widget->allocation.y;
9656 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9658 g_list_free (windows);
9659 clip_rect->width = clip_rect->height = 0;
9660 return NULL; /* empty snapshot area */
9665 height = snap.height;
9668 /* render snapshot */
9669 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9670 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9672 GdkWindow *subwin = list->data;
9674 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9675 continue; /* Input only window */
9676 gdk_window_get_position (subwin, &wx, &wy);
9677 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9678 MAX (0, wx - x), MAX (0, wy - y), width, height);
9680 expose_window (subwin);
9682 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9684 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9685 expose_window (widget->window);
9687 for (list = windows; list; list = list->next)
9688 gdk_window_remove_redirection (list->data);
9689 if (!windows) /* NO_WINDOW || toplevel */
9690 gdk_window_remove_redirection (widget->window);
9691 g_list_free (windows);
9693 /* return pixmap and snapshot rectangle coordinates */
9698 clip_rect->width = width;
9699 clip_rect->height = height;
9702 /* offset clip_rect from parent_window so it's widget relative */
9703 clip_rect->x -= widget->allocation.x;
9704 clip_rect->y -= widget->allocation.y;
9707 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9708 G_OBJECT_TYPE_NAME (widget),
9709 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9718 * gtk_widget_class_install_style_property_parser:
9719 * @klass: a #GtkWidgetClass
9720 * @pspec: the #GParamSpec for the style property
9721 * @parser: the parser for the style property
9723 * Installs a style property on a widget class.
9726 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9728 GtkRcPropertyParser parser)
9730 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9731 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9732 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9733 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9735 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9737 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9738 G_OBJECT_CLASS_NAME (klass),
9743 g_param_spec_ref_sink (pspec);
9744 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9745 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9749 * gtk_widget_class_install_style_property:
9750 * @klass: a #GtkWidgetClass
9751 * @pspec: the #GParamSpec for the property
9753 * Installs a style property on a widget class. The parser for the
9754 * style property is determined by the value type of @pspec.
9757 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9760 GtkRcPropertyParser parser;
9762 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9763 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9765 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9767 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9771 * gtk_widget_class_find_style_property:
9772 * @klass: a #GtkWidgetClass
9773 * @property_name: the name of the style property to find
9774 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9775 * style property with that name.
9777 * Finds a style property of a widget class by name.
9782 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9783 const gchar *property_name)
9785 g_return_val_if_fail (property_name != NULL, NULL);
9787 return g_param_spec_pool_lookup (style_property_spec_pool,
9789 G_OBJECT_CLASS_TYPE (klass),
9794 * gtk_widget_class_list_style_properties:
9795 * @klass: a #GtkWidgetClass
9796 * @n_properties: location to return the number of style properties found
9797 * @returns: an newly allocated array of #GParamSpec*. The array must
9798 * be freed with g_free().
9800 * Returns all style properties of a widget class.
9805 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9806 guint *n_properties)
9808 GParamSpec **pspecs;
9811 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9812 G_OBJECT_CLASS_TYPE (klass),
9821 * gtk_widget_style_get_property:
9822 * @widget: a #GtkWidget
9823 * @property_name: the name of a style property
9824 * @value: location to return the property value
9826 * Gets the value of a style property of @widget.
9829 gtk_widget_style_get_property (GtkWidget *widget,
9830 const gchar *property_name,
9835 g_return_if_fail (GTK_IS_WIDGET (widget));
9836 g_return_if_fail (property_name != NULL);
9837 g_return_if_fail (G_IS_VALUE (value));
9839 g_object_ref (widget);
9840 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9842 G_OBJECT_TYPE (widget),
9845 g_warning ("%s: widget class `%s' has no property named `%s'",
9847 G_OBJECT_TYPE_NAME (widget),
9851 const GValue *peek_value;
9853 peek_value = _gtk_style_peek_property_value (widget->style,
9854 G_OBJECT_TYPE (widget),
9856 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9858 /* auto-conversion of the caller's value type
9860 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9861 g_value_copy (peek_value, value);
9862 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9863 g_value_transform (peek_value, value);
9865 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9867 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9868 G_VALUE_TYPE_NAME (value));
9870 g_object_unref (widget);
9874 * gtk_widget_style_get_valist:
9875 * @widget: a #GtkWidget
9876 * @first_property_name: the name of the first property to get
9877 * @var_args: a <type>va_list</type> of pairs of property names and
9878 * locations to return the property values, starting with the location
9879 * for @first_property_name.
9881 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9885 gtk_widget_style_get_valist (GtkWidget *widget,
9886 const gchar *first_property_name,
9891 g_return_if_fail (GTK_IS_WIDGET (widget));
9893 g_object_ref (widget);
9895 name = first_property_name;
9898 const GValue *peek_value;
9902 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9904 G_OBJECT_TYPE (widget),
9908 g_warning ("%s: widget class `%s' has no property named `%s'",
9910 G_OBJECT_TYPE_NAME (widget),
9914 /* style pspecs are always readable so we can spare that check here */
9916 peek_value = _gtk_style_peek_property_value (widget->style,
9917 G_OBJECT_TYPE (widget),
9919 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9920 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9923 g_warning ("%s: %s", G_STRLOC, error);
9928 name = va_arg (var_args, gchar*);
9931 g_object_unref (widget);
9935 * gtk_widget_style_get:
9936 * @widget: a #GtkWidget
9937 * @first_property_name: the name of the first property to get
9938 * @Varargs: pairs of property names and locations to
9939 * return the property values, starting with the location for
9940 * @first_property_name, terminated by %NULL.
9942 * Gets the values of a multiple style properties of @widget.
9945 gtk_widget_style_get (GtkWidget *widget,
9946 const gchar *first_property_name,
9951 g_return_if_fail (GTK_IS_WIDGET (widget));
9953 va_start (var_args, first_property_name);
9954 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9960 * @widget: a #GtkWidget
9961 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
9962 * @path: (out) (allow-none): location to store allocated path string, or %NULL
9963 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
9965 * Obtains the full path to @widget. The path is simply the name of a
9966 * widget and all its parents in the container hierarchy, separated by
9967 * periods. The name of a widget comes from
9968 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9969 * in gtkrc configuration files. Widget names are the type of the
9970 * widget by default (e.g. "GtkButton") or can be set to an
9971 * application-specific value with gtk_widget_set_name(). By setting
9972 * the name of a widget, you allow users or theme authors to apply
9973 * styles to that specific widget in their gtkrc
9974 * file. @path_reversed_p fills in the path in reverse order,
9975 * i.e. starting with @widget's name instead of starting with the name
9976 * of @widget's outermost ancestor.
9979 gtk_widget_path (GtkWidget *widget,
9982 gchar **path_reversed)
9984 static gchar *rev_path = NULL;
9985 static guint tmp_path_len = 0;
9988 g_return_if_fail (GTK_IS_WIDGET (widget));
9993 const gchar *string;
9998 string = gtk_widget_get_name (widget);
9999 l = strlen (string);
10000 while (tmp_path_len <= len + l + 1)
10002 tmp_path_len += INIT_PATH_SIZE;
10003 rev_path = g_realloc (rev_path, tmp_path_len);
10005 s = string + l - 1;
10006 d = rev_path + len;
10007 while (s >= string)
10011 widget = widget->parent;
10014 rev_path[len++] = '.';
10016 rev_path[len++] = 0;
10021 *path_length = len - 1;
10023 *path_reversed = g_strdup (rev_path);
10026 *path = g_strdup (rev_path);
10027 g_strreverse (*path);
10032 * gtk_widget_class_path:
10033 * @widget: a #GtkWidget
10034 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10035 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10036 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10039 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10040 * never uses a custom name set with gtk_widget_set_name().
10044 gtk_widget_class_path (GtkWidget *widget,
10045 guint *path_length,
10047 gchar **path_reversed)
10049 static gchar *rev_path = NULL;
10050 static guint tmp_path_len = 0;
10053 g_return_if_fail (GTK_IS_WIDGET (widget));
10058 const gchar *string;
10063 string = g_type_name (G_OBJECT_TYPE (widget));
10064 l = strlen (string);
10065 while (tmp_path_len <= len + l + 1)
10067 tmp_path_len += INIT_PATH_SIZE;
10068 rev_path = g_realloc (rev_path, tmp_path_len);
10070 s = string + l - 1;
10071 d = rev_path + len;
10072 while (s >= string)
10076 widget = widget->parent;
10079 rev_path[len++] = '.';
10081 rev_path[len++] = 0;
10086 *path_length = len - 1;
10088 *path_reversed = g_strdup (rev_path);
10091 *path = g_strdup (rev_path);
10092 g_strreverse (*path);
10097 * gtk_requisition_copy:
10098 * @requisition: a #GtkRequisition
10100 * Copies a #GtkRequisition.
10102 * Returns: a copy of @requisition
10105 gtk_requisition_copy (const GtkRequisition *requisition)
10107 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10111 * gtk_requisition_free:
10112 * @requisition: a #GtkRequisition
10114 * Frees a #GtkRequisition.
10117 gtk_requisition_free (GtkRequisition *requisition)
10119 g_free (requisition);
10123 gtk_requisition_get_type (void)
10125 static GType our_type = 0;
10128 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10129 (GBoxedCopyFunc) gtk_requisition_copy,
10130 (GBoxedFreeFunc) gtk_requisition_free);
10136 * gtk_widget_get_accessible:
10137 * @widget: a #GtkWidget
10139 * Returns the accessible object that describes the widget to an
10140 * assistive technology.
10142 * If no accessibility library is loaded (i.e. no ATK implementation library is
10143 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10144 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10145 * if no class-specific #AtkObject implementation is available for the widget
10146 * instance in question, it will inherit an #AtkObject implementation from the
10147 * first ancestor class for which such an implementation is defined.
10149 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10150 * library contains more information about accessible objects and their uses.
10152 * Returns: (transfer none): the #AtkObject associated with @widget
10155 gtk_widget_get_accessible (GtkWidget *widget)
10157 GtkWidgetClass *klass;
10159 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10161 klass = GTK_WIDGET_GET_CLASS (widget);
10163 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10165 return klass->get_accessible (widget);
10169 gtk_widget_real_get_accessible (GtkWidget *widget)
10171 AtkObject* accessible;
10173 accessible = g_object_get_qdata (G_OBJECT (widget),
10174 quark_accessible_object);
10177 AtkObjectFactory *factory;
10178 AtkRegistry *default_registry;
10180 default_registry = atk_get_default_registry ();
10181 factory = atk_registry_get_factory (default_registry,
10182 G_TYPE_FROM_INSTANCE (widget));
10184 atk_object_factory_create_accessible (factory,
10185 G_OBJECT (widget));
10186 g_object_set_qdata (G_OBJECT (widget),
10187 quark_accessible_object,
10194 * Initialize a AtkImplementorIface instance's virtual pointers as
10195 * appropriate to this implementor's class (GtkWidget).
10198 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10200 iface->ref_accessible = gtk_widget_ref_accessible;
10204 gtk_widget_ref_accessible (AtkImplementor *implementor)
10206 AtkObject *accessible;
10208 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10210 g_object_ref (accessible);
10215 * GtkBuildable implementation
10217 static GQuark quark_builder_has_default = 0;
10218 static GQuark quark_builder_has_focus = 0;
10219 static GQuark quark_builder_atk_relations = 0;
10220 static GQuark quark_builder_set_name = 0;
10223 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10225 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10226 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10227 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10228 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10230 iface->set_name = gtk_widget_buildable_set_name;
10231 iface->get_name = gtk_widget_buildable_get_name;
10232 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10233 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10234 iface->parser_finished = gtk_widget_buildable_parser_finished;
10235 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10236 iface->custom_finished = gtk_widget_buildable_custom_finished;
10240 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10243 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10244 g_strdup (name), g_free);
10247 static const gchar *
10248 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10250 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10254 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10255 GtkBuilder *builder,
10256 const gchar *childname)
10258 if (strcmp (childname, "accessible") == 0)
10259 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10265 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10266 GtkBuilder *builder,
10268 const GValue *value)
10270 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10271 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10272 GINT_TO_POINTER (TRUE));
10273 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10274 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10275 GINT_TO_POINTER (TRUE));
10277 g_object_set_property (G_OBJECT (buildable), name, value);
10282 gchar *action_name;
10283 GString *description;
10285 gboolean translatable;
10295 free_action (AtkActionData *data, gpointer user_data)
10297 g_free (data->action_name);
10298 g_string_free (data->description, TRUE);
10299 g_free (data->context);
10300 g_slice_free (AtkActionData, data);
10304 free_relation (AtkRelationData *data, gpointer user_data)
10306 g_free (data->target);
10307 g_free (data->type);
10308 g_slice_free (AtkRelationData, data);
10312 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10313 GtkBuilder *builder)
10315 GSList *atk_relations;
10317 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10318 gtk_widget_grab_default (GTK_WIDGET (buildable));
10319 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10320 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10322 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10323 quark_builder_atk_relations);
10326 AtkObject *accessible;
10327 AtkRelationSet *relation_set;
10330 AtkRelationType relation_type;
10331 AtkObject *target_accessible;
10333 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10334 relation_set = atk_object_ref_relation_set (accessible);
10336 for (l = atk_relations; l; l = l->next)
10338 AtkRelationData *relation = (AtkRelationData*)l->data;
10340 target = gtk_builder_get_object (builder, relation->target);
10343 g_warning ("Target object %s in <relation> does not exist",
10347 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10348 g_assert (target_accessible != NULL);
10350 relation_type = atk_relation_type_for_name (relation->type);
10351 if (relation_type == ATK_RELATION_NULL)
10353 g_warning ("<relation> type %s not found",
10357 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10358 target_accessible);
10360 g_object_unref (relation_set);
10362 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10363 g_slist_free (atk_relations);
10364 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10373 } AccessibilitySubParserData;
10376 accessibility_start_element (GMarkupParseContext *context,
10377 const gchar *element_name,
10378 const gchar **names,
10379 const gchar **values,
10380 gpointer user_data,
10383 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10385 gint line_number, char_number;
10387 if (strcmp (element_name, "relation") == 0)
10389 gchar *target = NULL;
10390 gchar *type = NULL;
10391 AtkRelationData *relation;
10393 for (i = 0; names[i]; i++)
10395 if (strcmp (names[i], "target") == 0)
10396 target = g_strdup (values[i]);
10397 else if (strcmp (names[i], "type") == 0)
10398 type = g_strdup (values[i]);
10401 g_markup_parse_context_get_position (context,
10404 g_set_error (error,
10406 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10407 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10409 line_number, char_number, names[i], "relation");
10416 if (!target || !type)
10418 g_markup_parse_context_get_position (context,
10421 g_set_error (error,
10423 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10424 "%s:%d:%d <%s> requires attribute \"%s\"",
10426 line_number, char_number, "relation",
10427 type ? "target" : "type");
10433 relation = g_slice_new (AtkRelationData);
10434 relation->target = target;
10435 relation->type = type;
10437 data->relations = g_slist_prepend (data->relations, relation);
10439 else if (strcmp (element_name, "action") == 0)
10441 const gchar *action_name = NULL;
10442 const gchar *description = NULL;
10443 const gchar *msg_context = NULL;
10444 gboolean translatable = FALSE;
10445 AtkActionData *action;
10447 for (i = 0; names[i]; i++)
10449 if (strcmp (names[i], "action_name") == 0)
10450 action_name = values[i];
10451 else if (strcmp (names[i], "description") == 0)
10452 description = values[i];
10453 else if (strcmp (names[i], "translatable") == 0)
10455 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10458 else if (strcmp (names[i], "comments") == 0)
10460 /* do nothing, comments are for translators */
10462 else if (strcmp (names[i], "context") == 0)
10463 msg_context = values[i];
10466 g_markup_parse_context_get_position (context,
10469 g_set_error (error,
10471 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10472 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10474 line_number, char_number, names[i], "action");
10481 g_markup_parse_context_get_position (context,
10484 g_set_error (error,
10486 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10487 "%s:%d:%d <%s> requires attribute \"%s\"",
10489 line_number, char_number, "action",
10494 action = g_slice_new (AtkActionData);
10495 action->action_name = g_strdup (action_name);
10496 action->description = g_string_new (description);
10497 action->context = g_strdup (msg_context);
10498 action->translatable = translatable;
10500 data->actions = g_slist_prepend (data->actions, action);
10502 else if (strcmp (element_name, "accessibility") == 0)
10505 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10509 accessibility_text (GMarkupParseContext *context,
10512 gpointer user_data,
10515 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10517 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10519 AtkActionData *action = data->actions->data;
10521 g_string_append_len (action->description, text, text_len);
10525 static const GMarkupParser accessibility_parser =
10527 accessibility_start_element,
10529 accessibility_text,
10538 } AccelGroupParserData;
10541 accel_group_start_element (GMarkupParseContext *context,
10542 const gchar *element_name,
10543 const gchar **names,
10544 const gchar **values,
10545 gpointer user_data,
10550 guint modifiers = 0;
10551 gchar *signal = NULL;
10552 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10554 for (i = 0; names[i]; i++)
10556 if (strcmp (names[i], "key") == 0)
10557 key = gdk_keyval_from_name (values[i]);
10558 else if (strcmp (names[i], "modifiers") == 0)
10560 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10566 else if (strcmp (names[i], "signal") == 0)
10567 signal = g_strdup (values[i]);
10570 if (key == 0 || signal == NULL)
10572 g_warning ("<accelerator> requires key and signal attributes");
10575 parser_data->key = key;
10576 parser_data->modifiers = modifiers;
10577 parser_data->signal = signal;
10580 static const GMarkupParser accel_group_parser =
10582 accel_group_start_element,
10586 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10587 GtkBuilder *builder,
10589 const gchar *tagname,
10590 GMarkupParser *parser,
10593 g_assert (buildable);
10595 if (strcmp (tagname, "accelerator") == 0)
10597 AccelGroupParserData *parser_data;
10599 parser_data = g_slice_new0 (AccelGroupParserData);
10600 parser_data->object = g_object_ref (buildable);
10601 *parser = accel_group_parser;
10602 *data = parser_data;
10605 if (strcmp (tagname, "accessibility") == 0)
10607 AccessibilitySubParserData *parser_data;
10609 parser_data = g_slice_new0 (AccessibilitySubParserData);
10610 *parser = accessibility_parser;
10611 *data = parser_data;
10618 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10619 GtkWidget *toplevel,
10620 gpointer user_data)
10622 AccelGroupParserData *accel_data;
10623 GSList *accel_groups;
10624 GtkAccelGroup *accel_group;
10626 g_return_if_fail (GTK_IS_WIDGET (widget));
10627 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10628 g_return_if_fail (user_data != NULL);
10630 accel_data = (AccelGroupParserData*)user_data;
10631 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10632 if (g_slist_length (accel_groups) == 0)
10634 accel_group = gtk_accel_group_new ();
10635 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10639 g_assert (g_slist_length (accel_groups) == 1);
10640 accel_group = g_slist_nth_data (accel_groups, 0);
10643 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10644 accel_data->signal,
10647 accel_data->modifiers,
10648 GTK_ACCEL_VISIBLE);
10650 g_object_unref (accel_data->object);
10651 g_free (accel_data->signal);
10652 g_slice_free (AccelGroupParserData, accel_data);
10656 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10657 GtkBuilder *builder,
10659 const gchar *tagname,
10660 gpointer user_data)
10662 AccelGroupParserData *accel_data;
10663 AccessibilitySubParserData *a11y_data;
10664 GtkWidget *toplevel;
10666 if (strcmp (tagname, "accelerator") == 0)
10668 accel_data = (AccelGroupParserData*)user_data;
10669 g_assert (accel_data->object);
10671 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10673 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10675 else if (strcmp (tagname, "accessibility") == 0)
10677 a11y_data = (AccessibilitySubParserData*)user_data;
10679 if (a11y_data->actions)
10681 AtkObject *accessible;
10686 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10688 action = ATK_ACTION (accessible);
10689 n_actions = atk_action_get_n_actions (action);
10691 for (l = a11y_data->actions; l; l = l->next)
10693 AtkActionData *action_data = (AtkActionData*)l->data;
10695 for (i = 0; i < n_actions; i++)
10696 if (strcmp (atk_action_get_name (action, i),
10697 action_data->action_name) == 0)
10702 gchar *description;
10704 if (action_data->translatable && action_data->description->len)
10705 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10706 action_data->context,
10707 action_data->description->str);
10709 description = action_data->description->str;
10711 atk_action_set_description (action, i, description);
10715 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10716 g_slist_free (a11y_data->actions);
10719 if (a11y_data->relations)
10720 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10721 a11y_data->relations);
10723 g_slice_free (AccessibilitySubParserData, a11y_data);
10728 * GtkExtendedLayout implementation
10731 gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
10732 gint *minimum_size,
10733 gint *natural_size)
10735 /* Set the initial values so that unimplemented classes will fall back
10736 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10739 *minimum_size = GTK_WIDGET (layout)->requisition.width;
10742 *natural_size = GTK_WIDGET (layout)->requisition.width;
10746 gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
10747 gint *minimum_size,
10748 gint *natural_size)
10750 /* Set the initial values so that unimplemented classes will fall back
10751 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10754 *minimum_size = GTK_WIDGET (layout)->requisition.height;
10757 *natural_size = GTK_WIDGET (layout)->requisition.height;
10761 gtk_widget_real_get_height_for_width (GtkExtendedLayout *layout,
10763 gint *minimum_height,
10764 gint *natural_height)
10766 gtk_extended_layout_get_desired_height (layout, minimum_height, natural_height);
10770 gtk_widget_real_get_width_for_height (GtkExtendedLayout *layout,
10772 gint *minimum_width,
10773 gint *natural_width)
10775 gtk_extended_layout_get_desired_width (layout, minimum_width, natural_width);
10779 gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface)
10781 iface->get_desired_width = gtk_widget_real_get_desired_width;
10782 iface->get_desired_height = gtk_widget_real_get_desired_height;
10783 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
10784 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
10789 * gtk_widget_get_clipboard:
10790 * @widget: a #GtkWidget
10791 * @selection: a #GdkAtom which identifies the clipboard
10792 * to use. %GDK_SELECTION_CLIPBOARD gives the
10793 * default clipboard. Another common value
10794 * is %GDK_SELECTION_PRIMARY, which gives
10795 * the primary X selection.
10797 * Returns the clipboard object for the given selection to
10798 * be used with @widget. @widget must have a #GdkDisplay
10799 * associated with it, so must be attached to a toplevel
10802 * Return value: (transfer none): the appropriate clipboard object. If no
10803 * clipboard already exists, a new one will
10804 * be created. Once a clipboard object has
10805 * been created, it is persistent for all time.
10810 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10812 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10813 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10815 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10820 * gtk_widget_list_mnemonic_labels:
10821 * @widget: a #GtkWidget
10823 * Returns a newly allocated list of the widgets, normally labels, for
10824 * which this widget is a the target of a mnemonic (see for example,
10825 * gtk_label_set_mnemonic_widget()).
10827 * The widgets in the list are not individually referenced. If you
10828 * want to iterate through the list and perform actions involving
10829 * callbacks that might destroy the widgets, you
10830 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10831 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10832 * widgets afterwards.
10834 * Return value: (element-type GtkWidget) (transfer container): the list of
10835 * mnemonic labels; free this list
10836 * with g_list_free() when you are done with it.
10841 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10843 GList *list = NULL;
10846 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10848 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10849 list = g_list_prepend (list, l->data);
10855 * gtk_widget_add_mnemonic_label:
10856 * @widget: a #GtkWidget
10857 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10859 * Adds a widget to the list of mnemonic labels for
10860 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10861 * list of mnemonic labels for the widget is cleared when the
10862 * widget is destroyed, so the caller must make sure to update
10863 * its internal state at this point as well, by using a connection
10864 * to the #GtkWidget::destroy signal or a weak notifier.
10869 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10872 GSList *old_list, *new_list;
10874 g_return_if_fail (GTK_IS_WIDGET (widget));
10875 g_return_if_fail (GTK_IS_WIDGET (label));
10877 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10878 new_list = g_slist_prepend (old_list, label);
10880 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10881 new_list, (GDestroyNotify) g_slist_free);
10885 * gtk_widget_remove_mnemonic_label:
10886 * @widget: a #GtkWidget
10887 * @label: a #GtkWidget that was previously set as a mnemnic label for
10888 * @widget with gtk_widget_add_mnemonic_label().
10890 * Removes a widget from the list of mnemonic labels for
10891 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10892 * must have previously been added to the list with
10893 * gtk_widget_add_mnemonic_label().
10898 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10901 GSList *old_list, *new_list;
10903 g_return_if_fail (GTK_IS_WIDGET (widget));
10904 g_return_if_fail (GTK_IS_WIDGET (label));
10906 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10907 new_list = g_slist_remove (old_list, label);
10910 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10911 new_list, (GDestroyNotify) g_slist_free);
10915 * gtk_widget_get_no_show_all:
10916 * @widget: a #GtkWidget
10918 * Returns the current value of the GtkWidget:no-show-all property,
10919 * which determines whether calls to gtk_widget_show_all() and
10920 * gtk_widget_hide_all() will affect this widget.
10922 * Return value: the current value of the "no-show-all" property.
10927 gtk_widget_get_no_show_all (GtkWidget *widget)
10929 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10931 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10935 * gtk_widget_set_no_show_all:
10936 * @widget: a #GtkWidget
10937 * @no_show_all: the new value for the "no-show-all" property
10939 * Sets the #GtkWidget:no-show-all property, which determines whether
10940 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10943 * This is mostly for use in constructing widget hierarchies with externally
10944 * controlled visibility, see #GtkUIManager.
10949 gtk_widget_set_no_show_all (GtkWidget *widget,
10950 gboolean no_show_all)
10952 g_return_if_fail (GTK_IS_WIDGET (widget));
10954 no_show_all = (no_show_all != FALSE);
10956 if (no_show_all == gtk_widget_get_no_show_all (widget))
10960 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
10962 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
10964 g_object_notify (G_OBJECT (widget), "no-show-all");
10969 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10970 gboolean has_tooltip,
10973 gboolean priv_has_tooltip;
10975 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10976 quark_has_tooltip));
10978 if (priv_has_tooltip != has_tooltip || force)
10980 priv_has_tooltip = has_tooltip;
10982 if (priv_has_tooltip)
10984 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
10985 gdk_window_set_events (widget->window,
10986 gdk_window_get_events (widget->window) |
10987 GDK_LEAVE_NOTIFY_MASK |
10988 GDK_POINTER_MOTION_MASK |
10989 GDK_POINTER_MOTION_HINT_MASK);
10991 if (gtk_widget_get_has_window (widget))
10992 gtk_widget_add_events (widget,
10993 GDK_LEAVE_NOTIFY_MASK |
10994 GDK_POINTER_MOTION_MASK |
10995 GDK_POINTER_MOTION_HINT_MASK);
10998 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10999 GUINT_TO_POINTER (priv_has_tooltip));
11004 * gtk_widget_set_tooltip_window:
11005 * @widget: a #GtkWidget
11006 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11008 * Replaces the default, usually yellow, window used for displaying
11009 * tooltips with @custom_window. GTK+ will take care of showing and
11010 * hiding @custom_window at the right moment, to behave likewise as
11011 * the default tooltip window. If @custom_window is %NULL, the default
11012 * tooltip window will be used.
11014 * If the custom window should have the default theming it needs to
11015 * have the name "gtk-tooltip", see gtk_widget_set_name().
11020 gtk_widget_set_tooltip_window (GtkWidget *widget,
11021 GtkWindow *custom_window)
11023 gboolean has_tooltip;
11024 gchar *tooltip_markup;
11026 g_return_if_fail (GTK_IS_WIDGET (widget));
11027 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11029 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11032 g_object_ref (custom_window);
11034 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11035 custom_window, g_object_unref);
11037 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11038 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11040 if (has_tooltip && gtk_widget_get_visible (widget))
11041 gtk_widget_queue_tooltip_query (widget);
11045 * gtk_widget_get_tooltip_window:
11046 * @widget: a #GtkWidget
11048 * Returns the #GtkWindow of the current tooltip. This can be the
11049 * GtkWindow created by default, or the custom tooltip window set
11050 * using gtk_widget_set_tooltip_window().
11052 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11057 gtk_widget_get_tooltip_window (GtkWidget *widget)
11059 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11061 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11065 * gtk_widget_trigger_tooltip_query:
11066 * @widget: a #GtkWidget
11068 * Triggers a tooltip query on the display where the toplevel of @widget
11069 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11075 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11077 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11080 static guint tooltip_query_id;
11081 static GSList *tooltip_query_displays;
11084 tooltip_query_idle (gpointer data)
11086 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11087 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11088 g_slist_free (tooltip_query_displays);
11090 tooltip_query_displays = NULL;
11091 tooltip_query_id = 0;
11097 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11099 GdkDisplay *display;
11101 display = gtk_widget_get_display (widget);
11103 if (!g_slist_find (tooltip_query_displays, display))
11104 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11106 if (tooltip_query_id == 0)
11107 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11111 * gtk_widget_set_tooltip_text:
11112 * @widget: a #GtkWidget
11113 * @text: the contents of the tooltip for @widget
11115 * Sets @text as the contents of the tooltip. This function will take
11116 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11117 * handler for the GtkWidget::query-tooltip signal.
11119 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11124 gtk_widget_set_tooltip_text (GtkWidget *widget,
11127 g_return_if_fail (GTK_IS_WIDGET (widget));
11129 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11133 * gtk_widget_get_tooltip_text:
11134 * @widget: a #GtkWidget
11136 * Gets the contents of the tooltip for @widget.
11138 * Return value: the tooltip text, or %NULL. You should free the
11139 * returned string with g_free() when done.
11144 gtk_widget_get_tooltip_text (GtkWidget *widget)
11146 gchar *text = NULL;
11148 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11150 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11156 * gtk_widget_set_tooltip_markup:
11157 * @widget: a #GtkWidget
11158 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11160 * Sets @markup as the contents of the tooltip, which is marked up with
11161 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11163 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11164 * and of the default handler for the GtkWidget::query-tooltip signal.
11166 * See also the GtkWidget:tooltip-markup property and
11167 * gtk_tooltip_set_markup().
11172 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11173 const gchar *markup)
11175 g_return_if_fail (GTK_IS_WIDGET (widget));
11177 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11181 * gtk_widget_get_tooltip_markup:
11182 * @widget: a #GtkWidget
11184 * Gets the contents of the tooltip for @widget.
11186 * Return value: the tooltip text, or %NULL. You should free the
11187 * returned string with g_free() when done.
11192 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11194 gchar *text = NULL;
11196 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11198 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11204 * gtk_widget_set_has_tooltip:
11205 * @widget: a #GtkWidget
11206 * @has_tooltip: whether or not @widget has a tooltip.
11208 * Sets the has-tooltip property on @widget to @has_tooltip. See
11209 * GtkWidget:has-tooltip for more information.
11214 gtk_widget_set_has_tooltip (GtkWidget *widget,
11215 gboolean has_tooltip)
11217 g_return_if_fail (GTK_IS_WIDGET (widget));
11219 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11223 * gtk_widget_get_has_tooltip:
11224 * @widget: a #GtkWidget
11226 * Returns the current value of the has-tooltip property. See
11227 * GtkWidget:has-tooltip for more information.
11229 * Return value: current value of has-tooltip on @widget.
11234 gtk_widget_get_has_tooltip (GtkWidget *widget)
11236 gboolean has_tooltip = FALSE;
11238 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11240 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11242 return has_tooltip;
11246 * gtk_widget_get_allocation:
11247 * @widget: a #GtkWidget
11248 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11250 * Retrieves the widget's allocation.
11255 gtk_widget_get_allocation (GtkWidget *widget,
11256 GtkAllocation *allocation)
11258 g_return_if_fail (GTK_IS_WIDGET (widget));
11259 g_return_if_fail (allocation != NULL);
11261 *allocation = widget->allocation;
11265 * gtk_widget_set_allocation:
11266 * @widget: a #GtkWidget
11267 * @allocation: a pointer to a #GtkAllocation to copy from
11269 * Sets the widget's allocation. This should not be used
11270 * directly, but from within a widget's size_allocate method.
11275 gtk_widget_set_allocation (GtkWidget *widget,
11276 const GtkAllocation *allocation)
11278 g_return_if_fail (GTK_IS_WIDGET (widget));
11279 g_return_if_fail (allocation != NULL);
11281 widget->allocation = *allocation;
11285 * gtk_widget_get_requisition:
11286 * @widget: a #GtkWidget
11287 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11289 * Retrieves the widget's requisition.
11291 * This function should only be used by widget implementations in
11292 * order to figure whether the widget's requisition has actually
11293 * changed after some internal state change (so that they can call
11294 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11296 * Normally, gtk_widget_size_request() should be used.
11301 gtk_widget_get_requisition (GtkWidget *widget,
11302 GtkRequisition *requisition)
11304 g_return_if_fail (GTK_IS_WIDGET (widget));
11305 g_return_if_fail (requisition != NULL);
11307 *requisition = widget->requisition;
11311 * gtk_widget_set_window:
11312 * @widget: a #GtkWidget
11313 * @window: a #GdkWindow
11315 * Sets a widget's window. This function should only be used in a
11316 * widget's GtkWidget::realize() implementation. The %window passed is
11317 * usually either new window created with gdk_window_new(), or the
11318 * window of its parent widget as returned by
11319 * gtk_widget_get_parent_window().
11321 * Widgets must indicate whether they will create their own #GdkWindow
11322 * by calling gtk_widget_set_has_window(). This is usually done in the
11323 * widget's init() function.
11328 gtk_widget_set_window (GtkWidget *widget,
11331 g_return_if_fail (GTK_IS_WIDGET (widget));
11332 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11334 if (widget->window != window)
11336 widget->window = window;
11337 g_object_notify (G_OBJECT (widget), "window");
11342 * gtk_widget_get_window:
11343 * @widget: a #GtkWidget
11345 * Returns the widget's window if it is realized, %NULL otherwise
11347 * Return value: @widget's window.
11352 gtk_widget_get_window (GtkWidget *widget)
11354 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11356 return widget->window;
11359 #define __GTK_WIDGET_C__
11360 #include "gtkaliasdef.c"