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.
892 widget_signals[STATE_CHANGED] =
893 g_signal_new (I_("state-changed"),
894 G_TYPE_FROM_CLASS (gobject_class),
896 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
898 _gtk_marshal_VOID__ENUM,
900 GTK_TYPE_STATE_TYPE);
903 * GtkWidget::parent-set:
904 * @widget: the object on which the signal is emitted
905 * @old_parent: the previous parent, or %NULL if the widget
906 * just got its initial parent.
908 * The ::parent-set signal is emitted when a new parent
909 * has been set on a widget.
911 widget_signals[PARENT_SET] =
912 g_signal_new (I_("parent-set"),
913 G_TYPE_FROM_CLASS (gobject_class),
915 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
917 _gtk_marshal_VOID__OBJECT,
922 * GtkWidget::hierarchy-changed:
923 * @widget: the object on which the signal is emitted
924 * @previous_toplevel: the previous toplevel ancestor, or %NULL
925 * if the widget was previously unanchored
927 * The ::hierarchy-changed signal is emitted when the
928 * anchored state of a widget changes. A widget is
929 * <firstterm>anchored</firstterm> when its toplevel
930 * ancestor is a #GtkWindow. This signal is emitted when
931 * a widget changes from un-anchored to anchored or vice-versa.
933 widget_signals[HIERARCHY_CHANGED] =
934 g_signal_new (I_("hierarchy-changed"),
935 G_TYPE_FROM_CLASS (gobject_class),
937 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
939 _gtk_marshal_VOID__OBJECT,
944 * GtkWidget::style-set:
945 * @widget: the object on which the signal is emitted
946 * @previous_style: the previous style, or %NULL if the widget
947 * just got its initial style
949 * The ::style-set signal is emitted when a new style has been set
950 * on a widget. Note that style-modifying functions like
951 * gtk_widget_modify_base() also cause this signal to be emitted.
953 widget_signals[STYLE_SET] =
954 g_signal_new (I_("style-set"),
955 G_TYPE_FROM_CLASS (gobject_class),
957 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
959 _gtk_marshal_VOID__OBJECT,
963 * GtkWidget::direction-changed:
964 * @widget: the object on which the signal is emitted
965 * @previous_direction: the previous text direction of @widget
967 * The ::direction-changed signal is emitted when the text direction
968 * of a widget changes.
970 widget_signals[DIRECTION_CHANGED] =
971 g_signal_new (I_("direction-changed"),
972 G_TYPE_FROM_CLASS (gobject_class),
974 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
976 _gtk_marshal_VOID__ENUM,
978 GTK_TYPE_TEXT_DIRECTION);
981 * GtkWidget::grab-notify:
982 * @widget: the object which received the signal
983 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
984 * if it becomes unshadowed
986 * The ::grab-notify signal is emitted when a widget becomes
987 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
988 * another widget, or when it becomes unshadowed due to a grab
991 * A widget is shadowed by a gtk_grab_add() when the topmost
992 * grab widget in the grab stack of its window group is not
995 widget_signals[GRAB_NOTIFY] =
996 g_signal_new (I_("grab-notify"),
997 G_TYPE_FROM_CLASS (gobject_class),
999 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1001 _gtk_marshal_VOID__BOOLEAN,
1006 * GtkWidget::child-notify:
1007 * @widget: the object which received the signal
1008 * @pspec: the #GParamSpec of the changed child property
1010 * The ::child-notify signal is emitted for each
1011 * <link linkend="child-properties">child property</link> that has
1012 * changed on an object. The signal's detail holds the property name.
1014 widget_signals[CHILD_NOTIFY] =
1015 g_signal_new (I_("child-notify"),
1016 G_TYPE_FROM_CLASS (gobject_class),
1017 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1018 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1020 g_cclosure_marshal_VOID__PARAM,
1025 * GtkWidget::mnemonic-activate:
1026 * @widget: the object which received the signal.
1029 widget_signals[MNEMONIC_ACTIVATE] =
1030 g_signal_new (I_("mnemonic-activate"),
1031 G_TYPE_FROM_CLASS (gobject_class),
1033 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1034 _gtk_boolean_handled_accumulator, NULL,
1035 _gtk_marshal_BOOLEAN__BOOLEAN,
1040 * GtkWidget::grab-focus:
1041 * @widget: the object which received the signal.
1043 widget_signals[GRAB_FOCUS] =
1044 g_signal_new (I_("grab-focus"),
1045 G_TYPE_FROM_CLASS (gobject_class),
1046 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1047 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1049 _gtk_marshal_VOID__VOID,
1054 * @widget: the object which received the signal.
1057 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1059 widget_signals[FOCUS] =
1060 g_signal_new (I_("focus"),
1061 G_TYPE_FROM_CLASS (object_class),
1063 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1064 _gtk_boolean_handled_accumulator, NULL,
1065 _gtk_marshal_BOOLEAN__ENUM,
1067 GTK_TYPE_DIRECTION_TYPE);
1070 * GtkWidget::move-focus:
1071 * @widget: the object which received the signal.
1074 widget_signals[MOVE_FOCUS] =
1075 g_signal_new_class_handler (I_("move-focus"),
1076 G_TYPE_FROM_CLASS (object_class),
1077 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1078 G_CALLBACK (gtk_widget_real_move_focus),
1080 _gtk_marshal_VOID__ENUM,
1083 GTK_TYPE_DIRECTION_TYPE);
1086 * @widget: the object which received the signal.
1087 * @event: the #GdkEvent which triggered this signal
1089 * The GTK+ main loop will emit three signals for each GDK event delivered
1090 * to a widget: one generic ::event signal, another, more specific,
1091 * signal that matches the type of event delivered (e.g.
1092 * #GtkWidget::key-press-event) and finally a generic
1093 * #GtkWidget::event-after signal.
1095 * Returns: %TRUE to stop other handlers from being invoked for the event
1096 * and to cancel the emission of the second specific ::event signal.
1097 * %FALSE to propagate the event further and to allow the emission of
1098 * the second signal. The ::event-after signal is emitted regardless of
1101 widget_signals[EVENT] =
1102 g_signal_new (I_("event"),
1103 G_TYPE_FROM_CLASS (gobject_class),
1105 G_STRUCT_OFFSET (GtkWidgetClass, event),
1106 _gtk_boolean_handled_accumulator, NULL,
1107 _gtk_marshal_BOOLEAN__BOXED,
1109 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1112 * GtkWidget::event-after:
1113 * @widget: the object which received the signal.
1114 * @event: the #GdkEvent which triggered this signal
1116 * After the emission of the #GtkWidget::event signal and (optionally)
1117 * the second more specific signal, ::event-after will be emitted
1118 * regardless of the previous two signals handlers return values.
1121 widget_signals[EVENT_AFTER] =
1122 g_signal_new (I_("event-after"),
1123 G_TYPE_FROM_CLASS (gobject_class),
1127 _gtk_marshal_VOID__BOXED,
1129 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1132 * GtkWidget::button-press-event:
1133 * @widget: the object which received the signal.
1134 * @event: the #GdkEventButton which triggered this signal
1136 * The ::button-press-event signal will be emitted when a button
1137 * (typically from a mouse) is pressed.
1139 * To receive this signal, the #GdkWindow associated to the
1140 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1142 * This signal will be sent to the grab widget if there is one.
1144 * Returns: %TRUE to stop other handlers from being invoked for the event.
1145 * %FALSE to propagate the event further.
1147 widget_signals[BUTTON_PRESS_EVENT] =
1148 g_signal_new (I_("button-press-event"),
1149 G_TYPE_FROM_CLASS (gobject_class),
1151 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1152 _gtk_boolean_handled_accumulator, NULL,
1153 _gtk_marshal_BOOLEAN__BOXED,
1155 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1158 * GtkWidget::button-release-event:
1159 * @widget: the object which received the signal.
1160 * @event: the #GdkEventButton which triggered this signal
1162 * The ::button-release-event signal will be emitted when a button
1163 * (typically from a mouse) is released.
1165 * To receive this signal, the #GdkWindow associated to the
1166 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1168 * This signal will be sent to the grab widget if there is one.
1170 * Returns: %TRUE to stop other handlers from being invoked for the event.
1171 * %FALSE to propagate the event further.
1173 widget_signals[BUTTON_RELEASE_EVENT] =
1174 g_signal_new (I_("button-release-event"),
1175 G_TYPE_FROM_CLASS (gobject_class),
1177 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1178 _gtk_boolean_handled_accumulator, NULL,
1179 _gtk_marshal_BOOLEAN__BOXED,
1181 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1184 * GtkWidget::scroll-event:
1185 * @widget: the object which received the signal.
1186 * @event: the #GdkEventScroll which triggered this signal
1188 * The ::scroll-event signal is emitted when a button in the 4 to 7
1189 * range is pressed. Wheel mice are usually configured to generate
1190 * button press events for buttons 4 and 5 when the wheel is turned.
1192 * To receive this signal, the #GdkWindow associated to the widget needs
1193 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1195 * This signal will be sent to the grab widget if there is one.
1197 * Returns: %TRUE to stop other handlers from being invoked for the event.
1198 * %FALSE to propagate the event further.
1200 widget_signals[SCROLL_EVENT] =
1201 g_signal_new (I_("scroll-event"),
1202 G_TYPE_FROM_CLASS (gobject_class),
1204 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1205 _gtk_boolean_handled_accumulator, NULL,
1206 _gtk_marshal_BOOLEAN__BOXED,
1208 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1210 * GtkWidget::motion-notify-event:
1211 * @widget: the object which received the signal.
1212 * @event: the #GdkEventMotion which triggered this signal
1214 * The ::motion-notify-event signal is emitted when the pointer moves
1215 * over the widget's #GdkWindow.
1217 * To receive this signal, the #GdkWindow associated to the widget
1218 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1220 * This signal will be sent to the grab widget if there is one.
1222 * Returns: %TRUE to stop other handlers from being invoked for the event.
1223 * %FALSE to propagate the event further.
1225 widget_signals[MOTION_NOTIFY_EVENT] =
1226 g_signal_new (I_("motion-notify-event"),
1227 G_TYPE_FROM_CLASS (gobject_class),
1229 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1230 _gtk_boolean_handled_accumulator, NULL,
1231 _gtk_marshal_BOOLEAN__BOXED,
1233 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1236 * GtkWidget::composited-changed:
1237 * @widget: the object on which the signal is emitted
1239 * The ::composited-changed signal is emitted when the composited
1240 * status of @widget<!-- -->s screen changes.
1241 * See gdk_screen_is_composited().
1243 widget_signals[COMPOSITED_CHANGED] =
1244 g_signal_new (I_("composited-changed"),
1245 G_TYPE_FROM_CLASS (gobject_class),
1246 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1247 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1249 _gtk_marshal_VOID__VOID,
1253 * GtkWidget::keynav-failed:
1254 * @widget: the object which received the signal
1255 * @direction: the direction of movement
1257 * Gets emitted if keyboard navigation fails.
1258 * See gtk_widget_keynav_failed() for details.
1260 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1261 * if the emitting widget should try to handle the keyboard
1262 * navigation attempt in its parent container(s).
1266 widget_signals[KEYNAV_FAILED] =
1267 g_signal_new_class_handler (I_("keynav-failed"),
1268 G_TYPE_FROM_CLASS (gobject_class),
1270 G_CALLBACK (gtk_widget_real_keynav_failed),
1271 _gtk_boolean_handled_accumulator, NULL,
1272 _gtk_marshal_BOOLEAN__ENUM,
1274 GTK_TYPE_DIRECTION_TYPE);
1277 * GtkWidget::delete-event:
1278 * @widget: the object which received the signal
1279 * @event: the event which triggered this signal
1281 * The ::delete-event signal is emitted if a user requests that
1282 * a toplevel window is closed. The default handler for this signal
1283 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1284 * this signal will cause the window to be hidden instead, so that
1285 * it can later be shown again without reconstructing it.
1287 * Returns: %TRUE to stop other handlers from being invoked for the event.
1288 * %FALSE to propagate the event further.
1290 widget_signals[DELETE_EVENT] =
1291 g_signal_new (I_("delete-event"),
1292 G_TYPE_FROM_CLASS (gobject_class),
1294 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1295 _gtk_boolean_handled_accumulator, NULL,
1296 _gtk_marshal_BOOLEAN__BOXED,
1298 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1301 * GtkWidget::destroy-event:
1302 * @widget: the object which received the signal.
1303 * @event: the event which triggered this signal
1305 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1306 * You rarely get this signal, because most widgets disconnect themselves
1307 * from their window before they destroy it, so no widget owns the
1308 * window at destroy time.
1310 * To receive this signal, the #GdkWindow associated to the widget needs
1311 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1312 * automatically for all new windows.
1314 * Returns: %TRUE to stop other handlers from being invoked for the event.
1315 * %FALSE to propagate the event further.
1317 widget_signals[DESTROY_EVENT] =
1318 g_signal_new (I_("destroy-event"),
1319 G_TYPE_FROM_CLASS (gobject_class),
1321 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1322 _gtk_boolean_handled_accumulator, NULL,
1323 _gtk_marshal_BOOLEAN__BOXED,
1325 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1328 * GtkWidget::expose-event:
1329 * @widget: the object which received the signal.
1330 * @event: the #GdkEventExpose which triggered this signal
1332 * The ::expose-event signal is emitted when an area of a previously
1333 * obscured #GdkWindow is made visible and needs to be redrawn.
1334 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1337 * To receive this signal, the #GdkWindow associated to the widget needs
1338 * to enable the #GDK_EXPOSURE_MASK mask.
1340 * Returns: %TRUE to stop other handlers from being invoked for the event.
1341 * %FALSE to propagate the event further.
1343 widget_signals[EXPOSE_EVENT] =
1344 g_signal_new (I_("expose-event"),
1345 G_TYPE_FROM_CLASS (gobject_class),
1347 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1348 _gtk_boolean_handled_accumulator, NULL,
1349 _gtk_marshal_BOOLEAN__BOXED,
1351 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1354 * GtkWidget::key-press-event:
1355 * @widget: the object which received the signal
1356 * @event: the #GdkEventKey which triggered this signal
1358 * The ::key-press-event signal is emitted when a key is pressed.
1360 * To receive this signal, the #GdkWindow associated to the widget needs
1361 * to enable the #GDK_KEY_PRESS_MASK mask.
1363 * This signal will be sent to the grab widget if there is one.
1365 * Returns: %TRUE to stop other handlers from being invoked for the event.
1366 * %FALSE to propagate the event further.
1368 widget_signals[KEY_PRESS_EVENT] =
1369 g_signal_new (I_("key-press-event"),
1370 G_TYPE_FROM_CLASS (gobject_class),
1372 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1373 _gtk_boolean_handled_accumulator, NULL,
1374 _gtk_marshal_BOOLEAN__BOXED,
1376 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1379 * GtkWidget::key-release-event:
1380 * @widget: the object which received the signal
1381 * @event: the #GdkEventKey which triggered this signal
1383 * The ::key-release-event signal is emitted when a key is pressed.
1385 * To receive this signal, the #GdkWindow associated to the widget needs
1386 * to enable the #GDK_KEY_RELEASE_MASK mask.
1388 * This signal will be sent to the grab widget if there is one.
1390 * Returns: %TRUE to stop other handlers from being invoked for the event.
1391 * %FALSE to propagate the event further.
1393 widget_signals[KEY_RELEASE_EVENT] =
1394 g_signal_new (I_("key-release-event"),
1395 G_TYPE_FROM_CLASS (gobject_class),
1397 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1398 _gtk_boolean_handled_accumulator, NULL,
1399 _gtk_marshal_BOOLEAN__BOXED,
1401 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1404 * GtkWidget::enter-notify-event:
1405 * @widget: the object which received the signal
1406 * @event: the #GdkEventCrossing which triggered this signal
1408 * The ::enter-notify-event will be emitted when the pointer enters
1409 * the @widget's window.
1411 * To receive this signal, the #GdkWindow associated to the widget needs
1412 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1414 * This signal will be sent to the grab widget if there is one.
1416 * Returns: %TRUE to stop other handlers from being invoked for the event.
1417 * %FALSE to propagate the event further.
1419 widget_signals[ENTER_NOTIFY_EVENT] =
1420 g_signal_new (I_("enter-notify-event"),
1421 G_TYPE_FROM_CLASS (gobject_class),
1423 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1424 _gtk_boolean_handled_accumulator, NULL,
1425 _gtk_marshal_BOOLEAN__BOXED,
1427 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1430 * GtkWidget::leave-notify-event:
1431 * @widget: the object which received the signal
1432 * @event: the #GdkEventCrossing which triggered this signal
1434 * The ::leave-notify-event will be emitted when the pointer leaves
1435 * the @widget's window.
1437 * To receive this signal, the #GdkWindow associated to the widget needs
1438 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1440 * This signal will be sent to the grab widget if there is one.
1442 * Returns: %TRUE to stop other handlers from being invoked for the event.
1443 * %FALSE to propagate the event further.
1445 widget_signals[LEAVE_NOTIFY_EVENT] =
1446 g_signal_new (I_("leave-notify-event"),
1447 G_TYPE_FROM_CLASS (gobject_class),
1449 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1450 _gtk_boolean_handled_accumulator, NULL,
1451 _gtk_marshal_BOOLEAN__BOXED,
1453 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1456 * GtkWidget::configure-event
1457 * @widget: the object which received the signal
1458 * @event: the #GdkEventConfigure which triggered this signal
1460 * The ::configure-event signal will be emitted when the size, position or
1461 * stacking of the @widget's window has changed.
1463 * To receive this signal, the #GdkWindow associated to the widget needs
1464 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1465 * automatically for all new windows.
1467 * Returns: %TRUE to stop other handlers from being invoked for the event.
1468 * %FALSE to propagate the event further.
1470 widget_signals[CONFIGURE_EVENT] =
1471 g_signal_new (I_("configure-event"),
1472 G_TYPE_FROM_CLASS (gobject_class),
1474 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1475 _gtk_boolean_handled_accumulator, NULL,
1476 _gtk_marshal_BOOLEAN__BOXED,
1478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1481 * GtkWidget::focus-in-event
1482 * @widget: the object which received the signal
1483 * @event: the #GdkEventFocus which triggered this signal
1485 * The ::focus-in-event signal will be emitted when the keyboard focus
1486 * enters the @widget's window.
1488 * To receive this signal, the #GdkWindow associated to the widget needs
1489 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1491 * Returns: %TRUE to stop other handlers from being invoked for the event.
1492 * %FALSE to propagate the event further.
1494 widget_signals[FOCUS_IN_EVENT] =
1495 g_signal_new (I_("focus-in-event"),
1496 G_TYPE_FROM_CLASS (gobject_class),
1498 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1499 _gtk_boolean_handled_accumulator, NULL,
1500 _gtk_marshal_BOOLEAN__BOXED,
1502 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1505 * GtkWidget::focus-out-event
1506 * @widget: the object which received the signal
1507 * @event: the #GdkEventFocus which triggered this signal
1509 * The ::focus-out-event signal will be emitted when the keyboard focus
1510 * leaves the @widget's window.
1512 * To receive this signal, the #GdkWindow associated to the widget needs
1513 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1515 * Returns: %TRUE to stop other handlers from being invoked for the event.
1516 * %FALSE to propagate the event further.
1518 widget_signals[FOCUS_OUT_EVENT] =
1519 g_signal_new (I_("focus-out-event"),
1520 G_TYPE_FROM_CLASS (gobject_class),
1522 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1523 _gtk_boolean_handled_accumulator, NULL,
1524 _gtk_marshal_BOOLEAN__BOXED,
1526 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1529 * GtkWidget::map-event
1530 * @widget: the object which received the signal
1531 * @event: the #GdkEventAny which triggered this signal
1533 * The ::map-event signal will be emitted when the @widget's window is
1534 * mapped. A window is mapped when it becomes visible on the screen.
1536 * To receive this signal, the #GdkWindow associated to the widget needs
1537 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1538 * automatically for all new windows.
1540 * Returns: %TRUE to stop other handlers from being invoked for the event.
1541 * %FALSE to propagate the event further.
1543 widget_signals[MAP_EVENT] =
1544 g_signal_new (I_("map-event"),
1545 G_TYPE_FROM_CLASS (gobject_class),
1547 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1548 _gtk_boolean_handled_accumulator, NULL,
1549 _gtk_marshal_BOOLEAN__BOXED,
1551 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1554 * GtkWidget::unmap-event
1555 * @widget: the object which received the signal
1556 * @event: the #GdkEventAny which triggered this signal
1558 * The ::unmap-event signal will be emitted when the @widget's window is
1559 * unmapped. A window is unmapped when it becomes invisible on the screen.
1561 * To receive this signal, the #GdkWindow associated to the widget needs
1562 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1563 * automatically for all new windows.
1565 * Returns: %TRUE to stop other handlers from being invoked for the event.
1566 * %FALSE to propagate the event further.
1568 widget_signals[UNMAP_EVENT] =
1569 g_signal_new (I_("unmap-event"),
1570 G_TYPE_FROM_CLASS (gobject_class),
1572 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1573 _gtk_boolean_handled_accumulator, NULL,
1574 _gtk_marshal_BOOLEAN__BOXED,
1576 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1579 * GtkWidget::property-notify-event
1580 * @widget: the object which received the signal
1581 * @event: the #GdkEventProperty which triggered this signal
1583 * The ::property-notify-event signal will be emitted when a property on
1584 * the @widget's window has been changed or deleted.
1586 * To receive this signal, the #GdkWindow associated to the widget needs
1587 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1589 * Returns: %TRUE to stop other handlers from being invoked for the event.
1590 * %FALSE to propagate the event further.
1592 widget_signals[PROPERTY_NOTIFY_EVENT] =
1593 g_signal_new (I_("property-notify-event"),
1594 G_TYPE_FROM_CLASS (gobject_class),
1596 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1597 _gtk_boolean_handled_accumulator, NULL,
1598 _gtk_marshal_BOOLEAN__BOXED,
1600 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1603 * GtkWidget::selection-clear-event
1604 * @widget: the object which received the signal
1605 * @event: the #GdkEventSelection which triggered this signal
1607 * The ::selection-clear-event signal will be emitted when the
1608 * the @widget's window has lost ownership of a selection.
1610 * Returns: %TRUE to stop other handlers from being invoked for the event.
1611 * %FALSE to propagate the event further.
1613 widget_signals[SELECTION_CLEAR_EVENT] =
1614 g_signal_new (I_("selection-clear-event"),
1615 G_TYPE_FROM_CLASS (gobject_class),
1617 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1618 _gtk_boolean_handled_accumulator, NULL,
1619 _gtk_marshal_BOOLEAN__BOXED,
1621 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1624 * GtkWidget::selection-request-event
1625 * @widget: the object which received the signal
1626 * @event: the #GdkEventSelection which triggered this signal
1628 * The ::selection-request-event signal will be emitted when
1629 * another client requests ownership of the selection owned by
1630 * the @widget's window.
1632 * Returns: %TRUE to stop other handlers from being invoked for the event.
1633 * %FALSE to propagate the event further.
1635 widget_signals[SELECTION_REQUEST_EVENT] =
1636 g_signal_new (I_("selection-request-event"),
1637 G_TYPE_FROM_CLASS (gobject_class),
1639 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1640 _gtk_boolean_handled_accumulator, NULL,
1641 _gtk_marshal_BOOLEAN__BOXED,
1643 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1646 * GtkWidget::selection-notify-event:
1647 * @widget: the object which received the signal.
1650 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1652 widget_signals[SELECTION_NOTIFY_EVENT] =
1653 g_signal_new (I_("selection-notify-event"),
1654 G_TYPE_FROM_CLASS (gobject_class),
1656 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1657 _gtk_boolean_handled_accumulator, NULL,
1658 _gtk_marshal_BOOLEAN__BOXED,
1660 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1663 * GtkWidget::selection-received:
1664 * @widget: the object which received the signal.
1668 widget_signals[SELECTION_RECEIVED] =
1669 g_signal_new (I_("selection-received"),
1670 G_TYPE_FROM_CLASS (gobject_class),
1672 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1674 _gtk_marshal_VOID__BOXED_UINT,
1676 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1680 * GtkWidget::selection-get:
1681 * @widget: the object which received the signal.
1686 widget_signals[SELECTION_GET] =
1687 g_signal_new (I_("selection-get"),
1688 G_TYPE_FROM_CLASS (gobject_class),
1690 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1692 _gtk_marshal_VOID__BOXED_UINT_UINT,
1694 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1699 * GtkWidget::proximity-in-event
1700 * @widget: the object which received the signal
1701 * @event: the #GdkEventProximity which triggered this signal
1703 * To receive this signal the #GdkWindow associated to the widget needs
1704 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1706 * This signal will be sent to the grab widget if there is one.
1708 * Returns: %TRUE to stop other handlers from being invoked for the event.
1709 * %FALSE to propagate the event further.
1711 widget_signals[PROXIMITY_IN_EVENT] =
1712 g_signal_new (I_("proximity-in-event"),
1713 G_TYPE_FROM_CLASS (gobject_class),
1715 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1716 _gtk_boolean_handled_accumulator, NULL,
1717 _gtk_marshal_BOOLEAN__BOXED,
1719 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1722 * GtkWidget::proximity-out-event
1723 * @widget: the object which received the signal
1724 * @event: the #GdkEventProximity which triggered this signal
1726 * To receive this signal the #GdkWindow associated to the widget needs
1727 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1729 * This signal will be sent to the grab widget if there is one.
1731 * Returns: %TRUE to stop other handlers from being invoked for the event.
1732 * %FALSE to propagate the event further.
1734 widget_signals[PROXIMITY_OUT_EVENT] =
1735 g_signal_new (I_("proximity-out-event"),
1736 G_TYPE_FROM_CLASS (gobject_class),
1738 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1739 _gtk_boolean_handled_accumulator, NULL,
1740 _gtk_marshal_BOOLEAN__BOXED,
1742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1745 * GtkWidget::drag-leave:
1746 * @widget: the object which received the signal.
1747 * @drag_context: the drag context
1748 * @time: the timestamp of the motion event
1750 * The ::drag-leave signal is emitted on the drop site when the cursor
1751 * leaves the widget. A typical reason to connect to this signal is to
1752 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1753 * with gtk_drag_unhighlight()
1755 widget_signals[DRAG_LEAVE] =
1756 g_signal_new (I_("drag-leave"),
1757 G_TYPE_FROM_CLASS (gobject_class),
1759 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1761 _gtk_marshal_VOID__OBJECT_UINT,
1763 GDK_TYPE_DRAG_CONTEXT,
1767 * GtkWidget::drag-begin:
1768 * @widget: the object which received the signal
1769 * @drag_context: the drag context
1771 * The ::drag-begin signal is emitted on the drag source when a drag is
1772 * started. A typical reason to connect to this signal is to set up a
1773 * custom drag icon with gtk_drag_source_set_icon().
1775 * Note that some widgets set up a drag icon in the default handler of
1776 * this signal, so you may have to use g_signal_connect_after() to
1777 * override what the default handler did.
1779 widget_signals[DRAG_BEGIN] =
1780 g_signal_new (I_("drag-begin"),
1781 G_TYPE_FROM_CLASS (gobject_class),
1783 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1785 _gtk_marshal_VOID__OBJECT,
1787 GDK_TYPE_DRAG_CONTEXT);
1790 * GtkWidget::drag-end:
1791 * @widget: the object which received the signal
1792 * @drag_context: the drag context
1794 * The ::drag-end signal is emitted on the drag source when a drag is
1795 * finished. A typical reason to connect to this signal is to undo
1796 * things done in #GtkWidget::drag-begin.
1798 widget_signals[DRAG_END] =
1799 g_signal_new (I_("drag-end"),
1800 G_TYPE_FROM_CLASS (gobject_class),
1802 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1804 _gtk_marshal_VOID__OBJECT,
1806 GDK_TYPE_DRAG_CONTEXT);
1809 * GtkWidget::drag-data-delete:
1810 * @widget: the object which received the signal
1811 * @drag_context: the drag context
1813 * The ::drag-data-delete signal is emitted on the drag source when a drag
1814 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1815 * handler is responsible for deleting the data that has been dropped. What
1816 * "delete" means depends on the context of the drag operation.
1818 widget_signals[DRAG_DATA_DELETE] =
1819 g_signal_new (I_("drag-data-delete"),
1820 G_TYPE_FROM_CLASS (gobject_class),
1822 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1824 _gtk_marshal_VOID__OBJECT,
1826 GDK_TYPE_DRAG_CONTEXT);
1829 * GtkWidget::drag-failed:
1830 * @widget: the object which received the signal
1831 * @drag_context: the drag context
1832 * @result: the result of the drag operation
1834 * The ::drag-failed signal is emitted on the drag source when a drag has
1835 * failed. The signal handler may hook custom code to handle a failed DND
1836 * operation based on the type of error, it returns %TRUE is the failure has
1837 * been already handled (not showing the default "drag operation failed"
1838 * animation), otherwise it returns %FALSE.
1840 * Return value: %TRUE if the failed drag operation has been already handled.
1844 widget_signals[DRAG_FAILED] =
1845 g_signal_new (I_("drag-failed"),
1846 G_TYPE_FROM_CLASS (gobject_class),
1848 0, _gtk_boolean_handled_accumulator, NULL,
1849 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1851 GDK_TYPE_DRAG_CONTEXT,
1852 GTK_TYPE_DRAG_RESULT);
1855 * GtkWidget::drag-motion:
1856 * @widget: the object which received the signal
1857 * @drag_context: the drag context
1858 * @x: the x coordinate of the current cursor position
1859 * @y: the y coordinate of the current cursor position
1860 * @time: the timestamp of the motion event
1861 * @returns: whether the cursor position is in a drop zone
1863 * The drag-motion signal is emitted on the drop site when the user
1864 * moves the cursor over the widget during a drag. The signal handler
1865 * must determine whether the cursor position is in a drop zone or not.
1866 * If it is not in a drop zone, it returns %FALSE and no further processing
1867 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1868 * handler is responsible for providing the necessary information for
1869 * displaying feedback to the user, by calling gdk_drag_status().
1871 * If the decision whether the drop will be accepted or rejected can't be
1872 * made based solely on the cursor position and the type of the data, the
1873 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1874 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1875 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1876 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1877 * when using the drag-motion signal that way.
1879 * Also note that there is no drag-enter signal. The drag receiver has to
1880 * keep track of whether he has received any drag-motion signals since the
1881 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1882 * an "enter" signal. Upon an "enter", the handler will typically highlight
1883 * the drop site with gtk_drag_highlight().
1886 * drag_motion (GtkWidget *widget,
1887 * GdkDragContext *context,
1894 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1896 * if (!private_data->drag_highlight)
1898 * private_data->drag_highlight = 1;
1899 * gtk_drag_highlight (widget);
1902 * target = gtk_drag_dest_find_target (widget, context, NULL);
1903 * if (target == GDK_NONE)
1904 * gdk_drag_status (context, 0, time);
1907 * private_data->pending_status = context->suggested_action;
1908 * gtk_drag_get_data (widget, context, target, time);
1915 * drag_data_received (GtkWidget *widget,
1916 * GdkDragContext *context,
1919 * GtkSelectionData *selection_data,
1923 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1925 * if (private_data->suggested_action)
1927 * private_data->suggested_action = 0;
1929 * /* We are getting this data due to a request in drag_motion,
1930 * * rather than due to a request in drag_drop, so we are just
1931 * * supposed to call gdk_drag_status (), not actually paste in
1934 * str = gtk_selection_data_get_text (selection_data);
1935 * if (!data_is_acceptable (str))
1936 * gdk_drag_status (context, 0, time);
1938 * gdk_drag_status (context, private_data->suggested_action, time);
1942 * /* accept the drop */
1947 widget_signals[DRAG_MOTION] =
1948 g_signal_new (I_("drag-motion"),
1949 G_TYPE_FROM_CLASS (gobject_class),
1951 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1952 _gtk_boolean_handled_accumulator, NULL,
1953 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1955 GDK_TYPE_DRAG_CONTEXT,
1961 * GtkWidget::drag-drop:
1962 * @widget: the object which received the signal
1963 * @drag_context: the drag context
1964 * @x: the x coordinate of the current cursor position
1965 * @y: the y coordinate of the current cursor position
1966 * @time: the timestamp of the motion event
1967 * @returns: whether the cursor position is in a drop zone
1969 * The ::drag-drop signal is emitted on the drop site when the user drops
1970 * the data onto the widget. The signal handler must determine whether
1971 * the cursor position is in a drop zone or not. If it is not in a drop
1972 * zone, it returns %FALSE and no further processing is necessary.
1973 * Otherwise, the handler returns %TRUE. In this case, the handler must
1974 * ensure that gtk_drag_finish() is called to let the source know that
1975 * the drop is done. The call to gtk_drag_finish() can be done either
1976 * directly or in a #GtkWidget::drag-data-received handler which gets
1977 * triggered by calling gtk_drag_get_data() to receive the data for one
1978 * or more of the supported targets.
1980 widget_signals[DRAG_DROP] =
1981 g_signal_new (I_("drag-drop"),
1982 G_TYPE_FROM_CLASS (gobject_class),
1984 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1985 _gtk_boolean_handled_accumulator, NULL,
1986 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1988 GDK_TYPE_DRAG_CONTEXT,
1994 * GtkWidget::drag-data-get:
1995 * @widget: the object which received the signal
1996 * @drag_context: the drag context
1997 * @data: the #GtkSelectionData to be filled with the dragged data
1998 * @info: the info that has been registered with the target in the
2000 * @time: the timestamp at which the data was requested
2002 * The ::drag-data-get signal is emitted on the drag source when the drop
2003 * site requests the data which is dragged. It is the responsibility of
2004 * the signal handler to fill @data with the data in the format which
2005 * is indicated by @info. See gtk_selection_data_set() and
2006 * gtk_selection_data_set_text().
2008 widget_signals[DRAG_DATA_GET] =
2009 g_signal_new (I_("drag-data-get"),
2010 G_TYPE_FROM_CLASS (gobject_class),
2012 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2014 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2016 GDK_TYPE_DRAG_CONTEXT,
2017 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2022 * GtkWidget::drag-data-received:
2023 * @widget: the object which received the signal
2024 * @drag_context: the drag context
2025 * @x: where the drop happened
2026 * @y: where the drop happened
2027 * @data: the received data
2028 * @info: the info that has been registered with the target in the
2030 * @time: the timestamp at which the data was received
2032 * The ::drag-data-received signal is emitted on the drop site when the
2033 * dragged data has been received. If the data was received in order to
2034 * determine whether the drop will be accepted, the handler is expected
2035 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2036 * If the data was received in response to a #GtkWidget::drag-drop signal
2037 * (and this is the last target to be received), the handler for this
2038 * signal is expected to process the received data and then call
2039 * gtk_drag_finish(), setting the @success parameter depending on whether
2040 * the data was processed successfully.
2042 * The handler may inspect and modify @drag_context->action before calling
2043 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2044 * following example:
2047 * drag_data_received (GtkWidget *widget,
2048 * GdkDragContext *drag_context,
2051 * GtkSelectionData *data,
2055 * if ((data->length >= 0) && (data->format == 8))
2057 * if (drag_context->action == GDK_ACTION_ASK)
2059 * GtkWidget *dialog;
2062 * dialog = gtk_message_dialog_new (NULL,
2063 * GTK_DIALOG_MODAL |
2064 * GTK_DIALOG_DESTROY_WITH_PARENT,
2066 * GTK_BUTTONS_YES_NO,
2067 * "Move the data ?\n");
2068 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2069 * gtk_widget_destroy (dialog);
2071 * if (response == GTK_RESPONSE_YES)
2072 * drag_context->action = GDK_ACTION_MOVE;
2074 * drag_context->action = GDK_ACTION_COPY;
2077 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2081 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2085 widget_signals[DRAG_DATA_RECEIVED] =
2086 g_signal_new (I_("drag-data-received"),
2087 G_TYPE_FROM_CLASS (gobject_class),
2089 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2091 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2093 GDK_TYPE_DRAG_CONTEXT,
2096 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2101 * GtkWidget::visibility-notify-event:
2102 * @widget: the object which received the signal
2103 * @event: the #GdkEventVisibility which triggered this signal
2105 * The ::visibility-notify-event will be emitted when the @widget's window
2106 * is obscured or unobscured.
2108 * To receive this signal the #GdkWindow associated to the widget needs
2109 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2111 * Returns: %TRUE to stop other handlers from being invoked for the event.
2112 * %FALSE to propagate the event further.
2114 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2115 g_signal_new (I_("visibility-notify-event"),
2116 G_TYPE_FROM_CLASS (gobject_class),
2118 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2119 _gtk_boolean_handled_accumulator, NULL,
2120 _gtk_marshal_BOOLEAN__BOXED,
2122 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2125 * GtkWidget::client-event:
2126 * @widget: the object which received the signal
2127 * @event: the #GdkEventClient which triggered this signal
2129 * The ::client-event will be emitted when the @widget's window
2130 * receives a message (via a ClientMessage event) from another
2133 * Returns: %TRUE to stop other handlers from being invoked for
2134 * the event. %FALSE to propagate the event further.
2136 widget_signals[CLIENT_EVENT] =
2137 g_signal_new (I_("client-event"),
2138 G_TYPE_FROM_CLASS (gobject_class),
2140 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2141 _gtk_boolean_handled_accumulator, NULL,
2142 _gtk_marshal_BOOLEAN__BOXED,
2144 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2147 * GtkWidget::no-expose-event:
2148 * @widget: the object which received the signal
2149 * @event: the #GdkEventNoExpose which triggered this signal
2151 * The ::no-expose-event will be emitted when the @widget's window is
2152 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2153 * gdk_window_copy_area()) which was completely unobscured. If the source
2154 * window was partially obscured #GdkEventExpose events will be generated
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[NO_EXPOSE_EVENT] =
2161 g_signal_new (I_("no-expose-event"),
2162 G_TYPE_FROM_CLASS (gobject_class),
2164 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2171 * GtkWidget::window-state-event:
2172 * @widget: the object which received the signal
2173 * @event: the #GdkEventWindowState which triggered this signal
2175 * The ::window-state-event will be emitted when the state of the
2176 * toplevel window associated to the @widget changes.
2178 * To receive this signal the #GdkWindow associated to the widget
2179 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2180 * this mask automatically for all new windows.
2182 * Returns: %TRUE to stop other handlers from being invoked for the
2183 * event. %FALSE to propagate the event further.
2185 widget_signals[WINDOW_STATE_EVENT] =
2186 g_signal_new (I_("window-state-event"),
2187 G_TYPE_FROM_CLASS (gobject_class),
2189 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2190 _gtk_boolean_handled_accumulator, NULL,
2191 _gtk_marshal_BOOLEAN__BOXED,
2193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2196 * GtkWidget::damage-event:
2197 * @widget: the object which received the signal
2198 * @event: the #GdkEventExpose event
2200 * Emitted when a redirected window belonging to @widget gets drawn into.
2201 * The region/area members of the event shows what area of the redirected
2202 * drawable was drawn into.
2204 * Returns: %TRUE to stop other handlers from being invoked for the event.
2205 * %FALSE to propagate the event further.
2209 widget_signals[DAMAGE_EVENT] =
2210 g_signal_new (I_("damage-event"),
2211 G_TYPE_FROM_CLASS (gobject_class),
2214 _gtk_boolean_handled_accumulator, NULL,
2215 _gtk_marshal_BOOLEAN__BOXED,
2217 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2219 * GtkWidget::grab-broken-event:
2220 * @widget: the object which received the signal
2221 * @event: the #GdkEventGrabBroken event
2223 * Emitted when a pointer or keyboard grab on a window belonging
2224 * to @widget gets broken.
2226 * On X11, this happens when the grab window becomes unviewable
2227 * (i.e. it or one of its ancestors is unmapped), or if the same
2228 * application grabs the pointer or keyboard again.
2230 * Returns: %TRUE to stop other handlers from being invoked for
2231 * the event. %FALSE to propagate the event further.
2235 widget_signals[GRAB_BROKEN] =
2236 g_signal_new (I_("grab-broken-event"),
2237 G_TYPE_FROM_CLASS (gobject_class),
2239 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2240 _gtk_boolean_handled_accumulator, NULL,
2241 _gtk_marshal_BOOLEAN__BOXED,
2243 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2245 * GtkWidget::query-tooltip:
2246 * @widget: the object which received the signal
2247 * @x: the x coordinate of the cursor position where the request has
2248 * been emitted, relative to @widget->window
2249 * @y: the y coordinate of the cursor position where the request has
2250 * been emitted, relative to @widget->window
2251 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2252 * @tooltip: a #GtkTooltip
2254 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2255 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2256 * focus in keyboard mode.
2258 * Using the given coordinates, the signal handler should determine
2259 * whether a tooltip should be shown for @widget. If this is the case
2260 * %TRUE should be returned, %FALSE otherwise. Note that if
2261 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2262 * should not be used.
2264 * The signal handler is free to manipulate @tooltip with the therefore
2265 * destined function calls.
2267 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2271 widget_signals[QUERY_TOOLTIP] =
2272 g_signal_new (I_("query-tooltip"),
2273 G_TYPE_FROM_CLASS (gobject_class),
2275 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2276 _gtk_boolean_handled_accumulator, NULL,
2277 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2285 * GtkWidget::popup-menu
2286 * @widget: the object which received the signal
2288 * This signal gets emitted whenever a widget should pop up a context
2289 * menu. This usually happens through the standard key binding mechanism;
2290 * by pressing a certain key while a widget is focused, the user can cause
2291 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2292 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2293 * for an example of how to use this signal.
2295 * Returns: %TRUE if a menu was activated
2297 widget_signals[POPUP_MENU] =
2298 g_signal_new (I_("popup-menu"),
2299 G_TYPE_FROM_CLASS (gobject_class),
2300 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2301 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2302 _gtk_boolean_handled_accumulator, NULL,
2303 _gtk_marshal_BOOLEAN__VOID,
2307 * GtkWidget::show-help:
2308 * @widget: the object which received the signal.
2311 widget_signals[SHOW_HELP] =
2312 g_signal_new (I_("show-help"),
2313 G_TYPE_FROM_CLASS (gobject_class),
2314 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2315 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2316 _gtk_boolean_handled_accumulator, NULL,
2317 _gtk_marshal_BOOLEAN__ENUM,
2319 GTK_TYPE_WIDGET_HELP_TYPE);
2322 * GtkWidget::accel-closures-changed:
2323 * @widget: the object which received the signal.
2325 widget_signals[ACCEL_CLOSURES_CHANGED] =
2326 g_signal_new (I_("accel-closures-changed"),
2327 G_TYPE_FROM_CLASS (gobject_class),
2331 _gtk_marshal_VOID__VOID,
2335 * GtkWidget::screen-changed:
2336 * @widget: the object on which the signal is emitted
2337 * @previous_screen: the previous screen, or %NULL if the
2338 * widget was not associated with a screen before
2340 * The ::screen-changed signal gets emitted when the
2341 * screen of a widget has changed.
2343 widget_signals[SCREEN_CHANGED] =
2344 g_signal_new (I_("screen-changed"),
2345 G_TYPE_FROM_CLASS (gobject_class),
2347 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2349 _gtk_marshal_VOID__OBJECT,
2354 * GtkWidget::can-activate-accel:
2355 * @widget: the object which received the signal
2356 * @signal_id: the ID of a signal installed on @widget
2358 * Determines whether an accelerator that activates the signal
2359 * identified by @signal_id can currently be activated.
2360 * This signal is present to allow applications and derived
2361 * widgets to override the default #GtkWidget handling
2362 * for determining whether an accelerator can be activated.
2364 * Returns: %TRUE if the signal can be activated.
2366 widget_signals[CAN_ACTIVATE_ACCEL] =
2367 g_signal_new (I_("can-activate-accel"),
2368 G_TYPE_FROM_CLASS (gobject_class),
2370 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2371 _gtk_boolean_handled_accumulator, NULL,
2372 _gtk_marshal_BOOLEAN__UINT,
2373 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2375 binding_set = gtk_binding_set_by_class (klass);
2376 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2378 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2381 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2383 GTK_TYPE_WIDGET_HELP_TYPE,
2384 GTK_WIDGET_HELP_TOOLTIP);
2385 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2387 GTK_TYPE_WIDGET_HELP_TYPE,
2388 GTK_WIDGET_HELP_TOOLTIP);
2389 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2391 GTK_TYPE_WIDGET_HELP_TYPE,
2392 GTK_WIDGET_HELP_WHATS_THIS);
2393 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2395 GTK_TYPE_WIDGET_HELP_TYPE,
2396 GTK_WIDGET_HELP_WHATS_THIS);
2398 gtk_widget_class_install_style_property (klass,
2399 g_param_spec_boolean ("interior-focus",
2400 P_("Interior Focus"),
2401 P_("Whether to draw the focus indicator inside widgets"),
2403 GTK_PARAM_READABLE));
2405 gtk_widget_class_install_style_property (klass,
2406 g_param_spec_int ("focus-line-width",
2407 P_("Focus linewidth"),
2408 P_("Width, in pixels, of the focus indicator line"),
2410 GTK_PARAM_READABLE));
2412 gtk_widget_class_install_style_property (klass,
2413 g_param_spec_string ("focus-line-pattern",
2414 P_("Focus line dash pattern"),
2415 P_("Dash pattern used to draw the focus indicator"),
2417 GTK_PARAM_READABLE));
2418 gtk_widget_class_install_style_property (klass,
2419 g_param_spec_int ("focus-padding",
2420 P_("Focus padding"),
2421 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2423 GTK_PARAM_READABLE));
2424 gtk_widget_class_install_style_property (klass,
2425 g_param_spec_boxed ("cursor-color",
2427 P_("Color with which to draw insertion cursor"),
2429 GTK_PARAM_READABLE));
2430 gtk_widget_class_install_style_property (klass,
2431 g_param_spec_boxed ("secondary-cursor-color",
2432 P_("Secondary cursor color"),
2433 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2435 GTK_PARAM_READABLE));
2436 gtk_widget_class_install_style_property (klass,
2437 g_param_spec_float ("cursor-aspect-ratio",
2438 P_("Cursor line aspect ratio"),
2439 P_("Aspect ratio with which to draw insertion cursor"),
2441 GTK_PARAM_READABLE));
2444 * GtkWidget:draw-border:
2446 * The "draw-border" style property defines the size of areas outside
2447 * the widget's allocation to draw.
2451 gtk_widget_class_install_style_property (klass,
2452 g_param_spec_boxed ("draw-border",
2454 P_("Size of areas outside the widget's allocation to draw"),
2456 GTK_PARAM_READABLE));
2459 * GtkWidget:link-color:
2461 * The "link-color" style property defines the color of unvisited links.
2465 gtk_widget_class_install_style_property (klass,
2466 g_param_spec_boxed ("link-color",
2467 P_("Unvisited Link Color"),
2468 P_("Color of unvisited links"),
2470 GTK_PARAM_READABLE));
2473 * GtkWidget:visited-link-color:
2475 * The "visited-link-color" style property defines the color of visited links.
2479 gtk_widget_class_install_style_property (klass,
2480 g_param_spec_boxed ("visited-link-color",
2481 P_("Visited Link Color"),
2482 P_("Color of visited links"),
2484 GTK_PARAM_READABLE));
2487 * GtkWidget:wide-separators:
2489 * The "wide-separators" style property defines whether separators have
2490 * configurable width and should be drawn using a box instead of a line.
2494 gtk_widget_class_install_style_property (klass,
2495 g_param_spec_boolean ("wide-separators",
2496 P_("Wide Separators"),
2497 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2499 GTK_PARAM_READABLE));
2502 * GtkWidget:separator-width:
2504 * The "separator-width" style property defines the width of separators.
2505 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2509 gtk_widget_class_install_style_property (klass,
2510 g_param_spec_int ("separator-width",
2511 P_("Separator Width"),
2512 P_("The width of separators if wide-separators is TRUE"),
2514 GTK_PARAM_READABLE));
2517 * GtkWidget:separator-height:
2519 * The "separator-height" style property defines the height of separators.
2520 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2524 gtk_widget_class_install_style_property (klass,
2525 g_param_spec_int ("separator-height",
2526 P_("Separator Height"),
2527 P_("The height of separators if \"wide-separators\" is TRUE"),
2529 GTK_PARAM_READABLE));
2532 * GtkWidget:scroll-arrow-hlength:
2534 * The "scroll-arrow-hlength" style property defines the length of
2535 * horizontal scroll arrows.
2539 gtk_widget_class_install_style_property (klass,
2540 g_param_spec_int ("scroll-arrow-hlength",
2541 P_("Horizontal Scroll Arrow Length"),
2542 P_("The length of horizontal scroll arrows"),
2544 GTK_PARAM_READABLE));
2547 * GtkWidget:scroll-arrow-vlength:
2549 * The "scroll-arrow-vlength" style property defines the length of
2550 * vertical scroll arrows.
2554 gtk_widget_class_install_style_property (klass,
2555 g_param_spec_int ("scroll-arrow-vlength",
2556 P_("Vertical Scroll Arrow Length"),
2557 P_("The length of vertical scroll arrows"),
2559 GTK_PARAM_READABLE));
2563 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2567 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2568 for (node = list; node; node = node->next)
2570 GParamSpec *pspec = node->data;
2572 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2573 g_param_spec_unref (pspec);
2579 gtk_widget_set_property (GObject *object,
2581 const GValue *value,
2584 GtkWidget *widget = GTK_WIDGET (object);
2589 gchar *tooltip_markup;
2590 const gchar *tooltip_text;
2591 GtkWindow *tooltip_window;
2594 gtk_widget_set_name (widget, g_value_get_string (value));
2597 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2599 case PROP_WIDTH_REQUEST:
2600 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2602 case PROP_HEIGHT_REQUEST:
2603 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2606 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2608 case PROP_SENSITIVE:
2609 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2611 case PROP_APP_PAINTABLE:
2612 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2614 case PROP_CAN_FOCUS:
2615 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2617 case PROP_HAS_FOCUS:
2618 if (g_value_get_boolean (value))
2619 gtk_widget_grab_focus (widget);
2622 if (g_value_get_boolean (value))
2623 gtk_widget_grab_focus (widget);
2625 case PROP_CAN_DEFAULT:
2626 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2628 case PROP_HAS_DEFAULT:
2629 if (g_value_get_boolean (value))
2630 gtk_widget_grab_default (widget);
2632 case PROP_RECEIVES_DEFAULT:
2633 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2636 gtk_widget_set_style (widget, g_value_get_object (value));
2639 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2640 gtk_widget_set_events (widget, g_value_get_flags (value));
2642 case PROP_EXTENSION_EVENTS:
2643 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2645 case PROP_NO_SHOW_ALL:
2646 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2648 case PROP_HAS_TOOLTIP:
2649 gtk_widget_real_set_has_tooltip (widget,
2650 g_value_get_boolean (value), FALSE);
2652 case PROP_TOOLTIP_MARKUP:
2653 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2654 tooltip_markup = g_value_dup_string (value);
2656 /* Treat an empty string as a NULL string,
2657 * because an empty string would be useless for a tooltip:
2659 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2661 g_free (tooltip_markup);
2662 tooltip_markup = NULL;
2665 g_object_set_qdata_full (object, quark_tooltip_markup,
2666 tooltip_markup, g_free);
2668 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2669 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2670 if (GTK_WIDGET_VISIBLE (widget))
2671 gtk_widget_queue_tooltip_query (widget);
2673 case PROP_TOOLTIP_TEXT:
2674 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2676 tooltip_text = g_value_get_string (value);
2678 /* Treat an empty string as a NULL string,
2679 * because an empty string would be useless for a tooltip:
2681 if (tooltip_text && (strlen (tooltip_text) == 0))
2682 tooltip_text = NULL;
2684 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2686 g_object_set_qdata_full (object, quark_tooltip_markup,
2687 tooltip_markup, g_free);
2689 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2690 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2691 if (GTK_WIDGET_VISIBLE (widget))
2692 gtk_widget_queue_tooltip_query (widget);
2694 case PROP_DOUBLE_BUFFERED:
2695 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2698 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2704 gtk_widget_get_property (GObject *object,
2709 GtkWidget *widget = GTK_WIDGET (object);
2718 g_value_set_string (value, widget->name);
2720 g_value_set_static_string (value, "");
2723 g_value_set_object (value, widget->parent);
2725 case PROP_WIDTH_REQUEST:
2728 gtk_widget_get_size_request (widget, &w, NULL);
2729 g_value_set_int (value, w);
2732 case PROP_HEIGHT_REQUEST:
2735 gtk_widget_get_size_request (widget, NULL, &h);
2736 g_value_set_int (value, h);
2740 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2742 case PROP_SENSITIVE:
2743 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2745 case PROP_APP_PAINTABLE:
2746 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2748 case PROP_CAN_FOCUS:
2749 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2751 case PROP_HAS_FOCUS:
2752 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2755 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2757 case PROP_CAN_DEFAULT:
2758 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2760 case PROP_HAS_DEFAULT:
2761 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2763 case PROP_RECEIVES_DEFAULT:
2764 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2766 case PROP_COMPOSITE_CHILD:
2767 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2770 g_value_set_object (value, gtk_widget_get_style (widget));
2773 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2774 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2776 case PROP_EXTENSION_EVENTS:
2777 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2778 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2780 case PROP_NO_SHOW_ALL:
2781 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2783 case PROP_HAS_TOOLTIP:
2784 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2786 case PROP_TOOLTIP_TEXT:
2788 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2791 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2792 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2794 g_value_set_string (value, text);
2798 case PROP_TOOLTIP_MARKUP:
2799 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2802 g_value_set_object (value, gtk_widget_get_window (widget));
2804 case PROP_DOUBLE_BUFFERED:
2805 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2808 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2814 gtk_widget_init (GtkWidget *widget)
2816 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2817 widget->state = GTK_STATE_NORMAL;
2818 widget->saved_state = GTK_STATE_NORMAL;
2819 widget->name = NULL;
2820 widget->requisition.width = 0;
2821 widget->requisition.height = 0;
2822 widget->allocation.x = -1;
2823 widget->allocation.y = -1;
2824 widget->allocation.width = 1;
2825 widget->allocation.height = 1;
2826 widget->window = NULL;
2827 widget->parent = NULL;
2829 GTK_WIDGET_SET_FLAGS (widget,
2831 GTK_PARENT_SENSITIVE |
2832 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2833 GTK_DOUBLE_BUFFERED);
2835 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2836 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2837 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2839 widget->style = gtk_widget_get_default_style ();
2840 g_object_ref (widget->style);
2845 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2847 GParamSpec **pspecs)
2849 GtkWidget *container = widget->parent;
2852 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2853 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2857 * gtk_widget_freeze_child_notify:
2858 * @widget: a #GtkWidget
2860 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2861 * signals are queued until gtk_widget_thaw_child_notify() is called
2864 * This is the analogue of g_object_freeze_notify() for child properties.
2867 gtk_widget_freeze_child_notify (GtkWidget *widget)
2869 g_return_if_fail (GTK_IS_WIDGET (widget));
2871 if (!G_OBJECT (widget)->ref_count)
2874 g_object_ref (widget);
2875 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2876 g_object_unref (widget);
2880 * gtk_widget_child_notify:
2881 * @widget: a #GtkWidget
2882 * @child_property: the name of a child property installed on the
2883 * class of @widget<!-- -->'s parent
2885 * Emits a #GtkWidget::child-notify signal for the
2886 * <link linkend="child-properties">child property</link> @child_property
2889 * This is the analogue of g_object_notify() for child properties.
2892 gtk_widget_child_notify (GtkWidget *widget,
2893 const gchar *child_property)
2897 g_return_if_fail (GTK_IS_WIDGET (widget));
2898 g_return_if_fail (child_property != NULL);
2899 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2902 g_object_ref (widget);
2903 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2905 G_OBJECT_TYPE (widget->parent),
2908 g_warning ("%s: container class `%s' has no child property named `%s'",
2910 G_OBJECT_TYPE_NAME (widget->parent),
2914 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2916 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2917 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2919 g_object_unref (widget);
2923 * gtk_widget_thaw_child_notify:
2924 * @widget: a #GtkWidget
2926 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2927 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2931 gtk_widget_thaw_child_notify (GtkWidget *widget)
2933 GObjectNotifyQueue *nqueue;
2935 g_return_if_fail (GTK_IS_WIDGET (widget));
2937 if (!G_OBJECT (widget)->ref_count)
2940 g_object_ref (widget);
2941 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2942 if (!nqueue || !nqueue->freeze_count)
2943 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2944 G_OBJECT_TYPE_NAME (widget), widget);
2946 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2947 g_object_unref (widget);
2953 * @type: type ID of the widget to create
2954 * @first_property_name: name of first property to set
2955 * @Varargs: value of first property, followed by more properties,
2958 * This is a convenience function for creating a widget and setting
2959 * its properties in one go. For example you might write:
2960 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2961 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2962 * g_object_new(), but returns a widget so you don't have to
2963 * cast the object yourself.
2965 * Return value: a new #GtkWidget of type @widget_type
2968 gtk_widget_new (GType type,
2969 const gchar *first_property_name,
2975 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2977 va_start (var_args, first_property_name);
2978 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2986 * @widget: a #GtkWidget
2987 * @first_property_name: name of first property to set
2988 * @Varargs: value of first property, followed by more properties,
2991 * Precursor of g_object_set().
2993 * Deprecated: 2.0: Use g_object_set() instead.
2996 gtk_widget_set (GtkWidget *widget,
2997 const gchar *first_property_name,
3002 g_return_if_fail (GTK_IS_WIDGET (widget));
3004 va_start (var_args, first_property_name);
3005 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3010 gtk_widget_queue_draw_child (GtkWidget *widget)
3014 parent = widget->parent;
3015 if (parent && GTK_WIDGET_DRAWABLE (parent))
3016 gtk_widget_queue_draw_area (parent,
3017 widget->allocation.x,
3018 widget->allocation.y,
3019 widget->allocation.width,
3020 widget->allocation.height);
3024 * gtk_widget_unparent:
3025 * @widget: a #GtkWidget
3027 * This function is only for use in widget implementations.
3028 * Should be called by implementations of the remove method
3029 * on #GtkContainer, to dissociate a child from the container.
3032 gtk_widget_unparent (GtkWidget *widget)
3034 GObjectNotifyQueue *nqueue;
3035 GtkWidget *toplevel;
3036 GtkWidget *old_parent;
3038 g_return_if_fail (GTK_IS_WIDGET (widget));
3039 if (widget->parent == NULL)
3042 /* keep this function in sync with gtk_menu_detach()
3045 g_object_freeze_notify (G_OBJECT (widget));
3046 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3048 toplevel = gtk_widget_get_toplevel (widget);
3049 if (GTK_WIDGET_TOPLEVEL (toplevel))
3050 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3052 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3053 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3055 /* If we are unanchoring the child, we save around the toplevel
3056 * to emit hierarchy changed
3058 if (GTK_WIDGET_ANCHORED (widget->parent))
3059 g_object_ref (toplevel);
3063 gtk_widget_queue_draw_child (widget);
3065 /* Reset the width and height here, to force reallocation if we
3066 * get added back to a new parent. This won't work if our new
3067 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3068 * (would 0x0 be OK here?)
3070 widget->allocation.width = 1;
3071 widget->allocation.height = 1;
3073 if (GTK_WIDGET_REALIZED (widget))
3075 if (GTK_WIDGET_IN_REPARENT (widget))
3076 gtk_widget_unmap (widget);
3078 gtk_widget_unrealize (widget);
3081 /* Removing a widget from a container restores the child visible
3082 * flag to the default state, so it doesn't affect the child
3083 * in the next parent.
3085 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3087 old_parent = widget->parent;
3088 widget->parent = NULL;
3089 gtk_widget_set_parent_window (widget, NULL);
3090 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3093 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3094 g_object_unref (toplevel);
3097 g_object_notify (G_OBJECT (widget), "parent");
3098 g_object_thaw_notify (G_OBJECT (widget));
3099 if (!widget->parent)
3100 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3101 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3102 g_object_unref (widget);
3106 * gtk_widget_destroy:
3107 * @widget: a #GtkWidget
3109 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3110 * you don't have to cast the widget to #GtkObject. When a widget is
3111 * destroyed, it will break any references it holds to other objects.
3112 * If the widget is inside a container, the widget will be removed
3113 * from the container. If the widget is a toplevel (derived from
3114 * #GtkWindow), it will be removed from the list of toplevels, and the
3115 * reference GTK+ holds to it will be removed. Removing a
3116 * widget from its container or the list of toplevels results in the
3117 * widget being finalized, unless you've added additional references
3118 * to the widget with g_object_ref().
3120 * In most cases, only toplevel widgets (windows) require explicit
3121 * destruction, because when you destroy a toplevel its children will
3122 * be destroyed as well.
3125 gtk_widget_destroy (GtkWidget *widget)
3127 g_return_if_fail (GTK_IS_WIDGET (widget));
3129 gtk_object_destroy ((GtkObject*) widget);
3133 * gtk_widget_destroyed:
3134 * @widget: a #GtkWidget
3135 * @widget_pointer: address of a variable that contains @widget
3137 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3138 * %NULL. It's intended to be used as a callback connected to the
3139 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3140 * as a signal handler, and pass the address of your widget variable
3141 * as user data. Then when the widget is destroyed, the variable will
3142 * be set to %NULL. Useful for example to avoid multiple copies
3143 * of the same dialog.
3146 gtk_widget_destroyed (GtkWidget *widget,
3147 GtkWidget **widget_pointer)
3149 /* Don't make any assumptions about the
3151 * Even check widget_pointer.
3154 *widget_pointer = NULL;
3159 * @widget: a #GtkWidget
3161 * Flags a widget to be displayed. Any widget that isn't shown will
3162 * not appear on the screen. If you want to show all the widgets in a
3163 * container, it's easier to call gtk_widget_show_all() on the
3164 * container, instead of individually showing the widgets.
3166 * Remember that you have to show the containers containing a widget,
3167 * in addition to the widget itself, before it will appear onscreen.
3169 * When a toplevel container is shown, it is immediately realized and
3170 * mapped; other shown widgets are realized and mapped when their
3171 * toplevel container is realized and mapped.
3174 gtk_widget_show (GtkWidget *widget)
3176 g_return_if_fail (GTK_IS_WIDGET (widget));
3178 if (!GTK_WIDGET_VISIBLE (widget))
3180 g_object_ref (widget);
3181 if (!GTK_WIDGET_TOPLEVEL (widget))
3182 gtk_widget_queue_resize (widget);
3183 g_signal_emit (widget, widget_signals[SHOW], 0);
3184 g_object_notify (G_OBJECT (widget), "visible");
3185 g_object_unref (widget);
3190 gtk_widget_real_show (GtkWidget *widget)
3192 if (!GTK_WIDGET_VISIBLE (widget))
3194 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3196 if (widget->parent &&
3197 GTK_WIDGET_MAPPED (widget->parent) &&
3198 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3199 !GTK_WIDGET_MAPPED (widget))
3200 gtk_widget_map (widget);
3205 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3208 g_signal_handlers_disconnect_by_func (widget,
3209 gtk_widget_show_map_callback,
3214 * gtk_widget_show_now:
3215 * @widget: a #GtkWidget
3217 * Shows a widget. If the widget is an unmapped toplevel widget
3218 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3219 * loop and wait for the window to actually be mapped. Be careful;
3220 * because the main loop is running, anything can happen during
3224 gtk_widget_show_now (GtkWidget *widget)
3228 g_return_if_fail (GTK_IS_WIDGET (widget));
3230 /* make sure we will get event */
3231 if (!GTK_WIDGET_MAPPED (widget) &&
3232 GTK_WIDGET_TOPLEVEL (widget))
3234 gtk_widget_show (widget);
3236 g_signal_connect (widget, "map-event",
3237 G_CALLBACK (gtk_widget_show_map_callback),
3241 gtk_main_iteration ();
3244 gtk_widget_show (widget);
3249 * @widget: a #GtkWidget
3251 * Reverses the effects of gtk_widget_show(), causing the widget to be
3252 * hidden (invisible to the user).
3255 gtk_widget_hide (GtkWidget *widget)
3257 g_return_if_fail (GTK_IS_WIDGET (widget));
3259 if (GTK_WIDGET_VISIBLE (widget))
3261 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3263 g_object_ref (widget);
3264 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3265 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3267 g_signal_emit (widget, widget_signals[HIDE], 0);
3268 if (!GTK_WIDGET_TOPLEVEL (widget))
3269 gtk_widget_queue_resize (widget);
3270 g_object_notify (G_OBJECT (widget), "visible");
3271 g_object_unref (widget);
3276 gtk_widget_real_hide (GtkWidget *widget)
3278 if (GTK_WIDGET_VISIBLE (widget))
3280 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3282 if (GTK_WIDGET_MAPPED (widget))
3283 gtk_widget_unmap (widget);
3288 * gtk_widget_hide_on_delete:
3289 * @widget: a #GtkWidget
3291 * Utility function; intended to be connected to the #GtkWidget::delete-event
3292 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3293 * argument, then returns %TRUE. If connected to ::delete-event, the
3294 * result is that clicking the close button for a window (on the
3295 * window frame, top right corner usually) will hide but not destroy
3296 * the window. By default, GTK+ destroys windows when ::delete-event
3299 * Return value: %TRUE
3302 gtk_widget_hide_on_delete (GtkWidget *widget)
3304 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3306 gtk_widget_hide (widget);
3312 * gtk_widget_show_all:
3313 * @widget: a #GtkWidget
3315 * Recursively shows a widget, and any child widgets (if the widget is
3319 gtk_widget_show_all (GtkWidget *widget)
3321 GtkWidgetClass *class;
3323 g_return_if_fail (GTK_IS_WIDGET (widget));
3325 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3328 class = GTK_WIDGET_GET_CLASS (widget);
3330 if (class->show_all)
3331 class->show_all (widget);
3335 * gtk_widget_hide_all:
3336 * @widget: a #GtkWidget
3338 * Recursively hides a widget and any child widgets.
3341 gtk_widget_hide_all (GtkWidget *widget)
3343 GtkWidgetClass *class;
3345 g_return_if_fail (GTK_IS_WIDGET (widget));
3347 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3350 class = GTK_WIDGET_GET_CLASS (widget);
3352 if (class->hide_all)
3353 class->hide_all (widget);
3358 * @widget: a #GtkWidget
3360 * This function is only for use in widget implementations. Causes
3361 * a widget to be mapped if it isn't already.
3364 gtk_widget_map (GtkWidget *widget)
3366 g_return_if_fail (GTK_IS_WIDGET (widget));
3367 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3368 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3370 if (!GTK_WIDGET_MAPPED (widget))
3372 if (!GTK_WIDGET_REALIZED (widget))
3373 gtk_widget_realize (widget);
3375 g_signal_emit (widget, widget_signals[MAP], 0);
3377 if (GTK_WIDGET_NO_WINDOW (widget))
3378 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3384 * @widget: a #GtkWidget
3386 * This function is only for use in widget implementations. Causes
3387 * a widget to be unmapped if it's currently mapped.
3390 gtk_widget_unmap (GtkWidget *widget)
3392 g_return_if_fail (GTK_IS_WIDGET (widget));
3394 if (GTK_WIDGET_MAPPED (widget))
3396 if (GTK_WIDGET_NO_WINDOW (widget))
3397 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3398 _gtk_tooltip_hide (widget);
3399 g_signal_emit (widget, widget_signals[UNMAP], 0);
3404 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3405 GdkExtensionMode mode,
3408 GList *free_list = NULL;
3411 if (window_list == NULL)
3413 if (!GTK_WIDGET_NO_WINDOW (widget))
3414 window_list = g_list_prepend (NULL, widget->window);
3416 window_list = gdk_window_get_children (widget->window);
3418 free_list = window_list;
3421 for (l = window_list; l != NULL; l = l->next)
3423 GdkWindow *window = l->data;
3426 gdk_window_get_user_data (window, &user_data);
3427 if (user_data == widget)
3431 gdk_input_set_extension_events (window,
3432 gdk_window_get_events (window),
3435 children = gdk_window_get_children (window);
3438 gtk_widget_set_extension_events_internal (widget, mode, children);
3439 g_list_free (children);
3445 g_list_free (free_list);
3449 * gtk_widget_realize:
3450 * @widget: a #GtkWidget
3452 * Creates the GDK (windowing system) resources associated with a
3453 * widget. For example, @widget->window will be created when a widget
3454 * is realized. Normally realization happens implicitly; if you show
3455 * a widget and all its parent containers, then the widget will be
3456 * realized and mapped automatically.
3458 * Realizing a widget requires all
3459 * the widget's parent widgets to be realized; calling
3460 * gtk_widget_realize() realizes the widget's parents in addition to
3461 * @widget itself. If a widget is not yet inside a toplevel window
3462 * when you realize it, bad things will happen.
3464 * This function is primarily used in widget implementations, and
3465 * isn't very useful otherwise. Many times when you think you might
3466 * need it, a better approach is to connect to a signal that will be
3467 * called after the widget is realized automatically, such as
3468 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3469 * GtkWidget::realize signal.
3472 gtk_widget_realize (GtkWidget *widget)
3474 GdkExtensionMode mode;
3475 GtkWidgetShapeInfo *shape_info;
3477 g_return_if_fail (GTK_IS_WIDGET (widget));
3478 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3479 GTK_IS_INVISIBLE (widget));
3481 if (!GTK_WIDGET_REALIZED (widget))
3484 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3485 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3488 if (widget->parent == NULL &&
3489 !GTK_WIDGET_TOPLEVEL (widget))
3490 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3491 "inside a toplevel window is not going to work very well. "
3492 "Widgets must be inside a toplevel container before realizing them.");
3494 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3495 gtk_widget_realize (widget->parent);
3497 gtk_widget_ensure_style (widget);
3499 g_signal_emit (widget, widget_signals[REALIZE], 0);
3501 gtk_widget_real_set_has_tooltip (widget,
3502 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3505 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3507 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3508 gdk_window_shape_combine_mask (widget->window,
3509 shape_info->shape_mask,
3510 shape_info->offset_x,
3511 shape_info->offset_y);
3514 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3516 gdk_window_input_shape_combine_mask (widget->window,
3517 shape_info->shape_mask,
3518 shape_info->offset_x,
3519 shape_info->offset_y);
3521 mode = gtk_widget_get_extension_events (widget);
3522 if (mode != GDK_EXTENSION_EVENTS_NONE)
3523 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3528 * gtk_widget_unrealize:
3529 * @widget: a #GtkWidget
3531 * This function is only useful in widget implementations.
3532 * Causes a widget to be unrealized (frees all GDK resources
3533 * associated with the widget, such as @widget->window).
3536 gtk_widget_unrealize (GtkWidget *widget)
3538 g_return_if_fail (GTK_IS_WIDGET (widget));
3540 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3541 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3543 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3544 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3546 if (GTK_WIDGET_REALIZED (widget))
3548 g_object_ref (widget);
3549 _gtk_tooltip_hide (widget);
3550 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3551 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3552 g_object_unref (widget);
3556 /*****************************************
3558 *****************************************/
3561 * gtk_widget_queue_draw_area:
3562 * @widget: a #GtkWidget
3563 * @x: x coordinate of upper-left corner of rectangle to redraw
3564 * @y: y coordinate of upper-left corner of rectangle to redraw
3565 * @width: width of region to draw
3566 * @height: height of region to draw
3568 * Invalidates the rectangular area of @widget defined by @x, @y,
3569 * @width and @height by calling gdk_window_invalidate_rect() on the
3570 * widget's window and all its child windows. Once the main loop
3571 * becomes idle (after the current batch of events has been processed,
3572 * roughly), the window will receive expose events for the union of
3573 * all regions that have been invalidated.
3575 * Normally you would only use this function in widget
3576 * implementations. You might also use it, or
3577 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3578 * #GtkDrawingArea or some portion thereof.
3580 * Frequently you can just call gdk_window_invalidate_rect() or
3581 * gdk_window_invalidate_region() instead of this function. Those
3582 * functions will invalidate only a single window, instead of the
3583 * widget and all its children.
3585 * The advantage of adding to the invalidated region compared to
3586 * simply drawing immediately is efficiency; using an invalid region
3587 * ensures that you only have to redraw one time.
3590 gtk_widget_queue_draw_area (GtkWidget *widget,
3596 GdkRectangle invalid_rect;
3599 g_return_if_fail (GTK_IS_WIDGET (widget));
3601 if (!GTK_WIDGET_REALIZED (widget))
3604 /* Just return if the widget or one of its ancestors isn't mapped */
3605 for (w = widget; w != NULL; w = w->parent)
3606 if (!GTK_WIDGET_MAPPED (w))
3609 /* Find the correct widget */
3611 if (!GTK_WIDGET_NO_WINDOW (widget))
3615 /* Translate widget relative to window-relative */
3617 gint wx, wy, wwidth, wheight;
3619 gdk_window_get_position (widget->window, &wx, &wy);
3620 x -= wx - widget->allocation.x;
3621 y -= wy - widget->allocation.y;
3623 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3625 if (x + width <= 0 || y + height <= 0 ||
3626 x >= wwidth || y >= wheight)
3637 if (x + width > wwidth)
3639 if (y + height > wheight)
3640 height = wheight - y;
3646 invalid_rect.width = width;
3647 invalid_rect.height = height;
3649 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3653 widget_add_child_draw_rectangle (GtkWidget *widget,
3656 GdkRectangle child_rect;
3658 if (!GTK_WIDGET_MAPPED (widget) ||
3659 widget->window != widget->parent->window)
3662 gtk_widget_get_draw_rectangle (widget, &child_rect);
3663 gdk_rectangle_union (rect, &child_rect, rect);
3667 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3670 if (GTK_WIDGET_NO_WINDOW (widget))
3672 GtkBorder *draw_border = NULL;
3674 *rect = widget->allocation;
3676 gtk_widget_style_get (widget,
3677 "draw-border", &draw_border,
3681 rect->x -= draw_border->left;
3682 rect->y -= draw_border->top;
3683 rect->width += draw_border->left + draw_border->right;
3684 rect->height += draw_border->top + draw_border->bottom;
3686 gtk_border_free (draw_border);
3689 if (GTK_IS_CONTAINER (widget))
3690 gtk_container_forall (GTK_CONTAINER (widget),
3691 (GtkCallback)widget_add_child_draw_rectangle,
3698 rect->width = widget->allocation.width;
3699 rect->height = widget->allocation.height;
3704 * gtk_widget_queue_draw:
3705 * @widget: a #GtkWidget
3707 * Equivalent to calling gtk_widget_queue_draw_area() for the
3708 * entire area of a widget.
3711 gtk_widget_queue_draw (GtkWidget *widget)
3715 g_return_if_fail (GTK_IS_WIDGET (widget));
3717 gtk_widget_get_draw_rectangle (widget, &rect);
3719 gtk_widget_queue_draw_area (widget,
3721 rect.width, rect.height);
3724 /* Invalidates the given area (allocation-relative-coordinates)
3725 * in all of the widget's windows
3728 * gtk_widget_queue_clear_area:
3729 * @widget: a #GtkWidget
3730 * @x: x coordinate of upper-left corner of rectangle to redraw
3731 * @y: y coordinate of upper-left corner of rectangle to redraw
3732 * @width: width of region to draw
3733 * @height: height of region to draw
3735 * This function is no longer different from
3736 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3737 * gtk_widget_queue_draw_area(). Originally
3738 * gtk_widget_queue_clear_area() would force a redraw of the
3739 * background for %GTK_NO_WINDOW widgets, and
3740 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3741 * the background will be redrawn.
3743 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3746 gtk_widget_queue_clear_area (GtkWidget *widget,
3752 g_return_if_fail (GTK_IS_WIDGET (widget));
3754 gtk_widget_queue_draw_area (widget, x, y, width, height);
3758 * gtk_widget_queue_clear:
3759 * @widget: a #GtkWidget
3761 * This function does the same as gtk_widget_queue_draw().
3763 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3766 gtk_widget_queue_clear (GtkWidget *widget)
3768 g_return_if_fail (GTK_IS_WIDGET (widget));
3770 gtk_widget_queue_draw (widget);
3774 * gtk_widget_queue_resize:
3775 * @widget: a #GtkWidget
3777 * This function is only for use in widget implementations.
3778 * Flags a widget to have its size renegotiated; should
3779 * be called when a widget for some reason has a new size request.
3780 * For example, when you change the text in a #GtkLabel, #GtkLabel
3781 * queues a resize to ensure there's enough space for the new text.
3784 gtk_widget_queue_resize (GtkWidget *widget)
3786 g_return_if_fail (GTK_IS_WIDGET (widget));
3788 if (GTK_WIDGET_REALIZED (widget))
3789 gtk_widget_queue_shallow_draw (widget);
3791 _gtk_size_group_queue_resize (widget);
3795 * gtk_widget_queue_resize_no_redraw:
3796 * @widget: a #GtkWidget
3798 * This function works like gtk_widget_queue_resize(),
3799 * except that the widget is not invalidated.
3804 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3806 g_return_if_fail (GTK_IS_WIDGET (widget));
3808 _gtk_size_group_queue_resize (widget);
3813 * @widget: a #GtkWidget
3814 * @area: area to draw
3816 * In GTK+ 1.2, this function would immediately render the
3817 * region @area of a widget, by invoking the virtual draw method of a
3818 * widget. In GTK+ 2.0, the draw method is gone, and instead
3819 * gtk_widget_draw() simply invalidates the specified region of the
3820 * widget, then updates the invalid region of the widget immediately.
3821 * Usually you don't want to update the region immediately for
3822 * performance reasons, so in general gtk_widget_queue_draw_area() is
3823 * a better choice if you want to draw a region of a widget.
3826 gtk_widget_draw (GtkWidget *widget,
3827 const GdkRectangle *area)
3829 g_return_if_fail (GTK_IS_WIDGET (widget));
3831 if (GTK_WIDGET_DRAWABLE (widget))
3834 gtk_widget_queue_draw_area (widget,
3836 area->width, area->height);
3838 gtk_widget_queue_draw (widget);
3840 gdk_window_process_updates (widget->window, TRUE);
3845 * gtk_widget_size_request:
3846 * @widget: a #GtkWidget
3847 * @requisition: a #GtkRequisition to be filled in
3849 * This function is typically used when implementing a #GtkContainer
3850 * subclass. Obtains the preferred size of a widget. The container
3851 * uses this information to arrange its child widgets and decide what
3852 * size allocations to give them with gtk_widget_size_allocate().
3854 * You can also call this function from an application, with some
3855 * caveats. Most notably, getting a size request requires the widget
3856 * to be associated with a screen, because font information may be
3857 * needed. Multihead-aware applications should keep this in mind.
3859 * Also remember that the size request is not necessarily the size
3860 * a widget will actually be allocated.
3862 * See also gtk_widget_get_child_requisition().
3865 gtk_widget_size_request (GtkWidget *widget,
3866 GtkRequisition *requisition)
3868 g_return_if_fail (GTK_IS_WIDGET (widget));
3870 #ifdef G_ENABLE_DEBUG
3871 if (requisition == &widget->requisition)
3872 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.");
3873 #endif /* G_ENABLE_DEBUG */
3875 _gtk_size_group_compute_requisition (widget, requisition);
3879 * gtk_widget_get_child_requisition:
3880 * @widget: a #GtkWidget
3881 * @requisition: a #GtkRequisition to be filled in
3883 * This function is only for use in widget implementations. Obtains
3884 * @widget->requisition, unless someone has forced a particular
3885 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3886 * in which case it returns that geometry instead of the widget's
3889 * This function differs from gtk_widget_size_request() in that
3890 * it retrieves the last size request value from @widget->requisition,
3891 * while gtk_widget_size_request() actually calls the "size_request" method
3892 * on @widget to compute the size request and fill in @widget->requisition,
3893 * and only then returns @widget->requisition.
3895 * Because this function does not call the "size_request" method, it
3896 * can only be used when you know that @widget->requisition is
3897 * up-to-date, that is, gtk_widget_size_request() has been called
3898 * since the last time a resize was queued. In general, only container
3899 * implementations have this information; applications should use
3900 * gtk_widget_size_request().
3903 gtk_widget_get_child_requisition (GtkWidget *widget,
3904 GtkRequisition *requisition)
3906 _gtk_size_group_get_child_requisition (widget, requisition);
3910 invalidate_predicate (GdkWindow *window,
3915 gdk_window_get_user_data (window, &user_data);
3917 return (user_data == data);
3920 /* Invalidate @region in widget->window and all children
3921 * of widget->window owned by widget. @region is in the
3922 * same coordinates as widget->allocation and will be
3923 * modified by this call.
3926 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3929 if (!GTK_WIDGET_REALIZED (widget))
3932 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3936 gdk_window_get_position (widget->window, &x, &y);
3937 gdk_region_offset (region, -x, -y);
3940 gdk_window_invalidate_maybe_recurse (widget->window, region,
3941 invalidate_predicate, widget);
3945 * gtk_widget_queue_shallow_draw:
3946 * @widget: a #GtkWidget
3948 * Like gtk_widget_queue_draw(), but only windows owned
3949 * by @widget are invalidated.
3952 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3957 if (!GTK_WIDGET_REALIZED (widget))
3960 gtk_widget_get_draw_rectangle (widget, &rect);
3962 /* get_draw_rectangle() gives us window coordinates, we
3963 * need to convert to the coordinates that widget->allocation
3966 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3970 gdk_window_get_position (widget->window, &wx, &wy);
3976 region = gdk_region_rectangle (&rect);
3977 gtk_widget_invalidate_widget_windows (widget, region);
3978 gdk_region_destroy (region);
3982 * gtk_widget_size_allocate:
3983 * @widget: a #GtkWidget
3984 * @allocation: position and size to be allocated to @widget
3986 * This function is only used by #GtkContainer subclasses, to assign a size
3987 * and position to their child widgets.
3990 gtk_widget_size_allocate (GtkWidget *widget,
3991 GtkAllocation *allocation)
3993 GtkWidgetAuxInfo *aux_info;
3994 GdkRectangle real_allocation;
3995 GdkRectangle old_allocation;
3996 gboolean alloc_needed;
3997 gboolean size_changed;
3998 gboolean position_changed;
4000 g_return_if_fail (GTK_IS_WIDGET (widget));
4002 #ifdef G_ENABLE_DEBUG
4003 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4014 parent = gtk_widget_get_parent (parent);
4017 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4018 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4019 2 * depth, " ", name,
4020 allocation->width, allocation->height);
4022 #endif /* G_ENABLE_DEBUG */
4024 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4025 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4026 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4028 old_allocation = widget->allocation;
4029 real_allocation = *allocation;
4030 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4034 if (aux_info->x_set)
4035 real_allocation.x = aux_info->x;
4036 if (aux_info->y_set)
4037 real_allocation.y = aux_info->y;
4040 if (real_allocation.width < 0 || real_allocation.height < 0)
4042 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4043 real_allocation.width,
4044 real_allocation.height);
4047 real_allocation.width = MAX (real_allocation.width, 1);
4048 real_allocation.height = MAX (real_allocation.height, 1);
4050 size_changed = (old_allocation.width != real_allocation.width ||
4051 old_allocation.height != real_allocation.height);
4052 position_changed = (old_allocation.x != real_allocation.x ||
4053 old_allocation.y != real_allocation.y);
4055 if (!alloc_needed && !size_changed && !position_changed)
4058 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4060 if (GTK_WIDGET_MAPPED (widget))
4062 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4064 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4066 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4067 gdk_region_union_with_rect (invalidate, &old_allocation);
4069 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4070 gdk_region_destroy (invalidate);
4075 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4077 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4079 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4080 gdk_region_union_with_rect (invalidate, &old_allocation);
4082 gtk_widget_invalidate_widget_windows (widget, invalidate);
4083 gdk_region_destroy (invalidate);
4088 if ((size_changed || position_changed) && widget->parent &&
4089 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4091 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4092 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4093 gdk_region_destroy (invalidate);
4098 * gtk_widget_common_ancestor:
4099 * @widget_a: a #GtkWidget
4100 * @widget_b: a #GtkWidget
4102 * Find the common ancestor of @widget_a and @widget_b that
4103 * is closest to the two widgets.
4105 * Return value: the closest common ancestor of @widget_a and
4106 * @widget_b or %NULL if @widget_a and @widget_b do not
4107 * share a common ancestor.
4110 gtk_widget_common_ancestor (GtkWidget *widget_a,
4111 GtkWidget *widget_b)
4113 GtkWidget *parent_a;
4114 GtkWidget *parent_b;
4118 parent_a = widget_a;
4119 while (parent_a->parent)
4121 parent_a = parent_a->parent;
4125 parent_b = widget_b;
4126 while (parent_b->parent)
4128 parent_b = parent_b->parent;
4132 if (parent_a != parent_b)
4135 while (depth_a > depth_b)
4137 widget_a = widget_a->parent;
4141 while (depth_b > depth_a)
4143 widget_b = widget_b->parent;
4147 while (widget_a != widget_b)
4149 widget_a = widget_a->parent;
4150 widget_b = widget_b->parent;
4157 * gtk_widget_translate_coordinates:
4158 * @src_widget: a #GtkWidget
4159 * @dest_widget: a #GtkWidget
4160 * @src_x: X position relative to @src_widget
4161 * @src_y: Y position relative to @src_widget
4162 * @dest_x: location to store X position relative to @dest_widget
4163 * @dest_y: location to store Y position relative to @dest_widget
4165 * Translate coordinates relative to @src_widget's allocation to coordinates
4166 * relative to @dest_widget's allocations. In order to perform this
4167 * operation, both widgets must be realized, and must share a common
4170 * Return value: %FALSE if either widget was not realized, or there
4171 * was no common ancestor. In this case, nothing is stored in
4172 * *@dest_x and *@dest_y. Otherwise %TRUE.
4175 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4176 GtkWidget *dest_widget,
4182 GtkWidget *ancestor;
4185 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4186 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4188 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4189 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4192 /* Translate from allocation relative to window relative */
4193 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4196 gdk_window_get_position (src_widget->window, &wx, &wy);
4198 src_x -= wx - src_widget->allocation.x;
4199 src_y -= wy - src_widget->allocation.y;
4203 src_x += src_widget->allocation.x;
4204 src_y += src_widget->allocation.y;
4207 /* Translate to the common ancestor */
4208 window = src_widget->window;
4209 while (window != ancestor->window)
4213 gdk_window_get_position (window, &dx, &dy);
4218 window = gdk_window_get_parent (window);
4220 if (!window) /* Handle GtkHandleBox */
4225 window = dest_widget->window;
4226 while (window != ancestor->window)
4230 gdk_window_get_position (window, &dx, &dy);
4235 window = gdk_window_get_parent (window);
4237 if (!window) /* Handle GtkHandleBox */
4241 /* Translate from window relative to allocation relative */
4242 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4245 gdk_window_get_position (dest_widget->window, &wx, &wy);
4247 src_x += wx - dest_widget->allocation.x;
4248 src_y += wy - dest_widget->allocation.y;
4252 src_x -= dest_widget->allocation.x;
4253 src_y -= dest_widget->allocation.y;
4265 gtk_widget_real_size_allocate (GtkWidget *widget,
4266 GtkAllocation *allocation)
4268 widget->allocation = *allocation;
4270 if (GTK_WIDGET_REALIZED (widget) &&
4271 !GTK_WIDGET_NO_WINDOW (widget))
4273 gdk_window_move_resize (widget->window,
4274 allocation->x, allocation->y,
4275 allocation->width, allocation->height);
4280 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4283 /* widgets must be onscreen for accels to take effect */
4284 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4288 * gtk_widget_can_activate_accel:
4289 * @widget: a #GtkWidget
4290 * @signal_id: the ID of a signal installed on @widget
4292 * Determines whether an accelerator that activates the signal
4293 * identified by @signal_id can currently be activated.
4294 * This is done by emitting the #GtkWidget::can-activate-accel
4295 * signal on @widget; if the signal isn't overridden by a
4296 * handler or in a derived widget, then the default check is
4297 * that the widget must be sensitive, and the widget and all
4298 * its ancestors mapped.
4300 * Return value: %TRUE if the accelerator can be activated.
4305 gtk_widget_can_activate_accel (GtkWidget *widget,
4308 gboolean can_activate = FALSE;
4309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4310 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4311 return can_activate;
4320 closure_accel_activate (GClosure *closure,
4321 GValue *return_value,
4322 guint n_param_values,
4323 const GValue *param_values,
4324 gpointer invocation_hint,
4325 gpointer marshal_data)
4327 AccelClosure *aclosure = (AccelClosure*) closure;
4328 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4331 g_signal_emit (closure->data, aclosure->signal_id, 0);
4333 /* whether accelerator was handled */
4334 g_value_set_boolean (return_value, can_activate);
4338 closures_destroy (gpointer data)
4340 GSList *slist, *closures = data;
4342 for (slist = closures; slist; slist = slist->next)
4344 g_closure_invalidate (slist->data);
4345 g_closure_unref (slist->data);
4347 g_slist_free (closures);
4351 widget_new_accel_closure (GtkWidget *widget,
4354 AccelClosure *aclosure;
4355 GClosure *closure = NULL;
4356 GSList *slist, *closures;
4358 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4359 for (slist = closures; slist; slist = slist->next)
4360 if (!gtk_accel_group_from_accel_closure (slist->data))
4362 /* reuse this closure */
4363 closure = slist->data;
4368 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4369 closures = g_slist_prepend (closures, g_closure_ref (closure));
4370 g_closure_sink (closure);
4371 g_closure_set_marshal (closure, closure_accel_activate);
4373 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4375 aclosure = (AccelClosure*) closure;
4376 g_assert (closure->data == widget);
4377 g_assert (closure->marshal == closure_accel_activate);
4378 aclosure->signal_id = signal_id;
4384 * gtk_widget_add_accelerator
4385 * @widget: widget to install an accelerator on
4386 * @accel_signal: widget signal to emit on accelerator activation
4387 * @accel_group: accel group for this widget, added to its toplevel
4388 * @accel_key: GDK keyval of the accelerator
4389 * @accel_mods: modifier key combination of the accelerator
4390 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4392 * Installs an accelerator for this @widget in @accel_group that causes
4393 * @accel_signal to be emitted if the accelerator is activated.
4394 * The @accel_group needs to be added to the widget's toplevel via
4395 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4396 * Accelerators added through this function are not user changeable during
4397 * runtime. If you want to support accelerators that can be changed by the
4398 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4399 * gtk_menu_item_set_accel_path() instead.
4402 gtk_widget_add_accelerator (GtkWidget *widget,
4403 const gchar *accel_signal,
4404 GtkAccelGroup *accel_group,
4406 GdkModifierType accel_mods,
4407 GtkAccelFlags accel_flags)
4412 g_return_if_fail (GTK_IS_WIDGET (widget));
4413 g_return_if_fail (accel_signal != NULL);
4414 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4416 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4417 if (!query.signal_id ||
4418 !(query.signal_flags & G_SIGNAL_ACTION) ||
4419 query.return_type != G_TYPE_NONE ||
4422 /* hmm, should be elaborate enough */
4423 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4424 G_OBJECT_TYPE_NAME (widget), accel_signal);
4428 closure = widget_new_accel_closure (widget, query.signal_id);
4430 g_object_ref (widget);
4432 /* install the accelerator. since we don't map this onto an accel_path,
4433 * the accelerator will automatically be locked.
4435 gtk_accel_group_connect (accel_group,
4438 accel_flags | GTK_ACCEL_LOCKED,
4441 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4443 g_object_unref (widget);
4447 * gtk_widget_remove_accelerator:
4448 * @widget: widget to install an accelerator on
4449 * @accel_group: accel group for this widget
4450 * @accel_key: GDK keyval of the accelerator
4451 * @accel_mods: modifier key combination of the accelerator
4452 * @returns: whether an accelerator was installed and could be removed
4454 * Removes an accelerator from @widget, previously installed with
4455 * gtk_widget_add_accelerator().
4458 gtk_widget_remove_accelerator (GtkWidget *widget,
4459 GtkAccelGroup *accel_group,
4461 GdkModifierType accel_mods)
4463 GtkAccelGroupEntry *ag_entry;
4464 GList *slist, *clist;
4467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4468 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4470 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4471 clist = gtk_widget_list_accel_closures (widget);
4472 for (slist = clist; slist; slist = slist->next)
4476 for (i = 0; i < n; i++)
4477 if (slist->data == (gpointer) ag_entry[i].closure)
4479 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4481 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4483 g_list_free (clist);
4488 g_list_free (clist);
4490 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4491 accel_key, accel_mods, accel_group,
4492 G_OBJECT_TYPE_NAME (widget), widget);
4498 * gtk_widget_list_accel_closures
4499 * @widget: widget to list accelerator closures for
4500 * @returns: a newly allocated #GList of closures
4502 * Lists the closures used by @widget for accelerator group connections
4503 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4504 * The closures can be used to monitor accelerator changes on @widget,
4505 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4506 * #GtkAccelGroup of a closure which can be found out with
4507 * gtk_accel_group_from_accel_closure().
4510 gtk_widget_list_accel_closures (GtkWidget *widget)
4513 GList *clist = NULL;
4515 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4517 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4518 if (gtk_accel_group_from_accel_closure (slist->data))
4519 clist = g_list_prepend (clist, slist->data);
4525 GtkAccelGroup *accel_group;
4530 destroy_accel_path (gpointer data)
4532 AccelPath *apath = data;
4534 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4536 /* closures_destroy takes care of unrefing the closure */
4537 g_object_unref (apath->accel_group);
4539 g_slice_free (AccelPath, apath);
4544 * gtk_widget_set_accel_path:
4545 * @widget: a #GtkWidget
4546 * @accel_path: path used to look up the accelerator
4547 * @accel_group: a #GtkAccelGroup.
4549 * Given an accelerator group, @accel_group, and an accelerator path,
4550 * @accel_path, sets up an accelerator in @accel_group so whenever the
4551 * key binding that is defined for @accel_path is pressed, @widget
4552 * will be activated. This removes any accelerators (for any
4553 * accelerator group) installed by previous calls to
4554 * gtk_widget_set_accel_path(). Associating accelerators with
4555 * paths allows them to be modified by the user and the modifications
4556 * to be saved for future use. (See gtk_accel_map_save().)
4558 * This function is a low level function that would most likely
4559 * be used by a menu creation system like #GtkUIManager. If you
4560 * use #GtkUIManager, setting up accelerator paths will be done
4563 * Even when you you aren't using #GtkUIManager, if you only want to
4564 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4565 * provides a somewhat more convenient interface.
4567 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4568 * pass a static string, you can save some memory by interning it first with
4569 * g_intern_static_string().
4572 gtk_widget_set_accel_path (GtkWidget *widget,
4573 const gchar *accel_path,
4574 GtkAccelGroup *accel_group)
4578 g_return_if_fail (GTK_IS_WIDGET (widget));
4579 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4583 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4584 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4586 gtk_accel_map_add_entry (accel_path, 0, 0);
4587 apath = g_slice_new (AccelPath);
4588 apath->accel_group = g_object_ref (accel_group);
4589 apath->path_quark = g_quark_from_string (accel_path);
4590 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4595 /* also removes possible old settings */
4596 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4599 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4601 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4605 _gtk_widget_get_accel_path (GtkWidget *widget,
4610 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4612 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4614 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4615 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4619 * gtk_widget_mnemonic_activate:
4620 * @widget: a #GtkWidget
4621 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4623 * Emits the #GtkWidget::mnemonic-activate signal.
4625 * The default handler for this signal activates the @widget if
4626 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4629 * Returns: %TRUE if the signal has been handled
4632 gtk_widget_mnemonic_activate (GtkWidget *widget,
4633 gboolean group_cycling)
4637 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4639 group_cycling = group_cycling != FALSE;
4640 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4643 g_signal_emit (widget,
4644 widget_signals[MNEMONIC_ACTIVATE],
4652 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4653 gboolean group_cycling)
4655 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4656 gtk_widget_activate (widget);
4657 else if (GTK_WIDGET_CAN_FOCUS (widget))
4658 gtk_widget_grab_focus (widget);
4661 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4662 G_OBJECT_TYPE_NAME (widget));
4663 gtk_widget_error_bell (widget);
4669 gtk_widget_real_key_press_event (GtkWidget *widget,
4672 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4676 gtk_widget_real_key_release_event (GtkWidget *widget,
4679 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4683 gtk_widget_real_focus_in_event (GtkWidget *widget,
4684 GdkEventFocus *event)
4686 gtk_widget_queue_shallow_draw (widget);
4692 gtk_widget_real_focus_out_event (GtkWidget *widget,
4693 GdkEventFocus *event)
4695 gtk_widget_queue_shallow_draw (widget);
4700 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4701 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4705 * @widget: a #GtkWidget
4706 * @event: a #GdkEvent
4708 * Rarely-used function. This function is used to emit
4709 * the event signals on a widget (those signals should never
4710 * be emitted without using this function to do so).
4711 * If you want to synthesize an event though, don't use this function;
4712 * instead, use gtk_main_do_event() so the event will behave as if
4713 * it were in the event queue. Don't synthesize expose events; instead,
4714 * use gdk_window_invalidate_rect() to invalidate a region of the
4717 * Return value: return from the event signal emission (%TRUE if
4718 * the event was handled)
4721 gtk_widget_event (GtkWidget *widget,
4724 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4725 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4727 if (event->type == GDK_EXPOSE)
4729 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4730 "the same effect, call gdk_window_invalidate_rect/region(), "
4731 "followed by gdk_window_process_updates().");
4735 return gtk_widget_event_internal (widget, event);
4740 * gtk_widget_send_expose:
4741 * @widget: a #GtkWidget
4742 * @event: a expose #GdkEvent
4744 * Very rarely-used function. This function is used to emit
4745 * an expose event signals on a widget. This function is not
4746 * normally used directly. The only time it is used is when
4747 * propagating an expose event to a child %NO_WINDOW widget, and
4748 * that is normally done using gtk_container_propagate_expose().
4750 * If you want to force an area of a window to be redrawn,
4751 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4752 * To cause the redraw to be done immediately, follow that call
4753 * with a call to gdk_window_process_updates().
4755 * Return value: return from the event signal emission (%TRUE if
4756 * the event was handled)
4759 gtk_widget_send_expose (GtkWidget *widget,
4762 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4763 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4764 g_return_val_if_fail (event != NULL, TRUE);
4765 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4767 return gtk_widget_event_internal (widget, event);
4771 event_window_is_still_viewable (GdkEvent *event)
4773 /* Some programs, such as gnome-theme-manager, fake widgets
4774 * into exposing onto a pixmap by sending expose events with
4775 * event->window pointing to a pixmap
4777 if (GDK_IS_PIXMAP (event->any.window))
4778 return event->type == GDK_EXPOSE;
4780 /* Check that we think the event's window is viewable before
4781 * delivering the event, to prevent suprises. We do this here
4782 * at the last moment, since the event may have been queued
4783 * up behind other events, held over a recursive main loop, etc.
4785 switch (event->type)
4788 case GDK_MOTION_NOTIFY:
4789 case GDK_BUTTON_PRESS:
4790 case GDK_2BUTTON_PRESS:
4791 case GDK_3BUTTON_PRESS:
4793 case GDK_ENTER_NOTIFY:
4794 case GDK_PROXIMITY_IN:
4796 return event->any.window && gdk_window_is_viewable (event->any.window);
4799 /* The following events are the second half of paired events;
4800 * we always deliver them to deal with widgets that clean up
4801 * on the second half.
4803 case GDK_BUTTON_RELEASE:
4804 case GDK_KEY_RELEASE:
4805 case GDK_LEAVE_NOTIFY:
4806 case GDK_PROXIMITY_OUT:
4810 /* Remaining events would make sense on an not-viewable window,
4811 * or don't have an associated window.
4818 gtk_widget_event_internal (GtkWidget *widget,
4821 gboolean return_val = FALSE;
4823 /* We check only once for is-still-visible; if someone
4824 * hides the window in on of the signals on the widget,
4825 * they are responsible for returning TRUE to terminate
4828 if (!event_window_is_still_viewable (event))
4831 g_object_ref (widget);
4833 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4834 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4839 switch (event->type)
4844 case GDK_BUTTON_PRESS:
4845 case GDK_2BUTTON_PRESS:
4846 case GDK_3BUTTON_PRESS:
4847 signal_num = BUTTON_PRESS_EVENT;
4850 signal_num = SCROLL_EVENT;
4852 case GDK_BUTTON_RELEASE:
4853 signal_num = BUTTON_RELEASE_EVENT;
4855 case GDK_MOTION_NOTIFY:
4856 signal_num = MOTION_NOTIFY_EVENT;
4859 signal_num = DELETE_EVENT;
4862 signal_num = DESTROY_EVENT;
4863 _gtk_tooltip_hide (widget);
4866 signal_num = KEY_PRESS_EVENT;
4868 case GDK_KEY_RELEASE:
4869 signal_num = KEY_RELEASE_EVENT;
4871 case GDK_ENTER_NOTIFY:
4872 signal_num = ENTER_NOTIFY_EVENT;
4874 case GDK_LEAVE_NOTIFY:
4875 signal_num = LEAVE_NOTIFY_EVENT;
4877 case GDK_FOCUS_CHANGE:
4878 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4879 if (event->focus_change.in)
4880 _gtk_tooltip_focus_in (widget);
4882 _gtk_tooltip_focus_out (widget);
4885 signal_num = CONFIGURE_EVENT;
4888 signal_num = MAP_EVENT;
4891 signal_num = UNMAP_EVENT;
4893 case GDK_WINDOW_STATE:
4894 signal_num = WINDOW_STATE_EVENT;
4896 case GDK_PROPERTY_NOTIFY:
4897 signal_num = PROPERTY_NOTIFY_EVENT;
4899 case GDK_SELECTION_CLEAR:
4900 signal_num = SELECTION_CLEAR_EVENT;
4902 case GDK_SELECTION_REQUEST:
4903 signal_num = SELECTION_REQUEST_EVENT;
4905 case GDK_SELECTION_NOTIFY:
4906 signal_num = SELECTION_NOTIFY_EVENT;
4908 case GDK_PROXIMITY_IN:
4909 signal_num = PROXIMITY_IN_EVENT;
4911 case GDK_PROXIMITY_OUT:
4912 signal_num = PROXIMITY_OUT_EVENT;
4915 signal_num = NO_EXPOSE_EVENT;
4917 case GDK_CLIENT_EVENT:
4918 signal_num = CLIENT_EVENT;
4921 signal_num = EXPOSE_EVENT;
4923 case GDK_VISIBILITY_NOTIFY:
4924 signal_num = VISIBILITY_NOTIFY_EVENT;
4926 case GDK_GRAB_BROKEN:
4927 signal_num = GRAB_BROKEN;
4930 signal_num = DAMAGE_EVENT;
4933 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4937 if (signal_num != -1)
4938 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4940 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4941 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4945 g_object_unref (widget);
4951 * gtk_widget_activate:
4952 * @widget: a #GtkWidget that's activatable
4954 * For widgets that can be "activated" (buttons, menu items, etc.)
4955 * this function activates them. Activation is what happens when you
4956 * press Enter on a widget during key navigation. If @widget isn't
4957 * activatable, the function returns %FALSE.
4959 * Return value: %TRUE if the widget was activatable
4962 gtk_widget_activate (GtkWidget *widget)
4964 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4966 if (WIDGET_CLASS (widget)->activate_signal)
4968 /* FIXME: we should eventually check the signals signature here */
4969 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4978 * gtk_widget_set_scroll_adjustments:
4979 * @widget: a #GtkWidget
4980 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4981 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4983 * For widgets that support scrolling, sets the scroll adjustments and
4984 * returns %TRUE. For widgets that don't support scrolling, does
4985 * nothing and returns %FALSE. Widgets that don't support scrolling
4986 * can be scrolled by placing them in a #GtkViewport, which does
4987 * support scrolling.
4989 * Return value: %TRUE if the widget supports scrolling
4992 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4993 GtkAdjustment *hadjustment,
4994 GtkAdjustment *vadjustment)
4999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5002 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5004 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5006 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5010 g_signal_query (signal_id, &query);
5011 if (!query.signal_id ||
5012 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5013 query.return_type != G_TYPE_NONE ||
5014 query.n_params != 2 ||
5015 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5016 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5018 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5019 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5023 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5028 gtk_widget_reparent_subwindows (GtkWidget *widget,
5029 GdkWindow *new_window)
5031 if (GTK_WIDGET_NO_WINDOW (widget))
5033 GList *children = gdk_window_get_children (widget->window);
5036 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5038 GdkWindow *window = tmp_list->data;
5041 gdk_window_get_user_data (window, &child);
5042 while (child && child != widget)
5043 child = ((GtkWidget*) child)->parent;
5046 gdk_window_reparent (window, new_window, 0, 0);
5049 g_list_free (children);
5054 GList *tmp_list, *children;
5056 parent = gdk_window_get_parent (widget->window);
5059 gdk_window_reparent (widget->window, new_window, 0, 0);
5062 children = gdk_window_get_children (parent);
5064 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5066 GdkWindow *window = tmp_list->data;
5069 gdk_window_get_user_data (window, &child);
5071 if (child == widget)
5072 gdk_window_reparent (window, new_window, 0, 0);
5075 g_list_free (children);
5081 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5082 gpointer client_data)
5084 g_assert (client_data != NULL);
5086 if (GTK_WIDGET_NO_WINDOW (widget))
5089 g_object_unref (widget->window);
5090 widget->window = (GdkWindow*) client_data;
5092 g_object_ref (widget->window);
5094 if (GTK_IS_CONTAINER (widget))
5095 gtk_container_forall (GTK_CONTAINER (widget),
5096 gtk_widget_reparent_fixup_child,
5102 * gtk_widget_reparent:
5103 * @widget: a #GtkWidget
5104 * @new_parent: a #GtkContainer to move the widget into
5106 * Moves a widget from one #GtkContainer to another, handling reference
5107 * count issues to avoid destroying the widget.
5110 gtk_widget_reparent (GtkWidget *widget,
5111 GtkWidget *new_parent)
5113 g_return_if_fail (GTK_IS_WIDGET (widget));
5114 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5115 g_return_if_fail (widget->parent != NULL);
5117 if (widget->parent != new_parent)
5119 /* First try to see if we can get away without unrealizing
5120 * the widget as we reparent it. if so we set a flag so
5121 * that gtk_widget_unparent doesn't unrealize widget
5123 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
5124 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5126 g_object_ref (widget);
5127 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5128 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5129 g_object_unref (widget);
5131 if (GTK_WIDGET_IN_REPARENT (widget))
5133 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5135 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5136 gtk_widget_reparent_fixup_child (widget,
5137 gtk_widget_get_parent_window (widget));
5140 g_object_notify (G_OBJECT (widget), "parent");
5145 * gtk_widget_intersect:
5146 * @widget: a #GtkWidget
5147 * @area: a rectangle
5148 * @intersection: rectangle to store intersection of @widget and @area
5150 * Computes the intersection of a @widget's area and @area, storing
5151 * the intersection in @intersection, and returns %TRUE if there was
5152 * an intersection. @intersection may be %NULL if you're only
5153 * interested in whether there was an intersection.
5155 * Return value: %TRUE if there was an intersection
5158 gtk_widget_intersect (GtkWidget *widget,
5159 const GdkRectangle *area,
5160 GdkRectangle *intersection)
5166 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5167 g_return_val_if_fail (area != NULL, FALSE);
5170 dest = intersection;
5174 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5176 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
5178 intersection->x -= widget->allocation.x;
5179 intersection->y -= widget->allocation.y;
5186 * gtk_widget_region_intersect:
5187 * @widget: a #GtkWidget
5188 * @region: a #GdkRegion, in the same coordinate system as
5189 * @widget->allocation. That is, relative to @widget->window
5190 * for %NO_WINDOW widgets; relative to the parent window
5191 * of @widget->window for widgets with their own window.
5192 * @returns: A newly allocated region holding the intersection of @widget
5193 * and @region. The coordinates of the return value are
5194 * relative to @widget->window for %NO_WINDOW widgets, and
5195 * relative to the parent window of @widget->window for
5196 * widgets with their own window.
5198 * Computes the intersection of a @widget's area and @region, returning
5199 * the intersection. The result may be empty, use gdk_region_empty() to
5203 gtk_widget_region_intersect (GtkWidget *widget,
5204 const GdkRegion *region)
5209 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5210 g_return_val_if_fail (region != NULL, NULL);
5212 gtk_widget_get_draw_rectangle (widget, &rect);
5214 dest = gdk_region_rectangle (&rect);
5216 gdk_region_intersect (dest, region);
5222 * _gtk_widget_grab_notify:
5223 * @widget: a #GtkWidget
5224 * @was_grabbed: whether a grab is now in effect
5226 * Emits the #GtkWidget::grab-notify signal on @widget.
5231 _gtk_widget_grab_notify (GtkWidget *widget,
5232 gboolean was_grabbed)
5234 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5238 * gtk_widget_grab_focus:
5239 * @widget: a #GtkWidget
5241 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5242 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5243 * something like #GtkFrame won't work.
5245 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5246 * gtk_widget_set_can_focus() to modify that flag.
5249 gtk_widget_grab_focus (GtkWidget *widget)
5251 g_return_if_fail (GTK_IS_WIDGET (widget));
5253 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5256 g_object_ref (widget);
5257 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5258 g_object_notify (G_OBJECT (widget), "has-focus");
5259 g_object_unref (widget);
5263 reset_focus_recurse (GtkWidget *widget,
5266 if (GTK_IS_CONTAINER (widget))
5268 GtkContainer *container;
5270 container = GTK_CONTAINER (widget);
5271 gtk_container_set_focus_child (container, NULL);
5273 gtk_container_foreach (container,
5274 reset_focus_recurse,
5280 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5282 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5284 GtkWidget *toplevel;
5287 /* clear the current focus setting, break if the current widget
5288 * is the focus widget's parent, since containers above that will
5289 * be set by the next loop.
5291 toplevel = gtk_widget_get_toplevel (focus_widget);
5292 if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
5294 widget = GTK_WINDOW (toplevel)->focus_widget;
5296 if (widget == focus_widget)
5298 /* We call _gtk_window_internal_set_focus() here so that the
5299 * toplevel window can request the focus if necessary.
5300 * This is needed when the toplevel is a GtkPlug
5302 if (!GTK_WIDGET_HAS_FOCUS (widget))
5303 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5310 while (widget->parent && widget->parent != focus_widget->parent)
5312 widget = widget->parent;
5313 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5317 else if (toplevel != focus_widget)
5319 /* gtk_widget_grab_focus() operates on a tree without window...
5320 * actually, this is very questionable behaviour.
5323 gtk_container_foreach (GTK_CONTAINER (toplevel),
5324 reset_focus_recurse,
5328 /* now propagate the new focus up the widget tree and finally
5329 * set it on the window
5331 widget = focus_widget;
5332 while (widget->parent)
5334 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5335 widget = widget->parent;
5337 if (GTK_IS_WINDOW (widget))
5338 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5343 gtk_widget_real_query_tooltip (GtkWidget *widget,
5346 gboolean keyboard_tip,
5347 GtkTooltip *tooltip)
5349 gchar *tooltip_markup;
5350 gboolean has_tooltip;
5352 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5353 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5355 if (has_tooltip && tooltip_markup)
5357 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5365 gtk_widget_real_show_help (GtkWidget *widget,
5366 GtkWidgetHelpType help_type)
5368 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5370 _gtk_tooltip_toggle_keyboard_mode (widget);
5379 gtk_widget_real_focus (GtkWidget *widget,
5380 GtkDirectionType direction)
5382 if (!GTK_WIDGET_CAN_FOCUS (widget))
5385 if (!gtk_widget_is_focus (widget))
5387 gtk_widget_grab_focus (widget);
5395 gtk_widget_real_move_focus (GtkWidget *widget,
5396 GtkDirectionType direction)
5398 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5400 if (GTK_IS_WINDOW (toplevel) &&
5401 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5403 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5409 gtk_widget_real_keynav_failed (GtkWidget *widget,
5410 GtkDirectionType direction)
5412 gboolean cursor_only;
5416 case GTK_DIR_TAB_FORWARD:
5417 case GTK_DIR_TAB_BACKWARD:
5424 g_object_get (gtk_widget_get_settings (widget),
5425 "gtk-keynav-cursor-only", &cursor_only,
5432 gtk_widget_error_bell (widget);
5438 * gtk_widget_set_can_focus:
5439 * @widget: a #GtkWidget
5440 * @can_focus: whether or not @widget can own the input focus.
5442 * Specifies whether @widget can own the input focus. See
5443 * gtk_widget_grab_focus() for actually setting the input focus on a
5449 gtk_widget_set_can_focus (GtkWidget *widget,
5452 g_return_if_fail (GTK_IS_WIDGET (widget));
5454 if (can_focus != GTK_WIDGET_CAN_FOCUS (widget))
5457 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
5459 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
5461 gtk_widget_queue_resize (widget);
5462 g_object_notify (G_OBJECT (widget), "can-focus");
5467 * gtk_widget_get_can_focus:
5468 * @widget: a #GtkWidget
5470 * Determines whether @widget can own the input focus. See
5471 * gtk_widget_set_can_focus().
5473 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5478 gtk_widget_get_can_focus (GtkWidget *widget)
5480 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5482 return GTK_WIDGET_CAN_FOCUS (widget);
5486 * gtk_widget_has_focus:
5487 * @widget: a #GtkWidget
5489 * Determines if the widget has the global input focus. See
5490 * gtk_widget_is_focus() for the difference between having the global
5491 * input focus, and only having the focus within a toplevel.
5493 * Return value: %TRUE if the widget has the global input focus.
5498 gtk_widget_has_focus (GtkWidget *widget)
5500 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5502 return GTK_WIDGET_HAS_FOCUS (widget);
5506 * gtk_widget_is_focus:
5507 * @widget: a #GtkWidget
5509 * Determines if the widget is the focus widget within its
5510 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5511 * necessarily set; %HAS_FOCUS will only be set if the
5512 * toplevel widget additionally has the global input focus.)
5514 * Return value: %TRUE if the widget is the focus widget.
5517 gtk_widget_is_focus (GtkWidget *widget)
5519 GtkWidget *toplevel;
5521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5523 toplevel = gtk_widget_get_toplevel (widget);
5525 if (GTK_IS_WINDOW (toplevel))
5526 return widget == GTK_WINDOW (toplevel)->focus_widget;
5532 * gtk_widget_set_can_default:
5533 * @widget: a #GtkWidget
5534 * @can_default: whether or not @widget can be a default widget.
5536 * Specifies whether @widget can be a default widget. See
5537 * gtk_widget_grab_default() for details about the meaning of
5543 gtk_widget_set_can_default (GtkWidget *widget,
5544 gboolean can_default)
5546 g_return_if_fail (GTK_IS_WIDGET (widget));
5548 if (can_default != GTK_WIDGET_CAN_DEFAULT (widget))
5551 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
5553 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
5555 gtk_widget_queue_resize (widget);
5556 g_object_notify (G_OBJECT (widget), "can-default");
5561 * gtk_widget_get_can_default:
5562 * @widget: a #GtkWidget
5564 * Determines whether @widget can be a default widget. See
5565 * gtk_widget_set_can_default().
5567 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5572 gtk_widget_get_can_default (GtkWidget *widget)
5574 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5576 return GTK_WIDGET_CAN_DEFAULT (widget);
5580 * gtk_widget_has_default:
5581 * @widget: a #GtkWidget
5583 * Determines whether @widget is the current default widget within its
5584 * toplevel. See gtk_widget_set_can_default().
5586 * Return value: %TRUE if @widget is the current default widget within
5587 * its toplevel, %FALSE otherwise
5592 gtk_widget_has_default (GtkWidget *widget)
5594 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5596 return GTK_WIDGET_HAS_DEFAULT (widget);
5600 * gtk_widget_grab_default:
5601 * @widget: a #GtkWidget
5603 * Causes @widget to become the default widget. @widget must have the
5604 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5605 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5606 * %TRUE)</literal>. The default widget is activated when
5607 * the user presses Enter in a window. Default widgets must be
5608 * activatable, that is, gtk_widget_activate() should affect them.
5611 gtk_widget_grab_default (GtkWidget *widget)
5615 g_return_if_fail (GTK_IS_WIDGET (widget));
5616 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5618 window = gtk_widget_get_toplevel (widget);
5620 if (window && GTK_WIDGET_TOPLEVEL (window))
5621 gtk_window_set_default (GTK_WINDOW (window), widget);
5623 g_warning (G_STRLOC ": widget not within a GtkWindow");
5627 * gtk_widget_set_receives_default:
5628 * @widget: a #GtkWidget
5629 * @receives_default: whether or not @widget can be a default widget.
5631 * Specifies whether @widget will be treated as the default widget
5632 * within its toplevel when it has the focus, even if another widget
5635 * See gtk_widget_grab_default() for details about the meaning of
5641 gtk_widget_set_receives_default (GtkWidget *widget,
5642 gboolean receives_default)
5644 g_return_if_fail (GTK_IS_WIDGET (widget));
5646 if (receives_default != gtk_widget_get_receives_default (widget))
5648 if (receives_default)
5649 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5651 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5653 g_object_notify (G_OBJECT (widget), "receives-default");
5658 * gtk_widget_get_receives_default:
5659 * @widget: a #GtkWidget
5661 * Determines whether @widget is alyways treated as default widget
5662 * withing its toplevel when it has the focus, even if another widget
5665 * See gtk_widget_set_receives_default().
5667 * Return value: %TRUE if @widget acts as default widget when focussed,
5673 gtk_widget_get_receives_default (GtkWidget *widget)
5675 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5677 return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5681 * gtk_widget_has_grab:
5682 * @widget: a #GtkWidget
5684 * Determines whether the widget is currently grabbing events, so it
5685 * is the only widget receiving input events (keyboard and mouse).
5687 * See also gtk_grab_add().
5689 * Return value: %TRUE if the widget is in the grab_widgets stack
5694 gtk_widget_has_grab (GtkWidget *widget)
5696 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5698 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5702 * gtk_widget_set_name:
5703 * @widget: a #GtkWidget
5704 * @name: name for the widget
5706 * Widgets can be named, which allows you to refer to them from a
5707 * gtkrc file. You can apply a style to widgets with a particular name
5708 * in the gtkrc file. See the documentation for gtkrc files (on the
5709 * same page as the docs for #GtkRcStyle).
5711 * Note that widget names are separated by periods in paths (see
5712 * gtk_widget_path()), so names with embedded periods may cause confusion.
5715 gtk_widget_set_name (GtkWidget *widget,
5720 g_return_if_fail (GTK_IS_WIDGET (widget));
5722 new_name = g_strdup (name);
5723 g_free (widget->name);
5724 widget->name = new_name;
5726 if (GTK_WIDGET_RC_STYLE (widget))
5727 gtk_widget_reset_rc_style (widget);
5729 g_object_notify (G_OBJECT (widget), "name");
5733 * gtk_widget_get_name:
5734 * @widget: a #GtkWidget
5736 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5737 * significance of widget names.
5739 * Return value: name of the widget. This string is owned by GTK+ and
5740 * should not be modified or freed
5742 G_CONST_RETURN gchar*
5743 gtk_widget_get_name (GtkWidget *widget)
5745 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5748 return widget->name;
5749 return g_type_name (GTK_WIDGET_TYPE (widget));
5753 * gtk_widget_set_state:
5754 * @widget: a #GtkWidget
5755 * @state: new state for @widget
5757 * This function is for use in widget implementations. Sets the state
5758 * of a widget (insensitive, prelighted, etc.) Usually you should set
5759 * the state using wrapper functions such as gtk_widget_set_sensitive().
5762 gtk_widget_set_state (GtkWidget *widget,
5765 g_return_if_fail (GTK_IS_WIDGET (widget));
5767 if (state == GTK_WIDGET_STATE (widget))
5770 if (state == GTK_STATE_INSENSITIVE)
5771 gtk_widget_set_sensitive (widget, FALSE);
5777 data.state_restoration = FALSE;
5778 data.use_forall = FALSE;
5780 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5782 data.parent_sensitive = TRUE;
5784 gtk_widget_propagate_state (widget, &data);
5786 if (GTK_WIDGET_DRAWABLE (widget))
5787 gtk_widget_queue_draw (widget);
5792 * gtk_widget_get_state:
5793 * @widget: a #GtkWidget
5795 * Returns the widget's state. See gtk_widget_set_state().
5797 * Returns: the state of @widget.
5802 gtk_widget_get_state (GtkWidget *widget)
5804 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5806 return widget->state;
5810 * gtk_widget_set_visible:
5811 * @widget: a #GtkWidget
5812 * @visible: whether the widget should be shown or not
5814 * Sets the visibility state of @widget. Note that setting this to
5815 * %TRUE doesn't mean the widget is actually viewable, see
5816 * gtk_widget_get_visible().
5818 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5819 * but is nicer to use when the visibility of the widget depends on
5825 gtk_widget_set_visible (GtkWidget *widget,
5828 g_return_if_fail (GTK_IS_WIDGET (widget));
5830 if (visible != GTK_WIDGET_VISIBLE (widget))
5833 gtk_widget_show (widget);
5835 gtk_widget_hide (widget);
5840 * gtk_widget_get_visible:
5841 * @widget: a #GtkWidget
5843 * Determines whether the widget is visible. Note that this doesn't
5844 * take into account whether the widget's parent is also visible
5845 * or the widget is obscured in any way.
5847 * See gtk_widget_set_visible().
5849 * Return value: %TRUE if the widget is visible
5854 gtk_widget_get_visible (GtkWidget *widget)
5856 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5858 return (GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0;
5862 * gtk_widget_set_has_window:
5863 * @widget: a #GtkWidget
5864 * @has_window: whether or not @widget has a window.
5866 * Specifies whether @widget has a #GdkWindow of its own. Note that
5867 * all realized widgets have a non-%NULL "window" pointer
5868 * (gtk_widget_get_window() never returns a %NULL window when a widget
5869 * is realized), but for many of them it's actually the #GdkWindow of
5870 * one of its parent widgets. Widgets that create a %window for
5871 * themselves in GtkWidget::realize() however must announce this by
5872 * calling this function with @has_window = %TRUE.
5874 * This function should only be called by widget implementations,
5875 * and they should call it in their init() function.
5880 gtk_widget_set_has_window (GtkWidget *widget,
5881 gboolean has_window)
5883 g_return_if_fail (GTK_IS_WIDGET (widget));
5886 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
5888 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
5892 * gtk_widget_get_has_window:
5893 * @widget: a #GtkWidget
5895 * Determines whether @widget has a #GdkWindow of its own. See
5896 * gtk_widget_set_has_window().
5898 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5903 gtk_widget_get_has_window (GtkWidget *widget)
5905 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5907 return !GTK_WIDGET_NO_WINDOW (widget);
5911 * gtk_widget_is_toplevel:
5912 * @widget: a #GtkWidget
5914 * Determines whether @widget is a toplevel widget. Currently only
5915 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5916 * widgets have no parent widget.
5918 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5923 gtk_widget_is_toplevel (GtkWidget *widget)
5925 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5927 return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5931 * gtk_widget_is_drawable:
5932 * @widget: a #GtkWidget
5934 * Determines whether @widget can be drawn to. A widget can be drawn
5935 * to if it is mapped and visible.
5937 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5942 gtk_widget_is_drawable (GtkWidget *widget)
5944 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5946 return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 &&
5947 (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0);
5951 * gtk_widget_set_app_paintable:
5952 * @widget: a #GtkWidget
5953 * @app_paintable: %TRUE if the application will paint on the widget
5955 * Sets whether the application intends to draw on the widget in
5956 * an #GtkWidget::expose-event handler.
5958 * This is a hint to the widget and does not affect the behavior of
5959 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5960 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5961 * the effect is to suppress default themed drawing of the widget's
5962 * background. (Children of the widget will still be drawn.) The application
5963 * is then entirely responsible for drawing the widget background.
5965 * Note that the background is still drawn when the widget is mapped.
5966 * If this is not suitable (e.g. because you want to make a transparent
5967 * window using an RGBA visual), you can work around this by doing:
5969 * gtk_widget_realize (window);
5970 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5971 * gtk_widget_show (window);
5975 gtk_widget_set_app_paintable (GtkWidget *widget,
5976 gboolean app_paintable)
5978 g_return_if_fail (GTK_IS_WIDGET (widget));
5980 app_paintable = (app_paintable != FALSE);
5982 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5985 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5987 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5989 if (GTK_WIDGET_DRAWABLE (widget))
5990 gtk_widget_queue_draw (widget);
5992 g_object_notify (G_OBJECT (widget), "app-paintable");
5997 * gtk_widget_get_app_paintable:
5998 * @widget: a #GtkWidget
6000 * Determines whether the application intends to draw on the widget in
6001 * an #GtkWidget::expose-event handler.
6003 * See gtk_widget_set_app_paintable()
6005 * Return value: %TRUE if the widget is app paintable
6010 gtk_widget_get_app_paintable (GtkWidget *widget)
6012 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6014 return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6018 * gtk_widget_set_double_buffered:
6019 * @widget: a #GtkWidget
6020 * @double_buffered: %TRUE to double-buffer a widget
6022 * Widgets are double buffered by default; you can use this function
6023 * to turn off the buffering. "Double buffered" simply means that
6024 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6025 * automatically around expose events sent to the
6026 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6027 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6028 * buffer to the screen. The result is that users see the window
6029 * update in one smooth step, and don't see individual graphics
6030 * primitives being rendered.
6032 * In very simple terms, double buffered widgets don't flicker,
6033 * so you would only use this function to turn off double buffering
6034 * if you had special needs and really knew what you were doing.
6036 * Note: if you turn off double-buffering, you have to handle
6037 * expose events, since even the clearing to the background color or
6038 * pixmap will not happen automatically (as it is done in
6039 * gdk_window_begin_paint()).
6042 gtk_widget_set_double_buffered (GtkWidget *widget,
6043 gboolean double_buffered)
6045 g_return_if_fail (GTK_IS_WIDGET (widget));
6047 if (double_buffered != GTK_WIDGET_DOUBLE_BUFFERED (widget))
6049 if (double_buffered)
6050 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
6052 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
6054 g_object_notify (G_OBJECT (widget), "double-buffered");
6059 * gtk_widget_get_double_buffered:
6060 * @widget: a #GtkWidget
6062 * Determines whether the widget is double buffered.
6064 * See gtk_widget_set_double_buffered()
6066 * Return value: %TRUE if the widget is double buffered
6071 gtk_widget_get_double_buffered (GtkWidget *widget)
6073 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6075 return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6079 * gtk_widget_set_redraw_on_allocate:
6080 * @widget: a #GtkWidget
6081 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6082 * when it is allocated to a new size. Otherwise, only the
6083 * new portion of the widget will be redrawn.
6085 * Sets whether the entire widget is queued for drawing when its size
6086 * allocation changes. By default, this setting is %TRUE and
6087 * the entire widget is redrawn on every size change. If your widget
6088 * leaves the upper left unchanged when made bigger, turning this
6089 * setting off will improve performance.
6091 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6092 * off all allocation on resizing: the widget will not even redraw if
6093 * its position changes; this is to allow containers that don't draw
6094 * anything to avoid excess invalidations. If you set this flag on a
6095 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6096 * you are responsible for invalidating both the old and new allocation
6097 * of the widget when the widget is moved and responsible for invalidating
6098 * regions newly when the widget increases size.
6101 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6102 gboolean redraw_on_allocate)
6104 g_return_if_fail (GTK_IS_WIDGET (widget));
6106 if (redraw_on_allocate)
6107 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6109 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6113 * gtk_widget_set_sensitive:
6114 * @widget: a #GtkWidget
6115 * @sensitive: %TRUE to make the widget sensitive
6117 * Sets the sensitivity of a widget. A widget is sensitive if the user
6118 * can interact with it. Insensitive widgets are "grayed out" and the
6119 * user can't interact with them. Insensitive widgets are known as
6120 * "inactive", "disabled", or "ghosted" in some other toolkits.
6123 gtk_widget_set_sensitive (GtkWidget *widget,
6128 g_return_if_fail (GTK_IS_WIDGET (widget));
6130 sensitive = (sensitive != FALSE);
6132 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
6137 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
6138 data.state = GTK_WIDGET_SAVED_STATE (widget);
6142 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
6143 data.state = GTK_WIDGET_STATE (widget);
6145 data.state_restoration = TRUE;
6146 data.use_forall = TRUE;
6149 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
6151 data.parent_sensitive = TRUE;
6153 gtk_widget_propagate_state (widget, &data);
6154 if (GTK_WIDGET_DRAWABLE (widget))
6155 gtk_widget_queue_draw (widget);
6157 g_object_notify (G_OBJECT (widget), "sensitive");
6161 * gtk_widget_get_sensitive:
6162 * @widget: a #GtkWidget
6164 * Returns the widget's sensitivity (in the sense of returning
6165 * the value that has been set using gtk_widget_set_sensitive()).
6167 * The effective sensitivity of a widget is however determined by both its
6168 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6170 * Returns: %TRUE if the widget is sensitive
6175 gtk_widget_get_sensitive (GtkWidget *widget)
6177 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6179 return GTK_WIDGET_SENSITIVE (widget);
6183 * gtk_widget_is_sensitive:
6184 * @widget: a #GtkWidget
6186 * Returns the widget's effective sensitivity, which means
6187 * it is sensitive itself and also its parent widget is sensntive
6189 * Returns: %TRUE if the widget is effectively sensitive
6194 gtk_widget_is_sensitive (GtkWidget *widget)
6196 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6198 return GTK_WIDGET_IS_SENSITIVE (widget);
6202 * gtk_widget_set_parent:
6203 * @widget: a #GtkWidget
6204 * @parent: parent container
6206 * This function is useful only when implementing subclasses of
6208 * Sets the container as the parent of @widget, and takes care of
6209 * some details such as updating the state and style of the child
6210 * to reflect its new location. The opposite function is
6211 * gtk_widget_unparent().
6214 gtk_widget_set_parent (GtkWidget *widget,
6219 g_return_if_fail (GTK_IS_WIDGET (widget));
6220 g_return_if_fail (GTK_IS_WIDGET (parent));
6221 g_return_if_fail (widget != parent);
6222 if (widget->parent != NULL)
6224 g_warning ("Can't set a parent on widget which has a parent\n");
6227 if (GTK_WIDGET_TOPLEVEL (widget))
6229 g_warning ("Can't set a parent on a toplevel widget\n");
6233 /* keep this function in sync with gtk_menu_attach_to_widget()
6236 g_object_ref_sink (widget);
6237 widget->parent = parent;
6239 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
6240 data.state = GTK_WIDGET_STATE (parent);
6242 data.state = GTK_WIDGET_STATE (widget);
6243 data.state_restoration = FALSE;
6244 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
6245 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
6247 gtk_widget_propagate_state (widget, &data);
6249 gtk_widget_reset_rc_styles (widget);
6251 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6252 if (GTK_WIDGET_ANCHORED (widget->parent))
6253 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6254 g_object_notify (G_OBJECT (widget), "parent");
6256 /* Enforce realized/mapped invariants
6258 if (GTK_WIDGET_REALIZED (widget->parent))
6259 gtk_widget_realize (widget);
6261 if (GTK_WIDGET_VISIBLE (widget->parent) &&
6262 GTK_WIDGET_VISIBLE (widget))
6264 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6265 GTK_WIDGET_MAPPED (widget->parent))
6266 gtk_widget_map (widget);
6268 gtk_widget_queue_resize (widget);
6273 * gtk_widget_get_parent:
6274 * @widget: a #GtkWidget
6276 * Returns the parent container of @widget.
6278 * Return value: the parent container of @widget, or %NULL
6281 gtk_widget_get_parent (GtkWidget *widget)
6283 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6285 return widget->parent;
6288 /*****************************************
6290 * see docs/styles.txt
6291 *****************************************/
6294 * gtk_widget_set_style:
6295 * @widget: a #GtkWidget
6296 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
6297 * gtk_widget_set_style() and go back to the default style
6299 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6300 * want to use this function; it interacts badly with themes, because
6301 * themes work by replacing the #GtkStyle. Instead, use
6302 * gtk_widget_modify_style().
6305 gtk_widget_set_style (GtkWidget *widget,
6308 g_return_if_fail (GTK_IS_WIDGET (widget));
6312 gboolean initial_emission;
6314 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6316 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
6317 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6319 gtk_widget_set_style_internal (widget, style, initial_emission);
6323 if (GTK_WIDGET_USER_STYLE (widget))
6324 gtk_widget_reset_rc_style (widget);
6329 * gtk_widget_ensure_style:
6330 * @widget: a #GtkWidget
6332 * Ensures that @widget has a style (@widget->style). Not a very useful
6333 * function; most of the time, if you want the style, the widget is
6334 * realized, and realized widgets are guaranteed to have a style
6338 gtk_widget_ensure_style (GtkWidget *widget)
6340 g_return_if_fail (GTK_IS_WIDGET (widget));
6342 if (!GTK_WIDGET_USER_STYLE (widget) &&
6343 !GTK_WIDGET_RC_STYLE (widget))
6344 gtk_widget_reset_rc_style (widget);
6347 /* Look up the RC style for this widget, unsetting any user style that
6348 * may be in effect currently
6351 gtk_widget_reset_rc_style (GtkWidget *widget)
6353 GtkStyle *new_style = NULL;
6354 gboolean initial_emission;
6356 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6358 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6359 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
6361 if (gtk_widget_has_screen (widget))
6362 new_style = gtk_rc_get_style (widget);
6364 new_style = gtk_widget_get_default_style ();
6366 if (initial_emission || new_style != widget->style)
6367 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6371 * gtk_widget_get_style:
6372 * @widget: a #GtkWidget
6374 * Simply an accessor function that returns @widget->style.
6376 * Return value: the widget's #GtkStyle
6379 gtk_widget_get_style (GtkWidget *widget)
6381 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6383 return widget->style;
6387 * gtk_widget_modify_style:
6388 * @widget: a #GtkWidget
6389 * @style: the #GtkRcStyle holding the style modifications
6391 * Modifies style values on the widget. Modifications made using this
6392 * technique take precedence over style values set via an RC file,
6393 * however, they will be overriden if a style is explicitely set on
6394 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6395 * is designed so each field can either be set or unset, so it is
6396 * possible, using this function, to modify some style values and
6397 * leave the others unchanged.
6399 * Note that modifications made with this function are not cumulative
6400 * with previous calls to gtk_widget_modify_style() or with such
6401 * functions as gtk_widget_modify_fg(). If you wish to retain
6402 * previous values, you must first call gtk_widget_get_modifier_style(),
6403 * make your modifications to the returned style, then call
6404 * gtk_widget_modify_style() with that style. On the other hand,
6405 * if you first call gtk_widget_modify_style(), subsequent calls
6406 * to such functions gtk_widget_modify_fg() will have a cumulative
6407 * effect with the initial modifications.
6410 gtk_widget_modify_style (GtkWidget *widget,
6413 g_return_if_fail (GTK_IS_WIDGET (widget));
6414 g_return_if_fail (GTK_IS_RC_STYLE (style));
6416 g_object_set_qdata_full (G_OBJECT (widget),
6418 gtk_rc_style_copy (style),
6419 (GDestroyNotify) g_object_unref);
6421 /* note that "style" may be invalid here if it was the old
6422 * modifier style and the only reference was our own.
6425 if (GTK_WIDGET_RC_STYLE (widget))
6426 gtk_widget_reset_rc_style (widget);
6430 * gtk_widget_get_modifier_style:
6431 * @widget: a #GtkWidget
6433 * Returns the current modifier style for the widget. (As set by
6434 * gtk_widget_modify_style().) If no style has previously set, a new
6435 * #GtkRcStyle will be created with all values unset, and set as the
6436 * modifier style for the widget. If you make changes to this rc
6437 * style, you must call gtk_widget_modify_style(), passing in the
6438 * returned rc style, to make sure that your changes take effect.
6440 * Caution: passing the style back to gtk_widget_modify_style() will
6441 * normally end up destroying it, because gtk_widget_modify_style() copies
6442 * the passed-in style and sets the copy as the new modifier style,
6443 * thus dropping any reference to the old modifier style. Add a reference
6444 * to the modifier style if you want to keep it alive.
6446 * Return value: the modifier style for the widget. This rc style is
6447 * owned by the widget. If you want to keep a pointer to value this
6448 * around, you must add a refcount using g_object_ref().
6451 gtk_widget_get_modifier_style (GtkWidget *widget)
6453 GtkRcStyle *rc_style;
6455 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6457 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6461 rc_style = gtk_rc_style_new ();
6462 g_object_set_qdata_full (G_OBJECT (widget),
6465 (GDestroyNotify) g_object_unref);
6472 gtk_widget_modify_color_component (GtkWidget *widget,
6473 GtkRcFlags component,
6475 const GdkColor *color)
6477 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6484 rc_style->fg[state] = *color;
6487 rc_style->bg[state] = *color;
6490 rc_style->text[state] = *color;
6493 rc_style->base[state] = *color;
6496 g_assert_not_reached();
6499 rc_style->color_flags[state] |= component;
6502 rc_style->color_flags[state] &= ~component;
6504 gtk_widget_modify_style (widget, rc_style);
6508 * gtk_widget_modify_fg:
6509 * @widget: a #GtkWidget
6510 * @state: the state for which to set the foreground color
6511 * @color: the color to assign (does not need to be allocated),
6512 * or %NULL to undo the effect of previous calls to
6513 * of gtk_widget_modify_fg().
6515 * Sets the foreground color for a widget in a particular state.
6516 * All other style values are left untouched. See also
6517 * gtk_widget_modify_style().
6520 gtk_widget_modify_fg (GtkWidget *widget,
6522 const GdkColor *color)
6524 g_return_if_fail (GTK_IS_WIDGET (widget));
6525 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6527 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6531 * gtk_widget_modify_bg:
6532 * @widget: a #GtkWidget
6533 * @state: the state for which to set the background color
6534 * @color: the color to assign (does not need to be allocated),
6535 * or %NULL to undo the effect of previous calls to
6536 * of gtk_widget_modify_bg().
6538 * Sets the background color for a widget in a particular state.
6539 * All other style values are left untouched. See also
6540 * gtk_widget_modify_style().
6542 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6543 * draw on their parent container's window and thus may not draw any
6544 * background themselves. This is the case for e.g. #GtkLabel. To modify
6545 * the background of such widgets, you have to set the background color
6546 * on their parent; if you want to set the background of a rectangular
6547 * area around a label, try placing the label in a #GtkEventBox widget
6548 * and setting the background color on that.
6551 gtk_widget_modify_bg (GtkWidget *widget,
6553 const GdkColor *color)
6555 g_return_if_fail (GTK_IS_WIDGET (widget));
6556 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6558 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6562 * gtk_widget_modify_text:
6563 * @widget: a #GtkWidget
6564 * @state: the state for which to set the text color
6565 * @color: the color to assign (does not need to be allocated),
6566 * or %NULL to undo the effect of previous calls to
6567 * of gtk_widget_modify_text().
6569 * Sets the text color for a widget in a particular state. All other
6570 * style values are left untouched. The text color is the foreground
6571 * color used along with the base color (see gtk_widget_modify_base())
6572 * for widgets such as #GtkEntry and #GtkTextView. See also
6573 * gtk_widget_modify_style().
6576 gtk_widget_modify_text (GtkWidget *widget,
6578 const GdkColor *color)
6580 g_return_if_fail (GTK_IS_WIDGET (widget));
6581 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6583 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6587 * gtk_widget_modify_base:
6588 * @widget: a #GtkWidget
6589 * @state: the state for which to set the base color
6590 * @color: the color to assign (does not need to be allocated),
6591 * or %NULL to undo the effect of previous calls to
6592 * of gtk_widget_modify_base().
6594 * Sets the base color for a widget in a particular state.
6595 * All other style values are left untouched. The base color
6596 * is the background color used along with the text color
6597 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6598 * and #GtkTextView. See also gtk_widget_modify_style().
6600 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6601 * draw on their parent container's window and thus may not draw any
6602 * background themselves. This is the case for e.g. #GtkLabel. To modify
6603 * the background of such widgets, you have to set the base color on their
6604 * parent; if you want to set the background of a rectangular area around
6605 * a label, try placing the label in a #GtkEventBox widget and setting
6606 * the base color on that.
6609 gtk_widget_modify_base (GtkWidget *widget,
6611 const GdkColor *color)
6613 g_return_if_fail (GTK_IS_WIDGET (widget));
6614 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6616 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6620 modify_color_property (GtkWidget *widget,
6621 GtkRcStyle *rc_style,
6623 const GdkColor *color)
6625 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6626 GQuark property_name = g_quark_from_string (name);
6630 GtkRcProperty rc_property = {0};
6633 rc_property.type_name = type_name;
6634 rc_property.property_name = property_name;
6635 rc_property.origin = NULL;
6637 color_name = gdk_color_to_string (color);
6638 g_value_init (&rc_property.value, G_TYPE_STRING);
6639 g_value_take_string (&rc_property.value, color_name);
6641 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6643 g_value_unset (&rc_property.value);
6646 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6650 * gtk_widget_modify_cursor:
6651 * @widget: a #GtkWidget
6652 * @primary: the color to use for primary cursor (does not need to be
6653 * allocated), or %NULL to undo the effect of previous calls to
6654 * of gtk_widget_modify_cursor().
6655 * @secondary: the color to use for secondary cursor (does not need to be
6656 * allocated), or %NULL to undo the effect of previous calls to
6657 * of gtk_widget_modify_cursor().
6659 * Sets the cursor color to use in a widget, overriding the
6660 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6661 * style properties. All other style values are left untouched.
6662 * See also gtk_widget_modify_style().
6667 gtk_widget_modify_cursor (GtkWidget *widget,
6668 const GdkColor *primary,
6669 const GdkColor *secondary)
6671 GtkRcStyle *rc_style;
6673 g_return_if_fail (GTK_IS_WIDGET (widget));
6675 rc_style = gtk_widget_get_modifier_style (widget);
6677 modify_color_property (widget, rc_style, "cursor-color", primary);
6678 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6680 gtk_widget_modify_style (widget, rc_style);
6684 * gtk_widget_modify_font:
6685 * @widget: a #GtkWidget
6686 * @font_desc: the font description to use, or %NULL to undo
6687 * the effect of previous calls to gtk_widget_modify_font().
6689 * Sets the font to use for a widget. All other style values are left
6690 * untouched. See also gtk_widget_modify_style().
6693 gtk_widget_modify_font (GtkWidget *widget,
6694 PangoFontDescription *font_desc)
6696 GtkRcStyle *rc_style;
6698 g_return_if_fail (GTK_IS_WIDGET (widget));
6700 rc_style = gtk_widget_get_modifier_style (widget);
6702 if (rc_style->font_desc)
6703 pango_font_description_free (rc_style->font_desc);
6706 rc_style->font_desc = pango_font_description_copy (font_desc);
6708 rc_style->font_desc = NULL;
6710 gtk_widget_modify_style (widget, rc_style);
6714 gtk_widget_real_direction_changed (GtkWidget *widget,
6715 GtkTextDirection previous_direction)
6717 gtk_widget_queue_resize (widget);
6721 gtk_widget_real_style_set (GtkWidget *widget,
6722 GtkStyle *previous_style)
6724 if (GTK_WIDGET_REALIZED (widget) &&
6725 !GTK_WIDGET_NO_WINDOW (widget))
6726 gtk_style_set_background (widget->style, widget->window, widget->state);
6730 gtk_widget_set_style_internal (GtkWidget *widget,
6732 gboolean initial_emission)
6734 g_object_ref (widget);
6735 g_object_freeze_notify (G_OBJECT (widget));
6737 if (widget->style != style)
6739 GtkStyle *previous_style;
6741 if (GTK_WIDGET_REALIZED (widget))
6743 gtk_widget_reset_shapes (widget);
6744 gtk_style_detach (widget->style);
6747 previous_style = widget->style;
6748 widget->style = style;
6749 g_object_ref (widget->style);
6751 if (GTK_WIDGET_REALIZED (widget))
6752 widget->style = gtk_style_attach (widget->style, widget->window);
6754 gtk_widget_update_pango_context (widget);
6755 g_signal_emit (widget,
6756 widget_signals[STYLE_SET],
6758 initial_emission ? NULL : previous_style);
6759 g_object_unref (previous_style);
6761 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6762 gtk_widget_queue_resize (widget);
6764 else if (initial_emission)
6766 gtk_widget_update_pango_context (widget);
6767 g_signal_emit (widget,
6768 widget_signals[STYLE_SET],
6772 g_object_notify (G_OBJECT (widget), "style");
6773 g_object_thaw_notify (G_OBJECT (widget));
6774 g_object_unref (widget);
6778 GtkWidget *previous_toplevel;
6779 GdkScreen *previous_screen;
6780 GdkScreen *new_screen;
6781 } HierarchyChangedInfo;
6784 do_screen_change (GtkWidget *widget,
6785 GdkScreen *old_screen,
6786 GdkScreen *new_screen)
6788 if (old_screen != new_screen)
6792 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6794 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6797 _gtk_tooltip_hide (widget);
6798 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6803 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6804 gpointer client_data)
6806 HierarchyChangedInfo *info = client_data;
6807 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6808 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6810 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6812 g_object_ref (widget);
6815 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6817 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6819 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6820 do_screen_change (widget, info->previous_screen, info->new_screen);
6822 if (GTK_IS_CONTAINER (widget))
6823 gtk_container_forall (GTK_CONTAINER (widget),
6824 gtk_widget_propagate_hierarchy_changed_recurse,
6827 g_object_unref (widget);
6832 * _gtk_widget_propagate_hierarchy_changed:
6833 * @widget: a #GtkWidget
6834 * @previous_toplevel: Previous toplevel
6836 * Propagates changes in the anchored state to a widget and all
6837 * children, unsetting or setting the %ANCHORED flag, and
6838 * emitting #GtkWidget::hierarchy-changed.
6841 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6842 GtkWidget *previous_toplevel)
6844 HierarchyChangedInfo info;
6846 info.previous_toplevel = previous_toplevel;
6847 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6849 if (GTK_WIDGET_TOPLEVEL (widget) ||
6850 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6851 info.new_screen = gtk_widget_get_screen (widget);
6853 info.new_screen = NULL;
6855 if (info.previous_screen)
6856 g_object_ref (info.previous_screen);
6857 if (previous_toplevel)
6858 g_object_ref (previous_toplevel);
6860 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6862 if (previous_toplevel)
6863 g_object_unref (previous_toplevel);
6864 if (info.previous_screen)
6865 g_object_unref (info.previous_screen);
6869 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6870 gpointer client_data)
6872 HierarchyChangedInfo *info = client_data;
6874 g_object_ref (widget);
6876 do_screen_change (widget, info->previous_screen, info->new_screen);
6878 if (GTK_IS_CONTAINER (widget))
6879 gtk_container_forall (GTK_CONTAINER (widget),
6880 gtk_widget_propagate_screen_changed_recurse,
6883 g_object_unref (widget);
6887 * gtk_widget_is_composited:
6888 * @widget: a #GtkWidget
6890 * Whether @widget can rely on having its alpha channel
6891 * drawn correctly. On X11 this function returns whether a
6892 * compositing manager is running for @widget's screen.
6894 * Please note that the semantics of this call will change
6895 * in the future if used on a widget that has a composited
6896 * window in its hierarchy (as set by gdk_window_set_composited()).
6898 * Return value: %TRUE if the widget can rely on its alpha
6899 * channel being drawn correctly.
6904 gtk_widget_is_composited (GtkWidget *widget)
6908 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6910 screen = gtk_widget_get_screen (widget);
6912 return gdk_screen_is_composited (screen);
6916 propagate_composited_changed (GtkWidget *widget,
6919 if (GTK_IS_CONTAINER (widget))
6921 gtk_container_forall (GTK_CONTAINER (widget),
6922 propagate_composited_changed,
6926 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6930 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6932 propagate_composited_changed (widget, NULL);
6936 * _gtk_widget_propagate_screen_changed:
6937 * @widget: a #GtkWidget
6938 * @previous_screen: Previous screen
6940 * Propagates changes in the screen for a widget to all
6941 * children, emitting #GtkWidget::screen-changed.
6944 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6945 GdkScreen *previous_screen)
6947 HierarchyChangedInfo info;
6949 info.previous_screen = previous_screen;
6950 info.new_screen = gtk_widget_get_screen (widget);
6952 if (previous_screen)
6953 g_object_ref (previous_screen);
6955 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6957 if (previous_screen)
6958 g_object_unref (previous_screen);
6962 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6964 if (GTK_WIDGET_RC_STYLE (widget))
6965 gtk_widget_reset_rc_style (widget);
6967 if (GTK_IS_CONTAINER (widget))
6968 gtk_container_forall (GTK_CONTAINER (widget),
6969 reset_rc_styles_recurse,
6975 * gtk_widget_reset_rc_styles:
6976 * @widget: a #GtkWidget.
6978 * Reset the styles of @widget and all descendents, so when
6979 * they are looked up again, they get the correct values
6980 * for the currently loaded RC file settings.
6982 * This function is not useful for applications.
6985 gtk_widget_reset_rc_styles (GtkWidget *widget)
6987 g_return_if_fail (GTK_IS_WIDGET (widget));
6989 reset_rc_styles_recurse (widget, NULL);
6993 * gtk_widget_get_default_style:
6995 * Returns the default style used by all widgets initially.
6997 * Returns: the default style. This #GtkStyle object is owned
6998 * by GTK+ and should not be modified or freed.
7001 gtk_widget_get_default_style (void)
7003 if (!gtk_default_style)
7005 gtk_default_style = gtk_style_new ();
7006 g_object_ref (gtk_default_style);
7009 return gtk_default_style;
7012 static PangoContext *
7013 gtk_widget_peek_pango_context (GtkWidget *widget)
7015 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7019 * gtk_widget_get_pango_context:
7020 * @widget: a #GtkWidget
7022 * Gets a #PangoContext with the appropriate font map, font description,
7023 * and base direction for this widget. Unlike the context returned
7024 * by gtk_widget_create_pango_context(), this context is owned by
7025 * the widget (it can be used until the screen for the widget changes
7026 * or the widget is removed from its toplevel), and will be updated to
7027 * match any changes to the widget's attributes.
7029 * If you create and keep a #PangoLayout using this context, you must
7030 * deal with changes to the context by calling pango_layout_context_changed()
7031 * on the layout in response to the #GtkWidget::style-set and
7032 * #GtkWidget::direction-changed signals for the widget.
7034 * Return value: the #PangoContext for the widget.
7037 gtk_widget_get_pango_context (GtkWidget *widget)
7039 PangoContext *context;
7041 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7043 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7046 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7047 g_object_set_qdata_full (G_OBJECT (widget),
7048 quark_pango_context,
7057 update_pango_context (GtkWidget *widget,
7058 PangoContext *context)
7060 pango_context_set_font_description (context, widget->style->font_desc);
7061 pango_context_set_base_dir (context,
7062 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7063 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7067 gtk_widget_update_pango_context (GtkWidget *widget)
7069 PangoContext *context = gtk_widget_peek_pango_context (widget);
7075 update_pango_context (widget, context);
7077 screen = gtk_widget_get_screen_unchecked (widget);
7080 pango_cairo_context_set_resolution (context,
7081 gdk_screen_get_resolution (screen));
7082 pango_cairo_context_set_font_options (context,
7083 gdk_screen_get_font_options (screen));
7089 * gtk_widget_create_pango_context:
7090 * @widget: a #GtkWidget
7092 * Creates a new #PangoContext with the appropriate font map,
7093 * font description, and base direction for drawing text for
7094 * this widget. See also gtk_widget_get_pango_context().
7096 * Return value: the new #PangoContext
7099 gtk_widget_create_pango_context (GtkWidget *widget)
7102 PangoContext *context;
7104 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7106 screen = gtk_widget_get_screen_unchecked (widget);
7109 GTK_NOTE (MULTIHEAD,
7110 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7112 screen = gdk_screen_get_default ();
7115 context = gdk_pango_context_get_for_screen (screen);
7117 update_pango_context (widget, context);
7118 pango_context_set_language (context, gtk_get_default_language ());
7124 * gtk_widget_create_pango_layout:
7125 * @widget: a #GtkWidget
7126 * @text: text to set on the layout (can be %NULL)
7128 * Creates a new #PangoLayout with the appropriate font map,
7129 * font description, and base direction for drawing text for
7132 * If you keep a #PangoLayout created in this way around, in order to
7133 * notify the layout of changes to the base direction or font of this
7134 * widget, you must call pango_layout_context_changed() in response to
7135 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7138 * Return value: the new #PangoLayout
7141 gtk_widget_create_pango_layout (GtkWidget *widget,
7144 PangoLayout *layout;
7145 PangoContext *context;
7147 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7149 context = gtk_widget_get_pango_context (widget);
7150 layout = pango_layout_new (context);
7153 pango_layout_set_text (layout, text, -1);
7159 * gtk_widget_render_icon:
7160 * @widget: a #GtkWidget
7161 * @stock_id: a stock ID
7162 * @size: a stock size. A size of (GtkIconSize)-1 means render at
7163 * the size of the source and don't scale (if there are multiple
7164 * source sizes, GTK+ picks one of the available sizes).
7165 * @detail: render detail to pass to theme engine
7167 * A convenience function that uses the theme engine and RC file
7168 * settings for @widget to look up @stock_id and render it to
7169 * a pixbuf. @stock_id should be a stock icon ID such as
7170 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7171 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7172 * identifies the widget or code doing the rendering, so that
7173 * theme engines can special-case rendering for that widget or code.
7175 * The pixels in the returned #GdkPixbuf are shared with the rest of
7176 * the application and should not be modified. The pixbuf should be freed
7177 * after use with g_object_unref().
7179 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7182 gtk_widget_render_icon (GtkWidget *widget,
7183 const gchar *stock_id,
7185 const gchar *detail)
7187 GtkIconSet *icon_set;
7190 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7191 g_return_val_if_fail (stock_id != NULL, NULL);
7192 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7194 gtk_widget_ensure_style (widget);
7196 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7198 if (icon_set == NULL)
7201 retval = gtk_icon_set_render_icon (icon_set,
7203 gtk_widget_get_direction (widget),
7204 GTK_WIDGET_STATE (widget),
7213 * gtk_widget_set_parent_window:
7214 * @widget: a #GtkWidget.
7215 * @parent_window: the new parent window.
7217 * Sets a non default parent window for @widget.
7220 gtk_widget_set_parent_window (GtkWidget *widget,
7221 GdkWindow *parent_window)
7223 GdkWindow *old_parent_window;
7225 g_return_if_fail (GTK_IS_WIDGET (widget));
7227 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7228 quark_parent_window);
7230 if (parent_window != old_parent_window)
7232 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7234 if (old_parent_window)
7235 g_object_unref (old_parent_window);
7237 g_object_ref (parent_window);
7242 * gtk_widget_get_parent_window:
7243 * @widget: a #GtkWidget.
7244 * @returns: the parent window of @widget.
7246 * Gets @widget's parent window.
7249 gtk_widget_get_parent_window (GtkWidget *widget)
7251 GdkWindow *parent_window;
7253 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7255 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7257 return (parent_window != NULL) ? parent_window :
7258 (widget->parent != NULL) ? widget->parent->window : NULL;
7263 * gtk_widget_set_child_visible:
7264 * @widget: a #GtkWidget
7265 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7267 * Sets whether @widget should be mapped along with its when its parent
7268 * is mapped and @widget has been shown with gtk_widget_show().
7270 * The child visibility can be set for widget before it is added to
7271 * a container with gtk_widget_set_parent(), to avoid mapping
7272 * children unnecessary before immediately unmapping them. However
7273 * it will be reset to its default state of %TRUE when the widget
7274 * is removed from a container.
7276 * Note that changing the child visibility of a widget does not
7277 * queue a resize on the widget. Most of the time, the size of
7278 * a widget is computed from all visible children, whether or
7279 * not they are mapped. If this is not the case, the container
7280 * can queue a resize itself.
7282 * This function is only useful for container implementations and
7283 * never should be called by an application.
7286 gtk_widget_set_child_visible (GtkWidget *widget,
7287 gboolean is_visible)
7289 g_return_if_fail (GTK_IS_WIDGET (widget));
7290 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
7292 g_object_ref (widget);
7295 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7298 GtkWidget *toplevel;
7300 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7302 toplevel = gtk_widget_get_toplevel (widget);
7303 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
7304 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7307 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
7309 if (GTK_WIDGET_MAPPED (widget->parent) &&
7310 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7311 GTK_WIDGET_VISIBLE (widget))
7312 gtk_widget_map (widget);
7314 gtk_widget_unmap (widget);
7317 g_object_unref (widget);
7321 * gtk_widget_get_child_visible:
7322 * @widget: a #GtkWidget
7324 * Gets the value set with gtk_widget_set_child_visible().
7325 * If you feel a need to use this function, your code probably
7326 * needs reorganization.
7328 * This function is only useful for container implementations and
7329 * never should be called by an application.
7331 * Return value: %TRUE if the widget is mapped with the parent.
7334 gtk_widget_get_child_visible (GtkWidget *widget)
7336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7338 return GTK_WIDGET_CHILD_VISIBLE (widget);
7342 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7344 GtkWidget *toplevel;
7346 toplevel = gtk_widget_get_toplevel (widget);
7348 if (GTK_WIDGET_TOPLEVEL (toplevel))
7350 if (GTK_IS_WINDOW (toplevel))
7351 return GTK_WINDOW (toplevel)->screen;
7352 else if (GTK_IS_INVISIBLE (toplevel))
7353 return GTK_INVISIBLE (widget)->screen;
7360 * gtk_widget_get_screen:
7361 * @widget: a #GtkWidget
7363 * Get the #GdkScreen from the toplevel window associated with
7364 * this widget. This function can only be called after the widget
7365 * has been added to a widget hierarchy with a #GtkWindow
7368 * In general, you should only create screen specific
7369 * resources when a widget has been realized, and you should
7370 * free those resources when the widget is unrealized.
7372 * Return value: the #GdkScreen for the toplevel for this widget.
7377 gtk_widget_get_screen (GtkWidget *widget)
7381 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7383 screen = gtk_widget_get_screen_unchecked (widget);
7390 g_warning (G_STRLOC ": Can't get associated screen"
7391 " for a widget unless it is inside a toplevel GtkWindow\n"
7392 " widget type is %s associated top level type is %s",
7393 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7394 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7396 return gdk_screen_get_default ();
7401 * gtk_widget_has_screen:
7402 * @widget: a #GtkWidget
7404 * Checks whether there is a #GdkScreen is associated with
7405 * this widget. All toplevel widgets have an associated
7406 * screen, and all widgets added into a hierarchy with a toplevel
7407 * window at the top.
7409 * Return value: %TRUE if there is a #GdkScreen associcated
7415 gtk_widget_has_screen (GtkWidget *widget)
7417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7419 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7423 * gtk_widget_get_display:
7424 * @widget: a #GtkWidget
7426 * Get the #GdkDisplay for the toplevel window associated with
7427 * this widget. This function can only be called after the widget
7428 * has been added to a widget hierarchy with a #GtkWindow at the top.
7430 * In general, you should only create display specific
7431 * resources when a widget has been realized, and you should
7432 * free those resources when the widget is unrealized.
7434 * Return value: the #GdkDisplay for the toplevel for this widget.
7439 gtk_widget_get_display (GtkWidget *widget)
7441 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7443 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7447 * gtk_widget_get_root_window:
7448 * @widget: a #GtkWidget
7450 * Get the root window where this widget is located. This function can
7451 * only be called after the widget has been added to a widget
7452 * hierarchy with #GtkWindow at the top.
7454 * The root window is useful for such purposes as creating a popup
7455 * #GdkWindow associated with the window. In general, you should only
7456 * create display specific resources when a widget has been realized,
7457 * and you should free those resources when the widget is unrealized.
7459 * Return value: the #GdkWindow root window for the toplevel for this widget.
7464 gtk_widget_get_root_window (GtkWidget *widget)
7466 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7468 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7472 * gtk_widget_child_focus:
7473 * @widget: a #GtkWidget
7474 * @direction: direction of focus movement
7476 * This function is used by custom widget implementations; if you're
7477 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7478 * to a particular widget, and gtk_container_set_focus_chain() to
7479 * change the focus tab order. So you may want to investigate those
7480 * functions instead.
7482 * gtk_widget_child_focus() is called by containers as the user moves
7483 * around the window using keyboard shortcuts. @direction indicates
7484 * what kind of motion is taking place (up, down, left, right, tab
7485 * forward, tab backward). gtk_widget_child_focus() emits the
7486 * #GtkWidget::focus" signal; widgets override the default handler
7487 * for this signal in order to implement appropriate focus behavior.
7489 * The default ::focus handler for a widget should return %TRUE if
7490 * moving in @direction left the focus on a focusable location inside
7491 * that widget, and %FALSE if moving in @direction moved the focus
7492 * outside the widget. If returning %TRUE, widgets normally
7493 * call gtk_widget_grab_focus() to place the focus accordingly;
7494 * if returning %FALSE, they don't modify the current focus location.
7496 * This function replaces gtk_container_focus() from GTK+ 1.2.
7497 * It was necessary to check that the child was visible, sensitive,
7498 * and focusable before calling gtk_container_focus().
7499 * gtk_widget_child_focus() returns %FALSE if the widget is not
7500 * currently in a focusable state, so there's no need for those checks.
7502 * Return value: %TRUE if focus ended up inside @widget
7505 gtk_widget_child_focus (GtkWidget *widget,
7506 GtkDirectionType direction)
7508 gboolean return_val;
7510 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7512 if (!GTK_WIDGET_VISIBLE (widget) ||
7513 !GTK_WIDGET_IS_SENSITIVE (widget))
7516 /* child widgets must set CAN_FOCUS, containers
7517 * don't have to though.
7519 if (!GTK_IS_CONTAINER (widget) &&
7520 !GTK_WIDGET_CAN_FOCUS (widget))
7523 g_signal_emit (widget,
7524 widget_signals[FOCUS],
7526 direction, &return_val);
7532 * gtk_widget_keynav_failed:
7533 * @widget: a #GtkWidget
7534 * @direction: direction of focus movement
7536 * This function should be called whenever keyboard navigation within
7537 * a single widget hits a boundary. The function emits the
7538 * #GtkWidget::keynav-failed signal on the widget and its return
7539 * value should be interpreted in a way similar to the return value of
7540 * gtk_widget_child_focus():
7542 * When %TRUE is returned, stay in the widget, the failed keyboard
7543 * navigation is Ok and/or there is nowhere we can/should move the
7546 * When %FALSE is returned, the caller should continue with keyboard
7547 * navigation outside the widget, e.g. by calling
7548 * gtk_widget_child_focus() on the widget's toplevel.
7550 * The default ::keynav-failed handler returns %TRUE for
7551 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7552 * values of #GtkDirectionType, it looks at the
7553 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7554 * if the setting is %TRUE. This way the entire user interface
7555 * becomes cursor-navigatable on input devices such as mobile phones
7556 * which only have cursor keys but no tab key.
7558 * Whenever the default handler returns %TRUE, it also calls
7559 * gtk_widget_error_bell() to notify the user of the failed keyboard
7562 * A use case for providing an own implementation of ::keynav-failed
7563 * (either by connecting to it or by overriding it) would be a row of
7564 * #GtkEntry widgets where the user should be able to navigate the
7565 * entire row with the cursor keys, as e.g. known from user interfaces
7566 * that require entering license keys.
7568 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7569 * if the emitting widget should try to handle the keyboard
7570 * navigation attempt in its parent container(s).
7575 gtk_widget_keynav_failed (GtkWidget *widget,
7576 GtkDirectionType direction)
7578 gboolean return_val;
7580 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7582 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7583 direction, &return_val);
7589 * gtk_widget_error_bell:
7590 * @widget: a #GtkWidget
7592 * Notifies the user about an input-related error on this widget.
7593 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7594 * gdk_window_beep(), otherwise it does nothing.
7596 * Note that the effect of gdk_window_beep() can be configured in many
7597 * ways, depending on the windowing backend and the desktop environment
7598 * or window manager that is used.
7603 gtk_widget_error_bell (GtkWidget *widget)
7605 GtkSettings* settings;
7608 g_return_if_fail (GTK_IS_WIDGET (widget));
7610 settings = gtk_widget_get_settings (widget);
7614 g_object_get (settings,
7615 "gtk-error-bell", &beep,
7618 if (beep && widget->window)
7619 gdk_window_beep (widget->window);
7623 * gtk_widget_set_uposition:
7624 * @widget: a #GtkWidget
7625 * @x: x position; -1 to unset x; -2 to leave x unchanged
7626 * @y: y position; -1 to unset y; -2 to leave y unchanged
7629 * Sets the position of a widget. The funny "u" in the name comes from
7630 * the "user position" hint specified by the X Window System, and
7631 * exists for legacy reasons. This function doesn't work if a widget
7632 * is inside a container; it's only really useful on #GtkWindow.
7634 * Don't use this function to center dialogs over the main application
7635 * window; most window managers will do the centering on your behalf
7636 * if you call gtk_window_set_transient_for(), and it's really not
7637 * possible to get the centering to work correctly in all cases from
7638 * application code. But if you insist, use gtk_window_set_position()
7639 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7642 * Note that although @x and @y can be individually unset, the position
7643 * is not honoured unless both @x and @y are set.
7646 gtk_widget_set_uposition (GtkWidget *widget,
7650 /* FIXME this function is the only place that aux_info->x and
7651 * aux_info->y are even used I believe, and this function is
7652 * deprecated. Should be cleaned up.
7654 * (Actually, size_allocate uses them) -Yosh
7657 GtkWidgetAuxInfo *aux_info;
7659 g_return_if_fail (GTK_IS_WIDGET (widget));
7661 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7666 aux_info->x_set = FALSE;
7669 aux_info->x_set = TRUE;
7677 aux_info->y_set = FALSE;
7680 aux_info->y_set = TRUE;
7685 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7686 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7688 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7689 gtk_widget_size_allocate (widget, &widget->allocation);
7693 gtk_widget_set_usize_internal (GtkWidget *widget,
7697 GtkWidgetAuxInfo *aux_info;
7698 gboolean changed = FALSE;
7700 g_object_freeze_notify (G_OBJECT (widget));
7702 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7704 if (width > -2 && aux_info->width != width)
7706 g_object_notify (G_OBJECT (widget), "width-request");
7707 aux_info->width = width;
7710 if (height > -2 && aux_info->height != height)
7712 g_object_notify (G_OBJECT (widget), "height-request");
7713 aux_info->height = height;
7717 if (GTK_WIDGET_VISIBLE (widget) && changed)
7718 gtk_widget_queue_resize (widget);
7720 g_object_thaw_notify (G_OBJECT (widget));
7724 * gtk_widget_set_usize:
7725 * @widget: a #GtkWidget
7726 * @width: minimum width, or -1 to unset
7727 * @height: minimum height, or -1 to unset
7729 * Sets the minimum size of a widget; that is, the widget's size
7730 * request will be @width by @height. You can use this function to
7731 * force a widget to be either larger or smaller than it is. The
7732 * strange "usize" name dates from the early days of GTK+, and derives
7733 * from X Window System terminology. In many cases,
7734 * gtk_window_set_default_size() is a better choice for toplevel
7735 * windows than this function; setting the default size will still
7736 * allow users to shrink the window. Setting the usize will force them
7737 * to leave the window at least as large as the usize. When dealing
7738 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7741 * Note the inherent danger of setting any fixed size - themes,
7742 * translations into other languages, different fonts, and user action
7743 * can all change the appropriate size for a given widget. So, it's
7744 * basically impossible to hardcode a size that will always be
7747 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7750 gtk_widget_set_usize (GtkWidget *widget,
7754 g_return_if_fail (GTK_IS_WIDGET (widget));
7756 gtk_widget_set_usize_internal (widget, width, height);
7760 * gtk_widget_set_size_request:
7761 * @widget: a #GtkWidget
7762 * @width: width @widget should request, or -1 to unset
7763 * @height: height @widget should request, or -1 to unset
7765 * Sets the minimum size of a widget; that is, the widget's size
7766 * request will be @width by @height. You can use this function to
7767 * force a widget to be either larger or smaller than it normally
7770 * In most cases, gtk_window_set_default_size() is a better choice for
7771 * toplevel windows than this function; setting the default size will
7772 * still allow users to shrink the window. Setting the size request
7773 * will force them to leave the window at least as large as the size
7774 * request. When dealing with window sizes,
7775 * gtk_window_set_geometry_hints() can be a useful function as well.
7777 * Note the inherent danger of setting any fixed size - themes,
7778 * translations into other languages, different fonts, and user action
7779 * can all change the appropriate size for a given widget. So, it's
7780 * basically impossible to hardcode a size that will always be
7783 * The size request of a widget is the smallest size a widget can
7784 * accept while still functioning well and drawing itself correctly.
7785 * However in some strange cases a widget may be allocated less than
7786 * its requested size, and in many cases a widget may be allocated more
7787 * space than it requested.
7789 * If the size request in a given direction is -1 (unset), then
7790 * the "natural" size request of the widget will be used instead.
7792 * Widgets can't actually be allocated a size less than 1 by 1, but
7793 * you can pass 0,0 to this function to mean "as small as possible."
7796 gtk_widget_set_size_request (GtkWidget *widget,
7800 g_return_if_fail (GTK_IS_WIDGET (widget));
7801 g_return_if_fail (width >= -1);
7802 g_return_if_fail (height >= -1);
7809 gtk_widget_set_usize_internal (widget, width, height);
7814 * gtk_widget_get_size_request:
7815 * @widget: a #GtkWidget
7816 * @width: return location for width, or %NULL
7817 * @height: return location for height, or %NULL
7819 * Gets the size request that was explicitly set for the widget using
7820 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7821 * @height indicates that that dimension has not been set explicitly
7822 * and the natural requisition of the widget will be used intead. See
7823 * gtk_widget_set_size_request(). To get the size a widget will
7824 * actually use, call gtk_widget_size_request() instead of
7828 gtk_widget_get_size_request (GtkWidget *widget,
7832 GtkWidgetAuxInfo *aux_info;
7834 g_return_if_fail (GTK_IS_WIDGET (widget));
7836 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7839 *width = aux_info ? aux_info->width : -1;
7842 *height = aux_info ? aux_info->height : -1;
7846 * gtk_widget_set_events:
7847 * @widget: a #GtkWidget
7848 * @events: event mask
7850 * Sets the event mask (see #GdkEventMask) for a widget. The event
7851 * mask determines which events a widget will receive. Keep in mind
7852 * that different widgets have different default event masks, and by
7853 * changing the event mask you may disrupt a widget's functionality,
7854 * so be careful. This function must be called while a widget is
7855 * unrealized. Consider gtk_widget_add_events() for widgets that are
7856 * already realized, or if you want to preserve the existing event
7857 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7858 * to get events on those widgets, place them inside a #GtkEventBox
7859 * and receive events on the event box.
7862 gtk_widget_set_events (GtkWidget *widget,
7865 g_return_if_fail (GTK_IS_WIDGET (widget));
7866 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7868 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7869 GINT_TO_POINTER (events));
7870 g_object_notify (G_OBJECT (widget), "events");
7874 gtk_widget_add_events_internal (GtkWidget *widget,
7880 for (l = window_list; l != NULL; l = l->next)
7882 GdkWindow *window = l->data;
7885 gdk_window_get_user_data (window, &user_data);
7886 if (user_data == widget)
7890 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7892 children = gdk_window_get_children (window);
7893 gtk_widget_add_events_internal (widget, events, children);
7894 g_list_free (children);
7900 * gtk_widget_add_events:
7901 * @widget: a #GtkWidget
7902 * @events: an event mask, see #GdkEventMask
7904 * Adds the events in the bitfield @events to the event mask for
7905 * @widget. See gtk_widget_set_events() for details.
7908 gtk_widget_add_events (GtkWidget *widget,
7913 g_return_if_fail (GTK_IS_WIDGET (widget));
7915 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7916 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7917 GINT_TO_POINTER (old_events | events));
7919 if (GTK_WIDGET_REALIZED (widget))
7923 if (GTK_WIDGET_NO_WINDOW (widget))
7924 window_list = gdk_window_get_children (widget->window);
7926 window_list = g_list_prepend (NULL, widget->window);
7928 gtk_widget_add_events_internal (widget, events, window_list);
7930 g_list_free (window_list);
7933 g_object_notify (G_OBJECT (widget), "events");
7937 * gtk_widget_set_extension_events:
7938 * @widget: a #GtkWidget
7939 * @mode: bitfield of extension events to receive
7941 * Sets the extension events mask to @mode. See #GdkExtensionMode
7942 * and gdk_input_set_extension_events().
7945 gtk_widget_set_extension_events (GtkWidget *widget,
7946 GdkExtensionMode mode)
7948 g_return_if_fail (GTK_IS_WIDGET (widget));
7950 if (GTK_WIDGET_REALIZED (widget))
7951 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7953 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7954 GINT_TO_POINTER (mode));
7955 g_object_notify (G_OBJECT (widget), "extension-events");
7959 * gtk_widget_get_toplevel:
7960 * @widget: a #GtkWidget
7962 * This function returns the topmost widget in the container hierarchy
7963 * @widget is a part of. If @widget has no parent widgets, it will be
7964 * returned as the topmost widget. No reference will be added to the
7965 * returned widget; it should not be unreferenced.
7967 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7968 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7970 * %NULL if @widget wasn't inside a toplevel window, and if the
7971 * window was inside a #GtkWindow-derived widget which was in turn
7972 * inside the toplevel #GtkWindow. While the second case may
7973 * seem unlikely, it actually happens when a #GtkPlug is embedded
7974 * inside a #GtkSocket within the same application.
7976 * To reliably find the toplevel #GtkWindow, use
7977 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7978 * is set on the result.
7980 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7981 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7983 * /* Perform action on toplevel. */
7987 * Return value: the topmost ancestor of @widget, or @widget itself
7988 * if there's no ancestor.
7991 gtk_widget_get_toplevel (GtkWidget *widget)
7993 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7995 while (widget->parent)
7996 widget = widget->parent;
8002 * gtk_widget_get_ancestor:
8003 * @widget: a #GtkWidget
8004 * @widget_type: ancestor type
8006 * Gets the first ancestor of @widget with type @widget_type. For example,
8007 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8008 * the first #GtkBox that's an ancestor of @widget. No reference will be
8009 * added to the returned widget; it should not be unreferenced. See note
8010 * about checking for a toplevel #GtkWindow in the docs for
8011 * gtk_widget_get_toplevel().
8013 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8014 * considers @widget to be an ancestor of itself.
8016 * Return value: the ancestor widget, or %NULL if not found
8019 gtk_widget_get_ancestor (GtkWidget *widget,
8022 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8024 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
8025 widget = widget->parent;
8027 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
8034 * gtk_widget_get_colormap:
8035 * @widget: a #GtkWidget
8037 * Gets the colormap that will be used to render @widget. No reference will
8038 * be added to the returned colormap; it should not be unreferenced.
8040 * Return value: the colormap used by @widget
8043 gtk_widget_get_colormap (GtkWidget *widget)
8045 GdkColormap *colormap;
8046 GtkWidget *tmp_widget;
8048 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8052 colormap = gdk_drawable_get_colormap (widget->window);
8053 /* If window was destroyed previously, we'll get NULL here */
8058 tmp_widget = widget;
8061 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8065 tmp_widget= tmp_widget->parent;
8068 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8072 * gtk_widget_get_visual:
8073 * @widget: a #GtkWidget
8075 * Gets the visual that will be used to render @widget.
8077 * Return value: the visual for @widget
8080 gtk_widget_get_visual (GtkWidget *widget)
8082 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8084 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8088 * gtk_widget_get_settings:
8089 * @widget: a #GtkWidget
8091 * Gets the settings object holding the settings (global property
8092 * settings, RC file information, etc) used for this widget.
8094 * Note that this function can only be called when the #GtkWidget
8095 * is attached to a toplevel, since the settings object is specific
8096 * to a particular #GdkScreen.
8098 * Return value: the relevant #GtkSettings object
8101 gtk_widget_get_settings (GtkWidget *widget)
8103 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8105 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8109 * gtk_widget_set_colormap:
8110 * @widget: a #GtkWidget
8111 * @colormap: a colormap
8113 * Sets the colormap for the widget to the given value. Widget must not
8114 * have been previously realized. This probably should only be used
8115 * from an <function>init()</function> function (i.e. from the constructor
8119 gtk_widget_set_colormap (GtkWidget *widget,
8120 GdkColormap *colormap)
8122 g_return_if_fail (GTK_IS_WIDGET (widget));
8123 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
8124 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8126 g_object_ref (colormap);
8128 g_object_set_qdata_full (G_OBJECT (widget),
8135 * gtk_widget_get_events:
8136 * @widget: a #GtkWidget
8138 * Returns the event mask for the widget (a bitfield containing flags
8139 * from the #GdkEventMask enumeration). These are the events that the widget
8142 * Return value: event mask for @widget
8145 gtk_widget_get_events (GtkWidget *widget)
8147 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8149 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8153 * gtk_widget_get_extension_events:
8154 * @widget: a #GtkWidget
8156 * Retrieves the extension events the widget will receive; see
8157 * gdk_input_set_extension_events().
8159 * Return value: extension events for @widget
8162 gtk_widget_get_extension_events (GtkWidget *widget)
8164 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8166 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8170 * gtk_widget_get_pointer:
8171 * @widget: a #GtkWidget
8172 * @x: return location for the X coordinate, or %NULL
8173 * @y: return location for the Y coordinate, or %NULL
8175 * Obtains the location of the mouse pointer in widget coordinates.
8176 * Widget coordinates are a bit odd; for historical reasons, they are
8177 * defined as @widget->window coordinates for widgets that are not
8178 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8179 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8182 gtk_widget_get_pointer (GtkWidget *widget,
8186 g_return_if_fail (GTK_IS_WIDGET (widget));
8193 if (GTK_WIDGET_REALIZED (widget))
8195 gdk_window_get_pointer (widget->window, x, y, NULL);
8197 if (GTK_WIDGET_NO_WINDOW (widget))
8200 *x -= widget->allocation.x;
8202 *y -= widget->allocation.y;
8208 * gtk_widget_is_ancestor:
8209 * @widget: a #GtkWidget
8210 * @ancestor: another #GtkWidget
8212 * Determines whether @widget is somewhere inside @ancestor, possibly with
8213 * intermediate containers.
8215 * Return value: %TRUE if @ancestor contains @widget as a child,
8216 * grandchild, great grandchild, etc.
8219 gtk_widget_is_ancestor (GtkWidget *widget,
8220 GtkWidget *ancestor)
8222 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8223 g_return_val_if_fail (ancestor != NULL, FALSE);
8227 if (widget->parent == ancestor)
8229 widget = widget->parent;
8235 static GQuark quark_composite_name = 0;
8238 * gtk_widget_set_composite_name:
8239 * @widget: a #GtkWidget.
8240 * @name: the name to set
8242 * Sets a widgets composite name. The widget must be
8243 * a composite child of its parent; see gtk_widget_push_composite_child().
8246 gtk_widget_set_composite_name (GtkWidget *widget,
8249 g_return_if_fail (GTK_IS_WIDGET (widget));
8250 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
8251 g_return_if_fail (name != NULL);
8253 if (!quark_composite_name)
8254 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8256 g_object_set_qdata_full (G_OBJECT (widget),
8257 quark_composite_name,
8263 * gtk_widget_get_composite_name:
8264 * @widget: a #GtkWidget
8266 * Obtains the composite name of a widget.
8268 * Returns: the composite name of @widget, or %NULL if @widget is not
8269 * a composite child. The string should be freed when it is no
8273 gtk_widget_get_composite_name (GtkWidget *widget)
8275 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8277 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
8278 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8285 * gtk_widget_push_composite_child:
8287 * Makes all newly-created widgets as composite children until
8288 * the corresponding gtk_widget_pop_composite_child() call.
8290 * A composite child is a child that's an implementation detail of the
8291 * container it's inside and should not be visible to people using the
8292 * container. Composite children aren't treated differently by GTK (but
8293 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8294 * builders might want to treat them in a different way.
8296 * Here is a simple example:
8298 * gtk_widget_push_composite_child ();
8299 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8300 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8301 * gtk_widget_pop_composite_child ();
8302 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8303 * GTK_WIDGET (scrolled_window));
8304 * g_object_ref (scrolled_window->hscrollbar);
8308 gtk_widget_push_composite_child (void)
8310 composite_child_stack++;
8314 * gtk_widget_pop_composite_child:
8316 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8319 gtk_widget_pop_composite_child (void)
8321 if (composite_child_stack)
8322 composite_child_stack--;
8326 * gtk_widget_push_colormap:
8327 * @cmap: a #GdkColormap
8329 * Pushes @cmap onto a global stack of colormaps; the topmost
8330 * colormap on the stack will be used to create all widgets.
8331 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8332 * reason to use this function.
8335 gtk_widget_push_colormap (GdkColormap *cmap)
8337 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8339 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8343 * gtk_widget_pop_colormap:
8345 * Removes a colormap pushed with gtk_widget_push_colormap().
8348 gtk_widget_pop_colormap (void)
8351 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8355 * gtk_widget_set_default_colormap:
8356 * @colormap: a #GdkColormap
8358 * Sets the default colormap to use when creating widgets.
8359 * gtk_widget_push_colormap() is a better function to use if
8360 * you only want to affect a few widgets, rather than all widgets.
8363 gtk_widget_set_default_colormap (GdkColormap *colormap)
8365 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8367 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8372 * gtk_widget_get_default_colormap:
8374 * Obtains the default colormap used to create widgets.
8376 * Return value: default widget colormap
8379 gtk_widget_get_default_colormap (void)
8381 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8385 * gtk_widget_get_default_visual:
8387 * Obtains the visual of the default colormap. Not really useful;
8388 * used to be useful before gdk_colormap_get_visual() existed.
8390 * Return value: visual of the default colormap
8393 gtk_widget_get_default_visual (void)
8395 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8399 gtk_widget_emit_direction_changed (GtkWidget *widget,
8400 GtkTextDirection old_dir)
8402 gtk_widget_update_pango_context (widget);
8404 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8408 * gtk_widget_set_direction:
8409 * @widget: a #GtkWidget
8410 * @dir: the new direction
8412 * Sets the reading direction on a particular widget. This direction
8413 * controls the primary direction for widgets containing text,
8414 * and also the direction in which the children of a container are
8415 * packed. The ability to set the direction is present in order
8416 * so that correct localization into languages with right-to-left
8417 * reading directions can be done. Generally, applications will
8418 * let the default reading direction present, except for containers
8419 * where the containers are arranged in an order that is explicitely
8420 * visual rather than logical (such as buttons for text justification).
8422 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8423 * set by gtk_widget_set_default_direction() will be used.
8426 gtk_widget_set_direction (GtkWidget *widget,
8427 GtkTextDirection dir)
8429 GtkTextDirection old_dir;
8431 g_return_if_fail (GTK_IS_WIDGET (widget));
8432 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8434 old_dir = gtk_widget_get_direction (widget);
8436 if (dir == GTK_TEXT_DIR_NONE)
8437 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8440 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8441 if (dir == GTK_TEXT_DIR_LTR)
8442 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8444 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8447 if (old_dir != gtk_widget_get_direction (widget))
8448 gtk_widget_emit_direction_changed (widget, old_dir);
8452 * gtk_widget_get_direction:
8453 * @widget: a #GtkWidget
8455 * Gets the reading direction for a particular widget. See
8456 * gtk_widget_set_direction().
8458 * Return value: the reading direction for the widget.
8461 gtk_widget_get_direction (GtkWidget *widget)
8463 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8465 if (GTK_WIDGET_DIRECTION_SET (widget))
8466 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8468 return gtk_default_direction;
8472 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8474 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8476 g_object_ref (widget);
8478 if (!GTK_WIDGET_DIRECTION_SET (widget))
8479 gtk_widget_emit_direction_changed (widget, old_dir);
8481 if (GTK_IS_CONTAINER (widget))
8482 gtk_container_forall (GTK_CONTAINER (widget),
8483 gtk_widget_set_default_direction_recurse,
8486 g_object_unref (widget);
8490 * gtk_widget_set_default_direction:
8491 * @dir: the new default direction. This cannot be
8492 * %GTK_TEXT_DIR_NONE.
8494 * Sets the default reading direction for widgets where the
8495 * direction has not been explicitly set by gtk_widget_set_direction().
8498 gtk_widget_set_default_direction (GtkTextDirection dir)
8500 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8502 if (dir != gtk_default_direction)
8504 GList *toplevels, *tmp_list;
8505 GtkTextDirection old_dir = gtk_default_direction;
8507 gtk_default_direction = dir;
8509 tmp_list = toplevels = gtk_window_list_toplevels ();
8510 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8514 gtk_widget_set_default_direction_recurse (tmp_list->data,
8515 GUINT_TO_POINTER (old_dir));
8516 g_object_unref (tmp_list->data);
8517 tmp_list = tmp_list->next;
8520 g_list_free (toplevels);
8525 * gtk_widget_get_default_direction:
8527 * Obtains the current default reading direction. See
8528 * gtk_widget_set_default_direction().
8530 * Return value: the current default direction.
8533 gtk_widget_get_default_direction (void)
8535 return gtk_default_direction;
8539 gtk_widget_dispose (GObject *object)
8541 GtkWidget *widget = GTK_WIDGET (object);
8544 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8545 else if (GTK_WIDGET_VISIBLE (widget))
8546 gtk_widget_hide (widget);
8548 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8549 if (GTK_WIDGET_REALIZED (widget))
8550 gtk_widget_unrealize (widget);
8552 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8556 gtk_widget_real_destroy (GtkObject *object)
8558 /* gtk_object_destroy() will already hold a refcount on object */
8559 GtkWidget *widget = GTK_WIDGET (object);
8561 /* wipe accelerator closures (keep order) */
8562 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8563 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8565 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8566 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8568 gtk_grab_remove (widget);
8570 g_object_unref (widget->style);
8571 widget->style = gtk_widget_get_default_style ();
8572 g_object_ref (widget->style);
8574 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8578 gtk_widget_finalize (GObject *object)
8580 GtkWidget *widget = GTK_WIDGET (object);
8581 GtkWidgetAuxInfo *aux_info;
8582 GtkAccessible *accessible;
8584 gtk_grab_remove (widget);
8586 g_object_unref (widget->style);
8587 widget->style = NULL;
8589 g_free (widget->name);
8591 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8593 gtk_widget_aux_info_destroy (aux_info);
8595 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8597 g_object_unref (accessible);
8599 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8602 /*****************************************
8603 * gtk_widget_real_map:
8608 *****************************************/
8611 gtk_widget_real_map (GtkWidget *widget)
8613 g_assert (GTK_WIDGET_REALIZED (widget));
8615 if (!GTK_WIDGET_MAPPED (widget))
8617 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
8619 if (!GTK_WIDGET_NO_WINDOW (widget))
8620 gdk_window_show (widget->window);
8624 /*****************************************
8625 * gtk_widget_real_unmap:
8630 *****************************************/
8633 gtk_widget_real_unmap (GtkWidget *widget)
8635 if (GTK_WIDGET_MAPPED (widget))
8637 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8639 if (!GTK_WIDGET_NO_WINDOW (widget))
8640 gdk_window_hide (widget->window);
8644 /*****************************************
8645 * gtk_widget_real_realize:
8650 *****************************************/
8653 gtk_widget_real_realize (GtkWidget *widget)
8655 g_assert (GTK_WIDGET_NO_WINDOW (widget));
8657 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8660 widget->window = gtk_widget_get_parent_window (widget);
8661 g_object_ref (widget->window);
8663 widget->style = gtk_style_attach (widget->style, widget->window);
8666 /*****************************************
8667 * gtk_widget_real_unrealize:
8672 *****************************************/
8675 gtk_widget_real_unrealize (GtkWidget *widget)
8677 if (GTK_WIDGET_MAPPED (widget))
8678 gtk_widget_real_unmap (widget);
8680 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8682 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8685 /* We must do unrealize child widget BEFORE container widget.
8686 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8687 * So, unrealizing container widget bofore its children causes the problem
8688 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8691 if (GTK_IS_CONTAINER (widget))
8692 gtk_container_forall (GTK_CONTAINER (widget),
8693 (GtkCallback) gtk_widget_unrealize,
8696 gtk_style_detach (widget->style);
8697 if (!GTK_WIDGET_NO_WINDOW (widget))
8699 gdk_window_set_user_data (widget->window, NULL);
8700 gdk_window_destroy (widget->window);
8701 widget->window = NULL;
8705 g_object_unref (widget->window);
8706 widget->window = NULL;
8709 gtk_selection_remove_all (widget);
8711 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8715 gtk_widget_real_size_request (GtkWidget *widget,
8716 GtkRequisition *requisition)
8718 requisition->width = widget->requisition.width;
8719 requisition->height = widget->requisition.height;
8723 * _gtk_widget_peek_colormap:
8725 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8727 * Return value: the currently pushed colormap, or %NULL if there is none.
8730 _gtk_widget_peek_colormap (void)
8733 return (GdkColormap*) colormap_stack->data;
8738 * _gtk_widget_set_pointer_window:
8739 * @widget: a #GtkWidget.
8740 * @pointer_window: the new pointer window.
8742 * Sets pointer window for @widget. Does not ref @pointer_window.
8743 * Actually stores it on the #GdkScreen, but you don't need to know that.
8746 _gtk_widget_set_pointer_window (GtkWidget *widget,
8747 GdkWindow *pointer_window)
8749 g_return_if_fail (GTK_IS_WIDGET (widget));
8751 if (GTK_WIDGET_REALIZED (widget))
8753 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8755 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8761 * _gtk_widget_get_pointer_window:
8762 * @widget: a #GtkWidget.
8764 * Return value: the pointer window set on the #GdkScreen @widget is attached
8768 _gtk_widget_get_pointer_window (GtkWidget *widget)
8770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8772 if (GTK_WIDGET_REALIZED (widget))
8774 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8776 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8783 synth_crossing (GtkWidget *widget,
8786 GdkCrossingMode mode,
8787 GdkNotifyType detail)
8791 event = gdk_event_new (type);
8793 event->crossing.window = g_object_ref (window);
8794 event->crossing.send_event = TRUE;
8795 event->crossing.subwindow = g_object_ref (window);
8796 event->crossing.time = GDK_CURRENT_TIME;
8797 event->crossing.x = event->crossing.y = 0;
8798 event->crossing.x_root = event->crossing.y_root = 0;
8799 event->crossing.mode = mode;
8800 event->crossing.detail = detail;
8801 event->crossing.focus = FALSE;
8802 event->crossing.state = 0;
8805 widget = gtk_get_event_widget (event);
8808 gtk_widget_event_internal (widget, event);
8810 gdk_event_free (event);
8814 * _gtk_widget_is_pointer_widget:
8815 * @widget: a #GtkWidget
8817 * Returns %TRUE if the pointer window belongs to @widget.
8820 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8822 if (GTK_WIDGET_HAS_POINTER (widget))
8827 win = _gtk_widget_get_pointer_window (widget);
8830 gdk_window_get_user_data (win, (gpointer *)&wid);
8840 * _gtk_widget_synthesize_crossing:
8841 * @from: the #GtkWidget the virtual pointer is leaving.
8842 * @to: the #GtkWidget the virtual pointer is moving to.
8843 * @mode: the #GdkCrossingMode to place on the synthesized events.
8845 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8847 * The real pointer window is the window that most recently received an enter notify
8848 * event. Windows that don't select for crossing events can't become the real
8849 * poiner window. The real pointer widget that owns the real pointer window. The
8850 * effective pointer window is the same as the real pointer window unless the real
8851 * pointer widget is either insensitive or there is a grab on a widget that is not
8852 * an ancestor of the real pointer widget (in which case the effective pointer
8853 * window should be the root window).
8855 * When the effective pointer window is the same as the real poiner window, we
8856 * receive crossing events from the windowing system. When the effective pointer
8857 * window changes to become different from the real pointer window we synthesize
8858 * crossing events, attempting to follow X protocol rules:
8860 * When the root window becomes the effective pointer window:
8861 * - leave notify on real pointer window, detail Ancestor
8862 * - leave notify on all of its ancestors, detail Virtual
8863 * - enter notify on root window, detail Inferior
8865 * When the root window ceases to be the effective pointer window:
8866 * - leave notify on root window, detail Inferior
8867 * - enter notify on all ancestors of real pointer window, detail Virtual
8868 * - enter notify on real pointer window, detail Ancestor
8871 _gtk_widget_synthesize_crossing (GtkWidget *from,
8873 GdkCrossingMode mode)
8875 GdkWindow *from_window = NULL, *to_window = NULL;
8877 g_return_if_fail (from != NULL || to != NULL);
8880 from_window = GTK_WIDGET_HAS_POINTER (from)
8881 ? _gtk_widget_get_pointer_window (from) : from->window;
8883 to_window = GTK_WIDGET_HAS_POINTER (to)
8884 ? _gtk_widget_get_pointer_window (to) : to->window;
8886 if (from_window == NULL && to_window == NULL)
8888 else if (from_window != NULL && to_window == NULL)
8890 GList *from_ancestors = NULL, *list;
8891 GdkWindow *from_ancestor = from_window;
8893 while (from_ancestor != NULL)
8895 from_ancestor = gdk_window_get_parent (from_ancestor);
8896 if (from_ancestor == NULL)
8898 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8901 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8902 mode, GDK_NOTIFY_ANCESTOR);
8903 for (list = g_list_last (from_ancestors); list; list = list->prev)
8905 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8906 mode, GDK_NOTIFY_VIRTUAL);
8909 /* XXX: enter/inferior on root window? */
8911 g_list_free (from_ancestors);
8913 else if (from_window == NULL && to_window != NULL)
8915 GList *to_ancestors = NULL, *list;
8916 GdkWindow *to_ancestor = to_window;
8918 while (to_ancestor != NULL)
8920 to_ancestor = gdk_window_get_parent (to_ancestor);
8921 if (to_ancestor == NULL)
8923 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8926 /* XXX: leave/inferior on root window? */
8928 for (list = to_ancestors; list; list = list->next)
8930 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8931 mode, GDK_NOTIFY_VIRTUAL);
8933 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8934 mode, GDK_NOTIFY_ANCESTOR);
8936 g_list_free (to_ancestors);
8938 else if (from_window == to_window)
8942 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8943 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8945 while (from_ancestor != NULL || to_ancestor != NULL)
8947 if (from_ancestor != NULL)
8949 from_ancestor = gdk_window_get_parent (from_ancestor);
8950 if (from_ancestor == to_window)
8953 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8955 if (to_ancestor != NULL)
8957 to_ancestor = gdk_window_get_parent (to_ancestor);
8958 if (to_ancestor == from_window)
8961 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8964 if (to_ancestor == from_window)
8966 if (mode != GDK_CROSSING_GTK_UNGRAB)
8967 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8968 mode, GDK_NOTIFY_INFERIOR);
8969 for (list = to_ancestors; list; list = list->next)
8970 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8971 mode, GDK_NOTIFY_VIRTUAL);
8972 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8973 mode, GDK_NOTIFY_ANCESTOR);
8975 else if (from_ancestor == to_window)
8977 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8978 mode, GDK_NOTIFY_ANCESTOR);
8979 for (list = g_list_last (from_ancestors); list; list = list->prev)
8981 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8982 mode, GDK_NOTIFY_VIRTUAL);
8984 if (mode != GDK_CROSSING_GTK_GRAB)
8985 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8986 mode, GDK_NOTIFY_INFERIOR);
8990 while (from_ancestors != NULL && to_ancestors != NULL
8991 && from_ancestors->data == to_ancestors->data)
8993 from_ancestors = g_list_delete_link (from_ancestors,
8995 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8998 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8999 mode, GDK_NOTIFY_NONLINEAR);
9001 for (list = g_list_last (from_ancestors); list; list = list->prev)
9003 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9004 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9006 for (list = to_ancestors; list; list = list->next)
9008 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9009 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9011 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9012 mode, GDK_NOTIFY_NONLINEAR);
9014 g_list_free (from_ancestors);
9015 g_list_free (to_ancestors);
9020 gtk_widget_propagate_state (GtkWidget *widget,
9023 guint8 old_state = GTK_WIDGET_STATE (widget);
9024 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
9026 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9027 * parent_sensitive==TRUE on a sensitive widget
9031 if (data->parent_sensitive)
9032 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9034 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
9036 if (GTK_WIDGET_IS_SENSITIVE (widget))
9038 if (data->state_restoration)
9039 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
9041 GTK_WIDGET_STATE (widget) = data->state;
9045 if (!data->state_restoration)
9047 if (data->state != GTK_STATE_INSENSITIVE)
9048 GTK_WIDGET_SAVED_STATE (widget) = data->state;
9050 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
9051 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
9052 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
9055 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
9059 window = gtk_widget_get_toplevel (widget);
9060 if (window && GTK_WIDGET_TOPLEVEL (window))
9061 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9064 if (old_state != GTK_WIDGET_STATE (widget) ||
9065 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
9067 g_object_ref (widget);
9069 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
9070 gtk_grab_remove (widget);
9072 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9074 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9076 if (!GTK_WIDGET_IS_SENSITIVE (widget))
9077 _gtk_widget_synthesize_crossing (widget, NULL,
9078 GDK_CROSSING_STATE_CHANGED);
9079 else if (old_state == GTK_STATE_INSENSITIVE)
9080 _gtk_widget_synthesize_crossing (NULL, widget,
9081 GDK_CROSSING_STATE_CHANGED);
9084 if (GTK_IS_CONTAINER (widget))
9086 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
9087 if (data->use_forall)
9088 gtk_container_forall (GTK_CONTAINER (widget),
9089 (GtkCallback) gtk_widget_propagate_state,
9092 gtk_container_foreach (GTK_CONTAINER (widget),
9093 (GtkCallback) gtk_widget_propagate_state,
9096 g_object_unref (widget);
9101 * _gtk_widget_get_aux_info:
9102 * @widget: a #GtkWidget
9103 * @create: if %TRUE, create the structure if it doesn't exist
9105 * Get the #GtkWidgetAuxInfo structure for the widget.
9107 * Return value: the #GtkAuxInfo structure for the widget, or
9108 * %NULL if @create is %FALSE and one doesn't already exist.
9111 _gtk_widget_get_aux_info (GtkWidget *widget,
9114 GtkWidgetAuxInfo *aux_info;
9116 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9117 if (!aux_info && create)
9119 aux_info = g_slice_new (GtkWidgetAuxInfo);
9121 aux_info->width = -1;
9122 aux_info->height = -1;
9125 aux_info->x_set = FALSE;
9126 aux_info->y_set = FALSE;
9127 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9133 /*****************************************
9134 * gtk_widget_aux_info_destroy:
9139 *****************************************/
9142 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9144 g_slice_free (GtkWidgetAuxInfo, aux_info);
9148 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9150 g_object_unref (info->shape_mask);
9151 g_slice_free (GtkWidgetShapeInfo, info);
9155 * gtk_widget_shape_combine_mask:
9156 * @widget: a #GtkWidget
9157 * @shape_mask: shape to be added, or %NULL to remove an existing shape
9158 * @offset_x: X position of shape mask with respect to @window
9159 * @offset_y: Y position of shape mask with respect to @window
9161 * Sets a shape for this widget's GDK window. This allows for
9162 * transparent windows etc., see gdk_window_shape_combine_mask()
9163 * for more information.
9166 gtk_widget_shape_combine_mask (GtkWidget *widget,
9167 GdkBitmap *shape_mask,
9171 GtkWidgetShapeInfo* shape_info;
9173 g_return_if_fail (GTK_IS_WIDGET (widget));
9174 /* set_shape doesn't work on widgets without gdk window */
9175 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9179 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9182 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9184 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9188 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9190 shape_info = g_slice_new (GtkWidgetShapeInfo);
9191 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9192 (GDestroyNotify) gtk_widget_shape_info_destroy);
9194 shape_info->shape_mask = g_object_ref (shape_mask);
9195 shape_info->offset_x = offset_x;
9196 shape_info->offset_y = offset_y;
9198 /* set shape if widget has a gdk window already.
9199 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9202 gdk_window_shape_combine_mask (widget->window, shape_mask,
9203 offset_x, offset_y);
9208 * gtk_widget_input_shape_combine_mask:
9209 * @widget: a #GtkWidget
9210 * @shape_mask: shape to be added, or %NULL to remove an existing shape
9211 * @offset_x: X position of shape mask with respect to @window
9212 * @offset_y: Y position of shape mask with respect to @window
9214 * Sets an input shape for this widget's GDK window. This allows for
9215 * windows which react to mouse click in a nonrectangular region, see
9216 * gdk_window_input_shape_combine_mask() for more information.
9221 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9222 GdkBitmap *shape_mask,
9226 GtkWidgetShapeInfo* shape_info;
9228 g_return_if_fail (GTK_IS_WIDGET (widget));
9229 /* set_shape doesn't work on widgets without gdk window */
9230 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9235 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9237 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9241 shape_info = g_slice_new (GtkWidgetShapeInfo);
9242 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9244 (GDestroyNotify) gtk_widget_shape_info_destroy);
9246 shape_info->shape_mask = g_object_ref (shape_mask);
9247 shape_info->offset_x = offset_x;
9248 shape_info->offset_y = offset_y;
9250 /* set shape if widget has a gdk window already.
9251 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9254 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9255 offset_x, offset_y);
9261 gtk_reset_shapes_recurse (GtkWidget *widget,
9267 gdk_window_get_user_data (window, &data);
9271 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9272 for (list = gdk_window_peek_children (window); list; list = list->next)
9273 gtk_reset_shapes_recurse (widget, list->data);
9277 * gtk_widget_reset_shapes:
9278 * @widget: a #GtkWidget
9280 * Recursively resets the shape on this widget and its descendants.
9283 gtk_widget_reset_shapes (GtkWidget *widget)
9285 g_return_if_fail (GTK_IS_WIDGET (widget));
9286 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
9288 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9289 gtk_reset_shapes_recurse (widget, widget->window);
9294 * @widget: a #GtkWidget
9296 * Adds a reference to a widget. This function is exactly the same
9297 * as calling g_object_ref(), and exists mostly for historical
9298 * reasons. It can still be convenient to avoid casting a widget
9299 * to a #GObject, it saves a small amount of typing.
9301 * Return value: the widget that was referenced
9303 * Deprecated: 2.12: Use g_object_ref() instead.
9306 gtk_widget_ref (GtkWidget *widget)
9308 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9310 return (GtkWidget*) g_object_ref ((GObject*) widget);
9315 * @widget: a #GtkWidget
9317 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9319 * Deprecated: 2.12: Use g_object_unref() instead.
9322 gtk_widget_unref (GtkWidget *widget)
9324 g_return_if_fail (GTK_IS_WIDGET (widget));
9326 g_object_unref ((GObject*) widget);
9330 expose_window (GdkWindow *window)
9333 GList *l, *children;
9335 gboolean is_double_buffered;
9337 gdk_window_get_user_data (window, &user_data);
9340 is_double_buffered = GTK_WIDGET_DOUBLE_BUFFERED (GTK_WIDGET (user_data));
9342 is_double_buffered = FALSE;
9344 event.expose.type = GDK_EXPOSE;
9345 event.expose.window = g_object_ref (window);
9346 event.expose.send_event = FALSE;
9347 event.expose.count = 0;
9348 event.expose.area.x = 0;
9349 event.expose.area.y = 0;
9350 gdk_drawable_get_size (GDK_DRAWABLE (window),
9351 &event.expose.area.width,
9352 &event.expose.area.height);
9353 event.expose.region = gdk_region_rectangle (&event.expose.area);
9355 /* If this is not double buffered, force a double buffer so that
9356 redirection works. */
9357 if (!is_double_buffered)
9358 gdk_window_begin_paint_region (window, event.expose.region);
9360 gtk_main_do_event (&event);
9362 if (!is_double_buffered)
9363 gdk_window_end_paint (window);
9365 children = gdk_window_peek_children (window);
9366 for (l = children; l != NULL; l = l->next)
9368 GdkWindow *child = l->data;
9370 /* Don't expose input-only windows */
9371 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9372 expose_window (l->data);
9375 g_object_unref (window);
9379 * gtk_widget_get_snapshot:
9380 * @widget: a #GtkWidget
9381 * @clip_rect: a #GdkRectangle or %NULL
9383 * Create a #GdkPixmap of the contents of the widget and its children.
9385 * Works even if the widget is obscured. The depth and visual of the
9386 * resulting pixmap is dependent on the widget being snapshot and likely
9387 * differs from those of a target widget displaying the pixmap.
9388 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9389 * the pixmap to a visual independant representation.
9391 * The snapshot area used by this function is the @widget's allocation plus
9392 * any extra space occupied by additional windows belonging to this widget
9393 * (such as the arrows of a spin button).
9394 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9396 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9397 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9398 * interpreted widget relative. If width or height of @clip_rect are 0 or
9399 * negative, the width or height of the resulting pixmap will be shrunken
9400 * by the respective amount.
9401 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9402 * chop off 5 pixels at each side of the snapshot pixmap.
9403 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9404 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9405 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9406 * as a pure output parameter.
9408 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9410 * Return value: #GdkPixmap snapshot of the widget
9415 gtk_widget_get_snapshot (GtkWidget *widget,
9416 GdkRectangle *clip_rect)
9418 int x, y, width, height;
9419 GdkWindow *parent_window = NULL;
9421 GList *windows = NULL, *list;
9423 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9424 if (!GTK_WIDGET_VISIBLE (widget))
9427 /* the widget (and parent_window) must be realized to be drawable */
9428 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
9429 gtk_widget_realize (widget->parent);
9430 if (!GTK_WIDGET_REALIZED (widget))
9431 gtk_widget_realize (widget);
9433 /* determine snapshot rectangle */
9434 x = widget->allocation.x;
9435 y = widget->allocation.y;
9436 width = widget->allocation.width;
9437 height = widget->allocation.height;
9439 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
9441 /* grow snapshot rectangle to cover all widget windows */
9442 parent_window = gtk_widget_get_parent_window (widget);
9443 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9445 GdkWindow *subwin = list->data;
9448 gdk_window_get_user_data (subwin, &windata);
9449 if (windata != widget)
9451 windows = g_list_prepend (windows, subwin);
9452 gdk_window_get_position (subwin, &wx, &wy);
9453 gdk_drawable_get_size (subwin, &ww, &wh);
9454 /* grow snapshot rectangle by extra widget sub window */
9465 if (x + width < wx + ww)
9466 width += wx + ww - (x + width);
9467 if (y + height < wy + wh)
9468 height += wy + wh - (y + height);
9471 else if (!widget->parent)
9472 x = y = 0; /* toplevel */
9474 /* at this point, (x,y,width,height) is the parent_window relative
9475 * snapshot area covering all of widget's windows.
9478 /* shrink snapshot size by clip_rectangle */
9481 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9482 clip.x = clip.x < 0 ? x : clip.x;
9483 clip.y = clip.y < 0 ? y : clip.y;
9484 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9485 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9488 /* offset clip_rect, so it's parent_window relative */
9489 if (clip_rect->x >= 0)
9490 clip.x += widget->allocation.x;
9491 if (clip_rect->y >= 0)
9492 clip.y += widget->allocation.y;
9494 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9496 g_list_free (windows);
9497 clip_rect->width = clip_rect->height = 0;
9498 return NULL; /* empty snapshot area */
9503 height = snap.height;
9506 /* render snapshot */
9507 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9508 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9510 GdkWindow *subwin = list->data;
9512 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9513 continue; /* Input only window */
9514 gdk_window_get_position (subwin, &wx, &wy);
9515 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9516 MAX (0, wx - x), MAX (0, wy - y), width, height);
9518 expose_window (subwin);
9520 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9522 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9523 expose_window (widget->window);
9525 for (list = windows; list; list = list->next)
9526 gdk_window_remove_redirection (list->data);
9527 if (!windows) /* NO_WINDOW || toplevel */
9528 gdk_window_remove_redirection (widget->window);
9529 g_list_free (windows);
9531 /* return pixmap and snapshot rectangle coordinates */
9536 clip_rect->width = width;
9537 clip_rect->height = height;
9540 /* offset clip_rect from parent_window so it's widget relative */
9541 clip_rect->x -= widget->allocation.x;
9542 clip_rect->y -= widget->allocation.y;
9545 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9546 G_OBJECT_TYPE_NAME (widget),
9547 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9556 * gtk_widget_class_install_style_property_parser:
9557 * @klass: a #GtkWidgetClass
9558 * @pspec: the #GParamSpec for the style property
9559 * @parser: the parser for the style property
9561 * Installs a style property on a widget class.
9564 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9566 GtkRcPropertyParser parser)
9568 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9569 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9570 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9571 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9573 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9575 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9576 G_OBJECT_CLASS_NAME (klass),
9581 g_param_spec_ref_sink (pspec);
9582 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9583 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9587 * gtk_widget_class_install_style_property:
9588 * @klass: a #GtkWidgetClass
9589 * @pspec: the #GParamSpec for the property
9591 * Installs a style property on a widget class. The parser for the
9592 * style property is determined by the value type of @pspec.
9595 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9598 GtkRcPropertyParser parser;
9600 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9601 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9603 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9605 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9609 * gtk_widget_class_find_style_property:
9610 * @klass: a #GtkWidgetClass
9611 * @property_name: the name of the style property to find
9612 * @returns: the #GParamSpec of the style property or %NULL if @class has no
9613 * style property with that name.
9615 * Finds a style property of a widget class by name.
9620 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9621 const gchar *property_name)
9623 g_return_val_if_fail (property_name != NULL, NULL);
9625 return g_param_spec_pool_lookup (style_property_spec_pool,
9627 G_OBJECT_CLASS_TYPE (klass),
9632 * gtk_widget_class_list_style_properties:
9633 * @klass: a #GtkWidgetClass
9634 * @n_properties: location to return the number of style properties found
9635 * @returns: an newly allocated array of #GParamSpec*. The array must
9636 * be freed with g_free().
9638 * Returns all style properties of a widget class.
9643 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9644 guint *n_properties)
9646 GParamSpec **pspecs;
9649 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9650 G_OBJECT_CLASS_TYPE (klass),
9659 * gtk_widget_style_get_property:
9660 * @widget: a #GtkWidget
9661 * @property_name: the name of a style property
9662 * @value: location to return the property value
9664 * Gets the value of a style property of @widget.
9667 gtk_widget_style_get_property (GtkWidget *widget,
9668 const gchar *property_name,
9673 g_return_if_fail (GTK_IS_WIDGET (widget));
9674 g_return_if_fail (property_name != NULL);
9675 g_return_if_fail (G_IS_VALUE (value));
9677 g_object_ref (widget);
9678 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9680 G_OBJECT_TYPE (widget),
9683 g_warning ("%s: widget class `%s' has no property named `%s'",
9685 G_OBJECT_TYPE_NAME (widget),
9689 const GValue *peek_value;
9691 peek_value = _gtk_style_peek_property_value (widget->style,
9692 G_OBJECT_TYPE (widget),
9694 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9696 /* auto-conversion of the caller's value type
9698 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9699 g_value_copy (peek_value, value);
9700 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9701 g_value_transform (peek_value, value);
9703 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9705 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9706 G_VALUE_TYPE_NAME (value));
9708 g_object_unref (widget);
9712 * gtk_widget_style_get_valist:
9713 * @widget: a #GtkWidget
9714 * @first_property_name: the name of the first property to get
9715 * @var_args: a <type>va_list</type> of pairs of property names and
9716 * locations to return the property values, starting with the location
9717 * for @first_property_name.
9719 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9723 gtk_widget_style_get_valist (GtkWidget *widget,
9724 const gchar *first_property_name,
9729 g_return_if_fail (GTK_IS_WIDGET (widget));
9731 g_object_ref (widget);
9733 name = first_property_name;
9736 const GValue *peek_value;
9740 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9742 G_OBJECT_TYPE (widget),
9746 g_warning ("%s: widget class `%s' has no property named `%s'",
9748 G_OBJECT_TYPE_NAME (widget),
9752 /* style pspecs are always readable so we can spare that check here */
9754 peek_value = _gtk_style_peek_property_value (widget->style,
9755 G_OBJECT_TYPE (widget),
9757 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9758 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9761 g_warning ("%s: %s", G_STRLOC, error);
9766 name = va_arg (var_args, gchar*);
9769 g_object_unref (widget);
9773 * gtk_widget_style_get:
9774 * @widget: a #GtkWidget
9775 * @first_property_name: the name of the first property to get
9776 * @Varargs: pairs of property names and locations to
9777 * return the property values, starting with the location for
9778 * @first_property_name, terminated by %NULL.
9780 * Gets the values of a multiple style properties of @widget.
9783 gtk_widget_style_get (GtkWidget *widget,
9784 const gchar *first_property_name,
9789 g_return_if_fail (GTK_IS_WIDGET (widget));
9791 va_start (var_args, first_property_name);
9792 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9798 * @widget: a #GtkWidget
9799 * @path_length: location to store length of the path, or %NULL
9800 * @path: location to store allocated path string, or %NULL
9801 * @path_reversed: location to store allocated reverse path string, or %NULL
9803 * Obtains the full path to @widget. The path is simply the name of a
9804 * widget and all its parents in the container hierarchy, separated by
9805 * periods. The name of a widget comes from
9806 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9807 * in gtkrc configuration files. Widget names are the type of the
9808 * widget by default (e.g. "GtkButton") or can be set to an
9809 * application-specific value with gtk_widget_set_name(). By setting
9810 * the name of a widget, you allow users or theme authors to apply
9811 * styles to that specific widget in their gtkrc
9812 * file. @path_reversed_p fills in the path in reverse order,
9813 * i.e. starting with @widget's name instead of starting with the name
9814 * of @widget's outermost ancestor.
9817 gtk_widget_path (GtkWidget *widget,
9820 gchar **path_reversed)
9822 static gchar *rev_path = NULL;
9823 static guint tmp_path_len = 0;
9826 g_return_if_fail (GTK_IS_WIDGET (widget));
9831 const gchar *string;
9836 string = gtk_widget_get_name (widget);
9837 l = strlen (string);
9838 while (tmp_path_len <= len + l + 1)
9840 tmp_path_len += INIT_PATH_SIZE;
9841 rev_path = g_realloc (rev_path, tmp_path_len);
9849 widget = widget->parent;
9852 rev_path[len++] = '.';
9854 rev_path[len++] = 0;
9859 *path_length = len - 1;
9861 *path_reversed = g_strdup (rev_path);
9864 *path = g_strdup (rev_path);
9865 g_strreverse (*path);
9870 * gtk_widget_class_path:
9871 * @widget: a #GtkWidget
9872 * @path_length: location to store the length of the class path, or %NULL
9873 * @path: location to store the class path as an allocated string, or %NULL
9874 * @path_reversed: location to store the reverse class path as an allocated
9877 * Same as gtk_widget_path(), but always uses the name of a widget's type,
9878 * never uses a custom name set with gtk_widget_set_name().
9882 gtk_widget_class_path (GtkWidget *widget,
9885 gchar **path_reversed)
9887 static gchar *rev_path = NULL;
9888 static guint tmp_path_len = 0;
9891 g_return_if_fail (GTK_IS_WIDGET (widget));
9896 const gchar *string;
9901 string = g_type_name (GTK_WIDGET_TYPE (widget));
9902 l = strlen (string);
9903 while (tmp_path_len <= len + l + 1)
9905 tmp_path_len += INIT_PATH_SIZE;
9906 rev_path = g_realloc (rev_path, tmp_path_len);
9914 widget = widget->parent;
9917 rev_path[len++] = '.';
9919 rev_path[len++] = 0;
9924 *path_length = len - 1;
9926 *path_reversed = g_strdup (rev_path);
9929 *path = g_strdup (rev_path);
9930 g_strreverse (*path);
9935 * gtk_requisition_copy:
9936 * @requisition: a #GtkRequisition
9938 * Copies a #GtkRequisition.
9940 * Returns: a copy of @requisition
9943 gtk_requisition_copy (const GtkRequisition *requisition)
9945 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9949 * gtk_requisition_free:
9950 * @requisition: a #GtkRequisition
9952 * Frees a #GtkRequisition.
9955 gtk_requisition_free (GtkRequisition *requisition)
9957 g_free (requisition);
9961 gtk_requisition_get_type (void)
9963 static GType our_type = 0;
9966 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9967 (GBoxedCopyFunc) gtk_requisition_copy,
9968 (GBoxedFreeFunc) gtk_requisition_free);
9974 * gtk_widget_get_accessible:
9975 * @widget: a #GtkWidget
9977 * Returns the accessible object that describes the widget to an
9978 * assistive technology.
9980 * If no accessibility library is loaded (i.e. no ATK implementation library is
9981 * loaded via <envar>GTK_MODULES</envar> or via another application library,
9982 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
9983 * if no class-specific #AtkObject implementation is available for the widget
9984 * instance in question, it will inherit an #AtkObject implementation from the
9985 * first ancestor class for which such an implementation is defined.
9987 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9988 * library contains more information about accessible objects and their uses.
9990 * Returns: the #AtkObject associated with @widget
9993 gtk_widget_get_accessible (GtkWidget *widget)
9995 GtkWidgetClass *klass;
9997 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9999 klass = GTK_WIDGET_GET_CLASS (widget);
10001 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10003 return klass->get_accessible (widget);
10007 gtk_widget_real_get_accessible (GtkWidget *widget)
10009 AtkObject* accessible;
10011 accessible = g_object_get_qdata (G_OBJECT (widget),
10012 quark_accessible_object);
10015 AtkObjectFactory *factory;
10016 AtkRegistry *default_registry;
10018 default_registry = atk_get_default_registry ();
10019 factory = atk_registry_get_factory (default_registry,
10020 G_TYPE_FROM_INSTANCE (widget));
10022 atk_object_factory_create_accessible (factory,
10023 G_OBJECT (widget));
10024 g_object_set_qdata (G_OBJECT (widget),
10025 quark_accessible_object,
10032 * Initialize a AtkImplementorIface instance's virtual pointers as
10033 * appropriate to this implementor's class (GtkWidget).
10036 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10038 iface->ref_accessible = gtk_widget_ref_accessible;
10042 gtk_widget_ref_accessible (AtkImplementor *implementor)
10044 AtkObject *accessible;
10046 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10048 g_object_ref (accessible);
10053 * GtkBuildable implementation
10055 static GQuark quark_builder_has_default = 0;
10056 static GQuark quark_builder_has_focus = 0;
10057 static GQuark quark_builder_atk_relations = 0;
10058 static GQuark quark_builder_set_name = 0;
10061 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10063 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10064 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10065 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10066 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10068 iface->set_name = gtk_widget_buildable_set_name;
10069 iface->get_name = gtk_widget_buildable_get_name;
10070 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10071 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10072 iface->parser_finished = gtk_widget_buildable_parser_finished;
10073 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10074 iface->custom_finished = gtk_widget_buildable_custom_finished;
10078 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10081 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10082 g_strdup (name), g_free);
10085 static const gchar *
10086 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10088 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10092 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10093 GtkBuilder *builder,
10094 const gchar *childname)
10096 if (strcmp (childname, "accessible") == 0)
10097 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10103 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10104 GtkBuilder *builder,
10106 const GValue *value)
10108 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10109 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10110 GINT_TO_POINTER (TRUE));
10111 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10112 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10113 GINT_TO_POINTER (TRUE));
10115 g_object_set_property (G_OBJECT (buildable), name, value);
10120 gchar *action_name;
10121 GString *description;
10123 gboolean translatable;
10133 free_action (AtkActionData *data, gpointer user_data)
10135 g_free (data->action_name);
10136 g_string_free (data->description, TRUE);
10137 g_free (data->context);
10138 g_slice_free (AtkActionData, data);
10142 free_relation (AtkRelationData *data, gpointer user_data)
10144 g_free (data->target);
10145 g_free (data->type);
10146 g_slice_free (AtkRelationData, data);
10150 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10151 GtkBuilder *builder)
10153 GSList *atk_relations;
10155 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10156 gtk_widget_grab_default (GTK_WIDGET (buildable));
10157 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10158 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10160 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10161 quark_builder_atk_relations);
10164 AtkObject *accessible;
10165 AtkRelationSet *relation_set;
10168 AtkRelationType relation_type;
10169 AtkObject *target_accessible;
10171 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10172 relation_set = atk_object_ref_relation_set (accessible);
10174 for (l = atk_relations; l; l = l->next)
10176 AtkRelationData *relation = (AtkRelationData*)l->data;
10178 target = gtk_builder_get_object (builder, relation->target);
10181 g_warning ("Target object %s in <relation> does not exist",
10185 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10186 g_assert (target_accessible != NULL);
10188 relation_type = atk_relation_type_for_name (relation->type);
10189 if (relation_type == ATK_RELATION_NULL)
10191 g_warning ("<relation> type %s not found",
10195 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10196 target_accessible);
10198 g_object_unref (relation_set);
10200 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10201 g_slist_free (atk_relations);
10202 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10211 } AccessibilitySubParserData;
10214 accessibility_start_element (GMarkupParseContext *context,
10215 const gchar *element_name,
10216 const gchar **names,
10217 const gchar **values,
10218 gpointer user_data,
10221 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10223 gint line_number, char_number;
10225 if (strcmp (element_name, "relation") == 0)
10227 gchar *target = NULL;
10228 gchar *type = NULL;
10229 AtkRelationData *relation;
10231 for (i = 0; names[i]; i++)
10233 if (strcmp (names[i], "target") == 0)
10234 target = g_strdup (values[i]);
10235 else if (strcmp (names[i], "type") == 0)
10236 type = g_strdup (values[i]);
10239 g_markup_parse_context_get_position (context,
10242 g_set_error (error,
10244 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10245 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10247 line_number, char_number, names[i], "relation");
10254 if (!target || !type)
10256 g_markup_parse_context_get_position (context,
10259 g_set_error (error,
10261 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10262 "%s:%d:%d <%s> requires attribute \"%s\"",
10264 line_number, char_number, "relation",
10265 type ? "target" : "type");
10271 relation = g_slice_new (AtkRelationData);
10272 relation->target = target;
10273 relation->type = type;
10275 data->relations = g_slist_prepend (data->relations, relation);
10277 else if (strcmp (element_name, "action") == 0)
10279 const gchar *action_name = NULL;
10280 const gchar *description = NULL;
10281 const gchar *msg_context = NULL;
10282 gboolean translatable = FALSE;
10283 AtkActionData *action;
10285 for (i = 0; names[i]; i++)
10287 if (strcmp (names[i], "action_name") == 0)
10288 action_name = values[i];
10289 else if (strcmp (names[i], "description") == 0)
10290 description = values[i];
10291 else if (strcmp (names[i], "translatable") == 0)
10293 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10296 else if (strcmp (names[i], "comments") == 0)
10298 /* do nothing, comments are for translators */
10300 else if (strcmp (names[i], "context") == 0)
10301 msg_context = values[i];
10304 g_markup_parse_context_get_position (context,
10307 g_set_error (error,
10309 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10310 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10312 line_number, char_number, names[i], "action");
10319 g_markup_parse_context_get_position (context,
10322 g_set_error (error,
10324 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10325 "%s:%d:%d <%s> requires attribute \"%s\"",
10327 line_number, char_number, "action",
10332 action = g_slice_new (AtkActionData);
10333 action->action_name = g_strdup (action_name);
10334 action->description = g_string_new (description);
10335 action->context = g_strdup (msg_context);
10336 action->translatable = translatable;
10338 data->actions = g_slist_prepend (data->actions, action);
10340 else if (strcmp (element_name, "accessibility") == 0)
10343 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10347 accessibility_text (GMarkupParseContext *context,
10350 gpointer user_data,
10353 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10355 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10357 AtkActionData *action = data->actions->data;
10359 g_string_append_len (action->description, text, text_len);
10363 static const GMarkupParser accessibility_parser =
10365 accessibility_start_element,
10367 accessibility_text,
10376 } AccelGroupParserData;
10379 accel_group_start_element (GMarkupParseContext *context,
10380 const gchar *element_name,
10381 const gchar **names,
10382 const gchar **values,
10383 gpointer user_data,
10388 guint modifiers = 0;
10389 gchar *signal = NULL;
10390 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10392 for (i = 0; names[i]; i++)
10394 if (strcmp (names[i], "key") == 0)
10395 key = gdk_keyval_from_name (values[i]);
10396 else if (strcmp (names[i], "modifiers") == 0)
10398 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10404 else if (strcmp (names[i], "signal") == 0)
10405 signal = g_strdup (values[i]);
10408 if (key == 0 || signal == NULL)
10410 g_warning ("<accelerator> requires key and signal attributes");
10413 parser_data->key = key;
10414 parser_data->modifiers = modifiers;
10415 parser_data->signal = signal;
10418 static const GMarkupParser accel_group_parser =
10420 accel_group_start_element,
10424 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10425 GtkBuilder *builder,
10427 const gchar *tagname,
10428 GMarkupParser *parser,
10431 g_assert (buildable);
10433 if (strcmp (tagname, "accelerator") == 0)
10435 AccelGroupParserData *parser_data;
10437 parser_data = g_slice_new0 (AccelGroupParserData);
10438 parser_data->object = g_object_ref (buildable);
10439 *parser = accel_group_parser;
10440 *data = parser_data;
10443 if (strcmp (tagname, "accessibility") == 0)
10445 AccessibilitySubParserData *parser_data;
10447 parser_data = g_slice_new0 (AccessibilitySubParserData);
10448 *parser = accessibility_parser;
10449 *data = parser_data;
10456 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10457 GtkWidget *toplevel,
10458 gpointer user_data)
10460 AccelGroupParserData *accel_data;
10461 GSList *accel_groups;
10462 GtkAccelGroup *accel_group;
10464 g_return_if_fail (GTK_IS_WIDGET (widget));
10465 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10466 g_return_if_fail (user_data != NULL);
10468 accel_data = (AccelGroupParserData*)user_data;
10469 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10470 if (g_slist_length (accel_groups) == 0)
10472 accel_group = gtk_accel_group_new ();
10473 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10477 g_assert (g_slist_length (accel_groups) == 1);
10478 accel_group = g_slist_nth_data (accel_groups, 0);
10481 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10482 accel_data->signal,
10485 accel_data->modifiers,
10486 GTK_ACCEL_VISIBLE);
10488 g_object_unref (accel_data->object);
10489 g_free (accel_data->signal);
10490 g_slice_free (AccelGroupParserData, accel_data);
10494 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10495 GtkBuilder *builder,
10497 const gchar *tagname,
10498 gpointer user_data)
10500 AccelGroupParserData *accel_data;
10501 AccessibilitySubParserData *a11y_data;
10502 GtkWidget *toplevel;
10504 if (strcmp (tagname, "accelerator") == 0)
10506 accel_data = (AccelGroupParserData*)user_data;
10507 g_assert (accel_data->object);
10509 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10511 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10513 else if (strcmp (tagname, "accessibility") == 0)
10515 a11y_data = (AccessibilitySubParserData*)user_data;
10517 if (a11y_data->actions)
10519 AtkObject *accessible;
10524 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10526 action = ATK_ACTION (accessible);
10527 n_actions = atk_action_get_n_actions (action);
10529 for (l = a11y_data->actions; l; l = l->next)
10531 AtkActionData *action_data = (AtkActionData*)l->data;
10533 for (i = 0; i < n_actions; i++)
10534 if (strcmp (atk_action_get_name (action, i),
10535 action_data->action_name) == 0)
10540 gchar *description;
10542 if (action_data->translatable && action_data->description->len)
10543 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10544 action_data->context,
10545 action_data->description->str);
10547 description = action_data->description->str;
10549 atk_action_set_description (action, i, description);
10553 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10554 g_slist_free (a11y_data->actions);
10557 if (a11y_data->relations)
10558 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10559 a11y_data->relations);
10561 g_slice_free (AccessibilitySubParserData, a11y_data);
10567 * gtk_widget_get_clipboard:
10568 * @widget: a #GtkWidget
10569 * @selection: a #GdkAtom which identifies the clipboard
10570 * to use. %GDK_SELECTION_CLIPBOARD gives the
10571 * default clipboard. Another common value
10572 * is %GDK_SELECTION_PRIMARY, which gives
10573 * the primary X selection.
10575 * Returns the clipboard object for the given selection to
10576 * be used with @widget. @widget must have a #GdkDisplay
10577 * associated with it, so must be attached to a toplevel
10580 * Return value: the appropriate clipboard object. If no
10581 * clipboard already exists, a new one will
10582 * be created. Once a clipboard object has
10583 * been created, it is persistent for all time.
10588 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10590 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10591 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10593 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10598 * gtk_widget_list_mnemonic_labels:
10599 * @widget: a #GtkWidget
10601 * Returns a newly allocated list of the widgets, normally labels, for
10602 * which this widget is a the target of a mnemonic (see for example,
10603 * gtk_label_set_mnemonic_widget()).
10605 * The widgets in the list are not individually referenced. If you
10606 * want to iterate through the list and perform actions involving
10607 * callbacks that might destroy the widgets, you
10608 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10609 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10610 * widgets afterwards.
10612 * Return value: the list of mnemonic labels; free this list
10613 * with g_list_free() when you are done with it.
10618 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10620 GList *list = NULL;
10623 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10625 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10626 list = g_list_prepend (list, l->data);
10632 * gtk_widget_add_mnemonic_label:
10633 * @widget: a #GtkWidget
10634 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10636 * Adds a widget to the list of mnemonic labels for
10637 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10638 * list of mnemonic labels for the widget is cleared when the
10639 * widget is destroyed, so the caller must make sure to update
10640 * its internal state at this point as well, by using a connection
10641 * to the #GtkWidget::destroy signal or a weak notifier.
10646 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10649 GSList *old_list, *new_list;
10651 g_return_if_fail (GTK_IS_WIDGET (widget));
10652 g_return_if_fail (GTK_IS_WIDGET (label));
10654 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10655 new_list = g_slist_prepend (old_list, label);
10657 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10658 new_list, (GDestroyNotify) g_slist_free);
10662 * gtk_widget_remove_mnemonic_label:
10663 * @widget: a #GtkWidget
10664 * @label: a #GtkWidget that was previously set as a mnemnic label for
10665 * @widget with gtk_widget_add_mnemonic_label().
10667 * Removes a widget from the list of mnemonic labels for
10668 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10669 * must have previously been added to the list with
10670 * gtk_widget_add_mnemonic_label().
10675 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10678 GSList *old_list, *new_list;
10680 g_return_if_fail (GTK_IS_WIDGET (widget));
10681 g_return_if_fail (GTK_IS_WIDGET (label));
10683 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10684 new_list = g_slist_remove (old_list, label);
10687 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10688 new_list, (GDestroyNotify) g_slist_free);
10692 * gtk_widget_get_no_show_all:
10693 * @widget: a #GtkWidget
10695 * Returns the current value of the GtkWidget:no-show-all property,
10696 * which determines whether calls to gtk_widget_show_all() and
10697 * gtk_widget_hide_all() will affect this widget.
10699 * Return value: the current value of the "no-show-all" property.
10704 gtk_widget_get_no_show_all (GtkWidget *widget)
10706 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10708 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10712 * gtk_widget_set_no_show_all:
10713 * @widget: a #GtkWidget
10714 * @no_show_all: the new value for the "no-show-all" property
10716 * Sets the #GtkWidget:no-show-all property, which determines whether
10717 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10720 * This is mostly for use in constructing widget hierarchies with externally
10721 * controlled visibility, see #GtkUIManager.
10726 gtk_widget_set_no_show_all (GtkWidget *widget,
10727 gboolean no_show_all)
10729 g_return_if_fail (GTK_IS_WIDGET (widget));
10731 no_show_all = (no_show_all != FALSE);
10733 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10737 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10739 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10741 g_object_notify (G_OBJECT (widget), "no-show-all");
10746 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10747 gboolean has_tooltip,
10750 gboolean priv_has_tooltip;
10752 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10753 quark_has_tooltip));
10755 if (priv_has_tooltip != has_tooltip || force)
10757 priv_has_tooltip = has_tooltip;
10759 if (priv_has_tooltip)
10761 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
10762 gdk_window_set_events (widget->window,
10763 gdk_window_get_events (widget->window) |
10764 GDK_LEAVE_NOTIFY_MASK |
10765 GDK_POINTER_MOTION_MASK |
10766 GDK_POINTER_MOTION_HINT_MASK);
10768 if (!GTK_WIDGET_NO_WINDOW (widget))
10769 gtk_widget_add_events (widget,
10770 GDK_LEAVE_NOTIFY_MASK |
10771 GDK_POINTER_MOTION_MASK |
10772 GDK_POINTER_MOTION_HINT_MASK);
10775 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10776 GUINT_TO_POINTER (priv_has_tooltip));
10781 * gtk_widget_set_tooltip_window:
10782 * @widget: a #GtkWidget
10783 * @custom_window: a #GtkWindow, or %NULL
10785 * Replaces the default, usually yellow, window used for displaying
10786 * tooltips with @custom_window. GTK+ will take care of showing and
10787 * hiding @custom_window at the right moment, to behave likewise as
10788 * the default tooltip window. If @custom_window is %NULL, the default
10789 * tooltip window will be used.
10791 * If the custom window should have the default theming it needs to
10792 * have the name "gtk-tooltip", see gtk_widget_set_name().
10797 gtk_widget_set_tooltip_window (GtkWidget *widget,
10798 GtkWindow *custom_window)
10800 gboolean has_tooltip;
10801 gchar *tooltip_markup;
10803 g_return_if_fail (GTK_IS_WIDGET (widget));
10804 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10806 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10809 g_object_ref (custom_window);
10811 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10812 custom_window, g_object_unref);
10814 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10815 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10817 if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10818 gtk_widget_queue_tooltip_query (widget);
10822 * gtk_widget_get_tooltip_window:
10823 * @widget: a #GtkWidget
10825 * Returns the #GtkWindow of the current tooltip. This can be the
10826 * GtkWindow created by default, or the custom tooltip window set
10827 * using gtk_widget_set_tooltip_window().
10829 * Return value: The #GtkWindow of the current tooltip.
10834 gtk_widget_get_tooltip_window (GtkWidget *widget)
10836 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10838 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10842 * gtk_widget_trigger_tooltip_query:
10843 * @widget: a #GtkWidget
10845 * Triggers a tooltip query on the display where the toplevel of @widget
10846 * is located. See gtk_tooltip_trigger_tooltip_query() for more
10852 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10854 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10857 static guint tooltip_query_id;
10858 static GSList *tooltip_query_displays;
10861 tooltip_query_idle (gpointer data)
10863 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
10864 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
10865 g_slist_free (tooltip_query_displays);
10867 tooltip_query_displays = NULL;
10868 tooltip_query_id = 0;
10874 gtk_widget_queue_tooltip_query (GtkWidget *widget)
10876 GdkDisplay *display;
10878 display = gtk_widget_get_display (widget);
10880 if (!g_slist_find (tooltip_query_displays, display))
10881 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
10883 if (tooltip_query_id == 0)
10884 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
10888 * gtk_widget_set_tooltip_text:
10889 * @widget: a #GtkWidget
10890 * @text: the contents of the tooltip for @widget
10892 * Sets @text as the contents of the tooltip. This function will take
10893 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10894 * handler for the GtkWidget::query-tooltip signal.
10896 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10901 gtk_widget_set_tooltip_text (GtkWidget *widget,
10904 g_return_if_fail (GTK_IS_WIDGET (widget));
10906 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10910 * gtk_widget_get_tooltip_text:
10911 * @widget: a #GtkWidget
10913 * Gets the contents of the tooltip for @widget.
10915 * Return value: the tooltip text, or %NULL. You should free the
10916 * returned string with g_free() when done.
10921 gtk_widget_get_tooltip_text (GtkWidget *widget)
10923 gchar *text = NULL;
10925 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10927 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10933 * gtk_widget_set_tooltip_markup:
10934 * @widget: a #GtkWidget
10935 * @markup: the contents of the tooltip for @widget, or %NULL
10937 * Sets @markup as the contents of the tooltip, which is marked up with
10938 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10940 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10941 * and of the default handler for the GtkWidget::query-tooltip signal.
10943 * See also the GtkWidget:tooltip-markup property and
10944 * gtk_tooltip_set_markup().
10949 gtk_widget_set_tooltip_markup (GtkWidget *widget,
10950 const gchar *markup)
10952 g_return_if_fail (GTK_IS_WIDGET (widget));
10954 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10958 * gtk_widget_get_tooltip_markup:
10959 * @widget: a #GtkWidget
10961 * Gets the contents of the tooltip for @widget.
10963 * Return value: the tooltip text, or %NULL. You should free the
10964 * returned string with g_free() when done.
10969 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10971 gchar *text = NULL;
10973 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10975 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10981 * gtk_widget_set_has_tooltip:
10982 * @widget: a #GtkWidget
10983 * @has_tooltip: whether or not @widget has a tooltip.
10985 * Sets the has-tooltip property on @widget to @has_tooltip. See
10986 * GtkWidget:has-tooltip for more information.
10991 gtk_widget_set_has_tooltip (GtkWidget *widget,
10992 gboolean has_tooltip)
10994 g_return_if_fail (GTK_IS_WIDGET (widget));
10996 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11000 * gtk_widget_get_has_tooltip:
11001 * @widget: a #GtkWidget
11003 * Returns the current value of the has-tooltip property. See
11004 * GtkWidget:has-tooltip for more information.
11006 * Return value: current value of has-tooltip on @widget.
11011 gtk_widget_get_has_tooltip (GtkWidget *widget)
11013 gboolean has_tooltip = FALSE;
11015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11017 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11019 return has_tooltip;
11023 * gtk_widget_get_allocation:
11024 * @widget: a #GtkWidget
11025 * @allocation: a pointer to a #GtkAllocation to copy to
11027 * Retrieves the widget's allocation.
11032 gtk_widget_get_allocation (GtkWidget *widget,
11033 GtkAllocation *allocation)
11035 g_return_if_fail (GTK_IS_WIDGET (widget));
11036 g_return_if_fail (allocation != NULL);
11038 *allocation = widget->allocation;
11042 * gtk_widget_set_allocation:
11043 * @widget: a #GtkWidget
11044 * @allocation: a pointer to a #GtkAllocation to copy from
11046 * Sets the widget's allocation. This should not be used
11047 * directly, but from within a widget's size_allocate method.
11052 gtk_widget_set_allocation (GtkWidget *widget,
11053 const GtkAllocation *allocation)
11055 g_return_if_fail (GTK_IS_WIDGET (widget));
11056 g_return_if_fail (allocation != NULL);
11058 widget->allocation = *allocation;
11062 * gtk_widget_set_window:
11063 * @widget: a #GtkWidget
11064 * @window: a #GdkWindow
11066 * Sets a widget's window. This function should only be used in a
11067 * widget's GtkWidget::realize() implementation. The %window passed is
11068 * usually either new window created with gdk_window_new(), or the
11069 * window of its parent widget as returned by
11070 * gtk_widget_get_parent_window().
11072 * Widgets must indicate whether they will create their own #GdkWindow
11073 * by calling gtk_widget_set_has_window(). This is usually done in the
11074 * widget's init() function.
11079 gtk_widget_set_window (GtkWidget *widget,
11082 g_return_if_fail (GTK_IS_WIDGET (widget));
11083 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11085 if (widget->window != window)
11087 widget->window = window;
11088 g_object_notify (G_OBJECT (widget), "window");
11093 * gtk_widget_get_window:
11094 * @widget: a #GtkWidget
11096 * Returns the widget's window if it is realized, %NULL otherwise
11098 * Return value: @widget's window.
11103 gtk_widget_get_window (GtkWidget *widget)
11105 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11107 return widget->window;
11110 #define __GTK_WIDGET_C__
11111 #include "gtkaliasdef.c"