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"
58 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
59 #define INIT_PATH_SIZE (512)
100 PROPERTY_NOTIFY_EVENT,
101 SELECTION_CLEAR_EVENT,
102 SELECTION_REQUEST_EVENT,
103 SELECTION_NOTIFY_EVENT,
118 VISIBILITY_NOTIFY_EVENT,
122 ACCEL_CLOSURES_CHANGED,
148 PROP_RECEIVES_DEFAULT,
149 PROP_COMPOSITE_CHILD,
152 PROP_EXTENSION_EVENTS,
161 typedef struct _GtkStateData GtkStateData;
166 guint state_restoration : 1;
167 guint parent_sensitive : 1;
168 guint use_forall : 1;
171 /* --- prototypes --- */
172 static void gtk_widget_class_init (GtkWidgetClass *klass);
173 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
174 static void gtk_widget_init (GtkWidget *widget);
175 static void gtk_widget_set_property (GObject *object,
179 static void gtk_widget_get_property (GObject *object,
183 static void gtk_widget_dispose (GObject *object);
184 static void gtk_widget_real_destroy (GtkObject *object);
185 static void gtk_widget_finalize (GObject *object);
186 static void gtk_widget_real_show (GtkWidget *widget);
187 static void gtk_widget_real_hide (GtkWidget *widget);
188 static void gtk_widget_real_map (GtkWidget *widget);
189 static void gtk_widget_real_unmap (GtkWidget *widget);
190 static void gtk_widget_real_realize (GtkWidget *widget);
191 static void gtk_widget_real_unrealize (GtkWidget *widget);
192 static void gtk_widget_real_size_request (GtkWidget *widget,
193 GtkRequisition *requisition);
194 static void gtk_widget_real_size_allocate (GtkWidget *widget,
195 GtkAllocation *allocation);
196 static void gtk_widget_real_style_set (GtkWidget *widget,
197 GtkStyle *previous_style);
198 static void gtk_widget_real_direction_changed(GtkWidget *widget,
199 GtkTextDirection previous_direction);
201 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
202 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
205 gboolean keyboard_tip,
206 GtkTooltip *tooltip);
207 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
208 GtkWidgetHelpType help_type);
210 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
212 GParamSpec **pspecs);
213 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
215 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
217 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
218 GdkEventFocus *event);
219 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
220 GdkEventFocus *event);
221 static gboolean gtk_widget_real_focus (GtkWidget *widget,
222 GtkDirectionType direction);
223 static void gtk_widget_real_move_focus (GtkWidget *widget,
224 GtkDirectionType direction);
225 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
226 GtkDirectionType direction);
227 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
228 static void gtk_widget_update_pango_context (GtkWidget *widget);
229 static void gtk_widget_propagate_state (GtkWidget *widget,
231 static void gtk_widget_reset_rc_style (GtkWidget *widget);
232 static void gtk_widget_set_style_internal (GtkWidget *widget,
234 gboolean initial_emission);
235 static gint gtk_widget_event_internal (GtkWidget *widget,
237 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
238 gboolean group_cycling);
239 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
240 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
241 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
242 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
243 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
245 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
246 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
247 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
250 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
251 gboolean has_tooltip,
253 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
254 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
256 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
257 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
259 const gchar *childname);
260 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
263 const GValue *value);
264 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
267 const gchar *tagname,
268 GMarkupParser *parser,
270 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
273 const gchar *tagname,
275 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
276 GtkBuilder *builder);
278 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
280 static void gtk_widget_set_usize_internal (GtkWidget *widget,
283 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
287 /* --- variables --- */
288 static gpointer gtk_widget_parent_class = NULL;
289 static guint widget_signals[LAST_SIGNAL] = { 0 };
290 static GtkStyle *gtk_default_style = NULL;
291 static GSList *colormap_stack = NULL;
292 static guint composite_child_stack = 0;
293 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
294 static GParamSpecPool *style_property_spec_pool = NULL;
296 static GQuark quark_property_parser = 0;
297 static GQuark quark_aux_info = 0;
298 static GQuark quark_accel_path = 0;
299 static GQuark quark_accel_closures = 0;
300 static GQuark quark_event_mask = 0;
301 static GQuark quark_extension_event_mode = 0;
302 static GQuark quark_parent_window = 0;
303 static GQuark quark_pointer_window = 0;
304 static GQuark quark_shape_info = 0;
305 static GQuark quark_input_shape_info = 0;
306 static GQuark quark_colormap = 0;
307 static GQuark quark_pango_context = 0;
308 static GQuark quark_rc_style = 0;
309 static GQuark quark_accessible_object = 0;
310 static GQuark quark_mnemonic_labels = 0;
311 static GQuark quark_tooltip_markup = 0;
312 static GQuark quark_has_tooltip = 0;
313 static GQuark quark_tooltip_window = 0;
314 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
315 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
317 /* --- functions --- */
319 gtk_widget_get_type (void)
321 static GType widget_type = 0;
323 if (G_UNLIKELY (widget_type == 0))
325 const GTypeInfo widget_info =
327 sizeof (GtkWidgetClass),
328 NULL, /* base_init */
329 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
330 (GClassInitFunc) gtk_widget_class_init,
331 NULL, /* class_finalize */
332 NULL, /* class_init */
335 (GInstanceInitFunc) gtk_widget_init,
336 NULL, /* value_table */
339 const GInterfaceInfo accessibility_info =
341 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
342 (GInterfaceFinalizeFunc) NULL,
343 NULL /* interface data */
346 const GInterfaceInfo buildable_info =
348 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
349 (GInterfaceFinalizeFunc) NULL,
350 NULL /* interface data */
353 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
354 &widget_info, G_TYPE_FLAG_ABSTRACT);
356 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
357 &accessibility_info) ;
358 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
367 child_property_notify_dispatcher (GObject *object,
371 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
375 gtk_widget_class_init (GtkWidgetClass *klass)
377 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
378 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
379 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
380 GtkBindingSet *binding_set;
382 gtk_widget_parent_class = g_type_class_peek_parent (klass);
384 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
385 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
386 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
387 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
388 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
389 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
390 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
391 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
392 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
393 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
394 quark_colormap = g_quark_from_static_string ("gtk-colormap");
395 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
396 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
397 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
398 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
399 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
400 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
401 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
403 style_property_spec_pool = g_param_spec_pool_new (FALSE);
404 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
405 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
406 cpn_context.dispatcher = child_property_notify_dispatcher;
407 _gtk_widget_child_property_notify_context = &cpn_context;
409 gobject_class->dispose = gtk_widget_dispose;
410 gobject_class->finalize = gtk_widget_finalize;
411 gobject_class->set_property = gtk_widget_set_property;
412 gobject_class->get_property = gtk_widget_get_property;
414 object_class->destroy = gtk_widget_real_destroy;
416 klass->activate_signal = 0;
417 klass->set_scroll_adjustments_signal = 0;
418 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
419 klass->show = gtk_widget_real_show;
420 klass->show_all = gtk_widget_show;
421 klass->hide = gtk_widget_real_hide;
422 klass->hide_all = gtk_widget_hide;
423 klass->map = gtk_widget_real_map;
424 klass->unmap = gtk_widget_real_unmap;
425 klass->realize = gtk_widget_real_realize;
426 klass->unrealize = gtk_widget_real_unrealize;
427 klass->size_request = gtk_widget_real_size_request;
428 klass->size_allocate = gtk_widget_real_size_allocate;
429 klass->state_changed = NULL;
430 klass->parent_set = NULL;
431 klass->hierarchy_changed = NULL;
432 klass->style_set = gtk_widget_real_style_set;
433 klass->direction_changed = gtk_widget_real_direction_changed;
434 klass->grab_notify = NULL;
435 klass->child_notify = NULL;
436 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
437 klass->grab_focus = gtk_widget_real_grab_focus;
438 klass->focus = gtk_widget_real_focus;
440 klass->button_press_event = NULL;
441 klass->button_release_event = NULL;
442 klass->motion_notify_event = NULL;
443 klass->delete_event = NULL;
444 klass->destroy_event = NULL;
445 klass->expose_event = NULL;
446 klass->key_press_event = gtk_widget_real_key_press_event;
447 klass->key_release_event = gtk_widget_real_key_release_event;
448 klass->enter_notify_event = NULL;
449 klass->leave_notify_event = NULL;
450 klass->configure_event = NULL;
451 klass->focus_in_event = gtk_widget_real_focus_in_event;
452 klass->focus_out_event = gtk_widget_real_focus_out_event;
453 klass->map_event = NULL;
454 klass->unmap_event = NULL;
455 klass->window_state_event = NULL;
456 klass->property_notify_event = _gtk_selection_property_notify;
457 klass->selection_clear_event = gtk_selection_clear;
458 klass->selection_request_event = _gtk_selection_request;
459 klass->selection_notify_event = _gtk_selection_notify;
460 klass->selection_received = NULL;
461 klass->proximity_in_event = NULL;
462 klass->proximity_out_event = NULL;
463 klass->drag_begin = NULL;
464 klass->drag_end = NULL;
465 klass->drag_data_delete = NULL;
466 klass->drag_leave = NULL;
467 klass->drag_motion = NULL;
468 klass->drag_drop = NULL;
469 klass->drag_data_received = NULL;
470 klass->screen_changed = NULL;
471 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
472 klass->grab_broken_event = NULL;
473 klass->query_tooltip = gtk_widget_real_query_tooltip;
475 klass->show_help = gtk_widget_real_show_help;
477 /* Accessibility support */
478 klass->get_accessible = gtk_widget_real_get_accessible;
480 klass->no_expose_event = NULL;
482 g_object_class_install_property (gobject_class,
484 g_param_spec_string ("name",
486 P_("The name of the widget"),
488 GTK_PARAM_READWRITE));
489 g_object_class_install_property (gobject_class,
491 g_param_spec_object ("parent",
493 P_("The parent widget of this widget. Must be a Container widget"),
495 GTK_PARAM_READWRITE));
497 g_object_class_install_property (gobject_class,
499 g_param_spec_int ("width-request",
501 P_("Override for width request of the widget, or -1 if natural request should be used"),
505 GTK_PARAM_READWRITE));
506 g_object_class_install_property (gobject_class,
508 g_param_spec_int ("height-request",
509 P_("Height request"),
510 P_("Override for height request of the widget, or -1 if natural request should be used"),
514 GTK_PARAM_READWRITE));
515 g_object_class_install_property (gobject_class,
517 g_param_spec_boolean ("visible",
519 P_("Whether the widget is visible"),
521 GTK_PARAM_READWRITE));
522 g_object_class_install_property (gobject_class,
524 g_param_spec_boolean ("sensitive",
526 P_("Whether the widget responds to input"),
528 GTK_PARAM_READWRITE));
529 g_object_class_install_property (gobject_class,
531 g_param_spec_boolean ("app-paintable",
532 P_("Application paintable"),
533 P_("Whether the application will paint directly on the widget"),
535 GTK_PARAM_READWRITE));
536 g_object_class_install_property (gobject_class,
538 g_param_spec_boolean ("can-focus",
540 P_("Whether the widget can accept the input focus"),
542 GTK_PARAM_READWRITE));
543 g_object_class_install_property (gobject_class,
545 g_param_spec_boolean ("has-focus",
547 P_("Whether the widget has the input focus"),
549 GTK_PARAM_READWRITE));
550 g_object_class_install_property (gobject_class,
552 g_param_spec_boolean ("is-focus",
554 P_("Whether the widget is the focus widget within the toplevel"),
556 GTK_PARAM_READWRITE));
557 g_object_class_install_property (gobject_class,
559 g_param_spec_boolean ("can-default",
561 P_("Whether the widget can be the default widget"),
563 GTK_PARAM_READWRITE));
564 g_object_class_install_property (gobject_class,
566 g_param_spec_boolean ("has-default",
568 P_("Whether the widget is the default widget"),
570 GTK_PARAM_READWRITE));
571 g_object_class_install_property (gobject_class,
572 PROP_RECEIVES_DEFAULT,
573 g_param_spec_boolean ("receives-default",
574 P_("Receives default"),
575 P_("If TRUE, the widget will receive the default action when it is focused"),
577 GTK_PARAM_READWRITE));
578 g_object_class_install_property (gobject_class,
579 PROP_COMPOSITE_CHILD,
580 g_param_spec_boolean ("composite-child",
581 P_("Composite child"),
582 P_("Whether the widget is part of a composite widget"),
584 GTK_PARAM_READABLE));
585 g_object_class_install_property (gobject_class,
587 g_param_spec_object ("style",
589 P_("The style of the widget, which contains information about how it will look (colors etc)"),
591 GTK_PARAM_READWRITE));
592 g_object_class_install_property (gobject_class,
594 g_param_spec_flags ("events",
596 P_("The event mask that decides what kind of GdkEvents this widget gets"),
599 GTK_PARAM_READWRITE));
600 g_object_class_install_property (gobject_class,
601 PROP_EXTENSION_EVENTS,
602 g_param_spec_enum ("extension-events",
603 P_("Extension events"),
604 P_("The mask that decides what kind of extension events this widget gets"),
605 GDK_TYPE_EXTENSION_MODE,
606 GDK_EXTENSION_EVENTS_NONE,
607 GTK_PARAM_READWRITE));
608 g_object_class_install_property (gobject_class,
610 g_param_spec_boolean ("no-show-all",
612 P_("Whether gtk_widget_show_all() should not affect this widget"),
614 GTK_PARAM_READWRITE));
617 * GtkWidget:has-tooltip:
619 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
620 * A value of %TRUE indicates that @widget can have a tooltip, in this case
621 * the widget will be queried using #GtkWidget::query-tooltip to determine
622 * whether it will provide a tooltip or not.
624 * Note that setting this property to %TRUE for the first time will change
625 * the event masks of the GdkWindows of this widget to include leave-notify
626 * and motion-notify events. This cannot and will not be undone when the
627 * property is set to %FALSE again.
631 g_object_class_install_property (gobject_class,
633 g_param_spec_boolean ("has-tooltip",
635 P_("Whether this widget has a tooltip"),
637 GTK_PARAM_READWRITE));
639 * GtkWidget:tooltip-text:
641 * Sets the text of tooltip to be the given string.
643 * Also see gtk_tooltip_set_text().
645 * This is a convenience property which will take care of getting the
646 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
647 * will automatically be set to %TRUE and there will be taken care of
648 * #GtkWidget::query-tooltip in the default signal handler.
652 g_object_class_install_property (gobject_class,
654 g_param_spec_string ("tooltip-text",
656 P_("The contents of the tooltip for this widget"),
658 GTK_PARAM_READWRITE));
660 * GtkWidget:tooltip-markup:
662 * Sets the text of tooltip to be the given string, which is marked up
663 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
664 * Also see gtk_tooltip_set_markup().
666 * This is a convenience property which will take care of getting the
667 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
668 * will automatically be set to %TRUE and there will be taken care of
669 * #GtkWidget::query-tooltip in the default signal handler.
673 g_object_class_install_property (gobject_class,
675 g_param_spec_string ("tooltip-markup",
676 P_("Tooltip markup"),
677 P_("The contents of the tooltip for this widget"),
679 GTK_PARAM_READWRITE));
684 * The widget's window if it is realized, %NULL otherwise.
688 g_object_class_install_property (gobject_class,
690 g_param_spec_object ("window",
692 P_("The widget's window if it is realized"),
694 GTK_PARAM_READABLE));
697 * GtkWidget:double-buffered
699 * Whether or not the widget is double buffered.
703 g_object_class_install_property (gobject_class,
704 PROP_DOUBLE_BUFFERED,
705 g_param_spec_boolean ("double-buffered",
706 P_("Double Buffered"),
707 P_("Whether or not the widget is double buffered"),
709 GTK_PARAM_READWRITE));
711 widget_signals[SHOW] =
712 g_signal_new (I_("show"),
713 G_TYPE_FROM_CLASS (gobject_class),
715 G_STRUCT_OFFSET (GtkWidgetClass, show),
717 _gtk_marshal_VOID__VOID,
719 widget_signals[HIDE] =
720 g_signal_new (I_("hide"),
721 G_TYPE_FROM_CLASS (gobject_class),
723 G_STRUCT_OFFSET (GtkWidgetClass, hide),
725 _gtk_marshal_VOID__VOID,
727 widget_signals[MAP] =
728 g_signal_new (I_("map"),
729 G_TYPE_FROM_CLASS (gobject_class),
731 G_STRUCT_OFFSET (GtkWidgetClass, map),
733 _gtk_marshal_VOID__VOID,
735 widget_signals[UNMAP] =
736 g_signal_new (I_("unmap"),
737 G_TYPE_FROM_CLASS (gobject_class),
739 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
741 _gtk_marshal_VOID__VOID,
743 widget_signals[REALIZE] =
744 g_signal_new (I_("realize"),
745 G_TYPE_FROM_CLASS (gobject_class),
747 G_STRUCT_OFFSET (GtkWidgetClass, realize),
749 _gtk_marshal_VOID__VOID,
751 widget_signals[UNREALIZE] =
752 g_signal_new (I_("unrealize"),
753 G_TYPE_FROM_CLASS (gobject_class),
755 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
757 _gtk_marshal_VOID__VOID,
759 widget_signals[SIZE_REQUEST] =
760 g_signal_new (I_("size-request"),
761 G_TYPE_FROM_CLASS (gobject_class),
763 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
765 _gtk_marshal_VOID__BOXED,
767 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
768 widget_signals[SIZE_ALLOCATE] =
769 g_signal_new (I_("size-allocate"),
770 G_TYPE_FROM_CLASS (gobject_class),
772 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
774 _gtk_marshal_VOID__BOXED,
776 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
778 widget_signals[STATE_CHANGED] =
779 g_signal_new (I_("state-changed"),
780 G_TYPE_FROM_CLASS (gobject_class),
782 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
784 _gtk_marshal_VOID__ENUM,
786 GTK_TYPE_STATE_TYPE);
789 * GtkWidget::parent-set:
790 * @widget: the object on which the signal is emitted
791 * @old_parent: the previous parent, or %NULL if the widget
792 * just got its initial parent.
794 * The ::parent-set signal is emitted when a new parent
795 * has been set on a widget.
797 widget_signals[PARENT_SET] =
798 g_signal_new (I_("parent-set"),
799 G_TYPE_FROM_CLASS (gobject_class),
801 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
803 _gtk_marshal_VOID__OBJECT,
808 * GtkWidget::hierarchy-changed:
809 * @widget: the object on which the signal is emitted
810 * @previous_toplevel: the previous toplevel ancestor, or %NULL
811 * if the widget was previously unanchored
813 * The ::hierarchy-changed signal is emitted when the
814 * anchored state of a widget changes. A widget is
815 * <firstterm>anchored</firstterm> when its toplevel
816 * ancestor is a #GtkWindow. This signal is emitted when
817 * a widget changes from un-anchored to anchored or vice-versa.
819 widget_signals[HIERARCHY_CHANGED] =
820 g_signal_new (I_("hierarchy-changed"),
821 G_TYPE_FROM_CLASS (gobject_class),
823 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
825 _gtk_marshal_VOID__OBJECT,
830 * GtkWidget::style-set:
831 * @widget: the object on which the signal is emitted
832 * @previous_style: the previous style, or %NULL if the widget
833 * just got its initial style
835 * The ::style-set signal is emitted when a new style has been set
836 * on a widget. Note that style-modifying functions like
837 * gtk_widget_modify_base() also cause this signal to be emitted.
839 widget_signals[STYLE_SET] =
840 g_signal_new (I_("style-set"),
841 G_TYPE_FROM_CLASS (gobject_class),
843 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
845 _gtk_marshal_VOID__OBJECT,
849 * GtkWidget::direction-changed:
850 * @widget: the object on which the signal is emitted
851 * @previous_direction: the previous text direction of @widget
853 * The ::direction-changed signal is emitted when the text direction
854 * of a widget changes.
856 widget_signals[DIRECTION_CHANGED] =
857 g_signal_new (I_("direction-changed"),
858 G_TYPE_FROM_CLASS (gobject_class),
860 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
862 _gtk_marshal_VOID__ENUM,
864 GTK_TYPE_TEXT_DIRECTION);
867 * GtkWidget::grab-notify:
868 * @widget: the object which received the signal
869 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
870 * if it becomes unshadowed
872 * The ::grab-notify signal is emitted when a widget becomes
873 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
874 * another widget, or when it becomes unshadowed due to a grab
877 * A widget is shadowed by a gtk_grab_add() when the topmost
878 * grab widget in the grab stack of its window group is not
881 widget_signals[GRAB_NOTIFY] =
882 g_signal_new (I_("grab-notify"),
883 G_TYPE_FROM_CLASS (gobject_class),
885 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
887 _gtk_marshal_VOID__BOOLEAN,
892 * GtkWidget::child-notify:
893 * @widget: the object which received the signal
894 * @pspec: the #GParamSpec of the changed child property
896 * The ::child-notify signal is emitted for each
897 * <link linkend="child-properties">child property</link> that has
898 * changed on an object. The signal's detail holds the property name.
900 widget_signals[CHILD_NOTIFY] =
901 g_signal_new (I_("child-notify"),
902 G_TYPE_FROM_CLASS (gobject_class),
903 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
904 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
906 g_cclosure_marshal_VOID__PARAM,
909 widget_signals[MNEMONIC_ACTIVATE] =
910 g_signal_new (I_("mnemonic-activate"),
911 G_TYPE_FROM_CLASS (gobject_class),
913 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
914 _gtk_boolean_handled_accumulator, NULL,
915 _gtk_marshal_BOOLEAN__BOOLEAN,
918 widget_signals[GRAB_FOCUS] =
919 g_signal_new (I_("grab-focus"),
920 G_TYPE_FROM_CLASS (gobject_class),
921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
924 _gtk_marshal_VOID__VOID,
926 widget_signals[FOCUS] =
927 g_signal_new (I_("focus"),
928 G_TYPE_FROM_CLASS (object_class),
930 G_STRUCT_OFFSET (GtkWidgetClass, focus),
931 _gtk_boolean_handled_accumulator, NULL,
932 _gtk_marshal_BOOLEAN__ENUM,
934 GTK_TYPE_DIRECTION_TYPE);
935 widget_signals[MOVE_FOCUS] =
936 g_signal_new_class_handler (I_("move-focus"),
937 G_TYPE_FROM_CLASS (object_class),
938 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
939 G_CALLBACK (gtk_widget_real_move_focus),
941 _gtk_marshal_VOID__ENUM,
944 GTK_TYPE_DIRECTION_TYPE);
947 * @widget: the object which received the signal.
948 * @event: the #GdkEvent which triggered this signal
950 * The GTK+ main loop will emit three signals for each GDK event delivered
951 * to a widget: one generic ::event signal, another, more specific,
952 * signal that matches the type of event delivered (e.g.
953 * #GtkWidget::key-press-event) and finally a generic
954 * #GtkWidget::event-after signal.
956 * Returns: %TRUE to stop other handlers from being invoked for the event
957 * and to cancel the emission of the second specific ::event signal.
958 * %FALSE to propagate the event further and to allow the emission of
959 * the second signal. The ::event-after signal is emitted regardless of
962 widget_signals[EVENT] =
963 g_signal_new (I_("event"),
964 G_TYPE_FROM_CLASS (gobject_class),
966 G_STRUCT_OFFSET (GtkWidgetClass, event),
967 _gtk_boolean_handled_accumulator, NULL,
968 _gtk_marshal_BOOLEAN__BOXED,
970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
973 * GtkWidget::event-after:
974 * @widget: the object which received the signal.
975 * @event: the #GdkEvent which triggered this signal
977 * After the emission of the #GtkWidget::event signal and (optionally)
978 * the second more specific signal, ::event-after will be emitted
979 * regardless of the previous two signals handlers return values.
982 widget_signals[EVENT_AFTER] =
983 g_signal_new (I_("event-after"),
984 G_TYPE_FROM_CLASS (gobject_class),
988 _gtk_marshal_VOID__BOXED,
990 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
993 * GtkWidget::button-press-event:
994 * @widget: the object which received the signal.
995 * @event: the #GdkEventButton which triggered this signal
997 * The ::button-press-event signal will be emitted when a button
998 * (typically from a mouse) is pressed.
1000 * To receive this signal, the #GdkWindow associated to the
1001 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1003 * This signal will be sent to the grab widget if there is one.
1005 * Returns: %TRUE to stop other handlers from being invoked for the event.
1006 * %FALSE to propagate the event further.
1008 widget_signals[BUTTON_PRESS_EVENT] =
1009 g_signal_new (I_("button-press-event"),
1010 G_TYPE_FROM_CLASS (gobject_class),
1012 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1013 _gtk_boolean_handled_accumulator, NULL,
1014 _gtk_marshal_BOOLEAN__BOXED,
1016 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1019 * GtkWidget::button-release-event:
1020 * @widget: the object which received the signal.
1021 * @event: the #GdkEventButton which triggered this signal
1023 * The ::button-release-event signal will be emitted when a button
1024 * (typically from a mouse) is released.
1026 * To receive this signal, the #GdkWindow associated to the
1027 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1029 * This signal will be sent to the grab widget if there is one.
1031 * Returns: %TRUE to stop other handlers from being invoked for the event.
1032 * %FALSE to propagate the event further.
1034 widget_signals[BUTTON_RELEASE_EVENT] =
1035 g_signal_new (I_("button-release-event"),
1036 G_TYPE_FROM_CLASS (gobject_class),
1038 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1039 _gtk_boolean_handled_accumulator, NULL,
1040 _gtk_marshal_BOOLEAN__BOXED,
1042 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1045 * GtkWidget::scroll-event:
1046 * @widget: the object which received the signal.
1047 * @event: the #GdkEventScroll which triggered this signal
1049 * The ::scroll-event signal is emitted when a button in the 4 to 7
1050 * range is pressed. Wheel mice are usually configured to generate
1051 * button press events for buttons 4 and 5 when the wheel is turned.
1053 * To receive this signal, the #GdkWindow associated to the widget needs
1054 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1056 * This signal will be sent to the grab widget if there is one.
1058 * Returns: %TRUE to stop other handlers from being invoked for the event.
1059 * %FALSE to propagate the event further.
1061 widget_signals[SCROLL_EVENT] =
1062 g_signal_new (I_("scroll-event"),
1063 G_TYPE_FROM_CLASS (gobject_class),
1065 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1066 _gtk_boolean_handled_accumulator, NULL,
1067 _gtk_marshal_BOOLEAN__BOXED,
1069 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1071 * GtkWidget::motion-notify-event:
1072 * @widget: the object which received the signal.
1073 * @event: the #GdkEventMotion which triggered this signal
1075 * The ::motion-notify-event signal is emitted when the pointer moves
1076 * over the widget's #GdkWindow.
1078 * To receive this signal, the #GdkWindow associated to the widget
1079 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1081 * This signal will be sent to the grab widget if there is one.
1083 * Returns: %TRUE to stop other handlers from being invoked for the event.
1084 * %FALSE to propagate the event further.
1086 widget_signals[MOTION_NOTIFY_EVENT] =
1087 g_signal_new (I_("motion-notify-event"),
1088 G_TYPE_FROM_CLASS (gobject_class),
1090 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1091 _gtk_boolean_handled_accumulator, NULL,
1092 _gtk_marshal_BOOLEAN__BOXED,
1094 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1097 * GtkWidget::composited-changed:
1098 * @widget: the object on which the signal is emitted
1100 * The ::composited-changed signal is emitted when the composited
1101 * status of @widget<!-- -->s screen changes.
1102 * See gdk_screen_is_composited().
1104 widget_signals[COMPOSITED_CHANGED] =
1105 g_signal_new (I_("composited-changed"),
1106 G_TYPE_FROM_CLASS (gobject_class),
1107 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1108 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1110 _gtk_marshal_VOID__VOID,
1114 * GtkWidget::keynav-failed:
1115 * @widget: the object which received the signal
1116 * @direction: the direction of movement
1118 * Gets emitted if keyboard navigation fails.
1119 * See gtk_widget_keynav_failed() for details.
1121 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1122 * if the emitting widget should try to handle the keyboard
1123 * navigation attempt in its parent container(s).
1127 widget_signals[KEYNAV_FAILED] =
1128 g_signal_new_class_handler (I_("keynav-failed"),
1129 G_TYPE_FROM_CLASS (gobject_class),
1131 G_CALLBACK (gtk_widget_real_keynav_failed),
1132 _gtk_boolean_handled_accumulator, NULL,
1133 _gtk_marshal_BOOLEAN__ENUM,
1135 GTK_TYPE_DIRECTION_TYPE);
1138 * GtkWidget::delete-event:
1139 * @widget: the object which received the signal
1140 * @event: the event which triggered this signal
1142 * The ::delete-event signal is emitted if a user requests that
1143 * a toplevel window is closed. The default handler for this signal
1144 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1145 * this signal will cause the window to be hidden instead, so that
1146 * it can later be shown again without reconstructing it.
1148 * Returns: %TRUE to stop other handlers from being invoked for the event.
1149 * %FALSE to propagate the event further.
1151 widget_signals[DELETE_EVENT] =
1152 g_signal_new (I_("delete-event"),
1153 G_TYPE_FROM_CLASS (gobject_class),
1155 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1156 _gtk_boolean_handled_accumulator, NULL,
1157 _gtk_marshal_BOOLEAN__BOXED,
1159 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1162 * GtkWidget::destroy-event:
1163 * @widget: the object which received the signal.
1164 * @event: the event which triggered this signal
1166 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1167 * You rarely get this signal, because most widgets disconnect themselves
1168 * from their window before they destroy it, so no widget owns the
1169 * window at destroy time.
1171 * To receive this signal, the #GdkWindow associated to the widget needs
1172 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1173 * automatically for all new windows.
1175 * Returns: %TRUE to stop other handlers from being invoked for the event.
1176 * %FALSE to propagate the event further.
1178 widget_signals[DESTROY_EVENT] =
1179 g_signal_new (I_("destroy-event"),
1180 G_TYPE_FROM_CLASS (gobject_class),
1182 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1183 _gtk_boolean_handled_accumulator, NULL,
1184 _gtk_marshal_BOOLEAN__BOXED,
1186 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1189 * GtkWidget::expose-event:
1190 * @widget: the object which received the signal.
1191 * @event: the #GdkEventExpose which triggered this signal
1193 * The ::expose-event signal is emitted when an area of a previously
1194 * obscured #GdkWindow is made visible and needs to be redrawn.
1195 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1198 * To receive this signal, the #GdkWindow associated to the widget needs
1199 * to enable the #GDK_EXPOSURE_MASK mask.
1201 * Returns: %TRUE to stop other handlers from being invoked for the event.
1202 * %FALSE to propagate the event further.
1204 widget_signals[EXPOSE_EVENT] =
1205 g_signal_new (I_("expose-event"),
1206 G_TYPE_FROM_CLASS (gobject_class),
1208 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1209 _gtk_boolean_handled_accumulator, NULL,
1210 _gtk_marshal_BOOLEAN__BOXED,
1212 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1215 * GtkWidget::key-press-event:
1216 * @widget: the object which received the signal
1217 * @event: the #GdkEventKey which triggered this signal
1219 * The ::key-press-event signal is emitted when a key is pressed.
1221 * To receive this signal, the #GdkWindow associated to the widget needs
1222 * to enable the #GDK_KEY_PRESS_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[KEY_PRESS_EVENT] =
1230 g_signal_new (I_("key-press-event"),
1231 G_TYPE_FROM_CLASS (gobject_class),
1233 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1234 _gtk_boolean_handled_accumulator, NULL,
1235 _gtk_marshal_BOOLEAN__BOXED,
1237 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1240 * GtkWidget::key-release-event:
1241 * @widget: the object which received the signal
1242 * @event: the #GdkEventKey which triggered this signal
1244 * The ::key-release-event signal is emitted when a key is pressed.
1246 * To receive this signal, the #GdkWindow associated to the widget needs
1247 * to enable the #GDK_KEY_RELEASE_MASK mask.
1249 * This signal will be sent to the grab widget if there is one.
1251 * Returns: %TRUE to stop other handlers from being invoked for the event.
1252 * %FALSE to propagate the event further.
1254 widget_signals[KEY_RELEASE_EVENT] =
1255 g_signal_new (I_("key-release-event"),
1256 G_TYPE_FROM_CLASS (gobject_class),
1258 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1259 _gtk_boolean_handled_accumulator, NULL,
1260 _gtk_marshal_BOOLEAN__BOXED,
1262 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1265 * GtkWidget::enter-notify-event:
1266 * @widget: the object which received the signal
1267 * @event: the #GdkEventCrossing which triggered this signal
1269 * The ::enter-notify-event will be emitted when the pointer enters
1270 * the @widget's window.
1272 * To receive this signal, the #GdkWindow associated to the widget needs
1273 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1275 * This signal will be sent to the grab widget if there is one.
1277 * Returns: %TRUE to stop other handlers from being invoked for the event.
1278 * %FALSE to propagate the event further.
1280 widget_signals[ENTER_NOTIFY_EVENT] =
1281 g_signal_new (I_("enter-notify-event"),
1282 G_TYPE_FROM_CLASS (gobject_class),
1284 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1285 _gtk_boolean_handled_accumulator, NULL,
1286 _gtk_marshal_BOOLEAN__BOXED,
1288 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1291 * GtkWidget::leave-notify-event:
1292 * @widget: the object which received the signal
1293 * @event: the #GdkEventCrossing which triggered this signal
1295 * The ::leave-notify-event will be emitted when the pointer leaves
1296 * the @widget's window.
1298 * To receive this signal, the #GdkWindow associated to the widget needs
1299 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1301 * This signal will be sent to the grab widget if there is one.
1303 * Returns: %TRUE to stop other handlers from being invoked for the event.
1304 * %FALSE to propagate the event further.
1306 widget_signals[LEAVE_NOTIFY_EVENT] =
1307 g_signal_new (I_("leave-notify-event"),
1308 G_TYPE_FROM_CLASS (gobject_class),
1310 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1311 _gtk_boolean_handled_accumulator, NULL,
1312 _gtk_marshal_BOOLEAN__BOXED,
1314 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1317 * GtkWidget::configure-event
1318 * @widget: the object which received the signal
1319 * @event: the #GdkEventConfigure which triggered this signal
1321 * The ::configure-event signal will be emitted when the size, position or
1322 * stacking of the @widget's window has changed.
1324 * To receive this signal, the #GdkWindow associated to the widget needs
1325 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1326 * automatically for all new windows.
1328 * Returns: %TRUE to stop other handlers from being invoked for the event.
1329 * %FALSE to propagate the event further.
1331 widget_signals[CONFIGURE_EVENT] =
1332 g_signal_new (I_("configure-event"),
1333 G_TYPE_FROM_CLASS (gobject_class),
1335 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1336 _gtk_boolean_handled_accumulator, NULL,
1337 _gtk_marshal_BOOLEAN__BOXED,
1339 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1342 * GtkWidget::focus-in-event
1343 * @widget: the object which received the signal
1344 * @event: the #GdkEventFocus which triggered this signal
1346 * The ::focus-in-event signal will be emitted when the keyboard focus
1347 * enters the @widget's window.
1349 * To receive this signal, the #GdkWindow associated to the widget needs
1350 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1352 * Returns: %TRUE to stop other handlers from being invoked for the event.
1353 * %FALSE to propagate the event further.
1355 widget_signals[FOCUS_IN_EVENT] =
1356 g_signal_new (I_("focus-in-event"),
1357 G_TYPE_FROM_CLASS (gobject_class),
1359 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1360 _gtk_boolean_handled_accumulator, NULL,
1361 _gtk_marshal_BOOLEAN__BOXED,
1363 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1366 * GtkWidget::focus-out-event
1367 * @widget: the object which received the signal
1368 * @event: the #GdkEventFocus which triggered this signal
1370 * The ::focus-out-event signal will be emitted when the keyboard focus
1371 * leaves the @widget's window.
1373 * To receive this signal, the #GdkWindow associated to the widget needs
1374 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1376 * Returns: %TRUE to stop other handlers from being invoked for the event.
1377 * %FALSE to propagate the event further.
1379 widget_signals[FOCUS_OUT_EVENT] =
1380 g_signal_new (I_("focus-out-event"),
1381 G_TYPE_FROM_CLASS (gobject_class),
1383 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1384 _gtk_boolean_handled_accumulator, NULL,
1385 _gtk_marshal_BOOLEAN__BOXED,
1387 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1390 * GtkWidget::map-event
1391 * @widget: the object which received the signal
1392 * @event: the #GdkEventAny which triggered this signal
1394 * The ::map-event signal will be emitted when the @widget's window is
1395 * mapped. A window is mapped when it becomes visible on the screen.
1397 * To receive this signal, the #GdkWindow associated to the widget needs
1398 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1399 * automatically for all new windows.
1401 * Returns: %TRUE to stop other handlers from being invoked for the event.
1402 * %FALSE to propagate the event further.
1404 widget_signals[MAP_EVENT] =
1405 g_signal_new (I_("map-event"),
1406 G_TYPE_FROM_CLASS (gobject_class),
1408 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1409 _gtk_boolean_handled_accumulator, NULL,
1410 _gtk_marshal_BOOLEAN__BOXED,
1412 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1415 * GtkWidget::unmap-event
1416 * @widget: the object which received the signal
1417 * @event: the #GdkEventAny which triggered this signal
1419 * The ::unmap-event signal will be emitted when the @widget's window is
1420 * unmapped. A window is unmapped when it becomes invisible on the screen.
1422 * To receive this signal, the #GdkWindow associated to the widget needs
1423 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1424 * automatically for all new windows.
1426 * Returns: %TRUE to stop other handlers from being invoked for the event.
1427 * %FALSE to propagate the event further.
1429 widget_signals[UNMAP_EVENT] =
1430 g_signal_new (I_("unmap-event"),
1431 G_TYPE_FROM_CLASS (gobject_class),
1433 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1434 _gtk_boolean_handled_accumulator, NULL,
1435 _gtk_marshal_BOOLEAN__BOXED,
1437 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1440 * GtkWidget::property-notify-event
1441 * @widget: the object which received the signal
1442 * @event: the #GdkEventProperty which triggered this signal
1444 * The ::property-notify-event signal will be emitted when a property on
1445 * the @widget's window has been changed or deleted.
1447 * To receive this signal, the #GdkWindow associated to the widget needs
1448 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1450 * Returns: %TRUE to stop other handlers from being invoked for the event.
1451 * %FALSE to propagate the event further.
1453 widget_signals[PROPERTY_NOTIFY_EVENT] =
1454 g_signal_new (I_("property-notify-event"),
1455 G_TYPE_FROM_CLASS (gobject_class),
1457 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1458 _gtk_boolean_handled_accumulator, NULL,
1459 _gtk_marshal_BOOLEAN__BOXED,
1461 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1464 * GtkWidget::selection-clear-event
1465 * @widget: the object which received the signal
1466 * @event: the #GdkEventSelection which triggered this signal
1468 * The ::selection-clear-event signal will be emitted when the
1469 * the @widget's window has lost ownership of a selection.
1471 * Returns: %TRUE to stop other handlers from being invoked for the event.
1472 * %FALSE to propagate the event further.
1474 widget_signals[SELECTION_CLEAR_EVENT] =
1475 g_signal_new (I_("selection-clear-event"),
1476 G_TYPE_FROM_CLASS (gobject_class),
1478 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1479 _gtk_boolean_handled_accumulator, NULL,
1480 _gtk_marshal_BOOLEAN__BOXED,
1482 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1485 * GtkWidget::selection-request-event
1486 * @widget: the object which received the signal
1487 * @event: the #GdkEventSelection which triggered this signal
1489 * The ::selection-request-event signal will be emitted when
1490 * another client requests ownership of the selection owned by
1491 * the @widget's window.
1493 * Returns: %TRUE to stop other handlers from being invoked for the event.
1494 * %FALSE to propagate the event further.
1496 widget_signals[SELECTION_REQUEST_EVENT] =
1497 g_signal_new (I_("selection-request-event"),
1498 G_TYPE_FROM_CLASS (gobject_class),
1500 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1501 _gtk_boolean_handled_accumulator, NULL,
1502 _gtk_marshal_BOOLEAN__BOXED,
1504 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1506 widget_signals[SELECTION_NOTIFY_EVENT] =
1507 g_signal_new (I_("selection-notify-event"),
1508 G_TYPE_FROM_CLASS (gobject_class),
1510 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1511 _gtk_boolean_handled_accumulator, NULL,
1512 _gtk_marshal_BOOLEAN__BOXED,
1514 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1516 widget_signals[SELECTION_RECEIVED] =
1517 g_signal_new (I_("selection-received"),
1518 G_TYPE_FROM_CLASS (gobject_class),
1520 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1522 _gtk_marshal_VOID__BOXED_UINT,
1524 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1527 widget_signals[SELECTION_GET] =
1528 g_signal_new (I_("selection-get"),
1529 G_TYPE_FROM_CLASS (gobject_class),
1531 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1533 _gtk_marshal_VOID__BOXED_UINT_UINT,
1535 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1540 * GtkWidget::proximity-in-event
1541 * @widget: the object which received the signal
1542 * @event: the #GdkEventProximity which triggered this signal
1544 * To receive this signal the #GdkWindow associated to the widget needs
1545 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1547 * This signal will be sent to the grab widget if there is one.
1549 * Returns: %TRUE to stop other handlers from being invoked for the event.
1550 * %FALSE to propagate the event further.
1552 widget_signals[PROXIMITY_IN_EVENT] =
1553 g_signal_new (I_("proximity-in-event"),
1554 G_TYPE_FROM_CLASS (gobject_class),
1556 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1557 _gtk_boolean_handled_accumulator, NULL,
1558 _gtk_marshal_BOOLEAN__BOXED,
1560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1563 * GtkWidget::proximity-out-event
1564 * @widget: the object which received the signal
1565 * @event: the #GdkEventProximity which triggered this signal
1567 * To receive this signal the #GdkWindow associated to the widget needs
1568 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1570 * This signal will be sent to the grab widget if there is one.
1572 * Returns: %TRUE to stop other handlers from being invoked for the event.
1573 * %FALSE to propagate the event further.
1575 widget_signals[PROXIMITY_OUT_EVENT] =
1576 g_signal_new (I_("proximity-out-event"),
1577 G_TYPE_FROM_CLASS (gobject_class),
1579 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1580 _gtk_boolean_handled_accumulator, NULL,
1581 _gtk_marshal_BOOLEAN__BOXED,
1583 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1586 * GtkWidget::drag-leave:
1587 * @widget: the object which received the signal.
1588 * @drag_context: the drag context
1589 * @time: the timestamp of the motion event
1591 * The ::drag-leave signal is emitted on the drop site when the cursor
1592 * leaves the widget. A typical reason to connect to this signal is to
1593 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1594 * with gtk_drag_unhighlight()
1596 widget_signals[DRAG_LEAVE] =
1597 g_signal_new (I_("drag-leave"),
1598 G_TYPE_FROM_CLASS (gobject_class),
1600 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1602 _gtk_marshal_VOID__OBJECT_UINT,
1604 GDK_TYPE_DRAG_CONTEXT,
1608 * GtkWidget::drag-begin:
1609 * @widget: the object which received the signal
1610 * @drag_context: the drag context
1612 * The ::drag-begin signal is emitted on the drag source when a drag is
1613 * started. A typical reason to connect to this signal is to set up a
1614 * custom drag icon with gtk_drag_source_set_icon().
1616 * Note that some widgets set up a drag icon in the default handler of
1617 * this signal, so you may have to use g_signal_connect_after() to
1618 * override what the default handler did.
1620 widget_signals[DRAG_BEGIN] =
1621 g_signal_new (I_("drag-begin"),
1622 G_TYPE_FROM_CLASS (gobject_class),
1624 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1626 _gtk_marshal_VOID__OBJECT,
1628 GDK_TYPE_DRAG_CONTEXT);
1631 * GtkWidget::drag-end:
1632 * @widget: the object which received the signal
1633 * @drag_context: the drag context
1635 * The ::drag-end signal is emitted on the drag source when a drag is
1636 * finished. A typical reason to connect to this signal is to undo
1637 * things done in #GtkWidget::drag-begin.
1639 widget_signals[DRAG_END] =
1640 g_signal_new (I_("drag-end"),
1641 G_TYPE_FROM_CLASS (gobject_class),
1643 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1645 _gtk_marshal_VOID__OBJECT,
1647 GDK_TYPE_DRAG_CONTEXT);
1650 * GtkWidget::drag-data-delete:
1651 * @widget: the object which received the signal
1652 * @drag_context: the drag context
1654 * The ::drag-data-delete signal is emitted on the drag source when a drag
1655 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1656 * handler is responsible for deleting the data that has been dropped. What
1657 * "delete" means depends on the context of the drag operation.
1659 widget_signals[DRAG_DATA_DELETE] =
1660 g_signal_new (I_("drag-data-delete"),
1661 G_TYPE_FROM_CLASS (gobject_class),
1663 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1665 _gtk_marshal_VOID__OBJECT,
1667 GDK_TYPE_DRAG_CONTEXT);
1670 * GtkWidget::drag-failed:
1671 * @widget: the object which received the signal
1672 * @drag_context: the drag context
1673 * @result: the result of the drag operation
1675 * The ::drag-failed signal is emitted on the drag source when a drag has
1676 * failed. The signal handler may hook custom code to handle a failed DND
1677 * operation based on the type of error, it returns %TRUE is the failure has
1678 * been already handled (not showing the default "drag operation failed"
1679 * animation), otherwise it returns %FALSE.
1681 * Return value: %TRUE if the failed drag operation has been already handled.
1685 widget_signals[DRAG_FAILED] =
1686 g_signal_new (I_("drag-failed"),
1687 G_TYPE_FROM_CLASS (gobject_class),
1689 0, _gtk_boolean_handled_accumulator, NULL,
1690 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1692 GDK_TYPE_DRAG_CONTEXT,
1693 GTK_TYPE_DRAG_RESULT);
1696 * GtkWidget::drag-motion:
1697 * @widget: the object which received the signal
1698 * @drag_context: the drag context
1699 * @x: the x coordinate of the current cursor position
1700 * @y: the y coordinate of the current cursor position
1701 * @time: the timestamp of the motion event
1702 * @returns: whether the cursor position is in a drop zone
1704 * The drag-motion signal is emitted on the drop site when the user
1705 * moves the cursor over the widget during a drag. The signal handler
1706 * must determine whether the cursor position is in a drop zone or not.
1707 * If it is not in a drop zone, it returns %FALSE and no further processing
1708 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1709 * handler is responsible for providing the necessary information for
1710 * displaying feedback to the user, by calling gdk_drag_status().
1712 * If the decision whether the drop will be accepted or rejected can't be
1713 * made based solely on the cursor position and the type of the data, the
1714 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1715 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1716 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1717 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1718 * when using the drag-motion signal that way.
1720 * Also note that there is no drag-enter signal. The drag receiver has to
1721 * keep track of whether he has received any drag-motion signals since the
1722 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1723 * an "enter" signal. Upon an "enter", the handler will typically highlight
1724 * the drop site with gtk_drag_highlight().
1727 * drag_motion (GtkWidget *widget,
1728 * GdkDragContext *context,
1735 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1737 * if (!private_data->drag_highlight)
1739 * private_data->drag_highlight = 1;
1740 * gtk_drag_highlight (widget);
1743 * target = gtk_drag_dest_find_target (widget, context, NULL);
1744 * if (target == GDK_NONE)
1745 * gdk_drag_status (context, 0, time);
1748 * private_data->pending_status = context->suggested_action;
1749 * gtk_drag_get_data (widget, context, target, time);
1756 * drag_data_received (GtkWidget *widget,
1757 * GdkDragContext *context,
1760 * GtkSelectionData *selection_data,
1764 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1766 * if (private_data->suggested_action)
1768 * private_data->suggested_action = 0;
1770 * /* We are getting this data due to a request in drag_motion,
1771 * * rather than due to a request in drag_drop, so we are just
1772 * * supposed to call gdk_drag_status (), not actually paste in
1775 * str = gtk_selection_data_get_text (selection_data);
1776 * if (!data_is_acceptable (str))
1777 * gdk_drag_status (context, 0, time);
1779 * gdk_drag_status (context, private_data->suggested_action, time);
1783 * /* accept the drop */
1788 widget_signals[DRAG_MOTION] =
1789 g_signal_new (I_("drag-motion"),
1790 G_TYPE_FROM_CLASS (gobject_class),
1792 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1793 _gtk_boolean_handled_accumulator, NULL,
1794 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1796 GDK_TYPE_DRAG_CONTEXT,
1802 * GtkWidget::drag-drop:
1803 * @widget: the object which received the signal
1804 * @drag_context: the drag context
1805 * @x: the x coordinate of the current cursor position
1806 * @y: the y coordinate of the current cursor position
1807 * @time: the timestamp of the motion event
1808 * @returns: whether the cursor position is in a drop zone
1810 * The ::drag-drop signal is emitted on the drop site when the user drops
1811 * the data onto the widget. The signal handler must determine whether
1812 * the cursor position is in a drop zone or not. If it is not in a drop
1813 * zone, it returns %FALSE and no further processing is necessary.
1814 * Otherwise, the handler returns %TRUE. In this case, the handler must
1815 * ensure that gtk_drag_finish() is called to let the source know that
1816 * the drop is done. The call to gtk_drag_finish() can be done either
1817 * directly or in a #GtkWidget::drag-data-received handler which gets
1818 * triggered by calling gtk_drag_get_data() to receive the data for one
1819 * or more of the supported targets.
1821 widget_signals[DRAG_DROP] =
1822 g_signal_new (I_("drag-drop"),
1823 G_TYPE_FROM_CLASS (gobject_class),
1825 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1826 _gtk_boolean_handled_accumulator, NULL,
1827 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1829 GDK_TYPE_DRAG_CONTEXT,
1835 * GtkWidget::drag-data-get:
1836 * @widget: the object which received the signal
1837 * @drag_context: the drag context
1838 * @data: the #GtkSelectionData to be filled with the dragged data
1839 * @info: the info that has been registered with the target in the
1841 * @time: the timestamp at which the data was requested
1843 * The ::drag-data-get signal is emitted on the drag source when the drop
1844 * site requests the data which is dragged. It is the responsibility of
1845 * the signal handler to fill @data with the data in the format which
1846 * is indicated by @info. See gtk_selection_data_set() and
1847 * gtk_selection_data_set_text().
1849 widget_signals[DRAG_DATA_GET] =
1850 g_signal_new (I_("drag-data-get"),
1851 G_TYPE_FROM_CLASS (gobject_class),
1853 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1855 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1857 GDK_TYPE_DRAG_CONTEXT,
1858 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1863 * GtkWidget::drag-data-received:
1864 * @widget: the object which received the signal
1865 * @drag_context: the drag context
1866 * @x: where the drop happened
1867 * @y: where the drop happened
1868 * @data: the received data
1869 * @info: the info that has been registered with the target in the
1871 * @time: the timestamp at which the data was received
1873 * The ::drag-data-received signal is emitted on the drop site when the
1874 * dragged data has been received. If the data was received in order to
1875 * determine whether the drop will be accepted, the handler is expected
1876 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1877 * If the data was received in response to a #GtkWidget::drag-drop signal
1878 * (and this is the last target to be received), the handler for this
1879 * signal is expected to process the received data and then call
1880 * gtk_drag_finish(), setting the @success parameter depending on whether
1881 * the data was processed successfully.
1883 * The handler may inspect and modify @drag_context->action before calling
1884 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1885 * following example:
1888 * drag_data_received (GtkWidget *widget,
1889 * GdkDragContext *drag_context,
1892 * GtkSelectionData *data,
1896 * if ((data->length >= 0) && (data->format == 8))
1898 * if (drag_context->action == GDK_ACTION_ASK)
1900 * GtkWidget *dialog;
1903 * dialog = gtk_message_dialog_new (NULL,
1904 * GTK_DIALOG_MODAL |
1905 * GTK_DIALOG_DESTROY_WITH_PARENT,
1907 * GTK_BUTTONS_YES_NO,
1908 * "Move the data ?\n");
1909 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1910 * gtk_widget_destroy (dialog);
1912 * if (response == GTK_RESPONSE_YES)
1913 * drag_context->action = GDK_ACTION_MOVE;
1915 * drag_context->action = GDK_ACTION_COPY;
1918 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1922 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1926 widget_signals[DRAG_DATA_RECEIVED] =
1927 g_signal_new (I_("drag-data-received"),
1928 G_TYPE_FROM_CLASS (gobject_class),
1930 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1932 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1934 GDK_TYPE_DRAG_CONTEXT,
1937 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1942 * GtkWidget::visibility-notify-event:
1943 * @widget: the object which received the signal
1944 * @event: the #GdkEventVisibility which triggered this signal
1946 * The ::visibility-notify-event will be emitted when the @widget's window
1947 * is obscured or unobscured.
1949 * To receive this signal the #GdkWindow associated to the widget needs
1950 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1952 * Returns: %TRUE to stop other handlers from being invoked for the event.
1953 * %FALSE to propagate the event further.
1955 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1956 g_signal_new (I_("visibility-notify-event"),
1957 G_TYPE_FROM_CLASS (gobject_class),
1959 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1960 _gtk_boolean_handled_accumulator, NULL,
1961 _gtk_marshal_BOOLEAN__BOXED,
1963 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1966 * GtkWidget::client-event:
1967 * @widget: the object which received the signal
1968 * @event: the #GdkEventClient which triggered this signal
1970 * The ::client-event will be emitted when the @widget's window
1971 * receives a message (via a ClientMessage event) from another
1974 * Returns: %TRUE to stop other handlers from being invoked for
1975 * the event. %FALSE to propagate the event further.
1977 widget_signals[CLIENT_EVENT] =
1978 g_signal_new (I_("client-event"),
1979 G_TYPE_FROM_CLASS (gobject_class),
1981 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1982 _gtk_boolean_handled_accumulator, NULL,
1983 _gtk_marshal_BOOLEAN__BOXED,
1985 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1988 * GtkWidget::no-expose-event:
1989 * @widget: the object which received the signal
1990 * @event: the #GdkEventNoExpose which triggered this signal
1992 * The ::no-expose-event will be emitted when the @widget's window is
1993 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1994 * gdk_window_copy_area()) which was completely unobscured. If the source
1995 * window was partially obscured #GdkEventExpose events will be generated
1998 * Returns: %TRUE to stop other handlers from being invoked for the event.
1999 * %FALSE to propagate the event further.
2001 widget_signals[NO_EXPOSE_EVENT] =
2002 g_signal_new (I_("no-expose-event"),
2003 G_TYPE_FROM_CLASS (gobject_class),
2005 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2006 _gtk_boolean_handled_accumulator, NULL,
2007 _gtk_marshal_BOOLEAN__BOXED,
2009 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2012 * GtkWidget::window-state-event:
2013 * @widget: the object which received the signal
2014 * @event: the #GdkEventWindowState which triggered this signal
2016 * The ::window-state-event will be emitted when the state of the
2017 * toplevel window associated to the @widget changes.
2019 * To receive this signal the #GdkWindow associated to the widget
2020 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2021 * this mask automatically for all new windows.
2023 * Returns: %TRUE to stop other handlers from being invoked for the
2024 * event. %FALSE to propagate the event further.
2026 widget_signals[WINDOW_STATE_EVENT] =
2027 g_signal_new (I_("window-state-event"),
2028 G_TYPE_FROM_CLASS (gobject_class),
2030 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2031 _gtk_boolean_handled_accumulator, NULL,
2032 _gtk_marshal_BOOLEAN__BOXED,
2034 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2037 * GtkWidget::damage-event:
2038 * @widget: the object which received the signal
2039 * @event: the #GdkEventExpose event
2041 * Emitted when a redirected window belonging to @widget gets drawn into.
2042 * The region/area members of the event shows what area of the redirected
2043 * drawable was drawn into.
2045 * Returns: %TRUE to stop other handlers from being invoked for the event.
2046 * %FALSE to propagate the event further.
2050 widget_signals[DAMAGE_EVENT] =
2051 g_signal_new (I_("damage-event"),
2052 G_TYPE_FROM_CLASS (gobject_class),
2055 _gtk_boolean_handled_accumulator, NULL,
2056 _gtk_marshal_BOOLEAN__BOXED,
2058 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2060 * GtkWidget::grab-broken-event:
2061 * @widget: the object which received the signal
2062 * @event: the #GdkEventGrabBroken event
2064 * Emitted when a pointer or keyboard grab on a window belonging
2065 * to @widget gets broken.
2067 * On X11, this happens when the grab window becomes unviewable
2068 * (i.e. it or one of its ancestors is unmapped), or if the same
2069 * application grabs the pointer or keyboard again.
2071 * Returns: %TRUE to stop other handlers from being invoked for
2072 * the event. %FALSE to propagate the event further.
2076 widget_signals[GRAB_BROKEN] =
2077 g_signal_new (I_("grab-broken-event"),
2078 G_TYPE_FROM_CLASS (gobject_class),
2080 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2081 _gtk_boolean_handled_accumulator, NULL,
2082 _gtk_marshal_BOOLEAN__BOXED,
2084 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2086 * GtkWidget::query-tooltip:
2087 * @widget: the object which received the signal
2088 * @x: the x coordinate of the cursor position where the request has
2089 * been emitted, relative to @widget->window
2090 * @y: the y coordinate of the cursor position where the request has
2091 * been emitted, relative to @widget->window
2092 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2093 * @tooltip: a #GtkTooltip
2095 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2096 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2097 * focus in keyboard mode.
2099 * Using the given coordinates, the signal handler should determine
2100 * whether a tooltip should be shown for @widget. If this is the case
2101 * %TRUE should be returned, %FALSE otherwise. Note that if
2102 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2103 * should not be used.
2105 * The signal handler is free to manipulate @tooltip with the therefore
2106 * destined function calls.
2108 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2112 widget_signals[QUERY_TOOLTIP] =
2113 g_signal_new (I_("query-tooltip"),
2114 G_TYPE_FROM_CLASS (gobject_class),
2116 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2117 _gtk_boolean_handled_accumulator, NULL,
2118 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2126 * GtkWidget::popup-menu
2127 * @widget: the object which received the signal
2129 * This signal gets emitted whenever a widget should pop up a context
2130 * menu. This usually happens through the standard key binding mechanism;
2131 * by pressing a certain key while a widget is focused, the user can cause
2132 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2133 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2134 * for an example of how to use this signal.
2136 * Returns: %TRUE if a menu was activated
2138 widget_signals[POPUP_MENU] =
2139 g_signal_new (I_("popup-menu"),
2140 G_TYPE_FROM_CLASS (gobject_class),
2141 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2142 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2143 _gtk_boolean_handled_accumulator, NULL,
2144 _gtk_marshal_BOOLEAN__VOID,
2146 widget_signals[SHOW_HELP] =
2147 g_signal_new (I_("show-help"),
2148 G_TYPE_FROM_CLASS (gobject_class),
2149 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2150 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2151 _gtk_boolean_handled_accumulator, NULL,
2152 _gtk_marshal_BOOLEAN__ENUM,
2154 GTK_TYPE_WIDGET_HELP_TYPE);
2155 widget_signals[ACCEL_CLOSURES_CHANGED] =
2156 g_signal_new (I_("accel-closures-changed"),
2157 G_TYPE_FROM_CLASS (gobject_class),
2161 _gtk_marshal_VOID__VOID,
2165 * GtkWidget::screen-changed:
2166 * @widget: the object on which the signal is emitted
2167 * @previous_screen: the previous screen, or %NULL if the
2168 * widget was not associated with a screen before
2170 * The ::screen-changed signal gets emitted when the
2171 * screen of a widget has changed.
2173 widget_signals[SCREEN_CHANGED] =
2174 g_signal_new (I_("screen-changed"),
2175 G_TYPE_FROM_CLASS (gobject_class),
2177 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2179 _gtk_marshal_VOID__OBJECT,
2183 * GtkWidget::can-activate-accel:
2184 * @widget: the object which received the signal
2185 * @signal_id: the ID of a signal installed on @widget
2187 * Determines whether an accelerator that activates the signal
2188 * identified by @signal_id can currently be activated.
2189 * This signal is present to allow applications and derived
2190 * widgets to override the default #GtkWidget handling
2191 * for determining whether an accelerator can be activated.
2193 * Returns: %TRUE if the signal can be activated.
2195 widget_signals[CAN_ACTIVATE_ACCEL] =
2196 g_signal_new (I_("can-activate-accel"),
2197 G_TYPE_FROM_CLASS (gobject_class),
2199 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2200 _gtk_boolean_handled_accumulator, NULL,
2201 _gtk_marshal_BOOLEAN__UINT,
2202 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2204 binding_set = gtk_binding_set_by_class (klass);
2205 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2207 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2210 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2212 GTK_TYPE_WIDGET_HELP_TYPE,
2213 GTK_WIDGET_HELP_TOOLTIP);
2214 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2216 GTK_TYPE_WIDGET_HELP_TYPE,
2217 GTK_WIDGET_HELP_TOOLTIP);
2218 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2220 GTK_TYPE_WIDGET_HELP_TYPE,
2221 GTK_WIDGET_HELP_WHATS_THIS);
2222 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2224 GTK_TYPE_WIDGET_HELP_TYPE,
2225 GTK_WIDGET_HELP_WHATS_THIS);
2227 gtk_widget_class_install_style_property (klass,
2228 g_param_spec_boolean ("interior-focus",
2229 P_("Interior Focus"),
2230 P_("Whether to draw the focus indicator inside widgets"),
2232 GTK_PARAM_READABLE));
2234 gtk_widget_class_install_style_property (klass,
2235 g_param_spec_int ("focus-line-width",
2236 P_("Focus linewidth"),
2237 P_("Width, in pixels, of the focus indicator line"),
2239 GTK_PARAM_READABLE));
2241 gtk_widget_class_install_style_property (klass,
2242 g_param_spec_string ("focus-line-pattern",
2243 P_("Focus line dash pattern"),
2244 P_("Dash pattern used to draw the focus indicator"),
2246 GTK_PARAM_READABLE));
2247 gtk_widget_class_install_style_property (klass,
2248 g_param_spec_int ("focus-padding",
2249 P_("Focus padding"),
2250 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2252 GTK_PARAM_READABLE));
2253 gtk_widget_class_install_style_property (klass,
2254 g_param_spec_boxed ("cursor-color",
2256 P_("Color with which to draw insertion cursor"),
2258 GTK_PARAM_READABLE));
2259 gtk_widget_class_install_style_property (klass,
2260 g_param_spec_boxed ("secondary-cursor-color",
2261 P_("Secondary cursor color"),
2262 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2264 GTK_PARAM_READABLE));
2265 gtk_widget_class_install_style_property (klass,
2266 g_param_spec_float ("cursor-aspect-ratio",
2267 P_("Cursor line aspect ratio"),
2268 P_("Aspect ratio with which to draw insertion cursor"),
2270 GTK_PARAM_READABLE));
2273 * GtkWidget:draw-border:
2275 * The "draw-border" style property defines the size of areas outside
2276 * the widget's allocation to draw.
2280 gtk_widget_class_install_style_property (klass,
2281 g_param_spec_boxed ("draw-border",
2283 P_("Size of areas outside the widget's allocation to draw"),
2285 GTK_PARAM_READABLE));
2288 * GtkWidget:link-color:
2290 * The "link-color" style property defines the color of unvisited links.
2294 gtk_widget_class_install_style_property (klass,
2295 g_param_spec_boxed ("link-color",
2296 P_("Unvisited Link Color"),
2297 P_("Color of unvisited links"),
2299 GTK_PARAM_READABLE));
2302 * GtkWidget:visited-link-color:
2304 * The "visited-link-color" style property defines the color of visited links.
2308 gtk_widget_class_install_style_property (klass,
2309 g_param_spec_boxed ("visited-link-color",
2310 P_("Visited Link Color"),
2311 P_("Color of visited links"),
2313 GTK_PARAM_READABLE));
2316 * GtkWidget:wide-separators:
2318 * The "wide-separators" style property defines whether separators have
2319 * configurable width and should be drawn using a box instead of a line.
2323 gtk_widget_class_install_style_property (klass,
2324 g_param_spec_boolean ("wide-separators",
2325 P_("Wide Separators"),
2326 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2328 GTK_PARAM_READABLE));
2331 * GtkWidget:separator-width:
2333 * The "separator-width" style property defines the width of separators.
2334 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2338 gtk_widget_class_install_style_property (klass,
2339 g_param_spec_int ("separator-width",
2340 P_("Separator Width"),
2341 P_("The width of separators if wide-separators is TRUE"),
2343 GTK_PARAM_READABLE));
2346 * GtkWidget:separator-height:
2348 * The "separator-height" style property defines the height of separators.
2349 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2353 gtk_widget_class_install_style_property (klass,
2354 g_param_spec_int ("separator-height",
2355 P_("Separator Height"),
2356 P_("The height of separators if \"wide-separators\" is TRUE"),
2358 GTK_PARAM_READABLE));
2361 * GtkWidget:scroll-arrow-hlength:
2363 * The "scroll-arrow-hlength" style property defines the length of
2364 * horizontal scroll arrows.
2368 gtk_widget_class_install_style_property (klass,
2369 g_param_spec_int ("scroll-arrow-hlength",
2370 P_("Horizontal Scroll Arrow Length"),
2371 P_("The length of horizontal scroll arrows"),
2373 GTK_PARAM_READABLE));
2376 * GtkWidget:scroll-arrow-vlength:
2378 * The "scroll-arrow-vlength" style property defines the length of
2379 * vertical scroll arrows.
2383 gtk_widget_class_install_style_property (klass,
2384 g_param_spec_int ("scroll-arrow-vlength",
2385 P_("Vertical Scroll Arrow Length"),
2386 P_("The length of vertical scroll arrows"),
2388 GTK_PARAM_READABLE));
2392 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2396 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2397 for (node = list; node; node = node->next)
2399 GParamSpec *pspec = node->data;
2401 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2402 g_param_spec_unref (pspec);
2408 gtk_widget_set_property (GObject *object,
2410 const GValue *value,
2413 GtkWidget *widget = GTK_WIDGET (object);
2418 gchar *tooltip_markup;
2419 const gchar *tooltip_text;
2420 GtkWindow *tooltip_window;
2423 gtk_widget_set_name (widget, g_value_get_string (value));
2426 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2428 case PROP_WIDTH_REQUEST:
2429 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2431 case PROP_HEIGHT_REQUEST:
2432 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2435 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2437 case PROP_SENSITIVE:
2438 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2440 case PROP_APP_PAINTABLE:
2441 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2443 case PROP_CAN_FOCUS:
2444 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2446 case PROP_HAS_FOCUS:
2447 if (g_value_get_boolean (value))
2448 gtk_widget_grab_focus (widget);
2451 if (g_value_get_boolean (value))
2452 gtk_widget_grab_focus (widget);
2454 case PROP_CAN_DEFAULT:
2455 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2457 case PROP_HAS_DEFAULT:
2458 if (g_value_get_boolean (value))
2459 gtk_widget_grab_default (widget);
2461 case PROP_RECEIVES_DEFAULT:
2462 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2465 gtk_widget_set_style (widget, g_value_get_object (value));
2468 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2469 gtk_widget_set_events (widget, g_value_get_flags (value));
2471 case PROP_EXTENSION_EVENTS:
2472 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2474 case PROP_NO_SHOW_ALL:
2475 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2477 case PROP_HAS_TOOLTIP:
2478 gtk_widget_real_set_has_tooltip (widget,
2479 g_value_get_boolean (value), FALSE);
2481 case PROP_TOOLTIP_MARKUP:
2482 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2483 tooltip_markup = g_value_dup_string (value);
2485 /* Treat an empty string as a NULL string,
2486 * because an empty string would be useless for a tooltip:
2488 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2490 g_free (tooltip_markup);
2491 tooltip_markup = NULL;
2494 g_object_set_qdata_full (object, quark_tooltip_markup,
2495 tooltip_markup, g_free);
2497 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2498 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2499 if (GTK_WIDGET_VISIBLE (widget))
2500 gtk_widget_queue_tooltip_query (widget);
2502 case PROP_TOOLTIP_TEXT:
2503 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2505 tooltip_text = g_value_get_string (value);
2507 /* Treat an empty string as a NULL string,
2508 * because an empty string would be useless for a tooltip:
2510 if (tooltip_text && (strlen (tooltip_text) == 0))
2511 tooltip_text = NULL;
2513 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2515 g_object_set_qdata_full (object, quark_tooltip_markup,
2516 tooltip_markup, g_free);
2518 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2519 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2520 if (GTK_WIDGET_VISIBLE (widget))
2521 gtk_widget_queue_tooltip_query (widget);
2523 case PROP_DOUBLE_BUFFERED:
2524 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2533 gtk_widget_get_property (GObject *object,
2538 GtkWidget *widget = GTK_WIDGET (object);
2547 g_value_set_string (value, widget->name);
2549 g_value_set_static_string (value, "");
2552 g_value_set_object (value, widget->parent);
2554 case PROP_WIDTH_REQUEST:
2557 gtk_widget_get_size_request (widget, &w, NULL);
2558 g_value_set_int (value, w);
2561 case PROP_HEIGHT_REQUEST:
2564 gtk_widget_get_size_request (widget, NULL, &h);
2565 g_value_set_int (value, h);
2569 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2571 case PROP_SENSITIVE:
2572 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2574 case PROP_APP_PAINTABLE:
2575 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2577 case PROP_CAN_FOCUS:
2578 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2580 case PROP_HAS_FOCUS:
2581 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2584 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2586 case PROP_CAN_DEFAULT:
2587 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2589 case PROP_HAS_DEFAULT:
2590 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2592 case PROP_RECEIVES_DEFAULT:
2593 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2595 case PROP_COMPOSITE_CHILD:
2596 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2599 g_value_set_object (value, gtk_widget_get_style (widget));
2602 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2603 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2605 case PROP_EXTENSION_EVENTS:
2606 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2607 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2609 case PROP_NO_SHOW_ALL:
2610 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2612 case PROP_HAS_TOOLTIP:
2613 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2615 case PROP_TOOLTIP_TEXT:
2617 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2620 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2621 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2623 g_value_set_string (value, text);
2627 case PROP_TOOLTIP_MARKUP:
2628 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2631 g_value_set_object (value, gtk_widget_get_window (widget));
2633 case PROP_DOUBLE_BUFFERED:
2634 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
2637 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2643 gtk_widget_init (GtkWidget *widget)
2645 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2646 widget->state = GTK_STATE_NORMAL;
2647 widget->saved_state = GTK_STATE_NORMAL;
2648 widget->name = NULL;
2649 widget->requisition.width = 0;
2650 widget->requisition.height = 0;
2651 widget->allocation.x = -1;
2652 widget->allocation.y = -1;
2653 widget->allocation.width = 1;
2654 widget->allocation.height = 1;
2655 widget->window = NULL;
2656 widget->parent = NULL;
2658 GTK_WIDGET_SET_FLAGS (widget,
2660 GTK_PARENT_SENSITIVE |
2661 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2662 GTK_DOUBLE_BUFFERED);
2664 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2665 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2666 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2668 widget->style = gtk_widget_get_default_style ();
2669 g_object_ref (widget->style);
2674 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2676 GParamSpec **pspecs)
2678 GtkWidget *container = widget->parent;
2681 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2682 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2686 * gtk_widget_freeze_child_notify:
2687 * @widget: a #GtkWidget
2689 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2690 * signals are queued until gtk_widget_thaw_child_notify() is called
2693 * This is the analogue of g_object_freeze_notify() for child properties.
2696 gtk_widget_freeze_child_notify (GtkWidget *widget)
2698 g_return_if_fail (GTK_IS_WIDGET (widget));
2700 if (!G_OBJECT (widget)->ref_count)
2703 g_object_ref (widget);
2704 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2705 g_object_unref (widget);
2709 * gtk_widget_child_notify:
2710 * @widget: a #GtkWidget
2711 * @child_property: the name of a child property installed on the
2712 * class of @widget<!-- -->'s parent
2714 * Emits a #GtkWidget::child-notify signal for the
2715 * <link linkend="child-properties">child property</link> @child_property
2718 * This is the analogue of g_object_notify() for child properties.
2721 gtk_widget_child_notify (GtkWidget *widget,
2722 const gchar *child_property)
2726 g_return_if_fail (GTK_IS_WIDGET (widget));
2727 g_return_if_fail (child_property != NULL);
2728 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2731 g_object_ref (widget);
2732 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2734 G_OBJECT_TYPE (widget->parent),
2737 g_warning ("%s: container class `%s' has no child property named `%s'",
2739 G_OBJECT_TYPE_NAME (widget->parent),
2743 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2745 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2746 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2748 g_object_unref (widget);
2752 * gtk_widget_thaw_child_notify:
2753 * @widget: a #GtkWidget
2755 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2756 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2760 gtk_widget_thaw_child_notify (GtkWidget *widget)
2762 GObjectNotifyQueue *nqueue;
2764 g_return_if_fail (GTK_IS_WIDGET (widget));
2766 if (!G_OBJECT (widget)->ref_count)
2769 g_object_ref (widget);
2770 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2771 if (!nqueue || !nqueue->freeze_count)
2772 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2773 G_OBJECT_TYPE_NAME (widget), widget);
2775 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2776 g_object_unref (widget);
2782 * @type: type ID of the widget to create
2783 * @first_property_name: name of first property to set
2784 * @Varargs: value of first property, followed by more properties,
2787 * This is a convenience function for creating a widget and setting
2788 * its properties in one go. For example you might write:
2789 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2790 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2791 * g_object_new(), but returns a widget so you don't have to
2792 * cast the object yourself.
2794 * Return value: a new #GtkWidget of type @widget_type
2797 gtk_widget_new (GType type,
2798 const gchar *first_property_name,
2804 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2806 va_start (var_args, first_property_name);
2807 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2815 * @widget: a #GtkWidget
2816 * @first_property_name: name of first property to set
2817 * @Varargs: value of first property, followed by more properties,
2820 * Precursor of g_object_set().
2822 * Deprecated: 2.0: Use g_object_set() instead.
2825 gtk_widget_set (GtkWidget *widget,
2826 const gchar *first_property_name,
2831 g_return_if_fail (GTK_IS_WIDGET (widget));
2833 va_start (var_args, first_property_name);
2834 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2839 gtk_widget_queue_draw_child (GtkWidget *widget)
2843 parent = widget->parent;
2844 if (parent && GTK_WIDGET_DRAWABLE (parent))
2845 gtk_widget_queue_draw_area (parent,
2846 widget->allocation.x,
2847 widget->allocation.y,
2848 widget->allocation.width,
2849 widget->allocation.height);
2853 * gtk_widget_unparent:
2854 * @widget: a #GtkWidget
2856 * This function is only for use in widget implementations.
2857 * Should be called by implementations of the remove method
2858 * on #GtkContainer, to dissociate a child from the container.
2861 gtk_widget_unparent (GtkWidget *widget)
2863 GObjectNotifyQueue *nqueue;
2864 GtkWidget *toplevel;
2865 GtkWidget *old_parent;
2867 g_return_if_fail (GTK_IS_WIDGET (widget));
2868 if (widget->parent == NULL)
2871 /* keep this function in sync with gtk_menu_detach()
2874 g_object_freeze_notify (G_OBJECT (widget));
2875 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2877 toplevel = gtk_widget_get_toplevel (widget);
2878 if (GTK_WIDGET_TOPLEVEL (toplevel))
2879 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2881 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2882 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2884 /* If we are unanchoring the child, we save around the toplevel
2885 * to emit hierarchy changed
2887 if (GTK_WIDGET_ANCHORED (widget->parent))
2888 g_object_ref (toplevel);
2892 gtk_widget_queue_draw_child (widget);
2894 /* Reset the width and height here, to force reallocation if we
2895 * get added back to a new parent. This won't work if our new
2896 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2897 * (would 0x0 be OK here?)
2899 widget->allocation.width = 1;
2900 widget->allocation.height = 1;
2902 if (GTK_WIDGET_REALIZED (widget))
2904 if (GTK_WIDGET_IN_REPARENT (widget))
2905 gtk_widget_unmap (widget);
2907 gtk_widget_unrealize (widget);
2910 /* Removing a widget from a container restores the child visible
2911 * flag to the default state, so it doesn't affect the child
2912 * in the next parent.
2914 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2916 old_parent = widget->parent;
2917 widget->parent = NULL;
2918 gtk_widget_set_parent_window (widget, NULL);
2919 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2922 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2923 g_object_unref (toplevel);
2926 g_object_notify (G_OBJECT (widget), "parent");
2927 g_object_thaw_notify (G_OBJECT (widget));
2928 if (!widget->parent)
2929 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2930 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2931 g_object_unref (widget);
2935 * gtk_widget_destroy:
2936 * @widget: a #GtkWidget
2938 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2939 * you don't have to cast the widget to #GtkObject. When a widget is
2940 * destroyed, it will break any references it holds to other objects.
2941 * If the widget is inside a container, the widget will be removed
2942 * from the container. If the widget is a toplevel (derived from
2943 * #GtkWindow), it will be removed from the list of toplevels, and the
2944 * reference GTK+ holds to it will be removed. Removing a
2945 * widget from its container or the list of toplevels results in the
2946 * widget being finalized, unless you've added additional references
2947 * to the widget with g_object_ref().
2949 * In most cases, only toplevel widgets (windows) require explicit
2950 * destruction, because when you destroy a toplevel its children will
2951 * be destroyed as well.
2954 gtk_widget_destroy (GtkWidget *widget)
2956 g_return_if_fail (GTK_IS_WIDGET (widget));
2958 gtk_object_destroy ((GtkObject*) widget);
2962 * gtk_widget_destroyed:
2963 * @widget: a #GtkWidget
2964 * @widget_pointer: address of a variable that contains @widget
2966 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2967 * %NULL. It's intended to be used as a callback connected to the
2968 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2969 * as a signal handler, and pass the address of your widget variable
2970 * as user data. Then when the widget is destroyed, the variable will
2971 * be set to %NULL. Useful for example to avoid multiple copies
2972 * of the same dialog.
2975 gtk_widget_destroyed (GtkWidget *widget,
2976 GtkWidget **widget_pointer)
2978 /* Don't make any assumptions about the
2980 * Even check widget_pointer.
2983 *widget_pointer = NULL;
2988 * @widget: a #GtkWidget
2990 * Flags a widget to be displayed. Any widget that isn't shown will
2991 * not appear on the screen. If you want to show all the widgets in a
2992 * container, it's easier to call gtk_widget_show_all() on the
2993 * container, instead of individually showing the widgets.
2995 * Remember that you have to show the containers containing a widget,
2996 * in addition to the widget itself, before it will appear onscreen.
2998 * When a toplevel container is shown, it is immediately realized and
2999 * mapped; other shown widgets are realized and mapped when their
3000 * toplevel container is realized and mapped.
3003 gtk_widget_show (GtkWidget *widget)
3005 g_return_if_fail (GTK_IS_WIDGET (widget));
3007 if (!GTK_WIDGET_VISIBLE (widget))
3009 g_object_ref (widget);
3010 if (!GTK_WIDGET_TOPLEVEL (widget))
3011 gtk_widget_queue_resize (widget);
3012 g_signal_emit (widget, widget_signals[SHOW], 0);
3013 g_object_notify (G_OBJECT (widget), "visible");
3014 g_object_unref (widget);
3019 gtk_widget_real_show (GtkWidget *widget)
3021 if (!GTK_WIDGET_VISIBLE (widget))
3023 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3025 if (widget->parent &&
3026 GTK_WIDGET_MAPPED (widget->parent) &&
3027 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3028 !GTK_WIDGET_MAPPED (widget))
3029 gtk_widget_map (widget);
3034 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3037 g_signal_handlers_disconnect_by_func (widget,
3038 gtk_widget_show_map_callback,
3043 * gtk_widget_show_now:
3044 * @widget: a #GtkWidget
3046 * Shows a widget. If the widget is an unmapped toplevel widget
3047 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3048 * loop and wait for the window to actually be mapped. Be careful;
3049 * because the main loop is running, anything can happen during
3053 gtk_widget_show_now (GtkWidget *widget)
3057 g_return_if_fail (GTK_IS_WIDGET (widget));
3059 /* make sure we will get event */
3060 if (!GTK_WIDGET_MAPPED (widget) &&
3061 GTK_WIDGET_TOPLEVEL (widget))
3063 gtk_widget_show (widget);
3065 g_signal_connect (widget, "map-event",
3066 G_CALLBACK (gtk_widget_show_map_callback),
3070 gtk_main_iteration ();
3073 gtk_widget_show (widget);
3078 * @widget: a #GtkWidget
3080 * Reverses the effects of gtk_widget_show(), causing the widget to be
3081 * hidden (invisible to the user).
3084 gtk_widget_hide (GtkWidget *widget)
3086 g_return_if_fail (GTK_IS_WIDGET (widget));
3088 if (GTK_WIDGET_VISIBLE (widget))
3090 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3092 g_object_ref (widget);
3093 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3094 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3096 g_signal_emit (widget, widget_signals[HIDE], 0);
3097 if (!GTK_WIDGET_TOPLEVEL (widget))
3098 gtk_widget_queue_resize (widget);
3099 g_object_notify (G_OBJECT (widget), "visible");
3100 g_object_unref (widget);
3105 gtk_widget_real_hide (GtkWidget *widget)
3107 if (GTK_WIDGET_VISIBLE (widget))
3109 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3111 if (GTK_WIDGET_MAPPED (widget))
3112 gtk_widget_unmap (widget);
3117 * gtk_widget_hide_on_delete:
3118 * @widget: a #GtkWidget
3120 * Utility function; intended to be connected to the #GtkWidget::delete-event
3121 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3122 * argument, then returns %TRUE. If connected to ::delete-event, the
3123 * result is that clicking the close button for a window (on the
3124 * window frame, top right corner usually) will hide but not destroy
3125 * the window. By default, GTK+ destroys windows when ::delete-event
3128 * Return value: %TRUE
3131 gtk_widget_hide_on_delete (GtkWidget *widget)
3133 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3135 gtk_widget_hide (widget);
3141 * gtk_widget_show_all:
3142 * @widget: a #GtkWidget
3144 * Recursively shows a widget, and any child widgets (if the widget is
3148 gtk_widget_show_all (GtkWidget *widget)
3150 GtkWidgetClass *class;
3152 g_return_if_fail (GTK_IS_WIDGET (widget));
3154 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3157 class = GTK_WIDGET_GET_CLASS (widget);
3159 if (class->show_all)
3160 class->show_all (widget);
3164 * gtk_widget_hide_all:
3165 * @widget: a #GtkWidget
3167 * Recursively hides a widget and any child widgets.
3170 gtk_widget_hide_all (GtkWidget *widget)
3172 GtkWidgetClass *class;
3174 g_return_if_fail (GTK_IS_WIDGET (widget));
3176 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3179 class = GTK_WIDGET_GET_CLASS (widget);
3181 if (class->hide_all)
3182 class->hide_all (widget);
3187 * @widget: a #GtkWidget
3189 * This function is only for use in widget implementations. Causes
3190 * a widget to be mapped if it isn't already.
3193 gtk_widget_map (GtkWidget *widget)
3195 g_return_if_fail (GTK_IS_WIDGET (widget));
3196 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3197 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3199 if (!GTK_WIDGET_MAPPED (widget))
3201 if (!GTK_WIDGET_REALIZED (widget))
3202 gtk_widget_realize (widget);
3204 g_signal_emit (widget, widget_signals[MAP], 0);
3206 if (GTK_WIDGET_NO_WINDOW (widget))
3207 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3213 * @widget: a #GtkWidget
3215 * This function is only for use in widget implementations. Causes
3216 * a widget to be unmapped if it's currently mapped.
3219 gtk_widget_unmap (GtkWidget *widget)
3221 g_return_if_fail (GTK_IS_WIDGET (widget));
3223 if (GTK_WIDGET_MAPPED (widget))
3225 if (GTK_WIDGET_NO_WINDOW (widget))
3226 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3227 _gtk_tooltip_hide (widget);
3228 g_signal_emit (widget, widget_signals[UNMAP], 0);
3233 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3234 GdkExtensionMode mode,
3237 GList *free_list = NULL;
3240 if (window_list == NULL)
3242 if (!GTK_WIDGET_NO_WINDOW (widget))
3243 window_list = g_list_prepend (NULL, widget->window);
3245 window_list = gdk_window_get_children (widget->window);
3247 free_list = window_list;
3250 for (l = window_list; l != NULL; l = l->next)
3252 GdkWindow *window = l->data;
3255 gdk_window_get_user_data (window, &user_data);
3256 if (user_data == widget)
3260 gdk_input_set_extension_events (window,
3261 gdk_window_get_events (window),
3264 children = gdk_window_get_children (window);
3267 gtk_widget_set_extension_events_internal (widget, mode, children);
3268 g_list_free (children);
3274 g_list_free (free_list);
3278 * gtk_widget_realize:
3279 * @widget: a #GtkWidget
3281 * Creates the GDK (windowing system) resources associated with a
3282 * widget. For example, @widget->window will be created when a widget
3283 * is realized. Normally realization happens implicitly; if you show
3284 * a widget and all its parent containers, then the widget will be
3285 * realized and mapped automatically.
3287 * Realizing a widget requires all
3288 * the widget's parent widgets to be realized; calling
3289 * gtk_widget_realize() realizes the widget's parents in addition to
3290 * @widget itself. If a widget is not yet inside a toplevel window
3291 * when you realize it, bad things will happen.
3293 * This function is primarily used in widget implementations, and
3294 * isn't very useful otherwise. Many times when you think you might
3295 * need it, a better approach is to connect to a signal that will be
3296 * called after the widget is realized automatically, such as
3297 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3298 * GtkWidget::realize signal.
3301 gtk_widget_realize (GtkWidget *widget)
3303 GdkExtensionMode mode;
3304 GtkWidgetShapeInfo *shape_info;
3306 g_return_if_fail (GTK_IS_WIDGET (widget));
3307 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3308 GTK_IS_INVISIBLE (widget));
3310 if (!GTK_WIDGET_REALIZED (widget))
3313 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3314 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3317 if (widget->parent == NULL &&
3318 !GTK_WIDGET_TOPLEVEL (widget))
3319 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3320 "inside a toplevel window is not going to work very well. "
3321 "Widgets must be inside a toplevel container before realizing them.");
3323 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3324 gtk_widget_realize (widget->parent);
3326 gtk_widget_ensure_style (widget);
3328 g_signal_emit (widget, widget_signals[REALIZE], 0);
3330 gtk_widget_real_set_has_tooltip (widget,
3331 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3334 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3336 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3337 gdk_window_shape_combine_mask (widget->window,
3338 shape_info->shape_mask,
3339 shape_info->offset_x,
3340 shape_info->offset_y);
3343 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3345 gdk_window_input_shape_combine_mask (widget->window,
3346 shape_info->shape_mask,
3347 shape_info->offset_x,
3348 shape_info->offset_y);
3350 mode = gtk_widget_get_extension_events (widget);
3351 if (mode != GDK_EXTENSION_EVENTS_NONE)
3352 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3357 * gtk_widget_unrealize:
3358 * @widget: a #GtkWidget
3360 * This function is only useful in widget implementations.
3361 * Causes a widget to be unrealized (frees all GDK resources
3362 * associated with the widget, such as @widget->window).
3365 gtk_widget_unrealize (GtkWidget *widget)
3367 g_return_if_fail (GTK_IS_WIDGET (widget));
3369 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3370 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3372 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3373 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3375 if (GTK_WIDGET_REALIZED (widget))
3377 g_object_ref (widget);
3378 _gtk_tooltip_hide (widget);
3379 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3380 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3381 g_object_unref (widget);
3385 /*****************************************
3387 *****************************************/
3390 * gtk_widget_queue_draw_area:
3391 * @widget: a #GtkWidget
3392 * @x: x coordinate of upper-left corner of rectangle to redraw
3393 * @y: y coordinate of upper-left corner of rectangle to redraw
3394 * @width: width of region to draw
3395 * @height: height of region to draw
3397 * Invalidates the rectangular area of @widget defined by @x, @y,
3398 * @width and @height by calling gdk_window_invalidate_rect() on the
3399 * widget's window and all its child windows. Once the main loop
3400 * becomes idle (after the current batch of events has been processed,
3401 * roughly), the window will receive expose events for the union of
3402 * all regions that have been invalidated.
3404 * Normally you would only use this function in widget
3405 * implementations. You might also use it, or
3406 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3407 * #GtkDrawingArea or some portion thereof.
3409 * Frequently you can just call gdk_window_invalidate_rect() or
3410 * gdk_window_invalidate_region() instead of this function. Those
3411 * functions will invalidate only a single window, instead of the
3412 * widget and all its children.
3414 * The advantage of adding to the invalidated region compared to
3415 * simply drawing immediately is efficiency; using an invalid region
3416 * ensures that you only have to redraw one time.
3419 gtk_widget_queue_draw_area (GtkWidget *widget,
3425 GdkRectangle invalid_rect;
3428 g_return_if_fail (GTK_IS_WIDGET (widget));
3430 if (!GTK_WIDGET_REALIZED (widget))
3433 /* Just return if the widget or one of its ancestors isn't mapped */
3434 for (w = widget; w != NULL; w = w->parent)
3435 if (!GTK_WIDGET_MAPPED (w))
3438 /* Find the correct widget */
3440 if (!GTK_WIDGET_NO_WINDOW (widget))
3444 /* Translate widget relative to window-relative */
3446 gint wx, wy, wwidth, wheight;
3448 gdk_window_get_position (widget->window, &wx, &wy);
3449 x -= wx - widget->allocation.x;
3450 y -= wy - widget->allocation.y;
3452 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3454 if (x + width <= 0 || y + height <= 0 ||
3455 x >= wwidth || y >= wheight)
3466 if (x + width > wwidth)
3468 if (y + height > wheight)
3469 height = wheight - y;
3475 invalid_rect.width = width;
3476 invalid_rect.height = height;
3478 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3482 widget_add_child_draw_rectangle (GtkWidget *widget,
3485 GdkRectangle child_rect;
3487 if (!GTK_WIDGET_MAPPED (widget) ||
3488 widget->window != widget->parent->window)
3491 gtk_widget_get_draw_rectangle (widget, &child_rect);
3492 gdk_rectangle_union (rect, &child_rect, rect);
3496 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3499 if (GTK_WIDGET_NO_WINDOW (widget))
3501 GtkBorder *draw_border = NULL;
3503 *rect = widget->allocation;
3505 gtk_widget_style_get (widget,
3506 "draw-border", &draw_border,
3510 rect->x -= draw_border->left;
3511 rect->y -= draw_border->top;
3512 rect->width += draw_border->left + draw_border->right;
3513 rect->height += draw_border->top + draw_border->bottom;
3515 gtk_border_free (draw_border);
3518 if (GTK_IS_CONTAINER (widget))
3519 gtk_container_forall (GTK_CONTAINER (widget),
3520 (GtkCallback)widget_add_child_draw_rectangle,
3527 rect->width = widget->allocation.width;
3528 rect->height = widget->allocation.height;
3533 * gtk_widget_queue_draw:
3534 * @widget: a #GtkWidget
3536 * Equivalent to calling gtk_widget_queue_draw_area() for the
3537 * entire area of a widget.
3540 gtk_widget_queue_draw (GtkWidget *widget)
3544 g_return_if_fail (GTK_IS_WIDGET (widget));
3546 gtk_widget_get_draw_rectangle (widget, &rect);
3548 gtk_widget_queue_draw_area (widget,
3550 rect.width, rect.height);
3553 /* Invalidates the given area (allocation-relative-coordinates)
3554 * in all of the widget's windows
3557 * gtk_widget_queue_clear_area:
3558 * @widget: a #GtkWidget
3559 * @x: x coordinate of upper-left corner of rectangle to redraw
3560 * @y: y coordinate of upper-left corner of rectangle to redraw
3561 * @width: width of region to draw
3562 * @height: height of region to draw
3564 * This function is no longer different from
3565 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3566 * gtk_widget_queue_draw_area(). Originally
3567 * gtk_widget_queue_clear_area() would force a redraw of the
3568 * background for %GTK_NO_WINDOW widgets, and
3569 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3570 * the background will be redrawn.
3572 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3575 gtk_widget_queue_clear_area (GtkWidget *widget,
3581 g_return_if_fail (GTK_IS_WIDGET (widget));
3583 gtk_widget_queue_draw_area (widget, x, y, width, height);
3587 * gtk_widget_queue_clear:
3588 * @widget: a #GtkWidget
3590 * This function does the same as gtk_widget_queue_draw().
3592 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3595 gtk_widget_queue_clear (GtkWidget *widget)
3597 g_return_if_fail (GTK_IS_WIDGET (widget));
3599 gtk_widget_queue_draw (widget);
3603 * gtk_widget_queue_resize:
3604 * @widget: a #GtkWidget
3606 * This function is only for use in widget implementations.
3607 * Flags a widget to have its size renegotiated; should
3608 * be called when a widget for some reason has a new size request.
3609 * For example, when you change the text in a #GtkLabel, #GtkLabel
3610 * queues a resize to ensure there's enough space for the new text.
3613 gtk_widget_queue_resize (GtkWidget *widget)
3615 g_return_if_fail (GTK_IS_WIDGET (widget));
3617 if (GTK_WIDGET_REALIZED (widget))
3618 gtk_widget_queue_shallow_draw (widget);
3620 _gtk_size_group_queue_resize (widget);
3624 * gtk_widget_queue_resize_no_redraw:
3625 * @widget: a #GtkWidget
3627 * This function works like gtk_widget_queue_resize(),
3628 * except that the widget is not invalidated.
3633 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3635 g_return_if_fail (GTK_IS_WIDGET (widget));
3637 _gtk_size_group_queue_resize (widget);
3642 * @widget: a #GtkWidget
3643 * @area: area to draw
3645 * In GTK+ 1.2, this function would immediately render the
3646 * region @area of a widget, by invoking the virtual draw method of a
3647 * widget. In GTK+ 2.0, the draw method is gone, and instead
3648 * gtk_widget_draw() simply invalidates the specified region of the
3649 * widget, then updates the invalid region of the widget immediately.
3650 * Usually you don't want to update the region immediately for
3651 * performance reasons, so in general gtk_widget_queue_draw_area() is
3652 * a better choice if you want to draw a region of a widget.
3655 gtk_widget_draw (GtkWidget *widget,
3656 const GdkRectangle *area)
3658 g_return_if_fail (GTK_IS_WIDGET (widget));
3660 if (GTK_WIDGET_DRAWABLE (widget))
3663 gtk_widget_queue_draw_area (widget,
3665 area->width, area->height);
3667 gtk_widget_queue_draw (widget);
3669 gdk_window_process_updates (widget->window, TRUE);
3674 * gtk_widget_size_request:
3675 * @widget: a #GtkWidget
3676 * @requisition: a #GtkRequisition to be filled in
3678 * This function is typically used when implementing a #GtkContainer
3679 * subclass. Obtains the preferred size of a widget. The container
3680 * uses this information to arrange its child widgets and decide what
3681 * size allocations to give them with gtk_widget_size_allocate().
3683 * You can also call this function from an application, with some
3684 * caveats. Most notably, getting a size request requires the widget
3685 * to be associated with a screen, because font information may be
3686 * needed. Multihead-aware applications should keep this in mind.
3688 * Also remember that the size request is not necessarily the size
3689 * a widget will actually be allocated.
3691 * See also gtk_widget_get_child_requisition().
3694 gtk_widget_size_request (GtkWidget *widget,
3695 GtkRequisition *requisition)
3697 g_return_if_fail (GTK_IS_WIDGET (widget));
3699 #ifdef G_ENABLE_DEBUG
3700 if (requisition == &widget->requisition)
3701 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.");
3702 #endif /* G_ENABLE_DEBUG */
3704 _gtk_size_group_compute_requisition (widget, requisition);
3708 * gtk_widget_get_child_requisition:
3709 * @widget: a #GtkWidget
3710 * @requisition: a #GtkRequisition to be filled in
3712 * This function is only for use in widget implementations. Obtains
3713 * @widget->requisition, unless someone has forced a particular
3714 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3715 * in which case it returns that geometry instead of the widget's
3718 * This function differs from gtk_widget_size_request() in that
3719 * it retrieves the last size request value from @widget->requisition,
3720 * while gtk_widget_size_request() actually calls the "size_request" method
3721 * on @widget to compute the size request and fill in @widget->requisition,
3722 * and only then returns @widget->requisition.
3724 * Because this function does not call the "size_request" method, it
3725 * can only be used when you know that @widget->requisition is
3726 * up-to-date, that is, gtk_widget_size_request() has been called
3727 * since the last time a resize was queued. In general, only container
3728 * implementations have this information; applications should use
3729 * gtk_widget_size_request().
3732 gtk_widget_get_child_requisition (GtkWidget *widget,
3733 GtkRequisition *requisition)
3735 _gtk_size_group_get_child_requisition (widget, requisition);
3739 invalidate_predicate (GdkWindow *window,
3744 gdk_window_get_user_data (window, &user_data);
3746 return (user_data == data);
3749 /* Invalidate @region in widget->window and all children
3750 * of widget->window owned by widget. @region is in the
3751 * same coordinates as widget->allocation and will be
3752 * modified by this call.
3755 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3758 if (!GTK_WIDGET_REALIZED (widget))
3761 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3765 gdk_window_get_position (widget->window, &x, &y);
3766 gdk_region_offset (region, -x, -y);
3769 gdk_window_invalidate_maybe_recurse (widget->window, region,
3770 invalidate_predicate, widget);
3774 * gtk_widget_queue_shallow_draw:
3775 * @widget: a #GtkWidget
3777 * Like gtk_widget_queue_draw(), but only windows owned
3778 * by @widget are invalidated.
3781 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3786 if (!GTK_WIDGET_REALIZED (widget))
3789 gtk_widget_get_draw_rectangle (widget, &rect);
3791 /* get_draw_rectangle() gives us window coordinates, we
3792 * need to convert to the coordinates that widget->allocation
3795 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3799 gdk_window_get_position (widget->window, &wx, &wy);
3805 region = gdk_region_rectangle (&rect);
3806 gtk_widget_invalidate_widget_windows (widget, region);
3807 gdk_region_destroy (region);
3811 * gtk_widget_size_allocate:
3812 * @widget: a #GtkWidget
3813 * @allocation: position and size to be allocated to @widget
3815 * This function is only used by #GtkContainer subclasses, to assign a size
3816 * and position to their child widgets.
3819 gtk_widget_size_allocate (GtkWidget *widget,
3820 GtkAllocation *allocation)
3822 GtkWidgetAuxInfo *aux_info;
3823 GdkRectangle real_allocation;
3824 GdkRectangle old_allocation;
3825 gboolean alloc_needed;
3826 gboolean size_changed;
3827 gboolean position_changed;
3829 g_return_if_fail (GTK_IS_WIDGET (widget));
3831 #ifdef G_ENABLE_DEBUG
3832 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3843 parent = gtk_widget_get_parent (parent);
3846 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3847 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3848 2 * depth, " ", name,
3849 allocation->width, allocation->height);
3851 #endif /* G_ENABLE_DEBUG */
3853 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3854 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3855 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3857 old_allocation = widget->allocation;
3858 real_allocation = *allocation;
3859 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3863 if (aux_info->x_set)
3864 real_allocation.x = aux_info->x;
3865 if (aux_info->y_set)
3866 real_allocation.y = aux_info->y;
3869 if (real_allocation.width < 0 || real_allocation.height < 0)
3871 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3872 real_allocation.width,
3873 real_allocation.height);
3876 real_allocation.width = MAX (real_allocation.width, 1);
3877 real_allocation.height = MAX (real_allocation.height, 1);
3879 size_changed = (old_allocation.width != real_allocation.width ||
3880 old_allocation.height != real_allocation.height);
3881 position_changed = (old_allocation.x != real_allocation.x ||
3882 old_allocation.y != real_allocation.y);
3884 if (!alloc_needed && !size_changed && !position_changed)
3887 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3889 if (GTK_WIDGET_MAPPED (widget))
3891 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3893 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3895 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3896 gdk_region_union_with_rect (invalidate, &old_allocation);
3898 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3899 gdk_region_destroy (invalidate);
3904 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3906 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3908 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3909 gdk_region_union_with_rect (invalidate, &old_allocation);
3911 gtk_widget_invalidate_widget_windows (widget, invalidate);
3912 gdk_region_destroy (invalidate);
3917 if ((size_changed || position_changed) && widget->parent &&
3918 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3920 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3921 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3922 gdk_region_destroy (invalidate);
3927 * gtk_widget_common_ancestor:
3928 * @widget_a: a #GtkWidget
3929 * @widget_b: a #GtkWidget
3931 * Find the common ancestor of @widget_a and @widget_b that
3932 * is closest to the two widgets.
3934 * Return value: the closest common ancestor of @widget_a and
3935 * @widget_b or %NULL if @widget_a and @widget_b do not
3936 * share a common ancestor.
3939 gtk_widget_common_ancestor (GtkWidget *widget_a,
3940 GtkWidget *widget_b)
3942 GtkWidget *parent_a;
3943 GtkWidget *parent_b;
3947 parent_a = widget_a;
3948 while (parent_a->parent)
3950 parent_a = parent_a->parent;
3954 parent_b = widget_b;
3955 while (parent_b->parent)
3957 parent_b = parent_b->parent;
3961 if (parent_a != parent_b)
3964 while (depth_a > depth_b)
3966 widget_a = widget_a->parent;
3970 while (depth_b > depth_a)
3972 widget_b = widget_b->parent;
3976 while (widget_a != widget_b)
3978 widget_a = widget_a->parent;
3979 widget_b = widget_b->parent;
3986 * gtk_widget_translate_coordinates:
3987 * @src_widget: a #GtkWidget
3988 * @dest_widget: a #GtkWidget
3989 * @src_x: X position relative to @src_widget
3990 * @src_y: Y position relative to @src_widget
3991 * @dest_x: location to store X position relative to @dest_widget
3992 * @dest_y: location to store Y position relative to @dest_widget
3994 * Translate coordinates relative to @src_widget's allocation to coordinates
3995 * relative to @dest_widget's allocations. In order to perform this
3996 * operation, both widgets must be realized, and must share a common
3999 * Return value: %FALSE if either widget was not realized, or there
4000 * was no common ancestor. In this case, nothing is stored in
4001 * *@dest_x and *@dest_y. Otherwise %TRUE.
4004 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4005 GtkWidget *dest_widget,
4011 GtkWidget *ancestor;
4014 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4015 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4017 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4018 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4021 /* Translate from allocation relative to window relative */
4022 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4025 gdk_window_get_position (src_widget->window, &wx, &wy);
4027 src_x -= wx - src_widget->allocation.x;
4028 src_y -= wy - src_widget->allocation.y;
4032 src_x += src_widget->allocation.x;
4033 src_y += src_widget->allocation.y;
4036 /* Translate to the common ancestor */
4037 window = src_widget->window;
4038 while (window != ancestor->window)
4042 gdk_window_get_position (window, &dx, &dy);
4047 window = gdk_window_get_parent (window);
4049 if (!window) /* Handle GtkHandleBox */
4054 window = dest_widget->window;
4055 while (window != ancestor->window)
4059 gdk_window_get_position (window, &dx, &dy);
4064 window = gdk_window_get_parent (window);
4066 if (!window) /* Handle GtkHandleBox */
4070 /* Translate from window relative to allocation relative */
4071 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4074 gdk_window_get_position (dest_widget->window, &wx, &wy);
4076 src_x += wx - dest_widget->allocation.x;
4077 src_y += wy - dest_widget->allocation.y;
4081 src_x -= dest_widget->allocation.x;
4082 src_y -= dest_widget->allocation.y;
4094 gtk_widget_real_size_allocate (GtkWidget *widget,
4095 GtkAllocation *allocation)
4097 widget->allocation = *allocation;
4099 if (GTK_WIDGET_REALIZED (widget) &&
4100 !GTK_WIDGET_NO_WINDOW (widget))
4102 gdk_window_move_resize (widget->window,
4103 allocation->x, allocation->y,
4104 allocation->width, allocation->height);
4109 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4112 /* widgets must be onscreen for accels to take effect */
4113 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4117 * gtk_widget_can_activate_accel:
4118 * @widget: a #GtkWidget
4119 * @signal_id: the ID of a signal installed on @widget
4121 * Determines whether an accelerator that activates the signal
4122 * identified by @signal_id can currently be activated.
4123 * This is done by emitting the #GtkWidget::can-activate-accel
4124 * signal on @widget; if the signal isn't overridden by a
4125 * handler or in a derived widget, then the default check is
4126 * that the widget must be sensitive, and the widget and all
4127 * its ancestors mapped.
4129 * Return value: %TRUE if the accelerator can be activated.
4134 gtk_widget_can_activate_accel (GtkWidget *widget,
4137 gboolean can_activate = FALSE;
4138 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4139 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4140 return can_activate;
4149 closure_accel_activate (GClosure *closure,
4150 GValue *return_value,
4151 guint n_param_values,
4152 const GValue *param_values,
4153 gpointer invocation_hint,
4154 gpointer marshal_data)
4156 AccelClosure *aclosure = (AccelClosure*) closure;
4157 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4160 g_signal_emit (closure->data, aclosure->signal_id, 0);
4162 /* whether accelerator was handled */
4163 g_value_set_boolean (return_value, can_activate);
4167 closures_destroy (gpointer data)
4169 GSList *slist, *closures = data;
4171 for (slist = closures; slist; slist = slist->next)
4173 g_closure_invalidate (slist->data);
4174 g_closure_unref (slist->data);
4176 g_slist_free (closures);
4180 widget_new_accel_closure (GtkWidget *widget,
4183 AccelClosure *aclosure;
4184 GClosure *closure = NULL;
4185 GSList *slist, *closures;
4187 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4188 for (slist = closures; slist; slist = slist->next)
4189 if (!gtk_accel_group_from_accel_closure (slist->data))
4191 /* reuse this closure */
4192 closure = slist->data;
4197 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4198 closures = g_slist_prepend (closures, g_closure_ref (closure));
4199 g_closure_sink (closure);
4200 g_closure_set_marshal (closure, closure_accel_activate);
4202 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4204 aclosure = (AccelClosure*) closure;
4205 g_assert (closure->data == widget);
4206 g_assert (closure->marshal == closure_accel_activate);
4207 aclosure->signal_id = signal_id;
4213 * gtk_widget_add_accelerator
4214 * @widget: widget to install an accelerator on
4215 * @accel_signal: widget signal to emit on accelerator activation
4216 * @accel_group: accel group for this widget, added to its toplevel
4217 * @accel_key: GDK keyval of the accelerator
4218 * @accel_mods: modifier key combination of the accelerator
4219 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4221 * Installs an accelerator for this @widget in @accel_group that causes
4222 * @accel_signal to be emitted if the accelerator is activated.
4223 * The @accel_group needs to be added to the widget's toplevel via
4224 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4225 * Accelerators added through this function are not user changeable during
4226 * runtime. If you want to support accelerators that can be changed by the
4227 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4228 * gtk_menu_item_set_accel_path() instead.
4231 gtk_widget_add_accelerator (GtkWidget *widget,
4232 const gchar *accel_signal,
4233 GtkAccelGroup *accel_group,
4235 GdkModifierType accel_mods,
4236 GtkAccelFlags accel_flags)
4241 g_return_if_fail (GTK_IS_WIDGET (widget));
4242 g_return_if_fail (accel_signal != NULL);
4243 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4245 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4246 if (!query.signal_id ||
4247 !(query.signal_flags & G_SIGNAL_ACTION) ||
4248 query.return_type != G_TYPE_NONE ||
4251 /* hmm, should be elaborate enough */
4252 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4253 G_OBJECT_TYPE_NAME (widget), accel_signal);
4257 closure = widget_new_accel_closure (widget, query.signal_id);
4259 g_object_ref (widget);
4261 /* install the accelerator. since we don't map this onto an accel_path,
4262 * the accelerator will automatically be locked.
4264 gtk_accel_group_connect (accel_group,
4267 accel_flags | GTK_ACCEL_LOCKED,
4270 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4272 g_object_unref (widget);
4276 * gtk_widget_remove_accelerator:
4277 * @widget: widget to install an accelerator on
4278 * @accel_group: accel group for this widget
4279 * @accel_key: GDK keyval of the accelerator
4280 * @accel_mods: modifier key combination of the accelerator
4281 * @returns: whether an accelerator was installed and could be removed
4283 * Removes an accelerator from @widget, previously installed with
4284 * gtk_widget_add_accelerator().
4287 gtk_widget_remove_accelerator (GtkWidget *widget,
4288 GtkAccelGroup *accel_group,
4290 GdkModifierType accel_mods)
4292 GtkAccelGroupEntry *ag_entry;
4293 GList *slist, *clist;
4296 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4297 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4299 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4300 clist = gtk_widget_list_accel_closures (widget);
4301 for (slist = clist; slist; slist = slist->next)
4305 for (i = 0; i < n; i++)
4306 if (slist->data == (gpointer) ag_entry[i].closure)
4308 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4310 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4312 g_list_free (clist);
4317 g_list_free (clist);
4319 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4320 accel_key, accel_mods, accel_group,
4321 G_OBJECT_TYPE_NAME (widget), widget);
4327 * gtk_widget_list_accel_closures
4328 * @widget: widget to list accelerator closures for
4329 * @returns: a newly allocated #GList of closures
4331 * Lists the closures used by @widget for accelerator group connections
4332 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4333 * The closures can be used to monitor accelerator changes on @widget,
4334 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4335 * #GtkAccelGroup of a closure which can be found out with
4336 * gtk_accel_group_from_accel_closure().
4339 gtk_widget_list_accel_closures (GtkWidget *widget)
4342 GList *clist = NULL;
4344 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4346 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4347 if (gtk_accel_group_from_accel_closure (slist->data))
4348 clist = g_list_prepend (clist, slist->data);
4354 GtkAccelGroup *accel_group;
4359 destroy_accel_path (gpointer data)
4361 AccelPath *apath = data;
4363 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4365 /* closures_destroy takes care of unrefing the closure */
4366 g_object_unref (apath->accel_group);
4368 g_slice_free (AccelPath, apath);
4373 * gtk_widget_set_accel_path:
4374 * @widget: a #GtkWidget
4375 * @accel_path: path used to look up the accelerator
4376 * @accel_group: a #GtkAccelGroup.
4378 * Given an accelerator group, @accel_group, and an accelerator path,
4379 * @accel_path, sets up an accelerator in @accel_group so whenever the
4380 * key binding that is defined for @accel_path is pressed, @widget
4381 * will be activated. This removes any accelerators (for any
4382 * accelerator group) installed by previous calls to
4383 * gtk_widget_set_accel_path(). Associating accelerators with
4384 * paths allows them to be modified by the user and the modifications
4385 * to be saved for future use. (See gtk_accel_map_save().)
4387 * This function is a low level function that would most likely
4388 * be used by a menu creation system like #GtkUIManager. If you
4389 * use #GtkUIManager, setting up accelerator paths will be done
4392 * Even when you you aren't using #GtkUIManager, if you only want to
4393 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4394 * provides a somewhat more convenient interface.
4396 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4397 * pass a static string, you can save some memory by interning it first with
4398 * g_intern_static_string().
4401 gtk_widget_set_accel_path (GtkWidget *widget,
4402 const gchar *accel_path,
4403 GtkAccelGroup *accel_group)
4407 g_return_if_fail (GTK_IS_WIDGET (widget));
4408 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4412 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4413 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4415 gtk_accel_map_add_entry (accel_path, 0, 0);
4416 apath = g_slice_new (AccelPath);
4417 apath->accel_group = g_object_ref (accel_group);
4418 apath->path_quark = g_quark_from_string (accel_path);
4419 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4424 /* also removes possible old settings */
4425 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4428 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4430 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4434 _gtk_widget_get_accel_path (GtkWidget *widget,
4439 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4441 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4443 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4444 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4448 * gtk_widget_mnemonic_activate:
4449 * @widget: a #GtkWidget
4450 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4452 * Emits the #GtkWidget::mnemonic-activate signal.
4454 * The default handler for this signal activates the @widget if
4455 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4458 * Returns: %TRUE if the signal has been handled
4461 gtk_widget_mnemonic_activate (GtkWidget *widget,
4462 gboolean group_cycling)
4466 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4468 group_cycling = group_cycling != FALSE;
4469 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4472 g_signal_emit (widget,
4473 widget_signals[MNEMONIC_ACTIVATE],
4481 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4482 gboolean group_cycling)
4484 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4485 gtk_widget_activate (widget);
4486 else if (GTK_WIDGET_CAN_FOCUS (widget))
4487 gtk_widget_grab_focus (widget);
4490 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4491 G_OBJECT_TYPE_NAME (widget));
4492 gtk_widget_error_bell (widget);
4498 gtk_widget_real_key_press_event (GtkWidget *widget,
4501 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4505 gtk_widget_real_key_release_event (GtkWidget *widget,
4508 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4512 gtk_widget_real_focus_in_event (GtkWidget *widget,
4513 GdkEventFocus *event)
4515 gtk_widget_queue_shallow_draw (widget);
4521 gtk_widget_real_focus_out_event (GtkWidget *widget,
4522 GdkEventFocus *event)
4524 gtk_widget_queue_shallow_draw (widget);
4529 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4530 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4534 * @widget: a #GtkWidget
4535 * @event: a #GdkEvent
4537 * Rarely-used function. This function is used to emit
4538 * the event signals on a widget (those signals should never
4539 * be emitted without using this function to do so).
4540 * If you want to synthesize an event though, don't use this function;
4541 * instead, use gtk_main_do_event() so the event will behave as if
4542 * it were in the event queue. Don't synthesize expose events; instead,
4543 * use gdk_window_invalidate_rect() to invalidate a region of the
4546 * Return value: return from the event signal emission (%TRUE if
4547 * the event was handled)
4550 gtk_widget_event (GtkWidget *widget,
4553 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4554 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4556 if (event->type == GDK_EXPOSE)
4558 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4559 "the same effect, call gdk_window_invalidate_rect/region(), "
4560 "followed by gdk_window_process_updates().");
4564 return gtk_widget_event_internal (widget, event);
4569 * gtk_widget_send_expose:
4570 * @widget: a #GtkWidget
4571 * @event: a expose #GdkEvent
4573 * Very rarely-used function. This function is used to emit
4574 * an expose event signals on a widget. This function is not
4575 * normally used directly. The only time it is used is when
4576 * propagating an expose event to a child %NO_WINDOW widget, and
4577 * that is normally done using gtk_container_propagate_expose().
4579 * If you want to force an area of a window to be redrawn,
4580 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4581 * To cause the redraw to be done immediately, follow that call
4582 * with a call to gdk_window_process_updates().
4584 * Return value: return from the event signal emission (%TRUE if
4585 * the event was handled)
4588 gtk_widget_send_expose (GtkWidget *widget,
4591 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4592 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4593 g_return_val_if_fail (event != NULL, TRUE);
4594 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4596 return gtk_widget_event_internal (widget, event);
4600 event_window_is_still_viewable (GdkEvent *event)
4602 /* Some programs, such as gnome-theme-manager, fake widgets
4603 * into exposing onto a pixmap by sending expose events with
4604 * event->window pointing to a pixmap
4606 if (GDK_IS_PIXMAP (event->any.window))
4607 return event->type == GDK_EXPOSE;
4609 /* Check that we think the event's window is viewable before
4610 * delivering the event, to prevent suprises. We do this here
4611 * at the last moment, since the event may have been queued
4612 * up behind other events, held over a recursive main loop, etc.
4614 switch (event->type)
4617 case GDK_MOTION_NOTIFY:
4618 case GDK_BUTTON_PRESS:
4619 case GDK_2BUTTON_PRESS:
4620 case GDK_3BUTTON_PRESS:
4622 case GDK_ENTER_NOTIFY:
4623 case GDK_PROXIMITY_IN:
4625 return event->any.window && gdk_window_is_viewable (event->any.window);
4628 /* The following events are the second half of paired events;
4629 * we always deliver them to deal with widgets that clean up
4630 * on the second half.
4632 case GDK_BUTTON_RELEASE:
4633 case GDK_KEY_RELEASE:
4634 case GDK_LEAVE_NOTIFY:
4635 case GDK_PROXIMITY_OUT:
4639 /* Remaining events would make sense on an not-viewable window,
4640 * or don't have an associated window.
4647 gtk_widget_event_internal (GtkWidget *widget,
4650 gboolean return_val = FALSE;
4652 /* We check only once for is-still-visible; if someone
4653 * hides the window in on of the signals on the widget,
4654 * they are responsible for returning TRUE to terminate
4657 if (!event_window_is_still_viewable (event))
4660 g_object_ref (widget);
4662 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4663 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4668 switch (event->type)
4673 case GDK_BUTTON_PRESS:
4674 case GDK_2BUTTON_PRESS:
4675 case GDK_3BUTTON_PRESS:
4676 signal_num = BUTTON_PRESS_EVENT;
4679 signal_num = SCROLL_EVENT;
4681 case GDK_BUTTON_RELEASE:
4682 signal_num = BUTTON_RELEASE_EVENT;
4684 case GDK_MOTION_NOTIFY:
4685 signal_num = MOTION_NOTIFY_EVENT;
4688 signal_num = DELETE_EVENT;
4691 signal_num = DESTROY_EVENT;
4692 _gtk_tooltip_hide (widget);
4695 signal_num = KEY_PRESS_EVENT;
4697 case GDK_KEY_RELEASE:
4698 signal_num = KEY_RELEASE_EVENT;
4700 case GDK_ENTER_NOTIFY:
4701 signal_num = ENTER_NOTIFY_EVENT;
4703 case GDK_LEAVE_NOTIFY:
4704 signal_num = LEAVE_NOTIFY_EVENT;
4706 case GDK_FOCUS_CHANGE:
4707 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4708 if (event->focus_change.in)
4709 _gtk_tooltip_focus_in (widget);
4711 _gtk_tooltip_focus_out (widget);
4714 signal_num = CONFIGURE_EVENT;
4717 signal_num = MAP_EVENT;
4720 signal_num = UNMAP_EVENT;
4722 case GDK_WINDOW_STATE:
4723 signal_num = WINDOW_STATE_EVENT;
4725 case GDK_PROPERTY_NOTIFY:
4726 signal_num = PROPERTY_NOTIFY_EVENT;
4728 case GDK_SELECTION_CLEAR:
4729 signal_num = SELECTION_CLEAR_EVENT;
4731 case GDK_SELECTION_REQUEST:
4732 signal_num = SELECTION_REQUEST_EVENT;
4734 case GDK_SELECTION_NOTIFY:
4735 signal_num = SELECTION_NOTIFY_EVENT;
4737 case GDK_PROXIMITY_IN:
4738 signal_num = PROXIMITY_IN_EVENT;
4740 case GDK_PROXIMITY_OUT:
4741 signal_num = PROXIMITY_OUT_EVENT;
4744 signal_num = NO_EXPOSE_EVENT;
4746 case GDK_CLIENT_EVENT:
4747 signal_num = CLIENT_EVENT;
4750 signal_num = EXPOSE_EVENT;
4752 case GDK_VISIBILITY_NOTIFY:
4753 signal_num = VISIBILITY_NOTIFY_EVENT;
4755 case GDK_GRAB_BROKEN:
4756 signal_num = GRAB_BROKEN;
4759 signal_num = DAMAGE_EVENT;
4762 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4766 if (signal_num != -1)
4767 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4769 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4770 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4774 g_object_unref (widget);
4780 * gtk_widget_activate:
4781 * @widget: a #GtkWidget that's activatable
4783 * For widgets that can be "activated" (buttons, menu items, etc.)
4784 * this function activates them. Activation is what happens when you
4785 * press Enter on a widget during key navigation. If @widget isn't
4786 * activatable, the function returns %FALSE.
4788 * Return value: %TRUE if the widget was activatable
4791 gtk_widget_activate (GtkWidget *widget)
4793 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4795 if (WIDGET_CLASS (widget)->activate_signal)
4797 /* FIXME: we should eventually check the signals signature here */
4798 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4807 * gtk_widget_set_scroll_adjustments:
4808 * @widget: a #GtkWidget
4809 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4810 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4812 * For widgets that support scrolling, sets the scroll adjustments and
4813 * returns %TRUE. For widgets that don't support scrolling, does
4814 * nothing and returns %FALSE. Widgets that don't support scrolling
4815 * can be scrolled by placing them in a #GtkViewport, which does
4816 * support scrolling.
4818 * Return value: %TRUE if the widget supports scrolling
4821 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4822 GtkAdjustment *hadjustment,
4823 GtkAdjustment *vadjustment)
4828 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4831 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4833 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4835 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
4839 g_signal_query (signal_id, &query);
4840 if (!query.signal_id ||
4841 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
4842 query.return_type != G_TYPE_NONE ||
4843 query.n_params != 2 ||
4844 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
4845 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
4847 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
4848 G_OBJECT_TYPE_NAME (widget), query.signal_name);
4852 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
4857 gtk_widget_reparent_subwindows (GtkWidget *widget,
4858 GdkWindow *new_window)
4860 if (GTK_WIDGET_NO_WINDOW (widget))
4862 GList *children = gdk_window_get_children (widget->window);
4865 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4867 GdkWindow *window = tmp_list->data;
4870 gdk_window_get_user_data (window, &child);
4871 while (child && child != widget)
4872 child = ((GtkWidget*) child)->parent;
4875 gdk_window_reparent (window, new_window, 0, 0);
4878 g_list_free (children);
4883 GList *tmp_list, *children;
4885 parent = gdk_window_get_parent (widget->window);
4888 gdk_window_reparent (widget->window, new_window, 0, 0);
4891 children = gdk_window_get_children (parent);
4893 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4895 GdkWindow *window = tmp_list->data;
4898 gdk_window_get_user_data (window, &child);
4900 if (child == widget)
4901 gdk_window_reparent (window, new_window, 0, 0);
4904 g_list_free (children);
4910 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4911 gpointer client_data)
4913 g_assert (client_data != NULL);
4915 if (GTK_WIDGET_NO_WINDOW (widget))
4918 g_object_unref (widget->window);
4919 widget->window = (GdkWindow*) client_data;
4921 g_object_ref (widget->window);
4923 if (GTK_IS_CONTAINER (widget))
4924 gtk_container_forall (GTK_CONTAINER (widget),
4925 gtk_widget_reparent_fixup_child,
4931 * gtk_widget_reparent:
4932 * @widget: a #GtkWidget
4933 * @new_parent: a #GtkContainer to move the widget into
4935 * Moves a widget from one #GtkContainer to another, handling reference
4936 * count issues to avoid destroying the widget.
4939 gtk_widget_reparent (GtkWidget *widget,
4940 GtkWidget *new_parent)
4942 g_return_if_fail (GTK_IS_WIDGET (widget));
4943 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4944 g_return_if_fail (widget->parent != NULL);
4946 if (widget->parent != new_parent)
4948 /* First try to see if we can get away without unrealizing
4949 * the widget as we reparent it. if so we set a flag so
4950 * that gtk_widget_unparent doesn't unrealize widget
4952 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4953 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4955 g_object_ref (widget);
4956 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4957 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4958 g_object_unref (widget);
4960 if (GTK_WIDGET_IN_REPARENT (widget))
4962 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4964 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4965 gtk_widget_reparent_fixup_child (widget,
4966 gtk_widget_get_parent_window (widget));
4969 g_object_notify (G_OBJECT (widget), "parent");
4974 * gtk_widget_intersect:
4975 * @widget: a #GtkWidget
4976 * @area: a rectangle
4977 * @intersection: rectangle to store intersection of @widget and @area
4979 * Computes the intersection of a @widget's area and @area, storing
4980 * the intersection in @intersection, and returns %TRUE if there was
4981 * an intersection. @intersection may be %NULL if you're only
4982 * interested in whether there was an intersection.
4984 * Return value: %TRUE if there was an intersection
4987 gtk_widget_intersect (GtkWidget *widget,
4988 const GdkRectangle *area,
4989 GdkRectangle *intersection)
4995 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4996 g_return_val_if_fail (area != NULL, FALSE);
4999 dest = intersection;
5003 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5005 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
5007 intersection->x -= widget->allocation.x;
5008 intersection->y -= widget->allocation.y;
5015 * gtk_widget_region_intersect:
5016 * @widget: a #GtkWidget
5017 * @region: a #GdkRegion, in the same coordinate system as
5018 * @widget->allocation. That is, relative to @widget->window
5019 * for %NO_WINDOW widgets; relative to the parent window
5020 * of @widget->window for widgets with their own window.
5021 * @returns: A newly allocated region holding the intersection of @widget
5022 * and @region. The coordinates of the return value are
5023 * relative to @widget->window for %NO_WINDOW widgets, and
5024 * relative to the parent window of @widget->window for
5025 * widgets with their own window.
5027 * Computes the intersection of a @widget's area and @region, returning
5028 * the intersection. The result may be empty, use gdk_region_empty() to
5032 gtk_widget_region_intersect (GtkWidget *widget,
5033 const GdkRegion *region)
5038 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5039 g_return_val_if_fail (region != NULL, NULL);
5041 gtk_widget_get_draw_rectangle (widget, &rect);
5043 dest = gdk_region_rectangle (&rect);
5045 gdk_region_intersect (dest, region);
5051 * _gtk_widget_grab_notify:
5052 * @widget: a #GtkWidget
5053 * @was_grabbed: whether a grab is now in effect
5055 * Emits the #GtkWidget::grab-notify signal on @widget.
5060 _gtk_widget_grab_notify (GtkWidget *widget,
5061 gboolean was_grabbed)
5063 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5067 * gtk_widget_grab_focus:
5068 * @widget: a #GtkWidget
5070 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5071 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5072 * something like #GtkFrame won't work.
5074 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5075 * gtk_widget_set_can_focus() to modify that flag.
5078 gtk_widget_grab_focus (GtkWidget *widget)
5080 g_return_if_fail (GTK_IS_WIDGET (widget));
5082 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5085 g_object_ref (widget);
5086 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5087 g_object_notify (G_OBJECT (widget), "has-focus");
5088 g_object_unref (widget);
5092 reset_focus_recurse (GtkWidget *widget,
5095 if (GTK_IS_CONTAINER (widget))
5097 GtkContainer *container;
5099 container = GTK_CONTAINER (widget);
5100 gtk_container_set_focus_child (container, NULL);
5102 gtk_container_foreach (container,
5103 reset_focus_recurse,
5109 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5111 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5113 GtkWidget *toplevel;
5116 /* clear the current focus setting, break if the current widget
5117 * is the focus widget's parent, since containers above that will
5118 * be set by the next loop.
5120 toplevel = gtk_widget_get_toplevel (focus_widget);
5121 if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
5123 widget = GTK_WINDOW (toplevel)->focus_widget;
5125 if (widget == focus_widget)
5127 /* We call _gtk_window_internal_set_focus() here so that the
5128 * toplevel window can request the focus if necessary.
5129 * This is needed when the toplevel is a GtkPlug
5131 if (!GTK_WIDGET_HAS_FOCUS (widget))
5132 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5139 while (widget->parent && widget->parent != focus_widget->parent)
5141 widget = widget->parent;
5142 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5146 else if (toplevel != focus_widget)
5148 /* gtk_widget_grab_focus() operates on a tree without window...
5149 * actually, this is very questionable behaviour.
5152 gtk_container_foreach (GTK_CONTAINER (toplevel),
5153 reset_focus_recurse,
5157 /* now propagate the new focus up the widget tree and finally
5158 * set it on the window
5160 widget = focus_widget;
5161 while (widget->parent)
5163 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5164 widget = widget->parent;
5166 if (GTK_IS_WINDOW (widget))
5167 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5172 gtk_widget_real_query_tooltip (GtkWidget *widget,
5175 gboolean keyboard_tip,
5176 GtkTooltip *tooltip)
5178 gchar *tooltip_markup;
5179 gboolean has_tooltip;
5181 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5182 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5184 if (has_tooltip && tooltip_markup)
5186 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5194 gtk_widget_real_show_help (GtkWidget *widget,
5195 GtkWidgetHelpType help_type)
5197 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5199 _gtk_tooltip_toggle_keyboard_mode (widget);
5208 gtk_widget_real_focus (GtkWidget *widget,
5209 GtkDirectionType direction)
5211 if (!GTK_WIDGET_CAN_FOCUS (widget))
5214 if (!gtk_widget_is_focus (widget))
5216 gtk_widget_grab_focus (widget);
5224 gtk_widget_real_move_focus (GtkWidget *widget,
5225 GtkDirectionType direction)
5227 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5229 if (GTK_IS_WINDOW (toplevel) &&
5230 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5232 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5238 gtk_widget_real_keynav_failed (GtkWidget *widget,
5239 GtkDirectionType direction)
5241 gboolean cursor_only;
5245 case GTK_DIR_TAB_FORWARD:
5246 case GTK_DIR_TAB_BACKWARD:
5253 g_object_get (gtk_widget_get_settings (widget),
5254 "gtk-keynav-cursor-only", &cursor_only,
5261 gtk_widget_error_bell (widget);
5267 * gtk_widget_set_can_focus:
5268 * @widget: a #GtkWidget
5269 * @can_focus: whether or not @widget can own the input focus.
5271 * Specifies whether @widget can own the input focus. See
5272 * gtk_widget_grab_focus() for actually setting the input focus on a
5278 gtk_widget_set_can_focus (GtkWidget *widget,
5281 g_return_if_fail (GTK_IS_WIDGET (widget));
5283 if (can_focus != GTK_WIDGET_CAN_FOCUS (widget))
5286 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
5288 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
5290 gtk_widget_queue_resize (widget);
5291 g_object_notify (G_OBJECT (widget), "can-focus");
5296 * gtk_widget_get_can_focus:
5297 * @widget: a #GtkWidget
5299 * Determines whether @widget can own the input focus. See
5300 * gtk_widget_set_can_focus().
5302 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5307 gtk_widget_get_can_focus (GtkWidget *widget)
5309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5311 return GTK_WIDGET_CAN_FOCUS (widget);
5315 * gtk_widget_has_focus:
5316 * @widget: a #GtkWidget
5318 * Determines if the widget has the global input focus. See
5319 * gtk_widget_is_focus() for the difference between having the global
5320 * input focus, and only having the focus within a toplevel.
5322 * Return value: %TRUE if the widget has the global input focus.
5327 gtk_widget_has_focus (GtkWidget *widget)
5329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5331 return GTK_WIDGET_HAS_FOCUS (widget);
5335 * gtk_widget_is_focus:
5336 * @widget: a #GtkWidget
5338 * Determines if the widget is the focus widget within its
5339 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5340 * necessarily set; %HAS_FOCUS will only be set if the
5341 * toplevel widget additionally has the global input focus.)
5343 * Return value: %TRUE if the widget is the focus widget.
5346 gtk_widget_is_focus (GtkWidget *widget)
5348 GtkWidget *toplevel;
5350 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5352 toplevel = gtk_widget_get_toplevel (widget);
5354 if (GTK_IS_WINDOW (toplevel))
5355 return widget == GTK_WINDOW (toplevel)->focus_widget;
5361 * gtk_widget_set_can_default:
5362 * @widget: a #GtkWidget
5363 * @can_default: whether or not @widget can be a default widget.
5365 * Specifies whether @widget can be a default widget. See
5366 * gtk_widget_grab_default() for details about the meaning of
5372 gtk_widget_set_can_default (GtkWidget *widget,
5373 gboolean can_default)
5375 g_return_if_fail (GTK_IS_WIDGET (widget));
5377 if (can_default != GTK_WIDGET_CAN_DEFAULT (widget))
5380 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
5382 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
5384 gtk_widget_queue_resize (widget);
5385 g_object_notify (G_OBJECT (widget), "can-default");
5390 * gtk_widget_get_can_default:
5391 * @widget: a #GtkWidget
5393 * Determines whether @widget can be a default widget. See
5394 * gtk_widget_set_can_default().
5396 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
5401 gtk_widget_get_can_default (GtkWidget *widget)
5403 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5405 return GTK_WIDGET_CAN_DEFAULT (widget);
5409 * gtk_widget_has_default:
5410 * @widget: a #GtkWidget
5412 * Determines whether @widget is the current default widget within its
5413 * toplevel. See gtk_widget_set_can_default().
5415 * Return value: %TRUE if @widget is the current default widget within
5416 * its toplevel, %FALSE otherwise
5421 gtk_widget_has_default (GtkWidget *widget)
5423 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5425 return GTK_WIDGET_HAS_DEFAULT (widget);
5429 * gtk_widget_grab_default:
5430 * @widget: a #GtkWidget
5432 * Causes @widget to become the default widget. @widget must have the
5433 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5434 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
5435 * %TRUE)</literal>. The default widget is activated when
5436 * the user presses Enter in a window. Default widgets must be
5437 * activatable, that is, gtk_widget_activate() should affect them.
5440 gtk_widget_grab_default (GtkWidget *widget)
5444 g_return_if_fail (GTK_IS_WIDGET (widget));
5445 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5447 window = gtk_widget_get_toplevel (widget);
5449 if (window && GTK_WIDGET_TOPLEVEL (window))
5450 gtk_window_set_default (GTK_WINDOW (window), widget);
5452 g_warning (G_STRLOC ": widget not within a GtkWindow");
5456 * gtk_widget_set_receives_default:
5457 * @widget: a #GtkWidget
5458 * @receives_default: whether or not @widget can be a default widget.
5460 * Specifies whether @widget will be treated as the default widget
5461 * within its toplevel when it has the focus, even if another widget
5464 * See gtk_widget_grab_default() for details about the meaning of
5470 gtk_widget_set_receives_default (GtkWidget *widget,
5471 gboolean receives_default)
5473 g_return_if_fail (GTK_IS_WIDGET (widget));
5475 if (receives_default != gtk_widget_get_receives_default (widget))
5477 if (receives_default)
5478 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5480 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
5482 g_object_notify (G_OBJECT (widget), "receives-default");
5487 * gtk_widget_get_receives_default:
5488 * @widget: a #GtkWidget
5490 * Determines whether @widget is alyways treated as default widget
5491 * withing its toplevel when it has the focus, even if another widget
5494 * See gtk_widget_set_receives_default().
5496 * Return value: %TRUE if @widget acts as default widget when focussed,
5502 gtk_widget_get_receives_default (GtkWidget *widget)
5504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5506 return (GTK_WIDGET_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
5510 * gtk_widget_has_grab:
5511 * @widget: a #GtkWidget
5513 * Determines whether the widget is currently grabbing events, so it
5514 * is the only widget receiving input events (keyboard and mouse).
5516 * See also gtk_grab_add().
5518 * Return value: %TRUE if the widget is in the grab_widgets stack
5523 gtk_widget_has_grab (GtkWidget *widget)
5525 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5527 return (GTK_WIDGET_FLAGS (widget) & GTK_HAS_GRAB) != 0;
5531 * gtk_widget_set_name:
5532 * @widget: a #GtkWidget
5533 * @name: name for the widget
5535 * Widgets can be named, which allows you to refer to them from a
5536 * gtkrc file. You can apply a style to widgets with a particular name
5537 * in the gtkrc file. See the documentation for gtkrc files (on the
5538 * same page as the docs for #GtkRcStyle).
5540 * Note that widget names are separated by periods in paths (see
5541 * gtk_widget_path()), so names with embedded periods may cause confusion.
5544 gtk_widget_set_name (GtkWidget *widget,
5549 g_return_if_fail (GTK_IS_WIDGET (widget));
5551 new_name = g_strdup (name);
5552 g_free (widget->name);
5553 widget->name = new_name;
5555 if (GTK_WIDGET_RC_STYLE (widget))
5556 gtk_widget_reset_rc_style (widget);
5558 g_object_notify (G_OBJECT (widget), "name");
5562 * gtk_widget_get_name:
5563 * @widget: a #GtkWidget
5565 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5566 * significance of widget names.
5568 * Return value: name of the widget. This string is owned by GTK+ and
5569 * should not be modified or freed
5571 G_CONST_RETURN gchar*
5572 gtk_widget_get_name (GtkWidget *widget)
5574 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5577 return widget->name;
5578 return g_type_name (GTK_WIDGET_TYPE (widget));
5582 * gtk_widget_set_state:
5583 * @widget: a #GtkWidget
5584 * @state: new state for @widget
5586 * This function is for use in widget implementations. Sets the state
5587 * of a widget (insensitive, prelighted, etc.) Usually you should set
5588 * the state using wrapper functions such as gtk_widget_set_sensitive().
5591 gtk_widget_set_state (GtkWidget *widget,
5594 g_return_if_fail (GTK_IS_WIDGET (widget));
5596 if (state == GTK_WIDGET_STATE (widget))
5599 if (state == GTK_STATE_INSENSITIVE)
5600 gtk_widget_set_sensitive (widget, FALSE);
5606 data.state_restoration = FALSE;
5607 data.use_forall = FALSE;
5609 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5611 data.parent_sensitive = TRUE;
5613 gtk_widget_propagate_state (widget, &data);
5615 if (GTK_WIDGET_DRAWABLE (widget))
5616 gtk_widget_queue_draw (widget);
5621 * gtk_widget_get_state:
5622 * @widget: a #GtkWidget
5624 * Returns the widget's state. See gtk_widget_set_state().
5626 * Returns: the state of @widget.
5631 gtk_widget_get_state (GtkWidget *widget)
5633 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
5635 return widget->state;
5639 * gtk_widget_set_visible:
5640 * @widget: a #GtkWidget
5641 * @visible: whether the widget should be shown or not
5643 * Sets the visibility state of @widget. Note that setting this to
5644 * %TRUE doesn't mean the widget is actually viewable, see
5645 * gtk_widget_get_visible().
5647 * This function simply calls gtk_widget_show() or gtk_widget_hide()
5648 * but is nicer to use when the visibility of the widget depends on
5654 gtk_widget_set_visible (GtkWidget *widget,
5657 g_return_if_fail (GTK_IS_WIDGET (widget));
5659 if (visible != GTK_WIDGET_VISIBLE (widget))
5662 gtk_widget_show (widget);
5664 gtk_widget_hide (widget);
5669 * gtk_widget_get_visible:
5670 * @widget: a #GtkWidget
5672 * Determines whether the widget is visible. Note that this doesn't
5673 * take into account whether the widget's parent is also visible
5674 * or the widget is obscured in any way.
5676 * See gtk_widget_set_visible().
5678 * Return value: %TRUE if the widget is visible
5683 gtk_widget_get_visible (GtkWidget *widget)
5685 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5687 return (GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0;
5691 * gtk_widget_set_has_window:
5692 * @widget: a #GtkWidget
5693 * @has_window: whether or not @widget has a window.
5695 * Specifies whether @widget has a #GdkWindow of its own. Note that
5696 * all realized widgets have a non-%NULL "window" pointer
5697 * (gtk_widget_get_window() never returns a %NULL window when a widget
5698 * is realized), but for many of them it's actually the #GdkWindow of
5699 * one of its parent widgets. Widgets that create a %window for
5700 * themselves in GtkWidget::realize() however must announce this by
5701 * calling this function with @has_window = %TRUE.
5703 * This function should only be called by widget implementations,
5704 * and they should call it in their init() function.
5709 gtk_widget_set_has_window (GtkWidget *widget,
5710 gboolean has_window)
5712 g_return_if_fail (GTK_IS_WIDGET (widget));
5715 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_WINDOW);
5717 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_WINDOW);
5721 * gtk_widget_get_has_window:
5722 * @widget: a #GtkWidget
5724 * Determines whether @widget has a #GdkWindow of its own. See
5725 * gtk_widget_set_has_window().
5727 * Return value: %TRUE if @widget has a window, %FALSE otherwise
5732 gtk_widget_get_has_window (GtkWidget *widget)
5734 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5736 return !GTK_WIDGET_NO_WINDOW (widget);
5740 * gtk_widget_is_toplevel:
5741 * @widget: a #GtkWidget
5743 * Determines whether @widget is a toplevel widget. Currently only
5744 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
5745 * widgets have no parent widget.
5747 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
5752 gtk_widget_is_toplevel (GtkWidget *widget)
5754 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5756 return (GTK_WIDGET_FLAGS (widget) & GTK_TOPLEVEL) != 0;
5760 * gtk_widget_is_drawable:
5761 * @widget: a #GtkWidget
5763 * Determines whether @widget can be drawn to. A widget can be drawn
5764 * to if it is mapped and visible.
5766 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
5771 gtk_widget_is_drawable (GtkWidget *widget)
5773 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5775 return ((GTK_WIDGET_FLAGS (widget) & GTK_VISIBLE) != 0 &&
5776 (GTK_WIDGET_FLAGS (widget) & GTK_MAPPED) != 0);
5780 * gtk_widget_set_app_paintable:
5781 * @widget: a #GtkWidget
5782 * @app_paintable: %TRUE if the application will paint on the widget
5784 * Sets whether the application intends to draw on the widget in
5785 * an #GtkWidget::expose-event handler.
5787 * This is a hint to the widget and does not affect the behavior of
5788 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5789 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5790 * the effect is to suppress default themed drawing of the widget's
5791 * background. (Children of the widget will still be drawn.) The application
5792 * is then entirely responsible for drawing the widget background.
5794 * Note that the background is still drawn when the widget is mapped.
5795 * If this is not suitable (e.g. because you want to make a transparent
5796 * window using an RGBA visual), you can work around this by doing:
5798 * gtk_widget_realize (window);
5799 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5800 * gtk_widget_show (window);
5804 gtk_widget_set_app_paintable (GtkWidget *widget,
5805 gboolean app_paintable)
5807 g_return_if_fail (GTK_IS_WIDGET (widget));
5809 app_paintable = (app_paintable != FALSE);
5811 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5814 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5816 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5818 if (GTK_WIDGET_DRAWABLE (widget))
5819 gtk_widget_queue_draw (widget);
5821 g_object_notify (G_OBJECT (widget), "app-paintable");
5826 * gtk_widget_get_app_paintable:
5827 * @widget: a #GtkWidget
5829 * Determines whether the application intends to draw on the widget in
5830 * an #GtkWidget::expose-event handler.
5832 * See gtk_widget_set_app_paintable()
5834 * Return value: %TRUE if the widget is app paintable
5839 gtk_widget_get_app_paintable (GtkWidget *widget)
5841 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5843 return (GTK_WIDGET_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
5847 * gtk_widget_set_double_buffered:
5848 * @widget: a #GtkWidget
5849 * @double_buffered: %TRUE to double-buffer a widget
5851 * Widgets are double buffered by default; you can use this function
5852 * to turn off the buffering. "Double buffered" simply means that
5853 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5854 * automatically around expose events sent to the
5855 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5856 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5857 * buffer to the screen. The result is that users see the window
5858 * update in one smooth step, and don't see individual graphics
5859 * primitives being rendered.
5861 * In very simple terms, double buffered widgets don't flicker,
5862 * so you would only use this function to turn off double buffering
5863 * if you had special needs and really knew what you were doing.
5865 * Note: if you turn off double-buffering, you have to handle
5866 * expose events, since even the clearing to the background color or
5867 * pixmap will not happen automatically (as it is done in
5868 * gdk_window_begin_paint()).
5871 gtk_widget_set_double_buffered (GtkWidget *widget,
5872 gboolean double_buffered)
5874 g_return_if_fail (GTK_IS_WIDGET (widget));
5876 if (double_buffered != GTK_WIDGET_DOUBLE_BUFFERED (widget))
5878 if (double_buffered)
5879 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5881 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5883 g_object_notify (G_OBJECT (widget), "double-buffered");
5888 * gtk_widget_get_double_buffered:
5889 * @widget: a #GtkWidget
5891 * Determines whether the widget is double buffered.
5893 * See gtk_widget_set_double_buffered()
5895 * Return value: %TRUE if the widget is double buffered
5900 gtk_widget_get_double_buffered (GtkWidget *widget)
5902 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5904 return (GTK_WIDGET_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
5908 * gtk_widget_set_redraw_on_allocate:
5909 * @widget: a #GtkWidget
5910 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5911 * when it is allocated to a new size. Otherwise, only the
5912 * new portion of the widget will be redrawn.
5914 * Sets whether the entire widget is queued for drawing when its size
5915 * allocation changes. By default, this setting is %TRUE and
5916 * the entire widget is redrawn on every size change. If your widget
5917 * leaves the upper left unchanged when made bigger, turning this
5918 * setting off will improve performance.
5920 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5921 * off all allocation on resizing: the widget will not even redraw if
5922 * its position changes; this is to allow containers that don't draw
5923 * anything to avoid excess invalidations. If you set this flag on a
5924 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5925 * you are responsible for invalidating both the old and new allocation
5926 * of the widget when the widget is moved and responsible for invalidating
5927 * regions newly when the widget increases size.
5930 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5931 gboolean redraw_on_allocate)
5933 g_return_if_fail (GTK_IS_WIDGET (widget));
5935 if (redraw_on_allocate)
5936 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5938 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5942 * gtk_widget_set_sensitive:
5943 * @widget: a #GtkWidget
5944 * @sensitive: %TRUE to make the widget sensitive
5946 * Sets the sensitivity of a widget. A widget is sensitive if the user
5947 * can interact with it. Insensitive widgets are "grayed out" and the
5948 * user can't interact with them. Insensitive widgets are known as
5949 * "inactive", "disabled", or "ghosted" in some other toolkits.
5952 gtk_widget_set_sensitive (GtkWidget *widget,
5957 g_return_if_fail (GTK_IS_WIDGET (widget));
5959 sensitive = (sensitive != FALSE);
5961 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5966 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5967 data.state = GTK_WIDGET_SAVED_STATE (widget);
5971 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5972 data.state = GTK_WIDGET_STATE (widget);
5974 data.state_restoration = TRUE;
5975 data.use_forall = TRUE;
5978 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5980 data.parent_sensitive = TRUE;
5982 gtk_widget_propagate_state (widget, &data);
5983 if (GTK_WIDGET_DRAWABLE (widget))
5984 gtk_widget_queue_draw (widget);
5986 g_object_notify (G_OBJECT (widget), "sensitive");
5990 * gtk_widget_get_sensitive:
5991 * @widget: a #GtkWidget
5993 * Returns the widget's sensitivity (in the sense of returning
5994 * the value that has been set using gtk_widget_set_sensitive()).
5996 * The effective sensitivity of a widget is however determined by both its
5997 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
5999 * Returns: %TRUE if the widget is sensitive
6004 gtk_widget_get_sensitive (GtkWidget *widget)
6006 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6008 return GTK_WIDGET_SENSITIVE (widget);
6012 * gtk_widget_is_sensitive:
6013 * @widget: a #GtkWidget
6015 * Returns the widget's effective sensitivity, which means
6016 * it is sensitive itself and also its parent widget is sensntive
6018 * Returns: %TRUE if the widget is effectively sensitive
6023 gtk_widget_is_sensitive (GtkWidget *widget)
6025 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6027 return GTK_WIDGET_IS_SENSITIVE (widget);
6031 * gtk_widget_set_parent:
6032 * @widget: a #GtkWidget
6033 * @parent: parent container
6035 * This function is useful only when implementing subclasses of
6037 * Sets the container as the parent of @widget, and takes care of
6038 * some details such as updating the state and style of the child
6039 * to reflect its new location. The opposite function is
6040 * gtk_widget_unparent().
6043 gtk_widget_set_parent (GtkWidget *widget,
6048 g_return_if_fail (GTK_IS_WIDGET (widget));
6049 g_return_if_fail (GTK_IS_WIDGET (parent));
6050 g_return_if_fail (widget != parent);
6051 if (widget->parent != NULL)
6053 g_warning ("Can't set a parent on widget which has a parent\n");
6056 if (GTK_WIDGET_TOPLEVEL (widget))
6058 g_warning ("Can't set a parent on a toplevel widget\n");
6062 /* keep this function in sync with gtk_menu_attach_to_widget()
6065 g_object_ref_sink (widget);
6066 widget->parent = parent;
6068 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
6069 data.state = GTK_WIDGET_STATE (parent);
6071 data.state = GTK_WIDGET_STATE (widget);
6072 data.state_restoration = FALSE;
6073 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
6074 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
6076 gtk_widget_propagate_state (widget, &data);
6078 gtk_widget_reset_rc_styles (widget);
6080 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6081 if (GTK_WIDGET_ANCHORED (widget->parent))
6082 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6083 g_object_notify (G_OBJECT (widget), "parent");
6085 /* Enforce realized/mapped invariants
6087 if (GTK_WIDGET_REALIZED (widget->parent))
6088 gtk_widget_realize (widget);
6090 if (GTK_WIDGET_VISIBLE (widget->parent) &&
6091 GTK_WIDGET_VISIBLE (widget))
6093 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6094 GTK_WIDGET_MAPPED (widget->parent))
6095 gtk_widget_map (widget);
6097 gtk_widget_queue_resize (widget);
6102 * gtk_widget_get_parent:
6103 * @widget: a #GtkWidget
6105 * Returns the parent container of @widget.
6107 * Return value: the parent container of @widget, or %NULL
6110 gtk_widget_get_parent (GtkWidget *widget)
6112 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6114 return widget->parent;
6117 /*****************************************
6119 * see docs/styles.txt
6120 *****************************************/
6123 * gtk_widget_set_style:
6124 * @widget: a #GtkWidget
6125 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
6126 * gtk_widget_set_style() and go back to the default style
6128 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
6129 * want to use this function; it interacts badly with themes, because
6130 * themes work by replacing the #GtkStyle. Instead, use
6131 * gtk_widget_modify_style().
6134 gtk_widget_set_style (GtkWidget *widget,
6137 g_return_if_fail (GTK_IS_WIDGET (widget));
6141 gboolean initial_emission;
6143 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6145 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
6146 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
6148 gtk_widget_set_style_internal (widget, style, initial_emission);
6152 if (GTK_WIDGET_USER_STYLE (widget))
6153 gtk_widget_reset_rc_style (widget);
6158 * gtk_widget_ensure_style:
6159 * @widget: a #GtkWidget
6161 * Ensures that @widget has a style (@widget->style). Not a very useful
6162 * function; most of the time, if you want the style, the widget is
6163 * realized, and realized widgets are guaranteed to have a style
6167 gtk_widget_ensure_style (GtkWidget *widget)
6169 g_return_if_fail (GTK_IS_WIDGET (widget));
6171 if (!GTK_WIDGET_USER_STYLE (widget) &&
6172 !GTK_WIDGET_RC_STYLE (widget))
6173 gtk_widget_reset_rc_style (widget);
6176 /* Look up the RC style for this widget, unsetting any user style that
6177 * may be in effect currently
6180 gtk_widget_reset_rc_style (GtkWidget *widget)
6182 GtkStyle *new_style = NULL;
6183 gboolean initial_emission;
6185 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
6187 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
6188 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
6190 if (gtk_widget_has_screen (widget))
6191 new_style = gtk_rc_get_style (widget);
6193 new_style = gtk_widget_get_default_style ();
6195 if (initial_emission || new_style != widget->style)
6196 gtk_widget_set_style_internal (widget, new_style, initial_emission);
6200 * gtk_widget_get_style:
6201 * @widget: a #GtkWidget
6203 * Simply an accessor function that returns @widget->style.
6205 * Return value: the widget's #GtkStyle
6208 gtk_widget_get_style (GtkWidget *widget)
6210 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6212 return widget->style;
6216 * gtk_widget_modify_style:
6217 * @widget: a #GtkWidget
6218 * @style: the #GtkRcStyle holding the style modifications
6220 * Modifies style values on the widget. Modifications made using this
6221 * technique take precedence over style values set via an RC file,
6222 * however, they will be overriden if a style is explicitely set on
6223 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
6224 * is designed so each field can either be set or unset, so it is
6225 * possible, using this function, to modify some style values and
6226 * leave the others unchanged.
6228 * Note that modifications made with this function are not cumulative
6229 * with previous calls to gtk_widget_modify_style() or with such
6230 * functions as gtk_widget_modify_fg(). If you wish to retain
6231 * previous values, you must first call gtk_widget_get_modifier_style(),
6232 * make your modifications to the returned style, then call
6233 * gtk_widget_modify_style() with that style. On the other hand,
6234 * if you first call gtk_widget_modify_style(), subsequent calls
6235 * to such functions gtk_widget_modify_fg() will have a cumulative
6236 * effect with the initial modifications.
6239 gtk_widget_modify_style (GtkWidget *widget,
6242 g_return_if_fail (GTK_IS_WIDGET (widget));
6243 g_return_if_fail (GTK_IS_RC_STYLE (style));
6245 g_object_set_qdata_full (G_OBJECT (widget),
6247 gtk_rc_style_copy (style),
6248 (GDestroyNotify) g_object_unref);
6250 /* note that "style" may be invalid here if it was the old
6251 * modifier style and the only reference was our own.
6254 if (GTK_WIDGET_RC_STYLE (widget))
6255 gtk_widget_reset_rc_style (widget);
6259 * gtk_widget_get_modifier_style:
6260 * @widget: a #GtkWidget
6262 * Returns the current modifier style for the widget. (As set by
6263 * gtk_widget_modify_style().) If no style has previously set, a new
6264 * #GtkRcStyle will be created with all values unset, and set as the
6265 * modifier style for the widget. If you make changes to this rc
6266 * style, you must call gtk_widget_modify_style(), passing in the
6267 * returned rc style, to make sure that your changes take effect.
6269 * Caution: passing the style back to gtk_widget_modify_style() will
6270 * normally end up destroying it, because gtk_widget_modify_style() copies
6271 * the passed-in style and sets the copy as the new modifier style,
6272 * thus dropping any reference to the old modifier style. Add a reference
6273 * to the modifier style if you want to keep it alive.
6275 * Return value: the modifier style for the widget. This rc style is
6276 * owned by the widget. If you want to keep a pointer to value this
6277 * around, you must add a refcount using g_object_ref().
6280 gtk_widget_get_modifier_style (GtkWidget *widget)
6282 GtkRcStyle *rc_style;
6284 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6286 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
6290 rc_style = gtk_rc_style_new ();
6291 g_object_set_qdata_full (G_OBJECT (widget),
6294 (GDestroyNotify) g_object_unref);
6301 gtk_widget_modify_color_component (GtkWidget *widget,
6302 GtkRcFlags component,
6304 const GdkColor *color)
6306 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
6313 rc_style->fg[state] = *color;
6316 rc_style->bg[state] = *color;
6319 rc_style->text[state] = *color;
6322 rc_style->base[state] = *color;
6325 g_assert_not_reached();
6328 rc_style->color_flags[state] |= component;
6331 rc_style->color_flags[state] &= ~component;
6333 gtk_widget_modify_style (widget, rc_style);
6337 * gtk_widget_modify_fg:
6338 * @widget: a #GtkWidget
6339 * @state: the state for which to set the foreground color
6340 * @color: the color to assign (does not need to be allocated),
6341 * or %NULL to undo the effect of previous calls to
6342 * of gtk_widget_modify_fg().
6344 * Sets the foreground color for a widget in a particular state.
6345 * All other style values are left untouched. See also
6346 * gtk_widget_modify_style().
6349 gtk_widget_modify_fg (GtkWidget *widget,
6351 const GdkColor *color)
6353 g_return_if_fail (GTK_IS_WIDGET (widget));
6354 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6356 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
6360 * gtk_widget_modify_bg:
6361 * @widget: a #GtkWidget
6362 * @state: the state for which to set the background color
6363 * @color: the color to assign (does not need to be allocated),
6364 * or %NULL to undo the effect of previous calls to
6365 * of gtk_widget_modify_bg().
6367 * Sets the background color for a widget in a particular state.
6368 * All other style values are left untouched. See also
6369 * gtk_widget_modify_style().
6371 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6372 * draw on their parent container's window and thus may not draw any
6373 * background themselves. This is the case for e.g. #GtkLabel. To modify
6374 * the background of such widgets, you have to set the background color
6375 * on their parent; if you want to set the background of a rectangular
6376 * area around a label, try placing the label in a #GtkEventBox widget
6377 * and setting the background color on that.
6380 gtk_widget_modify_bg (GtkWidget *widget,
6382 const GdkColor *color)
6384 g_return_if_fail (GTK_IS_WIDGET (widget));
6385 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6387 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
6391 * gtk_widget_modify_text:
6392 * @widget: a #GtkWidget
6393 * @state: the state for which to set the text color
6394 * @color: the color to assign (does not need to be allocated),
6395 * or %NULL to undo the effect of previous calls to
6396 * of gtk_widget_modify_text().
6398 * Sets the text color for a widget in a particular state. All other
6399 * style values are left untouched. The text color is the foreground
6400 * color used along with the base color (see gtk_widget_modify_base())
6401 * for widgets such as #GtkEntry and #GtkTextView. See also
6402 * gtk_widget_modify_style().
6405 gtk_widget_modify_text (GtkWidget *widget,
6407 const GdkColor *color)
6409 g_return_if_fail (GTK_IS_WIDGET (widget));
6410 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6412 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
6416 * gtk_widget_modify_base:
6417 * @widget: a #GtkWidget
6418 * @state: the state for which to set the base color
6419 * @color: the color to assign (does not need to be allocated),
6420 * or %NULL to undo the effect of previous calls to
6421 * of gtk_widget_modify_base().
6423 * Sets the base color for a widget in a particular state.
6424 * All other style values are left untouched. The base color
6425 * is the background color used along with the text color
6426 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
6427 * and #GtkTextView. See also gtk_widget_modify_style().
6429 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
6430 * draw on their parent container's window and thus may not draw any
6431 * background themselves. This is the case for e.g. #GtkLabel. To modify
6432 * the background of such widgets, you have to set the base color on their
6433 * parent; if you want to set the background of a rectangular area around
6434 * a label, try placing the label in a #GtkEventBox widget and setting
6435 * the base color on that.
6438 gtk_widget_modify_base (GtkWidget *widget,
6440 const GdkColor *color)
6442 g_return_if_fail (GTK_IS_WIDGET (widget));
6443 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
6445 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
6449 modify_color_property (GtkWidget *widget,
6450 GtkRcStyle *rc_style,
6452 const GdkColor *color)
6454 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
6455 GQuark property_name = g_quark_from_string (name);
6459 GtkRcProperty rc_property = {0};
6462 rc_property.type_name = type_name;
6463 rc_property.property_name = property_name;
6464 rc_property.origin = NULL;
6466 color_name = gdk_color_to_string (color);
6467 g_value_init (&rc_property.value, G_TYPE_STRING);
6468 g_value_take_string (&rc_property.value, color_name);
6470 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6472 g_value_unset (&rc_property.value);
6475 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6479 * gtk_widget_modify_cursor:
6480 * @widget: a #GtkWidget
6481 * @primary: the color to use for primary cursor (does not need to be
6482 * allocated), or %NULL to undo the effect of previous calls to
6483 * of gtk_widget_modify_cursor().
6484 * @secondary: the color to use for secondary cursor (does not need to be
6485 * allocated), or %NULL to undo the effect of previous calls to
6486 * of gtk_widget_modify_cursor().
6488 * Sets the cursor color to use in a widget, overriding the
6489 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6490 * style properties. All other style values are left untouched.
6491 * See also gtk_widget_modify_style().
6496 gtk_widget_modify_cursor (GtkWidget *widget,
6497 const GdkColor *primary,
6498 const GdkColor *secondary)
6500 GtkRcStyle *rc_style;
6502 g_return_if_fail (GTK_IS_WIDGET (widget));
6504 rc_style = gtk_widget_get_modifier_style (widget);
6506 modify_color_property (widget, rc_style, "cursor-color", primary);
6507 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6509 gtk_widget_modify_style (widget, rc_style);
6513 * gtk_widget_modify_font:
6514 * @widget: a #GtkWidget
6515 * @font_desc: the font description to use, or %NULL to undo
6516 * the effect of previous calls to gtk_widget_modify_font().
6518 * Sets the font to use for a widget. All other style values are left
6519 * untouched. See also gtk_widget_modify_style().
6522 gtk_widget_modify_font (GtkWidget *widget,
6523 PangoFontDescription *font_desc)
6525 GtkRcStyle *rc_style;
6527 g_return_if_fail (GTK_IS_WIDGET (widget));
6529 rc_style = gtk_widget_get_modifier_style (widget);
6531 if (rc_style->font_desc)
6532 pango_font_description_free (rc_style->font_desc);
6535 rc_style->font_desc = pango_font_description_copy (font_desc);
6537 rc_style->font_desc = NULL;
6539 gtk_widget_modify_style (widget, rc_style);
6543 gtk_widget_real_direction_changed (GtkWidget *widget,
6544 GtkTextDirection previous_direction)
6546 gtk_widget_queue_resize (widget);
6550 gtk_widget_real_style_set (GtkWidget *widget,
6551 GtkStyle *previous_style)
6553 if (GTK_WIDGET_REALIZED (widget) &&
6554 !GTK_WIDGET_NO_WINDOW (widget))
6555 gtk_style_set_background (widget->style, widget->window, widget->state);
6559 gtk_widget_set_style_internal (GtkWidget *widget,
6561 gboolean initial_emission)
6563 g_object_ref (widget);
6564 g_object_freeze_notify (G_OBJECT (widget));
6566 if (widget->style != style)
6568 GtkStyle *previous_style;
6570 if (GTK_WIDGET_REALIZED (widget))
6572 gtk_widget_reset_shapes (widget);
6573 gtk_style_detach (widget->style);
6576 previous_style = widget->style;
6577 widget->style = style;
6578 g_object_ref (widget->style);
6580 if (GTK_WIDGET_REALIZED (widget))
6581 widget->style = gtk_style_attach (widget->style, widget->window);
6583 gtk_widget_update_pango_context (widget);
6584 g_signal_emit (widget,
6585 widget_signals[STYLE_SET],
6587 initial_emission ? NULL : previous_style);
6588 g_object_unref (previous_style);
6590 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6591 gtk_widget_queue_resize (widget);
6593 else if (initial_emission)
6595 gtk_widget_update_pango_context (widget);
6596 g_signal_emit (widget,
6597 widget_signals[STYLE_SET],
6601 g_object_notify (G_OBJECT (widget), "style");
6602 g_object_thaw_notify (G_OBJECT (widget));
6603 g_object_unref (widget);
6607 GtkWidget *previous_toplevel;
6608 GdkScreen *previous_screen;
6609 GdkScreen *new_screen;
6610 } HierarchyChangedInfo;
6613 do_screen_change (GtkWidget *widget,
6614 GdkScreen *old_screen,
6615 GdkScreen *new_screen)
6617 if (old_screen != new_screen)
6621 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6623 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6626 _gtk_tooltip_hide (widget);
6627 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6632 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6633 gpointer client_data)
6635 HierarchyChangedInfo *info = client_data;
6636 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6637 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6639 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6641 g_object_ref (widget);
6644 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6646 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6648 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6649 do_screen_change (widget, info->previous_screen, info->new_screen);
6651 if (GTK_IS_CONTAINER (widget))
6652 gtk_container_forall (GTK_CONTAINER (widget),
6653 gtk_widget_propagate_hierarchy_changed_recurse,
6656 g_object_unref (widget);
6661 * _gtk_widget_propagate_hierarchy_changed:
6662 * @widget: a #GtkWidget
6663 * @previous_toplevel: Previous toplevel
6665 * Propagates changes in the anchored state to a widget and all
6666 * children, unsetting or setting the %ANCHORED flag, and
6667 * emitting #GtkWidget::hierarchy-changed.
6670 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6671 GtkWidget *previous_toplevel)
6673 HierarchyChangedInfo info;
6675 info.previous_toplevel = previous_toplevel;
6676 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6678 if (GTK_WIDGET_TOPLEVEL (widget) ||
6679 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6680 info.new_screen = gtk_widget_get_screen (widget);
6682 info.new_screen = NULL;
6684 if (info.previous_screen)
6685 g_object_ref (info.previous_screen);
6686 if (previous_toplevel)
6687 g_object_ref (previous_toplevel);
6689 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6691 if (previous_toplevel)
6692 g_object_unref (previous_toplevel);
6693 if (info.previous_screen)
6694 g_object_unref (info.previous_screen);
6698 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6699 gpointer client_data)
6701 HierarchyChangedInfo *info = client_data;
6703 g_object_ref (widget);
6705 do_screen_change (widget, info->previous_screen, info->new_screen);
6707 if (GTK_IS_CONTAINER (widget))
6708 gtk_container_forall (GTK_CONTAINER (widget),
6709 gtk_widget_propagate_screen_changed_recurse,
6712 g_object_unref (widget);
6716 * gtk_widget_is_composited:
6717 * @widget: a #GtkWidget
6719 * Whether @widget can rely on having its alpha channel
6720 * drawn correctly. On X11 this function returns whether a
6721 * compositing manager is running for @widget's screen.
6723 * Please note that the semantics of this call will change
6724 * in the future if used on a widget that has a composited
6725 * window in its hierarchy (as set by gdk_window_set_composited()).
6727 * Return value: %TRUE if the widget can rely on its alpha
6728 * channel being drawn correctly.
6733 gtk_widget_is_composited (GtkWidget *widget)
6737 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6739 screen = gtk_widget_get_screen (widget);
6741 return gdk_screen_is_composited (screen);
6745 propagate_composited_changed (GtkWidget *widget,
6748 if (GTK_IS_CONTAINER (widget))
6750 gtk_container_forall (GTK_CONTAINER (widget),
6751 propagate_composited_changed,
6755 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6759 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6761 propagate_composited_changed (widget, NULL);
6765 * _gtk_widget_propagate_screen_changed:
6766 * @widget: a #GtkWidget
6767 * @previous_screen: Previous screen
6769 * Propagates changes in the screen for a widget to all
6770 * children, emitting #GtkWidget::screen-changed.
6773 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6774 GdkScreen *previous_screen)
6776 HierarchyChangedInfo info;
6778 info.previous_screen = previous_screen;
6779 info.new_screen = gtk_widget_get_screen (widget);
6781 if (previous_screen)
6782 g_object_ref (previous_screen);
6784 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6786 if (previous_screen)
6787 g_object_unref (previous_screen);
6791 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6793 if (GTK_WIDGET_RC_STYLE (widget))
6794 gtk_widget_reset_rc_style (widget);
6796 if (GTK_IS_CONTAINER (widget))
6797 gtk_container_forall (GTK_CONTAINER (widget),
6798 reset_rc_styles_recurse,
6803 gtk_widget_reset_rc_styles (GtkWidget *widget)
6805 g_return_if_fail (GTK_IS_WIDGET (widget));
6807 reset_rc_styles_recurse (widget, NULL);
6811 * gtk_widget_get_default_style:
6813 * Returns the default style used by all widgets initially.
6815 * Returns: the default style. This #GtkStyle object is owned
6816 * by GTK+ and should not be modified or freed.
6819 gtk_widget_get_default_style (void)
6821 if (!gtk_default_style)
6823 gtk_default_style = gtk_style_new ();
6824 g_object_ref (gtk_default_style);
6827 return gtk_default_style;
6830 static PangoContext *
6831 gtk_widget_peek_pango_context (GtkWidget *widget)
6833 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6837 * gtk_widget_get_pango_context:
6838 * @widget: a #GtkWidget
6840 * Gets a #PangoContext with the appropriate font map, font description,
6841 * and base direction for this widget. Unlike the context returned
6842 * by gtk_widget_create_pango_context(), this context is owned by
6843 * the widget (it can be used until the screen for the widget changes
6844 * or the widget is removed from its toplevel), and will be updated to
6845 * match any changes to the widget's attributes.
6847 * If you create and keep a #PangoLayout using this context, you must
6848 * deal with changes to the context by calling pango_layout_context_changed()
6849 * on the layout in response to the #GtkWidget::style-set and
6850 * #GtkWidget::direction-changed signals for the widget.
6852 * Return value: the #PangoContext for the widget.
6855 gtk_widget_get_pango_context (GtkWidget *widget)
6857 PangoContext *context;
6859 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6861 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6864 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6865 g_object_set_qdata_full (G_OBJECT (widget),
6866 quark_pango_context,
6875 update_pango_context (GtkWidget *widget,
6876 PangoContext *context)
6878 pango_context_set_font_description (context, widget->style->font_desc);
6879 pango_context_set_base_dir (context,
6880 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6881 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6885 gtk_widget_update_pango_context (GtkWidget *widget)
6887 PangoContext *context = gtk_widget_peek_pango_context (widget);
6893 update_pango_context (widget, context);
6895 screen = gtk_widget_get_screen_unchecked (widget);
6898 pango_cairo_context_set_resolution (context,
6899 gdk_screen_get_resolution (screen));
6900 pango_cairo_context_set_font_options (context,
6901 gdk_screen_get_font_options (screen));
6907 * gtk_widget_create_pango_context:
6908 * @widget: a #GtkWidget
6910 * Creates a new #PangoContext with the appropriate font map,
6911 * font description, and base direction for drawing text for
6912 * this widget. See also gtk_widget_get_pango_context().
6914 * Return value: the new #PangoContext
6917 gtk_widget_create_pango_context (GtkWidget *widget)
6920 PangoContext *context;
6922 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6924 screen = gtk_widget_get_screen_unchecked (widget);
6927 GTK_NOTE (MULTIHEAD,
6928 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6930 screen = gdk_screen_get_default ();
6933 context = gdk_pango_context_get_for_screen (screen);
6935 update_pango_context (widget, context);
6936 pango_context_set_language (context, gtk_get_default_language ());
6942 * gtk_widget_create_pango_layout:
6943 * @widget: a #GtkWidget
6944 * @text: text to set on the layout (can be %NULL)
6946 * Creates a new #PangoLayout with the appropriate font map,
6947 * font description, and base direction for drawing text for
6950 * If you keep a #PangoLayout created in this way around, in order to
6951 * notify the layout of changes to the base direction or font of this
6952 * widget, you must call pango_layout_context_changed() in response to
6953 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6956 * Return value: the new #PangoLayout
6959 gtk_widget_create_pango_layout (GtkWidget *widget,
6962 PangoLayout *layout;
6963 PangoContext *context;
6965 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6967 context = gtk_widget_get_pango_context (widget);
6968 layout = pango_layout_new (context);
6971 pango_layout_set_text (layout, text, -1);
6977 * gtk_widget_render_icon:
6978 * @widget: a #GtkWidget
6979 * @stock_id: a stock ID
6980 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6981 * the size of the source and don't scale (if there are multiple
6982 * source sizes, GTK+ picks one of the available sizes).
6983 * @detail: render detail to pass to theme engine
6985 * A convenience function that uses the theme engine and RC file
6986 * settings for @widget to look up @stock_id and render it to
6987 * a pixbuf. @stock_id should be a stock icon ID such as
6988 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6989 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6990 * identifies the widget or code doing the rendering, so that
6991 * theme engines can special-case rendering for that widget or code.
6993 * The pixels in the returned #GdkPixbuf are shared with the rest of
6994 * the application and should not be modified. The pixbuf should be freed
6995 * after use with g_object_unref().
6997 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
7000 gtk_widget_render_icon (GtkWidget *widget,
7001 const gchar *stock_id,
7003 const gchar *detail)
7005 GtkIconSet *icon_set;
7008 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7009 g_return_val_if_fail (stock_id != NULL, NULL);
7010 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7012 gtk_widget_ensure_style (widget);
7014 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
7016 if (icon_set == NULL)
7019 retval = gtk_icon_set_render_icon (icon_set,
7021 gtk_widget_get_direction (widget),
7022 GTK_WIDGET_STATE (widget),
7031 * gtk_widget_set_parent_window:
7032 * @widget: a #GtkWidget.
7033 * @parent_window: the new parent window.
7035 * Sets a non default parent window for @widget.
7038 gtk_widget_set_parent_window (GtkWidget *widget,
7039 GdkWindow *parent_window)
7041 GdkWindow *old_parent_window;
7043 g_return_if_fail (GTK_IS_WIDGET (widget));
7045 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
7046 quark_parent_window);
7048 if (parent_window != old_parent_window)
7050 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
7052 if (old_parent_window)
7053 g_object_unref (old_parent_window);
7055 g_object_ref (parent_window);
7060 * gtk_widget_get_parent_window:
7061 * @widget: a #GtkWidget.
7062 * @returns: the parent window of @widget.
7064 * Gets @widget's parent window.
7067 gtk_widget_get_parent_window (GtkWidget *widget)
7069 GdkWindow *parent_window;
7071 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7073 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
7075 return (parent_window != NULL) ? parent_window :
7076 (widget->parent != NULL) ? widget->parent->window : NULL;
7081 * gtk_widget_set_child_visible:
7082 * @widget: a #GtkWidget
7083 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
7085 * Sets whether @widget should be mapped along with its when its parent
7086 * is mapped and @widget has been shown with gtk_widget_show().
7088 * The child visibility can be set for widget before it is added to
7089 * a container with gtk_widget_set_parent(), to avoid mapping
7090 * children unnecessary before immediately unmapping them. However
7091 * it will be reset to its default state of %TRUE when the widget
7092 * is removed from a container.
7094 * Note that changing the child visibility of a widget does not
7095 * queue a resize on the widget. Most of the time, the size of
7096 * a widget is computed from all visible children, whether or
7097 * not they are mapped. If this is not the case, the container
7098 * can queue a resize itself.
7100 * This function is only useful for container implementations and
7101 * never should be called by an application.
7104 gtk_widget_set_child_visible (GtkWidget *widget,
7105 gboolean is_visible)
7107 g_return_if_fail (GTK_IS_WIDGET (widget));
7108 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
7110 g_object_ref (widget);
7113 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
7116 GtkWidget *toplevel;
7118 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
7120 toplevel = gtk_widget_get_toplevel (widget);
7121 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
7122 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
7125 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
7127 if (GTK_WIDGET_MAPPED (widget->parent) &&
7128 GTK_WIDGET_CHILD_VISIBLE (widget) &&
7129 GTK_WIDGET_VISIBLE (widget))
7130 gtk_widget_map (widget);
7132 gtk_widget_unmap (widget);
7135 g_object_unref (widget);
7139 * gtk_widget_get_child_visible:
7140 * @widget: a #GtkWidget
7142 * Gets the value set with gtk_widget_set_child_visible().
7143 * If you feel a need to use this function, your code probably
7144 * needs reorganization.
7146 * This function is only useful for container implementations and
7147 * never should be called by an application.
7149 * Return value: %TRUE if the widget is mapped with the parent.
7152 gtk_widget_get_child_visible (GtkWidget *widget)
7154 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7156 return GTK_WIDGET_CHILD_VISIBLE (widget);
7160 gtk_widget_get_screen_unchecked (GtkWidget *widget)
7162 GtkWidget *toplevel;
7164 toplevel = gtk_widget_get_toplevel (widget);
7166 if (GTK_WIDGET_TOPLEVEL (toplevel))
7168 if (GTK_IS_WINDOW (toplevel))
7169 return GTK_WINDOW (toplevel)->screen;
7170 else if (GTK_IS_INVISIBLE (toplevel))
7171 return GTK_INVISIBLE (widget)->screen;
7178 * gtk_widget_get_screen:
7179 * @widget: a #GtkWidget
7181 * Get the #GdkScreen from the toplevel window associated with
7182 * this widget. This function can only be called after the widget
7183 * has been added to a widget hierarchy with a #GtkWindow
7186 * In general, you should only create screen specific
7187 * resources when a widget has been realized, and you should
7188 * free those resources when the widget is unrealized.
7190 * Return value: the #GdkScreen for the toplevel for this widget.
7195 gtk_widget_get_screen (GtkWidget *widget)
7199 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7201 screen = gtk_widget_get_screen_unchecked (widget);
7208 g_warning (G_STRLOC ": Can't get associated screen"
7209 " for a widget unless it is inside a toplevel GtkWindow\n"
7210 " widget type is %s associated top level type is %s",
7211 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
7212 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
7214 return gdk_screen_get_default ();
7219 * gtk_widget_has_screen:
7220 * @widget: a #GtkWidget
7222 * Checks whether there is a #GdkScreen is associated with
7223 * this widget. All toplevel widgets have an associated
7224 * screen, and all widgets added into a hierarchy with a toplevel
7225 * window at the top.
7227 * Return value: %TRUE if there is a #GdkScreen associcated
7233 gtk_widget_has_screen (GtkWidget *widget)
7235 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7237 return (gtk_widget_get_screen_unchecked (widget) != NULL);
7241 * gtk_widget_get_display:
7242 * @widget: a #GtkWidget
7244 * Get the #GdkDisplay for the toplevel window associated with
7245 * this widget. This function can only be called after the widget
7246 * has been added to a widget hierarchy with a #GtkWindow at the top.
7248 * In general, you should only create display specific
7249 * resources when a widget has been realized, and you should
7250 * free those resources when the widget is unrealized.
7252 * Return value: the #GdkDisplay for the toplevel for this widget.
7257 gtk_widget_get_display (GtkWidget *widget)
7259 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7261 return gdk_screen_get_display (gtk_widget_get_screen (widget));
7265 * gtk_widget_get_root_window:
7266 * @widget: a #GtkWidget
7268 * Get the root window where this widget is located. This function can
7269 * only be called after the widget has been added to a widget
7270 * hierarchy with #GtkWindow at the top.
7272 * The root window is useful for such purposes as creating a popup
7273 * #GdkWindow associated with the window. In general, you should only
7274 * create display specific resources when a widget has been realized,
7275 * and you should free those resources when the widget is unrealized.
7277 * Return value: the #GdkWindow root window for the toplevel for this widget.
7282 gtk_widget_get_root_window (GtkWidget *widget)
7284 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7286 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
7290 * gtk_widget_child_focus:
7291 * @widget: a #GtkWidget
7292 * @direction: direction of focus movement
7294 * This function is used by custom widget implementations; if you're
7295 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
7296 * to a particular widget, and gtk_container_set_focus_chain() to
7297 * change the focus tab order. So you may want to investigate those
7298 * functions instead.
7300 * gtk_widget_child_focus() is called by containers as the user moves
7301 * around the window using keyboard shortcuts. @direction indicates
7302 * what kind of motion is taking place (up, down, left, right, tab
7303 * forward, tab backward). gtk_widget_child_focus() emits the
7304 * #GtkWidget::focus" signal; widgets override the default handler
7305 * for this signal in order to implement appropriate focus behavior.
7307 * The default ::focus handler for a widget should return %TRUE if
7308 * moving in @direction left the focus on a focusable location inside
7309 * that widget, and %FALSE if moving in @direction moved the focus
7310 * outside the widget. If returning %TRUE, widgets normally
7311 * call gtk_widget_grab_focus() to place the focus accordingly;
7312 * if returning %FALSE, they don't modify the current focus location.
7314 * This function replaces gtk_container_focus() from GTK+ 1.2.
7315 * It was necessary to check that the child was visible, sensitive,
7316 * and focusable before calling gtk_container_focus().
7317 * gtk_widget_child_focus() returns %FALSE if the widget is not
7318 * currently in a focusable state, so there's no need for those checks.
7320 * Return value: %TRUE if focus ended up inside @widget
7323 gtk_widget_child_focus (GtkWidget *widget,
7324 GtkDirectionType direction)
7326 gboolean return_val;
7328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7330 if (!GTK_WIDGET_VISIBLE (widget) ||
7331 !GTK_WIDGET_IS_SENSITIVE (widget))
7334 /* child widgets must set CAN_FOCUS, containers
7335 * don't have to though.
7337 if (!GTK_IS_CONTAINER (widget) &&
7338 !GTK_WIDGET_CAN_FOCUS (widget))
7341 g_signal_emit (widget,
7342 widget_signals[FOCUS],
7344 direction, &return_val);
7350 * gtk_widget_keynav_failed:
7351 * @widget: a #GtkWidget
7352 * @direction: direction of focus movement
7354 * This function should be called whenever keyboard navigation within
7355 * a single widget hits a boundary. The function emits the
7356 * #GtkWidget::keynav-failed signal on the widget and its return
7357 * value should be interpreted in a way similar to the return value of
7358 * gtk_widget_child_focus():
7360 * When %TRUE is returned, stay in the widget, the failed keyboard
7361 * navigation is Ok and/or there is nowhere we can/should move the
7364 * When %FALSE is returned, the caller should continue with keyboard
7365 * navigation outside the widget, e.g. by calling
7366 * gtk_widget_child_focus() on the widget's toplevel.
7368 * The default ::keynav-failed handler returns %TRUE for
7369 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
7370 * values of #GtkDirectionType, it looks at the
7371 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
7372 * if the setting is %TRUE. This way the entire user interface
7373 * becomes cursor-navigatable on input devices such as mobile phones
7374 * which only have cursor keys but no tab key.
7376 * Whenever the default handler returns %TRUE, it also calls
7377 * gtk_widget_error_bell() to notify the user of the failed keyboard
7380 * A use case for providing an own implementation of ::keynav-failed
7381 * (either by connecting to it or by overriding it) would be a row of
7382 * #GtkEntry widgets where the user should be able to navigate the
7383 * entire row with the cursor keys, as e.g. known from user interfaces
7384 * that require entering license keys.
7386 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
7387 * if the emitting widget should try to handle the keyboard
7388 * navigation attempt in its parent container(s).
7393 gtk_widget_keynav_failed (GtkWidget *widget,
7394 GtkDirectionType direction)
7396 gboolean return_val;
7398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7400 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
7401 direction, &return_val);
7407 * gtk_widget_error_bell:
7408 * @widget: a #GtkWidget
7410 * Notifies the user about an input-related error on this widget.
7411 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
7412 * gdk_window_beep(), otherwise it does nothing.
7414 * Note that the effect of gdk_window_beep() can be configured in many
7415 * ways, depending on the windowing backend and the desktop environment
7416 * or window manager that is used.
7421 gtk_widget_error_bell (GtkWidget *widget)
7423 GtkSettings* settings;
7426 g_return_if_fail (GTK_IS_WIDGET (widget));
7428 settings = gtk_widget_get_settings (widget);
7432 g_object_get (settings,
7433 "gtk-error-bell", &beep,
7436 if (beep && widget->window)
7437 gdk_window_beep (widget->window);
7441 * gtk_widget_set_uposition:
7442 * @widget: a #GtkWidget
7443 * @x: x position; -1 to unset x; -2 to leave x unchanged
7444 * @y: y position; -1 to unset y; -2 to leave y unchanged
7447 * Sets the position of a widget. The funny "u" in the name comes from
7448 * the "user position" hint specified by the X Window System, and
7449 * exists for legacy reasons. This function doesn't work if a widget
7450 * is inside a container; it's only really useful on #GtkWindow.
7452 * Don't use this function to center dialogs over the main application
7453 * window; most window managers will do the centering on your behalf
7454 * if you call gtk_window_set_transient_for(), and it's really not
7455 * possible to get the centering to work correctly in all cases from
7456 * application code. But if you insist, use gtk_window_set_position()
7457 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
7460 * Note that although @x and @y can be individually unset, the position
7461 * is not honoured unless both @x and @y are set.
7464 gtk_widget_set_uposition (GtkWidget *widget,
7468 /* FIXME this function is the only place that aux_info->x and
7469 * aux_info->y are even used I believe, and this function is
7470 * deprecated. Should be cleaned up.
7472 * (Actually, size_allocate uses them) -Yosh
7475 GtkWidgetAuxInfo *aux_info;
7477 g_return_if_fail (GTK_IS_WIDGET (widget));
7479 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7484 aux_info->x_set = FALSE;
7487 aux_info->x_set = TRUE;
7495 aux_info->y_set = FALSE;
7498 aux_info->y_set = TRUE;
7503 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7504 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7506 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7507 gtk_widget_size_allocate (widget, &widget->allocation);
7511 gtk_widget_set_usize_internal (GtkWidget *widget,
7515 GtkWidgetAuxInfo *aux_info;
7516 gboolean changed = FALSE;
7518 g_object_freeze_notify (G_OBJECT (widget));
7520 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7522 if (width > -2 && aux_info->width != width)
7524 g_object_notify (G_OBJECT (widget), "width-request");
7525 aux_info->width = width;
7528 if (height > -2 && aux_info->height != height)
7530 g_object_notify (G_OBJECT (widget), "height-request");
7531 aux_info->height = height;
7535 if (GTK_WIDGET_VISIBLE (widget) && changed)
7536 gtk_widget_queue_resize (widget);
7538 g_object_thaw_notify (G_OBJECT (widget));
7542 * gtk_widget_set_usize:
7543 * @widget: a #GtkWidget
7544 * @width: minimum width, or -1 to unset
7545 * @height: minimum height, or -1 to unset
7547 * Sets the minimum size of a widget; that is, the widget's size
7548 * request will be @width by @height. You can use this function to
7549 * force a widget to be either larger or smaller than it is. The
7550 * strange "usize" name dates from the early days of GTK+, and derives
7551 * from X Window System terminology. In many cases,
7552 * gtk_window_set_default_size() is a better choice for toplevel
7553 * windows than this function; setting the default size will still
7554 * allow users to shrink the window. Setting the usize will force them
7555 * to leave the window at least as large as the usize. When dealing
7556 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7559 * Note the inherent danger of setting any fixed size - themes,
7560 * translations into other languages, different fonts, and user action
7561 * can all change the appropriate size for a given widget. So, it's
7562 * basically impossible to hardcode a size that will always be
7565 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7568 gtk_widget_set_usize (GtkWidget *widget,
7572 g_return_if_fail (GTK_IS_WIDGET (widget));
7574 gtk_widget_set_usize_internal (widget, width, height);
7578 * gtk_widget_set_size_request:
7579 * @widget: a #GtkWidget
7580 * @width: width @widget should request, or -1 to unset
7581 * @height: height @widget should request, or -1 to unset
7583 * Sets the minimum size of a widget; that is, the widget's size
7584 * request will be @width by @height. You can use this function to
7585 * force a widget to be either larger or smaller than it normally
7588 * In most cases, gtk_window_set_default_size() is a better choice for
7589 * toplevel windows than this function; setting the default size will
7590 * still allow users to shrink the window. Setting the size request
7591 * will force them to leave the window at least as large as the size
7592 * request. When dealing with window sizes,
7593 * gtk_window_set_geometry_hints() can be a useful function as well.
7595 * Note the inherent danger of setting any fixed size - themes,
7596 * translations into other languages, different fonts, and user action
7597 * can all change the appropriate size for a given widget. So, it's
7598 * basically impossible to hardcode a size that will always be
7601 * The size request of a widget is the smallest size a widget can
7602 * accept while still functioning well and drawing itself correctly.
7603 * However in some strange cases a widget may be allocated less than
7604 * its requested size, and in many cases a widget may be allocated more
7605 * space than it requested.
7607 * If the size request in a given direction is -1 (unset), then
7608 * the "natural" size request of the widget will be used instead.
7610 * Widgets can't actually be allocated a size less than 1 by 1, but
7611 * you can pass 0,0 to this function to mean "as small as possible."
7614 gtk_widget_set_size_request (GtkWidget *widget,
7618 g_return_if_fail (GTK_IS_WIDGET (widget));
7619 g_return_if_fail (width >= -1);
7620 g_return_if_fail (height >= -1);
7627 gtk_widget_set_usize_internal (widget, width, height);
7632 * gtk_widget_get_size_request:
7633 * @widget: a #GtkWidget
7634 * @width: return location for width, or %NULL
7635 * @height: return location for height, or %NULL
7637 * Gets the size request that was explicitly set for the widget using
7638 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7639 * @height indicates that that dimension has not been set explicitly
7640 * and the natural requisition of the widget will be used intead. See
7641 * gtk_widget_set_size_request(). To get the size a widget will
7642 * actually use, call gtk_widget_size_request() instead of
7646 gtk_widget_get_size_request (GtkWidget *widget,
7650 GtkWidgetAuxInfo *aux_info;
7652 g_return_if_fail (GTK_IS_WIDGET (widget));
7654 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7657 *width = aux_info ? aux_info->width : -1;
7660 *height = aux_info ? aux_info->height : -1;
7664 * gtk_widget_set_events:
7665 * @widget: a #GtkWidget
7666 * @events: event mask
7668 * Sets the event mask (see #GdkEventMask) for a widget. The event
7669 * mask determines which events a widget will receive. Keep in mind
7670 * that different widgets have different default event masks, and by
7671 * changing the event mask you may disrupt a widget's functionality,
7672 * so be careful. This function must be called while a widget is
7673 * unrealized. Consider gtk_widget_add_events() for widgets that are
7674 * already realized, or if you want to preserve the existing event
7675 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7676 * to get events on those widgets, place them inside a #GtkEventBox
7677 * and receive events on the event box.
7680 gtk_widget_set_events (GtkWidget *widget,
7683 g_return_if_fail (GTK_IS_WIDGET (widget));
7684 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7686 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7687 GINT_TO_POINTER (events));
7688 g_object_notify (G_OBJECT (widget), "events");
7692 gtk_widget_add_events_internal (GtkWidget *widget,
7698 for (l = window_list; l != NULL; l = l->next)
7700 GdkWindow *window = l->data;
7703 gdk_window_get_user_data (window, &user_data);
7704 if (user_data == widget)
7708 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7710 children = gdk_window_get_children (window);
7711 gtk_widget_add_events_internal (widget, events, children);
7712 g_list_free (children);
7718 * gtk_widget_add_events:
7719 * @widget: a #GtkWidget
7720 * @events: an event mask, see #GdkEventMask
7722 * Adds the events in the bitfield @events to the event mask for
7723 * @widget. See gtk_widget_set_events() for details.
7726 gtk_widget_add_events (GtkWidget *widget,
7731 g_return_if_fail (GTK_IS_WIDGET (widget));
7733 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7734 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7735 GINT_TO_POINTER (old_events | events));
7737 if (GTK_WIDGET_REALIZED (widget))
7741 if (GTK_WIDGET_NO_WINDOW (widget))
7742 window_list = gdk_window_get_children (widget->window);
7744 window_list = g_list_prepend (NULL, widget->window);
7746 gtk_widget_add_events_internal (widget, events, window_list);
7748 g_list_free (window_list);
7751 g_object_notify (G_OBJECT (widget), "events");
7755 * gtk_widget_set_extension_events:
7756 * @widget: a #GtkWidget
7757 * @mode: bitfield of extension events to receive
7759 * Sets the extension events mask to @mode. See #GdkExtensionMode
7760 * and gdk_input_set_extension_events().
7763 gtk_widget_set_extension_events (GtkWidget *widget,
7764 GdkExtensionMode mode)
7766 g_return_if_fail (GTK_IS_WIDGET (widget));
7768 if (GTK_WIDGET_REALIZED (widget))
7769 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7771 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7772 GINT_TO_POINTER (mode));
7773 g_object_notify (G_OBJECT (widget), "extension-events");
7777 * gtk_widget_get_toplevel:
7778 * @widget: a #GtkWidget
7780 * This function returns the topmost widget in the container hierarchy
7781 * @widget is a part of. If @widget has no parent widgets, it will be
7782 * returned as the topmost widget. No reference will be added to the
7783 * returned widget; it should not be unreferenced.
7785 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7786 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7788 * %NULL if @widget wasn't inside a toplevel window, and if the
7789 * window was inside a #GtkWindow-derived widget which was in turn
7790 * inside the toplevel #GtkWindow. While the second case may
7791 * seem unlikely, it actually happens when a #GtkPlug is embedded
7792 * inside a #GtkSocket within the same application.
7794 * To reliably find the toplevel #GtkWindow, use
7795 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7796 * is set on the result.
7798 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7799 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7801 * /* Perform action on toplevel. */
7805 * Return value: the topmost ancestor of @widget, or @widget itself
7806 * if there's no ancestor.
7809 gtk_widget_get_toplevel (GtkWidget *widget)
7811 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7813 while (widget->parent)
7814 widget = widget->parent;
7820 * gtk_widget_get_ancestor:
7821 * @widget: a #GtkWidget
7822 * @widget_type: ancestor type
7824 * Gets the first ancestor of @widget with type @widget_type. For example,
7825 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7826 * the first #GtkBox that's an ancestor of @widget. No reference will be
7827 * added to the returned widget; it should not be unreferenced. See note
7828 * about checking for a toplevel #GtkWindow in the docs for
7829 * gtk_widget_get_toplevel().
7831 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7832 * considers @widget to be an ancestor of itself.
7834 * Return value: the ancestor widget, or %NULL if not found
7837 gtk_widget_get_ancestor (GtkWidget *widget,
7840 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7842 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7843 widget = widget->parent;
7845 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7852 * gtk_widget_get_colormap:
7853 * @widget: a #GtkWidget
7855 * Gets the colormap that will be used to render @widget. No reference will
7856 * be added to the returned colormap; it should not be unreferenced.
7858 * Return value: the colormap used by @widget
7861 gtk_widget_get_colormap (GtkWidget *widget)
7863 GdkColormap *colormap;
7864 GtkWidget *tmp_widget;
7866 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7870 colormap = gdk_drawable_get_colormap (widget->window);
7871 /* If window was destroyed previously, we'll get NULL here */
7876 tmp_widget = widget;
7879 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7883 tmp_widget= tmp_widget->parent;
7886 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7890 * gtk_widget_get_visual:
7891 * @widget: a #GtkWidget
7893 * Gets the visual that will be used to render @widget.
7895 * Return value: the visual for @widget
7898 gtk_widget_get_visual (GtkWidget *widget)
7900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7902 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7906 * gtk_widget_get_settings:
7907 * @widget: a #GtkWidget
7909 * Gets the settings object holding the settings (global property
7910 * settings, RC file information, etc) used for this widget.
7912 * Note that this function can only be called when the #GtkWidget
7913 * is attached to a toplevel, since the settings object is specific
7914 * to a particular #GdkScreen.
7916 * Return value: the relevant #GtkSettings object
7919 gtk_widget_get_settings (GtkWidget *widget)
7921 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7923 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7927 * gtk_widget_set_colormap:
7928 * @widget: a #GtkWidget
7929 * @colormap: a colormap
7931 * Sets the colormap for the widget to the given value. Widget must not
7932 * have been previously realized. This probably should only be used
7933 * from an <function>init()</function> function (i.e. from the constructor
7937 gtk_widget_set_colormap (GtkWidget *widget,
7938 GdkColormap *colormap)
7940 g_return_if_fail (GTK_IS_WIDGET (widget));
7941 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7942 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7944 g_object_ref (colormap);
7946 g_object_set_qdata_full (G_OBJECT (widget),
7953 * gtk_widget_get_events:
7954 * @widget: a #GtkWidget
7956 * Returns the event mask for the widget (a bitfield containing flags
7957 * from the #GdkEventMask enumeration). These are the events that the widget
7960 * Return value: event mask for @widget
7963 gtk_widget_get_events (GtkWidget *widget)
7965 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7967 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7971 * gtk_widget_get_extension_events:
7972 * @widget: a #GtkWidget
7974 * Retrieves the extension events the widget will receive; see
7975 * gdk_input_set_extension_events().
7977 * Return value: extension events for @widget
7980 gtk_widget_get_extension_events (GtkWidget *widget)
7982 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7984 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7988 * gtk_widget_get_pointer:
7989 * @widget: a #GtkWidget
7990 * @x: return location for the X coordinate, or %NULL
7991 * @y: return location for the Y coordinate, or %NULL
7993 * Obtains the location of the mouse pointer in widget coordinates.
7994 * Widget coordinates are a bit odd; for historical reasons, they are
7995 * defined as @widget->window coordinates for widgets that are not
7996 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7997 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8000 gtk_widget_get_pointer (GtkWidget *widget,
8004 g_return_if_fail (GTK_IS_WIDGET (widget));
8011 if (GTK_WIDGET_REALIZED (widget))
8013 gdk_window_get_pointer (widget->window, x, y, NULL);
8015 if (GTK_WIDGET_NO_WINDOW (widget))
8018 *x -= widget->allocation.x;
8020 *y -= widget->allocation.y;
8026 * gtk_widget_is_ancestor:
8027 * @widget: a #GtkWidget
8028 * @ancestor: another #GtkWidget
8030 * Determines whether @widget is somewhere inside @ancestor, possibly with
8031 * intermediate containers.
8033 * Return value: %TRUE if @ancestor contains @widget as a child,
8034 * grandchild, great grandchild, etc.
8037 gtk_widget_is_ancestor (GtkWidget *widget,
8038 GtkWidget *ancestor)
8040 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8041 g_return_val_if_fail (ancestor != NULL, FALSE);
8045 if (widget->parent == ancestor)
8047 widget = widget->parent;
8053 static GQuark quark_composite_name = 0;
8056 * gtk_widget_set_composite_name:
8057 * @widget: a #GtkWidget.
8058 * @name: the name to set
8060 * Sets a widgets composite name. The widget must be
8061 * a composite child of its parent; see gtk_widget_push_composite_child().
8064 gtk_widget_set_composite_name (GtkWidget *widget,
8067 g_return_if_fail (GTK_IS_WIDGET (widget));
8068 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
8069 g_return_if_fail (name != NULL);
8071 if (!quark_composite_name)
8072 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
8074 g_object_set_qdata_full (G_OBJECT (widget),
8075 quark_composite_name,
8081 * gtk_widget_get_composite_name:
8082 * @widget: a #GtkWidget
8084 * Obtains the composite name of a widget.
8086 * Returns: the composite name of @widget, or %NULL if @widget is not
8087 * a composite child. The string should be freed when it is no
8091 gtk_widget_get_composite_name (GtkWidget *widget)
8093 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8095 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
8096 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
8103 * gtk_widget_push_composite_child:
8105 * Makes all newly-created widgets as composite children until
8106 * the corresponding gtk_widget_pop_composite_child() call.
8108 * A composite child is a child that's an implementation detail of the
8109 * container it's inside and should not be visible to people using the
8110 * container. Composite children aren't treated differently by GTK (but
8111 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
8112 * builders might want to treat them in a different way.
8114 * Here is a simple example:
8116 * gtk_widget_push_composite_child ();
8117 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
8118 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
8119 * gtk_widget_pop_composite_child ();
8120 * gtk_widget_set_parent (scrolled_window->hscrollbar,
8121 * GTK_WIDGET (scrolled_window));
8122 * g_object_ref (scrolled_window->hscrollbar);
8126 gtk_widget_push_composite_child (void)
8128 composite_child_stack++;
8132 * gtk_widget_pop_composite_child:
8134 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
8137 gtk_widget_pop_composite_child (void)
8139 if (composite_child_stack)
8140 composite_child_stack--;
8144 * gtk_widget_push_colormap:
8145 * @cmap: a #GdkColormap
8147 * Pushes @cmap onto a global stack of colormaps; the topmost
8148 * colormap on the stack will be used to create all widgets.
8149 * Remove @cmap with gtk_widget_pop_colormap(). There's little
8150 * reason to use this function.
8153 gtk_widget_push_colormap (GdkColormap *cmap)
8155 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
8157 colormap_stack = g_slist_prepend (colormap_stack, cmap);
8161 * gtk_widget_pop_colormap:
8163 * Removes a colormap pushed with gtk_widget_push_colormap().
8166 gtk_widget_pop_colormap (void)
8169 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
8173 * gtk_widget_set_default_colormap:
8174 * @colormap: a #GdkColormap
8176 * Sets the default colormap to use when creating widgets.
8177 * gtk_widget_push_colormap() is a better function to use if
8178 * you only want to affect a few widgets, rather than all widgets.
8181 gtk_widget_set_default_colormap (GdkColormap *colormap)
8183 g_return_if_fail (GDK_IS_COLORMAP (colormap));
8185 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
8190 * gtk_widget_get_default_colormap:
8192 * Obtains the default colormap used to create widgets.
8194 * Return value: default widget colormap
8197 gtk_widget_get_default_colormap (void)
8199 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
8203 * gtk_widget_get_default_visual:
8205 * Obtains the visual of the default colormap. Not really useful;
8206 * used to be useful before gdk_colormap_get_visual() existed.
8208 * Return value: visual of the default colormap
8211 gtk_widget_get_default_visual (void)
8213 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
8217 gtk_widget_emit_direction_changed (GtkWidget *widget,
8218 GtkTextDirection old_dir)
8220 gtk_widget_update_pango_context (widget);
8222 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
8226 * gtk_widget_set_direction:
8227 * @widget: a #GtkWidget
8228 * @dir: the new direction
8230 * Sets the reading direction on a particular widget. This direction
8231 * controls the primary direction for widgets containing text,
8232 * and also the direction in which the children of a container are
8233 * packed. The ability to set the direction is present in order
8234 * so that correct localization into languages with right-to-left
8235 * reading directions can be done. Generally, applications will
8236 * let the default reading direction present, except for containers
8237 * where the containers are arranged in an order that is explicitely
8238 * visual rather than logical (such as buttons for text justification).
8240 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
8241 * set by gtk_widget_set_default_direction() will be used.
8244 gtk_widget_set_direction (GtkWidget *widget,
8245 GtkTextDirection dir)
8247 GtkTextDirection old_dir;
8249 g_return_if_fail (GTK_IS_WIDGET (widget));
8250 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
8252 old_dir = gtk_widget_get_direction (widget);
8254 if (dir == GTK_TEXT_DIR_NONE)
8255 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
8258 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
8259 if (dir == GTK_TEXT_DIR_LTR)
8260 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
8262 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
8265 if (old_dir != gtk_widget_get_direction (widget))
8266 gtk_widget_emit_direction_changed (widget, old_dir);
8270 * gtk_widget_get_direction:
8271 * @widget: a #GtkWidget
8273 * Gets the reading direction for a particular widget. See
8274 * gtk_widget_set_direction().
8276 * Return value: the reading direction for the widget.
8279 gtk_widget_get_direction (GtkWidget *widget)
8281 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
8283 if (GTK_WIDGET_DIRECTION_SET (widget))
8284 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
8286 return gtk_default_direction;
8290 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
8292 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
8294 g_object_ref (widget);
8296 if (!GTK_WIDGET_DIRECTION_SET (widget))
8297 gtk_widget_emit_direction_changed (widget, old_dir);
8299 if (GTK_IS_CONTAINER (widget))
8300 gtk_container_forall (GTK_CONTAINER (widget),
8301 gtk_widget_set_default_direction_recurse,
8304 g_object_unref (widget);
8308 * gtk_widget_set_default_direction:
8309 * @dir: the new default direction. This cannot be
8310 * %GTK_TEXT_DIR_NONE.
8312 * Sets the default reading direction for widgets where the
8313 * direction has not been explicitly set by gtk_widget_set_direction().
8316 gtk_widget_set_default_direction (GtkTextDirection dir)
8318 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
8320 if (dir != gtk_default_direction)
8322 GList *toplevels, *tmp_list;
8323 GtkTextDirection old_dir = gtk_default_direction;
8325 gtk_default_direction = dir;
8327 tmp_list = toplevels = gtk_window_list_toplevels ();
8328 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
8332 gtk_widget_set_default_direction_recurse (tmp_list->data,
8333 GUINT_TO_POINTER (old_dir));
8334 g_object_unref (tmp_list->data);
8335 tmp_list = tmp_list->next;
8338 g_list_free (toplevels);
8343 * gtk_widget_get_default_direction:
8345 * Obtains the current default reading direction. See
8346 * gtk_widget_set_default_direction().
8348 * Return value: the current default direction.
8351 gtk_widget_get_default_direction (void)
8353 return gtk_default_direction;
8357 gtk_widget_dispose (GObject *object)
8359 GtkWidget *widget = GTK_WIDGET (object);
8362 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
8363 else if (GTK_WIDGET_VISIBLE (widget))
8364 gtk_widget_hide (widget);
8366 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
8367 if (GTK_WIDGET_REALIZED (widget))
8368 gtk_widget_unrealize (widget);
8370 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
8374 gtk_widget_real_destroy (GtkObject *object)
8376 /* gtk_object_destroy() will already hold a refcount on object */
8377 GtkWidget *widget = GTK_WIDGET (object);
8379 /* wipe accelerator closures (keep order) */
8380 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
8381 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
8383 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
8384 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
8386 gtk_grab_remove (widget);
8388 g_object_unref (widget->style);
8389 widget->style = gtk_widget_get_default_style ();
8390 g_object_ref (widget->style);
8392 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
8396 gtk_widget_finalize (GObject *object)
8398 GtkWidget *widget = GTK_WIDGET (object);
8399 GtkWidgetAuxInfo *aux_info;
8400 GtkAccessible *accessible;
8402 gtk_grab_remove (widget);
8404 g_object_unref (widget->style);
8405 widget->style = NULL;
8407 g_free (widget->name);
8409 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
8411 gtk_widget_aux_info_destroy (aux_info);
8413 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
8415 g_object_unref (accessible);
8417 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
8420 /*****************************************
8421 * gtk_widget_real_map:
8426 *****************************************/
8429 gtk_widget_real_map (GtkWidget *widget)
8431 g_assert (GTK_WIDGET_REALIZED (widget));
8433 if (!GTK_WIDGET_MAPPED (widget))
8435 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
8437 if (!GTK_WIDGET_NO_WINDOW (widget))
8438 gdk_window_show (widget->window);
8442 /*****************************************
8443 * gtk_widget_real_unmap:
8448 *****************************************/
8451 gtk_widget_real_unmap (GtkWidget *widget)
8453 if (GTK_WIDGET_MAPPED (widget))
8455 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8457 if (!GTK_WIDGET_NO_WINDOW (widget))
8458 gdk_window_hide (widget->window);
8462 /*****************************************
8463 * gtk_widget_real_realize:
8468 *****************************************/
8471 gtk_widget_real_realize (GtkWidget *widget)
8473 g_assert (GTK_WIDGET_NO_WINDOW (widget));
8475 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8478 widget->window = gtk_widget_get_parent_window (widget);
8479 g_object_ref (widget->window);
8481 widget->style = gtk_style_attach (widget->style, widget->window);
8484 /*****************************************
8485 * gtk_widget_real_unrealize:
8490 *****************************************/
8493 gtk_widget_real_unrealize (GtkWidget *widget)
8495 if (GTK_WIDGET_MAPPED (widget))
8496 gtk_widget_real_unmap (widget);
8498 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8500 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8503 /* We must do unrealize child widget BEFORE container widget.
8504 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8505 * So, unrealizing container widget bofore its children causes the problem
8506 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8509 if (GTK_IS_CONTAINER (widget))
8510 gtk_container_forall (GTK_CONTAINER (widget),
8511 (GtkCallback) gtk_widget_unrealize,
8514 gtk_style_detach (widget->style);
8515 if (!GTK_WIDGET_NO_WINDOW (widget))
8517 gdk_window_set_user_data (widget->window, NULL);
8518 gdk_window_destroy (widget->window);
8519 widget->window = NULL;
8523 g_object_unref (widget->window);
8524 widget->window = NULL;
8527 gtk_selection_remove_all (widget);
8529 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8533 gtk_widget_real_size_request (GtkWidget *widget,
8534 GtkRequisition *requisition)
8536 requisition->width = widget->requisition.width;
8537 requisition->height = widget->requisition.height;
8541 * _gtk_widget_peek_colormap:
8543 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8545 * Return value: the currently pushed colormap, or %NULL if there is none.
8548 _gtk_widget_peek_colormap (void)
8551 return (GdkColormap*) colormap_stack->data;
8556 * _gtk_widget_set_pointer_window:
8557 * @widget: a #GtkWidget.
8558 * @pointer_window: the new pointer window.
8560 * Sets pointer window for @widget. Does not ref @pointer_window.
8561 * Actually stores it on the #GdkScreen, but you don't need to know that.
8564 _gtk_widget_set_pointer_window (GtkWidget *widget,
8565 GdkWindow *pointer_window)
8567 g_return_if_fail (GTK_IS_WIDGET (widget));
8569 if (GTK_WIDGET_REALIZED (widget))
8571 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8573 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8579 * _gtk_widget_get_pointer_window:
8580 * @widget: a #GtkWidget.
8582 * Return value: the pointer window set on the #GdkScreen @widget is attached
8586 _gtk_widget_get_pointer_window (GtkWidget *widget)
8588 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8590 if (GTK_WIDGET_REALIZED (widget))
8592 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8594 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8601 synth_crossing (GtkWidget *widget,
8604 GdkCrossingMode mode,
8605 GdkNotifyType detail)
8609 event = gdk_event_new (type);
8611 event->crossing.window = g_object_ref (window);
8612 event->crossing.send_event = TRUE;
8613 event->crossing.subwindow = g_object_ref (window);
8614 event->crossing.time = GDK_CURRENT_TIME;
8615 event->crossing.x = event->crossing.y = 0;
8616 event->crossing.x_root = event->crossing.y_root = 0;
8617 event->crossing.mode = mode;
8618 event->crossing.detail = detail;
8619 event->crossing.focus = FALSE;
8620 event->crossing.state = 0;
8623 widget = gtk_get_event_widget (event);
8626 gtk_widget_event_internal (widget, event);
8628 gdk_event_free (event);
8632 * _gtk_widget_is_pointer_widget:
8633 * @widget: a #GtkWidget
8635 * Returns %TRUE if the pointer window belongs to @widget.
8638 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8640 if (GTK_WIDGET_HAS_POINTER (widget))
8645 win = _gtk_widget_get_pointer_window (widget);
8648 gdk_window_get_user_data (win, (gpointer *)&wid);
8658 * _gtk_widget_synthesize_crossing:
8659 * @from: the #GtkWidget the virtual pointer is leaving.
8660 * @to: the #GtkWidget the virtual pointer is moving to.
8661 * @mode: the #GdkCrossingMode to place on the synthesized events.
8663 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8665 * The real pointer window is the window that most recently received an enter notify
8666 * event. Windows that don't select for crossing events can't become the real
8667 * poiner window. The real pointer widget that owns the real pointer window. The
8668 * effective pointer window is the same as the real pointer window unless the real
8669 * pointer widget is either insensitive or there is a grab on a widget that is not
8670 * an ancestor of the real pointer widget (in which case the effective pointer
8671 * window should be the root window).
8673 * When the effective pointer window is the same as the real poiner window, we
8674 * receive crossing events from the windowing system. When the effective pointer
8675 * window changes to become different from the real pointer window we synthesize
8676 * crossing events, attempting to follow X protocol rules:
8678 * When the root window becomes the effective pointer window:
8679 * - leave notify on real pointer window, detail Ancestor
8680 * - leave notify on all of its ancestors, detail Virtual
8681 * - enter notify on root window, detail Inferior
8683 * When the root window ceases to be the effective pointer window:
8684 * - leave notify on root window, detail Inferior
8685 * - enter notify on all ancestors of real pointer window, detail Virtual
8686 * - enter notify on real pointer window, detail Ancestor
8689 _gtk_widget_synthesize_crossing (GtkWidget *from,
8691 GdkCrossingMode mode)
8693 GdkWindow *from_window = NULL, *to_window = NULL;
8695 g_return_if_fail (from != NULL || to != NULL);
8698 from_window = GTK_WIDGET_HAS_POINTER (from)
8699 ? _gtk_widget_get_pointer_window (from) : from->window;
8701 to_window = GTK_WIDGET_HAS_POINTER (to)
8702 ? _gtk_widget_get_pointer_window (to) : to->window;
8704 if (from_window == NULL && to_window == NULL)
8706 else if (from_window != NULL && to_window == NULL)
8708 GList *from_ancestors = NULL, *list;
8709 GdkWindow *from_ancestor = from_window;
8711 while (from_ancestor != NULL)
8713 from_ancestor = gdk_window_get_parent (from_ancestor);
8714 if (from_ancestor == NULL)
8716 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8719 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8720 mode, GDK_NOTIFY_ANCESTOR);
8721 for (list = g_list_last (from_ancestors); list; list = list->prev)
8723 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8724 mode, GDK_NOTIFY_VIRTUAL);
8727 /* XXX: enter/inferior on root window? */
8729 g_list_free (from_ancestors);
8731 else if (from_window == NULL && to_window != NULL)
8733 GList *to_ancestors = NULL, *list;
8734 GdkWindow *to_ancestor = to_window;
8736 while (to_ancestor != NULL)
8738 to_ancestor = gdk_window_get_parent (to_ancestor);
8739 if (to_ancestor == NULL)
8741 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8744 /* XXX: leave/inferior on root window? */
8746 for (list = to_ancestors; list; list = list->next)
8748 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8749 mode, GDK_NOTIFY_VIRTUAL);
8751 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8752 mode, GDK_NOTIFY_ANCESTOR);
8754 g_list_free (to_ancestors);
8756 else if (from_window == to_window)
8760 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8761 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8763 while (from_ancestor != NULL || to_ancestor != NULL)
8765 if (from_ancestor != NULL)
8767 from_ancestor = gdk_window_get_parent (from_ancestor);
8768 if (from_ancestor == to_window)
8771 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8773 if (to_ancestor != NULL)
8775 to_ancestor = gdk_window_get_parent (to_ancestor);
8776 if (to_ancestor == from_window)
8779 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8782 if (to_ancestor == from_window)
8784 if (mode != GDK_CROSSING_GTK_UNGRAB)
8785 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8786 mode, GDK_NOTIFY_INFERIOR);
8787 for (list = to_ancestors; list; list = list->next)
8788 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8789 mode, GDK_NOTIFY_VIRTUAL);
8790 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8791 mode, GDK_NOTIFY_ANCESTOR);
8793 else if (from_ancestor == to_window)
8795 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8796 mode, GDK_NOTIFY_ANCESTOR);
8797 for (list = g_list_last (from_ancestors); list; list = list->prev)
8799 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8800 mode, GDK_NOTIFY_VIRTUAL);
8802 if (mode != GDK_CROSSING_GTK_GRAB)
8803 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8804 mode, GDK_NOTIFY_INFERIOR);
8808 while (from_ancestors != NULL && to_ancestors != NULL
8809 && from_ancestors->data == to_ancestors->data)
8811 from_ancestors = g_list_delete_link (from_ancestors,
8813 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8816 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8817 mode, GDK_NOTIFY_NONLINEAR);
8819 for (list = g_list_last (from_ancestors); list; list = list->prev)
8821 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8822 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8824 for (list = to_ancestors; list; list = list->next)
8826 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8827 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8829 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8830 mode, GDK_NOTIFY_NONLINEAR);
8832 g_list_free (from_ancestors);
8833 g_list_free (to_ancestors);
8838 gtk_widget_propagate_state (GtkWidget *widget,
8841 guint8 old_state = GTK_WIDGET_STATE (widget);
8842 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8844 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8845 * parent_sensitive==TRUE on a sensitive widget
8849 if (data->parent_sensitive)
8850 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8852 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8854 if (GTK_WIDGET_IS_SENSITIVE (widget))
8856 if (data->state_restoration)
8857 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8859 GTK_WIDGET_STATE (widget) = data->state;
8863 if (!data->state_restoration)
8865 if (data->state != GTK_STATE_INSENSITIVE)
8866 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8868 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8869 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8870 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8873 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8877 window = gtk_widget_get_toplevel (widget);
8878 if (window && GTK_WIDGET_TOPLEVEL (window))
8879 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8882 if (old_state != GTK_WIDGET_STATE (widget) ||
8883 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8885 g_object_ref (widget);
8887 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8888 gtk_grab_remove (widget);
8890 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8892 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
8894 if (!GTK_WIDGET_IS_SENSITIVE (widget))
8895 _gtk_widget_synthesize_crossing (widget, NULL,
8896 GDK_CROSSING_STATE_CHANGED);
8897 else if (old_state == GTK_STATE_INSENSITIVE)
8898 _gtk_widget_synthesize_crossing (NULL, widget,
8899 GDK_CROSSING_STATE_CHANGED);
8902 if (GTK_IS_CONTAINER (widget))
8904 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8905 if (data->use_forall)
8906 gtk_container_forall (GTK_CONTAINER (widget),
8907 (GtkCallback) gtk_widget_propagate_state,
8910 gtk_container_foreach (GTK_CONTAINER (widget),
8911 (GtkCallback) gtk_widget_propagate_state,
8914 g_object_unref (widget);
8919 * _gtk_widget_get_aux_info:
8920 * @widget: a #GtkWidget
8921 * @create: if %TRUE, create the structure if it doesn't exist
8923 * Get the #GtkWidgetAuxInfo structure for the widget.
8925 * Return value: the #GtkAuxInfo structure for the widget, or
8926 * %NULL if @create is %FALSE and one doesn't already exist.
8929 _gtk_widget_get_aux_info (GtkWidget *widget,
8932 GtkWidgetAuxInfo *aux_info;
8934 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8935 if (!aux_info && create)
8937 aux_info = g_slice_new (GtkWidgetAuxInfo);
8939 aux_info->width = -1;
8940 aux_info->height = -1;
8943 aux_info->x_set = FALSE;
8944 aux_info->y_set = FALSE;
8945 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8951 /*****************************************
8952 * gtk_widget_aux_info_destroy:
8957 *****************************************/
8960 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8962 g_slice_free (GtkWidgetAuxInfo, aux_info);
8966 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8968 g_object_unref (info->shape_mask);
8969 g_slice_free (GtkWidgetShapeInfo, info);
8973 * gtk_widget_shape_combine_mask:
8974 * @widget: a #GtkWidget
8975 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8976 * @offset_x: X position of shape mask with respect to @window
8977 * @offset_y: Y position of shape mask with respect to @window
8979 * Sets a shape for this widget's GDK window. This allows for
8980 * transparent windows etc., see gdk_window_shape_combine_mask()
8981 * for more information.
8984 gtk_widget_shape_combine_mask (GtkWidget *widget,
8985 GdkBitmap *shape_mask,
8989 GtkWidgetShapeInfo* shape_info;
8991 g_return_if_fail (GTK_IS_WIDGET (widget));
8992 /* set_shape doesn't work on widgets without gdk window */
8993 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8997 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9000 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
9002 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
9006 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
9008 shape_info = g_slice_new (GtkWidgetShapeInfo);
9009 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
9010 (GDestroyNotify) gtk_widget_shape_info_destroy);
9012 shape_info->shape_mask = g_object_ref (shape_mask);
9013 shape_info->offset_x = offset_x;
9014 shape_info->offset_y = offset_y;
9016 /* set shape if widget has a gdk window already.
9017 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9020 gdk_window_shape_combine_mask (widget->window, shape_mask,
9021 offset_x, offset_y);
9026 * gtk_widget_input_shape_combine_mask:
9027 * @widget: a #GtkWidget
9028 * @shape_mask: shape to be added, or %NULL to remove an existing shape
9029 * @offset_x: X position of shape mask with respect to @window
9030 * @offset_y: Y position of shape mask with respect to @window
9032 * Sets an input shape for this widget's GDK window. This allows for
9033 * windows which react to mouse click in a nonrectangular region, see
9034 * gdk_window_input_shape_combine_mask() for more information.
9039 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
9040 GdkBitmap *shape_mask,
9044 GtkWidgetShapeInfo* shape_info;
9046 g_return_if_fail (GTK_IS_WIDGET (widget));
9047 /* set_shape doesn't work on widgets without gdk window */
9048 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
9053 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
9055 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
9059 shape_info = g_slice_new (GtkWidgetShapeInfo);
9060 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
9062 (GDestroyNotify) gtk_widget_shape_info_destroy);
9064 shape_info->shape_mask = g_object_ref (shape_mask);
9065 shape_info->offset_x = offset_x;
9066 shape_info->offset_y = offset_y;
9068 /* set shape if widget has a gdk window already.
9069 * otherwise the shape is scheduled to be set by gtk_widget_realize().
9072 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
9073 offset_x, offset_y);
9079 gtk_reset_shapes_recurse (GtkWidget *widget,
9085 gdk_window_get_user_data (window, &data);
9089 gdk_window_shape_combine_mask (window, NULL, 0, 0);
9090 for (list = gdk_window_peek_children (window); list; list = list->next)
9091 gtk_reset_shapes_recurse (widget, list->data);
9095 * gtk_widget_reset_shapes:
9096 * @widget: a #GtkWidget
9098 * Recursively resets the shape on this widget and its descendants.
9101 gtk_widget_reset_shapes (GtkWidget *widget)
9103 g_return_if_fail (GTK_IS_WIDGET (widget));
9104 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
9106 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
9107 gtk_reset_shapes_recurse (widget, widget->window);
9112 * @widget: a #GtkWidget
9114 * Adds a reference to a widget. This function is exactly the same
9115 * as calling g_object_ref(), and exists mostly for historical
9116 * reasons. It can still be convenient to avoid casting a widget
9117 * to a #GObject, it saves a small amount of typing.
9119 * Return value: the widget that was referenced
9121 * Deprecated: 2.12: Use g_object_ref() instead.
9124 gtk_widget_ref (GtkWidget *widget)
9126 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9128 return (GtkWidget*) g_object_ref ((GObject*) widget);
9133 * @widget: a #GtkWidget
9135 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
9137 * Deprecated: 2.12: Use g_object_unref() instead.
9140 gtk_widget_unref (GtkWidget *widget)
9142 g_return_if_fail (GTK_IS_WIDGET (widget));
9144 g_object_unref ((GObject*) widget);
9148 expose_window (GdkWindow *window)
9151 GList *l, *children;
9153 gboolean is_double_buffered;
9155 gdk_window_get_user_data (window, &user_data);
9158 is_double_buffered = GTK_WIDGET_DOUBLE_BUFFERED (GTK_WIDGET (user_data));
9160 is_double_buffered = FALSE;
9162 event.expose.type = GDK_EXPOSE;
9163 event.expose.window = g_object_ref (window);
9164 event.expose.send_event = FALSE;
9165 event.expose.count = 0;
9166 event.expose.area.x = 0;
9167 event.expose.area.y = 0;
9168 gdk_drawable_get_size (GDK_DRAWABLE (window),
9169 &event.expose.area.width,
9170 &event.expose.area.height);
9171 event.expose.region = gdk_region_rectangle (&event.expose.area);
9173 /* If this is not double buffered, force a double buffer so that
9174 redirection works. */
9175 if (!is_double_buffered)
9176 gdk_window_begin_paint_region (window, event.expose.region);
9178 gtk_main_do_event (&event);
9180 if (!is_double_buffered)
9181 gdk_window_end_paint (window);
9183 children = gdk_window_peek_children (window);
9184 for (l = children; l != NULL; l = l->next)
9186 GdkWindow *child = l->data;
9188 /* Don't expose input-only windows */
9189 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
9190 expose_window (l->data);
9193 g_object_unref (window);
9197 * gtk_widget_get_snapshot:
9198 * @widget: a #GtkWidget
9199 * @clip_rect: a #GdkRectangle or %NULL
9201 * Create a #GdkPixmap of the contents of the widget and its children.
9203 * Works even if the widget is obscured. The depth and visual of the
9204 * resulting pixmap is dependent on the widget being snapshot and likely
9205 * differs from those of a target widget displaying the pixmap.
9206 * The function gdk_pixbuf_get_from_drawable() can be used to convert
9207 * the pixmap to a visual independant representation.
9209 * The snapshot area used by this function is the @widget's allocation plus
9210 * any extra space occupied by additional windows belonging to this widget
9211 * (such as the arrows of a spin button).
9212 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
9214 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
9215 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
9216 * interpreted widget relative. If width or height of @clip_rect are 0 or
9217 * negative, the width or height of the resulting pixmap will be shrunken
9218 * by the respective amount.
9219 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
9220 * chop off 5 pixels at each side of the snapshot pixmap.
9221 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
9222 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
9223 * can be used to preserve the auto-grown snapshot area and use @clip_rect
9224 * as a pure output parameter.
9226 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
9228 * Return value: #GdkPixmap snapshot of the widget
9233 gtk_widget_get_snapshot (GtkWidget *widget,
9234 GdkRectangle *clip_rect)
9236 int x, y, width, height;
9237 GdkWindow *parent_window = NULL;
9239 GList *windows = NULL, *list;
9241 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9242 if (!GTK_WIDGET_VISIBLE (widget))
9245 /* the widget (and parent_window) must be realized to be drawable */
9246 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
9247 gtk_widget_realize (widget->parent);
9248 if (!GTK_WIDGET_REALIZED (widget))
9249 gtk_widget_realize (widget);
9251 /* determine snapshot rectangle */
9252 x = widget->allocation.x;
9253 y = widget->allocation.y;
9254 width = widget->allocation.width;
9255 height = widget->allocation.height;
9257 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
9259 /* grow snapshot rectangle to cover all widget windows */
9260 parent_window = gtk_widget_get_parent_window (widget);
9261 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
9263 GdkWindow *subwin = list->data;
9266 gdk_window_get_user_data (subwin, &windata);
9267 if (windata != widget)
9269 windows = g_list_prepend (windows, subwin);
9270 gdk_window_get_position (subwin, &wx, &wy);
9271 gdk_drawable_get_size (subwin, &ww, &wh);
9272 /* grow snapshot rectangle by extra widget sub window */
9283 if (x + width < wx + ww)
9284 width += wx + ww - (x + width);
9285 if (y + height < wy + wh)
9286 height += wy + wh - (y + height);
9289 else if (!widget->parent)
9290 x = y = 0; /* toplevel */
9292 /* at this point, (x,y,width,height) is the parent_window relative
9293 * snapshot area covering all of widget's windows.
9296 /* shrink snapshot size by clip_rectangle */
9299 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
9300 clip.x = clip.x < 0 ? x : clip.x;
9301 clip.y = clip.y < 0 ? y : clip.y;
9302 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
9303 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
9306 /* offset clip_rect, so it's parent_window relative */
9307 if (clip_rect->x >= 0)
9308 clip.x += widget->allocation.x;
9309 if (clip_rect->y >= 0)
9310 clip.y += widget->allocation.y;
9312 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
9314 g_list_free (windows);
9315 clip_rect->width = clip_rect->height = 0;
9316 return NULL; /* empty snapshot area */
9321 height = snap.height;
9324 /* render snapshot */
9325 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
9326 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
9328 GdkWindow *subwin = list->data;
9330 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
9331 continue; /* Input only window */
9332 gdk_window_get_position (subwin, &wx, &wy);
9333 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
9334 MAX (0, wx - x), MAX (0, wy - y), width, height);
9336 expose_window (subwin);
9338 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
9340 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
9341 expose_window (widget->window);
9343 for (list = windows; list; list = list->next)
9344 gdk_window_remove_redirection (list->data);
9345 if (!windows) /* NO_WINDOW || toplevel */
9346 gdk_window_remove_redirection (widget->window);
9347 g_list_free (windows);
9349 /* return pixmap and snapshot rectangle coordinates */
9354 clip_rect->width = width;
9355 clip_rect->height = height;
9358 /* offset clip_rect from parent_window so it's widget relative */
9359 clip_rect->x -= widget->allocation.x;
9360 clip_rect->y -= widget->allocation.y;
9363 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
9364 G_OBJECT_TYPE_NAME (widget),
9365 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
9374 * gtk_widget_class_install_style_property_parser:
9375 * @klass: a #GtkWidgetClass
9376 * @pspec: the #GParamSpec for the style property
9377 * @parser: the parser for the style property
9379 * Installs a style property on a widget class.
9382 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
9384 GtkRcPropertyParser parser)
9386 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9387 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9388 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
9389 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
9391 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
9393 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
9394 G_OBJECT_CLASS_NAME (klass),
9399 g_param_spec_ref_sink (pspec);
9400 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
9401 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
9405 * gtk_widget_class_install_style_property:
9406 * @klass: a #GtkWidgetClass
9407 * @pspec: the #GParamSpec for the property
9409 * Installs a style property on a widget class. The parser for the
9410 * style property is determined by the value type of @pspec.
9413 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
9416 GtkRcPropertyParser parser;
9418 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
9419 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
9421 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
9423 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
9427 * gtk_widget_class_find_style_property:
9428 * @klass: a #GtkWidgetClass
9429 * @property_name: the name of the style property to find
9430 * @returns: the #GParamSpec of the style property or %NULL if @class has no
9431 * style property with that name.
9433 * Finds a style property of a widget class by name.
9438 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
9439 const gchar *property_name)
9441 g_return_val_if_fail (property_name != NULL, NULL);
9443 return g_param_spec_pool_lookup (style_property_spec_pool,
9445 G_OBJECT_CLASS_TYPE (klass),
9450 * gtk_widget_class_list_style_properties:
9451 * @klass: a #GtkWidgetClass
9452 * @n_properties: location to return the number of style properties found
9453 * @returns: an newly allocated array of #GParamSpec*. The array must
9454 * be freed with g_free().
9456 * Returns all style properties of a widget class.
9461 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9462 guint *n_properties)
9464 GParamSpec **pspecs;
9467 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9468 G_OBJECT_CLASS_TYPE (klass),
9477 * gtk_widget_style_get_property:
9478 * @widget: a #GtkWidget
9479 * @property_name: the name of a style property
9480 * @value: location to return the property value
9482 * Gets the value of a style property of @widget.
9485 gtk_widget_style_get_property (GtkWidget *widget,
9486 const gchar *property_name,
9491 g_return_if_fail (GTK_IS_WIDGET (widget));
9492 g_return_if_fail (property_name != NULL);
9493 g_return_if_fail (G_IS_VALUE (value));
9495 g_object_ref (widget);
9496 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9498 G_OBJECT_TYPE (widget),
9501 g_warning ("%s: widget class `%s' has no property named `%s'",
9503 G_OBJECT_TYPE_NAME (widget),
9507 const GValue *peek_value;
9509 peek_value = _gtk_style_peek_property_value (widget->style,
9510 G_OBJECT_TYPE (widget),
9512 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9514 /* auto-conversion of the caller's value type
9516 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9517 g_value_copy (peek_value, value);
9518 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9519 g_value_transform (peek_value, value);
9521 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9523 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9524 G_VALUE_TYPE_NAME (value));
9526 g_object_unref (widget);
9530 * gtk_widget_style_get_valist:
9531 * @widget: a #GtkWidget
9532 * @first_property_name: the name of the first property to get
9533 * @var_args: a <type>va_list</type> of pairs of property names and
9534 * locations to return the property values, starting with the location
9535 * for @first_property_name.
9537 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9541 gtk_widget_style_get_valist (GtkWidget *widget,
9542 const gchar *first_property_name,
9547 g_return_if_fail (GTK_IS_WIDGET (widget));
9549 g_object_ref (widget);
9551 name = first_property_name;
9554 const GValue *peek_value;
9558 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9560 G_OBJECT_TYPE (widget),
9564 g_warning ("%s: widget class `%s' has no property named `%s'",
9566 G_OBJECT_TYPE_NAME (widget),
9570 /* style pspecs are always readable so we can spare that check here */
9572 peek_value = _gtk_style_peek_property_value (widget->style,
9573 G_OBJECT_TYPE (widget),
9575 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9576 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9579 g_warning ("%s: %s", G_STRLOC, error);
9584 name = va_arg (var_args, gchar*);
9587 g_object_unref (widget);
9591 * gtk_widget_style_get:
9592 * @widget: a #GtkWidget
9593 * @first_property_name: the name of the first property to get
9594 * @Varargs: pairs of property names and locations to
9595 * return the property values, starting with the location for
9596 * @first_property_name, terminated by %NULL.
9598 * Gets the values of a multiple style properties of @widget.
9601 gtk_widget_style_get (GtkWidget *widget,
9602 const gchar *first_property_name,
9607 g_return_if_fail (GTK_IS_WIDGET (widget));
9609 va_start (var_args, first_property_name);
9610 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9616 * @widget: a #GtkWidget
9617 * @path_length: location to store length of the path, or %NULL
9618 * @path: location to store allocated path string, or %NULL
9619 * @path_reversed: location to store allocated reverse path string, or %NULL
9621 * Obtains the full path to @widget. The path is simply the name of a
9622 * widget and all its parents in the container hierarchy, separated by
9623 * periods. The name of a widget comes from
9624 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9625 * in gtkrc configuration files. Widget names are the type of the
9626 * widget by default (e.g. "GtkButton") or can be set to an
9627 * application-specific value with gtk_widget_set_name(). By setting
9628 * the name of a widget, you allow users or theme authors to apply
9629 * styles to that specific widget in their gtkrc
9630 * file. @path_reversed_p fills in the path in reverse order,
9631 * i.e. starting with @widget's name instead of starting with the name
9632 * of @widget's outermost ancestor.
9635 gtk_widget_path (GtkWidget *widget,
9638 gchar **path_reversed)
9640 static gchar *rev_path = NULL;
9641 static guint tmp_path_len = 0;
9644 g_return_if_fail (GTK_IS_WIDGET (widget));
9649 const gchar *string;
9654 string = gtk_widget_get_name (widget);
9655 l = strlen (string);
9656 while (tmp_path_len <= len + l + 1)
9658 tmp_path_len += INIT_PATH_SIZE;
9659 rev_path = g_realloc (rev_path, tmp_path_len);
9667 widget = widget->parent;
9670 rev_path[len++] = '.';
9672 rev_path[len++] = 0;
9677 *path_length = len - 1;
9679 *path_reversed = g_strdup (rev_path);
9682 *path = g_strdup (rev_path);
9683 g_strreverse (*path);
9688 * gtk_widget_class_path:
9689 * @widget: a #GtkWidget
9690 * @path_length: location to store the length of the class path, or %NULL
9691 * @path: location to store the class path as an allocated string, or %NULL
9692 * @path_reversed: location to store the reverse class path as an allocated
9695 * Same as gtk_widget_path(), but always uses the name of a widget's type,
9696 * never uses a custom name set with gtk_widget_set_name().
9700 gtk_widget_class_path (GtkWidget *widget,
9703 gchar **path_reversed)
9705 static gchar *rev_path = NULL;
9706 static guint tmp_path_len = 0;
9709 g_return_if_fail (GTK_IS_WIDGET (widget));
9714 const gchar *string;
9719 string = g_type_name (GTK_WIDGET_TYPE (widget));
9720 l = strlen (string);
9721 while (tmp_path_len <= len + l + 1)
9723 tmp_path_len += INIT_PATH_SIZE;
9724 rev_path = g_realloc (rev_path, tmp_path_len);
9732 widget = widget->parent;
9735 rev_path[len++] = '.';
9737 rev_path[len++] = 0;
9742 *path_length = len - 1;
9744 *path_reversed = g_strdup (rev_path);
9747 *path = g_strdup (rev_path);
9748 g_strreverse (*path);
9753 * gtk_requisition_copy:
9754 * @requisition: a #GtkRequisition
9756 * Copies a #GtkRequisition.
9758 * Returns: a copy of @requisition
9761 gtk_requisition_copy (const GtkRequisition *requisition)
9763 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9767 * gtk_requisition_free:
9768 * @requisition: a #GtkRequisition
9770 * Frees a #GtkRequisition.
9773 gtk_requisition_free (GtkRequisition *requisition)
9775 g_free (requisition);
9779 gtk_requisition_get_type (void)
9781 static GType our_type = 0;
9784 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9785 (GBoxedCopyFunc) gtk_requisition_copy,
9786 (GBoxedFreeFunc) gtk_requisition_free);
9792 * gtk_widget_get_accessible:
9793 * @widget: a #GtkWidget
9795 * Returns the accessible object that describes the widget to an
9796 * assistive technology.
9798 * If no accessibility library is loaded (i.e. no ATK implementation library is
9799 * loaded via <envar>GTK_MODULES</envar> or via another application library,
9800 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
9801 * if no class-specific #AtkObject implementation is available for the widget
9802 * instance in question, it will inherit an #AtkObject implementation from the
9803 * first ancestor class for which such an implementation is defined.
9805 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9806 * library contains more information about accessible objects and their uses.
9808 * Returns: the #AtkObject associated with @widget
9811 gtk_widget_get_accessible (GtkWidget *widget)
9813 GtkWidgetClass *klass;
9815 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9817 klass = GTK_WIDGET_GET_CLASS (widget);
9819 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
9821 return klass->get_accessible (widget);
9825 gtk_widget_real_get_accessible (GtkWidget *widget)
9827 AtkObject* accessible;
9829 accessible = g_object_get_qdata (G_OBJECT (widget),
9830 quark_accessible_object);
9833 AtkObjectFactory *factory;
9834 AtkRegistry *default_registry;
9836 default_registry = atk_get_default_registry ();
9837 factory = atk_registry_get_factory (default_registry,
9838 G_TYPE_FROM_INSTANCE (widget));
9840 atk_object_factory_create_accessible (factory,
9842 g_object_set_qdata (G_OBJECT (widget),
9843 quark_accessible_object,
9850 * Initialize a AtkImplementorIface instance's virtual pointers as
9851 * appropriate to this implementor's class (GtkWidget).
9854 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9856 iface->ref_accessible = gtk_widget_ref_accessible;
9860 gtk_widget_ref_accessible (AtkImplementor *implementor)
9862 AtkObject *accessible;
9864 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9866 g_object_ref (accessible);
9871 * GtkBuildable implementation
9873 static GQuark quark_builder_has_default = 0;
9874 static GQuark quark_builder_has_focus = 0;
9875 static GQuark quark_builder_atk_relations = 0;
9878 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9880 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9881 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9882 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9884 iface->set_name = gtk_widget_buildable_set_name;
9885 iface->get_name = gtk_widget_buildable_get_name;
9886 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9887 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9888 iface->parser_finished = gtk_widget_buildable_parser_finished;
9889 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9890 iface->custom_finished = gtk_widget_buildable_custom_finished;
9894 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9897 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9900 static const gchar *
9901 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9903 return gtk_widget_get_name (GTK_WIDGET (buildable));
9907 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9908 GtkBuilder *builder,
9909 const gchar *childname)
9911 if (strcmp (childname, "accessible") == 0)
9912 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9918 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9919 GtkBuilder *builder,
9921 const GValue *value)
9923 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9924 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9925 GINT_TO_POINTER (TRUE));
9926 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9927 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9928 GINT_TO_POINTER (TRUE));
9930 g_object_set_property (G_OBJECT (buildable), name, value);
9936 GString *description;
9938 gboolean translatable;
9948 free_action (AtkActionData *data, gpointer user_data)
9950 g_free (data->action_name);
9951 g_string_free (data->description, TRUE);
9952 g_free (data->context);
9953 g_slice_free (AtkActionData, data);
9957 free_relation (AtkRelationData *data, gpointer user_data)
9959 g_free (data->target);
9960 g_free (data->type);
9961 g_slice_free (AtkRelationData, data);
9965 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9966 GtkBuilder *builder)
9968 GSList *atk_relations;
9970 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9971 gtk_widget_grab_default (GTK_WIDGET (buildable));
9972 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9973 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9975 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9976 quark_builder_atk_relations);
9979 AtkObject *accessible;
9980 AtkRelationSet *relation_set;
9983 AtkRelationType relation_type;
9984 AtkObject *target_accessible;
9986 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9987 relation_set = atk_object_ref_relation_set (accessible);
9989 for (l = atk_relations; l; l = l->next)
9991 AtkRelationData *relation = (AtkRelationData*)l->data;
9993 target = gtk_builder_get_object (builder, relation->target);
9996 g_warning ("Target object %s in <relation> does not exist",
10000 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10001 g_assert (target_accessible != NULL);
10003 relation_type = atk_relation_type_for_name (relation->type);
10004 if (relation_type == ATK_RELATION_NULL)
10006 g_warning ("<relation> type %s not found",
10010 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10011 target_accessible);
10013 g_object_unref (relation_set);
10015 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10016 g_slist_free (atk_relations);
10017 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10026 } AccessibilitySubParserData;
10029 accessibility_start_element (GMarkupParseContext *context,
10030 const gchar *element_name,
10031 const gchar **names,
10032 const gchar **values,
10033 gpointer user_data,
10036 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10038 gint line_number, char_number;
10040 if (strcmp (element_name, "relation") == 0)
10042 gchar *target = NULL;
10043 gchar *type = NULL;
10044 AtkRelationData *relation;
10046 for (i = 0; names[i]; i++)
10048 if (strcmp (names[i], "target") == 0)
10049 target = g_strdup (values[i]);
10050 else if (strcmp (names[i], "type") == 0)
10051 type = g_strdup (values[i]);
10054 g_markup_parse_context_get_position (context,
10057 g_set_error (error,
10059 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10060 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10062 line_number, char_number, names[i], "relation");
10069 if (!target || !type)
10071 g_markup_parse_context_get_position (context,
10074 g_set_error (error,
10076 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10077 "%s:%d:%d <%s> requires attribute \"%s\"",
10079 line_number, char_number, "relation",
10080 type ? "target" : "type");
10086 relation = g_slice_new (AtkRelationData);
10087 relation->target = target;
10088 relation->type = type;
10090 data->relations = g_slist_prepend (data->relations, relation);
10092 else if (strcmp (element_name, "action") == 0)
10094 const gchar *action_name = NULL;
10095 const gchar *description = NULL;
10096 const gchar *msg_context = NULL;
10097 gboolean translatable = FALSE;
10098 AtkActionData *action;
10100 for (i = 0; names[i]; i++)
10102 if (strcmp (names[i], "action_name") == 0)
10103 action_name = values[i];
10104 else if (strcmp (names[i], "description") == 0)
10105 description = values[i];
10106 else if (strcmp (names[i], "translatable") == 0)
10108 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10111 else if (strcmp (names[i], "comments") == 0)
10113 /* do nothing, comments are for translators */
10115 else if (strcmp (names[i], "context") == 0)
10116 msg_context = values[i];
10119 g_markup_parse_context_get_position (context,
10122 g_set_error (error,
10124 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10125 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10127 line_number, char_number, names[i], "action");
10134 g_markup_parse_context_get_position (context,
10137 g_set_error (error,
10139 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10140 "%s:%d:%d <%s> requires attribute \"%s\"",
10142 line_number, char_number, "action",
10147 action = g_slice_new (AtkActionData);
10148 action->action_name = g_strdup (action_name);
10149 action->description = g_string_new (description);
10150 action->context = g_strdup (msg_context);
10151 action->translatable = translatable;
10153 data->actions = g_slist_prepend (data->actions, action);
10155 else if (strcmp (element_name, "accessibility") == 0)
10158 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10162 accessibility_text (GMarkupParseContext *context,
10165 gpointer user_data,
10168 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10170 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10172 AtkActionData *action = data->actions->data;
10174 g_string_append_len (action->description, text, text_len);
10178 static const GMarkupParser accessibility_parser =
10180 accessibility_start_element,
10182 accessibility_text,
10191 } AccelGroupParserData;
10194 accel_group_start_element (GMarkupParseContext *context,
10195 const gchar *element_name,
10196 const gchar **names,
10197 const gchar **values,
10198 gpointer user_data,
10203 guint modifiers = 0;
10204 gchar *signal = NULL;
10205 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
10207 for (i = 0; names[i]; i++)
10209 if (strcmp (names[i], "key") == 0)
10210 key = gdk_keyval_from_name (values[i]);
10211 else if (strcmp (names[i], "modifiers") == 0)
10213 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
10219 else if (strcmp (names[i], "signal") == 0)
10220 signal = g_strdup (values[i]);
10223 if (key == 0 || signal == NULL)
10225 g_warning ("<accelerator> requires key and signal attributes");
10228 parser_data->key = key;
10229 parser_data->modifiers = modifiers;
10230 parser_data->signal = signal;
10233 static const GMarkupParser accel_group_parser =
10235 accel_group_start_element,
10239 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
10240 GtkBuilder *builder,
10242 const gchar *tagname,
10243 GMarkupParser *parser,
10246 g_assert (buildable);
10248 if (strcmp (tagname, "accelerator") == 0)
10250 AccelGroupParserData *parser_data;
10252 parser_data = g_slice_new0 (AccelGroupParserData);
10253 parser_data->object = g_object_ref (buildable);
10254 *parser = accel_group_parser;
10255 *data = parser_data;
10258 if (strcmp (tagname, "accessibility") == 0)
10260 AccessibilitySubParserData *parser_data;
10262 parser_data = g_slice_new0 (AccessibilitySubParserData);
10263 *parser = accessibility_parser;
10264 *data = parser_data;
10271 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
10272 GtkWidget *toplevel,
10273 gpointer user_data)
10275 AccelGroupParserData *accel_data;
10276 GSList *accel_groups;
10277 GtkAccelGroup *accel_group;
10279 g_return_if_fail (GTK_IS_WIDGET (widget));
10280 g_return_if_fail (GTK_IS_WIDGET (toplevel));
10281 g_return_if_fail (user_data != NULL);
10283 accel_data = (AccelGroupParserData*)user_data;
10284 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
10285 if (g_slist_length (accel_groups) == 0)
10287 accel_group = gtk_accel_group_new ();
10288 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
10292 g_assert (g_slist_length (accel_groups) == 1);
10293 accel_group = g_slist_nth_data (accel_groups, 0);
10296 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
10297 accel_data->signal,
10300 accel_data->modifiers,
10301 GTK_ACCEL_VISIBLE);
10303 g_object_unref (accel_data->object);
10304 g_free (accel_data->signal);
10305 g_slice_free (AccelGroupParserData, accel_data);
10309 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
10310 GtkBuilder *builder,
10312 const gchar *tagname,
10313 gpointer user_data)
10315 AccelGroupParserData *accel_data;
10316 AccessibilitySubParserData *a11y_data;
10317 GtkWidget *toplevel;
10319 if (strcmp (tagname, "accelerator") == 0)
10321 accel_data = (AccelGroupParserData*)user_data;
10322 g_assert (accel_data->object);
10324 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
10326 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
10328 else if (strcmp (tagname, "accessibility") == 0)
10330 a11y_data = (AccessibilitySubParserData*)user_data;
10332 if (a11y_data->actions)
10334 AtkObject *accessible;
10339 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10341 action = ATK_ACTION (accessible);
10342 n_actions = atk_action_get_n_actions (action);
10344 for (l = a11y_data->actions; l; l = l->next)
10346 AtkActionData *action_data = (AtkActionData*)l->data;
10348 for (i = 0; i < n_actions; i++)
10349 if (strcmp (atk_action_get_name (action, i),
10350 action_data->action_name) == 0)
10355 gchar *description;
10357 if (action_data->translatable && action_data->description->len)
10358 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
10359 action_data->context,
10360 action_data->description->str);
10362 description = action_data->description->str;
10364 atk_action_set_description (action, i, description);
10368 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
10369 g_slist_free (a11y_data->actions);
10372 if (a11y_data->relations)
10373 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10374 a11y_data->relations);
10376 g_slice_free (AccessibilitySubParserData, a11y_data);
10382 * gtk_widget_get_clipboard:
10383 * @widget: a #GtkWidget
10384 * @selection: a #GdkAtom which identifies the clipboard
10385 * to use. %GDK_SELECTION_CLIPBOARD gives the
10386 * default clipboard. Another common value
10387 * is %GDK_SELECTION_PRIMARY, which gives
10388 * the primary X selection.
10390 * Returns the clipboard object for the given selection to
10391 * be used with @widget. @widget must have a #GdkDisplay
10392 * associated with it, so must be attached to a toplevel
10395 * Return value: the appropriate clipboard object. If no
10396 * clipboard already exists, a new one will
10397 * be created. Once a clipboard object has
10398 * been created, it is persistent for all time.
10403 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
10405 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10406 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
10408 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
10413 * gtk_widget_list_mnemonic_labels:
10414 * @widget: a #GtkWidget
10416 * Returns a newly allocated list of the widgets, normally labels, for
10417 * which this widget is a the target of a mnemonic (see for example,
10418 * gtk_label_set_mnemonic_widget()).
10420 * The widgets in the list are not individually referenced. If you
10421 * want to iterate through the list and perform actions involving
10422 * callbacks that might destroy the widgets, you
10423 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
10424 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
10425 * widgets afterwards.
10427 * Return value: the list of mnemonic labels; free this list
10428 * with g_list_free() when you are done with it.
10433 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
10435 GList *list = NULL;
10438 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10440 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
10441 list = g_list_prepend (list, l->data);
10447 * gtk_widget_add_mnemonic_label:
10448 * @widget: a #GtkWidget
10449 * @label: a #GtkWidget that acts as a mnemonic label for @widget
10451 * Adds a widget to the list of mnemonic labels for
10452 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
10453 * list of mnemonic labels for the widget is cleared when the
10454 * widget is destroyed, so the caller must make sure to update
10455 * its internal state at this point as well, by using a connection
10456 * to the #GtkWidget::destroy signal or a weak notifier.
10461 gtk_widget_add_mnemonic_label (GtkWidget *widget,
10464 GSList *old_list, *new_list;
10466 g_return_if_fail (GTK_IS_WIDGET (widget));
10467 g_return_if_fail (GTK_IS_WIDGET (label));
10469 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10470 new_list = g_slist_prepend (old_list, label);
10472 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10473 new_list, (GDestroyNotify) g_slist_free);
10477 * gtk_widget_remove_mnemonic_label:
10478 * @widget: a #GtkWidget
10479 * @label: a #GtkWidget that was previously set as a mnemnic label for
10480 * @widget with gtk_widget_add_mnemonic_label().
10482 * Removes a widget from the list of mnemonic labels for
10483 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10484 * must have previously been added to the list with
10485 * gtk_widget_add_mnemonic_label().
10490 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10493 GSList *old_list, *new_list;
10495 g_return_if_fail (GTK_IS_WIDGET (widget));
10496 g_return_if_fail (GTK_IS_WIDGET (label));
10498 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10499 new_list = g_slist_remove (old_list, label);
10502 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10503 new_list, (GDestroyNotify) g_slist_free);
10507 * gtk_widget_get_no_show_all:
10508 * @widget: a #GtkWidget
10510 * Returns the current value of the GtkWidget:no-show-all property,
10511 * which determines whether calls to gtk_widget_show_all() and
10512 * gtk_widget_hide_all() will affect this widget.
10514 * Return value: the current value of the "no-show-all" property.
10519 gtk_widget_get_no_show_all (GtkWidget *widget)
10521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10523 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10527 * gtk_widget_set_no_show_all:
10528 * @widget: a #GtkWidget
10529 * @no_show_all: the new value for the "no-show-all" property
10531 * Sets the #GtkWidget:no-show-all property, which determines whether
10532 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10535 * This is mostly for use in constructing widget hierarchies with externally
10536 * controlled visibility, see #GtkUIManager.
10541 gtk_widget_set_no_show_all (GtkWidget *widget,
10542 gboolean no_show_all)
10544 g_return_if_fail (GTK_IS_WIDGET (widget));
10546 no_show_all = (no_show_all != FALSE);
10548 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10552 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10554 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10556 g_object_notify (G_OBJECT (widget), "no-show-all");
10561 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10562 gboolean has_tooltip,
10565 gboolean priv_has_tooltip;
10567 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10568 quark_has_tooltip));
10570 if (priv_has_tooltip != has_tooltip || force)
10572 priv_has_tooltip = has_tooltip;
10574 if (priv_has_tooltip)
10576 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
10577 gdk_window_set_events (widget->window,
10578 gdk_window_get_events (widget->window) |
10579 GDK_LEAVE_NOTIFY_MASK |
10580 GDK_POINTER_MOTION_MASK |
10581 GDK_POINTER_MOTION_HINT_MASK);
10583 if (!GTK_WIDGET_NO_WINDOW (widget))
10584 gtk_widget_add_events (widget,
10585 GDK_LEAVE_NOTIFY_MASK |
10586 GDK_POINTER_MOTION_MASK |
10587 GDK_POINTER_MOTION_HINT_MASK);
10590 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10591 GUINT_TO_POINTER (priv_has_tooltip));
10596 * gtk_widget_set_tooltip_window:
10597 * @widget: a #GtkWidget
10598 * @custom_window: a #GtkWindow, or %NULL
10600 * Replaces the default, usually yellow, window used for displaying
10601 * tooltips with @custom_window. GTK+ will take care of showing and
10602 * hiding @custom_window at the right moment, to behave likewise as
10603 * the default tooltip window. If @custom_window is %NULL, the default
10604 * tooltip window will be used.
10606 * If the custom window should have the default theming it needs to
10607 * have the name "gtk-tooltip", see gtk_widget_set_name().
10612 gtk_widget_set_tooltip_window (GtkWidget *widget,
10613 GtkWindow *custom_window)
10615 gboolean has_tooltip;
10616 gchar *tooltip_markup;
10618 g_return_if_fail (GTK_IS_WIDGET (widget));
10619 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10621 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10624 g_object_ref (custom_window);
10626 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10627 custom_window, g_object_unref);
10629 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10630 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10632 if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10633 gtk_widget_queue_tooltip_query (widget);
10637 * gtk_widget_get_tooltip_window:
10638 * @widget: a #GtkWidget
10640 * Returns the #GtkWindow of the current tooltip. This can be the
10641 * GtkWindow created by default, or the custom tooltip window set
10642 * using gtk_widget_set_tooltip_window().
10644 * Return value: The #GtkWindow of the current tooltip.
10649 gtk_widget_get_tooltip_window (GtkWidget *widget)
10651 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10653 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10657 * gtk_widget_trigger_tooltip_query:
10658 * @widget: a #GtkWidget
10660 * Triggers a tooltip query on the display where the toplevel of @widget
10661 * is located. See gtk_tooltip_trigger_tooltip_query() for more
10667 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10669 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10672 static guint tooltip_query_id;
10673 static GSList *tooltip_query_displays;
10676 tooltip_query_idle (gpointer data)
10678 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
10679 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
10680 g_slist_free (tooltip_query_displays);
10682 tooltip_query_displays = NULL;
10683 tooltip_query_id = 0;
10689 gtk_widget_queue_tooltip_query (GtkWidget *widget)
10691 GdkDisplay *display;
10693 display = gtk_widget_get_display (widget);
10695 if (!g_slist_find (tooltip_query_displays, display))
10696 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
10698 if (tooltip_query_id == 0)
10699 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
10703 * gtk_widget_set_tooltip_text:
10704 * @widget: a #GtkWidget
10705 * @text: the contents of the tooltip for @widget
10707 * Sets @text as the contents of the tooltip. This function will take
10708 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10709 * handler for the GtkWidget::query-tooltip signal.
10711 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10716 gtk_widget_set_tooltip_text (GtkWidget *widget,
10719 g_return_if_fail (GTK_IS_WIDGET (widget));
10721 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10725 * gtk_widget_get_tooltip_text:
10726 * @widget: a #GtkWidget
10728 * Gets the contents of the tooltip for @widget.
10730 * Return value: the tooltip text, or %NULL. You should free the
10731 * returned string with g_free() when done.
10736 gtk_widget_get_tooltip_text (GtkWidget *widget)
10738 gchar *text = NULL;
10740 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10742 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10748 * gtk_widget_set_tooltip_markup:
10749 * @widget: a #GtkWidget
10750 * @markup: the contents of the tooltip for @widget, or %NULL
10752 * Sets @markup as the contents of the tooltip, which is marked up with
10753 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10755 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10756 * and of the default handler for the GtkWidget::query-tooltip signal.
10758 * See also the GtkWidget:tooltip-markup property and
10759 * gtk_tooltip_set_markup().
10764 gtk_widget_set_tooltip_markup (GtkWidget *widget,
10765 const gchar *markup)
10767 g_return_if_fail (GTK_IS_WIDGET (widget));
10769 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10773 * gtk_widget_get_tooltip_markup:
10774 * @widget: a #GtkWidget
10776 * Gets the contents of the tooltip for @widget.
10778 * Return value: the tooltip text, or %NULL. You should free the
10779 * returned string with g_free() when done.
10784 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10786 gchar *text = NULL;
10788 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10790 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10796 * gtk_widget_set_has_tooltip:
10797 * @widget: a #GtkWidget
10798 * @has_tooltip: whether or not @widget has a tooltip.
10800 * Sets the has-tooltip property on @widget to @has_tooltip. See
10801 * GtkWidget:has-tooltip for more information.
10806 gtk_widget_set_has_tooltip (GtkWidget *widget,
10807 gboolean has_tooltip)
10809 g_return_if_fail (GTK_IS_WIDGET (widget));
10811 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
10815 * gtk_widget_get_has_tooltip:
10816 * @widget: a #GtkWidget
10818 * Returns the current value of the has-tooltip property. See
10819 * GtkWidget:has-tooltip for more information.
10821 * Return value: current value of has-tooltip on @widget.
10826 gtk_widget_get_has_tooltip (GtkWidget *widget)
10828 gboolean has_tooltip = FALSE;
10830 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10832 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
10834 return has_tooltip;
10838 * gtk_widget_get_allocation:
10839 * @widget: a #GtkWidget
10840 * @allocation: a pointer to a #GtkAllocation to copy to
10842 * Retrieves the widget's allocation.
10847 gtk_widget_get_allocation (GtkWidget *widget,
10848 GtkAllocation *allocation)
10850 g_return_if_fail (GTK_IS_WIDGET (widget));
10851 g_return_if_fail (allocation != NULL);
10853 *allocation = widget->allocation;
10857 * gtk_widget_set_allocation:
10858 * @widget: a #GtkWidget
10859 * @allocation: a pointer to a #GtkAllocation to copy from
10861 * Sets the widget's allocation. This should not be used
10862 * directly, but from within a widget's size_allocate method.
10867 gtk_widget_set_allocation (GtkWidget *widget,
10868 const GtkAllocation *allocation)
10870 g_return_if_fail (GTK_IS_WIDGET (widget));
10871 g_return_if_fail (allocation != NULL);
10873 widget->allocation = *allocation;
10877 * gtk_widget_set_window:
10878 * @widget: a #GtkWidget
10879 * @window: a #GdkWindow
10881 * Sets a widget's window. This function should only be used in a
10882 * widget's GtkWidget::realize() implementation. The %window passed is
10883 * usually either new window created with gdk_window_new(), or the
10884 * window of its parent widget as returned by
10885 * gtk_widget_get_parent_window().
10887 * Widgets must indicate whether they will create their own #GdkWindow
10888 * by calling gtk_widget_set_has_window(). This is usually done in the
10889 * widget's init() function.
10894 gtk_widget_set_window (GtkWidget *widget,
10897 g_return_if_fail (GTK_IS_WIDGET (widget));
10898 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10900 if (widget->window != window)
10902 widget->window = window;
10903 g_object_notify (G_OBJECT (widget), "window");
10908 * gtk_widget_get_window:
10909 * @widget: a #GtkWidget
10911 * Returns the widget's window if it is realized, %NULL otherwise
10913 * Return value: @widget's window.
10918 gtk_widget_get_window (GtkWidget *widget)
10920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10922 return widget->window;
10925 #define __GTK_WIDGET_C__
10926 #include "gtkaliasdef.c"