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"
60 * @Short_description: Base class for all widgets
63 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
64 * widget lifecycle, states and style.
65 * <refsect2 id="style-properties">
67 * <structname>GtkWidget</structname> introduces <firstterm>style
68 * properties</firstterm> - these are basically object properties that are stored
69 * not on the object, but in the style object associated to the widget. Style
70 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
71 * This mechanism is used for configuring such things as the location of the
72 * scrollbar arrows through the theme, giving theme authors more control over the
73 * look of applications without the need to write a theme engine in C.
76 * Use gtk_widget_class_install_style_property() to install style properties for
77 * a widget class, gtk_widget_class_find_style_property() or
78 * gtk_widget_class_list_style_properties() to get information about existing
79 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
80 * gtk_widget_style_get_valist() to obtain the value of a style property.
83 * <refsect2 id="GtkWidget-BUILDER-UI">
84 * <title>GtkWidget as GtkBuildable</title>
86 * The GtkWidget implementation of the GtkBuildable interface supports a
87 * custom <accelerator> element, which has attributes named key,
88 * modifiers and signal and allows to specify accelerators.
91 * <title>A UI definition fragment specifying an accelerator</title>
92 * <programlisting><![CDATA[
93 * <object class="GtkButton">
94 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
96 * ]]></programlisting>
99 * In addition to accelerators, <structname>GtkWidget</structname> also support a
100 * custom <accessible> element, which supports actions and relations.
101 * Properties on the accessible implementation of an object can be set by accessing the
102 * internal child "accessible" of a <structname>GtkWidget</structname>.
105 * <title>A UI definition fragment specifying an accessible</title>
106 * <programlisting><![CDATA[
107 * <object class="GtkButton" id="label1"/>
108 * <property name="label">I am a Label for a Button</property>
110 * <object class="GtkButton" id="button1">
112 * <action action_name="click" translatable="yes">Click the button.</action>
113 * <relation target="label1" type="labelled-by"/>
115 * <child internal-child="accessible">
116 * <object class="AtkObject" id="a11y-button1">
117 * <property name="AtkObject::name">Clickable Button</property>
121 * ]]></programlisting>
126 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
127 #define INIT_PATH_SIZE (512)
153 BUTTON_RELEASE_EVENT,
168 PROPERTY_NOTIFY_EVENT,
169 SELECTION_CLEAR_EVENT,
170 SELECTION_REQUEST_EVENT,
171 SELECTION_NOTIFY_EVENT,
186 VISIBILITY_NOTIFY_EVENT,
190 ACCEL_CLOSURES_CHANGED,
216 PROP_RECEIVES_DEFAULT,
217 PROP_COMPOSITE_CHILD,
220 PROP_EXTENSION_EVENTS,
229 typedef struct _GtkStateData GtkStateData;
234 guint state_restoration : 1;
235 guint parent_sensitive : 1;
236 guint use_forall : 1;
239 /* --- prototypes --- */
240 static void gtk_widget_class_init (GtkWidgetClass *klass);
241 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
242 static void gtk_widget_init (GtkWidget *widget);
243 static void gtk_widget_set_property (GObject *object,
247 static void gtk_widget_get_property (GObject *object,
251 static void gtk_widget_dispose (GObject *object);
252 static void gtk_widget_real_destroy (GtkObject *object);
253 static void gtk_widget_finalize (GObject *object);
254 static void gtk_widget_real_show (GtkWidget *widget);
255 static void gtk_widget_real_hide (GtkWidget *widget);
256 static void gtk_widget_real_map (GtkWidget *widget);
257 static void gtk_widget_real_unmap (GtkWidget *widget);
258 static void gtk_widget_real_realize (GtkWidget *widget);
259 static void gtk_widget_real_unrealize (GtkWidget *widget);
260 static void gtk_widget_real_size_request (GtkWidget *widget,
261 GtkRequisition *requisition);
262 static void gtk_widget_real_size_allocate (GtkWidget *widget,
263 GtkAllocation *allocation);
264 static void gtk_widget_real_style_set (GtkWidget *widget,
265 GtkStyle *previous_style);
266 static void gtk_widget_real_direction_changed(GtkWidget *widget,
267 GtkTextDirection previous_direction);
269 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
270 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
273 gboolean keyboard_tip,
274 GtkTooltip *tooltip);
275 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
276 GtkWidgetHelpType help_type);
278 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
280 GParamSpec **pspecs);
281 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
283 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
285 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
286 GdkEventFocus *event);
287 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
288 GdkEventFocus *event);
289 static gboolean gtk_widget_real_focus (GtkWidget *widget,
290 GtkDirectionType direction);
291 static void gtk_widget_real_move_focus (GtkWidget *widget,
292 GtkDirectionType direction);
293 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
294 GtkDirectionType direction);
295 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
296 static void gtk_widget_update_pango_context (GtkWidget *widget);
297 static void gtk_widget_propagate_state (GtkWidget *widget,
299 static void gtk_widget_reset_rc_style (GtkWidget *widget);
300 static void gtk_widget_set_style_internal (GtkWidget *widget,
302 gboolean initial_emission);
303 static gint gtk_widget_event_internal (GtkWidget *widget,
305 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
306 gboolean group_cycling);
307 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
308 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
309 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
310 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
311 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
313 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
314 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
315 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
318 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
319 gboolean has_tooltip,
321 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
322 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
324 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
325 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
327 const gchar *childname);
328 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
331 const GValue *value);
332 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
335 const gchar *tagname,
336 GMarkupParser *parser,
338 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
341 const gchar *tagname,
343 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
344 GtkBuilder *builder);
346 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
348 static void gtk_widget_set_usize_internal (GtkWidget *widget,
351 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
355 /* --- variables --- */
356 static gpointer gtk_widget_parent_class = NULL;
357 static guint widget_signals[LAST_SIGNAL] = { 0 };
358 static GtkStyle *gtk_default_style = NULL;
359 static GSList *colormap_stack = NULL;
360 static guint composite_child_stack = 0;
361 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
362 static GParamSpecPool *style_property_spec_pool = NULL;
364 static GQuark quark_property_parser = 0;
365 static GQuark quark_aux_info = 0;
366 static GQuark quark_accel_path = 0;
367 static GQuark quark_accel_closures = 0;
368 static GQuark quark_event_mask = 0;
369 static GQuark quark_extension_event_mode = 0;
370 static GQuark quark_parent_window = 0;
371 static GQuark quark_pointer_window = 0;
372 static GQuark quark_shape_info = 0;
373 static GQuark quark_input_shape_info = 0;
374 static GQuark quark_colormap = 0;
375 static GQuark quark_pango_context = 0;
376 static GQuark quark_rc_style = 0;
377 static GQuark quark_accessible_object = 0;
378 static GQuark quark_mnemonic_labels = 0;
379 static GQuark quark_tooltip_markup = 0;
380 static GQuark quark_has_tooltip = 0;
381 static GQuark quark_tooltip_window = 0;
382 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
383 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
385 /* --- functions --- */
387 gtk_widget_get_type (void)
389 static GType widget_type = 0;
391 if (G_UNLIKELY (widget_type == 0))
393 const GTypeInfo widget_info =
395 sizeof (GtkWidgetClass),
396 NULL, /* base_init */
397 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
398 (GClassInitFunc) gtk_widget_class_init,
399 NULL, /* class_finalize */
400 NULL, /* class_init */
403 (GInstanceInitFunc) gtk_widget_init,
404 NULL, /* value_table */
407 const GInterfaceInfo accessibility_info =
409 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
410 (GInterfaceFinalizeFunc) NULL,
411 NULL /* interface data */
414 const GInterfaceInfo buildable_info =
416 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
417 (GInterfaceFinalizeFunc) NULL,
418 NULL /* interface data */
421 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
422 &widget_info, G_TYPE_FLAG_ABSTRACT);
424 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
425 &accessibility_info) ;
426 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
435 child_property_notify_dispatcher (GObject *object,
439 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
443 gtk_widget_class_init (GtkWidgetClass *klass)
445 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
446 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
447 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
448 GtkBindingSet *binding_set;
450 gtk_widget_parent_class = g_type_class_peek_parent (klass);
452 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
453 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
454 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
455 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
456 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
457 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
458 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
459 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
460 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
461 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
462 quark_colormap = g_quark_from_static_string ("gtk-colormap");
463 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
464 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
465 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
466 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
467 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
468 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
469 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
471 style_property_spec_pool = g_param_spec_pool_new (FALSE);
472 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
473 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
474 cpn_context.dispatcher = child_property_notify_dispatcher;
475 _gtk_widget_child_property_notify_context = &cpn_context;
477 gobject_class->dispose = gtk_widget_dispose;
478 gobject_class->finalize = gtk_widget_finalize;
479 gobject_class->set_property = gtk_widget_set_property;
480 gobject_class->get_property = gtk_widget_get_property;
482 object_class->destroy = gtk_widget_real_destroy;
484 klass->activate_signal = 0;
485 klass->set_scroll_adjustments_signal = 0;
486 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
487 klass->show = gtk_widget_real_show;
488 klass->show_all = gtk_widget_show;
489 klass->hide = gtk_widget_real_hide;
490 klass->hide_all = gtk_widget_hide;
491 klass->map = gtk_widget_real_map;
492 klass->unmap = gtk_widget_real_unmap;
493 klass->realize = gtk_widget_real_realize;
494 klass->unrealize = gtk_widget_real_unrealize;
495 klass->size_request = gtk_widget_real_size_request;
496 klass->size_allocate = gtk_widget_real_size_allocate;
497 klass->state_changed = NULL;
498 klass->parent_set = NULL;
499 klass->hierarchy_changed = NULL;
500 klass->style_set = gtk_widget_real_style_set;
501 klass->direction_changed = gtk_widget_real_direction_changed;
502 klass->grab_notify = NULL;
503 klass->child_notify = NULL;
504 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
505 klass->grab_focus = gtk_widget_real_grab_focus;
506 klass->focus = gtk_widget_real_focus;
508 klass->button_press_event = NULL;
509 klass->button_release_event = NULL;
510 klass->motion_notify_event = NULL;
511 klass->delete_event = NULL;
512 klass->destroy_event = NULL;
513 klass->expose_event = NULL;
514 klass->key_press_event = gtk_widget_real_key_press_event;
515 klass->key_release_event = gtk_widget_real_key_release_event;
516 klass->enter_notify_event = NULL;
517 klass->leave_notify_event = NULL;
518 klass->configure_event = NULL;
519 klass->focus_in_event = gtk_widget_real_focus_in_event;
520 klass->focus_out_event = gtk_widget_real_focus_out_event;
521 klass->map_event = NULL;
522 klass->unmap_event = NULL;
523 klass->window_state_event = NULL;
524 klass->property_notify_event = _gtk_selection_property_notify;
525 klass->selection_clear_event = gtk_selection_clear;
526 klass->selection_request_event = _gtk_selection_request;
527 klass->selection_notify_event = _gtk_selection_notify;
528 klass->selection_received = NULL;
529 klass->proximity_in_event = NULL;
530 klass->proximity_out_event = NULL;
531 klass->drag_begin = NULL;
532 klass->drag_end = NULL;
533 klass->drag_data_delete = NULL;
534 klass->drag_leave = NULL;
535 klass->drag_motion = NULL;
536 klass->drag_drop = NULL;
537 klass->drag_data_received = NULL;
538 klass->screen_changed = NULL;
539 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
540 klass->grab_broken_event = NULL;
541 klass->query_tooltip = gtk_widget_real_query_tooltip;
543 klass->show_help = gtk_widget_real_show_help;
545 /* Accessibility support */
546 klass->get_accessible = gtk_widget_real_get_accessible;
548 klass->no_expose_event = NULL;
550 g_object_class_install_property (gobject_class,
552 g_param_spec_string ("name",
554 P_("The name of the widget"),
556 GTK_PARAM_READWRITE));
557 g_object_class_install_property (gobject_class,
559 g_param_spec_object ("parent",
561 P_("The parent widget of this widget. Must be a Container widget"),
563 GTK_PARAM_READWRITE));
565 g_object_class_install_property (gobject_class,
567 g_param_spec_int ("width-request",
569 P_("Override for width request of the widget, or -1 if natural request should be used"),
573 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
576 g_param_spec_int ("height-request",
577 P_("Height request"),
578 P_("Override for height request of the widget, or -1 if natural request should be used"),
582 GTK_PARAM_READWRITE));
583 g_object_class_install_property (gobject_class,
585 g_param_spec_boolean ("visible",
587 P_("Whether the widget is visible"),
589 GTK_PARAM_READWRITE));
590 g_object_class_install_property (gobject_class,
592 g_param_spec_boolean ("sensitive",
594 P_("Whether the widget responds to input"),
596 GTK_PARAM_READWRITE));
597 g_object_class_install_property (gobject_class,
599 g_param_spec_boolean ("app-paintable",
600 P_("Application paintable"),
601 P_("Whether the application will paint directly on the widget"),
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_boolean ("can-focus",
608 P_("Whether the widget can accept the input focus"),
610 GTK_PARAM_READWRITE));
611 g_object_class_install_property (gobject_class,
613 g_param_spec_boolean ("has-focus",
615 P_("Whether the widget has the input focus"),
617 GTK_PARAM_READWRITE));
618 g_object_class_install_property (gobject_class,
620 g_param_spec_boolean ("is-focus",
622 P_("Whether the widget is the focus widget within the toplevel"),
624 GTK_PARAM_READWRITE));
625 g_object_class_install_property (gobject_class,
627 g_param_spec_boolean ("can-default",
629 P_("Whether the widget can be the default widget"),
631 GTK_PARAM_READWRITE));
632 g_object_class_install_property (gobject_class,
634 g_param_spec_boolean ("has-default",
636 P_("Whether the widget is the default widget"),
638 GTK_PARAM_READWRITE));
639 g_object_class_install_property (gobject_class,
640 PROP_RECEIVES_DEFAULT,
641 g_param_spec_boolean ("receives-default",
642 P_("Receives default"),
643 P_("If TRUE, the widget will receive the default action when it is focused"),
645 GTK_PARAM_READWRITE));
646 g_object_class_install_property (gobject_class,
647 PROP_COMPOSITE_CHILD,
648 g_param_spec_boolean ("composite-child",
649 P_("Composite child"),
650 P_("Whether the widget is part of a composite widget"),
652 GTK_PARAM_READABLE));
653 g_object_class_install_property (gobject_class,
655 g_param_spec_object ("style",
657 P_("The style of the widget, which contains information about how it will look (colors etc)"),
659 GTK_PARAM_READWRITE));
660 g_object_class_install_property (gobject_class,
662 g_param_spec_flags ("events",
664 P_("The event mask that decides what kind of GdkEvents this widget gets"),
667 GTK_PARAM_READWRITE));
668 g_object_class_install_property (gobject_class,
669 PROP_EXTENSION_EVENTS,
670 g_param_spec_enum ("extension-events",
671 P_("Extension events"),
672 P_("The mask that decides what kind of extension events this widget gets"),
673 GDK_TYPE_EXTENSION_MODE,
674 GDK_EXTENSION_EVENTS_NONE,
675 GTK_PARAM_READWRITE));
676 g_object_class_install_property (gobject_class,
678 g_param_spec_boolean ("no-show-all",
680 P_("Whether gtk_widget_show_all() should not affect this widget"),
682 GTK_PARAM_READWRITE));
685 * GtkWidget:has-tooltip:
687 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
688 * A value of %TRUE indicates that @widget can have a tooltip, in this case
689 * the widget will be queried using #GtkWidget::query-tooltip to determine
690 * whether it will provide a tooltip or not.
692 * Note that setting this property to %TRUE for the first time will change
693 * the event masks of the GdkWindows of this widget to include leave-notify
694 * and motion-notify events. This cannot and will not be undone when the
695 * property is set to %FALSE again.
699 g_object_class_install_property (gobject_class,
701 g_param_spec_boolean ("has-tooltip",
703 P_("Whether this widget has a tooltip"),
705 GTK_PARAM_READWRITE));
707 * GtkWidget:tooltip-text:
709 * Sets the text of tooltip to be the given string.
711 * Also see gtk_tooltip_set_text().
713 * This is a convenience property which will take care of getting the
714 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
715 * will automatically be set to %TRUE and there will be taken care of
716 * #GtkWidget::query-tooltip in the default signal handler.
720 g_object_class_install_property (gobject_class,
722 g_param_spec_string ("tooltip-text",
724 P_("The contents of the tooltip for this widget"),
726 GTK_PARAM_READWRITE));
728 * GtkWidget:tooltip-markup:
730 * Sets the text of tooltip to be the given string, which is marked up
731 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
732 * Also see gtk_tooltip_set_markup().
734 * This is a convenience property which will take care of getting the
735 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
736 * will automatically be set to %TRUE and there will be taken care of
737 * #GtkWidget::query-tooltip in the default signal handler.
741 g_object_class_install_property (gobject_class,
743 g_param_spec_string ("tooltip-markup",
744 P_("Tooltip markup"),
745 P_("The contents of the tooltip for this widget"),
747 GTK_PARAM_READWRITE));
752 * The widget's window if it is realized, %NULL otherwise.
756 g_object_class_install_property (gobject_class,
758 g_param_spec_object ("window",
760 P_("The widget's window if it is realized"),
762 GTK_PARAM_READABLE));
765 * GtkWidget:double-buffered
767 * Whether or not the widget is double buffered.
771 g_object_class_install_property (gobject_class,
772 PROP_DOUBLE_BUFFERED,
773 g_param_spec_boolean ("double-buffered",
774 P_("Double Buffered"),
775 P_("Whether or not the widget is double buffered"),
777 GTK_PARAM_READWRITE));
781 * @widget: the object which received the signal.
783 widget_signals[SHOW] =
784 g_signal_new (I_("show"),
785 G_TYPE_FROM_CLASS (gobject_class),
787 G_STRUCT_OFFSET (GtkWidgetClass, show),
789 _gtk_marshal_VOID__VOID,
794 * @widget: the object which received the signal.
796 widget_signals[HIDE] =
797 g_signal_new (I_("hide"),
798 G_TYPE_FROM_CLASS (gobject_class),
800 G_STRUCT_OFFSET (GtkWidgetClass, hide),
802 _gtk_marshal_VOID__VOID,
807 * @widget: the object which received the signal.
809 widget_signals[MAP] =
810 g_signal_new (I_("map"),
811 G_TYPE_FROM_CLASS (gobject_class),
813 G_STRUCT_OFFSET (GtkWidgetClass, map),
815 _gtk_marshal_VOID__VOID,
820 * @widget: the object which received the signal.
822 widget_signals[UNMAP] =
823 g_signal_new (I_("unmap"),
824 G_TYPE_FROM_CLASS (gobject_class),
826 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
828 _gtk_marshal_VOID__VOID,
832 * GtkWidget::realize:
833 * @widget: the object which received the signal.
835 widget_signals[REALIZE] =
836 g_signal_new (I_("realize"),
837 G_TYPE_FROM_CLASS (gobject_class),
839 G_STRUCT_OFFSET (GtkWidgetClass, realize),
841 _gtk_marshal_VOID__VOID,
845 * GtkWidget::unrealize:
846 * @widget: the object which received the signal.
848 widget_signals[UNREALIZE] =
849 g_signal_new (I_("unrealize"),
850 G_TYPE_FROM_CLASS (gobject_class),
852 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
854 _gtk_marshal_VOID__VOID,
858 * GtkWidget::size-request:
859 * @widget: the object which received the signal.
862 widget_signals[SIZE_REQUEST] =
863 g_signal_new (I_("size-request"),
864 G_TYPE_FROM_CLASS (gobject_class),
866 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
868 _gtk_marshal_VOID__BOXED,
870 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
873 * GtkWidget::size-allocate:
874 * @widget: the object which received the signal.
877 widget_signals[SIZE_ALLOCATE] =
878 g_signal_new (I_("size-allocate"),
879 G_TYPE_FROM_CLASS (gobject_class),
881 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
883 _gtk_marshal_VOID__BOXED,
885 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
888 * GtkWidget::state-changed:
889 * @widget: the object which received the signal.
890 * @state: the previous state
892 * The ::state-changed signal is emitted when the widget state changes.
893 * See gtk_widget_get_state().
895 widget_signals[STATE_CHANGED] =
896 g_signal_new (I_("state-changed"),
897 G_TYPE_FROM_CLASS (gobject_class),
899 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
901 _gtk_marshal_VOID__ENUM,
903 GTK_TYPE_STATE_TYPE);
906 * GtkWidget::parent-set:
907 * @widget: the object on which the signal is emitted
908 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
909 * just got its initial parent.
911 * The ::parent-set signal is emitted when a new parent
912 * has been set on a widget.
914 widget_signals[PARENT_SET] =
915 g_signal_new (I_("parent-set"),
916 G_TYPE_FROM_CLASS (gobject_class),
918 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
920 _gtk_marshal_VOID__OBJECT,
925 * GtkWidget::hierarchy-changed:
926 * @widget: the object on which the signal is emitted
927 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
928 * if the widget was previously unanchored
930 * The ::hierarchy-changed signal is emitted when the
931 * anchored state of a widget changes. A widget is
932 * <firstterm>anchored</firstterm> when its toplevel
933 * ancestor is a #GtkWindow. This signal is emitted when
934 * a widget changes from un-anchored to anchored or vice-versa.
936 widget_signals[HIERARCHY_CHANGED] =
937 g_signal_new (I_("hierarchy-changed"),
938 G_TYPE_FROM_CLASS (gobject_class),
940 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
942 _gtk_marshal_VOID__OBJECT,
947 * GtkWidget::style-set:
948 * @widget: the object on which the signal is emitted
949 * @previous_style: (allow-none): the previous style, or %NULL if the widget
950 * just got its initial style
952 * The ::style-set signal is emitted when a new style has been set
953 * on a widget. Note that style-modifying functions like
954 * gtk_widget_modify_base() also cause this signal to be emitted.
956 widget_signals[STYLE_SET] =
957 g_signal_new (I_("style-set"),
958 G_TYPE_FROM_CLASS (gobject_class),
960 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
962 _gtk_marshal_VOID__OBJECT,
966 * GtkWidget::direction-changed:
967 * @widget: the object on which the signal is emitted
968 * @previous_direction: the previous text direction of @widget
970 * The ::direction-changed signal is emitted when the text direction
971 * of a widget changes.
973 widget_signals[DIRECTION_CHANGED] =
974 g_signal_new (I_("direction-changed"),
975 G_TYPE_FROM_CLASS (gobject_class),
977 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
979 _gtk_marshal_VOID__ENUM,
981 GTK_TYPE_TEXT_DIRECTION);
984 * GtkWidget::grab-notify:
985 * @widget: the object which received the signal
986 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
987 * if it becomes unshadowed
989 * The ::grab-notify signal is emitted when a widget becomes
990 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
991 * another widget, or when it becomes unshadowed due to a grab
994 * A widget is shadowed by a gtk_grab_add() when the topmost
995 * grab widget in the grab stack of its window group is not
998 widget_signals[GRAB_NOTIFY] =
999 g_signal_new (I_("grab-notify"),
1000 G_TYPE_FROM_CLASS (gobject_class),
1002 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1004 _gtk_marshal_VOID__BOOLEAN,
1009 * GtkWidget::child-notify:
1010 * @widget: the object which received the signal
1011 * @pspec: the #GParamSpec of the changed child property
1013 * The ::child-notify signal is emitted for each
1014 * <link linkend="child-properties">child property</link> that has
1015 * changed on an object. The signal's detail holds the property name.
1017 widget_signals[CHILD_NOTIFY] =
1018 g_signal_new (I_("child-notify"),
1019 G_TYPE_FROM_CLASS (gobject_class),
1020 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1021 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1023 g_cclosure_marshal_VOID__PARAM,
1028 * GtkWidget::mnemonic-activate:
1029 * @widget: the object which received the signal.
1032 widget_signals[MNEMONIC_ACTIVATE] =
1033 g_signal_new (I_("mnemonic-activate"),
1034 G_TYPE_FROM_CLASS (gobject_class),
1036 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1037 _gtk_boolean_handled_accumulator, NULL,
1038 _gtk_marshal_BOOLEAN__BOOLEAN,
1043 * GtkWidget::grab-focus:
1044 * @widget: the object which received the signal.
1046 widget_signals[GRAB_FOCUS] =
1047 g_signal_new (I_("grab-focus"),
1048 G_TYPE_FROM_CLASS (gobject_class),
1049 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1050 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1052 _gtk_marshal_VOID__VOID,
1057 * @widget: the object which received the signal.
1060 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1062 widget_signals[FOCUS] =
1063 g_signal_new (I_("focus"),
1064 G_TYPE_FROM_CLASS (object_class),
1066 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1067 _gtk_boolean_handled_accumulator, NULL,
1068 _gtk_marshal_BOOLEAN__ENUM,
1070 GTK_TYPE_DIRECTION_TYPE);
1073 * GtkWidget::move-focus:
1074 * @widget: the object which received the signal.
1077 widget_signals[MOVE_FOCUS] =
1078 g_signal_new_class_handler (I_("move-focus"),
1079 G_TYPE_FROM_CLASS (object_class),
1080 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1081 G_CALLBACK (gtk_widget_real_move_focus),
1083 _gtk_marshal_VOID__ENUM,
1086 GTK_TYPE_DIRECTION_TYPE);
1089 * @widget: the object which received the signal.
1090 * @event: the #GdkEvent which triggered this signal
1092 * The GTK+ main loop will emit three signals for each GDK event delivered
1093 * to a widget: one generic ::event signal, another, more specific,
1094 * signal that matches the type of event delivered (e.g.
1095 * #GtkWidget::key-press-event) and finally a generic
1096 * #GtkWidget::event-after signal.
1098 * Returns: %TRUE to stop other handlers from being invoked for the event
1099 * and to cancel the emission of the second specific ::event signal.
1100 * %FALSE to propagate the event further and to allow the emission of
1101 * the second signal. The ::event-after signal is emitted regardless of
1104 widget_signals[EVENT] =
1105 g_signal_new (I_("event"),
1106 G_TYPE_FROM_CLASS (gobject_class),
1108 G_STRUCT_OFFSET (GtkWidgetClass, event),
1109 _gtk_boolean_handled_accumulator, NULL,
1110 _gtk_marshal_BOOLEAN__BOXED,
1112 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1115 * GtkWidget::event-after:
1116 * @widget: the object which received the signal.
1117 * @event: the #GdkEvent which triggered this signal
1119 * After the emission of the #GtkWidget::event signal and (optionally)
1120 * the second more specific signal, ::event-after will be emitted
1121 * regardless of the previous two signals handlers return values.
1124 widget_signals[EVENT_AFTER] =
1125 g_signal_new (I_("event-after"),
1126 G_TYPE_FROM_CLASS (gobject_class),
1130 _gtk_marshal_VOID__BOXED,
1132 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1135 * GtkWidget::button-press-event:
1136 * @widget: the object which received the signal.
1137 * @event: the #GdkEventButton which triggered this signal
1139 * The ::button-press-event signal will be emitted when a button
1140 * (typically from a mouse) is pressed.
1142 * To receive this signal, the #GdkWindow associated to the
1143 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1145 * This signal will be sent to the grab widget if there is one.
1147 * Returns: %TRUE to stop other handlers from being invoked for the event.
1148 * %FALSE to propagate the event further.
1150 widget_signals[BUTTON_PRESS_EVENT] =
1151 g_signal_new (I_("button-press-event"),
1152 G_TYPE_FROM_CLASS (gobject_class),
1154 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1155 _gtk_boolean_handled_accumulator, NULL,
1156 _gtk_marshal_BOOLEAN__BOXED,
1158 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1161 * GtkWidget::button-release-event:
1162 * @widget: the object which received the signal.
1163 * @event: the #GdkEventButton which triggered this signal
1165 * The ::button-release-event signal will be emitted when a button
1166 * (typically from a mouse) is released.
1168 * To receive this signal, the #GdkWindow associated to the
1169 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1171 * This signal will be sent to the grab widget if there is one.
1173 * Returns: %TRUE to stop other handlers from being invoked for the event.
1174 * %FALSE to propagate the event further.
1176 widget_signals[BUTTON_RELEASE_EVENT] =
1177 g_signal_new (I_("button-release-event"),
1178 G_TYPE_FROM_CLASS (gobject_class),
1180 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1181 _gtk_boolean_handled_accumulator, NULL,
1182 _gtk_marshal_BOOLEAN__BOXED,
1184 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1187 * GtkWidget::scroll-event:
1188 * @widget: the object which received the signal.
1189 * @event: the #GdkEventScroll which triggered this signal
1191 * The ::scroll-event signal is emitted when a button in the 4 to 7
1192 * range is pressed. Wheel mice are usually configured to generate
1193 * button press events for buttons 4 and 5 when the wheel is turned.
1195 * To receive this signal, the #GdkWindow associated to the widget needs
1196 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1198 * This signal will be sent to the grab widget if there is one.
1200 * Returns: %TRUE to stop other handlers from being invoked for the event.
1201 * %FALSE to propagate the event further.
1203 widget_signals[SCROLL_EVENT] =
1204 g_signal_new (I_("scroll-event"),
1205 G_TYPE_FROM_CLASS (gobject_class),
1207 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1208 _gtk_boolean_handled_accumulator, NULL,
1209 _gtk_marshal_BOOLEAN__BOXED,
1211 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1213 * GtkWidget::motion-notify-event:
1214 * @widget: the object which received the signal.
1215 * @event: the #GdkEventMotion which triggered this signal
1217 * The ::motion-notify-event signal is emitted when the pointer moves
1218 * over the widget's #GdkWindow.
1220 * To receive this signal, the #GdkWindow associated to the widget
1221 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1223 * This signal will be sent to the grab widget if there is one.
1225 * Returns: %TRUE to stop other handlers from being invoked for the event.
1226 * %FALSE to propagate the event further.
1228 widget_signals[MOTION_NOTIFY_EVENT] =
1229 g_signal_new (I_("motion-notify-event"),
1230 G_TYPE_FROM_CLASS (gobject_class),
1232 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1233 _gtk_boolean_handled_accumulator, NULL,
1234 _gtk_marshal_BOOLEAN__BOXED,
1236 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1239 * GtkWidget::composited-changed:
1240 * @widget: the object on which the signal is emitted
1242 * The ::composited-changed signal is emitted when the composited
1243 * status of @widget<!-- -->s screen changes.
1244 * See gdk_screen_is_composited().
1246 widget_signals[COMPOSITED_CHANGED] =
1247 g_signal_new (I_("composited-changed"),
1248 G_TYPE_FROM_CLASS (gobject_class),
1249 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1250 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1252 _gtk_marshal_VOID__VOID,
1256 * GtkWidget::keynav-failed:
1257 * @widget: the object which received the signal
1258 * @direction: the direction of movement
1260 * Gets emitted if keyboard navigation fails.
1261 * See gtk_widget_keynav_failed() for details.
1263 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1264 * if the emitting widget should try to handle the keyboard
1265 * navigation attempt in its parent container(s).
1269 widget_signals[KEYNAV_FAILED] =
1270 g_signal_new_class_handler (I_("keynav-failed"),
1271 G_TYPE_FROM_CLASS (gobject_class),
1273 G_CALLBACK (gtk_widget_real_keynav_failed),
1274 _gtk_boolean_handled_accumulator, NULL,
1275 _gtk_marshal_BOOLEAN__ENUM,
1277 GTK_TYPE_DIRECTION_TYPE);
1280 * GtkWidget::delete-event:
1281 * @widget: the object which received the signal
1282 * @event: the event which triggered this signal
1284 * The ::delete-event signal is emitted if a user requests that
1285 * a toplevel window is closed. The default handler for this signal
1286 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1287 * this signal will cause the window to be hidden instead, so that
1288 * it can later be shown again without reconstructing it.
1290 * Returns: %TRUE to stop other handlers from being invoked for the event.
1291 * %FALSE to propagate the event further.
1293 widget_signals[DELETE_EVENT] =
1294 g_signal_new (I_("delete-event"),
1295 G_TYPE_FROM_CLASS (gobject_class),
1297 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1298 _gtk_boolean_handled_accumulator, NULL,
1299 _gtk_marshal_BOOLEAN__BOXED,
1301 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1304 * GtkWidget::destroy-event:
1305 * @widget: the object which received the signal.
1306 * @event: the event which triggered this signal
1308 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1309 * You rarely get this signal, because most widgets disconnect themselves
1310 * from their window before they destroy it, so no widget owns the
1311 * window at destroy time.
1313 * To receive this signal, the #GdkWindow associated to the widget needs
1314 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1315 * automatically for all new windows.
1317 * Returns: %TRUE to stop other handlers from being invoked for the event.
1318 * %FALSE to propagate the event further.
1320 widget_signals[DESTROY_EVENT] =
1321 g_signal_new (I_("destroy-event"),
1322 G_TYPE_FROM_CLASS (gobject_class),
1324 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1325 _gtk_boolean_handled_accumulator, NULL,
1326 _gtk_marshal_BOOLEAN__BOXED,
1328 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1331 * GtkWidget::expose-event:
1332 * @widget: the object which received the signal.
1333 * @event: the #GdkEventExpose which triggered this signal
1335 * The ::expose-event signal is emitted when an area of a previously
1336 * obscured #GdkWindow is made visible and needs to be redrawn.
1337 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1340 * To receive this signal, the #GdkWindow associated to the widget needs
1341 * to enable the #GDK_EXPOSURE_MASK mask.
1343 * Returns: %TRUE to stop other handlers from being invoked for the event.
1344 * %FALSE to propagate the event further.
1346 widget_signals[EXPOSE_EVENT] =
1347 g_signal_new (I_("expose-event"),
1348 G_TYPE_FROM_CLASS (gobject_class),
1350 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1351 _gtk_boolean_handled_accumulator, NULL,
1352 _gtk_marshal_BOOLEAN__BOXED,
1354 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1357 * GtkWidget::key-press-event:
1358 * @widget: the object which received the signal
1359 * @event: the #GdkEventKey which triggered this signal
1361 * The ::key-press-event signal is emitted when a key is pressed.
1363 * To receive this signal, the #GdkWindow associated to the widget needs
1364 * to enable the #GDK_KEY_PRESS_MASK mask.
1366 * This signal will be sent to the grab widget if there is one.
1368 * Returns: %TRUE to stop other handlers from being invoked for the event.
1369 * %FALSE to propagate the event further.
1371 widget_signals[KEY_PRESS_EVENT] =
1372 g_signal_new (I_("key-press-event"),
1373 G_TYPE_FROM_CLASS (gobject_class),
1375 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1376 _gtk_boolean_handled_accumulator, NULL,
1377 _gtk_marshal_BOOLEAN__BOXED,
1379 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1382 * GtkWidget::key-release-event:
1383 * @widget: the object which received the signal
1384 * @event: the #GdkEventKey which triggered this signal
1386 * The ::key-release-event signal is emitted when a key is pressed.
1388 * To receive this signal, the #GdkWindow associated to the widget needs
1389 * to enable the #GDK_KEY_RELEASE_MASK mask.
1391 * This signal will be sent to the grab widget if there is one.
1393 * Returns: %TRUE to stop other handlers from being invoked for the event.
1394 * %FALSE to propagate the event further.
1396 widget_signals[KEY_RELEASE_EVENT] =
1397 g_signal_new (I_("key-release-event"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1401 _gtk_boolean_handled_accumulator, NULL,
1402 _gtk_marshal_BOOLEAN__BOXED,
1404 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1407 * GtkWidget::enter-notify-event:
1408 * @widget: the object which received the signal
1409 * @event: the #GdkEventCrossing which triggered this signal
1411 * The ::enter-notify-event will be emitted when the pointer enters
1412 * the @widget's window.
1414 * To receive this signal, the #GdkWindow associated to the widget needs
1415 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1417 * This signal will be sent to the grab widget if there is one.
1419 * Returns: %TRUE to stop other handlers from being invoked for the event.
1420 * %FALSE to propagate the event further.
1422 widget_signals[ENTER_NOTIFY_EVENT] =
1423 g_signal_new (I_("enter-notify-event"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1427 _gtk_boolean_handled_accumulator, NULL,
1428 _gtk_marshal_BOOLEAN__BOXED,
1430 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1433 * GtkWidget::leave-notify-event:
1434 * @widget: the object which received the signal
1435 * @event: the #GdkEventCrossing which triggered this signal
1437 * The ::leave-notify-event will be emitted when the pointer leaves
1438 * the @widget's window.
1440 * To receive this signal, the #GdkWindow associated to the widget needs
1441 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1443 * This signal will be sent to the grab widget if there is one.
1445 * Returns: %TRUE to stop other handlers from being invoked for the event.
1446 * %FALSE to propagate the event further.
1448 widget_signals[LEAVE_NOTIFY_EVENT] =
1449 g_signal_new (I_("leave-notify-event"),
1450 G_TYPE_FROM_CLASS (gobject_class),
1452 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1453 _gtk_boolean_handled_accumulator, NULL,
1454 _gtk_marshal_BOOLEAN__BOXED,
1456 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1459 * GtkWidget::configure-event
1460 * @widget: the object which received the signal
1461 * @event: the #GdkEventConfigure which triggered this signal
1463 * The ::configure-event signal will be emitted when the size, position or
1464 * stacking of the @widget's window has changed.
1466 * To receive this signal, the #GdkWindow associated to the widget needs
1467 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1468 * automatically for all new windows.
1470 * Returns: %TRUE to stop other handlers from being invoked for the event.
1471 * %FALSE to propagate the event further.
1473 widget_signals[CONFIGURE_EVENT] =
1474 g_signal_new (I_("configure-event"),
1475 G_TYPE_FROM_CLASS (gobject_class),
1477 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1478 _gtk_boolean_handled_accumulator, NULL,
1479 _gtk_marshal_BOOLEAN__BOXED,
1481 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1484 * GtkWidget::focus-in-event
1485 * @widget: the object which received the signal
1486 * @event: the #GdkEventFocus which triggered this signal
1488 * The ::focus-in-event signal will be emitted when the keyboard focus
1489 * enters the @widget's window.
1491 * To receive this signal, the #GdkWindow associated to the widget needs
1492 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1494 * Returns: %TRUE to stop other handlers from being invoked for the event.
1495 * %FALSE to propagate the event further.
1497 widget_signals[FOCUS_IN_EVENT] =
1498 g_signal_new (I_("focus-in-event"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1502 _gtk_boolean_handled_accumulator, NULL,
1503 _gtk_marshal_BOOLEAN__BOXED,
1505 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1508 * GtkWidget::focus-out-event
1509 * @widget: the object which received the signal
1510 * @event: the #GdkEventFocus which triggered this signal
1512 * The ::focus-out-event signal will be emitted when the keyboard focus
1513 * leaves the @widget's window.
1515 * To receive this signal, the #GdkWindow associated to the widget needs
1516 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1518 * Returns: %TRUE to stop other handlers from being invoked for the event.
1519 * %FALSE to propagate the event further.
1521 widget_signals[FOCUS_OUT_EVENT] =
1522 g_signal_new (I_("focus-out-event"),
1523 G_TYPE_FROM_CLASS (gobject_class),
1525 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1526 _gtk_boolean_handled_accumulator, NULL,
1527 _gtk_marshal_BOOLEAN__BOXED,
1529 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1532 * GtkWidget::map-event
1533 * @widget: the object which received the signal
1534 * @event: the #GdkEventAny which triggered this signal
1536 * The ::map-event signal will be emitted when the @widget's window is
1537 * mapped. A window is mapped when it becomes visible on the screen.
1539 * To receive this signal, the #GdkWindow associated to the widget needs
1540 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1541 * automatically for all new windows.
1543 * Returns: %TRUE to stop other handlers from being invoked for the event.
1544 * %FALSE to propagate the event further.
1546 widget_signals[MAP_EVENT] =
1547 g_signal_new (I_("map-event"),
1548 G_TYPE_FROM_CLASS (gobject_class),
1550 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1551 _gtk_boolean_handled_accumulator, NULL,
1552 _gtk_marshal_BOOLEAN__BOXED,
1554 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1557 * GtkWidget::unmap-event
1558 * @widget: the object which received the signal
1559 * @event: the #GdkEventAny which triggered this signal
1561 * The ::unmap-event signal will be emitted when the @widget's window is
1562 * unmapped. A window is unmapped when it becomes invisible on the screen.
1564 * To receive this signal, the #GdkWindow associated to the widget needs
1565 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1566 * automatically for all new windows.
1568 * Returns: %TRUE to stop other handlers from being invoked for the event.
1569 * %FALSE to propagate the event further.
1571 widget_signals[UNMAP_EVENT] =
1572 g_signal_new (I_("unmap-event"),
1573 G_TYPE_FROM_CLASS (gobject_class),
1575 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1576 _gtk_boolean_handled_accumulator, NULL,
1577 _gtk_marshal_BOOLEAN__BOXED,
1579 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1582 * GtkWidget::property-notify-event
1583 * @widget: the object which received the signal
1584 * @event: the #GdkEventProperty which triggered this signal
1586 * The ::property-notify-event signal will be emitted when a property on
1587 * the @widget's window has been changed or deleted.
1589 * To receive this signal, the #GdkWindow associated to the widget needs
1590 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1592 * Returns: %TRUE to stop other handlers from being invoked for the event.
1593 * %FALSE to propagate the event further.
1595 widget_signals[PROPERTY_NOTIFY_EVENT] =
1596 g_signal_new (I_("property-notify-event"),
1597 G_TYPE_FROM_CLASS (gobject_class),
1599 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1600 _gtk_boolean_handled_accumulator, NULL,
1601 _gtk_marshal_BOOLEAN__BOXED,
1603 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1606 * GtkWidget::selection-clear-event
1607 * @widget: the object which received the signal
1608 * @event: the #GdkEventSelection which triggered this signal
1610 * The ::selection-clear-event signal will be emitted when the
1611 * the @widget's window has lost ownership of a selection.
1613 * Returns: %TRUE to stop other handlers from being invoked for the event.
1614 * %FALSE to propagate the event further.
1616 widget_signals[SELECTION_CLEAR_EVENT] =
1617 g_signal_new (I_("selection-clear-event"),
1618 G_TYPE_FROM_CLASS (gobject_class),
1620 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1621 _gtk_boolean_handled_accumulator, NULL,
1622 _gtk_marshal_BOOLEAN__BOXED,
1624 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1627 * GtkWidget::selection-request-event
1628 * @widget: the object which received the signal
1629 * @event: the #GdkEventSelection which triggered this signal
1631 * The ::selection-request-event signal will be emitted when
1632 * another client requests ownership of the selection owned by
1633 * the @widget's window.
1635 * Returns: %TRUE to stop other handlers from being invoked for the event.
1636 * %FALSE to propagate the event further.
1638 widget_signals[SELECTION_REQUEST_EVENT] =
1639 g_signal_new (I_("selection-request-event"),
1640 G_TYPE_FROM_CLASS (gobject_class),
1642 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1643 _gtk_boolean_handled_accumulator, NULL,
1644 _gtk_marshal_BOOLEAN__BOXED,
1646 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1649 * GtkWidget::selection-notify-event:
1650 * @widget: the object which received the signal.
1653 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1655 widget_signals[SELECTION_NOTIFY_EVENT] =
1656 g_signal_new (I_("selection-notify-event"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1659 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1660 _gtk_boolean_handled_accumulator, NULL,
1661 _gtk_marshal_BOOLEAN__BOXED,
1663 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1666 * GtkWidget::selection-received:
1667 * @widget: the object which received the signal.
1671 widget_signals[SELECTION_RECEIVED] =
1672 g_signal_new (I_("selection-received"),
1673 G_TYPE_FROM_CLASS (gobject_class),
1675 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1677 _gtk_marshal_VOID__BOXED_UINT,
1679 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1683 * GtkWidget::selection-get:
1684 * @widget: the object which received the signal.
1689 widget_signals[SELECTION_GET] =
1690 g_signal_new (I_("selection-get"),
1691 G_TYPE_FROM_CLASS (gobject_class),
1693 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1695 _gtk_marshal_VOID__BOXED_UINT_UINT,
1697 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1702 * GtkWidget::proximity-in-event
1703 * @widget: the object which received the signal
1704 * @event: the #GdkEventProximity which triggered this signal
1706 * To receive this signal the #GdkWindow associated to the widget needs
1707 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1709 * This signal will be sent to the grab widget if there is one.
1711 * Returns: %TRUE to stop other handlers from being invoked for the event.
1712 * %FALSE to propagate the event further.
1714 widget_signals[PROXIMITY_IN_EVENT] =
1715 g_signal_new (I_("proximity-in-event"),
1716 G_TYPE_FROM_CLASS (gobject_class),
1718 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1719 _gtk_boolean_handled_accumulator, NULL,
1720 _gtk_marshal_BOOLEAN__BOXED,
1722 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1725 * GtkWidget::proximity-out-event
1726 * @widget: the object which received the signal
1727 * @event: the #GdkEventProximity which triggered this signal
1729 * To receive this signal the #GdkWindow associated to the widget needs
1730 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1732 * This signal will be sent to the grab widget if there is one.
1734 * Returns: %TRUE to stop other handlers from being invoked for the event.
1735 * %FALSE to propagate the event further.
1737 widget_signals[PROXIMITY_OUT_EVENT] =
1738 g_signal_new (I_("proximity-out-event"),
1739 G_TYPE_FROM_CLASS (gobject_class),
1741 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1742 _gtk_boolean_handled_accumulator, NULL,
1743 _gtk_marshal_BOOLEAN__BOXED,
1745 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1748 * GtkWidget::drag-leave:
1749 * @widget: the object which received the signal.
1750 * @drag_context: the drag context
1751 * @time: the timestamp of the motion event
1753 * The ::drag-leave signal is emitted on the drop site when the cursor
1754 * leaves the widget. A typical reason to connect to this signal is to
1755 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1756 * with gtk_drag_unhighlight()
1758 widget_signals[DRAG_LEAVE] =
1759 g_signal_new (I_("drag-leave"),
1760 G_TYPE_FROM_CLASS (gobject_class),
1762 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1764 _gtk_marshal_VOID__OBJECT_UINT,
1766 GDK_TYPE_DRAG_CONTEXT,
1770 * GtkWidget::drag-begin:
1771 * @widget: the object which received the signal
1772 * @drag_context: the drag context
1774 * The ::drag-begin signal is emitted on the drag source when a drag is
1775 * started. A typical reason to connect to this signal is to set up a
1776 * custom drag icon with gtk_drag_source_set_icon().
1778 * Note that some widgets set up a drag icon in the default handler of
1779 * this signal, so you may have to use g_signal_connect_after() to
1780 * override what the default handler did.
1782 widget_signals[DRAG_BEGIN] =
1783 g_signal_new (I_("drag-begin"),
1784 G_TYPE_FROM_CLASS (gobject_class),
1786 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1788 _gtk_marshal_VOID__OBJECT,
1790 GDK_TYPE_DRAG_CONTEXT);
1793 * GtkWidget::drag-end:
1794 * @widget: the object which received the signal
1795 * @drag_context: the drag context
1797 * The ::drag-end signal is emitted on the drag source when a drag is
1798 * finished. A typical reason to connect to this signal is to undo
1799 * things done in #GtkWidget::drag-begin.
1801 widget_signals[DRAG_END] =
1802 g_signal_new (I_("drag-end"),
1803 G_TYPE_FROM_CLASS (gobject_class),
1805 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1807 _gtk_marshal_VOID__OBJECT,
1809 GDK_TYPE_DRAG_CONTEXT);
1812 * GtkWidget::drag-data-delete:
1813 * @widget: the object which received the signal
1814 * @drag_context: the drag context
1816 * The ::drag-data-delete signal is emitted on the drag source when a drag
1817 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1818 * handler is responsible for deleting the data that has been dropped. What
1819 * "delete" means depends on the context of the drag operation.
1821 widget_signals[DRAG_DATA_DELETE] =
1822 g_signal_new (I_("drag-data-delete"),
1823 G_TYPE_FROM_CLASS (gobject_class),
1825 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1827 _gtk_marshal_VOID__OBJECT,
1829 GDK_TYPE_DRAG_CONTEXT);
1832 * GtkWidget::drag-failed:
1833 * @widget: the object which received the signal
1834 * @drag_context: the drag context
1835 * @result: the result of the drag operation
1837 * The ::drag-failed signal is emitted on the drag source when a drag has
1838 * failed. The signal handler may hook custom code to handle a failed DND
1839 * operation based on the type of error, it returns %TRUE is the failure has
1840 * been already handled (not showing the default "drag operation failed"
1841 * animation), otherwise it returns %FALSE.
1843 * Return value: %TRUE if the failed drag operation has been already handled.
1847 widget_signals[DRAG_FAILED] =
1848 g_signal_new (I_("drag-failed"),
1849 G_TYPE_FROM_CLASS (gobject_class),
1851 0, _gtk_boolean_handled_accumulator, NULL,
1852 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1854 GDK_TYPE_DRAG_CONTEXT,
1855 GTK_TYPE_DRAG_RESULT);
1858 * GtkWidget::drag-motion:
1859 * @widget: the object which received the signal
1860 * @drag_context: the drag context
1861 * @x: the x coordinate of the current cursor position
1862 * @y: the y coordinate of the current cursor position
1863 * @time: the timestamp of the motion event
1864 * @returns: whether the cursor position is in a drop zone
1866 * The drag-motion signal is emitted on the drop site when the user
1867 * moves the cursor over the widget during a drag. The signal handler
1868 * must determine whether the cursor position is in a drop zone or not.
1869 * If it is not in a drop zone, it returns %FALSE and no further processing
1870 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1871 * handler is responsible for providing the necessary information for
1872 * displaying feedback to the user, by calling gdk_drag_status().
1874 * If the decision whether the drop will be accepted or rejected can't be
1875 * made based solely on the cursor position and the type of the data, the
1876 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1877 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1878 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1879 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1880 * when using the drag-motion signal that way.
1882 * Also note that there is no drag-enter signal. The drag receiver has to
1883 * keep track of whether he has received any drag-motion signals since the
1884 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1885 * an "enter" signal. Upon an "enter", the handler will typically highlight
1886 * the drop site with gtk_drag_highlight().
1889 * drag_motion (GtkWidget *widget,
1890 * GdkDragContext *context,
1897 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1899 * if (!private_data->drag_highlight)
1901 * private_data->drag_highlight = 1;
1902 * gtk_drag_highlight (widget);
1905 * target = gtk_drag_dest_find_target (widget, context, NULL);
1906 * if (target == GDK_NONE)
1907 * gdk_drag_status (context, 0, time);
1910 * private_data->pending_status = context->suggested_action;
1911 * gtk_drag_get_data (widget, context, target, time);
1918 * drag_data_received (GtkWidget *widget,
1919 * GdkDragContext *context,
1922 * GtkSelectionData *selection_data,
1926 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1928 * if (private_data->suggested_action)
1930 * private_data->suggested_action = 0;
1932 * /* We are getting this data due to a request in drag_motion,
1933 * * rather than due to a request in drag_drop, so we are just
1934 * * supposed to call gdk_drag_status (), not actually paste in
1937 * str = gtk_selection_data_get_text (selection_data);
1938 * if (!data_is_acceptable (str))
1939 * gdk_drag_status (context, 0, time);
1941 * gdk_drag_status (context, private_data->suggested_action, time);
1945 * /* accept the drop */
1950 widget_signals[DRAG_MOTION] =
1951 g_signal_new (I_("drag-motion"),
1952 G_TYPE_FROM_CLASS (gobject_class),
1954 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1955 _gtk_boolean_handled_accumulator, NULL,
1956 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1958 GDK_TYPE_DRAG_CONTEXT,
1964 * GtkWidget::drag-drop:
1965 * @widget: the object which received the signal
1966 * @drag_context: the drag context
1967 * @x: the x coordinate of the current cursor position
1968 * @y: the y coordinate of the current cursor position
1969 * @time: the timestamp of the motion event
1970 * @returns: whether the cursor position is in a drop zone
1972 * The ::drag-drop signal is emitted on the drop site when the user drops
1973 * the data onto the widget. The signal handler must determine whether
1974 * the cursor position is in a drop zone or not. If it is not in a drop
1975 * zone, it returns %FALSE and no further processing is necessary.
1976 * Otherwise, the handler returns %TRUE. In this case, the handler must
1977 * ensure that gtk_drag_finish() is called to let the source know that
1978 * the drop is done. The call to gtk_drag_finish() can be done either
1979 * directly or in a #GtkWidget::drag-data-received handler which gets
1980 * triggered by calling gtk_drag_get_data() to receive the data for one
1981 * or more of the supported targets.
1983 widget_signals[DRAG_DROP] =
1984 g_signal_new (I_("drag-drop"),
1985 G_TYPE_FROM_CLASS (gobject_class),
1987 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1988 _gtk_boolean_handled_accumulator, NULL,
1989 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1991 GDK_TYPE_DRAG_CONTEXT,
1997 * GtkWidget::drag-data-get:
1998 * @widget: the object which received the signal
1999 * @drag_context: the drag context
2000 * @data: the #GtkSelectionData to be filled with the dragged data
2001 * @info: the info that has been registered with the target in the
2003 * @time: the timestamp at which the data was requested
2005 * The ::drag-data-get signal is emitted on the drag source when the drop
2006 * site requests the data which is dragged. It is the responsibility of
2007 * the signal handler to fill @data with the data in the format which
2008 * is indicated by @info. See gtk_selection_data_set() and
2009 * gtk_selection_data_set_text().
2011 widget_signals[DRAG_DATA_GET] =
2012 g_signal_new (I_("drag-data-get"),
2013 G_TYPE_FROM_CLASS (gobject_class),
2015 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2017 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2019 GDK_TYPE_DRAG_CONTEXT,
2020 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2025 * GtkWidget::drag-data-received:
2026 * @widget: the object which received the signal
2027 * @drag_context: the drag context
2028 * @x: where the drop happened
2029 * @y: where the drop happened
2030 * @data: the received data
2031 * @info: the info that has been registered with the target in the
2033 * @time: the timestamp at which the data was received
2035 * The ::drag-data-received signal is emitted on the drop site when the
2036 * dragged data has been received. If the data was received in order to
2037 * determine whether the drop will be accepted, the handler is expected
2038 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2039 * If the data was received in response to a #GtkWidget::drag-drop signal
2040 * (and this is the last target to be received), the handler for this
2041 * signal is expected to process the received data and then call
2042 * gtk_drag_finish(), setting the @success parameter depending on whether
2043 * the data was processed successfully.
2045 * The handler may inspect and modify @drag_context->action before calling
2046 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2047 * following example:
2050 * drag_data_received (GtkWidget *widget,
2051 * GdkDragContext *drag_context,
2054 * GtkSelectionData *data,
2058 * if ((data->length >= 0) && (data->format == 8))
2060 * if (drag_context->action == GDK_ACTION_ASK)
2062 * GtkWidget *dialog;
2065 * dialog = gtk_message_dialog_new (NULL,
2066 * GTK_DIALOG_MODAL |
2067 * GTK_DIALOG_DESTROY_WITH_PARENT,
2069 * GTK_BUTTONS_YES_NO,
2070 * "Move the data ?\n");
2071 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2072 * gtk_widget_destroy (dialog);
2074 * if (response == GTK_RESPONSE_YES)
2075 * drag_context->action = GDK_ACTION_MOVE;
2077 * drag_context->action = GDK_ACTION_COPY;
2080 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2084 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2088 widget_signals[DRAG_DATA_RECEIVED] =
2089 g_signal_new (I_("drag-data-received"),
2090 G_TYPE_FROM_CLASS (gobject_class),
2092 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2094 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2096 GDK_TYPE_DRAG_CONTEXT,
2099 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2104 * GtkWidget::visibility-notify-event:
2105 * @widget: the object which received the signal
2106 * @event: the #GdkEventVisibility which triggered this signal
2108 * The ::visibility-notify-event will be emitted when the @widget's window
2109 * is obscured or unobscured.
2111 * To receive this signal the #GdkWindow associated to the widget needs
2112 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2114 * Returns: %TRUE to stop other handlers from being invoked for the event.
2115 * %FALSE to propagate the event further.
2117 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2118 g_signal_new (I_("visibility-notify-event"),
2119 G_TYPE_FROM_CLASS (gobject_class),
2121 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2122 _gtk_boolean_handled_accumulator, NULL,
2123 _gtk_marshal_BOOLEAN__BOXED,
2125 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2128 * GtkWidget::client-event:
2129 * @widget: the object which received the signal
2130 * @event: the #GdkEventClient which triggered this signal
2132 * The ::client-event will be emitted when the @widget's window
2133 * receives a message (via a ClientMessage event) from another
2136 * Returns: %TRUE to stop other handlers from being invoked for
2137 * the event. %FALSE to propagate the event further.
2139 widget_signals[CLIENT_EVENT] =
2140 g_signal_new (I_("client-event"),
2141 G_TYPE_FROM_CLASS (gobject_class),
2143 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2144 _gtk_boolean_handled_accumulator, NULL,
2145 _gtk_marshal_BOOLEAN__BOXED,
2147 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2150 * GtkWidget::no-expose-event:
2151 * @widget: the object which received the signal
2152 * @event: the #GdkEventNoExpose which triggered this signal
2154 * The ::no-expose-event will be emitted when the @widget's window is
2155 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2156 * gdk_window_copy_area()) which was completely unobscured. If the source
2157 * window was partially obscured #GdkEventExpose events will be generated
2160 * Returns: %TRUE to stop other handlers from being invoked for the event.
2161 * %FALSE to propagate the event further.
2163 widget_signals[NO_EXPOSE_EVENT] =
2164 g_signal_new (I_("no-expose-event"),
2165 G_TYPE_FROM_CLASS (gobject_class),
2167 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2174 * GtkWidget::window-state-event:
2175 * @widget: the object which received the signal
2176 * @event: the #GdkEventWindowState which triggered this signal
2178 * The ::window-state-event will be emitted when the state of the
2179 * toplevel window associated to the @widget changes.
2181 * To receive this signal the #GdkWindow associated to the widget
2182 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2183 * this mask automatically for all new windows.
2185 * Returns: %TRUE to stop other handlers from being invoked for the
2186 * event. %FALSE to propagate the event further.
2188 widget_signals[WINDOW_STATE_EVENT] =
2189 g_signal_new (I_("window-state-event"),
2190 G_TYPE_FROM_CLASS (gobject_class),
2192 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2199 * GtkWidget::damage-event:
2200 * @widget: the object which received the signal
2201 * @event: the #GdkEventExpose event
2203 * Emitted when a redirected window belonging to @widget gets drawn into.
2204 * The region/area members of the event shows what area of the redirected
2205 * drawable was drawn into.
2207 * Returns: %TRUE to stop other handlers from being invoked for the event.
2208 * %FALSE to propagate the event further.
2212 widget_signals[DAMAGE_EVENT] =
2213 g_signal_new (I_("damage-event"),
2214 G_TYPE_FROM_CLASS (gobject_class),
2217 _gtk_boolean_handled_accumulator, NULL,
2218 _gtk_marshal_BOOLEAN__BOXED,
2220 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2222 * GtkWidget::grab-broken-event:
2223 * @widget: the object which received the signal
2224 * @event: the #GdkEventGrabBroken event
2226 * Emitted when a pointer or keyboard grab on a window belonging
2227 * to @widget gets broken.
2229 * On X11, this happens when the grab window becomes unviewable
2230 * (i.e. it or one of its ancestors is unmapped), or if the same
2231 * application grabs the pointer or keyboard again.
2233 * Returns: %TRUE to stop other handlers from being invoked for
2234 * the event. %FALSE to propagate the event further.
2238 widget_signals[GRAB_BROKEN] =
2239 g_signal_new (I_("grab-broken-event"),
2240 G_TYPE_FROM_CLASS (gobject_class),
2242 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2243 _gtk_boolean_handled_accumulator, NULL,
2244 _gtk_marshal_BOOLEAN__BOXED,
2246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2248 * GtkWidget::query-tooltip:
2249 * @widget: the object which received the signal
2250 * @x: the x coordinate of the cursor position where the request has
2251 * been emitted, relative to @widget->window
2252 * @y: the y coordinate of the cursor position where the request has
2253 * been emitted, relative to @widget->window
2254 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2255 * @tooltip: a #GtkTooltip
2257 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2258 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2259 * focus in keyboard mode.
2261 * Using the given coordinates, the signal handler should determine
2262 * whether a tooltip should be shown for @widget. If this is the case
2263 * %TRUE should be returned, %FALSE otherwise. Note that if
2264 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2265 * should not be used.
2267 * The signal handler is free to manipulate @tooltip with the therefore
2268 * destined function calls.
2270 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2274 widget_signals[QUERY_TOOLTIP] =
2275 g_signal_new (I_("query-tooltip"),
2276 G_TYPE_FROM_CLASS (gobject_class),
2278 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2279 _gtk_boolean_handled_accumulator, NULL,
2280 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2288 * GtkWidget::popup-menu
2289 * @widget: the object which received the signal
2291 * This signal gets emitted whenever a widget should pop up a context
2292 * menu. This usually happens through the standard key binding mechanism;
2293 * by pressing a certain key while a widget is focused, the user can cause
2294 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2295 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2296 * for an example of how to use this signal.
2298 * Returns: %TRUE if a menu was activated
2300 widget_signals[POPUP_MENU] =
2301 g_signal_new (I_("popup-menu"),
2302 G_TYPE_FROM_CLASS (gobject_class),
2303 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2304 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2305 _gtk_boolean_handled_accumulator, NULL,
2306 _gtk_marshal_BOOLEAN__VOID,
2310 * GtkWidget::show-help:
2311 * @widget: the object which received the signal.
2314 widget_signals[SHOW_HELP] =
2315 g_signal_new (I_("show-help"),
2316 G_TYPE_FROM_CLASS (gobject_class),
2317 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2318 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__ENUM,
2322 GTK_TYPE_WIDGET_HELP_TYPE);
2325 * GtkWidget::accel-closures-changed:
2326 * @widget: the object which received the signal.
2328 widget_signals[ACCEL_CLOSURES_CHANGED] =
2329 g_signal_new (I_("accel-closures-changed"),
2330 G_TYPE_FROM_CLASS (gobject_class),
2334 _gtk_marshal_VOID__VOID,
2338 * GtkWidget::screen-changed:
2339 * @widget: the object on which the signal is emitted
2340 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2341 * widget was not associated with a screen before
2343 * The ::screen-changed signal gets emitted when the
2344 * screen of a widget has changed.
2346 widget_signals[SCREEN_CHANGED] =
2347 g_signal_new (I_("screen-changed"),
2348 G_TYPE_FROM_CLASS (gobject_class),
2350 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2352 _gtk_marshal_VOID__OBJECT,
2357 * GtkWidget::can-activate-accel:
2358 * @widget: the object which received the signal
2359 * @signal_id: the ID of a signal installed on @widget
2361 * Determines whether an accelerator that activates the signal
2362 * identified by @signal_id can currently be activated.
2363 * This signal is present to allow applications and derived
2364 * widgets to override the default #GtkWidget handling
2365 * for determining whether an accelerator can be activated.
2367 * Returns: %TRUE if the signal can be activated.
2369 widget_signals[CAN_ACTIVATE_ACCEL] =
2370 g_signal_new (I_("can-activate-accel"),
2371 G_TYPE_FROM_CLASS (gobject_class),
2373 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2374 _gtk_boolean_handled_accumulator, NULL,
2375 _gtk_marshal_BOOLEAN__UINT,
2376 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2378 binding_set = gtk_binding_set_by_class (klass);
2379 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2381 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2384 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2386 GTK_TYPE_WIDGET_HELP_TYPE,
2387 GTK_WIDGET_HELP_TOOLTIP);
2388 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2390 GTK_TYPE_WIDGET_HELP_TYPE,
2391 GTK_WIDGET_HELP_TOOLTIP);
2392 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2394 GTK_TYPE_WIDGET_HELP_TYPE,
2395 GTK_WIDGET_HELP_WHATS_THIS);
2396 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2398 GTK_TYPE_WIDGET_HELP_TYPE,
2399 GTK_WIDGET_HELP_WHATS_THIS);
2401 gtk_widget_class_install_style_property (klass,
2402 g_param_spec_boolean ("interior-focus",
2403 P_("Interior Focus"),
2404 P_("Whether to draw the focus indicator inside widgets"),
2406 GTK_PARAM_READABLE));
2408 gtk_widget_class_install_style_property (klass,
2409 g_param_spec_int ("focus-line-width",
2410 P_("Focus linewidth"),
2411 P_("Width, in pixels, of the focus indicator line"),
2413 GTK_PARAM_READABLE));
2415 gtk_widget_class_install_style_property (klass,
2416 g_param_spec_string ("focus-line-pattern",
2417 P_("Focus line dash pattern"),
2418 P_("Dash pattern used to draw the focus indicator"),
2420 GTK_PARAM_READABLE));
2421 gtk_widget_class_install_style_property (klass,
2422 g_param_spec_int ("focus-padding",
2423 P_("Focus padding"),
2424 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2426 GTK_PARAM_READABLE));
2427 gtk_widget_class_install_style_property (klass,
2428 g_param_spec_boxed ("cursor-color",
2430 P_("Color with which to draw insertion cursor"),
2432 GTK_PARAM_READABLE));
2433 gtk_widget_class_install_style_property (klass,
2434 g_param_spec_boxed ("secondary-cursor-color",
2435 P_("Secondary cursor color"),
2436 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2438 GTK_PARAM_READABLE));
2439 gtk_widget_class_install_style_property (klass,
2440 g_param_spec_float ("cursor-aspect-ratio",
2441 P_("Cursor line aspect ratio"),
2442 P_("Aspect ratio with which to draw insertion cursor"),
2444 GTK_PARAM_READABLE));
2447 * GtkWidget:draw-border:
2449 * The "draw-border" style property defines the size of areas outside
2450 * the widget's allocation to draw.
2454 gtk_widget_class_install_style_property (klass,
2455 g_param_spec_boxed ("draw-border",
2457 P_("Size of areas outside the widget's allocation to draw"),
2459 GTK_PARAM_READABLE));
2462 * GtkWidget:link-color:
2464 * The "link-color" style property defines the color of unvisited links.
2468 gtk_widget_class_install_style_property (klass,
2469 g_param_spec_boxed ("link-color",
2470 P_("Unvisited Link Color"),
2471 P_("Color of unvisited links"),
2473 GTK_PARAM_READABLE));
2476 * GtkWidget:visited-link-color:
2478 * The "visited-link-color" style property defines the color of visited links.
2482 gtk_widget_class_install_style_property (klass,
2483 g_param_spec_boxed ("visited-link-color",
2484 P_("Visited Link Color"),
2485 P_("Color of visited links"),
2487 GTK_PARAM_READABLE));
2490 * GtkWidget:wide-separators:
2492 * The "wide-separators" style property defines whether separators have
2493 * configurable width and should be drawn using a box instead of a line.
2497 gtk_widget_class_install_style_property (klass,
2498 g_param_spec_boolean ("wide-separators",
2499 P_("Wide Separators"),
2500 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2502 GTK_PARAM_READABLE));
2505 * GtkWidget:separator-width:
2507 * The "separator-width" style property defines the width of separators.
2508 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2512 gtk_widget_class_install_style_property (klass,
2513 g_param_spec_int ("separator-width",
2514 P_("Separator Width"),
2515 P_("The width of separators if wide-separators is TRUE"),
2517 GTK_PARAM_READABLE));
2520 * GtkWidget:separator-height:
2522 * The "separator-height" style property defines the height of separators.
2523 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2527 gtk_widget_class_install_style_property (klass,
2528 g_param_spec_int ("separator-height",
2529 P_("Separator Height"),
2530 P_("The height of separators if \"wide-separators\" is TRUE"),
2532 GTK_PARAM_READABLE));
2535 * GtkWidget:scroll-arrow-hlength:
2537 * The "scroll-arrow-hlength" style property defines the length of
2538 * horizontal scroll arrows.
2542 gtk_widget_class_install_style_property (klass,
2543 g_param_spec_int ("scroll-arrow-hlength",
2544 P_("Horizontal Scroll Arrow Length"),
2545 P_("The length of horizontal scroll arrows"),
2547 GTK_PARAM_READABLE));
2550 * GtkWidget:scroll-arrow-vlength:
2552 * The "scroll-arrow-vlength" style property defines the length of
2553 * vertical scroll arrows.
2557 gtk_widget_class_install_style_property (klass,
2558 g_param_spec_int ("scroll-arrow-vlength",
2559 P_("Vertical Scroll Arrow Length"),
2560 P_("The length of vertical scroll arrows"),
2562 GTK_PARAM_READABLE));
2566 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2570 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2571 for (node = list; node; node = node->next)
2573 GParamSpec *pspec = node->data;
2575 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2576 g_param_spec_unref (pspec);
2582 gtk_widget_set_property (GObject *object,
2584 const GValue *value,
2587 GtkWidget *widget = GTK_WIDGET (object);
2592 gchar *tooltip_markup;
2593 const gchar *tooltip_text;
2594 GtkWindow *tooltip_window;
2597 gtk_widget_set_name (widget, g_value_get_string (value));
2600 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2602 case PROP_WIDTH_REQUEST:
2603 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2605 case PROP_HEIGHT_REQUEST:
2606 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2609 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2611 case PROP_SENSITIVE:
2612 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2614 case PROP_APP_PAINTABLE:
2615 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2617 case PROP_CAN_FOCUS:
2618 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2620 case PROP_HAS_FOCUS:
2621 if (g_value_get_boolean (value))
2622 gtk_widget_grab_focus (widget);
2625 if (g_value_get_boolean (value))
2626 gtk_widget_grab_focus (widget);
2628 case PROP_CAN_DEFAULT:
2629 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2631 case PROP_HAS_DEFAULT:
2632 if (g_value_get_boolean (value))
2633 gtk_widget_grab_default (widget);
2635 case PROP_RECEIVES_DEFAULT:
2636 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2639 gtk_widget_set_style (widget, g_value_get_object (value));
2642 if (!GTK_WIDGET_REALIZED (widget) && gtk_widget_get_has_window (widget))
2643 gtk_widget_set_events (widget, g_value_get_flags (value));
2645 case PROP_EXTENSION_EVENTS:
2646 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2648 case PROP_NO_SHOW_ALL:
2649 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2651 case PROP_HAS_TOOLTIP:
2652 gtk_widget_real_set_has_tooltip (widget,
2653 g_value_get_boolean (value), FALSE);
2655 case PROP_TOOLTIP_MARKUP:
2656 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2657 tooltip_markup = g_value_dup_string (value);
2659 /* Treat an empty string as a NULL string,
2660 * because an empty string would be useless for a tooltip:
2662 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2664 g_free (tooltip_markup);
2665 tooltip_markup = NULL;
2668 g_object_set_qdata_full (object, quark_tooltip_markup,
2669 tooltip_markup, g_free);
2671 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2672 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2673 if (GTK_WIDGET_VISIBLE (widget))
2674 gtk_widget_queue_tooltip_query (widget);
2676 case PROP_TOOLTIP_TEXT:
2677 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2679 tooltip_text = g_value_get_string (value);
2681 /* Treat an empty string as a NULL string,
2682 * because an empty string would be useless for a tooltip:
2684 if (tooltip_text && (strlen (tooltip_text) == 0))
2685 tooltip_text = NULL;
2687 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2689 g_object_set_qdata_full (object, quark_tooltip_markup,
2690 tooltip_markup, g_free);
2692 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2693 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2694 if (GTK_WIDGET_VISIBLE (widget))
2695 gtk_widget_queue_tooltip_query (widget);
2697 case PROP_DOUBLE_BUFFERED:
2698 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2701 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2707 gtk_widget_get_property (GObject *object,
2712 GtkWidget *widget = GTK_WIDGET (object);
2721 g_value_set_string (value, widget->name);
2723 g_value_set_static_string (value, "");
2726 g_value_set_object (value, widget->parent);
2728 case PROP_WIDTH_REQUEST:
2731 gtk_widget_get_size_request (widget, &w, NULL);
2732 g_value_set_int (value, w);
2735 case PROP_HEIGHT_REQUEST:
2738 gtk_widget_get_size_request (widget, NULL, &h);
2739 g_value_set_int (value, h);
2743 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2745 case PROP_SENSITIVE:
2746 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2748 case PROP_APP_PAINTABLE:
2749 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2751 case PROP_CAN_FOCUS:
2752 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2754 case PROP_HAS_FOCUS:
2755 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2758 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2760 case PROP_CAN_DEFAULT:
2761 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2763 case PROP_HAS_DEFAULT:
2764 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2766 case PROP_RECEIVES_DEFAULT:
2767 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2769 case PROP_COMPOSITE_CHILD:
2770 g_value_set_boolean (value, (GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2773 g_value_set_object (value, gtk_widget_get_style (widget));
2776 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2777 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2779 case PROP_EXTENSION_EVENTS:
2780 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2781 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2783 case PROP_NO_SHOW_ALL:
2784 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2786 case PROP_HAS_TOOLTIP:
2787 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2789 case PROP_TOOLTIP_TEXT:
2791 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2794 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2795 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2797 g_value_set_string (value, text);
2801 case PROP_TOOLTIP_MARKUP:
2802 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2805 g_value_set_object (value, gtk_widget_get_window (widget));
2807 case PROP_DOUBLE_BUFFERED:
2808 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2811 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2817 gtk_widget_init (GtkWidget *widget)
2819 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2820 widget->state = GTK_STATE_NORMAL;
2821 widget->saved_state = GTK_STATE_NORMAL;
2822 widget->name = NULL;
2823 widget->requisition.width = 0;
2824 widget->requisition.height = 0;
2825 widget->allocation.x = -1;
2826 widget->allocation.y = -1;
2827 widget->allocation.width = 1;
2828 widget->allocation.height = 1;
2829 widget->window = NULL;
2830 widget->parent = NULL;
2832 GTK_WIDGET_SET_FLAGS (widget,
2834 GTK_PARENT_SENSITIVE |
2835 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2836 GTK_DOUBLE_BUFFERED);
2838 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2839 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2840 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2842 widget->style = gtk_widget_get_default_style ();
2843 g_object_ref (widget->style);
2848 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2850 GParamSpec **pspecs)
2852 GtkWidget *container = widget->parent;
2855 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2856 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2860 * gtk_widget_freeze_child_notify:
2861 * @widget: a #GtkWidget
2863 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2864 * signals are queued until gtk_widget_thaw_child_notify() is called
2867 * This is the analogue of g_object_freeze_notify() for child properties.
2870 gtk_widget_freeze_child_notify (GtkWidget *widget)
2872 g_return_if_fail (GTK_IS_WIDGET (widget));
2874 if (!G_OBJECT (widget)->ref_count)
2877 g_object_ref (widget);
2878 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2879 g_object_unref (widget);
2883 * gtk_widget_child_notify:
2884 * @widget: a #GtkWidget
2885 * @child_property: the name of a child property installed on the
2886 * class of @widget<!-- -->'s parent
2888 * Emits a #GtkWidget::child-notify signal for the
2889 * <link linkend="child-properties">child property</link> @child_property
2892 * This is the analogue of g_object_notify() for child properties.
2895 gtk_widget_child_notify (GtkWidget *widget,
2896 const gchar *child_property)
2900 g_return_if_fail (GTK_IS_WIDGET (widget));
2901 g_return_if_fail (child_property != NULL);
2902 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2905 g_object_ref (widget);
2906 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2908 G_OBJECT_TYPE (widget->parent),
2911 g_warning ("%s: container class `%s' has no child property named `%s'",
2913 G_OBJECT_TYPE_NAME (widget->parent),
2917 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2919 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2920 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2922 g_object_unref (widget);
2926 * gtk_widget_thaw_child_notify:
2927 * @widget: a #GtkWidget
2929 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2930 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2934 gtk_widget_thaw_child_notify (GtkWidget *widget)
2936 GObjectNotifyQueue *nqueue;
2938 g_return_if_fail (GTK_IS_WIDGET (widget));
2940 if (!G_OBJECT (widget)->ref_count)
2943 g_object_ref (widget);
2944 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2945 if (!nqueue || !nqueue->freeze_count)
2946 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2947 G_OBJECT_TYPE_NAME (widget), widget);
2949 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2950 g_object_unref (widget);
2956 * @type: type ID of the widget to create
2957 * @first_property_name: name of first property to set
2958 * @Varargs: value of first property, followed by more properties,
2961 * This is a convenience function for creating a widget and setting
2962 * its properties in one go. For example you might write:
2963 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2964 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2965 * g_object_new(), but returns a widget so you don't have to
2966 * cast the object yourself.
2968 * Return value: a new #GtkWidget of type @widget_type
2971 gtk_widget_new (GType type,
2972 const gchar *first_property_name,
2978 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2980 va_start (var_args, first_property_name);
2981 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2989 * @widget: a #GtkWidget
2990 * @first_property_name: name of first property to set
2991 * @Varargs: value of first property, followed by more properties,
2994 * Precursor of g_object_set().
2996 * Deprecated: 2.0: Use g_object_set() instead.
2999 gtk_widget_set (GtkWidget *widget,
3000 const gchar *first_property_name,
3005 g_return_if_fail (GTK_IS_WIDGET (widget));
3007 va_start (var_args, first_property_name);
3008 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3013 gtk_widget_queue_draw_child (GtkWidget *widget)
3017 parent = widget->parent;
3018 if (parent && gtk_widget_is_drawable (parent))
3019 gtk_widget_queue_draw_area (parent,
3020 widget->allocation.x,
3021 widget->allocation.y,
3022 widget->allocation.width,
3023 widget->allocation.height);
3027 * gtk_widget_unparent:
3028 * @widget: a #GtkWidget
3030 * This function is only for use in widget implementations.
3031 * Should be called by implementations of the remove method
3032 * on #GtkContainer, to dissociate a child from the container.
3035 gtk_widget_unparent (GtkWidget *widget)
3037 GObjectNotifyQueue *nqueue;
3038 GtkWidget *toplevel;
3039 GtkWidget *old_parent;
3041 g_return_if_fail (GTK_IS_WIDGET (widget));
3042 if (widget->parent == NULL)
3045 /* keep this function in sync with gtk_menu_detach()
3048 g_object_freeze_notify (G_OBJECT (widget));
3049 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3051 toplevel = gtk_widget_get_toplevel (widget);
3052 if (gtk_widget_is_toplevel (toplevel))
3053 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3055 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3056 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3058 /* If we are unanchoring the child, we save around the toplevel
3059 * to emit hierarchy changed
3061 if (GTK_WIDGET_ANCHORED (widget->parent))
3062 g_object_ref (toplevel);
3066 gtk_widget_queue_draw_child (widget);
3068 /* Reset the width and height here, to force reallocation if we
3069 * get added back to a new parent. This won't work if our new
3070 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3071 * (would 0x0 be OK here?)
3073 widget->allocation.width = 1;
3074 widget->allocation.height = 1;
3076 if (GTK_WIDGET_REALIZED (widget))
3078 if (GTK_WIDGET_IN_REPARENT (widget))
3079 gtk_widget_unmap (widget);
3081 gtk_widget_unrealize (widget);
3084 /* Removing a widget from a container restores the child visible
3085 * flag to the default state, so it doesn't affect the child
3086 * in the next parent.
3088 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3090 old_parent = widget->parent;
3091 widget->parent = NULL;
3092 gtk_widget_set_parent_window (widget, NULL);
3093 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3096 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3097 g_object_unref (toplevel);
3100 g_object_notify (G_OBJECT (widget), "parent");
3101 g_object_thaw_notify (G_OBJECT (widget));
3102 if (!widget->parent)
3103 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3104 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3105 g_object_unref (widget);
3109 * gtk_widget_destroy:
3110 * @widget: a #GtkWidget
3112 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3113 * you don't have to cast the widget to #GtkObject. When a widget is
3114 * destroyed, it will break any references it holds to other objects.
3115 * If the widget is inside a container, the widget will be removed
3116 * from the container. If the widget is a toplevel (derived from
3117 * #GtkWindow), it will be removed from the list of toplevels, and the
3118 * reference GTK+ holds to it will be removed. Removing a
3119 * widget from its container or the list of toplevels results in the
3120 * widget being finalized, unless you've added additional references
3121 * to the widget with g_object_ref().
3123 * In most cases, only toplevel widgets (windows) require explicit
3124 * destruction, because when you destroy a toplevel its children will
3125 * be destroyed as well.
3128 gtk_widget_destroy (GtkWidget *widget)
3130 g_return_if_fail (GTK_IS_WIDGET (widget));
3132 gtk_object_destroy ((GtkObject*) widget);
3136 * gtk_widget_destroyed:
3137 * @widget: a #GtkWidget
3138 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3140 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3141 * %NULL. It's intended to be used as a callback connected to the
3142 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3143 * as a signal handler, and pass the address of your widget variable
3144 * as user data. Then when the widget is destroyed, the variable will
3145 * be set to %NULL. Useful for example to avoid multiple copies
3146 * of the same dialog.
3149 gtk_widget_destroyed (GtkWidget *widget,
3150 GtkWidget **widget_pointer)
3152 /* Don't make any assumptions about the
3154 * Even check widget_pointer.
3157 *widget_pointer = NULL;
3162 * @widget: a #GtkWidget
3164 * Flags a widget to be displayed. Any widget that isn't shown will
3165 * not appear on the screen. If you want to show all the widgets in a
3166 * container, it's easier to call gtk_widget_show_all() on the
3167 * container, instead of individually showing the widgets.
3169 * Remember that you have to show the containers containing a widget,
3170 * in addition to the widget itself, before it will appear onscreen.
3172 * When a toplevel container is shown, it is immediately realized and
3173 * mapped; other shown widgets are realized and mapped when their
3174 * toplevel container is realized and mapped.
3177 gtk_widget_show (GtkWidget *widget)
3179 g_return_if_fail (GTK_IS_WIDGET (widget));
3181 if (!GTK_WIDGET_VISIBLE (widget))
3183 g_object_ref (widget);
3184 if (!gtk_widget_is_toplevel (widget))
3185 gtk_widget_queue_resize (widget);
3186 g_signal_emit (widget, widget_signals[SHOW], 0);
3187 g_object_notify (G_OBJECT (widget), "visible");
3188 g_object_unref (widget);
3193 gtk_widget_real_show (GtkWidget *widget)
3195 if (!GTK_WIDGET_VISIBLE (widget))
3197 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3199 if (widget->parent &&
3200 GTK_WIDGET_MAPPED (widget->parent) &&
3201 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3202 !GTK_WIDGET_MAPPED (widget))
3203 gtk_widget_map (widget);
3208 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3211 g_signal_handlers_disconnect_by_func (widget,
3212 gtk_widget_show_map_callback,
3217 * gtk_widget_show_now:
3218 * @widget: a #GtkWidget
3220 * Shows a widget. If the widget is an unmapped toplevel widget
3221 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3222 * loop and wait for the window to actually be mapped. Be careful;
3223 * because the main loop is running, anything can happen during
3227 gtk_widget_show_now (GtkWidget *widget)
3231 g_return_if_fail (GTK_IS_WIDGET (widget));
3233 /* make sure we will get event */
3234 if (!GTK_WIDGET_MAPPED (widget) &&
3235 gtk_widget_is_toplevel (widget))
3237 gtk_widget_show (widget);
3239 g_signal_connect (widget, "map-event",
3240 G_CALLBACK (gtk_widget_show_map_callback),
3244 gtk_main_iteration ();
3247 gtk_widget_show (widget);
3252 * @widget: a #GtkWidget
3254 * Reverses the effects of gtk_widget_show(), causing the widget to be
3255 * hidden (invisible to the user).
3258 gtk_widget_hide (GtkWidget *widget)
3260 g_return_if_fail (GTK_IS_WIDGET (widget));
3262 if (GTK_WIDGET_VISIBLE (widget))
3264 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3266 g_object_ref (widget);
3267 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3268 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3270 g_signal_emit (widget, widget_signals[HIDE], 0);
3271 if (!gtk_widget_is_toplevel (widget))
3272 gtk_widget_queue_resize (widget);
3273 g_object_notify (G_OBJECT (widget), "visible");
3274 g_object_unref (widget);
3279 gtk_widget_real_hide (GtkWidget *widget)
3281 if (GTK_WIDGET_VISIBLE (widget))
3283 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3285 if (GTK_WIDGET_MAPPED (widget))
3286 gtk_widget_unmap (widget);
3291 * gtk_widget_hide_on_delete:
3292 * @widget: a #GtkWidget
3294 * Utility function; intended to be connected to the #GtkWidget::delete-event
3295 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3296 * argument, then returns %TRUE. If connected to ::delete-event, the
3297 * result is that clicking the close button for a window (on the
3298 * window frame, top right corner usually) will hide but not destroy
3299 * the window. By default, GTK+ destroys windows when ::delete-event
3302 * Return value: %TRUE
3305 gtk_widget_hide_on_delete (GtkWidget *widget)
3307 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3309 gtk_widget_hide (widget);
3315 * gtk_widget_show_all:
3316 * @widget: a #GtkWidget
3318 * Recursively shows a widget, and any child widgets (if the widget is
3322 gtk_widget_show_all (GtkWidget *widget)
3324 GtkWidgetClass *class;
3326 g_return_if_fail (GTK_IS_WIDGET (widget));
3328 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3331 class = GTK_WIDGET_GET_CLASS (widget);
3333 if (class->show_all)
3334 class->show_all (widget);
3338 * gtk_widget_hide_all:
3339 * @widget: a #GtkWidget
3341 * Recursively hides a widget and any child widgets.
3344 gtk_widget_hide_all (GtkWidget *widget)
3346 GtkWidgetClass *class;
3348 g_return_if_fail (GTK_IS_WIDGET (widget));
3350 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3353 class = GTK_WIDGET_GET_CLASS (widget);
3355 if (class->hide_all)
3356 class->hide_all (widget);
3361 * @widget: a #GtkWidget
3363 * This function is only for use in widget implementations. Causes
3364 * a widget to be mapped if it isn't already.
3367 gtk_widget_map (GtkWidget *widget)
3369 g_return_if_fail (GTK_IS_WIDGET (widget));
3370 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3371 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3373 if (!GTK_WIDGET_MAPPED (widget))
3375 if (!GTK_WIDGET_REALIZED (widget))
3376 gtk_widget_realize (widget);
3378 g_signal_emit (widget, widget_signals[MAP], 0);
3380 if (!gtk_widget_get_has_window (widget))
3381 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3387 * @widget: a #GtkWidget
3389 * This function is only for use in widget implementations. Causes
3390 * a widget to be unmapped if it's currently mapped.
3393 gtk_widget_unmap (GtkWidget *widget)
3395 g_return_if_fail (GTK_IS_WIDGET (widget));
3397 if (GTK_WIDGET_MAPPED (widget))
3399 if (!gtk_widget_get_has_window (widget))
3400 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3401 _gtk_tooltip_hide (widget);
3402 g_signal_emit (widget, widget_signals[UNMAP], 0);
3407 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3408 GdkExtensionMode mode,
3411 GList *free_list = NULL;
3414 if (window_list == NULL)
3416 if (gtk_widget_get_has_window (widget))
3417 window_list = g_list_prepend (NULL, widget->window);
3419 window_list = gdk_window_get_children (widget->window);
3421 free_list = window_list;
3424 for (l = window_list; l != NULL; l = l->next)
3426 GdkWindow *window = l->data;
3429 gdk_window_get_user_data (window, &user_data);
3430 if (user_data == widget)
3434 gdk_input_set_extension_events (window,
3435 gdk_window_get_events (window),
3438 children = gdk_window_get_children (window);
3441 gtk_widget_set_extension_events_internal (widget, mode, children);
3442 g_list_free (children);
3448 g_list_free (free_list);
3452 * gtk_widget_realize:
3453 * @widget: a #GtkWidget
3455 * Creates the GDK (windowing system) resources associated with a
3456 * widget. For example, @widget->window will be created when a widget
3457 * is realized. Normally realization happens implicitly; if you show
3458 * a widget and all its parent containers, then the widget will be
3459 * realized and mapped automatically.
3461 * Realizing a widget requires all
3462 * the widget's parent widgets to be realized; calling
3463 * gtk_widget_realize() realizes the widget's parents in addition to
3464 * @widget itself. If a widget is not yet inside a toplevel window
3465 * when you realize it, bad things will happen.
3467 * This function is primarily used in widget implementations, and
3468 * isn't very useful otherwise. Many times when you think you might
3469 * need it, a better approach is to connect to a signal that will be
3470 * called after the widget is realized automatically, such as
3471 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3472 * GtkWidget::realize signal.
3475 gtk_widget_realize (GtkWidget *widget)
3477 GdkExtensionMode mode;
3478 GtkWidgetShapeInfo *shape_info;
3480 g_return_if_fail (GTK_IS_WIDGET (widget));
3481 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3482 GTK_IS_INVISIBLE (widget));
3484 if (!GTK_WIDGET_REALIZED (widget))
3487 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3488 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3491 if (widget->parent == NULL &&
3492 !gtk_widget_is_toplevel (widget))
3493 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3494 "inside a toplevel window is not going to work very well. "
3495 "Widgets must be inside a toplevel container before realizing them.");
3497 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3498 gtk_widget_realize (widget->parent);
3500 gtk_widget_ensure_style (widget);
3502 g_signal_emit (widget, widget_signals[REALIZE], 0);
3504 gtk_widget_real_set_has_tooltip (widget,
3505 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3508 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3510 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3511 gdk_window_shape_combine_mask (widget->window,
3512 shape_info->shape_mask,
3513 shape_info->offset_x,
3514 shape_info->offset_y);
3517 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3519 gdk_window_input_shape_combine_mask (widget->window,
3520 shape_info->shape_mask,
3521 shape_info->offset_x,
3522 shape_info->offset_y);
3524 mode = gtk_widget_get_extension_events (widget);
3525 if (mode != GDK_EXTENSION_EVENTS_NONE)
3526 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3531 * gtk_widget_unrealize:
3532 * @widget: a #GtkWidget
3534 * This function is only useful in widget implementations.
3535 * Causes a widget to be unrealized (frees all GDK resources
3536 * associated with the widget, such as @widget->window).
3539 gtk_widget_unrealize (GtkWidget *widget)
3541 g_return_if_fail (GTK_IS_WIDGET (widget));
3543 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3544 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3546 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3547 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3549 if (GTK_WIDGET_REALIZED (widget))
3551 g_object_ref (widget);
3552 _gtk_tooltip_hide (widget);
3553 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3554 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3555 g_object_unref (widget);
3559 /*****************************************
3561 *****************************************/
3564 * gtk_widget_queue_draw_area:
3565 * @widget: a #GtkWidget
3566 * @x: x coordinate of upper-left corner of rectangle to redraw
3567 * @y: y coordinate of upper-left corner of rectangle to redraw
3568 * @width: width of region to draw
3569 * @height: height of region to draw
3571 * Invalidates the rectangular area of @widget defined by @x, @y,
3572 * @width and @height by calling gdk_window_invalidate_rect() on the
3573 * widget's window and all its child windows. Once the main loop
3574 * becomes idle (after the current batch of events has been processed,
3575 * roughly), the window will receive expose events for the union of
3576 * all regions that have been invalidated.
3578 * Normally you would only use this function in widget
3579 * implementations. You might also use it, or
3580 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3581 * #GtkDrawingArea or some portion thereof.
3583 * Frequently you can just call gdk_window_invalidate_rect() or
3584 * gdk_window_invalidate_region() instead of this function. Those
3585 * functions will invalidate only a single window, instead of the
3586 * widget and all its children.
3588 * The advantage of adding to the invalidated region compared to
3589 * simply drawing immediately is efficiency; using an invalid region
3590 * ensures that you only have to redraw one time.
3593 gtk_widget_queue_draw_area (GtkWidget *widget,
3599 GdkRectangle invalid_rect;
3602 g_return_if_fail (GTK_IS_WIDGET (widget));
3604 if (!GTK_WIDGET_REALIZED (widget))
3607 /* Just return if the widget or one of its ancestors isn't mapped */
3608 for (w = widget; w != NULL; w = w->parent)
3609 if (!GTK_WIDGET_MAPPED (w))
3612 /* Find the correct widget */
3614 if (gtk_widget_get_has_window (widget))
3618 /* Translate widget relative to window-relative */
3620 gint wx, wy, wwidth, wheight;
3622 gdk_window_get_position (widget->window, &wx, &wy);
3623 x -= wx - widget->allocation.x;
3624 y -= wy - widget->allocation.y;
3626 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3628 if (x + width <= 0 || y + height <= 0 ||
3629 x >= wwidth || y >= wheight)
3640 if (x + width > wwidth)
3642 if (y + height > wheight)
3643 height = wheight - y;
3649 invalid_rect.width = width;
3650 invalid_rect.height = height;
3652 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3656 widget_add_child_draw_rectangle (GtkWidget *widget,
3659 GdkRectangle child_rect;
3661 if (!GTK_WIDGET_MAPPED (widget) ||
3662 widget->window != widget->parent->window)
3665 gtk_widget_get_draw_rectangle (widget, &child_rect);
3666 gdk_rectangle_union (rect, &child_rect, rect);
3670 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3673 if (!gtk_widget_get_has_window (widget))
3675 GtkBorder *draw_border = NULL;
3677 *rect = widget->allocation;
3679 gtk_widget_style_get (widget,
3680 "draw-border", &draw_border,
3684 rect->x -= draw_border->left;
3685 rect->y -= draw_border->top;
3686 rect->width += draw_border->left + draw_border->right;
3687 rect->height += draw_border->top + draw_border->bottom;
3689 gtk_border_free (draw_border);
3692 if (GTK_IS_CONTAINER (widget))
3693 gtk_container_forall (GTK_CONTAINER (widget),
3694 (GtkCallback)widget_add_child_draw_rectangle,
3701 rect->width = widget->allocation.width;
3702 rect->height = widget->allocation.height;
3707 * gtk_widget_queue_draw:
3708 * @widget: a #GtkWidget
3710 * Equivalent to calling gtk_widget_queue_draw_area() for the
3711 * entire area of a widget.
3714 gtk_widget_queue_draw (GtkWidget *widget)
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3720 gtk_widget_get_draw_rectangle (widget, &rect);
3722 gtk_widget_queue_draw_area (widget,
3724 rect.width, rect.height);
3727 /* Invalidates the given area (allocation-relative-coordinates)
3728 * in all of the widget's windows
3731 * gtk_widget_queue_clear_area:
3732 * @widget: a #GtkWidget
3733 * @x: x coordinate of upper-left corner of rectangle to redraw
3734 * @y: y coordinate of upper-left corner of rectangle to redraw
3735 * @width: width of region to draw
3736 * @height: height of region to draw
3738 * This function is no longer different from
3739 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3740 * gtk_widget_queue_draw_area(). Originally
3741 * gtk_widget_queue_clear_area() would force a redraw of the
3742 * background for %GTK_NO_WINDOW widgets, and
3743 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3744 * the background will be redrawn.
3746 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3749 gtk_widget_queue_clear_area (GtkWidget *widget,
3755 g_return_if_fail (GTK_IS_WIDGET (widget));
3757 gtk_widget_queue_draw_area (widget, x, y, width, height);
3761 * gtk_widget_queue_clear:
3762 * @widget: a #GtkWidget
3764 * This function does the same as gtk_widget_queue_draw().
3766 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3769 gtk_widget_queue_clear (GtkWidget *widget)
3771 g_return_if_fail (GTK_IS_WIDGET (widget));
3773 gtk_widget_queue_draw (widget);
3777 * gtk_widget_queue_resize:
3778 * @widget: a #GtkWidget
3780 * This function is only for use in widget implementations.
3781 * Flags a widget to have its size renegotiated; should
3782 * be called when a widget for some reason has a new size request.
3783 * For example, when you change the text in a #GtkLabel, #GtkLabel
3784 * queues a resize to ensure there's enough space for the new text.
3787 gtk_widget_queue_resize (GtkWidget *widget)
3789 g_return_if_fail (GTK_IS_WIDGET (widget));
3791 if (GTK_WIDGET_REALIZED (widget))
3792 gtk_widget_queue_shallow_draw (widget);
3794 _gtk_size_group_queue_resize (widget);
3798 * gtk_widget_queue_resize_no_redraw:
3799 * @widget: a #GtkWidget
3801 * This function works like gtk_widget_queue_resize(),
3802 * except that the widget is not invalidated.
3807 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3809 g_return_if_fail (GTK_IS_WIDGET (widget));
3811 _gtk_size_group_queue_resize (widget);
3816 * @widget: a #GtkWidget
3817 * @area: area to draw
3819 * In GTK+ 1.2, this function would immediately render the
3820 * region @area of a widget, by invoking the virtual draw method of a
3821 * widget. In GTK+ 2.0, the draw method is gone, and instead
3822 * gtk_widget_draw() simply invalidates the specified region of the
3823 * widget, then updates the invalid region of the widget immediately.
3824 * Usually you don't want to update the region immediately for
3825 * performance reasons, so in general gtk_widget_queue_draw_area() is
3826 * a better choice if you want to draw a region of a widget.
3829 gtk_widget_draw (GtkWidget *widget,
3830 const GdkRectangle *area)
3832 g_return_if_fail (GTK_IS_WIDGET (widget));
3834 if (gtk_widget_is_drawable (widget))
3837 gtk_widget_queue_draw_area (widget,
3839 area->width, area->height);
3841 gtk_widget_queue_draw (widget);
3843 gdk_window_process_updates (widget->window, TRUE);
3848 * gtk_widget_size_request:
3849 * @widget: a #GtkWidget
3850 * @requisition: a #GtkRequisition to be filled in
3852 * This function is typically used when implementing a #GtkContainer
3853 * subclass. Obtains the preferred size of a widget. The container
3854 * uses this information to arrange its child widgets and decide what
3855 * size allocations to give them with gtk_widget_size_allocate().
3857 * You can also call this function from an application, with some
3858 * caveats. Most notably, getting a size request requires the widget
3859 * to be associated with a screen, because font information may be
3860 * needed. Multihead-aware applications should keep this in mind.
3862 * Also remember that the size request is not necessarily the size
3863 * a widget will actually be allocated.
3865 * See also gtk_widget_get_child_requisition().
3868 gtk_widget_size_request (GtkWidget *widget,
3869 GtkRequisition *requisition)
3871 g_return_if_fail (GTK_IS_WIDGET (widget));
3873 #ifdef G_ENABLE_DEBUG
3874 if (requisition == &widget->requisition)
3875 g_warning ("gtk_widget_size_request() called on child widget with request equal\n to widget->requisition. gtk_widget_set_usize() may not work properly.");
3876 #endif /* G_ENABLE_DEBUG */
3878 _gtk_size_group_compute_requisition (widget, requisition);
3882 * gtk_widget_get_child_requisition:
3883 * @widget: a #GtkWidget
3884 * @requisition: a #GtkRequisition to be filled in
3886 * This function is only for use in widget implementations. Obtains
3887 * @widget->requisition, unless someone has forced a particular
3888 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3889 * in which case it returns that geometry instead of the widget's
3892 * This function differs from gtk_widget_size_request() in that
3893 * it retrieves the last size request value from @widget->requisition,
3894 * while gtk_widget_size_request() actually calls the "size_request" method
3895 * on @widget to compute the size request and fill in @widget->requisition,
3896 * and only then returns @widget->requisition.
3898 * Because this function does not call the "size_request" method, it
3899 * can only be used when you know that @widget->requisition is
3900 * up-to-date, that is, gtk_widget_size_request() has been called
3901 * since the last time a resize was queued. In general, only container
3902 * implementations have this information; applications should use
3903 * gtk_widget_size_request().
3906 gtk_widget_get_child_requisition (GtkWidget *widget,
3907 GtkRequisition *requisition)
3909 _gtk_size_group_get_child_requisition (widget, requisition);
3913 invalidate_predicate (GdkWindow *window,
3918 gdk_window_get_user_data (window, &user_data);
3920 return (user_data == data);
3923 /* Invalidate @region in widget->window and all children
3924 * of widget->window owned by widget. @region is in the
3925 * same coordinates as widget->allocation and will be
3926 * modified by this call.
3929 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3932 if (!GTK_WIDGET_REALIZED (widget))
3935 if (gtk_widget_get_has_window (widget) && widget->parent)
3939 gdk_window_get_position (widget->window, &x, &y);
3940 gdk_region_offset (region, -x, -y);
3943 gdk_window_invalidate_maybe_recurse (widget->window, region,
3944 invalidate_predicate, widget);
3948 * gtk_widget_queue_shallow_draw:
3949 * @widget: a #GtkWidget
3951 * Like gtk_widget_queue_draw(), but only windows owned
3952 * by @widget are invalidated.
3955 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3960 if (!GTK_WIDGET_REALIZED (widget))
3963 gtk_widget_get_draw_rectangle (widget, &rect);
3965 /* get_draw_rectangle() gives us window coordinates, we
3966 * need to convert to the coordinates that widget->allocation
3969 if (gtk_widget_get_has_window (widget) && widget->parent)
3973 gdk_window_get_position (widget->window, &wx, &wy);
3979 region = gdk_region_rectangle (&rect);
3980 gtk_widget_invalidate_widget_windows (widget, region);
3981 gdk_region_destroy (region);
3985 * gtk_widget_size_allocate:
3986 * @widget: a #GtkWidget
3987 * @allocation: position and size to be allocated to @widget
3989 * This function is only used by #GtkContainer subclasses, to assign a size
3990 * and position to their child widgets.
3993 gtk_widget_size_allocate (GtkWidget *widget,
3994 GtkAllocation *allocation)
3996 GtkWidgetAuxInfo *aux_info;
3997 GdkRectangle real_allocation;
3998 GdkRectangle old_allocation;
3999 gboolean alloc_needed;
4000 gboolean size_changed;
4001 gboolean position_changed;
4003 g_return_if_fail (GTK_IS_WIDGET (widget));
4005 #ifdef G_ENABLE_DEBUG
4006 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4017 parent = gtk_widget_get_parent (parent);
4020 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4021 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4022 2 * depth, " ", name,
4023 allocation->width, allocation->height);
4025 #endif /* G_ENABLE_DEBUG */
4027 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4028 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4029 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4031 old_allocation = widget->allocation;
4032 real_allocation = *allocation;
4033 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4037 if (aux_info->x_set)
4038 real_allocation.x = aux_info->x;
4039 if (aux_info->y_set)
4040 real_allocation.y = aux_info->y;
4043 if (real_allocation.width < 0 || real_allocation.height < 0)
4045 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4046 real_allocation.width,
4047 real_allocation.height);
4050 real_allocation.width = MAX (real_allocation.width, 1);
4051 real_allocation.height = MAX (real_allocation.height, 1);
4053 size_changed = (old_allocation.width != real_allocation.width ||
4054 old_allocation.height != real_allocation.height);
4055 position_changed = (old_allocation.x != real_allocation.x ||
4056 old_allocation.y != real_allocation.y);
4058 if (!alloc_needed && !size_changed && !position_changed)
4061 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4063 if (GTK_WIDGET_MAPPED (widget))
4065 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4067 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4069 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4070 gdk_region_union_with_rect (invalidate, &old_allocation);
4072 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4073 gdk_region_destroy (invalidate);
4078 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4080 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4082 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4083 gdk_region_union_with_rect (invalidate, &old_allocation);
4085 gtk_widget_invalidate_widget_windows (widget, invalidate);
4086 gdk_region_destroy (invalidate);
4091 if ((size_changed || position_changed) && widget->parent &&
4092 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4094 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4095 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4096 gdk_region_destroy (invalidate);
4101 * gtk_widget_common_ancestor:
4102 * @widget_a: a #GtkWidget
4103 * @widget_b: a #GtkWidget
4105 * Find the common ancestor of @widget_a and @widget_b that
4106 * is closest to the two widgets.
4108 * Return value: the closest common ancestor of @widget_a and
4109 * @widget_b or %NULL if @widget_a and @widget_b do not
4110 * share a common ancestor.
4113 gtk_widget_common_ancestor (GtkWidget *widget_a,
4114 GtkWidget *widget_b)
4116 GtkWidget *parent_a;
4117 GtkWidget *parent_b;
4121 parent_a = widget_a;
4122 while (parent_a->parent)
4124 parent_a = parent_a->parent;
4128 parent_b = widget_b;
4129 while (parent_b->parent)
4131 parent_b = parent_b->parent;
4135 if (parent_a != parent_b)
4138 while (depth_a > depth_b)
4140 widget_a = widget_a->parent;
4144 while (depth_b > depth_a)
4146 widget_b = widget_b->parent;
4150 while (widget_a != widget_b)
4152 widget_a = widget_a->parent;
4153 widget_b = widget_b->parent;
4160 * gtk_widget_translate_coordinates:
4161 * @src_widget: a #GtkWidget
4162 * @dest_widget: a #GtkWidget
4163 * @src_x: X position relative to @src_widget
4164 * @src_y: Y position relative to @src_widget
4165 * @dest_x: (out): location to store X position relative to @dest_widget
4166 * @dest_y: (out): location to store Y position relative to @dest_widget
4168 * Translate coordinates relative to @src_widget's allocation to coordinates
4169 * relative to @dest_widget's allocations. In order to perform this
4170 * operation, both widgets must be realized, and must share a common
4173 * Return value: %FALSE if either widget was not realized, or there
4174 * was no common ancestor. In this case, nothing is stored in
4175 * *@dest_x and *@dest_y. Otherwise %TRUE.
4178 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4179 GtkWidget *dest_widget,
4185 GtkWidget *ancestor;
4188 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4189 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4191 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4192 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4195 /* Translate from allocation relative to window relative */
4196 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4199 gdk_window_get_position (src_widget->window, &wx, &wy);
4201 src_x -= wx - src_widget->allocation.x;
4202 src_y -= wy - src_widget->allocation.y;
4206 src_x += src_widget->allocation.x;
4207 src_y += src_widget->allocation.y;
4210 /* Translate to the common ancestor */
4211 window = src_widget->window;
4212 while (window != ancestor->window)
4216 gdk_window_get_position (window, &dx, &dy);
4221 window = gdk_window_get_parent (window);
4223 if (!window) /* Handle GtkHandleBox */
4228 window = dest_widget->window;
4229 while (window != ancestor->window)
4233 gdk_window_get_position (window, &dx, &dy);
4238 window = gdk_window_get_parent (window);
4240 if (!window) /* Handle GtkHandleBox */
4244 /* Translate from window relative to allocation relative */
4245 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4248 gdk_window_get_position (dest_widget->window, &wx, &wy);
4250 src_x += wx - dest_widget->allocation.x;
4251 src_y += wy - dest_widget->allocation.y;
4255 src_x -= dest_widget->allocation.x;
4256 src_y -= dest_widget->allocation.y;
4268 gtk_widget_real_size_allocate (GtkWidget *widget,
4269 GtkAllocation *allocation)
4271 widget->allocation = *allocation;
4273 if (GTK_WIDGET_REALIZED (widget) &&
4274 gtk_widget_get_has_window (widget))
4276 gdk_window_move_resize (widget->window,
4277 allocation->x, allocation->y,
4278 allocation->width, allocation->height);
4283 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4286 /* widgets must be onscreen for accels to take effect */
4287 return gtk_widget_is_sensitive (widget) &&
4288 gtk_widget_is_drawable (widget) &&
4289 gdk_window_is_viewable (widget->window);
4293 * gtk_widget_can_activate_accel:
4294 * @widget: a #GtkWidget
4295 * @signal_id: the ID of a signal installed on @widget
4297 * Determines whether an accelerator that activates the signal
4298 * identified by @signal_id can currently be activated.
4299 * This is done by emitting the #GtkWidget::can-activate-accel
4300 * signal on @widget; if the signal isn't overridden by a
4301 * handler or in a derived widget, then the default check is
4302 * that the widget must be sensitive, and the widget and all
4303 * its ancestors mapped.
4305 * Return value: %TRUE if the accelerator can be activated.
4310 gtk_widget_can_activate_accel (GtkWidget *widget,
4313 gboolean can_activate = FALSE;
4314 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4315 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4316 return can_activate;
4325 closure_accel_activate (GClosure *closure,
4326 GValue *return_value,
4327 guint n_param_values,
4328 const GValue *param_values,
4329 gpointer invocation_hint,
4330 gpointer marshal_data)
4332 AccelClosure *aclosure = (AccelClosure*) closure;
4333 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4336 g_signal_emit (closure->data, aclosure->signal_id, 0);
4338 /* whether accelerator was handled */
4339 g_value_set_boolean (return_value, can_activate);
4343 closures_destroy (gpointer data)
4345 GSList *slist, *closures = data;
4347 for (slist = closures; slist; slist = slist->next)
4349 g_closure_invalidate (slist->data);
4350 g_closure_unref (slist->data);
4352 g_slist_free (closures);
4356 widget_new_accel_closure (GtkWidget *widget,
4359 AccelClosure *aclosure;
4360 GClosure *closure = NULL;
4361 GSList *slist, *closures;
4363 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4364 for (slist = closures; slist; slist = slist->next)
4365 if (!gtk_accel_group_from_accel_closure (slist->data))
4367 /* reuse this closure */
4368 closure = slist->data;
4373 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4374 closures = g_slist_prepend (closures, g_closure_ref (closure));
4375 g_closure_sink (closure);
4376 g_closure_set_marshal (closure, closure_accel_activate);
4378 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4380 aclosure = (AccelClosure*) closure;
4381 g_assert (closure->data == widget);
4382 g_assert (closure->marshal == closure_accel_activate);
4383 aclosure->signal_id = signal_id;
4389 * gtk_widget_add_accelerator
4390 * @widget: widget to install an accelerator on
4391 * @accel_signal: widget signal to emit on accelerator activation
4392 * @accel_group: accel group for this widget, added to its toplevel
4393 * @accel_key: GDK keyval of the accelerator
4394 * @accel_mods: modifier key combination of the accelerator
4395 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4397 * Installs an accelerator for this @widget in @accel_group that causes
4398 * @accel_signal to be emitted if the accelerator is activated.
4399 * The @accel_group needs to be added to the widget's toplevel via
4400 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4401 * Accelerators added through this function are not user changeable during
4402 * runtime. If you want to support accelerators that can be changed by the
4403 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4404 * gtk_menu_item_set_accel_path() instead.
4407 gtk_widget_add_accelerator (GtkWidget *widget,
4408 const gchar *accel_signal,
4409 GtkAccelGroup *accel_group,
4411 GdkModifierType accel_mods,
4412 GtkAccelFlags accel_flags)
4417 g_return_if_fail (GTK_IS_WIDGET (widget));
4418 g_return_if_fail (accel_signal != NULL);
4419 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4421 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4422 if (!query.signal_id ||
4423 !(query.signal_flags & G_SIGNAL_ACTION) ||
4424 query.return_type != G_TYPE_NONE ||
4427 /* hmm, should be elaborate enough */
4428 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4429 G_OBJECT_TYPE_NAME (widget), accel_signal);
4433 closure = widget_new_accel_closure (widget, query.signal_id);
4435 g_object_ref (widget);
4437 /* install the accelerator. since we don't map this onto an accel_path,
4438 * the accelerator will automatically be locked.
4440 gtk_accel_group_connect (accel_group,
4443 accel_flags | GTK_ACCEL_LOCKED,
4446 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4448 g_object_unref (widget);
4452 * gtk_widget_remove_accelerator:
4453 * @widget: widget to install an accelerator on
4454 * @accel_group: accel group for this widget
4455 * @accel_key: GDK keyval of the accelerator
4456 * @accel_mods: modifier key combination of the accelerator
4457 * @returns: whether an accelerator was installed and could be removed
4459 * Removes an accelerator from @widget, previously installed with
4460 * gtk_widget_add_accelerator().
4463 gtk_widget_remove_accelerator (GtkWidget *widget,
4464 GtkAccelGroup *accel_group,
4466 GdkModifierType accel_mods)
4468 GtkAccelGroupEntry *ag_entry;
4469 GList *slist, *clist;
4472 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4473 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4475 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4476 clist = gtk_widget_list_accel_closures (widget);
4477 for (slist = clist; slist; slist = slist->next)
4481 for (i = 0; i < n; i++)
4482 if (slist->data == (gpointer) ag_entry[i].closure)
4484 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4486 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4488 g_list_free (clist);
4493 g_list_free (clist);
4495 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4496 accel_key, accel_mods, accel_group,
4497 G_OBJECT_TYPE_NAME (widget), widget);
4503 * gtk_widget_list_accel_closures
4504 * @widget: widget to list accelerator closures for
4505 * @returns: a newly allocated #GList of closures
4507 * Lists the closures used by @widget for accelerator group connections
4508 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4509 * The closures can be used to monitor accelerator changes on @widget,
4510 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4511 * #GtkAccelGroup of a closure which can be found out with
4512 * gtk_accel_group_from_accel_closure().
4515 gtk_widget_list_accel_closures (GtkWidget *widget)
4518 GList *clist = NULL;
4520 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4522 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4523 if (gtk_accel_group_from_accel_closure (slist->data))
4524 clist = g_list_prepend (clist, slist->data);
4530 GtkAccelGroup *accel_group;
4535 destroy_accel_path (gpointer data)
4537 AccelPath *apath = data;
4539 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4541 /* closures_destroy takes care of unrefing the closure */
4542 g_object_unref (apath->accel_group);
4544 g_slice_free (AccelPath, apath);
4549 * gtk_widget_set_accel_path:
4550 * @widget: a #GtkWidget
4551 * @accel_path: (allow-none): path used to look up the accelerator
4552 * @accel_group: (allow-none): a #GtkAccelGroup.
4554 * Given an accelerator group, @accel_group, and an accelerator path,
4555 * @accel_path, sets up an accelerator in @accel_group so whenever the
4556 * key binding that is defined for @accel_path is pressed, @widget
4557 * will be activated. This removes any accelerators (for any
4558 * accelerator group) installed by previous calls to
4559 * gtk_widget_set_accel_path(). Associating accelerators with
4560 * paths allows them to be modified by the user and the modifications
4561 * to be saved for future use. (See gtk_accel_map_save().)
4563 * This function is a low level function that would most likely
4564 * be used by a menu creation system like #GtkUIManager. If you
4565 * use #GtkUIManager, setting up accelerator paths will be done
4568 * Even when you you aren't using #GtkUIManager, if you only want to
4569 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4570 * provides a somewhat more convenient interface.
4572 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4573 * pass a static string, you can save some memory by interning it first with
4574 * g_intern_static_string().
4577 gtk_widget_set_accel_path (GtkWidget *widget,
4578 const gchar *accel_path,
4579 GtkAccelGroup *accel_group)
4583 g_return_if_fail (GTK_IS_WIDGET (widget));
4584 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4588 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4589 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4591 gtk_accel_map_add_entry (accel_path, 0, 0);
4592 apath = g_slice_new (AccelPath);
4593 apath->accel_group = g_object_ref (accel_group);
4594 apath->path_quark = g_quark_from_string (accel_path);
4595 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4600 /* also removes possible old settings */
4601 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4604 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4606 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4610 _gtk_widget_get_accel_path (GtkWidget *widget,
4615 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4617 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4619 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4620 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4624 * gtk_widget_mnemonic_activate:
4625 * @widget: a #GtkWidget
4626 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4628 * Emits the #GtkWidget::mnemonic-activate signal.
4630 * The default handler for this signal activates the @widget if
4631 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4634 * Returns: %TRUE if the signal has been handled
4637 gtk_widget_mnemonic_activate (GtkWidget *widget,
4638 gboolean group_cycling)
4642 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4644 group_cycling = group_cycling != FALSE;
4645 if (!gtk_widget_is_sensitive (widget))
4648 g_signal_emit (widget,
4649 widget_signals[MNEMONIC_ACTIVATE],
4657 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4658 gboolean group_cycling)
4660 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4661 gtk_widget_activate (widget);
4662 else if (gtk_widget_get_can_focus (widget))
4663 gtk_widget_grab_focus (widget);
4666 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4667 G_OBJECT_TYPE_NAME (widget));
4668 gtk_widget_error_bell (widget);
4674 gtk_widget_real_key_press_event (GtkWidget *widget,
4677 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4681 gtk_widget_real_key_release_event (GtkWidget *widget,
4684 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4688 gtk_widget_real_focus_in_event (GtkWidget *widget,
4689 GdkEventFocus *event)
4691 gtk_widget_queue_shallow_draw (widget);
4697 gtk_widget_real_focus_out_event (GtkWidget *widget,
4698 GdkEventFocus *event)
4700 gtk_widget_queue_shallow_draw (widget);
4705 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4706 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4710 * @widget: a #GtkWidget
4711 * @event: a #GdkEvent
4713 * Rarely-used function. This function is used to emit
4714 * the event signals on a widget (those signals should never
4715 * be emitted without using this function to do so).
4716 * If you want to synthesize an event though, don't use this function;
4717 * instead, use gtk_main_do_event() so the event will behave as if
4718 * it were in the event queue. Don't synthesize expose events; instead,
4719 * use gdk_window_invalidate_rect() to invalidate a region of the
4722 * Return value: return from the event signal emission (%TRUE if
4723 * the event was handled)
4726 gtk_widget_event (GtkWidget *widget,
4729 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4730 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4732 if (event->type == GDK_EXPOSE)
4734 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4735 "the same effect, call gdk_window_invalidate_rect/region(), "
4736 "followed by gdk_window_process_updates().");
4740 return gtk_widget_event_internal (widget, event);
4745 * gtk_widget_send_expose:
4746 * @widget: a #GtkWidget
4747 * @event: a expose #GdkEvent
4749 * Very rarely-used function. This function is used to emit
4750 * an expose event signals on a widget. This function is not
4751 * normally used directly. The only time it is used is when
4752 * propagating an expose event to a child %NO_WINDOW widget, and
4753 * that is normally done using gtk_container_propagate_expose().
4755 * If you want to force an area of a window to be redrawn,
4756 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4757 * To cause the redraw to be done immediately, follow that call
4758 * with a call to gdk_window_process_updates().
4760 * Return value: return from the event signal emission (%TRUE if
4761 * the event was handled)
4764 gtk_widget_send_expose (GtkWidget *widget,
4767 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4768 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4769 g_return_val_if_fail (event != NULL, TRUE);
4770 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4772 return gtk_widget_event_internal (widget, event);
4776 event_window_is_still_viewable (GdkEvent *event)
4778 /* Some programs, such as gnome-theme-manager, fake widgets
4779 * into exposing onto a pixmap by sending expose events with
4780 * event->window pointing to a pixmap
4782 if (GDK_IS_PIXMAP (event->any.window))
4783 return event->type == GDK_EXPOSE;
4785 /* Check that we think the event's window is viewable before
4786 * delivering the event, to prevent suprises. We do this here
4787 * at the last moment, since the event may have been queued
4788 * up behind other events, held over a recursive main loop, etc.
4790 switch (event->type)
4793 case GDK_MOTION_NOTIFY:
4794 case GDK_BUTTON_PRESS:
4795 case GDK_2BUTTON_PRESS:
4796 case GDK_3BUTTON_PRESS:
4798 case GDK_ENTER_NOTIFY:
4799 case GDK_PROXIMITY_IN:
4801 return event->any.window && gdk_window_is_viewable (event->any.window);
4804 /* The following events are the second half of paired events;
4805 * we always deliver them to deal with widgets that clean up
4806 * on the second half.
4808 case GDK_BUTTON_RELEASE:
4809 case GDK_KEY_RELEASE:
4810 case GDK_LEAVE_NOTIFY:
4811 case GDK_PROXIMITY_OUT:
4815 /* Remaining events would make sense on an not-viewable window,
4816 * or don't have an associated window.
4823 gtk_widget_event_internal (GtkWidget *widget,
4826 gboolean return_val = FALSE;
4828 /* We check only once for is-still-visible; if someone
4829 * hides the window in on of the signals on the widget,
4830 * they are responsible for returning TRUE to terminate
4833 if (!event_window_is_still_viewable (event))
4836 g_object_ref (widget);
4838 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4839 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4844 switch (event->type)
4849 case GDK_BUTTON_PRESS:
4850 case GDK_2BUTTON_PRESS:
4851 case GDK_3BUTTON_PRESS:
4852 signal_num = BUTTON_PRESS_EVENT;
4855 signal_num = SCROLL_EVENT;
4857 case GDK_BUTTON_RELEASE:
4858 signal_num = BUTTON_RELEASE_EVENT;
4860 case GDK_MOTION_NOTIFY:
4861 signal_num = MOTION_NOTIFY_EVENT;
4864 signal_num = DELETE_EVENT;
4867 signal_num = DESTROY_EVENT;
4868 _gtk_tooltip_hide (widget);
4871 signal_num = KEY_PRESS_EVENT;
4873 case GDK_KEY_RELEASE:
4874 signal_num = KEY_RELEASE_EVENT;
4876 case GDK_ENTER_NOTIFY:
4877 signal_num = ENTER_NOTIFY_EVENT;
4879 case GDK_LEAVE_NOTIFY:
4880 signal_num = LEAVE_NOTIFY_EVENT;
4882 case GDK_FOCUS_CHANGE:
4883 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4884 if (event->focus_change.in)
4885 _gtk_tooltip_focus_in (widget);
4887 _gtk_tooltip_focus_out (widget);
4890 signal_num = CONFIGURE_EVENT;
4893 signal_num = MAP_EVENT;
4896 signal_num = UNMAP_EVENT;
4898 case GDK_WINDOW_STATE:
4899 signal_num = WINDOW_STATE_EVENT;
4901 case GDK_PROPERTY_NOTIFY:
4902 signal_num = PROPERTY_NOTIFY_EVENT;
4904 case GDK_SELECTION_CLEAR:
4905 signal_num = SELECTION_CLEAR_EVENT;
4907 case GDK_SELECTION_REQUEST:
4908 signal_num = SELECTION_REQUEST_EVENT;
4910 case GDK_SELECTION_NOTIFY:
4911 signal_num = SELECTION_NOTIFY_EVENT;
4913 case GDK_PROXIMITY_IN:
4914 signal_num = PROXIMITY_IN_EVENT;
4916 case GDK_PROXIMITY_OUT:
4917 signal_num = PROXIMITY_OUT_EVENT;
4920 signal_num = NO_EXPOSE_EVENT;
4922 case GDK_CLIENT_EVENT:
4923 signal_num = CLIENT_EVENT;
4926 signal_num = EXPOSE_EVENT;
4928 case GDK_VISIBILITY_NOTIFY:
4929 signal_num = VISIBILITY_NOTIFY_EVENT;
4931 case GDK_GRAB_BROKEN:
4932 signal_num = GRAB_BROKEN;
4935 signal_num = DAMAGE_EVENT;
4938 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4942 if (signal_num != -1)
4943 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4945 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4946 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4950 g_object_unref (widget);
4956 * gtk_widget_activate:
4957 * @widget: a #GtkWidget that's activatable
4959 * For widgets that can be "activated" (buttons, menu items, etc.)
4960 * this function activates them. Activation is what happens when you
4961 * press Enter on a widget during key navigation. If @widget isn't
4962 * activatable, the function returns %FALSE.
4964 * Return value: %TRUE if the widget was activatable
4967 gtk_widget_activate (GtkWidget *widget)
4969 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4971 if (WIDGET_CLASS (widget)->activate_signal)
4973 /* FIXME: we should eventually check the signals signature here */
4974 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4983 * gtk_widget_set_scroll_adjustments:
4984 * @widget: a #GtkWidget
4985 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
4986 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
4988 * For widgets that support scrolling, sets the scroll adjustments and
4989 * returns %TRUE. For widgets that don't support scrolling, does
4990 * nothing and returns %FALSE. Widgets that don't support scrolling
4991 * can be scrolled by placing them in a #GtkViewport, which does
4992 * support scrolling.
4994 * Return value: %TRUE if the widget supports scrolling
4997 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4998 GtkAdjustment *hadjustment,
4999 GtkAdjustment *vadjustment)
5004 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5007 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5009 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5011 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5015 g_signal_query (signal_id, &query);
5016 if (!query.signal_id ||
5017 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5018 query.return_type != G_TYPE_NONE ||
5019 query.n_params != 2 ||
5020 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5021 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5023 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5024 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5028 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5033 gtk_widget_reparent_subwindows (GtkWidget *widget,
5034 GdkWindow *new_window)
5036 if (!gtk_widget_get_has_window (widget))
5038 GList *children = gdk_window_get_children (widget->window);
5041 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5043 GdkWindow *window = tmp_list->data;
5046 gdk_window_get_user_data (window, &child);
5047 while (child && child != widget)
5048 child = ((GtkWidget*) child)->parent;
5051 gdk_window_reparent (window, new_window, 0, 0);
5054 g_list_free (children);
5059 GList *tmp_list, *children;
5061 parent = gdk_window_get_parent (widget->window);
5064 gdk_window_reparent (widget->window, new_window, 0, 0);
5067 children = gdk_window_get_children (parent);
5069 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5071 GdkWindow *window = tmp_list->data;
5074 gdk_window_get_user_data (window, &child);
5076 if (child == widget)
5077 gdk_window_reparent (window, new_window, 0, 0);
5080 g_list_free (children);
5086 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5087 gpointer client_data)
5089 g_assert (client_data != NULL);
5091 if (!gtk_widget_get_has_window (widget))
5094 g_object_unref (widget->window);
5095 widget->window = (GdkWindow*) client_data;
5097 g_object_ref (widget->window);
5099 if (GTK_IS_CONTAINER (widget))
5100 gtk_container_forall (GTK_CONTAINER (widget),
5101 gtk_widget_reparent_fixup_child,
5107 * gtk_widget_reparent:
5108 * @widget: a #GtkWidget
5109 * @new_parent: a #GtkContainer to move the widget into
5111 * Moves a widget from one #GtkContainer to another, handling reference
5112 * count issues to avoid destroying the widget.
5115 gtk_widget_reparent (GtkWidget *widget,
5116 GtkWidget *new_parent)
5118 g_return_if_fail (GTK_IS_WIDGET (widget));
5119 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5120 g_return_if_fail (widget->parent != NULL);
5122 if (widget->parent != new_parent)
5124 /* First try to see if we can get away without unrealizing
5125 * the widget as we reparent it. if so we set a flag so
5126 * that gtk_widget_unparent doesn't unrealize widget
5128 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
5129 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5131 g_object_ref (widget);
5132 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5133 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5134 g_object_unref (widget);
5136 if (GTK_WIDGET_IN_REPARENT (widget))
5138 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5140 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5141 gtk_widget_reparent_fixup_child (widget,
5142 gtk_widget_get_parent_window (widget));
5145 g_object_notify (G_OBJECT (widget), "parent");
5150 * gtk_widget_intersect:
5151 * @widget: a #GtkWidget
5152 * @area: a rectangle
5153 * @intersection: rectangle to store intersection of @widget and @area
5155 * Computes the intersection of a @widget's area and @area, storing
5156 * the intersection in @intersection, and returns %TRUE if there was
5157 * an intersection. @intersection may be %NULL if you're only
5158 * interested in whether there was an intersection.
5160 * Return value: %TRUE if there was an intersection
5163 gtk_widget_intersect (GtkWidget *widget,
5164 const GdkRectangle *area,
5165 GdkRectangle *intersection)
5171 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5172 g_return_val_if_fail (area != NULL, FALSE);
5175 dest = intersection;
5179 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5181 if (return_val && intersection && gtk_widget_get_has_window (widget))
5183 intersection->x -= widget->allocation.x;
5184 intersection->y -= widget->allocation.y;
5191 * gtk_widget_region_intersect:
5192 * @widget: a #GtkWidget
5193 * @region: a #GdkRegion, in the same coordinate system as
5194 * @widget->allocation. That is, relative to @widget->window
5195 * for %NO_WINDOW widgets; relative to the parent window
5196 * of @widget->window for widgets with their own window.
5197 * @returns: A newly allocated region holding the intersection of @widget
5198 * and @region. The coordinates of the return value are
5199 * relative to @widget->window for %NO_WINDOW widgets, and
5200 * relative to the parent window of @widget->window for
5201 * widgets with their own window.
5203 * Computes the intersection of a @widget's area and @region, returning
5204 * the intersection. The result may be empty, use gdk_region_empty() to
5208 gtk_widget_region_intersect (GtkWidget *widget,
5209 const GdkRegion *region)
5214 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5215 g_return_val_if_fail (region != NULL, NULL);
5217 gtk_widget_get_draw_rectangle (widget, &rect);
5219 dest = gdk_region_rectangle (&rect);
5221 gdk_region_intersect (dest, region);
5227 * _gtk_widget_grab_notify:
5228 * @widget: a #GtkWidget
5229 * @was_grabbed: whether a grab is now in effect
5231 * Emits the #GtkWidget::grab-notify signal on @widget.
5236 _gtk_widget_grab_notify (GtkWidget *widget,
5237 gboolean was_grabbed)
5239 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5243 * gtk_widget_grab_focus:
5244 * @widget: a #GtkWidget
5246 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5247 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5248 * something like #GtkFrame won't work.
5250 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5251 * gtk_widget_set_can_focus() to modify that flag.
5254 gtk_widget_grab_focus (GtkWidget *widget)
5256 g_return_if_fail (GTK_IS_WIDGET (widget));
5258 if (!gtk_widget_is_sensitive (widget))
5261 g_object_ref (widget);
5262 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5263 g_object_notify (G_OBJECT (widget), "has-focus");
5264 g_object_unref (widget);
5268 reset_focus_recurse (GtkWidget *widget,
5271 if (GTK_IS_CONTAINER (widget))
5273 GtkContainer *container;
5275 container = GTK_CONTAINER (widget);
5276 gtk_container_set_focus_child (container, NULL);
5278 gtk_container_foreach (container,
5279 reset_focus_recurse,
5285 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5287 if (gtk_widget_get_can_focus (focus_widget))
5289 GtkWidget *toplevel;
5292 /* clear the current focus setting, break if the current widget
5293 * is the focus widget's parent, since containers above that will
5294 * be set by the next loop.
5296 toplevel = gtk_widget_get_toplevel (focus_widget);
5297 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5299 widget = GTK_WINDOW (toplevel)->focus_widget;
5301 if (widget == focus_widget)
5303 /* We call _gtk_window_internal_set_focus() here so that the
5304 * toplevel window can request the focus if necessary.
5305 * This is needed when the toplevel is a GtkPlug
5307 if (!gtk_widget_has_focus (widget))
5308 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5315 while (widget->parent && widget->parent != focus_widget->parent)
5317 widget = widget->parent;
5318 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5322 else if (toplevel != focus_widget)
5324 /* gtk_widget_grab_focus() operates on a tree without window...
5325 * actually, this is very questionable behaviour.
5328 gtk_container_foreach (GTK_CONTAINER (toplevel),
5329 reset_focus_recurse,
5333 /* now propagate the new focus up the widget tree and finally
5334 * set it on the window
5336 widget = focus_widget;
5337 while (widget->parent)
5339 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5340 widget = widget->parent;
5342 if (GTK_IS_WINDOW (widget))
5343 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5348 gtk_widget_real_query_tooltip (GtkWidget *widget,
5351 gboolean keyboard_tip,
5352 GtkTooltip *tooltip)
5354 gchar *tooltip_markup;
5355 gboolean has_tooltip;
5357 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5358 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5360 if (has_tooltip && tooltip_markup)
5362 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5370 gtk_widget_real_show_help (GtkWidget *widget,
5371 GtkWidgetHelpType help_type)
5373 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5375 _gtk_tooltip_toggle_keyboard_mode (widget);
5384 gtk_widget_real_focus (GtkWidget *widget,
5385 GtkDirectionType direction)
5387 if (!gtk_widget_get_can_focus (widget))
5390 if (!gtk_widget_is_focus (widget))
5392 gtk_widget_grab_focus (widget);
5400 gtk_widget_real_move_focus (GtkWidget *widget,
5401 GtkDirectionType direction)
5403 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5405 if (GTK_IS_WINDOW (toplevel) &&
5406 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5408 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5414 gtk_widget_real_keynav_failed (GtkWidget *widget,
5415 GtkDirectionType direction)
5417 gboolean cursor_only;
5421 case GTK_DIR_TAB_FORWARD:
5422 case GTK_DIR_TAB_BACKWARD:
5429 g_object_get (gtk_widget_get_settings (widget),
5430 "gtk-keynav-cursor-only", &cursor_only,
5437 gtk_widget_error_bell (widget);
5443 * gtk_widget_set_can_focus:
5444 * @widget: a #GtkWidget
5445 * @can_focus: whether or not @widget can own the input focus.
5447 * Specifies whether @widget can own the input focus. See
5448 * gtk_widget_grab_focus() for actually setting the input focus on a
5454 gtk_widget_set_can_focus (GtkWidget *widget,
5457 g_return_if_fail (GTK_IS_WIDGET (widget));
5459 if (can_focus != gtk_widget_get_can_focus (widget))
5462 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
5464 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
5466 gtk_widget_queue_resize (widget);
5467 g_object_notify (G_OBJECT (widget), "can-focus");
5472 * gtk_widget_get_can_focus:
5473 * @widget: a #GtkWidget
5475 * Determines whether @widget can own the input focus. See
5476 * gtk_widget_set_can_focus().
5478 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5483 gtk_widget_get_can_focus (GtkWidget *widget)
5485 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5487 return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5491 * gtk_widget_has_focus:
5492 * @widget: a #GtkWidget
5494 * Determines if the widget has the global input focus. See
5495 * gtk_widget_is_focus() for the difference between having the global
5496 * input focus, and only having the focus within a toplevel.
5498 * Return value: %TRUE if the widget has the global input focus.
5503 gtk_widget_has_focus (GtkWidget *widget)
5505 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5507 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5511 * gtk_widget_is_focus:
5512 * @widget: a #GtkWidget
5514 * Determines if the widget is the focus widget within its
5515 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5516 * necessarily set; %HAS_FOCUS will only be set if the
5517 * toplevel widget additionally has the global input focus.)
5519 * Return value: %TRUE if the widget is the focus widget.
5522 gtk_widget_is_focus (GtkWidget *widget)
5524 GtkWidget *toplevel;
5526 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5528 toplevel = gtk_widget_get_toplevel (widget);
5530 if (GTK_IS_WINDOW (toplevel))
5531 return widget == GTK_WINDOW (toplevel)->focus_widget;
5537 * gtk_widget_set_can_default:
5538 * @widget: a #GtkWidget
5539 * @can_default: whether or not @widget can be a default widget.
5541 * Specifies whether @widget can be a default widget. See
5542 * gtk_widget_grab_default() for details about the meaning of
5548 gtk_widget_set_can_default (GtkWidget *widget,
5549 gboolean can_default)
5551 g_return_if_fail (GTK_IS_WIDGET (widget));
5553 if (can_default != gtk_widget_get_can_default (widget))
5556 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
5558 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
5560 gtk_widget_queue_resize (widget);
5561 g_object_notify (G_OBJECT (widget), "can-default");
5566 * gtk_widget_get_can_default:
5567 * @widget: a #GtkWidget
5569 * Determines whether @widget can be a default widget. See
5570 * gtk_widget_set_can_default().
5572 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5577 gtk_widget_get_can_default (GtkWidget *widget)
5579 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5581 return (GTK_WIDGET_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5585 * gtk_widget_has_default:
5586 * @widget: a #GtkWidget
5588 * Determines whether @widget is the current default widget within its
5589 * toplevel. See gtk_widget_set_can_default().
5591 * Return value: %TRUE if @widget is the current default widget within
5592 * its toplevel, %FALSE otherwise
5597 gtk_widget_has_default (GtkWidget *widget)
5599 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5601 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5605 * gtk_widget_grab_default:
5606 * @widget: a #GtkWidget
5608 * Causes @widget to become the default widget. @widget must have the
5609 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5610 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5611 * %TRUE)</literal>. The default widget is activated when
5612 * the user presses Enter in a window. Default widgets must be
5613 * activatable, that is, gtk_widget_activate() should affect them.
5616 gtk_widget_grab_default (GtkWidget *widget)
5620 g_return_if_fail (GTK_IS_WIDGET (widget));
5621 g_return_if_fail (gtk_widget_get_can_default (widget));
5623 window = gtk_widget_get_toplevel (widget);
5625 if (window && gtk_widget_is_toplevel (window))
5626 gtk_window_set_default (GTK_WINDOW (window), widget);
5628 g_warning (G_STRLOC ": widget not within a GtkWindow");
5632 * gtk_widget_set_receives_default:
5633 * @widget: a #GtkWidget
5634 * @receives_default: whether or not @widget can be a default widget.
5636 * Specifies whether @widget will be treated as the default widget
5637 * within its toplevel when it has the focus, even if another widget
5640 * See gtk_widget_grab_default() for details about the meaning of
5646 gtk_widget_set_receives_default (GtkWidget *widget,
5647 gboolean receives_default)
5649 g_return_if_fail (GTK_IS_WIDGET (widget));
5651 if (receives_default != gtk_widget_get_receives_default (widget))
5653 if (receives_default)
5654 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5656 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5658 g_object_notify (G_OBJECT (widget), "receives-default");
5663 * gtk_widget_get_receives_default:
5664 * @widget: a #GtkWidget
5666 * Determines whether @widget is alyways treated as default widget
5667 * withing its toplevel when it has the focus, even if another widget
5670 * See gtk_widget_set_receives_default().
5672 * Return value: %TRUE if @widget acts as default widget when focussed,
5678 gtk_widget_get_receives_default (GtkWidget *widget)
5680 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5682 return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5686 * gtk_widget_has_grab:
5687 * @widget: a #GtkWidget
5689 * Determines whether the widget is currently grabbing events, so it
5690 * is the only widget receiving input events (keyboard and mouse).
5692 * See also gtk_grab_add().
5694 * Return value: %TRUE if the widget is in the grab_widgets stack
5699 gtk_widget_has_grab (GtkWidget *widget)
5701 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5703 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5707 * gtk_widget_set_name:
5708 * @widget: a #GtkWidget
5709 * @name: name for the widget
5711 * Widgets can be named, which allows you to refer to them from a
5712 * gtkrc file. You can apply a style to widgets with a particular name
5713 * in the gtkrc file. See the documentation for gtkrc files (on the
5714 * same page as the docs for #GtkRcStyle).
5716 * Note that widget names are separated by periods in paths (see
5717 * gtk_widget_path()), so names with embedded periods may cause confusion.
5720 gtk_widget_set_name (GtkWidget *widget,
5725 g_return_if_fail (GTK_IS_WIDGET (widget));
5727 new_name = g_strdup (name);
5728 g_free (widget->name);
5729 widget->name = new_name;
5731 if (gtk_widget_has_rc_style (widget))
5732 gtk_widget_reset_rc_style (widget);
5734 g_object_notify (G_OBJECT (widget), "name");
5738 * gtk_widget_get_name:
5739 * @widget: a #GtkWidget
5741 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5742 * significance of widget names.
5744 * Return value: name of the widget. This string is owned by GTK+ and
5745 * should not be modified or freed
5747 G_CONST_RETURN gchar*
5748 gtk_widget_get_name (GtkWidget *widget)
5750 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5753 return widget->name;
5754 return G_OBJECT_TYPE_NAME (widget);
5758 * gtk_widget_set_state:
5759 * @widget: a #GtkWidget
5760 * @state: new state for @widget
5762 * This function is for use in widget implementations. Sets the state
5763 * of a widget (insensitive, prelighted, etc.) Usually you should set
5764 * the state using wrapper functions such as gtk_widget_set_sensitive().
5767 gtk_widget_set_state (GtkWidget *widget,
5770 g_return_if_fail (GTK_IS_WIDGET (widget));
5772 if (state == GTK_WIDGET_STATE (widget))
5775 if (state == GTK_STATE_INSENSITIVE)
5776 gtk_widget_set_sensitive (widget, FALSE);
5782 data.state_restoration = FALSE;
5783 data.use_forall = FALSE;
5785 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5787 data.parent_sensitive = TRUE;
5789 gtk_widget_propagate_state (widget, &data);
5791 if (gtk_widget_is_drawable (widget))
5792 gtk_widget_queue_draw (widget);
5797 * gtk_widget_get_state:
5798 * @widget: a #GtkWidget
5800 * Returns the widget's state. See gtk_widget_set_state().
5802 * Returns: the state of @widget.
5807 gtk_widget_get_state (GtkWidget *widget)
5809 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5811 return widget->state;
5815 * gtk_widget_set_visible:
5816 * @widget: a #GtkWidget
5817 * @visible: whether the widget should be shown or not
5819 * Sets the visibility state of @widget. Note that setting this to
5820 * %TRUE doesn't mean the widget is actually viewable, see
5821 * gtk_widget_get_visible().
5823 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5824 * but is nicer to use when the visibility of the widget depends on
5830 gtk_widget_set_visible (GtkWidget *widget,
5833 g_return_if_fail (GTK_IS_WIDGET (widget));
5835 if (visible != GTK_WIDGET_VISIBLE (widget))
5838 gtk_widget_show (widget);
5840 gtk_widget_hide (widget);
5845 * gtk_widget_get_visible:
5846 * @widget: a #GtkWidget
5848 * Determines whether the widget is visible. Note that this doesn't
5849 * take into account whether the widget's parent is also visible
5850 * or the widget is obscured in any way.
5852 * See gtk_widget_set_visible().
5854 * Return value: %TRUE if the widget is visible
5859 gtk_widget_get_visible (GtkWidget *widget)
5861 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5863 return (GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0;
5867 * gtk_widget_set_has_window:
5868 * @widget: a #GtkWidget
5869 * @has_window: whether or not @widget has a window.
5871 * Specifies whether @widget has a #GdkWindow of its own. Note that
5872 * all realized widgets have a non-%NULL "window" pointer
5873 * (gtk_widget_get_window() never returns a %NULL window when a widget
5874 * is realized), but for many of them it's actually the #GdkWindow of
5875 * one of its parent widgets. Widgets that create a %window for
5876 * themselves in GtkWidget::realize() however must announce this by
5877 * calling this function with @has_window = %TRUE.
5879 * This function should only be called by widget implementations,
5880 * and they should call it in their init() function.
5885 gtk_widget_set_has_window (GtkWidget *widget,
5886 gboolean has_window)
5888 g_return_if_fail (GTK_IS_WIDGET (widget));
5891 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
5893 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
5897 * gtk_widget_get_has_window:
5898 * @widget: a #GtkWidget
5900 * Determines whether @widget has a #GdkWindow of its own. See
5901 * gtk_widget_set_has_window().
5903 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5908 gtk_widget_get_has_window (GtkWidget *widget)
5910 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5912 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5916 * gtk_widget_is_toplevel:
5917 * @widget: a #GtkWidget
5919 * Determines whether @widget is a toplevel widget. Currently only
5920 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5921 * widgets have no parent widget.
5923 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5928 gtk_widget_is_toplevel (GtkWidget *widget)
5930 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5932 return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5936 * gtk_widget_is_drawable:
5937 * @widget: a #GtkWidget
5939 * Determines whether @widget can be drawn to. A widget can be drawn
5940 * to if it is mapped and visible.
5942 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5947 gtk_widget_is_drawable (GtkWidget *widget)
5949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5951 return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 &&
5952 (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0);
5956 * gtk_widget_get_realized:
5957 * @widget: a #GtkWidget
5959 * Determines whether @widget is realized.
5961 * Return value: %TRUE if @widget is realized, %FALSE otherwise
5966 gtk_widget_get_realized (GtkWidget *widget)
5968 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5970 return (GTK_WIDGET_FLAGS (widget) & GTK_REALIZED) != 0;
5974 * gtk_widget_set_realized:
5975 * @widget: a #GtkWidget
5976 * @realized: %TRUE to mark the widget as realized
5978 * Marks the widget as being realized.
5980 * This function should only ever be called in a derived widget's
5981 * "realize" or "unrealize" implementation.
5986 gtk_widget_set_realized (GtkWidget *widget,
5989 g_return_if_fail (GTK_IS_WIDGET (widget));
5992 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
5994 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
5998 * gtk_widget_get_mapped:
5999 * @widget: a #GtkWidget
6001 * Whether the widget is mapped.
6003 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6008 gtk_widget_get_mapped (GtkWidget *widget)
6010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6012 return (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0;
6016 * gtk_widget_set_mapped:
6017 * @widget: a #GtkWidget
6018 * @mapped: %TRUE to mark the widget as mapped
6020 * Marks the widget as being realized.
6022 * This function should only ever be called in a derived widget's
6023 * "map" or "unmap" implementation.
6028 gtk_widget_set_mapped (GtkWidget *widget,
6031 g_return_if_fail (GTK_IS_WIDGET (widget));
6034 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6036 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6040 * gtk_widget_set_app_paintable:
6041 * @widget: a #GtkWidget
6042 * @app_paintable: %TRUE if the application will paint on the widget
6044 * Sets whether the application intends to draw on the widget in
6045 * an #GtkWidget::expose-event handler.
6047 * This is a hint to the widget and does not affect the behavior of
6048 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6049 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6050 * the effect is to suppress default themed drawing of the widget's
6051 * background. (Children of the widget will still be drawn.) The application
6052 * is then entirely responsible for drawing the widget background.
6054 * Note that the background is still drawn when the widget is mapped.
6055 * If this is not suitable (e.g. because you want to make a transparent
6056 * window using an RGBA visual), you can work around this by doing:
6058 * gtk_widget_realize (window);
6059 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6060 * gtk_widget_show (window);
6064 gtk_widget_set_app_paintable (GtkWidget *widget,
6065 gboolean app_paintable)
6067 g_return_if_fail (GTK_IS_WIDGET (widget));
6069 app_paintable = (app_paintable != FALSE);
6071 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6074 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
6076 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
6078 if (gtk_widget_is_drawable (widget))
6079 gtk_widget_queue_draw (widget);
6081 g_object_notify (G_OBJECT (widget), "app-paintable");
6086 * gtk_widget_get_app_paintable:
6087 * @widget: a #GtkWidget
6089 * Determines whether the application intends to draw on the widget in
6090 * an #GtkWidget::expose-event handler.
6092 * See gtk_widget_set_app_paintable()
6094 * Return value: %TRUE if the widget is app paintable
6099 gtk_widget_get_app_paintable (GtkWidget *widget)
6101 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6103 return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6107 * gtk_widget_set_double_buffered:
6108 * @widget: a #GtkWidget
6109 * @double_buffered: %TRUE to double-buffer a widget
6111 * Widgets are double buffered by default; you can use this function
6112 * to turn off the buffering. "Double buffered" simply means that
6113 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6114 * automatically around expose events sent to the
6115 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6116 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6117 * buffer to the screen. The result is that users see the window
6118 * update in one smooth step, and don't see individual graphics
6119 * primitives being rendered.
6121 * In very simple terms, double buffered widgets don't flicker,
6122 * so you would only use this function to turn off double buffering
6123 * if you had special needs and really knew what you were doing.
6125 * Note: if you turn off double-buffering, you have to handle
6126 * expose events, since even the clearing to the background color or
6127 * pixmap will not happen automatically (as it is done in
6128 * gdk_window_begin_paint()).
6131 gtk_widget_set_double_buffered (GtkWidget *widget,
6132 gboolean double_buffered)
6134 g_return_if_fail (GTK_IS_WIDGET (widget));
6136 double_buffered = (double_buffered != FALSE);
6138 if (double_buffered != gtk_widget_get_double_buffered (widget))
6140 if (double_buffered)
6141 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
6143 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
6145 g_object_notify (G_OBJECT (widget), "double-buffered");
6150 * gtk_widget_get_double_buffered:
6151 * @widget: a #GtkWidget
6153 * Determines whether the widget is double buffered.
6155 * See gtk_widget_set_double_buffered()
6157 * Return value: %TRUE if the widget is double buffered
6162 gtk_widget_get_double_buffered (GtkWidget *widget)
6164 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6166 return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6170 * gtk_widget_set_redraw_on_allocate:
6171 * @widget: a #GtkWidget
6172 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6173 * when it is allocated to a new size. Otherwise, only the
6174 * new portion of the widget will be redrawn.
6176 * Sets whether the entire widget is queued for drawing when its size
6177 * allocation changes. By default, this setting is %TRUE and
6178 * the entire widget is redrawn on every size change. If your widget
6179 * leaves the upper left unchanged when made bigger, turning this
6180 * setting off will improve performance.
6182 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6183 * off all allocation on resizing: the widget will not even redraw if
6184 * its position changes; this is to allow containers that don't draw
6185 * anything to avoid excess invalidations. If you set this flag on a
6186 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6187 * you are responsible for invalidating both the old and new allocation
6188 * of the widget when the widget is moved and responsible for invalidating
6189 * regions newly when the widget increases size.
6192 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6193 gboolean redraw_on_allocate)
6195 g_return_if_fail (GTK_IS_WIDGET (widget));
6197 if (redraw_on_allocate)
6198 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6200 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6204 * gtk_widget_set_sensitive:
6205 * @widget: a #GtkWidget
6206 * @sensitive: %TRUE to make the widget sensitive
6208 * Sets the sensitivity of a widget. A widget is sensitive if the user
6209 * can interact with it. Insensitive widgets are "grayed out" and the
6210 * user can't interact with them. Insensitive widgets are known as
6211 * "inactive", "disabled", or "ghosted" in some other toolkits.
6214 gtk_widget_set_sensitive (GtkWidget *widget,
6219 g_return_if_fail (GTK_IS_WIDGET (widget));
6221 sensitive = (sensitive != FALSE);
6223 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6228 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
6229 data.state = widget->saved_state;
6233 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
6234 data.state = GTK_WIDGET_STATE (widget);
6236 data.state_restoration = TRUE;
6237 data.use_forall = TRUE;
6240 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6242 data.parent_sensitive = TRUE;
6244 gtk_widget_propagate_state (widget, &data);
6245 if (gtk_widget_is_drawable (widget))
6246 gtk_widget_queue_draw (widget);
6248 g_object_notify (G_OBJECT (widget), "sensitive");
6252 * gtk_widget_get_sensitive:
6253 * @widget: a #GtkWidget
6255 * Returns the widget's sensitivity (in the sense of returning
6256 * the value that has been set using gtk_widget_set_sensitive()).
6258 * The effective sensitivity of a widget is however determined by both its
6259 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6261 * Returns: %TRUE if the widget is sensitive
6266 gtk_widget_get_sensitive (GtkWidget *widget)
6268 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6270 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6274 * gtk_widget_is_sensitive:
6275 * @widget: a #GtkWidget
6277 * Returns the widget's effective sensitivity, which means
6278 * it is sensitive itself and also its parent widget is sensntive
6280 * Returns: %TRUE if the widget is effectively sensitive
6285 gtk_widget_is_sensitive (GtkWidget *widget)
6287 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6289 return gtk_widget_is_sensitive (widget);
6293 * gtk_widget_set_parent:
6294 * @widget: a #GtkWidget
6295 * @parent: parent container
6297 * This function is useful only when implementing subclasses of
6299 * Sets the container as the parent of @widget, and takes care of
6300 * some details such as updating the state and style of the child
6301 * to reflect its new location. The opposite function is
6302 * gtk_widget_unparent().
6305 gtk_widget_set_parent (GtkWidget *widget,
6310 g_return_if_fail (GTK_IS_WIDGET (widget));
6311 g_return_if_fail (GTK_IS_WIDGET (parent));
6312 g_return_if_fail (widget != parent);
6313 if (widget->parent != NULL)
6315 g_warning ("Can't set a parent on widget which has a parent\n");
6318 if (gtk_widget_is_toplevel (widget))
6320 g_warning ("Can't set a parent on a toplevel widget\n");
6324 /* keep this function in sync with gtk_menu_attach_to_widget()
6327 g_object_ref_sink (widget);
6328 widget->parent = parent;
6330 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
6331 data.state = GTK_WIDGET_STATE (parent);
6333 data.state = GTK_WIDGET_STATE (widget);
6334 data.state_restoration = FALSE;
6335 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6336 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6338 gtk_widget_propagate_state (widget, &data);
6340 gtk_widget_reset_rc_styles (widget);
6342 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6343 if (GTK_WIDGET_ANCHORED (widget->parent))
6344 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6345 g_object_notify (G_OBJECT (widget), "parent");
6347 /* Enforce realized/mapped invariants
6349 if (GTK_WIDGET_REALIZED (widget->parent))
6350 gtk_widget_realize (widget);
6352 if (GTK_WIDGET_VISIBLE (widget->parent) &&
6353 GTK_WIDGET_VISIBLE (widget))
6355 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6356 GTK_WIDGET_MAPPED (widget->parent))
6357 gtk_widget_map (widget);
6359 gtk_widget_queue_resize (widget);
6364 * gtk_widget_get_parent:
6365 * @widget: a #GtkWidget
6367 * Returns the parent container of @widget.
6369 * Return value: (transfer none): the parent container of @widget, or %NULL
6372 gtk_widget_get_parent (GtkWidget *widget)
6374 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6376 return widget->parent;
6379 /*****************************************
6381 * see docs/styles.txt
6382 *****************************************/
6385 * gtk_widget_style_attach:
6386 * @widget: a #GtkWidget
6388 * This function attaches the widget's #GtkStyle to the widget's
6389 * #GdkWindow. It is a replacement for
6392 * widget->style = gtk_style_attach (widget->style, widget->window);
6395 * and should only ever be called in a derived widget's "realize"
6396 * implementation which does not chain up to its parent class'
6397 * "realize" implementation, because one of the parent classes
6398 * (finally #GtkWidget) would attach the style itself.
6403 gtk_widget_style_attach (GtkWidget *widget)
6405 g_return_if_fail (GTK_IS_WIDGET (widget));
6406 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6408 widget->style = gtk_style_attach (widget->style, widget->window);
6412 * gtk_widget_has_rc_style:
6413 * @widget: a #GtkWidget
6415 * Determines if the widget style has been looked up through the rc mechanism.
6417 * Returns: %TRUE if the widget has been looked up through the rc
6418 * mechanism, %FALSE otherwise.
6423 gtk_widget_has_rc_style (GtkWidget *widget)
6425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6427 return (GTK_WIDGET_FLAGS (widget) & GTK_RC_STYLE) != 0;
6431 * gtk_widget_set_style:
6432 * @widget: a #GtkWidget
6433 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6434 * gtk_widget_set_style() and go back to the default style
6436 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6437 * want to use this function; it interacts badly with themes, because
6438 * themes work by replacing the #GtkStyle. Instead, use
6439 * gtk_widget_modify_style().
6442 gtk_widget_set_style (GtkWidget *widget,
6445 g_return_if_fail (GTK_IS_WIDGET (widget));
6449 gboolean initial_emission;
6451 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6453 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
6454 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6456 gtk_widget_set_style_internal (widget, style, initial_emission);
6460 if (GTK_WIDGET_USER_STYLE (widget))
6461 gtk_widget_reset_rc_style (widget);
6466 * gtk_widget_ensure_style:
6467 * @widget: a #GtkWidget
6469 * Ensures that @widget has a style (@widget->style). Not a very useful
6470 * function; most of the time, if you want the style, the widget is
6471 * realized, and realized widgets are guaranteed to have a style
6475 gtk_widget_ensure_style (GtkWidget *widget)
6477 g_return_if_fail (GTK_IS_WIDGET (widget));
6479 if (!GTK_WIDGET_USER_STYLE (widget) &&
6480 !gtk_widget_has_rc_style (widget))
6481 gtk_widget_reset_rc_style (widget);
6484 /* Look up the RC style for this widget, unsetting any user style that
6485 * may be in effect currently
6488 gtk_widget_reset_rc_style (GtkWidget *widget)
6490 GtkStyle *new_style = NULL;
6491 gboolean initial_emission;
6493 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6495 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6496 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
6498 if (gtk_widget_has_screen (widget))
6499 new_style = gtk_rc_get_style (widget);
6501 new_style = gtk_widget_get_default_style ();
6503 if (initial_emission || new_style != widget->style)
6504 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6508 * gtk_widget_get_style:
6509 * @widget: a #GtkWidget
6511 * Simply an accessor function that returns @widget->style.
6513 * Return value: (transfer none): the widget's #GtkStyle
6516 gtk_widget_get_style (GtkWidget *widget)
6518 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6520 return widget->style;
6524 * gtk_widget_modify_style:
6525 * @widget: a #GtkWidget
6526 * @style: the #GtkRcStyle holding the style modifications
6528 * Modifies style values on the widget. Modifications made using this
6529 * technique take precedence over style values set via an RC file,
6530 * however, they will be overriden if a style is explicitely set on
6531 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6532 * is designed so each field can either be set or unset, so it is
6533 * possible, using this function, to modify some style values and
6534 * leave the others unchanged.
6536 * Note that modifications made with this function are not cumulative
6537 * with previous calls to gtk_widget_modify_style() or with such
6538 * functions as gtk_widget_modify_fg(). If you wish to retain
6539 * previous values, you must first call gtk_widget_get_modifier_style(),
6540 * make your modifications to the returned style, then call
6541 * gtk_widget_modify_style() with that style. On the other hand,
6542 * if you first call gtk_widget_modify_style(), subsequent calls
6543 * to such functions gtk_widget_modify_fg() will have a cumulative
6544 * effect with the initial modifications.
6547 gtk_widget_modify_style (GtkWidget *widget,
6550 g_return_if_fail (GTK_IS_WIDGET (widget));
6551 g_return_if_fail (GTK_IS_RC_STYLE (style));
6553 g_object_set_qdata_full (G_OBJECT (widget),
6555 gtk_rc_style_copy (style),
6556 (GDestroyNotify) g_object_unref);
6558 /* note that "style" may be invalid here if it was the old
6559 * modifier style and the only reference was our own.
6562 if (gtk_widget_has_rc_style (widget))
6563 gtk_widget_reset_rc_style (widget);
6567 * gtk_widget_get_modifier_style:
6568 * @widget: a #GtkWidget
6570 * Returns the current modifier style for the widget. (As set by
6571 * gtk_widget_modify_style().) If no style has previously set, a new
6572 * #GtkRcStyle will be created with all values unset, and set as the
6573 * modifier style for the widget. If you make changes to this rc
6574 * style, you must call gtk_widget_modify_style(), passing in the
6575 * returned rc style, to make sure that your changes take effect.
6577 * Caution: passing the style back to gtk_widget_modify_style() will
6578 * normally end up destroying it, because gtk_widget_modify_style() copies
6579 * the passed-in style and sets the copy as the new modifier style,
6580 * thus dropping any reference to the old modifier style. Add a reference
6581 * to the modifier style if you want to keep it alive.
6583 * Return value: (transfer none): the modifier style for the widget. This rc style is
6584 * owned by the widget. If you want to keep a pointer to value this
6585 * around, you must add a refcount using g_object_ref().
6588 gtk_widget_get_modifier_style (GtkWidget *widget)
6590 GtkRcStyle *rc_style;
6592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6594 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6598 rc_style = gtk_rc_style_new ();
6599 g_object_set_qdata_full (G_OBJECT (widget),
6602 (GDestroyNotify) g_object_unref);
6609 gtk_widget_modify_color_component (GtkWidget *widget,
6610 GtkRcFlags component,
6612 const GdkColor *color)
6614 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6621 rc_style->fg[state] = *color;
6624 rc_style->bg[state] = *color;
6627 rc_style->text[state] = *color;
6630 rc_style->base[state] = *color;
6633 g_assert_not_reached();
6636 rc_style->color_flags[state] |= component;
6639 rc_style->color_flags[state] &= ~component;
6641 gtk_widget_modify_style (widget, rc_style);
6645 * gtk_widget_modify_fg:
6646 * @widget: a #GtkWidget
6647 * @state: the state for which to set the foreground color
6648 * @color: (allow-none): the color to assign (does not need to be allocated),
6649 * or %NULL to undo the effect of previous calls to
6650 * of gtk_widget_modify_fg().
6652 * Sets the foreground color for a widget in a particular state.
6653 * All other style values are left untouched. See also
6654 * gtk_widget_modify_style().
6657 gtk_widget_modify_fg (GtkWidget *widget,
6659 const GdkColor *color)
6661 g_return_if_fail (GTK_IS_WIDGET (widget));
6662 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6664 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6668 * gtk_widget_modify_bg:
6669 * @widget: a #GtkWidget
6670 * @state: the state for which to set the background color
6671 * @color: (allow-none): the color to assign (does not need to be allocated),
6672 * or %NULL to undo the effect of previous calls to
6673 * of gtk_widget_modify_bg().
6675 * Sets the background color for a widget in a particular state.
6676 * All other style values are left untouched. See also
6677 * gtk_widget_modify_style().
6679 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6680 * draw on their parent container's window and thus may not draw any
6681 * background themselves. This is the case for e.g. #GtkLabel. To modify
6682 * the background of such widgets, you have to set the background color
6683 * on their parent; if you want to set the background of a rectangular
6684 * area around a label, try placing the label in a #GtkEventBox widget
6685 * and setting the background color on that.
6688 gtk_widget_modify_bg (GtkWidget *widget,
6690 const GdkColor *color)
6692 g_return_if_fail (GTK_IS_WIDGET (widget));
6693 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6695 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6699 * gtk_widget_modify_text:
6700 * @widget: a #GtkWidget
6701 * @state: the state for which to set the text color
6702 * @color: (allow-none): the color to assign (does not need to be allocated),
6703 * or %NULL to undo the effect of previous calls to
6704 * of gtk_widget_modify_text().
6706 * Sets the text color for a widget in a particular state. All other
6707 * style values are left untouched. The text color is the foreground
6708 * color used along with the base color (see gtk_widget_modify_base())
6709 * for widgets such as #GtkEntry and #GtkTextView. See also
6710 * gtk_widget_modify_style().
6713 gtk_widget_modify_text (GtkWidget *widget,
6715 const GdkColor *color)
6717 g_return_if_fail (GTK_IS_WIDGET (widget));
6718 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6720 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6724 * gtk_widget_modify_base:
6725 * @widget: a #GtkWidget
6726 * @state: the state for which to set the base color
6727 * @color: (allow-none): the color to assign (does not need to be allocated),
6728 * or %NULL to undo the effect of previous calls to
6729 * of gtk_widget_modify_base().
6731 * Sets the base color for a widget in a particular state.
6732 * All other style values are left untouched. The base color
6733 * is the background color used along with the text color
6734 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6735 * and #GtkTextView. See also gtk_widget_modify_style().
6737 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6738 * draw on their parent container's window and thus may not draw any
6739 * background themselves. This is the case for e.g. #GtkLabel. To modify
6740 * the background of such widgets, you have to set the base color on their
6741 * parent; if you want to set the background of a rectangular area around
6742 * a label, try placing the label in a #GtkEventBox widget and setting
6743 * the base color on that.
6746 gtk_widget_modify_base (GtkWidget *widget,
6748 const GdkColor *color)
6750 g_return_if_fail (GTK_IS_WIDGET (widget));
6751 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6753 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6757 modify_color_property (GtkWidget *widget,
6758 GtkRcStyle *rc_style,
6760 const GdkColor *color)
6762 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6763 GQuark property_name = g_quark_from_string (name);
6767 GtkRcProperty rc_property = {0};
6770 rc_property.type_name = type_name;
6771 rc_property.property_name = property_name;
6772 rc_property.origin = NULL;
6774 color_name = gdk_color_to_string (color);
6775 g_value_init (&rc_property.value, G_TYPE_STRING);
6776 g_value_take_string (&rc_property.value, color_name);
6778 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6780 g_value_unset (&rc_property.value);
6783 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6787 * gtk_widget_modify_cursor:
6788 * @widget: a #GtkWidget
6789 * @primary: the color to use for primary cursor (does not need to be
6790 * allocated), or %NULL to undo the effect of previous calls to
6791 * of gtk_widget_modify_cursor().
6792 * @secondary: the color to use for secondary cursor (does not need to be
6793 * allocated), or %NULL to undo the effect of previous calls to
6794 * of gtk_widget_modify_cursor().
6796 * Sets the cursor color to use in a widget, overriding the
6797 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6798 * style properties. All other style values are left untouched.
6799 * See also gtk_widget_modify_style().
6804 gtk_widget_modify_cursor (GtkWidget *widget,
6805 const GdkColor *primary,
6806 const GdkColor *secondary)
6808 GtkRcStyle *rc_style;
6810 g_return_if_fail (GTK_IS_WIDGET (widget));
6812 rc_style = gtk_widget_get_modifier_style (widget);
6814 modify_color_property (widget, rc_style, "cursor-color", primary);
6815 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6817 gtk_widget_modify_style (widget, rc_style);
6821 * gtk_widget_modify_font:
6822 * @widget: a #GtkWidget
6823 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6824 * the effect of previous calls to gtk_widget_modify_font().
6826 * Sets the font to use for a widget. All other style values are left
6827 * untouched. See also gtk_widget_modify_style().
6830 gtk_widget_modify_font (GtkWidget *widget,
6831 PangoFontDescription *font_desc)
6833 GtkRcStyle *rc_style;
6835 g_return_if_fail (GTK_IS_WIDGET (widget));
6837 rc_style = gtk_widget_get_modifier_style (widget);
6839 if (rc_style->font_desc)
6840 pango_font_description_free (rc_style->font_desc);
6843 rc_style->font_desc = pango_font_description_copy (font_desc);
6845 rc_style->font_desc = NULL;
6847 gtk_widget_modify_style (widget, rc_style);
6851 gtk_widget_real_direction_changed (GtkWidget *widget,
6852 GtkTextDirection previous_direction)
6854 gtk_widget_queue_resize (widget);
6858 gtk_widget_real_style_set (GtkWidget *widget,
6859 GtkStyle *previous_style)
6861 if (GTK_WIDGET_REALIZED (widget) &&
6862 gtk_widget_get_has_window (widget))
6863 gtk_style_set_background (widget->style, widget->window, widget->state);
6867 gtk_widget_set_style_internal (GtkWidget *widget,
6869 gboolean initial_emission)
6871 g_object_ref (widget);
6872 g_object_freeze_notify (G_OBJECT (widget));
6874 if (widget->style != style)
6876 GtkStyle *previous_style;
6878 if (GTK_WIDGET_REALIZED (widget))
6880 gtk_widget_reset_shapes (widget);
6881 gtk_style_detach (widget->style);
6884 previous_style = widget->style;
6885 widget->style = style;
6886 g_object_ref (widget->style);
6888 if (GTK_WIDGET_REALIZED (widget))
6889 widget->style = gtk_style_attach (widget->style, widget->window);
6891 gtk_widget_update_pango_context (widget);
6892 g_signal_emit (widget,
6893 widget_signals[STYLE_SET],
6895 initial_emission ? NULL : previous_style);
6896 g_object_unref (previous_style);
6898 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6899 gtk_widget_queue_resize (widget);
6901 else if (initial_emission)
6903 gtk_widget_update_pango_context (widget);
6904 g_signal_emit (widget,
6905 widget_signals[STYLE_SET],
6909 g_object_notify (G_OBJECT (widget), "style");
6910 g_object_thaw_notify (G_OBJECT (widget));
6911 g_object_unref (widget);
6915 GtkWidget *previous_toplevel;
6916 GdkScreen *previous_screen;
6917 GdkScreen *new_screen;
6918 } HierarchyChangedInfo;
6921 do_screen_change (GtkWidget *widget,
6922 GdkScreen *old_screen,
6923 GdkScreen *new_screen)
6925 if (old_screen != new_screen)
6929 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6931 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6934 _gtk_tooltip_hide (widget);
6935 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6940 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6941 gpointer client_data)
6943 HierarchyChangedInfo *info = client_data;
6944 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
6945 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6947 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6949 g_object_ref (widget);
6952 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6954 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6956 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6957 do_screen_change (widget, info->previous_screen, info->new_screen);
6959 if (GTK_IS_CONTAINER (widget))
6960 gtk_container_forall (GTK_CONTAINER (widget),
6961 gtk_widget_propagate_hierarchy_changed_recurse,
6964 g_object_unref (widget);
6969 * _gtk_widget_propagate_hierarchy_changed:
6970 * @widget: a #GtkWidget
6971 * @previous_toplevel: Previous toplevel
6973 * Propagates changes in the anchored state to a widget and all
6974 * children, unsetting or setting the %ANCHORED flag, and
6975 * emitting #GtkWidget::hierarchy-changed.
6978 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6979 GtkWidget *previous_toplevel)
6981 HierarchyChangedInfo info;
6983 info.previous_toplevel = previous_toplevel;
6984 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6986 if (gtk_widget_is_toplevel (widget) ||
6987 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6988 info.new_screen = gtk_widget_get_screen (widget);
6990 info.new_screen = NULL;
6992 if (info.previous_screen)
6993 g_object_ref (info.previous_screen);
6994 if (previous_toplevel)
6995 g_object_ref (previous_toplevel);
6997 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6999 if (previous_toplevel)
7000 g_object_unref (previous_toplevel);
7001 if (info.previous_screen)
7002 g_object_unref (info.previous_screen);
7006 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7007 gpointer client_data)
7009 HierarchyChangedInfo *info = client_data;
7011 g_object_ref (widget);
7013 do_screen_change (widget, info->previous_screen, info->new_screen);
7015 if (GTK_IS_CONTAINER (widget))
7016 gtk_container_forall (GTK_CONTAINER (widget),
7017 gtk_widget_propagate_screen_changed_recurse,
7020 g_object_unref (widget);
7024 * gtk_widget_is_composited:
7025 * @widget: a #GtkWidget
7027 * Whether @widget can rely on having its alpha channel
7028 * drawn correctly. On X11 this function returns whether a
7029 * compositing manager is running for @widget's screen.
7031 * Please note that the semantics of this call will change
7032 * in the future if used on a widget that has a composited
7033 * window in its hierarchy (as set by gdk_window_set_composited()).
7035 * Return value: %TRUE if the widget can rely on its alpha
7036 * channel being drawn correctly.
7041 gtk_widget_is_composited (GtkWidget *widget)
7045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7047 screen = gtk_widget_get_screen (widget);
7049 return gdk_screen_is_composited (screen);
7053 propagate_composited_changed (GtkWidget *widget,
7056 if (GTK_IS_CONTAINER (widget))
7058 gtk_container_forall (GTK_CONTAINER (widget),
7059 propagate_composited_changed,
7063 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7067 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7069 propagate_composited_changed (widget, NULL);
7073 * _gtk_widget_propagate_screen_changed:
7074 * @widget: a #GtkWidget
7075 * @previous_screen: Previous screen
7077 * Propagates changes in the screen for a widget to all
7078 * children, emitting #GtkWidget::screen-changed.
7081 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7082 GdkScreen *previous_screen)
7084 HierarchyChangedInfo info;
7086 info.previous_screen = previous_screen;
7087 info.new_screen = gtk_widget_get_screen (widget);
7089 if (previous_screen)
7090 g_object_ref (previous_screen);
7092 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7094 if (previous_screen)
7095 g_object_unref (previous_screen);
7099 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7101 if (gtk_widget_has_rc_style (widget))
7102 gtk_widget_reset_rc_style (widget);
7104 if (GTK_IS_CONTAINER (widget))
7105 gtk_container_forall (GTK_CONTAINER (widget),
7106 reset_rc_styles_recurse,
7112 * gtk_widget_reset_rc_styles:
7113 * @widget: a #GtkWidget.
7115 * Reset the styles of @widget and all descendents, so when
7116 * they are looked up again, they get the correct values
7117 * for the currently loaded RC file settings.
7119 * This function is not useful for applications.
7122 gtk_widget_reset_rc_styles (GtkWidget *widget)
7124 g_return_if_fail (GTK_IS_WIDGET (widget));
7126 reset_rc_styles_recurse (widget, NULL);
7130 * gtk_widget_get_default_style:
7132 * Returns the default style used by all widgets initially.
7134 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7135 * by GTK+ and should not be modified or freed.
7138 gtk_widget_get_default_style (void)
7140 if (!gtk_default_style)
7142 gtk_default_style = gtk_style_new ();
7143 g_object_ref (gtk_default_style);
7146 return gtk_default_style;
7149 static PangoContext *
7150 gtk_widget_peek_pango_context (GtkWidget *widget)
7152 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7156 * gtk_widget_get_pango_context:
7157 * @widget: a #GtkWidget
7159 * Gets a #PangoContext with the appropriate font map, font description,
7160 * and base direction for this widget. Unlike the context returned
7161 * by gtk_widget_create_pango_context(), this context is owned by
7162 * the widget (it can be used until the screen for the widget changes
7163 * or the widget is removed from its toplevel), and will be updated to
7164 * match any changes to the widget's attributes.
7166 * If you create and keep a #PangoLayout using this context, you must
7167 * deal with changes to the context by calling pango_layout_context_changed()
7168 * on the layout in response to the #GtkWidget::style-set and
7169 * #GtkWidget::direction-changed signals for the widget.
7171 * Return value: (transfer none): the #PangoContext for the widget.
7174 gtk_widget_get_pango_context (GtkWidget *widget)
7176 PangoContext *context;
7178 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7180 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7183 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7184 g_object_set_qdata_full (G_OBJECT (widget),
7185 quark_pango_context,
7194 update_pango_context (GtkWidget *widget,
7195 PangoContext *context)
7197 pango_context_set_font_description (context, widget->style->font_desc);
7198 pango_context_set_base_dir (context,
7199 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7200 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7204 gtk_widget_update_pango_context (GtkWidget *widget)
7206 PangoContext *context = gtk_widget_peek_pango_context (widget);
7212 update_pango_context (widget, context);
7214 screen = gtk_widget_get_screen_unchecked (widget);
7217 pango_cairo_context_set_resolution (context,
7218 gdk_screen_get_resolution (screen));
7219 pango_cairo_context_set_font_options (context,
7220 gdk_screen_get_font_options (screen));
7226 * gtk_widget_create_pango_context:
7227 * @widget: a #GtkWidget
7229 * Creates a new #PangoContext with the appropriate font map,
7230 * font description, and base direction for drawing text for
7231 * this widget. See also gtk_widget_get_pango_context().
7233 * Return value: the new #PangoContext
7236 gtk_widget_create_pango_context (GtkWidget *widget)
7239 PangoContext *context;
7241 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7243 screen = gtk_widget_get_screen_unchecked (widget);
7246 GTK_NOTE (MULTIHEAD,
7247 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7249 screen = gdk_screen_get_default ();
7252 context = gdk_pango_context_get_for_screen (screen);
7254 update_pango_context (widget, context);
7255 pango_context_set_language (context, gtk_get_default_language ());
7261 * gtk_widget_create_pango_layout:
7262 * @widget: a #GtkWidget
7263 * @text: text to set on the layout (can be %NULL)
7265 * Creates a new #PangoLayout with the appropriate font map,
7266 * font description, and base direction for drawing text for
7269 * If you keep a #PangoLayout created in this way around, in order to
7270 * notify the layout of changes to the base direction or font of this
7271 * widget, you must call pango_layout_context_changed() in response to
7272 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7275 * Return value: the new #PangoLayout
7278 gtk_widget_create_pango_layout (GtkWidget *widget,
7281 PangoLayout *layout;
7282 PangoContext *context;
7284 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7286 context = gtk_widget_get_pango_context (widget);
7287 layout = pango_layout_new (context);
7290 pango_layout_set_text (layout, text, -1);
7296 * gtk_widget_render_icon:
7297 * @widget: a #GtkWidget
7298 * @stock_id: a stock ID
7299 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7300 * render at the size of the source and don't scale (if there are
7301 * multiple source sizes, GTK+ picks one of the available sizes).
7302 * @detail: (allow-none): render detail to pass to theme engine
7304 * A convenience function that uses the theme engine and RC file
7305 * settings for @widget to look up @stock_id and render it to
7306 * a pixbuf. @stock_id should be a stock icon ID such as
7307 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7308 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7309 * identifies the widget or code doing the rendering, so that
7310 * theme engines can special-case rendering for that widget or code.
7312 * The pixels in the returned #GdkPixbuf are shared with the rest of
7313 * the application and should not be modified. The pixbuf should be freed
7314 * after use with g_object_unref().
7316 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7319 gtk_widget_render_icon (GtkWidget *widget,
7320 const gchar *stock_id,
7322 const gchar *detail)
7324 GtkIconSet *icon_set;
7327 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7328 g_return_val_if_fail (stock_id != NULL, NULL);
7329 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7331 gtk_widget_ensure_style (widget);
7333 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7335 if (icon_set == NULL)
7338 retval = gtk_icon_set_render_icon (icon_set,
7340 gtk_widget_get_direction (widget),
7341 GTK_WIDGET_STATE (widget),
7350 * gtk_widget_set_parent_window:
7351 * @widget: a #GtkWidget.
7352 * @parent_window: the new parent window.
7354 * Sets a non default parent window for @widget.
7357 gtk_widget_set_parent_window (GtkWidget *widget,
7358 GdkWindow *parent_window)
7360 GdkWindow *old_parent_window;
7362 g_return_if_fail (GTK_IS_WIDGET (widget));
7364 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7365 quark_parent_window);
7367 if (parent_window != old_parent_window)
7369 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7371 if (old_parent_window)
7372 g_object_unref (old_parent_window);
7374 g_object_ref (parent_window);
7379 * gtk_widget_get_parent_window:
7380 * @widget: a #GtkWidget.
7382 * Gets @widget's parent window.
7384 * Returns: (transfer none): the parent window of @widget.
7387 gtk_widget_get_parent_window (GtkWidget *widget)
7389 GdkWindow *parent_window;
7391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7393 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7395 return (parent_window != NULL) ? parent_window :
7396 (widget->parent != NULL) ? widget->parent->window : NULL;
7401 * gtk_widget_set_child_visible:
7402 * @widget: a #GtkWidget
7403 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7405 * Sets whether @widget should be mapped along with its when its parent
7406 * is mapped and @widget has been shown with gtk_widget_show().
7408 * The child visibility can be set for widget before it is added to
7409 * a container with gtk_widget_set_parent(), to avoid mapping
7410 * children unnecessary before immediately unmapping them. However
7411 * it will be reset to its default state of %TRUE when the widget
7412 * is removed from a container.
7414 * Note that changing the child visibility of a widget does not
7415 * queue a resize on the widget. Most of the time, the size of
7416 * a widget is computed from all visible children, whether or
7417 * not they are mapped. If this is not the case, the container
7418 * can queue a resize itself.
7420 * This function is only useful for container implementations and
7421 * never should be called by an application.
7424 gtk_widget_set_child_visible (GtkWidget *widget,
7425 gboolean is_visible)
7427 g_return_if_fail (GTK_IS_WIDGET (widget));
7428 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7430 g_object_ref (widget);
7433 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7436 GtkWidget *toplevel;
7438 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7440 toplevel = gtk_widget_get_toplevel (widget);
7441 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7442 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7445 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
7447 if (GTK_WIDGET_MAPPED (widget->parent) &&
7448 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7449 GTK_WIDGET_VISIBLE (widget))
7450 gtk_widget_map (widget);
7452 gtk_widget_unmap (widget);
7455 g_object_unref (widget);
7459 * gtk_widget_get_child_visible:
7460 * @widget: a #GtkWidget
7462 * Gets the value set with gtk_widget_set_child_visible().
7463 * If you feel a need to use this function, your code probably
7464 * needs reorganization.
7466 * This function is only useful for container implementations and
7467 * never should be called by an application.
7469 * Return value: %TRUE if the widget is mapped with the parent.
7472 gtk_widget_get_child_visible (GtkWidget *widget)
7474 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7476 return GTK_WIDGET_CHILD_VISIBLE (widget);
7480 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7482 GtkWidget *toplevel;
7484 toplevel = gtk_widget_get_toplevel (widget);
7486 if (gtk_widget_is_toplevel (toplevel))
7488 if (GTK_IS_WINDOW (toplevel))
7489 return GTK_WINDOW (toplevel)->screen;
7490 else if (GTK_IS_INVISIBLE (toplevel))
7491 return GTK_INVISIBLE (widget)->screen;
7498 * gtk_widget_get_screen:
7499 * @widget: a #GtkWidget
7501 * Get the #GdkScreen from the toplevel window associated with
7502 * this widget. This function can only be called after the widget
7503 * has been added to a widget hierarchy with a #GtkWindow
7506 * In general, you should only create screen specific
7507 * resources when a widget has been realized, and you should
7508 * free those resources when the widget is unrealized.
7510 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7515 gtk_widget_get_screen (GtkWidget *widget)
7519 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7521 screen = gtk_widget_get_screen_unchecked (widget);
7528 g_warning (G_STRLOC ": Can't get associated screen"
7529 " for a widget unless it is inside a toplevel GtkWindow\n"
7530 " widget type is %s associated top level type is %s",
7531 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7532 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7534 return gdk_screen_get_default ();
7539 * gtk_widget_has_screen:
7540 * @widget: a #GtkWidget
7542 * Checks whether there is a #GdkScreen is associated with
7543 * this widget. All toplevel widgets have an associated
7544 * screen, and all widgets added into a hierarchy with a toplevel
7545 * window at the top.
7547 * Return value: %TRUE if there is a #GdkScreen associcated
7553 gtk_widget_has_screen (GtkWidget *widget)
7555 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7557 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7561 * gtk_widget_get_display:
7562 * @widget: a #GtkWidget
7564 * Get the #GdkDisplay for the toplevel window associated with
7565 * this widget. This function can only be called after the widget
7566 * has been added to a widget hierarchy with a #GtkWindow at the top.
7568 * In general, you should only create display specific
7569 * resources when a widget has been realized, and you should
7570 * free those resources when the widget is unrealized.
7572 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7577 gtk_widget_get_display (GtkWidget *widget)
7579 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7581 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7585 * gtk_widget_get_root_window:
7586 * @widget: a #GtkWidget
7588 * Get the root window where this widget is located. This function can
7589 * only be called after the widget has been added to a widget
7590 * hierarchy with #GtkWindow at the top.
7592 * The root window is useful for such purposes as creating a popup
7593 * #GdkWindow associated with the window. In general, you should only
7594 * create display specific resources when a widget has been realized,
7595 * and you should free those resources when the widget is unrealized.
7597 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7602 gtk_widget_get_root_window (GtkWidget *widget)
7604 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7606 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7610 * gtk_widget_child_focus:
7611 * @widget: a #GtkWidget
7612 * @direction: direction of focus movement
7614 * This function is used by custom widget implementations; if you're
7615 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7616 * to a particular widget, and gtk_container_set_focus_chain() to
7617 * change the focus tab order. So you may want to investigate those
7618 * functions instead.
7620 * gtk_widget_child_focus() is called by containers as the user moves
7621 * around the window using keyboard shortcuts. @direction indicates
7622 * what kind of motion is taking place (up, down, left, right, tab
7623 * forward, tab backward). gtk_widget_child_focus() emits the
7624 * #GtkWidget::focus" signal; widgets override the default handler
7625 * for this signal in order to implement appropriate focus behavior.
7627 * The default ::focus handler for a widget should return %TRUE if
7628 * moving in @direction left the focus on a focusable location inside
7629 * that widget, and %FALSE if moving in @direction moved the focus
7630 * outside the widget. If returning %TRUE, widgets normally
7631 * call gtk_widget_grab_focus() to place the focus accordingly;
7632 * if returning %FALSE, they don't modify the current focus location.
7634 * This function replaces gtk_container_focus() from GTK+ 1.2.
7635 * It was necessary to check that the child was visible, sensitive,
7636 * and focusable before calling gtk_container_focus().
7637 * gtk_widget_child_focus() returns %FALSE if the widget is not
7638 * currently in a focusable state, so there's no need for those checks.
7640 * Return value: %TRUE if focus ended up inside @widget
7643 gtk_widget_child_focus (GtkWidget *widget,
7644 GtkDirectionType direction)
7646 gboolean return_val;
7648 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7650 if (!GTK_WIDGET_VISIBLE (widget) ||
7651 !gtk_widget_is_sensitive (widget))
7654 /* child widgets must set CAN_FOCUS, containers
7655 * don't have to though.
7657 if (!GTK_IS_CONTAINER (widget) &&
7658 !gtk_widget_get_can_focus (widget))
7661 g_signal_emit (widget,
7662 widget_signals[FOCUS],
7664 direction, &return_val);
7670 * gtk_widget_keynav_failed:
7671 * @widget: a #GtkWidget
7672 * @direction: direction of focus movement
7674 * This function should be called whenever keyboard navigation within
7675 * a single widget hits a boundary. The function emits the
7676 * #GtkWidget::keynav-failed signal on the widget and its return
7677 * value should be interpreted in a way similar to the return value of
7678 * gtk_widget_child_focus():
7680 * When %TRUE is returned, stay in the widget, the failed keyboard
7681 * navigation is Ok and/or there is nowhere we can/should move the
7684 * When %FALSE is returned, the caller should continue with keyboard
7685 * navigation outside the widget, e.g. by calling
7686 * gtk_widget_child_focus() on the widget's toplevel.
7688 * The default ::keynav-failed handler returns %TRUE for
7689 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7690 * values of #GtkDirectionType, it looks at the
7691 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7692 * if the setting is %TRUE. This way the entire user interface
7693 * becomes cursor-navigatable on input devices such as mobile phones
7694 * which only have cursor keys but no tab key.
7696 * Whenever the default handler returns %TRUE, it also calls
7697 * gtk_widget_error_bell() to notify the user of the failed keyboard
7700 * A use case for providing an own implementation of ::keynav-failed
7701 * (either by connecting to it or by overriding it) would be a row of
7702 * #GtkEntry widgets where the user should be able to navigate the
7703 * entire row with the cursor keys, as e.g. known from user interfaces
7704 * that require entering license keys.
7706 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7707 * if the emitting widget should try to handle the keyboard
7708 * navigation attempt in its parent container(s).
7713 gtk_widget_keynav_failed (GtkWidget *widget,
7714 GtkDirectionType direction)
7716 gboolean return_val;
7718 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7720 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7721 direction, &return_val);
7727 * gtk_widget_error_bell:
7728 * @widget: a #GtkWidget
7730 * Notifies the user about an input-related error on this widget.
7731 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7732 * gdk_window_beep(), otherwise it does nothing.
7734 * Note that the effect of gdk_window_beep() can be configured in many
7735 * ways, depending on the windowing backend and the desktop environment
7736 * or window manager that is used.
7741 gtk_widget_error_bell (GtkWidget *widget)
7743 GtkSettings* settings;
7746 g_return_if_fail (GTK_IS_WIDGET (widget));
7748 settings = gtk_widget_get_settings (widget);
7752 g_object_get (settings,
7753 "gtk-error-bell", &beep,
7756 if (beep && widget->window)
7757 gdk_window_beep (widget->window);
7761 * gtk_widget_set_uposition:
7762 * @widget: a #GtkWidget
7763 * @x: x position; -1 to unset x; -2 to leave x unchanged
7764 * @y: y position; -1 to unset y; -2 to leave y unchanged
7767 * Sets the position of a widget. The funny "u" in the name comes from
7768 * the "user position" hint specified by the X Window System, and
7769 * exists for legacy reasons. This function doesn't work if a widget
7770 * is inside a container; it's only really useful on #GtkWindow.
7772 * Don't use this function to center dialogs over the main application
7773 * window; most window managers will do the centering on your behalf
7774 * if you call gtk_window_set_transient_for(), and it's really not
7775 * possible to get the centering to work correctly in all cases from
7776 * application code. But if you insist, use gtk_window_set_position()
7777 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7780 * Note that although @x and @y can be individually unset, the position
7781 * is not honoured unless both @x and @y are set.
7784 gtk_widget_set_uposition (GtkWidget *widget,
7788 /* FIXME this function is the only place that aux_info->x and
7789 * aux_info->y are even used I believe, and this function is
7790 * deprecated. Should be cleaned up.
7792 * (Actually, size_allocate uses them) -Yosh
7795 GtkWidgetAuxInfo *aux_info;
7797 g_return_if_fail (GTK_IS_WIDGET (widget));
7799 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7804 aux_info->x_set = FALSE;
7807 aux_info->x_set = TRUE;
7815 aux_info->y_set = FALSE;
7818 aux_info->y_set = TRUE;
7823 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7824 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7826 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7827 gtk_widget_size_allocate (widget, &widget->allocation);
7831 gtk_widget_set_usize_internal (GtkWidget *widget,
7835 GtkWidgetAuxInfo *aux_info;
7836 gboolean changed = FALSE;
7838 g_object_freeze_notify (G_OBJECT (widget));
7840 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7842 if (width > -2 && aux_info->width != width)
7844 g_object_notify (G_OBJECT (widget), "width-request");
7845 aux_info->width = width;
7848 if (height > -2 && aux_info->height != height)
7850 g_object_notify (G_OBJECT (widget), "height-request");
7851 aux_info->height = height;
7855 if (GTK_WIDGET_VISIBLE (widget) && changed)
7856 gtk_widget_queue_resize (widget);
7858 g_object_thaw_notify (G_OBJECT (widget));
7862 * gtk_widget_set_usize:
7863 * @widget: a #GtkWidget
7864 * @width: minimum width, or -1 to unset
7865 * @height: minimum height, or -1 to unset
7867 * Sets the minimum size of a widget; that is, the widget's size
7868 * request will be @width by @height. You can use this function to
7869 * force a widget to be either larger or smaller than it is. The
7870 * strange "usize" name dates from the early days of GTK+, and derives
7871 * from X Window System terminology. In many cases,
7872 * gtk_window_set_default_size() is a better choice for toplevel
7873 * windows than this function; setting the default size will still
7874 * allow users to shrink the window. Setting the usize will force them
7875 * to leave the window at least as large as the usize. When dealing
7876 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7879 * Note the inherent danger of setting any fixed size - themes,
7880 * translations into other languages, different fonts, and user action
7881 * can all change the appropriate size for a given widget. So, it's
7882 * basically impossible to hardcode a size that will always be
7885 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7888 gtk_widget_set_usize (GtkWidget *widget,
7892 g_return_if_fail (GTK_IS_WIDGET (widget));
7894 gtk_widget_set_usize_internal (widget, width, height);
7898 * gtk_widget_set_size_request:
7899 * @widget: a #GtkWidget
7900 * @width: width @widget should request, or -1 to unset
7901 * @height: height @widget should request, or -1 to unset
7903 * Sets the minimum size of a widget; that is, the widget's size
7904 * request will be @width by @height. You can use this function to
7905 * force a widget to be either larger or smaller than it normally
7908 * In most cases, gtk_window_set_default_size() is a better choice for
7909 * toplevel windows than this function; setting the default size will
7910 * still allow users to shrink the window. Setting the size request
7911 * will force them to leave the window at least as large as the size
7912 * request. When dealing with window sizes,
7913 * gtk_window_set_geometry_hints() can be a useful function as well.
7915 * Note the inherent danger of setting any fixed size - themes,
7916 * translations into other languages, different fonts, and user action
7917 * can all change the appropriate size for a given widget. So, it's
7918 * basically impossible to hardcode a size that will always be
7921 * The size request of a widget is the smallest size a widget can
7922 * accept while still functioning well and drawing itself correctly.
7923 * However in some strange cases a widget may be allocated less than
7924 * its requested size, and in many cases a widget may be allocated more
7925 * space than it requested.
7927 * If the size request in a given direction is -1 (unset), then
7928 * the "natural" size request of the widget will be used instead.
7930 * Widgets can't actually be allocated a size less than 1 by 1, but
7931 * you can pass 0,0 to this function to mean "as small as possible."
7934 gtk_widget_set_size_request (GtkWidget *widget,
7938 g_return_if_fail (GTK_IS_WIDGET (widget));
7939 g_return_if_fail (width >= -1);
7940 g_return_if_fail (height >= -1);
7947 gtk_widget_set_usize_internal (widget, width, height);
7952 * gtk_widget_get_size_request:
7953 * @widget: a #GtkWidget
7954 * @width: (allow-none): (out): return location for width, or %NULL
7955 * @height: (allow-none): (out): return location for height, or %NULL
7957 * Gets the size request that was explicitly set for the widget using
7958 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7959 * @height indicates that that dimension has not been set explicitly
7960 * and the natural requisition of the widget will be used intead. See
7961 * gtk_widget_set_size_request(). To get the size a widget will
7962 * actually use, call gtk_widget_size_request() instead of
7966 gtk_widget_get_size_request (GtkWidget *widget,
7970 GtkWidgetAuxInfo *aux_info;
7972 g_return_if_fail (GTK_IS_WIDGET (widget));
7974 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7977 *width = aux_info ? aux_info->width : -1;
7980 *height = aux_info ? aux_info->height : -1;
7984 * gtk_widget_set_events:
7985 * @widget: a #GtkWidget
7986 * @events: event mask
7988 * Sets the event mask (see #GdkEventMask) for a widget. The event
7989 * mask determines which events a widget will receive. Keep in mind
7990 * that different widgets have different default event masks, and by
7991 * changing the event mask you may disrupt a widget's functionality,
7992 * so be careful. This function must be called while a widget is
7993 * unrealized. Consider gtk_widget_add_events() for widgets that are
7994 * already realized, or if you want to preserve the existing event
7995 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7996 * to get events on those widgets, place them inside a #GtkEventBox
7997 * and receive events on the event box.
8000 gtk_widget_set_events (GtkWidget *widget,
8003 g_return_if_fail (GTK_IS_WIDGET (widget));
8004 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
8006 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8007 GINT_TO_POINTER (events));
8008 g_object_notify (G_OBJECT (widget), "events");
8012 gtk_widget_add_events_internal (GtkWidget *widget,
8018 for (l = window_list; l != NULL; l = l->next)
8020 GdkWindow *window = l->data;
8023 gdk_window_get_user_data (window, &user_data);
8024 if (user_data == widget)
8028 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8030 children = gdk_window_get_children (window);
8031 gtk_widget_add_events_internal (widget, events, children);
8032 g_list_free (children);
8038 * gtk_widget_add_events:
8039 * @widget: a #GtkWidget
8040 * @events: an event mask, see #GdkEventMask
8042 * Adds the events in the bitfield @events to the event mask for
8043 * @widget. See gtk_widget_set_events() for details.
8046 gtk_widget_add_events (GtkWidget *widget,
8051 g_return_if_fail (GTK_IS_WIDGET (widget));
8053 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8054 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8055 GINT_TO_POINTER (old_events | events));
8057 if (GTK_WIDGET_REALIZED (widget))
8061 if (!gtk_widget_get_has_window (widget))
8062 window_list = gdk_window_get_children (widget->window);
8064 window_list = g_list_prepend (NULL, widget->window);
8066 gtk_widget_add_events_internal (widget, events, window_list);
8068 g_list_free (window_list);
8071 g_object_notify (G_OBJECT (widget), "events");
8075 * gtk_widget_set_extension_events:
8076 * @widget: a #GtkWidget
8077 * @mode: bitfield of extension events to receive
8079 * Sets the extension events mask to @mode. See #GdkExtensionMode
8080 * and gdk_input_set_extension_events().
8083 gtk_widget_set_extension_events (GtkWidget *widget,
8084 GdkExtensionMode mode)
8086 g_return_if_fail (GTK_IS_WIDGET (widget));
8088 if (GTK_WIDGET_REALIZED (widget))
8089 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8091 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8092 GINT_TO_POINTER (mode));
8093 g_object_notify (G_OBJECT (widget), "extension-events");
8097 * gtk_widget_get_toplevel:
8098 * @widget: a #GtkWidget
8100 * This function returns the topmost widget in the container hierarchy
8101 * @widget is a part of. If @widget has no parent widgets, it will be
8102 * returned as the topmost widget. No reference will be added to the
8103 * returned widget; it should not be unreferenced.
8105 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8106 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8108 * %NULL if @widget wasn't inside a toplevel window, and if the
8109 * window was inside a #GtkWindow-derived widget which was in turn
8110 * inside the toplevel #GtkWindow. While the second case may
8111 * seem unlikely, it actually happens when a #GtkPlug is embedded
8112 * inside a #GtkSocket within the same application.
8114 * To reliably find the toplevel #GtkWindow, use
8115 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8116 * is set on the result.
8118 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8119 * if (gtk_widget_is_toplevel (toplevel))
8121 * /* Perform action on toplevel. */
8125 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8126 * if there's no ancestor.
8129 gtk_widget_get_toplevel (GtkWidget *widget)
8131 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8133 while (widget->parent)
8134 widget = widget->parent;
8140 * gtk_widget_get_ancestor:
8141 * @widget: a #GtkWidget
8142 * @widget_type: ancestor type
8144 * Gets the first ancestor of @widget with type @widget_type. For example,
8145 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8146 * the first #GtkBox that's an ancestor of @widget. No reference will be
8147 * added to the returned widget; it should not be unreferenced. See note
8148 * about checking for a toplevel #GtkWindow in the docs for
8149 * gtk_widget_get_toplevel().
8151 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8152 * considers @widget to be an ancestor of itself.
8154 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8157 gtk_widget_get_ancestor (GtkWidget *widget,
8160 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8162 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8163 widget = widget->parent;
8165 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8172 * gtk_widget_get_colormap:
8173 * @widget: a #GtkWidget
8175 * Gets the colormap that will be used to render @widget. No reference will
8176 * be added to the returned colormap; it should not be unreferenced.
8178 * Return value: (transfer none): the colormap used by @widget
8181 gtk_widget_get_colormap (GtkWidget *widget)
8183 GdkColormap *colormap;
8184 GtkWidget *tmp_widget;
8186 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8190 colormap = gdk_drawable_get_colormap (widget->window);
8191 /* If window was destroyed previously, we'll get NULL here */
8196 tmp_widget = widget;
8199 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8203 tmp_widget= tmp_widget->parent;
8206 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8210 * gtk_widget_get_visual:
8211 * @widget: a #GtkWidget
8213 * Gets the visual that will be used to render @widget.
8215 * Return value: (transfer none): the visual for @widget
8218 gtk_widget_get_visual (GtkWidget *widget)
8220 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8222 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8226 * gtk_widget_get_settings:
8227 * @widget: a #GtkWidget
8229 * Gets the settings object holding the settings (global property
8230 * settings, RC file information, etc) used for this widget.
8232 * Note that this function can only be called when the #GtkWidget
8233 * is attached to a toplevel, since the settings object is specific
8234 * to a particular #GdkScreen.
8236 * Return value: (transfer none): the relevant #GtkSettings object
8239 gtk_widget_get_settings (GtkWidget *widget)
8241 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8243 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8247 * gtk_widget_set_colormap:
8248 * @widget: a #GtkWidget
8249 * @colormap: a colormap
8251 * Sets the colormap for the widget to the given value. Widget must not
8252 * have been previously realized. This probably should only be used
8253 * from an <function>init()</function> function (i.e. from the constructor
8257 gtk_widget_set_colormap (GtkWidget *widget,
8258 GdkColormap *colormap)
8260 g_return_if_fail (GTK_IS_WIDGET (widget));
8261 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
8262 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8264 g_object_ref (colormap);
8266 g_object_set_qdata_full (G_OBJECT (widget),
8273 * gtk_widget_get_events:
8274 * @widget: a #GtkWidget
8276 * Returns the event mask for the widget (a bitfield containing flags
8277 * from the #GdkEventMask enumeration). These are the events that the widget
8280 * Return value: event mask for @widget
8283 gtk_widget_get_events (GtkWidget *widget)
8285 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8287 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8291 * gtk_widget_get_extension_events:
8292 * @widget: a #GtkWidget
8294 * Retrieves the extension events the widget will receive; see
8295 * gdk_input_set_extension_events().
8297 * Return value: extension events for @widget
8300 gtk_widget_get_extension_events (GtkWidget *widget)
8302 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8304 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8308 * gtk_widget_get_pointer:
8309 * @widget: a #GtkWidget
8310 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8311 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8313 * Obtains the location of the mouse pointer in widget coordinates.
8314 * Widget coordinates are a bit odd; for historical reasons, they are
8315 * defined as @widget->window coordinates for widgets that are not
8316 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8317 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8320 gtk_widget_get_pointer (GtkWidget *widget,
8324 g_return_if_fail (GTK_IS_WIDGET (widget));
8331 if (GTK_WIDGET_REALIZED (widget))
8333 gdk_window_get_pointer (widget->window, x, y, NULL);
8335 if (!gtk_widget_get_has_window (widget))
8338 *x -= widget->allocation.x;
8340 *y -= widget->allocation.y;
8346 * gtk_widget_is_ancestor:
8347 * @widget: a #GtkWidget
8348 * @ancestor: another #GtkWidget
8350 * Determines whether @widget is somewhere inside @ancestor, possibly with
8351 * intermediate containers.
8353 * Return value: %TRUE if @ancestor contains @widget as a child,
8354 * grandchild, great grandchild, etc.
8357 gtk_widget_is_ancestor (GtkWidget *widget,
8358 GtkWidget *ancestor)
8360 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8361 g_return_val_if_fail (ancestor != NULL, FALSE);
8365 if (widget->parent == ancestor)
8367 widget = widget->parent;
8373 static GQuark quark_composite_name = 0;
8376 * gtk_widget_set_composite_name:
8377 * @widget: a #GtkWidget.
8378 * @name: the name to set
8380 * Sets a widgets composite name. The widget must be
8381 * a composite child of its parent; see gtk_widget_push_composite_child().
8384 gtk_widget_set_composite_name (GtkWidget *widget,
8387 g_return_if_fail (GTK_IS_WIDGET (widget));
8388 g_return_if_fail ((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8389 g_return_if_fail (name != NULL);
8391 if (!quark_composite_name)
8392 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8394 g_object_set_qdata_full (G_OBJECT (widget),
8395 quark_composite_name,
8401 * gtk_widget_get_composite_name:
8402 * @widget: a #GtkWidget
8404 * Obtains the composite name of a widget.
8406 * Returns: the composite name of @widget, or %NULL if @widget is not
8407 * a composite child. The string should be freed when it is no
8411 gtk_widget_get_composite_name (GtkWidget *widget)
8413 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8415 if (((GTK_WIDGET_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8416 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8423 * gtk_widget_push_composite_child:
8425 * Makes all newly-created widgets as composite children until
8426 * the corresponding gtk_widget_pop_composite_child() call.
8428 * A composite child is a child that's an implementation detail of the
8429 * container it's inside and should not be visible to people using the
8430 * container. Composite children aren't treated differently by GTK (but
8431 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8432 * builders might want to treat them in a different way.
8434 * Here is a simple example:
8436 * gtk_widget_push_composite_child ();
8437 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8438 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8439 * gtk_widget_pop_composite_child ();
8440 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8441 * GTK_WIDGET (scrolled_window));
8442 * g_object_ref (scrolled_window->hscrollbar);
8446 gtk_widget_push_composite_child (void)
8448 composite_child_stack++;
8452 * gtk_widget_pop_composite_child:
8454 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8457 gtk_widget_pop_composite_child (void)
8459 if (composite_child_stack)
8460 composite_child_stack--;
8464 * gtk_widget_push_colormap:
8465 * @cmap: a #GdkColormap
8467 * Pushes @cmap onto a global stack of colormaps; the topmost
8468 * colormap on the stack will be used to create all widgets.
8469 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8470 * reason to use this function.
8473 gtk_widget_push_colormap (GdkColormap *cmap)
8475 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8477 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8481 * gtk_widget_pop_colormap:
8483 * Removes a colormap pushed with gtk_widget_push_colormap().
8486 gtk_widget_pop_colormap (void)
8489 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8493 * gtk_widget_set_default_colormap:
8494 * @colormap: a #GdkColormap
8496 * Sets the default colormap to use when creating widgets.
8497 * gtk_widget_push_colormap() is a better function to use if
8498 * you only want to affect a few widgets, rather than all widgets.
8501 gtk_widget_set_default_colormap (GdkColormap *colormap)
8503 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8505 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8510 * gtk_widget_get_default_colormap:
8512 * Obtains the default colormap used to create widgets.
8514 * Return value: (transfer none): default widget colormap
8517 gtk_widget_get_default_colormap (void)
8519 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8523 * gtk_widget_get_default_visual:
8525 * Obtains the visual of the default colormap. Not really useful;
8526 * used to be useful before gdk_colormap_get_visual() existed.
8528 * Return value: (transfer none): visual of the default colormap
8531 gtk_widget_get_default_visual (void)
8533 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8537 gtk_widget_emit_direction_changed (GtkWidget *widget,
8538 GtkTextDirection old_dir)
8540 gtk_widget_update_pango_context (widget);
8542 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8546 * gtk_widget_set_direction:
8547 * @widget: a #GtkWidget
8548 * @dir: the new direction
8550 * Sets the reading direction on a particular widget. This direction
8551 * controls the primary direction for widgets containing text,
8552 * and also the direction in which the children of a container are
8553 * packed. The ability to set the direction is present in order
8554 * so that correct localization into languages with right-to-left
8555 * reading directions can be done. Generally, applications will
8556 * let the default reading direction present, except for containers
8557 * where the containers are arranged in an order that is explicitely
8558 * visual rather than logical (such as buttons for text justification).
8560 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8561 * set by gtk_widget_set_default_direction() will be used.
8564 gtk_widget_set_direction (GtkWidget *widget,
8565 GtkTextDirection dir)
8567 GtkTextDirection old_dir;
8569 g_return_if_fail (GTK_IS_WIDGET (widget));
8570 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8572 old_dir = gtk_widget_get_direction (widget);
8574 if (dir == GTK_TEXT_DIR_NONE)
8575 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8578 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8579 if (dir == GTK_TEXT_DIR_LTR)
8580 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8582 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8585 if (old_dir != gtk_widget_get_direction (widget))
8586 gtk_widget_emit_direction_changed (widget, old_dir);
8590 * gtk_widget_get_direction:
8591 * @widget: a #GtkWidget
8593 * Gets the reading direction for a particular widget. See
8594 * gtk_widget_set_direction().
8596 * Return value: the reading direction for the widget.
8599 gtk_widget_get_direction (GtkWidget *widget)
8601 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8603 if (GTK_WIDGET_DIRECTION_SET (widget))
8604 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8606 return gtk_default_direction;
8610 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8612 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8614 g_object_ref (widget);
8616 if (!GTK_WIDGET_DIRECTION_SET (widget))
8617 gtk_widget_emit_direction_changed (widget, old_dir);
8619 if (GTK_IS_CONTAINER (widget))
8620 gtk_container_forall (GTK_CONTAINER (widget),
8621 gtk_widget_set_default_direction_recurse,
8624 g_object_unref (widget);
8628 * gtk_widget_set_default_direction:
8629 * @dir: the new default direction. This cannot be
8630 * %GTK_TEXT_DIR_NONE.
8632 * Sets the default reading direction for widgets where the
8633 * direction has not been explicitly set by gtk_widget_set_direction().
8636 gtk_widget_set_default_direction (GtkTextDirection dir)
8638 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8640 if (dir != gtk_default_direction)
8642 GList *toplevels, *tmp_list;
8643 GtkTextDirection old_dir = gtk_default_direction;
8645 gtk_default_direction = dir;
8647 tmp_list = toplevels = gtk_window_list_toplevels ();
8648 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8652 gtk_widget_set_default_direction_recurse (tmp_list->data,
8653 GUINT_TO_POINTER (old_dir));
8654 g_object_unref (tmp_list->data);
8655 tmp_list = tmp_list->next;
8658 g_list_free (toplevels);
8663 * gtk_widget_get_default_direction:
8665 * Obtains the current default reading direction. See
8666 * gtk_widget_set_default_direction().
8668 * Return value: the current default direction.
8671 gtk_widget_get_default_direction (void)
8673 return gtk_default_direction;
8677 gtk_widget_dispose (GObject *object)
8679 GtkWidget *widget = GTK_WIDGET (object);
8682 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8683 else if (GTK_WIDGET_VISIBLE (widget))
8684 gtk_widget_hide (widget);
8686 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8687 if (GTK_WIDGET_REALIZED (widget))
8688 gtk_widget_unrealize (widget);
8690 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8694 gtk_widget_real_destroy (GtkObject *object)
8696 /* gtk_object_destroy() will already hold a refcount on object */
8697 GtkWidget *widget = GTK_WIDGET (object);
8699 /* wipe accelerator closures (keep order) */
8700 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8701 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8703 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8704 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8706 gtk_grab_remove (widget);
8708 g_object_unref (widget->style);
8709 widget->style = gtk_widget_get_default_style ();
8710 g_object_ref (widget->style);
8712 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8716 gtk_widget_finalize (GObject *object)
8718 GtkWidget *widget = GTK_WIDGET (object);
8719 GtkWidgetAuxInfo *aux_info;
8720 GtkAccessible *accessible;
8722 gtk_grab_remove (widget);
8724 g_object_unref (widget->style);
8725 widget->style = NULL;
8727 g_free (widget->name);
8729 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8731 gtk_widget_aux_info_destroy (aux_info);
8733 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8735 g_object_unref (accessible);
8737 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8740 /*****************************************
8741 * gtk_widget_real_map:
8746 *****************************************/
8749 gtk_widget_real_map (GtkWidget *widget)
8751 g_assert (GTK_WIDGET_REALIZED (widget));
8753 if (!GTK_WIDGET_MAPPED (widget))
8755 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
8757 if (gtk_widget_get_has_window (widget))
8758 gdk_window_show (widget->window);
8762 /*****************************************
8763 * gtk_widget_real_unmap:
8768 *****************************************/
8771 gtk_widget_real_unmap (GtkWidget *widget)
8773 if (GTK_WIDGET_MAPPED (widget))
8775 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8777 if (gtk_widget_get_has_window (widget))
8778 gdk_window_hide (widget->window);
8782 /*****************************************
8783 * gtk_widget_real_realize:
8788 *****************************************/
8791 gtk_widget_real_realize (GtkWidget *widget)
8793 g_assert (!gtk_widget_get_has_window (widget));
8795 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8798 widget->window = gtk_widget_get_parent_window (widget);
8799 g_object_ref (widget->window);
8801 widget->style = gtk_style_attach (widget->style, widget->window);
8804 /*****************************************
8805 * gtk_widget_real_unrealize:
8810 *****************************************/
8813 gtk_widget_real_unrealize (GtkWidget *widget)
8815 if (GTK_WIDGET_MAPPED (widget))
8816 gtk_widget_real_unmap (widget);
8818 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8820 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8823 /* We must do unrealize child widget BEFORE container widget.
8824 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8825 * So, unrealizing container widget bofore its children causes the problem
8826 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8829 if (GTK_IS_CONTAINER (widget))
8830 gtk_container_forall (GTK_CONTAINER (widget),
8831 (GtkCallback) gtk_widget_unrealize,
8834 gtk_style_detach (widget->style);
8835 if (gtk_widget_get_has_window (widget))
8837 gdk_window_set_user_data (widget->window, NULL);
8838 gdk_window_destroy (widget->window);
8839 widget->window = NULL;
8843 g_object_unref (widget->window);
8844 widget->window = NULL;
8847 gtk_selection_remove_all (widget);
8849 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8853 gtk_widget_real_size_request (GtkWidget *widget,
8854 GtkRequisition *requisition)
8856 requisition->width = widget->requisition.width;
8857 requisition->height = widget->requisition.height;
8861 * _gtk_widget_peek_colormap:
8863 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8865 * Return value: the currently pushed colormap, or %NULL if there is none.
8868 _gtk_widget_peek_colormap (void)
8871 return (GdkColormap*) colormap_stack->data;
8876 * _gtk_widget_set_pointer_window:
8877 * @widget: a #GtkWidget.
8878 * @pointer_window: the new pointer window.
8880 * Sets pointer window for @widget. Does not ref @pointer_window.
8881 * Actually stores it on the #GdkScreen, but you don't need to know that.
8884 _gtk_widget_set_pointer_window (GtkWidget *widget,
8885 GdkWindow *pointer_window)
8887 g_return_if_fail (GTK_IS_WIDGET (widget));
8889 if (GTK_WIDGET_REALIZED (widget))
8891 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8893 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8899 * _gtk_widget_get_pointer_window:
8900 * @widget: a #GtkWidget.
8902 * Return value: the pointer window set on the #GdkScreen @widget is attached
8906 _gtk_widget_get_pointer_window (GtkWidget *widget)
8908 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8910 if (GTK_WIDGET_REALIZED (widget))
8912 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8914 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8921 synth_crossing (GtkWidget *widget,
8924 GdkCrossingMode mode,
8925 GdkNotifyType detail)
8929 event = gdk_event_new (type);
8931 event->crossing.window = g_object_ref (window);
8932 event->crossing.send_event = TRUE;
8933 event->crossing.subwindow = g_object_ref (window);
8934 event->crossing.time = GDK_CURRENT_TIME;
8935 event->crossing.x = event->crossing.y = 0;
8936 event->crossing.x_root = event->crossing.y_root = 0;
8937 event->crossing.mode = mode;
8938 event->crossing.detail = detail;
8939 event->crossing.focus = FALSE;
8940 event->crossing.state = 0;
8943 widget = gtk_get_event_widget (event);
8946 gtk_widget_event_internal (widget, event);
8948 gdk_event_free (event);
8952 * _gtk_widget_is_pointer_widget:
8953 * @widget: a #GtkWidget
8955 * Returns %TRUE if the pointer window belongs to @widget.
8958 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8960 if (GTK_WIDGET_HAS_POINTER (widget))
8965 win = _gtk_widget_get_pointer_window (widget);
8968 gdk_window_get_user_data (win, (gpointer *)&wid);
8978 * _gtk_widget_synthesize_crossing:
8979 * @from: the #GtkWidget the virtual pointer is leaving.
8980 * @to: the #GtkWidget the virtual pointer is moving to.
8981 * @mode: the #GdkCrossingMode to place on the synthesized events.
8983 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8985 * The real pointer window is the window that most recently received an enter notify
8986 * event. Windows that don't select for crossing events can't become the real
8987 * poiner window. The real pointer widget that owns the real pointer window. The
8988 * effective pointer window is the same as the real pointer window unless the real
8989 * pointer widget is either insensitive or there is a grab on a widget that is not
8990 * an ancestor of the real pointer widget (in which case the effective pointer
8991 * window should be the root window).
8993 * When the effective pointer window is the same as the real poiner window, we
8994 * receive crossing events from the windowing system. When the effective pointer
8995 * window changes to become different from the real pointer window we synthesize
8996 * crossing events, attempting to follow X protocol rules:
8998 * When the root window becomes the effective pointer window:
8999 * - leave notify on real pointer window, detail Ancestor
9000 * - leave notify on all of its ancestors, detail Virtual
9001 * - enter notify on root window, detail Inferior
9003 * When the root window ceases to be the effective pointer window:
9004 * - leave notify on root window, detail Inferior
9005 * - enter notify on all ancestors of real pointer window, detail Virtual
9006 * - enter notify on real pointer window, detail Ancestor
9009 _gtk_widget_synthesize_crossing (GtkWidget *from,
9011 GdkCrossingMode mode)
9013 GdkWindow *from_window = NULL, *to_window = NULL;
9015 g_return_if_fail (from != NULL || to != NULL);
9018 from_window = GTK_WIDGET_HAS_POINTER (from)
9019 ? _gtk_widget_get_pointer_window (from) : from->window;
9021 to_window = GTK_WIDGET_HAS_POINTER (to)
9022 ? _gtk_widget_get_pointer_window (to) : to->window;
9024 if (from_window == NULL && to_window == NULL)
9026 else if (from_window != NULL && to_window == NULL)
9028 GList *from_ancestors = NULL, *list;
9029 GdkWindow *from_ancestor = from_window;
9031 while (from_ancestor != NULL)
9033 from_ancestor = gdk_window_get_parent (from_ancestor);
9034 if (from_ancestor == NULL)
9036 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9039 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9040 mode, GDK_NOTIFY_ANCESTOR);
9041 for (list = g_list_last (from_ancestors); list; list = list->prev)
9043 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9044 mode, GDK_NOTIFY_VIRTUAL);
9047 /* XXX: enter/inferior on root window? */
9049 g_list_free (from_ancestors);
9051 else if (from_window == NULL && to_window != NULL)
9053 GList *to_ancestors = NULL, *list;
9054 GdkWindow *to_ancestor = to_window;
9056 while (to_ancestor != NULL)
9058 to_ancestor = gdk_window_get_parent (to_ancestor);
9059 if (to_ancestor == NULL)
9061 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9064 /* XXX: leave/inferior on root window? */
9066 for (list = to_ancestors; list; list = list->next)
9068 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9069 mode, GDK_NOTIFY_VIRTUAL);
9071 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9072 mode, GDK_NOTIFY_ANCESTOR);
9074 g_list_free (to_ancestors);
9076 else if (from_window == to_window)
9080 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9081 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9083 while (from_ancestor != NULL || to_ancestor != NULL)
9085 if (from_ancestor != NULL)
9087 from_ancestor = gdk_window_get_parent (from_ancestor);
9088 if (from_ancestor == to_window)
9091 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9093 if (to_ancestor != NULL)
9095 to_ancestor = gdk_window_get_parent (to_ancestor);
9096 if (to_ancestor == from_window)
9099 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9102 if (to_ancestor == from_window)
9104 if (mode != GDK_CROSSING_GTK_UNGRAB)
9105 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9106 mode, GDK_NOTIFY_INFERIOR);
9107 for (list = to_ancestors; list; list = list->next)
9108 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9109 mode, GDK_NOTIFY_VIRTUAL);
9110 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9111 mode, GDK_NOTIFY_ANCESTOR);
9113 else if (from_ancestor == to_window)
9115 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9116 mode, GDK_NOTIFY_ANCESTOR);
9117 for (list = g_list_last (from_ancestors); list; list = list->prev)
9119 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9120 mode, GDK_NOTIFY_VIRTUAL);
9122 if (mode != GDK_CROSSING_GTK_GRAB)
9123 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9124 mode, GDK_NOTIFY_INFERIOR);
9128 while (from_ancestors != NULL && to_ancestors != NULL
9129 && from_ancestors->data == to_ancestors->data)
9131 from_ancestors = g_list_delete_link (from_ancestors,
9133 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9136 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9137 mode, GDK_NOTIFY_NONLINEAR);
9139 for (list = g_list_last (from_ancestors); list; list = list->prev)
9141 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9142 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9144 for (list = to_ancestors; list; list = list->next)
9146 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9147 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9149 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9150 mode, GDK_NOTIFY_NONLINEAR);
9152 g_list_free (from_ancestors);
9153 g_list_free (to_ancestors);
9158 gtk_widget_propagate_state (GtkWidget *widget,
9161 guint8 old_state = GTK_WIDGET_STATE (widget);
9162 guint8 old_saved_state = widget->saved_state;
9164 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9165 * parent_sensitive==TRUE on a sensitive widget
9169 if (data->parent_sensitive)
9170 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9172 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9174 if (gtk_widget_is_sensitive (widget))
9176 if (data->state_restoration)
9177 GTK_WIDGET_STATE (widget) = widget->saved_state;
9179 GTK_WIDGET_STATE (widget) = data->state;
9183 if (!data->state_restoration)
9185 if (data->state != GTK_STATE_INSENSITIVE)
9186 widget->saved_state = data->state;
9188 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
9189 widget->saved_state = GTK_WIDGET_STATE (widget);
9190 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
9193 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9197 window = gtk_widget_get_toplevel (widget);
9198 if (window && gtk_widget_is_toplevel (window))
9199 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9202 if (old_state != GTK_WIDGET_STATE (widget) ||
9203 old_saved_state != widget->saved_state)
9205 g_object_ref (widget);
9207 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9208 gtk_grab_remove (widget);
9210 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9212 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9214 if (!gtk_widget_is_sensitive (widget))
9215 _gtk_widget_synthesize_crossing (widget, NULL,
9216 GDK_CROSSING_STATE_CHANGED);
9217 else if (old_state == GTK_STATE_INSENSITIVE)
9218 _gtk_widget_synthesize_crossing (NULL, widget,
9219 GDK_CROSSING_STATE_CHANGED);
9222 if (GTK_IS_CONTAINER (widget))
9224 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9225 if (data->use_forall)
9226 gtk_container_forall (GTK_CONTAINER (widget),
9227 (GtkCallback) gtk_widget_propagate_state,
9230 gtk_container_foreach (GTK_CONTAINER (widget),
9231 (GtkCallback) gtk_widget_propagate_state,
9234 g_object_unref (widget);
9239 * _gtk_widget_get_aux_info:
9240 * @widget: a #GtkWidget
9241 * @create: if %TRUE, create the structure if it doesn't exist
9243 * Get the #GtkWidgetAuxInfo structure for the widget.
9245 * Return value: the #GtkAuxInfo structure for the widget, or
9246 * %NULL if @create is %FALSE and one doesn't already exist.
9249 _gtk_widget_get_aux_info (GtkWidget *widget,
9252 GtkWidgetAuxInfo *aux_info;
9254 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9255 if (!aux_info && create)
9257 aux_info = g_slice_new (GtkWidgetAuxInfo);
9259 aux_info->width = -1;
9260 aux_info->height = -1;
9263 aux_info->x_set = FALSE;
9264 aux_info->y_set = FALSE;
9265 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9271 /*****************************************
9272 * gtk_widget_aux_info_destroy:
9277 *****************************************/
9280 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9282 g_slice_free (GtkWidgetAuxInfo, aux_info);
9286 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9288 g_object_unref (info->shape_mask);
9289 g_slice_free (GtkWidgetShapeInfo, info);
9293 * gtk_widget_shape_combine_mask:
9294 * @widget: a #GtkWidget
9295 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9296 * @offset_x: X position of shape mask with respect to @window
9297 * @offset_y: Y position of shape mask with respect to @window
9299 * Sets a shape for this widget's GDK window. This allows for
9300 * transparent windows etc., see gdk_window_shape_combine_mask()
9301 * for more information.
9304 gtk_widget_shape_combine_mask (GtkWidget *widget,
9305 GdkBitmap *shape_mask,
9309 GtkWidgetShapeInfo* shape_info;
9311 g_return_if_fail (GTK_IS_WIDGET (widget));
9312 /* set_shape doesn't work on widgets without gdk window */
9313 g_return_if_fail (gtk_widget_get_has_window (widget));
9317 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9320 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9322 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9326 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9328 shape_info = g_slice_new (GtkWidgetShapeInfo);
9329 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9330 (GDestroyNotify) gtk_widget_shape_info_destroy);
9332 shape_info->shape_mask = g_object_ref (shape_mask);
9333 shape_info->offset_x = offset_x;
9334 shape_info->offset_y = offset_y;
9336 /* set shape if widget has a gdk window already.
9337 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9340 gdk_window_shape_combine_mask (widget->window, shape_mask,
9341 offset_x, offset_y);
9346 * gtk_widget_input_shape_combine_mask:
9347 * @widget: a #GtkWidget
9348 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9349 * @offset_x: X position of shape mask with respect to @window
9350 * @offset_y: Y position of shape mask with respect to @window
9352 * Sets an input shape for this widget's GDK window. This allows for
9353 * windows which react to mouse click in a nonrectangular region, see
9354 * gdk_window_input_shape_combine_mask() for more information.
9359 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9360 GdkBitmap *shape_mask,
9364 GtkWidgetShapeInfo* shape_info;
9366 g_return_if_fail (GTK_IS_WIDGET (widget));
9367 /* set_shape doesn't work on widgets without gdk window */
9368 g_return_if_fail (gtk_widget_get_has_window (widget));
9373 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9375 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9379 shape_info = g_slice_new (GtkWidgetShapeInfo);
9380 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9382 (GDestroyNotify) gtk_widget_shape_info_destroy);
9384 shape_info->shape_mask = g_object_ref (shape_mask);
9385 shape_info->offset_x = offset_x;
9386 shape_info->offset_y = offset_y;
9388 /* set shape if widget has a gdk window already.
9389 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9392 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9393 offset_x, offset_y);
9399 gtk_reset_shapes_recurse (GtkWidget *widget,
9405 gdk_window_get_user_data (window, &data);
9409 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9410 for (list = gdk_window_peek_children (window); list; list = list->next)
9411 gtk_reset_shapes_recurse (widget, list->data);
9415 * gtk_widget_reset_shapes:
9416 * @widget: a #GtkWidget
9418 * Recursively resets the shape on this widget and its descendants.
9421 gtk_widget_reset_shapes (GtkWidget *widget)
9423 g_return_if_fail (GTK_IS_WIDGET (widget));
9424 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
9426 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9427 gtk_reset_shapes_recurse (widget, widget->window);
9432 * @widget: a #GtkWidget
9434 * Adds a reference to a widget. This function is exactly the same
9435 * as calling g_object_ref(), and exists mostly for historical
9436 * reasons. It can still be convenient to avoid casting a widget
9437 * to a #GObject, it saves a small amount of typing.
9439 * Return value: the widget that was referenced
9441 * Deprecated: 2.12: Use g_object_ref() instead.
9444 gtk_widget_ref (GtkWidget *widget)
9446 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9448 return (GtkWidget*) g_object_ref ((GObject*) widget);
9453 * @widget: a #GtkWidget
9455 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9457 * Deprecated: 2.12: Use g_object_unref() instead.
9460 gtk_widget_unref (GtkWidget *widget)
9462 g_return_if_fail (GTK_IS_WIDGET (widget));
9464 g_object_unref ((GObject*) widget);
9468 expose_window (GdkWindow *window)
9471 GList *l, *children;
9473 gboolean is_double_buffered;
9475 gdk_window_get_user_data (window, &user_data);
9478 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9480 is_double_buffered = FALSE;
9482 event.expose.type = GDK_EXPOSE;
9483 event.expose.window = g_object_ref (window);
9484 event.expose.send_event = FALSE;
9485 event.expose.count = 0;
9486 event.expose.area.x = 0;
9487 event.expose.area.y = 0;
9488 gdk_drawable_get_size (GDK_DRAWABLE (window),
9489 &event.expose.area.width,
9490 &event.expose.area.height);
9491 event.expose.region = gdk_region_rectangle (&event.expose.area);
9493 /* If this is not double buffered, force a double buffer so that
9494 redirection works. */
9495 if (!is_double_buffered)
9496 gdk_window_begin_paint_region (window, event.expose.region);
9498 gtk_main_do_event (&event);
9500 if (!is_double_buffered)
9501 gdk_window_end_paint (window);
9503 children = gdk_window_peek_children (window);
9504 for (l = children; l != NULL; l = l->next)
9506 GdkWindow *child = l->data;
9508 /* Don't expose input-only windows */
9509 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9510 expose_window (l->data);
9513 g_object_unref (window);
9517 * gtk_widget_get_snapshot:
9518 * @widget: a #GtkWidget
9519 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9521 * Create a #GdkPixmap of the contents of the widget and its children.
9523 * Works even if the widget is obscured. The depth and visual of the
9524 * resulting pixmap is dependent on the widget being snapshot and likely
9525 * differs from those of a target widget displaying the pixmap.
9526 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9527 * the pixmap to a visual independant representation.
9529 * The snapshot area used by this function is the @widget's allocation plus
9530 * any extra space occupied by additional windows belonging to this widget
9531 * (such as the arrows of a spin button).
9532 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9534 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9535 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9536 * interpreted widget relative. If width or height of @clip_rect are 0 or
9537 * negative, the width or height of the resulting pixmap will be shrunken
9538 * by the respective amount.
9539 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9540 * chop off 5 pixels at each side of the snapshot pixmap.
9541 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9542 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9543 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9544 * as a pure output parameter.
9546 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9548 * Return value: #GdkPixmap snapshot of the widget
9553 gtk_widget_get_snapshot (GtkWidget *widget,
9554 GdkRectangle *clip_rect)
9556 int x, y, width, height;
9557 GdkWindow *parent_window = NULL;
9559 GList *windows = NULL, *list;
9561 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9562 if (!GTK_WIDGET_VISIBLE (widget))
9565 /* the widget (and parent_window) must be realized to be drawable */
9566 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
9567 gtk_widget_realize (widget->parent);
9568 if (!GTK_WIDGET_REALIZED (widget))
9569 gtk_widget_realize (widget);
9571 /* determine snapshot rectangle */
9572 x = widget->allocation.x;
9573 y = widget->allocation.y;
9574 width = widget->allocation.width;
9575 height = widget->allocation.height;
9577 if (widget->parent && gtk_widget_get_has_window (widget))
9579 /* grow snapshot rectangle to cover all widget windows */
9580 parent_window = gtk_widget_get_parent_window (widget);
9581 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9583 GdkWindow *subwin = list->data;
9586 gdk_window_get_user_data (subwin, &windata);
9587 if (windata != widget)
9589 windows = g_list_prepend (windows, subwin);
9590 gdk_window_get_position (subwin, &wx, &wy);
9591 gdk_drawable_get_size (subwin, &ww, &wh);
9592 /* grow snapshot rectangle by extra widget sub window */
9603 if (x + width < wx + ww)
9604 width += wx + ww - (x + width);
9605 if (y + height < wy + wh)
9606 height += wy + wh - (y + height);
9609 else if (!widget->parent)
9610 x = y = 0; /* toplevel */
9612 /* at this point, (x,y,width,height) is the parent_window relative
9613 * snapshot area covering all of widget's windows.
9616 /* shrink snapshot size by clip_rectangle */
9619 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9620 clip.x = clip.x < 0 ? x : clip.x;
9621 clip.y = clip.y < 0 ? y : clip.y;
9622 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9623 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9626 /* offset clip_rect, so it's parent_window relative */
9627 if (clip_rect->x >= 0)
9628 clip.x += widget->allocation.x;
9629 if (clip_rect->y >= 0)
9630 clip.y += widget->allocation.y;
9632 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9634 g_list_free (windows);
9635 clip_rect->width = clip_rect->height = 0;
9636 return NULL; /* empty snapshot area */
9641 height = snap.height;
9644 /* render snapshot */
9645 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9646 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9648 GdkWindow *subwin = list->data;
9650 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9651 continue; /* Input only window */
9652 gdk_window_get_position (subwin, &wx, &wy);
9653 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9654 MAX (0, wx - x), MAX (0, wy - y), width, height);
9656 expose_window (subwin);
9658 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9660 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9661 expose_window (widget->window);
9663 for (list = windows; list; list = list->next)
9664 gdk_window_remove_redirection (list->data);
9665 if (!windows) /* NO_WINDOW || toplevel */
9666 gdk_window_remove_redirection (widget->window);
9667 g_list_free (windows);
9669 /* return pixmap and snapshot rectangle coordinates */
9674 clip_rect->width = width;
9675 clip_rect->height = height;
9678 /* offset clip_rect from parent_window so it's widget relative */
9679 clip_rect->x -= widget->allocation.x;
9680 clip_rect->y -= widget->allocation.y;
9683 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9684 G_OBJECT_TYPE_NAME (widget),
9685 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9694 * gtk_widget_class_install_style_property_parser:
9695 * @klass: a #GtkWidgetClass
9696 * @pspec: the #GParamSpec for the style property
9697 * @parser: the parser for the style property
9699 * Installs a style property on a widget class.
9702 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9704 GtkRcPropertyParser parser)
9706 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9707 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9708 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9709 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9711 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9713 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9714 G_OBJECT_CLASS_NAME (klass),
9719 g_param_spec_ref_sink (pspec);
9720 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9721 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9725 * gtk_widget_class_install_style_property:
9726 * @klass: a #GtkWidgetClass
9727 * @pspec: the #GParamSpec for the property
9729 * Installs a style property on a widget class. The parser for the
9730 * style property is determined by the value type of @pspec.
9733 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9736 GtkRcPropertyParser parser;
9738 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9739 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9741 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9743 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9747 * gtk_widget_class_find_style_property:
9748 * @klass: a #GtkWidgetClass
9749 * @property_name: the name of the style property to find
9750 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9751 * style property with that name.
9753 * Finds a style property of a widget class by name.
9758 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9759 const gchar *property_name)
9761 g_return_val_if_fail (property_name != NULL, NULL);
9763 return g_param_spec_pool_lookup (style_property_spec_pool,
9765 G_OBJECT_CLASS_TYPE (klass),
9770 * gtk_widget_class_list_style_properties:
9771 * @klass: a #GtkWidgetClass
9772 * @n_properties: location to return the number of style properties found
9773 * @returns: an newly allocated array of #GParamSpec*. The array must
9774 * be freed with g_free().
9776 * Returns all style properties of a widget class.
9781 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9782 guint *n_properties)
9784 GParamSpec **pspecs;
9787 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9788 G_OBJECT_CLASS_TYPE (klass),
9797 * gtk_widget_style_get_property:
9798 * @widget: a #GtkWidget
9799 * @property_name: the name of a style property
9800 * @value: location to return the property value
9802 * Gets the value of a style property of @widget.
9805 gtk_widget_style_get_property (GtkWidget *widget,
9806 const gchar *property_name,
9811 g_return_if_fail (GTK_IS_WIDGET (widget));
9812 g_return_if_fail (property_name != NULL);
9813 g_return_if_fail (G_IS_VALUE (value));
9815 g_object_ref (widget);
9816 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9818 G_OBJECT_TYPE (widget),
9821 g_warning ("%s: widget class `%s' has no property named `%s'",
9823 G_OBJECT_TYPE_NAME (widget),
9827 const GValue *peek_value;
9829 peek_value = _gtk_style_peek_property_value (widget->style,
9830 G_OBJECT_TYPE (widget),
9832 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9834 /* auto-conversion of the caller's value type
9836 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9837 g_value_copy (peek_value, value);
9838 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9839 g_value_transform (peek_value, value);
9841 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9843 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9844 G_VALUE_TYPE_NAME (value));
9846 g_object_unref (widget);
9850 * gtk_widget_style_get_valist:
9851 * @widget: a #GtkWidget
9852 * @first_property_name: the name of the first property to get
9853 * @var_args: a <type>va_list</type> of pairs of property names and
9854 * locations to return the property values, starting with the location
9855 * for @first_property_name.
9857 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9861 gtk_widget_style_get_valist (GtkWidget *widget,
9862 const gchar *first_property_name,
9867 g_return_if_fail (GTK_IS_WIDGET (widget));
9869 g_object_ref (widget);
9871 name = first_property_name;
9874 const GValue *peek_value;
9878 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9880 G_OBJECT_TYPE (widget),
9884 g_warning ("%s: widget class `%s' has no property named `%s'",
9886 G_OBJECT_TYPE_NAME (widget),
9890 /* style pspecs are always readable so we can spare that check here */
9892 peek_value = _gtk_style_peek_property_value (widget->style,
9893 G_OBJECT_TYPE (widget),
9895 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9896 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9899 g_warning ("%s: %s", G_STRLOC, error);
9904 name = va_arg (var_args, gchar*);
9907 g_object_unref (widget);
9911 * gtk_widget_style_get:
9912 * @widget: a #GtkWidget
9913 * @first_property_name: the name of the first property to get
9914 * @Varargs: pairs of property names and locations to
9915 * return the property values, starting with the location for
9916 * @first_property_name, terminated by %NULL.
9918 * Gets the values of a multiple style properties of @widget.
9921 gtk_widget_style_get (GtkWidget *widget,
9922 const gchar *first_property_name,
9927 g_return_if_fail (GTK_IS_WIDGET (widget));
9929 va_start (var_args, first_property_name);
9930 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9936 * @widget: a #GtkWidget
9937 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
9938 * @path: (out) (allow-none): location to store allocated path string, or %NULL
9939 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
9941 * Obtains the full path to @widget. The path is simply the name of a
9942 * widget and all its parents in the container hierarchy, separated by
9943 * periods. The name of a widget comes from
9944 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9945 * in gtkrc configuration files. Widget names are the type of the
9946 * widget by default (e.g. "GtkButton") or can be set to an
9947 * application-specific value with gtk_widget_set_name(). By setting
9948 * the name of a widget, you allow users or theme authors to apply
9949 * styles to that specific widget in their gtkrc
9950 * file. @path_reversed_p fills in the path in reverse order,
9951 * i.e. starting with @widget's name instead of starting with the name
9952 * of @widget's outermost ancestor.
9955 gtk_widget_path (GtkWidget *widget,
9958 gchar **path_reversed)
9960 static gchar *rev_path = NULL;
9961 static guint tmp_path_len = 0;
9964 g_return_if_fail (GTK_IS_WIDGET (widget));
9969 const gchar *string;
9974 string = gtk_widget_get_name (widget);
9975 l = strlen (string);
9976 while (tmp_path_len <= len + l + 1)
9978 tmp_path_len += INIT_PATH_SIZE;
9979 rev_path = g_realloc (rev_path, tmp_path_len);
9987 widget = widget->parent;
9990 rev_path[len++] = '.';
9992 rev_path[len++] = 0;
9997 *path_length = len - 1;
9999 *path_reversed = g_strdup (rev_path);
10002 *path = g_strdup (rev_path);
10003 g_strreverse (*path);
10008 * gtk_widget_class_path:
10009 * @widget: a #GtkWidget
10010 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10011 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10012 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10015 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10016 * never uses a custom name set with gtk_widget_set_name().
10020 gtk_widget_class_path (GtkWidget *widget,
10021 guint *path_length,
10023 gchar **path_reversed)
10025 static gchar *rev_path = NULL;
10026 static guint tmp_path_len = 0;
10029 g_return_if_fail (GTK_IS_WIDGET (widget));
10034 const gchar *string;
10039 string = g_type_name (G_OBJECT_TYPE (widget));
10040 l = strlen (string);
10041 while (tmp_path_len <= len + l + 1)
10043 tmp_path_len += INIT_PATH_SIZE;
10044 rev_path = g_realloc (rev_path, tmp_path_len);
10046 s = string + l - 1;
10047 d = rev_path + len;
10048 while (s >= string)
10052 widget = widget->parent;
10055 rev_path[len++] = '.';
10057 rev_path[len++] = 0;
10062 *path_length = len - 1;
10064 *path_reversed = g_strdup (rev_path);
10067 *path = g_strdup (rev_path);
10068 g_strreverse (*path);
10073 * gtk_requisition_copy:
10074 * @requisition: a #GtkRequisition
10076 * Copies a #GtkRequisition.
10078 * Returns: a copy of @requisition
10081 gtk_requisition_copy (const GtkRequisition *requisition)
10083 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10087 * gtk_requisition_free:
10088 * @requisition: a #GtkRequisition
10090 * Frees a #GtkRequisition.
10093 gtk_requisition_free (GtkRequisition *requisition)
10095 g_free (requisition);
10099 gtk_requisition_get_type (void)
10101 static GType our_type = 0;
10104 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10105 (GBoxedCopyFunc) gtk_requisition_copy,
10106 (GBoxedFreeFunc) gtk_requisition_free);
10112 * gtk_widget_get_accessible:
10113 * @widget: a #GtkWidget
10115 * Returns the accessible object that describes the widget to an
10116 * assistive technology.
10118 * If no accessibility library is loaded (i.e. no ATK implementation library is
10119 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10120 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10121 * if no class-specific #AtkObject implementation is available for the widget
10122 * instance in question, it will inherit an #AtkObject implementation from the
10123 * first ancestor class for which such an implementation is defined.
10125 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10126 * library contains more information about accessible objects and their uses.
10128 * Returns: (transfer none): the #AtkObject associated with @widget
10131 gtk_widget_get_accessible (GtkWidget *widget)
10133 GtkWidgetClass *klass;
10135 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10137 klass = GTK_WIDGET_GET_CLASS (widget);
10139 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10141 return klass->get_accessible (widget);
10145 gtk_widget_real_get_accessible (GtkWidget *widget)
10147 AtkObject* accessible;
10149 accessible = g_object_get_qdata (G_OBJECT (widget),
10150 quark_accessible_object);
10153 AtkObjectFactory *factory;
10154 AtkRegistry *default_registry;
10156 default_registry = atk_get_default_registry ();
10157 factory = atk_registry_get_factory (default_registry,
10158 G_TYPE_FROM_INSTANCE (widget));
10160 atk_object_factory_create_accessible (factory,
10161 G_OBJECT (widget));
10162 g_object_set_qdata (G_OBJECT (widget),
10163 quark_accessible_object,
10170 * Initialize a AtkImplementorIface instance's virtual pointers as
10171 * appropriate to this implementor's class (GtkWidget).
10174 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10176 iface->ref_accessible = gtk_widget_ref_accessible;
10180 gtk_widget_ref_accessible (AtkImplementor *implementor)
10182 AtkObject *accessible;
10184 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10186 g_object_ref (accessible);
10191 * GtkBuildable implementation
10193 static GQuark quark_builder_has_default = 0;
10194 static GQuark quark_builder_has_focus = 0;
10195 static GQuark quark_builder_atk_relations = 0;
10196 static GQuark quark_builder_set_name = 0;
10199 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10201 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10202 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10203 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10204 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10206 iface->set_name = gtk_widget_buildable_set_name;
10207 iface->get_name = gtk_widget_buildable_get_name;
10208 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10209 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10210 iface->parser_finished = gtk_widget_buildable_parser_finished;
10211 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10212 iface->custom_finished = gtk_widget_buildable_custom_finished;
10216 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10219 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10220 g_strdup (name), g_free);
10223 static const gchar *
10224 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10226 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10230 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10231 GtkBuilder *builder,
10232 const gchar *childname)
10234 if (strcmp (childname, "accessible") == 0)
10235 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10241 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10242 GtkBuilder *builder,
10244 const GValue *value)
10246 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10247 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10248 GINT_TO_POINTER (TRUE));
10249 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10250 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10251 GINT_TO_POINTER (TRUE));
10253 g_object_set_property (G_OBJECT (buildable), name, value);
10258 gchar *action_name;
10259 GString *description;
10261 gboolean translatable;
10271 free_action (AtkActionData *data, gpointer user_data)
10273 g_free (data->action_name);
10274 g_string_free (data->description, TRUE);
10275 g_free (data->context);
10276 g_slice_free (AtkActionData, data);
10280 free_relation (AtkRelationData *data, gpointer user_data)
10282 g_free (data->target);
10283 g_free (data->type);
10284 g_slice_free (AtkRelationData, data);
10288 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10289 GtkBuilder *builder)
10291 GSList *atk_relations;
10293 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10294 gtk_widget_grab_default (GTK_WIDGET (buildable));
10295 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10296 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10298 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10299 quark_builder_atk_relations);
10302 AtkObject *accessible;
10303 AtkRelationSet *relation_set;
10306 AtkRelationType relation_type;
10307 AtkObject *target_accessible;
10309 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10310 relation_set = atk_object_ref_relation_set (accessible);
10312 for (l = atk_relations; l; l = l->next)
10314 AtkRelationData *relation = (AtkRelationData*)l->data;
10316 target = gtk_builder_get_object (builder, relation->target);
10319 g_warning ("Target object %s in <relation> does not exist",
10323 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10324 g_assert (target_accessible != NULL);
10326 relation_type = atk_relation_type_for_name (relation->type);
10327 if (relation_type == ATK_RELATION_NULL)
10329 g_warning ("<relation> type %s not found",
10333 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10334 target_accessible);
10336 g_object_unref (relation_set);
10338 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10339 g_slist_free (atk_relations);
10340 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10349 } AccessibilitySubParserData;
10352 accessibility_start_element (GMarkupParseContext *context,
10353 const gchar *element_name,
10354 const gchar **names,
10355 const gchar **values,
10356 gpointer user_data,
10359 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10361 gint line_number, char_number;
10363 if (strcmp (element_name, "relation") == 0)
10365 gchar *target = NULL;
10366 gchar *type = NULL;
10367 AtkRelationData *relation;
10369 for (i = 0; names[i]; i++)
10371 if (strcmp (names[i], "target") == 0)
10372 target = g_strdup (values[i]);
10373 else if (strcmp (names[i], "type") == 0)
10374 type = g_strdup (values[i]);
10377 g_markup_parse_context_get_position (context,
10380 g_set_error (error,
10382 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10383 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10385 line_number, char_number, names[i], "relation");
10392 if (!target || !type)
10394 g_markup_parse_context_get_position (context,
10397 g_set_error (error,
10399 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10400 "%s:%d:%d <%s> requires attribute \"%s\"",
10402 line_number, char_number, "relation",
10403 type ? "target" : "type");
10409 relation = g_slice_new (AtkRelationData);
10410 relation->target = target;
10411 relation->type = type;
10413 data->relations = g_slist_prepend (data->relations, relation);
10415 else if (strcmp (element_name, "action") == 0)
10417 const gchar *action_name = NULL;
10418 const gchar *description = NULL;
10419 const gchar *msg_context = NULL;
10420 gboolean translatable = FALSE;
10421 AtkActionData *action;
10423 for (i = 0; names[i]; i++)
10425 if (strcmp (names[i], "action_name") == 0)
10426 action_name = values[i];
10427 else if (strcmp (names[i], "description") == 0)
10428 description = values[i];
10429 else if (strcmp (names[i], "translatable") == 0)
10431 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10434 else if (strcmp (names[i], "comments") == 0)
10436 /* do nothing, comments are for translators */
10438 else if (strcmp (names[i], "context") == 0)
10439 msg_context = values[i];
10442 g_markup_parse_context_get_position (context,
10445 g_set_error (error,
10447 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10448 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10450 line_number, char_number, names[i], "action");
10457 g_markup_parse_context_get_position (context,
10460 g_set_error (error,
10462 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10463 "%s:%d:%d <%s> requires attribute \"%s\"",
10465 line_number, char_number, "action",
10470 action = g_slice_new (AtkActionData);
10471 action->action_name = g_strdup (action_name);
10472 action->description = g_string_new (description);
10473 action->context = g_strdup (msg_context);
10474 action->translatable = translatable;
10476 data->actions = g_slist_prepend (data->actions, action);
10478 else if (strcmp (element_name, "accessibility") == 0)
10481 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10485 accessibility_text (GMarkupParseContext *context,
10488 gpointer user_data,
10491 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10493 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10495 AtkActionData *action = data->actions->data;
10497 g_string_append_len (action->description, text, text_len);
10501 static const GMarkupParser accessibility_parser =
10503 accessibility_start_element,
10505 accessibility_text,
10514 } AccelGroupParserData;
10517 accel_group_start_element (GMarkupParseContext *context,
10518 const gchar *element_name,
10519 const gchar **names,
10520 const gchar **values,
10521 gpointer user_data,
10526 guint modifiers = 0;
10527 gchar *signal = NULL;
10528 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10530 for (i = 0; names[i]; i++)
10532 if (strcmp (names[i], "key") == 0)
10533 key = gdk_keyval_from_name (values[i]);
10534 else if (strcmp (names[i], "modifiers") == 0)
10536 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10542 else if (strcmp (names[i], "signal") == 0)
10543 signal = g_strdup (values[i]);
10546 if (key == 0 || signal == NULL)
10548 g_warning ("<accelerator> requires key and signal attributes");
10551 parser_data->key = key;
10552 parser_data->modifiers = modifiers;
10553 parser_data->signal = signal;
10556 static const GMarkupParser accel_group_parser =
10558 accel_group_start_element,
10562 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10563 GtkBuilder *builder,
10565 const gchar *tagname,
10566 GMarkupParser *parser,
10569 g_assert (buildable);
10571 if (strcmp (tagname, "accelerator") == 0)
10573 AccelGroupParserData *parser_data;
10575 parser_data = g_slice_new0 (AccelGroupParserData);
10576 parser_data->object = g_object_ref (buildable);
10577 *parser = accel_group_parser;
10578 *data = parser_data;
10581 if (strcmp (tagname, "accessibility") == 0)
10583 AccessibilitySubParserData *parser_data;
10585 parser_data = g_slice_new0 (AccessibilitySubParserData);
10586 *parser = accessibility_parser;
10587 *data = parser_data;
10594 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10595 GtkWidget *toplevel,
10596 gpointer user_data)
10598 AccelGroupParserData *accel_data;
10599 GSList *accel_groups;
10600 GtkAccelGroup *accel_group;
10602 g_return_if_fail (GTK_IS_WIDGET (widget));
10603 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10604 g_return_if_fail (user_data != NULL);
10606 accel_data = (AccelGroupParserData*)user_data;
10607 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10608 if (g_slist_length (accel_groups) == 0)
10610 accel_group = gtk_accel_group_new ();
10611 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10615 g_assert (g_slist_length (accel_groups) == 1);
10616 accel_group = g_slist_nth_data (accel_groups, 0);
10619 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10620 accel_data->signal,
10623 accel_data->modifiers,
10624 GTK_ACCEL_VISIBLE);
10626 g_object_unref (accel_data->object);
10627 g_free (accel_data->signal);
10628 g_slice_free (AccelGroupParserData, accel_data);
10632 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10633 GtkBuilder *builder,
10635 const gchar *tagname,
10636 gpointer user_data)
10638 AccelGroupParserData *accel_data;
10639 AccessibilitySubParserData *a11y_data;
10640 GtkWidget *toplevel;
10642 if (strcmp (tagname, "accelerator") == 0)
10644 accel_data = (AccelGroupParserData*)user_data;
10645 g_assert (accel_data->object);
10647 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10649 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10651 else if (strcmp (tagname, "accessibility") == 0)
10653 a11y_data = (AccessibilitySubParserData*)user_data;
10655 if (a11y_data->actions)
10657 AtkObject *accessible;
10662 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10664 action = ATK_ACTION (accessible);
10665 n_actions = atk_action_get_n_actions (action);
10667 for (l = a11y_data->actions; l; l = l->next)
10669 AtkActionData *action_data = (AtkActionData*)l->data;
10671 for (i = 0; i < n_actions; i++)
10672 if (strcmp (atk_action_get_name (action, i),
10673 action_data->action_name) == 0)
10678 gchar *description;
10680 if (action_data->translatable && action_data->description->len)
10681 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10682 action_data->context,
10683 action_data->description->str);
10685 description = action_data->description->str;
10687 atk_action_set_description (action, i, description);
10691 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10692 g_slist_free (a11y_data->actions);
10695 if (a11y_data->relations)
10696 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10697 a11y_data->relations);
10699 g_slice_free (AccessibilitySubParserData, a11y_data);
10705 * gtk_widget_get_clipboard:
10706 * @widget: a #GtkWidget
10707 * @selection: a #GdkAtom which identifies the clipboard
10708 * to use. %GDK_SELECTION_CLIPBOARD gives the
10709 * default clipboard. Another common value
10710 * is %GDK_SELECTION_PRIMARY, which gives
10711 * the primary X selection.
10713 * Returns the clipboard object for the given selection to
10714 * be used with @widget. @widget must have a #GdkDisplay
10715 * associated with it, so must be attached to a toplevel
10718 * Return value: (transfer none): the appropriate clipboard object. If no
10719 * clipboard already exists, a new one will
10720 * be created. Once a clipboard object has
10721 * been created, it is persistent for all time.
10726 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10728 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10729 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10731 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10736 * gtk_widget_list_mnemonic_labels:
10737 * @widget: a #GtkWidget
10739 * Returns a newly allocated list of the widgets, normally labels, for
10740 * which this widget is a the target of a mnemonic (see for example,
10741 * gtk_label_set_mnemonic_widget()).
10743 * The widgets in the list are not individually referenced. If you
10744 * want to iterate through the list and perform actions involving
10745 * callbacks that might destroy the widgets, you
10746 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10747 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10748 * widgets afterwards.
10750 * Return value: (element-type GtkWidget) (transfer container): the list of
10751 * mnemonic labels; free this list
10752 * with g_list_free() when you are done with it.
10757 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10759 GList *list = NULL;
10762 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10764 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10765 list = g_list_prepend (list, l->data);
10771 * gtk_widget_add_mnemonic_label:
10772 * @widget: a #GtkWidget
10773 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10775 * Adds a widget to the list of mnemonic labels for
10776 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10777 * list of mnemonic labels for the widget is cleared when the
10778 * widget is destroyed, so the caller must make sure to update
10779 * its internal state at this point as well, by using a connection
10780 * to the #GtkWidget::destroy signal or a weak notifier.
10785 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10788 GSList *old_list, *new_list;
10790 g_return_if_fail (GTK_IS_WIDGET (widget));
10791 g_return_if_fail (GTK_IS_WIDGET (label));
10793 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10794 new_list = g_slist_prepend (old_list, label);
10796 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10797 new_list, (GDestroyNotify) g_slist_free);
10801 * gtk_widget_remove_mnemonic_label:
10802 * @widget: a #GtkWidget
10803 * @label: a #GtkWidget that was previously set as a mnemnic label for
10804 * @widget with gtk_widget_add_mnemonic_label().
10806 * Removes a widget from the list of mnemonic labels for
10807 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10808 * must have previously been added to the list with
10809 * gtk_widget_add_mnemonic_label().
10814 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10817 GSList *old_list, *new_list;
10819 g_return_if_fail (GTK_IS_WIDGET (widget));
10820 g_return_if_fail (GTK_IS_WIDGET (label));
10822 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10823 new_list = g_slist_remove (old_list, label);
10826 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10827 new_list, (GDestroyNotify) g_slist_free);
10831 * gtk_widget_get_no_show_all:
10832 * @widget: a #GtkWidget
10834 * Returns the current value of the GtkWidget:no-show-all property,
10835 * which determines whether calls to gtk_widget_show_all() and
10836 * gtk_widget_hide_all() will affect this widget.
10838 * Return value: the current value of the "no-show-all" property.
10843 gtk_widget_get_no_show_all (GtkWidget *widget)
10845 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10847 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10851 * gtk_widget_set_no_show_all:
10852 * @widget: a #GtkWidget
10853 * @no_show_all: the new value for the "no-show-all" property
10855 * Sets the #GtkWidget:no-show-all property, which determines whether
10856 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10859 * This is mostly for use in constructing widget hierarchies with externally
10860 * controlled visibility, see #GtkUIManager.
10865 gtk_widget_set_no_show_all (GtkWidget *widget,
10866 gboolean no_show_all)
10868 g_return_if_fail (GTK_IS_WIDGET (widget));
10870 no_show_all = (no_show_all != FALSE);
10872 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10876 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10878 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10880 g_object_notify (G_OBJECT (widget), "no-show-all");
10885 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10886 gboolean has_tooltip,
10889 gboolean priv_has_tooltip;
10891 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10892 quark_has_tooltip));
10894 if (priv_has_tooltip != has_tooltip || force)
10896 priv_has_tooltip = has_tooltip;
10898 if (priv_has_tooltip)
10900 if (GTK_WIDGET_REALIZED (widget) && !gtk_widget_get_has_window (widget))
10901 gdk_window_set_events (widget->window,
10902 gdk_window_get_events (widget->window) |
10903 GDK_LEAVE_NOTIFY_MASK |
10904 GDK_POINTER_MOTION_MASK |
10905 GDK_POINTER_MOTION_HINT_MASK);
10907 if (gtk_widget_get_has_window (widget))
10908 gtk_widget_add_events (widget,
10909 GDK_LEAVE_NOTIFY_MASK |
10910 GDK_POINTER_MOTION_MASK |
10911 GDK_POINTER_MOTION_HINT_MASK);
10914 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10915 GUINT_TO_POINTER (priv_has_tooltip));
10920 * gtk_widget_set_tooltip_window:
10921 * @widget: a #GtkWidget
10922 * @custom_window: (allow-none): a #GtkWindow, or %NULL
10924 * Replaces the default, usually yellow, window used for displaying
10925 * tooltips with @custom_window. GTK+ will take care of showing and
10926 * hiding @custom_window at the right moment, to behave likewise as
10927 * the default tooltip window. If @custom_window is %NULL, the default
10928 * tooltip window will be used.
10930 * If the custom window should have the default theming it needs to
10931 * have the name "gtk-tooltip", see gtk_widget_set_name().
10936 gtk_widget_set_tooltip_window (GtkWidget *widget,
10937 GtkWindow *custom_window)
10939 gboolean has_tooltip;
10940 gchar *tooltip_markup;
10942 g_return_if_fail (GTK_IS_WIDGET (widget));
10943 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10945 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10948 g_object_ref (custom_window);
10950 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10951 custom_window, g_object_unref);
10953 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10954 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10956 if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10957 gtk_widget_queue_tooltip_query (widget);
10961 * gtk_widget_get_tooltip_window:
10962 * @widget: a #GtkWidget
10964 * Returns the #GtkWindow of the current tooltip. This can be the
10965 * GtkWindow created by default, or the custom tooltip window set
10966 * using gtk_widget_set_tooltip_window().
10968 * Return value: (transfer none): The #GtkWindow of the current tooltip.
10973 gtk_widget_get_tooltip_window (GtkWidget *widget)
10975 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10977 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10981 * gtk_widget_trigger_tooltip_query:
10982 * @widget: a #GtkWidget
10984 * Triggers a tooltip query on the display where the toplevel of @widget
10985 * is located. See gtk_tooltip_trigger_tooltip_query() for more
10991 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10993 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10996 static guint tooltip_query_id;
10997 static GSList *tooltip_query_displays;
11000 tooltip_query_idle (gpointer data)
11002 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11003 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11004 g_slist_free (tooltip_query_displays);
11006 tooltip_query_displays = NULL;
11007 tooltip_query_id = 0;
11013 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11015 GdkDisplay *display;
11017 display = gtk_widget_get_display (widget);
11019 if (!g_slist_find (tooltip_query_displays, display))
11020 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11022 if (tooltip_query_id == 0)
11023 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11027 * gtk_widget_set_tooltip_text:
11028 * @widget: a #GtkWidget
11029 * @text: the contents of the tooltip for @widget
11031 * Sets @text as the contents of the tooltip. This function will take
11032 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11033 * handler for the GtkWidget::query-tooltip signal.
11035 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11040 gtk_widget_set_tooltip_text (GtkWidget *widget,
11043 g_return_if_fail (GTK_IS_WIDGET (widget));
11045 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11049 * gtk_widget_get_tooltip_text:
11050 * @widget: a #GtkWidget
11052 * Gets the contents of the tooltip for @widget.
11054 * Return value: the tooltip text, or %NULL. You should free the
11055 * returned string with g_free() when done.
11060 gtk_widget_get_tooltip_text (GtkWidget *widget)
11062 gchar *text = NULL;
11064 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11066 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11072 * gtk_widget_set_tooltip_markup:
11073 * @widget: a #GtkWidget
11074 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11076 * Sets @markup as the contents of the tooltip, which is marked up with
11077 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11079 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11080 * and of the default handler for the GtkWidget::query-tooltip signal.
11082 * See also the GtkWidget:tooltip-markup property and
11083 * gtk_tooltip_set_markup().
11088 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11089 const gchar *markup)
11091 g_return_if_fail (GTK_IS_WIDGET (widget));
11093 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11097 * gtk_widget_get_tooltip_markup:
11098 * @widget: a #GtkWidget
11100 * Gets the contents of the tooltip for @widget.
11102 * Return value: the tooltip text, or %NULL. You should free the
11103 * returned string with g_free() when done.
11108 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11110 gchar *text = NULL;
11112 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11114 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11120 * gtk_widget_set_has_tooltip:
11121 * @widget: a #GtkWidget
11122 * @has_tooltip: whether or not @widget has a tooltip.
11124 * Sets the has-tooltip property on @widget to @has_tooltip. See
11125 * GtkWidget:has-tooltip for more information.
11130 gtk_widget_set_has_tooltip (GtkWidget *widget,
11131 gboolean has_tooltip)
11133 g_return_if_fail (GTK_IS_WIDGET (widget));
11135 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11139 * gtk_widget_get_has_tooltip:
11140 * @widget: a #GtkWidget
11142 * Returns the current value of the has-tooltip property. See
11143 * GtkWidget:has-tooltip for more information.
11145 * Return value: current value of has-tooltip on @widget.
11150 gtk_widget_get_has_tooltip (GtkWidget *widget)
11152 gboolean has_tooltip = FALSE;
11154 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11156 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11158 return has_tooltip;
11162 * gtk_widget_get_allocation:
11163 * @widget: a #GtkWidget
11164 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11166 * Retrieves the widget's allocation.
11171 gtk_widget_get_allocation (GtkWidget *widget,
11172 GtkAllocation *allocation)
11174 g_return_if_fail (GTK_IS_WIDGET (widget));
11175 g_return_if_fail (allocation != NULL);
11177 *allocation = widget->allocation;
11181 * gtk_widget_set_allocation:
11182 * @widget: a #GtkWidget
11183 * @allocation: a pointer to a #GtkAllocation to copy from
11185 * Sets the widget's allocation. This should not be used
11186 * directly, but from within a widget's size_allocate method.
11191 gtk_widget_set_allocation (GtkWidget *widget,
11192 const GtkAllocation *allocation)
11194 g_return_if_fail (GTK_IS_WIDGET (widget));
11195 g_return_if_fail (allocation != NULL);
11197 widget->allocation = *allocation;
11201 * gtk_widget_get_requisition:
11202 * @widget: a #GtkWidget
11203 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11205 * Retrieves the widget's requisition.
11207 * This function should only be used by widget implementations in
11208 * order to figure whether the widget's requisition has actually
11209 * changed after some internal state change (so that they can call
11210 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11212 * Normally, gtk_widget_size_request() should be used.
11217 gtk_widget_get_requisition (GtkWidget *widget,
11218 GtkRequisition *requisition)
11220 g_return_if_fail (GTK_IS_WIDGET (widget));
11221 g_return_if_fail (requisition != NULL);
11223 *requisition = widget->requisition;
11227 * gtk_widget_set_window:
11228 * @widget: a #GtkWidget
11229 * @window: a #GdkWindow
11231 * Sets a widget's window. This function should only be used in a
11232 * widget's GtkWidget::realize() implementation. The %window passed is
11233 * usually either new window created with gdk_window_new(), or the
11234 * window of its parent widget as returned by
11235 * gtk_widget_get_parent_window().
11237 * Widgets must indicate whether they will create their own #GdkWindow
11238 * by calling gtk_widget_set_has_window(). This is usually done in the
11239 * widget's init() function.
11244 gtk_widget_set_window (GtkWidget *widget,
11247 g_return_if_fail (GTK_IS_WIDGET (widget));
11248 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11250 if (widget->window != window)
11252 widget->window = window;
11253 g_object_notify (G_OBJECT (widget), "window");
11258 * gtk_widget_get_window:
11259 * @widget: a #GtkWidget
11261 * Returns the widget's window if it is realized, %NULL otherwise
11263 * Return value: @widget's window.
11268 gtk_widget_get_window (GtkWidget *widget)
11270 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11272 return widget->window;
11275 #define __GTK_WIDGET_C__
11276 #include "gtkaliasdef.c"