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.
66 * <refsect2 id="style-properties">
68 * <structname>GtkWidget</structname> introduces <firstterm>style
69 * properties</firstterm> - these are basically object properties that are stored
70 * not on the object, but in the style object associated to the widget. Style
71 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
72 * This mechanism is used for configuring such things as the location of the
73 * scrollbar arrows through the theme, giving theme authors more control over the
74 * look of applications without the need to write a theme engine in C.
77 * Use gtk_widget_class_install_style_property() to install style properties for
78 * a widget class, gtk_widget_class_find_style_property() or
79 * gtk_widget_class_list_style_properties() to get information about existing
80 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
81 * gtk_widget_style_get_valist() to obtain the value of a style property.
84 * <refsect2 id="GtkWidget-BUILDER-UI">
85 * <title>GtkWidget as GtkBuildable</title>
87 * The GtkWidget implementation of the GtkBuildable interface supports a
88 * custom <accelerator> element, which has attributes named key,
89 * modifiers and signal and allows to specify accelerators.
92 * <title>A UI definition fragment specifying an accelerator</title>
93 * <programlisting><![CDATA[
94 * <object class="GtkButton">
95 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
97 * ]]></programlisting>
100 * In addition to accelerators, <structname>GtkWidget</structname> also support a
101 * custom <accessible> element, which supports actions and relations.
102 * Properties on the accessible implementation of an object can be set by accessing the
103 * internal child "accessible" of a <structname>GtkWidget</structname>.
106 * <title>A UI definition fragment specifying an accessible</title>
107 * <programlisting><![CDATA[
108 * <object class="GtkButton" id="label1"/>
109 * <property name="label">I am a Label for a Button</property>
111 * <object class="GtkButton" id="button1">
113 * <action action_name="click" translatable="yes">Click the button.</action>
114 * <relation target="label1" type="labelled-by"/>
116 * <child internal-child="accessible">
117 * <object class="AtkObject" id="a11y-button1">
118 * <property name="AtkObject::name">Clickable Button</property>
122 * ]]></programlisting>
127 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
128 #define INIT_PATH_SIZE (512)
154 BUTTON_RELEASE_EVENT,
169 PROPERTY_NOTIFY_EVENT,
170 SELECTION_CLEAR_EVENT,
171 SELECTION_REQUEST_EVENT,
172 SELECTION_NOTIFY_EVENT,
187 VISIBILITY_NOTIFY_EVENT,
191 ACCEL_CLOSURES_CHANGED,
217 PROP_RECEIVES_DEFAULT,
218 PROP_COMPOSITE_CHILD,
221 PROP_EXTENSION_EVENTS,
230 typedef struct _GtkStateData GtkStateData;
235 guint state_restoration : 1;
236 guint parent_sensitive : 1;
237 guint use_forall : 1;
240 /* --- prototypes --- */
241 static void gtk_widget_class_init (GtkWidgetClass *klass);
242 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
243 static void gtk_widget_init (GtkWidget *widget);
244 static void gtk_widget_set_property (GObject *object,
248 static void gtk_widget_get_property (GObject *object,
252 static void gtk_widget_dispose (GObject *object);
253 static void gtk_widget_real_destroy (GtkObject *object);
254 static void gtk_widget_finalize (GObject *object);
255 static void gtk_widget_real_show (GtkWidget *widget);
256 static void gtk_widget_real_hide (GtkWidget *widget);
257 static void gtk_widget_real_map (GtkWidget *widget);
258 static void gtk_widget_real_unmap (GtkWidget *widget);
259 static void gtk_widget_real_realize (GtkWidget *widget);
260 static void gtk_widget_real_unrealize (GtkWidget *widget);
261 static void gtk_widget_real_size_request (GtkWidget *widget,
262 GtkRequisition *requisition);
263 static void gtk_widget_real_size_allocate (GtkWidget *widget,
264 GtkAllocation *allocation);
265 static void gtk_widget_real_style_set (GtkWidget *widget,
266 GtkStyle *previous_style);
267 static void gtk_widget_real_direction_changed(GtkWidget *widget,
268 GtkTextDirection previous_direction);
270 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
271 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
274 gboolean keyboard_tip,
275 GtkTooltip *tooltip);
276 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
277 GtkWidgetHelpType help_type);
279 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
281 GParamSpec **pspecs);
282 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
284 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
286 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
287 GdkEventFocus *event);
288 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
289 GdkEventFocus *event);
290 static gboolean gtk_widget_real_focus (GtkWidget *widget,
291 GtkDirectionType direction);
292 static void gtk_widget_real_move_focus (GtkWidget *widget,
293 GtkDirectionType direction);
294 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
295 GtkDirectionType direction);
296 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
297 static void gtk_widget_update_pango_context (GtkWidget *widget);
298 static void gtk_widget_propagate_state (GtkWidget *widget,
300 static void gtk_widget_reset_rc_style (GtkWidget *widget);
301 static void gtk_widget_set_style_internal (GtkWidget *widget,
303 gboolean initial_emission);
304 static gint gtk_widget_event_internal (GtkWidget *widget,
306 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
307 gboolean group_cycling);
308 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
309 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
310 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
311 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
312 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
314 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
315 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
316 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
319 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
320 gboolean has_tooltip,
322 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
323 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
325 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
326 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
328 const gchar *childname);
329 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
332 const GValue *value);
333 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
336 const gchar *tagname,
337 GMarkupParser *parser,
339 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
342 const gchar *tagname,
344 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
345 GtkBuilder *builder);
347 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
349 static void gtk_widget_set_usize_internal (GtkWidget *widget,
352 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
356 /* --- variables --- */
357 static gpointer gtk_widget_parent_class = NULL;
358 static guint widget_signals[LAST_SIGNAL] = { 0 };
359 static GtkStyle *gtk_default_style = NULL;
360 static GSList *colormap_stack = NULL;
361 static guint composite_child_stack = 0;
362 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
363 static GParamSpecPool *style_property_spec_pool = NULL;
365 static GQuark quark_property_parser = 0;
366 static GQuark quark_aux_info = 0;
367 static GQuark quark_accel_path = 0;
368 static GQuark quark_accel_closures = 0;
369 static GQuark quark_event_mask = 0;
370 static GQuark quark_extension_event_mode = 0;
371 static GQuark quark_parent_window = 0;
372 static GQuark quark_pointer_window = 0;
373 static GQuark quark_shape_info = 0;
374 static GQuark quark_input_shape_info = 0;
375 static GQuark quark_colormap = 0;
376 static GQuark quark_pango_context = 0;
377 static GQuark quark_rc_style = 0;
378 static GQuark quark_accessible_object = 0;
379 static GQuark quark_mnemonic_labels = 0;
380 static GQuark quark_tooltip_markup = 0;
381 static GQuark quark_has_tooltip = 0;
382 static GQuark quark_tooltip_window = 0;
383 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
384 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
386 /* --- functions --- */
388 gtk_widget_get_type (void)
390 static GType widget_type = 0;
392 if (G_UNLIKELY (widget_type == 0))
394 const GTypeInfo widget_info =
396 sizeof (GtkWidgetClass),
397 NULL, /* base_init */
398 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
399 (GClassInitFunc) gtk_widget_class_init,
400 NULL, /* class_finalize */
401 NULL, /* class_init */
404 (GInstanceInitFunc) gtk_widget_init,
405 NULL, /* value_table */
408 const GInterfaceInfo accessibility_info =
410 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
411 (GInterfaceFinalizeFunc) NULL,
412 NULL /* interface data */
415 const GInterfaceInfo buildable_info =
417 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
418 (GInterfaceFinalizeFunc) NULL,
419 NULL /* interface data */
422 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
423 &widget_info, G_TYPE_FLAG_ABSTRACT);
425 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
426 &accessibility_info) ;
427 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
436 child_property_notify_dispatcher (GObject *object,
440 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
444 gtk_widget_class_init (GtkWidgetClass *klass)
446 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
447 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
448 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
449 GtkBindingSet *binding_set;
451 gtk_widget_parent_class = g_type_class_peek_parent (klass);
453 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
454 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
455 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
456 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
457 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
458 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
459 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
460 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
461 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
462 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
463 quark_colormap = g_quark_from_static_string ("gtk-colormap");
464 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
465 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
466 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
467 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
468 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
469 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
470 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
472 style_property_spec_pool = g_param_spec_pool_new (FALSE);
473 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
474 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
475 cpn_context.dispatcher = child_property_notify_dispatcher;
476 _gtk_widget_child_property_notify_context = &cpn_context;
478 gobject_class->dispose = gtk_widget_dispose;
479 gobject_class->finalize = gtk_widget_finalize;
480 gobject_class->set_property = gtk_widget_set_property;
481 gobject_class->get_property = gtk_widget_get_property;
483 object_class->destroy = gtk_widget_real_destroy;
485 klass->activate_signal = 0;
486 klass->set_scroll_adjustments_signal = 0;
487 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
488 klass->show = gtk_widget_real_show;
489 klass->show_all = gtk_widget_show;
490 klass->hide = gtk_widget_real_hide;
491 klass->hide_all = gtk_widget_hide;
492 klass->map = gtk_widget_real_map;
493 klass->unmap = gtk_widget_real_unmap;
494 klass->realize = gtk_widget_real_realize;
495 klass->unrealize = gtk_widget_real_unrealize;
496 klass->size_request = gtk_widget_real_size_request;
497 klass->size_allocate = gtk_widget_real_size_allocate;
498 klass->state_changed = NULL;
499 klass->parent_set = NULL;
500 klass->hierarchy_changed = NULL;
501 klass->style_set = gtk_widget_real_style_set;
502 klass->direction_changed = gtk_widget_real_direction_changed;
503 klass->grab_notify = NULL;
504 klass->child_notify = NULL;
505 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
506 klass->grab_focus = gtk_widget_real_grab_focus;
507 klass->focus = gtk_widget_real_focus;
509 klass->button_press_event = NULL;
510 klass->button_release_event = NULL;
511 klass->motion_notify_event = NULL;
512 klass->delete_event = NULL;
513 klass->destroy_event = NULL;
514 klass->expose_event = NULL;
515 klass->key_press_event = gtk_widget_real_key_press_event;
516 klass->key_release_event = gtk_widget_real_key_release_event;
517 klass->enter_notify_event = NULL;
518 klass->leave_notify_event = NULL;
519 klass->configure_event = NULL;
520 klass->focus_in_event = gtk_widget_real_focus_in_event;
521 klass->focus_out_event = gtk_widget_real_focus_out_event;
522 klass->map_event = NULL;
523 klass->unmap_event = NULL;
524 klass->window_state_event = NULL;
525 klass->property_notify_event = _gtk_selection_property_notify;
526 klass->selection_clear_event = gtk_selection_clear;
527 klass->selection_request_event = _gtk_selection_request;
528 klass->selection_notify_event = _gtk_selection_notify;
529 klass->selection_received = NULL;
530 klass->proximity_in_event = NULL;
531 klass->proximity_out_event = NULL;
532 klass->drag_begin = NULL;
533 klass->drag_end = NULL;
534 klass->drag_data_delete = NULL;
535 klass->drag_leave = NULL;
536 klass->drag_motion = NULL;
537 klass->drag_drop = NULL;
538 klass->drag_data_received = NULL;
539 klass->screen_changed = NULL;
540 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
541 klass->grab_broken_event = NULL;
542 klass->query_tooltip = gtk_widget_real_query_tooltip;
544 klass->show_help = gtk_widget_real_show_help;
546 /* Accessibility support */
547 klass->get_accessible = gtk_widget_real_get_accessible;
549 klass->no_expose_event = NULL;
551 g_object_class_install_property (gobject_class,
553 g_param_spec_string ("name",
555 P_("The name of the widget"),
557 GTK_PARAM_READWRITE));
558 g_object_class_install_property (gobject_class,
560 g_param_spec_object ("parent",
562 P_("The parent widget of this widget. Must be a Container widget"),
564 GTK_PARAM_READWRITE));
566 g_object_class_install_property (gobject_class,
568 g_param_spec_int ("width-request",
570 P_("Override for width request of the widget, or -1 if natural request should be used"),
574 GTK_PARAM_READWRITE));
575 g_object_class_install_property (gobject_class,
577 g_param_spec_int ("height-request",
578 P_("Height request"),
579 P_("Override for height request of the widget, or -1 if natural request should be used"),
583 GTK_PARAM_READWRITE));
584 g_object_class_install_property (gobject_class,
586 g_param_spec_boolean ("visible",
588 P_("Whether the widget is visible"),
590 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_boolean ("sensitive",
595 P_("Whether the widget responds to input"),
597 GTK_PARAM_READWRITE));
598 g_object_class_install_property (gobject_class,
600 g_param_spec_boolean ("app-paintable",
601 P_("Application paintable"),
602 P_("Whether the application will paint directly on the widget"),
604 GTK_PARAM_READWRITE));
605 g_object_class_install_property (gobject_class,
607 g_param_spec_boolean ("can-focus",
609 P_("Whether the widget can accept the input focus"),
611 GTK_PARAM_READWRITE));
612 g_object_class_install_property (gobject_class,
614 g_param_spec_boolean ("has-focus",
616 P_("Whether the widget has the input focus"),
618 GTK_PARAM_READWRITE));
619 g_object_class_install_property (gobject_class,
621 g_param_spec_boolean ("is-focus",
623 P_("Whether the widget is the focus widget within the toplevel"),
625 GTK_PARAM_READWRITE));
626 g_object_class_install_property (gobject_class,
628 g_param_spec_boolean ("can-default",
630 P_("Whether the widget can be the default widget"),
632 GTK_PARAM_READWRITE));
633 g_object_class_install_property (gobject_class,
635 g_param_spec_boolean ("has-default",
637 P_("Whether the widget is the default widget"),
639 GTK_PARAM_READWRITE));
640 g_object_class_install_property (gobject_class,
641 PROP_RECEIVES_DEFAULT,
642 g_param_spec_boolean ("receives-default",
643 P_("Receives default"),
644 P_("If TRUE, the widget will receive the default action when it is focused"),
646 GTK_PARAM_READWRITE));
647 g_object_class_install_property (gobject_class,
648 PROP_COMPOSITE_CHILD,
649 g_param_spec_boolean ("composite-child",
650 P_("Composite child"),
651 P_("Whether the widget is part of a composite widget"),
653 GTK_PARAM_READABLE));
654 g_object_class_install_property (gobject_class,
656 g_param_spec_object ("style",
658 P_("The style of the widget, which contains information about how it will look (colors etc)"),
660 GTK_PARAM_READWRITE));
661 g_object_class_install_property (gobject_class,
663 g_param_spec_flags ("events",
665 P_("The event mask that decides what kind of GdkEvents this widget gets"),
668 GTK_PARAM_READWRITE));
669 g_object_class_install_property (gobject_class,
670 PROP_EXTENSION_EVENTS,
671 g_param_spec_enum ("extension-events",
672 P_("Extension events"),
673 P_("The mask that decides what kind of extension events this widget gets"),
674 GDK_TYPE_EXTENSION_MODE,
675 GDK_EXTENSION_EVENTS_NONE,
676 GTK_PARAM_READWRITE));
677 g_object_class_install_property (gobject_class,
679 g_param_spec_boolean ("no-show-all",
681 P_("Whether gtk_widget_show_all() should not affect this widget"),
683 GTK_PARAM_READWRITE));
686 * GtkWidget:has-tooltip:
688 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
689 * A value of %TRUE indicates that @widget can have a tooltip, in this case
690 * the widget will be queried using #GtkWidget::query-tooltip to determine
691 * whether it will provide a tooltip or not.
693 * Note that setting this property to %TRUE for the first time will change
694 * the event masks of the GdkWindows of this widget to include leave-notify
695 * and motion-notify events. This cannot and will not be undone when the
696 * property is set to %FALSE again.
700 g_object_class_install_property (gobject_class,
702 g_param_spec_boolean ("has-tooltip",
704 P_("Whether this widget has a tooltip"),
706 GTK_PARAM_READWRITE));
708 * GtkWidget:tooltip-text:
710 * Sets the text of tooltip to be the given string.
712 * Also see gtk_tooltip_set_text().
714 * This is a convenience property which will take care of getting the
715 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
716 * will automatically be set to %TRUE and there will be taken care of
717 * #GtkWidget::query-tooltip in the default signal handler.
721 g_object_class_install_property (gobject_class,
723 g_param_spec_string ("tooltip-text",
725 P_("The contents of the tooltip for this widget"),
727 GTK_PARAM_READWRITE));
729 * GtkWidget:tooltip-markup:
731 * Sets the text of tooltip to be the given string, which is marked up
732 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
733 * Also see gtk_tooltip_set_markup().
735 * This is a convenience property which will take care of getting the
736 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
737 * will automatically be set to %TRUE and there will be taken care of
738 * #GtkWidget::query-tooltip in the default signal handler.
742 g_object_class_install_property (gobject_class,
744 g_param_spec_string ("tooltip-markup",
745 P_("Tooltip markup"),
746 P_("The contents of the tooltip for this widget"),
748 GTK_PARAM_READWRITE));
753 * The widget's window if it is realized, %NULL otherwise.
757 g_object_class_install_property (gobject_class,
759 g_param_spec_object ("window",
761 P_("The widget's window if it is realized"),
763 GTK_PARAM_READABLE));
766 * GtkWidget:double-buffered
768 * Whether or not the widget is double buffered.
772 g_object_class_install_property (gobject_class,
773 PROP_DOUBLE_BUFFERED,
774 g_param_spec_boolean ("double-buffered",
775 P_("Double Buffered"),
776 P_("Whether or not the widget is double buffered"),
778 GTK_PARAM_READWRITE));
782 * @widget: the object which received the signal.
784 widget_signals[SHOW] =
785 g_signal_new (I_("show"),
786 G_TYPE_FROM_CLASS (gobject_class),
788 G_STRUCT_OFFSET (GtkWidgetClass, show),
790 _gtk_marshal_VOID__VOID,
795 * @widget: the object which received the signal.
797 widget_signals[HIDE] =
798 g_signal_new (I_("hide"),
799 G_TYPE_FROM_CLASS (gobject_class),
801 G_STRUCT_OFFSET (GtkWidgetClass, hide),
803 _gtk_marshal_VOID__VOID,
808 * @widget: the object which received the signal.
810 widget_signals[MAP] =
811 g_signal_new (I_("map"),
812 G_TYPE_FROM_CLASS (gobject_class),
814 G_STRUCT_OFFSET (GtkWidgetClass, map),
816 _gtk_marshal_VOID__VOID,
821 * @widget: the object which received the signal.
823 widget_signals[UNMAP] =
824 g_signal_new (I_("unmap"),
825 G_TYPE_FROM_CLASS (gobject_class),
827 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
829 _gtk_marshal_VOID__VOID,
833 * GtkWidget::realize:
834 * @widget: the object which received the signal.
836 widget_signals[REALIZE] =
837 g_signal_new (I_("realize"),
838 G_TYPE_FROM_CLASS (gobject_class),
840 G_STRUCT_OFFSET (GtkWidgetClass, realize),
842 _gtk_marshal_VOID__VOID,
846 * GtkWidget::unrealize:
847 * @widget: the object which received the signal.
849 widget_signals[UNREALIZE] =
850 g_signal_new (I_("unrealize"),
851 G_TYPE_FROM_CLASS (gobject_class),
853 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
855 _gtk_marshal_VOID__VOID,
859 * GtkWidget::size-request:
860 * @widget: the object which received the signal.
863 widget_signals[SIZE_REQUEST] =
864 g_signal_new (I_("size-request"),
865 G_TYPE_FROM_CLASS (gobject_class),
867 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
869 _gtk_marshal_VOID__BOXED,
871 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
874 * GtkWidget::size-allocate:
875 * @widget: the object which received the signal.
878 widget_signals[SIZE_ALLOCATE] =
879 g_signal_new (I_("size-allocate"),
880 G_TYPE_FROM_CLASS (gobject_class),
882 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
884 _gtk_marshal_VOID__BOXED,
886 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
889 * GtkWidget::state-changed:
890 * @widget: the object which received the signal.
891 * @state: the previous state
893 * The ::state-changed signal is emitted when the widget state changes.
894 * See gtk_widget_get_state().
896 widget_signals[STATE_CHANGED] =
897 g_signal_new (I_("state-changed"),
898 G_TYPE_FROM_CLASS (gobject_class),
900 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
902 _gtk_marshal_VOID__ENUM,
904 GTK_TYPE_STATE_TYPE);
907 * GtkWidget::parent-set:
908 * @widget: the object on which the signal is emitted
909 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
910 * just got its initial parent.
912 * The ::parent-set signal is emitted when a new parent
913 * has been set on a widget.
915 widget_signals[PARENT_SET] =
916 g_signal_new (I_("parent-set"),
917 G_TYPE_FROM_CLASS (gobject_class),
919 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
921 _gtk_marshal_VOID__OBJECT,
926 * GtkWidget::hierarchy-changed:
927 * @widget: the object on which the signal is emitted
928 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
929 * if the widget was previously unanchored
931 * The ::hierarchy-changed signal is emitted when the
932 * anchored state of a widget changes. A widget is
933 * <firstterm>anchored</firstterm> when its toplevel
934 * ancestor is a #GtkWindow. This signal is emitted when
935 * a widget changes from un-anchored to anchored or vice-versa.
937 widget_signals[HIERARCHY_CHANGED] =
938 g_signal_new (I_("hierarchy-changed"),
939 G_TYPE_FROM_CLASS (gobject_class),
941 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
943 _gtk_marshal_VOID__OBJECT,
948 * GtkWidget::style-set:
949 * @widget: the object on which the signal is emitted
950 * @previous_style: (allow-none): the previous style, or %NULL if the widget
951 * just got its initial style
953 * The ::style-set signal is emitted when a new style has been set
954 * on a widget. Note that style-modifying functions like
955 * gtk_widget_modify_base() also cause this signal to be emitted.
957 widget_signals[STYLE_SET] =
958 g_signal_new (I_("style-set"),
959 G_TYPE_FROM_CLASS (gobject_class),
961 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
963 _gtk_marshal_VOID__OBJECT,
967 * GtkWidget::direction-changed:
968 * @widget: the object on which the signal is emitted
969 * @previous_direction: the previous text direction of @widget
971 * The ::direction-changed signal is emitted when the text direction
972 * of a widget changes.
974 widget_signals[DIRECTION_CHANGED] =
975 g_signal_new (I_("direction-changed"),
976 G_TYPE_FROM_CLASS (gobject_class),
978 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
980 _gtk_marshal_VOID__ENUM,
982 GTK_TYPE_TEXT_DIRECTION);
985 * GtkWidget::grab-notify:
986 * @widget: the object which received the signal
987 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
988 * if it becomes unshadowed
990 * The ::grab-notify signal is emitted when a widget becomes
991 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
992 * another widget, or when it becomes unshadowed due to a grab
995 * A widget is shadowed by a gtk_grab_add() when the topmost
996 * grab widget in the grab stack of its window group is not
999 widget_signals[GRAB_NOTIFY] =
1000 g_signal_new (I_("grab-notify"),
1001 G_TYPE_FROM_CLASS (gobject_class),
1003 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1005 _gtk_marshal_VOID__BOOLEAN,
1010 * GtkWidget::child-notify:
1011 * @widget: the object which received the signal
1012 * @pspec: the #GParamSpec of the changed child property
1014 * The ::child-notify signal is emitted for each
1015 * <link linkend="child-properties">child property</link> that has
1016 * changed on an object. The signal's detail holds the property name.
1018 widget_signals[CHILD_NOTIFY] =
1019 g_signal_new (I_("child-notify"),
1020 G_TYPE_FROM_CLASS (gobject_class),
1021 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1022 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1024 g_cclosure_marshal_VOID__PARAM,
1029 * GtkWidget::mnemonic-activate:
1030 * @widget: the object which received the signal.
1033 widget_signals[MNEMONIC_ACTIVATE] =
1034 g_signal_new (I_("mnemonic-activate"),
1035 G_TYPE_FROM_CLASS (gobject_class),
1037 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1038 _gtk_boolean_handled_accumulator, NULL,
1039 _gtk_marshal_BOOLEAN__BOOLEAN,
1044 * GtkWidget::grab-focus:
1045 * @widget: the object which received the signal.
1047 widget_signals[GRAB_FOCUS] =
1048 g_signal_new (I_("grab-focus"),
1049 G_TYPE_FROM_CLASS (gobject_class),
1050 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1051 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1053 _gtk_marshal_VOID__VOID,
1058 * @widget: the object which received the signal.
1061 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1063 widget_signals[FOCUS] =
1064 g_signal_new (I_("focus"),
1065 G_TYPE_FROM_CLASS (object_class),
1067 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1068 _gtk_boolean_handled_accumulator, NULL,
1069 _gtk_marshal_BOOLEAN__ENUM,
1071 GTK_TYPE_DIRECTION_TYPE);
1074 * GtkWidget::move-focus:
1075 * @widget: the object which received the signal.
1078 widget_signals[MOVE_FOCUS] =
1079 g_signal_new_class_handler (I_("move-focus"),
1080 G_TYPE_FROM_CLASS (object_class),
1081 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1082 G_CALLBACK (gtk_widget_real_move_focus),
1084 _gtk_marshal_VOID__ENUM,
1087 GTK_TYPE_DIRECTION_TYPE);
1090 * @widget: the object which received the signal.
1091 * @event: the #GdkEvent which triggered this signal
1093 * The GTK+ main loop will emit three signals for each GDK event delivered
1094 * to a widget: one generic ::event signal, another, more specific,
1095 * signal that matches the type of event delivered (e.g.
1096 * #GtkWidget::key-press-event) and finally a generic
1097 * #GtkWidget::event-after signal.
1099 * Returns: %TRUE to stop other handlers from being invoked for the event
1100 * and to cancel the emission of the second specific ::event signal.
1101 * %FALSE to propagate the event further and to allow the emission of
1102 * the second signal. The ::event-after signal is emitted regardless of
1105 widget_signals[EVENT] =
1106 g_signal_new (I_("event"),
1107 G_TYPE_FROM_CLASS (gobject_class),
1109 G_STRUCT_OFFSET (GtkWidgetClass, event),
1110 _gtk_boolean_handled_accumulator, NULL,
1111 _gtk_marshal_BOOLEAN__BOXED,
1113 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1116 * GtkWidget::event-after:
1117 * @widget: the object which received the signal.
1118 * @event: the #GdkEvent which triggered this signal
1120 * After the emission of the #GtkWidget::event signal and (optionally)
1121 * the second more specific signal, ::event-after will be emitted
1122 * regardless of the previous two signals handlers return values.
1125 widget_signals[EVENT_AFTER] =
1126 g_signal_new (I_("event-after"),
1127 G_TYPE_FROM_CLASS (gobject_class),
1131 _gtk_marshal_VOID__BOXED,
1133 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1136 * GtkWidget::button-press-event:
1137 * @widget: the object which received the signal.
1138 * @event: the #GdkEventButton which triggered this signal
1140 * The ::button-press-event signal will be emitted when a button
1141 * (typically from a mouse) is pressed.
1143 * To receive this signal, the #GdkWindow associated to the
1144 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1146 * This signal will be sent to the grab widget if there is one.
1148 * Returns: %TRUE to stop other handlers from being invoked for the event.
1149 * %FALSE to propagate the event further.
1151 widget_signals[BUTTON_PRESS_EVENT] =
1152 g_signal_new (I_("button-press-event"),
1153 G_TYPE_FROM_CLASS (gobject_class),
1155 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1156 _gtk_boolean_handled_accumulator, NULL,
1157 _gtk_marshal_BOOLEAN__BOXED,
1159 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1162 * GtkWidget::button-release-event:
1163 * @widget: the object which received the signal.
1164 * @event: the #GdkEventButton which triggered this signal
1166 * The ::button-release-event signal will be emitted when a button
1167 * (typically from a mouse) is released.
1169 * To receive this signal, the #GdkWindow associated to the
1170 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1172 * This signal will be sent to the grab widget if there is one.
1174 * Returns: %TRUE to stop other handlers from being invoked for the event.
1175 * %FALSE to propagate the event further.
1177 widget_signals[BUTTON_RELEASE_EVENT] =
1178 g_signal_new (I_("button-release-event"),
1179 G_TYPE_FROM_CLASS (gobject_class),
1181 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1182 _gtk_boolean_handled_accumulator, NULL,
1183 _gtk_marshal_BOOLEAN__BOXED,
1185 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1188 * GtkWidget::scroll-event:
1189 * @widget: the object which received the signal.
1190 * @event: the #GdkEventScroll which triggered this signal
1192 * The ::scroll-event signal is emitted when a button in the 4 to 7
1193 * range is pressed. Wheel mice are usually configured to generate
1194 * button press events for buttons 4 and 5 when the wheel is turned.
1196 * To receive this signal, the #GdkWindow associated to the widget needs
1197 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1199 * This signal will be sent to the grab widget if there is one.
1201 * Returns: %TRUE to stop other handlers from being invoked for the event.
1202 * %FALSE to propagate the event further.
1204 widget_signals[SCROLL_EVENT] =
1205 g_signal_new (I_("scroll-event"),
1206 G_TYPE_FROM_CLASS (gobject_class),
1208 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1209 _gtk_boolean_handled_accumulator, NULL,
1210 _gtk_marshal_BOOLEAN__BOXED,
1212 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1214 * GtkWidget::motion-notify-event:
1215 * @widget: the object which received the signal.
1216 * @event: the #GdkEventMotion which triggered this signal
1218 * The ::motion-notify-event signal is emitted when the pointer moves
1219 * over the widget's #GdkWindow.
1221 * To receive this signal, the #GdkWindow associated to the widget
1222 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1224 * This signal will be sent to the grab widget if there is one.
1226 * Returns: %TRUE to stop other handlers from being invoked for the event.
1227 * %FALSE to propagate the event further.
1229 widget_signals[MOTION_NOTIFY_EVENT] =
1230 g_signal_new (I_("motion-notify-event"),
1231 G_TYPE_FROM_CLASS (gobject_class),
1233 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1234 _gtk_boolean_handled_accumulator, NULL,
1235 _gtk_marshal_BOOLEAN__BOXED,
1237 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1240 * GtkWidget::composited-changed:
1241 * @widget: the object on which the signal is emitted
1243 * The ::composited-changed signal is emitted when the composited
1244 * status of @widget<!-- -->s screen changes.
1245 * See gdk_screen_is_composited().
1247 widget_signals[COMPOSITED_CHANGED] =
1248 g_signal_new (I_("composited-changed"),
1249 G_TYPE_FROM_CLASS (gobject_class),
1250 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1251 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1253 _gtk_marshal_VOID__VOID,
1257 * GtkWidget::keynav-failed:
1258 * @widget: the object which received the signal
1259 * @direction: the direction of movement
1261 * Gets emitted if keyboard navigation fails.
1262 * See gtk_widget_keynav_failed() for details.
1264 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1265 * if the emitting widget should try to handle the keyboard
1266 * navigation attempt in its parent container(s).
1270 widget_signals[KEYNAV_FAILED] =
1271 g_signal_new_class_handler (I_("keynav-failed"),
1272 G_TYPE_FROM_CLASS (gobject_class),
1274 G_CALLBACK (gtk_widget_real_keynav_failed),
1275 _gtk_boolean_handled_accumulator, NULL,
1276 _gtk_marshal_BOOLEAN__ENUM,
1278 GTK_TYPE_DIRECTION_TYPE);
1281 * GtkWidget::delete-event:
1282 * @widget: the object which received the signal
1283 * @event: the event which triggered this signal
1285 * The ::delete-event signal is emitted if a user requests that
1286 * a toplevel window is closed. The default handler for this signal
1287 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1288 * this signal will cause the window to be hidden instead, so that
1289 * it can later be shown again without reconstructing it.
1291 * Returns: %TRUE to stop other handlers from being invoked for the event.
1292 * %FALSE to propagate the event further.
1294 widget_signals[DELETE_EVENT] =
1295 g_signal_new (I_("delete-event"),
1296 G_TYPE_FROM_CLASS (gobject_class),
1298 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1299 _gtk_boolean_handled_accumulator, NULL,
1300 _gtk_marshal_BOOLEAN__BOXED,
1302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1305 * GtkWidget::destroy-event:
1306 * @widget: the object which received the signal.
1307 * @event: the event which triggered this signal
1309 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1310 * You rarely get this signal, because most widgets disconnect themselves
1311 * from their window before they destroy it, so no widget owns the
1312 * window at destroy time.
1314 * To receive this signal, the #GdkWindow associated to the widget needs
1315 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1316 * automatically for all new windows.
1318 * Returns: %TRUE to stop other handlers from being invoked for the event.
1319 * %FALSE to propagate the event further.
1321 widget_signals[DESTROY_EVENT] =
1322 g_signal_new (I_("destroy-event"),
1323 G_TYPE_FROM_CLASS (gobject_class),
1325 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1326 _gtk_boolean_handled_accumulator, NULL,
1327 _gtk_marshal_BOOLEAN__BOXED,
1329 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1332 * GtkWidget::expose-event:
1333 * @widget: the object which received the signal.
1334 * @event: the #GdkEventExpose which triggered this signal
1336 * The ::expose-event signal is emitted when an area of a previously
1337 * obscured #GdkWindow is made visible and needs to be redrawn.
1338 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1341 * To receive this signal, the #GdkWindow associated to the widget needs
1342 * to enable the #GDK_EXPOSURE_MASK mask.
1344 * Returns: %TRUE to stop other handlers from being invoked for the event.
1345 * %FALSE to propagate the event further.
1347 widget_signals[EXPOSE_EVENT] =
1348 g_signal_new (I_("expose-event"),
1349 G_TYPE_FROM_CLASS (gobject_class),
1351 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1352 _gtk_boolean_handled_accumulator, NULL,
1353 _gtk_marshal_BOOLEAN__BOXED,
1355 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1358 * GtkWidget::key-press-event:
1359 * @widget: the object which received the signal
1360 * @event: the #GdkEventKey which triggered this signal
1362 * The ::key-press-event signal is emitted when a key is pressed.
1364 * To receive this signal, the #GdkWindow associated to the widget needs
1365 * to enable the #GDK_KEY_PRESS_MASK mask.
1367 * This signal will be sent to the grab widget if there is one.
1369 * Returns: %TRUE to stop other handlers from being invoked for the event.
1370 * %FALSE to propagate the event further.
1372 widget_signals[KEY_PRESS_EVENT] =
1373 g_signal_new (I_("key-press-event"),
1374 G_TYPE_FROM_CLASS (gobject_class),
1376 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1377 _gtk_boolean_handled_accumulator, NULL,
1378 _gtk_marshal_BOOLEAN__BOXED,
1380 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1383 * GtkWidget::key-release-event:
1384 * @widget: the object which received the signal
1385 * @event: the #GdkEventKey which triggered this signal
1387 * The ::key-release-event signal is emitted when a key is pressed.
1389 * To receive this signal, the #GdkWindow associated to the widget needs
1390 * to enable the #GDK_KEY_RELEASE_MASK mask.
1392 * This signal will be sent to the grab widget if there is one.
1394 * Returns: %TRUE to stop other handlers from being invoked for the event.
1395 * %FALSE to propagate the event further.
1397 widget_signals[KEY_RELEASE_EVENT] =
1398 g_signal_new (I_("key-release-event"),
1399 G_TYPE_FROM_CLASS (gobject_class),
1401 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1402 _gtk_boolean_handled_accumulator, NULL,
1403 _gtk_marshal_BOOLEAN__BOXED,
1405 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1408 * GtkWidget::enter-notify-event:
1409 * @widget: the object which received the signal
1410 * @event: the #GdkEventCrossing which triggered this signal
1412 * The ::enter-notify-event will be emitted when the pointer enters
1413 * the @widget's window.
1415 * To receive this signal, the #GdkWindow associated to the widget needs
1416 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1418 * This signal will be sent to the grab widget if there is one.
1420 * Returns: %TRUE to stop other handlers from being invoked for the event.
1421 * %FALSE to propagate the event further.
1423 widget_signals[ENTER_NOTIFY_EVENT] =
1424 g_signal_new (I_("enter-notify-event"),
1425 G_TYPE_FROM_CLASS (gobject_class),
1427 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1428 _gtk_boolean_handled_accumulator, NULL,
1429 _gtk_marshal_BOOLEAN__BOXED,
1431 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1434 * GtkWidget::leave-notify-event:
1435 * @widget: the object which received the signal
1436 * @event: the #GdkEventCrossing which triggered this signal
1438 * The ::leave-notify-event will be emitted when the pointer leaves
1439 * the @widget's window.
1441 * To receive this signal, the #GdkWindow associated to the widget needs
1442 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1444 * This signal will be sent to the grab widget if there is one.
1446 * Returns: %TRUE to stop other handlers from being invoked for the event.
1447 * %FALSE to propagate the event further.
1449 widget_signals[LEAVE_NOTIFY_EVENT] =
1450 g_signal_new (I_("leave-notify-event"),
1451 G_TYPE_FROM_CLASS (gobject_class),
1453 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1454 _gtk_boolean_handled_accumulator, NULL,
1455 _gtk_marshal_BOOLEAN__BOXED,
1457 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1460 * GtkWidget::configure-event
1461 * @widget: the object which received the signal
1462 * @event: the #GdkEventConfigure which triggered this signal
1464 * The ::configure-event signal will be emitted when the size, position or
1465 * stacking of the @widget's window has changed.
1467 * To receive this signal, the #GdkWindow associated to the widget needs
1468 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1469 * automatically for all new windows.
1471 * Returns: %TRUE to stop other handlers from being invoked for the event.
1472 * %FALSE to propagate the event further.
1474 widget_signals[CONFIGURE_EVENT] =
1475 g_signal_new (I_("configure-event"),
1476 G_TYPE_FROM_CLASS (gobject_class),
1478 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1479 _gtk_boolean_handled_accumulator, NULL,
1480 _gtk_marshal_BOOLEAN__BOXED,
1482 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1485 * GtkWidget::focus-in-event
1486 * @widget: the object which received the signal
1487 * @event: the #GdkEventFocus which triggered this signal
1489 * The ::focus-in-event signal will be emitted when the keyboard focus
1490 * enters the @widget's window.
1492 * To receive this signal, the #GdkWindow associated to the widget needs
1493 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1495 * Returns: %TRUE to stop other handlers from being invoked for the event.
1496 * %FALSE to propagate the event further.
1498 widget_signals[FOCUS_IN_EVENT] =
1499 g_signal_new (I_("focus-in-event"),
1500 G_TYPE_FROM_CLASS (gobject_class),
1502 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1503 _gtk_boolean_handled_accumulator, NULL,
1504 _gtk_marshal_BOOLEAN__BOXED,
1506 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1509 * GtkWidget::focus-out-event
1510 * @widget: the object which received the signal
1511 * @event: the #GdkEventFocus which triggered this signal
1513 * The ::focus-out-event signal will be emitted when the keyboard focus
1514 * leaves the @widget's window.
1516 * To receive this signal, the #GdkWindow associated to the widget needs
1517 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1519 * Returns: %TRUE to stop other handlers from being invoked for the event.
1520 * %FALSE to propagate the event further.
1522 widget_signals[FOCUS_OUT_EVENT] =
1523 g_signal_new (I_("focus-out-event"),
1524 G_TYPE_FROM_CLASS (gobject_class),
1526 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1527 _gtk_boolean_handled_accumulator, NULL,
1528 _gtk_marshal_BOOLEAN__BOXED,
1530 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1533 * GtkWidget::map-event
1534 * @widget: the object which received the signal
1535 * @event: the #GdkEventAny which triggered this signal
1537 * The ::map-event signal will be emitted when the @widget's window is
1538 * mapped. A window is mapped when it becomes visible on the screen.
1540 * To receive this signal, the #GdkWindow associated to the widget needs
1541 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1542 * automatically for all new windows.
1544 * Returns: %TRUE to stop other handlers from being invoked for the event.
1545 * %FALSE to propagate the event further.
1547 widget_signals[MAP_EVENT] =
1548 g_signal_new (I_("map-event"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1551 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1552 _gtk_boolean_handled_accumulator, NULL,
1553 _gtk_marshal_BOOLEAN__BOXED,
1555 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1558 * GtkWidget::unmap-event
1559 * @widget: the object which received the signal
1560 * @event: the #GdkEventAny which triggered this signal
1562 * The ::unmap-event signal will be emitted when the @widget's window is
1563 * unmapped. A window is unmapped when it becomes invisible on the screen.
1565 * To receive this signal, the #GdkWindow associated to the widget needs
1566 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1567 * automatically for all new windows.
1569 * Returns: %TRUE to stop other handlers from being invoked for the event.
1570 * %FALSE to propagate the event further.
1572 widget_signals[UNMAP_EVENT] =
1573 g_signal_new (I_("unmap-event"),
1574 G_TYPE_FROM_CLASS (gobject_class),
1576 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1577 _gtk_boolean_handled_accumulator, NULL,
1578 _gtk_marshal_BOOLEAN__BOXED,
1580 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1583 * GtkWidget::property-notify-event
1584 * @widget: the object which received the signal
1585 * @event: the #GdkEventProperty which triggered this signal
1587 * The ::property-notify-event signal will be emitted when a property on
1588 * the @widget's window has been changed or deleted.
1590 * To receive this signal, the #GdkWindow associated to the widget needs
1591 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1593 * Returns: %TRUE to stop other handlers from being invoked for the event.
1594 * %FALSE to propagate the event further.
1596 widget_signals[PROPERTY_NOTIFY_EVENT] =
1597 g_signal_new (I_("property-notify-event"),
1598 G_TYPE_FROM_CLASS (gobject_class),
1600 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1601 _gtk_boolean_handled_accumulator, NULL,
1602 _gtk_marshal_BOOLEAN__BOXED,
1604 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1607 * GtkWidget::selection-clear-event
1608 * @widget: the object which received the signal
1609 * @event: the #GdkEventSelection which triggered this signal
1611 * The ::selection-clear-event signal will be emitted when the
1612 * the @widget's window has lost ownership of a selection.
1614 * Returns: %TRUE to stop other handlers from being invoked for the event.
1615 * %FALSE to propagate the event further.
1617 widget_signals[SELECTION_CLEAR_EVENT] =
1618 g_signal_new (I_("selection-clear-event"),
1619 G_TYPE_FROM_CLASS (gobject_class),
1621 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1622 _gtk_boolean_handled_accumulator, NULL,
1623 _gtk_marshal_BOOLEAN__BOXED,
1625 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1628 * GtkWidget::selection-request-event
1629 * @widget: the object which received the signal
1630 * @event: the #GdkEventSelection which triggered this signal
1632 * The ::selection-request-event signal will be emitted when
1633 * another client requests ownership of the selection owned by
1634 * the @widget's window.
1636 * Returns: %TRUE to stop other handlers from being invoked for the event.
1637 * %FALSE to propagate the event further.
1639 widget_signals[SELECTION_REQUEST_EVENT] =
1640 g_signal_new (I_("selection-request-event"),
1641 G_TYPE_FROM_CLASS (gobject_class),
1643 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1644 _gtk_boolean_handled_accumulator, NULL,
1645 _gtk_marshal_BOOLEAN__BOXED,
1647 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1650 * GtkWidget::selection-notify-event:
1651 * @widget: the object which received the signal.
1654 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1656 widget_signals[SELECTION_NOTIFY_EVENT] =
1657 g_signal_new (I_("selection-notify-event"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1661 _gtk_boolean_handled_accumulator, NULL,
1662 _gtk_marshal_BOOLEAN__BOXED,
1664 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1667 * GtkWidget::selection-received:
1668 * @widget: the object which received the signal.
1672 widget_signals[SELECTION_RECEIVED] =
1673 g_signal_new (I_("selection-received"),
1674 G_TYPE_FROM_CLASS (gobject_class),
1676 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1678 _gtk_marshal_VOID__BOXED_UINT,
1680 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1684 * GtkWidget::selection-get:
1685 * @widget: the object which received the signal.
1690 widget_signals[SELECTION_GET] =
1691 g_signal_new (I_("selection-get"),
1692 G_TYPE_FROM_CLASS (gobject_class),
1694 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1696 _gtk_marshal_VOID__BOXED_UINT_UINT,
1698 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1703 * GtkWidget::proximity-in-event
1704 * @widget: the object which received the signal
1705 * @event: the #GdkEventProximity which triggered this signal
1707 * To receive this signal the #GdkWindow associated to the widget needs
1708 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1710 * This signal will be sent to the grab widget if there is one.
1712 * Returns: %TRUE to stop other handlers from being invoked for the event.
1713 * %FALSE to propagate the event further.
1715 widget_signals[PROXIMITY_IN_EVENT] =
1716 g_signal_new (I_("proximity-in-event"),
1717 G_TYPE_FROM_CLASS (gobject_class),
1719 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1720 _gtk_boolean_handled_accumulator, NULL,
1721 _gtk_marshal_BOOLEAN__BOXED,
1723 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1726 * GtkWidget::proximity-out-event
1727 * @widget: the object which received the signal
1728 * @event: the #GdkEventProximity which triggered this signal
1730 * To receive this signal the #GdkWindow associated to the widget needs
1731 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1733 * This signal will be sent to the grab widget if there is one.
1735 * Returns: %TRUE to stop other handlers from being invoked for the event.
1736 * %FALSE to propagate the event further.
1738 widget_signals[PROXIMITY_OUT_EVENT] =
1739 g_signal_new (I_("proximity-out-event"),
1740 G_TYPE_FROM_CLASS (gobject_class),
1742 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1743 _gtk_boolean_handled_accumulator, NULL,
1744 _gtk_marshal_BOOLEAN__BOXED,
1746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1749 * GtkWidget::drag-leave:
1750 * @widget: the object which received the signal.
1751 * @drag_context: the drag context
1752 * @time: the timestamp of the motion event
1754 * The ::drag-leave signal is emitted on the drop site when the cursor
1755 * leaves the widget. A typical reason to connect to this signal is to
1756 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1757 * with gtk_drag_unhighlight()
1759 widget_signals[DRAG_LEAVE] =
1760 g_signal_new (I_("drag-leave"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1763 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1765 _gtk_marshal_VOID__OBJECT_UINT,
1767 GDK_TYPE_DRAG_CONTEXT,
1771 * GtkWidget::drag-begin:
1772 * @widget: the object which received the signal
1773 * @drag_context: the drag context
1775 * The ::drag-begin signal is emitted on the drag source when a drag is
1776 * started. A typical reason to connect to this signal is to set up a
1777 * custom drag icon with gtk_drag_source_set_icon().
1779 * Note that some widgets set up a drag icon in the default handler of
1780 * this signal, so you may have to use g_signal_connect_after() to
1781 * override what the default handler did.
1783 widget_signals[DRAG_BEGIN] =
1784 g_signal_new (I_("drag-begin"),
1785 G_TYPE_FROM_CLASS (gobject_class),
1787 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1789 _gtk_marshal_VOID__OBJECT,
1791 GDK_TYPE_DRAG_CONTEXT);
1794 * GtkWidget::drag-end:
1795 * @widget: the object which received the signal
1796 * @drag_context: the drag context
1798 * The ::drag-end signal is emitted on the drag source when a drag is
1799 * finished. A typical reason to connect to this signal is to undo
1800 * things done in #GtkWidget::drag-begin.
1802 widget_signals[DRAG_END] =
1803 g_signal_new (I_("drag-end"),
1804 G_TYPE_FROM_CLASS (gobject_class),
1806 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1808 _gtk_marshal_VOID__OBJECT,
1810 GDK_TYPE_DRAG_CONTEXT);
1813 * GtkWidget::drag-data-delete:
1814 * @widget: the object which received the signal
1815 * @drag_context: the drag context
1817 * The ::drag-data-delete signal is emitted on the drag source when a drag
1818 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1819 * handler is responsible for deleting the data that has been dropped. What
1820 * "delete" means depends on the context of the drag operation.
1822 widget_signals[DRAG_DATA_DELETE] =
1823 g_signal_new (I_("drag-data-delete"),
1824 G_TYPE_FROM_CLASS (gobject_class),
1826 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1828 _gtk_marshal_VOID__OBJECT,
1830 GDK_TYPE_DRAG_CONTEXT);
1833 * GtkWidget::drag-failed:
1834 * @widget: the object which received the signal
1835 * @drag_context: the drag context
1836 * @result: the result of the drag operation
1838 * The ::drag-failed signal is emitted on the drag source when a drag has
1839 * failed. The signal handler may hook custom code to handle a failed DND
1840 * operation based on the type of error, it returns %TRUE is the failure has
1841 * been already handled (not showing the default "drag operation failed"
1842 * animation), otherwise it returns %FALSE.
1844 * Return value: %TRUE if the failed drag operation has been already handled.
1848 widget_signals[DRAG_FAILED] =
1849 g_signal_new (I_("drag-failed"),
1850 G_TYPE_FROM_CLASS (gobject_class),
1852 0, _gtk_boolean_handled_accumulator, NULL,
1853 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1855 GDK_TYPE_DRAG_CONTEXT,
1856 GTK_TYPE_DRAG_RESULT);
1859 * GtkWidget::drag-motion:
1860 * @widget: the object which received the signal
1861 * @drag_context: the drag context
1862 * @x: the x coordinate of the current cursor position
1863 * @y: the y coordinate of the current cursor position
1864 * @time: the timestamp of the motion event
1865 * @returns: whether the cursor position is in a drop zone
1867 * The drag-motion signal is emitted on the drop site when the user
1868 * moves the cursor over the widget during a drag. The signal handler
1869 * must determine whether the cursor position is in a drop zone or not.
1870 * If it is not in a drop zone, it returns %FALSE and no further processing
1871 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1872 * handler is responsible for providing the necessary information for
1873 * displaying feedback to the user, by calling gdk_drag_status().
1875 * If the decision whether the drop will be accepted or rejected can't be
1876 * made based solely on the cursor position and the type of the data, the
1877 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1878 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1879 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1880 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1881 * when using the drag-motion signal that way.
1883 * Also note that there is no drag-enter signal. The drag receiver has to
1884 * keep track of whether he has received any drag-motion signals since the
1885 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1886 * an "enter" signal. Upon an "enter", the handler will typically highlight
1887 * the drop site with gtk_drag_highlight().
1890 * drag_motion (GtkWidget *widget,
1891 * GdkDragContext *context,
1898 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1900 * if (!private_data->drag_highlight)
1902 * private_data->drag_highlight = 1;
1903 * gtk_drag_highlight (widget);
1906 * target = gtk_drag_dest_find_target (widget, context, NULL);
1907 * if (target == GDK_NONE)
1908 * gdk_drag_status (context, 0, time);
1911 * private_data->pending_status = context->suggested_action;
1912 * gtk_drag_get_data (widget, context, target, time);
1919 * drag_data_received (GtkWidget *widget,
1920 * GdkDragContext *context,
1923 * GtkSelectionData *selection_data,
1927 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1929 * if (private_data->suggested_action)
1931 * private_data->suggested_action = 0;
1933 * /* We are getting this data due to a request in drag_motion,
1934 * * rather than due to a request in drag_drop, so we are just
1935 * * supposed to call gdk_drag_status (), not actually paste in
1938 * str = gtk_selection_data_get_text (selection_data);
1939 * if (!data_is_acceptable (str))
1940 * gdk_drag_status (context, 0, time);
1942 * gdk_drag_status (context, private_data->suggested_action, time);
1946 * /* accept the drop */
1951 widget_signals[DRAG_MOTION] =
1952 g_signal_new (I_("drag-motion"),
1953 G_TYPE_FROM_CLASS (gobject_class),
1955 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1956 _gtk_boolean_handled_accumulator, NULL,
1957 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1959 GDK_TYPE_DRAG_CONTEXT,
1965 * GtkWidget::drag-drop:
1966 * @widget: the object which received the signal
1967 * @drag_context: the drag context
1968 * @x: the x coordinate of the current cursor position
1969 * @y: the y coordinate of the current cursor position
1970 * @time: the timestamp of the motion event
1971 * @returns: whether the cursor position is in a drop zone
1973 * The ::drag-drop signal is emitted on the drop site when the user drops
1974 * the data onto the widget. The signal handler must determine whether
1975 * the cursor position is in a drop zone or not. If it is not in a drop
1976 * zone, it returns %FALSE and no further processing is necessary.
1977 * Otherwise, the handler returns %TRUE. In this case, the handler must
1978 * ensure that gtk_drag_finish() is called to let the source know that
1979 * the drop is done. The call to gtk_drag_finish() can be done either
1980 * directly or in a #GtkWidget::drag-data-received handler which gets
1981 * triggered by calling gtk_drag_get_data() to receive the data for one
1982 * or more of the supported targets.
1984 widget_signals[DRAG_DROP] =
1985 g_signal_new (I_("drag-drop"),
1986 G_TYPE_FROM_CLASS (gobject_class),
1988 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1989 _gtk_boolean_handled_accumulator, NULL,
1990 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1992 GDK_TYPE_DRAG_CONTEXT,
1998 * GtkWidget::drag-data-get:
1999 * @widget: the object which received the signal
2000 * @drag_context: the drag context
2001 * @data: the #GtkSelectionData to be filled with the dragged data
2002 * @info: the info that has been registered with the target in the
2004 * @time: the timestamp at which the data was requested
2006 * The ::drag-data-get signal is emitted on the drag source when the drop
2007 * site requests the data which is dragged. It is the responsibility of
2008 * the signal handler to fill @data with the data in the format which
2009 * is indicated by @info. See gtk_selection_data_set() and
2010 * gtk_selection_data_set_text().
2012 widget_signals[DRAG_DATA_GET] =
2013 g_signal_new (I_("drag-data-get"),
2014 G_TYPE_FROM_CLASS (gobject_class),
2016 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2018 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2020 GDK_TYPE_DRAG_CONTEXT,
2021 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2026 * GtkWidget::drag-data-received:
2027 * @widget: the object which received the signal
2028 * @drag_context: the drag context
2029 * @x: where the drop happened
2030 * @y: where the drop happened
2031 * @data: the received data
2032 * @info: the info that has been registered with the target in the
2034 * @time: the timestamp at which the data was received
2036 * The ::drag-data-received signal is emitted on the drop site when the
2037 * dragged data has been received. If the data was received in order to
2038 * determine whether the drop will be accepted, the handler is expected
2039 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2040 * If the data was received in response to a #GtkWidget::drag-drop signal
2041 * (and this is the last target to be received), the handler for this
2042 * signal is expected to process the received data and then call
2043 * gtk_drag_finish(), setting the @success parameter depending on whether
2044 * the data was processed successfully.
2046 * The handler may inspect and modify @drag_context->action before calling
2047 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2048 * following example:
2051 * drag_data_received (GtkWidget *widget,
2052 * GdkDragContext *drag_context,
2055 * GtkSelectionData *data,
2059 * if ((data->length >= 0) && (data->format == 8))
2061 * if (drag_context->action == GDK_ACTION_ASK)
2063 * GtkWidget *dialog;
2066 * dialog = gtk_message_dialog_new (NULL,
2067 * GTK_DIALOG_MODAL |
2068 * GTK_DIALOG_DESTROY_WITH_PARENT,
2070 * GTK_BUTTONS_YES_NO,
2071 * "Move the data ?\n");
2072 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2073 * gtk_widget_destroy (dialog);
2075 * if (response == GTK_RESPONSE_YES)
2076 * drag_context->action = GDK_ACTION_MOVE;
2078 * drag_context->action = GDK_ACTION_COPY;
2081 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2085 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2089 widget_signals[DRAG_DATA_RECEIVED] =
2090 g_signal_new (I_("drag-data-received"),
2091 G_TYPE_FROM_CLASS (gobject_class),
2093 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2095 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2097 GDK_TYPE_DRAG_CONTEXT,
2100 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2105 * GtkWidget::visibility-notify-event:
2106 * @widget: the object which received the signal
2107 * @event: the #GdkEventVisibility which triggered this signal
2109 * The ::visibility-notify-event will be emitted when the @widget's window
2110 * is obscured or unobscured.
2112 * To receive this signal the #GdkWindow associated to the widget needs
2113 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2115 * Returns: %TRUE to stop other handlers from being invoked for the event.
2116 * %FALSE to propagate the event further.
2118 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2119 g_signal_new (I_("visibility-notify-event"),
2120 G_TYPE_FROM_CLASS (gobject_class),
2122 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2123 _gtk_boolean_handled_accumulator, NULL,
2124 _gtk_marshal_BOOLEAN__BOXED,
2126 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2129 * GtkWidget::client-event:
2130 * @widget: the object which received the signal
2131 * @event: the #GdkEventClient which triggered this signal
2133 * The ::client-event will be emitted when the @widget's window
2134 * receives a message (via a ClientMessage event) from another
2137 * Returns: %TRUE to stop other handlers from being invoked for
2138 * the event. %FALSE to propagate the event further.
2140 widget_signals[CLIENT_EVENT] =
2141 g_signal_new (I_("client-event"),
2142 G_TYPE_FROM_CLASS (gobject_class),
2144 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2145 _gtk_boolean_handled_accumulator, NULL,
2146 _gtk_marshal_BOOLEAN__BOXED,
2148 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2151 * GtkWidget::no-expose-event:
2152 * @widget: the object which received the signal
2153 * @event: the #GdkEventNoExpose which triggered this signal
2155 * The ::no-expose-event will be emitted when the @widget's window is
2156 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
2157 * gdk_window_copy_area()) which was completely unobscured. If the source
2158 * window was partially obscured #GdkEventExpose events will be generated
2161 * Returns: %TRUE to stop other handlers from being invoked for the event.
2162 * %FALSE to propagate the event further.
2164 widget_signals[NO_EXPOSE_EVENT] =
2165 g_signal_new (I_("no-expose-event"),
2166 G_TYPE_FROM_CLASS (gobject_class),
2168 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2169 _gtk_boolean_handled_accumulator, NULL,
2170 _gtk_marshal_BOOLEAN__BOXED,
2172 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2175 * GtkWidget::window-state-event:
2176 * @widget: the object which received the signal
2177 * @event: the #GdkEventWindowState which triggered this signal
2179 * The ::window-state-event will be emitted when the state of the
2180 * toplevel window associated to the @widget changes.
2182 * To receive this signal the #GdkWindow associated to the widget
2183 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2184 * this mask automatically for all new windows.
2186 * Returns: %TRUE to stop other handlers from being invoked for the
2187 * event. %FALSE to propagate the event further.
2189 widget_signals[WINDOW_STATE_EVENT] =
2190 g_signal_new (I_("window-state-event"),
2191 G_TYPE_FROM_CLASS (gobject_class),
2193 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2194 _gtk_boolean_handled_accumulator, NULL,
2195 _gtk_marshal_BOOLEAN__BOXED,
2197 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2200 * GtkWidget::damage-event:
2201 * @widget: the object which received the signal
2202 * @event: the #GdkEventExpose event
2204 * Emitted when a redirected window belonging to @widget gets drawn into.
2205 * The region/area members of the event shows what area of the redirected
2206 * drawable was drawn into.
2208 * Returns: %TRUE to stop other handlers from being invoked for the event.
2209 * %FALSE to propagate the event further.
2213 widget_signals[DAMAGE_EVENT] =
2214 g_signal_new (I_("damage-event"),
2215 G_TYPE_FROM_CLASS (gobject_class),
2218 _gtk_boolean_handled_accumulator, NULL,
2219 _gtk_marshal_BOOLEAN__BOXED,
2221 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2223 * GtkWidget::grab-broken-event:
2224 * @widget: the object which received the signal
2225 * @event: the #GdkEventGrabBroken event
2227 * Emitted when a pointer or keyboard grab on a window belonging
2228 * to @widget gets broken.
2230 * On X11, this happens when the grab window becomes unviewable
2231 * (i.e. it or one of its ancestors is unmapped), or if the same
2232 * application grabs the pointer or keyboard again.
2234 * Returns: %TRUE to stop other handlers from being invoked for
2235 * the event. %FALSE to propagate the event further.
2239 widget_signals[GRAB_BROKEN] =
2240 g_signal_new (I_("grab-broken-event"),
2241 G_TYPE_FROM_CLASS (gobject_class),
2243 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2244 _gtk_boolean_handled_accumulator, NULL,
2245 _gtk_marshal_BOOLEAN__BOXED,
2247 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2249 * GtkWidget::query-tooltip:
2250 * @widget: the object which received the signal
2251 * @x: the x coordinate of the cursor position where the request has
2252 * been emitted, relative to @widget->window
2253 * @y: the y coordinate of the cursor position where the request has
2254 * been emitted, relative to @widget->window
2255 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2256 * @tooltip: a #GtkTooltip
2258 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2259 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2260 * focus in keyboard mode.
2262 * Using the given coordinates, the signal handler should determine
2263 * whether a tooltip should be shown for @widget. If this is the case
2264 * %TRUE should be returned, %FALSE otherwise. Note that if
2265 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2266 * should not be used.
2268 * The signal handler is free to manipulate @tooltip with the therefore
2269 * destined function calls.
2271 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2275 widget_signals[QUERY_TOOLTIP] =
2276 g_signal_new (I_("query-tooltip"),
2277 G_TYPE_FROM_CLASS (gobject_class),
2279 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2280 _gtk_boolean_handled_accumulator, NULL,
2281 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2289 * GtkWidget::popup-menu
2290 * @widget: the object which received the signal
2292 * This signal gets emitted whenever a widget should pop up a context
2293 * menu. This usually happens through the standard key binding mechanism;
2294 * by pressing a certain key while a widget is focused, the user can cause
2295 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2296 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2297 * for an example of how to use this signal.
2299 * Returns: %TRUE if a menu was activated
2301 widget_signals[POPUP_MENU] =
2302 g_signal_new (I_("popup-menu"),
2303 G_TYPE_FROM_CLASS (gobject_class),
2304 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2305 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2306 _gtk_boolean_handled_accumulator, NULL,
2307 _gtk_marshal_BOOLEAN__VOID,
2311 * GtkWidget::show-help:
2312 * @widget: the object which received the signal.
2315 widget_signals[SHOW_HELP] =
2316 g_signal_new (I_("show-help"),
2317 G_TYPE_FROM_CLASS (gobject_class),
2318 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2319 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2320 _gtk_boolean_handled_accumulator, NULL,
2321 _gtk_marshal_BOOLEAN__ENUM,
2323 GTK_TYPE_WIDGET_HELP_TYPE);
2326 * GtkWidget::accel-closures-changed:
2327 * @widget: the object which received the signal.
2329 widget_signals[ACCEL_CLOSURES_CHANGED] =
2330 g_signal_new (I_("accel-closures-changed"),
2331 G_TYPE_FROM_CLASS (gobject_class),
2335 _gtk_marshal_VOID__VOID,
2339 * GtkWidget::screen-changed:
2340 * @widget: the object on which the signal is emitted
2341 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2342 * widget was not associated with a screen before
2344 * The ::screen-changed signal gets emitted when the
2345 * screen of a widget has changed.
2347 widget_signals[SCREEN_CHANGED] =
2348 g_signal_new (I_("screen-changed"),
2349 G_TYPE_FROM_CLASS (gobject_class),
2351 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2353 _gtk_marshal_VOID__OBJECT,
2358 * GtkWidget::can-activate-accel:
2359 * @widget: the object which received the signal
2360 * @signal_id: the ID of a signal installed on @widget
2362 * Determines whether an accelerator that activates the signal
2363 * identified by @signal_id can currently be activated.
2364 * This signal is present to allow applications and derived
2365 * widgets to override the default #GtkWidget handling
2366 * for determining whether an accelerator can be activated.
2368 * Returns: %TRUE if the signal can be activated.
2370 widget_signals[CAN_ACTIVATE_ACCEL] =
2371 g_signal_new (I_("can-activate-accel"),
2372 G_TYPE_FROM_CLASS (gobject_class),
2374 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2375 _gtk_boolean_handled_accumulator, NULL,
2376 _gtk_marshal_BOOLEAN__UINT,
2377 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2379 binding_set = gtk_binding_set_by_class (klass);
2380 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2382 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2385 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2387 GTK_TYPE_WIDGET_HELP_TYPE,
2388 GTK_WIDGET_HELP_TOOLTIP);
2389 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2391 GTK_TYPE_WIDGET_HELP_TYPE,
2392 GTK_WIDGET_HELP_TOOLTIP);
2393 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2395 GTK_TYPE_WIDGET_HELP_TYPE,
2396 GTK_WIDGET_HELP_WHATS_THIS);
2397 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2399 GTK_TYPE_WIDGET_HELP_TYPE,
2400 GTK_WIDGET_HELP_WHATS_THIS);
2402 gtk_widget_class_install_style_property (klass,
2403 g_param_spec_boolean ("interior-focus",
2404 P_("Interior Focus"),
2405 P_("Whether to draw the focus indicator inside widgets"),
2407 GTK_PARAM_READABLE));
2409 gtk_widget_class_install_style_property (klass,
2410 g_param_spec_int ("focus-line-width",
2411 P_("Focus linewidth"),
2412 P_("Width, in pixels, of the focus indicator line"),
2414 GTK_PARAM_READABLE));
2416 gtk_widget_class_install_style_property (klass,
2417 g_param_spec_string ("focus-line-pattern",
2418 P_("Focus line dash pattern"),
2419 P_("Dash pattern used to draw the focus indicator"),
2421 GTK_PARAM_READABLE));
2422 gtk_widget_class_install_style_property (klass,
2423 g_param_spec_int ("focus-padding",
2424 P_("Focus padding"),
2425 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2427 GTK_PARAM_READABLE));
2428 gtk_widget_class_install_style_property (klass,
2429 g_param_spec_boxed ("cursor-color",
2431 P_("Color with which to draw insertion cursor"),
2433 GTK_PARAM_READABLE));
2434 gtk_widget_class_install_style_property (klass,
2435 g_param_spec_boxed ("secondary-cursor-color",
2436 P_("Secondary cursor color"),
2437 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2439 GTK_PARAM_READABLE));
2440 gtk_widget_class_install_style_property (klass,
2441 g_param_spec_float ("cursor-aspect-ratio",
2442 P_("Cursor line aspect ratio"),
2443 P_("Aspect ratio with which to draw insertion cursor"),
2445 GTK_PARAM_READABLE));
2448 * GtkWidget:draw-border:
2450 * The "draw-border" style property defines the size of areas outside
2451 * the widget's allocation to draw.
2455 gtk_widget_class_install_style_property (klass,
2456 g_param_spec_boxed ("draw-border",
2458 P_("Size of areas outside the widget's allocation to draw"),
2460 GTK_PARAM_READABLE));
2463 * GtkWidget:link-color:
2465 * The "link-color" style property defines the color of unvisited links.
2469 gtk_widget_class_install_style_property (klass,
2470 g_param_spec_boxed ("link-color",
2471 P_("Unvisited Link Color"),
2472 P_("Color of unvisited links"),
2474 GTK_PARAM_READABLE));
2477 * GtkWidget:visited-link-color:
2479 * The "visited-link-color" style property defines the color of visited links.
2483 gtk_widget_class_install_style_property (klass,
2484 g_param_spec_boxed ("visited-link-color",
2485 P_("Visited Link Color"),
2486 P_("Color of visited links"),
2488 GTK_PARAM_READABLE));
2491 * GtkWidget:wide-separators:
2493 * The "wide-separators" style property defines whether separators have
2494 * configurable width and should be drawn using a box instead of a line.
2498 gtk_widget_class_install_style_property (klass,
2499 g_param_spec_boolean ("wide-separators",
2500 P_("Wide Separators"),
2501 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2503 GTK_PARAM_READABLE));
2506 * GtkWidget:separator-width:
2508 * The "separator-width" style property defines the width of separators.
2509 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2513 gtk_widget_class_install_style_property (klass,
2514 g_param_spec_int ("separator-width",
2515 P_("Separator Width"),
2516 P_("The width of separators if wide-separators is TRUE"),
2518 GTK_PARAM_READABLE));
2521 * GtkWidget:separator-height:
2523 * The "separator-height" style property defines the height of separators.
2524 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2528 gtk_widget_class_install_style_property (klass,
2529 g_param_spec_int ("separator-height",
2530 P_("Separator Height"),
2531 P_("The height of separators if \"wide-separators\" is TRUE"),
2533 GTK_PARAM_READABLE));
2536 * GtkWidget:scroll-arrow-hlength:
2538 * The "scroll-arrow-hlength" style property defines the length of
2539 * horizontal scroll arrows.
2543 gtk_widget_class_install_style_property (klass,
2544 g_param_spec_int ("scroll-arrow-hlength",
2545 P_("Horizontal Scroll Arrow Length"),
2546 P_("The length of horizontal scroll arrows"),
2548 GTK_PARAM_READABLE));
2551 * GtkWidget:scroll-arrow-vlength:
2553 * The "scroll-arrow-vlength" style property defines the length of
2554 * vertical scroll arrows.
2558 gtk_widget_class_install_style_property (klass,
2559 g_param_spec_int ("scroll-arrow-vlength",
2560 P_("Vertical Scroll Arrow Length"),
2561 P_("The length of vertical scroll arrows"),
2563 GTK_PARAM_READABLE));
2567 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2571 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2572 for (node = list; node; node = node->next)
2574 GParamSpec *pspec = node->data;
2576 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2577 g_param_spec_unref (pspec);
2583 gtk_widget_set_property (GObject *object,
2585 const GValue *value,
2588 GtkWidget *widget = GTK_WIDGET (object);
2593 gchar *tooltip_markup;
2594 const gchar *tooltip_text;
2595 GtkWindow *tooltip_window;
2598 gtk_widget_set_name (widget, g_value_get_string (value));
2601 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2603 case PROP_WIDTH_REQUEST:
2604 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2606 case PROP_HEIGHT_REQUEST:
2607 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2610 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2612 case PROP_SENSITIVE:
2613 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2615 case PROP_APP_PAINTABLE:
2616 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2618 case PROP_CAN_FOCUS:
2619 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2621 case PROP_HAS_FOCUS:
2622 if (g_value_get_boolean (value))
2623 gtk_widget_grab_focus (widget);
2626 if (g_value_get_boolean (value))
2627 gtk_widget_grab_focus (widget);
2629 case PROP_CAN_DEFAULT:
2630 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2632 case PROP_HAS_DEFAULT:
2633 if (g_value_get_boolean (value))
2634 gtk_widget_grab_default (widget);
2636 case PROP_RECEIVES_DEFAULT:
2637 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2640 gtk_widget_set_style (widget, g_value_get_object (value));
2643 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2644 gtk_widget_set_events (widget, g_value_get_flags (value));
2646 case PROP_EXTENSION_EVENTS:
2647 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2649 case PROP_NO_SHOW_ALL:
2650 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2652 case PROP_HAS_TOOLTIP:
2653 gtk_widget_real_set_has_tooltip (widget,
2654 g_value_get_boolean (value), FALSE);
2656 case PROP_TOOLTIP_MARKUP:
2657 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2658 tooltip_markup = g_value_dup_string (value);
2660 /* Treat an empty string as a NULL string,
2661 * because an empty string would be useless for a tooltip:
2663 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2665 g_free (tooltip_markup);
2666 tooltip_markup = NULL;
2669 g_object_set_qdata_full (object, quark_tooltip_markup,
2670 tooltip_markup, g_free);
2672 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2673 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2674 if (gtk_widget_get_visible (widget))
2675 gtk_widget_queue_tooltip_query (widget);
2677 case PROP_TOOLTIP_TEXT:
2678 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2680 tooltip_text = g_value_get_string (value);
2682 /* Treat an empty string as a NULL string,
2683 * because an empty string would be useless for a tooltip:
2685 if (tooltip_text && (strlen (tooltip_text) == 0))
2686 tooltip_text = NULL;
2688 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2690 g_object_set_qdata_full (object, quark_tooltip_markup,
2691 tooltip_markup, g_free);
2693 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2694 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2695 if (gtk_widget_get_visible (widget))
2696 gtk_widget_queue_tooltip_query (widget);
2698 case PROP_DOUBLE_BUFFERED:
2699 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2702 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2708 gtk_widget_get_property (GObject *object,
2713 GtkWidget *widget = GTK_WIDGET (object);
2722 g_value_set_string (value, widget->name);
2724 g_value_set_static_string (value, "");
2727 g_value_set_object (value, widget->parent);
2729 case PROP_WIDTH_REQUEST:
2732 gtk_widget_get_size_request (widget, &w, NULL);
2733 g_value_set_int (value, w);
2736 case PROP_HEIGHT_REQUEST:
2739 gtk_widget_get_size_request (widget, NULL, &h);
2740 g_value_set_int (value, h);
2744 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
2746 case PROP_SENSITIVE:
2747 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
2749 case PROP_APP_PAINTABLE:
2750 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
2752 case PROP_CAN_FOCUS:
2753 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
2755 case PROP_HAS_FOCUS:
2756 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
2759 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2761 case PROP_CAN_DEFAULT:
2762 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
2764 case PROP_HAS_DEFAULT:
2765 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
2767 case PROP_RECEIVES_DEFAULT:
2768 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
2770 case PROP_COMPOSITE_CHILD:
2771 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
2774 g_value_set_object (value, gtk_widget_get_style (widget));
2777 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2778 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2780 case PROP_EXTENSION_EVENTS:
2781 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2782 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2784 case PROP_NO_SHOW_ALL:
2785 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2787 case PROP_HAS_TOOLTIP:
2788 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2790 case PROP_TOOLTIP_TEXT:
2792 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2795 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2796 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2798 g_value_take_string (value, text);
2801 case PROP_TOOLTIP_MARKUP:
2802 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2805 g_value_set_object (value, gtk_widget_get_window (widget));
2807 case PROP_DOUBLE_BUFFERED:
2808 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2811 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2817 gtk_widget_init (GtkWidget *widget)
2819 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2820 widget->state = GTK_STATE_NORMAL;
2821 widget->saved_state = GTK_STATE_NORMAL;
2822 widget->name = NULL;
2823 widget->requisition.width = 0;
2824 widget->requisition.height = 0;
2825 widget->allocation.x = -1;
2826 widget->allocation.y = -1;
2827 widget->allocation.width = 1;
2828 widget->allocation.height = 1;
2829 widget->window = NULL;
2830 widget->parent = NULL;
2832 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
2833 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
2834 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
2835 gtk_widget_set_double_buffered (widget, TRUE);
2837 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2838 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2839 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2841 widget->style = gtk_widget_get_default_style ();
2842 g_object_ref (widget->style);
2847 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2849 GParamSpec **pspecs)
2851 GtkWidget *container = widget->parent;
2854 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2855 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2859 * gtk_widget_freeze_child_notify:
2860 * @widget: a #GtkWidget
2862 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2863 * signals are queued until gtk_widget_thaw_child_notify() is called
2866 * This is the analogue of g_object_freeze_notify() for child properties.
2869 gtk_widget_freeze_child_notify (GtkWidget *widget)
2871 g_return_if_fail (GTK_IS_WIDGET (widget));
2873 if (!G_OBJECT (widget)->ref_count)
2876 g_object_ref (widget);
2877 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2878 g_object_unref (widget);
2882 * gtk_widget_child_notify:
2883 * @widget: a #GtkWidget
2884 * @child_property: the name of a child property installed on the
2885 * class of @widget<!-- -->'s parent
2887 * Emits a #GtkWidget::child-notify signal for the
2888 * <link linkend="child-properties">child property</link> @child_property
2891 * This is the analogue of g_object_notify() for child properties.
2894 gtk_widget_child_notify (GtkWidget *widget,
2895 const gchar *child_property)
2899 g_return_if_fail (GTK_IS_WIDGET (widget));
2900 g_return_if_fail (child_property != NULL);
2901 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2904 g_object_ref (widget);
2905 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2907 G_OBJECT_TYPE (widget->parent),
2910 g_warning ("%s: container class `%s' has no child property named `%s'",
2912 G_OBJECT_TYPE_NAME (widget->parent),
2916 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2918 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2919 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2921 g_object_unref (widget);
2925 * gtk_widget_thaw_child_notify:
2926 * @widget: a #GtkWidget
2928 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2929 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2933 gtk_widget_thaw_child_notify (GtkWidget *widget)
2935 GObjectNotifyQueue *nqueue;
2937 g_return_if_fail (GTK_IS_WIDGET (widget));
2939 if (!G_OBJECT (widget)->ref_count)
2942 g_object_ref (widget);
2943 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2944 if (!nqueue || !nqueue->freeze_count)
2945 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2946 G_OBJECT_TYPE_NAME (widget), widget);
2948 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2949 g_object_unref (widget);
2955 * @type: type ID of the widget to create
2956 * @first_property_name: name of first property to set
2957 * @Varargs: value of first property, followed by more properties,
2960 * This is a convenience function for creating a widget and setting
2961 * its properties in one go. For example you might write:
2962 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2963 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2964 * g_object_new(), but returns a widget so you don't have to
2965 * cast the object yourself.
2967 * Return value: a new #GtkWidget of type @widget_type
2970 gtk_widget_new (GType type,
2971 const gchar *first_property_name,
2977 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2979 va_start (var_args, first_property_name);
2980 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2988 * @widget: a #GtkWidget
2989 * @first_property_name: name of first property to set
2990 * @Varargs: value of first property, followed by more properties,
2993 * Precursor of g_object_set().
2995 * Deprecated: 2.0: Use g_object_set() instead.
2998 gtk_widget_set (GtkWidget *widget,
2999 const gchar *first_property_name,
3004 g_return_if_fail (GTK_IS_WIDGET (widget));
3006 va_start (var_args, first_property_name);
3007 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
3012 gtk_widget_queue_draw_child (GtkWidget *widget)
3016 parent = widget->parent;
3017 if (parent && gtk_widget_is_drawable (parent))
3018 gtk_widget_queue_draw_area (parent,
3019 widget->allocation.x,
3020 widget->allocation.y,
3021 widget->allocation.width,
3022 widget->allocation.height);
3026 * gtk_widget_unparent:
3027 * @widget: a #GtkWidget
3029 * This function is only for use in widget implementations.
3030 * Should be called by implementations of the remove method
3031 * on #GtkContainer, to dissociate a child from the container.
3034 gtk_widget_unparent (GtkWidget *widget)
3036 GObjectNotifyQueue *nqueue;
3037 GtkWidget *toplevel;
3038 GtkWidget *old_parent;
3040 g_return_if_fail (GTK_IS_WIDGET (widget));
3041 if (widget->parent == NULL)
3044 /* keep this function in sync with gtk_menu_detach()
3047 g_object_freeze_notify (G_OBJECT (widget));
3048 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3050 toplevel = gtk_widget_get_toplevel (widget);
3051 if (gtk_widget_is_toplevel (toplevel))
3052 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3054 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
3055 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
3057 /* If we are unanchoring the child, we save around the toplevel
3058 * to emit hierarchy changed
3060 if (GTK_WIDGET_ANCHORED (widget->parent))
3061 g_object_ref (toplevel);
3065 gtk_widget_queue_draw_child (widget);
3067 /* Reset the width and height here, to force reallocation if we
3068 * get added back to a new parent. This won't work if our new
3069 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3070 * (would 0x0 be OK here?)
3072 widget->allocation.width = 1;
3073 widget->allocation.height = 1;
3075 if (gtk_widget_get_realized (widget))
3077 if (GTK_WIDGET_IN_REPARENT (widget))
3078 gtk_widget_unmap (widget);
3080 gtk_widget_unrealize (widget);
3083 /* Removing a widget from a container restores the child visible
3084 * flag to the default state, so it doesn't affect the child
3085 * in the next parent.
3087 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3089 old_parent = widget->parent;
3090 widget->parent = NULL;
3091 gtk_widget_set_parent_window (widget, NULL);
3092 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3095 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3096 g_object_unref (toplevel);
3099 g_object_notify (G_OBJECT (widget), "parent");
3100 g_object_thaw_notify (G_OBJECT (widget));
3101 if (!widget->parent)
3102 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3103 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3104 g_object_unref (widget);
3108 * gtk_widget_destroy:
3109 * @widget: a #GtkWidget
3111 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3112 * you don't have to cast the widget to #GtkObject. When a widget is
3113 * destroyed, it will break any references it holds to other objects.
3114 * If the widget is inside a container, the widget will be removed
3115 * from the container. If the widget is a toplevel (derived from
3116 * #GtkWindow), it will be removed from the list of toplevels, and the
3117 * reference GTK+ holds to it will be removed. Removing a
3118 * widget from its container or the list of toplevels results in the
3119 * widget being finalized, unless you've added additional references
3120 * to the widget with g_object_ref().
3122 * In most cases, only toplevel widgets (windows) require explicit
3123 * destruction, because when you destroy a toplevel its children will
3124 * be destroyed as well.
3127 gtk_widget_destroy (GtkWidget *widget)
3129 g_return_if_fail (GTK_IS_WIDGET (widget));
3131 gtk_object_destroy ((GtkObject*) widget);
3135 * gtk_widget_destroyed:
3136 * @widget: a #GtkWidget
3137 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3139 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3140 * %NULL. It's intended to be used as a callback connected to the
3141 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3142 * as a signal handler, and pass the address of your widget variable
3143 * as user data. Then when the widget is destroyed, the variable will
3144 * be set to %NULL. Useful for example to avoid multiple copies
3145 * of the same dialog.
3148 gtk_widget_destroyed (GtkWidget *widget,
3149 GtkWidget **widget_pointer)
3151 /* Don't make any assumptions about the
3153 * Even check widget_pointer.
3156 *widget_pointer = NULL;
3161 * @widget: a #GtkWidget
3163 * Flags a widget to be displayed. Any widget that isn't shown will
3164 * not appear on the screen. If you want to show all the widgets in a
3165 * container, it's easier to call gtk_widget_show_all() on the
3166 * container, instead of individually showing the widgets.
3168 * Remember that you have to show the containers containing a widget,
3169 * in addition to the widget itself, before it will appear onscreen.
3171 * When a toplevel container is shown, it is immediately realized and
3172 * mapped; other shown widgets are realized and mapped when their
3173 * toplevel container is realized and mapped.
3176 gtk_widget_show (GtkWidget *widget)
3178 g_return_if_fail (GTK_IS_WIDGET (widget));
3180 if (!gtk_widget_get_visible (widget))
3182 g_object_ref (widget);
3183 if (!gtk_widget_is_toplevel (widget))
3184 gtk_widget_queue_resize (widget);
3185 g_signal_emit (widget, widget_signals[SHOW], 0);
3186 g_object_notify (G_OBJECT (widget), "visible");
3187 g_object_unref (widget);
3192 gtk_widget_real_show (GtkWidget *widget)
3194 if (!gtk_widget_get_visible (widget))
3196 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3198 if (widget->parent &&
3199 gtk_widget_get_mapped (widget->parent) &&
3200 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3201 !gtk_widget_get_mapped (widget))
3202 gtk_widget_map (widget);
3207 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3210 g_signal_handlers_disconnect_by_func (widget,
3211 gtk_widget_show_map_callback,
3216 * gtk_widget_show_now:
3217 * @widget: a #GtkWidget
3219 * Shows a widget. If the widget is an unmapped toplevel widget
3220 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3221 * loop and wait for the window to actually be mapped. Be careful;
3222 * because the main loop is running, anything can happen during
3226 gtk_widget_show_now (GtkWidget *widget)
3230 g_return_if_fail (GTK_IS_WIDGET (widget));
3232 /* make sure we will get event */
3233 if (!gtk_widget_get_mapped (widget) &&
3234 gtk_widget_is_toplevel (widget))
3236 gtk_widget_show (widget);
3238 g_signal_connect (widget, "map-event",
3239 G_CALLBACK (gtk_widget_show_map_callback),
3243 gtk_main_iteration ();
3246 gtk_widget_show (widget);
3251 * @widget: a #GtkWidget
3253 * Reverses the effects of gtk_widget_show(), causing the widget to be
3254 * hidden (invisible to the user).
3257 gtk_widget_hide (GtkWidget *widget)
3259 g_return_if_fail (GTK_IS_WIDGET (widget));
3261 if (gtk_widget_get_visible (widget))
3263 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3265 g_object_ref (widget);
3266 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3267 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3269 g_signal_emit (widget, widget_signals[HIDE], 0);
3270 if (!gtk_widget_is_toplevel (widget))
3271 gtk_widget_queue_resize (widget);
3272 g_object_notify (G_OBJECT (widget), "visible");
3273 g_object_unref (widget);
3278 gtk_widget_real_hide (GtkWidget *widget)
3280 if (gtk_widget_get_visible (widget))
3282 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3284 if (gtk_widget_get_mapped (widget))
3285 gtk_widget_unmap (widget);
3290 * gtk_widget_hide_on_delete:
3291 * @widget: a #GtkWidget
3293 * Utility function; intended to be connected to the #GtkWidget::delete-event
3294 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3295 * argument, then returns %TRUE. If connected to ::delete-event, the
3296 * result is that clicking the close button for a window (on the
3297 * window frame, top right corner usually) will hide but not destroy
3298 * the window. By default, GTK+ destroys windows when ::delete-event
3301 * Return value: %TRUE
3304 gtk_widget_hide_on_delete (GtkWidget *widget)
3306 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3308 gtk_widget_hide (widget);
3314 * gtk_widget_show_all:
3315 * @widget: a #GtkWidget
3317 * Recursively shows a widget, and any child widgets (if the widget is
3321 gtk_widget_show_all (GtkWidget *widget)
3323 GtkWidgetClass *class;
3325 g_return_if_fail (GTK_IS_WIDGET (widget));
3327 if (gtk_widget_get_no_show_all (widget))
3330 class = GTK_WIDGET_GET_CLASS (widget);
3332 if (class->show_all)
3333 class->show_all (widget);
3337 * gtk_widget_hide_all:
3338 * @widget: a #GtkWidget
3340 * Recursively hides a widget and any child widgets.
3343 gtk_widget_hide_all (GtkWidget *widget)
3345 GtkWidgetClass *class;
3347 g_return_if_fail (GTK_IS_WIDGET (widget));
3349 if (gtk_widget_get_no_show_all (widget))
3352 class = GTK_WIDGET_GET_CLASS (widget);
3354 if (class->hide_all)
3355 class->hide_all (widget);
3360 * @widget: a #GtkWidget
3362 * This function is only for use in widget implementations. Causes
3363 * a widget to be mapped if it isn't already.
3366 gtk_widget_map (GtkWidget *widget)
3368 g_return_if_fail (GTK_IS_WIDGET (widget));
3369 g_return_if_fail (gtk_widget_get_visible (widget));
3370 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3372 if (!gtk_widget_get_mapped (widget))
3374 if (!gtk_widget_get_realized (widget))
3375 gtk_widget_realize (widget);
3377 g_signal_emit (widget, widget_signals[MAP], 0);
3379 if (!gtk_widget_get_has_window (widget))
3380 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3386 * @widget: a #GtkWidget
3388 * This function is only for use in widget implementations. Causes
3389 * a widget to be unmapped if it's currently mapped.
3392 gtk_widget_unmap (GtkWidget *widget)
3394 g_return_if_fail (GTK_IS_WIDGET (widget));
3396 if (gtk_widget_get_mapped (widget))
3398 if (!gtk_widget_get_has_window (widget))
3399 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3400 _gtk_tooltip_hide (widget);
3401 g_signal_emit (widget, widget_signals[UNMAP], 0);
3406 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3407 GdkExtensionMode mode,
3410 GList *free_list = NULL;
3413 if (window_list == NULL)
3415 if (gtk_widget_get_has_window (widget))
3416 window_list = g_list_prepend (NULL, widget->window);
3418 window_list = gdk_window_get_children (widget->window);
3420 free_list = window_list;
3423 for (l = window_list; l != NULL; l = l->next)
3425 GdkWindow *window = l->data;
3428 gdk_window_get_user_data (window, &user_data);
3429 if (user_data == widget)
3433 gdk_input_set_extension_events (window,
3434 gdk_window_get_events (window),
3437 children = gdk_window_get_children (window);
3440 gtk_widget_set_extension_events_internal (widget, mode, children);
3441 g_list_free (children);
3447 g_list_free (free_list);
3451 * gtk_widget_realize:
3452 * @widget: a #GtkWidget
3454 * Creates the GDK (windowing system) resources associated with a
3455 * widget. For example, @widget->window will be created when a widget
3456 * is realized. Normally realization happens implicitly; if you show
3457 * a widget and all its parent containers, then the widget will be
3458 * realized and mapped automatically.
3460 * Realizing a widget requires all
3461 * the widget's parent widgets to be realized; calling
3462 * gtk_widget_realize() realizes the widget's parents in addition to
3463 * @widget itself. If a widget is not yet inside a toplevel window
3464 * when you realize it, bad things will happen.
3466 * This function is primarily used in widget implementations, and
3467 * isn't very useful otherwise. Many times when you think you might
3468 * need it, a better approach is to connect to a signal that will be
3469 * called after the widget is realized automatically, such as
3470 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3471 * GtkWidget::realize signal.
3474 gtk_widget_realize (GtkWidget *widget)
3476 GdkExtensionMode mode;
3477 GtkWidgetShapeInfo *shape_info;
3479 g_return_if_fail (GTK_IS_WIDGET (widget));
3480 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3481 GTK_IS_INVISIBLE (widget));
3483 if (!gtk_widget_get_realized (widget))
3486 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3487 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3490 if (widget->parent == NULL &&
3491 !gtk_widget_is_toplevel (widget))
3492 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3493 "inside a toplevel window is not going to work very well. "
3494 "Widgets must be inside a toplevel container before realizing them.");
3496 if (widget->parent && !gtk_widget_get_realized (widget->parent))
3497 gtk_widget_realize (widget->parent);
3499 gtk_widget_ensure_style (widget);
3501 g_signal_emit (widget, widget_signals[REALIZE], 0);
3503 gtk_widget_real_set_has_tooltip (widget,
3504 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3507 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3509 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3510 gdk_window_shape_combine_mask (widget->window,
3511 shape_info->shape_mask,
3512 shape_info->offset_x,
3513 shape_info->offset_y);
3516 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3518 gdk_window_input_shape_combine_mask (widget->window,
3519 shape_info->shape_mask,
3520 shape_info->offset_x,
3521 shape_info->offset_y);
3523 mode = gtk_widget_get_extension_events (widget);
3524 if (mode != GDK_EXTENSION_EVENTS_NONE)
3525 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3530 * gtk_widget_unrealize:
3531 * @widget: a #GtkWidget
3533 * This function is only useful in widget implementations.
3534 * Causes a widget to be unrealized (frees all GDK resources
3535 * associated with the widget, such as @widget->window).
3538 gtk_widget_unrealize (GtkWidget *widget)
3540 g_return_if_fail (GTK_IS_WIDGET (widget));
3542 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3543 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3545 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3546 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3548 if (gtk_widget_get_realized (widget))
3550 g_object_ref (widget);
3551 _gtk_tooltip_hide (widget);
3552 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3553 gtk_widget_set_realized (widget, FALSE);
3554 gtk_widget_set_mapped (widget, FALSE);
3555 g_object_unref (widget);
3559 /*****************************************
3561 *****************************************/
3564 * gtk_widget_queue_draw_area:
3565 * @widget: a #GtkWidget
3566 * @x: x coordinate of upper-left corner of rectangle to redraw
3567 * @y: y coordinate of upper-left corner of rectangle to redraw
3568 * @width: width of region to draw
3569 * @height: height of region to draw
3571 * Invalidates the rectangular area of @widget defined by @x, @y,
3572 * @width and @height by calling gdk_window_invalidate_rect() on the
3573 * widget's window and all its child windows. Once the main loop
3574 * becomes idle (after the current batch of events has been processed,
3575 * roughly), the window will receive expose events for the union of
3576 * all regions that have been invalidated.
3578 * Normally you would only use this function in widget
3579 * implementations. You might also use it, or
3580 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3581 * #GtkDrawingArea or some portion thereof.
3583 * Frequently you can just call gdk_window_invalidate_rect() or
3584 * gdk_window_invalidate_region() instead of this function. Those
3585 * functions will invalidate only a single window, instead of the
3586 * widget and all its children.
3588 * The advantage of adding to the invalidated region compared to
3589 * simply drawing immediately is efficiency; using an invalid region
3590 * ensures that you only have to redraw one time.
3593 gtk_widget_queue_draw_area (GtkWidget *widget,
3599 GdkRectangle invalid_rect;
3602 g_return_if_fail (GTK_IS_WIDGET (widget));
3604 if (!gtk_widget_get_realized (widget))
3607 /* Just return if the widget or one of its ancestors isn't mapped */
3608 for (w = widget; w != NULL; w = w->parent)
3609 if (!gtk_widget_get_mapped (w))
3612 /* Find the correct widget */
3614 if (gtk_widget_get_has_window (widget))
3618 /* Translate widget relative to window-relative */
3620 gint wx, wy, wwidth, wheight;
3622 gdk_window_get_position (widget->window, &wx, &wy);
3623 x -= wx - widget->allocation.x;
3624 y -= wy - widget->allocation.y;
3626 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3628 if (x + width <= 0 || y + height <= 0 ||
3629 x >= wwidth || y >= wheight)
3640 if (x + width > wwidth)
3642 if (y + height > wheight)
3643 height = wheight - y;
3649 invalid_rect.width = width;
3650 invalid_rect.height = height;
3652 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3656 widget_add_child_draw_rectangle (GtkWidget *widget,
3659 GdkRectangle child_rect;
3661 if (!gtk_widget_get_mapped (widget) ||
3662 widget->window != widget->parent->window)
3665 gtk_widget_get_draw_rectangle (widget, &child_rect);
3666 gdk_rectangle_union (rect, &child_rect, rect);
3670 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3673 if (!gtk_widget_get_has_window (widget))
3675 GtkBorder *draw_border = NULL;
3677 *rect = widget->allocation;
3679 gtk_widget_style_get (widget,
3680 "draw-border", &draw_border,
3684 rect->x -= draw_border->left;
3685 rect->y -= draw_border->top;
3686 rect->width += draw_border->left + draw_border->right;
3687 rect->height += draw_border->top + draw_border->bottom;
3689 gtk_border_free (draw_border);
3692 if (GTK_IS_CONTAINER (widget))
3693 gtk_container_forall (GTK_CONTAINER (widget),
3694 (GtkCallback)widget_add_child_draw_rectangle,
3701 rect->width = widget->allocation.width;
3702 rect->height = widget->allocation.height;
3707 * gtk_widget_queue_draw:
3708 * @widget: a #GtkWidget
3710 * Equivalent to calling gtk_widget_queue_draw_area() for the
3711 * entire area of a widget.
3714 gtk_widget_queue_draw (GtkWidget *widget)
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3720 gtk_widget_get_draw_rectangle (widget, &rect);
3722 gtk_widget_queue_draw_area (widget,
3724 rect.width, rect.height);
3727 /* Invalidates the given area (allocation-relative-coordinates)
3728 * in all of the widget's windows
3731 * gtk_widget_queue_clear_area:
3732 * @widget: a #GtkWidget
3733 * @x: x coordinate of upper-left corner of rectangle to redraw
3734 * @y: y coordinate of upper-left corner of rectangle to redraw
3735 * @width: width of region to draw
3736 * @height: height of region to draw
3738 * This function is no longer different from
3739 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3740 * gtk_widget_queue_draw_area(). Originally
3741 * gtk_widget_queue_clear_area() would force a redraw of the
3742 * background for %GTK_NO_WINDOW widgets, and
3743 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3744 * the background will be redrawn.
3746 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3749 gtk_widget_queue_clear_area (GtkWidget *widget,
3755 g_return_if_fail (GTK_IS_WIDGET (widget));
3757 gtk_widget_queue_draw_area (widget, x, y, width, height);
3761 * gtk_widget_queue_clear:
3762 * @widget: a #GtkWidget
3764 * This function does the same as gtk_widget_queue_draw().
3766 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3769 gtk_widget_queue_clear (GtkWidget *widget)
3771 g_return_if_fail (GTK_IS_WIDGET (widget));
3773 gtk_widget_queue_draw (widget);
3777 * gtk_widget_queue_resize:
3778 * @widget: a #GtkWidget
3780 * This function is only for use in widget implementations.
3781 * Flags a widget to have its size renegotiated; should
3782 * be called when a widget for some reason has a new size request.
3783 * For example, when you change the text in a #GtkLabel, #GtkLabel
3784 * queues a resize to ensure there's enough space for the new text.
3787 gtk_widget_queue_resize (GtkWidget *widget)
3789 g_return_if_fail (GTK_IS_WIDGET (widget));
3791 if (gtk_widget_get_realized (widget))
3792 gtk_widget_queue_shallow_draw (widget);
3794 _gtk_size_group_queue_resize (widget);
3798 * gtk_widget_queue_resize_no_redraw:
3799 * @widget: a #GtkWidget
3801 * This function works like gtk_widget_queue_resize(),
3802 * except that the widget is not invalidated.
3807 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3809 g_return_if_fail (GTK_IS_WIDGET (widget));
3811 _gtk_size_group_queue_resize (widget);
3816 * @widget: a #GtkWidget
3817 * @area: area to draw
3819 * In GTK+ 1.2, this function would immediately render the
3820 * region @area of a widget, by invoking the virtual draw method of a
3821 * widget. In GTK+ 2.0, the draw method is gone, and instead
3822 * gtk_widget_draw() simply invalidates the specified region of the
3823 * widget, then updates the invalid region of the widget immediately.
3824 * Usually you don't want to update the region immediately for
3825 * performance reasons, so in general gtk_widget_queue_draw_area() is
3826 * a better choice if you want to draw a region of a widget.
3829 gtk_widget_draw (GtkWidget *widget,
3830 const GdkRectangle *area)
3832 g_return_if_fail (GTK_IS_WIDGET (widget));
3834 if (gtk_widget_is_drawable (widget))
3837 gtk_widget_queue_draw_area (widget,
3839 area->width, area->height);
3841 gtk_widget_queue_draw (widget);
3843 gdk_window_process_updates (widget->window, TRUE);
3848 * gtk_widget_size_request:
3849 * @widget: a #GtkWidget
3850 * @requisition: a #GtkRequisition to be filled in
3852 * This function is typically used when implementing a #GtkContainer
3853 * subclass. Obtains the preferred size of a widget. The container
3854 * uses this information to arrange its child widgets and decide what
3855 * size allocations to give them with gtk_widget_size_allocate().
3857 * You can also call this function from an application, with some
3858 * caveats. Most notably, getting a size request requires the widget
3859 * to be associated with a screen, because font information may be
3860 * needed. Multihead-aware applications should keep this in mind.
3862 * Also remember that the size request is not necessarily the size
3863 * a widget will actually be allocated.
3865 * See also gtk_widget_get_child_requisition().
3868 gtk_widget_size_request (GtkWidget *widget,
3869 GtkRequisition *requisition)
3871 g_return_if_fail (GTK_IS_WIDGET (widget));
3873 #ifdef G_ENABLE_DEBUG
3874 if (requisition == &widget->requisition)
3875 g_warning ("gtk_widget_size_request() called on child widget with request equal\n to widget->requisition. gtk_widget_set_usize() may not work properly.");
3876 #endif /* G_ENABLE_DEBUG */
3878 _gtk_size_group_compute_requisition (widget, requisition);
3882 * gtk_widget_get_child_requisition:
3883 * @widget: a #GtkWidget
3884 * @requisition: a #GtkRequisition to be filled in
3886 * This function is only for use in widget implementations. Obtains
3887 * @widget->requisition, unless someone has forced a particular
3888 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3889 * in which case it returns that geometry instead of the widget's
3892 * This function differs from gtk_widget_size_request() in that
3893 * it retrieves the last size request value from @widget->requisition,
3894 * while gtk_widget_size_request() actually calls the "size_request" method
3895 * on @widget to compute the size request and fill in @widget->requisition,
3896 * and only then returns @widget->requisition.
3898 * Because this function does not call the "size_request" method, it
3899 * can only be used when you know that @widget->requisition is
3900 * up-to-date, that is, gtk_widget_size_request() has been called
3901 * since the last time a resize was queued. In general, only container
3902 * implementations have this information; applications should use
3903 * gtk_widget_size_request().
3906 gtk_widget_get_child_requisition (GtkWidget *widget,
3907 GtkRequisition *requisition)
3909 _gtk_size_group_get_child_requisition (widget, requisition);
3913 invalidate_predicate (GdkWindow *window,
3918 gdk_window_get_user_data (window, &user_data);
3920 return (user_data == data);
3923 /* Invalidate @region in widget->window and all children
3924 * of widget->window owned by widget. @region is in the
3925 * same coordinates as widget->allocation and will be
3926 * modified by this call.
3929 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3932 if (!gtk_widget_get_realized (widget))
3935 if (gtk_widget_get_has_window (widget) && widget->parent)
3939 gdk_window_get_position (widget->window, &x, &y);
3940 gdk_region_offset (region, -x, -y);
3943 gdk_window_invalidate_maybe_recurse (widget->window, region,
3944 invalidate_predicate, widget);
3948 * gtk_widget_queue_shallow_draw:
3949 * @widget: a #GtkWidget
3951 * Like gtk_widget_queue_draw(), but only windows owned
3952 * by @widget are invalidated.
3955 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3960 if (!gtk_widget_get_realized (widget))
3963 gtk_widget_get_draw_rectangle (widget, &rect);
3965 /* get_draw_rectangle() gives us window coordinates, we
3966 * need to convert to the coordinates that widget->allocation
3969 if (gtk_widget_get_has_window (widget) && widget->parent)
3973 gdk_window_get_position (widget->window, &wx, &wy);
3979 region = gdk_region_rectangle (&rect);
3980 gtk_widget_invalidate_widget_windows (widget, region);
3981 gdk_region_destroy (region);
3985 * gtk_widget_size_allocate:
3986 * @widget: a #GtkWidget
3987 * @allocation: position and size to be allocated to @widget
3989 * This function is only used by #GtkContainer subclasses, to assign a size
3990 * and position to their child widgets.
3993 gtk_widget_size_allocate (GtkWidget *widget,
3994 GtkAllocation *allocation)
3996 GtkWidgetAuxInfo *aux_info;
3997 GdkRectangle real_allocation;
3998 GdkRectangle old_allocation;
3999 gboolean alloc_needed;
4000 gboolean size_changed;
4001 gboolean position_changed;
4003 g_return_if_fail (GTK_IS_WIDGET (widget));
4005 #ifdef G_ENABLE_DEBUG
4006 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
4017 parent = gtk_widget_get_parent (parent);
4020 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4021 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4022 2 * depth, " ", name,
4023 allocation->width, allocation->height);
4025 #endif /* G_ENABLE_DEBUG */
4027 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4028 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4029 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4031 old_allocation = widget->allocation;
4032 real_allocation = *allocation;
4033 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4037 if (aux_info->x_set)
4038 real_allocation.x = aux_info->x;
4039 if (aux_info->y_set)
4040 real_allocation.y = aux_info->y;
4043 if (real_allocation.width < 0 || real_allocation.height < 0)
4045 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4046 real_allocation.width,
4047 real_allocation.height);
4050 real_allocation.width = MAX (real_allocation.width, 1);
4051 real_allocation.height = MAX (real_allocation.height, 1);
4053 size_changed = (old_allocation.width != real_allocation.width ||
4054 old_allocation.height != real_allocation.height);
4055 position_changed = (old_allocation.x != real_allocation.x ||
4056 old_allocation.y != real_allocation.y);
4058 if (!alloc_needed && !size_changed && !position_changed)
4061 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4063 if (gtk_widget_get_mapped (widget))
4065 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4067 /* Invalidate union(old_allaction,widget->allocation) in widget->window
4069 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4070 gdk_region_union_with_rect (invalidate, &old_allocation);
4072 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
4073 gdk_region_destroy (invalidate);
4078 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4080 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
4082 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
4083 gdk_region_union_with_rect (invalidate, &old_allocation);
4085 gtk_widget_invalidate_widget_windows (widget, invalidate);
4086 gdk_region_destroy (invalidate);
4091 if ((size_changed || position_changed) && widget->parent &&
4092 gtk_widget_get_realized (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
4094 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
4095 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
4096 gdk_region_destroy (invalidate);
4101 * gtk_widget_common_ancestor:
4102 * @widget_a: a #GtkWidget
4103 * @widget_b: a #GtkWidget
4105 * Find the common ancestor of @widget_a and @widget_b that
4106 * is closest to the two widgets.
4108 * Return value: the closest common ancestor of @widget_a and
4109 * @widget_b or %NULL if @widget_a and @widget_b do not
4110 * share a common ancestor.
4113 gtk_widget_common_ancestor (GtkWidget *widget_a,
4114 GtkWidget *widget_b)
4116 GtkWidget *parent_a;
4117 GtkWidget *parent_b;
4121 parent_a = widget_a;
4122 while (parent_a->parent)
4124 parent_a = parent_a->parent;
4128 parent_b = widget_b;
4129 while (parent_b->parent)
4131 parent_b = parent_b->parent;
4135 if (parent_a != parent_b)
4138 while (depth_a > depth_b)
4140 widget_a = widget_a->parent;
4144 while (depth_b > depth_a)
4146 widget_b = widget_b->parent;
4150 while (widget_a != widget_b)
4152 widget_a = widget_a->parent;
4153 widget_b = widget_b->parent;
4160 * gtk_widget_translate_coordinates:
4161 * @src_widget: a #GtkWidget
4162 * @dest_widget: a #GtkWidget
4163 * @src_x: X position relative to @src_widget
4164 * @src_y: Y position relative to @src_widget
4165 * @dest_x: (out): location to store X position relative to @dest_widget
4166 * @dest_y: (out): location to store Y position relative to @dest_widget
4168 * Translate coordinates relative to @src_widget's allocation to coordinates
4169 * relative to @dest_widget's allocations. In order to perform this
4170 * operation, both widgets must be realized, and must share a common
4173 * Return value: %FALSE if either widget was not realized, or there
4174 * was no common ancestor. In this case, nothing is stored in
4175 * *@dest_x and *@dest_y. Otherwise %TRUE.
4178 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4179 GtkWidget *dest_widget,
4185 GtkWidget *ancestor;
4187 GList *dest_list = NULL;
4189 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4190 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4192 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4193 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4196 /* Translate from allocation relative to window relative */
4197 if (gtk_widget_get_has_window (src_widget) && src_widget->parent)
4200 gdk_window_get_position (src_widget->window, &wx, &wy);
4202 src_x -= wx - src_widget->allocation.x;
4203 src_y -= wy - src_widget->allocation.y;
4207 src_x += src_widget->allocation.x;
4208 src_y += src_widget->allocation.y;
4211 /* Translate to the common ancestor */
4212 window = src_widget->window;
4213 while (window != ancestor->window)
4217 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4222 window = gdk_window_get_effective_parent (window);
4224 if (!window) /* Handle GtkHandleBox */
4229 window = dest_widget->window;
4230 while (window != ancestor->window)
4232 dest_list = g_list_prepend (dest_list, window);
4234 window = gdk_window_get_effective_parent (window);
4236 if (!window) /* Handle GtkHandleBox */
4238 g_list_free (dest_list);
4247 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4252 dest_list = g_list_remove (dest_list, dest_list->data);
4255 /* Translate from window relative to allocation relative */
4256 if (gtk_widget_get_has_window (dest_widget) && dest_widget->parent)
4259 gdk_window_get_position (dest_widget->window, &wx, &wy);
4261 src_x += wx - dest_widget->allocation.x;
4262 src_y += wy - dest_widget->allocation.y;
4266 src_x -= dest_widget->allocation.x;
4267 src_y -= dest_widget->allocation.y;
4279 gtk_widget_real_size_allocate (GtkWidget *widget,
4280 GtkAllocation *allocation)
4282 widget->allocation = *allocation;
4284 if (gtk_widget_get_realized (widget) &&
4285 gtk_widget_get_has_window (widget))
4287 gdk_window_move_resize (widget->window,
4288 allocation->x, allocation->y,
4289 allocation->width, allocation->height);
4294 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4297 /* widgets must be onscreen for accels to take effect */
4298 return gtk_widget_is_sensitive (widget) &&
4299 gtk_widget_is_drawable (widget) &&
4300 gdk_window_is_viewable (widget->window);
4304 * gtk_widget_can_activate_accel:
4305 * @widget: a #GtkWidget
4306 * @signal_id: the ID of a signal installed on @widget
4308 * Determines whether an accelerator that activates the signal
4309 * identified by @signal_id can currently be activated.
4310 * This is done by emitting the #GtkWidget::can-activate-accel
4311 * signal on @widget; if the signal isn't overridden by a
4312 * handler or in a derived widget, then the default check is
4313 * that the widget must be sensitive, and the widget and all
4314 * its ancestors mapped.
4316 * Return value: %TRUE if the accelerator can be activated.
4321 gtk_widget_can_activate_accel (GtkWidget *widget,
4324 gboolean can_activate = FALSE;
4325 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4326 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4327 return can_activate;
4336 closure_accel_activate (GClosure *closure,
4337 GValue *return_value,
4338 guint n_param_values,
4339 const GValue *param_values,
4340 gpointer invocation_hint,
4341 gpointer marshal_data)
4343 AccelClosure *aclosure = (AccelClosure*) closure;
4344 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4347 g_signal_emit (closure->data, aclosure->signal_id, 0);
4349 /* whether accelerator was handled */
4350 g_value_set_boolean (return_value, can_activate);
4354 closures_destroy (gpointer data)
4356 GSList *slist, *closures = data;
4358 for (slist = closures; slist; slist = slist->next)
4360 g_closure_invalidate (slist->data);
4361 g_closure_unref (slist->data);
4363 g_slist_free (closures);
4367 widget_new_accel_closure (GtkWidget *widget,
4370 AccelClosure *aclosure;
4371 GClosure *closure = NULL;
4372 GSList *slist, *closures;
4374 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4375 for (slist = closures; slist; slist = slist->next)
4376 if (!gtk_accel_group_from_accel_closure (slist->data))
4378 /* reuse this closure */
4379 closure = slist->data;
4384 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4385 closures = g_slist_prepend (closures, g_closure_ref (closure));
4386 g_closure_sink (closure);
4387 g_closure_set_marshal (closure, closure_accel_activate);
4389 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4391 aclosure = (AccelClosure*) closure;
4392 g_assert (closure->data == widget);
4393 g_assert (closure->marshal == closure_accel_activate);
4394 aclosure->signal_id = signal_id;
4400 * gtk_widget_add_accelerator
4401 * @widget: widget to install an accelerator on
4402 * @accel_signal: widget signal to emit on accelerator activation
4403 * @accel_group: accel group for this widget, added to its toplevel
4404 * @accel_key: GDK keyval of the accelerator
4405 * @accel_mods: modifier key combination of the accelerator
4406 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4408 * Installs an accelerator for this @widget in @accel_group that causes
4409 * @accel_signal to be emitted if the accelerator is activated.
4410 * The @accel_group needs to be added to the widget's toplevel via
4411 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4412 * Accelerators added through this function are not user changeable during
4413 * runtime. If you want to support accelerators that can be changed by the
4414 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4415 * gtk_menu_item_set_accel_path() instead.
4418 gtk_widget_add_accelerator (GtkWidget *widget,
4419 const gchar *accel_signal,
4420 GtkAccelGroup *accel_group,
4422 GdkModifierType accel_mods,
4423 GtkAccelFlags accel_flags)
4428 g_return_if_fail (GTK_IS_WIDGET (widget));
4429 g_return_if_fail (accel_signal != NULL);
4430 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4432 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4433 if (!query.signal_id ||
4434 !(query.signal_flags & G_SIGNAL_ACTION) ||
4435 query.return_type != G_TYPE_NONE ||
4438 /* hmm, should be elaborate enough */
4439 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4440 G_OBJECT_TYPE_NAME (widget), accel_signal);
4444 closure = widget_new_accel_closure (widget, query.signal_id);
4446 g_object_ref (widget);
4448 /* install the accelerator. since we don't map this onto an accel_path,
4449 * the accelerator will automatically be locked.
4451 gtk_accel_group_connect (accel_group,
4454 accel_flags | GTK_ACCEL_LOCKED,
4457 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4459 g_object_unref (widget);
4463 * gtk_widget_remove_accelerator:
4464 * @widget: widget to install an accelerator on
4465 * @accel_group: accel group for this widget
4466 * @accel_key: GDK keyval of the accelerator
4467 * @accel_mods: modifier key combination of the accelerator
4468 * @returns: whether an accelerator was installed and could be removed
4470 * Removes an accelerator from @widget, previously installed with
4471 * gtk_widget_add_accelerator().
4474 gtk_widget_remove_accelerator (GtkWidget *widget,
4475 GtkAccelGroup *accel_group,
4477 GdkModifierType accel_mods)
4479 GtkAccelGroupEntry *ag_entry;
4480 GList *slist, *clist;
4483 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4484 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4486 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4487 clist = gtk_widget_list_accel_closures (widget);
4488 for (slist = clist; slist; slist = slist->next)
4492 for (i = 0; i < n; i++)
4493 if (slist->data == (gpointer) ag_entry[i].closure)
4495 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4497 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4499 g_list_free (clist);
4504 g_list_free (clist);
4506 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4507 accel_key, accel_mods, accel_group,
4508 G_OBJECT_TYPE_NAME (widget), widget);
4514 * gtk_widget_list_accel_closures
4515 * @widget: widget to list accelerator closures for
4516 * @returns: a newly allocated #GList of closures
4518 * Lists the closures used by @widget for accelerator group connections
4519 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4520 * The closures can be used to monitor accelerator changes on @widget,
4521 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4522 * #GtkAccelGroup of a closure which can be found out with
4523 * gtk_accel_group_from_accel_closure().
4526 gtk_widget_list_accel_closures (GtkWidget *widget)
4529 GList *clist = NULL;
4531 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4533 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4534 if (gtk_accel_group_from_accel_closure (slist->data))
4535 clist = g_list_prepend (clist, slist->data);
4541 GtkAccelGroup *accel_group;
4546 destroy_accel_path (gpointer data)
4548 AccelPath *apath = data;
4550 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4552 /* closures_destroy takes care of unrefing the closure */
4553 g_object_unref (apath->accel_group);
4555 g_slice_free (AccelPath, apath);
4560 * gtk_widget_set_accel_path:
4561 * @widget: a #GtkWidget
4562 * @accel_path: (allow-none): path used to look up the accelerator
4563 * @accel_group: (allow-none): a #GtkAccelGroup.
4565 * Given an accelerator group, @accel_group, and an accelerator path,
4566 * @accel_path, sets up an accelerator in @accel_group so whenever the
4567 * key binding that is defined for @accel_path is pressed, @widget
4568 * will be activated. This removes any accelerators (for any
4569 * accelerator group) installed by previous calls to
4570 * gtk_widget_set_accel_path(). Associating accelerators with
4571 * paths allows them to be modified by the user and the modifications
4572 * to be saved for future use. (See gtk_accel_map_save().)
4574 * This function is a low level function that would most likely
4575 * be used by a menu creation system like #GtkUIManager. If you
4576 * use #GtkUIManager, setting up accelerator paths will be done
4579 * Even when you you aren't using #GtkUIManager, if you only want to
4580 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4581 * provides a somewhat more convenient interface.
4583 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4584 * pass a static string, you can save some memory by interning it first with
4585 * g_intern_static_string().
4588 gtk_widget_set_accel_path (GtkWidget *widget,
4589 const gchar *accel_path,
4590 GtkAccelGroup *accel_group)
4594 g_return_if_fail (GTK_IS_WIDGET (widget));
4595 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4599 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4600 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4602 gtk_accel_map_add_entry (accel_path, 0, 0);
4603 apath = g_slice_new (AccelPath);
4604 apath->accel_group = g_object_ref (accel_group);
4605 apath->path_quark = g_quark_from_string (accel_path);
4606 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4611 /* also removes possible old settings */
4612 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4615 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4617 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4621 _gtk_widget_get_accel_path (GtkWidget *widget,
4626 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4628 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4630 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4631 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4635 * gtk_widget_mnemonic_activate:
4636 * @widget: a #GtkWidget
4637 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4639 * Emits the #GtkWidget::mnemonic-activate signal.
4641 * The default handler for this signal activates the @widget if
4642 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4645 * Returns: %TRUE if the signal has been handled
4648 gtk_widget_mnemonic_activate (GtkWidget *widget,
4649 gboolean group_cycling)
4653 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4655 group_cycling = group_cycling != FALSE;
4656 if (!gtk_widget_is_sensitive (widget))
4659 g_signal_emit (widget,
4660 widget_signals[MNEMONIC_ACTIVATE],
4668 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4669 gboolean group_cycling)
4671 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4672 gtk_widget_activate (widget);
4673 else if (gtk_widget_get_can_focus (widget))
4674 gtk_widget_grab_focus (widget);
4677 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4678 G_OBJECT_TYPE_NAME (widget));
4679 gtk_widget_error_bell (widget);
4685 gtk_widget_real_key_press_event (GtkWidget *widget,
4688 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4692 gtk_widget_real_key_release_event (GtkWidget *widget,
4695 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4699 gtk_widget_real_focus_in_event (GtkWidget *widget,
4700 GdkEventFocus *event)
4702 gtk_widget_queue_shallow_draw (widget);
4708 gtk_widget_real_focus_out_event (GtkWidget *widget,
4709 GdkEventFocus *event)
4711 gtk_widget_queue_shallow_draw (widget);
4716 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4717 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
4721 * @widget: a #GtkWidget
4722 * @event: a #GdkEvent
4724 * Rarely-used function. This function is used to emit
4725 * the event signals on a widget (those signals should never
4726 * be emitted without using this function to do so).
4727 * If you want to synthesize an event though, don't use this function;
4728 * instead, use gtk_main_do_event() so the event will behave as if
4729 * it were in the event queue. Don't synthesize expose events; instead,
4730 * use gdk_window_invalidate_rect() to invalidate a region of the
4733 * Return value: return from the event signal emission (%TRUE if
4734 * the event was handled)
4737 gtk_widget_event (GtkWidget *widget,
4740 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4741 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4743 if (event->type == GDK_EXPOSE)
4745 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4746 "the same effect, call gdk_window_invalidate_rect/region(), "
4747 "followed by gdk_window_process_updates().");
4751 return gtk_widget_event_internal (widget, event);
4756 * gtk_widget_send_expose:
4757 * @widget: a #GtkWidget
4758 * @event: a expose #GdkEvent
4760 * Very rarely-used function. This function is used to emit
4761 * an expose event signals on a widget. This function is not
4762 * normally used directly. The only time it is used is when
4763 * propagating an expose event to a child %NO_WINDOW widget, and
4764 * that is normally done using gtk_container_propagate_expose().
4766 * If you want to force an area of a window to be redrawn,
4767 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4768 * To cause the redraw to be done immediately, follow that call
4769 * with a call to gdk_window_process_updates().
4771 * Return value: return from the event signal emission (%TRUE if
4772 * the event was handled)
4775 gtk_widget_send_expose (GtkWidget *widget,
4778 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4779 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
4780 g_return_val_if_fail (event != NULL, TRUE);
4781 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4783 return gtk_widget_event_internal (widget, event);
4787 event_window_is_still_viewable (GdkEvent *event)
4789 /* Some programs, such as gnome-theme-manager, fake widgets
4790 * into exposing onto a pixmap by sending expose events with
4791 * event->window pointing to a pixmap
4793 if (GDK_IS_PIXMAP (event->any.window))
4794 return event->type == GDK_EXPOSE;
4796 /* Check that we think the event's window is viewable before
4797 * delivering the event, to prevent suprises. We do this here
4798 * at the last moment, since the event may have been queued
4799 * up behind other events, held over a recursive main loop, etc.
4801 switch (event->type)
4804 case GDK_MOTION_NOTIFY:
4805 case GDK_BUTTON_PRESS:
4806 case GDK_2BUTTON_PRESS:
4807 case GDK_3BUTTON_PRESS:
4809 case GDK_ENTER_NOTIFY:
4810 case GDK_PROXIMITY_IN:
4812 return event->any.window && gdk_window_is_viewable (event->any.window);
4815 /* The following events are the second half of paired events;
4816 * we always deliver them to deal with widgets that clean up
4817 * on the second half.
4819 case GDK_BUTTON_RELEASE:
4820 case GDK_KEY_RELEASE:
4821 case GDK_LEAVE_NOTIFY:
4822 case GDK_PROXIMITY_OUT:
4826 /* Remaining events would make sense on an not-viewable window,
4827 * or don't have an associated window.
4834 gtk_widget_event_internal (GtkWidget *widget,
4837 gboolean return_val = FALSE;
4839 /* We check only once for is-still-visible; if someone
4840 * hides the window in on of the signals on the widget,
4841 * they are responsible for returning TRUE to terminate
4844 if (!event_window_is_still_viewable (event))
4847 g_object_ref (widget);
4849 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4850 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4855 switch (event->type)
4860 case GDK_BUTTON_PRESS:
4861 case GDK_2BUTTON_PRESS:
4862 case GDK_3BUTTON_PRESS:
4863 signal_num = BUTTON_PRESS_EVENT;
4866 signal_num = SCROLL_EVENT;
4868 case GDK_BUTTON_RELEASE:
4869 signal_num = BUTTON_RELEASE_EVENT;
4871 case GDK_MOTION_NOTIFY:
4872 signal_num = MOTION_NOTIFY_EVENT;
4875 signal_num = DELETE_EVENT;
4878 signal_num = DESTROY_EVENT;
4879 _gtk_tooltip_hide (widget);
4882 signal_num = KEY_PRESS_EVENT;
4884 case GDK_KEY_RELEASE:
4885 signal_num = KEY_RELEASE_EVENT;
4887 case GDK_ENTER_NOTIFY:
4888 signal_num = ENTER_NOTIFY_EVENT;
4890 case GDK_LEAVE_NOTIFY:
4891 signal_num = LEAVE_NOTIFY_EVENT;
4893 case GDK_FOCUS_CHANGE:
4894 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4895 if (event->focus_change.in)
4896 _gtk_tooltip_focus_in (widget);
4898 _gtk_tooltip_focus_out (widget);
4901 signal_num = CONFIGURE_EVENT;
4904 signal_num = MAP_EVENT;
4907 signal_num = UNMAP_EVENT;
4909 case GDK_WINDOW_STATE:
4910 signal_num = WINDOW_STATE_EVENT;
4912 case GDK_PROPERTY_NOTIFY:
4913 signal_num = PROPERTY_NOTIFY_EVENT;
4915 case GDK_SELECTION_CLEAR:
4916 signal_num = SELECTION_CLEAR_EVENT;
4918 case GDK_SELECTION_REQUEST:
4919 signal_num = SELECTION_REQUEST_EVENT;
4921 case GDK_SELECTION_NOTIFY:
4922 signal_num = SELECTION_NOTIFY_EVENT;
4924 case GDK_PROXIMITY_IN:
4925 signal_num = PROXIMITY_IN_EVENT;
4927 case GDK_PROXIMITY_OUT:
4928 signal_num = PROXIMITY_OUT_EVENT;
4931 signal_num = NO_EXPOSE_EVENT;
4933 case GDK_CLIENT_EVENT:
4934 signal_num = CLIENT_EVENT;
4937 signal_num = EXPOSE_EVENT;
4939 case GDK_VISIBILITY_NOTIFY:
4940 signal_num = VISIBILITY_NOTIFY_EVENT;
4942 case GDK_GRAB_BROKEN:
4943 signal_num = GRAB_BROKEN;
4946 signal_num = DAMAGE_EVENT;
4949 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4953 if (signal_num != -1)
4954 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4956 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4957 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4961 g_object_unref (widget);
4967 * gtk_widget_activate:
4968 * @widget: a #GtkWidget that's activatable
4970 * For widgets that can be "activated" (buttons, menu items, etc.)
4971 * this function activates them. Activation is what happens when you
4972 * press Enter on a widget during key navigation. If @widget isn't
4973 * activatable, the function returns %FALSE.
4975 * Return value: %TRUE if the widget was activatable
4978 gtk_widget_activate (GtkWidget *widget)
4980 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4982 if (WIDGET_CLASS (widget)->activate_signal)
4984 /* FIXME: we should eventually check the signals signature here */
4985 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4994 * gtk_widget_set_scroll_adjustments:
4995 * @widget: a #GtkWidget
4996 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
4997 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
4999 * For widgets that support scrolling, sets the scroll adjustments and
5000 * returns %TRUE. For widgets that don't support scrolling, does
5001 * nothing and returns %FALSE. Widgets that don't support scrolling
5002 * can be scrolled by placing them in a #GtkViewport, which does
5003 * support scrolling.
5005 * Return value: %TRUE if the widget supports scrolling
5008 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5009 GtkAdjustment *hadjustment,
5010 GtkAdjustment *vadjustment)
5015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5018 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5020 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5022 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5026 g_signal_query (signal_id, &query);
5027 if (!query.signal_id ||
5028 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5029 query.return_type != G_TYPE_NONE ||
5030 query.n_params != 2 ||
5031 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5032 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5034 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5035 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5039 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5044 gtk_widget_reparent_subwindows (GtkWidget *widget,
5045 GdkWindow *new_window)
5047 if (!gtk_widget_get_has_window (widget))
5049 GList *children = gdk_window_get_children (widget->window);
5052 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5054 GdkWindow *window = tmp_list->data;
5057 gdk_window_get_user_data (window, &child);
5058 while (child && child != widget)
5059 child = ((GtkWidget*) child)->parent;
5062 gdk_window_reparent (window, new_window, 0, 0);
5065 g_list_free (children);
5070 GList *tmp_list, *children;
5072 parent = gdk_window_get_parent (widget->window);
5075 gdk_window_reparent (widget->window, new_window, 0, 0);
5078 children = gdk_window_get_children (parent);
5080 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5082 GdkWindow *window = tmp_list->data;
5085 gdk_window_get_user_data (window, &child);
5087 if (child == widget)
5088 gdk_window_reparent (window, new_window, 0, 0);
5091 g_list_free (children);
5097 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5098 gpointer client_data)
5100 g_assert (client_data != NULL);
5102 if (!gtk_widget_get_has_window (widget))
5105 g_object_unref (widget->window);
5106 widget->window = (GdkWindow*) client_data;
5108 g_object_ref (widget->window);
5110 if (GTK_IS_CONTAINER (widget))
5111 gtk_container_forall (GTK_CONTAINER (widget),
5112 gtk_widget_reparent_fixup_child,
5118 * gtk_widget_reparent:
5119 * @widget: a #GtkWidget
5120 * @new_parent: a #GtkContainer to move the widget into
5122 * Moves a widget from one #GtkContainer to another, handling reference
5123 * count issues to avoid destroying the widget.
5126 gtk_widget_reparent (GtkWidget *widget,
5127 GtkWidget *new_parent)
5129 g_return_if_fail (GTK_IS_WIDGET (widget));
5130 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5131 g_return_if_fail (widget->parent != NULL);
5133 if (widget->parent != new_parent)
5135 /* First try to see if we can get away without unrealizing
5136 * the widget as we reparent it. if so we set a flag so
5137 * that gtk_widget_unparent doesn't unrealize widget
5139 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5140 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5142 g_object_ref (widget);
5143 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5144 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5145 g_object_unref (widget);
5147 if (GTK_WIDGET_IN_REPARENT (widget))
5149 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5151 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5152 gtk_widget_reparent_fixup_child (widget,
5153 gtk_widget_get_parent_window (widget));
5156 g_object_notify (G_OBJECT (widget), "parent");
5161 * gtk_widget_intersect:
5162 * @widget: a #GtkWidget
5163 * @area: a rectangle
5164 * @intersection: rectangle to store intersection of @widget and @area
5166 * Computes the intersection of a @widget's area and @area, storing
5167 * the intersection in @intersection, and returns %TRUE if there was
5168 * an intersection. @intersection may be %NULL if you're only
5169 * interested in whether there was an intersection.
5171 * Return value: %TRUE if there was an intersection
5174 gtk_widget_intersect (GtkWidget *widget,
5175 const GdkRectangle *area,
5176 GdkRectangle *intersection)
5182 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5183 g_return_val_if_fail (area != NULL, FALSE);
5186 dest = intersection;
5190 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5192 if (return_val && intersection && gtk_widget_get_has_window (widget))
5194 intersection->x -= widget->allocation.x;
5195 intersection->y -= widget->allocation.y;
5202 * gtk_widget_region_intersect:
5203 * @widget: a #GtkWidget
5204 * @region: a #GdkRegion, in the same coordinate system as
5205 * @widget->allocation. That is, relative to @widget->window
5206 * for %NO_WINDOW widgets; relative to the parent window
5207 * of @widget->window for widgets with their own window.
5208 * @returns: A newly allocated region holding the intersection of @widget
5209 * and @region. The coordinates of the return value are
5210 * relative to @widget->window for %NO_WINDOW widgets, and
5211 * relative to the parent window of @widget->window for
5212 * widgets with their own window.
5214 * Computes the intersection of a @widget's area and @region, returning
5215 * the intersection. The result may be empty, use gdk_region_empty() to
5219 gtk_widget_region_intersect (GtkWidget *widget,
5220 const GdkRegion *region)
5225 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5226 g_return_val_if_fail (region != NULL, NULL);
5228 gtk_widget_get_draw_rectangle (widget, &rect);
5230 dest = gdk_region_rectangle (&rect);
5232 gdk_region_intersect (dest, region);
5238 * _gtk_widget_grab_notify:
5239 * @widget: a #GtkWidget
5240 * @was_grabbed: whether a grab is now in effect
5242 * Emits the #GtkWidget::grab-notify signal on @widget.
5247 _gtk_widget_grab_notify (GtkWidget *widget,
5248 gboolean was_grabbed)
5250 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5254 * gtk_widget_grab_focus:
5255 * @widget: a #GtkWidget
5257 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5258 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5259 * something like #GtkFrame won't work.
5261 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5262 * gtk_widget_set_can_focus() to modify that flag.
5265 gtk_widget_grab_focus (GtkWidget *widget)
5267 g_return_if_fail (GTK_IS_WIDGET (widget));
5269 if (!gtk_widget_is_sensitive (widget))
5272 g_object_ref (widget);
5273 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5274 g_object_notify (G_OBJECT (widget), "has-focus");
5275 g_object_unref (widget);
5279 reset_focus_recurse (GtkWidget *widget,
5282 if (GTK_IS_CONTAINER (widget))
5284 GtkContainer *container;
5286 container = GTK_CONTAINER (widget);
5287 gtk_container_set_focus_child (container, NULL);
5289 gtk_container_foreach (container,
5290 reset_focus_recurse,
5296 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5298 if (gtk_widget_get_can_focus (focus_widget))
5300 GtkWidget *toplevel;
5303 /* clear the current focus setting, break if the current widget
5304 * is the focus widget's parent, since containers above that will
5305 * be set by the next loop.
5307 toplevel = gtk_widget_get_toplevel (focus_widget);
5308 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5310 widget = GTK_WINDOW (toplevel)->focus_widget;
5312 if (widget == focus_widget)
5314 /* We call _gtk_window_internal_set_focus() here so that the
5315 * toplevel window can request the focus if necessary.
5316 * This is needed when the toplevel is a GtkPlug
5318 if (!gtk_widget_has_focus (widget))
5319 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5326 while (widget->parent && widget->parent != focus_widget->parent)
5328 widget = widget->parent;
5329 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5333 else if (toplevel != focus_widget)
5335 /* gtk_widget_grab_focus() operates on a tree without window...
5336 * actually, this is very questionable behaviour.
5339 gtk_container_foreach (GTK_CONTAINER (toplevel),
5340 reset_focus_recurse,
5344 /* now propagate the new focus up the widget tree and finally
5345 * set it on the window
5347 widget = focus_widget;
5348 while (widget->parent)
5350 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5351 widget = widget->parent;
5353 if (GTK_IS_WINDOW (widget))
5354 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5359 gtk_widget_real_query_tooltip (GtkWidget *widget,
5362 gboolean keyboard_tip,
5363 GtkTooltip *tooltip)
5365 gchar *tooltip_markup;
5366 gboolean has_tooltip;
5368 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5369 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5371 if (has_tooltip && tooltip_markup)
5373 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5381 gtk_widget_real_show_help (GtkWidget *widget,
5382 GtkWidgetHelpType help_type)
5384 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5386 _gtk_tooltip_toggle_keyboard_mode (widget);
5395 gtk_widget_real_focus (GtkWidget *widget,
5396 GtkDirectionType direction)
5398 if (!gtk_widget_get_can_focus (widget))
5401 if (!gtk_widget_is_focus (widget))
5403 gtk_widget_grab_focus (widget);
5411 gtk_widget_real_move_focus (GtkWidget *widget,
5412 GtkDirectionType direction)
5414 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5416 if (GTK_IS_WINDOW (toplevel) &&
5417 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5419 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5425 gtk_widget_real_keynav_failed (GtkWidget *widget,
5426 GtkDirectionType direction)
5428 gboolean cursor_only;
5432 case GTK_DIR_TAB_FORWARD:
5433 case GTK_DIR_TAB_BACKWARD:
5440 g_object_get (gtk_widget_get_settings (widget),
5441 "gtk-keynav-cursor-only", &cursor_only,
5448 gtk_widget_error_bell (widget);
5454 * gtk_widget_set_can_focus:
5455 * @widget: a #GtkWidget
5456 * @can_focus: whether or not @widget can own the input focus.
5458 * Specifies whether @widget can own the input focus. See
5459 * gtk_widget_grab_focus() for actually setting the input focus on a
5465 gtk_widget_set_can_focus (GtkWidget *widget,
5468 g_return_if_fail (GTK_IS_WIDGET (widget));
5470 if (can_focus != gtk_widget_get_can_focus (widget))
5473 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5475 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5477 gtk_widget_queue_resize (widget);
5478 g_object_notify (G_OBJECT (widget), "can-focus");
5483 * gtk_widget_get_can_focus:
5484 * @widget: a #GtkWidget
5486 * Determines whether @widget can own the input focus. See
5487 * gtk_widget_set_can_focus().
5489 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5494 gtk_widget_get_can_focus (GtkWidget *widget)
5496 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5498 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
5502 * gtk_widget_has_focus:
5503 * @widget: a #GtkWidget
5505 * Determines if the widget has the global input focus. See
5506 * gtk_widget_is_focus() for the difference between having the global
5507 * input focus, and only having the focus within a toplevel.
5509 * Return value: %TRUE if the widget has the global input focus.
5514 gtk_widget_has_focus (GtkWidget *widget)
5516 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5518 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
5522 * gtk_widget_is_focus:
5523 * @widget: a #GtkWidget
5525 * Determines if the widget is the focus widget within its
5526 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5527 * necessarily set; %HAS_FOCUS will only be set if the
5528 * toplevel widget additionally has the global input focus.)
5530 * Return value: %TRUE if the widget is the focus widget.
5533 gtk_widget_is_focus (GtkWidget *widget)
5535 GtkWidget *toplevel;
5537 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5539 toplevel = gtk_widget_get_toplevel (widget);
5541 if (GTK_IS_WINDOW (toplevel))
5542 return widget == GTK_WINDOW (toplevel)->focus_widget;
5548 * gtk_widget_set_can_default:
5549 * @widget: a #GtkWidget
5550 * @can_default: whether or not @widget can be a default widget.
5552 * Specifies whether @widget can be a default widget. See
5553 * gtk_widget_grab_default() for details about the meaning of
5559 gtk_widget_set_can_default (GtkWidget *widget,
5560 gboolean can_default)
5562 g_return_if_fail (GTK_IS_WIDGET (widget));
5564 if (can_default != gtk_widget_get_can_default (widget))
5567 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
5569 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
5571 gtk_widget_queue_resize (widget);
5572 g_object_notify (G_OBJECT (widget), "can-default");
5577 * gtk_widget_get_can_default:
5578 * @widget: a #GtkWidget
5580 * Determines whether @widget can be a default widget. See
5581 * gtk_widget_set_can_default().
5583 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5588 gtk_widget_get_can_default (GtkWidget *widget)
5590 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5592 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
5596 * gtk_widget_has_default:
5597 * @widget: a #GtkWidget
5599 * Determines whether @widget is the current default widget within its
5600 * toplevel. See gtk_widget_set_can_default().
5602 * Return value: %TRUE if @widget is the current default widget within
5603 * its toplevel, %FALSE otherwise
5608 gtk_widget_has_default (GtkWidget *widget)
5610 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5612 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
5616 _gtk_widget_set_has_default (GtkWidget *widget,
5617 gboolean has_default)
5620 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
5622 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
5626 * gtk_widget_grab_default:
5627 * @widget: a #GtkWidget
5629 * Causes @widget to become the default widget. @widget must have the
5630 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5631 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5632 * %TRUE)</literal>. The default widget is activated when
5633 * the user presses Enter in a window. Default widgets must be
5634 * activatable, that is, gtk_widget_activate() should affect them.
5637 gtk_widget_grab_default (GtkWidget *widget)
5641 g_return_if_fail (GTK_IS_WIDGET (widget));
5642 g_return_if_fail (gtk_widget_get_can_default (widget));
5644 window = gtk_widget_get_toplevel (widget);
5646 if (window && gtk_widget_is_toplevel (window))
5647 gtk_window_set_default (GTK_WINDOW (window), widget);
5649 g_warning (G_STRLOC ": widget not within a GtkWindow");
5653 * gtk_widget_set_receives_default:
5654 * @widget: a #GtkWidget
5655 * @receives_default: whether or not @widget can be a default widget.
5657 * Specifies whether @widget will be treated as the default widget
5658 * within its toplevel when it has the focus, even if another widget
5661 * See gtk_widget_grab_default() for details about the meaning of
5667 gtk_widget_set_receives_default (GtkWidget *widget,
5668 gboolean receives_default)
5670 g_return_if_fail (GTK_IS_WIDGET (widget));
5672 if (receives_default != gtk_widget_get_receives_default (widget))
5674 if (receives_default)
5675 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
5677 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
5679 g_object_notify (G_OBJECT (widget), "receives-default");
5684 * gtk_widget_get_receives_default:
5685 * @widget: a #GtkWidget
5687 * Determines whether @widget is alyways treated as default widget
5688 * withing its toplevel when it has the focus, even if another widget
5691 * See gtk_widget_set_receives_default().
5693 * Return value: %TRUE if @widget acts as default widget when focussed,
5699 gtk_widget_get_receives_default (GtkWidget *widget)
5701 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5703 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5707 * gtk_widget_has_grab:
5708 * @widget: a #GtkWidget
5710 * Determines whether the widget is currently grabbing events, so it
5711 * is the only widget receiving input events (keyboard and mouse).
5713 * See also gtk_grab_add().
5715 * Return value: %TRUE if the widget is in the grab_widgets stack
5720 gtk_widget_has_grab (GtkWidget *widget)
5722 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5724 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5728 _gtk_widget_set_has_grab (GtkWidget *widget,
5732 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
5734 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
5738 * gtk_widget_set_name:
5739 * @widget: a #GtkWidget
5740 * @name: name for the widget
5742 * Widgets can be named, which allows you to refer to them from a
5743 * gtkrc file. You can apply a style to widgets with a particular name
5744 * in the gtkrc file. See the documentation for gtkrc files (on the
5745 * same page as the docs for #GtkRcStyle).
5747 * Note that widget names are separated by periods in paths (see
5748 * gtk_widget_path()), so names with embedded periods may cause confusion.
5751 gtk_widget_set_name (GtkWidget *widget,
5756 g_return_if_fail (GTK_IS_WIDGET (widget));
5758 new_name = g_strdup (name);
5759 g_free (widget->name);
5760 widget->name = new_name;
5762 if (gtk_widget_has_rc_style (widget))
5763 gtk_widget_reset_rc_style (widget);
5765 g_object_notify (G_OBJECT (widget), "name");
5769 * gtk_widget_get_name:
5770 * @widget: a #GtkWidget
5772 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5773 * significance of widget names.
5775 * Return value: name of the widget. This string is owned by GTK+ and
5776 * should not be modified or freed
5778 G_CONST_RETURN gchar*
5779 gtk_widget_get_name (GtkWidget *widget)
5781 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5784 return widget->name;
5785 return G_OBJECT_TYPE_NAME (widget);
5789 * gtk_widget_set_state:
5790 * @widget: a #GtkWidget
5791 * @state: new state for @widget
5793 * This function is for use in widget implementations. Sets the state
5794 * of a widget (insensitive, prelighted, etc.) Usually you should set
5795 * the state using wrapper functions such as gtk_widget_set_sensitive().
5798 gtk_widget_set_state (GtkWidget *widget,
5801 g_return_if_fail (GTK_IS_WIDGET (widget));
5803 if (state == gtk_widget_get_state (widget))
5806 if (state == GTK_STATE_INSENSITIVE)
5807 gtk_widget_set_sensitive (widget, FALSE);
5813 data.state_restoration = FALSE;
5814 data.use_forall = FALSE;
5816 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
5818 data.parent_sensitive = TRUE;
5820 gtk_widget_propagate_state (widget, &data);
5822 if (gtk_widget_is_drawable (widget))
5823 gtk_widget_queue_draw (widget);
5828 * gtk_widget_get_state:
5829 * @widget: a #GtkWidget
5831 * Returns the widget's state. See gtk_widget_set_state().
5833 * Returns: the state of @widget.
5838 gtk_widget_get_state (GtkWidget *widget)
5840 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5842 return widget->state;
5846 * gtk_widget_set_visible:
5847 * @widget: a #GtkWidget
5848 * @visible: whether the widget should be shown or not
5850 * Sets the visibility state of @widget. Note that setting this to
5851 * %TRUE doesn't mean the widget is actually viewable, see
5852 * gtk_widget_get_visible().
5854 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5855 * but is nicer to use when the visibility of the widget depends on
5861 gtk_widget_set_visible (GtkWidget *widget,
5864 g_return_if_fail (GTK_IS_WIDGET (widget));
5866 if (visible != gtk_widget_get_visible (widget))
5869 gtk_widget_show (widget);
5871 gtk_widget_hide (widget);
5876 * gtk_widget_get_visible:
5877 * @widget: a #GtkWidget
5879 * Determines whether the widget is visible. Note that this doesn't
5880 * take into account whether the widget's parent is also visible
5881 * or the widget is obscured in any way.
5883 * See gtk_widget_set_visible().
5885 * Return value: %TRUE if the widget is visible
5890 gtk_widget_get_visible (GtkWidget *widget)
5892 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5894 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
5898 * gtk_widget_set_has_window:
5899 * @widget: a #GtkWidget
5900 * @has_window: whether or not @widget has a window.
5902 * Specifies whether @widget has a #GdkWindow of its own. Note that
5903 * all realized widgets have a non-%NULL "window" pointer
5904 * (gtk_widget_get_window() never returns a %NULL window when a widget
5905 * is realized), but for many of them it's actually the #GdkWindow of
5906 * one of its parent widgets. Widgets that create a %window for
5907 * themselves in GtkWidget::realize() however must announce this by
5908 * calling this function with @has_window = %TRUE.
5910 * This function should only be called by widget implementations,
5911 * and they should call it in their init() function.
5916 gtk_widget_set_has_window (GtkWidget *widget,
5917 gboolean has_window)
5919 g_return_if_fail (GTK_IS_WIDGET (widget));
5922 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
5924 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
5928 * gtk_widget_get_has_window:
5929 * @widget: a #GtkWidget
5931 * Determines whether @widget has a #GdkWindow of its own. See
5932 * gtk_widget_set_has_window().
5934 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5939 gtk_widget_get_has_window (GtkWidget *widget)
5941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5943 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
5947 * gtk_widget_is_toplevel:
5948 * @widget: a #GtkWidget
5950 * Determines whether @widget is a toplevel widget. Currently only
5951 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5952 * widgets have no parent widget.
5954 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5959 gtk_widget_is_toplevel (GtkWidget *widget)
5961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5963 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5967 _gtk_widget_set_is_toplevel (GtkWidget *widget,
5968 gboolean is_toplevel)
5971 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
5973 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
5977 * gtk_widget_is_drawable:
5978 * @widget: a #GtkWidget
5980 * Determines whether @widget can be drawn to. A widget can be drawn
5981 * to if it is mapped and visible.
5983 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5988 gtk_widget_is_drawable (GtkWidget *widget)
5990 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5992 return (gtk_widget_get_visible (widget) &&
5993 gtk_widget_get_mapped (widget));
5997 * gtk_widget_get_realized:
5998 * @widget: a #GtkWidget
6000 * Determines whether @widget is realized.
6002 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6007 gtk_widget_get_realized (GtkWidget *widget)
6009 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6011 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6015 * gtk_widget_set_realized:
6016 * @widget: a #GtkWidget
6017 * @realized: %TRUE to mark the widget as realized
6019 * Marks the widget as being realized.
6021 * This function should only ever be called in a derived widget's
6022 * "realize" or "unrealize" implementation.
6027 gtk_widget_set_realized (GtkWidget *widget,
6030 g_return_if_fail (GTK_IS_WIDGET (widget));
6033 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6035 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6039 * gtk_widget_get_mapped:
6040 * @widget: a #GtkWidget
6042 * Whether the widget is mapped.
6044 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6049 gtk_widget_get_mapped (GtkWidget *widget)
6051 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6053 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6057 * gtk_widget_set_mapped:
6058 * @widget: a #GtkWidget
6059 * @mapped: %TRUE to mark the widget as mapped
6061 * Marks the widget as being realized.
6063 * This function should only ever be called in a derived widget's
6064 * "map" or "unmap" implementation.
6069 gtk_widget_set_mapped (GtkWidget *widget,
6072 g_return_if_fail (GTK_IS_WIDGET (widget));
6075 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6077 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6081 * gtk_widget_set_app_paintable:
6082 * @widget: a #GtkWidget
6083 * @app_paintable: %TRUE if the application will paint on the widget
6085 * Sets whether the application intends to draw on the widget in
6086 * an #GtkWidget::expose-event handler.
6088 * This is a hint to the widget and does not affect the behavior of
6089 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6090 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6091 * the effect is to suppress default themed drawing of the widget's
6092 * background. (Children of the widget will still be drawn.) The application
6093 * is then entirely responsible for drawing the widget background.
6095 * Note that the background is still drawn when the widget is mapped.
6096 * If this is not suitable (e.g. because you want to make a transparent
6097 * window using an RGBA visual), you can work around this by doing:
6099 * gtk_widget_realize (window);
6100 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
6101 * gtk_widget_show (window);
6105 gtk_widget_set_app_paintable (GtkWidget *widget,
6106 gboolean app_paintable)
6108 g_return_if_fail (GTK_IS_WIDGET (widget));
6110 app_paintable = (app_paintable != FALSE);
6112 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6115 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6117 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6119 if (gtk_widget_is_drawable (widget))
6120 gtk_widget_queue_draw (widget);
6122 g_object_notify (G_OBJECT (widget), "app-paintable");
6127 * gtk_widget_get_app_paintable:
6128 * @widget: a #GtkWidget
6130 * Determines whether the application intends to draw on the widget in
6131 * an #GtkWidget::expose-event handler.
6133 * See gtk_widget_set_app_paintable()
6135 * Return value: %TRUE if the widget is app paintable
6140 gtk_widget_get_app_paintable (GtkWidget *widget)
6142 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6144 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6148 * gtk_widget_set_double_buffered:
6149 * @widget: a #GtkWidget
6150 * @double_buffered: %TRUE to double-buffer a widget
6152 * Widgets are double buffered by default; you can use this function
6153 * to turn off the buffering. "Double buffered" simply means that
6154 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6155 * automatically around expose events sent to the
6156 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6157 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6158 * buffer to the screen. The result is that users see the window
6159 * update in one smooth step, and don't see individual graphics
6160 * primitives being rendered.
6162 * In very simple terms, double buffered widgets don't flicker,
6163 * so you would only use this function to turn off double buffering
6164 * if you had special needs and really knew what you were doing.
6166 * Note: if you turn off double-buffering, you have to handle
6167 * expose events, since even the clearing to the background color or
6168 * pixmap will not happen automatically (as it is done in
6169 * gdk_window_begin_paint()).
6172 gtk_widget_set_double_buffered (GtkWidget *widget,
6173 gboolean double_buffered)
6175 g_return_if_fail (GTK_IS_WIDGET (widget));
6177 double_buffered = (double_buffered != FALSE);
6179 if (double_buffered != gtk_widget_get_double_buffered (widget))
6181 if (double_buffered)
6182 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6184 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6186 g_object_notify (G_OBJECT (widget), "double-buffered");
6191 * gtk_widget_get_double_buffered:
6192 * @widget: a #GtkWidget
6194 * Determines whether the widget is double buffered.
6196 * See gtk_widget_set_double_buffered()
6198 * Return value: %TRUE if the widget is double buffered
6203 gtk_widget_get_double_buffered (GtkWidget *widget)
6205 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6207 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6211 * gtk_widget_set_redraw_on_allocate:
6212 * @widget: a #GtkWidget
6213 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6214 * when it is allocated to a new size. Otherwise, only the
6215 * new portion of the widget will be redrawn.
6217 * Sets whether the entire widget is queued for drawing when its size
6218 * allocation changes. By default, this setting is %TRUE and
6219 * the entire widget is redrawn on every size change. If your widget
6220 * leaves the upper left unchanged when made bigger, turning this
6221 * setting off will improve performance.
6223 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6224 * off all allocation on resizing: the widget will not even redraw if
6225 * its position changes; this is to allow containers that don't draw
6226 * anything to avoid excess invalidations. If you set this flag on a
6227 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6228 * you are responsible for invalidating both the old and new allocation
6229 * of the widget when the widget is moved and responsible for invalidating
6230 * regions newly when the widget increases size.
6233 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6234 gboolean redraw_on_allocate)
6236 g_return_if_fail (GTK_IS_WIDGET (widget));
6238 if (redraw_on_allocate)
6239 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6241 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6245 * gtk_widget_set_sensitive:
6246 * @widget: a #GtkWidget
6247 * @sensitive: %TRUE to make the widget sensitive
6249 * Sets the sensitivity of a widget. A widget is sensitive if the user
6250 * can interact with it. Insensitive widgets are "grayed out" and the
6251 * user can't interact with them. Insensitive widgets are known as
6252 * "inactive", "disabled", or "ghosted" in some other toolkits.
6255 gtk_widget_set_sensitive (GtkWidget *widget,
6260 g_return_if_fail (GTK_IS_WIDGET (widget));
6262 sensitive = (sensitive != FALSE);
6264 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6269 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6270 data.state = widget->saved_state;
6274 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6275 data.state = gtk_widget_get_state (widget);
6277 data.state_restoration = TRUE;
6278 data.use_forall = TRUE;
6281 data.parent_sensitive = (gtk_widget_is_sensitive (widget->parent) != FALSE);
6283 data.parent_sensitive = TRUE;
6285 gtk_widget_propagate_state (widget, &data);
6286 if (gtk_widget_is_drawable (widget))
6287 gtk_widget_queue_draw (widget);
6289 g_object_notify (G_OBJECT (widget), "sensitive");
6293 * gtk_widget_get_sensitive:
6294 * @widget: a #GtkWidget
6296 * Returns the widget's sensitivity (in the sense of returning
6297 * the value that has been set using gtk_widget_set_sensitive()).
6299 * The effective sensitivity of a widget is however determined by both its
6300 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6302 * Returns: %TRUE if the widget is sensitive
6307 gtk_widget_get_sensitive (GtkWidget *widget)
6309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6311 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6315 * gtk_widget_is_sensitive:
6316 * @widget: a #GtkWidget
6318 * Returns the widget's effective sensitivity, which means
6319 * it is sensitive itself and also its parent widget is sensntive
6321 * Returns: %TRUE if the widget is effectively sensitive
6326 gtk_widget_is_sensitive (GtkWidget *widget)
6328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6330 return (gtk_widget_get_sensitive (widget) &&
6331 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6335 * gtk_widget_set_parent:
6336 * @widget: a #GtkWidget
6337 * @parent: parent container
6339 * This function is useful only when implementing subclasses of
6341 * Sets the container as the parent of @widget, and takes care of
6342 * some details such as updating the state and style of the child
6343 * to reflect its new location. The opposite function is
6344 * gtk_widget_unparent().
6347 gtk_widget_set_parent (GtkWidget *widget,
6352 g_return_if_fail (GTK_IS_WIDGET (widget));
6353 g_return_if_fail (GTK_IS_WIDGET (parent));
6354 g_return_if_fail (widget != parent);
6355 if (widget->parent != NULL)
6357 g_warning ("Can't set a parent on widget which has a parent\n");
6360 if (gtk_widget_is_toplevel (widget))
6362 g_warning ("Can't set a parent on a toplevel widget\n");
6366 /* keep this function in sync with gtk_menu_attach_to_widget()
6369 g_object_ref_sink (widget);
6370 widget->parent = parent;
6372 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6373 data.state = gtk_widget_get_state (parent);
6375 data.state = gtk_widget_get_state (widget);
6376 data.state_restoration = FALSE;
6377 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6378 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6380 gtk_widget_propagate_state (widget, &data);
6382 gtk_widget_reset_rc_styles (widget);
6384 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6385 if (GTK_WIDGET_ANCHORED (widget->parent))
6386 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6387 g_object_notify (G_OBJECT (widget), "parent");
6389 /* Enforce realized/mapped invariants
6391 if (gtk_widget_get_realized (widget->parent))
6392 gtk_widget_realize (widget);
6394 if (gtk_widget_get_visible (widget->parent) &&
6395 gtk_widget_get_visible (widget))
6397 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6398 gtk_widget_get_mapped (widget->parent))
6399 gtk_widget_map (widget);
6401 gtk_widget_queue_resize (widget);
6406 * gtk_widget_get_parent:
6407 * @widget: a #GtkWidget
6409 * Returns the parent container of @widget.
6411 * Return value: (transfer none): the parent container of @widget, or %NULL
6414 gtk_widget_get_parent (GtkWidget *widget)
6416 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6418 return widget->parent;
6421 /*****************************************
6423 * see docs/styles.txt
6424 *****************************************/
6427 * gtk_widget_style_attach:
6428 * @widget: a #GtkWidget
6430 * This function attaches the widget's #GtkStyle to the widget's
6431 * #GdkWindow. It is a replacement for
6434 * widget->style = gtk_style_attach (widget->style, widget->window);
6437 * and should only ever be called in a derived widget's "realize"
6438 * implementation which does not chain up to its parent class'
6439 * "realize" implementation, because one of the parent classes
6440 * (finally #GtkWidget) would attach the style itself.
6445 gtk_widget_style_attach (GtkWidget *widget)
6447 g_return_if_fail (GTK_IS_WIDGET (widget));
6448 g_return_if_fail (gtk_widget_get_realized (widget));
6450 widget->style = gtk_style_attach (widget->style, widget->window);
6454 * gtk_widget_has_rc_style:
6455 * @widget: a #GtkWidget
6457 * Determines if the widget style has been looked up through the rc mechanism.
6459 * Returns: %TRUE if the widget has been looked up through the rc
6460 * mechanism, %FALSE otherwise.
6465 gtk_widget_has_rc_style (GtkWidget *widget)
6467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6469 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
6473 * gtk_widget_set_style:
6474 * @widget: a #GtkWidget
6475 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
6476 * gtk_widget_set_style() and go back to the default style
6478 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6479 * want to use this function; it interacts badly with themes, because
6480 * themes work by replacing the #GtkStyle. Instead, use
6481 * gtk_widget_modify_style().
6484 gtk_widget_set_style (GtkWidget *widget,
6487 g_return_if_fail (GTK_IS_WIDGET (widget));
6491 gboolean initial_emission;
6493 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6495 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
6496 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6498 gtk_widget_set_style_internal (widget, style, initial_emission);
6502 if (GTK_WIDGET_USER_STYLE (widget))
6503 gtk_widget_reset_rc_style (widget);
6508 * gtk_widget_ensure_style:
6509 * @widget: a #GtkWidget
6511 * Ensures that @widget has a style (@widget->style). Not a very useful
6512 * function; most of the time, if you want the style, the widget is
6513 * realized, and realized widgets are guaranteed to have a style
6517 gtk_widget_ensure_style (GtkWidget *widget)
6519 g_return_if_fail (GTK_IS_WIDGET (widget));
6521 if (!GTK_WIDGET_USER_STYLE (widget) &&
6522 !gtk_widget_has_rc_style (widget))
6523 gtk_widget_reset_rc_style (widget);
6526 /* Look up the RC style for this widget, unsetting any user style that
6527 * may be in effect currently
6530 gtk_widget_reset_rc_style (GtkWidget *widget)
6532 GtkStyle *new_style = NULL;
6533 gboolean initial_emission;
6535 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
6537 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6538 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
6540 if (gtk_widget_has_screen (widget))
6541 new_style = gtk_rc_get_style (widget);
6543 new_style = gtk_widget_get_default_style ();
6545 if (initial_emission || new_style != widget->style)
6546 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6550 * gtk_widget_get_style:
6551 * @widget: a #GtkWidget
6553 * Simply an accessor function that returns @widget->style.
6555 * Return value: (transfer none): the widget's #GtkStyle
6558 gtk_widget_get_style (GtkWidget *widget)
6560 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6562 return widget->style;
6566 * gtk_widget_modify_style:
6567 * @widget: a #GtkWidget
6568 * @style: the #GtkRcStyle holding the style modifications
6570 * Modifies style values on the widget. Modifications made using this
6571 * technique take precedence over style values set via an RC file,
6572 * however, they will be overriden if a style is explicitely set on
6573 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6574 * is designed so each field can either be set or unset, so it is
6575 * possible, using this function, to modify some style values and
6576 * leave the others unchanged.
6578 * Note that modifications made with this function are not cumulative
6579 * with previous calls to gtk_widget_modify_style() or with such
6580 * functions as gtk_widget_modify_fg(). If you wish to retain
6581 * previous values, you must first call gtk_widget_get_modifier_style(),
6582 * make your modifications to the returned style, then call
6583 * gtk_widget_modify_style() with that style. On the other hand,
6584 * if you first call gtk_widget_modify_style(), subsequent calls
6585 * to such functions gtk_widget_modify_fg() will have a cumulative
6586 * effect with the initial modifications.
6589 gtk_widget_modify_style (GtkWidget *widget,
6592 g_return_if_fail (GTK_IS_WIDGET (widget));
6593 g_return_if_fail (GTK_IS_RC_STYLE (style));
6595 g_object_set_qdata_full (G_OBJECT (widget),
6597 gtk_rc_style_copy (style),
6598 (GDestroyNotify) g_object_unref);
6600 /* note that "style" may be invalid here if it was the old
6601 * modifier style and the only reference was our own.
6604 if (gtk_widget_has_rc_style (widget))
6605 gtk_widget_reset_rc_style (widget);
6609 * gtk_widget_get_modifier_style:
6610 * @widget: a #GtkWidget
6612 * Returns the current modifier style for the widget. (As set by
6613 * gtk_widget_modify_style().) If no style has previously set, a new
6614 * #GtkRcStyle will be created with all values unset, and set as the
6615 * modifier style for the widget. If you make changes to this rc
6616 * style, you must call gtk_widget_modify_style(), passing in the
6617 * returned rc style, to make sure that your changes take effect.
6619 * Caution: passing the style back to gtk_widget_modify_style() will
6620 * normally end up destroying it, because gtk_widget_modify_style() copies
6621 * the passed-in style and sets the copy as the new modifier style,
6622 * thus dropping any reference to the old modifier style. Add a reference
6623 * to the modifier style if you want to keep it alive.
6625 * Return value: (transfer none): the modifier style for the widget. This rc style is
6626 * owned by the widget. If you want to keep a pointer to value this
6627 * around, you must add a refcount using g_object_ref().
6630 gtk_widget_get_modifier_style (GtkWidget *widget)
6632 GtkRcStyle *rc_style;
6634 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6636 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6640 rc_style = gtk_rc_style_new ();
6641 g_object_set_qdata_full (G_OBJECT (widget),
6644 (GDestroyNotify) g_object_unref);
6651 gtk_widget_modify_color_component (GtkWidget *widget,
6652 GtkRcFlags component,
6654 const GdkColor *color)
6656 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6663 rc_style->fg[state] = *color;
6666 rc_style->bg[state] = *color;
6669 rc_style->text[state] = *color;
6672 rc_style->base[state] = *color;
6675 g_assert_not_reached();
6678 rc_style->color_flags[state] |= component;
6681 rc_style->color_flags[state] &= ~component;
6683 gtk_widget_modify_style (widget, rc_style);
6687 * gtk_widget_modify_symbolic_color:
6688 * @widget: a #GtkWidget
6689 * @name: the name of the symbolic color to modify
6690 * @color: (allow-none): the color to assign (does not need to be allocated),
6691 * or %NULL to undo the effect of previous calls to
6692 * of gtk_widget_modify_symbolic_color().
6694 * Sets a symbolic color for a widget.
6695 * All other style values are left untouched. See also
6696 * gtk_widget_modify_style().
6701 gtk_widget_modify_symbolic_color (GtkWidget *widget,
6703 const GdkColor *color)
6705 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6707 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
6709 gtk_widget_modify_style (widget, rc_style);
6713 * gtk_widget_modify_fg:
6714 * @widget: a #GtkWidget
6715 * @state: the state for which to set the foreground color
6716 * @color: (allow-none): the color to assign (does not need to be allocated),
6717 * or %NULL to undo the effect of previous calls to
6718 * of gtk_widget_modify_fg().
6720 * Sets the foreground color for a widget in a particular state.
6721 * All other style values are left untouched. See also
6722 * gtk_widget_modify_style().
6725 gtk_widget_modify_fg (GtkWidget *widget,
6727 const GdkColor *color)
6729 g_return_if_fail (GTK_IS_WIDGET (widget));
6730 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6732 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6736 * gtk_widget_modify_bg:
6737 * @widget: a #GtkWidget
6738 * @state: the state for which to set the background color
6739 * @color: (allow-none): the color to assign (does not need to be allocated),
6740 * or %NULL to undo the effect of previous calls to
6741 * of gtk_widget_modify_bg().
6743 * Sets the background color for a widget in a particular state.
6744 * All other style values are left untouched. See also
6745 * gtk_widget_modify_style().
6747 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6748 * draw on their parent container's window and thus may not draw any
6749 * background themselves. This is the case for e.g. #GtkLabel. To modify
6750 * the background of such widgets, you have to set the background color
6751 * on their parent; if you want to set the background of a rectangular
6752 * area around a label, try placing the label in a #GtkEventBox widget
6753 * and setting the background color on that.
6756 gtk_widget_modify_bg (GtkWidget *widget,
6758 const GdkColor *color)
6760 g_return_if_fail (GTK_IS_WIDGET (widget));
6761 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6763 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6767 * gtk_widget_modify_text:
6768 * @widget: a #GtkWidget
6769 * @state: the state for which to set the text color
6770 * @color: (allow-none): the color to assign (does not need to be allocated),
6771 * or %NULL to undo the effect of previous calls to
6772 * of gtk_widget_modify_text().
6774 * Sets the text color for a widget in a particular state. All other
6775 * style values are left untouched. The text color is the foreground
6776 * color used along with the base color (see gtk_widget_modify_base())
6777 * for widgets such as #GtkEntry and #GtkTextView. See also
6778 * gtk_widget_modify_style().
6781 gtk_widget_modify_text (GtkWidget *widget,
6783 const GdkColor *color)
6785 g_return_if_fail (GTK_IS_WIDGET (widget));
6786 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6788 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6792 * gtk_widget_modify_base:
6793 * @widget: a #GtkWidget
6794 * @state: the state for which to set the base color
6795 * @color: (allow-none): the color to assign (does not need to be allocated),
6796 * or %NULL to undo the effect of previous calls to
6797 * of gtk_widget_modify_base().
6799 * Sets the base color for a widget in a particular state.
6800 * All other style values are left untouched. The base color
6801 * is the background color used along with the text color
6802 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6803 * and #GtkTextView. See also gtk_widget_modify_style().
6805 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6806 * draw on their parent container's window and thus may not draw any
6807 * background themselves. This is the case for e.g. #GtkLabel. To modify
6808 * the background of such widgets, you have to set the base color on their
6809 * parent; if you want to set the background of a rectangular area around
6810 * a label, try placing the label in a #GtkEventBox widget and setting
6811 * the base color on that.
6814 gtk_widget_modify_base (GtkWidget *widget,
6816 const GdkColor *color)
6818 g_return_if_fail (GTK_IS_WIDGET (widget));
6819 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6821 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6825 modify_color_property (GtkWidget *widget,
6826 GtkRcStyle *rc_style,
6828 const GdkColor *color)
6830 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6831 GQuark property_name = g_quark_from_string (name);
6835 GtkRcProperty rc_property = {0};
6838 rc_property.type_name = type_name;
6839 rc_property.property_name = property_name;
6840 rc_property.origin = NULL;
6842 color_name = gdk_color_to_string (color);
6843 g_value_init (&rc_property.value, G_TYPE_STRING);
6844 g_value_take_string (&rc_property.value, color_name);
6846 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6848 g_value_unset (&rc_property.value);
6851 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6855 * gtk_widget_modify_cursor:
6856 * @widget: a #GtkWidget
6857 * @primary: the color to use for primary cursor (does not need to be
6858 * allocated), or %NULL to undo the effect of previous calls to
6859 * of gtk_widget_modify_cursor().
6860 * @secondary: the color to use for secondary cursor (does not need to be
6861 * allocated), or %NULL to undo the effect of previous calls to
6862 * of gtk_widget_modify_cursor().
6864 * Sets the cursor color to use in a widget, overriding the
6865 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6866 * style properties. All other style values are left untouched.
6867 * See also gtk_widget_modify_style().
6872 gtk_widget_modify_cursor (GtkWidget *widget,
6873 const GdkColor *primary,
6874 const GdkColor *secondary)
6876 GtkRcStyle *rc_style;
6878 g_return_if_fail (GTK_IS_WIDGET (widget));
6880 rc_style = gtk_widget_get_modifier_style (widget);
6882 modify_color_property (widget, rc_style, "cursor-color", primary);
6883 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6885 gtk_widget_modify_style (widget, rc_style);
6889 * gtk_widget_modify_font:
6890 * @widget: a #GtkWidget
6891 * @font_desc: (allow-none): the font description to use, or %NULL to undo
6892 * the effect of previous calls to gtk_widget_modify_font().
6894 * Sets the font to use for a widget. All other style values are left
6895 * untouched. See also gtk_widget_modify_style().
6898 gtk_widget_modify_font (GtkWidget *widget,
6899 PangoFontDescription *font_desc)
6901 GtkRcStyle *rc_style;
6903 g_return_if_fail (GTK_IS_WIDGET (widget));
6905 rc_style = gtk_widget_get_modifier_style (widget);
6907 if (rc_style->font_desc)
6908 pango_font_description_free (rc_style->font_desc);
6911 rc_style->font_desc = pango_font_description_copy (font_desc);
6913 rc_style->font_desc = NULL;
6915 gtk_widget_modify_style (widget, rc_style);
6919 gtk_widget_real_direction_changed (GtkWidget *widget,
6920 GtkTextDirection previous_direction)
6922 gtk_widget_queue_resize (widget);
6926 gtk_widget_real_style_set (GtkWidget *widget,
6927 GtkStyle *previous_style)
6929 if (gtk_widget_get_realized (widget) &&
6930 gtk_widget_get_has_window (widget))
6931 gtk_style_set_background (widget->style, widget->window, widget->state);
6935 gtk_widget_set_style_internal (GtkWidget *widget,
6937 gboolean initial_emission)
6939 g_object_ref (widget);
6940 g_object_freeze_notify (G_OBJECT (widget));
6942 if (widget->style != style)
6944 GtkStyle *previous_style;
6946 if (gtk_widget_get_realized (widget))
6948 gtk_widget_reset_shapes (widget);
6949 gtk_style_detach (widget->style);
6952 previous_style = widget->style;
6953 widget->style = style;
6954 g_object_ref (widget->style);
6956 if (gtk_widget_get_realized (widget))
6957 widget->style = gtk_style_attach (widget->style, widget->window);
6959 gtk_widget_update_pango_context (widget);
6960 g_signal_emit (widget,
6961 widget_signals[STYLE_SET],
6963 initial_emission ? NULL : previous_style);
6964 g_object_unref (previous_style);
6966 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6967 gtk_widget_queue_resize (widget);
6969 else if (initial_emission)
6971 gtk_widget_update_pango_context (widget);
6972 g_signal_emit (widget,
6973 widget_signals[STYLE_SET],
6977 g_object_notify (G_OBJECT (widget), "style");
6978 g_object_thaw_notify (G_OBJECT (widget));
6979 g_object_unref (widget);
6983 GtkWidget *previous_toplevel;
6984 GdkScreen *previous_screen;
6985 GdkScreen *new_screen;
6986 } HierarchyChangedInfo;
6989 do_screen_change (GtkWidget *widget,
6990 GdkScreen *old_screen,
6991 GdkScreen *new_screen)
6993 if (old_screen != new_screen)
6997 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6999 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7002 _gtk_tooltip_hide (widget);
7003 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7008 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7009 gpointer client_data)
7011 HierarchyChangedInfo *info = client_data;
7012 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7013 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
7015 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7017 g_object_ref (widget);
7020 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7022 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7024 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7025 do_screen_change (widget, info->previous_screen, info->new_screen);
7027 if (GTK_IS_CONTAINER (widget))
7028 gtk_container_forall (GTK_CONTAINER (widget),
7029 gtk_widget_propagate_hierarchy_changed_recurse,
7032 g_object_unref (widget);
7037 * _gtk_widget_propagate_hierarchy_changed:
7038 * @widget: a #GtkWidget
7039 * @previous_toplevel: Previous toplevel
7041 * Propagates changes in the anchored state to a widget and all
7042 * children, unsetting or setting the %ANCHORED flag, and
7043 * emitting #GtkWidget::hierarchy-changed.
7046 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7047 GtkWidget *previous_toplevel)
7049 HierarchyChangedInfo info;
7051 info.previous_toplevel = previous_toplevel;
7052 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7054 if (gtk_widget_is_toplevel (widget) ||
7055 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
7056 info.new_screen = gtk_widget_get_screen (widget);
7058 info.new_screen = NULL;
7060 if (info.previous_screen)
7061 g_object_ref (info.previous_screen);
7062 if (previous_toplevel)
7063 g_object_ref (previous_toplevel);
7065 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7067 if (previous_toplevel)
7068 g_object_unref (previous_toplevel);
7069 if (info.previous_screen)
7070 g_object_unref (info.previous_screen);
7074 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7075 gpointer client_data)
7077 HierarchyChangedInfo *info = client_data;
7079 g_object_ref (widget);
7081 do_screen_change (widget, info->previous_screen, info->new_screen);
7083 if (GTK_IS_CONTAINER (widget))
7084 gtk_container_forall (GTK_CONTAINER (widget),
7085 gtk_widget_propagate_screen_changed_recurse,
7088 g_object_unref (widget);
7092 * gtk_widget_is_composited:
7093 * @widget: a #GtkWidget
7095 * Whether @widget can rely on having its alpha channel
7096 * drawn correctly. On X11 this function returns whether a
7097 * compositing manager is running for @widget's screen.
7099 * Please note that the semantics of this call will change
7100 * in the future if used on a widget that has a composited
7101 * window in its hierarchy (as set by gdk_window_set_composited()).
7103 * Return value: %TRUE if the widget can rely on its alpha
7104 * channel being drawn correctly.
7109 gtk_widget_is_composited (GtkWidget *widget)
7113 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7115 screen = gtk_widget_get_screen (widget);
7117 return gdk_screen_is_composited (screen);
7121 propagate_composited_changed (GtkWidget *widget,
7124 if (GTK_IS_CONTAINER (widget))
7126 gtk_container_forall (GTK_CONTAINER (widget),
7127 propagate_composited_changed,
7131 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7135 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7137 propagate_composited_changed (widget, NULL);
7141 * _gtk_widget_propagate_screen_changed:
7142 * @widget: a #GtkWidget
7143 * @previous_screen: Previous screen
7145 * Propagates changes in the screen for a widget to all
7146 * children, emitting #GtkWidget::screen-changed.
7149 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7150 GdkScreen *previous_screen)
7152 HierarchyChangedInfo info;
7154 info.previous_screen = previous_screen;
7155 info.new_screen = gtk_widget_get_screen (widget);
7157 if (previous_screen)
7158 g_object_ref (previous_screen);
7160 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7162 if (previous_screen)
7163 g_object_unref (previous_screen);
7167 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7169 if (gtk_widget_has_rc_style (widget))
7170 gtk_widget_reset_rc_style (widget);
7172 if (GTK_IS_CONTAINER (widget))
7173 gtk_container_forall (GTK_CONTAINER (widget),
7174 reset_rc_styles_recurse,
7180 * gtk_widget_reset_rc_styles:
7181 * @widget: a #GtkWidget.
7183 * Reset the styles of @widget and all descendents, so when
7184 * they are looked up again, they get the correct values
7185 * for the currently loaded RC file settings.
7187 * This function is not useful for applications.
7190 gtk_widget_reset_rc_styles (GtkWidget *widget)
7192 g_return_if_fail (GTK_IS_WIDGET (widget));
7194 reset_rc_styles_recurse (widget, NULL);
7198 * gtk_widget_get_default_style:
7200 * Returns the default style used by all widgets initially.
7202 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7203 * by GTK+ and should not be modified or freed.
7206 gtk_widget_get_default_style (void)
7208 if (!gtk_default_style)
7210 gtk_default_style = gtk_style_new ();
7211 g_object_ref (gtk_default_style);
7214 return gtk_default_style;
7217 static PangoContext *
7218 gtk_widget_peek_pango_context (GtkWidget *widget)
7220 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7224 * gtk_widget_get_pango_context:
7225 * @widget: a #GtkWidget
7227 * Gets a #PangoContext with the appropriate font map, font description,
7228 * and base direction for this widget. Unlike the context returned
7229 * by gtk_widget_create_pango_context(), this context is owned by
7230 * the widget (it can be used until the screen for the widget changes
7231 * or the widget is removed from its toplevel), and will be updated to
7232 * match any changes to the widget's attributes.
7234 * If you create and keep a #PangoLayout using this context, you must
7235 * deal with changes to the context by calling pango_layout_context_changed()
7236 * on the layout in response to the #GtkWidget::style-set and
7237 * #GtkWidget::direction-changed signals for the widget.
7239 * Return value: (transfer none): the #PangoContext for the widget.
7242 gtk_widget_get_pango_context (GtkWidget *widget)
7244 PangoContext *context;
7246 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7248 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7251 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7252 g_object_set_qdata_full (G_OBJECT (widget),
7253 quark_pango_context,
7262 update_pango_context (GtkWidget *widget,
7263 PangoContext *context)
7265 pango_context_set_font_description (context, widget->style->font_desc);
7266 pango_context_set_base_dir (context,
7267 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7268 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7272 gtk_widget_update_pango_context (GtkWidget *widget)
7274 PangoContext *context = gtk_widget_peek_pango_context (widget);
7280 update_pango_context (widget, context);
7282 screen = gtk_widget_get_screen_unchecked (widget);
7285 pango_cairo_context_set_resolution (context,
7286 gdk_screen_get_resolution (screen));
7287 pango_cairo_context_set_font_options (context,
7288 gdk_screen_get_font_options (screen));
7294 * gtk_widget_create_pango_context:
7295 * @widget: a #GtkWidget
7297 * Creates a new #PangoContext with the appropriate font map,
7298 * font description, and base direction for drawing text for
7299 * this widget. See also gtk_widget_get_pango_context().
7301 * Return value: the new #PangoContext
7304 gtk_widget_create_pango_context (GtkWidget *widget)
7307 PangoContext *context;
7309 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7311 screen = gtk_widget_get_screen_unchecked (widget);
7314 GTK_NOTE (MULTIHEAD,
7315 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7317 screen = gdk_screen_get_default ();
7320 context = gdk_pango_context_get_for_screen (screen);
7322 update_pango_context (widget, context);
7323 pango_context_set_language (context, gtk_get_default_language ());
7329 * gtk_widget_create_pango_layout:
7330 * @widget: a #GtkWidget
7331 * @text: text to set on the layout (can be %NULL)
7333 * Creates a new #PangoLayout with the appropriate font map,
7334 * font description, and base direction for drawing text for
7337 * If you keep a #PangoLayout created in this way around, in order to
7338 * notify the layout of changes to the base direction or font of this
7339 * widget, you must call pango_layout_context_changed() in response to
7340 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7343 * Return value: the new #PangoLayout
7346 gtk_widget_create_pango_layout (GtkWidget *widget,
7349 PangoLayout *layout;
7350 PangoContext *context;
7352 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7354 context = gtk_widget_get_pango_context (widget);
7355 layout = pango_layout_new (context);
7358 pango_layout_set_text (layout, text, -1);
7364 * gtk_widget_render_icon:
7365 * @widget: a #GtkWidget
7366 * @stock_id: a stock ID
7367 * @size: (type int) a stock size. A size of (GtkIconSize)-1 means
7368 * render at the size of the source and don't scale (if there are
7369 * multiple source sizes, GTK+ picks one of the available sizes).
7370 * @detail: (allow-none): render detail to pass to theme engine
7372 * A convenience function that uses the theme engine and RC file
7373 * settings for @widget to look up @stock_id and render it to
7374 * a pixbuf. @stock_id should be a stock icon ID such as
7375 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7376 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7377 * identifies the widget or code doing the rendering, so that
7378 * theme engines can special-case rendering for that widget or code.
7380 * The pixels in the returned #GdkPixbuf are shared with the rest of
7381 * the application and should not be modified. The pixbuf should be freed
7382 * after use with g_object_unref().
7384 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7387 gtk_widget_render_icon (GtkWidget *widget,
7388 const gchar *stock_id,
7390 const gchar *detail)
7392 GtkIconSet *icon_set;
7395 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7396 g_return_val_if_fail (stock_id != NULL, NULL);
7397 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7399 gtk_widget_ensure_style (widget);
7401 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7403 if (icon_set == NULL)
7406 retval = gtk_icon_set_render_icon (icon_set,
7408 gtk_widget_get_direction (widget),
7409 gtk_widget_get_state (widget),
7418 * gtk_widget_set_parent_window:
7419 * @widget: a #GtkWidget.
7420 * @parent_window: the new parent window.
7422 * Sets a non default parent window for @widget.
7425 gtk_widget_set_parent_window (GtkWidget *widget,
7426 GdkWindow *parent_window)
7428 GdkWindow *old_parent_window;
7430 g_return_if_fail (GTK_IS_WIDGET (widget));
7432 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7433 quark_parent_window);
7435 if (parent_window != old_parent_window)
7437 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7439 if (old_parent_window)
7440 g_object_unref (old_parent_window);
7442 g_object_ref (parent_window);
7447 * gtk_widget_get_parent_window:
7448 * @widget: a #GtkWidget.
7450 * Gets @widget's parent window.
7452 * Returns: (transfer none): the parent window of @widget.
7455 gtk_widget_get_parent_window (GtkWidget *widget)
7457 GdkWindow *parent_window;
7459 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7461 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7463 return (parent_window != NULL) ? parent_window :
7464 (widget->parent != NULL) ? widget->parent->window : NULL;
7469 * gtk_widget_set_child_visible:
7470 * @widget: a #GtkWidget
7471 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7473 * Sets whether @widget should be mapped along with its when its parent
7474 * is mapped and @widget has been shown with gtk_widget_show().
7476 * The child visibility can be set for widget before it is added to
7477 * a container with gtk_widget_set_parent(), to avoid mapping
7478 * children unnecessary before immediately unmapping them. However
7479 * it will be reset to its default state of %TRUE when the widget
7480 * is removed from a container.
7482 * Note that changing the child visibility of a widget does not
7483 * queue a resize on the widget. Most of the time, the size of
7484 * a widget is computed from all visible children, whether or
7485 * not they are mapped. If this is not the case, the container
7486 * can queue a resize itself.
7488 * This function is only useful for container implementations and
7489 * never should be called by an application.
7492 gtk_widget_set_child_visible (GtkWidget *widget,
7493 gboolean is_visible)
7495 g_return_if_fail (GTK_IS_WIDGET (widget));
7496 g_return_if_fail (!gtk_widget_is_toplevel (widget));
7498 g_object_ref (widget);
7501 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7504 GtkWidget *toplevel;
7506 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7508 toplevel = gtk_widget_get_toplevel (widget);
7509 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
7510 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7513 if (widget->parent && gtk_widget_get_realized (widget->parent))
7515 if (gtk_widget_get_mapped (widget->parent) &&
7516 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7517 gtk_widget_get_visible (widget))
7518 gtk_widget_map (widget);
7520 gtk_widget_unmap (widget);
7523 g_object_unref (widget);
7527 * gtk_widget_get_child_visible:
7528 * @widget: a #GtkWidget
7530 * Gets the value set with gtk_widget_set_child_visible().
7531 * If you feel a need to use this function, your code probably
7532 * needs reorganization.
7534 * This function is only useful for container implementations and
7535 * never should be called by an application.
7537 * Return value: %TRUE if the widget is mapped with the parent.
7540 gtk_widget_get_child_visible (GtkWidget *widget)
7542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7544 return GTK_WIDGET_CHILD_VISIBLE (widget);
7548 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7550 GtkWidget *toplevel;
7552 toplevel = gtk_widget_get_toplevel (widget);
7554 if (gtk_widget_is_toplevel (toplevel))
7556 if (GTK_IS_WINDOW (toplevel))
7557 return GTK_WINDOW (toplevel)->screen;
7558 else if (GTK_IS_INVISIBLE (toplevel))
7559 return GTK_INVISIBLE (widget)->screen;
7566 * gtk_widget_get_screen:
7567 * @widget: a #GtkWidget
7569 * Get the #GdkScreen from the toplevel window associated with
7570 * this widget. This function can only be called after the widget
7571 * has been added to a widget hierarchy with a #GtkWindow
7574 * In general, you should only create screen specific
7575 * resources when a widget has been realized, and you should
7576 * free those resources when the widget is unrealized.
7578 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
7583 gtk_widget_get_screen (GtkWidget *widget)
7587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7589 screen = gtk_widget_get_screen_unchecked (widget);
7596 g_warning (G_STRLOC ": Can't get associated screen"
7597 " for a widget unless it is inside a toplevel GtkWindow\n"
7598 " widget type is %s associated top level type is %s",
7599 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7600 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7602 return gdk_screen_get_default ();
7607 * gtk_widget_has_screen:
7608 * @widget: a #GtkWidget
7610 * Checks whether there is a #GdkScreen is associated with
7611 * this widget. All toplevel widgets have an associated
7612 * screen, and all widgets added into a hierarchy with a toplevel
7613 * window at the top.
7615 * Return value: %TRUE if there is a #GdkScreen associcated
7621 gtk_widget_has_screen (GtkWidget *widget)
7623 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7625 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7629 * gtk_widget_get_display:
7630 * @widget: a #GtkWidget
7632 * Get the #GdkDisplay for the toplevel window associated with
7633 * this widget. This function can only be called after the widget
7634 * has been added to a widget hierarchy with a #GtkWindow at the top.
7636 * In general, you should only create display specific
7637 * resources when a widget has been realized, and you should
7638 * free those resources when the widget is unrealized.
7640 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
7645 gtk_widget_get_display (GtkWidget *widget)
7647 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7649 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7653 * gtk_widget_get_root_window:
7654 * @widget: a #GtkWidget
7656 * Get the root window where this widget is located. This function can
7657 * only be called after the widget has been added to a widget
7658 * hierarchy with #GtkWindow at the top.
7660 * The root window is useful for such purposes as creating a popup
7661 * #GdkWindow associated with the window. In general, you should only
7662 * create display specific resources when a widget has been realized,
7663 * and you should free those resources when the widget is unrealized.
7665 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
7670 gtk_widget_get_root_window (GtkWidget *widget)
7672 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7674 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7678 * gtk_widget_child_focus:
7679 * @widget: a #GtkWidget
7680 * @direction: direction of focus movement
7682 * This function is used by custom widget implementations; if you're
7683 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7684 * to a particular widget, and gtk_container_set_focus_chain() to
7685 * change the focus tab order. So you may want to investigate those
7686 * functions instead.
7688 * gtk_widget_child_focus() is called by containers as the user moves
7689 * around the window using keyboard shortcuts. @direction indicates
7690 * what kind of motion is taking place (up, down, left, right, tab
7691 * forward, tab backward). gtk_widget_child_focus() emits the
7692 * #GtkWidget::focus signal; widgets override the default handler
7693 * for this signal in order to implement appropriate focus behavior.
7695 * The default ::focus handler for a widget should return %TRUE if
7696 * moving in @direction left the focus on a focusable location inside
7697 * that widget, and %FALSE if moving in @direction moved the focus
7698 * outside the widget. If returning %TRUE, widgets normally
7699 * call gtk_widget_grab_focus() to place the focus accordingly;
7700 * if returning %FALSE, they don't modify the current focus location.
7702 * This function replaces gtk_container_focus() from GTK+ 1.2.
7703 * It was necessary to check that the child was visible, sensitive,
7704 * and focusable before calling gtk_container_focus().
7705 * gtk_widget_child_focus() returns %FALSE if the widget is not
7706 * currently in a focusable state, so there's no need for those checks.
7708 * Return value: %TRUE if focus ended up inside @widget
7711 gtk_widget_child_focus (GtkWidget *widget,
7712 GtkDirectionType direction)
7714 gboolean return_val;
7716 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7718 if (!gtk_widget_get_visible (widget) ||
7719 !gtk_widget_is_sensitive (widget))
7722 /* child widgets must set CAN_FOCUS, containers
7723 * don't have to though.
7725 if (!GTK_IS_CONTAINER (widget) &&
7726 !gtk_widget_get_can_focus (widget))
7729 g_signal_emit (widget,
7730 widget_signals[FOCUS],
7732 direction, &return_val);
7738 * gtk_widget_keynav_failed:
7739 * @widget: a #GtkWidget
7740 * @direction: direction of focus movement
7742 * This function should be called whenever keyboard navigation within
7743 * a single widget hits a boundary. The function emits the
7744 * #GtkWidget::keynav-failed signal on the widget and its return
7745 * value should be interpreted in a way similar to the return value of
7746 * gtk_widget_child_focus():
7748 * When %TRUE is returned, stay in the widget, the failed keyboard
7749 * navigation is Ok and/or there is nowhere we can/should move the
7752 * When %FALSE is returned, the caller should continue with keyboard
7753 * navigation outside the widget, e.g. by calling
7754 * gtk_widget_child_focus() on the widget's toplevel.
7756 * The default ::keynav-failed handler returns %TRUE for
7757 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7758 * values of #GtkDirectionType, it looks at the
7759 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7760 * if the setting is %TRUE. This way the entire user interface
7761 * becomes cursor-navigatable on input devices such as mobile phones
7762 * which only have cursor keys but no tab key.
7764 * Whenever the default handler returns %TRUE, it also calls
7765 * gtk_widget_error_bell() to notify the user of the failed keyboard
7768 * A use case for providing an own implementation of ::keynav-failed
7769 * (either by connecting to it or by overriding it) would be a row of
7770 * #GtkEntry widgets where the user should be able to navigate the
7771 * entire row with the cursor keys, as e.g. known from user interfaces
7772 * that require entering license keys.
7774 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7775 * if the emitting widget should try to handle the keyboard
7776 * navigation attempt in its parent container(s).
7781 gtk_widget_keynav_failed (GtkWidget *widget,
7782 GtkDirectionType direction)
7784 gboolean return_val;
7786 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7788 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7789 direction, &return_val);
7795 * gtk_widget_error_bell:
7796 * @widget: a #GtkWidget
7798 * Notifies the user about an input-related error on this widget.
7799 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7800 * gdk_window_beep(), otherwise it does nothing.
7802 * Note that the effect of gdk_window_beep() can be configured in many
7803 * ways, depending on the windowing backend and the desktop environment
7804 * or window manager that is used.
7809 gtk_widget_error_bell (GtkWidget *widget)
7811 GtkSettings* settings;
7814 g_return_if_fail (GTK_IS_WIDGET (widget));
7816 settings = gtk_widget_get_settings (widget);
7820 g_object_get (settings,
7821 "gtk-error-bell", &beep,
7824 if (beep && widget->window)
7825 gdk_window_beep (widget->window);
7829 * gtk_widget_set_uposition:
7830 * @widget: a #GtkWidget
7831 * @x: x position; -1 to unset x; -2 to leave x unchanged
7832 * @y: y position; -1 to unset y; -2 to leave y unchanged
7835 * Sets the position of a widget. The funny "u" in the name comes from
7836 * the "user position" hint specified by the X Window System, and
7837 * exists for legacy reasons. This function doesn't work if a widget
7838 * is inside a container; it's only really useful on #GtkWindow.
7840 * Don't use this function to center dialogs over the main application
7841 * window; most window managers will do the centering on your behalf
7842 * if you call gtk_window_set_transient_for(), and it's really not
7843 * possible to get the centering to work correctly in all cases from
7844 * application code. But if you insist, use gtk_window_set_position()
7845 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7848 * Note that although @x and @y can be individually unset, the position
7849 * is not honoured unless both @x and @y are set.
7852 gtk_widget_set_uposition (GtkWidget *widget,
7856 /* FIXME this function is the only place that aux_info->x and
7857 * aux_info->y are even used I believe, and this function is
7858 * deprecated. Should be cleaned up.
7860 * (Actually, size_allocate uses them) -Yosh
7863 GtkWidgetAuxInfo *aux_info;
7865 g_return_if_fail (GTK_IS_WIDGET (widget));
7867 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7872 aux_info->x_set = FALSE;
7875 aux_info->x_set = TRUE;
7883 aux_info->y_set = FALSE;
7886 aux_info->y_set = TRUE;
7891 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7892 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7894 if (gtk_widget_get_visible (widget) && widget->parent)
7895 gtk_widget_size_allocate (widget, &widget->allocation);
7899 gtk_widget_set_usize_internal (GtkWidget *widget,
7903 GtkWidgetAuxInfo *aux_info;
7904 gboolean changed = FALSE;
7906 g_object_freeze_notify (G_OBJECT (widget));
7908 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7910 if (width > -2 && aux_info->width != width)
7912 g_object_notify (G_OBJECT (widget), "width-request");
7913 aux_info->width = width;
7916 if (height > -2 && aux_info->height != height)
7918 g_object_notify (G_OBJECT (widget), "height-request");
7919 aux_info->height = height;
7923 if (gtk_widget_get_visible (widget) && changed)
7924 gtk_widget_queue_resize (widget);
7926 g_object_thaw_notify (G_OBJECT (widget));
7930 * gtk_widget_set_usize:
7931 * @widget: a #GtkWidget
7932 * @width: minimum width, or -1 to unset
7933 * @height: minimum height, or -1 to unset
7935 * Sets the minimum size of a widget; that is, the widget's size
7936 * request will be @width by @height. You can use this function to
7937 * force a widget to be either larger or smaller than it is. The
7938 * strange "usize" name dates from the early days of GTK+, and derives
7939 * from X Window System terminology. In many cases,
7940 * gtk_window_set_default_size() is a better choice for toplevel
7941 * windows than this function; setting the default size will still
7942 * allow users to shrink the window. Setting the usize will force them
7943 * to leave the window at least as large as the usize. When dealing
7944 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7947 * Note the inherent danger of setting any fixed size - themes,
7948 * translations into other languages, different fonts, and user action
7949 * can all change the appropriate size for a given widget. So, it's
7950 * basically impossible to hardcode a size that will always be
7953 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7956 gtk_widget_set_usize (GtkWidget *widget,
7960 g_return_if_fail (GTK_IS_WIDGET (widget));
7962 gtk_widget_set_usize_internal (widget, width, height);
7966 * gtk_widget_set_size_request:
7967 * @widget: a #GtkWidget
7968 * @width: width @widget should request, or -1 to unset
7969 * @height: height @widget should request, or -1 to unset
7971 * Sets the minimum size of a widget; that is, the widget's size
7972 * request will be @width by @height. You can use this function to
7973 * force a widget to be either larger or smaller than it normally
7976 * In most cases, gtk_window_set_default_size() is a better choice for
7977 * toplevel windows than this function; setting the default size will
7978 * still allow users to shrink the window. Setting the size request
7979 * will force them to leave the window at least as large as the size
7980 * request. When dealing with window sizes,
7981 * gtk_window_set_geometry_hints() can be a useful function as well.
7983 * Note the inherent danger of setting any fixed size - themes,
7984 * translations into other languages, different fonts, and user action
7985 * can all change the appropriate size for a given widget. So, it's
7986 * basically impossible to hardcode a size that will always be
7989 * The size request of a widget is the smallest size a widget can
7990 * accept while still functioning well and drawing itself correctly.
7991 * However in some strange cases a widget may be allocated less than
7992 * its requested size, and in many cases a widget may be allocated more
7993 * space than it requested.
7995 * If the size request in a given direction is -1 (unset), then
7996 * the "natural" size request of the widget will be used instead.
7998 * Widgets can't actually be allocated a size less than 1 by 1, but
7999 * you can pass 0,0 to this function to mean "as small as possible."
8002 gtk_widget_set_size_request (GtkWidget *widget,
8006 g_return_if_fail (GTK_IS_WIDGET (widget));
8007 g_return_if_fail (width >= -1);
8008 g_return_if_fail (height >= -1);
8015 gtk_widget_set_usize_internal (widget, width, height);
8020 * gtk_widget_get_size_request:
8021 * @widget: a #GtkWidget
8022 * @width: (allow-none): (out): return location for width, or %NULL
8023 * @height: (allow-none): (out): return location for height, or %NULL
8025 * Gets the size request that was explicitly set for the widget using
8026 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8027 * @height indicates that that dimension has not been set explicitly
8028 * and the natural requisition of the widget will be used intead. See
8029 * gtk_widget_set_size_request(). To get the size a widget will
8030 * actually use, call gtk_widget_size_request() instead of
8034 gtk_widget_get_size_request (GtkWidget *widget,
8038 GtkWidgetAuxInfo *aux_info;
8040 g_return_if_fail (GTK_IS_WIDGET (widget));
8042 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
8045 *width = aux_info ? aux_info->width : -1;
8048 *height = aux_info ? aux_info->height : -1;
8052 * gtk_widget_set_events:
8053 * @widget: a #GtkWidget
8054 * @events: event mask
8056 * Sets the event mask (see #GdkEventMask) for a widget. The event
8057 * mask determines which events a widget will receive. Keep in mind
8058 * that different widgets have different default event masks, and by
8059 * changing the event mask you may disrupt a widget's functionality,
8060 * so be careful. This function must be called while a widget is
8061 * unrealized. Consider gtk_widget_add_events() for widgets that are
8062 * already realized, or if you want to preserve the existing event
8063 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8064 * to get events on those widgets, place them inside a #GtkEventBox
8065 * and receive events on the event box.
8068 gtk_widget_set_events (GtkWidget *widget,
8071 g_return_if_fail (GTK_IS_WIDGET (widget));
8072 g_return_if_fail (!gtk_widget_get_realized (widget));
8074 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8075 GINT_TO_POINTER (events));
8076 g_object_notify (G_OBJECT (widget), "events");
8080 gtk_widget_add_events_internal (GtkWidget *widget,
8086 for (l = window_list; l != NULL; l = l->next)
8088 GdkWindow *window = l->data;
8091 gdk_window_get_user_data (window, &user_data);
8092 if (user_data == widget)
8096 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8098 children = gdk_window_get_children (window);
8099 gtk_widget_add_events_internal (widget, events, children);
8100 g_list_free (children);
8106 * gtk_widget_add_events:
8107 * @widget: a #GtkWidget
8108 * @events: an event mask, see #GdkEventMask
8110 * Adds the events in the bitfield @events to the event mask for
8111 * @widget. See gtk_widget_set_events() for details.
8114 gtk_widget_add_events (GtkWidget *widget,
8119 g_return_if_fail (GTK_IS_WIDGET (widget));
8121 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8122 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8123 GINT_TO_POINTER (old_events | events));
8125 if (gtk_widget_get_realized (widget))
8129 if (!gtk_widget_get_has_window (widget))
8130 window_list = gdk_window_get_children (widget->window);
8132 window_list = g_list_prepend (NULL, widget->window);
8134 gtk_widget_add_events_internal (widget, events, window_list);
8136 g_list_free (window_list);
8139 g_object_notify (G_OBJECT (widget), "events");
8143 * gtk_widget_set_extension_events:
8144 * @widget: a #GtkWidget
8145 * @mode: bitfield of extension events to receive
8147 * Sets the extension events mask to @mode. See #GdkExtensionMode
8148 * and gdk_input_set_extension_events().
8151 gtk_widget_set_extension_events (GtkWidget *widget,
8152 GdkExtensionMode mode)
8154 g_return_if_fail (GTK_IS_WIDGET (widget));
8156 if (gtk_widget_get_realized (widget))
8157 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8159 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8160 GINT_TO_POINTER (mode));
8161 g_object_notify (G_OBJECT (widget), "extension-events");
8165 * gtk_widget_get_toplevel:
8166 * @widget: a #GtkWidget
8168 * This function returns the topmost widget in the container hierarchy
8169 * @widget is a part of. If @widget has no parent widgets, it will be
8170 * returned as the topmost widget. No reference will be added to the
8171 * returned widget; it should not be unreferenced.
8173 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8174 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8176 * %NULL if @widget wasn't inside a toplevel window, and if the
8177 * window was inside a #GtkWindow-derived widget which was in turn
8178 * inside the toplevel #GtkWindow. While the second case may
8179 * seem unlikely, it actually happens when a #GtkPlug is embedded
8180 * inside a #GtkSocket within the same application.
8182 * To reliably find the toplevel #GtkWindow, use
8183 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8184 * is set on the result.
8186 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8187 * if (gtk_widget_is_toplevel (toplevel))
8189 * /* Perform action on toplevel. */
8193 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8194 * if there's no ancestor.
8197 gtk_widget_get_toplevel (GtkWidget *widget)
8199 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8201 while (widget->parent)
8202 widget = widget->parent;
8208 * gtk_widget_get_ancestor:
8209 * @widget: a #GtkWidget
8210 * @widget_type: ancestor type
8212 * Gets the first ancestor of @widget with type @widget_type. For example,
8213 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8214 * the first #GtkBox that's an ancestor of @widget. No reference will be
8215 * added to the returned widget; it should not be unreferenced. See note
8216 * about checking for a toplevel #GtkWindow in the docs for
8217 * gtk_widget_get_toplevel().
8219 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8220 * considers @widget to be an ancestor of itself.
8222 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8225 gtk_widget_get_ancestor (GtkWidget *widget,
8228 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8230 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8231 widget = widget->parent;
8233 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8240 * gtk_widget_get_colormap:
8241 * @widget: a #GtkWidget
8243 * Gets the colormap that will be used to render @widget. No reference will
8244 * be added to the returned colormap; it should not be unreferenced.
8246 * Return value: (transfer none): the colormap used by @widget
8249 gtk_widget_get_colormap (GtkWidget *widget)
8251 GdkColormap *colormap;
8252 GtkWidget *tmp_widget;
8254 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8258 colormap = gdk_drawable_get_colormap (widget->window);
8259 /* If window was destroyed previously, we'll get NULL here */
8264 tmp_widget = widget;
8267 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
8271 tmp_widget= tmp_widget->parent;
8274 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
8278 * gtk_widget_get_visual:
8279 * @widget: a #GtkWidget
8281 * Gets the visual that will be used to render @widget.
8283 * Return value: (transfer none): the visual for @widget
8286 gtk_widget_get_visual (GtkWidget *widget)
8288 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8290 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
8294 * gtk_widget_get_settings:
8295 * @widget: a #GtkWidget
8297 * Gets the settings object holding the settings (global property
8298 * settings, RC file information, etc) used for this widget.
8300 * Note that this function can only be called when the #GtkWidget
8301 * is attached to a toplevel, since the settings object is specific
8302 * to a particular #GdkScreen.
8304 * Return value: (transfer none): the relevant #GtkSettings object
8307 gtk_widget_get_settings (GtkWidget *widget)
8309 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8311 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8315 * gtk_widget_set_colormap:
8316 * @widget: a #GtkWidget
8317 * @colormap: a colormap
8319 * Sets the colormap for the widget to the given value. Widget must not
8320 * have been previously realized. This probably should only be used
8321 * from an <function>init()</function> function (i.e. from the constructor
8325 gtk_widget_set_colormap (GtkWidget *widget,
8326 GdkColormap *colormap)
8328 g_return_if_fail (GTK_IS_WIDGET (widget));
8329 g_return_if_fail (!gtk_widget_get_realized (widget));
8330 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8332 g_object_ref (colormap);
8334 g_object_set_qdata_full (G_OBJECT (widget),
8341 * gtk_widget_get_events:
8342 * @widget: a #GtkWidget
8344 * Returns the event mask for the widget (a bitfield containing flags
8345 * from the #GdkEventMask enumeration). These are the events that the widget
8348 * Return value: event mask for @widget
8351 gtk_widget_get_events (GtkWidget *widget)
8353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8355 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8359 * gtk_widget_get_extension_events:
8360 * @widget: a #GtkWidget
8362 * Retrieves the extension events the widget will receive; see
8363 * gdk_input_set_extension_events().
8365 * Return value: extension events for @widget
8368 gtk_widget_get_extension_events (GtkWidget *widget)
8370 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8372 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8376 * gtk_widget_get_pointer:
8377 * @widget: a #GtkWidget
8378 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8379 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8381 * Obtains the location of the mouse pointer in widget coordinates.
8382 * Widget coordinates are a bit odd; for historical reasons, they are
8383 * defined as @widget->window coordinates for widgets that are not
8384 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8385 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8388 gtk_widget_get_pointer (GtkWidget *widget,
8392 g_return_if_fail (GTK_IS_WIDGET (widget));
8399 if (gtk_widget_get_realized (widget))
8401 gdk_window_get_pointer (widget->window, x, y, NULL);
8403 if (!gtk_widget_get_has_window (widget))
8406 *x -= widget->allocation.x;
8408 *y -= widget->allocation.y;
8414 * gtk_widget_is_ancestor:
8415 * @widget: a #GtkWidget
8416 * @ancestor: another #GtkWidget
8418 * Determines whether @widget is somewhere inside @ancestor, possibly with
8419 * intermediate containers.
8421 * Return value: %TRUE if @ancestor contains @widget as a child,
8422 * grandchild, great grandchild, etc.
8425 gtk_widget_is_ancestor (GtkWidget *widget,
8426 GtkWidget *ancestor)
8428 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8429 g_return_val_if_fail (ancestor != NULL, FALSE);
8433 if (widget->parent == ancestor)
8435 widget = widget->parent;
8441 static GQuark quark_composite_name = 0;
8444 * gtk_widget_set_composite_name:
8445 * @widget: a #GtkWidget.
8446 * @name: the name to set
8448 * Sets a widgets composite name. The widget must be
8449 * a composite child of its parent; see gtk_widget_push_composite_child().
8452 gtk_widget_set_composite_name (GtkWidget *widget,
8455 g_return_if_fail (GTK_IS_WIDGET (widget));
8456 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
8457 g_return_if_fail (name != NULL);
8459 if (!quark_composite_name)
8460 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8462 g_object_set_qdata_full (G_OBJECT (widget),
8463 quark_composite_name,
8469 * gtk_widget_get_composite_name:
8470 * @widget: a #GtkWidget
8472 * Obtains the composite name of a widget.
8474 * Returns: the composite name of @widget, or %NULL if @widget is not
8475 * a composite child. The string should be freed when it is no
8479 gtk_widget_get_composite_name (GtkWidget *widget)
8481 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8483 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && widget->parent)
8484 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8491 * gtk_widget_push_composite_child:
8493 * Makes all newly-created widgets as composite children until
8494 * the corresponding gtk_widget_pop_composite_child() call.
8496 * A composite child is a child that's an implementation detail of the
8497 * container it's inside and should not be visible to people using the
8498 * container. Composite children aren't treated differently by GTK (but
8499 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8500 * builders might want to treat them in a different way.
8502 * Here is a simple example:
8504 * gtk_widget_push_composite_child ();
8505 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8506 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8507 * gtk_widget_pop_composite_child ();
8508 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8509 * GTK_WIDGET (scrolled_window));
8510 * g_object_ref (scrolled_window->hscrollbar);
8514 gtk_widget_push_composite_child (void)
8516 composite_child_stack++;
8520 * gtk_widget_pop_composite_child:
8522 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8525 gtk_widget_pop_composite_child (void)
8527 if (composite_child_stack)
8528 composite_child_stack--;
8532 * gtk_widget_push_colormap:
8533 * @cmap: a #GdkColormap
8535 * Pushes @cmap onto a global stack of colormaps; the topmost
8536 * colormap on the stack will be used to create all widgets.
8537 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8538 * reason to use this function.
8541 gtk_widget_push_colormap (GdkColormap *cmap)
8543 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8545 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8549 * gtk_widget_pop_colormap:
8551 * Removes a colormap pushed with gtk_widget_push_colormap().
8554 gtk_widget_pop_colormap (void)
8557 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8561 * gtk_widget_set_default_colormap:
8562 * @colormap: a #GdkColormap
8564 * Sets the default colormap to use when creating widgets.
8565 * gtk_widget_push_colormap() is a better function to use if
8566 * you only want to affect a few widgets, rather than all widgets.
8569 gtk_widget_set_default_colormap (GdkColormap *colormap)
8571 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8573 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8578 * gtk_widget_get_default_colormap:
8580 * Obtains the default colormap used to create widgets.
8582 * Return value: (transfer none): default widget colormap
8585 gtk_widget_get_default_colormap (void)
8587 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8591 * gtk_widget_get_default_visual:
8593 * Obtains the visual of the default colormap. Not really useful;
8594 * used to be useful before gdk_colormap_get_visual() existed.
8596 * Return value: (transfer none): visual of the default colormap
8599 gtk_widget_get_default_visual (void)
8601 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8605 gtk_widget_emit_direction_changed (GtkWidget *widget,
8606 GtkTextDirection old_dir)
8608 gtk_widget_update_pango_context (widget);
8610 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8614 * gtk_widget_set_direction:
8615 * @widget: a #GtkWidget
8616 * @dir: the new direction
8618 * Sets the reading direction on a particular widget. This direction
8619 * controls the primary direction for widgets containing text,
8620 * and also the direction in which the children of a container are
8621 * packed. The ability to set the direction is present in order
8622 * so that correct localization into languages with right-to-left
8623 * reading directions can be done. Generally, applications will
8624 * let the default reading direction present, except for containers
8625 * where the containers are arranged in an order that is explicitely
8626 * visual rather than logical (such as buttons for text justification).
8628 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8629 * set by gtk_widget_set_default_direction() will be used.
8632 gtk_widget_set_direction (GtkWidget *widget,
8633 GtkTextDirection dir)
8635 GtkTextDirection old_dir;
8637 g_return_if_fail (GTK_IS_WIDGET (widget));
8638 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8640 old_dir = gtk_widget_get_direction (widget);
8642 if (dir == GTK_TEXT_DIR_NONE)
8643 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8646 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8647 if (dir == GTK_TEXT_DIR_LTR)
8648 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8650 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8653 if (old_dir != gtk_widget_get_direction (widget))
8654 gtk_widget_emit_direction_changed (widget, old_dir);
8658 * gtk_widget_get_direction:
8659 * @widget: a #GtkWidget
8661 * Gets the reading direction for a particular widget. See
8662 * gtk_widget_set_direction().
8664 * Return value: the reading direction for the widget.
8667 gtk_widget_get_direction (GtkWidget *widget)
8669 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8671 if (GTK_WIDGET_DIRECTION_SET (widget))
8672 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8674 return gtk_default_direction;
8678 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8680 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8682 g_object_ref (widget);
8684 if (!GTK_WIDGET_DIRECTION_SET (widget))
8685 gtk_widget_emit_direction_changed (widget, old_dir);
8687 if (GTK_IS_CONTAINER (widget))
8688 gtk_container_forall (GTK_CONTAINER (widget),
8689 gtk_widget_set_default_direction_recurse,
8692 g_object_unref (widget);
8696 * gtk_widget_set_default_direction:
8697 * @dir: the new default direction. This cannot be
8698 * %GTK_TEXT_DIR_NONE.
8700 * Sets the default reading direction for widgets where the
8701 * direction has not been explicitly set by gtk_widget_set_direction().
8704 gtk_widget_set_default_direction (GtkTextDirection dir)
8706 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8708 if (dir != gtk_default_direction)
8710 GList *toplevels, *tmp_list;
8711 GtkTextDirection old_dir = gtk_default_direction;
8713 gtk_default_direction = dir;
8715 tmp_list = toplevels = gtk_window_list_toplevels ();
8716 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8720 gtk_widget_set_default_direction_recurse (tmp_list->data,
8721 GUINT_TO_POINTER (old_dir));
8722 g_object_unref (tmp_list->data);
8723 tmp_list = tmp_list->next;
8726 g_list_free (toplevels);
8731 * gtk_widget_get_default_direction:
8733 * Obtains the current default reading direction. See
8734 * gtk_widget_set_default_direction().
8736 * Return value: the current default direction.
8739 gtk_widget_get_default_direction (void)
8741 return gtk_default_direction;
8745 gtk_widget_dispose (GObject *object)
8747 GtkWidget *widget = GTK_WIDGET (object);
8750 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8751 else if (gtk_widget_get_visible (widget))
8752 gtk_widget_hide (widget);
8754 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8755 if (gtk_widget_get_realized (widget))
8756 gtk_widget_unrealize (widget);
8758 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8762 gtk_widget_real_destroy (GtkObject *object)
8764 /* gtk_object_destroy() will already hold a refcount on object */
8765 GtkWidget *widget = GTK_WIDGET (object);
8767 /* wipe accelerator closures (keep order) */
8768 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8769 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8771 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8772 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8774 gtk_grab_remove (widget);
8776 g_object_unref (widget->style);
8777 widget->style = gtk_widget_get_default_style ();
8778 g_object_ref (widget->style);
8780 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8784 gtk_widget_finalize (GObject *object)
8786 GtkWidget *widget = GTK_WIDGET (object);
8787 GtkWidgetAuxInfo *aux_info;
8788 GtkAccessible *accessible;
8790 gtk_grab_remove (widget);
8792 g_object_unref (widget->style);
8793 widget->style = NULL;
8795 g_free (widget->name);
8797 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8799 gtk_widget_aux_info_destroy (aux_info);
8801 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8803 g_object_unref (accessible);
8805 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8808 /*****************************************
8809 * gtk_widget_real_map:
8814 *****************************************/
8817 gtk_widget_real_map (GtkWidget *widget)
8819 g_assert (gtk_widget_get_realized (widget));
8821 if (!gtk_widget_get_mapped (widget))
8823 gtk_widget_set_mapped (widget, TRUE);
8825 if (gtk_widget_get_has_window (widget))
8826 gdk_window_show (widget->window);
8830 /*****************************************
8831 * gtk_widget_real_unmap:
8836 *****************************************/
8839 gtk_widget_real_unmap (GtkWidget *widget)
8841 if (gtk_widget_get_mapped (widget))
8843 gtk_widget_set_mapped (widget, FALSE);
8845 if (gtk_widget_get_has_window (widget))
8846 gdk_window_hide (widget->window);
8850 /*****************************************
8851 * gtk_widget_real_realize:
8856 *****************************************/
8859 gtk_widget_real_realize (GtkWidget *widget)
8861 g_assert (!gtk_widget_get_has_window (widget));
8863 gtk_widget_set_realized (widget, TRUE);
8866 widget->window = gtk_widget_get_parent_window (widget);
8867 g_object_ref (widget->window);
8869 widget->style = gtk_style_attach (widget->style, widget->window);
8872 /*****************************************
8873 * gtk_widget_real_unrealize:
8878 *****************************************/
8881 gtk_widget_real_unrealize (GtkWidget *widget)
8883 if (gtk_widget_get_mapped (widget))
8884 gtk_widget_real_unmap (widget);
8886 gtk_widget_set_mapped (widget, FALSE);
8888 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8891 /* We must do unrealize child widget BEFORE container widget.
8892 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8893 * So, unrealizing container widget bofore its children causes the problem
8894 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8897 if (GTK_IS_CONTAINER (widget))
8898 gtk_container_forall (GTK_CONTAINER (widget),
8899 (GtkCallback) gtk_widget_unrealize,
8902 gtk_style_detach (widget->style);
8903 if (gtk_widget_get_has_window (widget))
8905 gdk_window_set_user_data (widget->window, NULL);
8906 gdk_window_destroy (widget->window);
8907 widget->window = NULL;
8911 g_object_unref (widget->window);
8912 widget->window = NULL;
8915 gtk_selection_remove_all (widget);
8917 gtk_widget_set_realized (widget, FALSE);
8921 gtk_widget_real_size_request (GtkWidget *widget,
8922 GtkRequisition *requisition)
8924 requisition->width = widget->requisition.width;
8925 requisition->height = widget->requisition.height;
8929 * _gtk_widget_peek_colormap:
8931 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8933 * Return value: the currently pushed colormap, or %NULL if there is none.
8936 _gtk_widget_peek_colormap (void)
8939 return (GdkColormap*) colormap_stack->data;
8944 * _gtk_widget_set_pointer_window:
8945 * @widget: a #GtkWidget.
8946 * @pointer_window: the new pointer window.
8948 * Sets pointer window for @widget. Does not ref @pointer_window.
8949 * Actually stores it on the #GdkScreen, but you don't need to know that.
8952 _gtk_widget_set_pointer_window (GtkWidget *widget,
8953 GdkWindow *pointer_window)
8955 g_return_if_fail (GTK_IS_WIDGET (widget));
8957 if (gtk_widget_get_realized (widget))
8959 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8961 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8967 * _gtk_widget_get_pointer_window:
8968 * @widget: a #GtkWidget.
8970 * Return value: the pointer window set on the #GdkScreen @widget is attached
8974 _gtk_widget_get_pointer_window (GtkWidget *widget)
8976 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8978 if (gtk_widget_get_realized (widget))
8980 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8982 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8989 synth_crossing (GtkWidget *widget,
8992 GdkCrossingMode mode,
8993 GdkNotifyType detail)
8997 event = gdk_event_new (type);
8999 event->crossing.window = g_object_ref (window);
9000 event->crossing.send_event = TRUE;
9001 event->crossing.subwindow = g_object_ref (window);
9002 event->crossing.time = GDK_CURRENT_TIME;
9003 event->crossing.x = event->crossing.y = 0;
9004 event->crossing.x_root = event->crossing.y_root = 0;
9005 event->crossing.mode = mode;
9006 event->crossing.detail = detail;
9007 event->crossing.focus = FALSE;
9008 event->crossing.state = 0;
9011 widget = gtk_get_event_widget (event);
9014 gtk_widget_event_internal (widget, event);
9016 gdk_event_free (event);
9020 * _gtk_widget_is_pointer_widget:
9021 * @widget: a #GtkWidget
9023 * Returns %TRUE if the pointer window belongs to @widget.
9026 _gtk_widget_is_pointer_widget (GtkWidget *widget)
9028 if (GTK_WIDGET_HAS_POINTER (widget))
9033 win = _gtk_widget_get_pointer_window (widget);
9036 gdk_window_get_user_data (win, (gpointer *)&wid);
9046 * _gtk_widget_synthesize_crossing:
9047 * @from: the #GtkWidget the virtual pointer is leaving.
9048 * @to: the #GtkWidget the virtual pointer is moving to.
9049 * @mode: the #GdkCrossingMode to place on the synthesized events.
9051 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9053 * The real pointer window is the window that most recently received an enter notify
9054 * event. Windows that don't select for crossing events can't become the real
9055 * poiner window. The real pointer widget that owns the real pointer window. The
9056 * effective pointer window is the same as the real pointer window unless the real
9057 * pointer widget is either insensitive or there is a grab on a widget that is not
9058 * an ancestor of the real pointer widget (in which case the effective pointer
9059 * window should be the root window).
9061 * When the effective pointer window is the same as the real poiner window, we
9062 * receive crossing events from the windowing system. When the effective pointer
9063 * window changes to become different from the real pointer window we synthesize
9064 * crossing events, attempting to follow X protocol rules:
9066 * When the root window becomes the effective pointer window:
9067 * - leave notify on real pointer window, detail Ancestor
9068 * - leave notify on all of its ancestors, detail Virtual
9069 * - enter notify on root window, detail Inferior
9071 * When the root window ceases to be the effective pointer window:
9072 * - leave notify on root window, detail Inferior
9073 * - enter notify on all ancestors of real pointer window, detail Virtual
9074 * - enter notify on real pointer window, detail Ancestor
9077 _gtk_widget_synthesize_crossing (GtkWidget *from,
9079 GdkCrossingMode mode)
9081 GdkWindow *from_window = NULL, *to_window = NULL;
9083 g_return_if_fail (from != NULL || to != NULL);
9086 from_window = GTK_WIDGET_HAS_POINTER (from)
9087 ? _gtk_widget_get_pointer_window (from) : from->window;
9089 to_window = GTK_WIDGET_HAS_POINTER (to)
9090 ? _gtk_widget_get_pointer_window (to) : to->window;
9092 if (from_window == NULL && to_window == NULL)
9094 else if (from_window != NULL && to_window == NULL)
9096 GList *from_ancestors = NULL, *list;
9097 GdkWindow *from_ancestor = from_window;
9099 while (from_ancestor != NULL)
9101 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9102 if (from_ancestor == NULL)
9104 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9107 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9108 mode, GDK_NOTIFY_ANCESTOR);
9109 for (list = g_list_last (from_ancestors); list; list = list->prev)
9111 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9112 mode, GDK_NOTIFY_VIRTUAL);
9115 /* XXX: enter/inferior on root window? */
9117 g_list_free (from_ancestors);
9119 else if (from_window == NULL && to_window != NULL)
9121 GList *to_ancestors = NULL, *list;
9122 GdkWindow *to_ancestor = to_window;
9124 while (to_ancestor != NULL)
9126 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9127 if (to_ancestor == NULL)
9129 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9132 /* XXX: leave/inferior on root window? */
9134 for (list = to_ancestors; list; list = list->next)
9136 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9137 mode, GDK_NOTIFY_VIRTUAL);
9139 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9140 mode, GDK_NOTIFY_ANCESTOR);
9142 g_list_free (to_ancestors);
9144 else if (from_window == to_window)
9148 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9149 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9151 while (from_ancestor != NULL || to_ancestor != NULL)
9153 if (from_ancestor != NULL)
9155 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9156 if (from_ancestor == to_window)
9159 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9161 if (to_ancestor != NULL)
9163 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9164 if (to_ancestor == from_window)
9167 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9170 if (to_ancestor == from_window)
9172 if (mode != GDK_CROSSING_GTK_UNGRAB)
9173 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9174 mode, GDK_NOTIFY_INFERIOR);
9175 for (list = to_ancestors; list; list = list->next)
9176 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9177 mode, GDK_NOTIFY_VIRTUAL);
9178 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9179 mode, GDK_NOTIFY_ANCESTOR);
9181 else if (from_ancestor == to_window)
9183 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9184 mode, GDK_NOTIFY_ANCESTOR);
9185 for (list = g_list_last (from_ancestors); list; list = list->prev)
9187 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9188 mode, GDK_NOTIFY_VIRTUAL);
9190 if (mode != GDK_CROSSING_GTK_GRAB)
9191 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9192 mode, GDK_NOTIFY_INFERIOR);
9196 while (from_ancestors != NULL && to_ancestors != NULL
9197 && from_ancestors->data == to_ancestors->data)
9199 from_ancestors = g_list_delete_link (from_ancestors,
9201 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9204 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9205 mode, GDK_NOTIFY_NONLINEAR);
9207 for (list = g_list_last (from_ancestors); list; list = list->prev)
9209 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9210 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9212 for (list = to_ancestors; list; list = list->next)
9214 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9215 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9217 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9218 mode, GDK_NOTIFY_NONLINEAR);
9220 g_list_free (from_ancestors);
9221 g_list_free (to_ancestors);
9226 gtk_widget_propagate_state (GtkWidget *widget,
9229 guint8 old_state = gtk_widget_get_state (widget);
9230 guint8 old_saved_state = widget->saved_state;
9232 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9233 * parent_sensitive==TRUE on a sensitive widget
9237 if (data->parent_sensitive)
9238 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9240 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9242 if (gtk_widget_is_sensitive (widget))
9244 if (data->state_restoration)
9245 widget->state = widget->saved_state;
9247 widget->state = data->state;
9251 if (!data->state_restoration)
9253 if (data->state != GTK_STATE_INSENSITIVE)
9254 widget->saved_state = data->state;
9256 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9257 widget->saved_state = gtk_widget_get_state (widget);
9258 widget->state = GTK_STATE_INSENSITIVE;
9261 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9265 window = gtk_widget_get_toplevel (widget);
9266 if (window && gtk_widget_is_toplevel (window))
9267 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9270 if (old_state != gtk_widget_get_state (widget) ||
9271 old_saved_state != widget->saved_state)
9273 g_object_ref (widget);
9275 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9276 gtk_grab_remove (widget);
9278 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9280 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
9282 if (!gtk_widget_is_sensitive (widget))
9283 _gtk_widget_synthesize_crossing (widget, NULL,
9284 GDK_CROSSING_STATE_CHANGED);
9285 else if (old_state == GTK_STATE_INSENSITIVE)
9286 _gtk_widget_synthesize_crossing (NULL, widget,
9287 GDK_CROSSING_STATE_CHANGED);
9290 if (GTK_IS_CONTAINER (widget))
9292 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9293 if (data->use_forall)
9294 gtk_container_forall (GTK_CONTAINER (widget),
9295 (GtkCallback) gtk_widget_propagate_state,
9298 gtk_container_foreach (GTK_CONTAINER (widget),
9299 (GtkCallback) gtk_widget_propagate_state,
9302 g_object_unref (widget);
9307 * _gtk_widget_get_aux_info:
9308 * @widget: a #GtkWidget
9309 * @create: if %TRUE, create the structure if it doesn't exist
9311 * Get the #GtkWidgetAuxInfo structure for the widget.
9313 * Return value: the #GtkAuxInfo structure for the widget, or
9314 * %NULL if @create is %FALSE and one doesn't already exist.
9317 _gtk_widget_get_aux_info (GtkWidget *widget,
9320 GtkWidgetAuxInfo *aux_info;
9322 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9323 if (!aux_info && create)
9325 aux_info = g_slice_new (GtkWidgetAuxInfo);
9327 aux_info->width = -1;
9328 aux_info->height = -1;
9331 aux_info->x_set = FALSE;
9332 aux_info->y_set = FALSE;
9333 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9339 /*****************************************
9340 * gtk_widget_aux_info_destroy:
9345 *****************************************/
9348 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
9350 g_slice_free (GtkWidgetAuxInfo, aux_info);
9354 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
9356 g_object_unref (info->shape_mask);
9357 g_slice_free (GtkWidgetShapeInfo, info);
9361 * gtk_widget_shape_combine_mask:
9362 * @widget: a #GtkWidget
9363 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9364 * @offset_x: X position of shape mask with respect to @window
9365 * @offset_y: Y position of shape mask with respect to @window
9367 * Sets a shape for this widget's GDK window. This allows for
9368 * transparent windows etc., see gdk_window_shape_combine_mask()
9369 * for more information.
9372 gtk_widget_shape_combine_mask (GtkWidget *widget,
9373 GdkBitmap *shape_mask,
9377 GtkWidgetShapeInfo* shape_info;
9379 g_return_if_fail (GTK_IS_WIDGET (widget));
9380 /* set_shape doesn't work on widgets without gdk window */
9381 g_return_if_fail (gtk_widget_get_has_window (widget));
9385 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9388 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9390 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9394 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9396 shape_info = g_slice_new (GtkWidgetShapeInfo);
9397 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9398 (GDestroyNotify) gtk_widget_shape_info_destroy);
9400 shape_info->shape_mask = g_object_ref (shape_mask);
9401 shape_info->offset_x = offset_x;
9402 shape_info->offset_y = offset_y;
9404 /* set shape if widget has a gdk window already.
9405 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9408 gdk_window_shape_combine_mask (widget->window, shape_mask,
9409 offset_x, offset_y);
9414 * gtk_widget_input_shape_combine_mask:
9415 * @widget: a #GtkWidget
9416 * @shape_mask: (allow-none): shape to be added, or %NULL to remove an existing shape
9417 * @offset_x: X position of shape mask with respect to @window
9418 * @offset_y: Y position of shape mask with respect to @window
9420 * Sets an input shape for this widget's GDK window. This allows for
9421 * windows which react to mouse click in a nonrectangular region, see
9422 * gdk_window_input_shape_combine_mask() for more information.
9427 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9428 GdkBitmap *shape_mask,
9432 GtkWidgetShapeInfo* shape_info;
9434 g_return_if_fail (GTK_IS_WIDGET (widget));
9435 /* set_shape doesn't work on widgets without gdk window */
9436 g_return_if_fail (gtk_widget_get_has_window (widget));
9441 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9443 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9447 shape_info = g_slice_new (GtkWidgetShapeInfo);
9448 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9450 (GDestroyNotify) gtk_widget_shape_info_destroy);
9452 shape_info->shape_mask = g_object_ref (shape_mask);
9453 shape_info->offset_x = offset_x;
9454 shape_info->offset_y = offset_y;
9456 /* set shape if widget has a gdk window already.
9457 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9460 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9461 offset_x, offset_y);
9467 gtk_reset_shapes_recurse (GtkWidget *widget,
9473 gdk_window_get_user_data (window, &data);
9477 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9478 for (list = gdk_window_peek_children (window); list; list = list->next)
9479 gtk_reset_shapes_recurse (widget, list->data);
9483 * gtk_widget_reset_shapes:
9484 * @widget: a #GtkWidget
9486 * Recursively resets the shape on this widget and its descendants.
9489 gtk_widget_reset_shapes (GtkWidget *widget)
9491 g_return_if_fail (GTK_IS_WIDGET (widget));
9492 g_return_if_fail (gtk_widget_get_realized (widget));
9494 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9495 gtk_reset_shapes_recurse (widget, widget->window);
9500 * @widget: a #GtkWidget
9502 * Adds a reference to a widget. This function is exactly the same
9503 * as calling g_object_ref(), and exists mostly for historical
9504 * reasons. It can still be convenient to avoid casting a widget
9505 * to a #GObject, it saves a small amount of typing.
9507 * Return value: the widget that was referenced
9509 * Deprecated: 2.12: Use g_object_ref() instead.
9512 gtk_widget_ref (GtkWidget *widget)
9514 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9516 return (GtkWidget*) g_object_ref ((GObject*) widget);
9521 * @widget: a #GtkWidget
9523 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9525 * Deprecated: 2.12: Use g_object_unref() instead.
9528 gtk_widget_unref (GtkWidget *widget)
9530 g_return_if_fail (GTK_IS_WIDGET (widget));
9532 g_object_unref ((GObject*) widget);
9536 expose_window (GdkWindow *window)
9539 GList *l, *children;
9541 gboolean is_double_buffered;
9543 gdk_window_get_user_data (window, &user_data);
9546 is_double_buffered = gtk_widget_get_double_buffered (GTK_WIDGET (user_data));
9548 is_double_buffered = FALSE;
9550 event.expose.type = GDK_EXPOSE;
9551 event.expose.window = g_object_ref (window);
9552 event.expose.send_event = FALSE;
9553 event.expose.count = 0;
9554 event.expose.area.x = 0;
9555 event.expose.area.y = 0;
9556 gdk_drawable_get_size (GDK_DRAWABLE (window),
9557 &event.expose.area.width,
9558 &event.expose.area.height);
9559 event.expose.region = gdk_region_rectangle (&event.expose.area);
9561 /* If this is not double buffered, force a double buffer so that
9562 redirection works. */
9563 if (!is_double_buffered)
9564 gdk_window_begin_paint_region (window, event.expose.region);
9566 gtk_main_do_event (&event);
9568 if (!is_double_buffered)
9569 gdk_window_end_paint (window);
9571 children = gdk_window_peek_children (window);
9572 for (l = children; l != NULL; l = l->next)
9574 GdkWindow *child = l->data;
9576 /* Don't expose input-only windows */
9577 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9578 expose_window (l->data);
9581 g_object_unref (window);
9585 * gtk_widget_get_snapshot:
9586 * @widget: a #GtkWidget
9587 * @clip_rect: (allow-none): a #GdkRectangle or %NULL
9589 * Create a #GdkPixmap of the contents of the widget and its children.
9591 * Works even if the widget is obscured. The depth and visual of the
9592 * resulting pixmap is dependent on the widget being snapshot and likely
9593 * differs from those of a target widget displaying the pixmap.
9594 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9595 * the pixmap to a visual independant representation.
9597 * The snapshot area used by this function is the @widget's allocation plus
9598 * any extra space occupied by additional windows belonging to this widget
9599 * (such as the arrows of a spin button).
9600 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9602 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9603 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9604 * interpreted widget relative. If width or height of @clip_rect are 0 or
9605 * negative, the width or height of the resulting pixmap will be shrunken
9606 * by the respective amount.
9607 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9608 * chop off 5 pixels at each side of the snapshot pixmap.
9609 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9610 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9611 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9612 * as a pure output parameter.
9614 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9616 * Return value: #GdkPixmap snapshot of the widget
9621 gtk_widget_get_snapshot (GtkWidget *widget,
9622 GdkRectangle *clip_rect)
9624 int x, y, width, height;
9625 GdkWindow *parent_window = NULL;
9627 GList *windows = NULL, *list;
9629 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9630 if (!gtk_widget_get_visible (widget))
9633 /* the widget (and parent_window) must be realized to be drawable */
9634 if (widget->parent && !gtk_widget_get_realized (widget->parent))
9635 gtk_widget_realize (widget->parent);
9636 if (!gtk_widget_get_realized (widget))
9637 gtk_widget_realize (widget);
9639 /* determine snapshot rectangle */
9640 x = widget->allocation.x;
9641 y = widget->allocation.y;
9642 width = widget->allocation.width;
9643 height = widget->allocation.height;
9645 if (widget->parent && gtk_widget_get_has_window (widget))
9647 /* grow snapshot rectangle to cover all widget windows */
9648 parent_window = gtk_widget_get_parent_window (widget);
9649 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9651 GdkWindow *subwin = list->data;
9654 gdk_window_get_user_data (subwin, &windata);
9655 if (windata != widget)
9657 windows = g_list_prepend (windows, subwin);
9658 gdk_window_get_position (subwin, &wx, &wy);
9659 gdk_drawable_get_size (subwin, &ww, &wh);
9660 /* grow snapshot rectangle by extra widget sub window */
9671 if (x + width < wx + ww)
9672 width += wx + ww - (x + width);
9673 if (y + height < wy + wh)
9674 height += wy + wh - (y + height);
9677 else if (!widget->parent)
9678 x = y = 0; /* toplevel */
9680 /* at this point, (x,y,width,height) is the parent_window relative
9681 * snapshot area covering all of widget's windows.
9684 /* shrink snapshot size by clip_rectangle */
9687 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9688 clip.x = clip.x < 0 ? x : clip.x;
9689 clip.y = clip.y < 0 ? y : clip.y;
9690 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9691 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9694 /* offset clip_rect, so it's parent_window relative */
9695 if (clip_rect->x >= 0)
9696 clip.x += widget->allocation.x;
9697 if (clip_rect->y >= 0)
9698 clip.y += widget->allocation.y;
9700 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9702 g_list_free (windows);
9703 clip_rect->width = clip_rect->height = 0;
9704 return NULL; /* empty snapshot area */
9709 height = snap.height;
9712 /* render snapshot */
9713 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9714 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9716 GdkWindow *subwin = list->data;
9718 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9719 continue; /* Input only window */
9720 gdk_window_get_position (subwin, &wx, &wy);
9721 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9722 MAX (0, wx - x), MAX (0, wy - y), width, height);
9724 expose_window (subwin);
9726 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9728 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9729 expose_window (widget->window);
9731 for (list = windows; list; list = list->next)
9732 gdk_window_remove_redirection (list->data);
9733 if (!windows) /* NO_WINDOW || toplevel */
9734 gdk_window_remove_redirection (widget->window);
9735 g_list_free (windows);
9737 /* return pixmap and snapshot rectangle coordinates */
9742 clip_rect->width = width;
9743 clip_rect->height = height;
9746 /* offset clip_rect from parent_window so it's widget relative */
9747 clip_rect->x -= widget->allocation.x;
9748 clip_rect->y -= widget->allocation.y;
9751 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9752 G_OBJECT_TYPE_NAME (widget),
9753 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9762 * gtk_widget_class_install_style_property_parser:
9763 * @klass: a #GtkWidgetClass
9764 * @pspec: the #GParamSpec for the style property
9765 * @parser: the parser for the style property
9767 * Installs a style property on a widget class.
9770 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9772 GtkRcPropertyParser parser)
9774 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9775 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9776 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9777 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9779 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9781 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9782 G_OBJECT_CLASS_NAME (klass),
9787 g_param_spec_ref_sink (pspec);
9788 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9789 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9793 * gtk_widget_class_install_style_property:
9794 * @klass: a #GtkWidgetClass
9795 * @pspec: the #GParamSpec for the property
9797 * Installs a style property on a widget class. The parser for the
9798 * style property is determined by the value type of @pspec.
9801 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9804 GtkRcPropertyParser parser;
9806 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9807 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9809 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9811 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9815 * gtk_widget_class_find_style_property:
9816 * @klass: a #GtkWidgetClass
9817 * @property_name: the name of the style property to find
9818 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
9819 * style property with that name.
9821 * Finds a style property of a widget class by name.
9826 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9827 const gchar *property_name)
9829 g_return_val_if_fail (property_name != NULL, NULL);
9831 return g_param_spec_pool_lookup (style_property_spec_pool,
9833 G_OBJECT_CLASS_TYPE (klass),
9838 * gtk_widget_class_list_style_properties:
9839 * @klass: a #GtkWidgetClass
9840 * @n_properties: location to return the number of style properties found
9841 * @returns: an newly allocated array of #GParamSpec*. The array must
9842 * be freed with g_free().
9844 * Returns all style properties of a widget class.
9849 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9850 guint *n_properties)
9852 GParamSpec **pspecs;
9855 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9856 G_OBJECT_CLASS_TYPE (klass),
9865 * gtk_widget_style_get_property:
9866 * @widget: a #GtkWidget
9867 * @property_name: the name of a style property
9868 * @value: location to return the property value
9870 * Gets the value of a style property of @widget.
9873 gtk_widget_style_get_property (GtkWidget *widget,
9874 const gchar *property_name,
9879 g_return_if_fail (GTK_IS_WIDGET (widget));
9880 g_return_if_fail (property_name != NULL);
9881 g_return_if_fail (G_IS_VALUE (value));
9883 g_object_ref (widget);
9884 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9886 G_OBJECT_TYPE (widget),
9889 g_warning ("%s: widget class `%s' has no property named `%s'",
9891 G_OBJECT_TYPE_NAME (widget),
9895 const GValue *peek_value;
9897 peek_value = _gtk_style_peek_property_value (widget->style,
9898 G_OBJECT_TYPE (widget),
9900 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9902 /* auto-conversion of the caller's value type
9904 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9905 g_value_copy (peek_value, value);
9906 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9907 g_value_transform (peek_value, value);
9909 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9911 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9912 G_VALUE_TYPE_NAME (value));
9914 g_object_unref (widget);
9918 * gtk_widget_style_get_valist:
9919 * @widget: a #GtkWidget
9920 * @first_property_name: the name of the first property to get
9921 * @var_args: a <type>va_list</type> of pairs of property names and
9922 * locations to return the property values, starting with the location
9923 * for @first_property_name.
9925 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9929 gtk_widget_style_get_valist (GtkWidget *widget,
9930 const gchar *first_property_name,
9935 g_return_if_fail (GTK_IS_WIDGET (widget));
9937 g_object_ref (widget);
9939 name = first_property_name;
9942 const GValue *peek_value;
9946 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9948 G_OBJECT_TYPE (widget),
9952 g_warning ("%s: widget class `%s' has no property named `%s'",
9954 G_OBJECT_TYPE_NAME (widget),
9958 /* style pspecs are always readable so we can spare that check here */
9960 peek_value = _gtk_style_peek_property_value (widget->style,
9961 G_OBJECT_TYPE (widget),
9963 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9964 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9967 g_warning ("%s: %s", G_STRLOC, error);
9972 name = va_arg (var_args, gchar*);
9975 g_object_unref (widget);
9979 * gtk_widget_style_get:
9980 * @widget: a #GtkWidget
9981 * @first_property_name: the name of the first property to get
9982 * @Varargs: pairs of property names and locations to
9983 * return the property values, starting with the location for
9984 * @first_property_name, terminated by %NULL.
9986 * Gets the values of a multiple style properties of @widget.
9989 gtk_widget_style_get (GtkWidget *widget,
9990 const gchar *first_property_name,
9995 g_return_if_fail (GTK_IS_WIDGET (widget));
9997 va_start (var_args, first_property_name);
9998 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10004 * @widget: a #GtkWidget
10005 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10006 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10007 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10009 * Obtains the full path to @widget. The path is simply the name of a
10010 * widget and all its parents in the container hierarchy, separated by
10011 * periods. The name of a widget comes from
10012 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10013 * in gtkrc configuration files. Widget names are the type of the
10014 * widget by default (e.g. "GtkButton") or can be set to an
10015 * application-specific value with gtk_widget_set_name(). By setting
10016 * the name of a widget, you allow users or theme authors to apply
10017 * styles to that specific widget in their gtkrc
10018 * file. @path_reversed_p fills in the path in reverse order,
10019 * i.e. starting with @widget's name instead of starting with the name
10020 * of @widget's outermost ancestor.
10023 gtk_widget_path (GtkWidget *widget,
10024 guint *path_length,
10026 gchar **path_reversed)
10028 static gchar *rev_path = NULL;
10029 static guint tmp_path_len = 0;
10032 g_return_if_fail (GTK_IS_WIDGET (widget));
10037 const gchar *string;
10042 string = gtk_widget_get_name (widget);
10043 l = strlen (string);
10044 while (tmp_path_len <= len + l + 1)
10046 tmp_path_len += INIT_PATH_SIZE;
10047 rev_path = g_realloc (rev_path, tmp_path_len);
10049 s = string + l - 1;
10050 d = rev_path + len;
10051 while (s >= string)
10055 widget = widget->parent;
10058 rev_path[len++] = '.';
10060 rev_path[len++] = 0;
10065 *path_length = len - 1;
10067 *path_reversed = g_strdup (rev_path);
10070 *path = g_strdup (rev_path);
10071 g_strreverse (*path);
10076 * gtk_widget_class_path:
10077 * @widget: a #GtkWidget
10078 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10079 * @path: (out) (allow-none) location to store the class path as an allocated string, or %NULL
10080 * @path_reversed: (out) (allow-none) location to store the reverse class path as an allocated
10083 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10084 * never uses a custom name set with gtk_widget_set_name().
10088 gtk_widget_class_path (GtkWidget *widget,
10089 guint *path_length,
10091 gchar **path_reversed)
10093 static gchar *rev_path = NULL;
10094 static guint tmp_path_len = 0;
10097 g_return_if_fail (GTK_IS_WIDGET (widget));
10102 const gchar *string;
10107 string = g_type_name (G_OBJECT_TYPE (widget));
10108 l = strlen (string);
10109 while (tmp_path_len <= len + l + 1)
10111 tmp_path_len += INIT_PATH_SIZE;
10112 rev_path = g_realloc (rev_path, tmp_path_len);
10114 s = string + l - 1;
10115 d = rev_path + len;
10116 while (s >= string)
10120 widget = widget->parent;
10123 rev_path[len++] = '.';
10125 rev_path[len++] = 0;
10130 *path_length = len - 1;
10132 *path_reversed = g_strdup (rev_path);
10135 *path = g_strdup (rev_path);
10136 g_strreverse (*path);
10141 * gtk_requisition_copy:
10142 * @requisition: a #GtkRequisition
10144 * Copies a #GtkRequisition.
10146 * Returns: a copy of @requisition
10149 gtk_requisition_copy (const GtkRequisition *requisition)
10151 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
10155 * gtk_requisition_free:
10156 * @requisition: a #GtkRequisition
10158 * Frees a #GtkRequisition.
10161 gtk_requisition_free (GtkRequisition *requisition)
10163 g_free (requisition);
10167 gtk_requisition_get_type (void)
10169 static GType our_type = 0;
10172 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
10173 (GBoxedCopyFunc) gtk_requisition_copy,
10174 (GBoxedFreeFunc) gtk_requisition_free);
10180 * gtk_widget_get_accessible:
10181 * @widget: a #GtkWidget
10183 * Returns the accessible object that describes the widget to an
10184 * assistive technology.
10186 * If no accessibility library is loaded (i.e. no ATK implementation library is
10187 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10188 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10189 * if no class-specific #AtkObject implementation is available for the widget
10190 * instance in question, it will inherit an #AtkObject implementation from the
10191 * first ancestor class for which such an implementation is defined.
10193 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10194 * library contains more information about accessible objects and their uses.
10196 * Returns: (transfer none): the #AtkObject associated with @widget
10199 gtk_widget_get_accessible (GtkWidget *widget)
10201 GtkWidgetClass *klass;
10203 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10205 klass = GTK_WIDGET_GET_CLASS (widget);
10207 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10209 return klass->get_accessible (widget);
10213 gtk_widget_real_get_accessible (GtkWidget *widget)
10215 AtkObject* accessible;
10217 accessible = g_object_get_qdata (G_OBJECT (widget),
10218 quark_accessible_object);
10221 AtkObjectFactory *factory;
10222 AtkRegistry *default_registry;
10224 default_registry = atk_get_default_registry ();
10225 factory = atk_registry_get_factory (default_registry,
10226 G_TYPE_FROM_INSTANCE (widget));
10228 atk_object_factory_create_accessible (factory,
10229 G_OBJECT (widget));
10230 g_object_set_qdata (G_OBJECT (widget),
10231 quark_accessible_object,
10238 * Initialize a AtkImplementorIface instance's virtual pointers as
10239 * appropriate to this implementor's class (GtkWidget).
10242 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10244 iface->ref_accessible = gtk_widget_ref_accessible;
10248 gtk_widget_ref_accessible (AtkImplementor *implementor)
10250 AtkObject *accessible;
10252 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10254 g_object_ref (accessible);
10259 * GtkBuildable implementation
10261 static GQuark quark_builder_has_default = 0;
10262 static GQuark quark_builder_has_focus = 0;
10263 static GQuark quark_builder_atk_relations = 0;
10264 static GQuark quark_builder_set_name = 0;
10267 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10269 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10270 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10271 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10272 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10274 iface->set_name = gtk_widget_buildable_set_name;
10275 iface->get_name = gtk_widget_buildable_get_name;
10276 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10277 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10278 iface->parser_finished = gtk_widget_buildable_parser_finished;
10279 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10280 iface->custom_finished = gtk_widget_buildable_custom_finished;
10284 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10287 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10288 g_strdup (name), g_free);
10291 static const gchar *
10292 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10294 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10298 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10299 GtkBuilder *builder,
10300 const gchar *childname)
10302 if (strcmp (childname, "accessible") == 0)
10303 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10309 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10310 GtkBuilder *builder,
10312 const GValue *value)
10314 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10315 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10316 GINT_TO_POINTER (TRUE));
10317 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10318 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10319 GINT_TO_POINTER (TRUE));
10321 g_object_set_property (G_OBJECT (buildable), name, value);
10326 gchar *action_name;
10327 GString *description;
10329 gboolean translatable;
10339 free_action (AtkActionData *data, gpointer user_data)
10341 g_free (data->action_name);
10342 g_string_free (data->description, TRUE);
10343 g_free (data->context);
10344 g_slice_free (AtkActionData, data);
10348 free_relation (AtkRelationData *data, gpointer user_data)
10350 g_free (data->target);
10351 g_free (data->type);
10352 g_slice_free (AtkRelationData, data);
10356 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10357 GtkBuilder *builder)
10359 GSList *atk_relations;
10361 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10362 gtk_widget_grab_default (GTK_WIDGET (buildable));
10363 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10364 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10366 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10367 quark_builder_atk_relations);
10370 AtkObject *accessible;
10371 AtkRelationSet *relation_set;
10374 AtkRelationType relation_type;
10375 AtkObject *target_accessible;
10377 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10378 relation_set = atk_object_ref_relation_set (accessible);
10380 for (l = atk_relations; l; l = l->next)
10382 AtkRelationData *relation = (AtkRelationData*)l->data;
10384 target = gtk_builder_get_object (builder, relation->target);
10387 g_warning ("Target object %s in <relation> does not exist",
10391 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10392 g_assert (target_accessible != NULL);
10394 relation_type = atk_relation_type_for_name (relation->type);
10395 if (relation_type == ATK_RELATION_NULL)
10397 g_warning ("<relation> type %s not found",
10401 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10402 target_accessible);
10404 g_object_unref (relation_set);
10406 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10407 g_slist_free (atk_relations);
10408 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10417 } AccessibilitySubParserData;
10420 accessibility_start_element (GMarkupParseContext *context,
10421 const gchar *element_name,
10422 const gchar **names,
10423 const gchar **values,
10424 gpointer user_data,
10427 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10429 gint line_number, char_number;
10431 if (strcmp (element_name, "relation") == 0)
10433 gchar *target = NULL;
10434 gchar *type = NULL;
10435 AtkRelationData *relation;
10437 for (i = 0; names[i]; i++)
10439 if (strcmp (names[i], "target") == 0)
10440 target = g_strdup (values[i]);
10441 else if (strcmp (names[i], "type") == 0)
10442 type = g_strdup (values[i]);
10445 g_markup_parse_context_get_position (context,
10448 g_set_error (error,
10450 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10451 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10453 line_number, char_number, names[i], "relation");
10460 if (!target || !type)
10462 g_markup_parse_context_get_position (context,
10465 g_set_error (error,
10467 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10468 "%s:%d:%d <%s> requires attribute \"%s\"",
10470 line_number, char_number, "relation",
10471 type ? "target" : "type");
10477 relation = g_slice_new (AtkRelationData);
10478 relation->target = target;
10479 relation->type = type;
10481 data->relations = g_slist_prepend (data->relations, relation);
10483 else if (strcmp (element_name, "action") == 0)
10485 const gchar *action_name = NULL;
10486 const gchar *description = NULL;
10487 const gchar *msg_context = NULL;
10488 gboolean translatable = FALSE;
10489 AtkActionData *action;
10491 for (i = 0; names[i]; i++)
10493 if (strcmp (names[i], "action_name") == 0)
10494 action_name = values[i];
10495 else if (strcmp (names[i], "description") == 0)
10496 description = values[i];
10497 else if (strcmp (names[i], "translatable") == 0)
10499 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10502 else if (strcmp (names[i], "comments") == 0)
10504 /* do nothing, comments are for translators */
10506 else if (strcmp (names[i], "context") == 0)
10507 msg_context = values[i];
10510 g_markup_parse_context_get_position (context,
10513 g_set_error (error,
10515 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10516 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10518 line_number, char_number, names[i], "action");
10525 g_markup_parse_context_get_position (context,
10528 g_set_error (error,
10530 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10531 "%s:%d:%d <%s> requires attribute \"%s\"",
10533 line_number, char_number, "action",
10538 action = g_slice_new (AtkActionData);
10539 action->action_name = g_strdup (action_name);
10540 action->description = g_string_new (description);
10541 action->context = g_strdup (msg_context);
10542 action->translatable = translatable;
10544 data->actions = g_slist_prepend (data->actions, action);
10546 else if (strcmp (element_name, "accessibility") == 0)
10549 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10553 accessibility_text (GMarkupParseContext *context,
10556 gpointer user_data,
10559 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10561 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10563 AtkActionData *action = data->actions->data;
10565 g_string_append_len (action->description, text, text_len);
10569 static const GMarkupParser accessibility_parser =
10571 accessibility_start_element,
10573 accessibility_text,
10582 } AccelGroupParserData;
10585 accel_group_start_element (GMarkupParseContext *context,
10586 const gchar *element_name,
10587 const gchar **names,
10588 const gchar **values,
10589 gpointer user_data,
10594 guint modifiers = 0;
10595 gchar *signal = NULL;
10596 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10598 for (i = 0; names[i]; i++)
10600 if (strcmp (names[i], "key") == 0)
10601 key = gdk_keyval_from_name (values[i]);
10602 else if (strcmp (names[i], "modifiers") == 0)
10604 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10610 else if (strcmp (names[i], "signal") == 0)
10611 signal = g_strdup (values[i]);
10614 if (key == 0 || signal == NULL)
10616 g_warning ("<accelerator> requires key and signal attributes");
10619 parser_data->key = key;
10620 parser_data->modifiers = modifiers;
10621 parser_data->signal = signal;
10624 static const GMarkupParser accel_group_parser =
10626 accel_group_start_element,
10630 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10631 GtkBuilder *builder,
10633 const gchar *tagname,
10634 GMarkupParser *parser,
10637 g_assert (buildable);
10639 if (strcmp (tagname, "accelerator") == 0)
10641 AccelGroupParserData *parser_data;
10643 parser_data = g_slice_new0 (AccelGroupParserData);
10644 parser_data->object = g_object_ref (buildable);
10645 *parser = accel_group_parser;
10646 *data = parser_data;
10649 if (strcmp (tagname, "accessibility") == 0)
10651 AccessibilitySubParserData *parser_data;
10653 parser_data = g_slice_new0 (AccessibilitySubParserData);
10654 *parser = accessibility_parser;
10655 *data = parser_data;
10662 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10663 GtkWidget *toplevel,
10664 gpointer user_data)
10666 AccelGroupParserData *accel_data;
10667 GSList *accel_groups;
10668 GtkAccelGroup *accel_group;
10670 g_return_if_fail (GTK_IS_WIDGET (widget));
10671 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10672 g_return_if_fail (user_data != NULL);
10674 accel_data = (AccelGroupParserData*)user_data;
10675 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10676 if (g_slist_length (accel_groups) == 0)
10678 accel_group = gtk_accel_group_new ();
10679 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10683 g_assert (g_slist_length (accel_groups) == 1);
10684 accel_group = g_slist_nth_data (accel_groups, 0);
10687 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10688 accel_data->signal,
10691 accel_data->modifiers,
10692 GTK_ACCEL_VISIBLE);
10694 g_object_unref (accel_data->object);
10695 g_free (accel_data->signal);
10696 g_slice_free (AccelGroupParserData, accel_data);
10700 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10701 GtkBuilder *builder,
10703 const gchar *tagname,
10704 gpointer user_data)
10706 AccelGroupParserData *accel_data;
10707 AccessibilitySubParserData *a11y_data;
10708 GtkWidget *toplevel;
10710 if (strcmp (tagname, "accelerator") == 0)
10712 accel_data = (AccelGroupParserData*)user_data;
10713 g_assert (accel_data->object);
10715 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10717 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10719 else if (strcmp (tagname, "accessibility") == 0)
10721 a11y_data = (AccessibilitySubParserData*)user_data;
10723 if (a11y_data->actions)
10725 AtkObject *accessible;
10730 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10732 action = ATK_ACTION (accessible);
10733 n_actions = atk_action_get_n_actions (action);
10735 for (l = a11y_data->actions; l; l = l->next)
10737 AtkActionData *action_data = (AtkActionData*)l->data;
10739 for (i = 0; i < n_actions; i++)
10740 if (strcmp (atk_action_get_name (action, i),
10741 action_data->action_name) == 0)
10746 gchar *description;
10748 if (action_data->translatable && action_data->description->len)
10749 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10750 action_data->context,
10751 action_data->description->str);
10753 description = action_data->description->str;
10755 atk_action_set_description (action, i, description);
10759 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10760 g_slist_free (a11y_data->actions);
10763 if (a11y_data->relations)
10764 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10765 a11y_data->relations);
10767 g_slice_free (AccessibilitySubParserData, a11y_data);
10773 * gtk_widget_get_clipboard:
10774 * @widget: a #GtkWidget
10775 * @selection: a #GdkAtom which identifies the clipboard
10776 * to use. %GDK_SELECTION_CLIPBOARD gives the
10777 * default clipboard. Another common value
10778 * is %GDK_SELECTION_PRIMARY, which gives
10779 * the primary X selection.
10781 * Returns the clipboard object for the given selection to
10782 * be used with @widget. @widget must have a #GdkDisplay
10783 * associated with it, so must be attached to a toplevel
10786 * Return value: (transfer none): the appropriate clipboard object. If no
10787 * clipboard already exists, a new one will
10788 * be created. Once a clipboard object has
10789 * been created, it is persistent for all time.
10794 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10796 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10797 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10799 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10804 * gtk_widget_list_mnemonic_labels:
10805 * @widget: a #GtkWidget
10807 * Returns a newly allocated list of the widgets, normally labels, for
10808 * which this widget is a the target of a mnemonic (see for example,
10809 * gtk_label_set_mnemonic_widget()).
10811 * The widgets in the list are not individually referenced. If you
10812 * want to iterate through the list and perform actions involving
10813 * callbacks that might destroy the widgets, you
10814 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10815 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10816 * widgets afterwards.
10818 * Return value: (element-type GtkWidget) (transfer container): the list of
10819 * mnemonic labels; free this list
10820 * with g_list_free() when you are done with it.
10825 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10827 GList *list = NULL;
10830 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10832 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10833 list = g_list_prepend (list, l->data);
10839 * gtk_widget_add_mnemonic_label:
10840 * @widget: a #GtkWidget
10841 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10843 * Adds a widget to the list of mnemonic labels for
10844 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10845 * list of mnemonic labels for the widget is cleared when the
10846 * widget is destroyed, so the caller must make sure to update
10847 * its internal state at this point as well, by using a connection
10848 * to the #GtkWidget::destroy signal or a weak notifier.
10853 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10856 GSList *old_list, *new_list;
10858 g_return_if_fail (GTK_IS_WIDGET (widget));
10859 g_return_if_fail (GTK_IS_WIDGET (label));
10861 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10862 new_list = g_slist_prepend (old_list, label);
10864 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10865 new_list, (GDestroyNotify) g_slist_free);
10869 * gtk_widget_remove_mnemonic_label:
10870 * @widget: a #GtkWidget
10871 * @label: a #GtkWidget that was previously set as a mnemnic label for
10872 * @widget with gtk_widget_add_mnemonic_label().
10874 * Removes a widget from the list of mnemonic labels for
10875 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10876 * must have previously been added to the list with
10877 * gtk_widget_add_mnemonic_label().
10882 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10885 GSList *old_list, *new_list;
10887 g_return_if_fail (GTK_IS_WIDGET (widget));
10888 g_return_if_fail (GTK_IS_WIDGET (label));
10890 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10891 new_list = g_slist_remove (old_list, label);
10894 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10895 new_list, (GDestroyNotify) g_slist_free);
10899 * gtk_widget_get_no_show_all:
10900 * @widget: a #GtkWidget
10902 * Returns the current value of the GtkWidget:no-show-all property,
10903 * which determines whether calls to gtk_widget_show_all() and
10904 * gtk_widget_hide_all() will affect this widget.
10906 * Return value: the current value of the "no-show-all" property.
10911 gtk_widget_get_no_show_all (GtkWidget *widget)
10913 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10915 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10919 * gtk_widget_set_no_show_all:
10920 * @widget: a #GtkWidget
10921 * @no_show_all: the new value for the "no-show-all" property
10923 * Sets the #GtkWidget:no-show-all property, which determines whether
10924 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10927 * This is mostly for use in constructing widget hierarchies with externally
10928 * controlled visibility, see #GtkUIManager.
10933 gtk_widget_set_no_show_all (GtkWidget *widget,
10934 gboolean no_show_all)
10936 g_return_if_fail (GTK_IS_WIDGET (widget));
10938 no_show_all = (no_show_all != FALSE);
10940 if (no_show_all == gtk_widget_get_no_show_all (widget))
10944 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
10946 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
10948 g_object_notify (G_OBJECT (widget), "no-show-all");
10953 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10954 gboolean has_tooltip,
10957 gboolean priv_has_tooltip;
10959 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10960 quark_has_tooltip));
10962 if (priv_has_tooltip != has_tooltip || force)
10964 priv_has_tooltip = has_tooltip;
10966 if (priv_has_tooltip)
10968 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
10969 gdk_window_set_events (widget->window,
10970 gdk_window_get_events (widget->window) |
10971 GDK_LEAVE_NOTIFY_MASK |
10972 GDK_POINTER_MOTION_MASK |
10973 GDK_POINTER_MOTION_HINT_MASK);
10975 if (gtk_widget_get_has_window (widget))
10976 gtk_widget_add_events (widget,
10977 GDK_LEAVE_NOTIFY_MASK |
10978 GDK_POINTER_MOTION_MASK |
10979 GDK_POINTER_MOTION_HINT_MASK);
10982 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10983 GUINT_TO_POINTER (priv_has_tooltip));
10988 * gtk_widget_set_tooltip_window:
10989 * @widget: a #GtkWidget
10990 * @custom_window: (allow-none): a #GtkWindow, or %NULL
10992 * Replaces the default, usually yellow, window used for displaying
10993 * tooltips with @custom_window. GTK+ will take care of showing and
10994 * hiding @custom_window at the right moment, to behave likewise as
10995 * the default tooltip window. If @custom_window is %NULL, the default
10996 * tooltip window will be used.
10998 * If the custom window should have the default theming it needs to
10999 * have the name "gtk-tooltip", see gtk_widget_set_name().
11004 gtk_widget_set_tooltip_window (GtkWidget *widget,
11005 GtkWindow *custom_window)
11007 gboolean has_tooltip;
11008 gchar *tooltip_markup;
11010 g_return_if_fail (GTK_IS_WIDGET (widget));
11011 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11013 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11016 g_object_ref (custom_window);
11018 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11019 custom_window, g_object_unref);
11021 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11022 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11024 if (has_tooltip && gtk_widget_get_visible (widget))
11025 gtk_widget_queue_tooltip_query (widget);
11029 * gtk_widget_get_tooltip_window:
11030 * @widget: a #GtkWidget
11032 * Returns the #GtkWindow of the current tooltip. This can be the
11033 * GtkWindow created by default, or the custom tooltip window set
11034 * using gtk_widget_set_tooltip_window().
11036 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11041 gtk_widget_get_tooltip_window (GtkWidget *widget)
11043 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11045 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11049 * gtk_widget_trigger_tooltip_query:
11050 * @widget: a #GtkWidget
11052 * Triggers a tooltip query on the display where the toplevel of @widget
11053 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11059 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11061 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11064 static guint tooltip_query_id;
11065 static GSList *tooltip_query_displays;
11068 tooltip_query_idle (gpointer data)
11070 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11071 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11072 g_slist_free (tooltip_query_displays);
11074 tooltip_query_displays = NULL;
11075 tooltip_query_id = 0;
11081 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11083 GdkDisplay *display;
11085 display = gtk_widget_get_display (widget);
11087 if (!g_slist_find (tooltip_query_displays, display))
11088 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11090 if (tooltip_query_id == 0)
11091 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11095 * gtk_widget_set_tooltip_text:
11096 * @widget: a #GtkWidget
11097 * @text: the contents of the tooltip for @widget
11099 * Sets @text as the contents of the tooltip. This function will take
11100 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11101 * handler for the GtkWidget::query-tooltip signal.
11103 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11108 gtk_widget_set_tooltip_text (GtkWidget *widget,
11111 g_return_if_fail (GTK_IS_WIDGET (widget));
11113 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11117 * gtk_widget_get_tooltip_text:
11118 * @widget: a #GtkWidget
11120 * Gets the contents of the tooltip for @widget.
11122 * Return value: the tooltip text, or %NULL. You should free the
11123 * returned string with g_free() when done.
11128 gtk_widget_get_tooltip_text (GtkWidget *widget)
11130 gchar *text = NULL;
11132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11134 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11140 * gtk_widget_set_tooltip_markup:
11141 * @widget: a #GtkWidget
11142 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11144 * Sets @markup as the contents of the tooltip, which is marked up with
11145 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11147 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11148 * and of the default handler for the GtkWidget::query-tooltip signal.
11150 * See also the GtkWidget:tooltip-markup property and
11151 * gtk_tooltip_set_markup().
11156 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11157 const gchar *markup)
11159 g_return_if_fail (GTK_IS_WIDGET (widget));
11161 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11165 * gtk_widget_get_tooltip_markup:
11166 * @widget: a #GtkWidget
11168 * Gets the contents of the tooltip for @widget.
11170 * Return value: the tooltip text, or %NULL. You should free the
11171 * returned string with g_free() when done.
11176 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11178 gchar *text = NULL;
11180 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11182 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11188 * gtk_widget_set_has_tooltip:
11189 * @widget: a #GtkWidget
11190 * @has_tooltip: whether or not @widget has a tooltip.
11192 * Sets the has-tooltip property on @widget to @has_tooltip. See
11193 * GtkWidget:has-tooltip for more information.
11198 gtk_widget_set_has_tooltip (GtkWidget *widget,
11199 gboolean has_tooltip)
11201 g_return_if_fail (GTK_IS_WIDGET (widget));
11203 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11207 * gtk_widget_get_has_tooltip:
11208 * @widget: a #GtkWidget
11210 * Returns the current value of the has-tooltip property. See
11211 * GtkWidget:has-tooltip for more information.
11213 * Return value: current value of has-tooltip on @widget.
11218 gtk_widget_get_has_tooltip (GtkWidget *widget)
11220 gboolean has_tooltip = FALSE;
11222 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11224 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11226 return has_tooltip;
11230 * gtk_widget_get_allocation:
11231 * @widget: a #GtkWidget
11232 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11234 * Retrieves the widget's allocation.
11239 gtk_widget_get_allocation (GtkWidget *widget,
11240 GtkAllocation *allocation)
11242 g_return_if_fail (GTK_IS_WIDGET (widget));
11243 g_return_if_fail (allocation != NULL);
11245 *allocation = widget->allocation;
11249 * gtk_widget_set_allocation:
11250 * @widget: a #GtkWidget
11251 * @allocation: a pointer to a #GtkAllocation to copy from
11253 * Sets the widget's allocation. This should not be used
11254 * directly, but from within a widget's size_allocate method.
11259 gtk_widget_set_allocation (GtkWidget *widget,
11260 const GtkAllocation *allocation)
11262 g_return_if_fail (GTK_IS_WIDGET (widget));
11263 g_return_if_fail (allocation != NULL);
11265 widget->allocation = *allocation;
11269 * gtk_widget_get_requisition:
11270 * @widget: a #GtkWidget
11271 * @requisition: (out): a pointer to a #GtkRequisition to copy to
11273 * Retrieves the widget's requisition.
11275 * This function should only be used by widget implementations in
11276 * order to figure whether the widget's requisition has actually
11277 * changed after some internal state change (so that they can call
11278 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
11280 * Normally, gtk_widget_size_request() should be used.
11285 gtk_widget_get_requisition (GtkWidget *widget,
11286 GtkRequisition *requisition)
11288 g_return_if_fail (GTK_IS_WIDGET (widget));
11289 g_return_if_fail (requisition != NULL);
11291 *requisition = widget->requisition;
11295 * gtk_widget_set_window:
11296 * @widget: a #GtkWidget
11297 * @window: a #GdkWindow
11299 * Sets a widget's window. This function should only be used in a
11300 * widget's GtkWidget::realize() implementation. The %window passed is
11301 * usually either new window created with gdk_window_new(), or the
11302 * window of its parent widget as returned by
11303 * gtk_widget_get_parent_window().
11305 * Widgets must indicate whether they will create their own #GdkWindow
11306 * by calling gtk_widget_set_has_window(). This is usually done in the
11307 * widget's init() function.
11312 gtk_widget_set_window (GtkWidget *widget,
11315 g_return_if_fail (GTK_IS_WIDGET (widget));
11316 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11318 if (widget->window != window)
11320 widget->window = window;
11321 g_object_notify (G_OBJECT (widget), "window");
11326 * gtk_widget_get_window:
11327 * @widget: a #GtkWidget
11329 * Returns the widget's window if it is realized, %NULL otherwise
11331 * Return value: @widget's window.
11336 gtk_widget_get_window (GtkWidget *widget)
11338 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11340 return widget->window;
11344 _gtk_widget_set_has_focus (GtkWidget *widget,
11345 gboolean has_focus)
11348 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
11350 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
11354 * gtk_widget_send_focus_change:
11355 * @widget: a #GtkWidget
11356 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
11358 * Sends the focus change @event to @widget
11360 * This function is not meant to be used by applications. The only time it
11361 * should be used is when it is necessary for a #GtkWidget to assign focus
11362 * to a widget that is semantically owned by the first widget even though
11363 * it's not a direct child - for instance, a search entry in a floating
11364 * window similar to the quick search in #GtkTreeView.
11366 * An example of its usage is:
11369 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
11371 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
11372 * fevent->focus_change.in = TRUE;
11373 * fevent->focus_change.window = gtk_widget_get_window (widget);
11374 * if (fevent->focus_change.window != NULL)
11375 * g_object_ref (fevent->focus_change.window);
11377 * gtk_widget_send_focus_change (widget, fevent);
11379 * gdk_event_free (event);
11382 * Return value: the return value from the event signal emission: %TRUE
11383 * if the event was handled, and %FALSE otherwise
11388 gtk_widget_send_focus_change (GtkWidget *widget,
11393 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11394 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
11396 g_object_ref (widget);
11398 _gtk_widget_set_has_focus (widget, event->focus_change.in);
11400 res = gtk_widget_event (widget, event);
11402 g_object_notify (G_OBJECT (widget), "has-focus");
11404 g_object_unref (widget);
11409 #define __GTK_WIDGET_C__
11410 #include "gtkaliasdef.c"