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,
160 typedef struct _GtkStateData GtkStateData;
165 guint state_restoration : 1;
166 guint parent_sensitive : 1;
167 guint use_forall : 1;
170 /* --- prototypes --- */
171 static void gtk_widget_class_init (GtkWidgetClass *klass);
172 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
173 static void gtk_widget_init (GtkWidget *widget);
174 static void gtk_widget_set_property (GObject *object,
178 static void gtk_widget_get_property (GObject *object,
182 static void gtk_widget_dispose (GObject *object);
183 static void gtk_widget_real_destroy (GtkObject *object);
184 static void gtk_widget_finalize (GObject *object);
185 static void gtk_widget_real_show (GtkWidget *widget);
186 static void gtk_widget_real_hide (GtkWidget *widget);
187 static void gtk_widget_real_map (GtkWidget *widget);
188 static void gtk_widget_real_unmap (GtkWidget *widget);
189 static void gtk_widget_real_realize (GtkWidget *widget);
190 static void gtk_widget_real_unrealize (GtkWidget *widget);
191 static void gtk_widget_real_size_request (GtkWidget *widget,
192 GtkRequisition *requisition);
193 static void gtk_widget_real_size_allocate (GtkWidget *widget,
194 GtkAllocation *allocation);
195 static void gtk_widget_real_style_set (GtkWidget *widget,
196 GtkStyle *previous_style);
197 static void gtk_widget_real_direction_changed(GtkWidget *widget,
198 GtkTextDirection previous_direction);
200 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
201 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
204 gboolean keyboard_tip,
205 GtkTooltip *tooltip);
206 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
207 GtkWidgetHelpType help_type);
209 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
211 GParamSpec **pspecs);
212 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
214 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
216 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
217 GdkEventFocus *event);
218 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
219 GdkEventFocus *event);
220 static gboolean gtk_widget_real_focus (GtkWidget *widget,
221 GtkDirectionType direction);
222 static void gtk_widget_real_move_focus (GtkWidget *widget,
223 GtkDirectionType direction);
224 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
225 GtkDirectionType direction);
226 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
227 static void gtk_widget_update_pango_context (GtkWidget *widget);
228 static void gtk_widget_propagate_state (GtkWidget *widget,
230 static void gtk_widget_reset_rc_style (GtkWidget *widget);
231 static void gtk_widget_set_style_internal (GtkWidget *widget,
233 gboolean initial_emission);
234 static gint gtk_widget_event_internal (GtkWidget *widget,
236 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
237 gboolean group_cycling);
238 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
239 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
240 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
241 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
242 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
244 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
245 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
246 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
249 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
250 gboolean has_tooltip,
252 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
253 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
255 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
256 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
258 const gchar *childname);
259 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
262 const GValue *value);
263 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
266 const gchar *tagname,
267 GMarkupParser *parser,
269 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
272 const gchar *tagname,
274 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
275 GtkBuilder *builder);
277 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
279 static void gtk_widget_set_usize_internal (GtkWidget *widget,
282 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
286 /* --- variables --- */
287 static gpointer gtk_widget_parent_class = NULL;
288 static guint widget_signals[LAST_SIGNAL] = { 0 };
289 static GtkStyle *gtk_default_style = NULL;
290 static GSList *colormap_stack = NULL;
291 static guint composite_child_stack = 0;
292 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
293 static GParamSpecPool *style_property_spec_pool = NULL;
295 static GQuark quark_property_parser = 0;
296 static GQuark quark_aux_info = 0;
297 static GQuark quark_accel_path = 0;
298 static GQuark quark_accel_closures = 0;
299 static GQuark quark_event_mask = 0;
300 static GQuark quark_extension_event_mode = 0;
301 static GQuark quark_parent_window = 0;
302 static GQuark quark_pointer_window = 0;
303 static GQuark quark_shape_info = 0;
304 static GQuark quark_input_shape_info = 0;
305 static GQuark quark_colormap = 0;
306 static GQuark quark_pango_context = 0;
307 static GQuark quark_rc_style = 0;
308 static GQuark quark_accessible_object = 0;
309 static GQuark quark_mnemonic_labels = 0;
310 static GQuark quark_tooltip_markup = 0;
311 static GQuark quark_has_tooltip = 0;
312 static GQuark quark_tooltip_window = 0;
313 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
314 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
316 /* --- functions --- */
318 gtk_widget_get_type (void)
320 static GType widget_type = 0;
322 if (G_UNLIKELY (widget_type == 0))
324 const GTypeInfo widget_info =
326 sizeof (GtkWidgetClass),
327 NULL, /* base_init */
328 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
329 (GClassInitFunc) gtk_widget_class_init,
330 NULL, /* class_finalize */
331 NULL, /* class_init */
334 (GInstanceInitFunc) gtk_widget_init,
335 NULL, /* value_table */
338 const GInterfaceInfo accessibility_info =
340 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
341 (GInterfaceFinalizeFunc) NULL,
342 NULL /* interface data */
345 const GInterfaceInfo buildable_info =
347 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
348 (GInterfaceFinalizeFunc) NULL,
349 NULL /* interface data */
352 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
353 &widget_info, G_TYPE_FLAG_ABSTRACT);
355 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
356 &accessibility_info) ;
357 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
366 child_property_notify_dispatcher (GObject *object,
370 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
374 gtk_widget_class_init (GtkWidgetClass *klass)
376 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
377 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
378 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
379 GtkBindingSet *binding_set;
381 gtk_widget_parent_class = g_type_class_peek_parent (klass);
383 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
384 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
385 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
386 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
387 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
388 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
389 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
390 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
391 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
392 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
393 quark_colormap = g_quark_from_static_string ("gtk-colormap");
394 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
395 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
396 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
397 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
398 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
399 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
400 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
402 style_property_spec_pool = g_param_spec_pool_new (FALSE);
403 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
404 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
405 cpn_context.dispatcher = child_property_notify_dispatcher;
406 _gtk_widget_child_property_notify_context = &cpn_context;
408 gobject_class->dispose = gtk_widget_dispose;
409 gobject_class->finalize = gtk_widget_finalize;
410 gobject_class->set_property = gtk_widget_set_property;
411 gobject_class->get_property = gtk_widget_get_property;
413 object_class->destroy = gtk_widget_real_destroy;
415 klass->activate_signal = 0;
416 klass->set_scroll_adjustments_signal = 0;
417 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
418 klass->show = gtk_widget_real_show;
419 klass->show_all = gtk_widget_show;
420 klass->hide = gtk_widget_real_hide;
421 klass->hide_all = gtk_widget_hide;
422 klass->map = gtk_widget_real_map;
423 klass->unmap = gtk_widget_real_unmap;
424 klass->realize = gtk_widget_real_realize;
425 klass->unrealize = gtk_widget_real_unrealize;
426 klass->size_request = gtk_widget_real_size_request;
427 klass->size_allocate = gtk_widget_real_size_allocate;
428 klass->state_changed = NULL;
429 klass->parent_set = NULL;
430 klass->hierarchy_changed = NULL;
431 klass->style_set = gtk_widget_real_style_set;
432 klass->direction_changed = gtk_widget_real_direction_changed;
433 klass->grab_notify = NULL;
434 klass->child_notify = NULL;
435 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
436 klass->grab_focus = gtk_widget_real_grab_focus;
437 klass->focus = gtk_widget_real_focus;
439 klass->button_press_event = NULL;
440 klass->button_release_event = NULL;
441 klass->motion_notify_event = NULL;
442 klass->delete_event = NULL;
443 klass->destroy_event = NULL;
444 klass->expose_event = NULL;
445 klass->key_press_event = gtk_widget_real_key_press_event;
446 klass->key_release_event = gtk_widget_real_key_release_event;
447 klass->enter_notify_event = NULL;
448 klass->leave_notify_event = NULL;
449 klass->configure_event = NULL;
450 klass->focus_in_event = gtk_widget_real_focus_in_event;
451 klass->focus_out_event = gtk_widget_real_focus_out_event;
452 klass->map_event = NULL;
453 klass->unmap_event = NULL;
454 klass->window_state_event = NULL;
455 klass->property_notify_event = _gtk_selection_property_notify;
456 klass->selection_clear_event = gtk_selection_clear;
457 klass->selection_request_event = _gtk_selection_request;
458 klass->selection_notify_event = _gtk_selection_notify;
459 klass->selection_received = NULL;
460 klass->proximity_in_event = NULL;
461 klass->proximity_out_event = NULL;
462 klass->drag_begin = NULL;
463 klass->drag_end = NULL;
464 klass->drag_data_delete = NULL;
465 klass->drag_leave = NULL;
466 klass->drag_motion = NULL;
467 klass->drag_drop = NULL;
468 klass->drag_data_received = NULL;
469 klass->screen_changed = NULL;
470 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
471 klass->grab_broken_event = NULL;
472 klass->query_tooltip = gtk_widget_real_query_tooltip;
474 klass->show_help = gtk_widget_real_show_help;
476 /* Accessibility support */
477 klass->get_accessible = gtk_widget_real_get_accessible;
479 klass->no_expose_event = NULL;
481 g_object_class_install_property (gobject_class,
483 g_param_spec_string ("name",
485 P_("The name of the widget"),
487 GTK_PARAM_READWRITE));
488 g_object_class_install_property (gobject_class,
490 g_param_spec_object ("parent",
492 P_("The parent widget of this widget. Must be a Container widget"),
494 GTK_PARAM_READWRITE));
496 g_object_class_install_property (gobject_class,
498 g_param_spec_int ("width-request",
500 P_("Override for width request of the widget, or -1 if natural request should be used"),
504 GTK_PARAM_READWRITE));
505 g_object_class_install_property (gobject_class,
507 g_param_spec_int ("height-request",
508 P_("Height request"),
509 P_("Override for height request of the widget, or -1 if natural request should be used"),
513 GTK_PARAM_READWRITE));
514 g_object_class_install_property (gobject_class,
516 g_param_spec_boolean ("visible",
518 P_("Whether the widget is visible"),
520 GTK_PARAM_READWRITE));
521 g_object_class_install_property (gobject_class,
523 g_param_spec_boolean ("sensitive",
525 P_("Whether the widget responds to input"),
527 GTK_PARAM_READWRITE));
528 g_object_class_install_property (gobject_class,
530 g_param_spec_boolean ("app-paintable",
531 P_("Application paintable"),
532 P_("Whether the application will paint directly on the widget"),
534 GTK_PARAM_READWRITE));
535 g_object_class_install_property (gobject_class,
537 g_param_spec_boolean ("can-focus",
539 P_("Whether the widget can accept the input focus"),
541 GTK_PARAM_READWRITE));
542 g_object_class_install_property (gobject_class,
544 g_param_spec_boolean ("has-focus",
546 P_("Whether the widget has the input focus"),
548 GTK_PARAM_READWRITE));
549 g_object_class_install_property (gobject_class,
551 g_param_spec_boolean ("is-focus",
553 P_("Whether the widget is the focus widget within the toplevel"),
555 GTK_PARAM_READWRITE));
556 g_object_class_install_property (gobject_class,
558 g_param_spec_boolean ("can-default",
560 P_("Whether the widget can be the default widget"),
562 GTK_PARAM_READWRITE));
563 g_object_class_install_property (gobject_class,
565 g_param_spec_boolean ("has-default",
567 P_("Whether the widget is the default widget"),
569 GTK_PARAM_READWRITE));
570 g_object_class_install_property (gobject_class,
571 PROP_RECEIVES_DEFAULT,
572 g_param_spec_boolean ("receives-default",
573 P_("Receives default"),
574 P_("If TRUE, the widget will receive the default action when it is focused"),
576 GTK_PARAM_READWRITE));
577 g_object_class_install_property (gobject_class,
578 PROP_COMPOSITE_CHILD,
579 g_param_spec_boolean ("composite-child",
580 P_("Composite child"),
581 P_("Whether the widget is part of a composite widget"),
583 GTK_PARAM_READABLE));
584 g_object_class_install_property (gobject_class,
586 g_param_spec_object ("style",
588 P_("The style of the widget, which contains information about how it will look (colors etc)"),
590 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_flags ("events",
595 P_("The event mask that decides what kind of GdkEvents this widget gets"),
598 GTK_PARAM_READWRITE));
599 g_object_class_install_property (gobject_class,
600 PROP_EXTENSION_EVENTS,
601 g_param_spec_enum ("extension-events",
602 P_("Extension events"),
603 P_("The mask that decides what kind of extension events this widget gets"),
604 GDK_TYPE_EXTENSION_MODE,
605 GDK_EXTENSION_EVENTS_NONE,
606 GTK_PARAM_READWRITE));
607 g_object_class_install_property (gobject_class,
609 g_param_spec_boolean ("no-show-all",
611 P_("Whether gtk_widget_show_all() should not affect this widget"),
613 GTK_PARAM_READWRITE));
616 * GtkWidget:has-tooltip:
618 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
619 * A value of %TRUE indicates that @widget can have a tooltip, in this case
620 * the widget will be queried using #GtkWidget::query-tooltip to determine
621 * whether it will provide a tooltip or not.
623 * Note that setting this property to %TRUE for the first time will change
624 * the event masks of the GdkWindows of this widget to include leave-notify
625 * and motion-notify events. This cannot and will not be undone when the
626 * property is set to %FALSE again.
630 g_object_class_install_property (gobject_class,
632 g_param_spec_boolean ("has-tooltip",
634 P_("Whether this widget has a tooltip"),
636 GTK_PARAM_READWRITE));
638 * GtkWidget:tooltip-text:
640 * Sets the text of tooltip to be the given string.
642 * Also see gtk_tooltip_set_text().
644 * This is a convenience property which will take care of getting the
645 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
646 * will automatically be set to %TRUE and there will be taken care of
647 * #GtkWidget::query-tooltip in the default signal handler.
651 g_object_class_install_property (gobject_class,
653 g_param_spec_string ("tooltip-text",
655 P_("The contents of the tooltip for this widget"),
657 GTK_PARAM_READWRITE));
659 * GtkWidget:tooltip-markup:
661 * Sets the text of tooltip to be the given string, which is marked up
662 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
663 * Also see gtk_tooltip_set_markup().
665 * This is a convenience property which will take care of getting the
666 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
667 * will automatically be set to %TRUE and there will be taken care of
668 * #GtkWidget::query-tooltip in the default signal handler.
672 g_object_class_install_property (gobject_class,
674 g_param_spec_string ("tooltip-markup",
675 P_("Tooltip markup"),
676 P_("The contents of the tooltip for this widget"),
678 GTK_PARAM_READWRITE));
683 * The widget's window if it is realized, %NULL otherwise.
687 g_object_class_install_property (gobject_class,
689 g_param_spec_object ("window",
691 P_("The widget's window if it is realized"),
693 GTK_PARAM_READABLE));
695 widget_signals[SHOW] =
696 g_signal_new (I_("show"),
697 G_TYPE_FROM_CLASS (gobject_class),
699 G_STRUCT_OFFSET (GtkWidgetClass, show),
701 _gtk_marshal_VOID__VOID,
703 widget_signals[HIDE] =
704 g_signal_new (I_("hide"),
705 G_TYPE_FROM_CLASS (gobject_class),
707 G_STRUCT_OFFSET (GtkWidgetClass, hide),
709 _gtk_marshal_VOID__VOID,
711 widget_signals[MAP] =
712 g_signal_new (I_("map"),
713 G_TYPE_FROM_CLASS (gobject_class),
715 G_STRUCT_OFFSET (GtkWidgetClass, map),
717 _gtk_marshal_VOID__VOID,
719 widget_signals[UNMAP] =
720 g_signal_new (I_("unmap"),
721 G_TYPE_FROM_CLASS (gobject_class),
723 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
725 _gtk_marshal_VOID__VOID,
727 widget_signals[REALIZE] =
728 g_signal_new (I_("realize"),
729 G_TYPE_FROM_CLASS (gobject_class),
731 G_STRUCT_OFFSET (GtkWidgetClass, realize),
733 _gtk_marshal_VOID__VOID,
735 widget_signals[UNREALIZE] =
736 g_signal_new (I_("unrealize"),
737 G_TYPE_FROM_CLASS (gobject_class),
739 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
741 _gtk_marshal_VOID__VOID,
743 widget_signals[SIZE_REQUEST] =
744 g_signal_new (I_("size-request"),
745 G_TYPE_FROM_CLASS (gobject_class),
747 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
749 _gtk_marshal_VOID__BOXED,
751 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
752 widget_signals[SIZE_ALLOCATE] =
753 g_signal_new (I_("size-allocate"),
754 G_TYPE_FROM_CLASS (gobject_class),
756 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
758 _gtk_marshal_VOID__BOXED,
760 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
762 widget_signals[STATE_CHANGED] =
763 g_signal_new (I_("state-changed"),
764 G_TYPE_FROM_CLASS (gobject_class),
766 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
768 _gtk_marshal_VOID__ENUM,
770 GTK_TYPE_STATE_TYPE);
773 * GtkWidget::parent-set:
774 * @widget: the object on which the signal is emitted
775 * @old_parent: the previous parent, or %NULL if the widget
776 * just got its initial parent.
778 * The ::parent-set signal is emitted when a new parent
779 * has been set on a widget.
781 widget_signals[PARENT_SET] =
782 g_signal_new (I_("parent-set"),
783 G_TYPE_FROM_CLASS (gobject_class),
785 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
787 _gtk_marshal_VOID__OBJECT,
792 * GtkWidget::hierarchy-changed:
793 * @widget: the object on which the signal is emitted
794 * @previous_toplevel: the previous toplevel ancestor, or %NULL
795 * if the widget was previously unanchored
797 * The ::hierarchy-changed signal is emitted when the
798 * anchored state of a widget changes. A widget is
799 * <firstterm>anchored</firstterm> when its toplevel
800 * ancestor is a #GtkWindow. This signal is emitted when
801 * a widget changes from un-anchored to anchored or vice-versa.
803 widget_signals[HIERARCHY_CHANGED] =
804 g_signal_new (I_("hierarchy-changed"),
805 G_TYPE_FROM_CLASS (gobject_class),
807 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
809 _gtk_marshal_VOID__OBJECT,
814 * GtkWidget::style-set:
815 * @widget: the object on which the signal is emitted
816 * @previous_style: the previous style, or %NULL if the widget
817 * just got its initial style
819 * The ::style-set signal is emitted when a new style has been set
820 * on a widget. Note that style-modifying functions like
821 * gtk_widget_modify_base() also cause this signal to be emitted.
823 widget_signals[STYLE_SET] =
824 g_signal_new (I_("style-set"),
825 G_TYPE_FROM_CLASS (gobject_class),
827 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
829 _gtk_marshal_VOID__OBJECT,
833 * GtkWidget::direction-changed:
834 * @widget: the object on which the signal is emitted
835 * @previous_direction: the previous text direction of @widget
837 * The ::direction-changed signal is emitted when the text direction
838 * of a widget changes.
840 widget_signals[DIRECTION_CHANGED] =
841 g_signal_new (I_("direction-changed"),
842 G_TYPE_FROM_CLASS (gobject_class),
844 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
846 _gtk_marshal_VOID__ENUM,
848 GTK_TYPE_TEXT_DIRECTION);
851 * GtkWidget::grab-notify:
852 * @widget: the object which received the signal
853 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
854 * if it becomes unshadowed
856 * The ::grab-notify signal is emitted when a widget becomes
857 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
858 * another widget, or when it becomes unshadowed due to a grab
861 * A widget is shadowed by a gtk_grab_add() when the topmost
862 * grab widget in the grab stack of its window group is not
865 widget_signals[GRAB_NOTIFY] =
866 g_signal_new (I_("grab-notify"),
867 G_TYPE_FROM_CLASS (gobject_class),
869 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
871 _gtk_marshal_VOID__BOOLEAN,
876 * GtkWidget::child-notify:
877 * @widget: the object which received the signal
878 * @pspec: the #GParamSpec of the changed child property
880 * The ::child-notify signal is emitted for each
881 * <link linkend="child-properties">child property</link> that has
882 * changed on an object. The signal's detail holds the property name.
884 widget_signals[CHILD_NOTIFY] =
885 g_signal_new (I_("child-notify"),
886 G_TYPE_FROM_CLASS (gobject_class),
887 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
888 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
890 g_cclosure_marshal_VOID__PARAM,
893 widget_signals[MNEMONIC_ACTIVATE] =
894 g_signal_new (I_("mnemonic-activate"),
895 G_TYPE_FROM_CLASS (gobject_class),
897 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
898 _gtk_boolean_handled_accumulator, NULL,
899 _gtk_marshal_BOOLEAN__BOOLEAN,
902 widget_signals[GRAB_FOCUS] =
903 g_signal_new (I_("grab-focus"),
904 G_TYPE_FROM_CLASS (gobject_class),
905 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
906 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
908 _gtk_marshal_VOID__VOID,
910 widget_signals[FOCUS] =
911 g_signal_new (I_("focus"),
912 G_TYPE_FROM_CLASS (object_class),
914 G_STRUCT_OFFSET (GtkWidgetClass, focus),
915 _gtk_boolean_handled_accumulator, NULL,
916 _gtk_marshal_BOOLEAN__ENUM,
918 GTK_TYPE_DIRECTION_TYPE);
919 widget_signals[MOVE_FOCUS] =
920 g_signal_new_class_handler (I_("move-focus"),
921 G_TYPE_FROM_CLASS (object_class),
922 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
923 G_CALLBACK (gtk_widget_real_move_focus),
925 _gtk_marshal_VOID__ENUM,
928 GTK_TYPE_DIRECTION_TYPE);
931 * @widget: the object which received the signal.
932 * @event: the #GdkEvent which triggered this signal
934 * The GTK+ main loop will emit three signals for each GDK event delivered
935 * to a widget: one generic ::event signal, another, more specific,
936 * signal that matches the type of event delivered (e.g.
937 * #GtkWidget::key-press-event) and finally a generic
938 * #GtkWidget::event-after signal.
940 * Returns: %TRUE to stop other handlers from being invoked for the event
941 * and to cancel the emission of the second specific ::event signal.
942 * %FALSE to propagate the event further and to allow the emission of
943 * the second signal. The ::event-after signal is emitted regardless of
946 widget_signals[EVENT] =
947 g_signal_new (I_("event"),
948 G_TYPE_FROM_CLASS (gobject_class),
950 G_STRUCT_OFFSET (GtkWidgetClass, event),
951 _gtk_boolean_handled_accumulator, NULL,
952 _gtk_marshal_BOOLEAN__BOXED,
954 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
957 * GtkWidget::event-after:
958 * @widget: the object which received the signal.
959 * @event: the #GdkEvent which triggered this signal
961 * After the emission of the #GtkWidget::event signal and (optionally)
962 * the second more specific signal, ::event-after will be emitted
963 * regardless of the previous two signals handlers return values.
966 widget_signals[EVENT_AFTER] =
967 g_signal_new (I_("event-after"),
968 G_TYPE_FROM_CLASS (gobject_class),
972 _gtk_marshal_VOID__BOXED,
974 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
977 * GtkWidget::button-press-event:
978 * @widget: the object which received the signal.
979 * @event: the #GdkEventButton which triggered this signal
981 * The ::button-press-event signal will be emitted when a button
982 * (typically from a mouse) is pressed.
984 * To receive this signal, the #GdkWindow associated to the
985 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
987 * This signal will be sent to the grab widget if there is one.
989 * Returns: %TRUE to stop other handlers from being invoked for the event.
990 * %FALSE to propagate the event further.
992 widget_signals[BUTTON_PRESS_EVENT] =
993 g_signal_new (I_("button-press-event"),
994 G_TYPE_FROM_CLASS (gobject_class),
996 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
997 _gtk_boolean_handled_accumulator, NULL,
998 _gtk_marshal_BOOLEAN__BOXED,
1000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1003 * GtkWidget::button-release-event:
1004 * @widget: the object which received the signal.
1005 * @event: the #GdkEventButton which triggered this signal
1007 * The ::button-release-event signal will be emitted when a button
1008 * (typically from a mouse) is released.
1010 * To receive this signal, the #GdkWindow associated to the
1011 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1013 * This signal will be sent to the grab widget if there is one.
1015 * Returns: %TRUE to stop other handlers from being invoked for the event.
1016 * %FALSE to propagate the event further.
1018 widget_signals[BUTTON_RELEASE_EVENT] =
1019 g_signal_new (I_("button-release-event"),
1020 G_TYPE_FROM_CLASS (gobject_class),
1022 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1023 _gtk_boolean_handled_accumulator, NULL,
1024 _gtk_marshal_BOOLEAN__BOXED,
1026 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1029 * GtkWidget::scroll-event:
1030 * @widget: the object which received the signal.
1031 * @event: the #GdkEventScroll which triggered this signal
1033 * The ::scroll-event signal is emitted when a button in the 4 to 7
1034 * range is pressed. Wheel mice are usually configured to generate
1035 * button press events for buttons 4 and 5 when the wheel is turned.
1037 * To receive this signal, the #GdkWindow associated to the widget needs
1038 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1040 * This signal will be sent to the grab widget if there is one.
1042 * Returns: %TRUE to stop other handlers from being invoked for the event.
1043 * %FALSE to propagate the event further.
1045 widget_signals[SCROLL_EVENT] =
1046 g_signal_new (I_("scroll-event"),
1047 G_TYPE_FROM_CLASS (gobject_class),
1049 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1050 _gtk_boolean_handled_accumulator, NULL,
1051 _gtk_marshal_BOOLEAN__BOXED,
1053 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1055 * GtkWidget::motion-notify-event:
1056 * @widget: the object which received the signal.
1057 * @event: the #GdkEventMotion which triggered this signal
1059 * The ::motion-notify-event signal is emitted when the pointer moves
1060 * over the widget's #GdkWindow.
1062 * To receive this signal, the #GdkWindow associated to the widget
1063 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1065 * This signal will be sent to the grab widget if there is one.
1067 * Returns: %TRUE to stop other handlers from being invoked for the event.
1068 * %FALSE to propagate the event further.
1070 widget_signals[MOTION_NOTIFY_EVENT] =
1071 g_signal_new (I_("motion-notify-event"),
1072 G_TYPE_FROM_CLASS (gobject_class),
1074 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1075 _gtk_boolean_handled_accumulator, NULL,
1076 _gtk_marshal_BOOLEAN__BOXED,
1078 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1081 * GtkWidget::composited-changed:
1082 * @widget: the object on which the signal is emitted
1084 * The ::composited-changed signal is emitted when the composited
1085 * status of @widget<!-- -->s screen changes.
1086 * See gdk_screen_is_composited().
1088 widget_signals[COMPOSITED_CHANGED] =
1089 g_signal_new (I_("composited-changed"),
1090 G_TYPE_FROM_CLASS (gobject_class),
1091 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1092 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1094 _gtk_marshal_VOID__VOID,
1098 * GtkWidget::keynav-failed:
1099 * @widget: the object which received the signal
1100 * @direction: the direction of movement
1102 * Gets emitted if keyboard navigation fails.
1103 * See gtk_widget_keynav_failed() for details.
1105 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1106 * if the emitting widget should try to handle the keyboard
1107 * navigation attempt in its parent container(s).
1111 widget_signals[KEYNAV_FAILED] =
1112 g_signal_new_class_handler (I_("keynav-failed"),
1113 G_TYPE_FROM_CLASS (gobject_class),
1115 G_CALLBACK (gtk_widget_real_keynav_failed),
1116 _gtk_boolean_handled_accumulator, NULL,
1117 _gtk_marshal_BOOLEAN__ENUM,
1119 GTK_TYPE_DIRECTION_TYPE);
1122 * GtkWidget::delete-event:
1123 * @widget: the object which received the signal
1124 * @event: the event which triggered this signal
1126 * The ::delete-event signal is emitted if a user requests that
1127 * a toplevel window is closed. The default handler for this signal
1128 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1129 * this signal will cause the window to be hidden instead, so that
1130 * it can later be shown again without reconstructing it.
1132 * Returns: %TRUE to stop other handlers from being invoked for the event.
1133 * %FALSE to propagate the event further.
1135 widget_signals[DELETE_EVENT] =
1136 g_signal_new (I_("delete-event"),
1137 G_TYPE_FROM_CLASS (gobject_class),
1139 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1140 _gtk_boolean_handled_accumulator, NULL,
1141 _gtk_marshal_BOOLEAN__BOXED,
1143 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1146 * GtkWidget::destroy-event:
1147 * @widget: the object which received the signal.
1148 * @event: the event which triggered this signal
1150 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1151 * You rarely get this signal, because most widgets disconnect themselves
1152 * from their window before they destroy it, so no widget owns the
1153 * window at destroy time.
1155 * To receive this signal, the #GdkWindow associated to the widget needs
1156 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1157 * automatically for all new windows.
1159 * Returns: %TRUE to stop other handlers from being invoked for the event.
1160 * %FALSE to propagate the event further.
1162 widget_signals[DESTROY_EVENT] =
1163 g_signal_new (I_("destroy-event"),
1164 G_TYPE_FROM_CLASS (gobject_class),
1166 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1167 _gtk_boolean_handled_accumulator, NULL,
1168 _gtk_marshal_BOOLEAN__BOXED,
1170 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1173 * GtkWidget::expose-event:
1174 * @widget: the object which received the signal.
1175 * @event: the #GdkEventExpose which triggered this signal
1177 * The ::expose-event signal is emitted when an area of a previously
1178 * obscured #GdkWindow is made visible and needs to be redrawn.
1179 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1182 * To receive this signal, the #GdkWindow associated to the widget needs
1183 * to enable the #GDK_EXPOSURE_MASK mask.
1185 * Returns: %TRUE to stop other handlers from being invoked for the event.
1186 * %FALSE to propagate the event further.
1188 widget_signals[EXPOSE_EVENT] =
1189 g_signal_new (I_("expose-event"),
1190 G_TYPE_FROM_CLASS (gobject_class),
1192 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1193 _gtk_boolean_handled_accumulator, NULL,
1194 _gtk_marshal_BOOLEAN__BOXED,
1196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1199 * GtkWidget::key-press-event:
1200 * @widget: the object which received the signal
1201 * @event: the #GdkEventKey which triggered this signal
1203 * The ::key-press-event signal is emitted when a key is pressed.
1205 * To receive this signal, the #GdkWindow associated to the widget needs
1206 * to enable the #GDK_KEY_PRESS_MASK mask.
1208 * This signal will be sent to the grab widget if there is one.
1210 * Returns: %TRUE to stop other handlers from being invoked for the event.
1211 * %FALSE to propagate the event further.
1213 widget_signals[KEY_PRESS_EVENT] =
1214 g_signal_new (I_("key-press-event"),
1215 G_TYPE_FROM_CLASS (gobject_class),
1217 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1218 _gtk_boolean_handled_accumulator, NULL,
1219 _gtk_marshal_BOOLEAN__BOXED,
1221 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1224 * GtkWidget::key-release-event:
1225 * @widget: the object which received the signal
1226 * @event: the #GdkEventKey which triggered this signal
1228 * The ::key-release-event signal is emitted when a key is pressed.
1230 * To receive this signal, the #GdkWindow associated to the widget needs
1231 * to enable the #GDK_KEY_RELEASE_MASK mask.
1233 * This signal will be sent to the grab widget if there is one.
1235 * Returns: %TRUE to stop other handlers from being invoked for the event.
1236 * %FALSE to propagate the event further.
1238 widget_signals[KEY_RELEASE_EVENT] =
1239 g_signal_new (I_("key-release-event"),
1240 G_TYPE_FROM_CLASS (gobject_class),
1242 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1243 _gtk_boolean_handled_accumulator, NULL,
1244 _gtk_marshal_BOOLEAN__BOXED,
1246 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1249 * GtkWidget::enter-notify-event:
1250 * @widget: the object which received the signal
1251 * @event: the #GdkEventCrossing which triggered this signal
1253 * The ::enter-notify-event will be emitted when the pointer enters
1254 * the @widget's window.
1256 * To receive this signal, the #GdkWindow associated to the widget needs
1257 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1259 * This signal will be sent to the grab widget if there is one.
1261 * Returns: %TRUE to stop other handlers from being invoked for the event.
1262 * %FALSE to propagate the event further.
1264 widget_signals[ENTER_NOTIFY_EVENT] =
1265 g_signal_new (I_("enter-notify-event"),
1266 G_TYPE_FROM_CLASS (gobject_class),
1268 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1269 _gtk_boolean_handled_accumulator, NULL,
1270 _gtk_marshal_BOOLEAN__BOXED,
1272 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1275 * GtkWidget::leave-notify-event:
1276 * @widget: the object which received the signal
1277 * @event: the #GdkEventCrossing which triggered this signal
1279 * The ::leave-notify-event will be emitted when the pointer leaves
1280 * the @widget's window.
1282 * To receive this signal, the #GdkWindow associated to the widget needs
1283 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1285 * This signal will be sent to the grab widget if there is one.
1287 * Returns: %TRUE to stop other handlers from being invoked for the event.
1288 * %FALSE to propagate the event further.
1290 widget_signals[LEAVE_NOTIFY_EVENT] =
1291 g_signal_new (I_("leave-notify-event"),
1292 G_TYPE_FROM_CLASS (gobject_class),
1294 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1295 _gtk_boolean_handled_accumulator, NULL,
1296 _gtk_marshal_BOOLEAN__BOXED,
1298 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1301 * GtkWidget::configure-event
1302 * @widget: the object which received the signal
1303 * @event: the #GdkEventConfigure which triggered this signal
1305 * The ::configure-event signal will be emitted when the size, position or
1306 * stacking of the @widget's window has changed.
1308 * To receive this signal, the #GdkWindow associated to the widget needs
1309 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1310 * automatically for all new windows.
1312 * Returns: %TRUE to stop other handlers from being invoked for the event.
1313 * %FALSE to propagate the event further.
1315 widget_signals[CONFIGURE_EVENT] =
1316 g_signal_new (I_("configure-event"),
1317 G_TYPE_FROM_CLASS (gobject_class),
1319 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1320 _gtk_boolean_handled_accumulator, NULL,
1321 _gtk_marshal_BOOLEAN__BOXED,
1323 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1326 * GtkWidget::focus-in-event
1327 * @widget: the object which received the signal
1328 * @event: the #GdkEventFocus which triggered this signal
1330 * The ::focus-in-event signal will be emitted when the keyboard focus
1331 * enters the @widget's window.
1333 * To receive this signal, the #GdkWindow associated to the widget needs
1334 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1336 * Returns: %TRUE to stop other handlers from being invoked for the event.
1337 * %FALSE to propagate the event further.
1339 widget_signals[FOCUS_IN_EVENT] =
1340 g_signal_new (I_("focus-in-event"),
1341 G_TYPE_FROM_CLASS (gobject_class),
1343 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1344 _gtk_boolean_handled_accumulator, NULL,
1345 _gtk_marshal_BOOLEAN__BOXED,
1347 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1350 * GtkWidget::focus-out-event
1351 * @widget: the object which received the signal
1352 * @event: the #GdkEventFocus which triggered this signal
1354 * The ::focus-out-event signal will be emitted when the keyboard focus
1355 * leaves the @widget's window.
1357 * To receive this signal, the #GdkWindow associated to the widget needs
1358 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1360 * Returns: %TRUE to stop other handlers from being invoked for the event.
1361 * %FALSE to propagate the event further.
1363 widget_signals[FOCUS_OUT_EVENT] =
1364 g_signal_new (I_("focus-out-event"),
1365 G_TYPE_FROM_CLASS (gobject_class),
1367 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1368 _gtk_boolean_handled_accumulator, NULL,
1369 _gtk_marshal_BOOLEAN__BOXED,
1371 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1374 * GtkWidget::map-event
1375 * @widget: the object which received the signal
1376 * @event: the #GdkEventAny which triggered this signal
1378 * The ::map-event signal will be emitted when the @widget's window is
1379 * mapped. A window is mapped when it becomes visible on the screen.
1381 * To receive this signal, the #GdkWindow associated to the widget needs
1382 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1383 * automatically for all new windows.
1385 * Returns: %TRUE to stop other handlers from being invoked for the event.
1386 * %FALSE to propagate the event further.
1388 widget_signals[MAP_EVENT] =
1389 g_signal_new (I_("map-event"),
1390 G_TYPE_FROM_CLASS (gobject_class),
1392 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1393 _gtk_boolean_handled_accumulator, NULL,
1394 _gtk_marshal_BOOLEAN__BOXED,
1396 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1399 * GtkWidget::unmap-event
1400 * @widget: the object which received the signal
1401 * @event: the #GdkEventAny which triggered this signal
1403 * The ::unmap-event signal will be emitted when the @widget's window is
1404 * unmapped. A window is unmapped when it becomes invisible on the screen.
1406 * To receive this signal, the #GdkWindow associated to the widget needs
1407 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1408 * automatically for all new windows.
1410 * Returns: %TRUE to stop other handlers from being invoked for the event.
1411 * %FALSE to propagate the event further.
1413 widget_signals[UNMAP_EVENT] =
1414 g_signal_new (I_("unmap-event"),
1415 G_TYPE_FROM_CLASS (gobject_class),
1417 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1418 _gtk_boolean_handled_accumulator, NULL,
1419 _gtk_marshal_BOOLEAN__BOXED,
1421 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1424 * GtkWidget::property-notify-event
1425 * @widget: the object which received the signal
1426 * @event: the #GdkEventProperty which triggered this signal
1428 * The ::property-notify-event signal will be emitted when a property on
1429 * the @widget's window has been changed or deleted.
1431 * To receive this signal, the #GdkWindow associated to the widget needs
1432 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1434 * Returns: %TRUE to stop other handlers from being invoked for the event.
1435 * %FALSE to propagate the event further.
1437 widget_signals[PROPERTY_NOTIFY_EVENT] =
1438 g_signal_new (I_("property-notify-event"),
1439 G_TYPE_FROM_CLASS (gobject_class),
1441 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1442 _gtk_boolean_handled_accumulator, NULL,
1443 _gtk_marshal_BOOLEAN__BOXED,
1445 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1448 * GtkWidget::selection-clear-event
1449 * @widget: the object which received the signal
1450 * @event: the #GdkEventSelection which triggered this signal
1452 * The ::selection-clear-event signal will be emitted when the
1453 * the @widget's window has lost ownership of a selection.
1455 * Returns: %TRUE to stop other handlers from being invoked for the event.
1456 * %FALSE to propagate the event further.
1458 widget_signals[SELECTION_CLEAR_EVENT] =
1459 g_signal_new (I_("selection-clear-event"),
1460 G_TYPE_FROM_CLASS (gobject_class),
1462 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1463 _gtk_boolean_handled_accumulator, NULL,
1464 _gtk_marshal_BOOLEAN__BOXED,
1466 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1469 * GtkWidget::selection-request-event
1470 * @widget: the object which received the signal
1471 * @event: the #GdkEventSelection which triggered this signal
1473 * The ::selection-request-event signal will be emitted when
1474 * another client requests ownership of the selection owned by
1475 * the @widget's window.
1477 * Returns: %TRUE to stop other handlers from being invoked for the event.
1478 * %FALSE to propagate the event further.
1480 widget_signals[SELECTION_REQUEST_EVENT] =
1481 g_signal_new (I_("selection-request-event"),
1482 G_TYPE_FROM_CLASS (gobject_class),
1484 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1485 _gtk_boolean_handled_accumulator, NULL,
1486 _gtk_marshal_BOOLEAN__BOXED,
1488 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1490 widget_signals[SELECTION_NOTIFY_EVENT] =
1491 g_signal_new (I_("selection-notify-event"),
1492 G_TYPE_FROM_CLASS (gobject_class),
1494 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1495 _gtk_boolean_handled_accumulator, NULL,
1496 _gtk_marshal_BOOLEAN__BOXED,
1498 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1500 widget_signals[SELECTION_RECEIVED] =
1501 g_signal_new (I_("selection-received"),
1502 G_TYPE_FROM_CLASS (gobject_class),
1504 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1506 _gtk_marshal_VOID__BOXED_UINT,
1508 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1511 widget_signals[SELECTION_GET] =
1512 g_signal_new (I_("selection-get"),
1513 G_TYPE_FROM_CLASS (gobject_class),
1515 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1517 _gtk_marshal_VOID__BOXED_UINT_UINT,
1519 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1524 * GtkWidget::proximity-in-event
1525 * @widget: the object which received the signal
1526 * @event: the #GdkEventProximity which triggered this signal
1528 * To receive this signal the #GdkWindow associated to the widget needs
1529 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1531 * This signal will be sent to the grab widget if there is one.
1533 * Returns: %TRUE to stop other handlers from being invoked for the event.
1534 * %FALSE to propagate the event further.
1536 widget_signals[PROXIMITY_IN_EVENT] =
1537 g_signal_new (I_("proximity-in-event"),
1538 G_TYPE_FROM_CLASS (gobject_class),
1540 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1541 _gtk_boolean_handled_accumulator, NULL,
1542 _gtk_marshal_BOOLEAN__BOXED,
1544 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1547 * GtkWidget::proximity-out-event
1548 * @widget: the object which received the signal
1549 * @event: the #GdkEventProximity which triggered this signal
1551 * To receive this signal the #GdkWindow associated to the widget needs
1552 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1554 * This signal will be sent to the grab widget if there is one.
1556 * Returns: %TRUE to stop other handlers from being invoked for the event.
1557 * %FALSE to propagate the event further.
1559 widget_signals[PROXIMITY_OUT_EVENT] =
1560 g_signal_new (I_("proximity-out-event"),
1561 G_TYPE_FROM_CLASS (gobject_class),
1563 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1564 _gtk_boolean_handled_accumulator, NULL,
1565 _gtk_marshal_BOOLEAN__BOXED,
1567 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1570 * GtkWidget::drag-leave:
1571 * @widget: the object which received the signal.
1572 * @drag_context: the drag context
1573 * @time: the timestamp of the motion event
1575 * The ::drag-leave signal is emitted on the drop site when the cursor
1576 * leaves the widget. A typical reason to connect to this signal is to
1577 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1578 * with gtk_drag_unhighlight()
1580 widget_signals[DRAG_LEAVE] =
1581 g_signal_new (I_("drag-leave"),
1582 G_TYPE_FROM_CLASS (gobject_class),
1584 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1586 _gtk_marshal_VOID__OBJECT_UINT,
1588 GDK_TYPE_DRAG_CONTEXT,
1592 * GtkWidget::drag-begin:
1593 * @widget: the object which received the signal
1594 * @drag_context: the drag context
1596 * The ::drag-begin signal is emitted on the drag source when a drag is
1597 * started. A typical reason to connect to this signal is to set up a
1598 * custom drag icon with gtk_drag_source_set_icon().
1600 * Note that some widgets set up a drag icon in the default handler of
1601 * this signal, so you may have to use g_signal_connect_after() to
1602 * override what the default handler did.
1604 widget_signals[DRAG_BEGIN] =
1605 g_signal_new (I_("drag-begin"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1608 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1610 _gtk_marshal_VOID__OBJECT,
1612 GDK_TYPE_DRAG_CONTEXT);
1615 * GtkWidget::drag-end:
1616 * @widget: the object which received the signal
1617 * @drag_context: the drag context
1619 * The ::drag-end signal is emitted on the drag source when a drag is
1620 * finished. A typical reason to connect to this signal is to undo
1621 * things done in #GtkWidget::drag-begin.
1623 widget_signals[DRAG_END] =
1624 g_signal_new (I_("drag-end"),
1625 G_TYPE_FROM_CLASS (gobject_class),
1627 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1629 _gtk_marshal_VOID__OBJECT,
1631 GDK_TYPE_DRAG_CONTEXT);
1634 * GtkWidget::drag-data-delete:
1635 * @widget: the object which received the signal
1636 * @drag_context: the drag context
1638 * The ::drag-data-delete signal is emitted on the drag source when a drag
1639 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1640 * handler is responsible for deleting the data that has been dropped. What
1641 * "delete" means depends on the context of the drag operation.
1643 widget_signals[DRAG_DATA_DELETE] =
1644 g_signal_new (I_("drag-data-delete"),
1645 G_TYPE_FROM_CLASS (gobject_class),
1647 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1649 _gtk_marshal_VOID__OBJECT,
1651 GDK_TYPE_DRAG_CONTEXT);
1654 * GtkWidget::drag-failed:
1655 * @widget: the object which received the signal
1656 * @drag_context: the drag context
1657 * @result: the result of the drag operation
1659 * The ::drag-failed signal is emitted on the drag source when a drag has
1660 * failed. The signal handler may hook custom code to handle a failed DND
1661 * operation based on the type of error, it returns %TRUE is the failure has
1662 * been already handled (not showing the default "drag operation failed"
1663 * animation), otherwise it returns %FALSE.
1665 * Return value: %TRUE if the failed drag operation has been already handled.
1669 widget_signals[DRAG_FAILED] =
1670 g_signal_new (I_("drag-failed"),
1671 G_TYPE_FROM_CLASS (gobject_class),
1673 0, _gtk_boolean_handled_accumulator, NULL,
1674 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1676 GDK_TYPE_DRAG_CONTEXT,
1677 GTK_TYPE_DRAG_RESULT);
1680 * GtkWidget::drag-motion:
1681 * @widget: the object which received the signal
1682 * @drag_context: the drag context
1683 * @x: the x coordinate of the current cursor position
1684 * @y: the y coordinate of the current cursor position
1685 * @time: the timestamp of the motion event
1686 * @returns: whether the cursor position is in a drop zone
1688 * The drag-motion signal is emitted on the drop site when the user
1689 * moves the cursor over the widget during a drag. The signal handler
1690 * must determine whether the cursor position is in a drop zone or not.
1691 * If it is not in a drop zone, it returns %FALSE and no further processing
1692 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1693 * handler is responsible for providing the necessary information for
1694 * displaying feedback to the user, by calling gdk_drag_status().
1696 * If the decision whether the drop will be accepted or rejected can't be
1697 * made based solely on the cursor position and the type of the data, the
1698 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1699 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1700 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1701 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1702 * when using the drag-motion signal that way.
1704 * Also note that there is no drag-enter signal. The drag receiver has to
1705 * keep track of whether he has received any drag-motion signals since the
1706 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1707 * an "enter" signal. Upon an "enter", the handler will typically highlight
1708 * the drop site with gtk_drag_highlight().
1711 * drag_motion (GtkWidget *widget,
1712 * GdkDragContext *context,
1719 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1721 * if (!private_data->drag_highlight)
1723 * private_data->drag_highlight = 1;
1724 * gtk_drag_highlight (widget);
1727 * target = gtk_drag_dest_find_target (widget, context, NULL);
1728 * if (target == GDK_NONE)
1729 * gdk_drag_status (context, 0, time);
1732 * private_data->pending_status = context->suggested_action;
1733 * gtk_drag_get_data (widget, context, target, time);
1740 * drag_data_received (GtkWidget *widget,
1741 * GdkDragContext *context,
1744 * GtkSelectionData *selection_data,
1748 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1750 * if (private_data->suggested_action)
1752 * private_data->suggested_action = 0;
1754 * /* We are getting this data due to a request in drag_motion,
1755 * * rather than due to a request in drag_drop, so we are just
1756 * * supposed to call gdk_drag_status (), not actually paste in
1759 * str = gtk_selection_data_get_text (selection_data);
1760 * if (!data_is_acceptable (str))
1761 * gdk_drag_status (context, 0, time);
1763 * gdk_drag_status (context, private_data->suggested_action, time);
1767 * /* accept the drop */
1772 widget_signals[DRAG_MOTION] =
1773 g_signal_new (I_("drag-motion"),
1774 G_TYPE_FROM_CLASS (gobject_class),
1776 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1777 _gtk_boolean_handled_accumulator, NULL,
1778 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1780 GDK_TYPE_DRAG_CONTEXT,
1786 * GtkWidget::drag-drop:
1787 * @widget: the object which received the signal
1788 * @drag_context: the drag context
1789 * @x: the x coordinate of the current cursor position
1790 * @y: the y coordinate of the current cursor position
1791 * @time: the timestamp of the motion event
1792 * @returns: whether the cursor position is in a drop zone
1794 * The ::drag-drop signal is emitted on the drop site when the user drops
1795 * the data onto the widget. The signal handler must determine whether
1796 * the cursor position is in a drop zone or not. If it is not in a drop
1797 * zone, it returns %FALSE and no further processing is necessary.
1798 * Otherwise, the handler returns %TRUE. In this case, the handler must
1799 * ensure that gtk_drag_finish() is called to let the source know that
1800 * the drop is done. The call to gtk_drag_finish() can be done either
1801 * directly or in a #GtkWidget::drag-data-received handler which gets
1802 * triggered by calling gtk_drag_get_data() to receive the data for one
1803 * or more of the supported targets.
1805 widget_signals[DRAG_DROP] =
1806 g_signal_new (I_("drag-drop"),
1807 G_TYPE_FROM_CLASS (gobject_class),
1809 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1810 _gtk_boolean_handled_accumulator, NULL,
1811 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1813 GDK_TYPE_DRAG_CONTEXT,
1819 * GtkWidget::drag-data-get:
1820 * @widget: the object which received the signal
1821 * @drag_context: the drag context
1822 * @data: the #GtkSelectionData to be filled with the dragged data
1823 * @info: the info that has been registered with the target in the
1825 * @time: the timestamp at which the data was requested
1827 * The ::drag-data-get signal is emitted on the drag source when the drop
1828 * site requests the data which is dragged. It is the responsibility of
1829 * the signal handler to fill @data with the data in the format which
1830 * is indicated by @info. See gtk_selection_data_set() and
1831 * gtk_selection_data_set_text().
1833 widget_signals[DRAG_DATA_GET] =
1834 g_signal_new (I_("drag-data-get"),
1835 G_TYPE_FROM_CLASS (gobject_class),
1837 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1839 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1841 GDK_TYPE_DRAG_CONTEXT,
1842 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1847 * GtkWidget::drag-data-received:
1848 * @widget: the object which received the signal
1849 * @drag_context: the drag context
1850 * @x: where the drop happened
1851 * @y: where the drop happened
1852 * @data: the received data
1853 * @info: the info that has been registered with the target in the
1855 * @time: the timestamp at which the data was received
1857 * The ::drag-data-received signal is emitted on the drop site when the
1858 * dragged data has been received. If the data was received in order to
1859 * determine whether the drop will be accepted, the handler is expected
1860 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1861 * If the data was received in response to a #GtkWidget::drag-drop signal
1862 * (and this is the last target to be received), the handler for this
1863 * signal is expected to process the received data and then call
1864 * gtk_drag_finish(), setting the @success parameter depending on whether
1865 * the data was processed successfully.
1867 * The handler may inspect and modify @drag_context->action before calling
1868 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1869 * following example:
1872 * drag_data_received (GtkWidget *widget,
1873 * GdkDragContext *drag_context,
1876 * GtkSelectionData *data,
1880 * if ((data->length >= 0) && (data->format == 8))
1882 * if (drag_context->action == GDK_ACTION_ASK)
1884 * GtkWidget *dialog;
1887 * dialog = gtk_message_dialog_new (NULL,
1888 * GTK_DIALOG_MODAL |
1889 * GTK_DIALOG_DESTROY_WITH_PARENT,
1891 * GTK_BUTTONS_YES_NO,
1892 * "Move the data ?\n");
1893 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1894 * gtk_widget_destroy (dialog);
1896 * if (response == GTK_RESPONSE_YES)
1897 * drag_context->action = GDK_ACTION_MOVE;
1899 * drag_context->action = GDK_ACTION_COPY;
1902 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1906 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1910 widget_signals[DRAG_DATA_RECEIVED] =
1911 g_signal_new (I_("drag-data-received"),
1912 G_TYPE_FROM_CLASS (gobject_class),
1914 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1916 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1918 GDK_TYPE_DRAG_CONTEXT,
1921 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1926 * GtkWidget::visibility-notify-event:
1927 * @widget: the object which received the signal
1928 * @event: the #GdkEventVisibility which triggered this signal
1930 * The ::visibility-notify-event will be emitted when the @widget's window
1931 * is obscured or unobscured.
1933 * To receive this signal the #GdkWindow associated to the widget needs
1934 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1936 * Returns: %TRUE to stop other handlers from being invoked for the event.
1937 * %FALSE to propagate the event further.
1939 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1940 g_signal_new (I_("visibility-notify-event"),
1941 G_TYPE_FROM_CLASS (gobject_class),
1943 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1944 _gtk_boolean_handled_accumulator, NULL,
1945 _gtk_marshal_BOOLEAN__BOXED,
1947 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1950 * GtkWidget::client-event:
1951 * @widget: the object which received the signal
1952 * @event: the #GdkEventClient which triggered this signal
1954 * The ::client-event will be emitted when the @widget's window
1955 * receives a message (via a ClientMessage event) from another
1958 * Returns: %TRUE to stop other handlers from being invoked for
1959 * the event. %FALSE to propagate the event further.
1961 widget_signals[CLIENT_EVENT] =
1962 g_signal_new (I_("client-event"),
1963 G_TYPE_FROM_CLASS (gobject_class),
1965 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1966 _gtk_boolean_handled_accumulator, NULL,
1967 _gtk_marshal_BOOLEAN__BOXED,
1969 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1972 * GtkWidget::no-expose-event:
1973 * @widget: the object which received the signal
1974 * @event: the #GdkEventNoExpose which triggered this signal
1976 * The ::no-expose-event will be emitted when the @widget's window is
1977 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1978 * gdk_window_copy_area()) which was completely unobscured. If the source
1979 * window was partially obscured #GdkEventExpose events will be generated
1982 * Returns: %TRUE to stop other handlers from being invoked for the event.
1983 * %FALSE to propagate the event further.
1985 widget_signals[NO_EXPOSE_EVENT] =
1986 g_signal_new (I_("no-expose-event"),
1987 G_TYPE_FROM_CLASS (gobject_class),
1989 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1990 _gtk_boolean_handled_accumulator, NULL,
1991 _gtk_marshal_BOOLEAN__BOXED,
1993 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1996 * GtkWidget::window-state-event:
1997 * @widget: the object which received the signal
1998 * @event: the #GdkEventWindowState which triggered this signal
2000 * The ::window-state-event will be emitted when the state of the
2001 * toplevel window associated to the @widget changes.
2003 * To receive this signal the #GdkWindow associated to the widget
2004 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2005 * this mask automatically for all new windows.
2007 * Returns: %TRUE to stop other handlers from being invoked for the
2008 * event. %FALSE to propagate the event further.
2010 widget_signals[WINDOW_STATE_EVENT] =
2011 g_signal_new (I_("window-state-event"),
2012 G_TYPE_FROM_CLASS (gobject_class),
2014 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2015 _gtk_boolean_handled_accumulator, NULL,
2016 _gtk_marshal_BOOLEAN__BOXED,
2018 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2021 * GtkWidget::damage-event:
2022 * @widget: the object which received the signal
2023 * @event: the #GdkEventExpose event
2025 * Emitted when a redirected window belonging to @widget gets drawn into.
2026 * The region/area members of the event shows what area of the redirected
2027 * drawable was drawn into.
2029 * Returns: %TRUE to stop other handlers from being invoked for the event.
2030 * %FALSE to propagate the event further.
2034 widget_signals[DAMAGE_EVENT] =
2035 g_signal_new (I_("damage-event"),
2036 G_TYPE_FROM_CLASS (gobject_class),
2039 _gtk_boolean_handled_accumulator, NULL,
2040 _gtk_marshal_BOOLEAN__BOXED,
2042 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 * GtkWidget::grab-broken-event:
2045 * @widget: the object which received the signal
2046 * @event: the #GdkEventGrabBroken event
2048 * Emitted when a pointer or keyboard grab on a window belonging
2049 * to @widget gets broken.
2051 * On X11, this happens when the grab window becomes unviewable
2052 * (i.e. it or one of its ancestors is unmapped), or if the same
2053 * application grabs the pointer or keyboard again.
2055 * Returns: %TRUE to stop other handlers from being invoked for
2056 * the event. %FALSE to propagate the event further.
2060 widget_signals[GRAB_BROKEN] =
2061 g_signal_new (I_("grab-broken-event"),
2062 G_TYPE_FROM_CLASS (gobject_class),
2064 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2065 _gtk_boolean_handled_accumulator, NULL,
2066 _gtk_marshal_BOOLEAN__BOXED,
2068 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2070 * GtkWidget::query-tooltip:
2071 * @widget: the object which received the signal
2072 * @x: the x coordinate of the cursor position where the request has
2073 * been emitted, relative to @widget->window
2074 * @y: the y coordinate of the cursor position where the request has
2075 * been emitted, relative to @widget->window
2076 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2077 * @tooltip: a #GtkTooltip
2079 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2080 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2081 * focus in keyboard mode.
2083 * Using the given coordinates, the signal handler should determine
2084 * whether a tooltip should be shown for @widget. If this is the case
2085 * %TRUE should be returned, %FALSE otherwise. Note that if
2086 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2087 * should not be used.
2089 * The signal handler is free to manipulate @tooltip with the therefore
2090 * destined function calls.
2092 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2096 widget_signals[QUERY_TOOLTIP] =
2097 g_signal_new (I_("query-tooltip"),
2098 G_TYPE_FROM_CLASS (gobject_class),
2100 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2101 _gtk_boolean_handled_accumulator, NULL,
2102 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2110 * GtkWidget::popup-menu
2111 * @widget: the object which received the signal
2113 * This signal gets emitted whenever a widget should pop up a context
2114 * menu. This usually happens through the standard key binding mechanism;
2115 * by pressing a certain key while a widget is focused, the user can cause
2116 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2117 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2118 * for an example of how to use this signal.
2120 * Returns: %TRUE if a menu was activated
2122 widget_signals[POPUP_MENU] =
2123 g_signal_new (I_("popup-menu"),
2124 G_TYPE_FROM_CLASS (gobject_class),
2125 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2126 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2127 _gtk_boolean_handled_accumulator, NULL,
2128 _gtk_marshal_BOOLEAN__VOID,
2130 widget_signals[SHOW_HELP] =
2131 g_signal_new (I_("show-help"),
2132 G_TYPE_FROM_CLASS (gobject_class),
2133 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2134 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2135 _gtk_boolean_handled_accumulator, NULL,
2136 _gtk_marshal_BOOLEAN__ENUM,
2138 GTK_TYPE_WIDGET_HELP_TYPE);
2139 widget_signals[ACCEL_CLOSURES_CHANGED] =
2140 g_signal_new (I_("accel-closures-changed"),
2141 G_TYPE_FROM_CLASS (gobject_class),
2145 _gtk_marshal_VOID__VOID,
2149 * GtkWidget::screen-changed:
2150 * @widget: the object on which the signal is emitted
2151 * @previous_screen: the previous screen, or %NULL if the
2152 * widget was not associated with a screen before
2154 * The ::screen-changed signal gets emitted when the
2155 * screen of a widget has changed.
2157 widget_signals[SCREEN_CHANGED] =
2158 g_signal_new (I_("screen-changed"),
2159 G_TYPE_FROM_CLASS (gobject_class),
2161 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2163 _gtk_marshal_VOID__OBJECT,
2167 * GtkWidget::can-activate-accel:
2168 * @widget: the object which received the signal
2169 * @signal_id: the ID of a signal installed on @widget
2171 * Determines whether an accelerator that activates the signal
2172 * identified by @signal_id can currently be activated.
2173 * This signal is present to allow applications and derived
2174 * widgets to override the default #GtkWidget handling
2175 * for determining whether an accelerator can be activated.
2177 * Returns: %TRUE if the signal can be activated.
2179 widget_signals[CAN_ACTIVATE_ACCEL] =
2180 g_signal_new (I_("can-activate-accel"),
2181 G_TYPE_FROM_CLASS (gobject_class),
2183 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2184 _gtk_boolean_handled_accumulator, NULL,
2185 _gtk_marshal_BOOLEAN__UINT,
2186 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2188 binding_set = gtk_binding_set_by_class (klass);
2189 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2191 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2194 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2196 GTK_TYPE_WIDGET_HELP_TYPE,
2197 GTK_WIDGET_HELP_TOOLTIP);
2198 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2200 GTK_TYPE_WIDGET_HELP_TYPE,
2201 GTK_WIDGET_HELP_TOOLTIP);
2202 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2204 GTK_TYPE_WIDGET_HELP_TYPE,
2205 GTK_WIDGET_HELP_WHATS_THIS);
2206 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2208 GTK_TYPE_WIDGET_HELP_TYPE,
2209 GTK_WIDGET_HELP_WHATS_THIS);
2211 gtk_widget_class_install_style_property (klass,
2212 g_param_spec_boolean ("interior-focus",
2213 P_("Interior Focus"),
2214 P_("Whether to draw the focus indicator inside widgets"),
2216 GTK_PARAM_READABLE));
2218 gtk_widget_class_install_style_property (klass,
2219 g_param_spec_int ("focus-line-width",
2220 P_("Focus linewidth"),
2221 P_("Width, in pixels, of the focus indicator line"),
2223 GTK_PARAM_READABLE));
2225 gtk_widget_class_install_style_property (klass,
2226 g_param_spec_string ("focus-line-pattern",
2227 P_("Focus line dash pattern"),
2228 P_("Dash pattern used to draw the focus indicator"),
2230 GTK_PARAM_READABLE));
2231 gtk_widget_class_install_style_property (klass,
2232 g_param_spec_int ("focus-padding",
2233 P_("Focus padding"),
2234 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2236 GTK_PARAM_READABLE));
2237 gtk_widget_class_install_style_property (klass,
2238 g_param_spec_boxed ("cursor-color",
2240 P_("Color with which to draw insertion cursor"),
2242 GTK_PARAM_READABLE));
2243 gtk_widget_class_install_style_property (klass,
2244 g_param_spec_boxed ("secondary-cursor-color",
2245 P_("Secondary cursor color"),
2246 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2248 GTK_PARAM_READABLE));
2249 gtk_widget_class_install_style_property (klass,
2250 g_param_spec_float ("cursor-aspect-ratio",
2251 P_("Cursor line aspect ratio"),
2252 P_("Aspect ratio with which to draw insertion cursor"),
2254 GTK_PARAM_READABLE));
2257 * GtkWidget:draw-border:
2259 * The "draw-border" style property defines the size of areas outside
2260 * the widget's allocation to draw.
2264 gtk_widget_class_install_style_property (klass,
2265 g_param_spec_boxed ("draw-border",
2267 P_("Size of areas outside the widget's allocation to draw"),
2269 GTK_PARAM_READABLE));
2272 * GtkWidget:link-color:
2274 * The "link-color" style property defines the color of unvisited links.
2278 gtk_widget_class_install_style_property (klass,
2279 g_param_spec_boxed ("link-color",
2280 P_("Unvisited Link Color"),
2281 P_("Color of unvisited links"),
2283 GTK_PARAM_READABLE));
2286 * GtkWidget:visited-link-color:
2288 * The "visited-link-color" style property defines the color of visited links.
2292 gtk_widget_class_install_style_property (klass,
2293 g_param_spec_boxed ("visited-link-color",
2294 P_("Visited Link Color"),
2295 P_("Color of visited links"),
2297 GTK_PARAM_READABLE));
2300 * GtkWidget:wide-separators:
2302 * The "wide-separators" style property defines whether separators have
2303 * configurable width and should be drawn using a box instead of a line.
2307 gtk_widget_class_install_style_property (klass,
2308 g_param_spec_boolean ("wide-separators",
2309 P_("Wide Separators"),
2310 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2312 GTK_PARAM_READABLE));
2315 * GtkWidget:separator-width:
2317 * The "separator-width" style property defines the width of separators.
2318 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2322 gtk_widget_class_install_style_property (klass,
2323 g_param_spec_int ("separator-width",
2324 P_("Separator Width"),
2325 P_("The width of separators if wide-separators is TRUE"),
2327 GTK_PARAM_READABLE));
2330 * GtkWidget:separator-height:
2332 * The "separator-height" style property defines the height of separators.
2333 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2337 gtk_widget_class_install_style_property (klass,
2338 g_param_spec_int ("separator-height",
2339 P_("Separator Height"),
2340 P_("The height of separators if \"wide-separators\" is TRUE"),
2342 GTK_PARAM_READABLE));
2345 * GtkWidget:scroll-arrow-hlength:
2347 * The "scroll-arrow-hlength" style property defines the length of
2348 * horizontal scroll arrows.
2352 gtk_widget_class_install_style_property (klass,
2353 g_param_spec_int ("scroll-arrow-hlength",
2354 P_("Horizontal Scroll Arrow Length"),
2355 P_("The length of horizontal scroll arrows"),
2357 GTK_PARAM_READABLE));
2360 * GtkWidget:scroll-arrow-vlength:
2362 * The "scroll-arrow-vlength" style property defines the length of
2363 * vertical scroll arrows.
2367 gtk_widget_class_install_style_property (klass,
2368 g_param_spec_int ("scroll-arrow-vlength",
2369 P_("Vertical Scroll Arrow Length"),
2370 P_("The length of vertical scroll arrows"),
2372 GTK_PARAM_READABLE));
2376 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2380 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2381 for (node = list; node; node = node->next)
2383 GParamSpec *pspec = node->data;
2385 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2386 g_param_spec_unref (pspec);
2392 gtk_widget_set_property (GObject *object,
2394 const GValue *value,
2397 GtkWidget *widget = GTK_WIDGET (object);
2402 guint32 saved_flags;
2403 gchar *tooltip_markup;
2404 const gchar *tooltip_text;
2405 GtkWindow *tooltip_window;
2408 gtk_widget_set_name (widget, g_value_get_string (value));
2411 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2413 case PROP_WIDTH_REQUEST:
2414 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2416 case PROP_HEIGHT_REQUEST:
2417 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2420 if (g_value_get_boolean (value))
2421 gtk_widget_show (widget);
2423 gtk_widget_hide (widget);
2425 case PROP_SENSITIVE:
2426 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2428 case PROP_APP_PAINTABLE:
2429 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2431 case PROP_CAN_FOCUS:
2432 saved_flags = GTK_WIDGET_FLAGS (widget);
2433 if (g_value_get_boolean (value))
2434 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2436 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2437 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2438 gtk_widget_queue_resize (widget);
2440 case PROP_HAS_FOCUS:
2441 if (g_value_get_boolean (value))
2442 gtk_widget_grab_focus (widget);
2445 if (g_value_get_boolean (value))
2446 gtk_widget_grab_focus (widget);
2448 case PROP_CAN_DEFAULT:
2449 saved_flags = GTK_WIDGET_FLAGS (widget);
2450 if (g_value_get_boolean (value))
2451 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2453 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2454 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2455 gtk_widget_queue_resize (widget);
2457 case PROP_HAS_DEFAULT:
2458 if (g_value_get_boolean (value))
2459 gtk_widget_grab_default (widget);
2461 case PROP_RECEIVES_DEFAULT:
2462 if (g_value_get_boolean (value))
2463 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2465 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2468 gtk_widget_set_style (widget, g_value_get_object (value));
2471 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2472 gtk_widget_set_events (widget, g_value_get_flags (value));
2474 case PROP_EXTENSION_EVENTS:
2475 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2477 case PROP_NO_SHOW_ALL:
2478 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2480 case PROP_HAS_TOOLTIP:
2481 gtk_widget_real_set_has_tooltip (widget,
2482 g_value_get_boolean (value), FALSE);
2484 case PROP_TOOLTIP_MARKUP:
2485 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2486 tooltip_markup = g_value_dup_string (value);
2488 /* Treat an empty string as a NULL string,
2489 * because an empty string would be useless for a tooltip:
2491 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2493 g_free (tooltip_markup);
2494 tooltip_markup = NULL;
2497 g_object_set_qdata_full (object, quark_tooltip_markup,
2498 tooltip_markup, g_free);
2500 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2501 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2502 if (GTK_WIDGET_VISIBLE (widget))
2503 gtk_widget_queue_tooltip_query (widget);
2505 case PROP_TOOLTIP_TEXT:
2506 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2508 tooltip_text = g_value_get_string (value);
2510 /* Treat an empty string as a NULL string,
2511 * because an empty string would be useless for a tooltip:
2513 if (tooltip_text && (strlen (tooltip_text) == 0))
2514 tooltip_text = NULL;
2516 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2518 g_object_set_qdata_full (object, quark_tooltip_markup,
2519 tooltip_markup, g_free);
2521 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2522 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2523 if (GTK_WIDGET_VISIBLE (widget))
2524 gtk_widget_queue_tooltip_query (widget);
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));
2634 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2640 gtk_widget_init (GtkWidget *widget)
2642 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2643 widget->state = GTK_STATE_NORMAL;
2644 widget->saved_state = GTK_STATE_NORMAL;
2645 widget->name = NULL;
2646 widget->requisition.width = 0;
2647 widget->requisition.height = 0;
2648 widget->allocation.x = -1;
2649 widget->allocation.y = -1;
2650 widget->allocation.width = 1;
2651 widget->allocation.height = 1;
2652 widget->window = NULL;
2653 widget->parent = NULL;
2655 GTK_WIDGET_SET_FLAGS (widget,
2657 GTK_PARENT_SENSITIVE |
2658 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2659 GTK_DOUBLE_BUFFERED);
2661 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2662 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2663 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2665 widget->style = gtk_widget_get_default_style ();
2666 g_object_ref (widget->style);
2671 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2673 GParamSpec **pspecs)
2675 GtkWidget *container = widget->parent;
2678 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2679 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2683 * gtk_widget_freeze_child_notify:
2684 * @widget: a #GtkWidget
2686 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2687 * signals are queued until gtk_widget_thaw_child_notify() is called
2690 * This is the analogue of g_object_freeze_notify() for child properties.
2693 gtk_widget_freeze_child_notify (GtkWidget *widget)
2695 g_return_if_fail (GTK_IS_WIDGET (widget));
2697 if (!G_OBJECT (widget)->ref_count)
2700 g_object_ref (widget);
2701 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2702 g_object_unref (widget);
2706 * gtk_widget_child_notify:
2707 * @widget: a #GtkWidget
2708 * @child_property: the name of a child property installed on the
2709 * class of @widget<!-- -->'s parent
2711 * Emits a #GtkWidget::child-notify signal for the
2712 * <link linkend="child-properties">child property</link> @child_property
2715 * This is the analogue of g_object_notify() for child properties.
2718 gtk_widget_child_notify (GtkWidget *widget,
2719 const gchar *child_property)
2723 g_return_if_fail (GTK_IS_WIDGET (widget));
2724 g_return_if_fail (child_property != NULL);
2725 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2728 g_object_ref (widget);
2729 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2731 G_OBJECT_TYPE (widget->parent),
2734 g_warning ("%s: container class `%s' has no child property named `%s'",
2736 G_OBJECT_TYPE_NAME (widget->parent),
2740 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2742 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2743 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2745 g_object_unref (widget);
2749 * gtk_widget_thaw_child_notify:
2750 * @widget: a #GtkWidget
2752 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2753 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2757 gtk_widget_thaw_child_notify (GtkWidget *widget)
2759 GObjectNotifyQueue *nqueue;
2761 g_return_if_fail (GTK_IS_WIDGET (widget));
2763 if (!G_OBJECT (widget)->ref_count)
2766 g_object_ref (widget);
2767 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2768 if (!nqueue || !nqueue->freeze_count)
2769 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2770 G_OBJECT_TYPE_NAME (widget), widget);
2772 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2773 g_object_unref (widget);
2779 * @type: type ID of the widget to create
2780 * @first_property_name: name of first property to set
2781 * @Varargs: value of first property, followed by more properties,
2784 * This is a convenience function for creating a widget and setting
2785 * its properties in one go. For example you might write:
2786 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2787 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2788 * g_object_new(), but returns a widget so you don't have to
2789 * cast the object yourself.
2791 * Return value: a new #GtkWidget of type @widget_type
2794 gtk_widget_new (GType type,
2795 const gchar *first_property_name,
2801 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2803 va_start (var_args, first_property_name);
2804 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2812 * @widget: a #GtkWidget
2813 * @first_property_name: name of first property to set
2814 * @Varargs: value of first property, followed by more properties,
2817 * Precursor of g_object_set().
2819 * Deprecated: 2.0: Use g_object_set() instead.
2822 gtk_widget_set (GtkWidget *widget,
2823 const gchar *first_property_name,
2828 g_return_if_fail (GTK_IS_WIDGET (widget));
2830 va_start (var_args, first_property_name);
2831 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2836 gtk_widget_queue_draw_child (GtkWidget *widget)
2840 parent = widget->parent;
2841 if (parent && GTK_WIDGET_DRAWABLE (parent))
2842 gtk_widget_queue_draw_area (parent,
2843 widget->allocation.x,
2844 widget->allocation.y,
2845 widget->allocation.width,
2846 widget->allocation.height);
2850 * gtk_widget_unparent:
2851 * @widget: a #GtkWidget
2853 * This function is only for use in widget implementations.
2854 * Should be called by implementations of the remove method
2855 * on #GtkContainer, to dissociate a child from the container.
2858 gtk_widget_unparent (GtkWidget *widget)
2860 GObjectNotifyQueue *nqueue;
2861 GtkWidget *toplevel;
2862 GtkWidget *old_parent;
2864 g_return_if_fail (GTK_IS_WIDGET (widget));
2865 if (widget->parent == NULL)
2868 /* keep this function in sync with gtk_menu_detach()
2871 g_object_freeze_notify (G_OBJECT (widget));
2872 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2874 toplevel = gtk_widget_get_toplevel (widget);
2875 if (GTK_WIDGET_TOPLEVEL (toplevel))
2876 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2878 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2879 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2881 /* If we are unanchoring the child, we save around the toplevel
2882 * to emit hierarchy changed
2884 if (GTK_WIDGET_ANCHORED (widget->parent))
2885 g_object_ref (toplevel);
2889 gtk_widget_queue_draw_child (widget);
2891 /* Reset the width and height here, to force reallocation if we
2892 * get added back to a new parent. This won't work if our new
2893 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2894 * (would 0x0 be OK here?)
2896 widget->allocation.width = 1;
2897 widget->allocation.height = 1;
2899 if (GTK_WIDGET_REALIZED (widget))
2901 if (GTK_WIDGET_IN_REPARENT (widget))
2902 gtk_widget_unmap (widget);
2904 gtk_widget_unrealize (widget);
2907 /* Removing a widget from a container restores the child visible
2908 * flag to the default state, so it doesn't affect the child
2909 * in the next parent.
2911 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2913 old_parent = widget->parent;
2914 widget->parent = NULL;
2915 gtk_widget_set_parent_window (widget, NULL);
2916 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2919 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2920 g_object_unref (toplevel);
2923 g_object_notify (G_OBJECT (widget), "parent");
2924 g_object_thaw_notify (G_OBJECT (widget));
2925 if (!widget->parent)
2926 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2927 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2928 g_object_unref (widget);
2932 * gtk_widget_destroy:
2933 * @widget: a #GtkWidget
2935 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2936 * you don't have to cast the widget to #GtkObject. When a widget is
2937 * destroyed, it will break any references it holds to other objects.
2938 * If the widget is inside a container, the widget will be removed
2939 * from the container. If the widget is a toplevel (derived from
2940 * #GtkWindow), it will be removed from the list of toplevels, and the
2941 * reference GTK+ holds to it will be removed. Removing a
2942 * widget from its container or the list of toplevels results in the
2943 * widget being finalized, unless you've added additional references
2944 * to the widget with g_object_ref().
2946 * In most cases, only toplevel widgets (windows) require explicit
2947 * destruction, because when you destroy a toplevel its children will
2948 * be destroyed as well.
2951 gtk_widget_destroy (GtkWidget *widget)
2953 g_return_if_fail (GTK_IS_WIDGET (widget));
2955 gtk_object_destroy ((GtkObject*) widget);
2959 * gtk_widget_destroyed:
2960 * @widget: a #GtkWidget
2961 * @widget_pointer: address of a variable that contains @widget
2963 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2964 * %NULL. It's intended to be used as a callback connected to the
2965 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2966 * as a signal handler, and pass the address of your widget variable
2967 * as user data. Then when the widget is destroyed, the variable will
2968 * be set to %NULL. Useful for example to avoid multiple copies
2969 * of the same dialog.
2972 gtk_widget_destroyed (GtkWidget *widget,
2973 GtkWidget **widget_pointer)
2975 /* Don't make any assumptions about the
2977 * Even check widget_pointer.
2980 *widget_pointer = NULL;
2985 * @widget: a #GtkWidget
2987 * Flags a widget to be displayed. Any widget that isn't shown will
2988 * not appear on the screen. If you want to show all the widgets in a
2989 * container, it's easier to call gtk_widget_show_all() on the
2990 * container, instead of individually showing the widgets.
2992 * Remember that you have to show the containers containing a widget,
2993 * in addition to the widget itself, before it will appear onscreen.
2995 * When a toplevel container is shown, it is immediately realized and
2996 * mapped; other shown widgets are realized and mapped when their
2997 * toplevel container is realized and mapped.
3000 gtk_widget_show (GtkWidget *widget)
3002 g_return_if_fail (GTK_IS_WIDGET (widget));
3004 if (!GTK_WIDGET_VISIBLE (widget))
3006 g_object_ref (widget);
3007 if (!GTK_WIDGET_TOPLEVEL (widget))
3008 gtk_widget_queue_resize (widget);
3009 g_signal_emit (widget, widget_signals[SHOW], 0);
3010 g_object_notify (G_OBJECT (widget), "visible");
3011 g_object_unref (widget);
3016 gtk_widget_real_show (GtkWidget *widget)
3018 if (!GTK_WIDGET_VISIBLE (widget))
3020 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3022 if (widget->parent &&
3023 GTK_WIDGET_MAPPED (widget->parent) &&
3024 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3025 !GTK_WIDGET_MAPPED (widget))
3026 gtk_widget_map (widget);
3031 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3034 g_signal_handlers_disconnect_by_func (widget,
3035 gtk_widget_show_map_callback,
3040 * gtk_widget_show_now:
3041 * @widget: a #GtkWidget
3043 * Shows a widget. If the widget is an unmapped toplevel widget
3044 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3045 * loop and wait for the window to actually be mapped. Be careful;
3046 * because the main loop is running, anything can happen during
3050 gtk_widget_show_now (GtkWidget *widget)
3054 g_return_if_fail (GTK_IS_WIDGET (widget));
3056 /* make sure we will get event */
3057 if (!GTK_WIDGET_MAPPED (widget) &&
3058 GTK_WIDGET_TOPLEVEL (widget))
3060 gtk_widget_show (widget);
3062 g_signal_connect (widget, "map-event",
3063 G_CALLBACK (gtk_widget_show_map_callback),
3067 gtk_main_iteration ();
3070 gtk_widget_show (widget);
3075 * @widget: a #GtkWidget
3077 * Reverses the effects of gtk_widget_show(), causing the widget to be
3078 * hidden (invisible to the user).
3081 gtk_widget_hide (GtkWidget *widget)
3083 g_return_if_fail (GTK_IS_WIDGET (widget));
3085 if (GTK_WIDGET_VISIBLE (widget))
3087 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3089 g_object_ref (widget);
3090 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3091 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3093 g_signal_emit (widget, widget_signals[HIDE], 0);
3094 if (!GTK_WIDGET_TOPLEVEL (widget))
3095 gtk_widget_queue_resize (widget);
3096 g_object_notify (G_OBJECT (widget), "visible");
3097 g_object_unref (widget);
3102 gtk_widget_real_hide (GtkWidget *widget)
3104 if (GTK_WIDGET_VISIBLE (widget))
3106 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3108 if (GTK_WIDGET_MAPPED (widget))
3109 gtk_widget_unmap (widget);
3114 * gtk_widget_hide_on_delete:
3115 * @widget: a #GtkWidget
3117 * Utility function; intended to be connected to the #GtkWidget::delete-event
3118 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3119 * argument, then returns %TRUE. If connected to ::delete-event, the
3120 * result is that clicking the close button for a window (on the
3121 * window frame, top right corner usually) will hide but not destroy
3122 * the window. By default, GTK+ destroys windows when ::delete-event
3125 * Return value: %TRUE
3128 gtk_widget_hide_on_delete (GtkWidget *widget)
3130 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3132 gtk_widget_hide (widget);
3138 * gtk_widget_show_all:
3139 * @widget: a #GtkWidget
3141 * Recursively shows a widget, and any child widgets (if the widget is
3145 gtk_widget_show_all (GtkWidget *widget)
3147 GtkWidgetClass *class;
3149 g_return_if_fail (GTK_IS_WIDGET (widget));
3151 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3154 class = GTK_WIDGET_GET_CLASS (widget);
3156 if (class->show_all)
3157 class->show_all (widget);
3161 * gtk_widget_hide_all:
3162 * @widget: a #GtkWidget
3164 * Recursively hides a widget and any child widgets.
3167 gtk_widget_hide_all (GtkWidget *widget)
3169 GtkWidgetClass *class;
3171 g_return_if_fail (GTK_IS_WIDGET (widget));
3173 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3176 class = GTK_WIDGET_GET_CLASS (widget);
3178 if (class->hide_all)
3179 class->hide_all (widget);
3184 * @widget: a #GtkWidget
3186 * This function is only for use in widget implementations. Causes
3187 * a widget to be mapped if it isn't already.
3190 gtk_widget_map (GtkWidget *widget)
3192 g_return_if_fail (GTK_IS_WIDGET (widget));
3193 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3194 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3196 if (!GTK_WIDGET_MAPPED (widget))
3198 if (!GTK_WIDGET_REALIZED (widget))
3199 gtk_widget_realize (widget);
3201 g_signal_emit (widget, widget_signals[MAP], 0);
3203 if (GTK_WIDGET_NO_WINDOW (widget))
3204 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3210 * @widget: a #GtkWidget
3212 * This function is only for use in widget implementations. Causes
3213 * a widget to be unmapped if it's currently mapped.
3216 gtk_widget_unmap (GtkWidget *widget)
3218 g_return_if_fail (GTK_IS_WIDGET (widget));
3220 if (GTK_WIDGET_MAPPED (widget))
3222 if (GTK_WIDGET_NO_WINDOW (widget))
3223 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3224 _gtk_tooltip_hide (widget);
3225 g_signal_emit (widget, widget_signals[UNMAP], 0);
3230 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3231 GdkExtensionMode mode,
3234 GList *free_list = NULL;
3237 if (window_list == NULL)
3239 if (!GTK_WIDGET_NO_WINDOW (widget))
3240 window_list = g_list_prepend (NULL, widget->window);
3242 window_list = gdk_window_get_children (widget->window);
3244 free_list = window_list;
3247 for (l = window_list; l != NULL; l = l->next)
3249 GdkWindow *window = l->data;
3252 gdk_window_get_user_data (window, &user_data);
3253 if (user_data == widget)
3257 gdk_input_set_extension_events (window,
3258 gdk_window_get_events (window),
3261 children = gdk_window_get_children (window);
3264 gtk_widget_set_extension_events_internal (widget, mode, children);
3265 g_list_free (children);
3271 g_list_free (free_list);
3275 * gtk_widget_realize:
3276 * @widget: a #GtkWidget
3278 * Creates the GDK (windowing system) resources associated with a
3279 * widget. For example, @widget->window will be created when a widget
3280 * is realized. Normally realization happens implicitly; if you show
3281 * a widget and all its parent containers, then the widget will be
3282 * realized and mapped automatically.
3284 * Realizing a widget requires all
3285 * the widget's parent widgets to be realized; calling
3286 * gtk_widget_realize() realizes the widget's parents in addition to
3287 * @widget itself. If a widget is not yet inside a toplevel window
3288 * when you realize it, bad things will happen.
3290 * This function is primarily used in widget implementations, and
3291 * isn't very useful otherwise. Many times when you think you might
3292 * need it, a better approach is to connect to a signal that will be
3293 * called after the widget is realized automatically, such as
3294 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3295 * GtkWidget::realize signal.
3298 gtk_widget_realize (GtkWidget *widget)
3300 GdkExtensionMode mode;
3301 GtkWidgetShapeInfo *shape_info;
3303 g_return_if_fail (GTK_IS_WIDGET (widget));
3304 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3305 GTK_IS_INVISIBLE (widget));
3307 if (!GTK_WIDGET_REALIZED (widget))
3310 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3311 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3314 if (widget->parent == NULL &&
3315 !GTK_WIDGET_TOPLEVEL (widget))
3316 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3317 "inside a toplevel window is not going to work very well. "
3318 "Widgets must be inside a toplevel container before realizing them.");
3320 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3321 gtk_widget_realize (widget->parent);
3323 gtk_widget_ensure_style (widget);
3325 g_signal_emit (widget, widget_signals[REALIZE], 0);
3327 gtk_widget_real_set_has_tooltip (widget,
3328 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3331 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3333 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3334 gdk_window_shape_combine_mask (widget->window,
3335 shape_info->shape_mask,
3336 shape_info->offset_x,
3337 shape_info->offset_y);
3340 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3342 gdk_window_input_shape_combine_mask (widget->window,
3343 shape_info->shape_mask,
3344 shape_info->offset_x,
3345 shape_info->offset_y);
3347 mode = gtk_widget_get_extension_events (widget);
3348 if (mode != GDK_EXTENSION_EVENTS_NONE)
3349 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3354 * gtk_widget_unrealize:
3355 * @widget: a #GtkWidget
3357 * This function is only useful in widget implementations.
3358 * Causes a widget to be unrealized (frees all GDK resources
3359 * associated with the widget, such as @widget->window).
3362 gtk_widget_unrealize (GtkWidget *widget)
3364 g_return_if_fail (GTK_IS_WIDGET (widget));
3366 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3367 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3369 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3370 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3372 if (GTK_WIDGET_REALIZED (widget))
3374 g_object_ref (widget);
3375 _gtk_tooltip_hide (widget);
3376 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3377 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3378 g_object_unref (widget);
3382 /*****************************************
3384 *****************************************/
3387 * gtk_widget_queue_draw_area:
3388 * @widget: a #GtkWidget
3389 * @x: x coordinate of upper-left corner of rectangle to redraw
3390 * @y: y coordinate of upper-left corner of rectangle to redraw
3391 * @width: width of region to draw
3392 * @height: height of region to draw
3394 * Invalidates the rectangular area of @widget defined by @x, @y,
3395 * @width and @height by calling gdk_window_invalidate_rect() on the
3396 * widget's window and all its child windows. Once the main loop
3397 * becomes idle (after the current batch of events has been processed,
3398 * roughly), the window will receive expose events for the union of
3399 * all regions that have been invalidated.
3401 * Normally you would only use this function in widget
3402 * implementations. You might also use it, or
3403 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3404 * #GtkDrawingArea or some portion thereof.
3406 * Frequently you can just call gdk_window_invalidate_rect() or
3407 * gdk_window_invalidate_region() instead of this function. Those
3408 * functions will invalidate only a single window, instead of the
3409 * widget and all its children.
3411 * The advantage of adding to the invalidated region compared to
3412 * simply drawing immediately is efficiency; using an invalid region
3413 * ensures that you only have to redraw one time.
3416 gtk_widget_queue_draw_area (GtkWidget *widget,
3422 GdkRectangle invalid_rect;
3425 g_return_if_fail (GTK_IS_WIDGET (widget));
3427 if (!GTK_WIDGET_REALIZED (widget))
3430 /* Just return if the widget or one of its ancestors isn't mapped */
3431 for (w = widget; w != NULL; w = w->parent)
3432 if (!GTK_WIDGET_MAPPED (w))
3435 /* Find the correct widget */
3437 if (!GTK_WIDGET_NO_WINDOW (widget))
3441 /* Translate widget relative to window-relative */
3443 gint wx, wy, wwidth, wheight;
3445 gdk_window_get_position (widget->window, &wx, &wy);
3446 x -= wx - widget->allocation.x;
3447 y -= wy - widget->allocation.y;
3449 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3451 if (x + width <= 0 || y + height <= 0 ||
3452 x >= wwidth || y >= wheight)
3463 if (x + width > wwidth)
3465 if (y + height > wheight)
3466 height = wheight - y;
3472 invalid_rect.width = width;
3473 invalid_rect.height = height;
3475 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3479 widget_add_child_draw_rectangle (GtkWidget *widget,
3482 GdkRectangle child_rect;
3484 if (!GTK_WIDGET_MAPPED (widget) ||
3485 widget->window != widget->parent->window)
3488 gtk_widget_get_draw_rectangle (widget, &child_rect);
3489 gdk_rectangle_union (rect, &child_rect, rect);
3493 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3496 if (GTK_WIDGET_NO_WINDOW (widget))
3498 GtkBorder *draw_border = NULL;
3500 *rect = widget->allocation;
3502 gtk_widget_style_get (widget,
3503 "draw-border", &draw_border,
3507 rect->x -= draw_border->left;
3508 rect->y -= draw_border->top;
3509 rect->width += draw_border->left + draw_border->right;
3510 rect->height += draw_border->top + draw_border->bottom;
3512 gtk_border_free (draw_border);
3515 if (GTK_IS_CONTAINER (widget))
3516 gtk_container_forall (GTK_CONTAINER (widget),
3517 (GtkCallback)widget_add_child_draw_rectangle,
3524 rect->width = widget->allocation.width;
3525 rect->height = widget->allocation.height;
3530 * gtk_widget_queue_draw:
3531 * @widget: a #GtkWidget
3533 * Equivalent to calling gtk_widget_queue_draw_area() for the
3534 * entire area of a widget.
3537 gtk_widget_queue_draw (GtkWidget *widget)
3541 g_return_if_fail (GTK_IS_WIDGET (widget));
3543 gtk_widget_get_draw_rectangle (widget, &rect);
3545 gtk_widget_queue_draw_area (widget,
3547 rect.width, rect.height);
3550 /* Invalidates the given area (allocation-relative-coordinates)
3551 * in all of the widget's windows
3554 * gtk_widget_queue_clear_area:
3555 * @widget: a #GtkWidget
3556 * @x: x coordinate of upper-left corner of rectangle to redraw
3557 * @y: y coordinate of upper-left corner of rectangle to redraw
3558 * @width: width of region to draw
3559 * @height: height of region to draw
3561 * This function is no longer different from
3562 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3563 * gtk_widget_queue_draw_area(). Originally
3564 * gtk_widget_queue_clear_area() would force a redraw of the
3565 * background for %GTK_NO_WINDOW widgets, and
3566 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3567 * the background will be redrawn.
3569 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3572 gtk_widget_queue_clear_area (GtkWidget *widget,
3578 g_return_if_fail (GTK_IS_WIDGET (widget));
3580 gtk_widget_queue_draw_area (widget, x, y, width, height);
3584 * gtk_widget_queue_clear:
3585 * @widget: a #GtkWidget
3587 * This function does the same as gtk_widget_queue_draw().
3589 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3592 gtk_widget_queue_clear (GtkWidget *widget)
3594 g_return_if_fail (GTK_IS_WIDGET (widget));
3596 gtk_widget_queue_draw (widget);
3600 * gtk_widget_queue_resize:
3601 * @widget: a #GtkWidget
3603 * This function is only for use in widget implementations.
3604 * Flags a widget to have its size renegotiated; should
3605 * be called when a widget for some reason has a new size request.
3606 * For example, when you change the text in a #GtkLabel, #GtkLabel
3607 * queues a resize to ensure there's enough space for the new text.
3610 gtk_widget_queue_resize (GtkWidget *widget)
3612 g_return_if_fail (GTK_IS_WIDGET (widget));
3614 if (GTK_WIDGET_REALIZED (widget))
3615 gtk_widget_queue_shallow_draw (widget);
3617 _gtk_size_group_queue_resize (widget);
3621 * gtk_widget_queue_resize_no_redraw:
3622 * @widget: a #GtkWidget
3624 * This function works like gtk_widget_queue_resize(),
3625 * except that the widget is not invalidated.
3630 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3632 g_return_if_fail (GTK_IS_WIDGET (widget));
3634 _gtk_size_group_queue_resize (widget);
3639 * @widget: a #GtkWidget
3640 * @area: area to draw
3642 * In GTK+ 1.2, this function would immediately render the
3643 * region @area of a widget, by invoking the virtual draw method of a
3644 * widget. In GTK+ 2.0, the draw method is gone, and instead
3645 * gtk_widget_draw() simply invalidates the specified region of the
3646 * widget, then updates the invalid region of the widget immediately.
3647 * Usually you don't want to update the region immediately for
3648 * performance reasons, so in general gtk_widget_queue_draw_area() is
3649 * a better choice if you want to draw a region of a widget.
3652 gtk_widget_draw (GtkWidget *widget,
3653 const GdkRectangle *area)
3655 g_return_if_fail (GTK_IS_WIDGET (widget));
3657 if (GTK_WIDGET_DRAWABLE (widget))
3660 gtk_widget_queue_draw_area (widget,
3662 area->width, area->height);
3664 gtk_widget_queue_draw (widget);
3666 gdk_window_process_updates (widget->window, TRUE);
3671 * gtk_widget_size_request:
3672 * @widget: a #GtkWidget
3673 * @requisition: a #GtkRequisition to be filled in
3675 * This function is typically used when implementing a #GtkContainer
3676 * subclass. Obtains the preferred size of a widget. The container
3677 * uses this information to arrange its child widgets and decide what
3678 * size allocations to give them with gtk_widget_size_allocate().
3680 * You can also call this function from an application, with some
3681 * caveats. Most notably, getting a size request requires the widget
3682 * to be associated with a screen, because font information may be
3683 * needed. Multihead-aware applications should keep this in mind.
3685 * Also remember that the size request is not necessarily the size
3686 * a widget will actually be allocated.
3688 * See also gtk_widget_get_child_requisition().
3691 gtk_widget_size_request (GtkWidget *widget,
3692 GtkRequisition *requisition)
3694 g_return_if_fail (GTK_IS_WIDGET (widget));
3696 #ifdef G_ENABLE_DEBUG
3697 if (requisition == &widget->requisition)
3698 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.");
3699 #endif /* G_ENABLE_DEBUG */
3701 _gtk_size_group_compute_requisition (widget, requisition);
3705 * gtk_widget_get_child_requisition:
3706 * @widget: a #GtkWidget
3707 * @requisition: a #GtkRequisition to be filled in
3709 * This function is only for use in widget implementations. Obtains
3710 * @widget->requisition, unless someone has forced a particular
3711 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3712 * in which case it returns that geometry instead of the widget's
3715 * This function differs from gtk_widget_size_request() in that
3716 * it retrieves the last size request value from @widget->requisition,
3717 * while gtk_widget_size_request() actually calls the "size_request" method
3718 * on @widget to compute the size request and fill in @widget->requisition,
3719 * and only then returns @widget->requisition.
3721 * Because this function does not call the "size_request" method, it
3722 * can only be used when you know that @widget->requisition is
3723 * up-to-date, that is, gtk_widget_size_request() has been called
3724 * since the last time a resize was queued. In general, only container
3725 * implementations have this information; applications should use
3726 * gtk_widget_size_request().
3729 gtk_widget_get_child_requisition (GtkWidget *widget,
3730 GtkRequisition *requisition)
3732 _gtk_size_group_get_child_requisition (widget, requisition);
3736 invalidate_predicate (GdkWindow *window,
3741 gdk_window_get_user_data (window, &user_data);
3743 return (user_data == data);
3746 /* Invalidate @region in widget->window and all children
3747 * of widget->window owned by widget. @region is in the
3748 * same coordinates as widget->allocation and will be
3749 * modified by this call.
3752 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3755 if (!GTK_WIDGET_REALIZED (widget))
3758 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3762 gdk_window_get_position (widget->window, &x, &y);
3763 gdk_region_offset (region, -x, -y);
3766 gdk_window_invalidate_maybe_recurse (widget->window, region,
3767 invalidate_predicate, widget);
3771 * gtk_widget_queue_shallow_draw:
3772 * @widget: a #GtkWidget
3774 * Like gtk_widget_queue_draw(), but only windows owned
3775 * by @widget are invalidated.
3778 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3783 if (!GTK_WIDGET_REALIZED (widget))
3786 gtk_widget_get_draw_rectangle (widget, &rect);
3788 /* get_draw_rectangle() gives us window coordinates, we
3789 * need to convert to the coordinates that widget->allocation
3792 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3796 gdk_window_get_position (widget->window, &wx, &wy);
3802 region = gdk_region_rectangle (&rect);
3803 gtk_widget_invalidate_widget_windows (widget, region);
3804 gdk_region_destroy (region);
3808 * gtk_widget_size_allocate:
3809 * @widget: a #GtkWidget
3810 * @allocation: position and size to be allocated to @widget
3812 * This function is only used by #GtkContainer subclasses, to assign a size
3813 * and position to their child widgets.
3816 gtk_widget_size_allocate (GtkWidget *widget,
3817 GtkAllocation *allocation)
3819 GtkWidgetAuxInfo *aux_info;
3820 GdkRectangle real_allocation;
3821 GdkRectangle old_allocation;
3822 gboolean alloc_needed;
3823 gboolean size_changed;
3824 gboolean position_changed;
3826 g_return_if_fail (GTK_IS_WIDGET (widget));
3828 #ifdef G_ENABLE_DEBUG
3829 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3840 parent = gtk_widget_get_parent (parent);
3843 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3844 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3845 2 * depth, " ", name,
3846 allocation->width, allocation->height);
3848 #endif /* G_ENABLE_DEBUG */
3850 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3851 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3852 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3854 old_allocation = widget->allocation;
3855 real_allocation = *allocation;
3856 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3860 if (aux_info->x_set)
3861 real_allocation.x = aux_info->x;
3862 if (aux_info->y_set)
3863 real_allocation.y = aux_info->y;
3866 if (real_allocation.width < 0 || real_allocation.height < 0)
3868 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3869 real_allocation.width,
3870 real_allocation.height);
3873 real_allocation.width = MAX (real_allocation.width, 1);
3874 real_allocation.height = MAX (real_allocation.height, 1);
3876 size_changed = (old_allocation.width != real_allocation.width ||
3877 old_allocation.height != real_allocation.height);
3878 position_changed = (old_allocation.x != real_allocation.x ||
3879 old_allocation.y != real_allocation.y);
3881 if (!alloc_needed && !size_changed && !position_changed)
3884 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3886 if (GTK_WIDGET_MAPPED (widget))
3888 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3890 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3892 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3893 gdk_region_union_with_rect (invalidate, &old_allocation);
3895 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3896 gdk_region_destroy (invalidate);
3901 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3903 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3905 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3906 gdk_region_union_with_rect (invalidate, &old_allocation);
3908 gtk_widget_invalidate_widget_windows (widget, invalidate);
3909 gdk_region_destroy (invalidate);
3914 if ((size_changed || position_changed) && widget->parent &&
3915 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3917 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3918 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3919 gdk_region_destroy (invalidate);
3924 * gtk_widget_common_ancestor:
3925 * @widget_a: a #GtkWidget
3926 * @widget_b: a #GtkWidget
3928 * Find the common ancestor of @widget_a and @widget_b that
3929 * is closest to the two widgets.
3931 * Return value: the closest common ancestor of @widget_a and
3932 * @widget_b or %NULL if @widget_a and @widget_b do not
3933 * share a common ancestor.
3936 gtk_widget_common_ancestor (GtkWidget *widget_a,
3937 GtkWidget *widget_b)
3939 GtkWidget *parent_a;
3940 GtkWidget *parent_b;
3944 parent_a = widget_a;
3945 while (parent_a->parent)
3947 parent_a = parent_a->parent;
3951 parent_b = widget_b;
3952 while (parent_b->parent)
3954 parent_b = parent_b->parent;
3958 if (parent_a != parent_b)
3961 while (depth_a > depth_b)
3963 widget_a = widget_a->parent;
3967 while (depth_b > depth_a)
3969 widget_b = widget_b->parent;
3973 while (widget_a != widget_b)
3975 widget_a = widget_a->parent;
3976 widget_b = widget_b->parent;
3983 * gtk_widget_translate_coordinates:
3984 * @src_widget: a #GtkWidget
3985 * @dest_widget: a #GtkWidget
3986 * @src_x: X position relative to @src_widget
3987 * @src_y: Y position relative to @src_widget
3988 * @dest_x: location to store X position relative to @dest_widget
3989 * @dest_y: location to store Y position relative to @dest_widget
3991 * Translate coordinates relative to @src_widget's allocation to coordinates
3992 * relative to @dest_widget's allocations. In order to perform this
3993 * operation, both widgets must be realized, and must share a common
3996 * Return value: %FALSE if either widget was not realized, or there
3997 * was no common ancestor. In this case, nothing is stored in
3998 * *@dest_x and *@dest_y. Otherwise %TRUE.
4001 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4002 GtkWidget *dest_widget,
4008 GtkWidget *ancestor;
4011 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4012 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4014 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4015 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4018 /* Translate from allocation relative to window relative */
4019 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4022 gdk_window_get_position (src_widget->window, &wx, &wy);
4024 src_x -= wx - src_widget->allocation.x;
4025 src_y -= wy - src_widget->allocation.y;
4029 src_x += src_widget->allocation.x;
4030 src_y += src_widget->allocation.y;
4033 /* Translate to the common ancestor */
4034 window = src_widget->window;
4035 while (window != ancestor->window)
4039 gdk_window_get_position (window, &dx, &dy);
4044 window = gdk_window_get_parent (window);
4046 if (!window) /* Handle GtkHandleBox */
4051 window = dest_widget->window;
4052 while (window != ancestor->window)
4056 gdk_window_get_position (window, &dx, &dy);
4061 window = gdk_window_get_parent (window);
4063 if (!window) /* Handle GtkHandleBox */
4067 /* Translate from window relative to allocation relative */
4068 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4071 gdk_window_get_position (dest_widget->window, &wx, &wy);
4073 src_x += wx - dest_widget->allocation.x;
4074 src_y += wy - dest_widget->allocation.y;
4078 src_x -= dest_widget->allocation.x;
4079 src_y -= dest_widget->allocation.y;
4091 gtk_widget_real_size_allocate (GtkWidget *widget,
4092 GtkAllocation *allocation)
4094 widget->allocation = *allocation;
4096 if (GTK_WIDGET_REALIZED (widget) &&
4097 !GTK_WIDGET_NO_WINDOW (widget))
4099 gdk_window_move_resize (widget->window,
4100 allocation->x, allocation->y,
4101 allocation->width, allocation->height);
4106 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4109 /* widgets must be onscreen for accels to take effect */
4110 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4114 * gtk_widget_can_activate_accel:
4115 * @widget: a #GtkWidget
4116 * @signal_id: the ID of a signal installed on @widget
4118 * Determines whether an accelerator that activates the signal
4119 * identified by @signal_id can currently be activated.
4120 * This is done by emitting the #GtkWidget::can-activate-accel
4121 * signal on @widget; if the signal isn't overridden by a
4122 * handler or in a derived widget, then the default check is
4123 * that the widget must be sensitive, and the widget and all
4124 * its ancestors mapped.
4126 * Return value: %TRUE if the accelerator can be activated.
4131 gtk_widget_can_activate_accel (GtkWidget *widget,
4134 gboolean can_activate = FALSE;
4135 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4136 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4137 return can_activate;
4146 closure_accel_activate (GClosure *closure,
4147 GValue *return_value,
4148 guint n_param_values,
4149 const GValue *param_values,
4150 gpointer invocation_hint,
4151 gpointer marshal_data)
4153 AccelClosure *aclosure = (AccelClosure*) closure;
4154 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4157 g_signal_emit (closure->data, aclosure->signal_id, 0);
4159 /* whether accelerator was handled */
4160 g_value_set_boolean (return_value, can_activate);
4164 closures_destroy (gpointer data)
4166 GSList *slist, *closures = data;
4168 for (slist = closures; slist; slist = slist->next)
4170 g_closure_invalidate (slist->data);
4171 g_closure_unref (slist->data);
4173 g_slist_free (closures);
4177 widget_new_accel_closure (GtkWidget *widget,
4180 AccelClosure *aclosure;
4181 GClosure *closure = NULL;
4182 GSList *slist, *closures;
4184 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4185 for (slist = closures; slist; slist = slist->next)
4186 if (!gtk_accel_group_from_accel_closure (slist->data))
4188 /* reuse this closure */
4189 closure = slist->data;
4194 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4195 closures = g_slist_prepend (closures, g_closure_ref (closure));
4196 g_closure_sink (closure);
4197 g_closure_set_marshal (closure, closure_accel_activate);
4199 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4201 aclosure = (AccelClosure*) closure;
4202 g_assert (closure->data == widget);
4203 g_assert (closure->marshal == closure_accel_activate);
4204 aclosure->signal_id = signal_id;
4210 * gtk_widget_add_accelerator
4211 * @widget: widget to install an accelerator on
4212 * @accel_signal: widget signal to emit on accelerator activation
4213 * @accel_group: accel group for this widget, added to its toplevel
4214 * @accel_key: GDK keyval of the accelerator
4215 * @accel_mods: modifier key combination of the accelerator
4216 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4218 * Installs an accelerator for this @widget in @accel_group that causes
4219 * @accel_signal to be emitted if the accelerator is activated.
4220 * The @accel_group needs to be added to the widget's toplevel via
4221 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4222 * Accelerators added through this function are not user changeable during
4223 * runtime. If you want to support accelerators that can be changed by the
4224 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4225 * gtk_menu_item_set_accel_path() instead.
4228 gtk_widget_add_accelerator (GtkWidget *widget,
4229 const gchar *accel_signal,
4230 GtkAccelGroup *accel_group,
4232 GdkModifierType accel_mods,
4233 GtkAccelFlags accel_flags)
4238 g_return_if_fail (GTK_IS_WIDGET (widget));
4239 g_return_if_fail (accel_signal != NULL);
4240 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4242 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4243 if (!query.signal_id ||
4244 !(query.signal_flags & G_SIGNAL_ACTION) ||
4245 query.return_type != G_TYPE_NONE ||
4248 /* hmm, should be elaborate enough */
4249 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4250 G_OBJECT_TYPE_NAME (widget), accel_signal);
4254 closure = widget_new_accel_closure (widget, query.signal_id);
4256 g_object_ref (widget);
4258 /* install the accelerator. since we don't map this onto an accel_path,
4259 * the accelerator will automatically be locked.
4261 gtk_accel_group_connect (accel_group,
4264 accel_flags | GTK_ACCEL_LOCKED,
4267 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4269 g_object_unref (widget);
4273 * gtk_widget_remove_accelerator:
4274 * @widget: widget to install an accelerator on
4275 * @accel_group: accel group for this widget
4276 * @accel_key: GDK keyval of the accelerator
4277 * @accel_mods: modifier key combination of the accelerator
4278 * @returns: whether an accelerator was installed and could be removed
4280 * Removes an accelerator from @widget, previously installed with
4281 * gtk_widget_add_accelerator().
4284 gtk_widget_remove_accelerator (GtkWidget *widget,
4285 GtkAccelGroup *accel_group,
4287 GdkModifierType accel_mods)
4289 GtkAccelGroupEntry *ag_entry;
4290 GList *slist, *clist;
4293 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4294 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4296 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4297 clist = gtk_widget_list_accel_closures (widget);
4298 for (slist = clist; slist; slist = slist->next)
4302 for (i = 0; i < n; i++)
4303 if (slist->data == (gpointer) ag_entry[i].closure)
4305 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4307 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4309 g_list_free (clist);
4314 g_list_free (clist);
4316 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4317 accel_key, accel_mods, accel_group,
4318 G_OBJECT_TYPE_NAME (widget), widget);
4324 * gtk_widget_list_accel_closures
4325 * @widget: widget to list accelerator closures for
4326 * @returns: a newly allocated #GList of closures
4328 * Lists the closures used by @widget for accelerator group connections
4329 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4330 * The closures can be used to monitor accelerator changes on @widget,
4331 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4332 * #GtkAccelGroup of a closure which can be found out with
4333 * gtk_accel_group_from_accel_closure().
4336 gtk_widget_list_accel_closures (GtkWidget *widget)
4339 GList *clist = NULL;
4341 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4343 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4344 if (gtk_accel_group_from_accel_closure (slist->data))
4345 clist = g_list_prepend (clist, slist->data);
4351 GtkAccelGroup *accel_group;
4356 destroy_accel_path (gpointer data)
4358 AccelPath *apath = data;
4360 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4362 /* closures_destroy takes care of unrefing the closure */
4363 g_object_unref (apath->accel_group);
4365 g_slice_free (AccelPath, apath);
4370 * gtk_widget_set_accel_path:
4371 * @widget: a #GtkWidget
4372 * @accel_path: path used to look up the accelerator
4373 * @accel_group: a #GtkAccelGroup.
4375 * Given an accelerator group, @accel_group, and an accelerator path,
4376 * @accel_path, sets up an accelerator in @accel_group so whenever the
4377 * key binding that is defined for @accel_path is pressed, @widget
4378 * will be activated. This removes any accelerators (for any
4379 * accelerator group) installed by previous calls to
4380 * gtk_widget_set_accel_path(). Associating accelerators with
4381 * paths allows them to be modified by the user and the modifications
4382 * to be saved for future use. (See gtk_accel_map_save().)
4384 * This function is a low level function that would most likely
4385 * be used by a menu creation system like #GtkUIManager. If you
4386 * use #GtkUIManager, setting up accelerator paths will be done
4389 * Even when you you aren't using #GtkUIManager, if you only want to
4390 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4391 * provides a somewhat more convenient interface.
4393 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4394 * pass a static string, you can save some memory by interning it first with
4395 * g_intern_static_string().
4398 gtk_widget_set_accel_path (GtkWidget *widget,
4399 const gchar *accel_path,
4400 GtkAccelGroup *accel_group)
4404 g_return_if_fail (GTK_IS_WIDGET (widget));
4405 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4409 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4410 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4412 gtk_accel_map_add_entry (accel_path, 0, 0);
4413 apath = g_slice_new (AccelPath);
4414 apath->accel_group = g_object_ref (accel_group);
4415 apath->path_quark = g_quark_from_string (accel_path);
4416 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4421 /* also removes possible old settings */
4422 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4425 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4427 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4431 _gtk_widget_get_accel_path (GtkWidget *widget,
4436 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4438 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4440 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4441 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4445 * gtk_widget_mnemonic_activate:
4446 * @widget: a #GtkWidget
4447 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
4449 * Emits the #GtkWidget::mnemonic-activate signal.
4451 * The default handler for this signal activates the @widget if
4452 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
4455 * Returns: %TRUE if the signal has been handled
4458 gtk_widget_mnemonic_activate (GtkWidget *widget,
4459 gboolean group_cycling)
4463 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4465 group_cycling = group_cycling != FALSE;
4466 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4469 g_signal_emit (widget,
4470 widget_signals[MNEMONIC_ACTIVATE],
4478 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4479 gboolean group_cycling)
4481 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4482 gtk_widget_activate (widget);
4483 else if (GTK_WIDGET_CAN_FOCUS (widget))
4484 gtk_widget_grab_focus (widget);
4487 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4488 G_OBJECT_TYPE_NAME (widget));
4489 gtk_widget_error_bell (widget);
4495 gtk_widget_real_key_press_event (GtkWidget *widget,
4498 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4502 gtk_widget_real_key_release_event (GtkWidget *widget,
4505 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4509 gtk_widget_real_focus_in_event (GtkWidget *widget,
4510 GdkEventFocus *event)
4512 gtk_widget_queue_shallow_draw (widget);
4518 gtk_widget_real_focus_out_event (GtkWidget *widget,
4519 GdkEventFocus *event)
4521 gtk_widget_queue_shallow_draw (widget);
4526 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4527 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4531 * @widget: a #GtkWidget
4532 * @event: a #GdkEvent
4534 * Rarely-used function. This function is used to emit
4535 * the event signals on a widget (those signals should never
4536 * be emitted without using this function to do so).
4537 * If you want to synthesize an event though, don't use this function;
4538 * instead, use gtk_main_do_event() so the event will behave as if
4539 * it were in the event queue. Don't synthesize expose events; instead,
4540 * use gdk_window_invalidate_rect() to invalidate a region of the
4543 * Return value: return from the event signal emission (%TRUE if
4544 * the event was handled)
4547 gtk_widget_event (GtkWidget *widget,
4550 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4551 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4553 if (event->type == GDK_EXPOSE)
4555 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4556 "the same effect, call gdk_window_invalidate_rect/region(), "
4557 "followed by gdk_window_process_updates().");
4561 return gtk_widget_event_internal (widget, event);
4566 * gtk_widget_send_expose:
4567 * @widget: a #GtkWidget
4568 * @event: a expose #GdkEvent
4570 * Very rarely-used function. This function is used to emit
4571 * an expose event signals on a widget. This function is not
4572 * normally used directly. The only time it is used is when
4573 * propagating an expose event to a child %NO_WINDOW widget, and
4574 * that is normally done using gtk_container_propagate_expose().
4576 * If you want to force an area of a window to be redrawn,
4577 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4578 * To cause the redraw to be done immediately, follow that call
4579 * with a call to gdk_window_process_updates().
4581 * Return value: return from the event signal emission (%TRUE if
4582 * the event was handled)
4585 gtk_widget_send_expose (GtkWidget *widget,
4588 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4589 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4590 g_return_val_if_fail (event != NULL, TRUE);
4591 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4593 return gtk_widget_event_internal (widget, event);
4597 event_window_is_still_viewable (GdkEvent *event)
4599 /* Some programs, such as gnome-theme-manager, fake widgets
4600 * into exposing onto a pixmap by sending expose events with
4601 * event->window pointing to a pixmap
4603 if (GDK_IS_PIXMAP (event->any.window))
4604 return event->type == GDK_EXPOSE;
4606 /* Check that we think the event's window is viewable before
4607 * delivering the event, to prevent suprises. We do this here
4608 * at the last moment, since the event may have been queued
4609 * up behind other events, held over a recursive main loop, etc.
4611 switch (event->type)
4614 case GDK_MOTION_NOTIFY:
4615 case GDK_BUTTON_PRESS:
4616 case GDK_2BUTTON_PRESS:
4617 case GDK_3BUTTON_PRESS:
4619 case GDK_ENTER_NOTIFY:
4620 case GDK_PROXIMITY_IN:
4622 return event->any.window && gdk_window_is_viewable (event->any.window);
4625 /* The following events are the second half of paired events;
4626 * we always deliver them to deal with widgets that clean up
4627 * on the second half.
4629 case GDK_BUTTON_RELEASE:
4630 case GDK_KEY_RELEASE:
4631 case GDK_LEAVE_NOTIFY:
4632 case GDK_PROXIMITY_OUT:
4636 /* Remaining events would make sense on an not-viewable window,
4637 * or don't have an associated window.
4644 gtk_widget_event_internal (GtkWidget *widget,
4647 gboolean return_val = FALSE;
4649 /* We check only once for is-still-visible; if someone
4650 * hides the window in on of the signals on the widget,
4651 * they are responsible for returning TRUE to terminate
4654 if (!event_window_is_still_viewable (event))
4657 g_object_ref (widget);
4659 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4660 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4665 switch (event->type)
4670 case GDK_BUTTON_PRESS:
4671 case GDK_2BUTTON_PRESS:
4672 case GDK_3BUTTON_PRESS:
4673 signal_num = BUTTON_PRESS_EVENT;
4676 signal_num = SCROLL_EVENT;
4678 case GDK_BUTTON_RELEASE:
4679 signal_num = BUTTON_RELEASE_EVENT;
4681 case GDK_MOTION_NOTIFY:
4682 signal_num = MOTION_NOTIFY_EVENT;
4685 signal_num = DELETE_EVENT;
4688 signal_num = DESTROY_EVENT;
4689 _gtk_tooltip_hide (widget);
4692 signal_num = KEY_PRESS_EVENT;
4694 case GDK_KEY_RELEASE:
4695 signal_num = KEY_RELEASE_EVENT;
4697 case GDK_ENTER_NOTIFY:
4698 signal_num = ENTER_NOTIFY_EVENT;
4700 case GDK_LEAVE_NOTIFY:
4701 signal_num = LEAVE_NOTIFY_EVENT;
4703 case GDK_FOCUS_CHANGE:
4704 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4705 if (event->focus_change.in)
4706 _gtk_tooltip_focus_in (widget);
4708 _gtk_tooltip_focus_out (widget);
4711 signal_num = CONFIGURE_EVENT;
4714 signal_num = MAP_EVENT;
4717 signal_num = UNMAP_EVENT;
4719 case GDK_WINDOW_STATE:
4720 signal_num = WINDOW_STATE_EVENT;
4722 case GDK_PROPERTY_NOTIFY:
4723 signal_num = PROPERTY_NOTIFY_EVENT;
4725 case GDK_SELECTION_CLEAR:
4726 signal_num = SELECTION_CLEAR_EVENT;
4728 case GDK_SELECTION_REQUEST:
4729 signal_num = SELECTION_REQUEST_EVENT;
4731 case GDK_SELECTION_NOTIFY:
4732 signal_num = SELECTION_NOTIFY_EVENT;
4734 case GDK_PROXIMITY_IN:
4735 signal_num = PROXIMITY_IN_EVENT;
4737 case GDK_PROXIMITY_OUT:
4738 signal_num = PROXIMITY_OUT_EVENT;
4741 signal_num = NO_EXPOSE_EVENT;
4743 case GDK_CLIENT_EVENT:
4744 signal_num = CLIENT_EVENT;
4747 signal_num = EXPOSE_EVENT;
4749 case GDK_VISIBILITY_NOTIFY:
4750 signal_num = VISIBILITY_NOTIFY_EVENT;
4752 case GDK_GRAB_BROKEN:
4753 signal_num = GRAB_BROKEN;
4756 signal_num = DAMAGE_EVENT;
4759 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4763 if (signal_num != -1)
4764 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4766 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4767 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4771 g_object_unref (widget);
4777 * gtk_widget_activate:
4778 * @widget: a #GtkWidget that's activatable
4780 * For widgets that can be "activated" (buttons, menu items, etc.)
4781 * this function activates them. Activation is what happens when you
4782 * press Enter on a widget during key navigation. If @widget isn't
4783 * activatable, the function returns %FALSE.
4785 * Return value: %TRUE if the widget was activatable
4788 gtk_widget_activate (GtkWidget *widget)
4790 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4792 if (WIDGET_CLASS (widget)->activate_signal)
4794 /* FIXME: we should eventually check the signals signature here */
4795 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4804 * gtk_widget_set_scroll_adjustments:
4805 * @widget: a #GtkWidget
4806 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4807 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4809 * For widgets that support scrolling, sets the scroll adjustments and
4810 * returns %TRUE. For widgets that don't support scrolling, does
4811 * nothing and returns %FALSE. Widgets that don't support scrolling
4812 * can be scrolled by placing them in a #GtkViewport, which does
4813 * support scrolling.
4815 * Return value: %TRUE if the widget supports scrolling
4818 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4819 GtkAdjustment *hadjustment,
4820 GtkAdjustment *vadjustment)
4825 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4828 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4830 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4832 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
4836 g_signal_query (signal_id, &query);
4837 if (!query.signal_id ||
4838 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
4839 query.return_type != G_TYPE_NONE ||
4840 query.n_params != 2 ||
4841 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
4842 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
4844 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
4845 G_OBJECT_TYPE_NAME (widget), query.signal_name);
4849 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
4854 gtk_widget_reparent_subwindows (GtkWidget *widget,
4855 GdkWindow *new_window)
4857 if (GTK_WIDGET_NO_WINDOW (widget))
4859 GList *children = gdk_window_get_children (widget->window);
4862 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4864 GdkWindow *window = tmp_list->data;
4867 gdk_window_get_user_data (window, &child);
4868 while (child && child != widget)
4869 child = ((GtkWidget*) child)->parent;
4872 gdk_window_reparent (window, new_window, 0, 0);
4875 g_list_free (children);
4880 GList *tmp_list, *children;
4882 parent = gdk_window_get_parent (widget->window);
4885 gdk_window_reparent (widget->window, new_window, 0, 0);
4888 children = gdk_window_get_children (parent);
4890 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4892 GdkWindow *window = tmp_list->data;
4895 gdk_window_get_user_data (window, &child);
4897 if (child == widget)
4898 gdk_window_reparent (window, new_window, 0, 0);
4901 g_list_free (children);
4907 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4908 gpointer client_data)
4910 g_assert (client_data != NULL);
4912 if (GTK_WIDGET_NO_WINDOW (widget))
4915 g_object_unref (widget->window);
4916 widget->window = (GdkWindow*) client_data;
4918 g_object_ref (widget->window);
4920 if (GTK_IS_CONTAINER (widget))
4921 gtk_container_forall (GTK_CONTAINER (widget),
4922 gtk_widget_reparent_fixup_child,
4928 * gtk_widget_reparent:
4929 * @widget: a #GtkWidget
4930 * @new_parent: a #GtkContainer to move the widget into
4932 * Moves a widget from one #GtkContainer to another, handling reference
4933 * count issues to avoid destroying the widget.
4936 gtk_widget_reparent (GtkWidget *widget,
4937 GtkWidget *new_parent)
4939 g_return_if_fail (GTK_IS_WIDGET (widget));
4940 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4941 g_return_if_fail (widget->parent != NULL);
4943 if (widget->parent != new_parent)
4945 /* First try to see if we can get away without unrealizing
4946 * the widget as we reparent it. if so we set a flag so
4947 * that gtk_widget_unparent doesn't unrealize widget
4949 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4950 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4952 g_object_ref (widget);
4953 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4954 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4955 g_object_unref (widget);
4957 if (GTK_WIDGET_IN_REPARENT (widget))
4959 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4961 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4962 gtk_widget_reparent_fixup_child (widget,
4963 gtk_widget_get_parent_window (widget));
4966 g_object_notify (G_OBJECT (widget), "parent");
4971 * gtk_widget_intersect:
4972 * @widget: a #GtkWidget
4973 * @area: a rectangle
4974 * @intersection: rectangle to store intersection of @widget and @area
4976 * Computes the intersection of a @widget's area and @area, storing
4977 * the intersection in @intersection, and returns %TRUE if there was
4978 * an intersection. @intersection may be %NULL if you're only
4979 * interested in whether there was an intersection.
4981 * Return value: %TRUE if there was an intersection
4984 gtk_widget_intersect (GtkWidget *widget,
4985 const GdkRectangle *area,
4986 GdkRectangle *intersection)
4992 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4993 g_return_val_if_fail (area != NULL, FALSE);
4996 dest = intersection;
5000 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
5002 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
5004 intersection->x -= widget->allocation.x;
5005 intersection->y -= widget->allocation.y;
5012 * gtk_widget_region_intersect:
5013 * @widget: a #GtkWidget
5014 * @region: a #GdkRegion, in the same coordinate system as
5015 * @widget->allocation. That is, relative to @widget->window
5016 * for %NO_WINDOW widgets; relative to the parent window
5017 * of @widget->window for widgets with their own window.
5018 * @returns: A newly allocated region holding the intersection of @widget
5019 * and @region. The coordinates of the return value are
5020 * relative to @widget->window for %NO_WINDOW widgets, and
5021 * relative to the parent window of @widget->window for
5022 * widgets with their own window.
5024 * Computes the intersection of a @widget's area and @region, returning
5025 * the intersection. The result may be empty, use gdk_region_empty() to
5029 gtk_widget_region_intersect (GtkWidget *widget,
5030 const GdkRegion *region)
5035 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5036 g_return_val_if_fail (region != NULL, NULL);
5038 gtk_widget_get_draw_rectangle (widget, &rect);
5040 dest = gdk_region_rectangle (&rect);
5042 gdk_region_intersect (dest, region);
5048 * _gtk_widget_grab_notify:
5049 * @widget: a #GtkWidget
5050 * @was_grabbed: whether a grab is now in effect
5052 * Emits the #GtkWidget::grab-notify signal on @widget.
5057 _gtk_widget_grab_notify (GtkWidget *widget,
5058 gboolean was_grabbed)
5060 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5064 * gtk_widget_grab_focus:
5065 * @widget: a #GtkWidget
5067 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5068 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5069 * something like #GtkFrame won't work. (More precisely, it must have the
5070 * %GTK_CAN_FOCUS flag set.)
5073 gtk_widget_grab_focus (GtkWidget *widget)
5075 g_return_if_fail (GTK_IS_WIDGET (widget));
5077 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5080 g_object_ref (widget);
5081 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5082 g_object_notify (G_OBJECT (widget), "has-focus");
5083 g_object_unref (widget);
5087 reset_focus_recurse (GtkWidget *widget,
5090 if (GTK_IS_CONTAINER (widget))
5092 GtkContainer *container;
5094 container = GTK_CONTAINER (widget);
5095 gtk_container_set_focus_child (container, NULL);
5097 gtk_container_foreach (container,
5098 reset_focus_recurse,
5104 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5106 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5108 GtkWidget *toplevel;
5111 /* clear the current focus setting, break if the current widget
5112 * is the focus widget's parent, since containers above that will
5113 * be set by the next loop.
5115 toplevel = gtk_widget_get_toplevel (focus_widget);
5116 if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
5118 widget = GTK_WINDOW (toplevel)->focus_widget;
5120 if (widget == focus_widget)
5122 /* We call _gtk_window_internal_set_focus() here so that the
5123 * toplevel window can request the focus if necessary.
5124 * This is needed when the toplevel is a GtkPlug
5126 if (!GTK_WIDGET_HAS_FOCUS (widget))
5127 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5134 while (widget->parent && widget->parent != focus_widget->parent)
5136 widget = widget->parent;
5137 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5141 else if (toplevel != focus_widget)
5143 /* gtk_widget_grab_focus() operates on a tree without window...
5144 * actually, this is very questionable behaviour.
5147 gtk_container_foreach (GTK_CONTAINER (toplevel),
5148 reset_focus_recurse,
5152 /* now propagate the new focus up the widget tree and finally
5153 * set it on the window
5155 widget = focus_widget;
5156 while (widget->parent)
5158 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5159 widget = widget->parent;
5161 if (GTK_IS_WINDOW (widget))
5162 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5167 gtk_widget_real_query_tooltip (GtkWidget *widget,
5170 gboolean keyboard_tip,
5171 GtkTooltip *tooltip)
5173 gchar *tooltip_markup;
5174 gboolean has_tooltip;
5176 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5177 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5179 if (has_tooltip && tooltip_markup)
5181 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5189 gtk_widget_real_show_help (GtkWidget *widget,
5190 GtkWidgetHelpType help_type)
5192 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5194 _gtk_tooltip_toggle_keyboard_mode (widget);
5203 gtk_widget_real_focus (GtkWidget *widget,
5204 GtkDirectionType direction)
5206 if (!GTK_WIDGET_CAN_FOCUS (widget))
5209 if (!gtk_widget_is_focus (widget))
5211 gtk_widget_grab_focus (widget);
5219 gtk_widget_real_move_focus (GtkWidget *widget,
5220 GtkDirectionType direction)
5222 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5224 if (GTK_IS_WINDOW (toplevel) &&
5225 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5227 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5233 gtk_widget_real_keynav_failed (GtkWidget *widget,
5234 GtkDirectionType direction)
5236 gboolean cursor_only;
5240 case GTK_DIR_TAB_FORWARD:
5241 case GTK_DIR_TAB_BACKWARD:
5248 g_object_get (gtk_widget_get_settings (widget),
5249 "gtk-keynav-cursor-only", &cursor_only,
5256 gtk_widget_error_bell (widget);
5262 * gtk_widget_is_focus:
5263 * @widget: a #GtkWidget
5265 * Determines if the widget is the focus widget within its
5266 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5267 * necessarily set; %HAS_FOCUS will only be set if the
5268 * toplevel widget additionally has the global input focus.)
5270 * Return value: %TRUE if the widget is the focus widget.
5273 gtk_widget_is_focus (GtkWidget *widget)
5275 GtkWidget *toplevel;
5277 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5279 toplevel = gtk_widget_get_toplevel (widget);
5281 if (GTK_IS_WINDOW (toplevel))
5282 return widget == GTK_WINDOW (toplevel)->focus_widget;
5288 * gtk_widget_grab_default:
5289 * @widget: a #GtkWidget
5291 * Causes @widget to become the default widget. @widget must have the
5292 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5293 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5294 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5295 * the user presses Enter in a window. Default widgets must be
5296 * activatable, that is, gtk_widget_activate() should affect them.
5299 gtk_widget_grab_default (GtkWidget *widget)
5303 g_return_if_fail (GTK_IS_WIDGET (widget));
5304 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5306 window = gtk_widget_get_toplevel (widget);
5308 if (window && GTK_WIDGET_TOPLEVEL (window))
5309 gtk_window_set_default (GTK_WINDOW (window), widget);
5311 g_warning (G_STRLOC ": widget not within a GtkWindow");
5315 * gtk_widget_set_name:
5316 * @widget: a #GtkWidget
5317 * @name: name for the widget
5319 * Widgets can be named, which allows you to refer to them from a
5320 * gtkrc file. You can apply a style to widgets with a particular name
5321 * in the gtkrc file. See the documentation for gtkrc files (on the
5322 * same page as the docs for #GtkRcStyle).
5324 * Note that widget names are separated by periods in paths (see
5325 * gtk_widget_path()), so names with embedded periods may cause confusion.
5328 gtk_widget_set_name (GtkWidget *widget,
5333 g_return_if_fail (GTK_IS_WIDGET (widget));
5335 new_name = g_strdup (name);
5336 g_free (widget->name);
5337 widget->name = new_name;
5339 if (GTK_WIDGET_RC_STYLE (widget))
5340 gtk_widget_reset_rc_style (widget);
5342 g_object_notify (G_OBJECT (widget), "name");
5346 * gtk_widget_get_name:
5347 * @widget: a #GtkWidget
5349 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5350 * significance of widget names.
5352 * Return value: name of the widget. This string is owned by GTK+ and
5353 * should not be modified or freed
5355 G_CONST_RETURN gchar*
5356 gtk_widget_get_name (GtkWidget *widget)
5358 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5361 return widget->name;
5362 return g_type_name (GTK_WIDGET_TYPE (widget));
5366 * gtk_widget_set_state:
5367 * @widget: a #GtkWidget
5368 * @state: new state for @widget
5370 * This function is for use in widget implementations. Sets the state
5371 * of a widget (insensitive, prelighted, etc.) Usually you should set
5372 * the state using wrapper functions such as gtk_widget_set_sensitive().
5375 gtk_widget_set_state (GtkWidget *widget,
5378 g_return_if_fail (GTK_IS_WIDGET (widget));
5380 if (state == GTK_WIDGET_STATE (widget))
5383 if (state == GTK_STATE_INSENSITIVE)
5384 gtk_widget_set_sensitive (widget, FALSE);
5390 data.state_restoration = FALSE;
5391 data.use_forall = FALSE;
5393 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5395 data.parent_sensitive = TRUE;
5397 gtk_widget_propagate_state (widget, &data);
5399 if (GTK_WIDGET_DRAWABLE (widget))
5400 gtk_widget_queue_draw (widget);
5406 * gtk_widget_set_app_paintable:
5407 * @widget: a #GtkWidget
5408 * @app_paintable: %TRUE if the application will paint on the widget
5410 * Sets whether the application intends to draw on the widget in
5411 * an #GtkWidget::expose-event handler.
5413 * This is a hint to the widget and does not affect the behavior of
5414 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5415 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5416 * the effect is to suppress default themed drawing of the widget's
5417 * background. (Children of the widget will still be drawn.) The application
5418 * is then entirely responsible for drawing the widget background.
5420 * Note that the background is still drawn when the widget is mapped.
5421 * If this is not suitable (e.g. because you want to make a transparent
5422 * window using an RGBA visual), you can work around this by doing:
5424 * gtk_widget_realize (window);
5425 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5426 * gtk_widget_show (window);
5430 gtk_widget_set_app_paintable (GtkWidget *widget,
5431 gboolean app_paintable)
5433 g_return_if_fail (GTK_IS_WIDGET (widget));
5435 app_paintable = (app_paintable != FALSE);
5437 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5440 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5442 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5444 if (GTK_WIDGET_DRAWABLE (widget))
5445 gtk_widget_queue_draw (widget);
5447 g_object_notify (G_OBJECT (widget), "app-paintable");
5452 * gtk_widget_set_double_buffered:
5453 * @widget: a #GtkWidget
5454 * @double_buffered: %TRUE to double-buffer a widget
5456 * Widgets are double buffered by default; you can use this function
5457 * to turn off the buffering. "Double buffered" simply means that
5458 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5459 * automatically around expose events sent to the
5460 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5461 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5462 * buffer to the screen. The result is that users see the window
5463 * update in one smooth step, and don't see individual graphics
5464 * primitives being rendered.
5466 * In very simple terms, double buffered widgets don't flicker,
5467 * so you would only use this function to turn off double buffering
5468 * if you had special needs and really knew what you were doing.
5470 * Note: if you turn off double-buffering, you have to handle
5471 * expose events, since even the clearing to the background color or
5472 * pixmap will not happen automatically (as it is done in
5473 * gdk_window_begin_paint()).
5476 gtk_widget_set_double_buffered (GtkWidget *widget,
5477 gboolean double_buffered)
5479 g_return_if_fail (GTK_IS_WIDGET (widget));
5481 if (double_buffered)
5482 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5484 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5488 * gtk_widget_set_redraw_on_allocate:
5489 * @widget: a #GtkWidget
5490 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5491 * when it is allocated to a new size. Otherwise, only the
5492 * new portion of the widget will be redrawn.
5494 * Sets whether the entire widget is queued for drawing when its size
5495 * allocation changes. By default, this setting is %TRUE and
5496 * the entire widget is redrawn on every size change. If your widget
5497 * leaves the upper left unchanged when made bigger, turning this
5498 * setting off will improve performance.
5500 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5501 * off all allocation on resizing: the widget will not even redraw if
5502 * its position changes; this is to allow containers that don't draw
5503 * anything to avoid excess invalidations. If you set this flag on a
5504 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5505 * you are responsible for invalidating both the old and new allocation
5506 * of the widget when the widget is moved and responsible for invalidating
5507 * regions newly when the widget increases size.
5510 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5511 gboolean redraw_on_allocate)
5513 g_return_if_fail (GTK_IS_WIDGET (widget));
5515 if (redraw_on_allocate)
5516 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5518 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5522 * gtk_widget_set_sensitive:
5523 * @widget: a #GtkWidget
5524 * @sensitive: %TRUE to make the widget sensitive
5526 * Sets the sensitivity of a widget. A widget is sensitive if the user
5527 * can interact with it. Insensitive widgets are "grayed out" and the
5528 * user can't interact with them. Insensitive widgets are known as
5529 * "inactive", "disabled", or "ghosted" in some other toolkits.
5532 gtk_widget_set_sensitive (GtkWidget *widget,
5537 g_return_if_fail (GTK_IS_WIDGET (widget));
5539 sensitive = (sensitive != FALSE);
5541 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5546 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5547 data.state = GTK_WIDGET_SAVED_STATE (widget);
5551 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5552 data.state = GTK_WIDGET_STATE (widget);
5554 data.state_restoration = TRUE;
5555 data.use_forall = TRUE;
5558 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5560 data.parent_sensitive = TRUE;
5562 gtk_widget_propagate_state (widget, &data);
5563 if (GTK_WIDGET_DRAWABLE (widget))
5564 gtk_widget_queue_draw (widget);
5566 g_object_notify (G_OBJECT (widget), "sensitive");
5570 * gtk_widget_set_parent:
5571 * @widget: a #GtkWidget
5572 * @parent: parent container
5574 * This function is useful only when implementing subclasses of
5576 * Sets the container as the parent of @widget, and takes care of
5577 * some details such as updating the state and style of the child
5578 * to reflect its new location. The opposite function is
5579 * gtk_widget_unparent().
5582 gtk_widget_set_parent (GtkWidget *widget,
5587 g_return_if_fail (GTK_IS_WIDGET (widget));
5588 g_return_if_fail (GTK_IS_WIDGET (parent));
5589 g_return_if_fail (widget != parent);
5590 if (widget->parent != NULL)
5592 g_warning ("Can't set a parent on widget which has a parent\n");
5595 if (GTK_WIDGET_TOPLEVEL (widget))
5597 g_warning ("Can't set a parent on a toplevel widget\n");
5601 /* keep this function in sync with gtk_menu_attach_to_widget()
5604 g_object_ref_sink (widget);
5605 widget->parent = parent;
5607 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5608 data.state = GTK_WIDGET_STATE (parent);
5610 data.state = GTK_WIDGET_STATE (widget);
5611 data.state_restoration = FALSE;
5612 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5613 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5615 gtk_widget_propagate_state (widget, &data);
5617 gtk_widget_reset_rc_styles (widget);
5619 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5620 if (GTK_WIDGET_ANCHORED (widget->parent))
5621 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5622 g_object_notify (G_OBJECT (widget), "parent");
5624 /* Enforce realized/mapped invariants
5626 if (GTK_WIDGET_REALIZED (widget->parent))
5627 gtk_widget_realize (widget);
5629 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5630 GTK_WIDGET_VISIBLE (widget))
5632 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5633 GTK_WIDGET_MAPPED (widget->parent))
5634 gtk_widget_map (widget);
5636 gtk_widget_queue_resize (widget);
5641 * gtk_widget_get_parent:
5642 * @widget: a #GtkWidget
5644 * Returns the parent container of @widget.
5646 * Return value: the parent container of @widget, or %NULL
5649 gtk_widget_get_parent (GtkWidget *widget)
5651 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5653 return widget->parent;
5656 /*****************************************
5658 * see docs/styles.txt
5659 *****************************************/
5662 * gtk_widget_set_style:
5663 * @widget: a #GtkWidget
5664 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5665 * gtk_widget_set_style() and go back to the default style
5667 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5668 * want to use this function; it interacts badly with themes, because
5669 * themes work by replacing the #GtkStyle. Instead, use
5670 * gtk_widget_modify_style().
5673 gtk_widget_set_style (GtkWidget *widget,
5676 g_return_if_fail (GTK_IS_WIDGET (widget));
5680 gboolean initial_emission;
5682 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5684 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5685 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5687 gtk_widget_set_style_internal (widget, style, initial_emission);
5691 if (GTK_WIDGET_USER_STYLE (widget))
5692 gtk_widget_reset_rc_style (widget);
5697 * gtk_widget_ensure_style:
5698 * @widget: a #GtkWidget
5700 * Ensures that @widget has a style (@widget->style). Not a very useful
5701 * function; most of the time, if you want the style, the widget is
5702 * realized, and realized widgets are guaranteed to have a style
5706 gtk_widget_ensure_style (GtkWidget *widget)
5708 g_return_if_fail (GTK_IS_WIDGET (widget));
5710 if (!GTK_WIDGET_USER_STYLE (widget) &&
5711 !GTK_WIDGET_RC_STYLE (widget))
5712 gtk_widget_reset_rc_style (widget);
5715 /* Look up the RC style for this widget, unsetting any user style that
5716 * may be in effect currently
5719 gtk_widget_reset_rc_style (GtkWidget *widget)
5721 GtkStyle *new_style = NULL;
5722 gboolean initial_emission;
5724 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5726 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5727 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5729 if (gtk_widget_has_screen (widget))
5730 new_style = gtk_rc_get_style (widget);
5732 new_style = gtk_widget_get_default_style ();
5734 if (initial_emission || new_style != widget->style)
5735 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5739 * gtk_widget_get_style:
5740 * @widget: a #GtkWidget
5742 * Simply an accessor function that returns @widget->style.
5744 * Return value: the widget's #GtkStyle
5747 gtk_widget_get_style (GtkWidget *widget)
5749 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5751 return widget->style;
5755 * gtk_widget_modify_style:
5756 * @widget: a #GtkWidget
5757 * @style: the #GtkRcStyle holding the style modifications
5759 * Modifies style values on the widget. Modifications made using this
5760 * technique take precedence over style values set via an RC file,
5761 * however, they will be overriden if a style is explicitely set on
5762 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5763 * is designed so each field can either be set or unset, so it is
5764 * possible, using this function, to modify some style values and
5765 * leave the others unchanged.
5767 * Note that modifications made with this function are not cumulative
5768 * with previous calls to gtk_widget_modify_style() or with such
5769 * functions as gtk_widget_modify_fg(). If you wish to retain
5770 * previous values, you must first call gtk_widget_get_modifier_style(),
5771 * make your modifications to the returned style, then call
5772 * gtk_widget_modify_style() with that style. On the other hand,
5773 * if you first call gtk_widget_modify_style(), subsequent calls
5774 * to such functions gtk_widget_modify_fg() will have a cumulative
5775 * effect with the initial modifications.
5778 gtk_widget_modify_style (GtkWidget *widget,
5781 g_return_if_fail (GTK_IS_WIDGET (widget));
5782 g_return_if_fail (GTK_IS_RC_STYLE (style));
5784 g_object_set_qdata_full (G_OBJECT (widget),
5786 gtk_rc_style_copy (style),
5787 (GDestroyNotify) g_object_unref);
5789 /* note that "style" may be invalid here if it was the old
5790 * modifier style and the only reference was our own.
5793 if (GTK_WIDGET_RC_STYLE (widget))
5794 gtk_widget_reset_rc_style (widget);
5798 * gtk_widget_get_modifier_style:
5799 * @widget: a #GtkWidget
5801 * Returns the current modifier style for the widget. (As set by
5802 * gtk_widget_modify_style().) If no style has previously set, a new
5803 * #GtkRcStyle will be created with all values unset, and set as the
5804 * modifier style for the widget. If you make changes to this rc
5805 * style, you must call gtk_widget_modify_style(), passing in the
5806 * returned rc style, to make sure that your changes take effect.
5808 * Caution: passing the style back to gtk_widget_modify_style() will
5809 * normally end up destroying it, because gtk_widget_modify_style() copies
5810 * the passed-in style and sets the copy as the new modifier style,
5811 * thus dropping any reference to the old modifier style. Add a reference
5812 * to the modifier style if you want to keep it alive.
5814 * Return value: the modifier style for the widget. This rc style is
5815 * owned by the widget. If you want to keep a pointer to value this
5816 * around, you must add a refcount using g_object_ref().
5819 gtk_widget_get_modifier_style (GtkWidget *widget)
5821 GtkRcStyle *rc_style;
5823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5825 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5829 rc_style = gtk_rc_style_new ();
5830 g_object_set_qdata_full (G_OBJECT (widget),
5833 (GDestroyNotify) g_object_unref);
5840 gtk_widget_modify_color_component (GtkWidget *widget,
5841 GtkRcFlags component,
5843 const GdkColor *color)
5845 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5852 rc_style->fg[state] = *color;
5855 rc_style->bg[state] = *color;
5858 rc_style->text[state] = *color;
5861 rc_style->base[state] = *color;
5864 g_assert_not_reached();
5867 rc_style->color_flags[state] |= component;
5870 rc_style->color_flags[state] &= ~component;
5872 gtk_widget_modify_style (widget, rc_style);
5876 * gtk_widget_modify_fg:
5877 * @widget: a #GtkWidget
5878 * @state: the state for which to set the foreground color
5879 * @color: the color to assign (does not need to be allocated),
5880 * or %NULL to undo the effect of previous calls to
5881 * of gtk_widget_modify_fg().
5883 * Sets the foreground color for a widget in a particular state.
5884 * All other style values are left untouched. See also
5885 * gtk_widget_modify_style().
5888 gtk_widget_modify_fg (GtkWidget *widget,
5890 const GdkColor *color)
5892 g_return_if_fail (GTK_IS_WIDGET (widget));
5893 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5895 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5899 * gtk_widget_modify_bg:
5900 * @widget: a #GtkWidget
5901 * @state: the state for which to set the background color
5902 * @color: the color to assign (does not need to be allocated),
5903 * or %NULL to undo the effect of previous calls to
5904 * of gtk_widget_modify_bg().
5906 * Sets the background color for a widget in a particular state.
5907 * All other style values are left untouched. See also
5908 * gtk_widget_modify_style().
5910 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5911 * draw on their parent container's window and thus may not draw any
5912 * background themselves. This is the case for e.g. #GtkLabel. To modify
5913 * the background of such widgets, you have to set the background color
5914 * on their parent; if you want to set the background of a rectangular
5915 * area around a label, try placing the label in a #GtkEventBox widget
5916 * and setting the background color on that.
5919 gtk_widget_modify_bg (GtkWidget *widget,
5921 const GdkColor *color)
5923 g_return_if_fail (GTK_IS_WIDGET (widget));
5924 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5926 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5930 * gtk_widget_modify_text:
5931 * @widget: a #GtkWidget
5932 * @state: the state for which to set the text color
5933 * @color: the color to assign (does not need to be allocated),
5934 * or %NULL to undo the effect of previous calls to
5935 * of gtk_widget_modify_text().
5937 * Sets the text color for a widget in a particular state. All other
5938 * style values are left untouched. The text color is the foreground
5939 * color used along with the base color (see gtk_widget_modify_base())
5940 * for widgets such as #GtkEntry and #GtkTextView. See also
5941 * gtk_widget_modify_style().
5944 gtk_widget_modify_text (GtkWidget *widget,
5946 const GdkColor *color)
5948 g_return_if_fail (GTK_IS_WIDGET (widget));
5949 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5951 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5955 * gtk_widget_modify_base:
5956 * @widget: a #GtkWidget
5957 * @state: the state for which to set the base color
5958 * @color: the color to assign (does not need to be allocated),
5959 * or %NULL to undo the effect of previous calls to
5960 * of gtk_widget_modify_base().
5962 * Sets the base color for a widget in a particular state.
5963 * All other style values are left untouched. The base color
5964 * is the background color used along with the text color
5965 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5966 * and #GtkTextView. See also gtk_widget_modify_style().
5968 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5969 * draw on their parent container's window and thus may not draw any
5970 * background themselves. This is the case for e.g. #GtkLabel. To modify
5971 * the background of such widgets, you have to set the base color on their
5972 * parent; if you want to set the background of a rectangular area around
5973 * a label, try placing the label in a #GtkEventBox widget and setting
5974 * the base color on that.
5977 gtk_widget_modify_base (GtkWidget *widget,
5979 const GdkColor *color)
5981 g_return_if_fail (GTK_IS_WIDGET (widget));
5982 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5984 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5988 modify_color_property (GtkWidget *widget,
5989 GtkRcStyle *rc_style,
5991 const GdkColor *color)
5993 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5994 GQuark property_name = g_quark_from_string (name);
5998 GtkRcProperty rc_property = {0};
6001 rc_property.type_name = type_name;
6002 rc_property.property_name = property_name;
6003 rc_property.origin = NULL;
6005 color_name = gdk_color_to_string (color);
6006 g_value_init (&rc_property.value, G_TYPE_STRING);
6007 g_value_take_string (&rc_property.value, color_name);
6009 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
6011 g_value_unset (&rc_property.value);
6014 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
6018 * gtk_widget_modify_cursor:
6019 * @widget: a #GtkWidget
6020 * @primary: the color to use for primary cursor (does not need to be
6021 * allocated), or %NULL to undo the effect of previous calls to
6022 * of gtk_widget_modify_cursor().
6023 * @secondary: the color to use for secondary cursor (does not need to be
6024 * allocated), or %NULL to undo the effect of previous calls to
6025 * of gtk_widget_modify_cursor().
6027 * Sets the cursor color to use in a widget, overriding the
6028 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6029 * style properties. All other style values are left untouched.
6030 * See also gtk_widget_modify_style().
6035 gtk_widget_modify_cursor (GtkWidget *widget,
6036 const GdkColor *primary,
6037 const GdkColor *secondary)
6039 GtkRcStyle *rc_style;
6041 g_return_if_fail (GTK_IS_WIDGET (widget));
6043 rc_style = gtk_widget_get_modifier_style (widget);
6045 modify_color_property (widget, rc_style, "cursor-color", primary);
6046 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6048 gtk_widget_modify_style (widget, rc_style);
6052 * gtk_widget_modify_font:
6053 * @widget: a #GtkWidget
6054 * @font_desc: the font description to use, or %NULL to undo
6055 * the effect of previous calls to gtk_widget_modify_font().
6057 * Sets the font to use for a widget. All other style values are left
6058 * untouched. See also gtk_widget_modify_style().
6061 gtk_widget_modify_font (GtkWidget *widget,
6062 PangoFontDescription *font_desc)
6064 GtkRcStyle *rc_style;
6066 g_return_if_fail (GTK_IS_WIDGET (widget));
6068 rc_style = gtk_widget_get_modifier_style (widget);
6070 if (rc_style->font_desc)
6071 pango_font_description_free (rc_style->font_desc);
6074 rc_style->font_desc = pango_font_description_copy (font_desc);
6076 rc_style->font_desc = NULL;
6078 gtk_widget_modify_style (widget, rc_style);
6082 gtk_widget_real_direction_changed (GtkWidget *widget,
6083 GtkTextDirection previous_direction)
6085 gtk_widget_queue_resize (widget);
6089 gtk_widget_real_style_set (GtkWidget *widget,
6090 GtkStyle *previous_style)
6092 if (GTK_WIDGET_REALIZED (widget) &&
6093 !GTK_WIDGET_NO_WINDOW (widget))
6094 gtk_style_set_background (widget->style, widget->window, widget->state);
6098 gtk_widget_set_style_internal (GtkWidget *widget,
6100 gboolean initial_emission)
6102 g_object_ref (widget);
6103 g_object_freeze_notify (G_OBJECT (widget));
6105 if (widget->style != style)
6107 GtkStyle *previous_style;
6109 if (GTK_WIDGET_REALIZED (widget))
6111 gtk_widget_reset_shapes (widget);
6112 gtk_style_detach (widget->style);
6115 previous_style = widget->style;
6116 widget->style = style;
6117 g_object_ref (widget->style);
6119 if (GTK_WIDGET_REALIZED (widget))
6120 widget->style = gtk_style_attach (widget->style, widget->window);
6122 gtk_widget_update_pango_context (widget);
6123 g_signal_emit (widget,
6124 widget_signals[STYLE_SET],
6126 initial_emission ? NULL : previous_style);
6127 g_object_unref (previous_style);
6129 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6130 gtk_widget_queue_resize (widget);
6132 else if (initial_emission)
6134 gtk_widget_update_pango_context (widget);
6135 g_signal_emit (widget,
6136 widget_signals[STYLE_SET],
6140 g_object_notify (G_OBJECT (widget), "style");
6141 g_object_thaw_notify (G_OBJECT (widget));
6142 g_object_unref (widget);
6146 GtkWidget *previous_toplevel;
6147 GdkScreen *previous_screen;
6148 GdkScreen *new_screen;
6149 } HierarchyChangedInfo;
6152 do_screen_change (GtkWidget *widget,
6153 GdkScreen *old_screen,
6154 GdkScreen *new_screen)
6156 if (old_screen != new_screen)
6160 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6162 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6165 _gtk_tooltip_hide (widget);
6166 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6171 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6172 gpointer client_data)
6174 HierarchyChangedInfo *info = client_data;
6175 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6176 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6178 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6180 g_object_ref (widget);
6183 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6185 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6187 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6188 do_screen_change (widget, info->previous_screen, info->new_screen);
6190 if (GTK_IS_CONTAINER (widget))
6191 gtk_container_forall (GTK_CONTAINER (widget),
6192 gtk_widget_propagate_hierarchy_changed_recurse,
6195 g_object_unref (widget);
6200 * _gtk_widget_propagate_hierarchy_changed:
6201 * @widget: a #GtkWidget
6202 * @previous_toplevel: Previous toplevel
6204 * Propagates changes in the anchored state to a widget and all
6205 * children, unsetting or setting the %ANCHORED flag, and
6206 * emitting #GtkWidget::hierarchy-changed.
6209 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6210 GtkWidget *previous_toplevel)
6212 HierarchyChangedInfo info;
6214 info.previous_toplevel = previous_toplevel;
6215 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6217 if (GTK_WIDGET_TOPLEVEL (widget) ||
6218 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6219 info.new_screen = gtk_widget_get_screen (widget);
6221 info.new_screen = NULL;
6223 if (info.previous_screen)
6224 g_object_ref (info.previous_screen);
6225 if (previous_toplevel)
6226 g_object_ref (previous_toplevel);
6228 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6230 if (previous_toplevel)
6231 g_object_unref (previous_toplevel);
6232 if (info.previous_screen)
6233 g_object_unref (info.previous_screen);
6237 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6238 gpointer client_data)
6240 HierarchyChangedInfo *info = client_data;
6242 g_object_ref (widget);
6244 do_screen_change (widget, info->previous_screen, info->new_screen);
6246 if (GTK_IS_CONTAINER (widget))
6247 gtk_container_forall (GTK_CONTAINER (widget),
6248 gtk_widget_propagate_screen_changed_recurse,
6251 g_object_unref (widget);
6255 * gtk_widget_is_composited:
6256 * @widget: a #GtkWidget
6258 * Whether @widget can rely on having its alpha channel
6259 * drawn correctly. On X11 this function returns whether a
6260 * compositing manager is running for @widget's screen.
6262 * Please note that the semantics of this call will change
6263 * in the future if used on a widget that has a composited
6264 * window in its hierarchy (as set by gdk_window_set_composited()).
6266 * Return value: %TRUE if the widget can rely on its alpha
6267 * channel being drawn correctly.
6272 gtk_widget_is_composited (GtkWidget *widget)
6276 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6278 screen = gtk_widget_get_screen (widget);
6280 return gdk_screen_is_composited (screen);
6284 propagate_composited_changed (GtkWidget *widget,
6287 if (GTK_IS_CONTAINER (widget))
6289 gtk_container_forall (GTK_CONTAINER (widget),
6290 propagate_composited_changed,
6294 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6298 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6300 propagate_composited_changed (widget, NULL);
6304 * _gtk_widget_propagate_screen_changed:
6305 * @widget: a #GtkWidget
6306 * @previous_screen: Previous screen
6308 * Propagates changes in the screen for a widget to all
6309 * children, emitting #GtkWidget::screen-changed.
6312 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6313 GdkScreen *previous_screen)
6315 HierarchyChangedInfo info;
6317 info.previous_screen = previous_screen;
6318 info.new_screen = gtk_widget_get_screen (widget);
6320 if (previous_screen)
6321 g_object_ref (previous_screen);
6323 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6325 if (previous_screen)
6326 g_object_unref (previous_screen);
6330 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6332 if (GTK_WIDGET_RC_STYLE (widget))
6333 gtk_widget_reset_rc_style (widget);
6335 if (GTK_IS_CONTAINER (widget))
6336 gtk_container_forall (GTK_CONTAINER (widget),
6337 reset_rc_styles_recurse,
6342 gtk_widget_reset_rc_styles (GtkWidget *widget)
6344 g_return_if_fail (GTK_IS_WIDGET (widget));
6346 reset_rc_styles_recurse (widget, NULL);
6350 * gtk_widget_get_default_style:
6352 * Returns the default style used by all widgets initially.
6354 * Returns: the default style. This #GtkStyle object is owned
6355 * by GTK+ and should not be modified or freed.
6358 gtk_widget_get_default_style (void)
6360 if (!gtk_default_style)
6362 gtk_default_style = gtk_style_new ();
6363 g_object_ref (gtk_default_style);
6366 return gtk_default_style;
6369 static PangoContext *
6370 gtk_widget_peek_pango_context (GtkWidget *widget)
6372 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6376 * gtk_widget_get_pango_context:
6377 * @widget: a #GtkWidget
6379 * Gets a #PangoContext with the appropriate font map, font description,
6380 * and base direction for this widget. Unlike the context returned
6381 * by gtk_widget_create_pango_context(), this context is owned by
6382 * the widget (it can be used until the screen for the widget changes
6383 * or the widget is removed from its toplevel), and will be updated to
6384 * match any changes to the widget's attributes.
6386 * If you create and keep a #PangoLayout using this context, you must
6387 * deal with changes to the context by calling pango_layout_context_changed()
6388 * on the layout in response to the #GtkWidget::style-set and
6389 * #GtkWidget::direction-changed signals for the widget.
6391 * Return value: the #PangoContext for the widget.
6394 gtk_widget_get_pango_context (GtkWidget *widget)
6396 PangoContext *context;
6398 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6400 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6403 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6404 g_object_set_qdata_full (G_OBJECT (widget),
6405 quark_pango_context,
6414 update_pango_context (GtkWidget *widget,
6415 PangoContext *context)
6417 pango_context_set_font_description (context, widget->style->font_desc);
6418 pango_context_set_base_dir (context,
6419 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6420 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6424 gtk_widget_update_pango_context (GtkWidget *widget)
6426 PangoContext *context = gtk_widget_peek_pango_context (widget);
6432 update_pango_context (widget, context);
6434 screen = gtk_widget_get_screen_unchecked (widget);
6437 pango_cairo_context_set_resolution (context,
6438 gdk_screen_get_resolution (screen));
6439 pango_cairo_context_set_font_options (context,
6440 gdk_screen_get_font_options (screen));
6446 * gtk_widget_create_pango_context:
6447 * @widget: a #GtkWidget
6449 * Creates a new #PangoContext with the appropriate font map,
6450 * font description, and base direction for drawing text for
6451 * this widget. See also gtk_widget_get_pango_context().
6453 * Return value: the new #PangoContext
6456 gtk_widget_create_pango_context (GtkWidget *widget)
6459 PangoContext *context;
6461 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6463 screen = gtk_widget_get_screen_unchecked (widget);
6466 GTK_NOTE (MULTIHEAD,
6467 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6469 screen = gdk_screen_get_default ();
6472 context = gdk_pango_context_get_for_screen (screen);
6474 update_pango_context (widget, context);
6475 pango_context_set_language (context, gtk_get_default_language ());
6481 * gtk_widget_create_pango_layout:
6482 * @widget: a #GtkWidget
6483 * @text: text to set on the layout (can be %NULL)
6485 * Creates a new #PangoLayout with the appropriate font map,
6486 * font description, and base direction for drawing text for
6489 * If you keep a #PangoLayout created in this way around, in order to
6490 * notify the layout of changes to the base direction or font of this
6491 * widget, you must call pango_layout_context_changed() in response to
6492 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6495 * Return value: the new #PangoLayout
6498 gtk_widget_create_pango_layout (GtkWidget *widget,
6501 PangoLayout *layout;
6502 PangoContext *context;
6504 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6506 context = gtk_widget_get_pango_context (widget);
6507 layout = pango_layout_new (context);
6510 pango_layout_set_text (layout, text, -1);
6516 * gtk_widget_render_icon:
6517 * @widget: a #GtkWidget
6518 * @stock_id: a stock ID
6519 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6520 * the size of the source and don't scale (if there are multiple
6521 * source sizes, GTK+ picks one of the available sizes).
6522 * @detail: render detail to pass to theme engine
6524 * A convenience function that uses the theme engine and RC file
6525 * settings for @widget to look up @stock_id and render it to
6526 * a pixbuf. @stock_id should be a stock icon ID such as
6527 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6528 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6529 * identifies the widget or code doing the rendering, so that
6530 * theme engines can special-case rendering for that widget or code.
6532 * The pixels in the returned #GdkPixbuf are shared with the rest of
6533 * the application and should not be modified. The pixbuf should be freed
6534 * after use with g_object_unref().
6536 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6539 gtk_widget_render_icon (GtkWidget *widget,
6540 const gchar *stock_id,
6542 const gchar *detail)
6544 GtkIconSet *icon_set;
6547 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6548 g_return_val_if_fail (stock_id != NULL, NULL);
6549 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6551 gtk_widget_ensure_style (widget);
6553 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6555 if (icon_set == NULL)
6558 retval = gtk_icon_set_render_icon (icon_set,
6560 gtk_widget_get_direction (widget),
6561 GTK_WIDGET_STATE (widget),
6570 * gtk_widget_set_parent_window:
6571 * @widget: a #GtkWidget.
6572 * @parent_window: the new parent window.
6574 * Sets a non default parent window for @widget.
6577 gtk_widget_set_parent_window (GtkWidget *widget,
6578 GdkWindow *parent_window)
6580 GdkWindow *old_parent_window;
6582 g_return_if_fail (GTK_IS_WIDGET (widget));
6584 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6585 quark_parent_window);
6587 if (parent_window != old_parent_window)
6589 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6591 if (old_parent_window)
6592 g_object_unref (old_parent_window);
6594 g_object_ref (parent_window);
6599 * gtk_widget_get_parent_window:
6600 * @widget: a #GtkWidget.
6601 * @returns: the parent window of @widget.
6603 * Gets @widget's parent window.
6606 gtk_widget_get_parent_window (GtkWidget *widget)
6608 GdkWindow *parent_window;
6610 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6612 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6614 return (parent_window != NULL) ? parent_window :
6615 (widget->parent != NULL) ? widget->parent->window : NULL;
6620 * gtk_widget_set_child_visible:
6621 * @widget: a #GtkWidget
6622 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6624 * Sets whether @widget should be mapped along with its when its parent
6625 * is mapped and @widget has been shown with gtk_widget_show().
6627 * The child visibility can be set for widget before it is added to
6628 * a container with gtk_widget_set_parent(), to avoid mapping
6629 * children unnecessary before immediately unmapping them. However
6630 * it will be reset to its default state of %TRUE when the widget
6631 * is removed from a container.
6633 * Note that changing the child visibility of a widget does not
6634 * queue a resize on the widget. Most of the time, the size of
6635 * a widget is computed from all visible children, whether or
6636 * not they are mapped. If this is not the case, the container
6637 * can queue a resize itself.
6639 * This function is only useful for container implementations and
6640 * never should be called by an application.
6643 gtk_widget_set_child_visible (GtkWidget *widget,
6644 gboolean is_visible)
6646 g_return_if_fail (GTK_IS_WIDGET (widget));
6647 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6649 g_object_ref (widget);
6652 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6655 GtkWidget *toplevel;
6657 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6659 toplevel = gtk_widget_get_toplevel (widget);
6660 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6661 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6664 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6666 if (GTK_WIDGET_MAPPED (widget->parent) &&
6667 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6668 GTK_WIDGET_VISIBLE (widget))
6669 gtk_widget_map (widget);
6671 gtk_widget_unmap (widget);
6674 g_object_unref (widget);
6678 * gtk_widget_get_child_visible:
6679 * @widget: a #GtkWidget
6681 * Gets the value set with gtk_widget_set_child_visible().
6682 * If you feel a need to use this function, your code probably
6683 * needs reorganization.
6685 * This function is only useful for container implementations and
6686 * never should be called by an application.
6688 * Return value: %TRUE if the widget is mapped with the parent.
6691 gtk_widget_get_child_visible (GtkWidget *widget)
6693 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6695 return GTK_WIDGET_CHILD_VISIBLE (widget);
6699 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6701 GtkWidget *toplevel;
6703 toplevel = gtk_widget_get_toplevel (widget);
6705 if (GTK_WIDGET_TOPLEVEL (toplevel))
6707 if (GTK_IS_WINDOW (toplevel))
6708 return GTK_WINDOW (toplevel)->screen;
6709 else if (GTK_IS_INVISIBLE (toplevel))
6710 return GTK_INVISIBLE (widget)->screen;
6717 * gtk_widget_get_screen:
6718 * @widget: a #GtkWidget
6720 * Get the #GdkScreen from the toplevel window associated with
6721 * this widget. This function can only be called after the widget
6722 * has been added to a widget hierarchy with a #GtkWindow
6725 * In general, you should only create screen specific
6726 * resources when a widget has been realized, and you should
6727 * free those resources when the widget is unrealized.
6729 * Return value: the #GdkScreen for the toplevel for this widget.
6734 gtk_widget_get_screen (GtkWidget *widget)
6738 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6740 screen = gtk_widget_get_screen_unchecked (widget);
6747 g_warning (G_STRLOC ": Can't get associated screen"
6748 " for a widget unless it is inside a toplevel GtkWindow\n"
6749 " widget type is %s associated top level type is %s",
6750 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6751 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6753 return gdk_screen_get_default ();
6758 * gtk_widget_has_screen:
6759 * @widget: a #GtkWidget
6761 * Checks whether there is a #GdkScreen is associated with
6762 * this widget. All toplevel widgets have an associated
6763 * screen, and all widgets added into a hierarchy with a toplevel
6764 * window at the top.
6766 * Return value: %TRUE if there is a #GdkScreen associcated
6772 gtk_widget_has_screen (GtkWidget *widget)
6774 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6776 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6780 * gtk_widget_get_display:
6781 * @widget: a #GtkWidget
6783 * Get the #GdkDisplay for the toplevel window associated with
6784 * this widget. This function can only be called after the widget
6785 * has been added to a widget hierarchy with a #GtkWindow at the top.
6787 * In general, you should only create display specific
6788 * resources when a widget has been realized, and you should
6789 * free those resources when the widget is unrealized.
6791 * Return value: the #GdkDisplay for the toplevel for this widget.
6796 gtk_widget_get_display (GtkWidget *widget)
6798 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6800 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6804 * gtk_widget_get_root_window:
6805 * @widget: a #GtkWidget
6807 * Get the root window where this widget is located. This function can
6808 * only be called after the widget has been added to a widget
6809 * hierarchy with #GtkWindow at the top.
6811 * The root window is useful for such purposes as creating a popup
6812 * #GdkWindow associated with the window. In general, you should only
6813 * create display specific resources when a widget has been realized,
6814 * and you should free those resources when the widget is unrealized.
6816 * Return value: the #GdkWindow root window for the toplevel for this widget.
6821 gtk_widget_get_root_window (GtkWidget *widget)
6823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6825 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6829 * gtk_widget_child_focus:
6830 * @widget: a #GtkWidget
6831 * @direction: direction of focus movement
6833 * This function is used by custom widget implementations; if you're
6834 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6835 * to a particular widget, and gtk_container_set_focus_chain() to
6836 * change the focus tab order. So you may want to investigate those
6837 * functions instead.
6839 * gtk_widget_child_focus() is called by containers as the user moves
6840 * around the window using keyboard shortcuts. @direction indicates
6841 * what kind of motion is taking place (up, down, left, right, tab
6842 * forward, tab backward). gtk_widget_child_focus() emits the
6843 * #GtkWidget::focus" signal; widgets override the default handler
6844 * for this signal in order to implement appropriate focus behavior.
6846 * The default ::focus handler for a widget should return %TRUE if
6847 * moving in @direction left the focus on a focusable location inside
6848 * that widget, and %FALSE if moving in @direction moved the focus
6849 * outside the widget. If returning %TRUE, widgets normally
6850 * call gtk_widget_grab_focus() to place the focus accordingly;
6851 * if returning %FALSE, they don't modify the current focus location.
6853 * This function replaces gtk_container_focus() from GTK+ 1.2.
6854 * It was necessary to check that the child was visible, sensitive,
6855 * and focusable before calling gtk_container_focus().
6856 * gtk_widget_child_focus() returns %FALSE if the widget is not
6857 * currently in a focusable state, so there's no need for those checks.
6859 * Return value: %TRUE if focus ended up inside @widget
6862 gtk_widget_child_focus (GtkWidget *widget,
6863 GtkDirectionType direction)
6865 gboolean return_val;
6867 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6869 if (!GTK_WIDGET_VISIBLE (widget) ||
6870 !GTK_WIDGET_IS_SENSITIVE (widget))
6873 /* child widgets must set CAN_FOCUS, containers
6874 * don't have to though.
6876 if (!GTK_IS_CONTAINER (widget) &&
6877 !GTK_WIDGET_CAN_FOCUS (widget))
6880 g_signal_emit (widget,
6881 widget_signals[FOCUS],
6883 direction, &return_val);
6889 * gtk_widget_keynav_failed:
6890 * @widget: a #GtkWidget
6891 * @direction: direction of focus movement
6893 * This function should be called whenever keyboard navigation within
6894 * a single widget hits a boundary. The function emits the
6895 * #GtkWidget::keynav-failed signal on the widget and its return
6896 * value should be interpreted in a way similar to the return value of
6897 * gtk_widget_child_focus():
6899 * When %TRUE is returned, stay in the widget, the failed keyboard
6900 * navigation is Ok and/or there is nowhere we can/should move the
6903 * When %FALSE is returned, the caller should continue with keyboard
6904 * navigation outside the widget, e.g. by calling
6905 * gtk_widget_child_focus() on the widget's toplevel.
6907 * The default ::keynav-failed handler returns %TRUE for
6908 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6909 * values of #GtkDirectionType, it looks at the
6910 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6911 * if the setting is %TRUE. This way the entire user interface
6912 * becomes cursor-navigatable on input devices such as mobile phones
6913 * which only have cursor keys but no tab key.
6915 * Whenever the default handler returns %TRUE, it also calls
6916 * gtk_widget_error_bell() to notify the user of the failed keyboard
6919 * A use case for providing an own implementation of ::keynav-failed
6920 * (either by connecting to it or by overriding it) would be a row of
6921 * #GtkEntry widgets where the user should be able to navigate the
6922 * entire row with the cursor keys, as e.g. known from user interfaces
6923 * that require entering license keys.
6925 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6926 * if the emitting widget should try to handle the keyboard
6927 * navigation attempt in its parent container(s).
6932 gtk_widget_keynav_failed (GtkWidget *widget,
6933 GtkDirectionType direction)
6935 gboolean return_val;
6937 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6939 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6940 direction, &return_val);
6946 * gtk_widget_error_bell:
6947 * @widget: a #GtkWidget
6949 * Notifies the user about an input-related error on this widget.
6950 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6951 * gdk_window_beep(), otherwise it does nothing.
6953 * Note that the effect of gdk_window_beep() can be configured in many
6954 * ways, depending on the windowing backend and the desktop environment
6955 * or window manager that is used.
6960 gtk_widget_error_bell (GtkWidget *widget)
6962 GtkSettings* settings;
6965 g_return_if_fail (GTK_IS_WIDGET (widget));
6967 settings = gtk_widget_get_settings (widget);
6971 g_object_get (settings,
6972 "gtk-error-bell", &beep,
6975 if (beep && widget->window)
6976 gdk_window_beep (widget->window);
6980 * gtk_widget_set_uposition:
6981 * @widget: a #GtkWidget
6982 * @x: x position; -1 to unset x; -2 to leave x unchanged
6983 * @y: y position; -1 to unset y; -2 to leave y unchanged
6986 * Sets the position of a widget. The funny "u" in the name comes from
6987 * the "user position" hint specified by the X Window System, and
6988 * exists for legacy reasons. This function doesn't work if a widget
6989 * is inside a container; it's only really useful on #GtkWindow.
6991 * Don't use this function to center dialogs over the main application
6992 * window; most window managers will do the centering on your behalf
6993 * if you call gtk_window_set_transient_for(), and it's really not
6994 * possible to get the centering to work correctly in all cases from
6995 * application code. But if you insist, use gtk_window_set_position()
6996 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6999 * Note that although @x and @y can be individually unset, the position
7000 * is not honoured unless both @x and @y are set.
7003 gtk_widget_set_uposition (GtkWidget *widget,
7007 /* FIXME this function is the only place that aux_info->x and
7008 * aux_info->y are even used I believe, and this function is
7009 * deprecated. Should be cleaned up.
7011 * (Actually, size_allocate uses them) -Yosh
7014 GtkWidgetAuxInfo *aux_info;
7016 g_return_if_fail (GTK_IS_WIDGET (widget));
7018 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7023 aux_info->x_set = FALSE;
7026 aux_info->x_set = TRUE;
7034 aux_info->y_set = FALSE;
7037 aux_info->y_set = TRUE;
7042 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7043 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7045 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7046 gtk_widget_size_allocate (widget, &widget->allocation);
7050 gtk_widget_set_usize_internal (GtkWidget *widget,
7054 GtkWidgetAuxInfo *aux_info;
7055 gboolean changed = FALSE;
7057 g_object_freeze_notify (G_OBJECT (widget));
7059 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7061 if (width > -2 && aux_info->width != width)
7063 g_object_notify (G_OBJECT (widget), "width-request");
7064 aux_info->width = width;
7067 if (height > -2 && aux_info->height != height)
7069 g_object_notify (G_OBJECT (widget), "height-request");
7070 aux_info->height = height;
7074 if (GTK_WIDGET_VISIBLE (widget) && changed)
7075 gtk_widget_queue_resize (widget);
7077 g_object_thaw_notify (G_OBJECT (widget));
7081 * gtk_widget_set_usize:
7082 * @widget: a #GtkWidget
7083 * @width: minimum width, or -1 to unset
7084 * @height: minimum height, or -1 to unset
7086 * Sets the minimum size of a widget; that is, the widget's size
7087 * request will be @width by @height. You can use this function to
7088 * force a widget to be either larger or smaller than it is. The
7089 * strange "usize" name dates from the early days of GTK+, and derives
7090 * from X Window System terminology. In many cases,
7091 * gtk_window_set_default_size() is a better choice for toplevel
7092 * windows than this function; setting the default size will still
7093 * allow users to shrink the window. Setting the usize will force them
7094 * to leave the window at least as large as the usize. When dealing
7095 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7098 * Note the inherent danger of setting any fixed size - themes,
7099 * translations into other languages, different fonts, and user action
7100 * can all change the appropriate size for a given widget. So, it's
7101 * basically impossible to hardcode a size that will always be
7104 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7107 gtk_widget_set_usize (GtkWidget *widget,
7111 g_return_if_fail (GTK_IS_WIDGET (widget));
7113 gtk_widget_set_usize_internal (widget, width, height);
7117 * gtk_widget_set_size_request:
7118 * @widget: a #GtkWidget
7119 * @width: width @widget should request, or -1 to unset
7120 * @height: height @widget should request, or -1 to unset
7122 * Sets the minimum size of a widget; that is, the widget's size
7123 * request will be @width by @height. You can use this function to
7124 * force a widget to be either larger or smaller than it normally
7127 * In most cases, gtk_window_set_default_size() is a better choice for
7128 * toplevel windows than this function; setting the default size will
7129 * still allow users to shrink the window. Setting the size request
7130 * will force them to leave the window at least as large as the size
7131 * request. When dealing with window sizes,
7132 * gtk_window_set_geometry_hints() can be a useful function as well.
7134 * Note the inherent danger of setting any fixed size - themes,
7135 * translations into other languages, different fonts, and user action
7136 * can all change the appropriate size for a given widget. So, it's
7137 * basically impossible to hardcode a size that will always be
7140 * The size request of a widget is the smallest size a widget can
7141 * accept while still functioning well and drawing itself correctly.
7142 * However in some strange cases a widget may be allocated less than
7143 * its requested size, and in many cases a widget may be allocated more
7144 * space than it requested.
7146 * If the size request in a given direction is -1 (unset), then
7147 * the "natural" size request of the widget will be used instead.
7149 * Widgets can't actually be allocated a size less than 1 by 1, but
7150 * you can pass 0,0 to this function to mean "as small as possible."
7153 gtk_widget_set_size_request (GtkWidget *widget,
7157 g_return_if_fail (GTK_IS_WIDGET (widget));
7158 g_return_if_fail (width >= -1);
7159 g_return_if_fail (height >= -1);
7166 gtk_widget_set_usize_internal (widget, width, height);
7171 * gtk_widget_get_size_request:
7172 * @widget: a #GtkWidget
7173 * @width: return location for width, or %NULL
7174 * @height: return location for height, or %NULL
7176 * Gets the size request that was explicitly set for the widget using
7177 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7178 * @height indicates that that dimension has not been set explicitly
7179 * and the natural requisition of the widget will be used intead. See
7180 * gtk_widget_set_size_request(). To get the size a widget will
7181 * actually use, call gtk_widget_size_request() instead of
7185 gtk_widget_get_size_request (GtkWidget *widget,
7189 GtkWidgetAuxInfo *aux_info;
7191 g_return_if_fail (GTK_IS_WIDGET (widget));
7193 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7196 *width = aux_info ? aux_info->width : -1;
7199 *height = aux_info ? aux_info->height : -1;
7203 * gtk_widget_set_events:
7204 * @widget: a #GtkWidget
7205 * @events: event mask
7207 * Sets the event mask (see #GdkEventMask) for a widget. The event
7208 * mask determines which events a widget will receive. Keep in mind
7209 * that different widgets have different default event masks, and by
7210 * changing the event mask you may disrupt a widget's functionality,
7211 * so be careful. This function must be called while a widget is
7212 * unrealized. Consider gtk_widget_add_events() for widgets that are
7213 * already realized, or if you want to preserve the existing event
7214 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7215 * to get events on those widgets, place them inside a #GtkEventBox
7216 * and receive events on the event box.
7219 gtk_widget_set_events (GtkWidget *widget,
7222 g_return_if_fail (GTK_IS_WIDGET (widget));
7223 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7225 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7226 GINT_TO_POINTER (events));
7227 g_object_notify (G_OBJECT (widget), "events");
7231 gtk_widget_add_events_internal (GtkWidget *widget,
7237 for (l = window_list; l != NULL; l = l->next)
7239 GdkWindow *window = l->data;
7242 gdk_window_get_user_data (window, &user_data);
7243 if (user_data == widget)
7247 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7249 children = gdk_window_get_children (window);
7250 gtk_widget_add_events_internal (widget, events, children);
7251 g_list_free (children);
7257 * gtk_widget_add_events:
7258 * @widget: a #GtkWidget
7259 * @events: an event mask, see #GdkEventMask
7261 * Adds the events in the bitfield @events to the event mask for
7262 * @widget. See gtk_widget_set_events() for details.
7265 gtk_widget_add_events (GtkWidget *widget,
7270 g_return_if_fail (GTK_IS_WIDGET (widget));
7272 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7273 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7274 GINT_TO_POINTER (old_events | events));
7276 if (GTK_WIDGET_REALIZED (widget))
7280 if (GTK_WIDGET_NO_WINDOW (widget))
7281 window_list = gdk_window_get_children (widget->window);
7283 window_list = g_list_prepend (NULL, widget->window);
7285 gtk_widget_add_events_internal (widget, events, window_list);
7287 g_list_free (window_list);
7290 g_object_notify (G_OBJECT (widget), "events");
7294 * gtk_widget_set_extension_events:
7295 * @widget: a #GtkWidget
7296 * @mode: bitfield of extension events to receive
7298 * Sets the extension events mask to @mode. See #GdkExtensionMode
7299 * and gdk_input_set_extension_events().
7302 gtk_widget_set_extension_events (GtkWidget *widget,
7303 GdkExtensionMode mode)
7305 g_return_if_fail (GTK_IS_WIDGET (widget));
7307 if (GTK_WIDGET_REALIZED (widget))
7308 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7310 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7311 GINT_TO_POINTER (mode));
7312 g_object_notify (G_OBJECT (widget), "extension-events");
7316 * gtk_widget_get_toplevel:
7317 * @widget: a #GtkWidget
7319 * This function returns the topmost widget in the container hierarchy
7320 * @widget is a part of. If @widget has no parent widgets, it will be
7321 * returned as the topmost widget. No reference will be added to the
7322 * returned widget; it should not be unreferenced.
7324 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7325 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7327 * %NULL if @widget wasn't inside a toplevel window, and if the
7328 * window was inside a #GtkWindow-derived widget which was in turn
7329 * inside the toplevel #GtkWindow. While the second case may
7330 * seem unlikely, it actually happens when a #GtkPlug is embedded
7331 * inside a #GtkSocket within the same application.
7333 * To reliably find the toplevel #GtkWindow, use
7334 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7335 * is set on the result.
7337 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7338 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7340 * /* Perform action on toplevel. */
7344 * Return value: the topmost ancestor of @widget, or @widget itself
7345 * if there's no ancestor.
7348 gtk_widget_get_toplevel (GtkWidget *widget)
7350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7352 while (widget->parent)
7353 widget = widget->parent;
7359 * gtk_widget_get_ancestor:
7360 * @widget: a #GtkWidget
7361 * @widget_type: ancestor type
7363 * Gets the first ancestor of @widget with type @widget_type. For example,
7364 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7365 * the first #GtkBox that's an ancestor of @widget. No reference will be
7366 * added to the returned widget; it should not be unreferenced. See note
7367 * about checking for a toplevel #GtkWindow in the docs for
7368 * gtk_widget_get_toplevel().
7370 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7371 * considers @widget to be an ancestor of itself.
7373 * Return value: the ancestor widget, or %NULL if not found
7376 gtk_widget_get_ancestor (GtkWidget *widget,
7379 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7381 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7382 widget = widget->parent;
7384 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7391 * gtk_widget_get_colormap:
7392 * @widget: a #GtkWidget
7394 * Gets the colormap that will be used to render @widget. No reference will
7395 * be added to the returned colormap; it should not be unreferenced.
7397 * Return value: the colormap used by @widget
7400 gtk_widget_get_colormap (GtkWidget *widget)
7402 GdkColormap *colormap;
7403 GtkWidget *tmp_widget;
7405 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7409 colormap = gdk_drawable_get_colormap (widget->window);
7410 /* If window was destroyed previously, we'll get NULL here */
7415 tmp_widget = widget;
7418 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7422 tmp_widget= tmp_widget->parent;
7425 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7429 * gtk_widget_get_visual:
7430 * @widget: a #GtkWidget
7432 * Gets the visual that will be used to render @widget.
7434 * Return value: the visual for @widget
7437 gtk_widget_get_visual (GtkWidget *widget)
7439 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7441 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7445 * gtk_widget_get_settings:
7446 * @widget: a #GtkWidget
7448 * Gets the settings object holding the settings (global property
7449 * settings, RC file information, etc) used for this widget.
7451 * Note that this function can only be called when the #GtkWidget
7452 * is attached to a toplevel, since the settings object is specific
7453 * to a particular #GdkScreen.
7455 * Return value: the relevant #GtkSettings object
7458 gtk_widget_get_settings (GtkWidget *widget)
7460 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7462 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7466 * gtk_widget_set_colormap:
7467 * @widget: a #GtkWidget
7468 * @colormap: a colormap
7470 * Sets the colormap for the widget to the given value. Widget must not
7471 * have been previously realized. This probably should only be used
7472 * from an <function>init()</function> function (i.e. from the constructor
7476 gtk_widget_set_colormap (GtkWidget *widget,
7477 GdkColormap *colormap)
7479 g_return_if_fail (GTK_IS_WIDGET (widget));
7480 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7481 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7483 g_object_ref (colormap);
7485 g_object_set_qdata_full (G_OBJECT (widget),
7492 * gtk_widget_get_events:
7493 * @widget: a #GtkWidget
7495 * Returns the event mask for the widget (a bitfield containing flags
7496 * from the #GdkEventMask enumeration). These are the events that the widget
7499 * Return value: event mask for @widget
7502 gtk_widget_get_events (GtkWidget *widget)
7504 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7506 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7510 * gtk_widget_get_extension_events:
7511 * @widget: a #GtkWidget
7513 * Retrieves the extension events the widget will receive; see
7514 * gdk_input_set_extension_events().
7516 * Return value: extension events for @widget
7519 gtk_widget_get_extension_events (GtkWidget *widget)
7521 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7523 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7527 * gtk_widget_get_pointer:
7528 * @widget: a #GtkWidget
7529 * @x: return location for the X coordinate, or %NULL
7530 * @y: return location for the Y coordinate, or %NULL
7532 * Obtains the location of the mouse pointer in widget coordinates.
7533 * Widget coordinates are a bit odd; for historical reasons, they are
7534 * defined as @widget->window coordinates for widgets that are not
7535 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7536 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7539 gtk_widget_get_pointer (GtkWidget *widget,
7543 g_return_if_fail (GTK_IS_WIDGET (widget));
7550 if (GTK_WIDGET_REALIZED (widget))
7552 gdk_window_get_pointer (widget->window, x, y, NULL);
7554 if (GTK_WIDGET_NO_WINDOW (widget))
7557 *x -= widget->allocation.x;
7559 *y -= widget->allocation.y;
7565 * gtk_widget_is_ancestor:
7566 * @widget: a #GtkWidget
7567 * @ancestor: another #GtkWidget
7569 * Determines whether @widget is somewhere inside @ancestor, possibly with
7570 * intermediate containers.
7572 * Return value: %TRUE if @ancestor contains @widget as a child,
7573 * grandchild, great grandchild, etc.
7576 gtk_widget_is_ancestor (GtkWidget *widget,
7577 GtkWidget *ancestor)
7579 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7580 g_return_val_if_fail (ancestor != NULL, FALSE);
7584 if (widget->parent == ancestor)
7586 widget = widget->parent;
7592 static GQuark quark_composite_name = 0;
7595 * gtk_widget_set_composite_name:
7596 * @widget: a #GtkWidget.
7597 * @name: the name to set
7599 * Sets a widgets composite name. The widget must be
7600 * a composite child of its parent; see gtk_widget_push_composite_child().
7603 gtk_widget_set_composite_name (GtkWidget *widget,
7606 g_return_if_fail (GTK_IS_WIDGET (widget));
7607 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7608 g_return_if_fail (name != NULL);
7610 if (!quark_composite_name)
7611 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7613 g_object_set_qdata_full (G_OBJECT (widget),
7614 quark_composite_name,
7620 * gtk_widget_get_composite_name:
7621 * @widget: a #GtkWidget
7623 * Obtains the composite name of a widget.
7625 * Returns: the composite name of @widget, or %NULL if @widget is not
7626 * a composite child. The string should be freed when it is no
7630 gtk_widget_get_composite_name (GtkWidget *widget)
7632 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7634 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7635 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7642 * gtk_widget_push_composite_child:
7644 * Makes all newly-created widgets as composite children until
7645 * the corresponding gtk_widget_pop_composite_child() call.
7647 * A composite child is a child that's an implementation detail of the
7648 * container it's inside and should not be visible to people using the
7649 * container. Composite children aren't treated differently by GTK (but
7650 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7651 * builders might want to treat them in a different way.
7653 * Here is a simple example:
7655 * gtk_widget_push_composite_child ();
7656 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7657 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7658 * gtk_widget_pop_composite_child ();
7659 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7660 * GTK_WIDGET (scrolled_window));
7661 * g_object_ref (scrolled_window->hscrollbar);
7665 gtk_widget_push_composite_child (void)
7667 composite_child_stack++;
7671 * gtk_widget_pop_composite_child:
7673 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7676 gtk_widget_pop_composite_child (void)
7678 if (composite_child_stack)
7679 composite_child_stack--;
7683 * gtk_widget_push_colormap:
7684 * @cmap: a #GdkColormap
7686 * Pushes @cmap onto a global stack of colormaps; the topmost
7687 * colormap on the stack will be used to create all widgets.
7688 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7689 * reason to use this function.
7692 gtk_widget_push_colormap (GdkColormap *cmap)
7694 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7696 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7700 * gtk_widget_pop_colormap:
7702 * Removes a colormap pushed with gtk_widget_push_colormap().
7705 gtk_widget_pop_colormap (void)
7708 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7712 * gtk_widget_set_default_colormap:
7713 * @colormap: a #GdkColormap
7715 * Sets the default colormap to use when creating widgets.
7716 * gtk_widget_push_colormap() is a better function to use if
7717 * you only want to affect a few widgets, rather than all widgets.
7720 gtk_widget_set_default_colormap (GdkColormap *colormap)
7722 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7724 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7729 * gtk_widget_get_default_colormap:
7731 * Obtains the default colormap used to create widgets.
7733 * Return value: default widget colormap
7736 gtk_widget_get_default_colormap (void)
7738 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7742 * gtk_widget_get_default_visual:
7744 * Obtains the visual of the default colormap. Not really useful;
7745 * used to be useful before gdk_colormap_get_visual() existed.
7747 * Return value: visual of the default colormap
7750 gtk_widget_get_default_visual (void)
7752 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7756 gtk_widget_emit_direction_changed (GtkWidget *widget,
7757 GtkTextDirection old_dir)
7759 gtk_widget_update_pango_context (widget);
7761 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7765 * gtk_widget_set_direction:
7766 * @widget: a #GtkWidget
7767 * @dir: the new direction
7769 * Sets the reading direction on a particular widget. This direction
7770 * controls the primary direction for widgets containing text,
7771 * and also the direction in which the children of a container are
7772 * packed. The ability to set the direction is present in order
7773 * so that correct localization into languages with right-to-left
7774 * reading directions can be done. Generally, applications will
7775 * let the default reading direction present, except for containers
7776 * where the containers are arranged in an order that is explicitely
7777 * visual rather than logical (such as buttons for text justification).
7779 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7780 * set by gtk_widget_set_default_direction() will be used.
7783 gtk_widget_set_direction (GtkWidget *widget,
7784 GtkTextDirection dir)
7786 GtkTextDirection old_dir;
7788 g_return_if_fail (GTK_IS_WIDGET (widget));
7789 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7791 old_dir = gtk_widget_get_direction (widget);
7793 if (dir == GTK_TEXT_DIR_NONE)
7794 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7797 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7798 if (dir == GTK_TEXT_DIR_LTR)
7799 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7801 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7804 if (old_dir != gtk_widget_get_direction (widget))
7805 gtk_widget_emit_direction_changed (widget, old_dir);
7809 * gtk_widget_get_direction:
7810 * @widget: a #GtkWidget
7812 * Gets the reading direction for a particular widget. See
7813 * gtk_widget_set_direction().
7815 * Return value: the reading direction for the widget.
7818 gtk_widget_get_direction (GtkWidget *widget)
7820 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7822 if (GTK_WIDGET_DIRECTION_SET (widget))
7823 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7825 return gtk_default_direction;
7829 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7831 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7833 g_object_ref (widget);
7835 if (!GTK_WIDGET_DIRECTION_SET (widget))
7836 gtk_widget_emit_direction_changed (widget, old_dir);
7838 if (GTK_IS_CONTAINER (widget))
7839 gtk_container_forall (GTK_CONTAINER (widget),
7840 gtk_widget_set_default_direction_recurse,
7843 g_object_unref (widget);
7847 * gtk_widget_set_default_direction:
7848 * @dir: the new default direction. This cannot be
7849 * %GTK_TEXT_DIR_NONE.
7851 * Sets the default reading direction for widgets where the
7852 * direction has not been explicitly set by gtk_widget_set_direction().
7855 gtk_widget_set_default_direction (GtkTextDirection dir)
7857 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7859 if (dir != gtk_default_direction)
7861 GList *toplevels, *tmp_list;
7862 GtkTextDirection old_dir = gtk_default_direction;
7864 gtk_default_direction = dir;
7866 tmp_list = toplevels = gtk_window_list_toplevels ();
7867 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7871 gtk_widget_set_default_direction_recurse (tmp_list->data,
7872 GUINT_TO_POINTER (old_dir));
7873 g_object_unref (tmp_list->data);
7874 tmp_list = tmp_list->next;
7877 g_list_free (toplevels);
7882 * gtk_widget_get_default_direction:
7884 * Obtains the current default reading direction. See
7885 * gtk_widget_set_default_direction().
7887 * Return value: the current default direction.
7890 gtk_widget_get_default_direction (void)
7892 return gtk_default_direction;
7896 gtk_widget_dispose (GObject *object)
7898 GtkWidget *widget = GTK_WIDGET (object);
7901 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7902 else if (GTK_WIDGET_VISIBLE (widget))
7903 gtk_widget_hide (widget);
7905 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7906 if (GTK_WIDGET_REALIZED (widget))
7907 gtk_widget_unrealize (widget);
7909 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7913 gtk_widget_real_destroy (GtkObject *object)
7915 /* gtk_object_destroy() will already hold a refcount on object */
7916 GtkWidget *widget = GTK_WIDGET (object);
7918 /* wipe accelerator closures (keep order) */
7919 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7920 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7922 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7923 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7925 gtk_grab_remove (widget);
7927 g_object_unref (widget->style);
7928 widget->style = gtk_widget_get_default_style ();
7929 g_object_ref (widget->style);
7931 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7935 gtk_widget_finalize (GObject *object)
7937 GtkWidget *widget = GTK_WIDGET (object);
7938 GtkWidgetAuxInfo *aux_info;
7939 GtkAccessible *accessible;
7941 gtk_grab_remove (widget);
7943 g_object_unref (widget->style);
7944 widget->style = NULL;
7946 g_free (widget->name);
7948 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7950 gtk_widget_aux_info_destroy (aux_info);
7952 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7954 g_object_unref (accessible);
7956 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7959 /*****************************************
7960 * gtk_widget_real_map:
7965 *****************************************/
7968 gtk_widget_real_map (GtkWidget *widget)
7970 g_assert (GTK_WIDGET_REALIZED (widget));
7972 if (!GTK_WIDGET_MAPPED (widget))
7974 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7976 if (!GTK_WIDGET_NO_WINDOW (widget))
7977 gdk_window_show (widget->window);
7981 /*****************************************
7982 * gtk_widget_real_unmap:
7987 *****************************************/
7990 gtk_widget_real_unmap (GtkWidget *widget)
7992 if (GTK_WIDGET_MAPPED (widget))
7994 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7996 if (!GTK_WIDGET_NO_WINDOW (widget))
7997 gdk_window_hide (widget->window);
8001 /*****************************************
8002 * gtk_widget_real_realize:
8007 *****************************************/
8010 gtk_widget_real_realize (GtkWidget *widget)
8012 g_assert (GTK_WIDGET_NO_WINDOW (widget));
8014 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
8017 widget->window = gtk_widget_get_parent_window (widget);
8018 g_object_ref (widget->window);
8020 widget->style = gtk_style_attach (widget->style, widget->window);
8023 /*****************************************
8024 * gtk_widget_real_unrealize:
8029 *****************************************/
8032 gtk_widget_real_unrealize (GtkWidget *widget)
8034 if (GTK_WIDGET_MAPPED (widget))
8035 gtk_widget_real_unmap (widget);
8037 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8039 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8042 /* We must do unrealize child widget BEFORE container widget.
8043 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8044 * So, unrealizing container widget bofore its children causes the problem
8045 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8048 if (GTK_IS_CONTAINER (widget))
8049 gtk_container_forall (GTK_CONTAINER (widget),
8050 (GtkCallback) gtk_widget_unrealize,
8053 gtk_style_detach (widget->style);
8054 if (!GTK_WIDGET_NO_WINDOW (widget))
8056 gdk_window_set_user_data (widget->window, NULL);
8057 gdk_window_destroy (widget->window);
8058 widget->window = NULL;
8062 g_object_unref (widget->window);
8063 widget->window = NULL;
8066 gtk_selection_remove_all (widget);
8068 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8072 gtk_widget_real_size_request (GtkWidget *widget,
8073 GtkRequisition *requisition)
8075 requisition->width = widget->requisition.width;
8076 requisition->height = widget->requisition.height;
8080 * _gtk_widget_peek_colormap:
8082 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8084 * Return value: the currently pushed colormap, or %NULL if there is none.
8087 _gtk_widget_peek_colormap (void)
8090 return (GdkColormap*) colormap_stack->data;
8095 * _gtk_widget_set_pointer_window:
8096 * @widget: a #GtkWidget.
8097 * @pointer_window: the new pointer window.
8099 * Sets pointer window for @widget. Does not ref @pointer_window.
8100 * Actually stores it on the #GdkScreen, but you don't need to know that.
8103 _gtk_widget_set_pointer_window (GtkWidget *widget,
8104 GdkWindow *pointer_window)
8106 g_return_if_fail (GTK_IS_WIDGET (widget));
8108 if (GTK_WIDGET_REALIZED (widget))
8110 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8112 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8118 * _gtk_widget_get_pointer_window:
8119 * @widget: a #GtkWidget.
8121 * Return value: the pointer window set on the #GdkScreen @widget is attached
8125 _gtk_widget_get_pointer_window (GtkWidget *widget)
8127 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8129 if (GTK_WIDGET_REALIZED (widget))
8131 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8133 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8140 synth_crossing (GtkWidget *widget,
8143 GdkCrossingMode mode,
8144 GdkNotifyType detail)
8148 event = gdk_event_new (type);
8150 event->crossing.window = g_object_ref (window);
8151 event->crossing.send_event = TRUE;
8152 event->crossing.subwindow = g_object_ref (window);
8153 event->crossing.time = GDK_CURRENT_TIME;
8154 event->crossing.x = event->crossing.y = 0;
8155 event->crossing.x_root = event->crossing.y_root = 0;
8156 event->crossing.mode = mode;
8157 event->crossing.detail = detail;
8158 event->crossing.focus = FALSE;
8159 event->crossing.state = 0;
8162 widget = gtk_get_event_widget (event);
8165 gtk_widget_event_internal (widget, event);
8167 gdk_event_free (event);
8171 * _gtk_widget_is_pointer_widget:
8172 * @widget: a #GtkWidget
8174 * Returns %TRUE if the pointer window belongs to @widget.
8177 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8179 if (GTK_WIDGET_HAS_POINTER (widget))
8184 win = _gtk_widget_get_pointer_window (widget);
8187 gdk_window_get_user_data (win, (gpointer *)&wid);
8197 * _gtk_widget_synthesize_crossing:
8198 * @from: the #GtkWidget the virtual pointer is leaving.
8199 * @to: the #GtkWidget the virtual pointer is moving to.
8200 * @mode: the #GdkCrossingMode to place on the synthesized events.
8202 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8204 * The real pointer window is the window that most recently received an enter notify
8205 * event. Windows that don't select for crossing events can't become the real
8206 * poiner window. The real pointer widget that owns the real pointer window. The
8207 * effective pointer window is the same as the real pointer window unless the real
8208 * pointer widget is either insensitive or there is a grab on a widget that is not
8209 * an ancestor of the real pointer widget (in which case the effective pointer
8210 * window should be the root window).
8212 * When the effective pointer window is the same as the real poiner window, we
8213 * receive crossing events from the windowing system. When the effective pointer
8214 * window changes to become different from the real pointer window we synthesize
8215 * crossing events, attempting to follow X protocol rules:
8217 * When the root window becomes the effective pointer window:
8218 * - leave notify on real pointer window, detail Ancestor
8219 * - leave notify on all of its ancestors, detail Virtual
8220 * - enter notify on root window, detail Inferior
8222 * When the root window ceases to be the effective pointer window:
8223 * - leave notify on root window, detail Inferior
8224 * - enter notify on all ancestors of real pointer window, detail Virtual
8225 * - enter notify on real pointer window, detail Ancestor
8228 _gtk_widget_synthesize_crossing (GtkWidget *from,
8230 GdkCrossingMode mode)
8232 GdkWindow *from_window = NULL, *to_window = NULL;
8234 g_return_if_fail (from != NULL || to != NULL);
8237 from_window = GTK_WIDGET_HAS_POINTER (from)
8238 ? _gtk_widget_get_pointer_window (from) : from->window;
8240 to_window = GTK_WIDGET_HAS_POINTER (to)
8241 ? _gtk_widget_get_pointer_window (to) : to->window;
8243 if (from_window == NULL && to_window == NULL)
8245 else if (from_window != NULL && to_window == NULL)
8247 GList *from_ancestors = NULL, *list;
8248 GdkWindow *from_ancestor = from_window;
8250 while (from_ancestor != NULL)
8252 from_ancestor = gdk_window_get_parent (from_ancestor);
8253 if (from_ancestor == NULL)
8255 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8258 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8259 mode, GDK_NOTIFY_ANCESTOR);
8260 for (list = g_list_last (from_ancestors); list; list = list->prev)
8262 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8263 mode, GDK_NOTIFY_VIRTUAL);
8266 /* XXX: enter/inferior on root window? */
8268 g_list_free (from_ancestors);
8270 else if (from_window == NULL && to_window != NULL)
8272 GList *to_ancestors = NULL, *list;
8273 GdkWindow *to_ancestor = to_window;
8275 while (to_ancestor != NULL)
8277 to_ancestor = gdk_window_get_parent (to_ancestor);
8278 if (to_ancestor == NULL)
8280 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8283 /* XXX: leave/inferior on root window? */
8285 for (list = to_ancestors; list; list = list->next)
8287 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8288 mode, GDK_NOTIFY_VIRTUAL);
8290 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8291 mode, GDK_NOTIFY_ANCESTOR);
8293 g_list_free (to_ancestors);
8295 else if (from_window == to_window)
8299 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8300 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8302 while (from_ancestor != NULL || to_ancestor != NULL)
8304 if (from_ancestor != NULL)
8306 from_ancestor = gdk_window_get_parent (from_ancestor);
8307 if (from_ancestor == to_window)
8310 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8312 if (to_ancestor != NULL)
8314 to_ancestor = gdk_window_get_parent (to_ancestor);
8315 if (to_ancestor == from_window)
8318 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8321 if (to_ancestor == from_window)
8323 if (mode != GDK_CROSSING_GTK_UNGRAB)
8324 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8325 mode, GDK_NOTIFY_INFERIOR);
8326 for (list = to_ancestors; list; list = list->next)
8327 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8328 mode, GDK_NOTIFY_VIRTUAL);
8329 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8330 mode, GDK_NOTIFY_ANCESTOR);
8332 else if (from_ancestor == to_window)
8334 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8335 mode, GDK_NOTIFY_ANCESTOR);
8336 for (list = g_list_last (from_ancestors); list; list = list->prev)
8338 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8339 mode, GDK_NOTIFY_VIRTUAL);
8341 if (mode != GDK_CROSSING_GTK_GRAB)
8342 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8343 mode, GDK_NOTIFY_INFERIOR);
8347 while (from_ancestors != NULL && to_ancestors != NULL
8348 && from_ancestors->data == to_ancestors->data)
8350 from_ancestors = g_list_delete_link (from_ancestors,
8352 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8355 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8356 mode, GDK_NOTIFY_NONLINEAR);
8358 for (list = g_list_last (from_ancestors); list; list = list->prev)
8360 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8361 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8363 for (list = to_ancestors; list; list = list->next)
8365 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8366 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8368 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8369 mode, GDK_NOTIFY_NONLINEAR);
8371 g_list_free (from_ancestors);
8372 g_list_free (to_ancestors);
8377 gtk_widget_propagate_state (GtkWidget *widget,
8380 guint8 old_state = GTK_WIDGET_STATE (widget);
8381 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8383 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8384 * parent_sensitive==TRUE on a sensitive widget
8388 if (data->parent_sensitive)
8389 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8391 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8393 if (GTK_WIDGET_IS_SENSITIVE (widget))
8395 if (data->state_restoration)
8396 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8398 GTK_WIDGET_STATE (widget) = data->state;
8402 if (!data->state_restoration)
8404 if (data->state != GTK_STATE_INSENSITIVE)
8405 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8407 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8408 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8409 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8412 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8416 window = gtk_widget_get_toplevel (widget);
8417 if (window && GTK_WIDGET_TOPLEVEL (window))
8418 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8421 if (old_state != GTK_WIDGET_STATE (widget) ||
8422 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8424 g_object_ref (widget);
8426 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8427 gtk_grab_remove (widget);
8429 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8431 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
8433 if (!GTK_WIDGET_IS_SENSITIVE (widget))
8434 _gtk_widget_synthesize_crossing (widget, NULL,
8435 GDK_CROSSING_STATE_CHANGED);
8436 else if (old_state == GTK_STATE_INSENSITIVE)
8437 _gtk_widget_synthesize_crossing (NULL, widget,
8438 GDK_CROSSING_STATE_CHANGED);
8441 if (GTK_IS_CONTAINER (widget))
8443 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8444 if (data->use_forall)
8445 gtk_container_forall (GTK_CONTAINER (widget),
8446 (GtkCallback) gtk_widget_propagate_state,
8449 gtk_container_foreach (GTK_CONTAINER (widget),
8450 (GtkCallback) gtk_widget_propagate_state,
8453 g_object_unref (widget);
8458 * _gtk_widget_get_aux_info:
8459 * @widget: a #GtkWidget
8460 * @create: if %TRUE, create the structure if it doesn't exist
8462 * Get the #GtkWidgetAuxInfo structure for the widget.
8464 * Return value: the #GtkAuxInfo structure for the widget, or
8465 * %NULL if @create is %FALSE and one doesn't already exist.
8468 _gtk_widget_get_aux_info (GtkWidget *widget,
8471 GtkWidgetAuxInfo *aux_info;
8473 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8474 if (!aux_info && create)
8476 aux_info = g_slice_new (GtkWidgetAuxInfo);
8478 aux_info->width = -1;
8479 aux_info->height = -1;
8482 aux_info->x_set = FALSE;
8483 aux_info->y_set = FALSE;
8484 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8490 /*****************************************
8491 * gtk_widget_aux_info_destroy:
8496 *****************************************/
8499 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8501 g_slice_free (GtkWidgetAuxInfo, aux_info);
8505 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8507 g_object_unref (info->shape_mask);
8508 g_slice_free (GtkWidgetShapeInfo, info);
8512 * gtk_widget_shape_combine_mask:
8513 * @widget: a #GtkWidget
8514 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8515 * @offset_x: X position of shape mask with respect to @window
8516 * @offset_y: Y position of shape mask with respect to @window
8518 * Sets a shape for this widget's GDK window. This allows for
8519 * transparent windows etc., see gdk_window_shape_combine_mask()
8520 * for more information.
8523 gtk_widget_shape_combine_mask (GtkWidget *widget,
8524 GdkBitmap *shape_mask,
8528 GtkWidgetShapeInfo* shape_info;
8530 g_return_if_fail (GTK_IS_WIDGET (widget));
8531 /* set_shape doesn't work on widgets without gdk window */
8532 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8536 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8539 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8541 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8545 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8547 shape_info = g_slice_new (GtkWidgetShapeInfo);
8548 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8549 (GDestroyNotify) gtk_widget_shape_info_destroy);
8551 shape_info->shape_mask = g_object_ref (shape_mask);
8552 shape_info->offset_x = offset_x;
8553 shape_info->offset_y = offset_y;
8555 /* set shape if widget has a gdk window already.
8556 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8559 gdk_window_shape_combine_mask (widget->window, shape_mask,
8560 offset_x, offset_y);
8565 * gtk_widget_input_shape_combine_mask:
8566 * @widget: a #GtkWidget
8567 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8568 * @offset_x: X position of shape mask with respect to @window
8569 * @offset_y: Y position of shape mask with respect to @window
8571 * Sets an input shape for this widget's GDK window. This allows for
8572 * windows which react to mouse click in a nonrectangular region, see
8573 * gdk_window_input_shape_combine_mask() for more information.
8578 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8579 GdkBitmap *shape_mask,
8583 GtkWidgetShapeInfo* shape_info;
8585 g_return_if_fail (GTK_IS_WIDGET (widget));
8586 /* set_shape doesn't work on widgets without gdk window */
8587 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8592 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8594 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8598 shape_info = g_slice_new (GtkWidgetShapeInfo);
8599 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8601 (GDestroyNotify) gtk_widget_shape_info_destroy);
8603 shape_info->shape_mask = g_object_ref (shape_mask);
8604 shape_info->offset_x = offset_x;
8605 shape_info->offset_y = offset_y;
8607 /* set shape if widget has a gdk window already.
8608 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8611 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8612 offset_x, offset_y);
8618 gtk_reset_shapes_recurse (GtkWidget *widget,
8624 gdk_window_get_user_data (window, &data);
8628 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8629 for (list = gdk_window_peek_children (window); list; list = list->next)
8630 gtk_reset_shapes_recurse (widget, list->data);
8634 * gtk_widget_reset_shapes:
8635 * @widget: a #GtkWidget
8637 * Recursively resets the shape on this widget and its descendants.
8640 gtk_widget_reset_shapes (GtkWidget *widget)
8642 g_return_if_fail (GTK_IS_WIDGET (widget));
8643 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8645 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8646 gtk_reset_shapes_recurse (widget, widget->window);
8651 * @widget: a #GtkWidget
8653 * Adds a reference to a widget. This function is exactly the same
8654 * as calling g_object_ref(), and exists mostly for historical
8655 * reasons. It can still be convenient to avoid casting a widget
8656 * to a #GObject, it saves a small amount of typing.
8658 * Return value: the widget that was referenced
8660 * Deprecated: 2.12: Use g_object_ref() instead.
8663 gtk_widget_ref (GtkWidget *widget)
8665 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8667 return (GtkWidget*) g_object_ref ((GObject*) widget);
8672 * @widget: a #GtkWidget
8674 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8676 * Deprecated: 2.12: Use g_object_unref() instead.
8679 gtk_widget_unref (GtkWidget *widget)
8681 g_return_if_fail (GTK_IS_WIDGET (widget));
8683 g_object_unref ((GObject*) widget);
8687 expose_window (GdkWindow *window)
8690 GList *l, *children;
8692 gboolean is_double_buffered;
8694 gdk_window_get_user_data (window, &user_data);
8697 is_double_buffered = GTK_WIDGET_DOUBLE_BUFFERED (GTK_WIDGET (user_data));
8699 is_double_buffered = FALSE;
8701 event.expose.type = GDK_EXPOSE;
8702 event.expose.window = g_object_ref (window);
8703 event.expose.send_event = FALSE;
8704 event.expose.count = 0;
8705 event.expose.area.x = 0;
8706 event.expose.area.y = 0;
8707 gdk_drawable_get_size (GDK_DRAWABLE (window),
8708 &event.expose.area.width,
8709 &event.expose.area.height);
8710 event.expose.region = gdk_region_rectangle (&event.expose.area);
8712 /* If this is not double buffered, force a double buffer so that
8713 redirection works. */
8714 if (!is_double_buffered)
8715 gdk_window_begin_paint_region (window, event.expose.region);
8717 gtk_main_do_event (&event);
8719 if (!is_double_buffered)
8720 gdk_window_end_paint (window);
8722 children = gdk_window_peek_children (window);
8723 for (l = children; l != NULL; l = l->next)
8725 GdkWindow *child = l->data;
8727 /* Don't expose input-only windows */
8728 if (gdk_drawable_get_depth (GDK_DRAWABLE (child)) != 0)
8729 expose_window (l->data);
8732 g_object_unref (window);
8736 * gtk_widget_get_snapshot:
8737 * @widget: a #GtkWidget
8738 * @clip_rect: a #GdkRectangle or %NULL
8740 * Create a #GdkPixmap of the contents of the widget and its children.
8742 * Works even if the widget is obscured. The depth and visual of the
8743 * resulting pixmap is dependent on the widget being snapshot and likely
8744 * differs from those of a target widget displaying the pixmap.
8745 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8746 * the pixmap to a visual independant representation.
8748 * The snapshot area used by this function is the @widget's allocation plus
8749 * any extra space occupied by additional windows belonging to this widget
8750 * (such as the arrows of a spin button).
8751 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8753 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8754 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8755 * interpreted widget relative. If width or height of @clip_rect are 0 or
8756 * negative, the width or height of the resulting pixmap will be shrunken
8757 * by the respective amount.
8758 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8759 * chop off 5 pixels at each side of the snapshot pixmap.
8760 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8761 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8762 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8763 * as a pure output parameter.
8765 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8767 * Return value: #GdkPixmap snapshot of the widget
8772 gtk_widget_get_snapshot (GtkWidget *widget,
8773 GdkRectangle *clip_rect)
8775 int x, y, width, height;
8776 GdkWindow *parent_window = NULL;
8778 GList *windows = NULL, *list;
8780 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8781 if (!GTK_WIDGET_VISIBLE (widget))
8784 /* the widget (and parent_window) must be realized to be drawable */
8785 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8786 gtk_widget_realize (widget->parent);
8787 if (!GTK_WIDGET_REALIZED (widget))
8788 gtk_widget_realize (widget);
8790 /* determine snapshot rectangle */
8791 x = widget->allocation.x;
8792 y = widget->allocation.y;
8793 width = widget->allocation.width;
8794 height = widget->allocation.height;
8796 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8798 /* grow snapshot rectangle to cover all widget windows */
8799 parent_window = gtk_widget_get_parent_window (widget);
8800 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8802 GdkWindow *subwin = list->data;
8805 gdk_window_get_user_data (subwin, &windata);
8806 if (windata != widget)
8808 windows = g_list_prepend (windows, subwin);
8809 gdk_window_get_position (subwin, &wx, &wy);
8810 gdk_drawable_get_size (subwin, &ww, &wh);
8811 /* grow snapshot rectangle by extra widget sub window */
8822 if (x + width < wx + ww)
8823 width += wx + ww - (x + width);
8824 if (y + height < wy + wh)
8825 height += wy + wh - (y + height);
8828 else if (!widget->parent)
8829 x = y = 0; /* toplevel */
8831 /* at this point, (x,y,width,height) is the parent_window relative
8832 * snapshot area covering all of widget's windows.
8835 /* shrink snapshot size by clip_rectangle */
8838 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8839 clip.x = clip.x < 0 ? x : clip.x;
8840 clip.y = clip.y < 0 ? y : clip.y;
8841 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8842 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8845 /* offset clip_rect, so it's parent_window relative */
8846 if (clip_rect->x >= 0)
8847 clip.x += widget->allocation.x;
8848 if (clip_rect->y >= 0)
8849 clip.y += widget->allocation.y;
8851 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8853 g_list_free (windows);
8854 clip_rect->width = clip_rect->height = 0;
8855 return NULL; /* empty snapshot area */
8860 height = snap.height;
8863 /* render snapshot */
8864 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8865 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8867 GdkWindow *subwin = list->data;
8869 if (gdk_drawable_get_depth (GDK_DRAWABLE (subwin)) == 0)
8870 continue; /* Input only window */
8871 gdk_window_get_position (subwin, &wx, &wy);
8872 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8873 MAX (0, wx - x), MAX (0, wy - y), width, height);
8875 expose_window (subwin);
8877 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8879 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8880 expose_window (widget->window);
8882 for (list = windows; list; list = list->next)
8883 gdk_window_remove_redirection (list->data);
8884 if (!windows) /* NO_WINDOW || toplevel */
8885 gdk_window_remove_redirection (widget->window);
8886 g_list_free (windows);
8888 /* return pixmap and snapshot rectangle coordinates */
8893 clip_rect->width = width;
8894 clip_rect->height = height;
8897 /* offset clip_rect from parent_window so it's widget relative */
8898 clip_rect->x -= widget->allocation.x;
8899 clip_rect->y -= widget->allocation.y;
8902 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8903 G_OBJECT_TYPE_NAME (widget),
8904 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8913 * gtk_widget_class_install_style_property_parser:
8914 * @klass: a #GtkWidgetClass
8915 * @pspec: the #GParamSpec for the style property
8916 * @parser: the parser for the style property
8918 * Installs a style property on a widget class.
8921 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8923 GtkRcPropertyParser parser)
8925 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8926 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8927 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8928 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8930 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8932 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8933 G_OBJECT_CLASS_NAME (klass),
8938 g_param_spec_ref_sink (pspec);
8939 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8940 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8944 * gtk_widget_class_install_style_property:
8945 * @klass: a #GtkWidgetClass
8946 * @pspec: the #GParamSpec for the property
8948 * Installs a style property on a widget class. The parser for the
8949 * style property is determined by the value type of @pspec.
8952 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8955 GtkRcPropertyParser parser;
8957 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8958 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8960 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8962 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8966 * gtk_widget_class_find_style_property:
8967 * @klass: a #GtkWidgetClass
8968 * @property_name: the name of the style property to find
8969 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8970 * style property with that name.
8972 * Finds a style property of a widget class by name.
8977 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8978 const gchar *property_name)
8980 g_return_val_if_fail (property_name != NULL, NULL);
8982 return g_param_spec_pool_lookup (style_property_spec_pool,
8984 G_OBJECT_CLASS_TYPE (klass),
8989 * gtk_widget_class_list_style_properties:
8990 * @klass: a #GtkWidgetClass
8991 * @n_properties: location to return the number of style properties found
8992 * @returns: an newly allocated array of #GParamSpec*. The array must
8993 * be freed with g_free().
8995 * Returns all style properties of a widget class.
9000 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
9001 guint *n_properties)
9003 GParamSpec **pspecs;
9006 pspecs = g_param_spec_pool_list (style_property_spec_pool,
9007 G_OBJECT_CLASS_TYPE (klass),
9016 * gtk_widget_style_get_property:
9017 * @widget: a #GtkWidget
9018 * @property_name: the name of a style property
9019 * @value: location to return the property value
9021 * Gets the value of a style property of @widget.
9024 gtk_widget_style_get_property (GtkWidget *widget,
9025 const gchar *property_name,
9030 g_return_if_fail (GTK_IS_WIDGET (widget));
9031 g_return_if_fail (property_name != NULL);
9032 g_return_if_fail (G_IS_VALUE (value));
9034 g_object_ref (widget);
9035 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9037 G_OBJECT_TYPE (widget),
9040 g_warning ("%s: widget class `%s' has no property named `%s'",
9042 G_OBJECT_TYPE_NAME (widget),
9046 const GValue *peek_value;
9048 peek_value = _gtk_style_peek_property_value (widget->style,
9049 G_OBJECT_TYPE (widget),
9051 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9053 /* auto-conversion of the caller's value type
9055 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
9056 g_value_copy (peek_value, value);
9057 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
9058 g_value_transform (peek_value, value);
9060 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9062 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9063 G_VALUE_TYPE_NAME (value));
9065 g_object_unref (widget);
9069 * gtk_widget_style_get_valist:
9070 * @widget: a #GtkWidget
9071 * @first_property_name: the name of the first property to get
9072 * @var_args: a <type>va_list</type> of pairs of property names and
9073 * locations to return the property values, starting with the location
9074 * for @first_property_name.
9076 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9080 gtk_widget_style_get_valist (GtkWidget *widget,
9081 const gchar *first_property_name,
9086 g_return_if_fail (GTK_IS_WIDGET (widget));
9088 g_object_ref (widget);
9090 name = first_property_name;
9093 const GValue *peek_value;
9097 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9099 G_OBJECT_TYPE (widget),
9103 g_warning ("%s: widget class `%s' has no property named `%s'",
9105 G_OBJECT_TYPE_NAME (widget),
9109 /* style pspecs are always readable so we can spare that check here */
9111 peek_value = _gtk_style_peek_property_value (widget->style,
9112 G_OBJECT_TYPE (widget),
9114 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9115 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9118 g_warning ("%s: %s", G_STRLOC, error);
9123 name = va_arg (var_args, gchar*);
9126 g_object_unref (widget);
9130 * gtk_widget_style_get:
9131 * @widget: a #GtkWidget
9132 * @first_property_name: the name of the first property to get
9133 * @Varargs: pairs of property names and locations to
9134 * return the property values, starting with the location for
9135 * @first_property_name, terminated by %NULL.
9137 * Gets the values of a multiple style properties of @widget.
9140 gtk_widget_style_get (GtkWidget *widget,
9141 const gchar *first_property_name,
9146 g_return_if_fail (GTK_IS_WIDGET (widget));
9148 va_start (var_args, first_property_name);
9149 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9155 * @widget: a #GtkWidget
9156 * @path_length: location to store length of the path, or %NULL
9157 * @path: location to store allocated path string, or %NULL
9158 * @path_reversed: location to store allocated reverse path string, or %NULL
9160 * Obtains the full path to @widget. The path is simply the name of a
9161 * widget and all its parents in the container hierarchy, separated by
9162 * periods. The name of a widget comes from
9163 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9164 * in gtkrc configuration files. Widget names are the type of the
9165 * widget by default (e.g. "GtkButton") or can be set to an
9166 * application-specific value with gtk_widget_set_name(). By setting
9167 * the name of a widget, you allow users or theme authors to apply
9168 * styles to that specific widget in their gtkrc
9169 * file. @path_reversed_p fills in the path in reverse order,
9170 * i.e. starting with @widget's name instead of starting with the name
9171 * of @widget's outermost ancestor.
9174 gtk_widget_path (GtkWidget *widget,
9177 gchar **path_reversed)
9179 static gchar *rev_path = NULL;
9180 static guint tmp_path_len = 0;
9183 g_return_if_fail (GTK_IS_WIDGET (widget));
9188 const gchar *string;
9193 string = gtk_widget_get_name (widget);
9194 l = strlen (string);
9195 while (tmp_path_len <= len + l + 1)
9197 tmp_path_len += INIT_PATH_SIZE;
9198 rev_path = g_realloc (rev_path, tmp_path_len);
9206 widget = widget->parent;
9209 rev_path[len++] = '.';
9211 rev_path[len++] = 0;
9216 *path_length = len - 1;
9218 *path_reversed = g_strdup (rev_path);
9221 *path = g_strdup (rev_path);
9222 g_strreverse (*path);
9227 * gtk_widget_class_path:
9228 * @widget: a #GtkWidget
9229 * @path_length: location to store the length of the class path, or %NULL
9230 * @path: location to store the class path as an allocated string, or %NULL
9231 * @path_reversed: location to store the reverse class path as an allocated
9234 * Same as gtk_widget_path(), but always uses the name of a widget's type,
9235 * never uses a custom name set with gtk_widget_set_name().
9239 gtk_widget_class_path (GtkWidget *widget,
9242 gchar **path_reversed)
9244 static gchar *rev_path = NULL;
9245 static guint tmp_path_len = 0;
9248 g_return_if_fail (GTK_IS_WIDGET (widget));
9253 const gchar *string;
9258 string = g_type_name (GTK_WIDGET_TYPE (widget));
9259 l = strlen (string);
9260 while (tmp_path_len <= len + l + 1)
9262 tmp_path_len += INIT_PATH_SIZE;
9263 rev_path = g_realloc (rev_path, tmp_path_len);
9271 widget = widget->parent;
9274 rev_path[len++] = '.';
9276 rev_path[len++] = 0;
9281 *path_length = len - 1;
9283 *path_reversed = g_strdup (rev_path);
9286 *path = g_strdup (rev_path);
9287 g_strreverse (*path);
9292 * gtk_requisition_copy:
9293 * @requisition: a #GtkRequisition
9295 * Copies a #GtkRequisition.
9297 * Returns: a copy of @requisition
9300 gtk_requisition_copy (const GtkRequisition *requisition)
9302 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9306 * gtk_requisition_free:
9307 * @requisition: a #GtkRequisition
9309 * Frees a #GtkRequisition.
9312 gtk_requisition_free (GtkRequisition *requisition)
9314 g_free (requisition);
9318 gtk_requisition_get_type (void)
9320 static GType our_type = 0;
9323 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9324 (GBoxedCopyFunc) gtk_requisition_copy,
9325 (GBoxedFreeFunc) gtk_requisition_free);
9331 * gtk_widget_get_accessible:
9332 * @widget: a #GtkWidget
9334 * Returns the accessible object that describes the widget to an
9335 * assistive technology.
9337 * If no accessibility library is loaded (i.e. no ATK implementation library is
9338 * loaded via <envar>GTK_MODULES</envar> or via another application library,
9339 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
9340 * if no class-specific #AtkObject implementation is available for the widget
9341 * instance in question, it will inherit an #AtkObject implementation from the
9342 * first ancestor class for which such an implementation is defined.
9344 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9345 * library contains more information about accessible objects and their uses.
9347 * Returns: the #AtkObject associated with @widget
9350 gtk_widget_get_accessible (GtkWidget *widget)
9352 GtkWidgetClass *klass;
9354 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9356 klass = GTK_WIDGET_GET_CLASS (widget);
9358 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
9360 return klass->get_accessible (widget);
9364 gtk_widget_real_get_accessible (GtkWidget *widget)
9366 AtkObject* accessible;
9368 accessible = g_object_get_qdata (G_OBJECT (widget),
9369 quark_accessible_object);
9372 AtkObjectFactory *factory;
9373 AtkRegistry *default_registry;
9375 default_registry = atk_get_default_registry ();
9376 factory = atk_registry_get_factory (default_registry,
9377 G_TYPE_FROM_INSTANCE (widget));
9379 atk_object_factory_create_accessible (factory,
9381 g_object_set_qdata (G_OBJECT (widget),
9382 quark_accessible_object,
9389 * Initialize a AtkImplementorIface instance's virtual pointers as
9390 * appropriate to this implementor's class (GtkWidget).
9393 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9395 iface->ref_accessible = gtk_widget_ref_accessible;
9399 gtk_widget_ref_accessible (AtkImplementor *implementor)
9401 AtkObject *accessible;
9403 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9405 g_object_ref (accessible);
9410 * GtkBuildable implementation
9412 static GQuark quark_builder_has_default = 0;
9413 static GQuark quark_builder_has_focus = 0;
9414 static GQuark quark_builder_atk_relations = 0;
9417 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9419 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9420 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9421 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9423 iface->set_name = gtk_widget_buildable_set_name;
9424 iface->get_name = gtk_widget_buildable_get_name;
9425 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9426 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9427 iface->parser_finished = gtk_widget_buildable_parser_finished;
9428 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9429 iface->custom_finished = gtk_widget_buildable_custom_finished;
9433 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9436 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9439 static const gchar *
9440 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9442 return gtk_widget_get_name (GTK_WIDGET (buildable));
9446 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9447 GtkBuilder *builder,
9448 const gchar *childname)
9450 if (strcmp (childname, "accessible") == 0)
9451 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9457 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9458 GtkBuilder *builder,
9460 const GValue *value)
9462 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9463 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9464 GINT_TO_POINTER (TRUE));
9465 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9466 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9467 GINT_TO_POINTER (TRUE));
9469 g_object_set_property (G_OBJECT (buildable), name, value);
9475 GString *description;
9477 gboolean translatable;
9487 free_action (AtkActionData *data, gpointer user_data)
9489 g_free (data->action_name);
9490 g_string_free (data->description, TRUE);
9491 g_free (data->context);
9492 g_slice_free (AtkActionData, data);
9496 free_relation (AtkRelationData *data, gpointer user_data)
9498 g_free (data->target);
9499 g_free (data->type);
9500 g_slice_free (AtkRelationData, data);
9504 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9505 GtkBuilder *builder)
9507 GSList *atk_relations;
9509 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9510 gtk_widget_grab_default (GTK_WIDGET (buildable));
9511 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9512 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9514 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9515 quark_builder_atk_relations);
9518 AtkObject *accessible;
9519 AtkRelationSet *relation_set;
9522 AtkRelationType relation_type;
9523 AtkObject *target_accessible;
9525 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9526 relation_set = atk_object_ref_relation_set (accessible);
9528 for (l = atk_relations; l; l = l->next)
9530 AtkRelationData *relation = (AtkRelationData*)l->data;
9532 target = gtk_builder_get_object (builder, relation->target);
9535 g_warning ("Target object %s in <relation> does not exist",
9539 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9540 g_assert (target_accessible != NULL);
9542 relation_type = atk_relation_type_for_name (relation->type);
9543 if (relation_type == ATK_RELATION_NULL)
9545 g_warning ("<relation> type %s not found",
9549 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9552 g_object_unref (relation_set);
9554 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9555 g_slist_free (atk_relations);
9556 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9565 } AccessibilitySubParserData;
9568 accessibility_start_element (GMarkupParseContext *context,
9569 const gchar *element_name,
9570 const gchar **names,
9571 const gchar **values,
9575 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9577 gint line_number, char_number;
9579 if (strcmp (element_name, "relation") == 0)
9581 gchar *target = NULL;
9583 AtkRelationData *relation;
9585 for (i = 0; names[i]; i++)
9587 if (strcmp (names[i], "target") == 0)
9588 target = g_strdup (values[i]);
9589 else if (strcmp (names[i], "type") == 0)
9590 type = g_strdup (values[i]);
9593 g_markup_parse_context_get_position (context,
9598 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9599 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9601 line_number, char_number, names[i], "relation");
9608 if (!target || !type)
9610 g_markup_parse_context_get_position (context,
9615 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9616 "%s:%d:%d <%s> requires attribute \"%s\"",
9618 line_number, char_number, "relation",
9619 type ? "target" : "type");
9625 relation = g_slice_new (AtkRelationData);
9626 relation->target = target;
9627 relation->type = type;
9629 data->relations = g_slist_prepend (data->relations, relation);
9631 else if (strcmp (element_name, "action") == 0)
9633 const gchar *action_name = NULL;
9634 const gchar *description = NULL;
9635 const gchar *msg_context = NULL;
9636 gboolean translatable = FALSE;
9637 AtkActionData *action;
9639 for (i = 0; names[i]; i++)
9641 if (strcmp (names[i], "action_name") == 0)
9642 action_name = values[i];
9643 else if (strcmp (names[i], "description") == 0)
9644 description = values[i];
9645 else if (strcmp (names[i], "translatable") == 0)
9647 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
9650 else if (strcmp (names[i], "comments") == 0)
9652 /* do nothing, comments are for translators */
9654 else if (strcmp (names[i], "context") == 0)
9655 msg_context = values[i];
9658 g_markup_parse_context_get_position (context,
9663 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9664 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9666 line_number, char_number, names[i], "action");
9673 g_markup_parse_context_get_position (context,
9678 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9679 "%s:%d:%d <%s> requires attribute \"%s\"",
9681 line_number, char_number, "action",
9686 action = g_slice_new (AtkActionData);
9687 action->action_name = g_strdup (action_name);
9688 action->description = g_string_new (description);
9689 action->context = g_strdup (msg_context);
9690 action->translatable = translatable;
9692 data->actions = g_slist_prepend (data->actions, action);
9694 else if (strcmp (element_name, "accessibility") == 0)
9697 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9701 accessibility_text (GMarkupParseContext *context,
9707 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9709 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
9711 AtkActionData *action = data->actions->data;
9713 g_string_append_len (action->description, text, text_len);
9717 static const GMarkupParser accessibility_parser =
9719 accessibility_start_element,
9730 } AccelGroupParserData;
9733 accel_group_start_element (GMarkupParseContext *context,
9734 const gchar *element_name,
9735 const gchar **names,
9736 const gchar **values,
9742 guint modifiers = 0;
9743 gchar *signal = NULL;
9744 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9746 for (i = 0; names[i]; i++)
9748 if (strcmp (names[i], "key") == 0)
9749 key = gdk_keyval_from_name (values[i]);
9750 else if (strcmp (names[i], "modifiers") == 0)
9752 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9758 else if (strcmp (names[i], "signal") == 0)
9759 signal = g_strdup (values[i]);
9762 if (key == 0 || signal == NULL)
9764 g_warning ("<accelerator> requires key and signal attributes");
9767 parser_data->key = key;
9768 parser_data->modifiers = modifiers;
9769 parser_data->signal = signal;
9772 static const GMarkupParser accel_group_parser =
9774 accel_group_start_element,
9778 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9779 GtkBuilder *builder,
9781 const gchar *tagname,
9782 GMarkupParser *parser,
9785 g_assert (buildable);
9787 if (strcmp (tagname, "accelerator") == 0)
9789 AccelGroupParserData *parser_data;
9791 parser_data = g_slice_new0 (AccelGroupParserData);
9792 parser_data->object = g_object_ref (buildable);
9793 *parser = accel_group_parser;
9794 *data = parser_data;
9797 if (strcmp (tagname, "accessibility") == 0)
9799 AccessibilitySubParserData *parser_data;
9801 parser_data = g_slice_new0 (AccessibilitySubParserData);
9802 *parser = accessibility_parser;
9803 *data = parser_data;
9810 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9811 GtkBuilder *builder,
9813 const gchar *tagname,
9816 AccelGroupParserData *accel_data;
9817 AccessibilitySubParserData *a11y_data;
9818 GtkWidget *toplevel;
9819 GSList *accel_groups;
9820 GtkAccelGroup *accel_group;
9822 if (strcmp (tagname, "accelerator") == 0)
9824 accel_data = (AccelGroupParserData*)user_data;
9825 g_assert (accel_data->object);
9827 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9828 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9829 if (g_slist_length (accel_groups) == 0)
9831 accel_group = gtk_accel_group_new ();
9832 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9836 g_assert (g_slist_length (accel_groups) == 1);
9837 accel_group = g_slist_nth_data (accel_groups, 0);
9839 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9843 accel_data->modifiers,
9845 g_object_unref (accel_data->object);
9846 g_free (accel_data->signal);
9847 g_slice_free (AccelGroupParserData, accel_data);
9849 else if (strcmp (tagname, "accessibility") == 0)
9851 a11y_data = (AccessibilitySubParserData*)user_data;
9853 if (a11y_data->actions)
9855 AtkObject *accessible;
9860 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9862 action = ATK_ACTION (accessible);
9863 n_actions = atk_action_get_n_actions (action);
9865 for (l = a11y_data->actions; l; l = l->next)
9867 AtkActionData *action_data = (AtkActionData*)l->data;
9869 for (i = 0; i < n_actions; i++)
9870 if (strcmp (atk_action_get_name (action, i),
9871 action_data->action_name) == 0)
9878 if (action_data->translatable && action_data->description->len)
9879 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
9880 action_data->context,
9881 action_data->description->str);
9883 description = action_data->description->str;
9885 atk_action_set_description (action, i, description);
9889 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9890 g_slist_free (a11y_data->actions);
9893 if (a11y_data->relations)
9894 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9895 a11y_data->relations);
9897 g_slice_free (AccessibilitySubParserData, a11y_data);
9903 * gtk_widget_get_clipboard:
9904 * @widget: a #GtkWidget
9905 * @selection: a #GdkAtom which identifies the clipboard
9906 * to use. %GDK_SELECTION_CLIPBOARD gives the
9907 * default clipboard. Another common value
9908 * is %GDK_SELECTION_PRIMARY, which gives
9909 * the primary X selection.
9911 * Returns the clipboard object for the given selection to
9912 * be used with @widget. @widget must have a #GdkDisplay
9913 * associated with it, so must be attached to a toplevel
9916 * Return value: the appropriate clipboard object. If no
9917 * clipboard already exists, a new one will
9918 * be created. Once a clipboard object has
9919 * been created, it is persistent for all time.
9924 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9926 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9927 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9929 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9934 * gtk_widget_list_mnemonic_labels:
9935 * @widget: a #GtkWidget
9937 * Returns a newly allocated list of the widgets, normally labels, for
9938 * which this widget is a the target of a mnemonic (see for example,
9939 * gtk_label_set_mnemonic_widget()).
9941 * The widgets in the list are not individually referenced. If you
9942 * want to iterate through the list and perform actions involving
9943 * callbacks that might destroy the widgets, you
9944 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9945 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9946 * widgets afterwards.
9948 * Return value: the list of mnemonic labels; free this list
9949 * with g_list_free() when you are done with it.
9954 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9959 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9961 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9962 list = g_list_prepend (list, l->data);
9968 * gtk_widget_add_mnemonic_label:
9969 * @widget: a #GtkWidget
9970 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9972 * Adds a widget to the list of mnemonic labels for
9973 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9974 * list of mnemonic labels for the widget is cleared when the
9975 * widget is destroyed, so the caller must make sure to update
9976 * its internal state at this point as well, by using a connection
9977 * to the #GtkWidget::destroy signal or a weak notifier.
9982 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9985 GSList *old_list, *new_list;
9987 g_return_if_fail (GTK_IS_WIDGET (widget));
9988 g_return_if_fail (GTK_IS_WIDGET (label));
9990 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9991 new_list = g_slist_prepend (old_list, label);
9993 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9994 new_list, (GDestroyNotify) g_slist_free);
9998 * gtk_widget_remove_mnemonic_label:
9999 * @widget: a #GtkWidget
10000 * @label: a #GtkWidget that was previously set as a mnemnic label for
10001 * @widget with gtk_widget_add_mnemonic_label().
10003 * Removes a widget from the list of mnemonic labels for
10004 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
10005 * must have previously been added to the list with
10006 * gtk_widget_add_mnemonic_label().
10011 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
10014 GSList *old_list, *new_list;
10016 g_return_if_fail (GTK_IS_WIDGET (widget));
10017 g_return_if_fail (GTK_IS_WIDGET (label));
10019 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
10020 new_list = g_slist_remove (old_list, label);
10023 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
10024 new_list, (GDestroyNotify) g_slist_free);
10028 * gtk_widget_get_no_show_all:
10029 * @widget: a #GtkWidget
10031 * Returns the current value of the GtkWidget:no-show-all property,
10032 * which determines whether calls to gtk_widget_show_all() and
10033 * gtk_widget_hide_all() will affect this widget.
10035 * Return value: the current value of the "no-show-all" property.
10040 gtk_widget_get_no_show_all (GtkWidget *widget)
10042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10044 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
10048 * gtk_widget_set_no_show_all:
10049 * @widget: a #GtkWidget
10050 * @no_show_all: the new value for the "no-show-all" property
10052 * Sets the #GtkWidget:no-show-all property, which determines whether
10053 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
10056 * This is mostly for use in constructing widget hierarchies with externally
10057 * controlled visibility, see #GtkUIManager.
10062 gtk_widget_set_no_show_all (GtkWidget *widget,
10063 gboolean no_show_all)
10065 g_return_if_fail (GTK_IS_WIDGET (widget));
10067 no_show_all = (no_show_all != FALSE);
10069 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
10073 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
10075 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
10077 g_object_notify (G_OBJECT (widget), "no-show-all");
10082 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
10083 gboolean has_tooltip,
10086 gboolean priv_has_tooltip;
10088 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
10089 quark_has_tooltip));
10091 if (priv_has_tooltip != has_tooltip || force)
10093 priv_has_tooltip = has_tooltip;
10095 if (priv_has_tooltip)
10097 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
10098 gdk_window_set_events (widget->window,
10099 gdk_window_get_events (widget->window) |
10100 GDK_LEAVE_NOTIFY_MASK |
10101 GDK_POINTER_MOTION_MASK |
10102 GDK_POINTER_MOTION_HINT_MASK);
10104 if (!GTK_WIDGET_NO_WINDOW (widget))
10105 gtk_widget_add_events (widget,
10106 GDK_LEAVE_NOTIFY_MASK |
10107 GDK_POINTER_MOTION_MASK |
10108 GDK_POINTER_MOTION_HINT_MASK);
10111 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10112 GUINT_TO_POINTER (priv_has_tooltip));
10117 * gtk_widget_set_tooltip_window:
10118 * @widget: a #GtkWidget
10119 * @custom_window: a #GtkWindow, or %NULL
10121 * Replaces the default, usually yellow, window used for displaying
10122 * tooltips with @custom_window. GTK+ will take care of showing and
10123 * hiding @custom_window at the right moment, to behave likewise as
10124 * the default tooltip window. If @custom_window is %NULL, the default
10125 * tooltip window will be used.
10130 gtk_widget_set_tooltip_window (GtkWidget *widget,
10131 GtkWindow *custom_window)
10133 gboolean has_tooltip;
10134 gchar *tooltip_markup;
10136 g_return_if_fail (GTK_IS_WIDGET (widget));
10137 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
10139 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10142 g_object_ref (custom_window);
10144 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10145 custom_window, g_object_unref);
10147 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
10148 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
10150 if (has_tooltip && GTK_WIDGET_VISIBLE (widget))
10151 gtk_widget_queue_tooltip_query (widget);
10155 * gtk_widget_get_tooltip_window:
10156 * @widget: a #GtkWidget
10158 * Returns the #GtkWindow of the current tooltip. This can be the
10159 * GtkWindow created by default, or the custom tooltip window set
10160 * using gtk_widget_set_tooltip_window().
10162 * Return value: The #GtkWindow of the current tooltip.
10167 gtk_widget_get_tooltip_window (GtkWidget *widget)
10169 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10171 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10175 * gtk_widget_trigger_tooltip_query:
10176 * @widget: a #GtkWidget
10178 * Triggers a tooltip query on the display where the toplevel of @widget
10179 * is located. See gtk_tooltip_trigger_tooltip_query() for more
10185 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10187 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10190 static guint tooltip_query_id;
10191 static GSList *tooltip_query_displays;
10194 tooltip_query_idle (gpointer data)
10196 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
10197 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
10198 g_slist_free (tooltip_query_displays);
10200 tooltip_query_displays = NULL;
10201 tooltip_query_id = 0;
10207 gtk_widget_queue_tooltip_query (GtkWidget *widget)
10209 GdkDisplay *display;
10211 display = gtk_widget_get_display (widget);
10213 if (!g_slist_find (tooltip_query_displays, display))
10214 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
10216 if (tooltip_query_id == 0)
10217 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
10221 * gtk_widget_set_tooltip_text:
10222 * @widget: a #GtkWidget
10223 * @text: the contents of the tooltip for @widget
10225 * Sets @text as the contents of the tooltip. This function will take
10226 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10227 * handler for the GtkWidget::query-tooltip signal.
10229 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10234 gtk_widget_set_tooltip_text (GtkWidget *widget,
10237 g_return_if_fail (GTK_IS_WIDGET (widget));
10239 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10243 * gtk_widget_get_tooltip_text:
10244 * @widget: a #GtkWidget
10246 * Gets the contents of the tooltip for @widget.
10248 * Return value: the tooltip text, or %NULL. You should free the
10249 * returned string with g_free() when done.
10254 gtk_widget_get_tooltip_text (GtkWidget *widget)
10256 gchar *text = NULL;
10258 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10260 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10266 * gtk_widget_set_tooltip_markup:
10267 * @widget: a #GtkWidget
10268 * @markup: the contents of the tooltip for @widget, or %NULL
10270 * Sets @markup as the contents of the tooltip, which is marked up with
10271 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10273 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10274 * and of the default handler for the GtkWidget::query-tooltip signal.
10276 * See also the GtkWidget:tooltip-markup property and
10277 * gtk_tooltip_set_markup().
10282 gtk_widget_set_tooltip_markup (GtkWidget *widget,
10283 const gchar *markup)
10285 g_return_if_fail (GTK_IS_WIDGET (widget));
10287 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10291 * gtk_widget_get_tooltip_markup:
10292 * @widget: a #GtkWidget
10294 * Gets the contents of the tooltip for @widget.
10296 * Return value: the tooltip text, or %NULL. You should free the
10297 * returned string with g_free() when done.
10302 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10304 gchar *text = NULL;
10306 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10308 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10314 * gtk_widget_set_has_tooltip:
10315 * @widget: a #GtkWidget
10316 * @has_tooltip: whether or not @widget has a tooltip.
10318 * Sets the has-tooltip property on @widget to @has_tooltip. See
10319 * GtkWidget:has-tooltip for more information.
10324 gtk_widget_set_has_tooltip (GtkWidget *widget,
10325 gboolean has_tooltip)
10327 g_return_if_fail (GTK_IS_WIDGET (widget));
10329 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
10333 * gtk_widget_get_has_tooltip:
10334 * @widget: a #GtkWidget
10336 * Returns the current value of the has-tooltip property. See
10337 * GtkWidget:has-tooltip for more information.
10339 * Return value: current value of has-tooltip on @widget.
10344 gtk_widget_get_has_tooltip (GtkWidget *widget)
10346 gboolean has_tooltip = FALSE;
10348 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10350 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
10352 return has_tooltip;
10356 * gtk_widget_get_window:
10357 * @widget: a #GtkWidget
10359 * Returns the widget's window if it is realized, %NULL otherwise
10361 * Return value: @widget's window.
10366 gtk_widget_get_window (GtkWidget *widget)
10368 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10370 return widget->window;
10373 #define __GTK_WIDGET_C__
10374 #include "gtkaliasdef.c"