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_layout_interface_init (GtkExtendedLayoutIface *iface);
348 static void gtk_widget_real_get_desired_size (GtkExtendedLayout *layout,
349 GtkRequisition *minimum_size,
350 GtkRequisition *natural_size);
352 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
354 static void gtk_widget_set_usize_internal (GtkWidget *widget,
357 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
361 /* --- variables --- */
362 static gpointer gtk_widget_parent_class = NULL;
363 static guint widget_signals[LAST_SIGNAL] = { 0 };
364 static GtkStyle *gtk_default_style = NULL;
365 static GSList *colormap_stack = NULL;
366 static guint composite_child_stack = 0;
367 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
368 static GParamSpecPool *style_property_spec_pool = NULL;
370 static GQuark quark_property_parser = 0;
371 static GQuark quark_aux_info = 0;
372 static GQuark quark_accel_path = 0;
373 static GQuark quark_accel_closures = 0;
374 static GQuark quark_event_mask = 0;
375 static GQuark quark_extension_event_mode = 0;
376 static GQuark quark_parent_window = 0;
377 static GQuark quark_pointer_window = 0;
378 static GQuark quark_shape_info = 0;
379 static GQuark quark_input_shape_info = 0;
380 static GQuark quark_colormap = 0;
381 static GQuark quark_pango_context = 0;
382 static GQuark quark_rc_style = 0;
383 static GQuark quark_accessible_object = 0;
384 static GQuark quark_mnemonic_labels = 0;
385 static GQuark quark_tooltip_markup = 0;
386 static GQuark quark_has_tooltip = 0;
387 static GQuark quark_tooltip_window = 0;
388 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
389 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
391 /* --- functions --- */
393 gtk_widget_get_type (void)
395 static GType widget_type = 0;
397 if (G_UNLIKELY (widget_type == 0))
399 const GTypeInfo widget_info =
401 sizeof (GtkWidgetClass),
402 NULL, /* base_init */
403 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
404 (GClassInitFunc) gtk_widget_class_init,
405 NULL, /* class_finalize */
406 NULL, /* class_init */
409 (GInstanceInitFunc) gtk_widget_init,
410 NULL, /* value_table */
413 const GInterfaceInfo accessibility_info =
415 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
416 (GInterfaceFinalizeFunc) NULL,
417 NULL /* interface data */
420 const GInterfaceInfo buildable_info =
422 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
423 (GInterfaceFinalizeFunc) NULL,
424 NULL /* interface data */
427 const GInterfaceInfo layout_info =
429 (GInterfaceInitFunc) gtk_widget_layout_interface_init,
430 (GInterfaceFinalizeFunc) NULL,
431 NULL /* interface data */
434 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
435 &widget_info, G_TYPE_FLAG_ABSTRACT);
437 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
438 &accessibility_info) ;
439 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
441 g_type_add_interface_static (widget_type, GTK_TYPE_EXTENDED_LAYOUT,
449 child_property_notify_dispatcher (GObject *object,
453 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
457 gtk_widget_class_init (GtkWidgetClass *klass)
459 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
460 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
461 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
462 GtkBindingSet *binding_set;
464 gtk_widget_parent_class = g_type_class_peek_parent (klass);
466 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
467 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
468 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
469 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
470 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
471 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
472 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
473 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
474 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
475 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
476 quark_colormap = g_quark_from_static_string ("gtk-colormap");
477 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
478 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
479 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
480 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
481 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
482 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
483 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
485 style_property_spec_pool = g_param_spec_pool_new (FALSE);
486 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
487 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
488 cpn_context.dispatcher = child_property_notify_dispatcher;
489 _gtk_widget_child_property_notify_context = &cpn_context;
491 gobject_class->dispose = gtk_widget_dispose;
492 gobject_class->finalize = gtk_widget_finalize;
493 gobject_class->set_property = gtk_widget_set_property;
494 gobject_class->get_property = gtk_widget_get_property;
496 object_class->destroy = gtk_widget_real_destroy;
498 klass->activate_signal = 0;
499 klass->set_scroll_adjustments_signal = 0;
500 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
501 klass->show = gtk_widget_real_show;
502 klass->show_all = gtk_widget_show;
503 klass->hide = gtk_widget_real_hide;
504 klass->hide_all = gtk_widget_hide;
505 klass->map = gtk_widget_real_map;
506 klass->unmap = gtk_widget_real_unmap;
507 klass->realize = gtk_widget_real_realize;
508 klass->unrealize = gtk_widget_real_unrealize;
509 klass->size_request = gtk_widget_real_size_request;
510 klass->size_allocate = gtk_widget_real_size_allocate;
511 klass->state_changed = NULL;
512 klass->parent_set = NULL;
513 klass->hierarchy_changed = NULL;
514 klass->style_set = gtk_widget_real_style_set;
515 klass->direction_changed = gtk_widget_real_direction_changed;
516 klass->grab_notify = NULL;
517 klass->child_notify = NULL;
518 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
519 klass->grab_focus = gtk_widget_real_grab_focus;
520 klass->focus = gtk_widget_real_focus;
522 klass->button_press_event = NULL;
523 klass->button_release_event = NULL;
524 klass->motion_notify_event = NULL;
525 klass->delete_event = NULL;
526 klass->destroy_event = NULL;
527 klass->expose_event = NULL;
528 klass->key_press_event = gtk_widget_real_key_press_event;
529 klass->key_release_event = gtk_widget_real_key_release_event;
530 klass->enter_notify_event = NULL;
531 klass->leave_notify_event = NULL;
532 klass->configure_event = NULL;
533 klass->focus_in_event = gtk_widget_real_focus_in_event;
534 klass->focus_out_event = gtk_widget_real_focus_out_event;
535 klass->map_event = NULL;
536 klass->unmap_event = NULL;
537 klass->window_state_event = NULL;
538 klass->property_notify_event = _gtk_selection_property_notify;
539 klass->selection_clear_event = gtk_selection_clear;
540 klass->selection_request_event = _gtk_selection_request;
541 klass->selection_notify_event = _gtk_selection_notify;
542 klass->selection_received = NULL;
543 klass->proximity_in_event = NULL;
544 klass->proximity_out_event = NULL;
545 klass->drag_begin = NULL;
546 klass->drag_end = NULL;
547 klass->drag_data_delete = NULL;
548 klass->drag_leave = NULL;
549 klass->drag_motion = NULL;
550 klass->drag_drop = NULL;
551 klass->drag_data_received = NULL;
552 klass->screen_changed = NULL;
553 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
554 klass->grab_broken_event = NULL;
555 klass->query_tooltip = gtk_widget_real_query_tooltip;
557 klass->show_help = gtk_widget_real_show_help;
559 /* Accessibility support */
560 klass->get_accessible = gtk_widget_real_get_accessible;
562 klass->no_expose_event = NULL;
564 g_object_class_install_property (gobject_class,
566 g_param_spec_string ("name",
568 P_("The name of the widget"),
570 GTK_PARAM_READWRITE));
571 g_object_class_install_property (gobject_class,
573 g_param_spec_object ("parent",
575 P_("The parent widget of this widget. Must be a Container widget"),
577 GTK_PARAM_READWRITE));
579 g_object_class_install_property (gobject_class,
581 g_param_spec_int ("width-request",
583 P_("Override for width request of the widget, or -1 if natural request should be used"),
587 GTK_PARAM_READWRITE));
588 g_object_class_install_property (gobject_class,
590 g_param_spec_int ("height-request",
591 P_("Height request"),
592 P_("Override for height request of the widget, or -1 if natural request should be used"),
596 GTK_PARAM_READWRITE));
597 g_object_class_install_property (gobject_class,
599 g_param_spec_boolean ("visible",
601 P_("Whether the widget is visible"),
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_boolean ("sensitive",
608 P_("Whether the widget responds to input"),
610 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_boolean ("app-paintable",
614 P_("Application paintable"),
615 P_("Whether the application will paint directly on the widget"),
617 GTK_PARAM_READWRITE));
618 g_object_class_install_property (gobject_class,
620 g_param_spec_boolean ("can-focus",
622 P_("Whether the widget can accept the input focus"),
624 GTK_PARAM_READWRITE));
625 g_object_class_install_property (gobject_class,
627 g_param_spec_boolean ("has-focus",
629 P_("Whether the widget has the input focus"),
631 GTK_PARAM_READWRITE));
632 g_object_class_install_property (gobject_class,
634 g_param_spec_boolean ("is-focus",
636 P_("Whether the widget is the focus widget within the toplevel"),
638 GTK_PARAM_READWRITE));
639 g_object_class_install_property (gobject_class,
641 g_param_spec_boolean ("can-default",
643 P_("Whether the widget can be the default widget"),
645 GTK_PARAM_READWRITE));
646 g_object_class_install_property (gobject_class,
648 g_param_spec_boolean ("has-default",
650 P_("Whether the widget is the default widget"),
652 GTK_PARAM_READWRITE));
653 g_object_class_install_property (gobject_class,
654 PROP_RECEIVES_DEFAULT,
655 g_param_spec_boolean ("receives-default",
656 P_("Receives default"),
657 P_("If TRUE, the widget will receive the default action when it is focused"),
659 GTK_PARAM_READWRITE));
660 g_object_class_install_property (gobject_class,
661 PROP_COMPOSITE_CHILD,
662 g_param_spec_boolean ("composite-child",
663 P_("Composite child"),
664 P_("Whether the widget is part of a composite widget"),
666 GTK_PARAM_READABLE));
667 g_object_class_install_property (gobject_class,
669 g_param_spec_object ("style",
671 P_("The style of the widget, which contains information about how it will look (colors etc)"),
673 GTK_PARAM_READWRITE));
674 g_object_class_install_property (gobject_class,
676 g_param_spec_flags ("events",
678 P_("The event mask that decides what kind of GdkEvents this widget gets"),
681 GTK_PARAM_READWRITE));
682 g_object_class_install_property (gobject_class,
683 PROP_EXTENSION_EVENTS,
684 g_param_spec_enum ("extension-events",
685 P_("Extension events"),
686 P_("The mask that decides what kind of extension events this widget gets"),
687 GDK_TYPE_EXTENSION_MODE,
688 GDK_EXTENSION_EVENTS_NONE,
689 GTK_PARAM_READWRITE));
690 g_object_class_install_property (gobject_class,
692 g_param_spec_boolean ("no-show-all",
694 P_("Whether gtk_widget_show_all() should not affect this widget"),
696 GTK_PARAM_READWRITE));
699 * GtkWidget:has-tooltip:
701 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
702 * A value of %TRUE indicates that @widget can have a tooltip, in this case
703 * the widget will be queried using #GtkWidget::query-tooltip to determine
704 * whether it will provide a tooltip or not.
706 * Note that setting this property to %TRUE for the first time will change
707 * the event masks of the GdkWindows of this widget to include leave-notify
708 * and motion-notify events. This cannot and will not be undone when the
709 * property is set to %FALSE again.
713 g_object_class_install_property (gobject_class,
715 g_param_spec_boolean ("has-tooltip",
717 P_("Whether this widget has a tooltip"),
719 GTK_PARAM_READWRITE));
721 * GtkWidget:tooltip-text:
723 * Sets the text of tooltip to be the given string.
725 * Also see gtk_tooltip_set_text().
727 * This is a convenience property which will take care of getting the
728 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
729 * will automatically be set to %TRUE and there will be taken care of
730 * #GtkWidget::query-tooltip in the default signal handler.
734 g_object_class_install_property (gobject_class,
736 g_param_spec_string ("tooltip-text",
738 P_("The contents of the tooltip for this widget"),
740 GTK_PARAM_READWRITE));
742 * GtkWidget:tooltip-markup:
744 * Sets the text of tooltip to be the given string, which is marked up
745 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
746 * Also see gtk_tooltip_set_markup().
748 * This is a convenience property which will take care of getting the
749 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
750 * will automatically be set to %TRUE and there will be taken care of
751 * #GtkWidget::query-tooltip in the default signal handler.
755 g_object_class_install_property (gobject_class,
757 g_param_spec_string ("tooltip-markup",
758 P_("Tooltip markup"),
759 P_("The contents of the tooltip for this widget"),
761 GTK_PARAM_READWRITE));
766 * The widget's window if it is realized, %NULL otherwise.
770 g_object_class_install_property (gobject_class,
772 g_param_spec_object ("window",
774 P_("The widget's window if it is realized"),
776 GTK_PARAM_READABLE));
779 * GtkWidget:double-buffered
781 * Whether or not the widget is double buffered.
785 g_object_class_install_property (gobject_class,
786 PROP_DOUBLE_BUFFERED,
787 g_param_spec_boolean ("double-buffered",
788 P_("Double Buffered"),
789 P_("Whether or not the widget is double buffered"),
791 GTK_PARAM_READWRITE));
795 * @widget: the object which received the signal.
797 widget_signals[SHOW] =
798 g_signal_new (I_("show"),
799 G_TYPE_FROM_CLASS (gobject_class),
801 G_STRUCT_OFFSET (GtkWidgetClass, show),
803 _gtk_marshal_VOID__VOID,
808 * @widget: the object which received the signal.
810 widget_signals[HIDE] =
811 g_signal_new (I_("hide"),
812 G_TYPE_FROM_CLASS (gobject_class),
814 G_STRUCT_OFFSET (GtkWidgetClass, hide),
816 _gtk_marshal_VOID__VOID,
821 * @widget: the object which received the signal.
823 widget_signals[MAP] =
824 g_signal_new (I_("map"),
825 G_TYPE_FROM_CLASS (gobject_class),
827 G_STRUCT_OFFSET (GtkWidgetClass, map),
829 _gtk_marshal_VOID__VOID,
834 * @widget: the object which received the signal.
836 widget_signals[UNMAP] =
837 g_signal_new (I_("unmap"),
838 G_TYPE_FROM_CLASS (gobject_class),
840 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
842 _gtk_marshal_VOID__VOID,
846 * GtkWidget::realize:
847 * @widget: the object which received the signal.
849 widget_signals[REALIZE] =
850 g_signal_new (I_("realize"),
851 G_TYPE_FROM_CLASS (gobject_class),
853 G_STRUCT_OFFSET (GtkWidgetClass, realize),
855 _gtk_marshal_VOID__VOID,
859 * GtkWidget::unrealize:
860 * @widget: the object which received the signal.
862 widget_signals[UNREALIZE] =
863 g_signal_new (I_("unrealize"),
864 G_TYPE_FROM_CLASS (gobject_class),
866 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
868 _gtk_marshal_VOID__VOID,
872 * GtkWidget::size-request:
873 * @widget: the object which received the signal.
876 widget_signals[SIZE_REQUEST] =
877 g_signal_new (I_("size-request"),
878 G_TYPE_FROM_CLASS (gobject_class),
880 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
882 _gtk_marshal_VOID__BOXED,
884 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
887 * GtkWidget::size-allocate:
888 * @widget: the object which received the signal.
891 widget_signals[SIZE_ALLOCATE] =
892 g_signal_new (I_("size-allocate"),
893 G_TYPE_FROM_CLASS (gobject_class),
895 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
897 _gtk_marshal_VOID__BOXED,
899 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
902 * GtkWidget::state-changed:
903 * @widget: the object which received the signal.
904 * @state: the previous state
906 * The ::state-changed signal is emitted when the widget state changes.
907 * See gtk_widget_get_state().
909 widget_signals[STATE_CHANGED] =
910 g_signal_new (I_("state-changed"),
911 G_TYPE_FROM_CLASS (gobject_class),
913 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
915 _gtk_marshal_VOID__ENUM,
917 GTK_TYPE_STATE_TYPE);
920 * GtkWidget::parent-set:
921 * @widget: the object on which the signal is emitted
922 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
923 * just got its initial parent.
925 * The ::parent-set signal is emitted when a new parent
926 * has been set on a widget.
928 widget_signals[PARENT_SET] =
929 g_signal_new (I_("parent-set"),
930 G_TYPE_FROM_CLASS (gobject_class),
932 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
934 _gtk_marshal_VOID__OBJECT,
939 * GtkWidget::hierarchy-changed:
940 * @widget: the object on which the signal is emitted
941 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
942 * if the widget was previously unanchored
944 * The ::hierarchy-changed signal is emitted when the
945 * anchored state of a widget changes. A widget is
946 * <firstterm>anchored</firstterm> when its toplevel
947 * ancestor is a #GtkWindow. This signal is emitted when
948 * a widget changes from un-anchored to anchored or vice-versa.
950 widget_signals[HIERARCHY_CHANGED] =
951 g_signal_new (I_("hierarchy-changed"),
952 G_TYPE_FROM_CLASS (gobject_class),
954 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
956 _gtk_marshal_VOID__OBJECT,
961 * GtkWidget::style-set:
962 * @widget: the object on which the signal is emitted
963 * @previous_style: (allow-none): the previous style, or %NULL if the widget
964 * just got its initial style
966 * The ::style-set signal is emitted when a new style has been set
967 * on a widget. Note that style-modifying functions like
968 * gtk_widget_modify_base() also cause this signal to be emitted.
970 widget_signals[STYLE_SET] =
971 g_signal_new (I_("style-set"),
972 G_TYPE_FROM_CLASS (gobject_class),
974 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
976 _gtk_marshal_VOID__OBJECT,
980 * GtkWidget::direction-changed:
981 * @widget: the object on which the signal is emitted
982 * @previous_direction: the previous text direction of @widget
984 * The ::direction-changed signal is emitted when the text direction
985 * of a widget changes.
987 widget_signals[DIRECTION_CHANGED] =
988 g_signal_new (I_("direction-changed"),
989 G_TYPE_FROM_CLASS (gobject_class),
991 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
993 _gtk_marshal_VOID__ENUM,
995 GTK_TYPE_TEXT_DIRECTION);
998 * GtkWidget::grab-notify:
999 * @widget: the object which received the signal
1000 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1001 * if it becomes unshadowed
1003 * The ::grab-notify signal is emitted when a widget becomes
1004 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1005 * another widget, or when it becomes unshadowed due to a grab
1008 * A widget is shadowed by a gtk_grab_add() when the topmost
1009 * grab widget in the grab stack of its window group is not
1012 widget_signals[GRAB_NOTIFY] =
1013 g_signal_new (I_("grab-notify"),
1014 G_TYPE_FROM_CLASS (gobject_class),
1016 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1018 _gtk_marshal_VOID__BOOLEAN,
1023 * GtkWidget::child-notify:
1024 * @widget: the object which received the signal
1025 * @pspec: the #GParamSpec of the changed child property
1027 * The ::child-notify signal is emitted for each
1028 * <link linkend="child-properties">child property</link> that has
1029 * changed on an object. The signal's detail holds the property name.
1031 widget_signals[CHILD_NOTIFY] =
1032 g_signal_new (I_("child-notify"),
1033 G_TYPE_FROM_CLASS (gobject_class),
1034 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1035 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1037 g_cclosure_marshal_VOID__PARAM,
1042 * GtkWidget::mnemonic-activate:
1043 * @widget: the object which received the signal.
1046 widget_signals[MNEMONIC_ACTIVATE] =
1047 g_signal_new (I_("mnemonic-activate"),
1048 G_TYPE_FROM_CLASS (gobject_class),
1050 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1051 _gtk_boolean_handled_accumulator, NULL,
1052 _gtk_marshal_BOOLEAN__BOOLEAN,
1057 * GtkWidget::grab-focus:
1058 * @widget: the object which received the signal.
1060 widget_signals[GRAB_FOCUS] =
1061 g_signal_new (I_("grab-focus"),
1062 G_TYPE_FROM_CLASS (gobject_class),
1063 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1064 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1066 _gtk_marshal_VOID__VOID,
1071 * @widget: the object which received the signal.
1074 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1076 widget_signals[FOCUS] =
1077 g_signal_new (I_("focus"),
1078 G_TYPE_FROM_CLASS (object_class),
1080 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1081 _gtk_boolean_handled_accumulator, NULL,
1082 _gtk_marshal_BOOLEAN__ENUM,
1084 GTK_TYPE_DIRECTION_TYPE);
1087 * GtkWidget::move-focus:
1088 * @widget: the object which received the signal.
1091 widget_signals[MOVE_FOCUS] =
1092 g_signal_new_class_handler (I_("move-focus"),
1093 G_TYPE_FROM_CLASS (object_class),
1094 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1095 G_CALLBACK (gtk_widget_real_move_focus),
1097 _gtk_marshal_VOID__ENUM,
1100 GTK_TYPE_DIRECTION_TYPE);
1103 * @widget: the object which received the signal.
1104 * @event: the #GdkEvent which triggered this signal
1106 * The GTK+ main loop will emit three signals for each GDK event delivered
1107 * to a widget: one generic ::event signal, another, more specific,
1108 * signal that matches the type of event delivered (e.g.
1109 * #GtkWidget::key-press-event) and finally a generic
1110 * #GtkWidget::event-after signal.
1112 * Returns: %TRUE to stop other handlers from being invoked for the event
1113 * and to cancel the emission of the second specific ::event signal.
1114 * %FALSE to propagate the event further and to allow the emission of
1115 * the second signal. The ::event-after signal is emitted regardless of
1118 widget_signals[EVENT] =
1119 g_signal_new (I_("event"),
1120 G_TYPE_FROM_CLASS (gobject_class),
1122 G_STRUCT_OFFSET (GtkWidgetClass, event),
1123 _gtk_boolean_handled_accumulator, NULL,
1124 _gtk_marshal_BOOLEAN__BOXED,
1126 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1129 * GtkWidget::event-after:
1130 * @widget: the object which received the signal.
1131 * @event: the #GdkEvent which triggered this signal
1133 * After the emission of the #GtkWidget::event signal and (optionally)
1134 * the second more specific signal, ::event-after will be emitted
1135 * regardless of the previous two signals handlers return values.
1138 widget_signals[EVENT_AFTER] =
1139 g_signal_new (I_("event-after"),
1140 G_TYPE_FROM_CLASS (gobject_class),
1144 _gtk_marshal_VOID__BOXED,
1146 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1149 * GtkWidget::button-press-event:
1150 * @widget: the object which received the signal.
1151 * @event: the #GdkEventButton which triggered this signal
1153 * The ::button-press-event signal will be emitted when a button
1154 * (typically from a mouse) is pressed.
1156 * To receive this signal, the #GdkWindow associated to the
1157 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1159 * This signal will be sent to the grab widget if there is one.
1161 * Returns: %TRUE to stop other handlers from being invoked for the event.
1162 * %FALSE to propagate the event further.
1164 widget_signals[BUTTON_PRESS_EVENT] =
1165 g_signal_new (I_("button-press-event"),
1166 G_TYPE_FROM_CLASS (gobject_class),
1168 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1169 _gtk_boolean_handled_accumulator, NULL,
1170 _gtk_marshal_BOOLEAN__BOXED,
1172 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1175 * GtkWidget::button-release-event:
1176 * @widget: the object which received the signal.
1177 * @event: the #GdkEventButton which triggered this signal
1179 * The ::button-release-event signal will be emitted when a button
1180 * (typically from a mouse) is released.
1182 * To receive this signal, the #GdkWindow associated to the
1183 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1185 * This signal will be sent to the grab widget if there is one.
1187 * Returns: %TRUE to stop other handlers from being invoked for the event.
1188 * %FALSE to propagate the event further.
1190 widget_signals[BUTTON_RELEASE_EVENT] =
1191 g_signal_new (I_("button-release-event"),
1192 G_TYPE_FROM_CLASS (gobject_class),
1194 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1195 _gtk_boolean_handled_accumulator, NULL,
1196 _gtk_marshal_BOOLEAN__BOXED,
1198 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1201 * GtkWidget::scroll-event:
1202 * @widget: the object which received the signal.
1203 * @event: the #GdkEventScroll which triggered this signal
1205 * The ::scroll-event signal is emitted when a button in the 4 to 7
1206 * range is pressed. Wheel mice are usually configured to generate
1207 * button press events for buttons 4 and 5 when the wheel is turned.
1209 * To receive this signal, the #GdkWindow associated to the widget needs
1210 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1212 * This signal will be sent to the grab widget if there is one.
1214 * Returns: %TRUE to stop other handlers from being invoked for the event.
1215 * %FALSE to propagate the event further.
1217 widget_signals[SCROLL_EVENT] =
1218 g_signal_new (I_("scroll-event"),
1219 G_TYPE_FROM_CLASS (gobject_class),
1221 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1222 _gtk_boolean_handled_accumulator, NULL,
1223 _gtk_marshal_BOOLEAN__BOXED,
1225 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1227 * GtkWidget::motion-notify-event:
1228 * @widget: the object which received the signal.
1229 * @event: the #GdkEventMotion which triggered this signal
1231 * The ::motion-notify-event signal is emitted when the pointer moves
1232 * over the widget's #GdkWindow.
1234 * To receive this signal, the #GdkWindow associated to the widget
1235 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1237 * This signal will be sent to the grab widget if there is one.
1239 * Returns: %TRUE to stop other handlers from being invoked for the event.
1240 * %FALSE to propagate the event further.
1242 widget_signals[MOTION_NOTIFY_EVENT] =
1243 g_signal_new (I_("motion-notify-event"),
1244 G_TYPE_FROM_CLASS (gobject_class),
1246 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1247 _gtk_boolean_handled_accumulator, NULL,
1248 _gtk_marshal_BOOLEAN__BOXED,
1250 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1253 * GtkWidget::composited-changed:
1254 * @widget: the object on which the signal is emitted
1256 * The ::composited-changed signal is emitted when the composited
1257 * status of @widget<!-- -->s screen changes.
1258 * See gdk_screen_is_composited().
1260 widget_signals[COMPOSITED_CHANGED] =
1261 g_signal_new (I_("composited-changed"),
1262 G_TYPE_FROM_CLASS (gobject_class),
1263 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1264 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1266 _gtk_marshal_VOID__VOID,
1270 * GtkWidget::keynav-failed:
1271 * @widget: the object which received the signal
1272 * @direction: the direction of movement
1274 * Gets emitted if keyboard navigation fails.
1275 * See gtk_widget_keynav_failed() for details.
1277 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1278 * if the emitting widget should try to handle the keyboard
1279 * navigation attempt in its parent container(s).
1283 widget_signals[KEYNAV_FAILED] =
1284 g_signal_new_class_handler (I_("keynav-failed"),
1285 G_TYPE_FROM_CLASS (gobject_class),
1287 G_CALLBACK (gtk_widget_real_keynav_failed),
1288 _gtk_boolean_handled_accumulator, NULL,
1289 _gtk_marshal_BOOLEAN__ENUM,
1291 GTK_TYPE_DIRECTION_TYPE);
1294 * GtkWidget::delete-event:
1295 * @widget: the object which received the signal
1296 * @event: the event which triggered this signal
1298 * The ::delete-event signal is emitted if a user requests that
1299 * a toplevel window is closed. The default handler for this signal
1300 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1301 * this signal will cause the window to be hidden instead, so that
1302 * it can later be shown again without reconstructing it.
1304 * Returns: %TRUE to stop other handlers from being invoked for the event.
1305 * %FALSE to propagate the event further.
1307 widget_signals[DELETE_EVENT] =
1308 g_signal_new (I_("delete-event"),
1309 G_TYPE_FROM_CLASS (gobject_class),
1311 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1312 _gtk_boolean_handled_accumulator, NULL,
1313 _gtk_marshal_BOOLEAN__BOXED,
1315 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1318 * GtkWidget::destroy-event:
1319 * @widget: the object which received the signal.
1320 * @event: the event which triggered this signal
1322 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1323 * You rarely get this signal, because most widgets disconnect themselves
1324 * from their window before they destroy it, so no widget owns the
1325 * window at destroy time.
1327 * To receive this signal, the #GdkWindow associated to the widget needs
1328 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1329 * automatically for all new windows.
1331 * Returns: %TRUE to stop other handlers from being invoked for the event.
1332 * %FALSE to propagate the event further.
1334 widget_signals[DESTROY_EVENT] =
1335 g_signal_new (I_("destroy-event"),
1336 G_TYPE_FROM_CLASS (gobject_class),
1338 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1339 _gtk_boolean_handled_accumulator, NULL,
1340 _gtk_marshal_BOOLEAN__BOXED,
1342 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1345 * GtkWidget::expose-event:
1346 * @widget: the object which received the signal.
1347 * @event: the #GdkEventExpose which triggered this signal
1349 * The ::expose-event signal is emitted when an area of a previously
1350 * obscured #GdkWindow is made visible and needs to be redrawn.
1351 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1354 * To receive this signal, the #GdkWindow associated to the widget needs
1355 * to enable the #GDK_EXPOSURE_MASK mask.
1357 * Returns: %TRUE to stop other handlers from being invoked for the event.
1358 * %FALSE to propagate the event further.
1360 widget_signals[EXPOSE_EVENT] =
1361 g_signal_new (I_("expose-event"),
1362 G_TYPE_FROM_CLASS (gobject_class),
1364 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1365 _gtk_boolean_handled_accumulator, NULL,
1366 _gtk_marshal_BOOLEAN__BOXED,
1368 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1371 * GtkWidget::key-press-event:
1372 * @widget: the object which received the signal
1373 * @event: the #GdkEventKey which triggered this signal
1375 * The ::key-press-event signal is emitted when a key is pressed.
1377 * To receive this signal, the #GdkWindow associated to the widget needs
1378 * to enable the #GDK_KEY_PRESS_MASK mask.
1380 * This signal will be sent to the grab widget if there is one.
1382 * Returns: %TRUE to stop other handlers from being invoked for the event.
1383 * %FALSE to propagate the event further.
1385 widget_signals[KEY_PRESS_EVENT] =
1386 g_signal_new (I_("key-press-event"),
1387 G_TYPE_FROM_CLASS (gobject_class),
1389 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1390 _gtk_boolean_handled_accumulator, NULL,
1391 _gtk_marshal_BOOLEAN__BOXED,
1393 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1396 * GtkWidget::key-release-event:
1397 * @widget: the object which received the signal
1398 * @event: the #GdkEventKey which triggered this signal
1400 * The ::key-release-event signal is emitted when a key is pressed.
1402 * To receive this signal, the #GdkWindow associated to the widget needs
1403 * to enable the #GDK_KEY_RELEASE_MASK mask.
1405 * This signal will be sent to the grab widget if there is one.
1407 * Returns: %TRUE to stop other handlers from being invoked for the event.
1408 * %FALSE to propagate the event further.
1410 widget_signals[KEY_RELEASE_EVENT] =
1411 g_signal_new (I_("key-release-event"),
1412 G_TYPE_FROM_CLASS (gobject_class),
1414 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1415 _gtk_boolean_handled_accumulator, NULL,
1416 _gtk_marshal_BOOLEAN__BOXED,
1418 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1421 * GtkWidget::enter-notify-event:
1422 * @widget: the object which received the signal
1423 * @event: the #GdkEventCrossing which triggered this signal
1425 * The ::enter-notify-event will be emitted when the pointer enters
1426 * the @widget's window.
1428 * To receive this signal, the #GdkWindow associated to the widget needs
1429 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1431 * This signal will be sent to the grab widget if there is one.
1433 * Returns: %TRUE to stop other handlers from being invoked for the event.
1434 * %FALSE to propagate the event further.
1436 widget_signals[ENTER_NOTIFY_EVENT] =
1437 g_signal_new (I_("enter-notify-event"),
1438 G_TYPE_FROM_CLASS (gobject_class),
1440 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1441 _gtk_boolean_handled_accumulator, NULL,
1442 _gtk_marshal_BOOLEAN__BOXED,
1444 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1447 * GtkWidget::leave-notify-event:
1448 * @widget: the object which received the signal
1449 * @event: the #GdkEventCrossing which triggered this signal
1451 * The ::leave-notify-event will be emitted when the pointer leaves
1452 * the @widget's window.
1454 * To receive this signal, the #GdkWindow associated to the widget needs
1455 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1457 * This signal will be sent to the grab widget if there is one.
1459 * Returns: %TRUE to stop other handlers from being invoked for the event.
1460 * %FALSE to propagate the event further.
1462 widget_signals[LEAVE_NOTIFY_EVENT] =
1463 g_signal_new (I_("leave-notify-event"),
1464 G_TYPE_FROM_CLASS (gobject_class),
1466 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1467 _gtk_boolean_handled_accumulator, NULL,
1468 _gtk_marshal_BOOLEAN__BOXED,
1470 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1473 * GtkWidget::configure-event
1474 * @widget: the object which received the signal
1475 * @event: the #GdkEventConfigure which triggered this signal
1477 * The ::configure-event signal will be emitted when the size, position or
1478 * stacking of the @widget's window has changed.
1480 * To receive this signal, the #GdkWindow associated to the widget needs
1481 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1482 * automatically for all new windows.
1484 * Returns: %TRUE to stop other handlers from being invoked for the event.
1485 * %FALSE to propagate the event further.
1487 widget_signals[CONFIGURE_EVENT] =
1488 g_signal_new (I_("configure-event"),
1489 G_TYPE_FROM_CLASS (gobject_class),
1491 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1492 _gtk_boolean_handled_accumulator, NULL,
1493 _gtk_marshal_BOOLEAN__BOXED,
1495 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1498 * GtkWidget::focus-in-event
1499 * @widget: the object which received the signal
1500 * @event: the #GdkEventFocus which triggered this signal
1502 * The ::focus-in-event signal will be emitted when the keyboard focus
1503 * enters the @widget's window.
1505 * To receive this signal, the #GdkWindow associated to the widget needs
1506 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1508 * Returns: %TRUE to stop other handlers from being invoked for the event.
1509 * %FALSE to propagate the event further.
1511 widget_signals[FOCUS_IN_EVENT] =
1512 g_signal_new (I_("focus-in-event"),
1513 G_TYPE_FROM_CLASS (gobject_class),
1515 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1516 _gtk_boolean_handled_accumulator, NULL,
1517 _gtk_marshal_BOOLEAN__BOXED,
1519 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1522 * GtkWidget::focus-out-event
1523 * @widget: the object which received the signal
1524 * @event: the #GdkEventFocus which triggered this signal
1526 * The ::focus-out-event signal will be emitted when the keyboard focus
1527 * leaves the @widget's window.
1529 * To receive this signal, the #GdkWindow associated to the widget needs
1530 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1532 * Returns: %TRUE to stop other handlers from being invoked for the event.
1533 * %FALSE to propagate the event further.
1535 widget_signals[FOCUS_OUT_EVENT] =
1536 g_signal_new (I_("focus-out-event"),
1537 G_TYPE_FROM_CLASS (gobject_class),
1539 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1540 _gtk_boolean_handled_accumulator, NULL,
1541 _gtk_marshal_BOOLEAN__BOXED,
1543 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1546 * GtkWidget::map-event
1547 * @widget: the object which received the signal
1548 * @event: the #GdkEventAny which triggered this signal
1550 * The ::map-event signal will be emitted when the @widget's window is
1551 * mapped. A window is mapped when it becomes visible on the screen.
1553 * To receive this signal, the #GdkWindow associated to the widget needs
1554 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1555 * automatically for all new windows.
1557 * Returns: %TRUE to stop other handlers from being invoked for the event.
1558 * %FALSE to propagate the event further.
1560 widget_signals[MAP_EVENT] =
1561 g_signal_new (I_("map-event"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1565 _gtk_boolean_handled_accumulator, NULL,
1566 _gtk_marshal_BOOLEAN__BOXED,
1568 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1571 * GtkWidget::unmap-event
1572 * @widget: the object which received the signal
1573 * @event: the #GdkEventAny which triggered this signal
1575 * The ::unmap-event signal will be emitted when the @widget's window is
1576 * unmapped. A window is unmapped when it becomes invisible on the screen.
1578 * To receive this signal, the #GdkWindow associated to the widget needs
1579 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1580 * automatically for all new windows.
1582 * Returns: %TRUE to stop other handlers from being invoked for the event.
1583 * %FALSE to propagate the event further.
1585 widget_signals[UNMAP_EVENT] =
1586 g_signal_new (I_("unmap-event"),
1587 G_TYPE_FROM_CLASS (gobject_class),
1589 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1590 _gtk_boolean_handled_accumulator, NULL,
1591 _gtk_marshal_BOOLEAN__BOXED,
1593 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1596 * GtkWidget::property-notify-event
1597 * @widget: the object which received the signal
1598 * @event: the #GdkEventProperty which triggered this signal
1600 * The ::property-notify-event signal will be emitted when a property on
1601 * the @widget's window has been changed or deleted.
1603 * To receive this signal, the #GdkWindow associated to the widget needs
1604 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1606 * Returns: %TRUE to stop other handlers from being invoked for the event.
1607 * %FALSE to propagate the event further.
1609 widget_signals[PROPERTY_NOTIFY_EVENT] =
1610 g_signal_new (I_("property-notify-event"),
1611 G_TYPE_FROM_CLASS (gobject_class),
1613 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1614 _gtk_boolean_handled_accumulator, NULL,
1615 _gtk_marshal_BOOLEAN__BOXED,
1617 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1620 * GtkWidget::selection-clear-event
1621 * @widget: the object which received the signal
1622 * @event: the #GdkEventSelection which triggered this signal
1624 * The ::selection-clear-event signal will be emitted when the
1625 * the @widget's window has lost ownership of a selection.
1627 * Returns: %TRUE to stop other handlers from being invoked for the event.
1628 * %FALSE to propagate the event further.
1630 widget_signals[SELECTION_CLEAR_EVENT] =
1631 g_signal_new (I_("selection-clear-event"),
1632 G_TYPE_FROM_CLASS (gobject_class),
1634 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1635 _gtk_boolean_handled_accumulator, NULL,
1636 _gtk_marshal_BOOLEAN__BOXED,
1638 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1641 * GtkWidget::selection-request-event
1642 * @widget: the object which received the signal
1643 * @event: the #GdkEventSelection which triggered this signal
1645 * The ::selection-request-event signal will be emitted when
1646 * another client requests ownership of the selection owned by
1647 * the @widget's window.
1649 * Returns: %TRUE to stop other handlers from being invoked for the event.
1650 * %FALSE to propagate the event further.
1652 widget_signals[SELECTION_REQUEST_EVENT] =
1653 g_signal_new (I_("selection-request-event"),
1654 G_TYPE_FROM_CLASS (gobject_class),
1656 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1657 _gtk_boolean_handled_accumulator, NULL,
1658 _gtk_marshal_BOOLEAN__BOXED,
1660 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1663 * GtkWidget::selection-notify-event:
1664 * @widget: the object which received the signal.
1667 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1669 widget_signals[SELECTION_NOTIFY_EVENT] =
1670 g_signal_new (I_("selection-notify-event"),
1671 G_TYPE_FROM_CLASS (gobject_class),
1673 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1674 _gtk_boolean_handled_accumulator, NULL,
1675 _gtk_marshal_BOOLEAN__BOXED,
1677 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1680 * GtkWidget::selection-received:
1681 * @widget: the object which received the signal.
1685 widget_signals[SELECTION_RECEIVED] =
1686 g_signal_new (I_("selection-received"),
1687 G_TYPE_FROM_CLASS (gobject_class),
1689 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1691 _gtk_marshal_VOID__BOXED_UINT,
1693 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1697 * GtkWidget::selection-get:
1698 * @widget: the object which received the signal.
1703 widget_signals[SELECTION_GET] =
1704 g_signal_new (I_("selection-get"),
1705 G_TYPE_FROM_CLASS (gobject_class),
1707 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1709 _gtk_marshal_VOID__BOXED_UINT_UINT,
1711 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1716 * GtkWidget::proximity-in-event
1717 * @widget: the object which received the signal
1718 * @event: the #GdkEventProximity which triggered this signal
1720 * To receive this signal the #GdkWindow associated to the widget needs
1721 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1723 * This signal will be sent to the grab widget if there is one.
1725 * Returns: %TRUE to stop other handlers from being invoked for the event.
1726 * %FALSE to propagate the event further.
1728 widget_signals[PROXIMITY_IN_EVENT] =
1729 g_signal_new (I_("proximity-in-event"),
1730 G_TYPE_FROM_CLASS (gobject_class),
1732 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1733 _gtk_boolean_handled_accumulator, NULL,
1734 _gtk_marshal_BOOLEAN__BOXED,
1736 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1739 * GtkWidget::proximity-out-event
1740 * @widget: the object which received the signal
1741 * @event: the #GdkEventProximity which triggered this signal
1743 * To receive this signal the #GdkWindow associated to the widget needs
1744 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1746 * This signal will be sent to the grab widget if there is one.
1748 * Returns: %TRUE to stop other handlers from being invoked for the event.
1749 * %FALSE to propagate the event further.
1751 widget_signals[PROXIMITY_OUT_EVENT] =
1752 g_signal_new (I_("proximity-out-event"),
1753 G_TYPE_FROM_CLASS (gobject_class),
1755 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1756 _gtk_boolean_handled_accumulator, NULL,
1757 _gtk_marshal_BOOLEAN__BOXED,
1759 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1762 * GtkWidget::drag-leave:
1763 * @widget: the object which received the signal.
1764 * @drag_context: the drag context
1765 * @time: the timestamp of the motion event
1767 * The ::drag-leave signal is emitted on the drop site when the cursor
1768 * leaves the widget. A typical reason to connect to this signal is to
1769 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1770 * with gtk_drag_unhighlight()
1772 widget_signals[DRAG_LEAVE] =
1773 g_signal_new (I_("drag-leave"),
1774 G_TYPE_FROM_CLASS (gobject_class),
1776 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1778 _gtk_marshal_VOID__OBJECT_UINT,
1780 GDK_TYPE_DRAG_CONTEXT,
1784 * GtkWidget::drag-begin:
1785 * @widget: the object which received the signal
1786 * @drag_context: the drag context
1788 * The ::drag-begin signal is emitted on the drag source when a drag is
1789 * started. A typical reason to connect to this signal is to set up a
1790 * custom drag icon with gtk_drag_source_set_icon().
1792 * Note that some widgets set up a drag icon in the default handler of
1793 * this signal, so you may have to use g_signal_connect_after() to
1794 * override what the default handler did.
1796 widget_signals[DRAG_BEGIN] =
1797 g_signal_new (I_("drag-begin"),
1798 G_TYPE_FROM_CLASS (gobject_class),
1800 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1802 _gtk_marshal_VOID__OBJECT,
1804 GDK_TYPE_DRAG_CONTEXT);
1807 * GtkWidget::drag-end:
1808 * @widget: the object which received the signal
1809 * @drag_context: the drag context
1811 * The ::drag-end signal is emitted on the drag source when a drag is
1812 * finished. A typical reason to connect to this signal is to undo
1813 * things done in #GtkWidget::drag-begin.
1815 widget_signals[DRAG_END] =
1816 g_signal_new (I_("drag-end"),
1817 G_TYPE_FROM_CLASS (gobject_class),
1819 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1821 _gtk_marshal_VOID__OBJECT,
1823 GDK_TYPE_DRAG_CONTEXT);
1826 * GtkWidget::drag-data-delete:
1827 * @widget: the object which received the signal
1828 * @drag_context: the drag context
1830 * The ::drag-data-delete signal is emitted on the drag source when a drag
1831 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1832 * handler is responsible for deleting the data that has been dropped. What
1833 * "delete" means depends on the context of the drag operation.
1835 widget_signals[DRAG_DATA_DELETE] =
1836 g_signal_new (I_("drag-data-delete"),
1837 G_TYPE_FROM_CLASS (gobject_class),
1839 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1841 _gtk_marshal_VOID__OBJECT,
1843 GDK_TYPE_DRAG_CONTEXT);
1846 * GtkWidget::drag-failed:
1847 * @widget: the object which received the signal
1848 * @drag_context: the drag context
1849 * @result: the result of the drag operation
1851 * The ::drag-failed signal is emitted on the drag source when a drag has
1852 * failed. The signal handler may hook custom code to handle a failed DND
1853 * operation based on the type of error, it returns %TRUE is the failure has
1854 * been already handled (not showing the default "drag operation failed"
1855 * animation), otherwise it returns %FALSE.
1857 * Return value: %TRUE if the failed drag operation has been already handled.
1861 widget_signals[DRAG_FAILED] =
1862 g_signal_new (I_("drag-failed"),
1863 G_TYPE_FROM_CLASS (gobject_class),
1865 0, _gtk_boolean_handled_accumulator, NULL,
1866 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1868 GDK_TYPE_DRAG_CONTEXT,
1869 GTK_TYPE_DRAG_RESULT);
1872 * GtkWidget::drag-motion:
1873 * @widget: the object which received the signal
1874 * @drag_context: the drag context
1875 * @x: the x coordinate of the current cursor position
1876 * @y: the y coordinate of the current cursor position
1877 * @time: the timestamp of the motion event
1878 * @returns: whether the cursor position is in a drop zone
1880 * The drag-motion signal is emitted on the drop site when the user
1881 * moves the cursor over the widget during a drag. The signal handler
1882 * must determine whether the cursor position is in a drop zone or not.
1883 * If it is not in a drop zone, it returns %FALSE and no further processing
1884 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1885 * handler is responsible for providing the necessary information for
1886 * displaying feedback to the user, by calling gdk_drag_status().
1888 * If the decision whether the drop will be accepted or rejected can't be
1889 * made based solely on the cursor position and the type of the data, the
1890 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1891 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1892 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1893 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1894 * when using the drag-motion signal that way.
1896 * Also note that there is no drag-enter signal. The drag receiver has to
1897 * keep track of whether he has received any drag-motion signals since the
1898 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1899 * an "enter" signal. Upon an "enter", the handler will typically highlight
1900 * the drop site with gtk_drag_highlight().
1903 * drag_motion (GtkWidget *widget,
1904 * GdkDragContext *context,
1911 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1913 * if (!private_data->drag_highlight)
1915 * private_data->drag_highlight = 1;
1916 * gtk_drag_highlight (widget);
1919 * target = gtk_drag_dest_find_target (widget, context, NULL);
1920 * if (target == GDK_NONE)
1921 * gdk_drag_status (context, 0, time);
1924 * private_data->pending_status = context->suggested_action;
1925 * gtk_drag_get_data (widget, context, target, time);
1932 * drag_data_received (GtkWidget *widget,
1933 * GdkDragContext *context,
1936 * GtkSelectionData *selection_data,
1940 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1942 * if (private_data->suggested_action)
1944 * private_data->suggested_action = 0;
1946 * /* We are getting this data due to a request in drag_motion,
1947 * * rather than due to a request in drag_drop, so we are just
1948 * * supposed to call gdk_drag_status (), not actually paste in
1951 * str = gtk_selection_data_get_text (selection_data);
1952 * if (!data_is_acceptable (str))
1953 * gdk_drag_status (context, 0, time);
1955 * gdk_drag_status (context, private_data->suggested_action, time);
1959 * /* accept the drop */
1964 widget_signals[DRAG_MOTION] =
1965 g_signal_new (I_("drag-motion"),
1966 G_TYPE_FROM_CLASS (gobject_class),
1968 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1969 _gtk_boolean_handled_accumulator, NULL,
1970 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1972 GDK_TYPE_DRAG_CONTEXT,
1978 * GtkWidget::drag-drop:
1979 * @widget: the object which received the signal
1980 * @drag_context: the drag context
1981 * @x: the x coordinate of the current cursor position
1982 * @y: the y coordinate of the current cursor position
1983 * @time: the timestamp of the motion event
1984 * @returns: whether the cursor position is in a drop zone
1986 * The ::drag-drop signal is emitted on the drop site when the user drops
1987 * the data onto the widget. The signal handler must determine whether
1988 * the cursor position is in a drop zone or not. If it is not in a drop
1989 * zone, it returns %FALSE and no further processing is necessary.
1990 * Otherwise, the handler returns %TRUE. In this case, the handler must
1991 * ensure that gtk_drag_finish() is called to let the source know that
1992 * the drop is done. The call to gtk_drag_finish() can be done either
1993 * directly or in a #GtkWidget::drag-data-received handler which gets
1994 * triggered by calling gtk_drag_get_data() to receive the data for one
1995 * or more of the supported targets.
1997 widget_signals[DRAG_DROP] =
1998 g_signal_new (I_("drag-drop"),
1999 G_TYPE_FROM_CLASS (gobject_class),
2001 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2002 _gtk_boolean_handled_accumulator, NULL,
2003 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2005 GDK_TYPE_DRAG_CONTEXT,
2011 * GtkWidget::drag-data-get:
2012 * @widget: the object which received the signal
2013 * @drag_context: the drag context
2014 * @data: the #GtkSelectionData to be filled with the dragged data
2015 * @info: the info that has been registered with the target in the
2017 * @time: the timestamp at which the data was requested
2019 * The ::drag-data-get signal is emitted on the drag source when the drop
2020 * site requests the data which is dragged. It is the responsibility of
2021 * the signal handler to fill @data with the data in the format which
2022 * is indicated by @info. See gtk_selection_data_set() and
2023 * gtk_selection_data_set_text().
2025 widget_signals[DRAG_DATA_GET] =
2026 g_signal_new (I_("drag-data-get"),
2027 G_TYPE_FROM_CLASS (gobject_class),
2029 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2031 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2033 GDK_TYPE_DRAG_CONTEXT,
2034 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2039 * GtkWidget::drag-data-received:
2040 * @widget: the object which received the signal
2041 * @drag_context: the drag context
2042 * @x: where the drop happened
2043 * @y: where the drop happened
2044 * @data: the received data
2045 * @info: the info that has been registered with the target in the
2047 * @time: the timestamp at which the data was received
2049 * The ::drag-data-received signal is emitted on the drop site when the
2050 * dragged data has been received. If the data was received in order to
2051 * determine whether the drop will be accepted, the handler is expected
2052 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2053 * If the data was received in response to a #GtkWidget::drag-drop signal
2054 * (and this is the last target to be received), the handler for this
2055 * signal is expected to process the received data and then call
2056 * gtk_drag_finish(), setting the @success parameter depending on whether
2057 * the data was processed successfully.
2059 * The handler may inspect and modify @drag_context->action before calling
2060 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2061 * following example:
2064 * drag_data_received (GtkWidget *widget,
2065 * GdkDragContext *drag_context,
2068 * GtkSelectionData *data,
2072 * if ((data->length >= 0) && (data->format == 8))
2074 * if (drag_context->action == GDK_ACTION_ASK)
2076 * GtkWidget *dialog;
2079 * dialog = gtk_message_dialog_new (NULL,
2080 * GTK_DIALOG_MODAL |
2081 * GTK_DIALOG_DESTROY_WITH_PARENT,
2083 * GTK_BUTTONS_YES_NO,
2084 * "Move the data ?\n");
2085 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2086 * gtk_widget_destroy (dialog);
2088 * if (response == GTK_RESPONSE_YES)
2089 * drag_context->action = GDK_ACTION_MOVE;
2091 * drag_context->action = GDK_ACTION_COPY;
2094 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2098 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2102 widget_signals[DRAG_DATA_RECEIVED] =
2103 g_signal_new (I_("drag-data-received"),
2104 G_TYPE_FROM_CLASS (gobject_class),
2106 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2108 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2110 GDK_TYPE_DRAG_CONTEXT,
2113 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2118 * GtkWidget::visibility-notify-event:
2119 * @widget: the object which received the signal
2120 * @event: the #GdkEventVisibility which triggered this signal
2122 * The ::visibility-notify-event will be emitted when the @widget's window
2123 * is obscured or unobscured.
2125 * To receive this signal the #GdkWindow associated to the widget needs
2126 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2132 g_signal_new (I_("visibility-notify-event"),
2133 G_TYPE_FROM_CLASS (gobject_class),
2135 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2142 * GtkWidget::client-event:
2143 * @widget: the object which received the signal
2144 * @event: the #GdkEventClient which triggered this signal
2146 * The ::client-event will be emitted when the @widget's window
2147 * receives a message (via a ClientMessage event) from another
2150 * Returns: %TRUE to stop other handlers from being invoked for
2151 * the event. %FALSE to propagate the event further.
2153 widget_signals[CLIENT_EVENT] =
2154 g_signal_new (I_("client-event"),
2155 G_TYPE_FROM_CLASS (gobject_class),
2157 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2158 _gtk_boolean_handled_accumulator, NULL,
2159 _gtk_marshal_BOOLEAN__BOXED,
2161 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2164 * GtkWidget::no-expose-event:
2165 * @widget: the object which received the signal
2166 * @event: the #GdkEventNoExpose which triggered this signal
2168 * The ::no-expose-event will be emitted when the @widget's window is
2169 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2170 * gdk_window_copy_area()) which was completely unobscured. If the source
2171 * window was partially obscured #GdkEventExpose events will be generated
2174 * Returns: %TRUE to stop other handlers from being invoked for the event.
2175 * %FALSE to propagate the event further.
2177 widget_signals[NO_EXPOSE_EVENT] =
2178 g_signal_new (I_("no-expose-event"),
2179 G_TYPE_FROM_CLASS (gobject_class),
2181 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2182 _gtk_boolean_handled_accumulator, NULL,
2183 _gtk_marshal_BOOLEAN__BOXED,
2185 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2188 * GtkWidget::window-state-event:
2189 * @widget: the object which received the signal
2190 * @event: the #GdkEventWindowState which triggered this signal
2192 * The ::window-state-event will be emitted when the state of the
2193 * toplevel window associated to the @widget changes.
2195 * To receive this signal the #GdkWindow associated to the widget
2196 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2197 * this mask automatically for all new windows.
2199 * Returns: %TRUE to stop other handlers from being invoked for the
2200 * event. %FALSE to propagate the event further.
2202 widget_signals[WINDOW_STATE_EVENT] =
2203 g_signal_new (I_("window-state-event"),
2204 G_TYPE_FROM_CLASS (gobject_class),
2206 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2207 _gtk_boolean_handled_accumulator, NULL,
2208 _gtk_marshal_BOOLEAN__BOXED,
2210 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2213 * GtkWidget::damage-event:
2214 * @widget: the object which received the signal
2215 * @event: the #GdkEventExpose event
2217 * Emitted when a redirected window belonging to @widget gets drawn into.
2218 * The region/area members of the event shows what area of the redirected
2219 * drawable was drawn into.
2221 * Returns: %TRUE to stop other handlers from being invoked for the event.
2222 * %FALSE to propagate the event further.
2226 widget_signals[DAMAGE_EVENT] =
2227 g_signal_new (I_("damage-event"),
2228 G_TYPE_FROM_CLASS (gobject_class),
2231 _gtk_boolean_handled_accumulator, NULL,
2232 _gtk_marshal_BOOLEAN__BOXED,
2234 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2236 * GtkWidget::grab-broken-event:
2237 * @widget: the object which received the signal
2238 * @event: the #GdkEventGrabBroken event
2240 * Emitted when a pointer or keyboard grab on a window belonging
2241 * to @widget gets broken.
2243 * On X11, this happens when the grab window becomes unviewable
2244 * (i.e. it or one of its ancestors is unmapped), or if the same
2245 * application grabs the pointer or keyboard again.
2247 * Returns: %TRUE to stop other handlers from being invoked for
2248 * the event. %FALSE to propagate the event further.
2252 widget_signals[GRAB_BROKEN] =
2253 g_signal_new (I_("grab-broken-event"),
2254 G_TYPE_FROM_CLASS (gobject_class),
2256 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2257 _gtk_boolean_handled_accumulator, NULL,
2258 _gtk_marshal_BOOLEAN__BOXED,
2260 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2262 * GtkWidget::query-tooltip:
2263 * @widget: the object which received the signal
2264 * @x: the x coordinate of the cursor position where the request has
2265 * been emitted, relative to @widget->window
2266 * @y: the y coordinate of the cursor position where the request has
2267 * been emitted, relative to @widget->window
2268 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2269 * @tooltip: a #GtkTooltip
2271 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2272 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2273 * focus in keyboard mode.
2275 * Using the given coordinates, the signal handler should determine
2276 * whether a tooltip should be shown for @widget. If this is the case
2277 * %TRUE should be returned, %FALSE otherwise. Note that if
2278 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2279 * should not be used.
2281 * The signal handler is free to manipulate @tooltip with the therefore
2282 * destined function calls.
2284 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2288 widget_signals[QUERY_TOOLTIP] =
2289 g_signal_new (I_("query-tooltip"),
2290 G_TYPE_FROM_CLASS (gobject_class),
2292 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2293 _gtk_boolean_handled_accumulator, NULL,
2294 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2302 * GtkWidget::popup-menu
2303 * @widget: the object which received the signal
2305 * This signal gets emitted whenever a widget should pop up a context
2306 * menu. This usually happens through the standard key binding mechanism;
2307 * by pressing a certain key while a widget is focused, the user can cause
2308 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2309 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2310 * for an example of how to use this signal.
2312 * Returns: %TRUE if a menu was activated
2314 widget_signals[POPUP_MENU] =
2315 g_signal_new (I_("popup-menu"),
2316 G_TYPE_FROM_CLASS (gobject_class),
2317 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2318 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__VOID,
2324 * GtkWidget::show-help:
2325 * @widget: the object which received the signal.
2328 widget_signals[SHOW_HELP] =
2329 g_signal_new (I_("show-help"),
2330 G_TYPE_FROM_CLASS (gobject_class),
2331 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2332 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2333 _gtk_boolean_handled_accumulator, NULL,
2334 _gtk_marshal_BOOLEAN__ENUM,
2336 GTK_TYPE_WIDGET_HELP_TYPE);
2339 * GtkWidget::accel-closures-changed:
2340 * @widget: the object which received the signal.
2342 widget_signals[ACCEL_CLOSURES_CHANGED] =
2343 g_signal_new (I_("accel-closures-changed"),
2344 G_TYPE_FROM_CLASS (gobject_class),
2348 _gtk_marshal_VOID__VOID,
2352 * GtkWidget::screen-changed:
2353 * @widget: the object on which the signal is emitted
2354 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2355 * widget was not associated with a screen before
2357 * The ::screen-changed signal gets emitted when the
2358 * screen of a widget has changed.
2360 widget_signals[SCREEN_CHANGED] =
2361 g_signal_new (I_("screen-changed"),
2362 G_TYPE_FROM_CLASS (gobject_class),
2364 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2366 _gtk_marshal_VOID__OBJECT,
2371 * GtkWidget::can-activate-accel:
2372 * @widget: the object which received the signal
2373 * @signal_id: the ID of a signal installed on @widget
2375 * Determines whether an accelerator that activates the signal
2376 * identified by @signal_id can currently be activated.
2377 * This signal is present to allow applications and derived
2378 * widgets to override the default #GtkWidget handling
2379 * for determining whether an accelerator can be activated.
2381 * Returns: %TRUE if the signal can be activated.
2383 widget_signals[CAN_ACTIVATE_ACCEL] =
2384 g_signal_new (I_("can-activate-accel"),
2385 G_TYPE_FROM_CLASS (gobject_class),
2387 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2388 _gtk_boolean_handled_accumulator, NULL,
2389 _gtk_marshal_BOOLEAN__UINT,
2390 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2392 binding_set = gtk_binding_set_by_class (klass);
2393 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2395 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2398 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2400 GTK_TYPE_WIDGET_HELP_TYPE,
2401 GTK_WIDGET_HELP_TOOLTIP);
2402 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2404 GTK_TYPE_WIDGET_HELP_TYPE,
2405 GTK_WIDGET_HELP_TOOLTIP);
2406 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2408 GTK_TYPE_WIDGET_HELP_TYPE,
2409 GTK_WIDGET_HELP_WHATS_THIS);
2410 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2412 GTK_TYPE_WIDGET_HELP_TYPE,
2413 GTK_WIDGET_HELP_WHATS_THIS);
2415 gtk_widget_class_install_style_property (klass,
2416 g_param_spec_boolean ("interior-focus",
2417 P_("Interior Focus"),
2418 P_("Whether to draw the focus indicator inside widgets"),
2420 GTK_PARAM_READABLE));
2422 gtk_widget_class_install_style_property (klass,
2423 g_param_spec_int ("focus-line-width",
2424 P_("Focus linewidth"),
2425 P_("Width, in pixels, of the focus indicator line"),
2427 GTK_PARAM_READABLE));
2429 gtk_widget_class_install_style_property (klass,
2430 g_param_spec_string ("focus-line-pattern",
2431 P_("Focus line dash pattern"),
2432 P_("Dash pattern used to draw the focus indicator"),
2434 GTK_PARAM_READABLE));
2435 gtk_widget_class_install_style_property (klass,
2436 g_param_spec_int ("focus-padding",
2437 P_("Focus padding"),
2438 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2440 GTK_PARAM_READABLE));
2441 gtk_widget_class_install_style_property (klass,
2442 g_param_spec_boxed ("cursor-color",
2444 P_("Color with which to draw insertion cursor"),
2446 GTK_PARAM_READABLE));
2447 gtk_widget_class_install_style_property (klass,
2448 g_param_spec_boxed ("secondary-cursor-color",
2449 P_("Secondary cursor color"),
2450 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2452 GTK_PARAM_READABLE));
2453 gtk_widget_class_install_style_property (klass,
2454 g_param_spec_float ("cursor-aspect-ratio",
2455 P_("Cursor line aspect ratio"),
2456 P_("Aspect ratio with which to draw insertion cursor"),
2458 GTK_PARAM_READABLE));
2461 * GtkWidget:draw-border:
2463 * The "draw-border" style property defines the size of areas outside
2464 * the widget's allocation to draw.
2468 gtk_widget_class_install_style_property (klass,
2469 g_param_spec_boxed ("draw-border",
2471 P_("Size of areas outside the widget's allocation to draw"),
2473 GTK_PARAM_READABLE));
2476 * GtkWidget:link-color:
2478 * The "link-color" style property defines the color of unvisited links.
2482 gtk_widget_class_install_style_property (klass,
2483 g_param_spec_boxed ("link-color",
2484 P_("Unvisited Link Color"),
2485 P_("Color of unvisited links"),
2487 GTK_PARAM_READABLE));
2490 * GtkWidget:visited-link-color:
2492 * The "visited-link-color" style property defines the color of visited links.
2496 gtk_widget_class_install_style_property (klass,
2497 g_param_spec_boxed ("visited-link-color",
2498 P_("Visited Link Color"),
2499 P_("Color of visited links"),
2501 GTK_PARAM_READABLE));
2504 * GtkWidget:wide-separators:
2506 * The "wide-separators" style property defines whether separators have
2507 * configurable width and should be drawn using a box instead of a line.
2511 gtk_widget_class_install_style_property (klass,
2512 g_param_spec_boolean ("wide-separators",
2513 P_("Wide Separators"),
2514 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2516 GTK_PARAM_READABLE));
2519 * GtkWidget:separator-width:
2521 * The "separator-width" style property defines the width of separators.
2522 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2526 gtk_widget_class_install_style_property (klass,
2527 g_param_spec_int ("separator-width",
2528 P_("Separator Width"),
2529 P_("The width of separators if wide-separators is TRUE"),
2531 GTK_PARAM_READABLE));
2534 * GtkWidget:separator-height:
2536 * The "separator-height" style property defines the height of separators.
2537 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2541 gtk_widget_class_install_style_property (klass,
2542 g_param_spec_int ("separator-height",
2543 P_("Separator Height"),
2544 P_("The height of separators if \"wide-separators\" is TRUE"),
2546 GTK_PARAM_READABLE));
2549 * GtkWidget:scroll-arrow-hlength:
2551 * The "scroll-arrow-hlength" style property defines the length of
2552 * horizontal scroll arrows.
2556 gtk_widget_class_install_style_property (klass,
2557 g_param_spec_int ("scroll-arrow-hlength",
2558 P_("Horizontal Scroll Arrow Length"),
2559 P_("The length of horizontal scroll arrows"),
2561 GTK_PARAM_READABLE));
2564 * GtkWidget:scroll-arrow-vlength:
2566 * The "scroll-arrow-vlength" style property defines the length of
2567 * vertical scroll arrows.
2571 gtk_widget_class_install_style_property (klass,
2572 g_param_spec_int ("scroll-arrow-vlength",
2573 P_("Vertical Scroll Arrow Length"),
2574 P_("The length of vertical scroll arrows"),
2576 GTK_PARAM_READABLE));
2580 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2584 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2585 for (node = list; node; node = node->next)
2587 GParamSpec *pspec = node->data;
2589 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2590 g_param_spec_unref (pspec);
2596 gtk_widget_set_property (GObject *object,
2598 const GValue *value,
2601 GtkWidget *widget = GTK_WIDGET (object);
2606 gchar *tooltip_markup;
2607 const gchar *tooltip_text;
2608 GtkWindow *tooltip_window;
2611 gtk_widget_set_name (widget, g_value_get_string (value));
2614 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2616 case PROP_WIDTH_REQUEST:
2617 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2619 case PROP_HEIGHT_REQUEST:
2620 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2623 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2625 case PROP_SENSITIVE:
2626 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2628 case PROP_APP_PAINTABLE:
2629 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2631 case PROP_CAN_FOCUS:
2632 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2634 case PROP_HAS_FOCUS:
2635 if (g_value_get_boolean (value))
2636 gtk_widget_grab_focus (widget);
2639 if (g_value_get_boolean (value))
2640 gtk_widget_grab_focus (widget);
2642 case PROP_CAN_DEFAULT:
2643 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2645 case PROP_HAS_DEFAULT:
2646 if (g_value_get_boolean (value))
2647 gtk_widget_grab_default (widget);
2649 case PROP_RECEIVES_DEFAULT:
2650 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2653 gtk_widget_set_style (widget, g_value_get_object (value));
2656 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2657 gtk_widget_set_events (widget, g_value_get_flags (value));
2659 case PROP_EXTENSION_EVENTS:
2660 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2662 case PROP_NO_SHOW_ALL:
2663 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2665 case PROP_HAS_TOOLTIP:
2666 gtk_widget_real_set_has_tooltip (widget,
2667 g_value_get_boolean (value), FALSE);
2669 case PROP_TOOLTIP_MARKUP:
2670 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2671 tooltip_markup = g_value_dup_string (value);
2673 /* Treat an empty string as a NULL string,
2674 * because an empty string would be useless for a tooltip:
2676 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2678 g_free (tooltip_markup);
2679 tooltip_markup = NULL;
2682 g_object_set_qdata_full (object, quark_tooltip_markup,
2683 tooltip_markup, g_free);
2685 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2686 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2687 if (gtk_widget_get_visible (widget))
2688 gtk_widget_queue_tooltip_query (widget);
2690 case PROP_TOOLTIP_TEXT:
2691 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2693 tooltip_text = g_value_get_string (value);
2695 /* Treat an empty string as a NULL string,
2696 * because an empty string would be useless for a tooltip:
2698 if (tooltip_text && (strlen (tooltip_text) == 0))
2699 tooltip_text = NULL;
2701 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2703 g_object_set_qdata_full (object, quark_tooltip_markup,
2704 tooltip_markup, g_free);
2706 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2707 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2708 if (gtk_widget_get_visible (widget))
2709 gtk_widget_queue_tooltip_query (widget);
2711 case PROP_DOUBLE_BUFFERED:
2712 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2715 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2721 gtk_widget_get_property (GObject *object,
2726 GtkWidget *widget = GTK_WIDGET (object);
2735 g_value_set_string (value, widget->name);
2737 g_value_set_static_string (value, "");
2740 g_value_set_object (value, widget->parent);
2742 case PROP_WIDTH_REQUEST:
2745 gtk_widget_get_size_request (widget, &w, NULL);
2746 g_value_set_int (value, w);
2749 case PROP_HEIGHT_REQUEST:
2752 gtk_widget_get_size_request (widget, NULL, &h);
2753 g_value_set_int (value, h);
2757 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2759 case PROP_SENSITIVE:
2760 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2762 case PROP_APP_PAINTABLE:
2763 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2765 case PROP_CAN_FOCUS:
2766 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2768 case PROP_HAS_FOCUS:
2769 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2772 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2774 case PROP_CAN_DEFAULT:
2775 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2777 case PROP_HAS_DEFAULT:
2778 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2780 case PROP_RECEIVES_DEFAULT:
2781 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2783 case PROP_COMPOSITE_CHILD:
2784 g_value_set_boolean (value, (GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2787 g_value_set_object (value, gtk_widget_get_style (widget));
2790 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2791 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2793 case PROP_EXTENSION_EVENTS:
2794 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2795 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2797 case PROP_NO_SHOW_ALL:
2798 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2800 case PROP_HAS_TOOLTIP:
2801 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2803 case PROP_TOOLTIP_TEXT:
2805 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2808 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2809 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2811 g_value_set_string (value, text);
2815 case PROP_TOOLTIP_MARKUP:
2816 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2819 g_value_set_object (value, gtk_widget_get_window (widget));
2821 case PROP_DOUBLE_BUFFERED:
2822 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2825 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2831 gtk_widget_init (GtkWidget *widget)
2833 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2834 widget->state = GTK_STATE_NORMAL;
2835 widget->saved_state = GTK_STATE_NORMAL;
2836 widget->name = NULL;
2837 widget->requisition.width = 0;
2838 widget->requisition.height = 0;
2839 widget->allocation.x = -1;
2840 widget->allocation.y = -1;
2841 widget->allocation.width = 1;
2842 widget->allocation.height = 1;
2843 widget->window = NULL;
2844 widget->parent = NULL;
2846 GTK_WIDGET_SET_FLAGS (widget,
2848 GTK_PARENT_SENSITIVE |
2849 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2850 GTK_DOUBLE_BUFFERED);
2852 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2853 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2854 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2856 widget->style = gtk_widget_get_default_style ();
2857 g_object_ref (widget->style);
2862 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2864 GParamSpec **pspecs)
2866 GtkWidget *container = widget->parent;
2869 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2870 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2874 * gtk_widget_freeze_child_notify:
2875 * @widget: a #GtkWidget
2877 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2878 * signals are queued until gtk_widget_thaw_child_notify() is called
2881 * This is the analogue of g_object_freeze_notify() for child properties.
2884 gtk_widget_freeze_child_notify (GtkWidget *widget)
2886 g_return_if_fail (GTK_IS_WIDGET (widget));
2888 if (!G_OBJECT (widget)->ref_count)
2891 g_object_ref (widget);
2892 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2893 g_object_unref (widget);
2897 * gtk_widget_child_notify:
2898 * @widget: a #GtkWidget
2899 * @child_property: the name of a child property installed on the
2900 * class of @widget<!-- -->'s parent
2902 * Emits a #GtkWidget::child-notify signal for the
2903 * <link linkend="child-properties">child property</link> @child_property
2906 * This is the analogue of g_object_notify() for child properties.
2909 gtk_widget_child_notify (GtkWidget *widget,
2910 const gchar *child_property)
2914 g_return_if_fail (GTK_IS_WIDGET (widget));
2915 g_return_if_fail (child_property != NULL);
2916 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2919 g_object_ref (widget);
2920 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2922 G_OBJECT_TYPE (widget->parent),
2925 g_warning ("%s: container class `%s' has no child property named `%s'",
2927 G_OBJECT_TYPE_NAME (widget->parent),
2931 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2933 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2934 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2936 g_object_unref (widget);
2940 * gtk_widget_thaw_child_notify:
2941 * @widget: a #GtkWidget
2943 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2944 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2948 gtk_widget_thaw_child_notify (GtkWidget *widget)
2950 GObjectNotifyQueue *nqueue;
2952 g_return_if_fail (GTK_IS_WIDGET (widget));
2954 if (!G_OBJECT (widget)->ref_count)
2957 g_object_ref (widget);
2958 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2959 if (!nqueue || !nqueue->freeze_count)
2960 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2961 G_OBJECT_TYPE_NAME (widget), widget);
2963 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2964 g_object_unref (widget);
2970 * @type: type ID of the widget to create
2971 * @first_property_name: name of first property to set
2972 * @Varargs: value of first property, followed by more properties,
2975 * This is a convenience function for creating a widget and setting
2976 * its properties in one go. For example you might write:
2977 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2978 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2979 * g_object_new(), but returns a widget so you don't have to
2980 * cast the object yourself.
2982 * Return value: a new #GtkWidget of type @widget_type
2985 gtk_widget_new (GType type,
2986 const gchar *first_property_name,
2992 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2994 va_start (var_args, first_property_name);
2995 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3003 * @widget: a #GtkWidget
3004 * @first_property_name: name of first property to set
3005 * @Varargs: value of first property, followed by more properties,
3008 * Precursor of g_object_set().
3010 * Deprecated: 2.0: Use g_object_set() instead.
3013 gtk_widget_set (GtkWidget *widget,
3014 const gchar *first_property_name,
3019 g_return_if_fail (GTK_IS_WIDGET (widget));
3021 va_start (var_args, first_property_name);
3022 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3027 gtk_widget_queue_draw_child (GtkWidget *widget)
3031 parent = widget->parent;
3032 if (parent && gtk_widget_is_drawable (parent))
3033 gtk_widget_queue_draw_area (parent,
3034 widget->allocation.x,
3035 widget->allocation.y,
3036 widget->allocation.width,
3037 widget->allocation.height);
3041 * gtk_widget_unparent:
3042 * @widget: a #GtkWidget
3044 * This function is only for use in widget implementations.
3045 * Should be called by implementations of the remove method
3046 * on #GtkContainer, to dissociate a child from the container.
3049 gtk_widget_unparent (GtkWidget *widget)
3051 GObjectNotifyQueue *nqueue;
3052 GtkWidget *toplevel;
3053 GtkWidget *old_parent;
3055 g_return_if_fail (GTK_IS_WIDGET (widget));
3056 if (widget->parent == NULL)
3059 /* keep this function in sync with gtk_menu_detach()
3062 g_object_freeze_notify (G_OBJECT (widget));
3063 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3065 toplevel = gtk_widget_get_toplevel (widget);
3066 if (gtk_widget_is_toplevel (toplevel))
3067 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3069 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3070 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3072 /* If we are unanchoring the child, we save around the toplevel
3073 * to emit hierarchy changed
3075 if (GTK_WIDGET_ANCHORED (widget->parent))
3076 g_object_ref (toplevel);
3080 gtk_widget_queue_draw_child (widget);
3082 /* Reset the width and height here, to force reallocation if we
3083 * get added back to a new parent. This won't work if our new
3084 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3085 * (would 0x0 be OK here?)
3087 widget->allocation.width = 1;
3088 widget->allocation.height = 1;
3090 if (gtk_widget_get_realized (widget))
3092 if (GTK_WIDGET_IN_REPARENT (widget))
3093 gtk_widget_unmap (widget);
3095 gtk_widget_unrealize (widget);
3098 /* Removing a widget from a container restores the child visible
3099 * flag to the default state, so it doesn't affect the child
3100 * in the next parent.
3102 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3104 old_parent = widget->parent;
3105 widget->parent = NULL;
3106 gtk_widget_set_parent_window (widget, NULL);
3107 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3110 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3111 g_object_unref (toplevel);
3114 g_object_notify (G_OBJECT (widget), "parent");
3115 g_object_thaw_notify (G_OBJECT (widget));
3116 if (!widget->parent)
3117 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3118 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3119 g_object_unref (widget);
3123 * gtk_widget_destroy:
3124 * @widget: a #GtkWidget
3126 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3127 * you don't have to cast the widget to #GtkObject. When a widget is
3128 * destroyed, it will break any references it holds to other objects.
3129 * If the widget is inside a container, the widget will be removed
3130 * from the container. If the widget is a toplevel (derived from
3131 * #GtkWindow), it will be removed from the list of toplevels, and the
3132 * reference GTK+ holds to it will be removed. Removing a
3133 * widget from its container or the list of toplevels results in the
3134 * widget being finalized, unless you've added additional references
3135 * to the widget with g_object_ref().
3137 * In most cases, only toplevel widgets (windows) require explicit
3138 * destruction, because when you destroy a toplevel its children will
3139 * be destroyed as well.
3142 gtk_widget_destroy (GtkWidget *widget)
3144 g_return_if_fail (GTK_IS_WIDGET (widget));
3146 gtk_object_destroy ((GtkObject*) widget);
3150 * gtk_widget_destroyed:
3151 * @widget: a #GtkWidget
3152 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3154 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3155 * %NULL. It's intended to be used as a callback connected to the
3156 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3157 * as a signal handler, and pass the address of your widget variable
3158 * as user data. Then when the widget is destroyed, the variable will
3159 * be set to %NULL. Useful for example to avoid multiple copies
3160 * of the same dialog.
3163 gtk_widget_destroyed (GtkWidget *widget,
3164 GtkWidget **widget_pointer)
3166 /* Don't make any assumptions about the
3168 * Even check widget_pointer.
3171 *widget_pointer = NULL;
3176 * @widget: a #GtkWidget
3178 * Flags a widget to be displayed. Any widget that isn't shown will
3179 * not appear on the screen. If you want to show all the widgets in a
3180 * container, it's easier to call gtk_widget_show_all() on the
3181 * container, instead of individually showing the widgets.
3183 * Remember that you have to show the containers containing a widget,
3184 * in addition to the widget itself, before it will appear onscreen.
3186 * When a toplevel container is shown, it is immediately realized and
3187 * mapped; other shown widgets are realized and mapped when their
3188 * toplevel container is realized and mapped.
3191 gtk_widget_show (GtkWidget *widget)
3193 g_return_if_fail (GTK_IS_WIDGET (widget));
3195 if (!gtk_widget_get_visible (widget))
3197 g_object_ref (widget);
3198 if (!gtk_widget_is_toplevel (widget))
3199 gtk_widget_queue_resize (widget);
3200 g_signal_emit (widget, widget_signals[SHOW], 0);
3201 g_object_notify (G_OBJECT (widget), "visible");
3202 g_object_unref (widget);
3207 gtk_widget_real_show (GtkWidget *widget)
3209 if (!gtk_widget_get_visible (widget))
3211 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3213 if (widget->parent &&
3214 gtk_widget_get_mapped (widget->parent) &&
3215 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3216 !gtk_widget_get_mapped (widget))
3217 gtk_widget_map (widget);
3222 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3225 g_signal_handlers_disconnect_by_func (widget,
3226 gtk_widget_show_map_callback,
3231 * gtk_widget_show_now:
3232 * @widget: a #GtkWidget
3234 * Shows a widget. If the widget is an unmapped toplevel widget
3235 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3236 * loop and wait for the window to actually be mapped. Be careful;
3237 * because the main loop is running, anything can happen during
3241 gtk_widget_show_now (GtkWidget *widget)
3245 g_return_if_fail (GTK_IS_WIDGET (widget));
3247 /* make sure we will get event */
3248 if (!gtk_widget_get_mapped (widget) &&
3249 gtk_widget_is_toplevel (widget))
3251 gtk_widget_show (widget);
3253 g_signal_connect (widget, "map-event",
3254 G_CALLBACK (gtk_widget_show_map_callback),
3258 gtk_main_iteration ();
3261 gtk_widget_show (widget);
3266 * @widget: a #GtkWidget
3268 * Reverses the effects of gtk_widget_show(), causing the widget to be
3269 * hidden (invisible to the user).
3272 gtk_widget_hide (GtkWidget *widget)
3274 g_return_if_fail (GTK_IS_WIDGET (widget));
3276 if (gtk_widget_get_visible (widget))
3278 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3280 g_object_ref (widget);
3281 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3282 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3284 g_signal_emit (widget, widget_signals[HIDE], 0);
3285 if (!gtk_widget_is_toplevel (widget))
3286 gtk_widget_queue_resize (widget);
3287 g_object_notify (G_OBJECT (widget), "visible");
3288 g_object_unref (widget);
3293 gtk_widget_real_hide (GtkWidget *widget)
3295 if (gtk_widget_get_visible (widget))
3297 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3299 if (gtk_widget_get_mapped (widget))
3300 gtk_widget_unmap (widget);
3305 * gtk_widget_hide_on_delete:
3306 * @widget: a #GtkWidget
3308 * Utility function; intended to be connected to the #GtkWidget::delete-event
3309 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3310 * argument, then returns %TRUE. If connected to ::delete-event, the
3311 * result is that clicking the close button for a window (on the
3312 * window frame, top right corner usually) will hide but not destroy
3313 * the window. By default, GTK+ destroys windows when ::delete-event
3316 * Return value: %TRUE
3319 gtk_widget_hide_on_delete (GtkWidget *widget)
3321 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3323 gtk_widget_hide (widget);
3329 * gtk_widget_show_all:
3330 * @widget: a #GtkWidget
3332 * Recursively shows a widget, and any child widgets (if the widget is
3336 gtk_widget_show_all (GtkWidget *widget)
3338 GtkWidgetClass *class;
3340 g_return_if_fail (GTK_IS_WIDGET (widget));
3342 if (gtk_widget_get_no_show_all (widget))
3345 class = GTK_WIDGET_GET_CLASS (widget);
3347 if (class->show_all)
3348 class->show_all (widget);
3352 * gtk_widget_hide_all:
3353 * @widget: a #GtkWidget
3355 * Recursively hides a widget and any child widgets.
3358 gtk_widget_hide_all (GtkWidget *widget)
3360 GtkWidgetClass *class;
3362 g_return_if_fail (GTK_IS_WIDGET (widget));
3364 if (gtk_widget_get_no_show_all (widget))
3367 class = GTK_WIDGET_GET_CLASS (widget);
3369 if (class->hide_all)
3370 class->hide_all (widget);
3375 * @widget: a #GtkWidget
3377 * This function is only for use in widget implementations. Causes
3378 * a widget to be mapped if it isn't already.
3381 gtk_widget_map (GtkWidget *widget)
3383 g_return_if_fail (GTK_IS_WIDGET (widget));
3384 g_return_if_fail (gtk_widget_get_visible (widget));
3385 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3387 if (!gtk_widget_get_mapped (widget))
3389 if (!gtk_widget_get_realized (widget))
3390 gtk_widget_realize (widget);
3392 g_signal_emit (widget, widget_signals[MAP], 0);
3394 if (!gtk_widget_get_has_window (widget))
3395 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3401 * @widget: a #GtkWidget
3403 * This function is only for use in widget implementations. Causes
3404 * a widget to be unmapped if it's currently mapped.
3407 gtk_widget_unmap (GtkWidget *widget)
3409 g_return_if_fail (GTK_IS_WIDGET (widget));
3411 if (gtk_widget_get_mapped (widget))
3413 if (!gtk_widget_get_has_window (widget))
3414 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3415 _gtk_tooltip_hide (widget);
3416 g_signal_emit (widget, widget_signals[UNMAP], 0);
3421 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3422 GdkExtensionMode mode,
3425 GList *free_list = NULL;
3428 if (window_list == NULL)
3430 if (gtk_widget_get_has_window (widget))
3431 window_list = g_list_prepend (NULL, widget->window);
3433 window_list = gdk_window_get_children (widget->window);
3435 free_list = window_list;
3438 for (l = window_list; l != NULL; l = l->next)
3440 GdkWindow *window = l->data;
3443 gdk_window_get_user_data (window, &user_data);
3444 if (user_data == widget)
3448 gdk_input_set_extension_events (window,
3449 gdk_window_get_events (window),
3452 children = gdk_window_get_children (window);
3455 gtk_widget_set_extension_events_internal (widget, mode, children);
3456 g_list_free (children);
3462 g_list_free (free_list);
3466 * gtk_widget_realize:
3467 * @widget: a #GtkWidget
3469 * Creates the GDK (windowing system) resources associated with a
3470 * widget. For example, @widget->window will be created when a widget
3471 * is realized. Normally realization happens implicitly; if you show
3472 * a widget and all its parent containers, then the widget will be
3473 * realized and mapped automatically.
3475 * Realizing a widget requires all
3476 * the widget's parent widgets to be realized; calling
3477 * gtk_widget_realize() realizes the widget's parents in addition to
3478 * @widget itself. If a widget is not yet inside a toplevel window
3479 * when you realize it, bad things will happen.
3481 * This function is primarily used in widget implementations, and
3482 * isn't very useful otherwise. Many times when you think you might
3483 * need it, a better approach is to connect to a signal that will be
3484 * called after the widget is realized automatically, such as
3485 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3486 * GtkWidget::realize signal.
3489 gtk_widget_realize (GtkWidget *widget)
3491 GdkExtensionMode mode;
3492 GtkWidgetShapeInfo *shape_info;
3494 g_return_if_fail (GTK_IS_WIDGET (widget));
3495 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3496 GTK_IS_INVISIBLE (widget));
3498 if (!gtk_widget_get_realized (widget))
3501 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3502 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3505 if (widget->parent == NULL &&
3506 !gtk_widget_is_toplevel (widget))
3507 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3508 "inside a toplevel window is not going to work very well. "
3509 "Widgets must be inside a toplevel container before realizing them.");
3511 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3512 gtk_widget_realize (widget->parent);
3514 gtk_widget_ensure_style (widget);
3516 g_signal_emit (widget, widget_signals[REALIZE], 0);
3518 gtk_widget_real_set_has_tooltip (widget,
3519 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3522 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3524 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3525 gdk_window_shape_combine_mask (widget->window,
3526 shape_info->shape_mask,
3527 shape_info->offset_x,
3528 shape_info->offset_y);
3531 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3533 gdk_window_input_shape_combine_mask (widget->window,
3534 shape_info->shape_mask,
3535 shape_info->offset_x,
3536 shape_info->offset_y);
3538 mode = gtk_widget_get_extension_events (widget);
3539 if (mode != GDK_EXTENSION_EVENTS_NONE)
3540 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3545 * gtk_widget_unrealize:
3546 * @widget: a #GtkWidget
3548 * This function is only useful in widget implementations.
3549 * Causes a widget to be unrealized (frees all GDK resources
3550 * associated with the widget, such as @widget->window).
3553 gtk_widget_unrealize (GtkWidget *widget)
3555 g_return_if_fail (GTK_IS_WIDGET (widget));
3557 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3558 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3560 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3561 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3563 if (gtk_widget_get_realized (widget))
3565 g_object_ref (widget);
3566 _gtk_tooltip_hide (widget);
3567 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3568 gtk_widget_set_realized (widget, FALSE);
3569 gtk_widget_set_mapped (widget, FALSE);
3570 g_object_unref (widget);
3574 /*****************************************
3576 *****************************************/
3579 * gtk_widget_queue_draw_area:
3580 * @widget: a #GtkWidget
3581 * @x: x coordinate of upper-left corner of rectangle to redraw
3582 * @y: y coordinate of upper-left corner of rectangle to redraw
3583 * @width: width of region to draw
3584 * @height: height of region to draw
3586 * Invalidates the rectangular area of @widget defined by @x, @y,
3587 * @width and @height by calling gdk_window_invalidate_rect() on the
3588 * widget's window and all its child windows. Once the main loop
3589 * becomes idle (after the current batch of events has been processed,
3590 * roughly), the window will receive expose events for the union of
3591 * all regions that have been invalidated.
3593 * Normally you would only use this function in widget
3594 * implementations. You might also use it, or
3595 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3596 * #GtkDrawingArea or some portion thereof.
3598 * Frequently you can just call gdk_window_invalidate_rect() or
3599 * gdk_window_invalidate_region() instead of this function. Those
3600 * functions will invalidate only a single window, instead of the
3601 * widget and all its children.
3603 * The advantage of adding to the invalidated region compared to
3604 * simply drawing immediately is efficiency; using an invalid region
3605 * ensures that you only have to redraw one time.
3608 gtk_widget_queue_draw_area (GtkWidget *widget,
3614 GdkRectangle invalid_rect;
3617 g_return_if_fail (GTK_IS_WIDGET (widget));
3619 if (!gtk_widget_get_realized (widget))
3622 /* Just return if the widget or one of its ancestors isn't mapped */
3623 for (w = widget; w != NULL; w = w->parent)
3624 if (!gtk_widget_get_mapped (w))
3627 /* Find the correct widget */
3629 if (gtk_widget_get_has_window (widget))
3633 /* Translate widget relative to window-relative */
3635 gint wx, wy, wwidth, wheight;
3637 gdk_window_get_position (widget->window, &wx, &wy);
3638 x -= wx - widget->allocation.x;
3639 y -= wy - widget->allocation.y;
3641 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3643 if (x + width <= 0 || y + height <= 0 ||
3644 x >= wwidth || y >= wheight)
3655 if (x + width > wwidth)
3657 if (y + height > wheight)
3658 height = wheight - y;
3664 invalid_rect.width = width;
3665 invalid_rect.height = height;
3667 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3671 widget_add_child_draw_rectangle (GtkWidget *widget,
3674 GdkRectangle child_rect;
3676 if (!gtk_widget_get_mapped (widget) ||
3677 widget->window != widget->parent->window)
3680 gtk_widget_get_draw_rectangle (widget, &child_rect);
3681 gdk_rectangle_union (rect, &child_rect, rect);
3685 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3688 if (!gtk_widget_get_has_window (widget))
3690 GtkBorder *draw_border = NULL;
3692 *rect = widget->allocation;
3694 gtk_widget_style_get (widget,
3695 "draw-border", &draw_border,
3699 rect->x -= draw_border->left;
3700 rect->y -= draw_border->top;
3701 rect->width += draw_border->left + draw_border->right;
3702 rect->height += draw_border->top + draw_border->bottom;
3704 gtk_border_free (draw_border);
3707 if (GTK_IS_CONTAINER (widget))
3708 gtk_container_forall (GTK_CONTAINER (widget),
3709 (GtkCallback)widget_add_child_draw_rectangle,
3716 rect->width = widget->allocation.width;
3717 rect->height = widget->allocation.height;
3722 * gtk_widget_queue_draw:
3723 * @widget: a #GtkWidget
3725 * Equivalent to calling gtk_widget_queue_draw_area() for the
3726 * entire area of a widget.
3729 gtk_widget_queue_draw (GtkWidget *widget)
3733 g_return_if_fail (GTK_IS_WIDGET (widget));
3735 gtk_widget_get_draw_rectangle (widget, &rect);
3737 gtk_widget_queue_draw_area (widget,
3739 rect.width, rect.height);
3742 /* Invalidates the given area (allocation-relative-coordinates)
3743 * in all of the widget's windows
3746 * gtk_widget_queue_clear_area:
3747 * @widget: a #GtkWidget
3748 * @x: x coordinate of upper-left corner of rectangle to redraw
3749 * @y: y coordinate of upper-left corner of rectangle to redraw
3750 * @width: width of region to draw
3751 * @height: height of region to draw
3753 * This function is no longer different from
3754 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3755 * gtk_widget_queue_draw_area(). Originally
3756 * gtk_widget_queue_clear_area() would force a redraw of the
3757 * background for %GTK_NO_WINDOW widgets, and
3758 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3759 * the background will be redrawn.
3761 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3764 gtk_widget_queue_clear_area (GtkWidget *widget,
3770 g_return_if_fail (GTK_IS_WIDGET (widget));
3772 gtk_widget_queue_draw_area (widget, x, y, width, height);
3776 * gtk_widget_queue_clear:
3777 * @widget: a #GtkWidget
3779 * This function does the same as gtk_widget_queue_draw().
3781 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3784 gtk_widget_queue_clear (GtkWidget *widget)
3786 g_return_if_fail (GTK_IS_WIDGET (widget));
3788 gtk_widget_queue_draw (widget);
3792 * gtk_widget_queue_resize:
3793 * @widget: a #GtkWidget
3795 * This function is only for use in widget implementations.
3796 * Flags a widget to have its size renegotiated; should
3797 * be called when a widget for some reason has a new size request.
3798 * For example, when you change the text in a #GtkLabel, #GtkLabel
3799 * queues a resize to ensure there's enough space for the new text.
3802 gtk_widget_queue_resize (GtkWidget *widget)
3804 g_return_if_fail (GTK_IS_WIDGET (widget));
3806 if (gtk_widget_get_realized (widget))
3807 gtk_widget_queue_shallow_draw (widget);
3809 _gtk_size_group_queue_resize (widget);
3813 * gtk_widget_queue_resize_no_redraw:
3814 * @widget: a #GtkWidget
3816 * This function works like gtk_widget_queue_resize(),
3817 * except that the widget is not invalidated.
3822 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3824 g_return_if_fail (GTK_IS_WIDGET (widget));
3826 _gtk_size_group_queue_resize (widget);
3831 * @widget: a #GtkWidget
3832 * @area: area to draw
3834 * In GTK+ 1.2, this function would immediately render the
3835 * region @area of a widget, by invoking the virtual draw method of a
3836 * widget. In GTK+ 2.0, the draw method is gone, and instead
3837 * gtk_widget_draw() simply invalidates the specified region of the
3838 * widget, then updates the invalid region of the widget immediately.
3839 * Usually you don't want to update the region immediately for
3840 * performance reasons, so in general gtk_widget_queue_draw_area() is
3841 * a better choice if you want to draw a region of a widget.
3844 gtk_widget_draw (GtkWidget *widget,
3845 const GdkRectangle *area)
3847 g_return_if_fail (GTK_IS_WIDGET (widget));
3849 if (gtk_widget_is_drawable (widget))
3852 gtk_widget_queue_draw_area (widget,
3854 area->width, area->height);
3856 gtk_widget_queue_draw (widget);
3858 gdk_window_process_updates (widget->window, TRUE);
3863 * gtk_widget_size_request:
3864 * @widget: a #GtkWidget
3865 * @requisition: a #GtkRequisition to be filled in
3867 * This function is typically used when implementing a #GtkContainer
3868 * subclass. Obtains the preferred size of a widget. The container
3869 * uses this information to arrange its child widgets and decide what
3870 * size allocations to give them with gtk_widget_size_allocate().
3872 * You can also call this function from an application, with some
3873 * caveats. Most notably, getting a size request requires the widget
3874 * to be associated with a screen, because font information may be
3875 * needed. Multihead-aware applications should keep this in mind.
3877 * Also remember that the size request is not necessarily the size
3878 * a widget will actually be allocated.
3880 * See also gtk_widget_get_child_requisition().
3883 gtk_widget_size_request (GtkWidget *widget,
3884 GtkRequisition *requisition)
3886 g_return_if_fail (GTK_IS_WIDGET (widget));
3888 #ifdef G_ENABLE_DEBUG
3889 if (requisition == &widget->requisition)
3890 g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
3891 "to widget->requisition. gtk_widget_set_usize() may not work properly.");
3892 #endif /* G_ENABLE_DEBUG */
3894 _gtk_size_group_compute_desired_size (widget, requisition, NULL);
3898 * gtk_widget_get_child_requisition:
3899 * @widget: a #GtkWidget
3900 * @requisition: a #GtkRequisition to be filled in
3902 * This function is only for use in widget implementations. Obtains
3903 * @widget->requisition, unless someone has forced a particular
3904 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3905 * in which case it returns that geometry instead of the widget's
3908 * This function differs from gtk_widget_size_request() in that
3909 * it retrieves the last size request value from @widget->requisition,
3910 * while gtk_widget_size_request() actually calls the "size_request" method
3911 * on @widget to compute the size request and fill in @widget->requisition,
3912 * and only then returns @widget->requisition.
3914 * Because this function does not call the "size_request" method, it
3915 * can only be used when you know that @widget->requisition is
3916 * up-to-date, that is, gtk_widget_size_request() has been called
3917 * since the last time a resize was queued. In general, only container
3918 * implementations have this information; applications should use
3919 * gtk_widget_size_request().
3922 gtk_widget_get_child_requisition (GtkWidget *widget,
3923 GtkRequisition *requisition)
3925 _gtk_size_group_get_child_requisition (widget, requisition);
3929 invalidate_predicate (GdkWindow *window,
3934 gdk_window_get_user_data (window, &user_data);
3936 return (user_data == data);
3939 /* Invalidate @region in widget->window and all children
3940 * of widget->window owned by widget. @region is in the
3941 * same coordinates as widget->allocation and will be
3942 * modified by this call.
3945 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3948 if (!gtk_widget_get_realized (widget))
3951 if (gtk_widget_get_has_window (widget) && widget->parent)
3955 gdk_window_get_position (widget->window, &x, &y);
3956 gdk_region_offset (region, -x, -y);
3959 gdk_window_invalidate_maybe_recurse (widget->window, region,
3960 invalidate_predicate, widget);
3964 * gtk_widget_queue_shallow_draw:
3965 * @widget: a #GtkWidget
3967 * Like gtk_widget_queue_draw(), but only windows owned
3968 * by @widget are invalidated.
3971 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3976 if (!gtk_widget_get_realized (widget))
3979 gtk_widget_get_draw_rectangle (widget, &rect);
3981 /* get_draw_rectangle() gives us window coordinates, we
3982 * need to convert to the coordinates that widget->allocation
3985 if (gtk_widget_get_has_window (widget) && widget->parent)
3989 gdk_window_get_position (widget->window, &wx, &wy);
3995 region = gdk_region_rectangle (&rect);
3996 gtk_widget_invalidate_widget_windows (widget, region);
3997 gdk_region_destroy (region);
4001 * gtk_widget_size_allocate:
4002 * @widget: a #GtkWidget
4003 * @allocation: position and size to be allocated to @widget
4005 * This function is only used by #GtkContainer subclasses, to assign a size
4006 * and position to their child widgets.
4009 gtk_widget_size_allocate (GtkWidget *widget,
4010 GtkAllocation *allocation)
4012 GtkWidgetAuxInfo *aux_info;
4013 GdkRectangle real_allocation;
4014 GdkRectangle old_allocation;
4015 gboolean alloc_needed;
4016 gboolean size_changed;
4017 gboolean position_changed;
4019 g_return_if_fail (GTK_IS_WIDGET (widget));
4021 #ifdef G_ENABLE_DEBUG
4022 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4033 parent = gtk_widget_get_parent (parent);
4036 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4037 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4038 2 * depth, " ", name,
4039 allocation->width, allocation->height);
4041 #endif /* G_ENABLE_DEBUG */
4043 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4044 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4045 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4047 old_allocation = widget->allocation;
4048 real_allocation = *allocation;
4049 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4053 if (aux_info->x_set)
4054 real_allocation.x = aux_info->x;
4055 if (aux_info->y_set)
4056 real_allocation.y = aux_info->y;
4059 if (real_allocation.width < 0 || real_allocation.height < 0)
4061 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4062 real_allocation.width,
4063 real_allocation.height);
4066 real_allocation.width = MAX (real_allocation.width, 1);
4067 real_allocation.height = MAX (real_allocation.height, 1);
4069 size_changed = (old_allocation.width != real_allocation.width ||
4070 old_allocation.height != real_allocation.height);
4071 position_changed = (old_allocation.x != real_allocation.x ||
4072 old_allocation.y != real_allocation.y);
4074 if (!alloc_needed && !size_changed && !position_changed)
4077 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4079 if (gtk_widget_get_mapped (widget))
4081 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4083 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4085 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4086 gdk_region_union_with_rect (invalidate, &old_allocation);
4088 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4089 gdk_region_destroy (invalidate);
4094 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4096 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4098 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4099 gdk_region_union_with_rect (invalidate, &old_allocation);
4101 gtk_widget_invalidate_widget_windows (widget, invalidate);
4102 gdk_region_destroy (invalidate);
4107 if ((size_changed || position_changed) && widget->parent &&
4108 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4110 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4111 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4112 gdk_region_destroy (invalidate);
4117 * gtk_widget_common_ancestor:
4118 * @widget_a: a #GtkWidget
4119 * @widget_b: a #GtkWidget
4121 * Find the common ancestor of @widget_a and @widget_b that
4122 * is closest to the two widgets.
4124 * Return value: the closest common ancestor of @widget_a and
4125 * @widget_b or %NULL if @widget_a and @widget_b do not
4126 * share a common ancestor.
4129 gtk_widget_common_ancestor (GtkWidget *widget_a,
4130 GtkWidget *widget_b)
4132 GtkWidget *parent_a;
4133 GtkWidget *parent_b;
4137 parent_a = widget_a;
4138 while (parent_a->parent)
4140 parent_a = parent_a->parent;
4144 parent_b = widget_b;
4145 while (parent_b->parent)
4147 parent_b = parent_b->parent;
4151 if (parent_a != parent_b)
4154 while (depth_a > depth_b)
4156 widget_a = widget_a->parent;
4160 while (depth_b > depth_a)
4162 widget_b = widget_b->parent;
4166 while (widget_a != widget_b)
4168 widget_a = widget_a->parent;
4169 widget_b = widget_b->parent;
4176 * gtk_widget_translate_coordinates:
4177 * @src_widget: a #GtkWidget
4178 * @dest_widget: a #GtkWidget
4179 * @src_x: X position relative to @src_widget
4180 * @src_y: Y position relative to @src_widget
4181 * @dest_x: (out): location to store X position relative to @dest_widget
4182 * @dest_y: (out): location to store Y position relative to @dest_widget
4184 * Translate coordinates relative to @src_widget's allocation to coordinates
4185 * relative to @dest_widget's allocations. In order to perform this
4186 * operation, both widgets must be realized, and must share a common
4189 * Return value: %FALSE if either widget was not realized, or there
4190 * was no common ancestor. In this case, nothing is stored in
4191 * *@dest_x and *@dest_y. Otherwise %TRUE.
4194 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4195 GtkWidget *dest_widget,
4201 GtkWidget *ancestor;
4204 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4205 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4207 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4208 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4211 /* Translate from allocation relative to window relative */
4212 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4215 gdk_window_get_position (src_widget->window, &wx, &wy);
4217 src_x -= wx - src_widget->allocation.x;
4218 src_y -= wy - src_widget->allocation.y;
4222 src_x += src_widget->allocation.x;
4223 src_y += src_widget->allocation.y;
4226 /* Translate to the common ancestor */
4227 window = src_widget->window;
4228 while (window != ancestor->window)
4232 gdk_window_get_position (window, &dx, &dy);
4237 window = gdk_window_get_parent (window);
4239 if (!window) /* Handle GtkHandleBox */
4244 window = dest_widget->window;
4245 while (window != ancestor->window)
4249 gdk_window_get_position (window, &dx, &dy);
4254 window = gdk_window_get_parent (window);
4256 if (!window) /* Handle GtkHandleBox */
4260 /* Translate from window relative to allocation relative */
4261 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4264 gdk_window_get_position (dest_widget->window, &wx, &wy);
4266 src_x += wx - dest_widget->allocation.x;
4267 src_y += wy - dest_widget->allocation.y;
4271 src_x -= dest_widget->allocation.x;
4272 src_y -= dest_widget->allocation.y;
4284 gtk_widget_real_size_allocate (GtkWidget *widget,
4285 GtkAllocation *allocation)
4287 widget->allocation = *allocation;
4289 if (gtk_widget_get_realized (widget) &&
4290 gtk_widget_get_has_window (widget))
4292 gdk_window_move_resize (widget->window,
4293 allocation->x, allocation->y,
4294 allocation->width, allocation->height);
4299 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4302 /* widgets must be onscreen for accels to take effect */
4303 return gtk_widget_is_sensitive (widget) &&
4304 gtk_widget_is_drawable (widget) &&
4305 gdk_window_is_viewable (widget->window);
4309 * gtk_widget_can_activate_accel:
4310 * @widget: a #GtkWidget
4311 * @signal_id: the ID of a signal installed on @widget
4313 * Determines whether an accelerator that activates the signal
4314 * identified by @signal_id can currently be activated.
4315 * This is done by emitting the #GtkWidget::can-activate-accel
4316 * signal on @widget; if the signal isn't overridden by a
4317 * handler or in a derived widget, then the default check is
4318 * that the widget must be sensitive, and the widget and all
4319 * its ancestors mapped.
4321 * Return value: %TRUE if the accelerator can be activated.
4326 gtk_widget_can_activate_accel (GtkWidget *widget,
4329 gboolean can_activate = FALSE;
4330 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4331 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4332 return can_activate;
4341 closure_accel_activate (GClosure *closure,
4342 GValue *return_value,
4343 guint n_param_values,
4344 const GValue *param_values,
4345 gpointer invocation_hint,
4346 gpointer marshal_data)
4348 AccelClosure *aclosure = (AccelClosure*) closure;
4349 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4352 g_signal_emit (closure->data, aclosure->signal_id, 0);
4354 /* whether accelerator was handled */
4355 g_value_set_boolean (return_value, can_activate);
4359 closures_destroy (gpointer data)
4361 GSList *slist, *closures = data;
4363 for (slist = closures; slist; slist = slist->next)
4365 g_closure_invalidate (slist->data);
4366 g_closure_unref (slist->data);
4368 g_slist_free (closures);
4372 widget_new_accel_closure (GtkWidget *widget,
4375 AccelClosure *aclosure;
4376 GClosure *closure = NULL;
4377 GSList *slist, *closures;
4379 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4380 for (slist = closures; slist; slist = slist->next)
4381 if (!gtk_accel_group_from_accel_closure (slist->data))
4383 /* reuse this closure */
4384 closure = slist->data;
4389 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4390 closures = g_slist_prepend (closures, g_closure_ref (closure));
4391 g_closure_sink (closure);
4392 g_closure_set_marshal (closure, closure_accel_activate);
4394 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4396 aclosure = (AccelClosure*) closure;
4397 g_assert (closure->data == widget);
4398 g_assert (closure->marshal == closure_accel_activate);
4399 aclosure->signal_id = signal_id;
4405 * gtk_widget_add_accelerator
4406 * @widget: widget to install an accelerator on
4407 * @accel_signal: widget signal to emit on accelerator activation
4408 * @accel_group: accel group for this widget, added to its toplevel
4409 * @accel_key: GDK keyval of the accelerator
4410 * @accel_mods: modifier key combination of the accelerator
4411 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4413 * Installs an accelerator for this @widget in @accel_group that causes
4414 * @accel_signal to be emitted if the accelerator is activated.
4415 * The @accel_group needs to be added to the widget's toplevel via
4416 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4417 * Accelerators added through this function are not user changeable during
4418 * runtime. If you want to support accelerators that can be changed by the
4419 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4420 * gtk_menu_item_set_accel_path() instead.
4423 gtk_widget_add_accelerator (GtkWidget *widget,
4424 const gchar *accel_signal,
4425 GtkAccelGroup *accel_group,
4427 GdkModifierType accel_mods,
4428 GtkAccelFlags accel_flags)
4433 g_return_if_fail (GTK_IS_WIDGET (widget));
4434 g_return_if_fail (accel_signal != NULL);
4435 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4437 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4438 if (!query.signal_id ||
4439 !(query.signal_flags & G_SIGNAL_ACTION) ||
4440 query.return_type != G_TYPE_NONE ||
4443 /* hmm, should be elaborate enough */
4444 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4445 G_OBJECT_TYPE_NAME (widget), accel_signal);
4449 closure = widget_new_accel_closure (widget, query.signal_id);
4451 g_object_ref (widget);
4453 /* install the accelerator. since we don't map this onto an accel_path,
4454 * the accelerator will automatically be locked.
4456 gtk_accel_group_connect (accel_group,
4459 accel_flags | GTK_ACCEL_LOCKED,
4462 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4464 g_object_unref (widget);
4468 * gtk_widget_remove_accelerator:
4469 * @widget: widget to install an accelerator on
4470 * @accel_group: accel group for this widget
4471 * @accel_key: GDK keyval of the accelerator
4472 * @accel_mods: modifier key combination of the accelerator
4473 * @returns: whether an accelerator was installed and could be removed
4475 * Removes an accelerator from @widget, previously installed with
4476 * gtk_widget_add_accelerator().
4479 gtk_widget_remove_accelerator (GtkWidget *widget,
4480 GtkAccelGroup *accel_group,
4482 GdkModifierType accel_mods)
4484 GtkAccelGroupEntry *ag_entry;
4485 GList *slist, *clist;
4488 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4489 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4491 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4492 clist = gtk_widget_list_accel_closures (widget);
4493 for (slist = clist; slist; slist = slist->next)
4497 for (i = 0; i < n; i++)
4498 if (slist->data == (gpointer) ag_entry[i].closure)
4500 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4502 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4504 g_list_free (clist);
4509 g_list_free (clist);
4511 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4512 accel_key, accel_mods, accel_group,
4513 G_OBJECT_TYPE_NAME (widget), widget);
4519 * gtk_widget_list_accel_closures
4520 * @widget: widget to list accelerator closures for
4521 * @returns: a newly allocated #GList of closures
4523 * Lists the closures used by @widget for accelerator group connections
4524 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4525 * The closures can be used to monitor accelerator changes on @widget,
4526 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4527 * #GtkAccelGroup of a closure which can be found out with
4528 * gtk_accel_group_from_accel_closure().
4531 gtk_widget_list_accel_closures (GtkWidget *widget)
4534 GList *clist = NULL;
4536 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4538 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4539 if (gtk_accel_group_from_accel_closure (slist->data))
4540 clist = g_list_prepend (clist, slist->data);
4546 GtkAccelGroup *accel_group;
4551 destroy_accel_path (gpointer data)
4553 AccelPath *apath = data;
4555 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4557 /* closures_destroy takes care of unrefing the closure */
4558 g_object_unref (apath->accel_group);
4560 g_slice_free (AccelPath, apath);
4565 * gtk_widget_set_accel_path:
4566 * @widget: a #GtkWidget
4567 * @accel_path: (allow-none): path used to look up the accelerator
4568 * @accel_group: (allow-none): a #GtkAccelGroup.
4570 * Given an accelerator group, @accel_group, and an accelerator path,
4571 * @accel_path, sets up an accelerator in @accel_group so whenever the
4572 * key binding that is defined for @accel_path is pressed, @widget
4573 * will be activated. This removes any accelerators (for any
4574 * accelerator group) installed by previous calls to
4575 * gtk_widget_set_accel_path(). Associating accelerators with
4576 * paths allows them to be modified by the user and the modifications
4577 * to be saved for future use. (See gtk_accel_map_save().)
4579 * This function is a low level function that would most likely
4580 * be used by a menu creation system like #GtkUIManager. If you
4581 * use #GtkUIManager, setting up accelerator paths will be done
4584 * Even when you you aren't using #GtkUIManager, if you only want to
4585 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4586 * provides a somewhat more convenient interface.
4588 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4589 * pass a static string, you can save some memory by interning it first with
4590 * g_intern_static_string().
4593 gtk_widget_set_accel_path (GtkWidget *widget,
4594 const gchar *accel_path,
4595 GtkAccelGroup *accel_group)
4599 g_return_if_fail (GTK_IS_WIDGET (widget));
4600 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4604 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4605 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4607 gtk_accel_map_add_entry (accel_path, 0, 0);
4608 apath = g_slice_new (AccelPath);
4609 apath->accel_group = g_object_ref (accel_group);
4610 apath->path_quark = g_quark_from_string (accel_path);
4611 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4616 /* also removes possible old settings */
4617 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4620 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4622 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4626 _gtk_widget_get_accel_path (GtkWidget *widget,
4631 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4633 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4635 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4636 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4640 * gtk_widget_mnemonic_activate:
4641 * @widget: a #GtkWidget
4642 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4644 * Emits the #GtkWidget::mnemonic-activate signal.
4646 * The default handler for this signal activates the @widget if
4647 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4650 * Returns: %TRUE if the signal has been handled
4653 gtk_widget_mnemonic_activate (GtkWidget *widget,
4654 gboolean group_cycling)
4658 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4660 group_cycling = group_cycling != FALSE;
4661 if (!gtk_widget_is_sensitive (widget))
4664 g_signal_emit (widget,
4665 widget_signals[MNEMONIC_ACTIVATE],
4673 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4674 gboolean group_cycling)
4676 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4677 gtk_widget_activate (widget);
4678 else if (gtk_widget_get_can_focus (widget))
4679 gtk_widget_grab_focus (widget);
4682 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4683 G_OBJECT_TYPE_NAME (widget));
4684 gtk_widget_error_bell (widget);
4690 gtk_widget_real_key_press_event (GtkWidget *widget,
4693 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4697 gtk_widget_real_key_release_event (GtkWidget *widget,
4700 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4704 gtk_widget_real_focus_in_event (GtkWidget *widget,
4705 GdkEventFocus *event)
4707 gtk_widget_queue_shallow_draw (widget);
4713 gtk_widget_real_focus_out_event (GtkWidget *widget,
4714 GdkEventFocus *event)
4716 gtk_widget_queue_shallow_draw (widget);
4721 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4722 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4726 * @widget: a #GtkWidget
4727 * @event: a #GdkEvent
4729 * Rarely-used function. This function is used to emit
4730 * the event signals on a widget (those signals should never
4731 * be emitted without using this function to do so).
4732 * If you want to synthesize an event though, don't use this function;
4733 * instead, use gtk_main_do_event() so the event will behave as if
4734 * it were in the event queue. Don't synthesize expose events; instead,
4735 * use gdk_window_invalidate_rect() to invalidate a region of the
4738 * Return value: return from the event signal emission (%TRUE if
4739 * the event was handled)
4742 gtk_widget_event (GtkWidget *widget,
4745 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4746 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4748 if (event->type == GDK_EXPOSE)
4750 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4751 "the same effect, call gdk_window_invalidate_rect/region(), "
4752 "followed by gdk_window_process_updates().");
4756 return gtk_widget_event_internal (widget, event);
4761 * gtk_widget_send_expose:
4762 * @widget: a #GtkWidget
4763 * @event: a expose #GdkEvent
4765 * Very rarely-used function. This function is used to emit
4766 * an expose event signals on a widget. This function is not
4767 * normally used directly. The only time it is used is when
4768 * propagating an expose event to a child %NO_WINDOW widget, and
4769 * that is normally done using gtk_container_propagate_expose().
4771 * If you want to force an area of a window to be redrawn,
4772 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4773 * To cause the redraw to be done immediately, follow that call
4774 * with a call to gdk_window_process_updates().
4776 * Return value: return from the event signal emission (%TRUE if
4777 * the event was handled)
4780 gtk_widget_send_expose (GtkWidget *widget,
4783 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4784 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4785 g_return_val_if_fail (event != NULL, TRUE);
4786 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4788 return gtk_widget_event_internal (widget, event);
4792 event_window_is_still_viewable (GdkEvent *event)
4794 /* Some programs, such as gnome-theme-manager, fake widgets
4795 * into exposing onto a pixmap by sending expose events with
4796 * event->window pointing to a pixmap
4798 if (GDK_IS_PIXMAP (event->any.window))
4799 return event->type == GDK_EXPOSE;
4801 /* Check that we think the event's window is viewable before
4802 * delivering the event, to prevent suprises. We do this here
4803 * at the last moment, since the event may have been queued
4804 * up behind other events, held over a recursive main loop, etc.
4806 switch (event->type)
4809 case GDK_MOTION_NOTIFY:
4810 case GDK_BUTTON_PRESS:
4811 case GDK_2BUTTON_PRESS:
4812 case GDK_3BUTTON_PRESS:
4814 case GDK_ENTER_NOTIFY:
4815 case GDK_PROXIMITY_IN:
4817 return event->any.window && gdk_window_is_viewable (event->any.window);
4820 /* The following events are the second half of paired events;
4821 * we always deliver them to deal with widgets that clean up
4822 * on the second half.
4824 case GDK_BUTTON_RELEASE:
4825 case GDK_KEY_RELEASE:
4826 case GDK_LEAVE_NOTIFY:
4827 case GDK_PROXIMITY_OUT:
4831 /* Remaining events would make sense on an not-viewable window,
4832 * or don't have an associated window.
4839 gtk_widget_event_internal (GtkWidget *widget,
4842 gboolean return_val = FALSE;
4844 /* We check only once for is-still-visible; if someone
4845 * hides the window in on of the signals on the widget,
4846 * they are responsible for returning TRUE to terminate
4849 if (!event_window_is_still_viewable (event))
4852 g_object_ref (widget);
4854 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4855 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4860 switch (event->type)
4865 case GDK_BUTTON_PRESS:
4866 case GDK_2BUTTON_PRESS:
4867 case GDK_3BUTTON_PRESS:
4868 signal_num = BUTTON_PRESS_EVENT;
4871 signal_num = SCROLL_EVENT;
4873 case GDK_BUTTON_RELEASE:
4874 signal_num = BUTTON_RELEASE_EVENT;
4876 case GDK_MOTION_NOTIFY:
4877 signal_num = MOTION_NOTIFY_EVENT;
4880 signal_num = DELETE_EVENT;
4883 signal_num = DESTROY_EVENT;
4884 _gtk_tooltip_hide (widget);
4887 signal_num = KEY_PRESS_EVENT;
4889 case GDK_KEY_RELEASE:
4890 signal_num = KEY_RELEASE_EVENT;
4892 case GDK_ENTER_NOTIFY:
4893 signal_num = ENTER_NOTIFY_EVENT;
4895 case GDK_LEAVE_NOTIFY:
4896 signal_num = LEAVE_NOTIFY_EVENT;
4898 case GDK_FOCUS_CHANGE:
4899 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4900 if (event->focus_change.in)
4901 _gtk_tooltip_focus_in (widget);
4903 _gtk_tooltip_focus_out (widget);
4906 signal_num = CONFIGURE_EVENT;
4909 signal_num = MAP_EVENT;
4912 signal_num = UNMAP_EVENT;
4914 case GDK_WINDOW_STATE:
4915 signal_num = WINDOW_STATE_EVENT;
4917 case GDK_PROPERTY_NOTIFY:
4918 signal_num = PROPERTY_NOTIFY_EVENT;
4920 case GDK_SELECTION_CLEAR:
4921 signal_num = SELECTION_CLEAR_EVENT;
4923 case GDK_SELECTION_REQUEST:
4924 signal_num = SELECTION_REQUEST_EVENT;
4926 case GDK_SELECTION_NOTIFY:
4927 signal_num = SELECTION_NOTIFY_EVENT;
4929 case GDK_PROXIMITY_IN:
4930 signal_num = PROXIMITY_IN_EVENT;
4932 case GDK_PROXIMITY_OUT:
4933 signal_num = PROXIMITY_OUT_EVENT;
4936 signal_num = NO_EXPOSE_EVENT;
4938 case GDK_CLIENT_EVENT:
4939 signal_num = CLIENT_EVENT;
4942 signal_num = EXPOSE_EVENT;
4944 case GDK_VISIBILITY_NOTIFY:
4945 signal_num = VISIBILITY_NOTIFY_EVENT;
4947 case GDK_GRAB_BROKEN:
4948 signal_num = GRAB_BROKEN;
4951 signal_num = DAMAGE_EVENT;
4954 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4958 if (signal_num != -1)
4959 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4961 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4962 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4966 g_object_unref (widget);
4972 * gtk_widget_activate:
4973 * @widget: a #GtkWidget that's activatable
4975 * For widgets that can be "activated" (buttons, menu items, etc.)
4976 * this function activates them. Activation is what happens when you
4977 * press Enter on a widget during key navigation. If @widget isn't
4978 * activatable, the function returns %FALSE.
4980 * Return value: %TRUE if the widget was activatable
4983 gtk_widget_activate (GtkWidget *widget)
4985 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4987 if (WIDGET_CLASS (widget)->activate_signal)
4989 /* FIXME: we should eventually check the signals signature here */
4990 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4999 * gtk_widget_set_scroll_adjustments:
5000 * @widget: a #GtkWidget
5001 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5002 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5004 * For widgets that support scrolling, sets the scroll adjustments and
5005 * returns %TRUE. For widgets that don't support scrolling, does
5006 * nothing and returns %FALSE. Widgets that don't support scrolling
5007 * can be scrolled by placing them in a #GtkViewport, which does
5008 * support scrolling.
5010 * Return value: %TRUE if the widget supports scrolling
5013 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5014 GtkAdjustment *hadjustment,
5015 GtkAdjustment *vadjustment)
5020 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5023 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5025 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5027 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5031 g_signal_query (signal_id, &query);
5032 if (!query.signal_id ||
5033 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5034 query.return_type != G_TYPE_NONE ||
5035 query.n_params != 2 ||
5036 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5037 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5039 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5040 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5044 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5049 gtk_widget_reparent_subwindows (GtkWidget *widget,
5050 GdkWindow *new_window)
5052 if (!gtk_widget_get_has_window (widget))
5054 GList *children = gdk_window_get_children (widget->window);
5057 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5059 GdkWindow *window = tmp_list->data;
5062 gdk_window_get_user_data (window, &child);
5063 while (child && child != widget)
5064 child = ((GtkWidget*) child)->parent;
5067 gdk_window_reparent (window, new_window, 0, 0);
5070 g_list_free (children);
5075 GList *tmp_list, *children;
5077 parent = gdk_window_get_parent (widget->window);
5080 gdk_window_reparent (widget->window, new_window, 0, 0);
5083 children = gdk_window_get_children (parent);
5085 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5087 GdkWindow *window = tmp_list->data;
5090 gdk_window_get_user_data (window, &child);
5092 if (child == widget)
5093 gdk_window_reparent (window, new_window, 0, 0);
5096 g_list_free (children);
5102 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5103 gpointer client_data)
5105 g_assert (client_data != NULL);
5107 if (!gtk_widget_get_has_window (widget))
5110 g_object_unref (widget->window);
5111 widget->window = (GdkWindow*) client_data;
5113 g_object_ref (widget->window);
5115 if (GTK_IS_CONTAINER (widget))
5116 gtk_container_forall (GTK_CONTAINER (widget),
5117 gtk_widget_reparent_fixup_child,
5123 * gtk_widget_reparent:
5124 * @widget: a #GtkWidget
5125 * @new_parent: a #GtkContainer to move the widget into
5127 * Moves a widget from one #GtkContainer to another, handling reference
5128 * count issues to avoid destroying the widget.
5131 gtk_widget_reparent (GtkWidget *widget,
5132 GtkWidget *new_parent)
5134 g_return_if_fail (GTK_IS_WIDGET (widget));
5135 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5136 g_return_if_fail (widget->parent != NULL);
5138 if (widget->parent != new_parent)
5140 /* First try to see if we can get away without unrealizing
5141 * the widget as we reparent it. if so we set a flag so
5142 * that gtk_widget_unparent doesn't unrealize widget
5144 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5145 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5147 g_object_ref (widget);
5148 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5149 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5150 g_object_unref (widget);
5152 if (GTK_WIDGET_IN_REPARENT (widget))
5154 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5156 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5157 gtk_widget_reparent_fixup_child (widget,
5158 gtk_widget_get_parent_window (widget));
5161 g_object_notify (G_OBJECT (widget), "parent");
5166 * gtk_widget_intersect:
5167 * @widget: a #GtkWidget
5168 * @area: a rectangle
5169 * @intersection: rectangle to store intersection of @widget and @area
5171 * Computes the intersection of a @widget's area and @area, storing
5172 * the intersection in @intersection, and returns %TRUE if there was
5173 * an intersection. @intersection may be %NULL if you're only
5174 * interested in whether there was an intersection.
5176 * Return value: %TRUE if there was an intersection
5179 gtk_widget_intersect (GtkWidget *widget,
5180 const GdkRectangle *area,
5181 GdkRectangle *intersection)
5187 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5188 g_return_val_if_fail (area != NULL, FALSE);
5191 dest = intersection;
5195 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5197 if (return_val && intersection && gtk_widget_get_has_window (widget))
5199 intersection->x -= widget->allocation.x;
5200 intersection->y -= widget->allocation.y;
5207 * gtk_widget_region_intersect:
5208 * @widget: a #GtkWidget
5209 * @region: a #GdkRegion, in the same coordinate system as
5210 * @widget->allocation. That is, relative to @widget->window
5211 * for %NO_WINDOW widgets; relative to the parent window
5212 * of @widget->window for widgets with their own window.
5213 * @returns: A newly allocated region holding the intersection of @widget
5214 * and @region. The coordinates of the return value are
5215 * relative to @widget->window for %NO_WINDOW widgets, and
5216 * relative to the parent window of @widget->window for
5217 * widgets with their own window.
5219 * Computes the intersection of a @widget's area and @region, returning
5220 * the intersection. The result may be empty, use gdk_region_empty() to
5224 gtk_widget_region_intersect (GtkWidget *widget,
5225 const GdkRegion *region)
5230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5231 g_return_val_if_fail (region != NULL, NULL);
5233 gtk_widget_get_draw_rectangle (widget, &rect);
5235 dest = gdk_region_rectangle (&rect);
5237 gdk_region_intersect (dest, region);
5243 * _gtk_widget_grab_notify:
5244 * @widget: a #GtkWidget
5245 * @was_grabbed: whether a grab is now in effect
5247 * Emits the #GtkWidget::grab-notify signal on @widget.
5252 _gtk_widget_grab_notify (GtkWidget *widget,
5253 gboolean was_grabbed)
5255 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5259 * gtk_widget_grab_focus:
5260 * @widget: a #GtkWidget
5262 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5263 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5264 * something like #GtkFrame won't work.
5266 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5267 * gtk_widget_set_can_focus() to modify that flag.
5270 gtk_widget_grab_focus (GtkWidget *widget)
5272 g_return_if_fail (GTK_IS_WIDGET (widget));
5274 if (!gtk_widget_is_sensitive (widget))
5277 g_object_ref (widget);
5278 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5279 g_object_notify (G_OBJECT (widget), "has-focus");
5280 g_object_unref (widget);
5284 reset_focus_recurse (GtkWidget *widget,
5287 if (GTK_IS_CONTAINER (widget))
5289 GtkContainer *container;
5291 container = GTK_CONTAINER (widget);
5292 gtk_container_set_focus_child (container, NULL);
5294 gtk_container_foreach (container,
5295 reset_focus_recurse,
5301 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5303 if (gtk_widget_get_can_focus (focus_widget))
5305 GtkWidget *toplevel;
5308 /* clear the current focus setting, break if the current widget
5309 * is the focus widget's parent, since containers above that will
5310 * be set by the next loop.
5312 toplevel = gtk_widget_get_toplevel (focus_widget);
5313 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5315 widget = GTK_WINDOW (toplevel)->focus_widget;
5317 if (widget == focus_widget)
5319 /* We call _gtk_window_internal_set_focus() here so that the
5320 * toplevel window can request the focus if necessary.
5321 * This is needed when the toplevel is a GtkPlug
5323 if (!gtk_widget_has_focus (widget))
5324 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5331 while (widget->parent && widget->parent != focus_widget->parent)
5333 widget = widget->parent;
5334 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5338 else if (toplevel != focus_widget)
5340 /* gtk_widget_grab_focus() operates on a tree without window...
5341 * actually, this is very questionable behaviour.
5344 gtk_container_foreach (GTK_CONTAINER (toplevel),
5345 reset_focus_recurse,
5349 /* now propagate the new focus up the widget tree and finally
5350 * set it on the window
5352 widget = focus_widget;
5353 while (widget->parent)
5355 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5356 widget = widget->parent;
5358 if (GTK_IS_WINDOW (widget))
5359 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5364 gtk_widget_real_query_tooltip (GtkWidget *widget,
5367 gboolean keyboard_tip,
5368 GtkTooltip *tooltip)
5370 gchar *tooltip_markup;
5371 gboolean has_tooltip;
5373 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5374 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5376 if (has_tooltip && tooltip_markup)
5378 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5386 gtk_widget_real_show_help (GtkWidget *widget,
5387 GtkWidgetHelpType help_type)
5389 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5391 _gtk_tooltip_toggle_keyboard_mode (widget);
5400 gtk_widget_real_focus (GtkWidget *widget,
5401 GtkDirectionType direction)
5403 if (!gtk_widget_get_can_focus (widget))
5406 if (!gtk_widget_is_focus (widget))
5408 gtk_widget_grab_focus (widget);
5416 gtk_widget_real_move_focus (GtkWidget *widget,
5417 GtkDirectionType direction)
5419 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5421 if (GTK_IS_WINDOW (toplevel) &&
5422 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5424 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5430 gtk_widget_real_keynav_failed (GtkWidget *widget,
5431 GtkDirectionType direction)
5433 gboolean cursor_only;
5437 case GTK_DIR_TAB_FORWARD:
5438 case GTK_DIR_TAB_BACKWARD:
5445 g_object_get (gtk_widget_get_settings (widget),
5446 "gtk-keynav-cursor-only", &cursor_only,
5453 gtk_widget_error_bell (widget);
5459 * gtk_widget_set_can_focus:
5460 * @widget: a #GtkWidget
5461 * @can_focus: whether or not @widget can own the input focus.
5463 * Specifies whether @widget can own the input focus. See
5464 * gtk_widget_grab_focus() for actually setting the input focus on a
5470 gtk_widget_set_can_focus (GtkWidget *widget,
5473 g_return_if_fail (GTK_IS_WIDGET (widget));
5475 if (can_focus != gtk_widget_get_can_focus (widget))
5478 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5480 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5482 gtk_widget_queue_resize (widget);
5483 g_object_notify (G_OBJECT (widget), "can-focus");
5488 * gtk_widget_get_can_focus:
5489 * @widget: a #GtkWidget
5491 * Determines whether @widget can own the input focus. See
5492 * gtk_widget_set_can_focus().
5494 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5499 gtk_widget_get_can_focus (GtkWidget *widget)
5501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5503 return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5507 * gtk_widget_has_focus:
5508 * @widget: a #GtkWidget
5510 * Determines if the widget has the global input focus. See
5511 * gtk_widget_is_focus() for the difference between having the global
5512 * input focus, and only having the focus within a toplevel.
5514 * Return value: %TRUE if the widget has the global input focus.
5519 gtk_widget_has_focus (GtkWidget *widget)
5521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5523 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5527 * gtk_widget_is_focus:
5528 * @widget: a #GtkWidget
5530 * Determines if the widget is the focus widget within its
5531 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5532 * necessarily set; %HAS_FOCUS will only be set if the
5533 * toplevel widget additionally has the global input focus.)
5535 * Return value: %TRUE if the widget is the focus widget.
5538 gtk_widget_is_focus (GtkWidget *widget)
5540 GtkWidget *toplevel;
5542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5544 toplevel = gtk_widget_get_toplevel (widget);
5546 if (GTK_IS_WINDOW (toplevel))
5547 return widget == GTK_WINDOW (toplevel)->focus_widget;
5553 * gtk_widget_set_can_default:
5554 * @widget: a #GtkWidget
5555 * @can_default: whether or not @widget can be a default widget.
5557 * Specifies whether @widget can be a default widget. See
5558 * gtk_widget_grab_default() for details about the meaning of
5564 gtk_widget_set_can_default (GtkWidget *widget,
5565 gboolean can_default)
5567 g_return_if_fail (GTK_IS_WIDGET (widget));
5569 if (can_default != gtk_widget_get_can_default (widget))
5572 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5574 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5576 gtk_widget_queue_resize (widget);
5577 g_object_notify (G_OBJECT (widget), "can-default");
5582 * gtk_widget_get_can_default:
5583 * @widget: a #GtkWidget
5585 * Determines whether @widget can be a default widget. See
5586 * gtk_widget_set_can_default().
5588 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5593 gtk_widget_get_can_default (GtkWidget *widget)
5595 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5597 return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5601 * gtk_widget_has_default:
5602 * @widget: a #GtkWidget
5604 * Determines whether @widget is the current default widget within its
5605 * toplevel. See gtk_widget_set_can_default().
5607 * Return value: %TRUE if @widget is the current default widget within
5608 * its toplevel, %FALSE otherwise
5613 gtk_widget_has_default (GtkWidget *widget)
5615 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5617 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5621 * gtk_widget_grab_default:
5622 * @widget: a #GtkWidget
5624 * Causes @widget to become the default widget. @widget must have the
5625 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5626 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5627 * %TRUE)</literal>. The default widget is activated when
5628 * the user presses Enter in a window. Default widgets must be
5629 * activatable, that is, gtk_widget_activate() should affect them.
5632 gtk_widget_grab_default (GtkWidget *widget)
5636 g_return_if_fail (GTK_IS_WIDGET (widget));
5637 g_return_if_fail (gtk_widget_get_can_default (widget));
5639 window = gtk_widget_get_toplevel (widget);
5641 if (window && gtk_widget_is_toplevel (window))
5642 gtk_window_set_default (GTK_WINDOW (window), widget);
5644 g_warning (G_STRLOC ": widget not within a GtkWindow");
5648 * gtk_widget_set_receives_default:
5649 * @widget: a #GtkWidget
5650 * @receives_default: whether or not @widget can be a default widget.
5652 * Specifies whether @widget will be treated as the default widget
5653 * within its toplevel when it has the focus, even if another widget
5656 * See gtk_widget_grab_default() for details about the meaning of
5662 gtk_widget_set_receives_default (GtkWidget *widget,
5663 gboolean receives_default)
5665 g_return_if_fail (GTK_IS_WIDGET (widget));
5667 if (receives_default != gtk_widget_get_receives_default (widget))
5669 if (receives_default)
5670 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5672 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5674 g_object_notify (G_OBJECT (widget), "receives-default");
5679 * gtk_widget_get_receives_default:
5680 * @widget: a #GtkWidget
5682 * Determines whether @widget is alyways treated as default widget
5683 * withing its toplevel when it has the focus, even if another widget
5686 * See gtk_widget_set_receives_default().
5688 * Return value: %TRUE if @widget acts as default widget when focussed,
5694 gtk_widget_get_receives_default (GtkWidget *widget)
5696 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5698 return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5702 * gtk_widget_has_grab:
5703 * @widget: a #GtkWidget
5705 * Determines whether the widget is currently grabbing events, so it
5706 * is the only widget receiving input events (keyboard and mouse).
5708 * See also gtk_grab_add().
5710 * Return value: %TRUE if the widget is in the grab_widgets stack
5715 gtk_widget_has_grab (GtkWidget *widget)
5717 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5719 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5723 * gtk_widget_set_name:
5724 * @widget: a #GtkWidget
5725 * @name: name for the widget
5727 * Widgets can be named, which allows you to refer to them from a
5728 * gtkrc file. You can apply a style to widgets with a particular name
5729 * in the gtkrc file. See the documentation for gtkrc files (on the
5730 * same page as the docs for #GtkRcStyle).
5732 * Note that widget names are separated by periods in paths (see
5733 * gtk_widget_path()), so names with embedded periods may cause confusion.
5736 gtk_widget_set_name (GtkWidget *widget,
5741 g_return_if_fail (GTK_IS_WIDGET (widget));
5743 new_name = g_strdup (name);
5744 g_free (widget->name);
5745 widget->name = new_name;
5747 if (gtk_widget_has_rc_style (widget))
5748 gtk_widget_reset_rc_style (widget);
5750 g_object_notify (G_OBJECT (widget), "name");
5754 * gtk_widget_get_name:
5755 * @widget: a #GtkWidget
5757 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5758 * significance of widget names.
5760 * Return value: name of the widget. This string is owned by GTK+ and
5761 * should not be modified or freed
5763 G_CONST_RETURN gchar*
5764 gtk_widget_get_name (GtkWidget *widget)
5766 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5769 return widget->name;
5770 return G_OBJECT_TYPE_NAME (widget);
5774 * gtk_widget_set_state:
5775 * @widget: a #GtkWidget
5776 * @state: new state for @widget
5778 * This function is for use in widget implementations. Sets the state
5779 * of a widget (insensitive, prelighted, etc.) Usually you should set
5780 * the state using wrapper functions such as gtk_widget_set_sensitive().
5783 gtk_widget_set_state (GtkWidget *widget,
5786 g_return_if_fail (GTK_IS_WIDGET (widget));
5788 if (state == GTK_WIDGET_STATE (widget))
5791 if (state == GTK_STATE_INSENSITIVE)
5792 gtk_widget_set_sensitive (widget, FALSE);
5798 data.state_restoration = FALSE;
5799 data.use_forall = FALSE;
5801 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5803 data.parent_sensitive = TRUE;
5805 gtk_widget_propagate_state (widget, &data);
5807 if (gtk_widget_is_drawable (widget))
5808 gtk_widget_queue_draw (widget);
5813 * gtk_widget_get_state:
5814 * @widget: a #GtkWidget
5816 * Returns the widget's state. See gtk_widget_set_state().
5818 * Returns: the state of @widget.
5823 gtk_widget_get_state (GtkWidget *widget)
5825 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5827 return widget->state;
5831 * gtk_widget_set_visible:
5832 * @widget: a #GtkWidget
5833 * @visible: whether the widget should be shown or not
5835 * Sets the visibility state of @widget. Note that setting this to
5836 * %TRUE doesn't mean the widget is actually viewable, see
5837 * gtk_widget_get_visible().
5839 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5840 * but is nicer to use when the visibility of the widget depends on
5846 gtk_widget_set_visible (GtkWidget *widget,
5849 g_return_if_fail (GTK_IS_WIDGET (widget));
5851 if (visible != gtk_widget_get_visible (widget))
5854 gtk_widget_show (widget);
5856 gtk_widget_hide (widget);
5861 * gtk_widget_get_visible:
5862 * @widget: a #GtkWidget
5864 * Determines whether the widget is visible. Note that this doesn't
5865 * take into account whether the widget's parent is also visible
5866 * or the widget is obscured in any way.
5868 * See gtk_widget_set_visible().
5870 * Return value: %TRUE if the widget is visible
5875 gtk_widget_get_visible (GtkWidget *widget)
5877 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5879 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5883 * gtk_widget_set_has_window:
5884 * @widget: a #GtkWidget
5885 * @has_window: whether or not @widget has a window.
5887 * Specifies whether @widget has a #GdkWindow of its own. Note that
5888 * all realized widgets have a non-%NULL "window" pointer
5889 * (gtk_widget_get_window() never returns a %NULL window when a widget
5890 * is realized), but for many of them it's actually the #GdkWindow of
5891 * one of its parent widgets. Widgets that create a %window for
5892 * themselves in GtkWidget::realize() however must announce this by
5893 * calling this function with @has_window = %TRUE.
5895 * This function should only be called by widget implementations,
5896 * and they should call it in their init() function.
5901 gtk_widget_set_has_window (GtkWidget *widget,
5902 gboolean has_window)
5904 g_return_if_fail (GTK_IS_WIDGET (widget));
5907 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5909 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5913 * gtk_widget_get_has_window:
5914 * @widget: a #GtkWidget
5916 * Determines whether @widget has a #GdkWindow of its own. See
5917 * gtk_widget_set_has_window().
5919 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5924 gtk_widget_get_has_window (GtkWidget *widget)
5926 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5928 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5932 * gtk_widget_is_toplevel:
5933 * @widget: a #GtkWidget
5935 * Determines whether @widget is a toplevel widget. Currently only
5936 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5937 * widgets have no parent widget.
5939 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5944 gtk_widget_is_toplevel (GtkWidget *widget)
5946 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5948 return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5952 * gtk_widget_is_drawable:
5953 * @widget: a #GtkWidget
5955 * Determines whether @widget can be drawn to. A widget can be drawn
5956 * to if it is mapped and visible.
5958 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5963 gtk_widget_is_drawable (GtkWidget *widget)
5965 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5967 return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 &&
5968 (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0);
5972 * gtk_widget_get_realized:
5973 * @widget: a #GtkWidget
5975 * Determines whether @widget is realized.
5977 * Return value: %TRUE if @widget is realized, %FALSE otherwise
5982 gtk_widget_get_realized (GtkWidget *widget)
5984 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5986 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
5990 * gtk_widget_set_realized:
5991 * @widget: a #GtkWidget
5992 * @realized: %TRUE to mark the widget as realized
5994 * Marks the widget as being realized.
5996 * This function should only ever be called in a derived widget's
5997 * "realize" or "unrealize" implementation.
6002 gtk_widget_set_realized (GtkWidget *widget,
6005 g_return_if_fail (GTK_IS_WIDGET (widget));
6008 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6010 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6014 * gtk_widget_get_mapped:
6015 * @widget: a #GtkWidget
6017 * Whether the widget is mapped.
6019 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6024 gtk_widget_get_mapped (GtkWidget *widget)
6026 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6028 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6032 * gtk_widget_set_mapped:
6033 * @widget: a #GtkWidget
6034 * @mapped: %TRUE to mark the widget as mapped
6036 * Marks the widget as being realized.
6038 * This function should only ever be called in a derived widget's
6039 * "map" or "unmap" implementation.
6044 gtk_widget_set_mapped (GtkWidget *widget,
6047 g_return_if_fail (GTK_IS_WIDGET (widget));
6050 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6052 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6056 * gtk_widget_set_app_paintable:
6057 * @widget: a #GtkWidget
6058 * @app_paintable: %TRUE if the application will paint on the widget
6060 * Sets whether the application intends to draw on the widget in
6061 * an #GtkWidget::expose-event handler.
6063 * This is a hint to the widget and does not affect the behavior of
6064 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6065 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6066 * the effect is to suppress default themed drawing of the widget's
6067 * background. (Children of the widget will still be drawn.) The application
6068 * is then entirely responsible for drawing the widget background.
6070 * Note that the background is still drawn when the widget is mapped.
6071 * If this is not suitable (e.g. because you want to make a transparent
6072 * window using an RGBA visual), you can work around this by doing:
6074 * gtk_widget_realize (window);
6075 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6076 * gtk_widget_show (window);
6080 gtk_widget_set_app_paintable (GtkWidget *widget,
6081 gboolean app_paintable)
6083 g_return_if_fail (GTK_IS_WIDGET (widget));
6085 app_paintable = (app_paintable != FALSE);
6087 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6090 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
6092 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
6094 if (gtk_widget_is_drawable (widget))
6095 gtk_widget_queue_draw (widget);
6097 g_object_notify (G_OBJECT (widget), "app-paintable");
6102 * gtk_widget_get_app_paintable:
6103 * @widget: a #GtkWidget
6105 * Determines whether the application intends to draw on the widget in
6106 * an #GtkWidget::expose-event handler.
6108 * See gtk_widget_set_app_paintable()
6110 * Return value: %TRUE if the widget is app paintable
6115 gtk_widget_get_app_paintable (GtkWidget *widget)
6117 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6119 return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6123 * gtk_widget_set_double_buffered:
6124 * @widget: a #GtkWidget
6125 * @double_buffered: %TRUE to double-buffer a widget
6127 * Widgets are double buffered by default; you can use this function
6128 * to turn off the buffering. "Double buffered" simply means that
6129 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6130 * automatically around expose events sent to the
6131 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6132 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6133 * buffer to the screen. The result is that users see the window
6134 * update in one smooth step, and don't see individual graphics
6135 * primitives being rendered.
6137 * In very simple terms, double buffered widgets don't flicker,
6138 * so you would only use this function to turn off double buffering
6139 * if you had special needs and really knew what you were doing.
6141 * Note: if you turn off double-buffering, you have to handle
6142 * expose events, since even the clearing to the background color or
6143 * pixmap will not happen automatically (as it is done in
6144 * gdk_window_begin_paint()).
6147 gtk_widget_set_double_buffered (GtkWidget *widget,
6148 gboolean double_buffered)
6150 g_return_if_fail (GTK_IS_WIDGET (widget));
6152 double_buffered = (double_buffered != FALSE);
6154 if (double_buffered != gtk_widget_get_double_buffered (widget))
6156 if (double_buffered)
6157 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6159 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6161 g_object_notify (G_OBJECT (widget), "double-buffered");
6166 * gtk_widget_get_double_buffered:
6167 * @widget: a #GtkWidget
6169 * Determines whether the widget is double buffered.
6171 * See gtk_widget_set_double_buffered()
6173 * Return value: %TRUE if the widget is double buffered
6178 gtk_widget_get_double_buffered (GtkWidget *widget)
6180 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6182 return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6186 * gtk_widget_set_redraw_on_allocate:
6187 * @widget: a #GtkWidget
6188 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6189 * when it is allocated to a new size. Otherwise, only the
6190 * new portion of the widget will be redrawn.
6192 * Sets whether the entire widget is queued for drawing when its size
6193 * allocation changes. By default, this setting is %TRUE and
6194 * the entire widget is redrawn on every size change. If your widget
6195 * leaves the upper left unchanged when made bigger, turning this
6196 * setting off will improve performance.
6198 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6199 * off all allocation on resizing: the widget will not even redraw if
6200 * its position changes; this is to allow containers that don't draw
6201 * anything to avoid excess invalidations. If you set this flag on a
6202 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6203 * you are responsible for invalidating both the old and new allocation
6204 * of the widget when the widget is moved and responsible for invalidating
6205 * regions newly when the widget increases size.
6208 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6209 gboolean redraw_on_allocate)
6211 g_return_if_fail (GTK_IS_WIDGET (widget));
6213 if (redraw_on_allocate)
6214 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6216 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6220 * gtk_widget_set_sensitive:
6221 * @widget: a #GtkWidget
6222 * @sensitive: %TRUE to make the widget sensitive
6224 * Sets the sensitivity of a widget. A widget is sensitive if the user
6225 * can interact with it. Insensitive widgets are "grayed out" and the
6226 * user can't interact with them. Insensitive widgets are known as
6227 * "inactive", "disabled", or "ghosted" in some other toolkits.
6230 gtk_widget_set_sensitive (GtkWidget *widget,
6235 g_return_if_fail (GTK_IS_WIDGET (widget));
6237 sensitive = (sensitive != FALSE);
6239 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6244 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6245 data.state = widget->saved_state;
6249 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6250 data.state = GTK_WIDGET_STATE (widget);
6252 data.state_restoration = TRUE;
6253 data.use_forall = TRUE;
6256 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6258 data.parent_sensitive = TRUE;
6260 gtk_widget_propagate_state (widget, &data);
6261 if (gtk_widget_is_drawable (widget))
6262 gtk_widget_queue_draw (widget);
6264 g_object_notify (G_OBJECT (widget), "sensitive");
6268 * gtk_widget_get_sensitive:
6269 * @widget: a #GtkWidget
6271 * Returns the widget's sensitivity (in the sense of returning
6272 * the value that has been set using gtk_widget_set_sensitive()).
6274 * The effective sensitivity of a widget is however determined by both its
6275 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6277 * Returns: %TRUE if the widget is sensitive
6282 gtk_widget_get_sensitive (GtkWidget *widget)
6284 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6286 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6290 * gtk_widget_is_sensitive:
6291 * @widget: a #GtkWidget
6293 * Returns the widget's effective sensitivity, which means
6294 * it is sensitive itself and also its parent widget is sensntive
6296 * Returns: %TRUE if the widget is effectively sensitive
6301 gtk_widget_is_sensitive (GtkWidget *widget)
6303 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6305 return (gtk_widget_get_sensitive (widget) &&
6306 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6310 * gtk_widget_set_parent:
6311 * @widget: a #GtkWidget
6312 * @parent: parent container
6314 * This function is useful only when implementing subclasses of
6316 * Sets the container as the parent of @widget, and takes care of
6317 * some details such as updating the state and style of the child
6318 * to reflect its new location. The opposite function is
6319 * gtk_widget_unparent().
6322 gtk_widget_set_parent (GtkWidget *widget,
6327 g_return_if_fail (GTK_IS_WIDGET (widget));
6328 g_return_if_fail (GTK_IS_WIDGET (parent));
6329 g_return_if_fail (widget != parent);
6330 if (widget->parent != NULL)
6332 g_warning ("Can't set a parent on widget which has a parent\n");
6335 if (gtk_widget_is_toplevel (widget))
6337 g_warning ("Can't set a parent on a toplevel widget\n");
6341 /* keep this function in sync with gtk_menu_attach_to_widget()
6344 g_object_ref_sink (widget);
6345 widget->parent = parent;
6347 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
6348 data.state = GTK_WIDGET_STATE (parent);
6350 data.state = GTK_WIDGET_STATE (widget);
6351 data.state_restoration = FALSE;
6352 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6353 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6355 gtk_widget_propagate_state (widget, &data);
6357 gtk_widget_reset_rc_styles (widget);
6359 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6360 if (GTK_WIDGET_ANCHORED (widget->parent))
6361 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6362 g_object_notify (G_OBJECT (widget), "parent");
6364 /* Enforce realized/mapped invariants
6366 if (gtk_widget_get_realized (widget->parent))
6367 gtk_widget_realize (widget);
6369 if (gtk_widget_get_visible (widget->parent) &&
6370 gtk_widget_get_visible (widget))
6372 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6373 gtk_widget_get_mapped (widget->parent))
6374 gtk_widget_map (widget);
6376 gtk_widget_queue_resize (widget);
6381 * gtk_widget_get_parent:
6382 * @widget: a #GtkWidget
6384 * Returns the parent container of @widget.
6386 * Return value: (transfer none): the parent container of @widget, or %NULL
6389 gtk_widget_get_parent (GtkWidget *widget)
6391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6393 return widget->parent;
6396 /*****************************************
6398 * see docs/styles.txt
6399 *****************************************/
6402 * gtk_widget_style_attach:
6403 * @widget: a #GtkWidget
6405 * This function attaches the widget's #GtkStyle to the widget's
6406 * #GdkWindow. It is a replacement for
6409 * widget->style = gtk_style_attach (widget->style, widget->window);
6412 * and should only ever be called in a derived widget's "realize"
6413 * implementation which does not chain up to its parent class'
6414 * "realize" implementation, because one of the parent classes
6415 * (finally #GtkWidget) would attach the style itself.
6420 gtk_widget_style_attach (GtkWidget *widget)
6422 g_return_if_fail (GTK_IS_WIDGET (widget));
6423 g_return_if_fail (gtk_widget_get_realized (widget));
6425 widget->style = gtk_style_attach (widget->style, widget->window);
6429 * gtk_widget_has_rc_style:
6430 * @widget: a #GtkWidget
6432 * Determines if the widget style has been looked up through the rc mechanism.
6434 * Returns: %TRUE if the widget has been looked up through the rc
6435 * mechanism, %FALSE otherwise.
6440 gtk_widget_has_rc_style (GtkWidget *widget)
6442 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6444 return (GTK_WIDGET_FLAGS (widget) & GTK_RC_STYLE) != 0;
6448 * gtk_widget_set_style:
6449 * @widget: a #GtkWidget
6450 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6451 * gtk_widget_set_style() and go back to the default style
6453 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6454 * want to use this function; it interacts badly with themes, because
6455 * themes work by replacing the #GtkStyle. Instead, use
6456 * gtk_widget_modify_style().
6459 gtk_widget_set_style (GtkWidget *widget,
6462 g_return_if_fail (GTK_IS_WIDGET (widget));
6466 gboolean initial_emission;
6468 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6470 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
6471 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6473 gtk_widget_set_style_internal (widget, style, initial_emission);
6477 if (GTK_WIDGET_USER_STYLE (widget))
6478 gtk_widget_reset_rc_style (widget);
6483 * gtk_widget_ensure_style:
6484 * @widget: a #GtkWidget
6486 * Ensures that @widget has a style (@widget->style). Not a very useful
6487 * function; most of the time, if you want the style, the widget is
6488 * realized, and realized widgets are guaranteed to have a style
6492 gtk_widget_ensure_style (GtkWidget *widget)
6494 g_return_if_fail (GTK_IS_WIDGET (widget));
6496 if (!GTK_WIDGET_USER_STYLE (widget) &&
6497 !gtk_widget_has_rc_style (widget))
6498 gtk_widget_reset_rc_style (widget);
6501 /* Look up the RC style for this widget, unsetting any user style that
6502 * may be in effect currently
6505 gtk_widget_reset_rc_style (GtkWidget *widget)
6507 GtkStyle *new_style = NULL;
6508 gboolean initial_emission;
6510 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6512 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6513 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
6515 if (gtk_widget_has_screen (widget))
6516 new_style = gtk_rc_get_style (widget);
6518 new_style = gtk_widget_get_default_style ();
6520 if (initial_emission || new_style != widget->style)
6521 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6525 * gtk_widget_get_style:
6526 * @widget: a #GtkWidget
6528 * Simply an accessor function that returns @widget->style.
6530 * Return value: (transfer none): the widget's #GtkStyle
6533 gtk_widget_get_style (GtkWidget *widget)
6535 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6537 return widget->style;
6541 * gtk_widget_modify_style:
6542 * @widget: a #GtkWidget
6543 * @style: the #GtkRcStyle holding the style modifications
6545 * Modifies style values on the widget. Modifications made using this
6546 * technique take precedence over style values set via an RC file,
6547 * however, they will be overriden if a style is explicitely set on
6548 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6549 * is designed so each field can either be set or unset, so it is
6550 * possible, using this function, to modify some style values and
6551 * leave the others unchanged.
6553 * Note that modifications made with this function are not cumulative
6554 * with previous calls to gtk_widget_modify_style() or with such
6555 * functions as gtk_widget_modify_fg(). If you wish to retain
6556 * previous values, you must first call gtk_widget_get_modifier_style(),
6557 * make your modifications to the returned style, then call
6558 * gtk_widget_modify_style() with that style. On the other hand,
6559 * if you first call gtk_widget_modify_style(), subsequent calls
6560 * to such functions gtk_widget_modify_fg() will have a cumulative
6561 * effect with the initial modifications.
6564 gtk_widget_modify_style (GtkWidget *widget,
6567 g_return_if_fail (GTK_IS_WIDGET (widget));
6568 g_return_if_fail (GTK_IS_RC_STYLE (style));
6570 g_object_set_qdata_full (G_OBJECT (widget),
6572 gtk_rc_style_copy (style),
6573 (GDestroyNotify) g_object_unref);
6575 /* note that "style" may be invalid here if it was the old
6576 * modifier style and the only reference was our own.
6579 if (gtk_widget_has_rc_style (widget))
6580 gtk_widget_reset_rc_style (widget);
6584 * gtk_widget_get_modifier_style:
6585 * @widget: a #GtkWidget
6587 * Returns the current modifier style for the widget. (As set by
6588 * gtk_widget_modify_style().) If no style has previously set, a new
6589 * #GtkRcStyle will be created with all values unset, and set as the
6590 * modifier style for the widget. If you make changes to this rc
6591 * style, you must call gtk_widget_modify_style(), passing in the
6592 * returned rc style, to make sure that your changes take effect.
6594 * Caution: passing the style back to gtk_widget_modify_style() will
6595 * normally end up destroying it, because gtk_widget_modify_style() copies
6596 * the passed-in style and sets the copy as the new modifier style,
6597 * thus dropping any reference to the old modifier style. Add a reference
6598 * to the modifier style if you want to keep it alive.
6600 * Return value: (transfer none): the modifier style for the widget. This rc style is
6601 * owned by the widget. If you want to keep a pointer to value this
6602 * around, you must add a refcount using g_object_ref().
6605 gtk_widget_get_modifier_style (GtkWidget *widget)
6607 GtkRcStyle *rc_style;
6609 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6611 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6615 rc_style = gtk_rc_style_new ();
6616 g_object_set_qdata_full (G_OBJECT (widget),
6619 (GDestroyNotify) g_object_unref);
6626 gtk_widget_modify_color_component (GtkWidget *widget,
6627 GtkRcFlags component,
6629 const GdkColor *color)
6631 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6638 rc_style->fg[state] = *color;
6641 rc_style->bg[state] = *color;
6644 rc_style->text[state] = *color;
6647 rc_style->base[state] = *color;
6650 g_assert_not_reached();
6653 rc_style->color_flags[state] |= component;
6656 rc_style->color_flags[state] &= ~component;
6658 gtk_widget_modify_style (widget, rc_style);
6662 * gtk_widget_modify_fg:
6663 * @widget: a #GtkWidget
6664 * @state: the state for which to set the foreground color
6665 * @color: (allow-none): the color to assign (does not need to be allocated),
6666 * or %NULL to undo the effect of previous calls to
6667 * of gtk_widget_modify_fg().
6669 * Sets the foreground color for a widget in a particular state.
6670 * All other style values are left untouched. See also
6671 * gtk_widget_modify_style().
6674 gtk_widget_modify_fg (GtkWidget *widget,
6676 const GdkColor *color)
6678 g_return_if_fail (GTK_IS_WIDGET (widget));
6679 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6681 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6685 * gtk_widget_modify_bg:
6686 * @widget: a #GtkWidget
6687 * @state: the state for which to set the background color
6688 * @color: (allow-none): the color to assign (does not need to be allocated),
6689 * or %NULL to undo the effect of previous calls to
6690 * of gtk_widget_modify_bg().
6692 * Sets the background color for a widget in a particular state.
6693 * All other style values are left untouched. See also
6694 * gtk_widget_modify_style().
6696 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6697 * draw on their parent container's window and thus may not draw any
6698 * background themselves. This is the case for e.g. #GtkLabel. To modify
6699 * the background of such widgets, you have to set the background color
6700 * on their parent; if you want to set the background of a rectangular
6701 * area around a label, try placing the label in a #GtkEventBox widget
6702 * and setting the background color on that.
6705 gtk_widget_modify_bg (GtkWidget *widget,
6707 const GdkColor *color)
6709 g_return_if_fail (GTK_IS_WIDGET (widget));
6710 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6712 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6716 * gtk_widget_modify_text:
6717 * @widget: a #GtkWidget
6718 * @state: the state for which to set the text color
6719 * @color: (allow-none): the color to assign (does not need to be allocated),
6720 * or %NULL to undo the effect of previous calls to
6721 * of gtk_widget_modify_text().
6723 * Sets the text color for a widget in a particular state. All other
6724 * style values are left untouched. The text color is the foreground
6725 * color used along with the base color (see gtk_widget_modify_base())
6726 * for widgets such as #GtkEntry and #GtkTextView. See also
6727 * gtk_widget_modify_style().
6730 gtk_widget_modify_text (GtkWidget *widget,
6732 const GdkColor *color)
6734 g_return_if_fail (GTK_IS_WIDGET (widget));
6735 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6737 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6741 * gtk_widget_modify_base:
6742 * @widget: a #GtkWidget
6743 * @state: the state for which to set the base color
6744 * @color: (allow-none): the color to assign (does not need to be allocated),
6745 * or %NULL to undo the effect of previous calls to
6746 * of gtk_widget_modify_base().
6748 * Sets the base color for a widget in a particular state.
6749 * All other style values are left untouched. The base color
6750 * is the background color used along with the text color
6751 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6752 * and #GtkTextView. See also gtk_widget_modify_style().
6754 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6755 * draw on their parent container's window and thus may not draw any
6756 * background themselves. This is the case for e.g. #GtkLabel. To modify
6757 * the background of such widgets, you have to set the base color on their
6758 * parent; if you want to set the background of a rectangular area around
6759 * a label, try placing the label in a #GtkEventBox widget and setting
6760 * the base color on that.
6763 gtk_widget_modify_base (GtkWidget *widget,
6765 const GdkColor *color)
6767 g_return_if_fail (GTK_IS_WIDGET (widget));
6768 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6770 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6774 modify_color_property (GtkWidget *widget,
6775 GtkRcStyle *rc_style,
6777 const GdkColor *color)
6779 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6780 GQuark property_name = g_quark_from_string (name);
6784 GtkRcProperty rc_property = {0};
6787 rc_property.type_name = type_name;
6788 rc_property.property_name = property_name;
6789 rc_property.origin = NULL;
6791 color_name = gdk_color_to_string (color);
6792 g_value_init (&rc_property.value, G_TYPE_STRING);
6793 g_value_take_string (&rc_property.value, color_name);
6795 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6797 g_value_unset (&rc_property.value);
6800 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6804 * gtk_widget_modify_cursor:
6805 * @widget: a #GtkWidget
6806 * @primary: the color to use for primary cursor (does not need to be
6807 * allocated), or %NULL to undo the effect of previous calls to
6808 * of gtk_widget_modify_cursor().
6809 * @secondary: the color to use for secondary cursor (does not need to be
6810 * allocated), or %NULL to undo the effect of previous calls to
6811 * of gtk_widget_modify_cursor().
6813 * Sets the cursor color to use in a widget, overriding the
6814 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6815 * style properties. All other style values are left untouched.
6816 * See also gtk_widget_modify_style().
6821 gtk_widget_modify_cursor (GtkWidget *widget,
6822 const GdkColor *primary,
6823 const GdkColor *secondary)
6825 GtkRcStyle *rc_style;
6827 g_return_if_fail (GTK_IS_WIDGET (widget));
6829 rc_style = gtk_widget_get_modifier_style (widget);
6831 modify_color_property (widget, rc_style, "cursor-color", primary);
6832 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6834 gtk_widget_modify_style (widget, rc_style);
6838 * gtk_widget_modify_font:
6839 * @widget: a #GtkWidget
6840 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6841 * the effect of previous calls to gtk_widget_modify_font().
6843 * Sets the font to use for a widget. All other style values are left
6844 * untouched. See also gtk_widget_modify_style().
6847 gtk_widget_modify_font (GtkWidget *widget,
6848 PangoFontDescription *font_desc)
6850 GtkRcStyle *rc_style;
6852 g_return_if_fail (GTK_IS_WIDGET (widget));
6854 rc_style = gtk_widget_get_modifier_style (widget);
6856 if (rc_style->font_desc)
6857 pango_font_description_free (rc_style->font_desc);
6860 rc_style->font_desc = pango_font_description_copy (font_desc);
6862 rc_style->font_desc = NULL;
6864 gtk_widget_modify_style (widget, rc_style);
6868 gtk_widget_real_direction_changed (GtkWidget *widget,
6869 GtkTextDirection previous_direction)
6871 gtk_widget_queue_resize (widget);
6875 gtk_widget_real_style_set (GtkWidget *widget,
6876 GtkStyle *previous_style)
6878 if (gtk_widget_get_realized (widget) &&
6879 gtk_widget_get_has_window (widget))
6880 gtk_style_set_background (widget->style, widget->window, widget->state);
6884 gtk_widget_set_style_internal (GtkWidget *widget,
6886 gboolean initial_emission)
6888 g_object_ref (widget);
6889 g_object_freeze_notify (G_OBJECT (widget));
6891 if (widget->style != style)
6893 GtkStyle *previous_style;
6895 if (gtk_widget_get_realized (widget))
6897 gtk_widget_reset_shapes (widget);
6898 gtk_style_detach (widget->style);
6901 previous_style = widget->style;
6902 widget->style = style;
6903 g_object_ref (widget->style);
6905 if (gtk_widget_get_realized (widget))
6906 widget->style = gtk_style_attach (widget->style, widget->window);
6908 gtk_widget_update_pango_context (widget);
6909 g_signal_emit (widget,
6910 widget_signals[STYLE_SET],
6912 initial_emission ? NULL : previous_style);
6913 g_object_unref (previous_style);
6915 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6916 gtk_widget_queue_resize (widget);
6918 else if (initial_emission)
6920 gtk_widget_update_pango_context (widget);
6921 g_signal_emit (widget,
6922 widget_signals[STYLE_SET],
6926 g_object_notify (G_OBJECT (widget), "style");
6927 g_object_thaw_notify (G_OBJECT (widget));
6928 g_object_unref (widget);
6932 GtkWidget *previous_toplevel;
6933 GdkScreen *previous_screen;
6934 GdkScreen *new_screen;
6935 } HierarchyChangedInfo;
6938 do_screen_change (GtkWidget *widget,
6939 GdkScreen *old_screen,
6940 GdkScreen *new_screen)
6942 if (old_screen != new_screen)
6946 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6948 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6951 _gtk_tooltip_hide (widget);
6952 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6957 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6958 gpointer client_data)
6960 HierarchyChangedInfo *info = client_data;
6961 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
6962 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6964 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6966 g_object_ref (widget);
6969 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6971 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6973 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6974 do_screen_change (widget, info->previous_screen, info->new_screen);
6976 if (GTK_IS_CONTAINER (widget))
6977 gtk_container_forall (GTK_CONTAINER (widget),
6978 gtk_widget_propagate_hierarchy_changed_recurse,
6981 g_object_unref (widget);
6986 * _gtk_widget_propagate_hierarchy_changed:
6987 * @widget: a #GtkWidget
6988 * @previous_toplevel: Previous toplevel
6990 * Propagates changes in the anchored state to a widget and all
6991 * children, unsetting or setting the %ANCHORED flag, and
6992 * emitting #GtkWidget::hierarchy-changed.
6995 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6996 GtkWidget *previous_toplevel)
6998 HierarchyChangedInfo info;
7000 info.previous_toplevel = previous_toplevel;
7001 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7003 if (gtk_widget_is_toplevel (widget) ||
7004 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7005 info.new_screen = gtk_widget_get_screen (widget);
7007 info.new_screen = NULL;
7009 if (info.previous_screen)
7010 g_object_ref (info.previous_screen);
7011 if (previous_toplevel)
7012 g_object_ref (previous_toplevel);
7014 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7016 if (previous_toplevel)
7017 g_object_unref (previous_toplevel);
7018 if (info.previous_screen)
7019 g_object_unref (info.previous_screen);
7023 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7024 gpointer client_data)
7026 HierarchyChangedInfo *info = client_data;
7028 g_object_ref (widget);
7030 do_screen_change (widget, info->previous_screen, info->new_screen);
7032 if (GTK_IS_CONTAINER (widget))
7033 gtk_container_forall (GTK_CONTAINER (widget),
7034 gtk_widget_propagate_screen_changed_recurse,
7037 g_object_unref (widget);
7041 * gtk_widget_is_composited:
7042 * @widget: a #GtkWidget
7044 * Whether @widget can rely on having its alpha channel
7045 * drawn correctly. On X11 this function returns whether a
7046 * compositing manager is running for @widget's screen.
7048 * Please note that the semantics of this call will change
7049 * in the future if used on a widget that has a composited
7050 * window in its hierarchy (as set by gdk_window_set_composited()).
7052 * Return value: %TRUE if the widget can rely on its alpha
7053 * channel being drawn correctly.
7058 gtk_widget_is_composited (GtkWidget *widget)
7062 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7064 screen = gtk_widget_get_screen (widget);
7066 return gdk_screen_is_composited (screen);
7070 propagate_composited_changed (GtkWidget *widget,
7073 if (GTK_IS_CONTAINER (widget))
7075 gtk_container_forall (GTK_CONTAINER (widget),
7076 propagate_composited_changed,
7080 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7084 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7086 propagate_composited_changed (widget, NULL);
7090 * _gtk_widget_propagate_screen_changed:
7091 * @widget: a #GtkWidget
7092 * @previous_screen: Previous screen
7094 * Propagates changes in the screen for a widget to all
7095 * children, emitting #GtkWidget::screen-changed.
7098 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7099 GdkScreen *previous_screen)
7101 HierarchyChangedInfo info;
7103 info.previous_screen = previous_screen;
7104 info.new_screen = gtk_widget_get_screen (widget);
7106 if (previous_screen)
7107 g_object_ref (previous_screen);
7109 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7111 if (previous_screen)
7112 g_object_unref (previous_screen);
7116 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7118 if (gtk_widget_has_rc_style (widget))
7119 gtk_widget_reset_rc_style (widget);
7121 if (GTK_IS_CONTAINER (widget))
7122 gtk_container_forall (GTK_CONTAINER (widget),
7123 reset_rc_styles_recurse,
7129 * gtk_widget_reset_rc_styles:
7130 * @widget: a #GtkWidget.
7132 * Reset the styles of @widget and all descendents, so when
7133 * they are looked up again, they get the correct values
7134 * for the currently loaded RC file settings.
7136 * This function is not useful for applications.
7139 gtk_widget_reset_rc_styles (GtkWidget *widget)
7141 g_return_if_fail (GTK_IS_WIDGET (widget));
7143 reset_rc_styles_recurse (widget, NULL);
7147 * gtk_widget_get_default_style:
7149 * Returns the default style used by all widgets initially.
7151 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7152 * by GTK+ and should not be modified or freed.
7155 gtk_widget_get_default_style (void)
7157 if (!gtk_default_style)
7159 gtk_default_style = gtk_style_new ();
7160 g_object_ref (gtk_default_style);
7163 return gtk_default_style;
7166 static PangoContext *
7167 gtk_widget_peek_pango_context (GtkWidget *widget)
7169 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7173 * gtk_widget_get_pango_context:
7174 * @widget: a #GtkWidget
7176 * Gets a #PangoContext with the appropriate font map, font description,
7177 * and base direction for this widget. Unlike the context returned
7178 * by gtk_widget_create_pango_context(), this context is owned by
7179 * the widget (it can be used until the screen for the widget changes
7180 * or the widget is removed from its toplevel), and will be updated to
7181 * match any changes to the widget's attributes.
7183 * If you create and keep a #PangoLayout using this context, you must
7184 * deal with changes to the context by calling pango_layout_context_changed()
7185 * on the layout in response to the #GtkWidget::style-set and
7186 * #GtkWidget::direction-changed signals for the widget.
7188 * Return value: (transfer none): the #PangoContext for the widget.
7191 gtk_widget_get_pango_context (GtkWidget *widget)
7193 PangoContext *context;
7195 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7197 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7200 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7201 g_object_set_qdata_full (G_OBJECT (widget),
7202 quark_pango_context,
7211 update_pango_context (GtkWidget *widget,
7212 PangoContext *context)
7214 pango_context_set_font_description (context, widget->style->font_desc);
7215 pango_context_set_base_dir (context,
7216 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7217 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7221 gtk_widget_update_pango_context (GtkWidget *widget)
7223 PangoContext *context = gtk_widget_peek_pango_context (widget);
7229 update_pango_context (widget, context);
7231 screen = gtk_widget_get_screen_unchecked (widget);
7234 pango_cairo_context_set_resolution (context,
7235 gdk_screen_get_resolution (screen));
7236 pango_cairo_context_set_font_options (context,
7237 gdk_screen_get_font_options (screen));
7243 * gtk_widget_create_pango_context:
7244 * @widget: a #GtkWidget
7246 * Creates a new #PangoContext with the appropriate font map,
7247 * font description, and base direction for drawing text for
7248 * this widget. See also gtk_widget_get_pango_context().
7250 * Return value: the new #PangoContext
7253 gtk_widget_create_pango_context (GtkWidget *widget)
7256 PangoContext *context;
7258 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7260 screen = gtk_widget_get_screen_unchecked (widget);
7263 GTK_NOTE (MULTIHEAD,
7264 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7266 screen = gdk_screen_get_default ();
7269 context = gdk_pango_context_get_for_screen (screen);
7271 update_pango_context (widget, context);
7272 pango_context_set_language (context, gtk_get_default_language ());
7278 * gtk_widget_create_pango_layout:
7279 * @widget: a #GtkWidget
7280 * @text: text to set on the layout (can be %NULL)
7282 * Creates a new #PangoLayout with the appropriate font map,
7283 * font description, and base direction for drawing text for
7286 * If you keep a #PangoLayout created in this way around, in order to
7287 * notify the layout of changes to the base direction or font of this
7288 * widget, you must call pango_layout_context_changed() in response to
7289 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7292 * Return value: the new #PangoLayout
7295 gtk_widget_create_pango_layout (GtkWidget *widget,
7298 PangoLayout *layout;
7299 PangoContext *context;
7301 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7303 context = gtk_widget_get_pango_context (widget);
7304 layout = pango_layout_new (context);
7307 pango_layout_set_text (layout, text, -1);
7313 * gtk_widget_render_icon:
7314 * @widget: a #GtkWidget
7315 * @stock_id: a stock ID
7316 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7317 * render at the size of the source and don't scale (if there are
7318 * multiple source sizes, GTK+ picks one of the available sizes).
7319 * @detail: (allow-none): render detail to pass to theme engine
7321 * A convenience function that uses the theme engine and RC file
7322 * settings for @widget to look up @stock_id and render it to
7323 * a pixbuf. @stock_id should be a stock icon ID such as
7324 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7325 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7326 * identifies the widget or code doing the rendering, so that
7327 * theme engines can special-case rendering for that widget or code.
7329 * The pixels in the returned #GdkPixbuf are shared with the rest of
7330 * the application and should not be modified. The pixbuf should be freed
7331 * after use with g_object_unref().
7333 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7336 gtk_widget_render_icon (GtkWidget *widget,
7337 const gchar *stock_id,
7339 const gchar *detail)
7341 GtkIconSet *icon_set;
7344 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7345 g_return_val_if_fail (stock_id != NULL, NULL);
7346 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7348 gtk_widget_ensure_style (widget);
7350 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7352 if (icon_set == NULL)
7355 retval = gtk_icon_set_render_icon (icon_set,
7357 gtk_widget_get_direction (widget),
7358 GTK_WIDGET_STATE (widget),
7367 * gtk_widget_set_parent_window:
7368 * @widget: a #GtkWidget.
7369 * @parent_window: the new parent window.
7371 * Sets a non default parent window for @widget.
7374 gtk_widget_set_parent_window (GtkWidget *widget,
7375 GdkWindow *parent_window)
7377 GdkWindow *old_parent_window;
7379 g_return_if_fail (GTK_IS_WIDGET (widget));
7381 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7382 quark_parent_window);
7384 if (parent_window != old_parent_window)
7386 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7388 if (old_parent_window)
7389 g_object_unref (old_parent_window);
7391 g_object_ref (parent_window);
7396 * gtk_widget_get_parent_window:
7397 * @widget: a #GtkWidget.
7399 * Gets @widget's parent window.
7401 * Returns: (transfer none): the parent window of @widget.
7404 gtk_widget_get_parent_window (GtkWidget *widget)
7406 GdkWindow *parent_window;
7408 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7410 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7412 return (parent_window != NULL) ? parent_window :
7413 (widget->parent != NULL) ? widget->parent->window : NULL;
7418 * gtk_widget_set_child_visible:
7419 * @widget: a #GtkWidget
7420 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7422 * Sets whether @widget should be mapped along with its when its parent
7423 * is mapped and @widget has been shown with gtk_widget_show().
7425 * The child visibility can be set for widget before it is added to
7426 * a container with gtk_widget_set_parent(), to avoid mapping
7427 * children unnecessary before immediately unmapping them. However
7428 * it will be reset to its default state of %TRUE when the widget
7429 * is removed from a container.
7431 * Note that changing the child visibility of a widget does not
7432 * queue a resize on the widget. Most of the time, the size of
7433 * a widget is computed from all visible children, whether or
7434 * not they are mapped. If this is not the case, the container
7435 * can queue a resize itself.
7437 * This function is only useful for container implementations and
7438 * never should be called by an application.
7441 gtk_widget_set_child_visible (GtkWidget *widget,
7442 gboolean is_visible)
7444 g_return_if_fail (GTK_IS_WIDGET (widget));
7445 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7447 g_object_ref (widget);
7450 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7453 GtkWidget *toplevel;
7455 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7457 toplevel = gtk_widget_get_toplevel (widget);
7458 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7459 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7462 if (widget->parent && gtk_widget_get_realized (widget->parent))
7464 if (gtk_widget_get_mapped (widget->parent) &&
7465 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7466 gtk_widget_get_visible (widget))
7467 gtk_widget_map (widget);
7469 gtk_widget_unmap (widget);
7472 g_object_unref (widget);
7476 * gtk_widget_get_child_visible:
7477 * @widget: a #GtkWidget
7479 * Gets the value set with gtk_widget_set_child_visible().
7480 * If you feel a need to use this function, your code probably
7481 * needs reorganization.
7483 * This function is only useful for container implementations and
7484 * never should be called by an application.
7486 * Return value: %TRUE if the widget is mapped with the parent.
7489 gtk_widget_get_child_visible (GtkWidget *widget)
7491 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7493 return GTK_WIDGET_CHILD_VISIBLE (widget);
7497 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7499 GtkWidget *toplevel;
7501 toplevel = gtk_widget_get_toplevel (widget);
7503 if (gtk_widget_is_toplevel (toplevel))
7505 if (GTK_IS_WINDOW (toplevel))
7506 return GTK_WINDOW (toplevel)->screen;
7507 else if (GTK_IS_INVISIBLE (toplevel))
7508 return GTK_INVISIBLE (widget)->screen;
7515 * gtk_widget_get_screen:
7516 * @widget: a #GtkWidget
7518 * Get the #GdkScreen from the toplevel window associated with
7519 * this widget. This function can only be called after the widget
7520 * has been added to a widget hierarchy with a #GtkWindow
7523 * In general, you should only create screen specific
7524 * resources when a widget has been realized, and you should
7525 * free those resources when the widget is unrealized.
7527 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7532 gtk_widget_get_screen (GtkWidget *widget)
7536 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7538 screen = gtk_widget_get_screen_unchecked (widget);
7545 g_warning (G_STRLOC ": Can't get associated screen"
7546 " for a widget unless it is inside a toplevel GtkWindow\n"
7547 " widget type is %s associated top level type is %s",
7548 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7549 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7551 return gdk_screen_get_default ();
7556 * gtk_widget_has_screen:
7557 * @widget: a #GtkWidget
7559 * Checks whether there is a #GdkScreen is associated with
7560 * this widget. All toplevel widgets have an associated
7561 * screen, and all widgets added into a hierarchy with a toplevel
7562 * window at the top.
7564 * Return value: %TRUE if there is a #GdkScreen associcated
7570 gtk_widget_has_screen (GtkWidget *widget)
7572 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7574 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7578 * gtk_widget_get_display:
7579 * @widget: a #GtkWidget
7581 * Get the #GdkDisplay for the toplevel window associated with
7582 * this widget. This function can only be called after the widget
7583 * has been added to a widget hierarchy with a #GtkWindow at the top.
7585 * In general, you should only create display specific
7586 * resources when a widget has been realized, and you should
7587 * free those resources when the widget is unrealized.
7589 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7594 gtk_widget_get_display (GtkWidget *widget)
7596 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7598 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7602 * gtk_widget_get_root_window:
7603 * @widget: a #GtkWidget
7605 * Get the root window where this widget is located. This function can
7606 * only be called after the widget has been added to a widget
7607 * hierarchy with #GtkWindow at the top.
7609 * The root window is useful for such purposes as creating a popup
7610 * #GdkWindow associated with the window. In general, you should only
7611 * create display specific resources when a widget has been realized,
7612 * and you should free those resources when the widget is unrealized.
7614 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7619 gtk_widget_get_root_window (GtkWidget *widget)
7621 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7623 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7627 * gtk_widget_child_focus:
7628 * @widget: a #GtkWidget
7629 * @direction: direction of focus movement
7631 * This function is used by custom widget implementations; if you're
7632 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7633 * to a particular widget, and gtk_container_set_focus_chain() to
7634 * change the focus tab order. So you may want to investigate those
7635 * functions instead.
7637 * gtk_widget_child_focus() is called by containers as the user moves
7638 * around the window using keyboard shortcuts. @direction indicates
7639 * what kind of motion is taking place (up, down, left, right, tab
7640 * forward, tab backward). gtk_widget_child_focus() emits the
7641 * #GtkWidget::focus" signal; widgets override the default handler
7642 * for this signal in order to implement appropriate focus behavior.
7644 * The default ::focus handler for a widget should return %TRUE if
7645 * moving in @direction left the focus on a focusable location inside
7646 * that widget, and %FALSE if moving in @direction moved the focus
7647 * outside the widget. If returning %TRUE, widgets normally
7648 * call gtk_widget_grab_focus() to place the focus accordingly;
7649 * if returning %FALSE, they don't modify the current focus location.
7651 * This function replaces gtk_container_focus() from GTK+ 1.2.
7652 * It was necessary to check that the child was visible, sensitive,
7653 * and focusable before calling gtk_container_focus().
7654 * gtk_widget_child_focus() returns %FALSE if the widget is not
7655 * currently in a focusable state, so there's no need for those checks.
7657 * Return value: %TRUE if focus ended up inside @widget
7660 gtk_widget_child_focus (GtkWidget *widget,
7661 GtkDirectionType direction)
7663 gboolean return_val;
7665 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7667 if (!gtk_widget_get_visible (widget) ||
7668 !gtk_widget_is_sensitive (widget))
7671 /* child widgets must set CAN_FOCUS, containers
7672 * don't have to though.
7674 if (!GTK_IS_CONTAINER (widget) &&
7675 !gtk_widget_get_can_focus (widget))
7678 g_signal_emit (widget,
7679 widget_signals[FOCUS],
7681 direction, &return_val);
7687 * gtk_widget_keynav_failed:
7688 * @widget: a #GtkWidget
7689 * @direction: direction of focus movement
7691 * This function should be called whenever keyboard navigation within
7692 * a single widget hits a boundary. The function emits the
7693 * #GtkWidget::keynav-failed signal on the widget and its return
7694 * value should be interpreted in a way similar to the return value of
7695 * gtk_widget_child_focus():
7697 * When %TRUE is returned, stay in the widget, the failed keyboard
7698 * navigation is Ok and/or there is nowhere we can/should move the
7701 * When %FALSE is returned, the caller should continue with keyboard
7702 * navigation outside the widget, e.g. by calling
7703 * gtk_widget_child_focus() on the widget's toplevel.
7705 * The default ::keynav-failed handler returns %TRUE for
7706 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7707 * values of #GtkDirectionType, it looks at the
7708 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7709 * if the setting is %TRUE. This way the entire user interface
7710 * becomes cursor-navigatable on input devices such as mobile phones
7711 * which only have cursor keys but no tab key.
7713 * Whenever the default handler returns %TRUE, it also calls
7714 * gtk_widget_error_bell() to notify the user of the failed keyboard
7717 * A use case for providing an own implementation of ::keynav-failed
7718 * (either by connecting to it or by overriding it) would be a row of
7719 * #GtkEntry widgets where the user should be able to navigate the
7720 * entire row with the cursor keys, as e.g. known from user interfaces
7721 * that require entering license keys.
7723 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7724 * if the emitting widget should try to handle the keyboard
7725 * navigation attempt in its parent container(s).
7730 gtk_widget_keynav_failed (GtkWidget *widget,
7731 GtkDirectionType direction)
7733 gboolean return_val;
7735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7737 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7738 direction, &return_val);
7744 * gtk_widget_error_bell:
7745 * @widget: a #GtkWidget
7747 * Notifies the user about an input-related error on this widget.
7748 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7749 * gdk_window_beep(), otherwise it does nothing.
7751 * Note that the effect of gdk_window_beep() can be configured in many
7752 * ways, depending on the windowing backend and the desktop environment
7753 * or window manager that is used.
7758 gtk_widget_error_bell (GtkWidget *widget)
7760 GtkSettings* settings;
7763 g_return_if_fail (GTK_IS_WIDGET (widget));
7765 settings = gtk_widget_get_settings (widget);
7769 g_object_get (settings,
7770 "gtk-error-bell", &beep,
7773 if (beep && widget->window)
7774 gdk_window_beep (widget->window);
7778 * gtk_widget_set_uposition:
7779 * @widget: a #GtkWidget
7780 * @x: x position; -1 to unset x; -2 to leave x unchanged
7781 * @y: y position; -1 to unset y; -2 to leave y unchanged
7784 * Sets the position of a widget. The funny "u" in the name comes from
7785 * the "user position" hint specified by the X Window System, and
7786 * exists for legacy reasons. This function doesn't work if a widget
7787 * is inside a container; it's only really useful on #GtkWindow.
7789 * Don't use this function to center dialogs over the main application
7790 * window; most window managers will do the centering on your behalf
7791 * if you call gtk_window_set_transient_for(), and it's really not
7792 * possible to get the centering to work correctly in all cases from
7793 * application code. But if you insist, use gtk_window_set_position()
7794 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7797 * Note that although @x and @y can be individually unset, the position
7798 * is not honoured unless both @x and @y are set.
7801 gtk_widget_set_uposition (GtkWidget *widget,
7805 /* FIXME this function is the only place that aux_info->x and
7806 * aux_info->y are even used I believe, and this function is
7807 * deprecated. Should be cleaned up.
7809 * (Actually, size_allocate uses them) -Yosh
7812 GtkWidgetAuxInfo *aux_info;
7814 g_return_if_fail (GTK_IS_WIDGET (widget));
7816 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7821 aux_info->x_set = FALSE;
7824 aux_info->x_set = TRUE;
7832 aux_info->y_set = FALSE;
7835 aux_info->y_set = TRUE;
7840 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7841 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7843 if (gtk_widget_get_visible (widget) && widget->parent)
7844 gtk_widget_size_allocate (widget, &widget->allocation);
7848 gtk_widget_set_usize_internal (GtkWidget *widget,
7852 GtkWidgetAuxInfo *aux_info;
7853 gboolean changed = FALSE;
7855 g_object_freeze_notify (G_OBJECT (widget));
7857 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7859 if (width > -2 && aux_info->width != width)
7861 g_object_notify (G_OBJECT (widget), "width-request");
7862 aux_info->width = width;
7865 if (height > -2 && aux_info->height != height)
7867 g_object_notify (G_OBJECT (widget), "height-request");
7868 aux_info->height = height;
7872 if (gtk_widget_get_visible (widget) && changed)
7873 gtk_widget_queue_resize (widget);
7875 g_object_thaw_notify (G_OBJECT (widget));
7879 * gtk_widget_set_usize:
7880 * @widget: a #GtkWidget
7881 * @width: minimum width, or -1 to unset
7882 * @height: minimum height, or -1 to unset
7884 * Sets the minimum size of a widget; that is, the widget's size
7885 * request will be @width by @height. You can use this function to
7886 * force a widget to be either larger or smaller than it is. The
7887 * strange "usize" name dates from the early days of GTK+, and derives
7888 * from X Window System terminology. In many cases,
7889 * gtk_window_set_default_size() is a better choice for toplevel
7890 * windows than this function; setting the default size will still
7891 * allow users to shrink the window. Setting the usize will force them
7892 * to leave the window at least as large as the usize. When dealing
7893 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7896 * Note the inherent danger of setting any fixed size - themes,
7897 * translations into other languages, different fonts, and user action
7898 * can all change the appropriate size for a given widget. So, it's
7899 * basically impossible to hardcode a size that will always be
7902 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7905 gtk_widget_set_usize (GtkWidget *widget,
7909 g_return_if_fail (GTK_IS_WIDGET (widget));
7911 gtk_widget_set_usize_internal (widget, width, height);
7915 * gtk_widget_set_size_request:
7916 * @widget: a #GtkWidget
7917 * @width: width @widget should request, or -1 to unset
7918 * @height: height @widget should request, or -1 to unset
7920 * Sets the minimum size of a widget; that is, the widget's size
7921 * request will be @width by @height. You can use this function to
7922 * force a widget to be either larger or smaller than it normally
7925 * In most cases, gtk_window_set_default_size() is a better choice for
7926 * toplevel windows than this function; setting the default size will
7927 * still allow users to shrink the window. Setting the size request
7928 * will force them to leave the window at least as large as the size
7929 * request. When dealing with window sizes,
7930 * gtk_window_set_geometry_hints() can be a useful function as well.
7932 * Note the inherent danger of setting any fixed size - themes,
7933 * translations into other languages, different fonts, and user action
7934 * can all change the appropriate size for a given widget. So, it's
7935 * basically impossible to hardcode a size that will always be
7938 * The size request of a widget is the smallest size a widget can
7939 * accept while still functioning well and drawing itself correctly.
7940 * However in some strange cases a widget may be allocated less than
7941 * its requested size, and in many cases a widget may be allocated more
7942 * space than it requested.
7944 * If the size request in a given direction is -1 (unset), then
7945 * the "natural" size request of the widget will be used instead.
7947 * Widgets can't actually be allocated a size less than 1 by 1, but
7948 * you can pass 0,0 to this function to mean "as small as possible."
7951 gtk_widget_set_size_request (GtkWidget *widget,
7955 g_return_if_fail (GTK_IS_WIDGET (widget));
7956 g_return_if_fail (width >= -1);
7957 g_return_if_fail (height >= -1);
7964 gtk_widget_set_usize_internal (widget, width, height);
7969 * gtk_widget_get_size_request:
7970 * @widget: a #GtkWidget
7971 * @width: (allow-none): (out): return location for width, or %NULL
7972 * @height: (allow-none): (out): return location for height, or %NULL
7974 * Gets the size request that was explicitly set for the widget using
7975 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7976 * @height indicates that that dimension has not been set explicitly
7977 * and the natural requisition of the widget will be used intead. See
7978 * gtk_widget_set_size_request(). To get the size a widget will
7979 * actually use, call gtk_widget_size_request() instead of
7983 gtk_widget_get_size_request (GtkWidget *widget,
7987 GtkWidgetAuxInfo *aux_info;
7989 g_return_if_fail (GTK_IS_WIDGET (widget));
7991 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7994 *width = aux_info ? aux_info->width : -1;
7997 *height = aux_info ? aux_info->height : -1;
8001 * gtk_widget_set_events:
8002 * @widget: a #GtkWidget
8003 * @events: event mask
8005 * Sets the event mask (see #GdkEventMask) for a widget. The event
8006 * mask determines which events a widget will receive. Keep in mind
8007 * that different widgets have different default event masks, and by
8008 * changing the event mask you may disrupt a widget's functionality,
8009 * so be careful. This function must be called while a widget is
8010 * unrealized. Consider gtk_widget_add_events() for widgets that are
8011 * already realized, or if you want to preserve the existing event
8012 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8013 * to get events on those widgets, place them inside a #GtkEventBox
8014 * and receive events on the event box.
8017 gtk_widget_set_events (GtkWidget *widget,
8020 g_return_if_fail (GTK_IS_WIDGET (widget));
8021 g_return_if_fail (!gtk_widget_get_realized (widget));
8023 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8024 GINT_TO_POINTER (events));
8025 g_object_notify (G_OBJECT (widget), "events");
8029 gtk_widget_add_events_internal (GtkWidget *widget,
8035 for (l = window_list; l != NULL; l = l->next)
8037 GdkWindow *window = l->data;
8040 gdk_window_get_user_data (window, &user_data);
8041 if (user_data == widget)
8045 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8047 children = gdk_window_get_children (window);
8048 gtk_widget_add_events_internal (widget, events, children);
8049 g_list_free (children);
8055 * gtk_widget_add_events:
8056 * @widget: a #GtkWidget
8057 * @events: an event mask, see #GdkEventMask
8059 * Adds the events in the bitfield @events to the event mask for
8060 * @widget. See gtk_widget_set_events() for details.
8063 gtk_widget_add_events (GtkWidget *widget,
8068 g_return_if_fail (GTK_IS_WIDGET (widget));
8070 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8071 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8072 GINT_TO_POINTER (old_events | events));
8074 if (gtk_widget_get_realized (widget))
8078 if (!gtk_widget_get_has_window (widget))
8079 window_list = gdk_window_get_children (widget->window);
8081 window_list = g_list_prepend (NULL, widget->window);
8083 gtk_widget_add_events_internal (widget, events, window_list);
8085 g_list_free (window_list);
8088 g_object_notify (G_OBJECT (widget), "events");
8092 * gtk_widget_set_extension_events:
8093 * @widget: a #GtkWidget
8094 * @mode: bitfield of extension events to receive
8096 * Sets the extension events mask to @mode. See #GdkExtensionMode
8097 * and gdk_input_set_extension_events().
8100 gtk_widget_set_extension_events (GtkWidget *widget,
8101 GdkExtensionMode mode)
8103 g_return_if_fail (GTK_IS_WIDGET (widget));
8105 if (gtk_widget_get_realized (widget))
8106 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8108 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8109 GINT_TO_POINTER (mode));
8110 g_object_notify (G_OBJECT (widget), "extension-events");
8114 * gtk_widget_get_toplevel:
8115 * @widget: a #GtkWidget
8117 * This function returns the topmost widget in the container hierarchy
8118 * @widget is a part of. If @widget has no parent widgets, it will be
8119 * returned as the topmost widget. No reference will be added to the
8120 * returned widget; it should not be unreferenced.
8122 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8123 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8125 * %NULL if @widget wasn't inside a toplevel window, and if the
8126 * window was inside a #GtkWindow-derived widget which was in turn
8127 * inside the toplevel #GtkWindow. While the second case may
8128 * seem unlikely, it actually happens when a #GtkPlug is embedded
8129 * inside a #GtkSocket within the same application.
8131 * To reliably find the toplevel #GtkWindow, use
8132 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8133 * is set on the result.
8135 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8136 * if (gtk_widget_is_toplevel (toplevel))
8138 * /* Perform action on toplevel. */
8142 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8143 * if there's no ancestor.
8146 gtk_widget_get_toplevel (GtkWidget *widget)
8148 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8150 while (widget->parent)
8151 widget = widget->parent;
8157 * gtk_widget_get_ancestor:
8158 * @widget: a #GtkWidget
8159 * @widget_type: ancestor type
8161 * Gets the first ancestor of @widget with type @widget_type. For example,
8162 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8163 * the first #GtkBox that's an ancestor of @widget. No reference will be
8164 * added to the returned widget; it should not be unreferenced. See note
8165 * about checking for a toplevel #GtkWindow in the docs for
8166 * gtk_widget_get_toplevel().
8168 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8169 * considers @widget to be an ancestor of itself.
8171 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8174 gtk_widget_get_ancestor (GtkWidget *widget,
8177 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8179 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8180 widget = widget->parent;
8182 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8189 * gtk_widget_get_colormap:
8190 * @widget: a #GtkWidget
8192 * Gets the colormap that will be used to render @widget. No reference will
8193 * be added to the returned colormap; it should not be unreferenced.
8195 * Return value: (transfer none): the colormap used by @widget
8198 gtk_widget_get_colormap (GtkWidget *widget)
8200 GdkColormap *colormap;
8201 GtkWidget *tmp_widget;
8203 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8207 colormap = gdk_drawable_get_colormap (widget->window);
8208 /* If window was destroyed previously, we'll get NULL here */
8213 tmp_widget = widget;
8216 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8220 tmp_widget= tmp_widget->parent;
8223 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8227 * gtk_widget_get_visual:
8228 * @widget: a #GtkWidget
8230 * Gets the visual that will be used to render @widget.
8232 * Return value: (transfer none): the visual for @widget
8235 gtk_widget_get_visual (GtkWidget *widget)
8237 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8239 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8243 * gtk_widget_get_settings:
8244 * @widget: a #GtkWidget
8246 * Gets the settings object holding the settings (global property
8247 * settings, RC file information, etc) used for this widget.
8249 * Note that this function can only be called when the #GtkWidget
8250 * is attached to a toplevel, since the settings object is specific
8251 * to a particular #GdkScreen.
8253 * Return value: (transfer none): the relevant #GtkSettings object
8256 gtk_widget_get_settings (GtkWidget *widget)
8258 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8260 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8264 * gtk_widget_set_colormap:
8265 * @widget: a #GtkWidget
8266 * @colormap: a colormap
8268 * Sets the colormap for the widget to the given value. Widget must not
8269 * have been previously realized. This probably should only be used
8270 * from an <function>init()</function> function (i.e. from the constructor
8274 gtk_widget_set_colormap (GtkWidget *widget,
8275 GdkColormap *colormap)
8277 g_return_if_fail (GTK_IS_WIDGET (widget));
8278 g_return_if_fail (!gtk_widget_get_realized (widget));
8279 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8281 g_object_ref (colormap);
8283 g_object_set_qdata_full (G_OBJECT (widget),
8290 * gtk_widget_get_events:
8291 * @widget: a #GtkWidget
8293 * Returns the event mask for the widget (a bitfield containing flags
8294 * from the #GdkEventMask enumeration). These are the events that the widget
8297 * Return value: event mask for @widget
8300 gtk_widget_get_events (GtkWidget *widget)
8302 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8304 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8308 * gtk_widget_get_extension_events:
8309 * @widget: a #GtkWidget
8311 * Retrieves the extension events the widget will receive; see
8312 * gdk_input_set_extension_events().
8314 * Return value: extension events for @widget
8317 gtk_widget_get_extension_events (GtkWidget *widget)
8319 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8321 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8325 * gtk_widget_get_pointer:
8326 * @widget: a #GtkWidget
8327 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8328 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8330 * Obtains the location of the mouse pointer in widget coordinates.
8331 * Widget coordinates are a bit odd; for historical reasons, they are
8332 * defined as @widget->window coordinates for widgets that are not
8333 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8334 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8337 gtk_widget_get_pointer (GtkWidget *widget,
8341 g_return_if_fail (GTK_IS_WIDGET (widget));
8348 if (gtk_widget_get_realized (widget))
8350 gdk_window_get_pointer (widget->window, x, y, NULL);
8352 if (!gtk_widget_get_has_window (widget))
8355 *x -= widget->allocation.x;
8357 *y -= widget->allocation.y;
8363 * gtk_widget_is_ancestor:
8364 * @widget: a #GtkWidget
8365 * @ancestor: another #GtkWidget
8367 * Determines whether @widget is somewhere inside @ancestor, possibly with
8368 * intermediate containers.
8370 * Return value: %TRUE if @ancestor contains @widget as a child,
8371 * grandchild, great grandchild, etc.
8374 gtk_widget_is_ancestor (GtkWidget *widget,
8375 GtkWidget *ancestor)
8377 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8378 g_return_val_if_fail (ancestor != NULL, FALSE);
8382 if (widget->parent == ancestor)
8384 widget = widget->parent;
8390 static GQuark quark_composite_name = 0;
8393 * gtk_widget_set_composite_name:
8394 * @widget: a #GtkWidget.
8395 * @name: the name to set
8397 * Sets a widgets composite name. The widget must be
8398 * a composite child of its parent; see gtk_widget_push_composite_child().
8401 gtk_widget_set_composite_name (GtkWidget *widget,
8404 g_return_if_fail (GTK_IS_WIDGET (widget));
8405 g_return_if_fail ((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8406 g_return_if_fail (name != NULL);
8408 if (!quark_composite_name)
8409 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8411 g_object_set_qdata_full (G_OBJECT (widget),
8412 quark_composite_name,
8418 * gtk_widget_get_composite_name:
8419 * @widget: a #GtkWidget
8421 * Obtains the composite name of a widget.
8423 * Returns: the composite name of @widget, or %NULL if @widget is not
8424 * a composite child. The string should be freed when it is no
8428 gtk_widget_get_composite_name (GtkWidget *widget)
8430 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8432 if (((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8433 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8440 * gtk_widget_push_composite_child:
8442 * Makes all newly-created widgets as composite children until
8443 * the corresponding gtk_widget_pop_composite_child() call.
8445 * A composite child is a child that's an implementation detail of the
8446 * container it's inside and should not be visible to people using the
8447 * container. Composite children aren't treated differently by GTK (but
8448 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8449 * builders might want to treat them in a different way.
8451 * Here is a simple example:
8453 * gtk_widget_push_composite_child ();
8454 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8455 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8456 * gtk_widget_pop_composite_child ();
8457 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8458 * GTK_WIDGET (scrolled_window));
8459 * g_object_ref (scrolled_window->hscrollbar);
8463 gtk_widget_push_composite_child (void)
8465 composite_child_stack++;
8469 * gtk_widget_pop_composite_child:
8471 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8474 gtk_widget_pop_composite_child (void)
8476 if (composite_child_stack)
8477 composite_child_stack--;
8481 * gtk_widget_push_colormap:
8482 * @cmap: a #GdkColormap
8484 * Pushes @cmap onto a global stack of colormaps; the topmost
8485 * colormap on the stack will be used to create all widgets.
8486 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8487 * reason to use this function.
8490 gtk_widget_push_colormap (GdkColormap *cmap)
8492 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8494 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8498 * gtk_widget_pop_colormap:
8500 * Removes a colormap pushed with gtk_widget_push_colormap().
8503 gtk_widget_pop_colormap (void)
8506 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8510 * gtk_widget_set_default_colormap:
8511 * @colormap: a #GdkColormap
8513 * Sets the default colormap to use when creating widgets.
8514 * gtk_widget_push_colormap() is a better function to use if
8515 * you only want to affect a few widgets, rather than all widgets.
8518 gtk_widget_set_default_colormap (GdkColormap *colormap)
8520 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8522 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8527 * gtk_widget_get_default_colormap:
8529 * Obtains the default colormap used to create widgets.
8531 * Return value: (transfer none): default widget colormap
8534 gtk_widget_get_default_colormap (void)
8536 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8540 * gtk_widget_get_default_visual:
8542 * Obtains the visual of the default colormap. Not really useful;
8543 * used to be useful before gdk_colormap_get_visual() existed.
8545 * Return value: (transfer none): visual of the default colormap
8548 gtk_widget_get_default_visual (void)
8550 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8554 gtk_widget_emit_direction_changed (GtkWidget *widget,
8555 GtkTextDirection old_dir)
8557 gtk_widget_update_pango_context (widget);
8559 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8563 * gtk_widget_set_direction:
8564 * @widget: a #GtkWidget
8565 * @dir: the new direction
8567 * Sets the reading direction on a particular widget. This direction
8568 * controls the primary direction for widgets containing text,
8569 * and also the direction in which the children of a container are
8570 * packed. The ability to set the direction is present in order
8571 * so that correct localization into languages with right-to-left
8572 * reading directions can be done. Generally, applications will
8573 * let the default reading direction present, except for containers
8574 * where the containers are arranged in an order that is explicitely
8575 * visual rather than logical (such as buttons for text justification).
8577 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8578 * set by gtk_widget_set_default_direction() will be used.
8581 gtk_widget_set_direction (GtkWidget *widget,
8582 GtkTextDirection dir)
8584 GtkTextDirection old_dir;
8586 g_return_if_fail (GTK_IS_WIDGET (widget));
8587 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8589 old_dir = gtk_widget_get_direction (widget);
8591 if (dir == GTK_TEXT_DIR_NONE)
8592 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8595 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8596 if (dir == GTK_TEXT_DIR_LTR)
8597 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8599 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8602 if (old_dir != gtk_widget_get_direction (widget))
8603 gtk_widget_emit_direction_changed (widget, old_dir);
8607 * gtk_widget_get_direction:
8608 * @widget: a #GtkWidget
8610 * Gets the reading direction for a particular widget. See
8611 * gtk_widget_set_direction().
8613 * Return value: the reading direction for the widget.
8616 gtk_widget_get_direction (GtkWidget *widget)
8618 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8620 if (GTK_WIDGET_DIRECTION_SET (widget))
8621 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8623 return gtk_default_direction;
8627 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8629 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8631 g_object_ref (widget);
8633 if (!GTK_WIDGET_DIRECTION_SET (widget))
8634 gtk_widget_emit_direction_changed (widget, old_dir);
8636 if (GTK_IS_CONTAINER (widget))
8637 gtk_container_forall (GTK_CONTAINER (widget),
8638 gtk_widget_set_default_direction_recurse,
8641 g_object_unref (widget);
8645 * gtk_widget_set_default_direction:
8646 * @dir: the new default direction. This cannot be
8647 * %GTK_TEXT_DIR_NONE.
8649 * Sets the default reading direction for widgets where the
8650 * direction has not been explicitly set by gtk_widget_set_direction().
8653 gtk_widget_set_default_direction (GtkTextDirection dir)
8655 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8657 if (dir != gtk_default_direction)
8659 GList *toplevels, *tmp_list;
8660 GtkTextDirection old_dir = gtk_default_direction;
8662 gtk_default_direction = dir;
8664 tmp_list = toplevels = gtk_window_list_toplevels ();
8665 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8669 gtk_widget_set_default_direction_recurse (tmp_list->data,
8670 GUINT_TO_POINTER (old_dir));
8671 g_object_unref (tmp_list->data);
8672 tmp_list = tmp_list->next;
8675 g_list_free (toplevels);
8680 * gtk_widget_get_default_direction:
8682 * Obtains the current default reading direction. See
8683 * gtk_widget_set_default_direction().
8685 * Return value: the current default direction.
8688 gtk_widget_get_default_direction (void)
8690 return gtk_default_direction;
8694 gtk_widget_dispose (GObject *object)
8696 GtkWidget *widget = GTK_WIDGET (object);
8699 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8700 else if (gtk_widget_get_visible (widget))
8701 gtk_widget_hide (widget);
8703 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8704 if (gtk_widget_get_realized (widget))
8705 gtk_widget_unrealize (widget);
8707 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8711 gtk_widget_real_destroy (GtkObject *object)
8713 /* gtk_object_destroy() will already hold a refcount on object */
8714 GtkWidget *widget = GTK_WIDGET (object);
8716 /* wipe accelerator closures (keep order) */
8717 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8718 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8720 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8721 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8723 gtk_grab_remove (widget);
8725 g_object_unref (widget->style);
8726 widget->style = gtk_widget_get_default_style ();
8727 g_object_ref (widget->style);
8729 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8733 gtk_widget_finalize (GObject *object)
8735 GtkWidget *widget = GTK_WIDGET (object);
8736 GtkWidgetAuxInfo *aux_info;
8737 GtkAccessible *accessible;
8739 gtk_grab_remove (widget);
8741 g_object_unref (widget->style);
8742 widget->style = NULL;
8744 g_free (widget->name);
8746 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8748 gtk_widget_aux_info_destroy (aux_info);
8750 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8752 g_object_unref (accessible);
8754 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8757 /*****************************************
8758 * gtk_widget_real_map:
8763 *****************************************/
8766 gtk_widget_real_map (GtkWidget *widget)
8768 g_assert (gtk_widget_get_realized (widget));
8770 if (!gtk_widget_get_mapped (widget))
8772 gtk_widget_set_mapped (widget, TRUE);
8774 if (gtk_widget_get_has_window (widget))
8775 gdk_window_show (widget->window);
8779 /*****************************************
8780 * gtk_widget_real_unmap:
8785 *****************************************/
8788 gtk_widget_real_unmap (GtkWidget *widget)
8790 if (gtk_widget_get_mapped (widget))
8792 gtk_widget_set_mapped (widget, FALSE);
8794 if (gtk_widget_get_has_window (widget))
8795 gdk_window_hide (widget->window);
8799 /*****************************************
8800 * gtk_widget_real_realize:
8805 *****************************************/
8808 gtk_widget_real_realize (GtkWidget *widget)
8810 g_assert (!gtk_widget_get_has_window (widget));
8812 gtk_widget_set_realized (widget, TRUE);
8815 widget->window = gtk_widget_get_parent_window (widget);
8816 g_object_ref (widget->window);
8818 widget->style = gtk_style_attach (widget->style, widget->window);
8821 /*****************************************
8822 * gtk_widget_real_unrealize:
8827 *****************************************/
8830 gtk_widget_real_unrealize (GtkWidget *widget)
8832 if (gtk_widget_get_mapped (widget))
8833 gtk_widget_real_unmap (widget);
8835 gtk_widget_set_mapped (widget, FALSE);
8837 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8840 /* We must do unrealize child widget BEFORE container widget.
8841 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8842 * So, unrealizing container widget bofore its children causes the problem
8843 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8846 if (GTK_IS_CONTAINER (widget))
8847 gtk_container_forall (GTK_CONTAINER (widget),
8848 (GtkCallback) gtk_widget_unrealize,
8851 gtk_style_detach (widget->style);
8852 if (gtk_widget_get_has_window (widget))
8854 gdk_window_set_user_data (widget->window, NULL);
8855 gdk_window_destroy (widget->window);
8856 widget->window = NULL;
8860 g_object_unref (widget->window);
8861 widget->window = NULL;
8864 gtk_selection_remove_all (widget);
8866 gtk_widget_set_realized (widget, FALSE);
8870 gtk_widget_real_size_request (GtkWidget *widget,
8871 GtkRequisition *requisition)
8873 requisition->width = widget->requisition.width;
8874 requisition->height = widget->requisition.height;
8878 * _gtk_widget_peek_colormap:
8880 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8882 * Return value: the currently pushed colormap, or %NULL if there is none.
8885 _gtk_widget_peek_colormap (void)
8888 return (GdkColormap*) colormap_stack->data;
8893 * _gtk_widget_set_pointer_window:
8894 * @widget: a #GtkWidget.
8895 * @pointer_window: the new pointer window.
8897 * Sets pointer window for @widget. Does not ref @pointer_window.
8898 * Actually stores it on the #GdkScreen, but you don't need to know that.
8901 _gtk_widget_set_pointer_window (GtkWidget *widget,
8902 GdkWindow *pointer_window)
8904 g_return_if_fail (GTK_IS_WIDGET (widget));
8906 if (gtk_widget_get_realized (widget))
8908 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8910 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8916 * _gtk_widget_get_pointer_window:
8917 * @widget: a #GtkWidget.
8919 * Return value: the pointer window set on the #GdkScreen @widget is attached
8923 _gtk_widget_get_pointer_window (GtkWidget *widget)
8925 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8927 if (gtk_widget_get_realized (widget))
8929 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8931 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8938 synth_crossing (GtkWidget *widget,
8941 GdkCrossingMode mode,
8942 GdkNotifyType detail)
8946 event = gdk_event_new (type);
8948 event->crossing.window = g_object_ref (window);
8949 event->crossing.send_event = TRUE;
8950 event->crossing.subwindow = g_object_ref (window);
8951 event->crossing.time = GDK_CURRENT_TIME;
8952 event->crossing.x = event->crossing.y = 0;
8953 event->crossing.x_root = event->crossing.y_root = 0;
8954 event->crossing.mode = mode;
8955 event->crossing.detail = detail;
8956 event->crossing.focus = FALSE;
8957 event->crossing.state = 0;
8960 widget = gtk_get_event_widget (event);
8963 gtk_widget_event_internal (widget, event);
8965 gdk_event_free (event);
8969 * _gtk_widget_is_pointer_widget:
8970 * @widget: a #GtkWidget
8972 * Returns %TRUE if the pointer window belongs to @widget.
8975 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8977 if (GTK_WIDGET_HAS_POINTER (widget))
8982 win = _gtk_widget_get_pointer_window (widget);
8985 gdk_window_get_user_data (win, (gpointer *)&wid);
8995 * _gtk_widget_synthesize_crossing:
8996 * @from: the #GtkWidget the virtual pointer is leaving.
8997 * @to: the #GtkWidget the virtual pointer is moving to.
8998 * @mode: the #GdkCrossingMode to place on the synthesized events.
9000 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9002 * The real pointer window is the window that most recently received an enter notify
9003 * event. Windows that don't select for crossing events can't become the real
9004 * poiner window. The real pointer widget that owns the real pointer window. The
9005 * effective pointer window is the same as the real pointer window unless the real
9006 * pointer widget is either insensitive or there is a grab on a widget that is not
9007 * an ancestor of the real pointer widget (in which case the effective pointer
9008 * window should be the root window).
9010 * When the effective pointer window is the same as the real poiner window, we
9011 * receive crossing events from the windowing system. When the effective pointer
9012 * window changes to become different from the real pointer window we synthesize
9013 * crossing events, attempting to follow X protocol rules:
9015 * When the root window becomes the effective pointer window:
9016 * - leave notify on real pointer window, detail Ancestor
9017 * - leave notify on all of its ancestors, detail Virtual
9018 * - enter notify on root window, detail Inferior
9020 * When the root window ceases to be the effective pointer window:
9021 * - leave notify on root window, detail Inferior
9022 * - enter notify on all ancestors of real pointer window, detail Virtual
9023 * - enter notify on real pointer window, detail Ancestor
9026 _gtk_widget_synthesize_crossing (GtkWidget *from,
9028 GdkCrossingMode mode)
9030 GdkWindow *from_window = NULL, *to_window = NULL;
9032 g_return_if_fail (from != NULL || to != NULL);
9035 from_window = GTK_WIDGET_HAS_POINTER (from)
9036 ? _gtk_widget_get_pointer_window (from) : from->window;
9038 to_window = GTK_WIDGET_HAS_POINTER (to)
9039 ? _gtk_widget_get_pointer_window (to) : to->window;
9041 if (from_window == NULL && to_window == NULL)
9043 else if (from_window != NULL && to_window == NULL)
9045 GList *from_ancestors = NULL, *list;
9046 GdkWindow *from_ancestor = from_window;
9048 while (from_ancestor != NULL)
9050 from_ancestor = gdk_window_get_parent (from_ancestor);
9051 if (from_ancestor == NULL)
9053 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9056 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9057 mode, GDK_NOTIFY_ANCESTOR);
9058 for (list = g_list_last (from_ancestors); list; list = list->prev)
9060 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9061 mode, GDK_NOTIFY_VIRTUAL);
9064 /* XXX: enter/inferior on root window? */
9066 g_list_free (from_ancestors);
9068 else if (from_window == NULL && to_window != NULL)
9070 GList *to_ancestors = NULL, *list;
9071 GdkWindow *to_ancestor = to_window;
9073 while (to_ancestor != NULL)
9075 to_ancestor = gdk_window_get_parent (to_ancestor);
9076 if (to_ancestor == NULL)
9078 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9081 /* XXX: leave/inferior on root window? */
9083 for (list = to_ancestors; list; list = list->next)
9085 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9086 mode, GDK_NOTIFY_VIRTUAL);
9088 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9089 mode, GDK_NOTIFY_ANCESTOR);
9091 g_list_free (to_ancestors);
9093 else if (from_window == to_window)
9097 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9098 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9100 while (from_ancestor != NULL || to_ancestor != NULL)
9102 if (from_ancestor != NULL)
9104 from_ancestor = gdk_window_get_parent (from_ancestor);
9105 if (from_ancestor == to_window)
9108 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9110 if (to_ancestor != NULL)
9112 to_ancestor = gdk_window_get_parent (to_ancestor);
9113 if (to_ancestor == from_window)
9116 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9119 if (to_ancestor == from_window)
9121 if (mode != GDK_CROSSING_GTK_UNGRAB)
9122 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9123 mode, GDK_NOTIFY_INFERIOR);
9124 for (list = to_ancestors; list; list = list->next)
9125 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9126 mode, GDK_NOTIFY_VIRTUAL);
9127 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9128 mode, GDK_NOTIFY_ANCESTOR);
9130 else if (from_ancestor == to_window)
9132 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9133 mode, GDK_NOTIFY_ANCESTOR);
9134 for (list = g_list_last (from_ancestors); list; list = list->prev)
9136 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9137 mode, GDK_NOTIFY_VIRTUAL);
9139 if (mode != GDK_CROSSING_GTK_GRAB)
9140 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9141 mode, GDK_NOTIFY_INFERIOR);
9145 while (from_ancestors != NULL && to_ancestors != NULL
9146 && from_ancestors->data == to_ancestors->data)
9148 from_ancestors = g_list_delete_link (from_ancestors,
9150 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9153 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9154 mode, GDK_NOTIFY_NONLINEAR);
9156 for (list = g_list_last (from_ancestors); list; list = list->prev)
9158 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9159 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9161 for (list = to_ancestors; list; list = list->next)
9163 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9164 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9166 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9167 mode, GDK_NOTIFY_NONLINEAR);
9169 g_list_free (from_ancestors);
9170 g_list_free (to_ancestors);
9175 gtk_widget_propagate_state (GtkWidget *widget,
9178 guint8 old_state = GTK_WIDGET_STATE (widget);
9179 guint8 old_saved_state = widget->saved_state;
9181 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9182 * parent_sensitive==TRUE on a sensitive widget
9186 if (data->parent_sensitive)
9187 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9189 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9191 if (gtk_widget_is_sensitive (widget))
9193 if (data->state_restoration)
9194 GTK_WIDGET_STATE (widget) = widget->saved_state;
9196 GTK_WIDGET_STATE (widget) = data->state;
9200 if (!data->state_restoration)
9202 if (data->state != GTK_STATE_INSENSITIVE)
9203 widget->saved_state = data->state;
9205 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
9206 widget->saved_state = GTK_WIDGET_STATE (widget);
9207 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
9210 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9214 window = gtk_widget_get_toplevel (widget);
9215 if (window && gtk_widget_is_toplevel (window))
9216 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9219 if (old_state != GTK_WIDGET_STATE (widget) ||
9220 old_saved_state != widget->saved_state)
9222 g_object_ref (widget);
9224 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9225 gtk_grab_remove (widget);
9227 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9229 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9231 if (!gtk_widget_is_sensitive (widget))
9232 _gtk_widget_synthesize_crossing (widget, NULL,
9233 GDK_CROSSING_STATE_CHANGED);
9234 else if (old_state == GTK_STATE_INSENSITIVE)
9235 _gtk_widget_synthesize_crossing (NULL, widget,
9236 GDK_CROSSING_STATE_CHANGED);
9239 if (GTK_IS_CONTAINER (widget))
9241 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9242 if (data->use_forall)
9243 gtk_container_forall (GTK_CONTAINER (widget),
9244 (GtkCallback) gtk_widget_propagate_state,
9247 gtk_container_foreach (GTK_CONTAINER (widget),
9248 (GtkCallback) gtk_widget_propagate_state,
9251 g_object_unref (widget);
9256 * _gtk_widget_get_aux_info:
9257 * @widget: a #GtkWidget
9258 * @create: if %TRUE, create the structure if it doesn't exist
9260 * Get the #GtkWidgetAuxInfo structure for the widget.
9262 * Return value: the #GtkAuxInfo structure for the widget, or
9263 * %NULL if @create is %FALSE and one doesn't already exist.
9266 _gtk_widget_get_aux_info (GtkWidget *widget,
9269 GtkWidgetAuxInfo *aux_info;
9271 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9272 if (!aux_info && create)
9274 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9276 aux_info->width = -1;
9277 aux_info->height = -1;
9279 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9285 /*****************************************
9286 * gtk_widget_aux_info_destroy:
9291 *****************************************/
9294 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9296 g_slice_free (GtkWidgetAuxInfo, aux_info);
9300 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9302 g_object_unref (info->shape_mask);
9303 g_slice_free (GtkWidgetShapeInfo, info);
9307 * gtk_widget_shape_combine_mask:
9308 * @widget: a #GtkWidget
9309 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9310 * @offset_x: X position of shape mask with respect to @window
9311 * @offset_y: Y position of shape mask with respect to @window
9313 * Sets a shape for this widget's GDK window. This allows for
9314 * transparent windows etc., see gdk_window_shape_combine_mask()
9315 * for more information.
9318 gtk_widget_shape_combine_mask (GtkWidget *widget,
9319 GdkBitmap *shape_mask,
9323 GtkWidgetShapeInfo* shape_info;
9325 g_return_if_fail (GTK_IS_WIDGET (widget));
9326 /* set_shape doesn't work on widgets without gdk window */
9327 g_return_if_fail (gtk_widget_get_has_window (widget));
9331 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9334 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9336 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9340 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9342 shape_info = g_slice_new (GtkWidgetShapeInfo);
9343 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9344 (GDestroyNotify) gtk_widget_shape_info_destroy);
9346 shape_info->shape_mask = g_object_ref (shape_mask);
9347 shape_info->offset_x = offset_x;
9348 shape_info->offset_y = offset_y;
9350 /* set shape if widget has a gdk window already.
9351 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9354 gdk_window_shape_combine_mask (widget->window, shape_mask,
9355 offset_x, offset_y);
9360 * gtk_widget_input_shape_combine_mask:
9361 * @widget: a #GtkWidget
9362 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9363 * @offset_x: X position of shape mask with respect to @window
9364 * @offset_y: Y position of shape mask with respect to @window
9366 * Sets an input shape for this widget's GDK window. This allows for
9367 * windows which react to mouse click in a nonrectangular region, see
9368 * gdk_window_input_shape_combine_mask() for more information.
9373 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9374 GdkBitmap *shape_mask,
9378 GtkWidgetShapeInfo* shape_info;
9380 g_return_if_fail (GTK_IS_WIDGET (widget));
9381 /* set_shape doesn't work on widgets without gdk window */
9382 g_return_if_fail (gtk_widget_get_has_window (widget));
9387 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9389 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9393 shape_info = g_slice_new (GtkWidgetShapeInfo);
9394 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9396 (GDestroyNotify) gtk_widget_shape_info_destroy);
9398 shape_info->shape_mask = g_object_ref (shape_mask);
9399 shape_info->offset_x = offset_x;
9400 shape_info->offset_y = offset_y;
9402 /* set shape if widget has a gdk window already.
9403 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9406 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9407 offset_x, offset_y);
9413 gtk_reset_shapes_recurse (GtkWidget *widget,
9419 gdk_window_get_user_data (window, &data);
9423 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9424 for (list = gdk_window_peek_children (window); list; list = list->next)
9425 gtk_reset_shapes_recurse (widget, list->data);
9429 * gtk_widget_reset_shapes:
9430 * @widget: a #GtkWidget
9432 * Recursively resets the shape on this widget and its descendants.
9435 gtk_widget_reset_shapes (GtkWidget *widget)
9437 g_return_if_fail (GTK_IS_WIDGET (widget));
9438 g_return_if_fail (gtk_widget_get_realized (widget));
9440 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9441 gtk_reset_shapes_recurse (widget, widget->window);
9446 * @widget: a #GtkWidget
9448 * Adds a reference to a widget. This function is exactly the same
9449 * as calling g_object_ref(), and exists mostly for historical
9450 * reasons. It can still be convenient to avoid casting a widget
9451 * to a #GObject, it saves a small amount of typing.
9453 * Return value: the widget that was referenced
9455 * Deprecated: 2.12: Use g_object_ref() instead.
9458 gtk_widget_ref (GtkWidget *widget)
9460 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9462 return (GtkWidget*) g_object_ref ((GObject*) widget);
9467 * @widget: a #GtkWidget
9469 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9471 * Deprecated: 2.12: Use g_object_unref() instead.
9474 gtk_widget_unref (GtkWidget *widget)
9476 g_return_if_fail (GTK_IS_WIDGET (widget));
9478 g_object_unref ((GObject*) widget);
9482 expose_window (GdkWindow *window)
9485 GList *l, *children;
9487 gboolean is_double_buffered;
9489 gdk_window_get_user_data (window, &user_data);
9492 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9494 is_double_buffered = FALSE;
9496 event.expose.type = GDK_EXPOSE;
9497 event.expose.window = g_object_ref (window);
9498 event.expose.send_event = FALSE;
9499 event.expose.count = 0;
9500 event.expose.area.x = 0;
9501 event.expose.area.y = 0;
9502 gdk_drawable_get_size (GDK_DRAWABLE (window),
9503 &event.expose.area.width,
9504 &event.expose.area.height);
9505 event.expose.region = gdk_region_rectangle (&event.expose.area);
9507 /* If this is not double buffered, force a double buffer so that
9508 redirection works. */
9509 if (!is_double_buffered)
9510 gdk_window_begin_paint_region (window, event.expose.region);
9512 gtk_main_do_event (&event);
9514 if (!is_double_buffered)
9515 gdk_window_end_paint (window);
9517 children = gdk_window_peek_children (window);
9518 for (l = children; l != NULL; l = l->next)
9520 GdkWindow *child = l->data;
9522 /* Don't expose input-only windows */
9523 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9524 expose_window (l->data);
9527 g_object_unref (window);
9531 * gtk_widget_get_snapshot:
9532 * @widget: a #GtkWidget
9533 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9535 * Create a #GdkPixmap of the contents of the widget and its children.
9537 * Works even if the widget is obscured. The depth and visual of the
9538 * resulting pixmap is dependent on the widget being snapshot and likely
9539 * differs from those of a target widget displaying the pixmap.
9540 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9541 * the pixmap to a visual independant representation.
9543 * The snapshot area used by this function is the @widget's allocation plus
9544 * any extra space occupied by additional windows belonging to this widget
9545 * (such as the arrows of a spin button).
9546 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9548 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9549 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9550 * interpreted widget relative. If width or height of @clip_rect are 0 or
9551 * negative, the width or height of the resulting pixmap will be shrunken
9552 * by the respective amount.
9553 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9554 * chop off 5 pixels at each side of the snapshot pixmap.
9555 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9556 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9557 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9558 * as a pure output parameter.
9560 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9562 * Return value: #GdkPixmap snapshot of the widget
9567 gtk_widget_get_snapshot (GtkWidget *widget,
9568 GdkRectangle *clip_rect)
9570 int x, y, width, height;
9571 GdkWindow *parent_window = NULL;
9573 GList *windows = NULL, *list;
9575 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9576 if (!gtk_widget_get_visible (widget))
9579 /* the widget (and parent_window) must be realized to be drawable */
9580 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9581 gtk_widget_realize (widget->parent);
9582 if (!gtk_widget_get_realized (widget))
9583 gtk_widget_realize (widget);
9585 /* determine snapshot rectangle */
9586 x = widget->allocation.x;
9587 y = widget->allocation.y;
9588 width = widget->allocation.width;
9589 height = widget->allocation.height;
9591 if (widget->parent && gtk_widget_get_has_window (widget))
9593 /* grow snapshot rectangle to cover all widget windows */
9594 parent_window = gtk_widget_get_parent_window (widget);
9595 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9597 GdkWindow *subwin = list->data;
9600 gdk_window_get_user_data (subwin, &windata);
9601 if (windata != widget)
9603 windows = g_list_prepend (windows, subwin);
9604 gdk_window_get_position (subwin, &wx, &wy);
9605 gdk_drawable_get_size (subwin, &ww, &wh);
9606 /* grow snapshot rectangle by extra widget sub window */
9617 if (x + width < wx + ww)
9618 width += wx + ww - (x + width);
9619 if (y + height < wy + wh)
9620 height += wy + wh - (y + height);
9623 else if (!widget->parent)
9624 x = y = 0; /* toplevel */
9626 /* at this point, (x,y,width,height) is the parent_window relative
9627 * snapshot area covering all of widget's windows.
9630 /* shrink snapshot size by clip_rectangle */
9633 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9634 clip.x = clip.x < 0 ? x : clip.x;
9635 clip.y = clip.y < 0 ? y : clip.y;
9636 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9637 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9640 /* offset clip_rect, so it's parent_window relative */
9641 if (clip_rect->x >= 0)
9642 clip.x += widget->allocation.x;
9643 if (clip_rect->y >= 0)
9644 clip.y += widget->allocation.y;
9646 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9648 g_list_free (windows);
9649 clip_rect->width = clip_rect->height = 0;
9650 return NULL; /* empty snapshot area */
9655 height = snap.height;
9658 /* render snapshot */
9659 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9660 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9662 GdkWindow *subwin = list->data;
9664 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9665 continue; /* Input only window */
9666 gdk_window_get_position (subwin, &wx, &wy);
9667 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9668 MAX (0, wx - x), MAX (0, wy - y), width, height);
9670 expose_window (subwin);
9672 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9674 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9675 expose_window (widget->window);
9677 for (list = windows; list; list = list->next)
9678 gdk_window_remove_redirection (list->data);
9679 if (!windows) /* NO_WINDOW || toplevel */
9680 gdk_window_remove_redirection (widget->window);
9681 g_list_free (windows);
9683 /* return pixmap and snapshot rectangle coordinates */
9688 clip_rect->width = width;
9689 clip_rect->height = height;
9692 /* offset clip_rect from parent_window so it's widget relative */
9693 clip_rect->x -= widget->allocation.x;
9694 clip_rect->y -= widget->allocation.y;
9697 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9698 G_OBJECT_TYPE_NAME (widget),
9699 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9708 * gtk_widget_class_install_style_property_parser:
9709 * @klass: a #GtkWidgetClass
9710 * @pspec: the #GParamSpec for the style property
9711 * @parser: the parser for the style property
9713 * Installs a style property on a widget class.
9716 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9718 GtkRcPropertyParser parser)
9720 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9721 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9722 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9723 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9725 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9727 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9728 G_OBJECT_CLASS_NAME (klass),
9733 g_param_spec_ref_sink (pspec);
9734 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9735 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9739 * gtk_widget_class_install_style_property:
9740 * @klass: a #GtkWidgetClass
9741 * @pspec: the #GParamSpec for the property
9743 * Installs a style property on a widget class. The parser for the
9744 * style property is determined by the value type of @pspec.
9747 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9750 GtkRcPropertyParser parser;
9752 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9753 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9755 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9757 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9761 * gtk_widget_class_find_style_property:
9762 * @klass: a #GtkWidgetClass
9763 * @property_name: the name of the style property to find
9764 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9765 * style property with that name.
9767 * Finds a style property of a widget class by name.
9772 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9773 const gchar *property_name)
9775 g_return_val_if_fail (property_name != NULL, NULL);
9777 return g_param_spec_pool_lookup (style_property_spec_pool,
9779 G_OBJECT_CLASS_TYPE (klass),
9784 * gtk_widget_class_list_style_properties:
9785 * @klass: a #GtkWidgetClass
9786 * @n_properties: location to return the number of style properties found
9787 * @returns: an newly allocated array of #GParamSpec*. The array must
9788 * be freed with g_free().
9790 * Returns all style properties of a widget class.
9795 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9796 guint *n_properties)
9798 GParamSpec **pspecs;
9801 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9802 G_OBJECT_CLASS_TYPE (klass),
9811 * gtk_widget_style_get_property:
9812 * @widget: a #GtkWidget
9813 * @property_name: the name of a style property
9814 * @value: location to return the property value
9816 * Gets the value of a style property of @widget.
9819 gtk_widget_style_get_property (GtkWidget *widget,
9820 const gchar *property_name,
9825 g_return_if_fail (GTK_IS_WIDGET (widget));
9826 g_return_if_fail (property_name != NULL);
9827 g_return_if_fail (G_IS_VALUE (value));
9829 g_object_ref (widget);
9830 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9832 G_OBJECT_TYPE (widget),
9835 g_warning ("%s: widget class `%s' has no property named `%s'",
9837 G_OBJECT_TYPE_NAME (widget),
9841 const GValue *peek_value;
9843 peek_value = _gtk_style_peek_property_value (widget->style,
9844 G_OBJECT_TYPE (widget),
9846 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9848 /* auto-conversion of the caller's value type
9850 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9851 g_value_copy (peek_value, value);
9852 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9853 g_value_transform (peek_value, value);
9855 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9857 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9858 G_VALUE_TYPE_NAME (value));
9860 g_object_unref (widget);
9864 * gtk_widget_style_get_valist:
9865 * @widget: a #GtkWidget
9866 * @first_property_name: the name of the first property to get
9867 * @var_args: a <type>va_list</type> of pairs of property names and
9868 * locations to return the property values, starting with the location
9869 * for @first_property_name.
9871 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9875 gtk_widget_style_get_valist (GtkWidget *widget,
9876 const gchar *first_property_name,
9881 g_return_if_fail (GTK_IS_WIDGET (widget));
9883 g_object_ref (widget);
9885 name = first_property_name;
9888 const GValue *peek_value;
9892 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9894 G_OBJECT_TYPE (widget),
9898 g_warning ("%s: widget class `%s' has no property named `%s'",
9900 G_OBJECT_TYPE_NAME (widget),
9904 /* style pspecs are always readable so we can spare that check here */
9906 peek_value = _gtk_style_peek_property_value (widget->style,
9907 G_OBJECT_TYPE (widget),
9909 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9910 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9913 g_warning ("%s: %s", G_STRLOC, error);
9918 name = va_arg (var_args, gchar*);
9921 g_object_unref (widget);
9925 * gtk_widget_style_get:
9926 * @widget: a #GtkWidget
9927 * @first_property_name: the name of the first property to get
9928 * @Varargs: pairs of property names and locations to
9929 * return the property values, starting with the location for
9930 * @first_property_name, terminated by %NULL.
9932 * Gets the values of a multiple style properties of @widget.
9935 gtk_widget_style_get (GtkWidget *widget,
9936 const gchar *first_property_name,
9941 g_return_if_fail (GTK_IS_WIDGET (widget));
9943 va_start (var_args, first_property_name);
9944 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9950 * @widget: a #GtkWidget
9951 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
9952 * @path: (out) (allow-none): location to store allocated path string, or %NULL
9953 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
9955 * Obtains the full path to @widget. The path is simply the name of a
9956 * widget and all its parents in the container hierarchy, separated by
9957 * periods. The name of a widget comes from
9958 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9959 * in gtkrc configuration files. Widget names are the type of the
9960 * widget by default (e.g. "GtkButton") or can be set to an
9961 * application-specific value with gtk_widget_set_name(). By setting
9962 * the name of a widget, you allow users or theme authors to apply
9963 * styles to that specific widget in their gtkrc
9964 * file. @path_reversed_p fills in the path in reverse order,
9965 * i.e. starting with @widget's name instead of starting with the name
9966 * of @widget's outermost ancestor.
9969 gtk_widget_path (GtkWidget *widget,
9972 gchar **path_reversed)
9974 static gchar *rev_path = NULL;
9975 static guint tmp_path_len = 0;
9978 g_return_if_fail (GTK_IS_WIDGET (widget));
9983 const gchar *string;
9988 string = gtk_widget_get_name (widget);
9989 l = strlen (string);
9990 while (tmp_path_len <= len + l + 1)
9992 tmp_path_len += INIT_PATH_SIZE;
9993 rev_path = g_realloc (rev_path, tmp_path_len);
10001 widget = widget->parent;
10004 rev_path[len++] = '.';
10006 rev_path[len++] = 0;
10011 *path_length = len - 1;
10013 *path_reversed = g_strdup (rev_path);
10016 *path = g_strdup (rev_path);
10017 g_strreverse (*path);
10022 * gtk_widget_class_path:
10023 * @widget: a #GtkWidget
10024 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10025 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10026 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10029 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10030 * never uses a custom name set with gtk_widget_set_name().
10034 gtk_widget_class_path (GtkWidget *widget,
10035 guint *path_length,
10037 gchar **path_reversed)
10039 static gchar *rev_path = NULL;
10040 static guint tmp_path_len = 0;
10043 g_return_if_fail (GTK_IS_WIDGET (widget));
10048 const gchar *string;
10053 string = g_type_name (G_OBJECT_TYPE (widget));
10054 l = strlen (string);
10055 while (tmp_path_len <= len + l + 1)
10057 tmp_path_len += INIT_PATH_SIZE;
10058 rev_path = g_realloc (rev_path, tmp_path_len);
10060 s = string + l - 1;
10061 d = rev_path + len;
10062 while (s >= string)
10066 widget = widget->parent;
10069 rev_path[len++] = '.';
10071 rev_path[len++] = 0;
10076 *path_length = len - 1;
10078 *path_reversed = g_strdup (rev_path);
10081 *path = g_strdup (rev_path);
10082 g_strreverse (*path);
10087 * gtk_requisition_copy:
10088 * @requisition: a #GtkRequisition
10090 * Copies a #GtkRequisition.
10092 * Returns: a copy of @requisition
10095 gtk_requisition_copy (const GtkRequisition *requisition)
10097 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10101 * gtk_requisition_free:
10102 * @requisition: a #GtkRequisition
10104 * Frees a #GtkRequisition.
10107 gtk_requisition_free (GtkRequisition *requisition)
10109 g_free (requisition);
10113 gtk_requisition_get_type (void)
10115 static GType our_type = 0;
10118 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10119 (GBoxedCopyFunc) gtk_requisition_copy,
10120 (GBoxedFreeFunc) gtk_requisition_free);
10126 * gtk_widget_get_accessible:
10127 * @widget: a #GtkWidget
10129 * Returns the accessible object that describes the widget to an
10130 * assistive technology.
10132 * If no accessibility library is loaded (i.e. no ATK implementation library is
10133 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10134 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10135 * if no class-specific #AtkObject implementation is available for the widget
10136 * instance in question, it will inherit an #AtkObject implementation from the
10137 * first ancestor class for which such an implementation is defined.
10139 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10140 * library contains more information about accessible objects and their uses.
10142 * Returns: (transfer none): the #AtkObject associated with @widget
10145 gtk_widget_get_accessible (GtkWidget *widget)
10147 GtkWidgetClass *klass;
10149 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10151 klass = GTK_WIDGET_GET_CLASS (widget);
10153 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10155 return klass->get_accessible (widget);
10159 gtk_widget_real_get_accessible (GtkWidget *widget)
10161 AtkObject* accessible;
10163 accessible = g_object_get_qdata (G_OBJECT (widget),
10164 quark_accessible_object);
10167 AtkObjectFactory *factory;
10168 AtkRegistry *default_registry;
10170 default_registry = atk_get_default_registry ();
10171 factory = atk_registry_get_factory (default_registry,
10172 G_TYPE_FROM_INSTANCE (widget));
10174 atk_object_factory_create_accessible (factory,
10175 G_OBJECT (widget));
10176 g_object_set_qdata (G_OBJECT (widget),
10177 quark_accessible_object,
10184 * Initialize a AtkImplementorIface instance's virtual pointers as
10185 * appropriate to this implementor's class (GtkWidget).
10188 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10190 iface->ref_accessible = gtk_widget_ref_accessible;
10194 gtk_widget_ref_accessible (AtkImplementor *implementor)
10196 AtkObject *accessible;
10198 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10200 g_object_ref (accessible);
10205 * GtkBuildable implementation
10207 static GQuark quark_builder_has_default = 0;
10208 static GQuark quark_builder_has_focus = 0;
10209 static GQuark quark_builder_atk_relations = 0;
10210 static GQuark quark_builder_set_name = 0;
10213 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10215 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10216 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10217 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10218 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10220 iface->set_name = gtk_widget_buildable_set_name;
10221 iface->get_name = gtk_widget_buildable_get_name;
10222 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10223 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10224 iface->parser_finished = gtk_widget_buildable_parser_finished;
10225 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10226 iface->custom_finished = gtk_widget_buildable_custom_finished;
10230 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10233 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10234 g_strdup (name), g_free);
10237 static const gchar *
10238 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10240 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10244 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10245 GtkBuilder *builder,
10246 const gchar *childname)
10248 if (strcmp (childname, "accessible") == 0)
10249 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10255 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10256 GtkBuilder *builder,
10258 const GValue *value)
10260 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10261 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10262 GINT_TO_POINTER (TRUE));
10263 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10264 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10265 GINT_TO_POINTER (TRUE));
10267 g_object_set_property (G_OBJECT (buildable), name, value);
10272 gchar *action_name;
10273 GString *description;
10275 gboolean translatable;
10285 free_action (AtkActionData *data, gpointer user_data)
10287 g_free (data->action_name);
10288 g_string_free (data->description, TRUE);
10289 g_free (data->context);
10290 g_slice_free (AtkActionData, data);
10294 free_relation (AtkRelationData *data, gpointer user_data)
10296 g_free (data->target);
10297 g_free (data->type);
10298 g_slice_free (AtkRelationData, data);
10302 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10303 GtkBuilder *builder)
10305 GSList *atk_relations;
10307 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10308 gtk_widget_grab_default (GTK_WIDGET (buildable));
10309 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10310 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10312 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10313 quark_builder_atk_relations);
10316 AtkObject *accessible;
10317 AtkRelationSet *relation_set;
10320 AtkRelationType relation_type;
10321 AtkObject *target_accessible;
10323 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10324 relation_set = atk_object_ref_relation_set (accessible);
10326 for (l = atk_relations; l; l = l->next)
10328 AtkRelationData *relation = (AtkRelationData*)l->data;
10330 target = gtk_builder_get_object (builder, relation->target);
10333 g_warning ("Target object %s in <relation> does not exist",
10337 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10338 g_assert (target_accessible != NULL);
10340 relation_type = atk_relation_type_for_name (relation->type);
10341 if (relation_type == ATK_RELATION_NULL)
10343 g_warning ("<relation> type %s not found",
10347 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10348 target_accessible);
10350 g_object_unref (relation_set);
10352 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10353 g_slist_free (atk_relations);
10354 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10363 } AccessibilitySubParserData;
10366 accessibility_start_element (GMarkupParseContext *context,
10367 const gchar *element_name,
10368 const gchar **names,
10369 const gchar **values,
10370 gpointer user_data,
10373 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10375 gint line_number, char_number;
10377 if (strcmp (element_name, "relation") == 0)
10379 gchar *target = NULL;
10380 gchar *type = NULL;
10381 AtkRelationData *relation;
10383 for (i = 0; names[i]; i++)
10385 if (strcmp (names[i], "target") == 0)
10386 target = g_strdup (values[i]);
10387 else if (strcmp (names[i], "type") == 0)
10388 type = g_strdup (values[i]);
10391 g_markup_parse_context_get_position (context,
10394 g_set_error (error,
10396 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10397 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10399 line_number, char_number, names[i], "relation");
10406 if (!target || !type)
10408 g_markup_parse_context_get_position (context,
10411 g_set_error (error,
10413 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10414 "%s:%d:%d <%s> requires attribute \"%s\"",
10416 line_number, char_number, "relation",
10417 type ? "target" : "type");
10423 relation = g_slice_new (AtkRelationData);
10424 relation->target = target;
10425 relation->type = type;
10427 data->relations = g_slist_prepend (data->relations, relation);
10429 else if (strcmp (element_name, "action") == 0)
10431 const gchar *action_name = NULL;
10432 const gchar *description = NULL;
10433 const gchar *msg_context = NULL;
10434 gboolean translatable = FALSE;
10435 AtkActionData *action;
10437 for (i = 0; names[i]; i++)
10439 if (strcmp (names[i], "action_name") == 0)
10440 action_name = values[i];
10441 else if (strcmp (names[i], "description") == 0)
10442 description = values[i];
10443 else if (strcmp (names[i], "translatable") == 0)
10445 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10448 else if (strcmp (names[i], "comments") == 0)
10450 /* do nothing, comments are for translators */
10452 else if (strcmp (names[i], "context") == 0)
10453 msg_context = values[i];
10456 g_markup_parse_context_get_position (context,
10459 g_set_error (error,
10461 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10462 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10464 line_number, char_number, names[i], "action");
10471 g_markup_parse_context_get_position (context,
10474 g_set_error (error,
10476 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10477 "%s:%d:%d <%s> requires attribute \"%s\"",
10479 line_number, char_number, "action",
10484 action = g_slice_new (AtkActionData);
10485 action->action_name = g_strdup (action_name);
10486 action->description = g_string_new (description);
10487 action->context = g_strdup (msg_context);
10488 action->translatable = translatable;
10490 data->actions = g_slist_prepend (data->actions, action);
10492 else if (strcmp (element_name, "accessibility") == 0)
10495 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10499 accessibility_text (GMarkupParseContext *context,
10502 gpointer user_data,
10505 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10507 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10509 AtkActionData *action = data->actions->data;
10511 g_string_append_len (action->description, text, text_len);
10515 static const GMarkupParser accessibility_parser =
10517 accessibility_start_element,
10519 accessibility_text,
10528 } AccelGroupParserData;
10531 accel_group_start_element (GMarkupParseContext *context,
10532 const gchar *element_name,
10533 const gchar **names,
10534 const gchar **values,
10535 gpointer user_data,
10540 guint modifiers = 0;
10541 gchar *signal = NULL;
10542 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10544 for (i = 0; names[i]; i++)
10546 if (strcmp (names[i], "key") == 0)
10547 key = gdk_keyval_from_name (values[i]);
10548 else if (strcmp (names[i], "modifiers") == 0)
10550 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10556 else if (strcmp (names[i], "signal") == 0)
10557 signal = g_strdup (values[i]);
10560 if (key == 0 || signal == NULL)
10562 g_warning ("<accelerator> requires key and signal attributes");
10565 parser_data->key = key;
10566 parser_data->modifiers = modifiers;
10567 parser_data->signal = signal;
10570 static const GMarkupParser accel_group_parser =
10572 accel_group_start_element,
10576 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10577 GtkBuilder *builder,
10579 const gchar *tagname,
10580 GMarkupParser *parser,
10583 g_assert (buildable);
10585 if (strcmp (tagname, "accelerator") == 0)
10587 AccelGroupParserData *parser_data;
10589 parser_data = g_slice_new0 (AccelGroupParserData);
10590 parser_data->object = g_object_ref (buildable);
10591 *parser = accel_group_parser;
10592 *data = parser_data;
10595 if (strcmp (tagname, "accessibility") == 0)
10597 AccessibilitySubParserData *parser_data;
10599 parser_data = g_slice_new0 (AccessibilitySubParserData);
10600 *parser = accessibility_parser;
10601 *data = parser_data;
10608 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10609 GtkWidget *toplevel,
10610 gpointer user_data)
10612 AccelGroupParserData *accel_data;
10613 GSList *accel_groups;
10614 GtkAccelGroup *accel_group;
10616 g_return_if_fail (GTK_IS_WIDGET (widget));
10617 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10618 g_return_if_fail (user_data != NULL);
10620 accel_data = (AccelGroupParserData*)user_data;
10621 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10622 if (g_slist_length (accel_groups) == 0)
10624 accel_group = gtk_accel_group_new ();
10625 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10629 g_assert (g_slist_length (accel_groups) == 1);
10630 accel_group = g_slist_nth_data (accel_groups, 0);
10633 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10634 accel_data->signal,
10637 accel_data->modifiers,
10638 GTK_ACCEL_VISIBLE);
10640 g_object_unref (accel_data->object);
10641 g_free (accel_data->signal);
10642 g_slice_free (AccelGroupParserData, accel_data);
10646 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10647 GtkBuilder *builder,
10649 const gchar *tagname,
10650 gpointer user_data)
10652 AccelGroupParserData *accel_data;
10653 AccessibilitySubParserData *a11y_data;
10654 GtkWidget *toplevel;
10656 if (strcmp (tagname, "accelerator") == 0)
10658 accel_data = (AccelGroupParserData*)user_data;
10659 g_assert (accel_data->object);
10661 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10663 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10665 else if (strcmp (tagname, "accessibility") == 0)
10667 a11y_data = (AccessibilitySubParserData*)user_data;
10669 if (a11y_data->actions)
10671 AtkObject *accessible;
10676 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10678 action = ATK_ACTION (accessible);
10679 n_actions = atk_action_get_n_actions (action);
10681 for (l = a11y_data->actions; l; l = l->next)
10683 AtkActionData *action_data = (AtkActionData*)l->data;
10685 for (i = 0; i < n_actions; i++)
10686 if (strcmp (atk_action_get_name (action, i),
10687 action_data->action_name) == 0)
10692 gchar *description;
10694 if (action_data->translatable && action_data->description->len)
10695 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10696 action_data->context,
10697 action_data->description->str);
10699 description = action_data->description->str;
10701 atk_action_set_description (action, i, description);
10705 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10706 g_slist_free (a11y_data->actions);
10709 if (a11y_data->relations)
10710 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10711 a11y_data->relations);
10713 g_slice_free (AccessibilitySubParserData, a11y_data);
10718 * GtkExtendedLayout implementation
10721 gtk_widget_real_get_desired_size (GtkExtendedLayout *layout,
10722 GtkRequisition *minimum_size,
10723 GtkRequisition *natural_size)
10725 GtkWidget *widget = GTK_WIDGET (layout);
10726 GtkRequisition requisition = widget->requisition;
10728 g_signal_emit (widget, widget_signals[SIZE_REQUEST], 0, &requisition);
10731 *minimum_size = requisition;
10733 *natural_size = requisition;
10737 gtk_widget_real_get_height_for_width (GtkExtendedLayout *layout,
10739 gint *minimum_height,
10740 gint *natural_height)
10742 GtkRequisition minimum_size;
10743 GtkRequisition natural_size;
10745 g_return_if_fail (GTK_IS_WIDGET (layout));
10748 TODO: integrate height-for-width with size-groups
10750 gtk_widget_get_desired_size (GTK_WIDGET(layout),
10751 minimum_height ? &minimum_size : NULL,
10752 natural_height ? &natural_size : NULL);
10754 if (minimum_height)
10755 *minimum_height = minimum_size.height;
10756 if (natural_height)
10757 *natural_height = natural_size.height;
10762 gtk_widget_real_get_width_for_height (GtkExtendedLayout *layout,
10764 gint *minimum_width,
10765 gint *natural_width)
10767 GtkRequisition minimum_size;
10768 GtkRequisition natural_size;
10770 g_return_if_fail (GTK_IS_WIDGET (layout));
10773 TODO: integrate width-for-height with size-groups
10775 gtk_widget_get_desired_size (GTK_WIDGET(layout),
10776 minimum_width ? &minimum_size : NULL,
10777 natural_width ? &natural_size : NULL);
10780 *minimum_width = minimum_size.width;
10782 *natural_width = natural_size.width;
10787 * gtk_widget_get_desired_size:
10788 * @widget: a #GtkWidget
10789 * @minimum_size: location for storing the @widget's minimum size, or %NULL
10790 * @natural_size: location for storing the @widget's preferred size, or %NULL
10792 * Retreives a widget's desired size, considering restrictions imposed by
10793 * #GtkSizeGroup<!-- -->s. See also: gtk_extended_layout_get_desired_size().
10798 gtk_widget_get_desired_size (GtkWidget *widget,
10799 GtkRequisition *minimum_size,
10800 GtkRequisition *natural_size)
10802 g_return_if_fail (GTK_IS_WIDGET (widget));
10803 _gtk_size_group_compute_desired_size (widget, minimum_size, natural_size);
10807 gtk_widget_layout_interface_init (GtkExtendedLayoutIface *iface)
10809 iface->get_desired_size = gtk_widget_real_get_desired_size;
10810 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
10811 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
10816 * gtk_widget_get_clipboard:
10817 * @widget: a #GtkWidget
10818 * @selection: a #GdkAtom which identifies the clipboard
10819 * to use. %GDK_SELECTION_CLIPBOARD gives the
10820 * default clipboard. Another common value
10821 * is %GDK_SELECTION_PRIMARY, which gives
10822 * the primary X selection.
10824 * Returns the clipboard object for the given selection to
10825 * be used with @widget. @widget must have a #GdkDisplay
10826 * associated with it, so must be attached to a toplevel
10829 * Return value: (transfer none): the appropriate clipboard object. If no
10830 * clipboard already exists, a new one will
10831 * be created. Once a clipboard object has
10832 * been created, it is persistent for all time.
10837 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10840 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10842 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10847 * gtk_widget_list_mnemonic_labels:
10848 * @widget: a #GtkWidget
10850 * Returns a newly allocated list of the widgets, normally labels, for
10851 * which this widget is a the target of a mnemonic (see for example,
10852 * gtk_label_set_mnemonic_widget()).
10854 * The widgets in the list are not individually referenced. If you
10855 * want to iterate through the list and perform actions involving
10856 * callbacks that might destroy the widgets, you
10857 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10858 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10859 * widgets afterwards.
10861 * Return value: (element-type GtkWidget) (transfer container): the list of
10862 * mnemonic labels; free this list
10863 * with g_list_free() when you are done with it.
10868 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10870 GList *list = NULL;
10873 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10875 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10876 list = g_list_prepend (list, l->data);
10882 * gtk_widget_add_mnemonic_label:
10883 * @widget: a #GtkWidget
10884 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10886 * Adds a widget to the list of mnemonic labels for
10887 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10888 * list of mnemonic labels for the widget is cleared when the
10889 * widget is destroyed, so the caller must make sure to update
10890 * its internal state at this point as well, by using a connection
10891 * to the #GtkWidget::destroy signal or a weak notifier.
10896 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10899 GSList *old_list, *new_list;
10901 g_return_if_fail (GTK_IS_WIDGET (widget));
10902 g_return_if_fail (GTK_IS_WIDGET (label));
10904 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10905 new_list = g_slist_prepend (old_list, label);
10907 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10908 new_list, (GDestroyNotify) g_slist_free);
10912 * gtk_widget_remove_mnemonic_label:
10913 * @widget: a #GtkWidget
10914 * @label: a #GtkWidget that was previously set as a mnemnic label for
10915 * @widget with gtk_widget_add_mnemonic_label().
10917 * Removes a widget from the list of mnemonic labels for
10918 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10919 * must have previously been added to the list with
10920 * gtk_widget_add_mnemonic_label().
10925 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10928 GSList *old_list, *new_list;
10930 g_return_if_fail (GTK_IS_WIDGET (widget));
10931 g_return_if_fail (GTK_IS_WIDGET (label));
10933 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10934 new_list = g_slist_remove (old_list, label);
10937 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10938 new_list, (GDestroyNotify) g_slist_free);
10942 * gtk_widget_get_no_show_all:
10943 * @widget: a #GtkWidget
10945 * Returns the current value of the GtkWidget:no-show-all property,
10946 * which determines whether calls to gtk_widget_show_all() and
10947 * gtk_widget_hide_all() will affect this widget.
10949 * Return value: the current value of the "no-show-all" property.
10954 gtk_widget_get_no_show_all (GtkWidget *widget)
10956 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10958 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10962 * gtk_widget_set_no_show_all:
10963 * @widget: a #GtkWidget
10964 * @no_show_all: the new value for the "no-show-all" property
10966 * Sets the #GtkWidget:no-show-all property, which determines whether
10967 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10970 * This is mostly for use in constructing widget hierarchies with externally
10971 * controlled visibility, see #GtkUIManager.
10976 gtk_widget_set_no_show_all (GtkWidget *widget,
10977 gboolean no_show_all)
10979 g_return_if_fail (GTK_IS_WIDGET (widget));
10981 no_show_all = (no_show_all != FALSE);
10983 if (no_show_all == gtk_widget_get_no_show_all (widget))
10987 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
10989 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
10991 g_object_notify (G_OBJECT (widget), "no-show-all");
10996 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10997 gboolean has_tooltip,
11000 gboolean priv_has_tooltip;
11002 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11003 quark_has_tooltip));
11005 if (priv_has_tooltip != has_tooltip || force)
11007 priv_has_tooltip = has_tooltip;
11009 if (priv_has_tooltip)
11011 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11012 gdk_window_set_events (widget->window,
11013 gdk_window_get_events (widget->window) |
11014 GDK_LEAVE_NOTIFY_MASK |
11015 GDK_POINTER_MOTION_MASK |
11016 GDK_POINTER_MOTION_HINT_MASK);
11018 if (gtk_widget_get_has_window (widget))
11019 gtk_widget_add_events (widget,
11020 GDK_LEAVE_NOTIFY_MASK |
11021 GDK_POINTER_MOTION_MASK |
11022 GDK_POINTER_MOTION_HINT_MASK);
11025 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11026 GUINT_TO_POINTER (priv_has_tooltip));
11031 * gtk_widget_set_tooltip_window:
11032 * @widget: a #GtkWidget
11033 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11035 * Replaces the default, usually yellow, window used for displaying
11036 * tooltips with @custom_window. GTK+ will take care of showing and
11037 * hiding @custom_window at the right moment, to behave likewise as
11038 * the default tooltip window. If @custom_window is %NULL, the default
11039 * tooltip window will be used.
11041 * If the custom window should have the default theming it needs to
11042 * have the name "gtk-tooltip", see gtk_widget_set_name().
11047 gtk_widget_set_tooltip_window (GtkWidget *widget,
11048 GtkWindow *custom_window)
11050 gboolean has_tooltip;
11051 gchar *tooltip_markup;
11053 g_return_if_fail (GTK_IS_WIDGET (widget));
11054 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11056 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11059 g_object_ref (custom_window);
11061 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11062 custom_window, g_object_unref);
11064 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11065 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11067 if (has_tooltip && gtk_widget_get_visible (widget))
11068 gtk_widget_queue_tooltip_query (widget);
11072 * gtk_widget_get_tooltip_window:
11073 * @widget: a #GtkWidget
11075 * Returns the #GtkWindow of the current tooltip. This can be the
11076 * GtkWindow created by default, or the custom tooltip window set
11077 * using gtk_widget_set_tooltip_window().
11079 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11084 gtk_widget_get_tooltip_window (GtkWidget *widget)
11086 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11088 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11092 * gtk_widget_trigger_tooltip_query:
11093 * @widget: a #GtkWidget
11095 * Triggers a tooltip query on the display where the toplevel of @widget
11096 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11102 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11104 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11107 static guint tooltip_query_id;
11108 static GSList *tooltip_query_displays;
11111 tooltip_query_idle (gpointer data)
11113 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11114 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11115 g_slist_free (tooltip_query_displays);
11117 tooltip_query_displays = NULL;
11118 tooltip_query_id = 0;
11124 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11126 GdkDisplay *display;
11128 display = gtk_widget_get_display (widget);
11130 if (!g_slist_find (tooltip_query_displays, display))
11131 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11133 if (tooltip_query_id == 0)
11134 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11138 * gtk_widget_set_tooltip_text:
11139 * @widget: a #GtkWidget
11140 * @text: the contents of the tooltip for @widget
11142 * Sets @text as the contents of the tooltip. This function will take
11143 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11144 * handler for the GtkWidget::query-tooltip signal.
11146 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11151 gtk_widget_set_tooltip_text (GtkWidget *widget,
11154 g_return_if_fail (GTK_IS_WIDGET (widget));
11156 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11160 * gtk_widget_get_tooltip_text:
11161 * @widget: a #GtkWidget
11163 * Gets the contents of the tooltip for @widget.
11165 * Return value: the tooltip text, or %NULL. You should free the
11166 * returned string with g_free() when done.
11171 gtk_widget_get_tooltip_text (GtkWidget *widget)
11173 gchar *text = NULL;
11175 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11177 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11183 * gtk_widget_set_tooltip_markup:
11184 * @widget: a #GtkWidget
11185 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11187 * Sets @markup as the contents of the tooltip, which is marked up with
11188 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11190 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11191 * and of the default handler for the GtkWidget::query-tooltip signal.
11193 * See also the GtkWidget:tooltip-markup property and
11194 * gtk_tooltip_set_markup().
11199 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11200 const gchar *markup)
11202 g_return_if_fail (GTK_IS_WIDGET (widget));
11204 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11208 * gtk_widget_get_tooltip_markup:
11209 * @widget: a #GtkWidget
11211 * Gets the contents of the tooltip for @widget.
11213 * Return value: the tooltip text, or %NULL. You should free the
11214 * returned string with g_free() when done.
11219 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11221 gchar *text = NULL;
11223 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11225 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11231 * gtk_widget_set_has_tooltip:
11232 * @widget: a #GtkWidget
11233 * @has_tooltip: whether or not @widget has a tooltip.
11235 * Sets the has-tooltip property on @widget to @has_tooltip. See
11236 * GtkWidget:has-tooltip for more information.
11241 gtk_widget_set_has_tooltip (GtkWidget *widget,
11242 gboolean has_tooltip)
11244 g_return_if_fail (GTK_IS_WIDGET (widget));
11246 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11250 * gtk_widget_get_has_tooltip:
11251 * @widget: a #GtkWidget
11253 * Returns the current value of the has-tooltip property. See
11254 * GtkWidget:has-tooltip for more information.
11256 * Return value: current value of has-tooltip on @widget.
11261 gtk_widget_get_has_tooltip (GtkWidget *widget)
11263 gboolean has_tooltip = FALSE;
11265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11267 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11269 return has_tooltip;
11273 * gtk_widget_get_allocation:
11274 * @widget: a #GtkWidget
11275 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11277 * Retrieves the widget's allocation.
11282 gtk_widget_get_allocation (GtkWidget *widget,
11283 GtkAllocation *allocation)
11285 g_return_if_fail (GTK_IS_WIDGET (widget));
11286 g_return_if_fail (allocation != NULL);
11288 *allocation = widget->allocation;
11292 * gtk_widget_set_allocation:
11293 * @widget: a #GtkWidget
11294 * @allocation: a pointer to a #GtkAllocation to copy from
11296 * Sets the widget's allocation. This should not be used
11297 * directly, but from within a widget's size_allocate method.
11302 gtk_widget_set_allocation (GtkWidget *widget,
11303 const GtkAllocation *allocation)
11305 g_return_if_fail (GTK_IS_WIDGET (widget));
11306 g_return_if_fail (allocation != NULL);
11308 widget->allocation = *allocation;
11312 * gtk_widget_get_requisition:
11313 * @widget: a #GtkWidget
11314 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11316 * Retrieves the widget's requisition.
11318 * This function should only be used by widget implementations in
11319 * order to figure whether the widget's requisition has actually
11320 * changed after some internal state change (so that they can call
11321 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11323 * Normally, gtk_widget_size_request() should be used.
11328 gtk_widget_get_requisition (GtkWidget *widget,
11329 GtkRequisition *requisition)
11331 g_return_if_fail (GTK_IS_WIDGET (widget));
11332 g_return_if_fail (requisition != NULL);
11334 *requisition = widget->requisition;
11338 * gtk_widget_set_window:
11339 * @widget: a #GtkWidget
11340 * @window: a #GdkWindow
11342 * Sets a widget's window. This function should only be used in a
11343 * widget's GtkWidget::realize() implementation. The %window passed is
11344 * usually either new window created with gdk_window_new(), or the
11345 * window of its parent widget as returned by
11346 * gtk_widget_get_parent_window().
11348 * Widgets must indicate whether they will create their own #GdkWindow
11349 * by calling gtk_widget_set_has_window(). This is usually done in the
11350 * widget's init() function.
11355 gtk_widget_set_window (GtkWidget *widget,
11358 g_return_if_fail (GTK_IS_WIDGET (widget));
11359 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11361 if (widget->window != window)
11363 widget->window = window;
11364 g_object_notify (G_OBJECT (widget), "window");
11369 * gtk_widget_get_window:
11370 * @widget: a #GtkWidget
11372 * Returns the widget's window if it is realized, %NULL otherwise
11374 * Return value: @widget's window.
11379 gtk_widget_get_window (GtkWidget *widget)
11381 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11383 return widget->window;
11386 #define __GTK_WIDGET_C__
11387 #include "gtkaliasdef.c"