1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
56 #include "gtkextendedlayout.h"
61 * @Short_description: Base class for all widgets
64 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
65 * widget lifecycle, states and style.
67 * <refsect2 id="style-properties">
69 * <structname>GtkWidget</structname> introduces <firstterm>style
70 * properties</firstterm> - these are basically object properties that are stored
71 * not on the object, but in the style object associated to the widget. Style
72 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
73 * This mechanism is used for configuring such things as the location of the
74 * scrollbar arrows through the theme, giving theme authors more control over the
75 * look of applications without the need to write a theme engine in C.
78 * Use gtk_widget_class_install_style_property() to install style properties for
79 * a widget class, gtk_widget_class_find_style_property() or
80 * gtk_widget_class_list_style_properties() to get information about existing
81 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
82 * gtk_widget_style_get_valist() to obtain the value of a style property.
85 * <refsect2 id="GtkWidget-BUILDER-UI">
86 * <title>GtkWidget as GtkBuildable</title>
88 * The GtkWidget implementation of the GtkBuildable interface supports a
89 * custom <accelerator> element, which has attributes named key,
90 * modifiers and signal and allows to specify accelerators.
93 * <title>A UI definition fragment specifying an accelerator</title>
94 * <programlisting><![CDATA[
95 * <object class="GtkButton">
96 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
98 * ]]></programlisting>
101 * In addition to accelerators, <structname>GtkWidget</structname> also support a
102 * custom <accessible> element, which supports actions and relations.
103 * Properties on the accessible implementation of an object can be set by accessing the
104 * internal child "accessible" of a <structname>GtkWidget</structname>.
107 * <title>A UI definition fragment specifying an accessible</title>
108 * <programlisting><![CDATA[
109 * <object class="GtkButton" id="label1"/>
110 * <property name="label">I am a Label for a Button</property>
112 * <object class="GtkButton" id="button1">
114 * <action action_name="click" translatable="yes">Click the button.</action>
115 * <relation target="label1" type="labelled-by"/>
117 * <child internal-child="accessible">
118 * <object class="AtkObject" id="a11y-button1">
119 * <property name="AtkObject::name">Clickable Button</property>
123 * ]]></programlisting>
128 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
129 #define INIT_PATH_SIZE (512)
155 BUTTON_RELEASE_EVENT,
170 PROPERTY_NOTIFY_EVENT,
171 SELECTION_CLEAR_EVENT,
172 SELECTION_REQUEST_EVENT,
173 SELECTION_NOTIFY_EVENT,
188 VISIBILITY_NOTIFY_EVENT,
192 ACCEL_CLOSURES_CHANGED,
218 PROP_RECEIVES_DEFAULT,
219 PROP_COMPOSITE_CHILD,
222 PROP_EXTENSION_EVENTS,
231 typedef struct _GtkStateData GtkStateData;
236 guint state_restoration : 1;
237 guint parent_sensitive : 1;
238 guint use_forall : 1;
241 /* --- prototypes --- */
242 static void gtk_widget_class_init (GtkWidgetClass *klass);
243 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
244 static void gtk_widget_init (GtkWidget *widget);
245 static void gtk_widget_set_property (GObject *object,
249 static void gtk_widget_get_property (GObject *object,
253 static void gtk_widget_dispose (GObject *object);
254 static void gtk_widget_real_destroy (GtkObject *object);
255 static void gtk_widget_finalize (GObject *object);
256 static void gtk_widget_real_show (GtkWidget *widget);
257 static void gtk_widget_real_hide (GtkWidget *widget);
258 static void gtk_widget_real_map (GtkWidget *widget);
259 static void gtk_widget_real_unmap (GtkWidget *widget);
260 static void gtk_widget_real_realize (GtkWidget *widget);
261 static void gtk_widget_real_unrealize (GtkWidget *widget);
262 static void gtk_widget_real_size_request (GtkWidget *widget,
263 GtkRequisition *requisition);
264 static void gtk_widget_real_size_allocate (GtkWidget *widget,
265 GtkAllocation *allocation);
266 static void gtk_widget_real_style_set (GtkWidget *widget,
267 GtkStyle *previous_style);
268 static void gtk_widget_real_direction_changed(GtkWidget *widget,
269 GtkTextDirection previous_direction);
271 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
272 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
275 gboolean keyboard_tip,
276 GtkTooltip *tooltip);
277 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
278 GtkWidgetHelpType help_type);
280 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
282 GParamSpec **pspecs);
283 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
285 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
287 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
288 GdkEventFocus *event);
289 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
290 GdkEventFocus *event);
291 static gboolean gtk_widget_real_focus (GtkWidget *widget,
292 GtkDirectionType direction);
293 static void gtk_widget_real_move_focus (GtkWidget *widget,
294 GtkDirectionType direction);
295 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
296 GtkDirectionType direction);
297 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
298 static void gtk_widget_update_pango_context (GtkWidget *widget);
299 static void gtk_widget_propagate_state (GtkWidget *widget,
301 static void gtk_widget_reset_rc_style (GtkWidget *widget);
302 static void gtk_widget_set_style_internal (GtkWidget *widget,
304 gboolean initial_emission);
305 static gint gtk_widget_event_internal (GtkWidget *widget,
307 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
308 gboolean group_cycling);
309 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
310 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
311 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
312 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
313 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
315 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
316 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
317 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
320 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
321 gboolean has_tooltip,
323 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
324 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
326 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
327 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
329 const gchar *childname);
330 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
333 const GValue *value);
334 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
337 const gchar *tagname,
338 GMarkupParser *parser,
340 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
343 const gchar *tagname,
345 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
346 GtkBuilder *builder);
348 static void gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface);
349 static void gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
352 static void gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
356 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
358 static void gtk_widget_set_usize_internal (GtkWidget *widget,
361 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
365 /* --- variables --- */
366 static gpointer gtk_widget_parent_class = NULL;
367 static guint widget_signals[LAST_SIGNAL] = { 0 };
368 static GtkStyle *gtk_default_style = NULL;
369 static GSList *colormap_stack = NULL;
370 static guint composite_child_stack = 0;
371 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
372 static GParamSpecPool *style_property_spec_pool = NULL;
374 static GQuark quark_property_parser = 0;
375 static GQuark quark_aux_info = 0;
376 static GQuark quark_accel_path = 0;
377 static GQuark quark_accel_closures = 0;
378 static GQuark quark_event_mask = 0;
379 static GQuark quark_extension_event_mode = 0;
380 static GQuark quark_parent_window = 0;
381 static GQuark quark_pointer_window = 0;
382 static GQuark quark_shape_info = 0;
383 static GQuark quark_input_shape_info = 0;
384 static GQuark quark_colormap = 0;
385 static GQuark quark_pango_context = 0;
386 static GQuark quark_rc_style = 0;
387 static GQuark quark_accessible_object = 0;
388 static GQuark quark_mnemonic_labels = 0;
389 static GQuark quark_tooltip_markup = 0;
390 static GQuark quark_has_tooltip = 0;
391 static GQuark quark_tooltip_window = 0;
392 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
393 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
395 /* --- functions --- */
397 gtk_widget_get_type (void)
399 static GType widget_type = 0;
401 if (G_UNLIKELY (widget_type == 0))
403 const GTypeInfo widget_info =
405 sizeof (GtkWidgetClass),
406 NULL, /* base_init */
407 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
408 (GClassInitFunc) gtk_widget_class_init,
409 NULL, /* class_finalize */
410 NULL, /* class_init */
413 (GInstanceInitFunc) gtk_widget_init,
414 NULL, /* value_table */
417 const GInterfaceInfo accessibility_info =
419 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
420 (GInterfaceFinalizeFunc) NULL,
421 NULL /* interface data */
424 const GInterfaceInfo buildable_info =
426 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
427 (GInterfaceFinalizeFunc) NULL,
428 NULL /* interface data */
431 const GInterfaceInfo layout_info =
433 (GInterfaceInitFunc) gtk_widget_extended_layout_init,
434 (GInterfaceFinalizeFunc) NULL,
435 NULL /* interface data */
438 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
439 &widget_info, G_TYPE_FLAG_ABSTRACT);
441 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
442 &accessibility_info) ;
443 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
445 g_type_add_interface_static (widget_type, GTK_TYPE_EXTENDED_LAYOUT,
453 child_property_notify_dispatcher (GObject *object,
457 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
461 gtk_widget_class_init (GtkWidgetClass *klass)
463 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
464 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
465 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
466 GtkBindingSet *binding_set;
468 gtk_widget_parent_class = g_type_class_peek_parent (klass);
470 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
471 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
472 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
473 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
474 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
475 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
476 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
477 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
478 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
479 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
480 quark_colormap = g_quark_from_static_string ("gtk-colormap");
481 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
482 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
483 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
484 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
485 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
486 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
487 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
489 style_property_spec_pool = g_param_spec_pool_new (FALSE);
490 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
491 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
492 cpn_context.dispatcher = child_property_notify_dispatcher;
493 _gtk_widget_child_property_notify_context = &cpn_context;
495 gobject_class->dispose = gtk_widget_dispose;
496 gobject_class->finalize = gtk_widget_finalize;
497 gobject_class->set_property = gtk_widget_set_property;
498 gobject_class->get_property = gtk_widget_get_property;
500 object_class->destroy = gtk_widget_real_destroy;
502 klass->activate_signal = 0;
503 klass->set_scroll_adjustments_signal = 0;
504 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
505 klass->show = gtk_widget_real_show;
506 klass->show_all = gtk_widget_show;
507 klass->hide = gtk_widget_real_hide;
508 klass->hide_all = gtk_widget_hide;
509 klass->map = gtk_widget_real_map;
510 klass->unmap = gtk_widget_real_unmap;
511 klass->realize = gtk_widget_real_realize;
512 klass->unrealize = gtk_widget_real_unrealize;
513 klass->size_request = gtk_widget_real_size_request;
514 klass->size_allocate = gtk_widget_real_size_allocate;
515 klass->state_changed = NULL;
516 klass->parent_set = NULL;
517 klass->hierarchy_changed = NULL;
518 klass->style_set = gtk_widget_real_style_set;
519 klass->direction_changed = gtk_widget_real_direction_changed;
520 klass->grab_notify = NULL;
521 klass->child_notify = NULL;
522 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
523 klass->grab_focus = gtk_widget_real_grab_focus;
524 klass->focus = gtk_widget_real_focus;
526 klass->button_press_event = NULL;
527 klass->button_release_event = NULL;
528 klass->motion_notify_event = NULL;
529 klass->delete_event = NULL;
530 klass->destroy_event = NULL;
531 klass->expose_event = NULL;
532 klass->key_press_event = gtk_widget_real_key_press_event;
533 klass->key_release_event = gtk_widget_real_key_release_event;
534 klass->enter_notify_event = NULL;
535 klass->leave_notify_event = NULL;
536 klass->configure_event = NULL;
537 klass->focus_in_event = gtk_widget_real_focus_in_event;
538 klass->focus_out_event = gtk_widget_real_focus_out_event;
539 klass->map_event = NULL;
540 klass->unmap_event = NULL;
541 klass->window_state_event = NULL;
542 klass->property_notify_event = _gtk_selection_property_notify;
543 klass->selection_clear_event = gtk_selection_clear;
544 klass->selection_request_event = _gtk_selection_request;
545 klass->selection_notify_event = _gtk_selection_notify;
546 klass->selection_received = NULL;
547 klass->proximity_in_event = NULL;
548 klass->proximity_out_event = NULL;
549 klass->drag_begin = NULL;
550 klass->drag_end = NULL;
551 klass->drag_data_delete = NULL;
552 klass->drag_leave = NULL;
553 klass->drag_motion = NULL;
554 klass->drag_drop = NULL;
555 klass->drag_data_received = NULL;
556 klass->screen_changed = NULL;
557 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
558 klass->grab_broken_event = NULL;
559 klass->query_tooltip = gtk_widget_real_query_tooltip;
561 klass->show_help = gtk_widget_real_show_help;
563 /* Accessibility support */
564 klass->get_accessible = gtk_widget_real_get_accessible;
566 klass->no_expose_event = NULL;
568 g_object_class_install_property (gobject_class,
570 g_param_spec_string ("name",
572 P_("The name of the widget"),
574 GTK_PARAM_READWRITE));
575 g_object_class_install_property (gobject_class,
577 g_param_spec_object ("parent",
579 P_("The parent widget of this widget. Must be a Container widget"),
581 GTK_PARAM_READWRITE));
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("width-request",
587 P_("Override for width request of the widget, or -1 if natural request should be used"),
591 GTK_PARAM_READWRITE));
592 g_object_class_install_property (gobject_class,
594 g_param_spec_int ("height-request",
595 P_("Height request"),
596 P_("Override for height request of the widget, or -1 if natural request should be used"),
600 GTK_PARAM_READWRITE));
601 g_object_class_install_property (gobject_class,
603 g_param_spec_boolean ("visible",
605 P_("Whether the widget is visible"),
607 GTK_PARAM_READWRITE));
608 g_object_class_install_property (gobject_class,
610 g_param_spec_boolean ("sensitive",
612 P_("Whether the widget responds to input"),
614 GTK_PARAM_READWRITE));
615 g_object_class_install_property (gobject_class,
617 g_param_spec_boolean ("app-paintable",
618 P_("Application paintable"),
619 P_("Whether the application will paint directly on the widget"),
621 GTK_PARAM_READWRITE));
622 g_object_class_install_property (gobject_class,
624 g_param_spec_boolean ("can-focus",
626 P_("Whether the widget can accept the input focus"),
628 GTK_PARAM_READWRITE));
629 g_object_class_install_property (gobject_class,
631 g_param_spec_boolean ("has-focus",
633 P_("Whether the widget has the input focus"),
635 GTK_PARAM_READWRITE));
636 g_object_class_install_property (gobject_class,
638 g_param_spec_boolean ("is-focus",
640 P_("Whether the widget is the focus widget within the toplevel"),
642 GTK_PARAM_READWRITE));
643 g_object_class_install_property (gobject_class,
645 g_param_spec_boolean ("can-default",
647 P_("Whether the widget can be the default widget"),
649 GTK_PARAM_READWRITE));
650 g_object_class_install_property (gobject_class,
652 g_param_spec_boolean ("has-default",
654 P_("Whether the widget is the default widget"),
656 GTK_PARAM_READWRITE));
657 g_object_class_install_property (gobject_class,
658 PROP_RECEIVES_DEFAULT,
659 g_param_spec_boolean ("receives-default",
660 P_("Receives default"),
661 P_("If TRUE, the widget will receive the default action when it is focused"),
663 GTK_PARAM_READWRITE));
664 g_object_class_install_property (gobject_class,
665 PROP_COMPOSITE_CHILD,
666 g_param_spec_boolean ("composite-child",
667 P_("Composite child"),
668 P_("Whether the widget is part of a composite widget"),
670 GTK_PARAM_READABLE));
671 g_object_class_install_property (gobject_class,
673 g_param_spec_object ("style",
675 P_("The style of the widget, which contains information about how it will look (colors etc)"),
677 GTK_PARAM_READWRITE));
678 g_object_class_install_property (gobject_class,
680 g_param_spec_flags ("events",
682 P_("The event mask that decides what kind of GdkEvents this widget gets"),
685 GTK_PARAM_READWRITE));
686 g_object_class_install_property (gobject_class,
687 PROP_EXTENSION_EVENTS,
688 g_param_spec_enum ("extension-events",
689 P_("Extension events"),
690 P_("The mask that decides what kind of extension events this widget gets"),
691 GDK_TYPE_EXTENSION_MODE,
692 GDK_EXTENSION_EVENTS_NONE,
693 GTK_PARAM_READWRITE));
694 g_object_class_install_property (gobject_class,
696 g_param_spec_boolean ("no-show-all",
698 P_("Whether gtk_widget_show_all() should not affect this widget"),
700 GTK_PARAM_READWRITE));
703 * GtkWidget:has-tooltip:
705 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
706 * A value of %TRUE indicates that @widget can have a tooltip, in this case
707 * the widget will be queried using #GtkWidget::query-tooltip to determine
708 * whether it will provide a tooltip or not.
710 * Note that setting this property to %TRUE for the first time will change
711 * the event masks of the GdkWindows of this widget to include leave-notify
712 * and motion-notify events. This cannot and will not be undone when the
713 * property is set to %FALSE again.
717 g_object_class_install_property (gobject_class,
719 g_param_spec_boolean ("has-tooltip",
721 P_("Whether this widget has a tooltip"),
723 GTK_PARAM_READWRITE));
725 * GtkWidget:tooltip-text:
727 * Sets the text of tooltip to be the given string.
729 * Also see gtk_tooltip_set_text().
731 * This is a convenience property which will take care of getting the
732 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
733 * will automatically be set to %TRUE and there will be taken care of
734 * #GtkWidget::query-tooltip in the default signal handler.
738 g_object_class_install_property (gobject_class,
740 g_param_spec_string ("tooltip-text",
742 P_("The contents of the tooltip for this widget"),
744 GTK_PARAM_READWRITE));
746 * GtkWidget:tooltip-markup:
748 * Sets the text of tooltip to be the given string, which is marked up
749 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
750 * Also see gtk_tooltip_set_markup().
752 * This is a convenience property which will take care of getting the
753 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
754 * will automatically be set to %TRUE and there will be taken care of
755 * #GtkWidget::query-tooltip in the default signal handler.
759 g_object_class_install_property (gobject_class,
761 g_param_spec_string ("tooltip-markup",
762 P_("Tooltip markup"),
763 P_("The contents of the tooltip for this widget"),
765 GTK_PARAM_READWRITE));
770 * The widget's window if it is realized, %NULL otherwise.
774 g_object_class_install_property (gobject_class,
776 g_param_spec_object ("window",
778 P_("The widget's window if it is realized"),
780 GTK_PARAM_READABLE));
783 * GtkWidget:double-buffered
785 * Whether or not the widget is double buffered.
789 g_object_class_install_property (gobject_class,
790 PROP_DOUBLE_BUFFERED,
791 g_param_spec_boolean ("double-buffered",
792 P_("Double Buffered"),
793 P_("Whether or not the widget is double buffered"),
795 GTK_PARAM_READWRITE));
799 * @widget: the object which received the signal.
801 widget_signals[SHOW] =
802 g_signal_new (I_("show"),
803 G_TYPE_FROM_CLASS (gobject_class),
805 G_STRUCT_OFFSET (GtkWidgetClass, show),
807 _gtk_marshal_VOID__VOID,
812 * @widget: the object which received the signal.
814 widget_signals[HIDE] =
815 g_signal_new (I_("hide"),
816 G_TYPE_FROM_CLASS (gobject_class),
818 G_STRUCT_OFFSET (GtkWidgetClass, hide),
820 _gtk_marshal_VOID__VOID,
825 * @widget: the object which received the signal.
827 widget_signals[MAP] =
828 g_signal_new (I_("map"),
829 G_TYPE_FROM_CLASS (gobject_class),
831 G_STRUCT_OFFSET (GtkWidgetClass, map),
833 _gtk_marshal_VOID__VOID,
838 * @widget: the object which received the signal.
840 widget_signals[UNMAP] =
841 g_signal_new (I_("unmap"),
842 G_TYPE_FROM_CLASS (gobject_class),
844 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
846 _gtk_marshal_VOID__VOID,
850 * GtkWidget::realize:
851 * @widget: the object which received the signal.
853 widget_signals[REALIZE] =
854 g_signal_new (I_("realize"),
855 G_TYPE_FROM_CLASS (gobject_class),
857 G_STRUCT_OFFSET (GtkWidgetClass, realize),
859 _gtk_marshal_VOID__VOID,
863 * GtkWidget::unrealize:
864 * @widget: the object which received the signal.
866 widget_signals[UNREALIZE] =
867 g_signal_new (I_("unrealize"),
868 G_TYPE_FROM_CLASS (gobject_class),
870 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
872 _gtk_marshal_VOID__VOID,
876 * GtkWidget::size-request:
877 * @widget: the object which received the signal.
880 widget_signals[SIZE_REQUEST] =
881 g_signal_new (I_("size-request"),
882 G_TYPE_FROM_CLASS (gobject_class),
884 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
886 _gtk_marshal_VOID__BOXED,
888 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
891 * GtkWidget::size-allocate:
892 * @widget: the object which received the signal.
895 widget_signals[SIZE_ALLOCATE] =
896 g_signal_new (I_("size-allocate"),
897 G_TYPE_FROM_CLASS (gobject_class),
899 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
901 _gtk_marshal_VOID__BOXED,
903 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
906 * GtkWidget::state-changed:
907 * @widget: the object which received the signal.
908 * @state: the previous state
910 * The ::state-changed signal is emitted when the widget state changes.
911 * See gtk_widget_get_state().
913 widget_signals[STATE_CHANGED] =
914 g_signal_new (I_("state-changed"),
915 G_TYPE_FROM_CLASS (gobject_class),
917 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
919 _gtk_marshal_VOID__ENUM,
921 GTK_TYPE_STATE_TYPE);
924 * GtkWidget::parent-set:
925 * @widget: the object on which the signal is emitted
926 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
927 * just got its initial parent.
929 * The ::parent-set signal is emitted when a new parent
930 * has been set on a widget.
932 widget_signals[PARENT_SET] =
933 g_signal_new (I_("parent-set"),
934 G_TYPE_FROM_CLASS (gobject_class),
936 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
938 _gtk_marshal_VOID__OBJECT,
943 * GtkWidget::hierarchy-changed:
944 * @widget: the object on which the signal is emitted
945 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
946 * if the widget was previously unanchored
948 * The ::hierarchy-changed signal is emitted when the
949 * anchored state of a widget changes. A widget is
950 * <firstterm>anchored</firstterm> when its toplevel
951 * ancestor is a #GtkWindow. This signal is emitted when
952 * a widget changes from un-anchored to anchored or vice-versa.
954 widget_signals[HIERARCHY_CHANGED] =
955 g_signal_new (I_("hierarchy-changed"),
956 G_TYPE_FROM_CLASS (gobject_class),
958 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
960 _gtk_marshal_VOID__OBJECT,
965 * GtkWidget::style-set:
966 * @widget: the object on which the signal is emitted
967 * @previous_style: (allow-none): the previous style, or %NULL if the widget
968 * just got its initial style
970 * The ::style-set signal is emitted when a new style has been set
971 * on a widget. Note that style-modifying functions like
972 * gtk_widget_modify_base() also cause this signal to be emitted.
974 widget_signals[STYLE_SET] =
975 g_signal_new (I_("style-set"),
976 G_TYPE_FROM_CLASS (gobject_class),
978 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
980 _gtk_marshal_VOID__OBJECT,
984 * GtkWidget::direction-changed:
985 * @widget: the object on which the signal is emitted
986 * @previous_direction: the previous text direction of @widget
988 * The ::direction-changed signal is emitted when the text direction
989 * of a widget changes.
991 widget_signals[DIRECTION_CHANGED] =
992 g_signal_new (I_("direction-changed"),
993 G_TYPE_FROM_CLASS (gobject_class),
995 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
997 _gtk_marshal_VOID__ENUM,
999 GTK_TYPE_TEXT_DIRECTION);
1002 * GtkWidget::grab-notify:
1003 * @widget: the object which received the signal
1004 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1005 * if it becomes unshadowed
1007 * The ::grab-notify signal is emitted when a widget becomes
1008 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1009 * another widget, or when it becomes unshadowed due to a grab
1012 * A widget is shadowed by a gtk_grab_add() when the topmost
1013 * grab widget in the grab stack of its window group is not
1016 widget_signals[GRAB_NOTIFY] =
1017 g_signal_new (I_("grab-notify"),
1018 G_TYPE_FROM_CLASS (gobject_class),
1020 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1022 _gtk_marshal_VOID__BOOLEAN,
1027 * GtkWidget::child-notify:
1028 * @widget: the object which received the signal
1029 * @pspec: the #GParamSpec of the changed child property
1031 * The ::child-notify signal is emitted for each
1032 * <link linkend="child-properties">child property</link> that has
1033 * changed on an object. The signal's detail holds the property name.
1035 widget_signals[CHILD_NOTIFY] =
1036 g_signal_new (I_("child-notify"),
1037 G_TYPE_FROM_CLASS (gobject_class),
1038 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1039 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1041 g_cclosure_marshal_VOID__PARAM,
1046 * GtkWidget::mnemonic-activate:
1047 * @widget: the object which received the signal.
1050 widget_signals[MNEMONIC_ACTIVATE] =
1051 g_signal_new (I_("mnemonic-activate"),
1052 G_TYPE_FROM_CLASS (gobject_class),
1054 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1055 _gtk_boolean_handled_accumulator, NULL,
1056 _gtk_marshal_BOOLEAN__BOOLEAN,
1061 * GtkWidget::grab-focus:
1062 * @widget: the object which received the signal.
1064 widget_signals[GRAB_FOCUS] =
1065 g_signal_new (I_("grab-focus"),
1066 G_TYPE_FROM_CLASS (gobject_class),
1067 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1068 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1070 _gtk_marshal_VOID__VOID,
1075 * @widget: the object which received the signal.
1078 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1080 widget_signals[FOCUS] =
1081 g_signal_new (I_("focus"),
1082 G_TYPE_FROM_CLASS (object_class),
1084 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1085 _gtk_boolean_handled_accumulator, NULL,
1086 _gtk_marshal_BOOLEAN__ENUM,
1088 GTK_TYPE_DIRECTION_TYPE);
1091 * GtkWidget::move-focus:
1092 * @widget: the object which received the signal.
1095 widget_signals[MOVE_FOCUS] =
1096 g_signal_new_class_handler (I_("move-focus"),
1097 G_TYPE_FROM_CLASS (object_class),
1098 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1099 G_CALLBACK (gtk_widget_real_move_focus),
1101 _gtk_marshal_VOID__ENUM,
1104 GTK_TYPE_DIRECTION_TYPE);
1107 * @widget: the object which received the signal.
1108 * @event: the #GdkEvent which triggered this signal
1110 * The GTK+ main loop will emit three signals for each GDK event delivered
1111 * to a widget: one generic ::event signal, another, more specific,
1112 * signal that matches the type of event delivered (e.g.
1113 * #GtkWidget::key-press-event) and finally a generic
1114 * #GtkWidget::event-after signal.
1116 * Returns: %TRUE to stop other handlers from being invoked for the event
1117 * and to cancel the emission of the second specific ::event signal.
1118 * %FALSE to propagate the event further and to allow the emission of
1119 * the second signal. The ::event-after signal is emitted regardless of
1122 widget_signals[EVENT] =
1123 g_signal_new (I_("event"),
1124 G_TYPE_FROM_CLASS (gobject_class),
1126 G_STRUCT_OFFSET (GtkWidgetClass, event),
1127 _gtk_boolean_handled_accumulator, NULL,
1128 _gtk_marshal_BOOLEAN__BOXED,
1130 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1133 * GtkWidget::event-after:
1134 * @widget: the object which received the signal.
1135 * @event: the #GdkEvent which triggered this signal
1137 * After the emission of the #GtkWidget::event signal and (optionally)
1138 * the second more specific signal, ::event-after will be emitted
1139 * regardless of the previous two signals handlers return values.
1142 widget_signals[EVENT_AFTER] =
1143 g_signal_new (I_("event-after"),
1144 G_TYPE_FROM_CLASS (gobject_class),
1148 _gtk_marshal_VOID__BOXED,
1150 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1153 * GtkWidget::button-press-event:
1154 * @widget: the object which received the signal.
1155 * @event: the #GdkEventButton which triggered this signal
1157 * The ::button-press-event signal will be emitted when a button
1158 * (typically from a mouse) is pressed.
1160 * To receive this signal, the #GdkWindow associated to the
1161 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1163 * This signal will be sent to the grab widget if there is one.
1165 * Returns: %TRUE to stop other handlers from being invoked for the event.
1166 * %FALSE to propagate the event further.
1168 widget_signals[BUTTON_PRESS_EVENT] =
1169 g_signal_new (I_("button-press-event"),
1170 G_TYPE_FROM_CLASS (gobject_class),
1172 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1173 _gtk_boolean_handled_accumulator, NULL,
1174 _gtk_marshal_BOOLEAN__BOXED,
1176 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1179 * GtkWidget::button-release-event:
1180 * @widget: the object which received the signal.
1181 * @event: the #GdkEventButton which triggered this signal
1183 * The ::button-release-event signal will be emitted when a button
1184 * (typically from a mouse) is released.
1186 * To receive this signal, the #GdkWindow associated to the
1187 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1189 * This signal will be sent to the grab widget if there is one.
1191 * Returns: %TRUE to stop other handlers from being invoked for the event.
1192 * %FALSE to propagate the event further.
1194 widget_signals[BUTTON_RELEASE_EVENT] =
1195 g_signal_new (I_("button-release-event"),
1196 G_TYPE_FROM_CLASS (gobject_class),
1198 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1199 _gtk_boolean_handled_accumulator, NULL,
1200 _gtk_marshal_BOOLEAN__BOXED,
1202 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1205 * GtkWidget::scroll-event:
1206 * @widget: the object which received the signal.
1207 * @event: the #GdkEventScroll which triggered this signal
1209 * The ::scroll-event signal is emitted when a button in the 4 to 7
1210 * range is pressed. Wheel mice are usually configured to generate
1211 * button press events for buttons 4 and 5 when the wheel is turned.
1213 * To receive this signal, the #GdkWindow associated to the widget needs
1214 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1216 * This signal will be sent to the grab widget if there is one.
1218 * Returns: %TRUE to stop other handlers from being invoked for the event.
1219 * %FALSE to propagate the event further.
1221 widget_signals[SCROLL_EVENT] =
1222 g_signal_new (I_("scroll-event"),
1223 G_TYPE_FROM_CLASS (gobject_class),
1225 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1226 _gtk_boolean_handled_accumulator, NULL,
1227 _gtk_marshal_BOOLEAN__BOXED,
1229 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1231 * GtkWidget::motion-notify-event:
1232 * @widget: the object which received the signal.
1233 * @event: the #GdkEventMotion which triggered this signal
1235 * The ::motion-notify-event signal is emitted when the pointer moves
1236 * over the widget's #GdkWindow.
1238 * To receive this signal, the #GdkWindow associated to the widget
1239 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1241 * This signal will be sent to the grab widget if there is one.
1243 * Returns: %TRUE to stop other handlers from being invoked for the event.
1244 * %FALSE to propagate the event further.
1246 widget_signals[MOTION_NOTIFY_EVENT] =
1247 g_signal_new (I_("motion-notify-event"),
1248 G_TYPE_FROM_CLASS (gobject_class),
1250 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1251 _gtk_boolean_handled_accumulator, NULL,
1252 _gtk_marshal_BOOLEAN__BOXED,
1254 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1257 * GtkWidget::composited-changed:
1258 * @widget: the object on which the signal is emitted
1260 * The ::composited-changed signal is emitted when the composited
1261 * status of @widget<!-- -->s screen changes.
1262 * See gdk_screen_is_composited().
1264 widget_signals[COMPOSITED_CHANGED] =
1265 g_signal_new (I_("composited-changed"),
1266 G_TYPE_FROM_CLASS (gobject_class),
1267 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1268 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1270 _gtk_marshal_VOID__VOID,
1274 * GtkWidget::keynav-failed:
1275 * @widget: the object which received the signal
1276 * @direction: the direction of movement
1278 * Gets emitted if keyboard navigation fails.
1279 * See gtk_widget_keynav_failed() for details.
1281 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1282 * if the emitting widget should try to handle the keyboard
1283 * navigation attempt in its parent container(s).
1287 widget_signals[KEYNAV_FAILED] =
1288 g_signal_new_class_handler (I_("keynav-failed"),
1289 G_TYPE_FROM_CLASS (gobject_class),
1291 G_CALLBACK (gtk_widget_real_keynav_failed),
1292 _gtk_boolean_handled_accumulator, NULL,
1293 _gtk_marshal_BOOLEAN__ENUM,
1295 GTK_TYPE_DIRECTION_TYPE);
1298 * GtkWidget::delete-event:
1299 * @widget: the object which received the signal
1300 * @event: the event which triggered this signal
1302 * The ::delete-event signal is emitted if a user requests that
1303 * a toplevel window is closed. The default handler for this signal
1304 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1305 * this signal will cause the window to be hidden instead, so that
1306 * it can later be shown again without reconstructing it.
1308 * Returns: %TRUE to stop other handlers from being invoked for the event.
1309 * %FALSE to propagate the event further.
1311 widget_signals[DELETE_EVENT] =
1312 g_signal_new (I_("delete-event"),
1313 G_TYPE_FROM_CLASS (gobject_class),
1315 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1316 _gtk_boolean_handled_accumulator, NULL,
1317 _gtk_marshal_BOOLEAN__BOXED,
1319 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1322 * GtkWidget::destroy-event:
1323 * @widget: the object which received the signal.
1324 * @event: the event which triggered this signal
1326 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1327 * You rarely get this signal, because most widgets disconnect themselves
1328 * from their window before they destroy it, so no widget owns the
1329 * window at destroy time.
1331 * To receive this signal, the #GdkWindow associated to the widget needs
1332 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1333 * automatically for all new windows.
1335 * Returns: %TRUE to stop other handlers from being invoked for the event.
1336 * %FALSE to propagate the event further.
1338 widget_signals[DESTROY_EVENT] =
1339 g_signal_new (I_("destroy-event"),
1340 G_TYPE_FROM_CLASS (gobject_class),
1342 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1343 _gtk_boolean_handled_accumulator, NULL,
1344 _gtk_marshal_BOOLEAN__BOXED,
1346 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1349 * GtkWidget::expose-event:
1350 * @widget: the object which received the signal.
1351 * @event: the #GdkEventExpose which triggered this signal
1353 * The ::expose-event signal is emitted when an area of a previously
1354 * obscured #GdkWindow is made visible and needs to be redrawn.
1355 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1358 * To receive this signal, the #GdkWindow associated to the widget needs
1359 * to enable the #GDK_EXPOSURE_MASK mask.
1361 * Returns: %TRUE to stop other handlers from being invoked for the event.
1362 * %FALSE to propagate the event further.
1364 widget_signals[EXPOSE_EVENT] =
1365 g_signal_new (I_("expose-event"),
1366 G_TYPE_FROM_CLASS (gobject_class),
1368 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1369 _gtk_boolean_handled_accumulator, NULL,
1370 _gtk_marshal_BOOLEAN__BOXED,
1372 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1375 * GtkWidget::key-press-event:
1376 * @widget: the object which received the signal
1377 * @event: the #GdkEventKey which triggered this signal
1379 * The ::key-press-event signal is emitted when a key is pressed.
1381 * To receive this signal, the #GdkWindow associated to the widget needs
1382 * to enable the #GDK_KEY_PRESS_MASK mask.
1384 * This signal will be sent to the grab widget if there is one.
1386 * Returns: %TRUE to stop other handlers from being invoked for the event.
1387 * %FALSE to propagate the event further.
1389 widget_signals[KEY_PRESS_EVENT] =
1390 g_signal_new (I_("key-press-event"),
1391 G_TYPE_FROM_CLASS (gobject_class),
1393 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1394 _gtk_boolean_handled_accumulator, NULL,
1395 _gtk_marshal_BOOLEAN__BOXED,
1397 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1400 * GtkWidget::key-release-event:
1401 * @widget: the object which received the signal
1402 * @event: the #GdkEventKey which triggered this signal
1404 * The ::key-release-event signal is emitted when a key is pressed.
1406 * To receive this signal, the #GdkWindow associated to the widget needs
1407 * to enable the #GDK_KEY_RELEASE_MASK mask.
1409 * This signal will be sent to the grab widget if there is one.
1411 * Returns: %TRUE to stop other handlers from being invoked for the event.
1412 * %FALSE to propagate the event further.
1414 widget_signals[KEY_RELEASE_EVENT] =
1415 g_signal_new (I_("key-release-event"),
1416 G_TYPE_FROM_CLASS (gobject_class),
1418 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1419 _gtk_boolean_handled_accumulator, NULL,
1420 _gtk_marshal_BOOLEAN__BOXED,
1422 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1425 * GtkWidget::enter-notify-event:
1426 * @widget: the object which received the signal
1427 * @event: the #GdkEventCrossing which triggered this signal
1429 * The ::enter-notify-event will be emitted when the pointer enters
1430 * the @widget's window.
1432 * To receive this signal, the #GdkWindow associated to the widget needs
1433 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1435 * This signal will be sent to the grab widget if there is one.
1437 * Returns: %TRUE to stop other handlers from being invoked for the event.
1438 * %FALSE to propagate the event further.
1440 widget_signals[ENTER_NOTIFY_EVENT] =
1441 g_signal_new (I_("enter-notify-event"),
1442 G_TYPE_FROM_CLASS (gobject_class),
1444 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1445 _gtk_boolean_handled_accumulator, NULL,
1446 _gtk_marshal_BOOLEAN__BOXED,
1448 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1451 * GtkWidget::leave-notify-event:
1452 * @widget: the object which received the signal
1453 * @event: the #GdkEventCrossing which triggered this signal
1455 * The ::leave-notify-event will be emitted when the pointer leaves
1456 * the @widget's window.
1458 * To receive this signal, the #GdkWindow associated to the widget needs
1459 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1461 * This signal will be sent to the grab widget if there is one.
1463 * Returns: %TRUE to stop other handlers from being invoked for the event.
1464 * %FALSE to propagate the event further.
1466 widget_signals[LEAVE_NOTIFY_EVENT] =
1467 g_signal_new (I_("leave-notify-event"),
1468 G_TYPE_FROM_CLASS (gobject_class),
1470 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1471 _gtk_boolean_handled_accumulator, NULL,
1472 _gtk_marshal_BOOLEAN__BOXED,
1474 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1477 * GtkWidget::configure-event
1478 * @widget: the object which received the signal
1479 * @event: the #GdkEventConfigure which triggered this signal
1481 * The ::configure-event signal will be emitted when the size, position or
1482 * stacking of the @widget's window has changed.
1484 * To receive this signal, the #GdkWindow associated to the widget needs
1485 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1486 * automatically for all new windows.
1488 * Returns: %TRUE to stop other handlers from being invoked for the event.
1489 * %FALSE to propagate the event further.
1491 widget_signals[CONFIGURE_EVENT] =
1492 g_signal_new (I_("configure-event"),
1493 G_TYPE_FROM_CLASS (gobject_class),
1495 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1496 _gtk_boolean_handled_accumulator, NULL,
1497 _gtk_marshal_BOOLEAN__BOXED,
1499 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1502 * GtkWidget::focus-in-event
1503 * @widget: the object which received the signal
1504 * @event: the #GdkEventFocus which triggered this signal
1506 * The ::focus-in-event signal will be emitted when the keyboard focus
1507 * enters the @widget's window.
1509 * To receive this signal, the #GdkWindow associated to the widget needs
1510 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1512 * Returns: %TRUE to stop other handlers from being invoked for the event.
1513 * %FALSE to propagate the event further.
1515 widget_signals[FOCUS_IN_EVENT] =
1516 g_signal_new (I_("focus-in-event"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1519 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1520 _gtk_boolean_handled_accumulator, NULL,
1521 _gtk_marshal_BOOLEAN__BOXED,
1523 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1526 * GtkWidget::focus-out-event
1527 * @widget: the object which received the signal
1528 * @event: the #GdkEventFocus which triggered this signal
1530 * The ::focus-out-event signal will be emitted when the keyboard focus
1531 * leaves the @widget's window.
1533 * To receive this signal, the #GdkWindow associated to the widget needs
1534 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1536 * Returns: %TRUE to stop other handlers from being invoked for the event.
1537 * %FALSE to propagate the event further.
1539 widget_signals[FOCUS_OUT_EVENT] =
1540 g_signal_new (I_("focus-out-event"),
1541 G_TYPE_FROM_CLASS (gobject_class),
1543 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1544 _gtk_boolean_handled_accumulator, NULL,
1545 _gtk_marshal_BOOLEAN__BOXED,
1547 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1550 * GtkWidget::map-event
1551 * @widget: the object which received the signal
1552 * @event: the #GdkEventAny which triggered this signal
1554 * The ::map-event signal will be emitted when the @widget's window is
1555 * mapped. A window is mapped when it becomes visible on the screen.
1557 * To receive this signal, the #GdkWindow associated to the widget needs
1558 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1559 * automatically for all new windows.
1561 * Returns: %TRUE to stop other handlers from being invoked for the event.
1562 * %FALSE to propagate the event further.
1564 widget_signals[MAP_EVENT] =
1565 g_signal_new (I_("map-event"),
1566 G_TYPE_FROM_CLASS (gobject_class),
1568 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1569 _gtk_boolean_handled_accumulator, NULL,
1570 _gtk_marshal_BOOLEAN__BOXED,
1572 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1575 * GtkWidget::unmap-event
1576 * @widget: the object which received the signal
1577 * @event: the #GdkEventAny which triggered this signal
1579 * The ::unmap-event signal will be emitted when the @widget's window is
1580 * unmapped. A window is unmapped when it becomes invisible on the screen.
1582 * To receive this signal, the #GdkWindow associated to the widget needs
1583 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1584 * automatically for all new windows.
1586 * Returns: %TRUE to stop other handlers from being invoked for the event.
1587 * %FALSE to propagate the event further.
1589 widget_signals[UNMAP_EVENT] =
1590 g_signal_new (I_("unmap-event"),
1591 G_TYPE_FROM_CLASS (gobject_class),
1593 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1594 _gtk_boolean_handled_accumulator, NULL,
1595 _gtk_marshal_BOOLEAN__BOXED,
1597 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1600 * GtkWidget::property-notify-event
1601 * @widget: the object which received the signal
1602 * @event: the #GdkEventProperty which triggered this signal
1604 * The ::property-notify-event signal will be emitted when a property on
1605 * the @widget's window has been changed or deleted.
1607 * To receive this signal, the #GdkWindow associated to the widget needs
1608 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1610 * Returns: %TRUE to stop other handlers from being invoked for the event.
1611 * %FALSE to propagate the event further.
1613 widget_signals[PROPERTY_NOTIFY_EVENT] =
1614 g_signal_new (I_("property-notify-event"),
1615 G_TYPE_FROM_CLASS (gobject_class),
1617 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1618 _gtk_boolean_handled_accumulator, NULL,
1619 _gtk_marshal_BOOLEAN__BOXED,
1621 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1624 * GtkWidget::selection-clear-event
1625 * @widget: the object which received the signal
1626 * @event: the #GdkEventSelection which triggered this signal
1628 * The ::selection-clear-event signal will be emitted when the
1629 * the @widget's window has lost ownership of a selection.
1631 * Returns: %TRUE to stop other handlers from being invoked for the event.
1632 * %FALSE to propagate the event further.
1634 widget_signals[SELECTION_CLEAR_EVENT] =
1635 g_signal_new (I_("selection-clear-event"),
1636 G_TYPE_FROM_CLASS (gobject_class),
1638 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1639 _gtk_boolean_handled_accumulator, NULL,
1640 _gtk_marshal_BOOLEAN__BOXED,
1642 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1645 * GtkWidget::selection-request-event
1646 * @widget: the object which received the signal
1647 * @event: the #GdkEventSelection which triggered this signal
1649 * The ::selection-request-event signal will be emitted when
1650 * another client requests ownership of the selection owned by
1651 * the @widget's window.
1653 * Returns: %TRUE to stop other handlers from being invoked for the event.
1654 * %FALSE to propagate the event further.
1656 widget_signals[SELECTION_REQUEST_EVENT] =
1657 g_signal_new (I_("selection-request-event"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1661 _gtk_boolean_handled_accumulator, NULL,
1662 _gtk_marshal_BOOLEAN__BOXED,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkWidget::selection-notify-event:
1668 * @widget: the object which received the signal.
1671 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1673 widget_signals[SELECTION_NOTIFY_EVENT] =
1674 g_signal_new (I_("selection-notify-event"),
1675 G_TYPE_FROM_CLASS (gobject_class),
1677 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1678 _gtk_boolean_handled_accumulator, NULL,
1679 _gtk_marshal_BOOLEAN__BOXED,
1681 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1684 * GtkWidget::selection-received:
1685 * @widget: the object which received the signal.
1689 widget_signals[SELECTION_RECEIVED] =
1690 g_signal_new (I_("selection-received"),
1691 G_TYPE_FROM_CLASS (gobject_class),
1693 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1695 _gtk_marshal_VOID__BOXED_UINT,
1697 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1701 * GtkWidget::selection-get:
1702 * @widget: the object which received the signal.
1707 widget_signals[SELECTION_GET] =
1708 g_signal_new (I_("selection-get"),
1709 G_TYPE_FROM_CLASS (gobject_class),
1711 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1713 _gtk_marshal_VOID__BOXED_UINT_UINT,
1715 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1720 * GtkWidget::proximity-in-event
1721 * @widget: the object which received the signal
1722 * @event: the #GdkEventProximity which triggered this signal
1724 * To receive this signal the #GdkWindow associated to the widget needs
1725 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1727 * This signal will be sent to the grab widget if there is one.
1729 * Returns: %TRUE to stop other handlers from being invoked for the event.
1730 * %FALSE to propagate the event further.
1732 widget_signals[PROXIMITY_IN_EVENT] =
1733 g_signal_new (I_("proximity-in-event"),
1734 G_TYPE_FROM_CLASS (gobject_class),
1736 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1737 _gtk_boolean_handled_accumulator, NULL,
1738 _gtk_marshal_BOOLEAN__BOXED,
1740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1743 * GtkWidget::proximity-out-event
1744 * @widget: the object which received the signal
1745 * @event: the #GdkEventProximity which triggered this signal
1747 * To receive this signal the #GdkWindow associated to the widget needs
1748 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1750 * This signal will be sent to the grab widget if there is one.
1752 * Returns: %TRUE to stop other handlers from being invoked for the event.
1753 * %FALSE to propagate the event further.
1755 widget_signals[PROXIMITY_OUT_EVENT] =
1756 g_signal_new (I_("proximity-out-event"),
1757 G_TYPE_FROM_CLASS (gobject_class),
1759 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1760 _gtk_boolean_handled_accumulator, NULL,
1761 _gtk_marshal_BOOLEAN__BOXED,
1763 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1766 * GtkWidget::drag-leave:
1767 * @widget: the object which received the signal.
1768 * @drag_context: the drag context
1769 * @time: the timestamp of the motion event
1771 * The ::drag-leave signal is emitted on the drop site when the cursor
1772 * leaves the widget. A typical reason to connect to this signal is to
1773 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1774 * with gtk_drag_unhighlight()
1776 widget_signals[DRAG_LEAVE] =
1777 g_signal_new (I_("drag-leave"),
1778 G_TYPE_FROM_CLASS (gobject_class),
1780 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1782 _gtk_marshal_VOID__OBJECT_UINT,
1784 GDK_TYPE_DRAG_CONTEXT,
1788 * GtkWidget::drag-begin:
1789 * @widget: the object which received the signal
1790 * @drag_context: the drag context
1792 * The ::drag-begin signal is emitted on the drag source when a drag is
1793 * started. A typical reason to connect to this signal is to set up a
1794 * custom drag icon with gtk_drag_source_set_icon().
1796 * Note that some widgets set up a drag icon in the default handler of
1797 * this signal, so you may have to use g_signal_connect_after() to
1798 * override what the default handler did.
1800 widget_signals[DRAG_BEGIN] =
1801 g_signal_new (I_("drag-begin"),
1802 G_TYPE_FROM_CLASS (gobject_class),
1804 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1806 _gtk_marshal_VOID__OBJECT,
1808 GDK_TYPE_DRAG_CONTEXT);
1811 * GtkWidget::drag-end:
1812 * @widget: the object which received the signal
1813 * @drag_context: the drag context
1815 * The ::drag-end signal is emitted on the drag source when a drag is
1816 * finished. A typical reason to connect to this signal is to undo
1817 * things done in #GtkWidget::drag-begin.
1819 widget_signals[DRAG_END] =
1820 g_signal_new (I_("drag-end"),
1821 G_TYPE_FROM_CLASS (gobject_class),
1823 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1825 _gtk_marshal_VOID__OBJECT,
1827 GDK_TYPE_DRAG_CONTEXT);
1830 * GtkWidget::drag-data-delete:
1831 * @widget: the object which received the signal
1832 * @drag_context: the drag context
1834 * The ::drag-data-delete signal is emitted on the drag source when a drag
1835 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1836 * handler is responsible for deleting the data that has been dropped. What
1837 * "delete" means depends on the context of the drag operation.
1839 widget_signals[DRAG_DATA_DELETE] =
1840 g_signal_new (I_("drag-data-delete"),
1841 G_TYPE_FROM_CLASS (gobject_class),
1843 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1845 _gtk_marshal_VOID__OBJECT,
1847 GDK_TYPE_DRAG_CONTEXT);
1850 * GtkWidget::drag-failed:
1851 * @widget: the object which received the signal
1852 * @drag_context: the drag context
1853 * @result: the result of the drag operation
1855 * The ::drag-failed signal is emitted on the drag source when a drag has
1856 * failed. The signal handler may hook custom code to handle a failed DND
1857 * operation based on the type of error, it returns %TRUE is the failure has
1858 * been already handled (not showing the default "drag operation failed"
1859 * animation), otherwise it returns %FALSE.
1861 * Return value: %TRUE if the failed drag operation has been already handled.
1865 widget_signals[DRAG_FAILED] =
1866 g_signal_new (I_("drag-failed"),
1867 G_TYPE_FROM_CLASS (gobject_class),
1869 0, _gtk_boolean_handled_accumulator, NULL,
1870 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1872 GDK_TYPE_DRAG_CONTEXT,
1873 GTK_TYPE_DRAG_RESULT);
1876 * GtkWidget::drag-motion:
1877 * @widget: the object which received the signal
1878 * @drag_context: the drag context
1879 * @x: the x coordinate of the current cursor position
1880 * @y: the y coordinate of the current cursor position
1881 * @time: the timestamp of the motion event
1882 * @returns: whether the cursor position is in a drop zone
1884 * The drag-motion signal is emitted on the drop site when the user
1885 * moves the cursor over the widget during a drag. The signal handler
1886 * must determine whether the cursor position is in a drop zone or not.
1887 * If it is not in a drop zone, it returns %FALSE and no further processing
1888 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1889 * handler is responsible for providing the necessary information for
1890 * displaying feedback to the user, by calling gdk_drag_status().
1892 * If the decision whether the drop will be accepted or rejected can't be
1893 * made based solely on the cursor position and the type of the data, the
1894 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1895 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1896 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1897 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1898 * when using the drag-motion signal that way.
1900 * Also note that there is no drag-enter signal. The drag receiver has to
1901 * keep track of whether he has received any drag-motion signals since the
1902 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1903 * an "enter" signal. Upon an "enter", the handler will typically highlight
1904 * the drop site with gtk_drag_highlight().
1907 * drag_motion (GtkWidget *widget,
1908 * GdkDragContext *context,
1915 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1917 * if (!private_data->drag_highlight)
1919 * private_data->drag_highlight = 1;
1920 * gtk_drag_highlight (widget);
1923 * target = gtk_drag_dest_find_target (widget, context, NULL);
1924 * if (target == GDK_NONE)
1925 * gdk_drag_status (context, 0, time);
1928 * private_data->pending_status = context->suggested_action;
1929 * gtk_drag_get_data (widget, context, target, time);
1936 * drag_data_received (GtkWidget *widget,
1937 * GdkDragContext *context,
1940 * GtkSelectionData *selection_data,
1944 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1946 * if (private_data->suggested_action)
1948 * private_data->suggested_action = 0;
1950 * /* We are getting this data due to a request in drag_motion,
1951 * * rather than due to a request in drag_drop, so we are just
1952 * * supposed to call gdk_drag_status (), not actually paste in
1955 * str = gtk_selection_data_get_text (selection_data);
1956 * if (!data_is_acceptable (str))
1957 * gdk_drag_status (context, 0, time);
1959 * gdk_drag_status (context, private_data->suggested_action, time);
1963 * /* accept the drop */
1968 widget_signals[DRAG_MOTION] =
1969 g_signal_new (I_("drag-motion"),
1970 G_TYPE_FROM_CLASS (gobject_class),
1972 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1973 _gtk_boolean_handled_accumulator, NULL,
1974 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1976 GDK_TYPE_DRAG_CONTEXT,
1982 * GtkWidget::drag-drop:
1983 * @widget: the object which received the signal
1984 * @drag_context: the drag context
1985 * @x: the x coordinate of the current cursor position
1986 * @y: the y coordinate of the current cursor position
1987 * @time: the timestamp of the motion event
1988 * @returns: whether the cursor position is in a drop zone
1990 * The ::drag-drop signal is emitted on the drop site when the user drops
1991 * the data onto the widget. The signal handler must determine whether
1992 * the cursor position is in a drop zone or not. If it is not in a drop
1993 * zone, it returns %FALSE and no further processing is necessary.
1994 * Otherwise, the handler returns %TRUE. In this case, the handler must
1995 * ensure that gtk_drag_finish() is called to let the source know that
1996 * the drop is done. The call to gtk_drag_finish() can be done either
1997 * directly or in a #GtkWidget::drag-data-received handler which gets
1998 * triggered by calling gtk_drag_get_data() to receive the data for one
1999 * or more of the supported targets.
2001 widget_signals[DRAG_DROP] =
2002 g_signal_new (I_("drag-drop"),
2003 G_TYPE_FROM_CLASS (gobject_class),
2005 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2006 _gtk_boolean_handled_accumulator, NULL,
2007 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2009 GDK_TYPE_DRAG_CONTEXT,
2015 * GtkWidget::drag-data-get:
2016 * @widget: the object which received the signal
2017 * @drag_context: the drag context
2018 * @data: the #GtkSelectionData to be filled with the dragged data
2019 * @info: the info that has been registered with the target in the
2021 * @time: the timestamp at which the data was requested
2023 * The ::drag-data-get signal is emitted on the drag source when the drop
2024 * site requests the data which is dragged. It is the responsibility of
2025 * the signal handler to fill @data with the data in the format which
2026 * is indicated by @info. See gtk_selection_data_set() and
2027 * gtk_selection_data_set_text().
2029 widget_signals[DRAG_DATA_GET] =
2030 g_signal_new (I_("drag-data-get"),
2031 G_TYPE_FROM_CLASS (gobject_class),
2033 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2035 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2037 GDK_TYPE_DRAG_CONTEXT,
2038 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2043 * GtkWidget::drag-data-received:
2044 * @widget: the object which received the signal
2045 * @drag_context: the drag context
2046 * @x: where the drop happened
2047 * @y: where the drop happened
2048 * @data: the received data
2049 * @info: the info that has been registered with the target in the
2051 * @time: the timestamp at which the data was received
2053 * The ::drag-data-received signal is emitted on the drop site when the
2054 * dragged data has been received. If the data was received in order to
2055 * determine whether the drop will be accepted, the handler is expected
2056 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2057 * If the data was received in response to a #GtkWidget::drag-drop signal
2058 * (and this is the last target to be received), the handler for this
2059 * signal is expected to process the received data and then call
2060 * gtk_drag_finish(), setting the @success parameter depending on whether
2061 * the data was processed successfully.
2063 * The handler may inspect and modify @drag_context->action before calling
2064 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2065 * following example:
2068 * drag_data_received (GtkWidget *widget,
2069 * GdkDragContext *drag_context,
2072 * GtkSelectionData *data,
2076 * if ((data->length >= 0) && (data->format == 8))
2078 * if (drag_context->action == GDK_ACTION_ASK)
2080 * GtkWidget *dialog;
2083 * dialog = gtk_message_dialog_new (NULL,
2084 * GTK_DIALOG_MODAL |
2085 * GTK_DIALOG_DESTROY_WITH_PARENT,
2087 * GTK_BUTTONS_YES_NO,
2088 * "Move the data ?\n");
2089 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2090 * gtk_widget_destroy (dialog);
2092 * if (response == GTK_RESPONSE_YES)
2093 * drag_context->action = GDK_ACTION_MOVE;
2095 * drag_context->action = GDK_ACTION_COPY;
2098 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2102 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2106 widget_signals[DRAG_DATA_RECEIVED] =
2107 g_signal_new (I_("drag-data-received"),
2108 G_TYPE_FROM_CLASS (gobject_class),
2110 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2112 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2114 GDK_TYPE_DRAG_CONTEXT,
2117 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2122 * GtkWidget::visibility-notify-event:
2123 * @widget: the object which received the signal
2124 * @event: the #GdkEventVisibility which triggered this signal
2126 * The ::visibility-notify-event will be emitted when the @widget's window
2127 * is obscured or unobscured.
2129 * To receive this signal the #GdkWindow associated to the widget needs
2130 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2132 * Returns: %TRUE to stop other handlers from being invoked for the event.
2133 * %FALSE to propagate the event further.
2135 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2136 g_signal_new (I_("visibility-notify-event"),
2137 G_TYPE_FROM_CLASS (gobject_class),
2139 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2140 _gtk_boolean_handled_accumulator, NULL,
2141 _gtk_marshal_BOOLEAN__BOXED,
2143 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2146 * GtkWidget::client-event:
2147 * @widget: the object which received the signal
2148 * @event: the #GdkEventClient which triggered this signal
2150 * The ::client-event will be emitted when the @widget's window
2151 * receives a message (via a ClientMessage event) from another
2154 * Returns: %TRUE to stop other handlers from being invoked for
2155 * the event. %FALSE to propagate the event further.
2157 widget_signals[CLIENT_EVENT] =
2158 g_signal_new (I_("client-event"),
2159 G_TYPE_FROM_CLASS (gobject_class),
2161 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2162 _gtk_boolean_handled_accumulator, NULL,
2163 _gtk_marshal_BOOLEAN__BOXED,
2165 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2168 * GtkWidget::no-expose-event:
2169 * @widget: the object which received the signal
2170 * @event: the #GdkEventNoExpose which triggered this signal
2172 * The ::no-expose-event will be emitted when the @widget's window is
2173 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2174 * gdk_window_copy_area()) which was completely unobscured. If the source
2175 * window was partially obscured #GdkEventExpose events will be generated
2178 * Returns: %TRUE to stop other handlers from being invoked for the event.
2179 * %FALSE to propagate the event further.
2181 widget_signals[NO_EXPOSE_EVENT] =
2182 g_signal_new (I_("no-expose-event"),
2183 G_TYPE_FROM_CLASS (gobject_class),
2185 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2186 _gtk_boolean_handled_accumulator, NULL,
2187 _gtk_marshal_BOOLEAN__BOXED,
2189 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2192 * GtkWidget::window-state-event:
2193 * @widget: the object which received the signal
2194 * @event: the #GdkEventWindowState which triggered this signal
2196 * The ::window-state-event will be emitted when the state of the
2197 * toplevel window associated to the @widget changes.
2199 * To receive this signal the #GdkWindow associated to the widget
2200 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2201 * this mask automatically for all new windows.
2203 * Returns: %TRUE to stop other handlers from being invoked for the
2204 * event. %FALSE to propagate the event further.
2206 widget_signals[WINDOW_STATE_EVENT] =
2207 g_signal_new (I_("window-state-event"),
2208 G_TYPE_FROM_CLASS (gobject_class),
2210 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2211 _gtk_boolean_handled_accumulator, NULL,
2212 _gtk_marshal_BOOLEAN__BOXED,
2214 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2217 * GtkWidget::damage-event:
2218 * @widget: the object which received the signal
2219 * @event: the #GdkEventExpose event
2221 * Emitted when a redirected window belonging to @widget gets drawn into.
2222 * The region/area members of the event shows what area of the redirected
2223 * drawable was drawn into.
2225 * Returns: %TRUE to stop other handlers from being invoked for the event.
2226 * %FALSE to propagate the event further.
2230 widget_signals[DAMAGE_EVENT] =
2231 g_signal_new (I_("damage-event"),
2232 G_TYPE_FROM_CLASS (gobject_class),
2235 _gtk_boolean_handled_accumulator, NULL,
2236 _gtk_marshal_BOOLEAN__BOXED,
2238 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2240 * GtkWidget::grab-broken-event:
2241 * @widget: the object which received the signal
2242 * @event: the #GdkEventGrabBroken event
2244 * Emitted when a pointer or keyboard grab on a window belonging
2245 * to @widget gets broken.
2247 * On X11, this happens when the grab window becomes unviewable
2248 * (i.e. it or one of its ancestors is unmapped), or if the same
2249 * application grabs the pointer or keyboard again.
2251 * Returns: %TRUE to stop other handlers from being invoked for
2252 * the event. %FALSE to propagate the event further.
2256 widget_signals[GRAB_BROKEN] =
2257 g_signal_new (I_("grab-broken-event"),
2258 G_TYPE_FROM_CLASS (gobject_class),
2260 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2261 _gtk_boolean_handled_accumulator, NULL,
2262 _gtk_marshal_BOOLEAN__BOXED,
2264 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2266 * GtkWidget::query-tooltip:
2267 * @widget: the object which received the signal
2268 * @x: the x coordinate of the cursor position where the request has
2269 * been emitted, relative to @widget->window
2270 * @y: the y coordinate of the cursor position where the request has
2271 * been emitted, relative to @widget->window
2272 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2273 * @tooltip: a #GtkTooltip
2275 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2276 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2277 * focus in keyboard mode.
2279 * Using the given coordinates, the signal handler should determine
2280 * whether a tooltip should be shown for @widget. If this is the case
2281 * %TRUE should be returned, %FALSE otherwise. Note that if
2282 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2283 * should not be used.
2285 * The signal handler is free to manipulate @tooltip with the therefore
2286 * destined function calls.
2288 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2292 widget_signals[QUERY_TOOLTIP] =
2293 g_signal_new (I_("query-tooltip"),
2294 G_TYPE_FROM_CLASS (gobject_class),
2296 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2297 _gtk_boolean_handled_accumulator, NULL,
2298 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2306 * GtkWidget::popup-menu
2307 * @widget: the object which received the signal
2309 * This signal gets emitted whenever a widget should pop up a context
2310 * menu. This usually happens through the standard key binding mechanism;
2311 * by pressing a certain key while a widget is focused, the user can cause
2312 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2313 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2314 * for an example of how to use this signal.
2316 * Returns: %TRUE if a menu was activated
2318 widget_signals[POPUP_MENU] =
2319 g_signal_new (I_("popup-menu"),
2320 G_TYPE_FROM_CLASS (gobject_class),
2321 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2322 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2323 _gtk_boolean_handled_accumulator, NULL,
2324 _gtk_marshal_BOOLEAN__VOID,
2328 * GtkWidget::show-help:
2329 * @widget: the object which received the signal.
2332 widget_signals[SHOW_HELP] =
2333 g_signal_new (I_("show-help"),
2334 G_TYPE_FROM_CLASS (gobject_class),
2335 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2336 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2337 _gtk_boolean_handled_accumulator, NULL,
2338 _gtk_marshal_BOOLEAN__ENUM,
2340 GTK_TYPE_WIDGET_HELP_TYPE);
2343 * GtkWidget::accel-closures-changed:
2344 * @widget: the object which received the signal.
2346 widget_signals[ACCEL_CLOSURES_CHANGED] =
2347 g_signal_new (I_("accel-closures-changed"),
2348 G_TYPE_FROM_CLASS (gobject_class),
2352 _gtk_marshal_VOID__VOID,
2356 * GtkWidget::screen-changed:
2357 * @widget: the object on which the signal is emitted
2358 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2359 * widget was not associated with a screen before
2361 * The ::screen-changed signal gets emitted when the
2362 * screen of a widget has changed.
2364 widget_signals[SCREEN_CHANGED] =
2365 g_signal_new (I_("screen-changed"),
2366 G_TYPE_FROM_CLASS (gobject_class),
2368 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2370 _gtk_marshal_VOID__OBJECT,
2375 * GtkWidget::can-activate-accel:
2376 * @widget: the object which received the signal
2377 * @signal_id: the ID of a signal installed on @widget
2379 * Determines whether an accelerator that activates the signal
2380 * identified by @signal_id can currently be activated.
2381 * This signal is present to allow applications and derived
2382 * widgets to override the default #GtkWidget handling
2383 * for determining whether an accelerator can be activated.
2385 * Returns: %TRUE if the signal can be activated.
2387 widget_signals[CAN_ACTIVATE_ACCEL] =
2388 g_signal_new (I_("can-activate-accel"),
2389 G_TYPE_FROM_CLASS (gobject_class),
2391 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2392 _gtk_boolean_handled_accumulator, NULL,
2393 _gtk_marshal_BOOLEAN__UINT,
2394 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2396 binding_set = gtk_binding_set_by_class (klass);
2397 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2399 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2402 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2404 GTK_TYPE_WIDGET_HELP_TYPE,
2405 GTK_WIDGET_HELP_TOOLTIP);
2406 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2408 GTK_TYPE_WIDGET_HELP_TYPE,
2409 GTK_WIDGET_HELP_TOOLTIP);
2410 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2412 GTK_TYPE_WIDGET_HELP_TYPE,
2413 GTK_WIDGET_HELP_WHATS_THIS);
2414 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2416 GTK_TYPE_WIDGET_HELP_TYPE,
2417 GTK_WIDGET_HELP_WHATS_THIS);
2419 gtk_widget_class_install_style_property (klass,
2420 g_param_spec_boolean ("interior-focus",
2421 P_("Interior Focus"),
2422 P_("Whether to draw the focus indicator inside widgets"),
2424 GTK_PARAM_READABLE));
2426 gtk_widget_class_install_style_property (klass,
2427 g_param_spec_int ("focus-line-width",
2428 P_("Focus linewidth"),
2429 P_("Width, in pixels, of the focus indicator line"),
2431 GTK_PARAM_READABLE));
2433 gtk_widget_class_install_style_property (klass,
2434 g_param_spec_string ("focus-line-pattern",
2435 P_("Focus line dash pattern"),
2436 P_("Dash pattern used to draw the focus indicator"),
2438 GTK_PARAM_READABLE));
2439 gtk_widget_class_install_style_property (klass,
2440 g_param_spec_int ("focus-padding",
2441 P_("Focus padding"),
2442 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2444 GTK_PARAM_READABLE));
2445 gtk_widget_class_install_style_property (klass,
2446 g_param_spec_boxed ("cursor-color",
2448 P_("Color with which to draw insertion cursor"),
2450 GTK_PARAM_READABLE));
2451 gtk_widget_class_install_style_property (klass,
2452 g_param_spec_boxed ("secondary-cursor-color",
2453 P_("Secondary cursor color"),
2454 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2456 GTK_PARAM_READABLE));
2457 gtk_widget_class_install_style_property (klass,
2458 g_param_spec_float ("cursor-aspect-ratio",
2459 P_("Cursor line aspect ratio"),
2460 P_("Aspect ratio with which to draw insertion cursor"),
2462 GTK_PARAM_READABLE));
2465 * GtkWidget:draw-border:
2467 * The "draw-border" style property defines the size of areas outside
2468 * the widget's allocation to draw.
2472 gtk_widget_class_install_style_property (klass,
2473 g_param_spec_boxed ("draw-border",
2475 P_("Size of areas outside the widget's allocation to draw"),
2477 GTK_PARAM_READABLE));
2480 * GtkWidget:link-color:
2482 * The "link-color" style property defines the color of unvisited links.
2486 gtk_widget_class_install_style_property (klass,
2487 g_param_spec_boxed ("link-color",
2488 P_("Unvisited Link Color"),
2489 P_("Color of unvisited links"),
2491 GTK_PARAM_READABLE));
2494 * GtkWidget:visited-link-color:
2496 * The "visited-link-color" style property defines the color of visited links.
2500 gtk_widget_class_install_style_property (klass,
2501 g_param_spec_boxed ("visited-link-color",
2502 P_("Visited Link Color"),
2503 P_("Color of visited links"),
2505 GTK_PARAM_READABLE));
2508 * GtkWidget:wide-separators:
2510 * The "wide-separators" style property defines whether separators have
2511 * configurable width and should be drawn using a box instead of a line.
2515 gtk_widget_class_install_style_property (klass,
2516 g_param_spec_boolean ("wide-separators",
2517 P_("Wide Separators"),
2518 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2520 GTK_PARAM_READABLE));
2523 * GtkWidget:separator-width:
2525 * The "separator-width" style property defines the width of separators.
2526 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2530 gtk_widget_class_install_style_property (klass,
2531 g_param_spec_int ("separator-width",
2532 P_("Separator Width"),
2533 P_("The width of separators if wide-separators is TRUE"),
2535 GTK_PARAM_READABLE));
2538 * GtkWidget:separator-height:
2540 * The "separator-height" style property defines the height of separators.
2541 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2545 gtk_widget_class_install_style_property (klass,
2546 g_param_spec_int ("separator-height",
2547 P_("Separator Height"),
2548 P_("The height of separators if \"wide-separators\" is TRUE"),
2550 GTK_PARAM_READABLE));
2553 * GtkWidget:scroll-arrow-hlength:
2555 * The "scroll-arrow-hlength" style property defines the length of
2556 * horizontal scroll arrows.
2560 gtk_widget_class_install_style_property (klass,
2561 g_param_spec_int ("scroll-arrow-hlength",
2562 P_("Horizontal Scroll Arrow Length"),
2563 P_("The length of horizontal scroll arrows"),
2565 GTK_PARAM_READABLE));
2568 * GtkWidget:scroll-arrow-vlength:
2570 * The "scroll-arrow-vlength" style property defines the length of
2571 * vertical scroll arrows.
2575 gtk_widget_class_install_style_property (klass,
2576 g_param_spec_int ("scroll-arrow-vlength",
2577 P_("Vertical Scroll Arrow Length"),
2578 P_("The length of vertical scroll arrows"),
2580 GTK_PARAM_READABLE));
2584 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2588 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2589 for (node = list; node; node = node->next)
2591 GParamSpec *pspec = node->data;
2593 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2594 g_param_spec_unref (pspec);
2600 gtk_widget_set_property (GObject *object,
2602 const GValue *value,
2605 GtkWidget *widget = GTK_WIDGET (object);
2610 gchar *tooltip_markup;
2611 const gchar *tooltip_text;
2612 GtkWindow *tooltip_window;
2615 gtk_widget_set_name (widget, g_value_get_string (value));
2618 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2620 case PROP_WIDTH_REQUEST:
2621 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2623 case PROP_HEIGHT_REQUEST:
2624 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2627 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2629 case PROP_SENSITIVE:
2630 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2632 case PROP_APP_PAINTABLE:
2633 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2635 case PROP_CAN_FOCUS:
2636 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2638 case PROP_HAS_FOCUS:
2639 if (g_value_get_boolean (value))
2640 gtk_widget_grab_focus (widget);
2643 if (g_value_get_boolean (value))
2644 gtk_widget_grab_focus (widget);
2646 case PROP_CAN_DEFAULT:
2647 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2649 case PROP_HAS_DEFAULT:
2650 if (g_value_get_boolean (value))
2651 gtk_widget_grab_default (widget);
2653 case PROP_RECEIVES_DEFAULT:
2654 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2657 gtk_widget_set_style (widget, g_value_get_object (value));
2660 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2661 gtk_widget_set_events (widget, g_value_get_flags (value));
2663 case PROP_EXTENSION_EVENTS:
2664 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2666 case PROP_NO_SHOW_ALL:
2667 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2669 case PROP_HAS_TOOLTIP:
2670 gtk_widget_real_set_has_tooltip (widget,
2671 g_value_get_boolean (value), FALSE);
2673 case PROP_TOOLTIP_MARKUP:
2674 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2675 tooltip_markup = g_value_dup_string (value);
2677 /* Treat an empty string as a NULL string,
2678 * because an empty string would be useless for a tooltip:
2680 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2682 g_free (tooltip_markup);
2683 tooltip_markup = NULL;
2686 g_object_set_qdata_full (object, quark_tooltip_markup,
2687 tooltip_markup, g_free);
2689 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2690 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2691 if (gtk_widget_get_visible (widget))
2692 gtk_widget_queue_tooltip_query (widget);
2694 case PROP_TOOLTIP_TEXT:
2695 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2697 tooltip_text = g_value_get_string (value);
2699 /* Treat an empty string as a NULL string,
2700 * because an empty string would be useless for a tooltip:
2702 if (tooltip_text && (strlen (tooltip_text) == 0))
2703 tooltip_text = NULL;
2705 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2707 g_object_set_qdata_full (object, quark_tooltip_markup,
2708 tooltip_markup, g_free);
2710 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2711 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2712 if (gtk_widget_get_visible (widget))
2713 gtk_widget_queue_tooltip_query (widget);
2715 case PROP_DOUBLE_BUFFERED:
2716 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2719 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2725 gtk_widget_get_property (GObject *object,
2730 GtkWidget *widget = GTK_WIDGET (object);
2739 g_value_set_string (value, widget->name);
2741 g_value_set_static_string (value, "");
2744 g_value_set_object (value, widget->parent);
2746 case PROP_WIDTH_REQUEST:
2749 gtk_widget_get_size_request (widget, &w, NULL);
2750 g_value_set_int (value, w);
2753 case PROP_HEIGHT_REQUEST:
2756 gtk_widget_get_size_request (widget, NULL, &h);
2757 g_value_set_int (value, h);
2761 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2763 case PROP_SENSITIVE:
2764 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2766 case PROP_APP_PAINTABLE:
2767 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2769 case PROP_CAN_FOCUS:
2770 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2772 case PROP_HAS_FOCUS:
2773 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2776 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2778 case PROP_CAN_DEFAULT:
2779 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2781 case PROP_HAS_DEFAULT:
2782 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2784 case PROP_RECEIVES_DEFAULT:
2785 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2787 case PROP_COMPOSITE_CHILD:
2788 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2791 g_value_set_object (value, gtk_widget_get_style (widget));
2794 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2795 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2797 case PROP_EXTENSION_EVENTS:
2798 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2799 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2801 case PROP_NO_SHOW_ALL:
2802 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2804 case PROP_HAS_TOOLTIP:
2805 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2807 case PROP_TOOLTIP_TEXT:
2809 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2812 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2813 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2815 g_value_take_string (value, text);
2818 case PROP_TOOLTIP_MARKUP:
2819 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2822 g_value_set_object (value, gtk_widget_get_window (widget));
2824 case PROP_DOUBLE_BUFFERED:
2825 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2828 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2834 gtk_widget_init (GtkWidget *widget)
2836 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2837 widget->state = GTK_STATE_NORMAL;
2838 widget->saved_state = GTK_STATE_NORMAL;
2839 widget->name = NULL;
2840 widget->requisition.width = 0;
2841 widget->requisition.height = 0;
2842 widget->allocation.x = -1;
2843 widget->allocation.y = -1;
2844 widget->allocation.width = 1;
2845 widget->allocation.height = 1;
2846 widget->window = NULL;
2847 widget->parent = NULL;
2849 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2850 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2851 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2852 gtk_widget_set_double_buffered (widget, TRUE);
2854 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2855 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2856 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
2857 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
2858 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2860 widget->style = gtk_widget_get_default_style ();
2861 g_object_ref (widget->style);
2866 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2868 GParamSpec **pspecs)
2870 GtkWidget *container = widget->parent;
2873 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2874 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2878 * gtk_widget_freeze_child_notify:
2879 * @widget: a #GtkWidget
2881 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2882 * signals are queued until gtk_widget_thaw_child_notify() is called
2885 * This is the analogue of g_object_freeze_notify() for child properties.
2888 gtk_widget_freeze_child_notify (GtkWidget *widget)
2890 g_return_if_fail (GTK_IS_WIDGET (widget));
2892 if (!G_OBJECT (widget)->ref_count)
2895 g_object_ref (widget);
2896 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2897 g_object_unref (widget);
2901 * gtk_widget_child_notify:
2902 * @widget: a #GtkWidget
2903 * @child_property: the name of a child property installed on the
2904 * class of @widget<!-- -->'s parent
2906 * Emits a #GtkWidget::child-notify signal for the
2907 * <link linkend="child-properties">child property</link> @child_property
2910 * This is the analogue of g_object_notify() for child properties.
2913 gtk_widget_child_notify (GtkWidget *widget,
2914 const gchar *child_property)
2918 g_return_if_fail (GTK_IS_WIDGET (widget));
2919 g_return_if_fail (child_property != NULL);
2920 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2923 g_object_ref (widget);
2924 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2926 G_OBJECT_TYPE (widget->parent),
2929 g_warning ("%s: container class `%s' has no child property named `%s'",
2931 G_OBJECT_TYPE_NAME (widget->parent),
2935 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2937 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2938 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2940 g_object_unref (widget);
2944 * gtk_widget_thaw_child_notify:
2945 * @widget: a #GtkWidget
2947 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2948 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2952 gtk_widget_thaw_child_notify (GtkWidget *widget)
2954 GObjectNotifyQueue *nqueue;
2956 g_return_if_fail (GTK_IS_WIDGET (widget));
2958 if (!G_OBJECT (widget)->ref_count)
2961 g_object_ref (widget);
2962 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2963 if (!nqueue || !nqueue->freeze_count)
2964 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2965 G_OBJECT_TYPE_NAME (widget), widget);
2967 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2968 g_object_unref (widget);
2974 * @type: type ID of the widget to create
2975 * @first_property_name: name of first property to set
2976 * @Varargs: value of first property, followed by more properties,
2979 * This is a convenience function for creating a widget and setting
2980 * its properties in one go. For example you might write:
2981 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2982 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2983 * g_object_new(), but returns a widget so you don't have to
2984 * cast the object yourself.
2986 * Return value: a new #GtkWidget of type @widget_type
2989 gtk_widget_new (GType type,
2990 const gchar *first_property_name,
2996 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2998 va_start (var_args, first_property_name);
2999 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3007 * @widget: a #GtkWidget
3008 * @first_property_name: name of first property to set
3009 * @Varargs: value of first property, followed by more properties,
3012 * Precursor of g_object_set().
3014 * Deprecated: 2.0: Use g_object_set() instead.
3017 gtk_widget_set (GtkWidget *widget,
3018 const gchar *first_property_name,
3023 g_return_if_fail (GTK_IS_WIDGET (widget));
3025 va_start (var_args, first_property_name);
3026 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3031 gtk_widget_queue_draw_child (GtkWidget *widget)
3035 parent = widget->parent;
3036 if (parent && gtk_widget_is_drawable (parent))
3037 gtk_widget_queue_draw_area (parent,
3038 widget->allocation.x,
3039 widget->allocation.y,
3040 widget->allocation.width,
3041 widget->allocation.height);
3045 * gtk_widget_unparent:
3046 * @widget: a #GtkWidget
3048 * This function is only for use in widget implementations.
3049 * Should be called by implementations of the remove method
3050 * on #GtkContainer, to dissociate a child from the container.
3053 gtk_widget_unparent (GtkWidget *widget)
3055 GObjectNotifyQueue *nqueue;
3056 GtkWidget *toplevel;
3057 GtkWidget *old_parent;
3059 g_return_if_fail (GTK_IS_WIDGET (widget));
3060 if (widget->parent == NULL)
3063 /* keep this function in sync with gtk_menu_detach()
3066 g_object_freeze_notify (G_OBJECT (widget));
3067 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3069 toplevel = gtk_widget_get_toplevel (widget);
3070 if (gtk_widget_is_toplevel (toplevel))
3071 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3073 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3074 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3076 /* If we are unanchoring the child, we save around the toplevel
3077 * to emit hierarchy changed
3079 if (GTK_WIDGET_ANCHORED (widget->parent))
3080 g_object_ref (toplevel);
3084 gtk_widget_queue_draw_child (widget);
3086 /* Reset the width and height here, to force reallocation if we
3087 * get added back to a new parent. This won't work if our new
3088 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3089 * (would 0x0 be OK here?)
3091 widget->allocation.width = 1;
3092 widget->allocation.height = 1;
3094 if (gtk_widget_get_realized (widget))
3096 if (GTK_WIDGET_IN_REPARENT (widget))
3097 gtk_widget_unmap (widget);
3099 gtk_widget_unrealize (widget);
3102 /* Removing a widget from a container restores the child visible
3103 * flag to the default state, so it doesn't affect the child
3104 * in the next parent.
3106 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3108 old_parent = widget->parent;
3109 widget->parent = NULL;
3110 gtk_widget_set_parent_window (widget, NULL);
3111 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3114 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3115 g_object_unref (toplevel);
3118 g_object_notify (G_OBJECT (widget), "parent");
3119 g_object_thaw_notify (G_OBJECT (widget));
3120 if (!widget->parent)
3121 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3122 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3123 g_object_unref (widget);
3127 * gtk_widget_destroy:
3128 * @widget: a #GtkWidget
3130 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3131 * you don't have to cast the widget to #GtkObject. When a widget is
3132 * destroyed, it will break any references it holds to other objects.
3133 * If the widget is inside a container, the widget will be removed
3134 * from the container. If the widget is a toplevel (derived from
3135 * #GtkWindow), it will be removed from the list of toplevels, and the
3136 * reference GTK+ holds to it will be removed. Removing a
3137 * widget from its container or the list of toplevels results in the
3138 * widget being finalized, unless you've added additional references
3139 * to the widget with g_object_ref().
3141 * In most cases, only toplevel widgets (windows) require explicit
3142 * destruction, because when you destroy a toplevel its children will
3143 * be destroyed as well.
3146 gtk_widget_destroy (GtkWidget *widget)
3148 g_return_if_fail (GTK_IS_WIDGET (widget));
3150 gtk_object_destroy ((GtkObject*) widget);
3154 * gtk_widget_destroyed:
3155 * @widget: a #GtkWidget
3156 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3158 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3159 * %NULL. It's intended to be used as a callback connected to the
3160 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3161 * as a signal handler, and pass the address of your widget variable
3162 * as user data. Then when the widget is destroyed, the variable will
3163 * be set to %NULL. Useful for example to avoid multiple copies
3164 * of the same dialog.
3167 gtk_widget_destroyed (GtkWidget *widget,
3168 GtkWidget **widget_pointer)
3170 /* Don't make any assumptions about the
3172 * Even check widget_pointer.
3175 *widget_pointer = NULL;
3180 * @widget: a #GtkWidget
3182 * Flags a widget to be displayed. Any widget that isn't shown will
3183 * not appear on the screen. If you want to show all the widgets in a
3184 * container, it's easier to call gtk_widget_show_all() on the
3185 * container, instead of individually showing the widgets.
3187 * Remember that you have to show the containers containing a widget,
3188 * in addition to the widget itself, before it will appear onscreen.
3190 * When a toplevel container is shown, it is immediately realized and
3191 * mapped; other shown widgets are realized and mapped when their
3192 * toplevel container is realized and mapped.
3195 gtk_widget_show (GtkWidget *widget)
3197 g_return_if_fail (GTK_IS_WIDGET (widget));
3199 if (!gtk_widget_get_visible (widget))
3201 g_object_ref (widget);
3202 if (!gtk_widget_is_toplevel (widget))
3203 gtk_widget_queue_resize (widget);
3204 g_signal_emit (widget, widget_signals[SHOW], 0);
3205 g_object_notify (G_OBJECT (widget), "visible");
3206 g_object_unref (widget);
3211 gtk_widget_real_show (GtkWidget *widget)
3213 if (!gtk_widget_get_visible (widget))
3215 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3217 if (widget->parent &&
3218 gtk_widget_get_mapped (widget->parent) &&
3219 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3220 !gtk_widget_get_mapped (widget))
3221 gtk_widget_map (widget);
3226 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3229 g_signal_handlers_disconnect_by_func (widget,
3230 gtk_widget_show_map_callback,
3235 * gtk_widget_show_now:
3236 * @widget: a #GtkWidget
3238 * Shows a widget. If the widget is an unmapped toplevel widget
3239 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3240 * loop and wait for the window to actually be mapped. Be careful;
3241 * because the main loop is running, anything can happen during
3245 gtk_widget_show_now (GtkWidget *widget)
3249 g_return_if_fail (GTK_IS_WIDGET (widget));
3251 /* make sure we will get event */
3252 if (!gtk_widget_get_mapped (widget) &&
3253 gtk_widget_is_toplevel (widget))
3255 gtk_widget_show (widget);
3257 g_signal_connect (widget, "map-event",
3258 G_CALLBACK (gtk_widget_show_map_callback),
3262 gtk_main_iteration ();
3265 gtk_widget_show (widget);
3270 * @widget: a #GtkWidget
3272 * Reverses the effects of gtk_widget_show(), causing the widget to be
3273 * hidden (invisible to the user).
3276 gtk_widget_hide (GtkWidget *widget)
3278 g_return_if_fail (GTK_IS_WIDGET (widget));
3280 if (gtk_widget_get_visible (widget))
3282 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3284 g_object_ref (widget);
3285 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3286 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3288 g_signal_emit (widget, widget_signals[HIDE], 0);
3289 if (!gtk_widget_is_toplevel (widget))
3290 gtk_widget_queue_resize (widget);
3291 g_object_notify (G_OBJECT (widget), "visible");
3292 g_object_unref (widget);
3297 gtk_widget_real_hide (GtkWidget *widget)
3299 if (gtk_widget_get_visible (widget))
3301 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3303 if (gtk_widget_get_mapped (widget))
3304 gtk_widget_unmap (widget);
3309 * gtk_widget_hide_on_delete:
3310 * @widget: a #GtkWidget
3312 * Utility function; intended to be connected to the #GtkWidget::delete-event
3313 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3314 * argument, then returns %TRUE. If connected to ::delete-event, the
3315 * result is that clicking the close button for a window (on the
3316 * window frame, top right corner usually) will hide but not destroy
3317 * the window. By default, GTK+ destroys windows when ::delete-event
3320 * Return value: %TRUE
3323 gtk_widget_hide_on_delete (GtkWidget *widget)
3325 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3327 gtk_widget_hide (widget);
3333 * gtk_widget_show_all:
3334 * @widget: a #GtkWidget
3336 * Recursively shows a widget, and any child widgets (if the widget is
3340 gtk_widget_show_all (GtkWidget *widget)
3342 GtkWidgetClass *class;
3344 g_return_if_fail (GTK_IS_WIDGET (widget));
3346 if (gtk_widget_get_no_show_all (widget))
3349 class = GTK_WIDGET_GET_CLASS (widget);
3351 if (class->show_all)
3352 class->show_all (widget);
3356 * gtk_widget_hide_all:
3357 * @widget: a #GtkWidget
3359 * Recursively hides a widget and any child widgets.
3362 gtk_widget_hide_all (GtkWidget *widget)
3364 GtkWidgetClass *class;
3366 g_return_if_fail (GTK_IS_WIDGET (widget));
3368 if (gtk_widget_get_no_show_all (widget))
3371 class = GTK_WIDGET_GET_CLASS (widget);
3373 if (class->hide_all)
3374 class->hide_all (widget);
3379 * @widget: a #GtkWidget
3381 * This function is only for use in widget implementations. Causes
3382 * a widget to be mapped if it isn't already.
3385 gtk_widget_map (GtkWidget *widget)
3387 g_return_if_fail (GTK_IS_WIDGET (widget));
3388 g_return_if_fail (gtk_widget_get_visible (widget));
3389 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3391 if (!gtk_widget_get_mapped (widget))
3393 if (!gtk_widget_get_realized (widget))
3394 gtk_widget_realize (widget);
3396 g_signal_emit (widget, widget_signals[MAP], 0);
3398 if (!gtk_widget_get_has_window (widget))
3399 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3405 * @widget: a #GtkWidget
3407 * This function is only for use in widget implementations. Causes
3408 * a widget to be unmapped if it's currently mapped.
3411 gtk_widget_unmap (GtkWidget *widget)
3413 g_return_if_fail (GTK_IS_WIDGET (widget));
3415 if (gtk_widget_get_mapped (widget))
3417 if (!gtk_widget_get_has_window (widget))
3418 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3419 _gtk_tooltip_hide (widget);
3420 g_signal_emit (widget, widget_signals[UNMAP], 0);
3425 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3426 GdkExtensionMode mode,
3429 GList *free_list = NULL;
3432 if (window_list == NULL)
3434 if (gtk_widget_get_has_window (widget))
3435 window_list = g_list_prepend (NULL, widget->window);
3437 window_list = gdk_window_get_children (widget->window);
3439 free_list = window_list;
3442 for (l = window_list; l != NULL; l = l->next)
3444 GdkWindow *window = l->data;
3447 gdk_window_get_user_data (window, &user_data);
3448 if (user_data == widget)
3452 gdk_input_set_extension_events (window,
3453 gdk_window_get_events (window),
3456 children = gdk_window_get_children (window);
3459 gtk_widget_set_extension_events_internal (widget, mode, children);
3460 g_list_free (children);
3466 g_list_free (free_list);
3470 * gtk_widget_realize:
3471 * @widget: a #GtkWidget
3473 * Creates the GDK (windowing system) resources associated with a
3474 * widget. For example, @widget->window will be created when a widget
3475 * is realized. Normally realization happens implicitly; if you show
3476 * a widget and all its parent containers, then the widget will be
3477 * realized and mapped automatically.
3479 * Realizing a widget requires all
3480 * the widget's parent widgets to be realized; calling
3481 * gtk_widget_realize() realizes the widget's parents in addition to
3482 * @widget itself. If a widget is not yet inside a toplevel window
3483 * when you realize it, bad things will happen.
3485 * This function is primarily used in widget implementations, and
3486 * isn't very useful otherwise. Many times when you think you might
3487 * need it, a better approach is to connect to a signal that will be
3488 * called after the widget is realized automatically, such as
3489 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3490 * GtkWidget::realize signal.
3493 gtk_widget_realize (GtkWidget *widget)
3495 GdkExtensionMode mode;
3496 GtkWidgetShapeInfo *shape_info;
3498 g_return_if_fail (GTK_IS_WIDGET (widget));
3499 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3500 GTK_IS_INVISIBLE (widget));
3502 if (!gtk_widget_get_realized (widget))
3505 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3506 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3509 if (widget->parent == NULL &&
3510 !gtk_widget_is_toplevel (widget))
3511 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3512 "inside a toplevel window is not going to work very well. "
3513 "Widgets must be inside a toplevel container before realizing them.");
3515 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3516 gtk_widget_realize (widget->parent);
3518 gtk_widget_ensure_style (widget);
3520 g_signal_emit (widget, widget_signals[REALIZE], 0);
3522 gtk_widget_real_set_has_tooltip (widget,
3523 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3526 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3528 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3529 gdk_window_shape_combine_mask (widget->window,
3530 shape_info->shape_mask,
3531 shape_info->offset_x,
3532 shape_info->offset_y);
3535 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3537 gdk_window_input_shape_combine_mask (widget->window,
3538 shape_info->shape_mask,
3539 shape_info->offset_x,
3540 shape_info->offset_y);
3542 mode = gtk_widget_get_extension_events (widget);
3543 if (mode != GDK_EXTENSION_EVENTS_NONE)
3544 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3549 * gtk_widget_unrealize:
3550 * @widget: a #GtkWidget
3552 * This function is only useful in widget implementations.
3553 * Causes a widget to be unrealized (frees all GDK resources
3554 * associated with the widget, such as @widget->window).
3557 gtk_widget_unrealize (GtkWidget *widget)
3559 g_return_if_fail (GTK_IS_WIDGET (widget));
3561 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3562 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3564 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3565 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3567 if (gtk_widget_get_realized (widget))
3569 g_object_ref (widget);
3570 _gtk_tooltip_hide (widget);
3571 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3572 gtk_widget_set_realized (widget, FALSE);
3573 gtk_widget_set_mapped (widget, FALSE);
3574 g_object_unref (widget);
3578 /*****************************************
3580 *****************************************/
3583 * gtk_widget_queue_draw_area:
3584 * @widget: a #GtkWidget
3585 * @x: x coordinate of upper-left corner of rectangle to redraw
3586 * @y: y coordinate of upper-left corner of rectangle to redraw
3587 * @width: width of region to draw
3588 * @height: height of region to draw
3590 * Invalidates the rectangular area of @widget defined by @x, @y,
3591 * @width and @height by calling gdk_window_invalidate_rect() on the
3592 * widget's window and all its child windows. Once the main loop
3593 * becomes idle (after the current batch of events has been processed,
3594 * roughly), the window will receive expose events for the union of
3595 * all regions that have been invalidated.
3597 * Normally you would only use this function in widget
3598 * implementations. You might also use it, or
3599 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3600 * #GtkDrawingArea or some portion thereof.
3602 * Frequently you can just call gdk_window_invalidate_rect() or
3603 * gdk_window_invalidate_region() instead of this function. Those
3604 * functions will invalidate only a single window, instead of the
3605 * widget and all its children.
3607 * The advantage of adding to the invalidated region compared to
3608 * simply drawing immediately is efficiency; using an invalid region
3609 * ensures that you only have to redraw one time.
3612 gtk_widget_queue_draw_area (GtkWidget *widget,
3618 GdkRectangle invalid_rect;
3621 g_return_if_fail (GTK_IS_WIDGET (widget));
3623 if (!gtk_widget_get_realized (widget))
3626 /* Just return if the widget or one of its ancestors isn't mapped */
3627 for (w = widget; w != NULL; w = w->parent)
3628 if (!gtk_widget_get_mapped (w))
3631 /* Find the correct widget */
3633 if (gtk_widget_get_has_window (widget))
3637 /* Translate widget relative to window-relative */
3639 gint wx, wy, wwidth, wheight;
3641 gdk_window_get_position (widget->window, &wx, &wy);
3642 x -= wx - widget->allocation.x;
3643 y -= wy - widget->allocation.y;
3645 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3647 if (x + width <= 0 || y + height <= 0 ||
3648 x >= wwidth || y >= wheight)
3659 if (x + width > wwidth)
3661 if (y + height > wheight)
3662 height = wheight - y;
3668 invalid_rect.width = width;
3669 invalid_rect.height = height;
3671 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3675 widget_add_child_draw_rectangle (GtkWidget *widget,
3678 GdkRectangle child_rect;
3680 if (!gtk_widget_get_mapped (widget) ||
3681 widget->window != widget->parent->window)
3684 gtk_widget_get_draw_rectangle (widget, &child_rect);
3685 gdk_rectangle_union (rect, &child_rect, rect);
3689 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3692 if (!gtk_widget_get_has_window (widget))
3694 GtkBorder *draw_border = NULL;
3696 *rect = widget->allocation;
3698 gtk_widget_style_get (widget,
3699 "draw-border", &draw_border,
3703 rect->x -= draw_border->left;
3704 rect->y -= draw_border->top;
3705 rect->width += draw_border->left + draw_border->right;
3706 rect->height += draw_border->top + draw_border->bottom;
3708 gtk_border_free (draw_border);
3711 if (GTK_IS_CONTAINER (widget))
3712 gtk_container_forall (GTK_CONTAINER (widget),
3713 (GtkCallback)widget_add_child_draw_rectangle,
3720 rect->width = widget->allocation.width;
3721 rect->height = widget->allocation.height;
3726 * gtk_widget_queue_draw:
3727 * @widget: a #GtkWidget
3729 * Equivalent to calling gtk_widget_queue_draw_area() for the
3730 * entire area of a widget.
3733 gtk_widget_queue_draw (GtkWidget *widget)
3737 g_return_if_fail (GTK_IS_WIDGET (widget));
3739 gtk_widget_get_draw_rectangle (widget, &rect);
3741 gtk_widget_queue_draw_area (widget,
3743 rect.width, rect.height);
3746 /* Invalidates the given area (allocation-relative-coordinates)
3747 * in all of the widget's windows
3750 * gtk_widget_queue_clear_area:
3751 * @widget: a #GtkWidget
3752 * @x: x coordinate of upper-left corner of rectangle to redraw
3753 * @y: y coordinate of upper-left corner of rectangle to redraw
3754 * @width: width of region to draw
3755 * @height: height of region to draw
3757 * This function is no longer different from
3758 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3759 * gtk_widget_queue_draw_area(). Originally
3760 * gtk_widget_queue_clear_area() would force a redraw of the
3761 * background for %GTK_NO_WINDOW widgets, and
3762 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3763 * the background will be redrawn.
3765 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3768 gtk_widget_queue_clear_area (GtkWidget *widget,
3774 g_return_if_fail (GTK_IS_WIDGET (widget));
3776 gtk_widget_queue_draw_area (widget, x, y, width, height);
3780 * gtk_widget_queue_clear:
3781 * @widget: a #GtkWidget
3783 * This function does the same as gtk_widget_queue_draw().
3785 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3788 gtk_widget_queue_clear (GtkWidget *widget)
3790 g_return_if_fail (GTK_IS_WIDGET (widget));
3792 gtk_widget_queue_draw (widget);
3796 * gtk_widget_queue_resize:
3797 * @widget: a #GtkWidget
3799 * This function is only for use in widget implementations.
3800 * Flags a widget to have its size renegotiated; should
3801 * be called when a widget for some reason has a new size request.
3802 * For example, when you change the text in a #GtkLabel, #GtkLabel
3803 * queues a resize to ensure there's enough space for the new text.
3806 gtk_widget_queue_resize (GtkWidget *widget)
3808 g_return_if_fail (GTK_IS_WIDGET (widget));
3810 if (gtk_widget_get_realized (widget))
3811 gtk_widget_queue_shallow_draw (widget);
3813 _gtk_size_group_queue_resize (widget);
3817 * gtk_widget_queue_resize_no_redraw:
3818 * @widget: a #GtkWidget
3820 * This function works like gtk_widget_queue_resize(),
3821 * except that the widget is not invalidated.
3826 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3828 g_return_if_fail (GTK_IS_WIDGET (widget));
3830 _gtk_size_group_queue_resize (widget);
3835 * @widget: a #GtkWidget
3836 * @area: area to draw
3838 * In GTK+ 1.2, this function would immediately render the
3839 * region @area of a widget, by invoking the virtual draw method of a
3840 * widget. In GTK+ 2.0, the draw method is gone, and instead
3841 * gtk_widget_draw() simply invalidates the specified region of the
3842 * widget, then updates the invalid region of the widget immediately.
3843 * Usually you don't want to update the region immediately for
3844 * performance reasons, so in general gtk_widget_queue_draw_area() is
3845 * a better choice if you want to draw a region of a widget.
3848 gtk_widget_draw (GtkWidget *widget,
3849 const GdkRectangle *area)
3851 g_return_if_fail (GTK_IS_WIDGET (widget));
3853 if (gtk_widget_is_drawable (widget))
3856 gtk_widget_queue_draw_area (widget,
3858 area->width, area->height);
3860 gtk_widget_queue_draw (widget);
3862 gdk_window_process_updates (widget->window, TRUE);
3867 * gtk_widget_size_request:
3868 * @widget: a #GtkWidget
3869 * @requisition: a #GtkRequisition to be filled in
3871 * This function is typically used when implementing a #GtkContainer
3872 * subclass. Obtains the preferred size of a widget. The container
3873 * uses this information to arrange its child widgets and decide what
3874 * size allocations to give them with gtk_widget_size_allocate().
3876 * You can also call this function from an application, with some
3877 * caveats. Most notably, getting a size request requires the widget
3878 * to be associated with a screen, because font information may be
3879 * needed. Multihead-aware applications should keep this in mind.
3881 * Also remember that the size request is not necessarily the size
3882 * a widget will actually be allocated.
3884 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3887 gtk_widget_size_request (GtkWidget *widget,
3888 GtkRequisition *requisition)
3890 g_return_if_fail (GTK_IS_WIDGET (widget));
3892 #ifdef G_ENABLE_DEBUG
3893 if (requisition == &widget->requisition)
3894 g_warning ("gtk_widget_size_request() called on child widget with request equal\n"
3895 "to widget->requisition. gtk_widget_set_usize() may not work properly.");
3896 #endif /* G_ENABLE_DEBUG */
3898 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget), FALSE, requisition, NULL);
3902 * gtk_widget_get_child_requisition:
3903 * @widget: a #GtkWidget
3904 * @requisition: a #GtkRequisition to be filled in
3906 * This function is only for use in widget implementations. Obtains
3907 * @widget->requisition, unless someone has forced a particular
3908 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3909 * in which case it returns that geometry instead of the widget's
3912 * This function differs from gtk_widget_size_request() in that
3913 * it retrieves the last size request value from @widget->requisition,
3914 * while gtk_widget_size_request() actually calls the "size_request" method
3915 * on @widget to compute the size request and fill in @widget->requisition,
3916 * and only then returns @widget->requisition.
3918 * Because this function does not call the "size_request" method, it
3919 * can only be used when you know that @widget->requisition is
3920 * up-to-date, that is, gtk_widget_size_request() has been called
3921 * since the last time a resize was queued. In general, only container
3922 * implementations have this information; applications should use
3923 * gtk_widget_size_request().
3926 * Deprecated: 3.0: Use gtk_extended_layout_get_desired_size() instead.
3929 gtk_widget_get_child_requisition (GtkWidget *widget,
3930 GtkRequisition *requisition)
3932 gtk_extended_layout_get_desired_size (GTK_EXTENDED_LAYOUT (widget), FALSE, requisition, NULL);
3936 invalidate_predicate (GdkWindow *window,
3941 gdk_window_get_user_data (window, &user_data);
3943 return (user_data == data);
3946 /* Invalidate @region in widget->window and all children
3947 * of widget->window owned by widget. @region is in the
3948 * same coordinates as widget->allocation and will be
3949 * modified by this call.
3952 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3955 if (!gtk_widget_get_realized (widget))
3958 if (gtk_widget_get_has_window (widget) && widget->parent)
3962 gdk_window_get_position (widget->window, &x, &y);
3963 gdk_region_offset (region, -x, -y);
3966 gdk_window_invalidate_maybe_recurse (widget->window, region,
3967 invalidate_predicate, widget);
3971 * gtk_widget_queue_shallow_draw:
3972 * @widget: a #GtkWidget
3974 * Like gtk_widget_queue_draw(), but only windows owned
3975 * by @widget are invalidated.
3978 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3983 if (!gtk_widget_get_realized (widget))
3986 gtk_widget_get_draw_rectangle (widget, &rect);
3988 /* get_draw_rectangle() gives us window coordinates, we
3989 * need to convert to the coordinates that widget->allocation
3992 if (gtk_widget_get_has_window (widget) && widget->parent)
3996 gdk_window_get_position (widget->window, &wx, &wy);
4002 region = gdk_region_rectangle (&rect);
4003 gtk_widget_invalidate_widget_windows (widget, region);
4004 gdk_region_destroy (region);
4008 * gtk_widget_size_allocate:
4009 * @widget: a #GtkWidget
4010 * @allocation: position and size to be allocated to @widget
4012 * This function is only used by #GtkContainer subclasses, to assign a size
4013 * and position to their child widgets.
4016 gtk_widget_size_allocate (GtkWidget *widget,
4017 GtkAllocation *allocation)
4019 GtkWidgetAuxInfo *aux_info;
4020 GdkRectangle real_allocation;
4021 GdkRectangle old_allocation;
4022 gboolean alloc_needed;
4023 gboolean size_changed;
4024 gboolean position_changed;
4026 g_return_if_fail (GTK_IS_WIDGET (widget));
4028 #ifdef G_ENABLE_DEBUG
4029 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4040 parent = gtk_widget_get_parent (parent);
4043 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4044 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4045 2 * depth, " ", name,
4046 allocation->width, allocation->height);
4048 #endif /* G_ENABLE_DEBUG */
4050 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4051 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4052 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4054 old_allocation = widget->allocation;
4055 real_allocation = *allocation;
4056 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4060 if (aux_info->x_set)
4061 real_allocation.x = aux_info->x;
4062 if (aux_info->y_set)
4063 real_allocation.y = aux_info->y;
4066 if (real_allocation.width < 0 || real_allocation.height < 0)
4068 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4069 real_allocation.width,
4070 real_allocation.height);
4073 real_allocation.width = MAX (real_allocation.width, 1);
4074 real_allocation.height = MAX (real_allocation.height, 1);
4076 size_changed = (old_allocation.width != real_allocation.width ||
4077 old_allocation.height != real_allocation.height);
4078 position_changed = (old_allocation.x != real_allocation.x ||
4079 old_allocation.y != real_allocation.y);
4081 if (!alloc_needed && !size_changed && !position_changed)
4084 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4086 if (gtk_widget_get_mapped (widget))
4088 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4090 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4092 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4093 gdk_region_union_with_rect (invalidate, &old_allocation);
4095 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4096 gdk_region_destroy (invalidate);
4101 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4103 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4105 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4106 gdk_region_union_with_rect (invalidate, &old_allocation);
4108 gtk_widget_invalidate_widget_windows (widget, invalidate);
4109 gdk_region_destroy (invalidate);
4114 if ((size_changed || position_changed) && widget->parent &&
4115 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4117 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4118 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4119 gdk_region_destroy (invalidate);
4124 * gtk_widget_common_ancestor:
4125 * @widget_a: a #GtkWidget
4126 * @widget_b: a #GtkWidget
4128 * Find the common ancestor of @widget_a and @widget_b that
4129 * is closest to the two widgets.
4131 * Return value: the closest common ancestor of @widget_a and
4132 * @widget_b or %NULL if @widget_a and @widget_b do not
4133 * share a common ancestor.
4136 gtk_widget_common_ancestor (GtkWidget *widget_a,
4137 GtkWidget *widget_b)
4139 GtkWidget *parent_a;
4140 GtkWidget *parent_b;
4144 parent_a = widget_a;
4145 while (parent_a->parent)
4147 parent_a = parent_a->parent;
4151 parent_b = widget_b;
4152 while (parent_b->parent)
4154 parent_b = parent_b->parent;
4158 if (parent_a != parent_b)
4161 while (depth_a > depth_b)
4163 widget_a = widget_a->parent;
4167 while (depth_b > depth_a)
4169 widget_b = widget_b->parent;
4173 while (widget_a != widget_b)
4175 widget_a = widget_a->parent;
4176 widget_b = widget_b->parent;
4183 * gtk_widget_translate_coordinates:
4184 * @src_widget: a #GtkWidget
4185 * @dest_widget: a #GtkWidget
4186 * @src_x: X position relative to @src_widget
4187 * @src_y: Y position relative to @src_widget
4188 * @dest_x: (out): location to store X position relative to @dest_widget
4189 * @dest_y: (out): location to store Y position relative to @dest_widget
4191 * Translate coordinates relative to @src_widget's allocation to coordinates
4192 * relative to @dest_widget's allocations. In order to perform this
4193 * operation, both widgets must be realized, and must share a common
4196 * Return value: %FALSE if either widget was not realized, or there
4197 * was no common ancestor. In this case, nothing is stored in
4198 * *@dest_x and *@dest_y. Otherwise %TRUE.
4201 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4202 GtkWidget *dest_widget,
4208 GtkWidget *ancestor;
4210 GList *dest_list = NULL;
4212 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4213 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4215 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4216 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4219 /* Translate from allocation relative to window relative */
4220 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4223 gdk_window_get_position (src_widget->window, &wx, &wy);
4225 src_x -= wx - src_widget->allocation.x;
4226 src_y -= wy - src_widget->allocation.y;
4230 src_x += src_widget->allocation.x;
4231 src_y += src_widget->allocation.y;
4234 /* Translate to the common ancestor */
4235 window = src_widget->window;
4236 while (window != ancestor->window)
4240 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4245 window = gdk_window_get_effective_parent (window);
4247 if (!window) /* Handle GtkHandleBox */
4252 window = dest_widget->window;
4253 while (window != ancestor->window)
4255 dest_list = g_list_prepend (dest_list, window);
4257 window = gdk_window_get_effective_parent (window);
4259 if (!window) /* Handle GtkHandleBox */
4261 g_list_free (dest_list);
4270 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4275 dest_list = g_list_remove (dest_list, dest_list->data);
4278 /* Translate from window relative to allocation relative */
4279 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4282 gdk_window_get_position (dest_widget->window, &wx, &wy);
4284 src_x += wx - dest_widget->allocation.x;
4285 src_y += wy - dest_widget->allocation.y;
4289 src_x -= dest_widget->allocation.x;
4290 src_y -= dest_widget->allocation.y;
4302 gtk_widget_real_size_allocate (GtkWidget *widget,
4303 GtkAllocation *allocation)
4305 widget->allocation = *allocation;
4307 if (gtk_widget_get_realized (widget) &&
4308 gtk_widget_get_has_window (widget))
4310 gdk_window_move_resize (widget->window,
4311 allocation->x, allocation->y,
4312 allocation->width, allocation->height);
4317 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4320 /* widgets must be onscreen for accels to take effect */
4321 return gtk_widget_is_sensitive (widget) &&
4322 gtk_widget_is_drawable (widget) &&
4323 gdk_window_is_viewable (widget->window);
4327 * gtk_widget_can_activate_accel:
4328 * @widget: a #GtkWidget
4329 * @signal_id: the ID of a signal installed on @widget
4331 * Determines whether an accelerator that activates the signal
4332 * identified by @signal_id can currently be activated.
4333 * This is done by emitting the #GtkWidget::can-activate-accel
4334 * signal on @widget; if the signal isn't overridden by a
4335 * handler or in a derived widget, then the default check is
4336 * that the widget must be sensitive, and the widget and all
4337 * its ancestors mapped.
4339 * Return value: %TRUE if the accelerator can be activated.
4344 gtk_widget_can_activate_accel (GtkWidget *widget,
4347 gboolean can_activate = FALSE;
4348 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4349 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4350 return can_activate;
4359 closure_accel_activate (GClosure *closure,
4360 GValue *return_value,
4361 guint n_param_values,
4362 const GValue *param_values,
4363 gpointer invocation_hint,
4364 gpointer marshal_data)
4366 AccelClosure *aclosure = (AccelClosure*) closure;
4367 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4370 g_signal_emit (closure->data, aclosure->signal_id, 0);
4372 /* whether accelerator was handled */
4373 g_value_set_boolean (return_value, can_activate);
4377 closures_destroy (gpointer data)
4379 GSList *slist, *closures = data;
4381 for (slist = closures; slist; slist = slist->next)
4383 g_closure_invalidate (slist->data);
4384 g_closure_unref (slist->data);
4386 g_slist_free (closures);
4390 widget_new_accel_closure (GtkWidget *widget,
4393 AccelClosure *aclosure;
4394 GClosure *closure = NULL;
4395 GSList *slist, *closures;
4397 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4398 for (slist = closures; slist; slist = slist->next)
4399 if (!gtk_accel_group_from_accel_closure (slist->data))
4401 /* reuse this closure */
4402 closure = slist->data;
4407 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4408 closures = g_slist_prepend (closures, g_closure_ref (closure));
4409 g_closure_sink (closure);
4410 g_closure_set_marshal (closure, closure_accel_activate);
4412 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4414 aclosure = (AccelClosure*) closure;
4415 g_assert (closure->data == widget);
4416 g_assert (closure->marshal == closure_accel_activate);
4417 aclosure->signal_id = signal_id;
4423 * gtk_widget_add_accelerator
4424 * @widget: widget to install an accelerator on
4425 * @accel_signal: widget signal to emit on accelerator activation
4426 * @accel_group: accel group for this widget, added to its toplevel
4427 * @accel_key: GDK keyval of the accelerator
4428 * @accel_mods: modifier key combination of the accelerator
4429 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4431 * Installs an accelerator for this @widget in @accel_group that causes
4432 * @accel_signal to be emitted if the accelerator is activated.
4433 * The @accel_group needs to be added to the widget's toplevel via
4434 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4435 * Accelerators added through this function are not user changeable during
4436 * runtime. If you want to support accelerators that can be changed by the
4437 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4438 * gtk_menu_item_set_accel_path() instead.
4441 gtk_widget_add_accelerator (GtkWidget *widget,
4442 const gchar *accel_signal,
4443 GtkAccelGroup *accel_group,
4445 GdkModifierType accel_mods,
4446 GtkAccelFlags accel_flags)
4451 g_return_if_fail (GTK_IS_WIDGET (widget));
4452 g_return_if_fail (accel_signal != NULL);
4453 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4455 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4456 if (!query.signal_id ||
4457 !(query.signal_flags & G_SIGNAL_ACTION) ||
4458 query.return_type != G_TYPE_NONE ||
4461 /* hmm, should be elaborate enough */
4462 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4463 G_OBJECT_TYPE_NAME (widget), accel_signal);
4467 closure = widget_new_accel_closure (widget, query.signal_id);
4469 g_object_ref (widget);
4471 /* install the accelerator. since we don't map this onto an accel_path,
4472 * the accelerator will automatically be locked.
4474 gtk_accel_group_connect (accel_group,
4477 accel_flags | GTK_ACCEL_LOCKED,
4480 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4482 g_object_unref (widget);
4486 * gtk_widget_remove_accelerator:
4487 * @widget: widget to install an accelerator on
4488 * @accel_group: accel group for this widget
4489 * @accel_key: GDK keyval of the accelerator
4490 * @accel_mods: modifier key combination of the accelerator
4491 * @returns: whether an accelerator was installed and could be removed
4493 * Removes an accelerator from @widget, previously installed with
4494 * gtk_widget_add_accelerator().
4497 gtk_widget_remove_accelerator (GtkWidget *widget,
4498 GtkAccelGroup *accel_group,
4500 GdkModifierType accel_mods)
4502 GtkAccelGroupEntry *ag_entry;
4503 GList *slist, *clist;
4506 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4507 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4509 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4510 clist = gtk_widget_list_accel_closures (widget);
4511 for (slist = clist; slist; slist = slist->next)
4515 for (i = 0; i < n; i++)
4516 if (slist->data == (gpointer) ag_entry[i].closure)
4518 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4520 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4522 g_list_free (clist);
4527 g_list_free (clist);
4529 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4530 accel_key, accel_mods, accel_group,
4531 G_OBJECT_TYPE_NAME (widget), widget);
4537 * gtk_widget_list_accel_closures
4538 * @widget: widget to list accelerator closures for
4539 * @returns: a newly allocated #GList of closures
4541 * Lists the closures used by @widget for accelerator group connections
4542 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4543 * The closures can be used to monitor accelerator changes on @widget,
4544 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4545 * #GtkAccelGroup of a closure which can be found out with
4546 * gtk_accel_group_from_accel_closure().
4549 gtk_widget_list_accel_closures (GtkWidget *widget)
4552 GList *clist = NULL;
4554 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4556 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4557 if (gtk_accel_group_from_accel_closure (slist->data))
4558 clist = g_list_prepend (clist, slist->data);
4564 GtkAccelGroup *accel_group;
4569 destroy_accel_path (gpointer data)
4571 AccelPath *apath = data;
4573 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4575 /* closures_destroy takes care of unrefing the closure */
4576 g_object_unref (apath->accel_group);
4578 g_slice_free (AccelPath, apath);
4583 * gtk_widget_set_accel_path:
4584 * @widget: a #GtkWidget
4585 * @accel_path: (allow-none): path used to look up the accelerator
4586 * @accel_group: (allow-none): a #GtkAccelGroup.
4588 * Given an accelerator group, @accel_group, and an accelerator path,
4589 * @accel_path, sets up an accelerator in @accel_group so whenever the
4590 * key binding that is defined for @accel_path is pressed, @widget
4591 * will be activated. This removes any accelerators (for any
4592 * accelerator group) installed by previous calls to
4593 * gtk_widget_set_accel_path(). Associating accelerators with
4594 * paths allows them to be modified by the user and the modifications
4595 * to be saved for future use. (See gtk_accel_map_save().)
4597 * This function is a low level function that would most likely
4598 * be used by a menu creation system like #GtkUIManager. If you
4599 * use #GtkUIManager, setting up accelerator paths will be done
4602 * Even when you you aren't using #GtkUIManager, if you only want to
4603 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4604 * provides a somewhat more convenient interface.
4606 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4607 * pass a static string, you can save some memory by interning it first with
4608 * g_intern_static_string().
4611 gtk_widget_set_accel_path (GtkWidget *widget,
4612 const gchar *accel_path,
4613 GtkAccelGroup *accel_group)
4617 g_return_if_fail (GTK_IS_WIDGET (widget));
4618 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4622 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4623 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4625 gtk_accel_map_add_entry (accel_path, 0, 0);
4626 apath = g_slice_new (AccelPath);
4627 apath->accel_group = g_object_ref (accel_group);
4628 apath->path_quark = g_quark_from_string (accel_path);
4629 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4634 /* also removes possible old settings */
4635 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4638 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4640 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4644 _gtk_widget_get_accel_path (GtkWidget *widget,
4649 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4651 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4653 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4654 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4658 * gtk_widget_mnemonic_activate:
4659 * @widget: a #GtkWidget
4660 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4662 * Emits the #GtkWidget::mnemonic-activate signal.
4664 * The default handler for this signal activates the @widget if
4665 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4668 * Returns: %TRUE if the signal has been handled
4671 gtk_widget_mnemonic_activate (GtkWidget *widget,
4672 gboolean group_cycling)
4676 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4678 group_cycling = group_cycling != FALSE;
4679 if (!gtk_widget_is_sensitive (widget))
4682 g_signal_emit (widget,
4683 widget_signals[MNEMONIC_ACTIVATE],
4691 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4692 gboolean group_cycling)
4694 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4695 gtk_widget_activate (widget);
4696 else if (gtk_widget_get_can_focus (widget))
4697 gtk_widget_grab_focus (widget);
4700 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4701 G_OBJECT_TYPE_NAME (widget));
4702 gtk_widget_error_bell (widget);
4708 gtk_widget_real_key_press_event (GtkWidget *widget,
4711 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4715 gtk_widget_real_key_release_event (GtkWidget *widget,
4718 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4722 gtk_widget_real_focus_in_event (GtkWidget *widget,
4723 GdkEventFocus *event)
4725 gtk_widget_queue_shallow_draw (widget);
4731 gtk_widget_real_focus_out_event (GtkWidget *widget,
4732 GdkEventFocus *event)
4734 gtk_widget_queue_shallow_draw (widget);
4739 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4740 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4744 * @widget: a #GtkWidget
4745 * @event: a #GdkEvent
4747 * Rarely-used function. This function is used to emit
4748 * the event signals on a widget (those signals should never
4749 * be emitted without using this function to do so).
4750 * If you want to synthesize an event though, don't use this function;
4751 * instead, use gtk_main_do_event() so the event will behave as if
4752 * it were in the event queue. Don't synthesize expose events; instead,
4753 * use gdk_window_invalidate_rect() to invalidate a region of the
4756 * Return value: return from the event signal emission (%TRUE if
4757 * the event was handled)
4760 gtk_widget_event (GtkWidget *widget,
4763 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4764 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4766 if (event->type == GDK_EXPOSE)
4768 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4769 "the same effect, call gdk_window_invalidate_rect/region(), "
4770 "followed by gdk_window_process_updates().");
4774 return gtk_widget_event_internal (widget, event);
4779 * gtk_widget_send_expose:
4780 * @widget: a #GtkWidget
4781 * @event: a expose #GdkEvent
4783 * Very rarely-used function. This function is used to emit
4784 * an expose event signals on a widget. This function is not
4785 * normally used directly. The only time it is used is when
4786 * propagating an expose event to a child %NO_WINDOW widget, and
4787 * that is normally done using gtk_container_propagate_expose().
4789 * If you want to force an area of a window to be redrawn,
4790 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4791 * To cause the redraw to be done immediately, follow that call
4792 * with a call to gdk_window_process_updates().
4794 * Return value: return from the event signal emission (%TRUE if
4795 * the event was handled)
4798 gtk_widget_send_expose (GtkWidget *widget,
4801 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4802 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4803 g_return_val_if_fail (event != NULL, TRUE);
4804 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4806 return gtk_widget_event_internal (widget, event);
4810 event_window_is_still_viewable (GdkEvent *event)
4812 /* Some programs, such as gnome-theme-manager, fake widgets
4813 * into exposing onto a pixmap by sending expose events with
4814 * event->window pointing to a pixmap
4816 if (GDK_IS_PIXMAP (event->any.window))
4817 return event->type == GDK_EXPOSE;
4819 /* Check that we think the event's window is viewable before
4820 * delivering the event, to prevent suprises. We do this here
4821 * at the last moment, since the event may have been queued
4822 * up behind other events, held over a recursive main loop, etc.
4824 switch (event->type)
4827 case GDK_MOTION_NOTIFY:
4828 case GDK_BUTTON_PRESS:
4829 case GDK_2BUTTON_PRESS:
4830 case GDK_3BUTTON_PRESS:
4832 case GDK_ENTER_NOTIFY:
4833 case GDK_PROXIMITY_IN:
4835 return event->any.window && gdk_window_is_viewable (event->any.window);
4838 /* The following events are the second half of paired events;
4839 * we always deliver them to deal with widgets that clean up
4840 * on the second half.
4842 case GDK_BUTTON_RELEASE:
4843 case GDK_KEY_RELEASE:
4844 case GDK_LEAVE_NOTIFY:
4845 case GDK_PROXIMITY_OUT:
4849 /* Remaining events would make sense on an not-viewable window,
4850 * or don't have an associated window.
4857 gtk_widget_event_internal (GtkWidget *widget,
4860 gboolean return_val = FALSE;
4862 /* We check only once for is-still-visible; if someone
4863 * hides the window in on of the signals on the widget,
4864 * they are responsible for returning TRUE to terminate
4867 if (!event_window_is_still_viewable (event))
4870 g_object_ref (widget);
4872 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4873 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4878 switch (event->type)
4883 case GDK_BUTTON_PRESS:
4884 case GDK_2BUTTON_PRESS:
4885 case GDK_3BUTTON_PRESS:
4886 signal_num = BUTTON_PRESS_EVENT;
4889 signal_num = SCROLL_EVENT;
4891 case GDK_BUTTON_RELEASE:
4892 signal_num = BUTTON_RELEASE_EVENT;
4894 case GDK_MOTION_NOTIFY:
4895 signal_num = MOTION_NOTIFY_EVENT;
4898 signal_num = DELETE_EVENT;
4901 signal_num = DESTROY_EVENT;
4902 _gtk_tooltip_hide (widget);
4905 signal_num = KEY_PRESS_EVENT;
4907 case GDK_KEY_RELEASE:
4908 signal_num = KEY_RELEASE_EVENT;
4910 case GDK_ENTER_NOTIFY:
4911 signal_num = ENTER_NOTIFY_EVENT;
4913 case GDK_LEAVE_NOTIFY:
4914 signal_num = LEAVE_NOTIFY_EVENT;
4916 case GDK_FOCUS_CHANGE:
4917 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4918 if (event->focus_change.in)
4919 _gtk_tooltip_focus_in (widget);
4921 _gtk_tooltip_focus_out (widget);
4924 signal_num = CONFIGURE_EVENT;
4927 signal_num = MAP_EVENT;
4930 signal_num = UNMAP_EVENT;
4932 case GDK_WINDOW_STATE:
4933 signal_num = WINDOW_STATE_EVENT;
4935 case GDK_PROPERTY_NOTIFY:
4936 signal_num = PROPERTY_NOTIFY_EVENT;
4938 case GDK_SELECTION_CLEAR:
4939 signal_num = SELECTION_CLEAR_EVENT;
4941 case GDK_SELECTION_REQUEST:
4942 signal_num = SELECTION_REQUEST_EVENT;
4944 case GDK_SELECTION_NOTIFY:
4945 signal_num = SELECTION_NOTIFY_EVENT;
4947 case GDK_PROXIMITY_IN:
4948 signal_num = PROXIMITY_IN_EVENT;
4950 case GDK_PROXIMITY_OUT:
4951 signal_num = PROXIMITY_OUT_EVENT;
4954 signal_num = NO_EXPOSE_EVENT;
4956 case GDK_CLIENT_EVENT:
4957 signal_num = CLIENT_EVENT;
4960 signal_num = EXPOSE_EVENT;
4962 case GDK_VISIBILITY_NOTIFY:
4963 signal_num = VISIBILITY_NOTIFY_EVENT;
4965 case GDK_GRAB_BROKEN:
4966 signal_num = GRAB_BROKEN;
4969 signal_num = DAMAGE_EVENT;
4972 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4976 if (signal_num != -1)
4977 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4979 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4980 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4984 g_object_unref (widget);
4990 * gtk_widget_activate:
4991 * @widget: a #GtkWidget that's activatable
4993 * For widgets that can be "activated" (buttons, menu items, etc.)
4994 * this function activates them. Activation is what happens when you
4995 * press Enter on a widget during key navigation. If @widget isn't
4996 * activatable, the function returns %FALSE.
4998 * Return value: %TRUE if the widget was activatable
5001 gtk_widget_activate (GtkWidget *widget)
5003 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5005 if (WIDGET_CLASS (widget)->activate_signal)
5007 /* FIXME: we should eventually check the signals signature here */
5008 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5017 * gtk_widget_set_scroll_adjustments:
5018 * @widget: a #GtkWidget
5019 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5020 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5022 * For widgets that support scrolling, sets the scroll adjustments and
5023 * returns %TRUE. For widgets that don't support scrolling, does
5024 * nothing and returns %FALSE. Widgets that don't support scrolling
5025 * can be scrolled by placing them in a #GtkViewport, which does
5026 * support scrolling.
5028 * Return value: %TRUE if the widget supports scrolling
5031 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5032 GtkAdjustment *hadjustment,
5033 GtkAdjustment *vadjustment)
5038 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5041 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5043 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5045 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5049 g_signal_query (signal_id, &query);
5050 if (!query.signal_id ||
5051 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5052 query.return_type != G_TYPE_NONE ||
5053 query.n_params != 2 ||
5054 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5055 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5057 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5058 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5062 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5067 gtk_widget_reparent_subwindows (GtkWidget *widget,
5068 GdkWindow *new_window)
5070 if (!gtk_widget_get_has_window (widget))
5072 GList *children = gdk_window_get_children (widget->window);
5075 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5077 GdkWindow *window = tmp_list->data;
5080 gdk_window_get_user_data (window, &child);
5081 while (child && child != widget)
5082 child = ((GtkWidget*) child)->parent;
5085 gdk_window_reparent (window, new_window, 0, 0);
5088 g_list_free (children);
5093 GList *tmp_list, *children;
5095 parent = gdk_window_get_parent (widget->window);
5098 gdk_window_reparent (widget->window, new_window, 0, 0);
5101 children = gdk_window_get_children (parent);
5103 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5105 GdkWindow *window = tmp_list->data;
5108 gdk_window_get_user_data (window, &child);
5110 if (child == widget)
5111 gdk_window_reparent (window, new_window, 0, 0);
5114 g_list_free (children);
5120 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5121 gpointer client_data)
5123 g_assert (client_data != NULL);
5125 if (!gtk_widget_get_has_window (widget))
5128 g_object_unref (widget->window);
5129 widget->window = (GdkWindow*) client_data;
5131 g_object_ref (widget->window);
5133 if (GTK_IS_CONTAINER (widget))
5134 gtk_container_forall (GTK_CONTAINER (widget),
5135 gtk_widget_reparent_fixup_child,
5141 * gtk_widget_reparent:
5142 * @widget: a #GtkWidget
5143 * @new_parent: a #GtkContainer to move the widget into
5145 * Moves a widget from one #GtkContainer to another, handling reference
5146 * count issues to avoid destroying the widget.
5149 gtk_widget_reparent (GtkWidget *widget,
5150 GtkWidget *new_parent)
5152 g_return_if_fail (GTK_IS_WIDGET (widget));
5153 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5154 g_return_if_fail (widget->parent != NULL);
5156 if (widget->parent != new_parent)
5158 /* First try to see if we can get away without unrealizing
5159 * the widget as we reparent it. if so we set a flag so
5160 * that gtk_widget_unparent doesn't unrealize widget
5162 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5163 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5165 g_object_ref (widget);
5166 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5167 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5168 g_object_unref (widget);
5170 if (GTK_WIDGET_IN_REPARENT (widget))
5172 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5174 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5175 gtk_widget_reparent_fixup_child (widget,
5176 gtk_widget_get_parent_window (widget));
5179 g_object_notify (G_OBJECT (widget), "parent");
5184 * gtk_widget_intersect:
5185 * @widget: a #GtkWidget
5186 * @area: a rectangle
5187 * @intersection: rectangle to store intersection of @widget and @area
5189 * Computes the intersection of a @widget's area and @area, storing
5190 * the intersection in @intersection, and returns %TRUE if there was
5191 * an intersection. @intersection may be %NULL if you're only
5192 * interested in whether there was an intersection.
5194 * Return value: %TRUE if there was an intersection
5197 gtk_widget_intersect (GtkWidget *widget,
5198 const GdkRectangle *area,
5199 GdkRectangle *intersection)
5205 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5206 g_return_val_if_fail (area != NULL, FALSE);
5209 dest = intersection;
5213 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5215 if (return_val && intersection && gtk_widget_get_has_window (widget))
5217 intersection->x -= widget->allocation.x;
5218 intersection->y -= widget->allocation.y;
5225 * gtk_widget_region_intersect:
5226 * @widget: a #GtkWidget
5227 * @region: a #GdkRegion, in the same coordinate system as
5228 * @widget->allocation. That is, relative to @widget->window
5229 * for %NO_WINDOW widgets; relative to the parent window
5230 * of @widget->window for widgets with their own window.
5231 * @returns: A newly allocated region holding the intersection of @widget
5232 * and @region. The coordinates of the return value are
5233 * relative to @widget->window for %NO_WINDOW widgets, and
5234 * relative to the parent window of @widget->window for
5235 * widgets with their own window.
5237 * Computes the intersection of a @widget's area and @region, returning
5238 * the intersection. The result may be empty, use gdk_region_empty() to
5242 gtk_widget_region_intersect (GtkWidget *widget,
5243 const GdkRegion *region)
5248 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5249 g_return_val_if_fail (region != NULL, NULL);
5251 gtk_widget_get_draw_rectangle (widget, &rect);
5253 dest = gdk_region_rectangle (&rect);
5255 gdk_region_intersect (dest, region);
5261 * _gtk_widget_grab_notify:
5262 * @widget: a #GtkWidget
5263 * @was_grabbed: whether a grab is now in effect
5265 * Emits the #GtkWidget::grab-notify signal on @widget.
5270 _gtk_widget_grab_notify (GtkWidget *widget,
5271 gboolean was_grabbed)
5273 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5277 * gtk_widget_grab_focus:
5278 * @widget: a #GtkWidget
5280 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5281 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5282 * something like #GtkFrame won't work.
5284 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5285 * gtk_widget_set_can_focus() to modify that flag.
5288 gtk_widget_grab_focus (GtkWidget *widget)
5290 g_return_if_fail (GTK_IS_WIDGET (widget));
5292 if (!gtk_widget_is_sensitive (widget))
5295 g_object_ref (widget);
5296 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5297 g_object_notify (G_OBJECT (widget), "has-focus");
5298 g_object_unref (widget);
5302 reset_focus_recurse (GtkWidget *widget,
5305 if (GTK_IS_CONTAINER (widget))
5307 GtkContainer *container;
5309 container = GTK_CONTAINER (widget);
5310 gtk_container_set_focus_child (container, NULL);
5312 gtk_container_foreach (container,
5313 reset_focus_recurse,
5319 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5321 if (gtk_widget_get_can_focus (focus_widget))
5323 GtkWidget *toplevel;
5326 /* clear the current focus setting, break if the current widget
5327 * is the focus widget's parent, since containers above that will
5328 * be set by the next loop.
5330 toplevel = gtk_widget_get_toplevel (focus_widget);
5331 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5333 widget = GTK_WINDOW (toplevel)->focus_widget;
5335 if (widget == focus_widget)
5337 /* We call _gtk_window_internal_set_focus() here so that the
5338 * toplevel window can request the focus if necessary.
5339 * This is needed when the toplevel is a GtkPlug
5341 if (!gtk_widget_has_focus (widget))
5342 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5349 while (widget->parent && widget->parent != focus_widget->parent)
5351 widget = widget->parent;
5352 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5356 else if (toplevel != focus_widget)
5358 /* gtk_widget_grab_focus() operates on a tree without window...
5359 * actually, this is very questionable behaviour.
5362 gtk_container_foreach (GTK_CONTAINER (toplevel),
5363 reset_focus_recurse,
5367 /* now propagate the new focus up the widget tree and finally
5368 * set it on the window
5370 widget = focus_widget;
5371 while (widget->parent)
5373 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5374 widget = widget->parent;
5376 if (GTK_IS_WINDOW (widget))
5377 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5382 gtk_widget_real_query_tooltip (GtkWidget *widget,
5385 gboolean keyboard_tip,
5386 GtkTooltip *tooltip)
5388 gchar *tooltip_markup;
5389 gboolean has_tooltip;
5391 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5392 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5394 if (has_tooltip && tooltip_markup)
5396 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5404 gtk_widget_real_show_help (GtkWidget *widget,
5405 GtkWidgetHelpType help_type)
5407 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5409 _gtk_tooltip_toggle_keyboard_mode (widget);
5418 gtk_widget_real_focus (GtkWidget *widget,
5419 GtkDirectionType direction)
5421 if (!gtk_widget_get_can_focus (widget))
5424 if (!gtk_widget_is_focus (widget))
5426 gtk_widget_grab_focus (widget);
5434 gtk_widget_real_move_focus (GtkWidget *widget,
5435 GtkDirectionType direction)
5437 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5439 if (GTK_IS_WINDOW (toplevel) &&
5440 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5442 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5448 gtk_widget_real_keynav_failed (GtkWidget *widget,
5449 GtkDirectionType direction)
5451 gboolean cursor_only;
5455 case GTK_DIR_TAB_FORWARD:
5456 case GTK_DIR_TAB_BACKWARD:
5463 g_object_get (gtk_widget_get_settings (widget),
5464 "gtk-keynav-cursor-only", &cursor_only,
5471 gtk_widget_error_bell (widget);
5477 * gtk_widget_set_can_focus:
5478 * @widget: a #GtkWidget
5479 * @can_focus: whether or not @widget can own the input focus.
5481 * Specifies whether @widget can own the input focus. See
5482 * gtk_widget_grab_focus() for actually setting the input focus on a
5488 gtk_widget_set_can_focus (GtkWidget *widget,
5491 g_return_if_fail (GTK_IS_WIDGET (widget));
5493 if (can_focus != gtk_widget_get_can_focus (widget))
5496 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5498 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5500 gtk_widget_queue_resize (widget);
5501 g_object_notify (G_OBJECT (widget), "can-focus");
5506 * gtk_widget_get_can_focus:
5507 * @widget: a #GtkWidget
5509 * Determines whether @widget can own the input focus. See
5510 * gtk_widget_set_can_focus().
5512 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5517 gtk_widget_get_can_focus (GtkWidget *widget)
5519 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5521 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5525 * gtk_widget_has_focus:
5526 * @widget: a #GtkWidget
5528 * Determines if the widget has the global input focus. See
5529 * gtk_widget_is_focus() for the difference between having the global
5530 * input focus, and only having the focus within a toplevel.
5532 * Return value: %TRUE if the widget has the global input focus.
5537 gtk_widget_has_focus (GtkWidget *widget)
5539 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5541 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5545 * gtk_widget_is_focus:
5546 * @widget: a #GtkWidget
5548 * Determines if the widget is the focus widget within its
5549 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5550 * necessarily set; %HAS_FOCUS will only be set if the
5551 * toplevel widget additionally has the global input focus.)
5553 * Return value: %TRUE if the widget is the focus widget.
5556 gtk_widget_is_focus (GtkWidget *widget)
5558 GtkWidget *toplevel;
5560 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5562 toplevel = gtk_widget_get_toplevel (widget);
5564 if (GTK_IS_WINDOW (toplevel))
5565 return widget == GTK_WINDOW (toplevel)->focus_widget;
5571 * gtk_widget_set_can_default:
5572 * @widget: a #GtkWidget
5573 * @can_default: whether or not @widget can be a default widget.
5575 * Specifies whether @widget can be a default widget. See
5576 * gtk_widget_grab_default() for details about the meaning of
5582 gtk_widget_set_can_default (GtkWidget *widget,
5583 gboolean can_default)
5585 g_return_if_fail (GTK_IS_WIDGET (widget));
5587 if (can_default != gtk_widget_get_can_default (widget))
5590 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5592 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5594 gtk_widget_queue_resize (widget);
5595 g_object_notify (G_OBJECT (widget), "can-default");
5600 * gtk_widget_get_can_default:
5601 * @widget: a #GtkWidget
5603 * Determines whether @widget can be a default widget. See
5604 * gtk_widget_set_can_default().
5606 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5611 gtk_widget_get_can_default (GtkWidget *widget)
5613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5615 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5619 * gtk_widget_has_default:
5620 * @widget: a #GtkWidget
5622 * Determines whether @widget is the current default widget within its
5623 * toplevel. See gtk_widget_set_can_default().
5625 * Return value: %TRUE if @widget is the current default widget within
5626 * its toplevel, %FALSE otherwise
5631 gtk_widget_has_default (GtkWidget *widget)
5633 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5635 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5639 _gtk_widget_set_has_default (GtkWidget *widget,
5640 gboolean has_default)
5643 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5645 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5649 * gtk_widget_grab_default:
5650 * @widget: a #GtkWidget
5652 * Causes @widget to become the default widget. @widget must have the
5653 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5654 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5655 * %TRUE)</literal>. The default widget is activated when
5656 * the user presses Enter in a window. Default widgets must be
5657 * activatable, that is, gtk_widget_activate() should affect them.
5660 gtk_widget_grab_default (GtkWidget *widget)
5664 g_return_if_fail (GTK_IS_WIDGET (widget));
5665 g_return_if_fail (gtk_widget_get_can_default (widget));
5667 window = gtk_widget_get_toplevel (widget);
5669 if (window && gtk_widget_is_toplevel (window))
5670 gtk_window_set_default (GTK_WINDOW (window), widget);
5672 g_warning (G_STRLOC ": widget not within a GtkWindow");
5676 * gtk_widget_set_receives_default:
5677 * @widget: a #GtkWidget
5678 * @receives_default: whether or not @widget can be a default widget.
5680 * Specifies whether @widget will be treated as the default widget
5681 * within its toplevel when it has the focus, even if another widget
5684 * See gtk_widget_grab_default() for details about the meaning of
5690 gtk_widget_set_receives_default (GtkWidget *widget,
5691 gboolean receives_default)
5693 g_return_if_fail (GTK_IS_WIDGET (widget));
5695 if (receives_default != gtk_widget_get_receives_default (widget))
5697 if (receives_default)
5698 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5700 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5702 g_object_notify (G_OBJECT (widget), "receives-default");
5707 * gtk_widget_get_receives_default:
5708 * @widget: a #GtkWidget
5710 * Determines whether @widget is alyways treated as default widget
5711 * withing its toplevel when it has the focus, even if another widget
5714 * See gtk_widget_set_receives_default().
5716 * Return value: %TRUE if @widget acts as default widget when focussed,
5722 gtk_widget_get_receives_default (GtkWidget *widget)
5724 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5726 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5730 * gtk_widget_has_grab:
5731 * @widget: a #GtkWidget
5733 * Determines whether the widget is currently grabbing events, so it
5734 * is the only widget receiving input events (keyboard and mouse).
5736 * See also gtk_grab_add().
5738 * Return value: %TRUE if the widget is in the grab_widgets stack
5743 gtk_widget_has_grab (GtkWidget *widget)
5745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5747 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5751 _gtk_widget_set_has_grab (GtkWidget *widget,
5755 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
5757 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
5761 * gtk_widget_set_name:
5762 * @widget: a #GtkWidget
5763 * @name: name for the widget
5765 * Widgets can be named, which allows you to refer to them from a
5766 * gtkrc file. You can apply a style to widgets with a particular name
5767 * in the gtkrc file. See the documentation for gtkrc files (on the
5768 * same page as the docs for #GtkRcStyle).
5770 * Note that widget names are separated by periods in paths (see
5771 * gtk_widget_path()), so names with embedded periods may cause confusion.
5774 gtk_widget_set_name (GtkWidget *widget,
5779 g_return_if_fail (GTK_IS_WIDGET (widget));
5781 new_name = g_strdup (name);
5782 g_free (widget->name);
5783 widget->name = new_name;
5785 if (gtk_widget_has_rc_style (widget))
5786 gtk_widget_reset_rc_style (widget);
5788 g_object_notify (G_OBJECT (widget), "name");
5792 * gtk_widget_get_name:
5793 * @widget: a #GtkWidget
5795 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5796 * significance of widget names.
5798 * Return value: name of the widget. This string is owned by GTK+ and
5799 * should not be modified or freed
5801 G_CONST_RETURN gchar*
5802 gtk_widget_get_name (GtkWidget *widget)
5804 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5807 return widget->name;
5808 return G_OBJECT_TYPE_NAME (widget);
5812 * gtk_widget_set_state:
5813 * @widget: a #GtkWidget
5814 * @state: new state for @widget
5816 * This function is for use in widget implementations. Sets the state
5817 * of a widget (insensitive, prelighted, etc.) Usually you should set
5818 * the state using wrapper functions such as gtk_widget_set_sensitive().
5821 gtk_widget_set_state (GtkWidget *widget,
5824 g_return_if_fail (GTK_IS_WIDGET (widget));
5826 if (state == gtk_widget_get_state (widget))
5829 if (state == GTK_STATE_INSENSITIVE)
5830 gtk_widget_set_sensitive (widget, FALSE);
5836 data.state_restoration = FALSE;
5837 data.use_forall = FALSE;
5839 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5841 data.parent_sensitive = TRUE;
5843 gtk_widget_propagate_state (widget, &data);
5845 if (gtk_widget_is_drawable (widget))
5846 gtk_widget_queue_draw (widget);
5851 * gtk_widget_get_state:
5852 * @widget: a #GtkWidget
5854 * Returns the widget's state. See gtk_widget_set_state().
5856 * Returns: the state of @widget.
5861 gtk_widget_get_state (GtkWidget *widget)
5863 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5865 return widget->state;
5869 * gtk_widget_set_visible:
5870 * @widget: a #GtkWidget
5871 * @visible: whether the widget should be shown or not
5873 * Sets the visibility state of @widget. Note that setting this to
5874 * %TRUE doesn't mean the widget is actually viewable, see
5875 * gtk_widget_get_visible().
5877 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5878 * but is nicer to use when the visibility of the widget depends on
5884 gtk_widget_set_visible (GtkWidget *widget,
5887 g_return_if_fail (GTK_IS_WIDGET (widget));
5889 if (visible != gtk_widget_get_visible (widget))
5892 gtk_widget_show (widget);
5894 gtk_widget_hide (widget);
5899 * gtk_widget_get_visible:
5900 * @widget: a #GtkWidget
5902 * Determines whether the widget is visible. Note that this doesn't
5903 * take into account whether the widget's parent is also visible
5904 * or the widget is obscured in any way.
5906 * See gtk_widget_set_visible().
5908 * Return value: %TRUE if the widget is visible
5913 gtk_widget_get_visible (GtkWidget *widget)
5915 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5917 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5921 * gtk_widget_set_has_window:
5922 * @widget: a #GtkWidget
5923 * @has_window: whether or not @widget has a window.
5925 * Specifies whether @widget has a #GdkWindow of its own. Note that
5926 * all realized widgets have a non-%NULL "window" pointer
5927 * (gtk_widget_get_window() never returns a %NULL window when a widget
5928 * is realized), but for many of them it's actually the #GdkWindow of
5929 * one of its parent widgets. Widgets that create a %window for
5930 * themselves in GtkWidget::realize() however must announce this by
5931 * calling this function with @has_window = %TRUE.
5933 * This function should only be called by widget implementations,
5934 * and they should call it in their init() function.
5939 gtk_widget_set_has_window (GtkWidget *widget,
5940 gboolean has_window)
5942 g_return_if_fail (GTK_IS_WIDGET (widget));
5945 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5947 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5951 * gtk_widget_get_has_window:
5952 * @widget: a #GtkWidget
5954 * Determines whether @widget has a #GdkWindow of its own. See
5955 * gtk_widget_set_has_window().
5957 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5962 gtk_widget_get_has_window (GtkWidget *widget)
5964 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5966 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5970 * gtk_widget_is_toplevel:
5971 * @widget: a #GtkWidget
5973 * Determines whether @widget is a toplevel widget. Currently only
5974 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5975 * widgets have no parent widget.
5977 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5982 gtk_widget_is_toplevel (GtkWidget *widget)
5984 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5986 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5990 _gtk_widget_set_is_toplevel (GtkWidget *widget,
5991 gboolean is_toplevel)
5994 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
5996 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6000 * gtk_widget_is_drawable:
6001 * @widget: a #GtkWidget
6003 * Determines whether @widget can be drawn to. A widget can be drawn
6004 * to if it is mapped and visible.
6006 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6011 gtk_widget_is_drawable (GtkWidget *widget)
6013 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6015 return (gtk_widget_get_visible (widget) &&
6016 gtk_widget_get_mapped (widget));
6020 * gtk_widget_get_realized:
6021 * @widget: a #GtkWidget
6023 * Determines whether @widget is realized.
6025 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6030 gtk_widget_get_realized (GtkWidget *widget)
6032 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6034 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6038 * gtk_widget_set_realized:
6039 * @widget: a #GtkWidget
6040 * @realized: %TRUE to mark the widget as realized
6042 * Marks the widget as being realized.
6044 * This function should only ever be called in a derived widget's
6045 * "realize" or "unrealize" implementation.
6050 gtk_widget_set_realized (GtkWidget *widget,
6053 g_return_if_fail (GTK_IS_WIDGET (widget));
6056 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6058 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6062 * gtk_widget_get_mapped:
6063 * @widget: a #GtkWidget
6065 * Whether the widget is mapped.
6067 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6072 gtk_widget_get_mapped (GtkWidget *widget)
6074 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6076 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6080 * gtk_widget_set_mapped:
6081 * @widget: a #GtkWidget
6082 * @mapped: %TRUE to mark the widget as mapped
6084 * Marks the widget as being realized.
6086 * This function should only ever be called in a derived widget's
6087 * "map" or "unmap" implementation.
6092 gtk_widget_set_mapped (GtkWidget *widget,
6095 g_return_if_fail (GTK_IS_WIDGET (widget));
6098 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6100 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6104 * gtk_widget_set_app_paintable:
6105 * @widget: a #GtkWidget
6106 * @app_paintable: %TRUE if the application will paint on the widget
6108 * Sets whether the application intends to draw on the widget in
6109 * an #GtkWidget::expose-event handler.
6111 * This is a hint to the widget and does not affect the behavior of
6112 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6113 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6114 * the effect is to suppress default themed drawing of the widget's
6115 * background. (Children of the widget will still be drawn.) The application
6116 * is then entirely responsible for drawing the widget background.
6118 * Note that the background is still drawn when the widget is mapped.
6119 * If this is not suitable (e.g. because you want to make a transparent
6120 * window using an RGBA visual), you can work around this by doing:
6122 * gtk_widget_realize (window);
6123 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6124 * gtk_widget_show (window);
6128 gtk_widget_set_app_paintable (GtkWidget *widget,
6129 gboolean app_paintable)
6131 g_return_if_fail (GTK_IS_WIDGET (widget));
6133 app_paintable = (app_paintable != FALSE);
6135 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6138 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6140 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6142 if (gtk_widget_is_drawable (widget))
6143 gtk_widget_queue_draw (widget);
6145 g_object_notify (G_OBJECT (widget), "app-paintable");
6150 * gtk_widget_get_app_paintable:
6151 * @widget: a #GtkWidget
6153 * Determines whether the application intends to draw on the widget in
6154 * an #GtkWidget::expose-event handler.
6156 * See gtk_widget_set_app_paintable()
6158 * Return value: %TRUE if the widget is app paintable
6163 gtk_widget_get_app_paintable (GtkWidget *widget)
6165 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6167 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6171 * gtk_widget_set_double_buffered:
6172 * @widget: a #GtkWidget
6173 * @double_buffered: %TRUE to double-buffer a widget
6175 * Widgets are double buffered by default; you can use this function
6176 * to turn off the buffering. "Double buffered" simply means that
6177 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6178 * automatically around expose events sent to the
6179 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6180 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6181 * buffer to the screen. The result is that users see the window
6182 * update in one smooth step, and don't see individual graphics
6183 * primitives being rendered.
6185 * In very simple terms, double buffered widgets don't flicker,
6186 * so you would only use this function to turn off double buffering
6187 * if you had special needs and really knew what you were doing.
6189 * Note: if you turn off double-buffering, you have to handle
6190 * expose events, since even the clearing to the background color or
6191 * pixmap will not happen automatically (as it is done in
6192 * gdk_window_begin_paint()).
6195 gtk_widget_set_double_buffered (GtkWidget *widget,
6196 gboolean double_buffered)
6198 g_return_if_fail (GTK_IS_WIDGET (widget));
6200 double_buffered = (double_buffered != FALSE);
6202 if (double_buffered != gtk_widget_get_double_buffered (widget))
6204 if (double_buffered)
6205 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6207 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6209 g_object_notify (G_OBJECT (widget), "double-buffered");
6214 * gtk_widget_get_double_buffered:
6215 * @widget: a #GtkWidget
6217 * Determines whether the widget is double buffered.
6219 * See gtk_widget_set_double_buffered()
6221 * Return value: %TRUE if the widget is double buffered
6226 gtk_widget_get_double_buffered (GtkWidget *widget)
6228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6230 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6234 * gtk_widget_set_redraw_on_allocate:
6235 * @widget: a #GtkWidget
6236 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6237 * when it is allocated to a new size. Otherwise, only the
6238 * new portion of the widget will be redrawn.
6240 * Sets whether the entire widget is queued for drawing when its size
6241 * allocation changes. By default, this setting is %TRUE and
6242 * the entire widget is redrawn on every size change. If your widget
6243 * leaves the upper left unchanged when made bigger, turning this
6244 * setting off will improve performance.
6246 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6247 * off all allocation on resizing: the widget will not even redraw if
6248 * its position changes; this is to allow containers that don't draw
6249 * anything to avoid excess invalidations. If you set this flag on a
6250 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6251 * you are responsible for invalidating both the old and new allocation
6252 * of the widget when the widget is moved and responsible for invalidating
6253 * regions newly when the widget increases size.
6256 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6257 gboolean redraw_on_allocate)
6259 g_return_if_fail (GTK_IS_WIDGET (widget));
6261 if (redraw_on_allocate)
6262 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6264 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6268 * gtk_widget_set_sensitive:
6269 * @widget: a #GtkWidget
6270 * @sensitive: %TRUE to make the widget sensitive
6272 * Sets the sensitivity of a widget. A widget is sensitive if the user
6273 * can interact with it. Insensitive widgets are "grayed out" and the
6274 * user can't interact with them. Insensitive widgets are known as
6275 * "inactive", "disabled", or "ghosted" in some other toolkits.
6278 gtk_widget_set_sensitive (GtkWidget *widget,
6283 g_return_if_fail (GTK_IS_WIDGET (widget));
6285 sensitive = (sensitive != FALSE);
6287 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6292 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6293 data.state = widget->saved_state;
6297 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6298 data.state = gtk_widget_get_state (widget);
6300 data.state_restoration = TRUE;
6301 data.use_forall = TRUE;
6304 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6306 data.parent_sensitive = TRUE;
6308 gtk_widget_propagate_state (widget, &data);
6309 if (gtk_widget_is_drawable (widget))
6310 gtk_widget_queue_draw (widget);
6312 g_object_notify (G_OBJECT (widget), "sensitive");
6316 * gtk_widget_get_sensitive:
6317 * @widget: a #GtkWidget
6319 * Returns the widget's sensitivity (in the sense of returning
6320 * the value that has been set using gtk_widget_set_sensitive()).
6322 * The effective sensitivity of a widget is however determined by both its
6323 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6325 * Returns: %TRUE if the widget is sensitive
6330 gtk_widget_get_sensitive (GtkWidget *widget)
6332 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6334 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6338 * gtk_widget_is_sensitive:
6339 * @widget: a #GtkWidget
6341 * Returns the widget's effective sensitivity, which means
6342 * it is sensitive itself and also its parent widget is sensntive
6344 * Returns: %TRUE if the widget is effectively sensitive
6349 gtk_widget_is_sensitive (GtkWidget *widget)
6351 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6353 return (gtk_widget_get_sensitive (widget) &&
6354 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6358 * gtk_widget_set_parent:
6359 * @widget: a #GtkWidget
6360 * @parent: parent container
6362 * This function is useful only when implementing subclasses of
6364 * Sets the container as the parent of @widget, and takes care of
6365 * some details such as updating the state and style of the child
6366 * to reflect its new location. The opposite function is
6367 * gtk_widget_unparent().
6370 gtk_widget_set_parent (GtkWidget *widget,
6375 g_return_if_fail (GTK_IS_WIDGET (widget));
6376 g_return_if_fail (GTK_IS_WIDGET (parent));
6377 g_return_if_fail (widget != parent);
6378 if (widget->parent != NULL)
6380 g_warning ("Can't set a parent on widget which has a parent\n");
6383 if (gtk_widget_is_toplevel (widget))
6385 g_warning ("Can't set a parent on a toplevel widget\n");
6389 /* keep this function in sync with gtk_menu_attach_to_widget()
6392 g_object_ref_sink (widget);
6393 widget->parent = parent;
6395 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6396 data.state = gtk_widget_get_state (parent);
6398 data.state = gtk_widget_get_state (widget);
6399 data.state_restoration = FALSE;
6400 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6401 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6403 gtk_widget_propagate_state (widget, &data);
6405 gtk_widget_reset_rc_styles (widget);
6407 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6408 if (GTK_WIDGET_ANCHORED (widget->parent))
6409 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6410 g_object_notify (G_OBJECT (widget), "parent");
6412 /* Enforce realized/mapped invariants
6414 if (gtk_widget_get_realized (widget->parent))
6415 gtk_widget_realize (widget);
6417 if (gtk_widget_get_visible (widget->parent) &&
6418 gtk_widget_get_visible (widget))
6420 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6421 gtk_widget_get_mapped (widget->parent))
6422 gtk_widget_map (widget);
6424 gtk_widget_queue_resize (widget);
6429 * gtk_widget_get_parent:
6430 * @widget: a #GtkWidget
6432 * Returns the parent container of @widget.
6434 * Return value: (transfer none): the parent container of @widget, or %NULL
6437 gtk_widget_get_parent (GtkWidget *widget)
6439 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6441 return widget->parent;
6444 /*****************************************
6446 * see docs/styles.txt
6447 *****************************************/
6450 * gtk_widget_style_attach:
6451 * @widget: a #GtkWidget
6453 * This function attaches the widget's #GtkStyle to the widget's
6454 * #GdkWindow. It is a replacement for
6457 * widget->style = gtk_style_attach (widget->style, widget->window);
6460 * and should only ever be called in a derived widget's "realize"
6461 * implementation which does not chain up to its parent class'
6462 * "realize" implementation, because one of the parent classes
6463 * (finally #GtkWidget) would attach the style itself.
6468 gtk_widget_style_attach (GtkWidget *widget)
6470 g_return_if_fail (GTK_IS_WIDGET (widget));
6471 g_return_if_fail (gtk_widget_get_realized (widget));
6473 widget->style = gtk_style_attach (widget->style, widget->window);
6477 * gtk_widget_has_rc_style:
6478 * @widget: a #GtkWidget
6480 * Determines if the widget style has been looked up through the rc mechanism.
6482 * Returns: %TRUE if the widget has been looked up through the rc
6483 * mechanism, %FALSE otherwise.
6488 gtk_widget_has_rc_style (GtkWidget *widget)
6490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6492 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6496 * gtk_widget_set_style:
6497 * @widget: a #GtkWidget
6498 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6499 * gtk_widget_set_style() and go back to the default style
6501 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6502 * want to use this function; it interacts badly with themes, because
6503 * themes work by replacing the #GtkStyle. Instead, use
6504 * gtk_widget_modify_style().
6507 gtk_widget_set_style (GtkWidget *widget,
6510 g_return_if_fail (GTK_IS_WIDGET (widget));
6514 gboolean initial_emission;
6516 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6518 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6519 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6521 gtk_widget_set_style_internal (widget, style, initial_emission);
6525 if (GTK_WIDGET_USER_STYLE (widget))
6526 gtk_widget_reset_rc_style (widget);
6531 * gtk_widget_ensure_style:
6532 * @widget: a #GtkWidget
6534 * Ensures that @widget has a style (@widget->style). Not a very useful
6535 * function; most of the time, if you want the style, the widget is
6536 * realized, and realized widgets are guaranteed to have a style
6540 gtk_widget_ensure_style (GtkWidget *widget)
6542 g_return_if_fail (GTK_IS_WIDGET (widget));
6544 if (!GTK_WIDGET_USER_STYLE (widget) &&
6545 !gtk_widget_has_rc_style (widget))
6546 gtk_widget_reset_rc_style (widget);
6549 /* Look up the RC style for this widget, unsetting any user style that
6550 * may be in effect currently
6553 gtk_widget_reset_rc_style (GtkWidget *widget)
6555 GtkStyle *new_style = NULL;
6556 gboolean initial_emission;
6558 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6560 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6561 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6563 if (gtk_widget_has_screen (widget))
6564 new_style = gtk_rc_get_style (widget);
6566 new_style = gtk_widget_get_default_style ();
6568 if (initial_emission || new_style != widget->style)
6569 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6573 * gtk_widget_get_style:
6574 * @widget: a #GtkWidget
6576 * Simply an accessor function that returns @widget->style.
6578 * Return value: (transfer none): the widget's #GtkStyle
6581 gtk_widget_get_style (GtkWidget *widget)
6583 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6585 return widget->style;
6589 * gtk_widget_modify_style:
6590 * @widget: a #GtkWidget
6591 * @style: the #GtkRcStyle holding the style modifications
6593 * Modifies style values on the widget. Modifications made using this
6594 * technique take precedence over style values set via an RC file,
6595 * however, they will be overriden if a style is explicitely set on
6596 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6597 * is designed so each field can either be set or unset, so it is
6598 * possible, using this function, to modify some style values and
6599 * leave the others unchanged.
6601 * Note that modifications made with this function are not cumulative
6602 * with previous calls to gtk_widget_modify_style() or with such
6603 * functions as gtk_widget_modify_fg(). If you wish to retain
6604 * previous values, you must first call gtk_widget_get_modifier_style(),
6605 * make your modifications to the returned style, then call
6606 * gtk_widget_modify_style() with that style. On the other hand,
6607 * if you first call gtk_widget_modify_style(), subsequent calls
6608 * to such functions gtk_widget_modify_fg() will have a cumulative
6609 * effect with the initial modifications.
6612 gtk_widget_modify_style (GtkWidget *widget,
6615 g_return_if_fail (GTK_IS_WIDGET (widget));
6616 g_return_if_fail (GTK_IS_RC_STYLE (style));
6618 g_object_set_qdata_full (G_OBJECT (widget),
6620 gtk_rc_style_copy (style),
6621 (GDestroyNotify) g_object_unref);
6623 /* note that "style" may be invalid here if it was the old
6624 * modifier style and the only reference was our own.
6627 if (gtk_widget_has_rc_style (widget))
6628 gtk_widget_reset_rc_style (widget);
6632 * gtk_widget_get_modifier_style:
6633 * @widget: a #GtkWidget
6635 * Returns the current modifier style for the widget. (As set by
6636 * gtk_widget_modify_style().) If no style has previously set, a new
6637 * #GtkRcStyle will be created with all values unset, and set as the
6638 * modifier style for the widget. If you make changes to this rc
6639 * style, you must call gtk_widget_modify_style(), passing in the
6640 * returned rc style, to make sure that your changes take effect.
6642 * Caution: passing the style back to gtk_widget_modify_style() will
6643 * normally end up destroying it, because gtk_widget_modify_style() copies
6644 * the passed-in style and sets the copy as the new modifier style,
6645 * thus dropping any reference to the old modifier style. Add a reference
6646 * to the modifier style if you want to keep it alive.
6648 * Return value: (transfer none): the modifier style for the widget. This rc style is
6649 * owned by the widget. If you want to keep a pointer to value this
6650 * around, you must add a refcount using g_object_ref().
6653 gtk_widget_get_modifier_style (GtkWidget *widget)
6655 GtkRcStyle *rc_style;
6657 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6659 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6663 rc_style = gtk_rc_style_new ();
6664 g_object_set_qdata_full (G_OBJECT (widget),
6667 (GDestroyNotify) g_object_unref);
6674 gtk_widget_modify_color_component (GtkWidget *widget,
6675 GtkRcFlags component,
6677 const GdkColor *color)
6679 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6686 rc_style->fg[state] = *color;
6689 rc_style->bg[state] = *color;
6692 rc_style->text[state] = *color;
6695 rc_style->base[state] = *color;
6698 g_assert_not_reached();
6701 rc_style->color_flags[state] |= component;
6704 rc_style->color_flags[state] &= ~component;
6706 gtk_widget_modify_style (widget, rc_style);
6710 * gtk_widget_modify_symbolic_color:
6711 * @widget: a #GtkWidget
6712 * @name: the name of the symbolic color to modify
6713 * @color: (allow-none): the color to assign (does not need to be allocated),
6714 * or %NULL to undo the effect of previous calls to
6715 * of gtk_widget_modify_symbolic_color().
6717 * Sets a symbolic color for a widget.
6718 * All other style values are left untouched. See also
6719 * gtk_widget_modify_style().
6724 gtk_widget_modify_symbolic_color (GtkWidget *widget,
6726 const GdkColor *color)
6728 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6730 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
6732 gtk_widget_modify_style (widget, rc_style);
6736 * gtk_widget_modify_fg:
6737 * @widget: a #GtkWidget
6738 * @state: the state for which to set the foreground color
6739 * @color: (allow-none): the color to assign (does not need to be allocated),
6740 * or %NULL to undo the effect of previous calls to
6741 * of gtk_widget_modify_fg().
6743 * Sets the foreground color for a widget in a particular state.
6744 * All other style values are left untouched. See also
6745 * gtk_widget_modify_style().
6748 gtk_widget_modify_fg (GtkWidget *widget,
6750 const GdkColor *color)
6752 g_return_if_fail (GTK_IS_WIDGET (widget));
6753 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6755 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6759 * gtk_widget_modify_bg:
6760 * @widget: a #GtkWidget
6761 * @state: the state for which to set the background color
6762 * @color: (allow-none): the color to assign (does not need to be allocated),
6763 * or %NULL to undo the effect of previous calls to
6764 * of gtk_widget_modify_bg().
6766 * Sets the background color for a widget in a particular state.
6767 * All other style values are left untouched. See also
6768 * gtk_widget_modify_style().
6770 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6771 * draw on their parent container's window and thus may not draw any
6772 * background themselves. This is the case for e.g. #GtkLabel. To modify
6773 * the background of such widgets, you have to set the background color
6774 * on their parent; if you want to set the background of a rectangular
6775 * area around a label, try placing the label in a #GtkEventBox widget
6776 * and setting the background color on that.
6779 gtk_widget_modify_bg (GtkWidget *widget,
6781 const GdkColor *color)
6783 g_return_if_fail (GTK_IS_WIDGET (widget));
6784 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6786 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6790 * gtk_widget_modify_text:
6791 * @widget: a #GtkWidget
6792 * @state: the state for which to set the text color
6793 * @color: (allow-none): the color to assign (does not need to be allocated),
6794 * or %NULL to undo the effect of previous calls to
6795 * of gtk_widget_modify_text().
6797 * Sets the text color for a widget in a particular state. All other
6798 * style values are left untouched. The text color is the foreground
6799 * color used along with the base color (see gtk_widget_modify_base())
6800 * for widgets such as #GtkEntry and #GtkTextView. See also
6801 * gtk_widget_modify_style().
6804 gtk_widget_modify_text (GtkWidget *widget,
6806 const GdkColor *color)
6808 g_return_if_fail (GTK_IS_WIDGET (widget));
6809 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6811 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6815 * gtk_widget_modify_base:
6816 * @widget: a #GtkWidget
6817 * @state: the state for which to set the base color
6818 * @color: (allow-none): the color to assign (does not need to be allocated),
6819 * or %NULL to undo the effect of previous calls to
6820 * of gtk_widget_modify_base().
6822 * Sets the base color for a widget in a particular state.
6823 * All other style values are left untouched. The base color
6824 * is the background color used along with the text color
6825 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6826 * and #GtkTextView. See also gtk_widget_modify_style().
6828 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6829 * draw on their parent container's window and thus may not draw any
6830 * background themselves. This is the case for e.g. #GtkLabel. To modify
6831 * the background of such widgets, you have to set the base color on their
6832 * parent; if you want to set the background of a rectangular area around
6833 * a label, try placing the label in a #GtkEventBox widget and setting
6834 * the base color on that.
6837 gtk_widget_modify_base (GtkWidget *widget,
6839 const GdkColor *color)
6841 g_return_if_fail (GTK_IS_WIDGET (widget));
6842 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6844 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6848 modify_color_property (GtkWidget *widget,
6849 GtkRcStyle *rc_style,
6851 const GdkColor *color)
6853 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6854 GQuark property_name = g_quark_from_string (name);
6858 GtkRcProperty rc_property = {0};
6861 rc_property.type_name = type_name;
6862 rc_property.property_name = property_name;
6863 rc_property.origin = NULL;
6865 color_name = gdk_color_to_string (color);
6866 g_value_init (&rc_property.value, G_TYPE_STRING);
6867 g_value_take_string (&rc_property.value, color_name);
6869 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6871 g_value_unset (&rc_property.value);
6874 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6878 * gtk_widget_modify_cursor:
6879 * @widget: a #GtkWidget
6880 * @primary: the color to use for primary cursor (does not need to be
6881 * allocated), or %NULL to undo the effect of previous calls to
6882 * of gtk_widget_modify_cursor().
6883 * @secondary: the color to use for secondary cursor (does not need to be
6884 * allocated), or %NULL to undo the effect of previous calls to
6885 * of gtk_widget_modify_cursor().
6887 * Sets the cursor color to use in a widget, overriding the
6888 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6889 * style properties. All other style values are left untouched.
6890 * See also gtk_widget_modify_style().
6895 gtk_widget_modify_cursor (GtkWidget *widget,
6896 const GdkColor *primary,
6897 const GdkColor *secondary)
6899 GtkRcStyle *rc_style;
6901 g_return_if_fail (GTK_IS_WIDGET (widget));
6903 rc_style = gtk_widget_get_modifier_style (widget);
6905 modify_color_property (widget, rc_style, "cursor-color", primary);
6906 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6908 gtk_widget_modify_style (widget, rc_style);
6912 * gtk_widget_modify_font:
6913 * @widget: a #GtkWidget
6914 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6915 * the effect of previous calls to gtk_widget_modify_font().
6917 * Sets the font to use for a widget. All other style values are left
6918 * untouched. See also gtk_widget_modify_style().
6921 gtk_widget_modify_font (GtkWidget *widget,
6922 PangoFontDescription *font_desc)
6924 GtkRcStyle *rc_style;
6926 g_return_if_fail (GTK_IS_WIDGET (widget));
6928 rc_style = gtk_widget_get_modifier_style (widget);
6930 if (rc_style->font_desc)
6931 pango_font_description_free (rc_style->font_desc);
6934 rc_style->font_desc = pango_font_description_copy (font_desc);
6936 rc_style->font_desc = NULL;
6938 gtk_widget_modify_style (widget, rc_style);
6942 gtk_widget_real_direction_changed (GtkWidget *widget,
6943 GtkTextDirection previous_direction)
6945 gtk_widget_queue_resize (widget);
6949 gtk_widget_real_style_set (GtkWidget *widget,
6950 GtkStyle *previous_style)
6952 if (gtk_widget_get_realized (widget) &&
6953 gtk_widget_get_has_window (widget))
6954 gtk_style_set_background (widget->style, widget->window, widget->state);
6958 gtk_widget_set_style_internal (GtkWidget *widget,
6960 gboolean initial_emission)
6962 g_object_ref (widget);
6963 g_object_freeze_notify (G_OBJECT (widget));
6965 if (widget->style != style)
6967 GtkStyle *previous_style;
6969 if (gtk_widget_get_realized (widget))
6971 gtk_widget_reset_shapes (widget);
6972 gtk_style_detach (widget->style);
6975 previous_style = widget->style;
6976 widget->style = style;
6977 g_object_ref (widget->style);
6979 if (gtk_widget_get_realized (widget))
6980 widget->style = gtk_style_attach (widget->style, widget->window);
6982 gtk_widget_update_pango_context (widget);
6983 g_signal_emit (widget,
6984 widget_signals[STYLE_SET],
6986 initial_emission ? NULL : previous_style);
6987 g_object_unref (previous_style);
6989 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6990 gtk_widget_queue_resize (widget);
6992 else if (initial_emission)
6994 gtk_widget_update_pango_context (widget);
6995 g_signal_emit (widget,
6996 widget_signals[STYLE_SET],
7000 g_object_notify (G_OBJECT (widget), "style");
7001 g_object_thaw_notify (G_OBJECT (widget));
7002 g_object_unref (widget);
7006 GtkWidget *previous_toplevel;
7007 GdkScreen *previous_screen;
7008 GdkScreen *new_screen;
7009 } HierarchyChangedInfo;
7012 do_screen_change (GtkWidget *widget,
7013 GdkScreen *old_screen,
7014 GdkScreen *new_screen)
7016 if (old_screen != new_screen)
7020 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7022 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7025 _gtk_tooltip_hide (widget);
7026 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7031 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7032 gpointer client_data)
7034 HierarchyChangedInfo *info = client_data;
7035 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7036 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
7038 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7040 g_object_ref (widget);
7043 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7045 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7047 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7048 do_screen_change (widget, info->previous_screen, info->new_screen);
7050 if (GTK_IS_CONTAINER (widget))
7051 gtk_container_forall (GTK_CONTAINER (widget),
7052 gtk_widget_propagate_hierarchy_changed_recurse,
7055 g_object_unref (widget);
7060 * _gtk_widget_propagate_hierarchy_changed:
7061 * @widget: a #GtkWidget
7062 * @previous_toplevel: Previous toplevel
7064 * Propagates changes in the anchored state to a widget and all
7065 * children, unsetting or setting the %ANCHORED flag, and
7066 * emitting #GtkWidget::hierarchy-changed.
7069 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7070 GtkWidget *previous_toplevel)
7072 HierarchyChangedInfo info;
7074 info.previous_toplevel = previous_toplevel;
7075 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7077 if (gtk_widget_is_toplevel (widget) ||
7078 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7079 info.new_screen = gtk_widget_get_screen (widget);
7081 info.new_screen = NULL;
7083 if (info.previous_screen)
7084 g_object_ref (info.previous_screen);
7085 if (previous_toplevel)
7086 g_object_ref (previous_toplevel);
7088 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7090 if (previous_toplevel)
7091 g_object_unref (previous_toplevel);
7092 if (info.previous_screen)
7093 g_object_unref (info.previous_screen);
7097 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7098 gpointer client_data)
7100 HierarchyChangedInfo *info = client_data;
7102 g_object_ref (widget);
7104 do_screen_change (widget, info->previous_screen, info->new_screen);
7106 if (GTK_IS_CONTAINER (widget))
7107 gtk_container_forall (GTK_CONTAINER (widget),
7108 gtk_widget_propagate_screen_changed_recurse,
7111 g_object_unref (widget);
7115 * gtk_widget_is_composited:
7116 * @widget: a #GtkWidget
7118 * Whether @widget can rely on having its alpha channel
7119 * drawn correctly. On X11 this function returns whether a
7120 * compositing manager is running for @widget's screen.
7122 * Please note that the semantics of this call will change
7123 * in the future if used on a widget that has a composited
7124 * window in its hierarchy (as set by gdk_window_set_composited()).
7126 * Return value: %TRUE if the widget can rely on its alpha
7127 * channel being drawn correctly.
7132 gtk_widget_is_composited (GtkWidget *widget)
7136 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7138 screen = gtk_widget_get_screen (widget);
7140 return gdk_screen_is_composited (screen);
7144 propagate_composited_changed (GtkWidget *widget,
7147 if (GTK_IS_CONTAINER (widget))
7149 gtk_container_forall (GTK_CONTAINER (widget),
7150 propagate_composited_changed,
7154 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7158 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7160 propagate_composited_changed (widget, NULL);
7164 * _gtk_widget_propagate_screen_changed:
7165 * @widget: a #GtkWidget
7166 * @previous_screen: Previous screen
7168 * Propagates changes in the screen for a widget to all
7169 * children, emitting #GtkWidget::screen-changed.
7172 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7173 GdkScreen *previous_screen)
7175 HierarchyChangedInfo info;
7177 info.previous_screen = previous_screen;
7178 info.new_screen = gtk_widget_get_screen (widget);
7180 if (previous_screen)
7181 g_object_ref (previous_screen);
7183 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7185 if (previous_screen)
7186 g_object_unref (previous_screen);
7190 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7192 if (gtk_widget_has_rc_style (widget))
7193 gtk_widget_reset_rc_style (widget);
7195 if (GTK_IS_CONTAINER (widget))
7196 gtk_container_forall (GTK_CONTAINER (widget),
7197 reset_rc_styles_recurse,
7203 * gtk_widget_reset_rc_styles:
7204 * @widget: a #GtkWidget.
7206 * Reset the styles of @widget and all descendents, so when
7207 * they are looked up again, they get the correct values
7208 * for the currently loaded RC file settings.
7210 * This function is not useful for applications.
7213 gtk_widget_reset_rc_styles (GtkWidget *widget)
7215 g_return_if_fail (GTK_IS_WIDGET (widget));
7217 reset_rc_styles_recurse (widget, NULL);
7221 * gtk_widget_get_default_style:
7223 * Returns the default style used by all widgets initially.
7225 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7226 * by GTK+ and should not be modified or freed.
7229 gtk_widget_get_default_style (void)
7231 if (!gtk_default_style)
7233 gtk_default_style = gtk_style_new ();
7234 g_object_ref (gtk_default_style);
7237 return gtk_default_style;
7240 static PangoContext *
7241 gtk_widget_peek_pango_context (GtkWidget *widget)
7243 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7247 * gtk_widget_get_pango_context:
7248 * @widget: a #GtkWidget
7250 * Gets a #PangoContext with the appropriate font map, font description,
7251 * and base direction for this widget. Unlike the context returned
7252 * by gtk_widget_create_pango_context(), this context is owned by
7253 * the widget (it can be used until the screen for the widget changes
7254 * or the widget is removed from its toplevel), and will be updated to
7255 * match any changes to the widget's attributes.
7257 * If you create and keep a #PangoLayout using this context, you must
7258 * deal with changes to the context by calling pango_layout_context_changed()
7259 * on the layout in response to the #GtkWidget::style-set and
7260 * #GtkWidget::direction-changed signals for the widget.
7262 * Return value: (transfer none): the #PangoContext for the widget.
7265 gtk_widget_get_pango_context (GtkWidget *widget)
7267 PangoContext *context;
7269 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7271 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7274 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7275 g_object_set_qdata_full (G_OBJECT (widget),
7276 quark_pango_context,
7285 update_pango_context (GtkWidget *widget,
7286 PangoContext *context)
7288 pango_context_set_font_description (context, widget->style->font_desc);
7289 pango_context_set_base_dir (context,
7290 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7291 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7295 gtk_widget_update_pango_context (GtkWidget *widget)
7297 PangoContext *context = gtk_widget_peek_pango_context (widget);
7303 update_pango_context (widget, context);
7305 screen = gtk_widget_get_screen_unchecked (widget);
7308 pango_cairo_context_set_resolution (context,
7309 gdk_screen_get_resolution (screen));
7310 pango_cairo_context_set_font_options (context,
7311 gdk_screen_get_font_options (screen));
7317 * gtk_widget_create_pango_context:
7318 * @widget: a #GtkWidget
7320 * Creates a new #PangoContext with the appropriate font map,
7321 * font description, and base direction for drawing text for
7322 * this widget. See also gtk_widget_get_pango_context().
7324 * Return value: the new #PangoContext
7327 gtk_widget_create_pango_context (GtkWidget *widget)
7330 PangoContext *context;
7332 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7334 screen = gtk_widget_get_screen_unchecked (widget);
7337 GTK_NOTE (MULTIHEAD,
7338 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7340 screen = gdk_screen_get_default ();
7343 context = gdk_pango_context_get_for_screen (screen);
7345 update_pango_context (widget, context);
7346 pango_context_set_language (context, gtk_get_default_language ());
7352 * gtk_widget_create_pango_layout:
7353 * @widget: a #GtkWidget
7354 * @text: text to set on the layout (can be %NULL)
7356 * Creates a new #PangoLayout with the appropriate font map,
7357 * font description, and base direction for drawing text for
7360 * If you keep a #PangoLayout created in this way around, in order to
7361 * notify the layout of changes to the base direction or font of this
7362 * widget, you must call pango_layout_context_changed() in response to
7363 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7366 * Return value: the new #PangoLayout
7369 gtk_widget_create_pango_layout (GtkWidget *widget,
7372 PangoLayout *layout;
7373 PangoContext *context;
7375 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7377 context = gtk_widget_get_pango_context (widget);
7378 layout = pango_layout_new (context);
7381 pango_layout_set_text (layout, text, -1);
7387 * gtk_widget_render_icon:
7388 * @widget: a #GtkWidget
7389 * @stock_id: a stock ID
7390 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7391 * render at the size of the source and don't scale (if there are
7392 * multiple source sizes, GTK+ picks one of the available sizes).
7393 * @detail: (allow-none): render detail to pass to theme engine
7395 * A convenience function that uses the theme engine and RC file
7396 * settings for @widget to look up @stock_id and render it to
7397 * a pixbuf. @stock_id should be a stock icon ID such as
7398 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7399 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7400 * identifies the widget or code doing the rendering, so that
7401 * theme engines can special-case rendering for that widget or code.
7403 * The pixels in the returned #GdkPixbuf are shared with the rest of
7404 * the application and should not be modified. The pixbuf should be freed
7405 * after use with g_object_unref().
7407 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7410 gtk_widget_render_icon (GtkWidget *widget,
7411 const gchar *stock_id,
7413 const gchar *detail)
7415 GtkIconSet *icon_set;
7418 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7419 g_return_val_if_fail (stock_id != NULL, NULL);
7420 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7422 gtk_widget_ensure_style (widget);
7424 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7426 if (icon_set == NULL)
7429 retval = gtk_icon_set_render_icon (icon_set,
7431 gtk_widget_get_direction (widget),
7432 gtk_widget_get_state (widget),
7441 * gtk_widget_set_parent_window:
7442 * @widget: a #GtkWidget.
7443 * @parent_window: the new parent window.
7445 * Sets a non default parent window for @widget.
7448 gtk_widget_set_parent_window (GtkWidget *widget,
7449 GdkWindow *parent_window)
7451 GdkWindow *old_parent_window;
7453 g_return_if_fail (GTK_IS_WIDGET (widget));
7455 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7456 quark_parent_window);
7458 if (parent_window != old_parent_window)
7460 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7462 if (old_parent_window)
7463 g_object_unref (old_parent_window);
7465 g_object_ref (parent_window);
7470 * gtk_widget_get_parent_window:
7471 * @widget: a #GtkWidget.
7473 * Gets @widget's parent window.
7475 * Returns: (transfer none): the parent window of @widget.
7478 gtk_widget_get_parent_window (GtkWidget *widget)
7480 GdkWindow *parent_window;
7482 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7484 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7486 return (parent_window != NULL) ? parent_window :
7487 (widget->parent != NULL) ? widget->parent->window : NULL;
7492 * gtk_widget_set_child_visible:
7493 * @widget: a #GtkWidget
7494 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7496 * Sets whether @widget should be mapped along with its when its parent
7497 * is mapped and @widget has been shown with gtk_widget_show().
7499 * The child visibility can be set for widget before it is added to
7500 * a container with gtk_widget_set_parent(), to avoid mapping
7501 * children unnecessary before immediately unmapping them. However
7502 * it will be reset to its default state of %TRUE when the widget
7503 * is removed from a container.
7505 * Note that changing the child visibility of a widget does not
7506 * queue a resize on the widget. Most of the time, the size of
7507 * a widget is computed from all visible children, whether or
7508 * not they are mapped. If this is not the case, the container
7509 * can queue a resize itself.
7511 * This function is only useful for container implementations and
7512 * never should be called by an application.
7515 gtk_widget_set_child_visible (GtkWidget *widget,
7516 gboolean is_visible)
7518 g_return_if_fail (GTK_IS_WIDGET (widget));
7519 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7521 g_object_ref (widget);
7524 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7527 GtkWidget *toplevel;
7529 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7531 toplevel = gtk_widget_get_toplevel (widget);
7532 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7533 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7536 if (widget->parent && gtk_widget_get_realized (widget->parent))
7538 if (gtk_widget_get_mapped (widget->parent) &&
7539 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7540 gtk_widget_get_visible (widget))
7541 gtk_widget_map (widget);
7543 gtk_widget_unmap (widget);
7546 g_object_unref (widget);
7550 * gtk_widget_get_child_visible:
7551 * @widget: a #GtkWidget
7553 * Gets the value set with gtk_widget_set_child_visible().
7554 * If you feel a need to use this function, your code probably
7555 * needs reorganization.
7557 * This function is only useful for container implementations and
7558 * never should be called by an application.
7560 * Return value: %TRUE if the widget is mapped with the parent.
7563 gtk_widget_get_child_visible (GtkWidget *widget)
7565 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7567 return GTK_WIDGET_CHILD_VISIBLE (widget);
7571 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7573 GtkWidget *toplevel;
7575 toplevel = gtk_widget_get_toplevel (widget);
7577 if (gtk_widget_is_toplevel (toplevel))
7579 if (GTK_IS_WINDOW (toplevel))
7580 return GTK_WINDOW (toplevel)->screen;
7581 else if (GTK_IS_INVISIBLE (toplevel))
7582 return GTK_INVISIBLE (widget)->screen;
7589 * gtk_widget_get_screen:
7590 * @widget: a #GtkWidget
7592 * Get the #GdkScreen from the toplevel window associated with
7593 * this widget. This function can only be called after the widget
7594 * has been added to a widget hierarchy with a #GtkWindow
7597 * In general, you should only create screen specific
7598 * resources when a widget has been realized, and you should
7599 * free those resources when the widget is unrealized.
7601 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7606 gtk_widget_get_screen (GtkWidget *widget)
7610 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7612 screen = gtk_widget_get_screen_unchecked (widget);
7619 g_warning (G_STRLOC ": Can't get associated screen"
7620 " for a widget unless it is inside a toplevel GtkWindow\n"
7621 " widget type is %s associated top level type is %s",
7622 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7623 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7625 return gdk_screen_get_default ();
7630 * gtk_widget_has_screen:
7631 * @widget: a #GtkWidget
7633 * Checks whether there is a #GdkScreen is associated with
7634 * this widget. All toplevel widgets have an associated
7635 * screen, and all widgets added into a hierarchy with a toplevel
7636 * window at the top.
7638 * Return value: %TRUE if there is a #GdkScreen associcated
7644 gtk_widget_has_screen (GtkWidget *widget)
7646 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7648 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7652 * gtk_widget_get_display:
7653 * @widget: a #GtkWidget
7655 * Get the #GdkDisplay for the toplevel window associated with
7656 * this widget. This function can only be called after the widget
7657 * has been added to a widget hierarchy with a #GtkWindow at the top.
7659 * In general, you should only create display specific
7660 * resources when a widget has been realized, and you should
7661 * free those resources when the widget is unrealized.
7663 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7668 gtk_widget_get_display (GtkWidget *widget)
7670 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7672 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7676 * gtk_widget_get_root_window:
7677 * @widget: a #GtkWidget
7679 * Get the root window where this widget is located. This function can
7680 * only be called after the widget has been added to a widget
7681 * hierarchy with #GtkWindow at the top.
7683 * The root window is useful for such purposes as creating a popup
7684 * #GdkWindow associated with the window. In general, you should only
7685 * create display specific resources when a widget has been realized,
7686 * and you should free those resources when the widget is unrealized.
7688 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7693 gtk_widget_get_root_window (GtkWidget *widget)
7695 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7697 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7701 * gtk_widget_child_focus:
7702 * @widget: a #GtkWidget
7703 * @direction: direction of focus movement
7705 * This function is used by custom widget implementations; if you're
7706 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7707 * to a particular widget, and gtk_container_set_focus_chain() to
7708 * change the focus tab order. So you may want to investigate those
7709 * functions instead.
7711 * gtk_widget_child_focus() is called by containers as the user moves
7712 * around the window using keyboard shortcuts. @direction indicates
7713 * what kind of motion is taking place (up, down, left, right, tab
7714 * forward, tab backward). gtk_widget_child_focus() emits the
7715 * #GtkWidget::focus signal; widgets override the default handler
7716 * for this signal in order to implement appropriate focus behavior.
7718 * The default ::focus handler for a widget should return %TRUE if
7719 * moving in @direction left the focus on a focusable location inside
7720 * that widget, and %FALSE if moving in @direction moved the focus
7721 * outside the widget. If returning %TRUE, widgets normally
7722 * call gtk_widget_grab_focus() to place the focus accordingly;
7723 * if returning %FALSE, they don't modify the current focus location.
7725 * This function replaces gtk_container_focus() from GTK+ 1.2.
7726 * It was necessary to check that the child was visible, sensitive,
7727 * and focusable before calling gtk_container_focus().
7728 * gtk_widget_child_focus() returns %FALSE if the widget is not
7729 * currently in a focusable state, so there's no need for those checks.
7731 * Return value: %TRUE if focus ended up inside @widget
7734 gtk_widget_child_focus (GtkWidget *widget,
7735 GtkDirectionType direction)
7737 gboolean return_val;
7739 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7741 if (!gtk_widget_get_visible (widget) ||
7742 !gtk_widget_is_sensitive (widget))
7745 /* child widgets must set CAN_FOCUS, containers
7746 * don't have to though.
7748 if (!GTK_IS_CONTAINER (widget) &&
7749 !gtk_widget_get_can_focus (widget))
7752 g_signal_emit (widget,
7753 widget_signals[FOCUS],
7755 direction, &return_val);
7761 * gtk_widget_keynav_failed:
7762 * @widget: a #GtkWidget
7763 * @direction: direction of focus movement
7765 * This function should be called whenever keyboard navigation within
7766 * a single widget hits a boundary. The function emits the
7767 * #GtkWidget::keynav-failed signal on the widget and its return
7768 * value should be interpreted in a way similar to the return value of
7769 * gtk_widget_child_focus():
7771 * When %TRUE is returned, stay in the widget, the failed keyboard
7772 * navigation is Ok and/or there is nowhere we can/should move the
7775 * When %FALSE is returned, the caller should continue with keyboard
7776 * navigation outside the widget, e.g. by calling
7777 * gtk_widget_child_focus() on the widget's toplevel.
7779 * The default ::keynav-failed handler returns %TRUE for
7780 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7781 * values of #GtkDirectionType, it looks at the
7782 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7783 * if the setting is %TRUE. This way the entire user interface
7784 * becomes cursor-navigatable on input devices such as mobile phones
7785 * which only have cursor keys but no tab key.
7787 * Whenever the default handler returns %TRUE, it also calls
7788 * gtk_widget_error_bell() to notify the user of the failed keyboard
7791 * A use case for providing an own implementation of ::keynav-failed
7792 * (either by connecting to it or by overriding it) would be a row of
7793 * #GtkEntry widgets where the user should be able to navigate the
7794 * entire row with the cursor keys, as e.g. known from user interfaces
7795 * that require entering license keys.
7797 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7798 * if the emitting widget should try to handle the keyboard
7799 * navigation attempt in its parent container(s).
7804 gtk_widget_keynav_failed (GtkWidget *widget,
7805 GtkDirectionType direction)
7807 gboolean return_val;
7809 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7811 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7812 direction, &return_val);
7818 * gtk_widget_error_bell:
7819 * @widget: a #GtkWidget
7821 * Notifies the user about an input-related error on this widget.
7822 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7823 * gdk_window_beep(), otherwise it does nothing.
7825 * Note that the effect of gdk_window_beep() can be configured in many
7826 * ways, depending on the windowing backend and the desktop environment
7827 * or window manager that is used.
7832 gtk_widget_error_bell (GtkWidget *widget)
7834 GtkSettings* settings;
7837 g_return_if_fail (GTK_IS_WIDGET (widget));
7839 settings = gtk_widget_get_settings (widget);
7843 g_object_get (settings,
7844 "gtk-error-bell", &beep,
7847 if (beep && widget->window)
7848 gdk_window_beep (widget->window);
7852 * gtk_widget_set_uposition:
7853 * @widget: a #GtkWidget
7854 * @x: x position; -1 to unset x; -2 to leave x unchanged
7855 * @y: y position; -1 to unset y; -2 to leave y unchanged
7858 * Sets the position of a widget. The funny "u" in the name comes from
7859 * the "user position" hint specified by the X Window System, and
7860 * exists for legacy reasons. This function doesn't work if a widget
7861 * is inside a container; it's only really useful on #GtkWindow.
7863 * Don't use this function to center dialogs over the main application
7864 * window; most window managers will do the centering on your behalf
7865 * if you call gtk_window_set_transient_for(), and it's really not
7866 * possible to get the centering to work correctly in all cases from
7867 * application code. But if you insist, use gtk_window_set_position()
7868 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7871 * Note that although @x and @y can be individually unset, the position
7872 * is not honoured unless both @x and @y are set.
7875 gtk_widget_set_uposition (GtkWidget *widget,
7879 /* FIXME this function is the only place that aux_info->x and
7880 * aux_info->y are even used I believe, and this function is
7881 * deprecated. Should be cleaned up.
7883 * (Actually, size_allocate uses them) -Yosh
7886 GtkWidgetAuxInfo *aux_info;
7888 g_return_if_fail (GTK_IS_WIDGET (widget));
7890 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7895 aux_info->x_set = FALSE;
7898 aux_info->x_set = TRUE;
7906 aux_info->y_set = FALSE;
7909 aux_info->y_set = TRUE;
7914 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7915 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7917 if (gtk_widget_get_visible (widget) && widget->parent)
7918 gtk_widget_size_allocate (widget, &widget->allocation);
7922 gtk_widget_set_usize_internal (GtkWidget *widget,
7926 GtkWidgetAuxInfo *aux_info;
7927 gboolean changed = FALSE;
7929 g_object_freeze_notify (G_OBJECT (widget));
7931 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7933 if (width > -2 && aux_info->width != width)
7935 g_object_notify (G_OBJECT (widget), "width-request");
7936 aux_info->width = width;
7939 if (height > -2 && aux_info->height != height)
7941 g_object_notify (G_OBJECT (widget), "height-request");
7942 aux_info->height = height;
7946 if (gtk_widget_get_visible (widget) && changed)
7947 gtk_widget_queue_resize (widget);
7949 g_object_thaw_notify (G_OBJECT (widget));
7953 * gtk_widget_set_usize:
7954 * @widget: a #GtkWidget
7955 * @width: minimum width, or -1 to unset
7956 * @height: minimum height, or -1 to unset
7958 * Sets the minimum size of a widget; that is, the widget's size
7959 * request will be @width by @height. You can use this function to
7960 * force a widget to be either larger or smaller than it is. The
7961 * strange "usize" name dates from the early days of GTK+, and derives
7962 * from X Window System terminology. In many cases,
7963 * gtk_window_set_default_size() is a better choice for toplevel
7964 * windows than this function; setting the default size will still
7965 * allow users to shrink the window. Setting the usize will force them
7966 * to leave the window at least as large as the usize. When dealing
7967 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7970 * Note the inherent danger of setting any fixed size - themes,
7971 * translations into other languages, different fonts, and user action
7972 * can all change the appropriate size for a given widget. So, it's
7973 * basically impossible to hardcode a size that will always be
7976 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7979 gtk_widget_set_usize (GtkWidget *widget,
7983 g_return_if_fail (GTK_IS_WIDGET (widget));
7985 gtk_widget_set_usize_internal (widget, width, height);
7989 * gtk_widget_set_size_request:
7990 * @widget: a #GtkWidget
7991 * @width: width @widget should request, or -1 to unset
7992 * @height: height @widget should request, or -1 to unset
7994 * Sets the minimum size of a widget; that is, the widget's size
7995 * request will be @width by @height. You can use this function to
7996 * force a widget to be either larger or smaller than it normally
7999 * In most cases, gtk_window_set_default_size() is a better choice for
8000 * toplevel windows than this function; setting the default size will
8001 * still allow users to shrink the window. Setting the size request
8002 * will force them to leave the window at least as large as the size
8003 * request. When dealing with window sizes,
8004 * gtk_window_set_geometry_hints() can be a useful function as well.
8006 * Note the inherent danger of setting any fixed size - themes,
8007 * translations into other languages, different fonts, and user action
8008 * can all change the appropriate size for a given widget. So, it's
8009 * basically impossible to hardcode a size that will always be
8012 * The size request of a widget is the smallest size a widget can
8013 * accept while still functioning well and drawing itself correctly.
8014 * However in some strange cases a widget may be allocated less than
8015 * its requested size, and in many cases a widget may be allocated more
8016 * space than it requested.
8018 * If the size request in a given direction is -1 (unset), then
8019 * the "natural" size request of the widget will be used instead.
8021 * Widgets can't actually be allocated a size less than 1 by 1, but
8022 * you can pass 0,0 to this function to mean "as small as possible."
8025 gtk_widget_set_size_request (GtkWidget *widget,
8029 g_return_if_fail (GTK_IS_WIDGET (widget));
8030 g_return_if_fail (width >= -1);
8031 g_return_if_fail (height >= -1);
8038 gtk_widget_set_usize_internal (widget, width, height);
8043 * gtk_widget_get_size_request:
8044 * @widget: a #GtkWidget
8045 * @width: (allow-none): (out): return location for width, or %NULL
8046 * @height: (allow-none): (out): return location for height, or %NULL
8048 * Gets the size request that was explicitly set for the widget using
8049 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8050 * @height indicates that that dimension has not been set explicitly
8051 * and the natural requisition of the widget will be used intead. See
8052 * gtk_widget_set_size_request(). To get the size a widget will
8053 * actually use, call gtk_widget_size_request() instead of
8057 gtk_widget_get_size_request (GtkWidget *widget,
8061 GtkWidgetAuxInfo *aux_info;
8063 g_return_if_fail (GTK_IS_WIDGET (widget));
8065 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
8068 *width = aux_info ? aux_info->width : -1;
8071 *height = aux_info ? aux_info->height : -1;
8075 * gtk_widget_set_events:
8076 * @widget: a #GtkWidget
8077 * @events: event mask
8079 * Sets the event mask (see #GdkEventMask) for a widget. The event
8080 * mask determines which events a widget will receive. Keep in mind
8081 * that different widgets have different default event masks, and by
8082 * changing the event mask you may disrupt a widget's functionality,
8083 * so be careful. This function must be called while a widget is
8084 * unrealized. Consider gtk_widget_add_events() for widgets that are
8085 * already realized, or if you want to preserve the existing event
8086 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8087 * to get events on those widgets, place them inside a #GtkEventBox
8088 * and receive events on the event box.
8091 gtk_widget_set_events (GtkWidget *widget,
8094 g_return_if_fail (GTK_IS_WIDGET (widget));
8095 g_return_if_fail (!gtk_widget_get_realized (widget));
8097 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8098 GINT_TO_POINTER (events));
8099 g_object_notify (G_OBJECT (widget), "events");
8103 gtk_widget_add_events_internal (GtkWidget *widget,
8109 for (l = window_list; l != NULL; l = l->next)
8111 GdkWindow *window = l->data;
8114 gdk_window_get_user_data (window, &user_data);
8115 if (user_data == widget)
8119 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8121 children = gdk_window_get_children (window);
8122 gtk_widget_add_events_internal (widget, events, children);
8123 g_list_free (children);
8129 * gtk_widget_add_events:
8130 * @widget: a #GtkWidget
8131 * @events: an event mask, see #GdkEventMask
8133 * Adds the events in the bitfield @events to the event mask for
8134 * @widget. See gtk_widget_set_events() for details.
8137 gtk_widget_add_events (GtkWidget *widget,
8142 g_return_if_fail (GTK_IS_WIDGET (widget));
8144 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8145 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8146 GINT_TO_POINTER (old_events | events));
8148 if (gtk_widget_get_realized (widget))
8152 if (!gtk_widget_get_has_window (widget))
8153 window_list = gdk_window_get_children (widget->window);
8155 window_list = g_list_prepend (NULL, widget->window);
8157 gtk_widget_add_events_internal (widget, events, window_list);
8159 g_list_free (window_list);
8162 g_object_notify (G_OBJECT (widget), "events");
8166 * gtk_widget_set_extension_events:
8167 * @widget: a #GtkWidget
8168 * @mode: bitfield of extension events to receive
8170 * Sets the extension events mask to @mode. See #GdkExtensionMode
8171 * and gdk_input_set_extension_events().
8174 gtk_widget_set_extension_events (GtkWidget *widget,
8175 GdkExtensionMode mode)
8177 g_return_if_fail (GTK_IS_WIDGET (widget));
8179 if (gtk_widget_get_realized (widget))
8180 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8182 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8183 GINT_TO_POINTER (mode));
8184 g_object_notify (G_OBJECT (widget), "extension-events");
8188 * gtk_widget_get_toplevel:
8189 * @widget: a #GtkWidget
8191 * This function returns the topmost widget in the container hierarchy
8192 * @widget is a part of. If @widget has no parent widgets, it will be
8193 * returned as the topmost widget. No reference will be added to the
8194 * returned widget; it should not be unreferenced.
8196 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8197 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8199 * %NULL if @widget wasn't inside a toplevel window, and if the
8200 * window was inside a #GtkWindow-derived widget which was in turn
8201 * inside the toplevel #GtkWindow. While the second case may
8202 * seem unlikely, it actually happens when a #GtkPlug is embedded
8203 * inside a #GtkSocket within the same application.
8205 * To reliably find the toplevel #GtkWindow, use
8206 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8207 * is set on the result.
8209 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8210 * if (gtk_widget_is_toplevel (toplevel))
8212 * /* Perform action on toplevel. */
8216 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8217 * if there's no ancestor.
8220 gtk_widget_get_toplevel (GtkWidget *widget)
8222 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8224 while (widget->parent)
8225 widget = widget->parent;
8231 * gtk_widget_get_ancestor:
8232 * @widget: a #GtkWidget
8233 * @widget_type: ancestor type
8235 * Gets the first ancestor of @widget with type @widget_type. For example,
8236 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8237 * the first #GtkBox that's an ancestor of @widget. No reference will be
8238 * added to the returned widget; it should not be unreferenced. See note
8239 * about checking for a toplevel #GtkWindow in the docs for
8240 * gtk_widget_get_toplevel().
8242 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8243 * considers @widget to be an ancestor of itself.
8245 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8248 gtk_widget_get_ancestor (GtkWidget *widget,
8251 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8253 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8254 widget = widget->parent;
8256 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8263 * gtk_widget_get_colormap:
8264 * @widget: a #GtkWidget
8266 * Gets the colormap that will be used to render @widget. No reference will
8267 * be added to the returned colormap; it should not be unreferenced.
8269 * Return value: (transfer none): the colormap used by @widget
8272 gtk_widget_get_colormap (GtkWidget *widget)
8274 GdkColormap *colormap;
8275 GtkWidget *tmp_widget;
8277 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8281 colormap = gdk_drawable_get_colormap (widget->window);
8282 /* If window was destroyed previously, we'll get NULL here */
8287 tmp_widget = widget;
8290 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8294 tmp_widget= tmp_widget->parent;
8297 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8301 * gtk_widget_get_visual:
8302 * @widget: a #GtkWidget
8304 * Gets the visual that will be used to render @widget.
8306 * Return value: (transfer none): the visual for @widget
8309 gtk_widget_get_visual (GtkWidget *widget)
8311 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8313 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8317 * gtk_widget_get_settings:
8318 * @widget: a #GtkWidget
8320 * Gets the settings object holding the settings (global property
8321 * settings, RC file information, etc) used for this widget.
8323 * Note that this function can only be called when the #GtkWidget
8324 * is attached to a toplevel, since the settings object is specific
8325 * to a particular #GdkScreen.
8327 * Return value: (transfer none): the relevant #GtkSettings object
8330 gtk_widget_get_settings (GtkWidget *widget)
8332 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8334 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8338 * gtk_widget_set_colormap:
8339 * @widget: a #GtkWidget
8340 * @colormap: a colormap
8342 * Sets the colormap for the widget to the given value. Widget must not
8343 * have been previously realized. This probably should only be used
8344 * from an <function>init()</function> function (i.e. from the constructor
8348 gtk_widget_set_colormap (GtkWidget *widget,
8349 GdkColormap *colormap)
8351 g_return_if_fail (GTK_IS_WIDGET (widget));
8352 g_return_if_fail (!gtk_widget_get_realized (widget));
8353 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8355 g_object_ref (colormap);
8357 g_object_set_qdata_full (G_OBJECT (widget),
8364 * gtk_widget_get_events:
8365 * @widget: a #GtkWidget
8367 * Returns the event mask for the widget (a bitfield containing flags
8368 * from the #GdkEventMask enumeration). These are the events that the widget
8371 * Return value: event mask for @widget
8374 gtk_widget_get_events (GtkWidget *widget)
8376 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8378 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8382 * gtk_widget_get_extension_events:
8383 * @widget: a #GtkWidget
8385 * Retrieves the extension events the widget will receive; see
8386 * gdk_input_set_extension_events().
8388 * Return value: extension events for @widget
8391 gtk_widget_get_extension_events (GtkWidget *widget)
8393 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8395 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8399 * gtk_widget_get_pointer:
8400 * @widget: a #GtkWidget
8401 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8402 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8404 * Obtains the location of the mouse pointer in widget coordinates.
8405 * Widget coordinates are a bit odd; for historical reasons, they are
8406 * defined as @widget->window coordinates for widgets that are not
8407 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8408 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8411 gtk_widget_get_pointer (GtkWidget *widget,
8415 g_return_if_fail (GTK_IS_WIDGET (widget));
8422 if (gtk_widget_get_realized (widget))
8424 gdk_window_get_pointer (widget->window, x, y, NULL);
8426 if (!gtk_widget_get_has_window (widget))
8429 *x -= widget->allocation.x;
8431 *y -= widget->allocation.y;
8437 * gtk_widget_is_ancestor:
8438 * @widget: a #GtkWidget
8439 * @ancestor: another #GtkWidget
8441 * Determines whether @widget is somewhere inside @ancestor, possibly with
8442 * intermediate containers.
8444 * Return value: %TRUE if @ancestor contains @widget as a child,
8445 * grandchild, great grandchild, etc.
8448 gtk_widget_is_ancestor (GtkWidget *widget,
8449 GtkWidget *ancestor)
8451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8452 g_return_val_if_fail (ancestor != NULL, FALSE);
8456 if (widget->parent == ancestor)
8458 widget = widget->parent;
8464 static GQuark quark_composite_name = 0;
8467 * gtk_widget_set_composite_name:
8468 * @widget: a #GtkWidget.
8469 * @name: the name to set
8471 * Sets a widgets composite name. The widget must be
8472 * a composite child of its parent; see gtk_widget_push_composite_child().
8475 gtk_widget_set_composite_name (GtkWidget *widget,
8478 g_return_if_fail (GTK_IS_WIDGET (widget));
8479 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8480 g_return_if_fail (name != NULL);
8482 if (!quark_composite_name)
8483 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8485 g_object_set_qdata_full (G_OBJECT (widget),
8486 quark_composite_name,
8492 * gtk_widget_get_composite_name:
8493 * @widget: a #GtkWidget
8495 * Obtains the composite name of a widget.
8497 * Returns: the composite name of @widget, or %NULL if @widget is not
8498 * a composite child. The string should be freed when it is no
8502 gtk_widget_get_composite_name (GtkWidget *widget)
8504 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8506 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8507 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8514 * gtk_widget_push_composite_child:
8516 * Makes all newly-created widgets as composite children until
8517 * the corresponding gtk_widget_pop_composite_child() call.
8519 * A composite child is a child that's an implementation detail of the
8520 * container it's inside and should not be visible to people using the
8521 * container. Composite children aren't treated differently by GTK (but
8522 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8523 * builders might want to treat them in a different way.
8525 * Here is a simple example:
8527 * gtk_widget_push_composite_child ();
8528 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8529 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8530 * gtk_widget_pop_composite_child ();
8531 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8532 * GTK_WIDGET (scrolled_window));
8533 * g_object_ref (scrolled_window->hscrollbar);
8537 gtk_widget_push_composite_child (void)
8539 composite_child_stack++;
8543 * gtk_widget_pop_composite_child:
8545 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8548 gtk_widget_pop_composite_child (void)
8550 if (composite_child_stack)
8551 composite_child_stack--;
8555 * gtk_widget_push_colormap:
8556 * @cmap: a #GdkColormap
8558 * Pushes @cmap onto a global stack of colormaps; the topmost
8559 * colormap on the stack will be used to create all widgets.
8560 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8561 * reason to use this function.
8564 gtk_widget_push_colormap (GdkColormap *cmap)
8566 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8568 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8572 * gtk_widget_pop_colormap:
8574 * Removes a colormap pushed with gtk_widget_push_colormap().
8577 gtk_widget_pop_colormap (void)
8580 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8584 * gtk_widget_set_default_colormap:
8585 * @colormap: a #GdkColormap
8587 * Sets the default colormap to use when creating widgets.
8588 * gtk_widget_push_colormap() is a better function to use if
8589 * you only want to affect a few widgets, rather than all widgets.
8592 gtk_widget_set_default_colormap (GdkColormap *colormap)
8594 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8596 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8601 * gtk_widget_get_default_colormap:
8603 * Obtains the default colormap used to create widgets.
8605 * Return value: (transfer none): default widget colormap
8608 gtk_widget_get_default_colormap (void)
8610 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8614 * gtk_widget_get_default_visual:
8616 * Obtains the visual of the default colormap. Not really useful;
8617 * used to be useful before gdk_colormap_get_visual() existed.
8619 * Return value: (transfer none): visual of the default colormap
8622 gtk_widget_get_default_visual (void)
8624 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8628 gtk_widget_emit_direction_changed (GtkWidget *widget,
8629 GtkTextDirection old_dir)
8631 gtk_widget_update_pango_context (widget);
8633 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8637 * gtk_widget_set_direction:
8638 * @widget: a #GtkWidget
8639 * @dir: the new direction
8641 * Sets the reading direction on a particular widget. This direction
8642 * controls the primary direction for widgets containing text,
8643 * and also the direction in which the children of a container are
8644 * packed. The ability to set the direction is present in order
8645 * so that correct localization into languages with right-to-left
8646 * reading directions can be done. Generally, applications will
8647 * let the default reading direction present, except for containers
8648 * where the containers are arranged in an order that is explicitely
8649 * visual rather than logical (such as buttons for text justification).
8651 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8652 * set by gtk_widget_set_default_direction() will be used.
8655 gtk_widget_set_direction (GtkWidget *widget,
8656 GtkTextDirection dir)
8658 GtkTextDirection old_dir;
8660 g_return_if_fail (GTK_IS_WIDGET (widget));
8661 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8663 old_dir = gtk_widget_get_direction (widget);
8665 if (dir == GTK_TEXT_DIR_NONE)
8666 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8669 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8670 if (dir == GTK_TEXT_DIR_LTR)
8671 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8673 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8676 if (old_dir != gtk_widget_get_direction (widget))
8677 gtk_widget_emit_direction_changed (widget, old_dir);
8681 * gtk_widget_get_direction:
8682 * @widget: a #GtkWidget
8684 * Gets the reading direction for a particular widget. See
8685 * gtk_widget_set_direction().
8687 * Return value: the reading direction for the widget.
8690 gtk_widget_get_direction (GtkWidget *widget)
8692 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8694 if (GTK_WIDGET_DIRECTION_SET (widget))
8695 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8697 return gtk_default_direction;
8701 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8703 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8705 g_object_ref (widget);
8707 if (!GTK_WIDGET_DIRECTION_SET (widget))
8708 gtk_widget_emit_direction_changed (widget, old_dir);
8710 if (GTK_IS_CONTAINER (widget))
8711 gtk_container_forall (GTK_CONTAINER (widget),
8712 gtk_widget_set_default_direction_recurse,
8715 g_object_unref (widget);
8719 * gtk_widget_set_default_direction:
8720 * @dir: the new default direction. This cannot be
8721 * %GTK_TEXT_DIR_NONE.
8723 * Sets the default reading direction for widgets where the
8724 * direction has not been explicitly set by gtk_widget_set_direction().
8727 gtk_widget_set_default_direction (GtkTextDirection dir)
8729 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8731 if (dir != gtk_default_direction)
8733 GList *toplevels, *tmp_list;
8734 GtkTextDirection old_dir = gtk_default_direction;
8736 gtk_default_direction = dir;
8738 tmp_list = toplevels = gtk_window_list_toplevels ();
8739 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8743 gtk_widget_set_default_direction_recurse (tmp_list->data,
8744 GUINT_TO_POINTER (old_dir));
8745 g_object_unref (tmp_list->data);
8746 tmp_list = tmp_list->next;
8749 g_list_free (toplevels);
8754 * gtk_widget_get_default_direction:
8756 * Obtains the current default reading direction. See
8757 * gtk_widget_set_default_direction().
8759 * Return value: the current default direction.
8762 gtk_widget_get_default_direction (void)
8764 return gtk_default_direction;
8768 gtk_widget_dispose (GObject *object)
8770 GtkWidget *widget = GTK_WIDGET (object);
8773 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8774 else if (gtk_widget_get_visible (widget))
8775 gtk_widget_hide (widget);
8777 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8778 if (gtk_widget_get_realized (widget))
8779 gtk_widget_unrealize (widget);
8781 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8785 gtk_widget_real_destroy (GtkObject *object)
8787 /* gtk_object_destroy() will already hold a refcount on object */
8788 GtkWidget *widget = GTK_WIDGET (object);
8790 /* wipe accelerator closures (keep order) */
8791 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8792 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8794 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8795 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8797 gtk_grab_remove (widget);
8799 g_object_unref (widget->style);
8800 widget->style = gtk_widget_get_default_style ();
8801 g_object_ref (widget->style);
8803 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8807 gtk_widget_finalize (GObject *object)
8809 GtkWidget *widget = GTK_WIDGET (object);
8810 GtkWidgetAuxInfo *aux_info;
8811 GtkAccessible *accessible;
8813 gtk_grab_remove (widget);
8815 g_object_unref (widget->style);
8816 widget->style = NULL;
8818 g_free (widget->name);
8820 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8822 gtk_widget_aux_info_destroy (aux_info);
8824 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8826 g_object_unref (accessible);
8828 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8831 /*****************************************
8832 * gtk_widget_real_map:
8837 *****************************************/
8840 gtk_widget_real_map (GtkWidget *widget)
8842 g_assert (gtk_widget_get_realized (widget));
8844 if (!gtk_widget_get_mapped (widget))
8846 gtk_widget_set_mapped (widget, TRUE);
8848 if (gtk_widget_get_has_window (widget))
8849 gdk_window_show (widget->window);
8853 /*****************************************
8854 * gtk_widget_real_unmap:
8859 *****************************************/
8862 gtk_widget_real_unmap (GtkWidget *widget)
8864 if (gtk_widget_get_mapped (widget))
8866 gtk_widget_set_mapped (widget, FALSE);
8868 if (gtk_widget_get_has_window (widget))
8869 gdk_window_hide (widget->window);
8873 /*****************************************
8874 * gtk_widget_real_realize:
8879 *****************************************/
8882 gtk_widget_real_realize (GtkWidget *widget)
8884 g_assert (!gtk_widget_get_has_window (widget));
8886 gtk_widget_set_realized (widget, TRUE);
8889 widget->window = gtk_widget_get_parent_window (widget);
8890 g_object_ref (widget->window);
8892 widget->style = gtk_style_attach (widget->style, widget->window);
8895 /*****************************************
8896 * gtk_widget_real_unrealize:
8901 *****************************************/
8904 gtk_widget_real_unrealize (GtkWidget *widget)
8906 if (gtk_widget_get_mapped (widget))
8907 gtk_widget_real_unmap (widget);
8909 gtk_widget_set_mapped (widget, FALSE);
8911 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8914 /* We must do unrealize child widget BEFORE container widget.
8915 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8916 * So, unrealizing container widget bofore its children causes the problem
8917 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8920 if (GTK_IS_CONTAINER (widget))
8921 gtk_container_forall (GTK_CONTAINER (widget),
8922 (GtkCallback) gtk_widget_unrealize,
8925 gtk_style_detach (widget->style);
8926 if (gtk_widget_get_has_window (widget))
8928 gdk_window_set_user_data (widget->window, NULL);
8929 gdk_window_destroy (widget->window);
8930 widget->window = NULL;
8934 g_object_unref (widget->window);
8935 widget->window = NULL;
8938 gtk_selection_remove_all (widget);
8940 gtk_widget_set_realized (widget, FALSE);
8944 gtk_widget_real_size_request (GtkWidget *widget,
8945 GtkRequisition *requisition)
8947 requisition->width = widget->requisition.width;
8948 requisition->height = widget->requisition.height;
8952 * _gtk_widget_peek_colormap:
8954 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8956 * Return value: the currently pushed colormap, or %NULL if there is none.
8959 _gtk_widget_peek_colormap (void)
8962 return (GdkColormap*) colormap_stack->data;
8967 * _gtk_widget_set_pointer_window:
8968 * @widget: a #GtkWidget.
8969 * @pointer_window: the new pointer window.
8971 * Sets pointer window for @widget. Does not ref @pointer_window.
8972 * Actually stores it on the #GdkScreen, but you don't need to know that.
8975 _gtk_widget_set_pointer_window (GtkWidget *widget,
8976 GdkWindow *pointer_window)
8978 g_return_if_fail (GTK_IS_WIDGET (widget));
8980 if (gtk_widget_get_realized (widget))
8982 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8984 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8990 * _gtk_widget_get_pointer_window:
8991 * @widget: a #GtkWidget.
8993 * Return value: the pointer window set on the #GdkScreen @widget is attached
8997 _gtk_widget_get_pointer_window (GtkWidget *widget)
8999 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9001 if (gtk_widget_get_realized (widget))
9003 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
9005 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9012 synth_crossing (GtkWidget *widget,
9015 GdkCrossingMode mode,
9016 GdkNotifyType detail)
9020 event = gdk_event_new (type);
9022 event->crossing.window = g_object_ref (window);
9023 event->crossing.send_event = TRUE;
9024 event->crossing.subwindow = g_object_ref (window);
9025 event->crossing.time = GDK_CURRENT_TIME;
9026 event->crossing.x = event->crossing.y = 0;
9027 event->crossing.x_root = event->crossing.y_root = 0;
9028 event->crossing.mode = mode;
9029 event->crossing.detail = detail;
9030 event->crossing.focus = FALSE;
9031 event->crossing.state = 0;
9034 widget = gtk_get_event_widget (event);
9037 gtk_widget_event_internal (widget, event);
9039 gdk_event_free (event);
9043 * _gtk_widget_is_pointer_widget:
9044 * @widget: a #GtkWidget
9046 * Returns %TRUE if the pointer window belongs to @widget.
9049 _gtk_widget_is_pointer_widget (GtkWidget *widget)
9051 if (GTK_WIDGET_HAS_POINTER (widget))
9056 win = _gtk_widget_get_pointer_window (widget);
9059 gdk_window_get_user_data (win, (gpointer *)&wid);
9069 * _gtk_widget_synthesize_crossing:
9070 * @from: the #GtkWidget the virtual pointer is leaving.
9071 * @to: the #GtkWidget the virtual pointer is moving to.
9072 * @mode: the #GdkCrossingMode to place on the synthesized events.
9074 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9076 * The real pointer window is the window that most recently received an enter notify
9077 * event. Windows that don't select for crossing events can't become the real
9078 * poiner window. The real pointer widget that owns the real pointer window. The
9079 * effective pointer window is the same as the real pointer window unless the real
9080 * pointer widget is either insensitive or there is a grab on a widget that is not
9081 * an ancestor of the real pointer widget (in which case the effective pointer
9082 * window should be the root window).
9084 * When the effective pointer window is the same as the real poiner window, we
9085 * receive crossing events from the windowing system. When the effective pointer
9086 * window changes to become different from the real pointer window we synthesize
9087 * crossing events, attempting to follow X protocol rules:
9089 * When the root window becomes the effective pointer window:
9090 * - leave notify on real pointer window, detail Ancestor
9091 * - leave notify on all of its ancestors, detail Virtual
9092 * - enter notify on root window, detail Inferior
9094 * When the root window ceases to be the effective pointer window:
9095 * - leave notify on root window, detail Inferior
9096 * - enter notify on all ancestors of real pointer window, detail Virtual
9097 * - enter notify on real pointer window, detail Ancestor
9100 _gtk_widget_synthesize_crossing (GtkWidget *from,
9102 GdkCrossingMode mode)
9104 GdkWindow *from_window = NULL, *to_window = NULL;
9106 g_return_if_fail (from != NULL || to != NULL);
9109 from_window = GTK_WIDGET_HAS_POINTER (from)
9110 ? _gtk_widget_get_pointer_window (from) : from->window;
9112 to_window = GTK_WIDGET_HAS_POINTER (to)
9113 ? _gtk_widget_get_pointer_window (to) : to->window;
9115 if (from_window == NULL && to_window == NULL)
9117 else if (from_window != NULL && to_window == NULL)
9119 GList *from_ancestors = NULL, *list;
9120 GdkWindow *from_ancestor = from_window;
9122 while (from_ancestor != NULL)
9124 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9125 if (from_ancestor == NULL)
9127 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9130 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9131 mode, GDK_NOTIFY_ANCESTOR);
9132 for (list = g_list_last (from_ancestors); list; list = list->prev)
9134 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9135 mode, GDK_NOTIFY_VIRTUAL);
9138 /* XXX: enter/inferior on root window? */
9140 g_list_free (from_ancestors);
9142 else if (from_window == NULL && to_window != NULL)
9144 GList *to_ancestors = NULL, *list;
9145 GdkWindow *to_ancestor = to_window;
9147 while (to_ancestor != NULL)
9149 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9150 if (to_ancestor == NULL)
9152 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9155 /* XXX: leave/inferior on root window? */
9157 for (list = to_ancestors; list; list = list->next)
9159 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9160 mode, GDK_NOTIFY_VIRTUAL);
9162 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9163 mode, GDK_NOTIFY_ANCESTOR);
9165 g_list_free (to_ancestors);
9167 else if (from_window == to_window)
9171 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9172 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9174 while (from_ancestor != NULL || to_ancestor != NULL)
9176 if (from_ancestor != NULL)
9178 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9179 if (from_ancestor == to_window)
9182 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9184 if (to_ancestor != NULL)
9186 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9187 if (to_ancestor == from_window)
9190 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9193 if (to_ancestor == from_window)
9195 if (mode != GDK_CROSSING_GTK_UNGRAB)
9196 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9197 mode, GDK_NOTIFY_INFERIOR);
9198 for (list = to_ancestors; list; list = list->next)
9199 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9200 mode, GDK_NOTIFY_VIRTUAL);
9201 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9202 mode, GDK_NOTIFY_ANCESTOR);
9204 else if (from_ancestor == to_window)
9206 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9207 mode, GDK_NOTIFY_ANCESTOR);
9208 for (list = g_list_last (from_ancestors); list; list = list->prev)
9210 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9211 mode, GDK_NOTIFY_VIRTUAL);
9213 if (mode != GDK_CROSSING_GTK_GRAB)
9214 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9215 mode, GDK_NOTIFY_INFERIOR);
9219 while (from_ancestors != NULL && to_ancestors != NULL
9220 && from_ancestors->data == to_ancestors->data)
9222 from_ancestors = g_list_delete_link (from_ancestors,
9224 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9227 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9228 mode, GDK_NOTIFY_NONLINEAR);
9230 for (list = g_list_last (from_ancestors); list; list = list->prev)
9232 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9233 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9235 for (list = to_ancestors; list; list = list->next)
9237 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9238 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9240 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9241 mode, GDK_NOTIFY_NONLINEAR);
9243 g_list_free (from_ancestors);
9244 g_list_free (to_ancestors);
9249 gtk_widget_propagate_state (GtkWidget *widget,
9252 guint8 old_state = gtk_widget_get_state (widget);
9253 guint8 old_saved_state = widget->saved_state;
9255 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9256 * parent_sensitive==TRUE on a sensitive widget
9260 if (data->parent_sensitive)
9261 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9263 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9265 if (gtk_widget_is_sensitive (widget))
9267 if (data->state_restoration)
9268 widget->state = widget->saved_state;
9270 widget->state = data->state;
9274 if (!data->state_restoration)
9276 if (data->state != GTK_STATE_INSENSITIVE)
9277 widget->saved_state = data->state;
9279 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9280 widget->saved_state = gtk_widget_get_state (widget);
9281 widget->state = GTK_STATE_INSENSITIVE;
9284 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9288 window = gtk_widget_get_toplevel (widget);
9289 if (window && gtk_widget_is_toplevel (window))
9290 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9293 if (old_state != gtk_widget_get_state (widget) ||
9294 old_saved_state != widget->saved_state)
9296 g_object_ref (widget);
9298 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9299 gtk_grab_remove (widget);
9301 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9303 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9305 if (!gtk_widget_is_sensitive (widget))
9306 _gtk_widget_synthesize_crossing (widget, NULL,
9307 GDK_CROSSING_STATE_CHANGED);
9308 else if (old_state == GTK_STATE_INSENSITIVE)
9309 _gtk_widget_synthesize_crossing (NULL, widget,
9310 GDK_CROSSING_STATE_CHANGED);
9313 if (GTK_IS_CONTAINER (widget))
9315 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9316 if (data->use_forall)
9317 gtk_container_forall (GTK_CONTAINER (widget),
9318 (GtkCallback) gtk_widget_propagate_state,
9321 gtk_container_foreach (GTK_CONTAINER (widget),
9322 (GtkCallback) gtk_widget_propagate_state,
9325 g_object_unref (widget);
9330 * _gtk_widget_get_aux_info:
9331 * @widget: a #GtkWidget
9332 * @create: if %TRUE, create the structure if it doesn't exist
9334 * Get the #GtkWidgetAuxInfo structure for the widget.
9336 * Return value: the #GtkAuxInfo structure for the widget, or
9337 * %NULL if @create is %FALSE and one doesn't already exist.
9340 _gtk_widget_get_aux_info (GtkWidget *widget,
9343 GtkWidgetAuxInfo *aux_info;
9345 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9346 if (!aux_info && create)
9348 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9350 aux_info->width = -1;
9351 aux_info->height = -1;
9353 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9360 /*****************************************
9361 * gtk_widget_aux_info_destroy:
9366 *****************************************/
9369 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9371 g_slice_free (GtkWidgetAuxInfo, aux_info);
9375 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9377 g_object_unref (info->shape_mask);
9378 g_slice_free (GtkWidgetShapeInfo, info);
9382 * gtk_widget_shape_combine_mask:
9383 * @widget: a #GtkWidget
9384 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9385 * @offset_x: X position of shape mask with respect to @window
9386 * @offset_y: Y position of shape mask with respect to @window
9388 * Sets a shape for this widget's GDK window. This allows for
9389 * transparent windows etc., see gdk_window_shape_combine_mask()
9390 * for more information.
9393 gtk_widget_shape_combine_mask (GtkWidget *widget,
9394 GdkBitmap *shape_mask,
9398 GtkWidgetShapeInfo* shape_info;
9400 g_return_if_fail (GTK_IS_WIDGET (widget));
9401 /* set_shape doesn't work on widgets without gdk window */
9402 g_return_if_fail (gtk_widget_get_has_window (widget));
9406 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9409 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9411 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9415 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9417 shape_info = g_slice_new (GtkWidgetShapeInfo);
9418 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9419 (GDestroyNotify) gtk_widget_shape_info_destroy);
9421 shape_info->shape_mask = g_object_ref (shape_mask);
9422 shape_info->offset_x = offset_x;
9423 shape_info->offset_y = offset_y;
9425 /* set shape if widget has a gdk window already.
9426 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9429 gdk_window_shape_combine_mask (widget->window, shape_mask,
9430 offset_x, offset_y);
9435 * gtk_widget_input_shape_combine_mask:
9436 * @widget: a #GtkWidget
9437 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9438 * @offset_x: X position of shape mask with respect to @window
9439 * @offset_y: Y position of shape mask with respect to @window
9441 * Sets an input shape for this widget's GDK window. This allows for
9442 * windows which react to mouse click in a nonrectangular region, see
9443 * gdk_window_input_shape_combine_mask() for more information.
9448 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9449 GdkBitmap *shape_mask,
9453 GtkWidgetShapeInfo* shape_info;
9455 g_return_if_fail (GTK_IS_WIDGET (widget));
9456 /* set_shape doesn't work on widgets without gdk window */
9457 g_return_if_fail (gtk_widget_get_has_window (widget));
9462 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9464 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9468 shape_info = g_slice_new (GtkWidgetShapeInfo);
9469 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9471 (GDestroyNotify) gtk_widget_shape_info_destroy);
9473 shape_info->shape_mask = g_object_ref (shape_mask);
9474 shape_info->offset_x = offset_x;
9475 shape_info->offset_y = offset_y;
9477 /* set shape if widget has a gdk window already.
9478 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9481 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9482 offset_x, offset_y);
9488 gtk_reset_shapes_recurse (GtkWidget *widget,
9494 gdk_window_get_user_data (window, &data);
9498 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9499 for (list = gdk_window_peek_children (window); list; list = list->next)
9500 gtk_reset_shapes_recurse (widget, list->data);
9504 * gtk_widget_reset_shapes:
9505 * @widget: a #GtkWidget
9507 * Recursively resets the shape on this widget and its descendants.
9510 gtk_widget_reset_shapes (GtkWidget *widget)
9512 g_return_if_fail (GTK_IS_WIDGET (widget));
9513 g_return_if_fail (gtk_widget_get_realized (widget));
9515 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9516 gtk_reset_shapes_recurse (widget, widget->window);
9521 * @widget: a #GtkWidget
9523 * Adds a reference to a widget. This function is exactly the same
9524 * as calling g_object_ref(), and exists mostly for historical
9525 * reasons. It can still be convenient to avoid casting a widget
9526 * to a #GObject, it saves a small amount of typing.
9528 * Return value: the widget that was referenced
9530 * Deprecated: 2.12: Use g_object_ref() instead.
9533 gtk_widget_ref (GtkWidget *widget)
9535 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9537 return (GtkWidget*) g_object_ref ((GObject*) widget);
9542 * @widget: a #GtkWidget
9544 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9546 * Deprecated: 2.12: Use g_object_unref() instead.
9549 gtk_widget_unref (GtkWidget *widget)
9551 g_return_if_fail (GTK_IS_WIDGET (widget));
9553 g_object_unref ((GObject*) widget);
9557 expose_window (GdkWindow *window)
9560 GList *l, *children;
9562 gboolean is_double_buffered;
9564 gdk_window_get_user_data (window, &user_data);
9567 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9569 is_double_buffered = FALSE;
9571 event.expose.type = GDK_EXPOSE;
9572 event.expose.window = g_object_ref (window);
9573 event.expose.send_event = FALSE;
9574 event.expose.count = 0;
9575 event.expose.area.x = 0;
9576 event.expose.area.y = 0;
9577 gdk_drawable_get_size (GDK_DRAWABLE (window),
9578 &event.expose.area.width,
9579 &event.expose.area.height);
9580 event.expose.region = gdk_region_rectangle (&event.expose.area);
9582 /* If this is not double buffered, force a double buffer so that
9583 redirection works. */
9584 if (!is_double_buffered)
9585 gdk_window_begin_paint_region (window, event.expose.region);
9587 gtk_main_do_event (&event);
9589 if (!is_double_buffered)
9590 gdk_window_end_paint (window);
9592 children = gdk_window_peek_children (window);
9593 for (l = children; l != NULL; l = l->next)
9595 GdkWindow *child = l->data;
9597 /* Don't expose input-only windows */
9598 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9599 expose_window (l->data);
9602 g_object_unref (window);
9606 * gtk_widget_get_snapshot:
9607 * @widget: a #GtkWidget
9608 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9610 * Create a #GdkPixmap of the contents of the widget and its children.
9612 * Works even if the widget is obscured. The depth and visual of the
9613 * resulting pixmap is dependent on the widget being snapshot and likely
9614 * differs from those of a target widget displaying the pixmap.
9615 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9616 * the pixmap to a visual independant representation.
9618 * The snapshot area used by this function is the @widget's allocation plus
9619 * any extra space occupied by additional windows belonging to this widget
9620 * (such as the arrows of a spin button).
9621 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9623 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9624 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9625 * interpreted widget relative. If width or height of @clip_rect are 0 or
9626 * negative, the width or height of the resulting pixmap will be shrunken
9627 * by the respective amount.
9628 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9629 * chop off 5 pixels at each side of the snapshot pixmap.
9630 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9631 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9632 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9633 * as a pure output parameter.
9635 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9637 * Return value: #GdkPixmap snapshot of the widget
9642 gtk_widget_get_snapshot (GtkWidget *widget,
9643 GdkRectangle *clip_rect)
9645 int x, y, width, height;
9646 GdkWindow *parent_window = NULL;
9648 GList *windows = NULL, *list;
9650 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9651 if (!gtk_widget_get_visible (widget))
9654 /* the widget (and parent_window) must be realized to be drawable */
9655 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9656 gtk_widget_realize (widget->parent);
9657 if (!gtk_widget_get_realized (widget))
9658 gtk_widget_realize (widget);
9660 /* determine snapshot rectangle */
9661 x = widget->allocation.x;
9662 y = widget->allocation.y;
9663 width = widget->allocation.width;
9664 height = widget->allocation.height;
9666 if (widget->parent && gtk_widget_get_has_window (widget))
9668 /* grow snapshot rectangle to cover all widget windows */
9669 parent_window = gtk_widget_get_parent_window (widget);
9670 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9672 GdkWindow *subwin = list->data;
9675 gdk_window_get_user_data (subwin, &windata);
9676 if (windata != widget)
9678 windows = g_list_prepend (windows, subwin);
9679 gdk_window_get_position (subwin, &wx, &wy);
9680 gdk_drawable_get_size (subwin, &ww, &wh);
9681 /* grow snapshot rectangle by extra widget sub window */
9692 if (x + width < wx + ww)
9693 width += wx + ww - (x + width);
9694 if (y + height < wy + wh)
9695 height += wy + wh - (y + height);
9698 else if (!widget->parent)
9699 x = y = 0; /* toplevel */
9701 /* at this point, (x,y,width,height) is the parent_window relative
9702 * snapshot area covering all of widget's windows.
9705 /* shrink snapshot size by clip_rectangle */
9708 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9709 clip.x = clip.x < 0 ? x : clip.x;
9710 clip.y = clip.y < 0 ? y : clip.y;
9711 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9712 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9715 /* offset clip_rect, so it's parent_window relative */
9716 if (clip_rect->x >= 0)
9717 clip.x += widget->allocation.x;
9718 if (clip_rect->y >= 0)
9719 clip.y += widget->allocation.y;
9721 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9723 g_list_free (windows);
9724 clip_rect->width = clip_rect->height = 0;
9725 return NULL; /* empty snapshot area */
9730 height = snap.height;
9733 /* render snapshot */
9734 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9735 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9737 GdkWindow *subwin = list->data;
9739 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9740 continue; /* Input only window */
9741 gdk_window_get_position (subwin, &wx, &wy);
9742 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9743 MAX (0, wx - x), MAX (0, wy - y), width, height);
9745 expose_window (subwin);
9747 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9749 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9750 expose_window (widget->window);
9752 for (list = windows; list; list = list->next)
9753 gdk_window_remove_redirection (list->data);
9754 if (!windows) /* NO_WINDOW || toplevel */
9755 gdk_window_remove_redirection (widget->window);
9756 g_list_free (windows);
9758 /* return pixmap and snapshot rectangle coordinates */
9763 clip_rect->width = width;
9764 clip_rect->height = height;
9767 /* offset clip_rect from parent_window so it's widget relative */
9768 clip_rect->x -= widget->allocation.x;
9769 clip_rect->y -= widget->allocation.y;
9772 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9773 G_OBJECT_TYPE_NAME (widget),
9774 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9783 * gtk_widget_class_install_style_property_parser:
9784 * @klass: a #GtkWidgetClass
9785 * @pspec: the #GParamSpec for the style property
9786 * @parser: the parser for the style property
9788 * Installs a style property on a widget class.
9791 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9793 GtkRcPropertyParser parser)
9795 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9796 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9797 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9798 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9800 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9802 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9803 G_OBJECT_CLASS_NAME (klass),
9808 g_param_spec_ref_sink (pspec);
9809 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9810 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9814 * gtk_widget_class_install_style_property:
9815 * @klass: a #GtkWidgetClass
9816 * @pspec: the #GParamSpec for the property
9818 * Installs a style property on a widget class. The parser for the
9819 * style property is determined by the value type of @pspec.
9822 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9825 GtkRcPropertyParser parser;
9827 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9828 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9830 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9832 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9836 * gtk_widget_class_find_style_property:
9837 * @klass: a #GtkWidgetClass
9838 * @property_name: the name of the style property to find
9839 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9840 * style property with that name.
9842 * Finds a style property of a widget class by name.
9847 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9848 const gchar *property_name)
9850 g_return_val_if_fail (property_name != NULL, NULL);
9852 return g_param_spec_pool_lookup (style_property_spec_pool,
9854 G_OBJECT_CLASS_TYPE (klass),
9859 * gtk_widget_class_list_style_properties:
9860 * @klass: a #GtkWidgetClass
9861 * @n_properties: location to return the number of style properties found
9862 * @returns: an newly allocated array of #GParamSpec*. The array must
9863 * be freed with g_free().
9865 * Returns all style properties of a widget class.
9870 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9871 guint *n_properties)
9873 GParamSpec **pspecs;
9876 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9877 G_OBJECT_CLASS_TYPE (klass),
9886 * gtk_widget_style_get_property:
9887 * @widget: a #GtkWidget
9888 * @property_name: the name of a style property
9889 * @value: location to return the property value
9891 * Gets the value of a style property of @widget.
9894 gtk_widget_style_get_property (GtkWidget *widget,
9895 const gchar *property_name,
9900 g_return_if_fail (GTK_IS_WIDGET (widget));
9901 g_return_if_fail (property_name != NULL);
9902 g_return_if_fail (G_IS_VALUE (value));
9904 g_object_ref (widget);
9905 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9907 G_OBJECT_TYPE (widget),
9910 g_warning ("%s: widget class `%s' has no property named `%s'",
9912 G_OBJECT_TYPE_NAME (widget),
9916 const GValue *peek_value;
9918 peek_value = _gtk_style_peek_property_value (widget->style,
9919 G_OBJECT_TYPE (widget),
9921 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9923 /* auto-conversion of the caller's value type
9925 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9926 g_value_copy (peek_value, value);
9927 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9928 g_value_transform (peek_value, value);
9930 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9932 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9933 G_VALUE_TYPE_NAME (value));
9935 g_object_unref (widget);
9939 * gtk_widget_style_get_valist:
9940 * @widget: a #GtkWidget
9941 * @first_property_name: the name of the first property to get
9942 * @var_args: a <type>va_list</type> of pairs of property names and
9943 * locations to return the property values, starting with the location
9944 * for @first_property_name.
9946 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9950 gtk_widget_style_get_valist (GtkWidget *widget,
9951 const gchar *first_property_name,
9956 g_return_if_fail (GTK_IS_WIDGET (widget));
9958 g_object_ref (widget);
9960 name = first_property_name;
9963 const GValue *peek_value;
9967 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9969 G_OBJECT_TYPE (widget),
9973 g_warning ("%s: widget class `%s' has no property named `%s'",
9975 G_OBJECT_TYPE_NAME (widget),
9979 /* style pspecs are always readable so we can spare that check here */
9981 peek_value = _gtk_style_peek_property_value (widget->style,
9982 G_OBJECT_TYPE (widget),
9984 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9985 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9988 g_warning ("%s: %s", G_STRLOC, error);
9993 name = va_arg (var_args, gchar*);
9996 g_object_unref (widget);
10000 * gtk_widget_style_get:
10001 * @widget: a #GtkWidget
10002 * @first_property_name: the name of the first property to get
10003 * @Varargs: pairs of property names and locations to
10004 * return the property values, starting with the location for
10005 * @first_property_name, terminated by %NULL.
10007 * Gets the values of a multiple style properties of @widget.
10010 gtk_widget_style_get (GtkWidget *widget,
10011 const gchar *first_property_name,
10016 g_return_if_fail (GTK_IS_WIDGET (widget));
10018 va_start (var_args, first_property_name);
10019 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10025 * @widget: a #GtkWidget
10026 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10027 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10028 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10030 * Obtains the full path to @widget. The path is simply the name of a
10031 * widget and all its parents in the container hierarchy, separated by
10032 * periods. The name of a widget comes from
10033 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10034 * in gtkrc configuration files. Widget names are the type of the
10035 * widget by default (e.g. "GtkButton") or can be set to an
10036 * application-specific value with gtk_widget_set_name(). By setting
10037 * the name of a widget, you allow users or theme authors to apply
10038 * styles to that specific widget in their gtkrc
10039 * file. @path_reversed_p fills in the path in reverse order,
10040 * i.e. starting with @widget's name instead of starting with the name
10041 * of @widget's outermost ancestor.
10044 gtk_widget_path (GtkWidget *widget,
10045 guint *path_length,
10047 gchar **path_reversed)
10049 static gchar *rev_path = NULL;
10050 static guint tmp_path_len = 0;
10053 g_return_if_fail (GTK_IS_WIDGET (widget));
10058 const gchar *string;
10063 string = gtk_widget_get_name (widget);
10064 l = strlen (string);
10065 while (tmp_path_len <= len + l + 1)
10067 tmp_path_len += INIT_PATH_SIZE;
10068 rev_path = g_realloc (rev_path, tmp_path_len);
10070 s = string + l - 1;
10071 d = rev_path + len;
10072 while (s >= string)
10076 widget = widget->parent;
10079 rev_path[len++] = '.';
10081 rev_path[len++] = 0;
10086 *path_length = len - 1;
10088 *path_reversed = g_strdup (rev_path);
10091 *path = g_strdup (rev_path);
10092 g_strreverse (*path);
10097 * gtk_widget_class_path:
10098 * @widget: a #GtkWidget
10099 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10100 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10101 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10104 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10105 * never uses a custom name set with gtk_widget_set_name().
10109 gtk_widget_class_path (GtkWidget *widget,
10110 guint *path_length,
10112 gchar **path_reversed)
10114 static gchar *rev_path = NULL;
10115 static guint tmp_path_len = 0;
10118 g_return_if_fail (GTK_IS_WIDGET (widget));
10123 const gchar *string;
10128 string = g_type_name (G_OBJECT_TYPE (widget));
10129 l = strlen (string);
10130 while (tmp_path_len <= len + l + 1)
10132 tmp_path_len += INIT_PATH_SIZE;
10133 rev_path = g_realloc (rev_path, tmp_path_len);
10135 s = string + l - 1;
10136 d = rev_path + len;
10137 while (s >= string)
10141 widget = widget->parent;
10144 rev_path[len++] = '.';
10146 rev_path[len++] = 0;
10151 *path_length = len - 1;
10153 *path_reversed = g_strdup (rev_path);
10156 *path = g_strdup (rev_path);
10157 g_strreverse (*path);
10162 * gtk_requisition_copy:
10163 * @requisition: a #GtkRequisition
10165 * Copies a #GtkRequisition.
10167 * Returns: a copy of @requisition
10170 gtk_requisition_copy (const GtkRequisition *requisition)
10172 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10176 * gtk_requisition_free:
10177 * @requisition: a #GtkRequisition
10179 * Frees a #GtkRequisition.
10182 gtk_requisition_free (GtkRequisition *requisition)
10184 g_free (requisition);
10188 gtk_requisition_get_type (void)
10190 static GType our_type = 0;
10193 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10194 (GBoxedCopyFunc) gtk_requisition_copy,
10195 (GBoxedFreeFunc) gtk_requisition_free);
10201 * gtk_widget_get_accessible:
10202 * @widget: a #GtkWidget
10204 * Returns the accessible object that describes the widget to an
10205 * assistive technology.
10207 * If no accessibility library is loaded (i.e. no ATK implementation library is
10208 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10209 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10210 * if no class-specific #AtkObject implementation is available for the widget
10211 * instance in question, it will inherit an #AtkObject implementation from the
10212 * first ancestor class for which such an implementation is defined.
10214 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10215 * library contains more information about accessible objects and their uses.
10217 * Returns: (transfer none): the #AtkObject associated with @widget
10220 gtk_widget_get_accessible (GtkWidget *widget)
10222 GtkWidgetClass *klass;
10224 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10226 klass = GTK_WIDGET_GET_CLASS (widget);
10228 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10230 return klass->get_accessible (widget);
10234 gtk_widget_real_get_accessible (GtkWidget *widget)
10236 AtkObject* accessible;
10238 accessible = g_object_get_qdata (G_OBJECT (widget),
10239 quark_accessible_object);
10242 AtkObjectFactory *factory;
10243 AtkRegistry *default_registry;
10245 default_registry = atk_get_default_registry ();
10246 factory = atk_registry_get_factory (default_registry,
10247 G_TYPE_FROM_INSTANCE (widget));
10249 atk_object_factory_create_accessible (factory,
10250 G_OBJECT (widget));
10251 g_object_set_qdata (G_OBJECT (widget),
10252 quark_accessible_object,
10259 * Initialize a AtkImplementorIface instance's virtual pointers as
10260 * appropriate to this implementor's class (GtkWidget).
10263 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10265 iface->ref_accessible = gtk_widget_ref_accessible;
10269 gtk_widget_ref_accessible (AtkImplementor *implementor)
10271 AtkObject *accessible;
10273 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10275 g_object_ref (accessible);
10280 * GtkBuildable implementation
10282 static GQuark quark_builder_has_default = 0;
10283 static GQuark quark_builder_has_focus = 0;
10284 static GQuark quark_builder_atk_relations = 0;
10285 static GQuark quark_builder_set_name = 0;
10288 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10290 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10291 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10292 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10293 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10295 iface->set_name = gtk_widget_buildable_set_name;
10296 iface->get_name = gtk_widget_buildable_get_name;
10297 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10298 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10299 iface->parser_finished = gtk_widget_buildable_parser_finished;
10300 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10301 iface->custom_finished = gtk_widget_buildable_custom_finished;
10305 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10308 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10309 g_strdup (name), g_free);
10312 static const gchar *
10313 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10315 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10319 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10320 GtkBuilder *builder,
10321 const gchar *childname)
10323 if (strcmp (childname, "accessible") == 0)
10324 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10330 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10331 GtkBuilder *builder,
10333 const GValue *value)
10335 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10336 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10337 GINT_TO_POINTER (TRUE));
10338 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10339 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10340 GINT_TO_POINTER (TRUE));
10342 g_object_set_property (G_OBJECT (buildable), name, value);
10347 gchar *action_name;
10348 GString *description;
10350 gboolean translatable;
10360 free_action (AtkActionData *data, gpointer user_data)
10362 g_free (data->action_name);
10363 g_string_free (data->description, TRUE);
10364 g_free (data->context);
10365 g_slice_free (AtkActionData, data);
10369 free_relation (AtkRelationData *data, gpointer user_data)
10371 g_free (data->target);
10372 g_free (data->type);
10373 g_slice_free (AtkRelationData, data);
10377 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10378 GtkBuilder *builder)
10380 GSList *atk_relations;
10382 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10383 gtk_widget_grab_default (GTK_WIDGET (buildable));
10384 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10385 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10387 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10388 quark_builder_atk_relations);
10391 AtkObject *accessible;
10392 AtkRelationSet *relation_set;
10395 AtkRelationType relation_type;
10396 AtkObject *target_accessible;
10398 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10399 relation_set = atk_object_ref_relation_set (accessible);
10401 for (l = atk_relations; l; l = l->next)
10403 AtkRelationData *relation = (AtkRelationData*)l->data;
10405 target = gtk_builder_get_object (builder, relation->target);
10408 g_warning ("Target object %s in <relation> does not exist",
10412 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10413 g_assert (target_accessible != NULL);
10415 relation_type = atk_relation_type_for_name (relation->type);
10416 if (relation_type == ATK_RELATION_NULL)
10418 g_warning ("<relation> type %s not found",
10422 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10423 target_accessible);
10425 g_object_unref (relation_set);
10427 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10428 g_slist_free (atk_relations);
10429 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10438 } AccessibilitySubParserData;
10441 accessibility_start_element (GMarkupParseContext *context,
10442 const gchar *element_name,
10443 const gchar **names,
10444 const gchar **values,
10445 gpointer user_data,
10448 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10450 gint line_number, char_number;
10452 if (strcmp (element_name, "relation") == 0)
10454 gchar *target = NULL;
10455 gchar *type = NULL;
10456 AtkRelationData *relation;
10458 for (i = 0; names[i]; i++)
10460 if (strcmp (names[i], "target") == 0)
10461 target = g_strdup (values[i]);
10462 else if (strcmp (names[i], "type") == 0)
10463 type = g_strdup (values[i]);
10466 g_markup_parse_context_get_position (context,
10469 g_set_error (error,
10471 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10472 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10474 line_number, char_number, names[i], "relation");
10481 if (!target || !type)
10483 g_markup_parse_context_get_position (context,
10486 g_set_error (error,
10488 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10489 "%s:%d:%d <%s> requires attribute \"%s\"",
10491 line_number, char_number, "relation",
10492 type ? "target" : "type");
10498 relation = g_slice_new (AtkRelationData);
10499 relation->target = target;
10500 relation->type = type;
10502 data->relations = g_slist_prepend (data->relations, relation);
10504 else if (strcmp (element_name, "action") == 0)
10506 const gchar *action_name = NULL;
10507 const gchar *description = NULL;
10508 const gchar *msg_context = NULL;
10509 gboolean translatable = FALSE;
10510 AtkActionData *action;
10512 for (i = 0; names[i]; i++)
10514 if (strcmp (names[i], "action_name") == 0)
10515 action_name = values[i];
10516 else if (strcmp (names[i], "description") == 0)
10517 description = values[i];
10518 else if (strcmp (names[i], "translatable") == 0)
10520 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10523 else if (strcmp (names[i], "comments") == 0)
10525 /* do nothing, comments are for translators */
10527 else if (strcmp (names[i], "context") == 0)
10528 msg_context = values[i];
10531 g_markup_parse_context_get_position (context,
10534 g_set_error (error,
10536 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10537 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10539 line_number, char_number, names[i], "action");
10546 g_markup_parse_context_get_position (context,
10549 g_set_error (error,
10551 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10552 "%s:%d:%d <%s> requires attribute \"%s\"",
10554 line_number, char_number, "action",
10559 action = g_slice_new (AtkActionData);
10560 action->action_name = g_strdup (action_name);
10561 action->description = g_string_new (description);
10562 action->context = g_strdup (msg_context);
10563 action->translatable = translatable;
10565 data->actions = g_slist_prepend (data->actions, action);
10567 else if (strcmp (element_name, "accessibility") == 0)
10570 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10574 accessibility_text (GMarkupParseContext *context,
10577 gpointer user_data,
10580 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10582 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10584 AtkActionData *action = data->actions->data;
10586 g_string_append_len (action->description, text, text_len);
10590 static const GMarkupParser accessibility_parser =
10592 accessibility_start_element,
10594 accessibility_text,
10603 } AccelGroupParserData;
10606 accel_group_start_element (GMarkupParseContext *context,
10607 const gchar *element_name,
10608 const gchar **names,
10609 const gchar **values,
10610 gpointer user_data,
10615 guint modifiers = 0;
10616 gchar *signal = NULL;
10617 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10619 for (i = 0; names[i]; i++)
10621 if (strcmp (names[i], "key") == 0)
10622 key = gdk_keyval_from_name (values[i]);
10623 else if (strcmp (names[i], "modifiers") == 0)
10625 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10631 else if (strcmp (names[i], "signal") == 0)
10632 signal = g_strdup (values[i]);
10635 if (key == 0 || signal == NULL)
10637 g_warning ("<accelerator> requires key and signal attributes");
10640 parser_data->key = key;
10641 parser_data->modifiers = modifiers;
10642 parser_data->signal = signal;
10645 static const GMarkupParser accel_group_parser =
10647 accel_group_start_element,
10651 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10652 GtkBuilder *builder,
10654 const gchar *tagname,
10655 GMarkupParser *parser,
10658 g_assert (buildable);
10660 if (strcmp (tagname, "accelerator") == 0)
10662 AccelGroupParserData *parser_data;
10664 parser_data = g_slice_new0 (AccelGroupParserData);
10665 parser_data->object = g_object_ref (buildable);
10666 *parser = accel_group_parser;
10667 *data = parser_data;
10670 if (strcmp (tagname, "accessibility") == 0)
10672 AccessibilitySubParserData *parser_data;
10674 parser_data = g_slice_new0 (AccessibilitySubParserData);
10675 *parser = accessibility_parser;
10676 *data = parser_data;
10683 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10684 GtkWidget *toplevel,
10685 gpointer user_data)
10687 AccelGroupParserData *accel_data;
10688 GSList *accel_groups;
10689 GtkAccelGroup *accel_group;
10691 g_return_if_fail (GTK_IS_WIDGET (widget));
10692 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10693 g_return_if_fail (user_data != NULL);
10695 accel_data = (AccelGroupParserData*)user_data;
10696 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10697 if (g_slist_length (accel_groups) == 0)
10699 accel_group = gtk_accel_group_new ();
10700 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10704 g_assert (g_slist_length (accel_groups) == 1);
10705 accel_group = g_slist_nth_data (accel_groups, 0);
10708 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10709 accel_data->signal,
10712 accel_data->modifiers,
10713 GTK_ACCEL_VISIBLE);
10715 g_object_unref (accel_data->object);
10716 g_free (accel_data->signal);
10717 g_slice_free (AccelGroupParserData, accel_data);
10721 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10722 GtkBuilder *builder,
10724 const gchar *tagname,
10725 gpointer user_data)
10727 AccelGroupParserData *accel_data;
10728 AccessibilitySubParserData *a11y_data;
10729 GtkWidget *toplevel;
10731 if (strcmp (tagname, "accelerator") == 0)
10733 accel_data = (AccelGroupParserData*)user_data;
10734 g_assert (accel_data->object);
10736 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10738 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10740 else if (strcmp (tagname, "accessibility") == 0)
10742 a11y_data = (AccessibilitySubParserData*)user_data;
10744 if (a11y_data->actions)
10746 AtkObject *accessible;
10751 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10753 action = ATK_ACTION (accessible);
10754 n_actions = atk_action_get_n_actions (action);
10756 for (l = a11y_data->actions; l; l = l->next)
10758 AtkActionData *action_data = (AtkActionData*)l->data;
10760 for (i = 0; i < n_actions; i++)
10761 if (strcmp (atk_action_get_name (action, i),
10762 action_data->action_name) == 0)
10767 gchar *description;
10769 if (action_data->translatable && action_data->description->len)
10770 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10771 action_data->context,
10772 action_data->description->str);
10774 description = action_data->description->str;
10776 atk_action_set_description (action, i, description);
10780 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10781 g_slist_free (a11y_data->actions);
10784 if (a11y_data->relations)
10785 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10786 a11y_data->relations);
10788 g_slice_free (AccessibilitySubParserData, a11y_data);
10793 * GtkExtendedLayout implementation
10796 gtk_widget_real_get_desired_width (GtkExtendedLayout *layout,
10797 gint *minimum_size,
10798 gint *natural_size)
10800 /* Set the initial values so that unimplemented classes will fall back
10801 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10804 *minimum_size = GTK_WIDGET (layout)->requisition.width;
10807 *natural_size = GTK_WIDGET (layout)->requisition.width;
10811 gtk_widget_real_get_desired_height (GtkExtendedLayout *layout,
10812 gint *minimum_size,
10813 gint *natural_size)
10815 /* Set the initial values so that unimplemented classes will fall back
10816 * on the "size-request" collected values (see gtksizegroup.c:do_size_request()).
10819 *minimum_size = GTK_WIDGET (layout)->requisition.height;
10822 *natural_size = GTK_WIDGET (layout)->requisition.height;
10826 gtk_widget_real_get_height_for_width (GtkExtendedLayout *layout,
10828 gint *minimum_height,
10829 gint *natural_height)
10831 gtk_extended_layout_get_desired_height (layout, minimum_height, natural_height);
10835 gtk_widget_real_get_width_for_height (GtkExtendedLayout *layout,
10837 gint *minimum_width,
10838 gint *natural_width)
10840 gtk_extended_layout_get_desired_width (layout, minimum_width, natural_width);
10844 gtk_widget_extended_layout_init (GtkExtendedLayoutIface *iface)
10846 iface->get_desired_width = gtk_widget_real_get_desired_width;
10847 iface->get_desired_height = gtk_widget_real_get_desired_height;
10848 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
10849 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
10854 * gtk_widget_get_clipboard:
10855 * @widget: a #GtkWidget
10856 * @selection: a #GdkAtom which identifies the clipboard
10857 * to use. %GDK_SELECTION_CLIPBOARD gives the
10858 * default clipboard. Another common value
10859 * is %GDK_SELECTION_PRIMARY, which gives
10860 * the primary X selection.
10862 * Returns the clipboard object for the given selection to
10863 * be used with @widget. @widget must have a #GdkDisplay
10864 * associated with it, so must be attached to a toplevel
10867 * Return value: (transfer none): the appropriate clipboard object. If no
10868 * clipboard already exists, a new one will
10869 * be created. Once a clipboard object has
10870 * been created, it is persistent for all time.
10875 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10877 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10878 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10880 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10885 * gtk_widget_list_mnemonic_labels:
10886 * @widget: a #GtkWidget
10888 * Returns a newly allocated list of the widgets, normally labels, for
10889 * which this widget is a the target of a mnemonic (see for example,
10890 * gtk_label_set_mnemonic_widget()).
10892 * The widgets in the list are not individually referenced. If you
10893 * want to iterate through the list and perform actions involving
10894 * callbacks that might destroy the widgets, you
10895 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10896 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10897 * widgets afterwards.
10899 * Return value: (element-type GtkWidget) (transfer container): the list of
10900 * mnemonic labels; free this list
10901 * with g_list_free() when you are done with it.
10906 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10908 GList *list = NULL;
10911 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10913 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10914 list = g_list_prepend (list, l->data);
10920 * gtk_widget_add_mnemonic_label:
10921 * @widget: a #GtkWidget
10922 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10924 * Adds a widget to the list of mnemonic labels for
10925 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10926 * list of mnemonic labels for the widget is cleared when the
10927 * widget is destroyed, so the caller must make sure to update
10928 * its internal state at this point as well, by using a connection
10929 * to the #GtkWidget::destroy signal or a weak notifier.
10934 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10937 GSList *old_list, *new_list;
10939 g_return_if_fail (GTK_IS_WIDGET (widget));
10940 g_return_if_fail (GTK_IS_WIDGET (label));
10942 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10943 new_list = g_slist_prepend (old_list, label);
10945 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10946 new_list, (GDestroyNotify) g_slist_free);
10950 * gtk_widget_remove_mnemonic_label:
10951 * @widget: a #GtkWidget
10952 * @label: a #GtkWidget that was previously set as a mnemnic label for
10953 * @widget with gtk_widget_add_mnemonic_label().
10955 * Removes a widget from the list of mnemonic labels for
10956 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10957 * must have previously been added to the list with
10958 * gtk_widget_add_mnemonic_label().
10963 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10966 GSList *old_list, *new_list;
10968 g_return_if_fail (GTK_IS_WIDGET (widget));
10969 g_return_if_fail (GTK_IS_WIDGET (label));
10971 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10972 new_list = g_slist_remove (old_list, label);
10975 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10976 new_list, (GDestroyNotify) g_slist_free);
10980 * gtk_widget_get_no_show_all:
10981 * @widget: a #GtkWidget
10983 * Returns the current value of the GtkWidget:no-show-all property,
10984 * which determines whether calls to gtk_widget_show_all() and
10985 * gtk_widget_hide_all() will affect this widget.
10987 * Return value: the current value of the "no-show-all" property.
10992 gtk_widget_get_no_show_all (GtkWidget *widget)
10994 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10996 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11000 * gtk_widget_set_no_show_all:
11001 * @widget: a #GtkWidget
11002 * @no_show_all: the new value for the "no-show-all" property
11004 * Sets the #GtkWidget:no-show-all property, which determines whether
11005 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11008 * This is mostly for use in constructing widget hierarchies with externally
11009 * controlled visibility, see #GtkUIManager.
11014 gtk_widget_set_no_show_all (GtkWidget *widget,
11015 gboolean no_show_all)
11017 g_return_if_fail (GTK_IS_WIDGET (widget));
11019 no_show_all = (no_show_all != FALSE);
11021 if (no_show_all == gtk_widget_get_no_show_all (widget))
11025 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11027 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11029 g_object_notify (G_OBJECT (widget), "no-show-all");
11034 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11035 gboolean has_tooltip,
11038 gboolean priv_has_tooltip;
11040 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11041 quark_has_tooltip));
11043 if (priv_has_tooltip != has_tooltip || force)
11045 priv_has_tooltip = has_tooltip;
11047 if (priv_has_tooltip)
11049 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11050 gdk_window_set_events (widget->window,
11051 gdk_window_get_events (widget->window) |
11052 GDK_LEAVE_NOTIFY_MASK |
11053 GDK_POINTER_MOTION_MASK |
11054 GDK_POINTER_MOTION_HINT_MASK);
11056 if (gtk_widget_get_has_window (widget))
11057 gtk_widget_add_events (widget,
11058 GDK_LEAVE_NOTIFY_MASK |
11059 GDK_POINTER_MOTION_MASK |
11060 GDK_POINTER_MOTION_HINT_MASK);
11063 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11064 GUINT_TO_POINTER (priv_has_tooltip));
11069 * gtk_widget_set_tooltip_window:
11070 * @widget: a #GtkWidget
11071 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11073 * Replaces the default, usually yellow, window used for displaying
11074 * tooltips with @custom_window. GTK+ will take care of showing and
11075 * hiding @custom_window at the right moment, to behave likewise as
11076 * the default tooltip window. If @custom_window is %NULL, the default
11077 * tooltip window will be used.
11079 * If the custom window should have the default theming it needs to
11080 * have the name "gtk-tooltip", see gtk_widget_set_name().
11085 gtk_widget_set_tooltip_window (GtkWidget *widget,
11086 GtkWindow *custom_window)
11088 gboolean has_tooltip;
11089 gchar *tooltip_markup;
11091 g_return_if_fail (GTK_IS_WIDGET (widget));
11092 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11094 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11097 g_object_ref (custom_window);
11099 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11100 custom_window, g_object_unref);
11102 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11103 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11105 if (has_tooltip && gtk_widget_get_visible (widget))
11106 gtk_widget_queue_tooltip_query (widget);
11110 * gtk_widget_get_tooltip_window:
11111 * @widget: a #GtkWidget
11113 * Returns the #GtkWindow of the current tooltip. This can be the
11114 * GtkWindow created by default, or the custom tooltip window set
11115 * using gtk_widget_set_tooltip_window().
11117 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11122 gtk_widget_get_tooltip_window (GtkWidget *widget)
11124 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11126 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11130 * gtk_widget_trigger_tooltip_query:
11131 * @widget: a #GtkWidget
11133 * Triggers a tooltip query on the display where the toplevel of @widget
11134 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11140 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11142 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11145 static guint tooltip_query_id;
11146 static GSList *tooltip_query_displays;
11149 tooltip_query_idle (gpointer data)
11151 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11152 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11153 g_slist_free (tooltip_query_displays);
11155 tooltip_query_displays = NULL;
11156 tooltip_query_id = 0;
11162 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11164 GdkDisplay *display;
11166 display = gtk_widget_get_display (widget);
11168 if (!g_slist_find (tooltip_query_displays, display))
11169 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11171 if (tooltip_query_id == 0)
11172 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11176 * gtk_widget_set_tooltip_text:
11177 * @widget: a #GtkWidget
11178 * @text: the contents of the tooltip for @widget
11180 * Sets @text as the contents of the tooltip. This function will take
11181 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11182 * handler for the GtkWidget::query-tooltip signal.
11184 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11189 gtk_widget_set_tooltip_text (GtkWidget *widget,
11192 g_return_if_fail (GTK_IS_WIDGET (widget));
11194 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11198 * gtk_widget_get_tooltip_text:
11199 * @widget: a #GtkWidget
11201 * Gets the contents of the tooltip for @widget.
11203 * Return value: the tooltip text, or %NULL. You should free the
11204 * returned string with g_free() when done.
11209 gtk_widget_get_tooltip_text (GtkWidget *widget)
11211 gchar *text = NULL;
11213 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11215 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11221 * gtk_widget_set_tooltip_markup:
11222 * @widget: a #GtkWidget
11223 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11225 * Sets @markup as the contents of the tooltip, which is marked up with
11226 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11228 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11229 * and of the default handler for the GtkWidget::query-tooltip signal.
11231 * See also the GtkWidget:tooltip-markup property and
11232 * gtk_tooltip_set_markup().
11237 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11238 const gchar *markup)
11240 g_return_if_fail (GTK_IS_WIDGET (widget));
11242 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11246 * gtk_widget_get_tooltip_markup:
11247 * @widget: a #GtkWidget
11249 * Gets the contents of the tooltip for @widget.
11251 * Return value: the tooltip text, or %NULL. You should free the
11252 * returned string with g_free() when done.
11257 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11259 gchar *text = NULL;
11261 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11263 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11269 * gtk_widget_set_has_tooltip:
11270 * @widget: a #GtkWidget
11271 * @has_tooltip: whether or not @widget has a tooltip.
11273 * Sets the has-tooltip property on @widget to @has_tooltip. See
11274 * GtkWidget:has-tooltip for more information.
11279 gtk_widget_set_has_tooltip (GtkWidget *widget,
11280 gboolean has_tooltip)
11282 g_return_if_fail (GTK_IS_WIDGET (widget));
11284 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11288 * gtk_widget_get_has_tooltip:
11289 * @widget: a #GtkWidget
11291 * Returns the current value of the has-tooltip property. See
11292 * GtkWidget:has-tooltip for more information.
11294 * Return value: current value of has-tooltip on @widget.
11299 gtk_widget_get_has_tooltip (GtkWidget *widget)
11301 gboolean has_tooltip = FALSE;
11303 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11305 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11307 return has_tooltip;
11311 * gtk_widget_get_allocation:
11312 * @widget: a #GtkWidget
11313 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11315 * Retrieves the widget's allocation.
11320 gtk_widget_get_allocation (GtkWidget *widget,
11321 GtkAllocation *allocation)
11323 g_return_if_fail (GTK_IS_WIDGET (widget));
11324 g_return_if_fail (allocation != NULL);
11326 *allocation = widget->allocation;
11330 * gtk_widget_set_allocation:
11331 * @widget: a #GtkWidget
11332 * @allocation: a pointer to a #GtkAllocation to copy from
11334 * Sets the widget's allocation. This should not be used
11335 * directly, but from within a widget's size_allocate method.
11340 gtk_widget_set_allocation (GtkWidget *widget,
11341 const GtkAllocation *allocation)
11343 g_return_if_fail (GTK_IS_WIDGET (widget));
11344 g_return_if_fail (allocation != NULL);
11346 widget->allocation = *allocation;
11350 * gtk_widget_get_requisition:
11351 * @widget: a #GtkWidget
11352 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11354 * Retrieves the widget's requisition.
11356 * This function should only be used by widget implementations in
11357 * order to figure whether the widget's requisition has actually
11358 * changed after some internal state change (so that they can call
11359 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11361 * Normally, gtk_widget_size_request() should be used.
11366 gtk_widget_get_requisition (GtkWidget *widget,
11367 GtkRequisition *requisition)
11369 g_return_if_fail (GTK_IS_WIDGET (widget));
11370 g_return_if_fail (requisition != NULL);
11372 *requisition = widget->requisition;
11376 * gtk_widget_set_window:
11377 * @widget: a #GtkWidget
11378 * @window: a #GdkWindow
11380 * Sets a widget's window. This function should only be used in a
11381 * widget's GtkWidget::realize() implementation. The %window passed is
11382 * usually either new window created with gdk_window_new(), or the
11383 * window of its parent widget as returned by
11384 * gtk_widget_get_parent_window().
11386 * Widgets must indicate whether they will create their own #GdkWindow
11387 * by calling gtk_widget_set_has_window(). This is usually done in the
11388 * widget's init() function.
11393 gtk_widget_set_window (GtkWidget *widget,
11396 g_return_if_fail (GTK_IS_WIDGET (widget));
11397 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11399 if (widget->window != window)
11401 widget->window = window;
11402 g_object_notify (G_OBJECT (widget), "window");
11407 * gtk_widget_get_window:
11408 * @widget: a #GtkWidget
11410 * Returns the widget's window if it is realized, %NULL otherwise
11412 * Return value: @widget's window.
11417 gtk_widget_get_window (GtkWidget *widget)
11419 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11421 return widget->window;
11425 _gtk_widget_set_has_focus (GtkWidget *widget,
11426 gboolean has_focus)
11429 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
11431 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
11435 * gtk_widget_send_focus_change:
11436 * @widget: a #GtkWidget
11437 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
11439 * Sends the focus change @event to @widget
11441 * This function is not meant to be used by applications. The only time it
11442 * should be used is when it is necessary for a #GtkWidget to assign focus
11443 * to a widget that is semantically owned by the first widget even though
11444 * it's not a direct child - for instance, a search entry in a floating
11445 * window similar to the quick search in #GtkTreeView.
11447 * An example of its usage is:
11450 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
11452 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
11453 * fevent->focus_change.in = TRUE;
11454 * fevent->focus_change.window = gtk_widget_get_window (widget);
11455 * if (fevent->focus_change.window != NULL)
11456 * g_object_ref (fevent->focus_change.window);
11458 * gtk_widget_send_focus_change (widget, fevent);
11460 * gdk_event_free (event);
11463 * Return value: the return value from the event signal emission: %TRUE
11464 * if the event was handled, and %FALSE otherwise
11469 gtk_widget_send_focus_change (GtkWidget *widget,
11474 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11475 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
11477 g_object_ref (widget);
11479 _gtk_widget_set_has_focus (widget, event->focus_change.in);
11481 res = gtk_widget_event (widget, event);
11483 g_object_notify (G_OBJECT (widget), "has-focus");
11485 g_object_unref (widget);
11490 #define __GTK_WIDGET_C__
11491 #include "gtkaliasdef.c"