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,
159 typedef struct _GtkStateData GtkStateData;
164 guint state_restoration : 1;
165 guint parent_sensitive : 1;
166 guint use_forall : 1;
169 /* --- prototypes --- */
170 static void gtk_widget_class_init (GtkWidgetClass *klass);
171 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
172 static void gtk_widget_init (GtkWidget *widget);
173 static void gtk_widget_set_property (GObject *object,
177 static void gtk_widget_get_property (GObject *object,
181 static void gtk_widget_dispose (GObject *object);
182 static void gtk_widget_real_destroy (GtkObject *object);
183 static void gtk_widget_finalize (GObject *object);
184 static void gtk_widget_real_show (GtkWidget *widget);
185 static void gtk_widget_real_hide (GtkWidget *widget);
186 static void gtk_widget_real_map (GtkWidget *widget);
187 static void gtk_widget_real_unmap (GtkWidget *widget);
188 static void gtk_widget_real_realize (GtkWidget *widget);
189 static void gtk_widget_real_unrealize (GtkWidget *widget);
190 static void gtk_widget_real_size_request (GtkWidget *widget,
191 GtkRequisition *requisition);
192 static void gtk_widget_real_size_allocate (GtkWidget *widget,
193 GtkAllocation *allocation);
194 static void gtk_widget_style_set (GtkWidget *widget,
195 GtkStyle *previous_style);
196 static void gtk_widget_direction_changed (GtkWidget *widget,
197 GtkTextDirection previous_direction);
199 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
200 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
203 gboolean keyboard_tip,
204 GtkTooltip *tooltip);
205 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
206 GtkWidgetHelpType help_type);
208 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
210 GParamSpec **pspecs);
211 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
213 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
215 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
216 GdkEventFocus *event);
217 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
218 GdkEventFocus *event);
219 static gboolean gtk_widget_real_focus (GtkWidget *widget,
220 GtkDirectionType direction);
221 static void gtk_widget_real_move_focus (GtkWidget *widget,
222 GtkDirectionType direction);
223 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
224 GtkDirectionType direction);
225 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
226 static void gtk_widget_update_pango_context (GtkWidget *widget);
227 static void gtk_widget_propagate_state (GtkWidget *widget,
229 static void gtk_widget_reset_rc_style (GtkWidget *widget);
230 static void gtk_widget_set_style_internal (GtkWidget *widget,
232 gboolean initial_emission);
233 static gint gtk_widget_event_internal (GtkWidget *widget,
235 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
236 gboolean group_cycling);
237 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
238 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
239 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
240 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
241 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
243 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
244 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
245 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
248 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
249 gboolean has_tooltip,
251 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
252 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
254 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
255 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
257 const gchar *childname);
258 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
261 const GValue *value);
262 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
265 const gchar *tagname,
266 GMarkupParser *parser,
268 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
271 const gchar *tagname,
273 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
274 GtkBuilder *builder);
277 static void gtk_widget_set_usize_internal (GtkWidget *widget,
280 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
284 /* --- variables --- */
285 static gpointer gtk_widget_parent_class = NULL;
286 static guint widget_signals[LAST_SIGNAL] = { 0 };
287 static GtkStyle *gtk_default_style = NULL;
288 static GSList *colormap_stack = NULL;
289 static guint composite_child_stack = 0;
290 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
291 static GParamSpecPool *style_property_spec_pool = NULL;
293 static GQuark quark_property_parser = 0;
294 static GQuark quark_aux_info = 0;
295 static GQuark quark_accel_path = 0;
296 static GQuark quark_accel_closures = 0;
297 static GQuark quark_event_mask = 0;
298 static GQuark quark_extension_event_mode = 0;
299 static GQuark quark_parent_window = 0;
300 static GQuark quark_shape_info = 0;
301 static GQuark quark_input_shape_info = 0;
302 static GQuark quark_colormap = 0;
303 static GQuark quark_pango_context = 0;
304 static GQuark quark_rc_style = 0;
305 static GQuark quark_accessible_object = 0;
306 static GQuark quark_mnemonic_labels = 0;
307 static GQuark quark_tooltip_markup = 0;
308 static GQuark quark_has_tooltip = 0;
309 static GQuark quark_tooltip_window = 0;
310 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
311 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
313 /* --- functions --- */
315 gtk_widget_get_type (void)
317 static GType widget_type = 0;
319 if (G_UNLIKELY (widget_type == 0))
321 const GTypeInfo widget_info =
323 sizeof (GtkWidgetClass),
324 NULL, /* base_init */
325 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
326 (GClassInitFunc) gtk_widget_class_init,
327 NULL, /* class_finalize */
328 NULL, /* class_init */
331 (GInstanceInitFunc) gtk_widget_init,
332 NULL, /* value_table */
335 const GInterfaceInfo accessibility_info =
337 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
338 (GInterfaceFinalizeFunc) NULL,
339 NULL /* interface data */
342 const GInterfaceInfo buildable_info =
344 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
345 (GInterfaceFinalizeFunc) NULL,
346 NULL /* interface data */
349 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
350 &widget_info, G_TYPE_FLAG_ABSTRACT);
352 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
353 &accessibility_info) ;
354 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
363 child_property_notify_dispatcher (GObject *object,
367 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
371 gtk_widget_class_init (GtkWidgetClass *klass)
373 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
374 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
375 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
376 GtkBindingSet *binding_set;
378 gtk_widget_parent_class = g_type_class_peek_parent (klass);
380 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
381 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
382 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
383 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
384 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
385 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
386 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
387 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
388 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
389 quark_colormap = g_quark_from_static_string ("gtk-colormap");
390 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
391 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
392 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
393 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
394 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
395 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
396 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
398 style_property_spec_pool = g_param_spec_pool_new (FALSE);
399 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
400 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
401 cpn_context.dispatcher = child_property_notify_dispatcher;
402 _gtk_widget_child_property_notify_context = &cpn_context;
404 gobject_class->dispose = gtk_widget_dispose;
405 gobject_class->finalize = gtk_widget_finalize;
406 gobject_class->set_property = gtk_widget_set_property;
407 gobject_class->get_property = gtk_widget_get_property;
409 object_class->destroy = gtk_widget_real_destroy;
411 klass->activate_signal = 0;
412 klass->set_scroll_adjustments_signal = 0;
413 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
414 klass->show = gtk_widget_real_show;
415 klass->show_all = gtk_widget_show;
416 klass->hide = gtk_widget_real_hide;
417 klass->hide_all = gtk_widget_hide;
418 klass->map = gtk_widget_real_map;
419 klass->unmap = gtk_widget_real_unmap;
420 klass->realize = gtk_widget_real_realize;
421 klass->unrealize = gtk_widget_real_unrealize;
422 klass->size_request = gtk_widget_real_size_request;
423 klass->size_allocate = gtk_widget_real_size_allocate;
424 klass->state_changed = NULL;
425 klass->parent_set = NULL;
426 klass->hierarchy_changed = NULL;
427 klass->style_set = gtk_widget_style_set;
428 klass->direction_changed = gtk_widget_direction_changed;
429 klass->grab_notify = NULL;
430 klass->child_notify = NULL;
431 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
432 klass->grab_focus = gtk_widget_real_grab_focus;
433 klass->focus = gtk_widget_real_focus;
435 klass->button_press_event = NULL;
436 klass->button_release_event = NULL;
437 klass->motion_notify_event = NULL;
438 klass->delete_event = NULL;
439 klass->destroy_event = NULL;
440 klass->expose_event = NULL;
441 klass->key_press_event = gtk_widget_real_key_press_event;
442 klass->key_release_event = gtk_widget_real_key_release_event;
443 klass->enter_notify_event = NULL;
444 klass->leave_notify_event = NULL;
445 klass->configure_event = NULL;
446 klass->focus_in_event = gtk_widget_real_focus_in_event;
447 klass->focus_out_event = gtk_widget_real_focus_out_event;
448 klass->map_event = NULL;
449 klass->unmap_event = NULL;
450 klass->window_state_event = NULL;
451 klass->property_notify_event = _gtk_selection_property_notify;
452 klass->selection_clear_event = gtk_selection_clear;
453 klass->selection_request_event = _gtk_selection_request;
454 klass->selection_notify_event = _gtk_selection_notify;
455 klass->selection_received = NULL;
456 klass->proximity_in_event = NULL;
457 klass->proximity_out_event = NULL;
458 klass->drag_begin = NULL;
459 klass->drag_end = NULL;
460 klass->drag_data_delete = NULL;
461 klass->drag_leave = NULL;
462 klass->drag_motion = NULL;
463 klass->drag_drop = NULL;
464 klass->drag_data_received = NULL;
465 klass->screen_changed = NULL;
466 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
467 klass->grab_broken_event = NULL;
468 klass->query_tooltip = gtk_widget_real_query_tooltip;
470 klass->show_help = gtk_widget_real_show_help;
472 /* Accessibility support */
473 klass->get_accessible = gtk_widget_real_get_accessible;
475 klass->no_expose_event = NULL;
477 g_object_class_install_property (gobject_class,
479 g_param_spec_string ("name",
481 P_("The name of the widget"),
483 GTK_PARAM_READWRITE));
484 g_object_class_install_property (gobject_class,
486 g_param_spec_object ("parent",
488 P_("The parent widget of this widget. Must be a Container widget"),
490 GTK_PARAM_READWRITE));
492 g_object_class_install_property (gobject_class,
494 g_param_spec_int ("width-request",
496 P_("Override for width request of the widget, or -1 if natural request should be used"),
500 GTK_PARAM_READWRITE));
501 g_object_class_install_property (gobject_class,
503 g_param_spec_int ("height-request",
504 P_("Height request"),
505 P_("Override for height request of the widget, or -1 if natural request should be used"),
509 GTK_PARAM_READWRITE));
510 g_object_class_install_property (gobject_class,
512 g_param_spec_boolean ("visible",
514 P_("Whether the widget is visible"),
516 GTK_PARAM_READWRITE));
517 g_object_class_install_property (gobject_class,
519 g_param_spec_boolean ("sensitive",
521 P_("Whether the widget responds to input"),
523 GTK_PARAM_READWRITE));
524 g_object_class_install_property (gobject_class,
526 g_param_spec_boolean ("app-paintable",
527 P_("Application paintable"),
528 P_("Whether the application will paint directly on the widget"),
530 GTK_PARAM_READWRITE));
531 g_object_class_install_property (gobject_class,
533 g_param_spec_boolean ("can-focus",
535 P_("Whether the widget can accept the input focus"),
537 GTK_PARAM_READWRITE));
538 g_object_class_install_property (gobject_class,
540 g_param_spec_boolean ("has-focus",
542 P_("Whether the widget has the input focus"),
544 GTK_PARAM_READWRITE));
545 g_object_class_install_property (gobject_class,
547 g_param_spec_boolean ("is-focus",
549 P_("Whether the widget is the focus widget within the toplevel"),
551 GTK_PARAM_READWRITE));
552 g_object_class_install_property (gobject_class,
554 g_param_spec_boolean ("can-default",
556 P_("Whether the widget can be the default widget"),
558 GTK_PARAM_READWRITE));
559 g_object_class_install_property (gobject_class,
561 g_param_spec_boolean ("has-default",
563 P_("Whether the widget is the default widget"),
565 GTK_PARAM_READWRITE));
566 g_object_class_install_property (gobject_class,
567 PROP_RECEIVES_DEFAULT,
568 g_param_spec_boolean ("receives-default",
569 P_("Receives default"),
570 P_("If TRUE, the widget will receive the default action when it is focused"),
572 GTK_PARAM_READWRITE));
573 g_object_class_install_property (gobject_class,
574 PROP_COMPOSITE_CHILD,
575 g_param_spec_boolean ("composite-child",
576 P_("Composite child"),
577 P_("Whether the widget is part of a composite widget"),
579 GTK_PARAM_READABLE));
580 g_object_class_install_property (gobject_class,
582 g_param_spec_object ("style",
584 P_("The style of the widget, which contains information about how it will look (colors etc)"),
586 GTK_PARAM_READWRITE));
587 g_object_class_install_property (gobject_class,
589 g_param_spec_flags ("events",
591 P_("The event mask that decides what kind of GdkEvents this widget gets"),
594 GTK_PARAM_READWRITE));
595 g_object_class_install_property (gobject_class,
596 PROP_EXTENSION_EVENTS,
597 g_param_spec_enum ("extension-events",
598 P_("Extension events"),
599 P_("The mask that decides what kind of extension events this widget gets"),
600 GDK_TYPE_EXTENSION_MODE,
601 GDK_EXTENSION_EVENTS_NONE,
602 GTK_PARAM_READWRITE));
603 g_object_class_install_property (gobject_class,
605 g_param_spec_boolean ("no-show-all",
607 P_("Whether gtk_widget_show_all() should not affect this widget"),
609 GTK_PARAM_READWRITE));
612 * GtkWidget:has-tooltip:
614 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
615 * A value of %TRUE indicates that @widget can have a tooltip, in this case
616 * the widget will be queried using #GtkWidget::query-tooltip to determine
617 * whether it will provide a tooltip or not.
619 * Note that setting this property to %TRUE for the first time will change
620 * the event masks of the GdkWindows of this widget to include leave-notify
621 * and motion-notify events. This cannot and will not be undone when the
622 * property is set to %FALSE again.
626 g_object_class_install_property (gobject_class,
628 g_param_spec_boolean ("has-tooltip",
630 P_("Whether this widget has a tooltip"),
632 GTK_PARAM_READWRITE));
634 * GtkWidget:tooltip-text:
636 * Sets the text of tooltip to be the given string.
638 * Also see gtk_tooltip_set_text().
640 * This is a convenience property which will take care of getting the
641 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
642 * will automatically be set to %TRUE and there will be taken care of
643 * #GtkWidget::query-tooltip in the default signal handler.
647 g_object_class_install_property (gobject_class,
649 g_param_spec_string ("tooltip-text",
651 P_("The contents of the tooltip for this widget"),
653 GTK_PARAM_READWRITE));
655 * GtkWidget:tooltip-markup:
657 * Sets the text of tooltip to be the given string, which is marked up
658 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
659 * Also see gtk_tooltip_set_markup().
661 * This is a convenience property which will take care of getting the
662 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
663 * will automatically be set to %TRUE and there will be taken care of
664 * #GtkWidget::query-tooltip in the default signal handler.
668 g_object_class_install_property (gobject_class,
670 g_param_spec_string ("tooltip-markup",
671 P_("Tooltip markup"),
672 P_("The contents of the tooltip for this widget"),
674 GTK_PARAM_READWRITE));
676 widget_signals[SHOW] =
677 g_signal_new (I_("show"),
678 G_TYPE_FROM_CLASS (gobject_class),
680 G_STRUCT_OFFSET (GtkWidgetClass, show),
682 _gtk_marshal_VOID__VOID,
684 widget_signals[HIDE] =
685 g_signal_new (I_("hide"),
686 G_TYPE_FROM_CLASS (gobject_class),
688 G_STRUCT_OFFSET (GtkWidgetClass, hide),
690 _gtk_marshal_VOID__VOID,
692 widget_signals[MAP] =
693 g_signal_new (I_("map"),
694 G_TYPE_FROM_CLASS (gobject_class),
696 G_STRUCT_OFFSET (GtkWidgetClass, map),
698 _gtk_marshal_VOID__VOID,
700 widget_signals[UNMAP] =
701 g_signal_new (I_("unmap"),
702 G_TYPE_FROM_CLASS (gobject_class),
704 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
706 _gtk_marshal_VOID__VOID,
708 widget_signals[REALIZE] =
709 g_signal_new (I_("realize"),
710 G_TYPE_FROM_CLASS (gobject_class),
712 G_STRUCT_OFFSET (GtkWidgetClass, realize),
714 _gtk_marshal_VOID__VOID,
716 widget_signals[UNREALIZE] =
717 g_signal_new (I_("unrealize"),
718 G_TYPE_FROM_CLASS (gobject_class),
720 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
722 _gtk_marshal_VOID__VOID,
724 widget_signals[SIZE_REQUEST] =
725 g_signal_new (I_("size_request"),
726 G_TYPE_FROM_CLASS (gobject_class),
728 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
730 _gtk_marshal_VOID__BOXED,
732 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
733 widget_signals[SIZE_ALLOCATE] =
734 g_signal_new (I_("size_allocate"),
735 G_TYPE_FROM_CLASS (gobject_class),
737 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
739 _gtk_marshal_VOID__BOXED,
741 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
743 widget_signals[STATE_CHANGED] =
744 g_signal_new (I_("state_changed"),
745 G_TYPE_FROM_CLASS (gobject_class),
747 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
749 _gtk_marshal_VOID__ENUM,
751 GTK_TYPE_STATE_TYPE);
754 * GtkWidget::parent-set:
755 * @widget: the object on which the signal is emitted
756 * @old_parent: the previous parent, or %NULL if the widget
757 * just got its initial parent.
759 * The ::parent-set signal is emitted when a new parent
760 * has been set on a widget.
762 widget_signals[PARENT_SET] =
763 g_signal_new (I_("parent_set"),
764 G_TYPE_FROM_CLASS (gobject_class),
766 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
768 _gtk_marshal_VOID__OBJECT,
773 * GtkWidget::hierarchy-changed:
774 * @widget: the object on which the signal is emitted
775 * @previous_toplevel: the previous toplevel ancestor, or %NULL
776 * if the widget was previously unanchored
778 * The ::hierarchy-changed signal is emitted when the
779 * anchored state of a widget changes. A widget is
780 * <firstterm>anchored</firstterm> when its toplevel
781 * ancestor is a #GtkWindow. This signal is emitted when
782 * a widget changes from un-anchored to anchored or vice-versa.
784 widget_signals[HIERARCHY_CHANGED] =
785 g_signal_new (I_("hierarchy_changed"),
786 G_TYPE_FROM_CLASS (gobject_class),
788 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
790 _gtk_marshal_VOID__OBJECT,
795 * GtkWidget::style-set:
796 * @widget: the object on which the signal is emitted
797 * @previous_style: the previous style, or %NULL if the widget
798 * just got its initial style
800 * The ::style-set signal is emitted when a new style has been set
801 * on a widget. Note that style-modifying functions like
802 * gtk_widget_modify_base() also cause this signal to be emitted.
804 widget_signals[STYLE_SET] =
805 g_signal_new (I_("style_set"),
806 G_TYPE_FROM_CLASS (gobject_class),
808 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
810 _gtk_marshal_VOID__OBJECT,
814 * GtkWidget::direction-changed:
815 * @widget: the object on which the signal is emitted
816 * @previous_direction: the previous text direction of @widget
818 * The ::direction-changed signal is emitted when the text direction
819 * of a widget changes.
821 widget_signals[DIRECTION_CHANGED] =
822 g_signal_new (I_("direction_changed"),
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
827 _gtk_marshal_VOID__ENUM,
829 GTK_TYPE_TEXT_DIRECTION);
832 * GtkWidget::grab-notify:
833 * @widget: the object which received the signal
834 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
835 * if it becomes unshadowed
837 * The ::grab-notify signal is emitted when a widget becomes
838 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
839 * another widget, or when it becomes unshadowed due to a grab
842 * A widget is shadowed by a gtk_grab_add() when the topmost
843 * grab widget in the grab stack of its window group is not
846 widget_signals[GRAB_NOTIFY] =
847 g_signal_new (I_("grab_notify"),
848 G_TYPE_FROM_CLASS (gobject_class),
850 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
852 _gtk_marshal_VOID__BOOLEAN,
857 * GtkWidget::child-notify:
858 * @widget: the object which received the signal
859 * @pspec: the #GParamSpec of the changed child property
861 * The ::child-notify signal is emitted for each
862 * <link linkend="child-properties">child property</link> that has
863 * changed on an object. The signal's detail holds the property name.
865 widget_signals[CHILD_NOTIFY] =
866 g_signal_new (I_("child_notify"),
867 G_TYPE_FROM_CLASS (gobject_class),
868 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
869 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
871 g_cclosure_marshal_VOID__PARAM,
874 widget_signals[MNEMONIC_ACTIVATE] =
875 g_signal_new (I_("mnemonic_activate"),
876 G_TYPE_FROM_CLASS (gobject_class),
878 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
879 _gtk_boolean_handled_accumulator, NULL,
880 _gtk_marshal_BOOLEAN__BOOLEAN,
883 widget_signals[GRAB_FOCUS] =
884 g_signal_new (I_("grab_focus"),
885 G_TYPE_FROM_CLASS (gobject_class),
886 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
887 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
889 _gtk_marshal_VOID__VOID,
891 widget_signals[FOCUS] =
892 g_signal_new (I_("focus"),
893 G_TYPE_FROM_CLASS (object_class),
895 G_STRUCT_OFFSET (GtkWidgetClass, focus),
896 _gtk_boolean_handled_accumulator, NULL,
897 _gtk_marshal_BOOLEAN__ENUM,
899 GTK_TYPE_DIRECTION_TYPE);
900 widget_signals[MOVE_FOCUS] =
901 _gtk_binding_signal_new (I_("move_focus"),
902 G_TYPE_FROM_CLASS (object_class),
903 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
904 G_CALLBACK (gtk_widget_real_move_focus),
906 _gtk_marshal_VOID__ENUM,
909 GTK_TYPE_DIRECTION_TYPE);
912 * @widget: the object which received the signal.
913 * @event: the #GdkEvent which triggered this signal
915 * The GTK+ main loop will emit three signals for each GDK event delivered
916 * to a widget: one generic ::event signal, another, more specific,
917 * signal that matches the type of event delivered (e.g.
918 * #GtkWidget::key-press-event) and finally a generic
919 * #GtkWidget::event-after signal.
921 * Returns: %TRUE to stop other handlers from being invoked for the event
922 * and to cancel the emission of the second specific ::event signal.
923 * %FALSE to propagate the event further and to allow the emission of
924 * the second signal. The ::event-after signal is emitted regardless of
927 widget_signals[EVENT] =
928 g_signal_new (I_("event"),
929 G_TYPE_FROM_CLASS (gobject_class),
931 G_STRUCT_OFFSET (GtkWidgetClass, event),
932 _gtk_boolean_handled_accumulator, NULL,
933 _gtk_marshal_BOOLEAN__BOXED,
935 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
938 * GtkWidget::event-after:
939 * @widget: the object which received the signal.
940 * @event: the #GdkEvent which triggered this signal
942 * After the emission of the #GtkWidget::event signal and (optionally)
943 * the second more specific signal, ::event-after will be emitted
944 * regardless of the previous two signals handlers return values.
947 widget_signals[EVENT_AFTER] =
948 g_signal_new (I_("event_after"),
949 G_TYPE_FROM_CLASS (gobject_class),
953 _gtk_marshal_VOID__BOXED,
955 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
958 * GtkWidget::button-press-event:
959 * @widget: the object which received the signal.
960 * @event: the #GdkEventButton which triggered this signal
962 * The ::button-press-event signal will be emitted when a button
963 * (typically from a mouse) is pressed.
965 * To receive this signal, the #GdkWindow associated to the
966 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
968 * This signal will be sent to the grab widget if there is one.
970 * Returns: %TRUE to stop other handlers from being invoked for the event.
971 * %FALSE to propagate the event further.
973 widget_signals[BUTTON_PRESS_EVENT] =
974 g_signal_new (I_("button_press_event"),
975 G_TYPE_FROM_CLASS (gobject_class),
977 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
978 _gtk_boolean_handled_accumulator, NULL,
979 _gtk_marshal_BOOLEAN__BOXED,
981 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
984 * GtkWidget::button-release-event:
985 * @widget: the object which received the signal.
986 * @event: the #GdkEventButton which triggered this signal
988 * The ::button-release-event signal will be emitted when a button
989 * (typically from a mouse) is released.
991 * To receive this signal, the #GdkWindow associated to the
992 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
994 * This signal will be sent to the grab widget if there is one.
996 * Returns: %TRUE to stop other handlers from being invoked for the event.
997 * %FALSE to propagate the event further.
999 widget_signals[BUTTON_RELEASE_EVENT] =
1000 g_signal_new (I_("button_release_event"),
1001 G_TYPE_FROM_CLASS (gobject_class),
1003 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1004 _gtk_boolean_handled_accumulator, NULL,
1005 _gtk_marshal_BOOLEAN__BOXED,
1007 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1010 * GtkWidget::scroll-event:
1011 * @widget: the object which received the signal.
1012 * @event: the #GdkEventScroll which triggered this signal
1014 * The ::scroll-event signal is emitted when a button in the 4 to 7
1015 * range is pressed. Wheel mice are usually configured to generate
1016 * button press events for buttons 4 and 5 when the wheel is turned.
1018 * To receive this signal, the #GdkWindow associated to the widget needs
1019 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1021 * This signal will be sent to the grab widget if there is one.
1023 * Returns: %TRUE to stop other handlers from being invoked for the event.
1024 * %FALSE to propagate the event further.
1026 widget_signals[SCROLL_EVENT] =
1027 g_signal_new (I_("scroll_event"),
1028 G_TYPE_FROM_CLASS (gobject_class),
1030 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1031 _gtk_boolean_handled_accumulator, NULL,
1032 _gtk_marshal_BOOLEAN__BOXED,
1034 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1036 * GtkWidget::motion-notify-event:
1037 * @widget: the object which received the signal.
1038 * @event: the #GdkEventMotion which triggered this signal
1040 * The ::motion-notify-event signal is emitted when the pointer moves
1041 * over the widget's #GdkWindow.
1043 * To receive this signal, the #GdkWindow associated to the widget
1044 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1046 * This signal will be sent to the grab widget if there is one.
1048 * Returns: %TRUE to stop other handlers from being invoked for the event.
1049 * %FALSE to propagate the event further.
1051 widget_signals[MOTION_NOTIFY_EVENT] =
1052 g_signal_new (I_("motion_notify_event"),
1053 G_TYPE_FROM_CLASS (gobject_class),
1055 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1056 _gtk_boolean_handled_accumulator, NULL,
1057 _gtk_marshal_BOOLEAN__BOXED,
1059 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1062 * GtkWidget::composited-changed:
1063 * @widget: the object on which the signal is emitted
1065 * The ::composited-changed signal is emitted when the composited
1066 * status of @widget<!-- -->s screen changes.
1067 * See gdk_screen_is_composited().
1069 widget_signals[COMPOSITED_CHANGED] =
1070 g_signal_new (I_("composited_changed"),
1071 G_TYPE_FROM_CLASS (gobject_class),
1072 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1073 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1075 _gtk_marshal_VOID__VOID,
1079 * GtkWidget::keynav-failed:
1080 * @widget: the object which received the signal
1081 * @direction: the direction of movement
1083 * Gets emitted if keyboard navigation fails.
1084 * See gtk_widget_keynav_failed() for details.
1086 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1087 * if the emitting widget should try to handle the keyboard
1088 * navigation attempt in its parent container(s).
1092 widget_signals[KEYNAV_FAILED] =
1093 _gtk_binding_signal_new (I_("keynav-failed"),
1094 G_TYPE_FROM_CLASS (gobject_class),
1096 G_CALLBACK (gtk_widget_real_keynav_failed),
1097 _gtk_boolean_handled_accumulator, NULL,
1098 _gtk_marshal_BOOLEAN__ENUM,
1100 GTK_TYPE_DIRECTION_TYPE);
1103 * GtkWidget::delete-event:
1104 * @widget: the object which received the signal
1105 * @event: the event which triggered this signal
1107 * The ::delete-event signal is emitted if a user requests that
1108 * a toplevel window is closed. The default handler for this signal
1109 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1110 * this signal will cause the window to be hidden instead, so that
1111 * it can later be shown again without reconstructing it.
1113 * Returns: %TRUE to stop other handlers from being invoked for the event.
1114 * %FALSE to propagate the event further.
1116 widget_signals[DELETE_EVENT] =
1117 g_signal_new (I_("delete_event"),
1118 G_TYPE_FROM_CLASS (gobject_class),
1120 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1121 _gtk_boolean_handled_accumulator, NULL,
1122 _gtk_marshal_BOOLEAN__BOXED,
1124 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1127 * GtkWidget::destroy-event:
1128 * @widget: the object which received the signal.
1129 * @event: the event which triggered this signal
1131 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1132 * You rarely get this signal, because most widgets disconnect themselves
1133 * from their window before they destroy it, so no widget owns the
1134 * window at destroy time.
1136 * To receive this signal, the #GdkWindow associated to the widget needs
1137 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1138 * automatically for all new windows.
1140 * Returns: %TRUE to stop other handlers from being invoked for the event.
1141 * %FALSE to propagate the event further.
1143 widget_signals[DESTROY_EVENT] =
1144 g_signal_new (I_("destroy_event"),
1145 G_TYPE_FROM_CLASS (gobject_class),
1147 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1148 _gtk_boolean_handled_accumulator, NULL,
1149 _gtk_marshal_BOOLEAN__BOXED,
1151 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1154 * GtkWidget::expose-event:
1155 * @widget: the object which received the signal.
1156 * @event: the #GdkEventExpose which triggered this signal
1158 * The ::expose-event signal is emitted when an area of a previously
1159 * obscured #GdkWindow is made visible and needs to be redrawn.
1160 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1163 * To receive this signal, the #GdkWindow associated to the widget needs
1164 * to enable the #GDK_EXPOSURE_MASK mask.
1166 * Returns: %TRUE to stop other handlers from being invoked for the event.
1167 * %FALSE to propagate the event further.
1169 widget_signals[EXPOSE_EVENT] =
1170 g_signal_new (I_("expose_event"),
1171 G_TYPE_FROM_CLASS (gobject_class),
1173 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1174 _gtk_boolean_handled_accumulator, NULL,
1175 _gtk_marshal_BOOLEAN__BOXED,
1177 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1180 * GtkWidget::key-press-event:
1181 * @widget: the object which received the signal
1182 * @event: the #GdkEventKey which triggered this signal
1184 * The ::key-press-event signal is emitted when a key is pressed.
1186 * To receive this signal, the #GdkWindow associated to the widget needs
1187 * to enable the #GDK_KEY_PRESS_MASK mask.
1189 * This signal will be sent to the grab widget if there is one.
1191 * Returns: %TRUE to stop other handlers from being invoked for the event.
1192 * %FALSE to propagate the event further.
1194 widget_signals[KEY_PRESS_EVENT] =
1195 g_signal_new (I_("key_press_event"),
1196 G_TYPE_FROM_CLASS (gobject_class),
1198 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1199 _gtk_boolean_handled_accumulator, NULL,
1200 _gtk_marshal_BOOLEAN__BOXED,
1202 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1205 * GtkWidget::key-release-event:
1206 * @widget: the object which received the signal
1207 * @event: the #GdkEventKey which triggered this signal
1209 * The ::key-release-event signal is emitted when a key is pressed.
1211 * To receive this signal, the #GdkWindow associated to the widget needs
1212 * to enable the #GDK_KEY_RELEASE_MASK mask.
1214 * This signal will be sent to the grab widget if there is one.
1216 * Returns: %TRUE to stop other handlers from being invoked for the event.
1217 * %FALSE to propagate the event further.
1219 widget_signals[KEY_RELEASE_EVENT] =
1220 g_signal_new (I_("key_release_event"),
1221 G_TYPE_FROM_CLASS (gobject_class),
1223 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1224 _gtk_boolean_handled_accumulator, NULL,
1225 _gtk_marshal_BOOLEAN__BOXED,
1227 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1230 * GtkWidget::enter-notify-event:
1231 * @widget: the object which received the signal
1232 * @event: the #GdkEventCrossing which triggered this signal
1234 * The ::enter-notify-event will be emitted when the pointer enters
1235 * the @widget's window.
1237 * To receive this signal, the #GdkWindow associated to the widget needs
1238 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1240 * This signal will be sent to the grab widget if there is one.
1242 * Returns: %TRUE to stop other handlers from being invoked for the event.
1243 * %FALSE to propagate the event further.
1245 widget_signals[ENTER_NOTIFY_EVENT] =
1246 g_signal_new (I_("enter_notify_event"),
1247 G_TYPE_FROM_CLASS (gobject_class),
1249 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1250 _gtk_boolean_handled_accumulator, NULL,
1251 _gtk_marshal_BOOLEAN__BOXED,
1253 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1256 * GtkWidget::leave-notify-event:
1257 * @widget: the object which received the signal
1258 * @event: the #GdkEventCrossing which triggered this signal
1260 * The ::leave-notify-event will be emitted when the pointer leaves
1261 * the @widget's window.
1263 * To receive this signal, the #GdkWindow associated to the widget needs
1264 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1266 * This signal will be sent to the grab widget if there is one.
1268 * Returns: %TRUE to stop other handlers from being invoked for the event.
1269 * %FALSE to propagate the event further.
1271 widget_signals[LEAVE_NOTIFY_EVENT] =
1272 g_signal_new (I_("leave_notify_event"),
1273 G_TYPE_FROM_CLASS (gobject_class),
1275 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1276 _gtk_boolean_handled_accumulator, NULL,
1277 _gtk_marshal_BOOLEAN__BOXED,
1279 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1282 * GtkWidget::configure-event
1283 * @widget: the object which received the signal
1284 * @event: the #GdkEventConfigure which triggered this signal
1286 * The ::configure-event signal will be emitted when the size, position or
1287 * stacking of the @widget's window has changed.
1289 * To receive this signal, the #GdkWindow associated to the widget needs
1290 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1291 * automatically for all new windows.
1293 * Returns: %TRUE to stop other handlers from being invoked for the event.
1294 * %FALSE to propagate the event further.
1296 widget_signals[CONFIGURE_EVENT] =
1297 g_signal_new (I_("configure_event"),
1298 G_TYPE_FROM_CLASS (gobject_class),
1300 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1301 _gtk_boolean_handled_accumulator, NULL,
1302 _gtk_marshal_BOOLEAN__BOXED,
1304 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1307 * GtkWidget::focus-in-event
1308 * @widget: the object which received the signal
1309 * @event: the #GdkEventFocus which triggered this signal
1311 * The ::focus-in-event signal will be emitted when the keyboard focus
1312 * enters the @widget's window.
1314 * To receive this signal, the #GdkWindow associated to the widget needs
1315 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1317 * Returns: %TRUE to stop other handlers from being invoked for the event.
1318 * %FALSE to propagate the event further.
1320 widget_signals[FOCUS_IN_EVENT] =
1321 g_signal_new (I_("focus_in_event"),
1322 G_TYPE_FROM_CLASS (gobject_class),
1324 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1325 _gtk_boolean_handled_accumulator, NULL,
1326 _gtk_marshal_BOOLEAN__BOXED,
1328 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1331 * GtkWidget::focus-out-event
1332 * @widget: the object which received the signal
1333 * @event: the #GdkEventFocus which triggered this signal
1335 * The ::focus-out-event signal will be emitted when the keyboard focus
1336 * leaves the @widget's window.
1338 * To receive this signal, the #GdkWindow associated to the widget needs
1339 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1341 * Returns: %TRUE to stop other handlers from being invoked for the event.
1342 * %FALSE to propagate the event further.
1344 widget_signals[FOCUS_OUT_EVENT] =
1345 g_signal_new (I_("focus_out_event"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1349 _gtk_boolean_handled_accumulator, NULL,
1350 _gtk_marshal_BOOLEAN__BOXED,
1352 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1355 * GtkWidget::map-event
1356 * @widget: the object which received the signal
1357 * @event: the #GdkEventAny which triggered this signal
1359 * The ::map-event signal will be emitted when the @widget's window is
1360 * mapped. A window is mapped when it becomes visible on the screen.
1362 * To receive this signal, the #GdkWindow associated to the widget needs
1363 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1364 * automatically for all new windows.
1366 * Returns: %TRUE to stop other handlers from being invoked for the event.
1367 * %FALSE to propagate the event further.
1369 widget_signals[MAP_EVENT] =
1370 g_signal_new (I_("map_event"),
1371 G_TYPE_FROM_CLASS (gobject_class),
1373 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1374 _gtk_boolean_handled_accumulator, NULL,
1375 _gtk_marshal_BOOLEAN__BOXED,
1377 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1380 * GtkWidget::unmap-event
1381 * @widget: the object which received the signal
1382 * @event: the #GdkEventAny which triggered this signal
1384 * The ::unmap-event signal will be emitted when the @widget's window is
1385 * unmapped. A window is unmapped when it becomes invisible on the screen.
1387 * To receive this signal, the #GdkWindow associated to the widget needs
1388 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1389 * automatically for all new windows.
1391 * Returns: %TRUE to stop other handlers from being invoked for the event.
1392 * %FALSE to propagate the event further.
1394 widget_signals[UNMAP_EVENT] =
1395 g_signal_new (I_("unmap_event"),
1396 G_TYPE_FROM_CLASS (gobject_class),
1398 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1399 _gtk_boolean_handled_accumulator, NULL,
1400 _gtk_marshal_BOOLEAN__BOXED,
1402 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1405 * GtkWidget::property-notify-event
1406 * @widget: the object which received the signal
1407 * @event: the #GdkEventProperty which triggered this signal
1409 * The ::property-notify-event signal will be emitted when a property on
1410 * the @widget's window has been changed or deleted.
1412 * To receive this signal, the #GdkWindow associated to the widget needs
1413 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1415 * Returns: %TRUE to stop other handlers from being invoked for the event.
1416 * %FALSE to propagate the event further.
1418 widget_signals[PROPERTY_NOTIFY_EVENT] =
1419 g_signal_new (I_("property_notify_event"),
1420 G_TYPE_FROM_CLASS (gobject_class),
1422 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1423 _gtk_boolean_handled_accumulator, NULL,
1424 _gtk_marshal_BOOLEAN__BOXED,
1426 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1429 * GtkWidget::selection-clear-event
1430 * @widget: the object which received the signal
1431 * @event: the #GdkEventSelection which triggered this signal
1433 * The ::selection-clear-event signal will be emitted when the
1434 * the @widget's window has lost ownership of a selection.
1436 * Returns: %TRUE to stop other handlers from being invoked for the event.
1437 * %FALSE to propagate the event further.
1439 widget_signals[SELECTION_CLEAR_EVENT] =
1440 g_signal_new (I_("selection_clear_event"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1444 _gtk_boolean_handled_accumulator, NULL,
1445 _gtk_marshal_BOOLEAN__BOXED,
1447 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1450 * GtkWidget::selection-request-event
1451 * @widget: the object which received the signal
1452 * @event: the #GdkEventSelection which triggered this signal
1454 * The ::selection-request-event signal will be emitted when
1455 * another client requests ownership of the selection owned by
1456 * the @widget's window.
1458 * Returns: %TRUE to stop other handlers from being invoked for the event.
1459 * %FALSE to propagate the event further.
1461 widget_signals[SELECTION_REQUEST_EVENT] =
1462 g_signal_new (I_("selection_request_event"),
1463 G_TYPE_FROM_CLASS (gobject_class),
1465 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1466 _gtk_boolean_handled_accumulator, NULL,
1467 _gtk_marshal_BOOLEAN__BOXED,
1469 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1471 widget_signals[SELECTION_NOTIFY_EVENT] =
1472 g_signal_new (I_("selection_notify_event"),
1473 G_TYPE_FROM_CLASS (gobject_class),
1475 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1476 _gtk_boolean_handled_accumulator, NULL,
1477 _gtk_marshal_BOOLEAN__BOXED,
1479 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1481 widget_signals[SELECTION_RECEIVED] =
1482 g_signal_new (I_("selection_received"),
1483 G_TYPE_FROM_CLASS (gobject_class),
1485 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1487 _gtk_marshal_VOID__BOXED_UINT,
1489 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1492 widget_signals[SELECTION_GET] =
1493 g_signal_new (I_("selection_get"),
1494 G_TYPE_FROM_CLASS (gobject_class),
1496 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1498 _gtk_marshal_VOID__BOXED_UINT_UINT,
1500 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1505 * GtkWidget::proximity-in-event
1506 * @widget: the object which received the signal
1507 * @event: the #GdkEventProximity which triggered this signal
1509 * To receive this signal the #GdkWindow associated to the widget needs
1510 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1512 * This signal will be sent to the grab widget if there is one.
1514 * Returns: %TRUE to stop other handlers from being invoked for the event.
1515 * %FALSE to propagate the event further.
1517 widget_signals[PROXIMITY_IN_EVENT] =
1518 g_signal_new (I_("proximity_in_event"),
1519 G_TYPE_FROM_CLASS (gobject_class),
1521 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1522 _gtk_boolean_handled_accumulator, NULL,
1523 _gtk_marshal_BOOLEAN__BOXED,
1525 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1528 * GtkWidget::proximity-out-event
1529 * @widget: the object which received the signal
1530 * @event: the #GdkEventProximity which triggered this signal
1532 * To receive this signal the #GdkWindow associated to the widget needs
1533 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1535 * This signal will be sent to the grab widget if there is one.
1537 * Returns: %TRUE to stop other handlers from being invoked for the event.
1538 * %FALSE to propagate the event further.
1540 widget_signals[PROXIMITY_OUT_EVENT] =
1541 g_signal_new (I_("proximity_out_event"),
1542 G_TYPE_FROM_CLASS (gobject_class),
1544 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1545 _gtk_boolean_handled_accumulator, NULL,
1546 _gtk_marshal_BOOLEAN__BOXED,
1548 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1551 * GtkWidget::drag-leave:
1552 * @widget: the object which received the signal.
1553 * @drag_context: the drag context
1554 * @time: the timestamp of the motion event
1556 * The ::drag-leave signal is emitted on the drop site when the cursor
1557 * leaves the widget. A typical reason to connect to this signal is to
1558 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1559 * with gtk_drag_unhighlight()
1561 widget_signals[DRAG_LEAVE] =
1562 g_signal_new (I_("drag_leave"),
1563 G_TYPE_FROM_CLASS (gobject_class),
1565 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1567 _gtk_marshal_VOID__OBJECT_UINT,
1569 GDK_TYPE_DRAG_CONTEXT,
1573 * GtkWidget::drag-begin:
1574 * @widget: the object which received the signal
1575 * @drag_context: the drag context
1577 * The ::drag-begin signal is emitted on the drag source when a drag is
1578 * started. A typical reason to connect to this signal is to set up a
1579 * custom drag icon with gtk_drag_source_set_icon().
1581 widget_signals[DRAG_BEGIN] =
1582 g_signal_new (I_("drag_begin"),
1583 G_TYPE_FROM_CLASS (gobject_class),
1585 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1587 _gtk_marshal_VOID__OBJECT,
1589 GDK_TYPE_DRAG_CONTEXT);
1592 * GtkWidget::drag-end:
1593 * @widget: the object which received the signal
1594 * @drag_context: the drag context
1596 * The ::drag-end signal is emitted on the drag source when a drag is
1597 * finished. A typical reason to connect to this signal is to undo
1598 * things done in #GtkWidget::drag-begin.
1600 widget_signals[DRAG_END] =
1601 g_signal_new (I_("drag_end"),
1602 G_TYPE_FROM_CLASS (gobject_class),
1604 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1606 _gtk_marshal_VOID__OBJECT,
1608 GDK_TYPE_DRAG_CONTEXT);
1611 * GtkWidget::drag-data-delete:
1612 * @widget: the object which received the signal
1613 * @drag_context: the drag context
1615 * The ::drag-data-delete signal is emitted on the drag source when a drag
1616 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1617 * handler is responsible for deleting the data that has been dropped. What
1618 * "delete" means depends on the context of the drag operation.
1620 widget_signals[DRAG_DATA_DELETE] =
1621 g_signal_new (I_("drag_data_delete"),
1622 G_TYPE_FROM_CLASS (gobject_class),
1624 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1626 _gtk_marshal_VOID__OBJECT,
1628 GDK_TYPE_DRAG_CONTEXT);
1631 * GtkWidget::drag-failed:
1632 * @widget: the object which received the signal
1633 * @drag_context: the drag context
1634 * @result: the result of the drag operation
1636 * The ::drag-failed signal is emitted on the drag source when a drag has
1637 * failed. The signal handler may hook custom code to handle a failed DND
1638 * operation based on the type of error, it returns %TRUE is the failure has
1639 * been already handled (not showing the default "drag operation failed"
1640 * animation), otherwise it returns %FALSE.
1642 * Return value: %TRUE if the failed drag operation has been already handled.
1646 widget_signals[DRAG_FAILED] =
1647 g_signal_new (I_("drag_failed"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1650 0, _gtk_boolean_handled_accumulator, NULL,
1651 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1653 GDK_TYPE_DRAG_CONTEXT,
1654 GTK_TYPE_DRAG_RESULT);
1657 * GtkWidget::drag-motion:
1658 * @widget: the object which received the signal
1659 * @drag_context: the drag context
1660 * @x: the x coordinate of the current cursor position
1661 * @y: the y coordinate of the current cursor position
1662 * @time: the timestamp of the motion event
1663 * @returns: whether the cursor position is in a drop zone
1665 * The drag-motion signal is emitted on the drop site when the user
1666 * moves the cursor over the widget during a drag. The signal handler
1667 * must determine whether the cursor position is in a drop zone or not.
1668 * If it is not in a drop zone, it returns %FALSE and no further processing
1669 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1670 * handler is responsible for providing the necessary information for
1671 * displaying feedback to the user, by calling gdk_drag_status().
1673 * If the decision whether the drop will be accepted or rejected can't be
1674 * made based solely on the cursor position and the type of the data, the
1675 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1676 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1677 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1678 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1679 * when using the drag-motion signal that way.
1681 * Also note that there is no drag-enter signal. The drag receiver has to
1682 * keep track of whether he has received any drag-motion signals since the
1683 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1684 * an "enter" signal. Upon an "enter", the handler will typically highlight
1685 * the drop site with gtk_drag_highlight().
1688 * drag_motion (GtkWidget *widget,
1689 * GdkDragContext *context,
1696 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1698 * if (!private_data->drag_highlight)
1700 * private_data->drag_highlight = 1;
1701 * gtk_drag_highlight (widget);
1704 * target = gtk_drag_dest_find_target (widget, context, NULL);
1705 * if (target == GDK_NONE)
1706 * gdk_drag_status (context, 0, time);
1709 * private_data->pending_status = context->suggested_action;
1710 * gtk_drag_get_data (widget, context, target, time);
1717 * drag_data_received (GtkWidget *widget,
1718 * GdkDragContext *context,
1721 * GtkSelectionData *selection_data,
1725 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1727 * if (private_data->suggested_action)
1729 * private_data->suggested_action = 0;
1731 * /* We are getting this data due to a request in drag_motion,
1732 * * rather than due to a request in drag_drop, so we are just
1733 * * supposed to call gdk_drag_status (), not actually paste in
1736 * str = gtk_selection_data_get_text (selection_data);
1737 * if (!data_is_acceptable (str))
1738 * gdk_drag_status (context, 0, time);
1740 * gdk_drag_status (context, private_data->suggested_action, time);
1744 * /* accept the drop */
1749 widget_signals[DRAG_MOTION] =
1750 g_signal_new (I_("drag_motion"),
1751 G_TYPE_FROM_CLASS (gobject_class),
1753 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1754 _gtk_boolean_handled_accumulator, NULL,
1755 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1757 GDK_TYPE_DRAG_CONTEXT,
1763 * GtkWidget::drag-drop:
1764 * @widget: the object which received the signal
1765 * @drag_context: the drag context
1766 * @x: the x coordinate of the current cursor position
1767 * @y: the y coordinate of the current cursor position
1768 * @time: the timestamp of the motion event
1769 * @returns: whether the cursor position is in a drop zone
1771 * The ::drag-drop signal is emitted on the drop site when the user drops
1772 * the data onto the widget. The signal handler must determine whether
1773 * the cursor position is in a drop zone or not. If it is not in a drop
1774 * zone, it returns %FALSE and no further processing is necessary.
1775 * Otherwise, the handler returns %TRUE. In this case, the handler must
1776 * ensure that gtk_drag_finish() is called to let the source know that
1777 * the drop is done. The call to gtk_drag_finish() can be done either
1778 * directly or in a #GtkWidget::drag-data-received handler which gets
1779 * triggered by calling gtk_drag_get_data() to receive the data for one
1780 * or more of the supported targets.
1782 widget_signals[DRAG_DROP] =
1783 g_signal_new (I_("drag_drop"),
1784 G_TYPE_FROM_CLASS (gobject_class),
1786 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1787 _gtk_boolean_handled_accumulator, NULL,
1788 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1790 GDK_TYPE_DRAG_CONTEXT,
1796 * GtkWidget::drag-data-get:
1797 * @widget: the object which received the signal
1798 * @drag_context: the drag context
1799 * @data: the #GtkSelectionData to be filled with the dragged data
1800 * @info: the info that has been registered with the target in the
1802 * @time: the timestamp at which the data was requested
1804 * The ::drag-data-get signal is emitted on the drag source when the drop
1805 * site requests the data which is dragged. It is the responsibility of
1806 * the signal handler to fill @data with the data in the format which
1807 * is indicated by @info. See gtk_selection_data_set() and
1808 * gtk_selection_data_set_text().
1810 widget_signals[DRAG_DATA_GET] =
1811 g_signal_new (I_("drag_data_get"),
1812 G_TYPE_FROM_CLASS (gobject_class),
1814 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1816 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1818 GDK_TYPE_DRAG_CONTEXT,
1819 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1824 * GtkWidget::drag-data-received:
1825 * @widget: the object which received the signal
1826 * @drag_context: the drag context
1827 * @x: where the drop happened
1828 * @y: where the drop happened
1829 * @data: the received data
1830 * @info: the info that has been registered with the target in the
1832 * @time: the timestamp at which the data was received
1834 * The ::drag-data-received signal is emitted on the drop site when the
1835 * dragged data has been received. If the data was received in order to
1836 * determine whether the drop will be accepted, the handler is expected
1837 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1838 * If the data was received in response to a #GtkWidget::drag-drop signal
1839 * (and this is the last target to be received), the handler for this
1840 * signal is expected to process the received data and then call
1841 * gtk_drag_finish(), setting the @success parameter depending on whether
1842 * the data was processed successfully.
1844 * The handler may inspect and modify @drag_context->action before calling
1845 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1846 * following example:
1849 * drag_data_received (GtkWidget *widget,
1850 * GdkDragContext *drag_context,
1853 * GtkSelectionData *data,
1857 * if ((data->length >= 0) && (data->format == 8))
1859 * if (drag_context->action == GDK_ACTION_ASK)
1861 * GtkWidget *dialog;
1864 * dialog = gtk_message_dialog_new (NULL,
1865 * GTK_DIALOG_MODAL |
1866 * GTK_DIALOG_DESTROY_WITH_PARENT,
1868 * GTK_BUTTONS_YES_NO,
1869 * "Move the data ?\n");
1870 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1871 * gtk_widget_destroy (dialog);
1873 * if (response == GTK_RESPONSE_YES)
1874 * drag_context->action = GDK_ACTION_MOVE;
1876 * drag_context->action = GDK_ACTION_COPY;
1879 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1883 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1887 widget_signals[DRAG_DATA_RECEIVED] =
1888 g_signal_new (I_("drag_data_received"),
1889 G_TYPE_FROM_CLASS (gobject_class),
1891 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1893 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1895 GDK_TYPE_DRAG_CONTEXT,
1898 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1903 * GtkWidget::visibility-notify-event:
1904 * @widget: the object which received the signal
1905 * @event: the #GdkEventVisibility which triggered this signal
1907 * The ::visibility-notify-event will be emitted when the @widget's window
1908 * is obscured or unobscured.
1910 * To receive this signal the #GdkWindow associated to the widget needs
1911 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1913 * Returns: %TRUE to stop other handlers from being invoked for the event.
1914 * %FALSE to propagate the event further.
1916 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1917 g_signal_new (I_("visibility_notify_event"),
1918 G_TYPE_FROM_CLASS (gobject_class),
1920 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1921 _gtk_boolean_handled_accumulator, NULL,
1922 _gtk_marshal_BOOLEAN__BOXED,
1924 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1927 * GtkWidget::client-event:
1928 * @widget: the object which received the signal
1929 * @event: the #GdkEventClient which triggered this signal
1931 * The ::client-event will be emitted when the @widget's window
1932 * receives a message (via a ClientMessage event) from another
1935 * Returns: %TRUE to stop other handlers from being invoked for
1936 * the event. %FALSE to propagate the event further.
1938 widget_signals[CLIENT_EVENT] =
1939 g_signal_new (I_("client_event"),
1940 G_TYPE_FROM_CLASS (gobject_class),
1942 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1943 _gtk_boolean_handled_accumulator, NULL,
1944 _gtk_marshal_BOOLEAN__BOXED,
1946 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1949 * GtkWidget::no-expose-event:
1950 * @widget: the object which received the signal
1951 * @event: the #GdkEventNoExpose which triggered this signal
1953 * The ::no-expose-event will be emitted when the @widget's window is
1954 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1955 * gdk_window_copy_area()) which was completely unobscured. If the source
1956 * window was partially obscured #GdkEventExpose events will be generated
1959 * Returns: %TRUE to stop other handlers from being invoked for the event.
1960 * %FALSE to propagate the event further.
1962 widget_signals[NO_EXPOSE_EVENT] =
1963 g_signal_new (I_("no_expose_event"),
1964 G_TYPE_FROM_CLASS (gobject_class),
1966 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1967 _gtk_boolean_handled_accumulator, NULL,
1968 _gtk_marshal_BOOLEAN__BOXED,
1970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1973 * GtkWidget::window-state-event:
1974 * @widget: the object which received the signal
1975 * @event: the #GdkEventWindowState which triggered this signal
1977 * The ::window-state-event will be emitted when the state of the
1978 * toplevel window associated to the @widget changes.
1980 * To receive this signal the #GdkWindow associated to the widget
1981 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
1982 * this mask automatically for all new windows.
1984 * Returns: %TRUE to stop other handlers from being invoked for the
1985 * event. %FALSE to propagate the event further.
1987 widget_signals[WINDOW_STATE_EVENT] =
1988 g_signal_new (I_("window_state_event"),
1989 G_TYPE_FROM_CLASS (gobject_class),
1991 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1992 _gtk_boolean_handled_accumulator, NULL,
1993 _gtk_marshal_BOOLEAN__BOXED,
1995 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1998 * GtkWidget::damage-event:
1999 * @widget: the object which received the signal
2000 * @event: the #GdkEventExpose event
2002 * Emitted when a redirected window belonging to @widget gets drawn into.
2003 * The region/area members of the event shows what area of the redirected
2004 * drawable was drawn into.
2006 * Returns: %TRUE to stop other handlers from being invoked for the event.
2007 * %FALSE to propagate the event further.
2011 widget_signals[DAMAGE_EVENT] =
2012 g_signal_new ("damage_event",
2013 G_TYPE_FROM_CLASS (gobject_class),
2014 G_SIGNAL_RUN_LAST, 0,
2015 _gtk_boolean_handled_accumulator, NULL,
2016 _gtk_marshal_BOOLEAN__BOXED,
2018 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2020 * GtkWidget::grab-broken-event:
2021 * @widget: the object which received the signal
2022 * @event: the #GdkEventGrabBroken event
2024 * Emitted when a pointer or keyboard grab on a window belonging
2025 * to @widget gets broken.
2027 * On X11, this happens when the grab window becomes unviewable
2028 * (i.e. it or one of its ancestors is unmapped), or if the same
2029 * application grabs the pointer or keyboard again.
2031 * Returns: %TRUE to stop other handlers from being invoked for
2032 * the event. %FALSE to propagate the event further.
2036 widget_signals[GRAB_BROKEN] =
2037 g_signal_new (I_("grab_broken_event"),
2038 G_TYPE_FROM_CLASS (gobject_class),
2040 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2041 _gtk_boolean_handled_accumulator, NULL,
2042 _gtk_marshal_BOOLEAN__BOXED,
2044 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2046 * GtkWidget::query-tooltip:
2047 * @widget: the object which received the signal
2048 * @x: the x coordinate of the cursor position where the request has
2049 * been emitted, relative to @widget->window
2050 * @y: the y coordinate of the cursor position where the request has
2051 * been emitted, relative to @widget->window
2052 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2053 * @tooltip: a #GtkTooltip
2055 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with
2056 * the cursor hovering "above" @widget; or emitted when @widget got
2057 * focus in keyboard mode.
2059 * Using the given coordinates, the signal handler should determine
2060 * whether a tooltip should be shown for @widget. If this is the case
2061 * %TRUE should be returned, %FALSE otherwise. Note that if
2062 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2063 * should not be used.
2065 * The signal handler is free to manipulate @tooltip with the therefore
2066 * destined function calls.
2068 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2072 widget_signals[QUERY_TOOLTIP] =
2073 g_signal_new (I_("query-tooltip"),
2074 G_TYPE_FROM_CLASS (gobject_class),
2076 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2077 _gtk_boolean_handled_accumulator, NULL,
2078 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2086 * GtkWidget::popup-menu
2087 * @widget: the object which received the signal
2089 * This signal gets emitted whenever a widget should pop up a context
2090 * menu. This usually happens through the standard key binding mechanism;
2091 * by pressing a certain key while a widget is focused, the user can cause
2092 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2093 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2094 * for an example of how to use this signal.
2096 * Returns: %TRUE if a menu was activated
2098 widget_signals[POPUP_MENU] =
2099 g_signal_new (I_("popup_menu"),
2100 G_TYPE_FROM_CLASS (gobject_class),
2101 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2102 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2103 _gtk_boolean_handled_accumulator, NULL,
2104 _gtk_marshal_BOOLEAN__VOID,
2106 widget_signals[SHOW_HELP] =
2107 g_signal_new (I_("show_help"),
2108 G_TYPE_FROM_CLASS (gobject_class),
2109 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2110 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2111 _gtk_boolean_handled_accumulator, NULL,
2112 _gtk_marshal_BOOLEAN__ENUM,
2114 GTK_TYPE_WIDGET_HELP_TYPE);
2115 widget_signals[ACCEL_CLOSURES_CHANGED] =
2116 g_signal_new (I_("accel_closures_changed"),
2117 G_TYPE_FROM_CLASS (gobject_class),
2121 _gtk_marshal_NONE__NONE,
2125 * GtkWidget::screen-changed:
2126 * @widget: the object on which the signal is emitted
2127 * @previous_screen: the previous screen, or %NULL if the
2128 * widget was not associated with a screen before
2130 * The ::screen-changed signal gets emitted when the
2131 * screen of a widget has changed.
2133 widget_signals[SCREEN_CHANGED] =
2134 g_signal_new (I_("screen_changed"),
2135 G_TYPE_FROM_CLASS (gobject_class),
2137 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2139 _gtk_marshal_VOID__OBJECT,
2143 * GtkWidget::can-activate-accel:
2144 * @widget: the object which received the signal
2145 * @signal_id: the ID of a signal installed on @widget
2147 * Determines whether an accelerator that activates the signal
2148 * identified by @signal_id can currently be activated.
2149 * This signal is present to allow applications and derived
2150 * widgets to override the default #GtkWidget handling
2151 * for determining whether an accelerator can be activated.
2153 * Returns: %TRUE if the signal can be activated.
2155 widget_signals[CAN_ACTIVATE_ACCEL] =
2156 g_signal_new (I_("can_activate_accel"),
2157 G_TYPE_FROM_CLASS (gobject_class),
2159 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2160 _gtk_boolean_handled_accumulator, NULL,
2161 _gtk_marshal_BOOLEAN__UINT,
2162 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2164 binding_set = gtk_binding_set_by_class (klass);
2165 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2167 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2170 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2172 GTK_TYPE_WIDGET_HELP_TYPE,
2173 GTK_WIDGET_HELP_TOOLTIP);
2174 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2176 GTK_TYPE_WIDGET_HELP_TYPE,
2177 GTK_WIDGET_HELP_TOOLTIP);
2178 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2180 GTK_TYPE_WIDGET_HELP_TYPE,
2181 GTK_WIDGET_HELP_WHATS_THIS);
2182 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2184 GTK_TYPE_WIDGET_HELP_TYPE,
2185 GTK_WIDGET_HELP_WHATS_THIS);
2187 gtk_widget_class_install_style_property (klass,
2188 g_param_spec_boolean ("interior-focus",
2189 P_("Interior Focus"),
2190 P_("Whether to draw the focus indicator inside widgets"),
2192 GTK_PARAM_READABLE));
2194 gtk_widget_class_install_style_property (klass,
2195 g_param_spec_int ("focus-line-width",
2196 P_("Focus linewidth"),
2197 P_("Width, in pixels, of the focus indicator line"),
2199 GTK_PARAM_READABLE));
2201 gtk_widget_class_install_style_property (klass,
2202 g_param_spec_string ("focus-line-pattern",
2203 P_("Focus line dash pattern"),
2204 P_("Dash pattern used to draw the focus indicator"),
2206 GTK_PARAM_READABLE));
2207 gtk_widget_class_install_style_property (klass,
2208 g_param_spec_int ("focus-padding",
2209 P_("Focus padding"),
2210 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2212 GTK_PARAM_READABLE));
2213 gtk_widget_class_install_style_property (klass,
2214 g_param_spec_boxed ("cursor-color",
2216 P_("Color with which to draw insertion cursor"),
2218 GTK_PARAM_READABLE));
2219 gtk_widget_class_install_style_property (klass,
2220 g_param_spec_boxed ("secondary-cursor-color",
2221 P_("Secondary cursor color"),
2222 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2224 GTK_PARAM_READABLE));
2225 gtk_widget_class_install_style_property (klass,
2226 g_param_spec_float ("cursor-aspect-ratio",
2227 P_("Cursor line aspect ratio"),
2228 P_("Aspect ratio with which to draw insertion cursor"),
2230 GTK_PARAM_READABLE));
2233 * GtkWidget:draw-border:
2235 * The "draw-border" style property defines the size of areas outside
2236 * the widget's allocation to draw.
2240 gtk_widget_class_install_style_property (klass,
2241 g_param_spec_boxed ("draw-border",
2243 P_("Size of areas outside the widget's allocation to draw"),
2245 GTK_PARAM_READABLE));
2248 * GtkWidget:link-color:
2250 * The "link-color" style property defines the color of unvisited links.
2254 gtk_widget_class_install_style_property (klass,
2255 g_param_spec_boxed ("link-color",
2256 P_("Unvisited Link Color"),
2257 P_("Color of unvisited links"),
2259 GTK_PARAM_READABLE));
2262 * GtkWidget:visited-link-color:
2264 * The "visited-link-color" style property defines the color of visited links.
2268 gtk_widget_class_install_style_property (klass,
2269 g_param_spec_boxed ("visited-link-color",
2270 P_("Visited Link Color"),
2271 P_("Color of visited links"),
2273 GTK_PARAM_READABLE));
2276 * GtkWidget:wide-separators:
2278 * The "wide-separators" style property defines whether separators have
2279 * configurable width and should be drawn using a box instead of a line.
2283 gtk_widget_class_install_style_property (klass,
2284 g_param_spec_boolean ("wide-separators",
2285 P_("Wide Separators"),
2286 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2288 GTK_PARAM_READABLE));
2291 * GtkWidget:separator-width:
2293 * The "separator-width" style property defines the width of separators.
2294 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2298 gtk_widget_class_install_style_property (klass,
2299 g_param_spec_int ("separator-width",
2300 P_("Separator Width"),
2301 P_("The width of separators if wide-separators is TRUE"),
2303 GTK_PARAM_READABLE));
2306 * GtkWidget:separator-height:
2308 * The "separator-height" style property defines the height of separators.
2309 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2313 gtk_widget_class_install_style_property (klass,
2314 g_param_spec_int ("separator-height",
2315 P_("Separator Height"),
2316 P_("The height of separators if \"wide-separators\" is TRUE"),
2318 GTK_PARAM_READABLE));
2321 * GtkWidget:scroll-arrow-hlength:
2323 * The "scroll-arrow-hlength" style property defines the length of
2324 * horizontal scroll arrows.
2328 gtk_widget_class_install_style_property (klass,
2329 g_param_spec_int ("scroll-arrow-hlength",
2330 P_("Horizontal Scroll Arrow Length"),
2331 P_("The length of horizontal scroll arrows"),
2333 GTK_PARAM_READABLE));
2336 * GtkWidget:scroll-arrow-vlength:
2338 * The "scroll-arrow-vlength" style property defines the length of
2339 * vertical scroll arrows.
2343 gtk_widget_class_install_style_property (klass,
2344 g_param_spec_int ("scroll-arrow-vlength",
2345 P_("Vertical Scroll Arrow Length"),
2346 P_("The length of vertical scroll arrows"),
2348 GTK_PARAM_READABLE));
2352 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2356 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2357 for (node = list; node; node = node->next)
2359 GParamSpec *pspec = node->data;
2361 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2362 g_param_spec_unref (pspec);
2368 gtk_widget_set_property (GObject *object,
2370 const GValue *value,
2373 GtkWidget *widget = GTK_WIDGET (object);
2378 guint32 saved_flags;
2379 gchar *tooltip_markup;
2380 const gchar *tooltip_text;
2381 GtkWindow *tooltip_window;
2384 gtk_widget_set_name (widget, g_value_get_string (value));
2387 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2389 case PROP_WIDTH_REQUEST:
2390 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2392 case PROP_HEIGHT_REQUEST:
2393 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2396 if (g_value_get_boolean (value))
2397 gtk_widget_show (widget);
2399 gtk_widget_hide (widget);
2401 case PROP_SENSITIVE:
2402 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2404 case PROP_APP_PAINTABLE:
2405 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2407 case PROP_CAN_FOCUS:
2408 saved_flags = GTK_WIDGET_FLAGS (widget);
2409 if (g_value_get_boolean (value))
2410 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2412 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2413 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2414 gtk_widget_queue_resize (widget);
2416 case PROP_HAS_FOCUS:
2417 if (g_value_get_boolean (value))
2418 gtk_widget_grab_focus (widget);
2421 if (g_value_get_boolean (value))
2422 gtk_widget_grab_focus (widget);
2424 case PROP_CAN_DEFAULT:
2425 saved_flags = GTK_WIDGET_FLAGS (widget);
2426 if (g_value_get_boolean (value))
2427 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2429 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2430 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2431 gtk_widget_queue_resize (widget);
2433 case PROP_HAS_DEFAULT:
2434 if (g_value_get_boolean (value))
2435 gtk_widget_grab_default (widget);
2437 case PROP_RECEIVES_DEFAULT:
2438 if (g_value_get_boolean (value))
2439 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2441 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2444 gtk_widget_set_style (widget, g_value_get_object (value));
2447 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2448 gtk_widget_set_events (widget, g_value_get_flags (value));
2450 case PROP_EXTENSION_EVENTS:
2451 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2453 case PROP_NO_SHOW_ALL:
2454 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2456 case PROP_HAS_TOOLTIP:
2457 gtk_widget_real_set_has_tooltip (widget,
2458 g_value_get_boolean (value), FALSE);
2460 case PROP_TOOLTIP_MARKUP:
2461 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2462 tooltip_markup = g_value_dup_string (value);
2464 g_object_set_qdata_full (object, quark_tooltip_markup,
2465 tooltip_markup, g_free);
2467 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2468 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2470 case PROP_TOOLTIP_TEXT:
2471 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2472 tooltip_text = g_value_get_string (value);
2473 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2475 g_object_set_qdata_full (object, quark_tooltip_markup,
2476 tooltip_markup, g_free);
2478 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2479 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2482 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2488 gtk_widget_get_property (GObject *object,
2493 GtkWidget *widget = GTK_WIDGET (object);
2502 g_value_set_string (value, widget->name);
2504 g_value_set_static_string (value, "");
2508 g_value_set_object (value, widget->parent);
2510 g_value_set_object (value, NULL);
2512 case PROP_WIDTH_REQUEST:
2515 gtk_widget_get_size_request (widget, &w, NULL);
2516 g_value_set_int (value, w);
2519 case PROP_HEIGHT_REQUEST:
2522 gtk_widget_get_size_request (widget, NULL, &h);
2523 g_value_set_int (value, h);
2527 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2529 case PROP_SENSITIVE:
2530 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2532 case PROP_APP_PAINTABLE:
2533 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2535 case PROP_CAN_FOCUS:
2536 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2538 case PROP_HAS_FOCUS:
2539 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2542 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2544 case PROP_CAN_DEFAULT:
2545 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2547 case PROP_HAS_DEFAULT:
2548 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2550 case PROP_RECEIVES_DEFAULT:
2551 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2553 case PROP_COMPOSITE_CHILD:
2554 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2557 g_value_set_object (value, gtk_widget_get_style (widget));
2560 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2561 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2563 case PROP_EXTENSION_EVENTS:
2564 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2565 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2567 case PROP_NO_SHOW_ALL:
2568 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2570 case PROP_HAS_TOOLTIP:
2571 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2573 case PROP_TOOLTIP_TEXT:
2575 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2578 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2579 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2581 g_value_set_string (value, text);
2585 case PROP_TOOLTIP_MARKUP:
2586 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2589 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2595 gtk_widget_init (GtkWidget *widget)
2597 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2598 widget->state = GTK_STATE_NORMAL;
2599 widget->saved_state = GTK_STATE_NORMAL;
2600 widget->name = NULL;
2601 widget->requisition.width = 0;
2602 widget->requisition.height = 0;
2603 widget->allocation.x = -1;
2604 widget->allocation.y = -1;
2605 widget->allocation.width = 1;
2606 widget->allocation.height = 1;
2607 widget->window = NULL;
2608 widget->parent = NULL;
2610 GTK_WIDGET_SET_FLAGS (widget,
2612 GTK_PARENT_SENSITIVE |
2613 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2614 GTK_DOUBLE_BUFFERED);
2616 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2617 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2618 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2620 widget->style = gtk_widget_get_default_style ();
2621 g_object_ref (widget->style);
2626 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2628 GParamSpec **pspecs)
2630 GtkWidget *container = widget->parent;
2633 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2634 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2638 * gtk_widget_freeze_child_notify:
2639 * @widget: a #GtkWidget
2641 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2642 * signals are queued until gtk_widget_thaw_child_notify() is called
2645 * This is the analogue of g_object_freeze_notify() for child properties.
2648 gtk_widget_freeze_child_notify (GtkWidget *widget)
2650 g_return_if_fail (GTK_IS_WIDGET (widget));
2652 if (!G_OBJECT (widget)->ref_count)
2655 g_object_ref (widget);
2656 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2657 g_object_unref (widget);
2661 * gtk_widget_child_notify:
2662 * @widget: a #GtkWidget
2663 * @child_property: the name of a child property installed on the
2664 * class of @widget<!-- -->'s parent
2666 * Emits a #GtkWidget::child-notify signal for the
2667 * <link linkend="child-properties">child property</link> @child_property
2670 * This is the analogue of g_object_notify() for child properties.
2673 gtk_widget_child_notify (GtkWidget *widget,
2674 const gchar *child_property)
2678 g_return_if_fail (GTK_IS_WIDGET (widget));
2679 g_return_if_fail (child_property != NULL);
2680 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2683 g_object_ref (widget);
2684 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2686 G_OBJECT_TYPE (widget->parent),
2689 g_warning ("%s: container class `%s' has no child property named `%s'",
2691 G_OBJECT_TYPE_NAME (widget->parent),
2695 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2697 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2698 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2700 g_object_unref (widget);
2704 * gtk_widget_thaw_child_notify:
2705 * @widget: a #GtkWidget
2707 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2708 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2712 gtk_widget_thaw_child_notify (GtkWidget *widget)
2714 GObjectNotifyQueue *nqueue;
2716 g_return_if_fail (GTK_IS_WIDGET (widget));
2718 if (!G_OBJECT (widget)->ref_count)
2721 g_object_ref (widget);
2722 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2723 if (!nqueue || !nqueue->freeze_count)
2724 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2725 G_OBJECT_TYPE_NAME (widget), widget);
2727 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2728 g_object_unref (widget);
2734 * @type: type ID of the widget to create
2735 * @first_property_name: name of first property to set
2736 * @Varargs: value of first property, followed by more properties,
2739 * This is a convenience function for creating a widget and setting
2740 * its properties in one go. For example you might write:
2741 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2742 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2743 * g_object_new(), but returns a widget so you don't have to
2744 * cast the object yourself.
2746 * Return value: a new #GtkWidget of type @widget_type
2749 gtk_widget_new (GType type,
2750 const gchar *first_property_name,
2756 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2758 va_start (var_args, first_property_name);
2759 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2767 * @widget: a #GtkWidget
2768 * @first_property_name: name of first property to set
2769 * @Varargs: value of first property, followed by more properties,
2772 * Precursor of g_object_set().
2774 * Deprecated: Use g_object_set() instead.
2777 gtk_widget_set (GtkWidget *widget,
2778 const gchar *first_property_name,
2783 g_return_if_fail (GTK_IS_WIDGET (widget));
2785 va_start (var_args, first_property_name);
2786 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2791 gtk_widget_queue_draw_child (GtkWidget *widget)
2795 parent = widget->parent;
2796 if (parent && GTK_WIDGET_DRAWABLE (parent))
2797 gtk_widget_queue_draw_area (parent,
2798 widget->allocation.x,
2799 widget->allocation.y,
2800 widget->allocation.width,
2801 widget->allocation.height);
2805 * gtk_widget_unparent:
2806 * @widget: a #GtkWidget
2808 * This function is only for use in widget implementations.
2809 * Should be called by implementations of the remove method
2810 * on #GtkContainer, to dissociate a child from the container.
2813 gtk_widget_unparent (GtkWidget *widget)
2815 GObjectNotifyQueue *nqueue;
2816 GtkWidget *toplevel;
2817 GtkWidget *old_parent;
2819 g_return_if_fail (GTK_IS_WIDGET (widget));
2820 if (widget->parent == NULL)
2823 /* keep this function in sync with gtk_menu_detach()
2826 g_object_freeze_notify (G_OBJECT (widget));
2827 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2829 toplevel = gtk_widget_get_toplevel (widget);
2830 if (GTK_WIDGET_TOPLEVEL (toplevel))
2831 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2833 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2834 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2836 /* If we are unanchoring the child, we save around the toplevel
2837 * to emit hierarchy changed
2839 if (GTK_WIDGET_ANCHORED (widget->parent))
2840 g_object_ref (toplevel);
2844 gtk_widget_queue_draw_child (widget);
2846 /* Reset the width and height here, to force reallocation if we
2847 * get added back to a new parent. This won't work if our new
2848 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2849 * (would 0x0 be OK here?)
2851 widget->allocation.width = 1;
2852 widget->allocation.height = 1;
2854 if (GTK_WIDGET_REALIZED (widget))
2856 if (GTK_WIDGET_IN_REPARENT (widget))
2857 gtk_widget_unmap (widget);
2859 gtk_widget_unrealize (widget);
2862 /* Removing a widget from a container restores the child visible
2863 * flag to the default state, so it doesn't affect the child
2864 * in the next parent.
2866 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2868 old_parent = widget->parent;
2869 widget->parent = NULL;
2870 gtk_widget_set_parent_window (widget, NULL);
2871 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2874 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2875 g_object_unref (toplevel);
2878 g_object_notify (G_OBJECT (widget), "parent");
2879 g_object_thaw_notify (G_OBJECT (widget));
2880 if (!widget->parent)
2881 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2882 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2883 g_object_unref (widget);
2887 * gtk_widget_destroy:
2888 * @widget: a #GtkWidget
2890 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2891 * you don't have to cast the widget to #GtkObject. When a widget is
2892 * destroyed, it will break any references it holds to other objects.
2893 * If the widget is inside a container, the widget will be removed
2894 * from the container. If the widget is a toplevel (derived from
2895 * #GtkWindow), it will be removed from the list of toplevels, and the
2896 * reference GTK+ holds to it will be removed. Removing a
2897 * widget from its container or the list of toplevels results in the
2898 * widget being finalized, unless you've added additional references
2899 * to the widget with g_object_ref().
2901 * In most cases, only toplevel widgets (windows) require explicit
2902 * destruction, because when you destroy a toplevel its children will
2903 * be destroyed as well.
2906 gtk_widget_destroy (GtkWidget *widget)
2908 g_return_if_fail (GTK_IS_WIDGET (widget));
2910 gtk_object_destroy ((GtkObject*) widget);
2914 * gtk_widget_destroyed:
2915 * @widget: a #GtkWidget
2916 * @widget_pointer: address of a variable that contains @widget
2918 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2919 * %NULL. It's intended to be used as a callback connected to the
2920 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2921 * as a signal handler, and pass the address of your widget variable
2922 * as user data. Then when the widget is destroyed, the variable will
2923 * be set to %NULL. Useful for example to avoid multiple copies
2924 * of the same dialog.
2927 gtk_widget_destroyed (GtkWidget *widget,
2928 GtkWidget **widget_pointer)
2930 /* Don't make any assumptions about the
2932 * Even check widget_pointer.
2935 *widget_pointer = NULL;
2940 * @widget: a #GtkWidget
2942 * Flags a widget to be displayed. Any widget that isn't shown will
2943 * not appear on the screen. If you want to show all the widgets in a
2944 * container, it's easier to call gtk_widget_show_all() on the
2945 * container, instead of individually showing the widgets.
2947 * Remember that you have to show the containers containing a widget,
2948 * in addition to the widget itself, before it will appear onscreen.
2950 * When a toplevel container is shown, it is immediately realized and
2951 * mapped; other shown widgets are realized and mapped when their
2952 * toplevel container is realized and mapped.
2955 gtk_widget_show (GtkWidget *widget)
2957 g_return_if_fail (GTK_IS_WIDGET (widget));
2959 if (!GTK_WIDGET_VISIBLE (widget))
2961 g_object_ref (widget);
2962 if (!GTK_WIDGET_TOPLEVEL (widget))
2963 gtk_widget_queue_resize (widget);
2964 g_signal_emit (widget, widget_signals[SHOW], 0);
2965 g_object_notify (G_OBJECT (widget), "visible");
2966 g_object_unref (widget);
2971 gtk_widget_real_show (GtkWidget *widget)
2973 if (!GTK_WIDGET_VISIBLE (widget))
2975 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2977 if (widget->parent &&
2978 GTK_WIDGET_MAPPED (widget->parent) &&
2979 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2980 !GTK_WIDGET_MAPPED (widget))
2981 gtk_widget_map (widget);
2986 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2989 g_signal_handlers_disconnect_by_func (widget,
2990 gtk_widget_show_map_callback,
2995 * gtk_widget_show_now:
2996 * @widget: a #GtkWidget
2998 * Shows a widget. If the widget is an unmapped toplevel widget
2999 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3000 * loop and wait for the window to actually be mapped. Be careful;
3001 * because the main loop is running, anything can happen during
3005 gtk_widget_show_now (GtkWidget *widget)
3009 g_return_if_fail (GTK_IS_WIDGET (widget));
3011 /* make sure we will get event */
3012 if (!GTK_WIDGET_MAPPED (widget) &&
3013 GTK_WIDGET_TOPLEVEL (widget))
3015 gtk_widget_show (widget);
3017 g_signal_connect (widget, "map_event",
3018 G_CALLBACK (gtk_widget_show_map_callback),
3022 gtk_main_iteration ();
3025 gtk_widget_show (widget);
3030 * @widget: a #GtkWidget
3032 * Reverses the effects of gtk_widget_show(), causing the widget to be
3033 * hidden (invisible to the user).
3036 gtk_widget_hide (GtkWidget *widget)
3038 g_return_if_fail (GTK_IS_WIDGET (widget));
3040 if (GTK_WIDGET_VISIBLE (widget))
3042 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3044 g_object_ref (widget);
3045 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3046 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3048 g_signal_emit (widget, widget_signals[HIDE], 0);
3049 if (!GTK_WIDGET_TOPLEVEL (widget))
3050 gtk_widget_queue_resize (widget);
3051 g_object_notify (G_OBJECT (widget), "visible");
3052 g_object_unref (widget);
3057 gtk_widget_real_hide (GtkWidget *widget)
3059 if (GTK_WIDGET_VISIBLE (widget))
3061 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3063 if (GTK_WIDGET_MAPPED (widget))
3064 gtk_widget_unmap (widget);
3069 * gtk_widget_hide_on_delete:
3070 * @widget: a #GtkWidget
3072 * Utility function; intended to be connected to the #GtkWidget::delete-event
3073 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3074 * argument, then returns %TRUE. If connected to ::delete-event, the
3075 * result is that clicking the close button for a window (on the
3076 * window frame, top right corner usually) will hide but not destroy
3077 * the window. By default, GTK+ destroys windows when ::delete-event
3080 * Return value: %TRUE
3083 gtk_widget_hide_on_delete (GtkWidget *widget)
3085 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3087 gtk_widget_hide (widget);
3093 * gtk_widget_show_all:
3094 * @widget: a #GtkWidget
3096 * Recursively shows a widget, and any child widgets (if the widget is
3100 gtk_widget_show_all (GtkWidget *widget)
3102 GtkWidgetClass *class;
3104 g_return_if_fail (GTK_IS_WIDGET (widget));
3106 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3109 class = GTK_WIDGET_GET_CLASS (widget);
3111 if (class->show_all)
3112 class->show_all (widget);
3116 * gtk_widget_hide_all:
3117 * @widget: a #GtkWidget
3119 * Recursively hides a widget and any child widgets.
3122 gtk_widget_hide_all (GtkWidget *widget)
3124 GtkWidgetClass *class;
3126 g_return_if_fail (GTK_IS_WIDGET (widget));
3128 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3131 class = GTK_WIDGET_GET_CLASS (widget);
3133 if (class->hide_all)
3134 class->hide_all (widget);
3139 * @widget: a #GtkWidget
3141 * This function is only for use in widget implementations. Causes
3142 * a widget to be mapped if it isn't already.
3145 gtk_widget_map (GtkWidget *widget)
3147 g_return_if_fail (GTK_IS_WIDGET (widget));
3148 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3149 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3151 if (!GTK_WIDGET_MAPPED (widget))
3153 if (!GTK_WIDGET_REALIZED (widget))
3154 gtk_widget_realize (widget);
3156 g_signal_emit (widget, widget_signals[MAP], 0);
3158 if (GTK_WIDGET_NO_WINDOW (widget))
3159 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3165 * @widget: a #GtkWidget
3167 * This function is only for use in widget implementations. Causes
3168 * a widget to be unmapped if it's currently mapped.
3171 gtk_widget_unmap (GtkWidget *widget)
3173 g_return_if_fail (GTK_IS_WIDGET (widget));
3175 if (GTK_WIDGET_MAPPED (widget))
3177 if (GTK_WIDGET_NO_WINDOW (widget))
3178 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3179 _gtk_tooltip_hide (widget);
3180 g_signal_emit (widget, widget_signals[UNMAP], 0);
3185 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3186 GdkExtensionMode mode,
3189 GList *free_list = NULL;
3192 if (window_list == NULL)
3194 if (!GTK_WIDGET_NO_WINDOW (widget))
3195 window_list = g_list_prepend (NULL, widget->window);
3197 window_list = gdk_window_get_children (widget->window);
3199 free_list = window_list;
3202 for (l = window_list; l != NULL; l = l->next)
3204 GdkWindow *window = l->data;
3207 gdk_window_get_user_data (window, &user_data);
3208 if (user_data == widget)
3212 gdk_input_set_extension_events (window,
3213 gdk_window_get_events (window),
3216 children = gdk_window_get_children (window);
3219 gtk_widget_set_extension_events_internal (widget, mode, children);
3220 g_list_free (children);
3226 g_list_free (free_list);
3230 * gtk_widget_realize:
3231 * @widget: a #GtkWidget
3233 * Creates the GDK (windowing system) resources associated with a
3234 * widget. For example, @widget->window will be created when a widget
3235 * is realized. Normally realization happens implicitly; if you show
3236 * a widget and all its parent containers, then the widget will be
3237 * realized and mapped automatically.
3239 * Realizing a widget requires all
3240 * the widget's parent widgets to be realized; calling
3241 * gtk_widget_realize() realizes the widget's parents in addition to
3242 * @widget itself. If a widget is not yet inside a toplevel window
3243 * when you realize it, bad things will happen.
3245 * This function is primarily used in widget implementations, and
3246 * isn't very useful otherwise. Many times when you think you might
3247 * need it, a better approach is to connect to a signal that will be
3248 * called after the widget is realized automatically, such as
3249 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3250 * GtkWidget::realize signal.
3253 gtk_widget_realize (GtkWidget *widget)
3255 GdkExtensionMode mode;
3256 GtkWidgetShapeInfo *shape_info;
3258 g_return_if_fail (GTK_IS_WIDGET (widget));
3259 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3260 GTK_IS_INVISIBLE (widget));
3262 if (!GTK_WIDGET_REALIZED (widget))
3265 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3266 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3269 if (widget->parent == NULL &&
3270 !GTK_WIDGET_TOPLEVEL (widget))
3271 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3272 "inside a toplevel window is not going to work very well. "
3273 "Widgets must be inside a toplevel container before realizing them.");
3275 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3276 gtk_widget_realize (widget->parent);
3278 gtk_widget_ensure_style (widget);
3280 g_signal_emit (widget, widget_signals[REALIZE], 0);
3282 gtk_widget_real_set_has_tooltip (widget,
3283 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3286 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3288 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3289 gdk_window_shape_combine_mask (widget->window,
3290 shape_info->shape_mask,
3291 shape_info->offset_x,
3292 shape_info->offset_y);
3295 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3297 gdk_window_input_shape_combine_mask (widget->window,
3298 shape_info->shape_mask,
3299 shape_info->offset_x,
3300 shape_info->offset_y);
3302 mode = gtk_widget_get_extension_events (widget);
3303 if (mode != GDK_EXTENSION_EVENTS_NONE)
3304 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3309 * gtk_widget_unrealize:
3310 * @widget: a #GtkWidget
3312 * This function is only useful in widget implementations.
3313 * Causes a widget to be unrealized (frees all GDK resources
3314 * associated with the widget, such as @widget->window).
3317 gtk_widget_unrealize (GtkWidget *widget)
3319 g_return_if_fail (GTK_IS_WIDGET (widget));
3321 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3322 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3324 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3325 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3327 if (GTK_WIDGET_REALIZED (widget))
3329 g_object_ref (widget);
3330 _gtk_tooltip_hide (widget);
3331 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3332 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3333 g_object_unref (widget);
3337 /*****************************************
3339 *****************************************/
3342 * gtk_widget_queue_draw_area:
3343 * @widget: a #GtkWidget
3344 * @x: x coordinate of upper-left corner of rectangle to redraw
3345 * @y: y coordinate of upper-left corner of rectangle to redraw
3346 * @width: width of region to draw
3347 * @height: height of region to draw
3349 * Invalidates the rectangular area of @widget defined by @x, @y,
3350 * @width and @height by calling gdk_window_invalidate_rect() on the
3351 * widget's window and all its child windows. Once the main loop
3352 * becomes idle (after the current batch of events has been processed,
3353 * roughly), the window will receive expose events for the union of
3354 * all regions that have been invalidated.
3356 * Normally you would only use this function in widget
3357 * implementations. You might also use it, or
3358 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3359 * #GtkDrawingArea or some portion thereof.
3361 * Frequently you can just call gdk_window_invalidate_rect() or
3362 * gdk_window_invalidate_region() instead of this function. Those
3363 * functions will invalidate only a single window, instead of the
3364 * widget and all its children.
3366 * The advantage of adding to the invalidated region compared to
3367 * simply drawing immediately is efficiency; using an invalid region
3368 * ensures that you only have to redraw one time.
3371 gtk_widget_queue_draw_area (GtkWidget *widget,
3377 GdkRectangle invalid_rect;
3380 g_return_if_fail (GTK_IS_WIDGET (widget));
3382 if (!GTK_WIDGET_REALIZED (widget))
3385 /* Just return if the widget or one of its ancestors isn't mapped */
3386 for (w = widget; w != NULL; w = w->parent)
3387 if (!GTK_WIDGET_MAPPED (w))
3390 /* Find the correct widget */
3392 if (!GTK_WIDGET_NO_WINDOW (widget))
3396 /* Translate widget relative to window-relative */
3398 gint wx, wy, wwidth, wheight;
3400 gdk_window_get_position (widget->window, &wx, &wy);
3401 x -= wx - widget->allocation.x;
3402 y -= wy - widget->allocation.y;
3404 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3406 if (x + width <= 0 || y + height <= 0 ||
3407 x >= wwidth || y >= wheight)
3418 if (x + width > wwidth)
3420 if (y + height > wheight)
3421 height = wheight - y;
3427 invalid_rect.width = width;
3428 invalid_rect.height = height;
3430 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3434 widget_add_child_draw_rectangle (GtkWidget *widget,
3437 GdkRectangle child_rect;
3439 if (!GTK_WIDGET_MAPPED (widget) ||
3440 widget->window != widget->parent->window)
3443 gtk_widget_get_draw_rectangle (widget, &child_rect);
3444 gdk_rectangle_union (rect, &child_rect, rect);
3448 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3451 if (GTK_WIDGET_NO_WINDOW (widget))
3453 GtkBorder *draw_border = NULL;
3455 *rect = widget->allocation;
3457 gtk_widget_style_get (widget,
3458 "draw-border", &draw_border,
3462 rect->x -= draw_border->top;
3463 rect->y -= draw_border->left;
3464 rect->width += draw_border->left + draw_border->right;
3465 rect->height += draw_border->top + draw_border->bottom;
3467 gtk_border_free (draw_border);
3470 if (GTK_IS_CONTAINER (widget))
3471 gtk_container_forall (GTK_CONTAINER (widget),
3472 (GtkCallback)widget_add_child_draw_rectangle,
3479 rect->width = widget->allocation.width;
3480 rect->height = widget->allocation.height;
3485 * gtk_widget_queue_draw:
3486 * @widget: a #GtkWidget
3488 * Equivalent to calling gtk_widget_queue_draw_area() for the
3489 * entire area of a widget.
3492 gtk_widget_queue_draw (GtkWidget *widget)
3496 g_return_if_fail (GTK_IS_WIDGET (widget));
3498 gtk_widget_get_draw_rectangle (widget, &rect);
3500 gtk_widget_queue_draw_area (widget,
3502 rect.width, rect.height);
3505 /* Invalidates the given area (allocation-relative-coordinates)
3506 * in all of the widget's windows
3509 * gtk_widget_queue_clear_area:
3510 * @widget: a #GtkWidget
3511 * @x: x coordinate of upper-left corner of rectangle to redraw
3512 * @y: y coordinate of upper-left corner of rectangle to redraw
3513 * @width: width of region to draw
3514 * @height: height of region to draw
3516 * This function is no longer different from
3517 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3518 * gtk_widget_queue_draw_area(). Originally
3519 * gtk_widget_queue_clear_area() would force a redraw of the
3520 * background for %GTK_NO_WINDOW widgets, and
3521 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3522 * the background will be redrawn.
3524 * Deprecated: Use gtk_widget_queue_draw_area() instead.
3527 gtk_widget_queue_clear_area (GtkWidget *widget,
3533 g_return_if_fail (GTK_IS_WIDGET (widget));
3535 gtk_widget_queue_draw_area (widget, x, y, width, height);
3539 * gtk_widget_queue_clear:
3540 * @widget: a #GtkWidget
3542 * This function does the same as gtk_widget_queue_draw().
3544 * Deprecated: Use gtk_widget_queue_draw() instead.
3547 gtk_widget_queue_clear (GtkWidget *widget)
3549 g_return_if_fail (GTK_IS_WIDGET (widget));
3551 gtk_widget_queue_draw (widget);
3555 * gtk_widget_queue_resize:
3556 * @widget: a #GtkWidget
3558 * This function is only for use in widget implementations.
3559 * Flags a widget to have its size renegotiated; should
3560 * be called when a widget for some reason has a new size request.
3561 * For example, when you change the text in a #GtkLabel, #GtkLabel
3562 * queues a resize to ensure there's enough space for the new text.
3565 gtk_widget_queue_resize (GtkWidget *widget)
3567 g_return_if_fail (GTK_IS_WIDGET (widget));
3569 if (GTK_WIDGET_REALIZED (widget))
3570 gtk_widget_queue_shallow_draw (widget);
3572 _gtk_size_group_queue_resize (widget);
3576 * gtk_widget_queue_resize_no_redraw:
3577 * @widget: a #GtkWidget
3579 * This function works like gtk_widget_queue_resize(),
3580 * except that the widget is not invalidated.
3585 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3587 g_return_if_fail (GTK_IS_WIDGET (widget));
3589 _gtk_size_group_queue_resize (widget);
3594 * @widget: a #GtkWidget
3595 * @area: area to draw
3597 * In GTK+ 1.2, this function would immediately render the
3598 * region @area of a widget, by invoking the virtual draw method of a
3599 * widget. In GTK+ 2.0, the draw method is gone, and instead
3600 * gtk_widget_draw() simply invalidates the specified region of the
3601 * widget, then updates the invalid region of the widget immediately.
3602 * Usually you don't want to update the region immediately for
3603 * performance reasons, so in general gtk_widget_queue_draw_area() is
3604 * a better choice if you want to draw a region of a widget.
3607 gtk_widget_draw (GtkWidget *widget,
3608 const GdkRectangle *area)
3610 g_return_if_fail (GTK_IS_WIDGET (widget));
3612 if (GTK_WIDGET_DRAWABLE (widget))
3615 gtk_widget_queue_draw_area (widget,
3617 area->width, area->height);
3619 gtk_widget_queue_draw (widget);
3621 gdk_window_process_updates (widget->window, TRUE);
3626 * gtk_widget_size_request:
3627 * @widget: a #GtkWidget
3628 * @requisition: a #GtkRequisition to be filled in
3630 * This function is typically used when implementing a #GtkContainer
3631 * subclass. Obtains the preferred size of a widget. The container
3632 * uses this information to arrange its child widgets and decide what
3633 * size allocations to give them with gtk_widget_size_allocate().
3635 * You can also call this function from an application, with some
3636 * caveats. Most notably, getting a size request requires the widget
3637 * to be associated with a screen, because font information may be
3638 * needed. Multihead-aware applications should keep this in mind.
3640 * Also remember that the size request is not necessarily the size
3641 * a widget will actually be allocated.
3643 * See also gtk_widget_get_child_requisition().
3646 gtk_widget_size_request (GtkWidget *widget,
3647 GtkRequisition *requisition)
3649 g_return_if_fail (GTK_IS_WIDGET (widget));
3651 #ifdef G_ENABLE_DEBUG
3652 if (requisition == &widget->requisition)
3653 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.");
3654 #endif /* G_ENABLE_DEBUG */
3656 _gtk_size_group_compute_requisition (widget, requisition);
3660 * gtk_widget_get_child_requisition:
3661 * @widget: a #GtkWidget
3662 * @requisition: a #GtkRequisition to be filled in
3664 * This function is only for use in widget implementations. Obtains
3665 * @widget->requisition, unless someone has forced a particular
3666 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3667 * in which case it returns that geometry instead of the widget's
3670 * This function differs from gtk_widget_size_request() in that
3671 * it retrieves the last size request value from @widget->requisition,
3672 * while gtk_widget_size_request() actually calls the "size_request" method
3673 * on @widget to compute the size request and fill in @widget->requisition,
3674 * and only then returns @widget->requisition.
3676 * Because this function does not call the "size_request" method, it
3677 * can only be used when you know that @widget->requisition is
3678 * up-to-date, that is, gtk_widget_size_request() has been called
3679 * since the last time a resize was queued. In general, only container
3680 * implementations have this information; applications should use
3681 * gtk_widget_size_request().
3684 gtk_widget_get_child_requisition (GtkWidget *widget,
3685 GtkRequisition *requisition)
3687 _gtk_size_group_get_child_requisition (widget, requisition);
3691 invalidate_predicate (GdkWindow *window,
3696 gdk_window_get_user_data (window, &user_data);
3698 return (user_data == data);
3701 /* Invalidate @region in widget->window and all children
3702 * of widget->window owned by widget. @region is in the
3703 * same coordinates as widget->allocation and will be
3704 * modified by this call.
3707 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3710 if (!GTK_WIDGET_REALIZED (widget))
3713 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3717 gdk_window_get_position (widget->window, &x, &y);
3718 gdk_region_offset (region, -x, -y);
3721 gdk_window_invalidate_maybe_recurse (widget->window, region,
3722 invalidate_predicate, widget);
3726 * gtk_widget_queue_shallow_draw:
3727 * @widget: a #GtkWidget
3729 * Like gtk_widget_queue_draw(), but only windows owned
3730 * by @widget are invalidated.
3733 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3738 if (!GTK_WIDGET_REALIZED (widget))
3741 gtk_widget_get_draw_rectangle (widget, &rect);
3743 /* get_draw_rectangle() gives us window coordinates, we
3744 * need to convert to the coordinates that widget->allocation
3747 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3751 gdk_window_get_position (widget->window, &wx, &wy);
3757 region = gdk_region_rectangle (&rect);
3758 gtk_widget_invalidate_widget_windows (widget, region);
3759 gdk_region_destroy (region);
3763 * gtk_widget_size_allocate:
3764 * @widget: a #GtkWidget
3765 * @allocation: position and size to be allocated to @widget
3767 * This function is only used by #GtkContainer subclasses, to assign a size
3768 * and position to their child widgets.
3771 gtk_widget_size_allocate (GtkWidget *widget,
3772 GtkAllocation *allocation)
3774 GtkWidgetAuxInfo *aux_info;
3775 GdkRectangle real_allocation;
3776 GdkRectangle old_allocation;
3777 gboolean alloc_needed;
3778 gboolean size_changed;
3779 gboolean position_changed;
3781 g_return_if_fail (GTK_IS_WIDGET (widget));
3783 #ifdef G_ENABLE_DEBUG
3784 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3795 parent = gtk_widget_get_parent (parent);
3798 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3799 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3800 2 * depth, " ", name,
3801 allocation->width, allocation->height);
3803 #endif /* G_ENABLE_DEBUG */
3805 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3806 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3807 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3809 old_allocation = widget->allocation;
3810 real_allocation = *allocation;
3811 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3815 if (aux_info->x_set)
3816 real_allocation.x = aux_info->x;
3817 if (aux_info->y_set)
3818 real_allocation.y = aux_info->y;
3821 if (real_allocation.width < 0 || real_allocation.height < 0)
3823 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3824 real_allocation.width,
3825 real_allocation.height);
3828 real_allocation.width = MAX (real_allocation.width, 1);
3829 real_allocation.height = MAX (real_allocation.height, 1);
3831 size_changed = (old_allocation.width != real_allocation.width ||
3832 old_allocation.height != real_allocation.height);
3833 position_changed = (old_allocation.x != real_allocation.x ||
3834 old_allocation.y != real_allocation.y);
3836 if (!alloc_needed && !size_changed && !position_changed)
3839 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3841 if (GTK_WIDGET_MAPPED (widget))
3843 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3845 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3847 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3848 gdk_region_union_with_rect (invalidate, &old_allocation);
3850 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3851 gdk_region_destroy (invalidate);
3856 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3858 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3860 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3861 gdk_region_union_with_rect (invalidate, &old_allocation);
3863 gtk_widget_invalidate_widget_windows (widget, invalidate);
3864 gdk_region_destroy (invalidate);
3869 if ((size_changed || position_changed) && widget->parent &&
3870 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3872 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3873 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3874 gdk_region_destroy (invalidate);
3879 * gtk_widget_common_ancestor:
3880 * @widget_a: a #GtkWidget
3881 * @widget_b: a #GtkWidget
3883 * Find the common ancestor of @widget_a and @widget_b that
3884 * is closest to the two widgets.
3886 * Return value: the closest common ancestor of @widget_a and
3887 * @widget_b or %NULL if @widget_a and @widget_b do not
3888 * share a common ancestor.
3891 gtk_widget_common_ancestor (GtkWidget *widget_a,
3892 GtkWidget *widget_b)
3894 GtkWidget *parent_a;
3895 GtkWidget *parent_b;
3899 parent_a = widget_a;
3900 while (parent_a->parent)
3902 parent_a = parent_a->parent;
3906 parent_b = widget_b;
3907 while (parent_b->parent)
3909 parent_b = parent_b->parent;
3913 if (parent_a != parent_b)
3916 while (depth_a > depth_b)
3918 widget_a = widget_a->parent;
3922 while (depth_b > depth_a)
3924 widget_b = widget_b->parent;
3928 while (widget_a != widget_b)
3930 widget_a = widget_a->parent;
3931 widget_b = widget_b->parent;
3938 * gtk_widget_translate_coordinates:
3939 * @src_widget: a #GtkWidget
3940 * @dest_widget: a #GtkWidget
3941 * @src_x: X position relative to @src_widget
3942 * @src_y: Y position relative to @src_widget
3943 * @dest_x: location to store X position relative to @dest_widget
3944 * @dest_y: location to store Y position relative to @dest_widget
3946 * Translate coordinates relative to @src_widget's allocation to coordinates
3947 * relative to @dest_widget's allocations. In order to perform this
3948 * operation, both widgets must be realized, and must share a common
3951 * Return value: %FALSE if either widget was not realized, or there
3952 * was no common ancestor. In this case, nothing is stored in
3953 * *@dest_x and *@dest_y. Otherwise %TRUE.
3956 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3957 GtkWidget *dest_widget,
3963 GtkWidget *ancestor;
3966 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3967 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3969 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3970 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3973 /* Translate from allocation relative to window relative */
3974 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3977 gdk_window_get_position (src_widget->window, &wx, &wy);
3979 src_x -= wx - src_widget->allocation.x;
3980 src_y -= wy - src_widget->allocation.y;
3984 src_x += src_widget->allocation.x;
3985 src_y += src_widget->allocation.y;
3988 /* Translate to the common ancestor */
3989 window = src_widget->window;
3990 while (window != ancestor->window)
3994 gdk_window_get_position (window, &dx, &dy);
3999 window = gdk_window_get_parent (window);
4001 if (!window) /* Handle GtkHandleBox */
4006 window = dest_widget->window;
4007 while (window != ancestor->window)
4011 gdk_window_get_position (window, &dx, &dy);
4016 window = gdk_window_get_parent (window);
4018 if (!window) /* Handle GtkHandleBox */
4022 /* Translate from window relative to allocation relative */
4023 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4026 gdk_window_get_position (dest_widget->window, &wx, &wy);
4028 src_x += wx - dest_widget->allocation.x;
4029 src_y += wy - dest_widget->allocation.y;
4033 src_x -= dest_widget->allocation.x;
4034 src_y -= dest_widget->allocation.y;
4046 gtk_widget_real_size_allocate (GtkWidget *widget,
4047 GtkAllocation *allocation)
4049 widget->allocation = *allocation;
4051 if (GTK_WIDGET_REALIZED (widget) &&
4052 !GTK_WIDGET_NO_WINDOW (widget))
4054 gdk_window_move_resize (widget->window,
4055 allocation->x, allocation->y,
4056 allocation->width, allocation->height);
4061 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4064 /* widgets must be onscreen for accels to take effect */
4065 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4069 * gtk_widget_can_activate_accel:
4070 * @widget: a #GtkWidget
4071 * @signal_id: the ID of a signal installed on @widget
4073 * Determines whether an accelerator that activates the signal
4074 * identified by @signal_id can currently be activated.
4075 * This is done by emitting the #GtkWidget::can-activate-accel
4076 * signal on @widget; if the signal isn't overridden by a
4077 * handler or in a derived widget, then the default check is
4078 * that the widget must be sensitive, and the widget and all
4079 * its ancestors mapped.
4081 * Return value: %TRUE if the accelerator can be activated.
4086 gtk_widget_can_activate_accel (GtkWidget *widget,
4089 gboolean can_activate = FALSE;
4090 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4091 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4092 return can_activate;
4101 closure_accel_activate (GClosure *closure,
4102 GValue *return_value,
4103 guint n_param_values,
4104 const GValue *param_values,
4105 gpointer invocation_hint,
4106 gpointer marshal_data)
4108 AccelClosure *aclosure = (AccelClosure*) closure;
4109 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4112 g_signal_emit (closure->data, aclosure->signal_id, 0);
4114 /* whether accelerator was handled */
4115 g_value_set_boolean (return_value, can_activate);
4119 closures_destroy (gpointer data)
4121 GSList *slist, *closures = data;
4123 for (slist = closures; slist; slist = slist->next)
4125 g_closure_invalidate (slist->data);
4126 g_closure_unref (slist->data);
4128 g_slist_free (closures);
4132 widget_new_accel_closure (GtkWidget *widget,
4135 AccelClosure *aclosure;
4136 GClosure *closure = NULL;
4137 GSList *slist, *closures;
4139 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4140 for (slist = closures; slist; slist = slist->next)
4141 if (!gtk_accel_group_from_accel_closure (slist->data))
4143 /* reuse this closure */
4144 closure = slist->data;
4149 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4150 closures = g_slist_prepend (closures, g_closure_ref (closure));
4151 g_closure_sink (closure);
4152 g_closure_set_marshal (closure, closure_accel_activate);
4154 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4156 aclosure = (AccelClosure*) closure;
4157 g_assert (closure->data == widget);
4158 g_assert (closure->marshal == closure_accel_activate);
4159 aclosure->signal_id = signal_id;
4165 * gtk_widget_add_accelerator
4166 * @widget: widget to install an accelerator on
4167 * @accel_signal: widget signal to emit on accelerator activation
4168 * @accel_group: accel group for this widget, added to its toplevel
4169 * @accel_key: GDK keyval of the accelerator
4170 * @accel_mods: modifier key combination of the accelerator
4171 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4173 * Installs an accelerator for this @widget in @accel_group that causes
4174 * @accel_signal to be emitted if the accelerator is activated.
4175 * The @accel_group needs to be added to the widget's toplevel via
4176 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4177 * Accelerators added through this function are not user changeable during
4178 * runtime. If you want to support accelerators that can be changed by the
4179 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4180 * gtk_menu_item_set_accel_path() instead.
4183 gtk_widget_add_accelerator (GtkWidget *widget,
4184 const gchar *accel_signal,
4185 GtkAccelGroup *accel_group,
4187 GdkModifierType accel_mods,
4188 GtkAccelFlags accel_flags)
4193 g_return_if_fail (GTK_IS_WIDGET (widget));
4194 g_return_if_fail (accel_signal != NULL);
4195 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4197 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4198 if (!query.signal_id ||
4199 !(query.signal_flags & G_SIGNAL_ACTION) ||
4200 query.return_type != G_TYPE_NONE ||
4203 /* hmm, should be elaborate enough */
4204 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4205 G_OBJECT_TYPE_NAME (widget), accel_signal);
4209 closure = widget_new_accel_closure (widget, query.signal_id);
4211 g_object_ref (widget);
4213 /* install the accelerator. since we don't map this onto an accel_path,
4214 * the accelerator will automatically be locked.
4216 gtk_accel_group_connect (accel_group,
4219 accel_flags | GTK_ACCEL_LOCKED,
4222 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4224 g_object_unref (widget);
4228 * gtk_widget_remove_accelerator:
4229 * @widget: widget to install an accelerator on
4230 * @accel_group: accel group for this widget
4231 * @accel_key: GDK keyval of the accelerator
4232 * @accel_mods: modifier key combination of the accelerator
4233 * @returns: whether an accelerator was installed and could be removed
4235 * Removes an accelerator from @widget, previously installed with
4236 * gtk_widget_add_accelerator().
4239 gtk_widget_remove_accelerator (GtkWidget *widget,
4240 GtkAccelGroup *accel_group,
4242 GdkModifierType accel_mods)
4244 GtkAccelGroupEntry *ag_entry;
4245 GList *slist, *clist;
4248 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4249 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4251 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4252 clist = gtk_widget_list_accel_closures (widget);
4253 for (slist = clist; slist; slist = slist->next)
4257 for (i = 0; i < n; i++)
4258 if (slist->data == (gpointer) ag_entry[i].closure)
4260 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4262 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4264 g_list_free (clist);
4269 g_list_free (clist);
4271 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4272 accel_key, accel_mods, accel_group,
4273 G_OBJECT_TYPE_NAME (widget), widget);
4279 * gtk_widget_list_accel_closures
4280 * @widget: widget to list accelerator closures for
4281 * @returns: a newly allocated #GList of closures
4283 * Lists the closures used by @widget for accelerator group connections
4284 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4285 * The closures can be used to monitor accelerator changes on @widget,
4286 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4287 * #GtkAccelGroup of a closure which can be found out with
4288 * gtk_accel_group_from_accel_closure().
4291 gtk_widget_list_accel_closures (GtkWidget *widget)
4294 GList *clist = NULL;
4296 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4298 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4299 if (gtk_accel_group_from_accel_closure (slist->data))
4300 clist = g_list_prepend (clist, slist->data);
4306 GtkAccelGroup *accel_group;
4311 destroy_accel_path (gpointer data)
4313 AccelPath *apath = data;
4315 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4317 /* closures_destroy takes care of unrefing the closure */
4318 g_object_unref (apath->accel_group);
4320 g_slice_free (AccelPath, apath);
4325 * gtk_widget_set_accel_path:
4326 * @widget: a #GtkWidget
4327 * @accel_path: path used to look up the accelerator
4328 * @accel_group: a #GtkAccelGroup.
4330 * Given an accelerator group, @accel_group, and an accelerator path,
4331 * @accel_path, sets up an accelerator in @accel_group so whenever the
4332 * key binding that is defined for @accel_path is pressed, @widget
4333 * will be activated. This removes any accelerators (for any
4334 * accelerator group) installed by previous calls to
4335 * gtk_widget_set_accel_path(). Associating accelerators with
4336 * paths allows them to be modified by the user and the modifications
4337 * to be saved for future use. (See gtk_accel_map_save().)
4339 * This function is a low level function that would most likely
4340 * be used by a menu creation system like #GtkUIManager. If you
4341 * use #GtkUIManager, setting up accelerator paths will be done
4344 * Even when you you aren't using #GtkUIManager, if you only want to
4345 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4346 * provides a somewhat more convenient interface.
4348 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4349 * pass a static string, you can save some memory by interning it first with
4350 * g_intern_static_string().
4353 gtk_widget_set_accel_path (GtkWidget *widget,
4354 const gchar *accel_path,
4355 GtkAccelGroup *accel_group)
4359 g_return_if_fail (GTK_IS_WIDGET (widget));
4360 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4364 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4365 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4367 gtk_accel_map_add_entry (accel_path, 0, 0);
4368 apath = g_slice_new (AccelPath);
4369 apath->accel_group = g_object_ref (accel_group);
4370 apath->path_quark = g_quark_from_string (accel_path);
4371 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4376 /* also removes possible old settings */
4377 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4380 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4382 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4386 _gtk_widget_get_accel_path (GtkWidget *widget,
4391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4393 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4395 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4396 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4400 gtk_widget_mnemonic_activate (GtkWidget *widget,
4401 gboolean group_cycling)
4405 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4407 group_cycling = group_cycling != FALSE;
4408 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4411 g_signal_emit (widget,
4412 widget_signals[MNEMONIC_ACTIVATE],
4420 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4421 gboolean group_cycling)
4423 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4424 gtk_widget_activate (widget);
4425 else if (GTK_WIDGET_CAN_FOCUS (widget))
4426 gtk_widget_grab_focus (widget);
4429 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4430 G_OBJECT_TYPE_NAME (widget));
4431 gtk_widget_error_bell (widget);
4437 gtk_widget_real_key_press_event (GtkWidget *widget,
4440 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4444 gtk_widget_real_key_release_event (GtkWidget *widget,
4447 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4451 gtk_widget_real_focus_in_event (GtkWidget *widget,
4452 GdkEventFocus *event)
4454 gtk_widget_queue_shallow_draw (widget);
4460 gtk_widget_real_focus_out_event (GtkWidget *widget,
4461 GdkEventFocus *event)
4463 gtk_widget_queue_shallow_draw (widget);
4468 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4469 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4473 * @widget: a #GtkWidget
4474 * @event: a #GdkEvent
4476 * Rarely-used function. This function is used to emit
4477 * the event signals on a widget (those signals should never
4478 * be emitted without using this function to do so).
4479 * If you want to synthesize an event though, don't use this function;
4480 * instead, use gtk_main_do_event() so the event will behave as if
4481 * it were in the event queue. Don't synthesize expose events; instead,
4482 * use gdk_window_invalidate_rect() to invalidate a region of the
4485 * Return value: return from the event signal emission (%TRUE if
4486 * the event was handled)
4489 gtk_widget_event (GtkWidget *widget,
4492 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4493 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4495 if (event->type == GDK_EXPOSE)
4497 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4498 "the same effect, call gdk_window_invalidate_rect/region(), "
4499 "followed by gdk_window_process_updates().");
4503 return gtk_widget_event_internal (widget, event);
4508 * gtk_widget_send_expose:
4509 * @widget: a #GtkWidget
4510 * @event: a expose #GdkEvent
4512 * Very rarely-used function. This function is used to emit
4513 * an expose event signals on a widget. This function is not
4514 * normally used directly. The only time it is used is when
4515 * propagating an expose event to a child %NO_WINDOW widget, and
4516 * that is normally done using gtk_container_propagate_expose().
4518 * If you want to force an area of a window to be redrawn,
4519 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4520 * To cause the redraw to be done immediately, follow that call
4521 * with a call to gdk_window_process_updates().
4523 * Return value: return from the event signal emission (%TRUE if
4524 * the event was handled)
4527 gtk_widget_send_expose (GtkWidget *widget,
4530 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4531 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4532 g_return_val_if_fail (event != NULL, TRUE);
4533 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4535 return gtk_widget_event_internal (widget, event);
4539 event_window_is_still_viewable (GdkEvent *event)
4541 /* Some programs, such as gnome-theme-manager, fake widgets
4542 * into exposing onto a pixmap by sending expose events with
4543 * event->window pointing to a pixmap
4545 if (GDK_IS_PIXMAP (event->any.window))
4546 return event->type == GDK_EXPOSE;
4548 /* Check that we think the event's window is viewable before
4549 * delivering the event, to prevent suprises. We do this here
4550 * at the last moment, since the event may have been queued
4551 * up behind other events, held over a recursive main loop, etc.
4553 switch (event->type)
4556 case GDK_MOTION_NOTIFY:
4557 case GDK_BUTTON_PRESS:
4558 case GDK_2BUTTON_PRESS:
4559 case GDK_3BUTTON_PRESS:
4561 case GDK_ENTER_NOTIFY:
4562 case GDK_PROXIMITY_IN:
4564 return event->any.window && gdk_window_is_viewable (event->any.window);
4567 /* The following events are the second half of paired events;
4568 * we always deliver them to deal with widgets that clean up
4569 * on the second half.
4571 case GDK_BUTTON_RELEASE:
4572 case GDK_KEY_RELEASE:
4573 case GDK_LEAVE_NOTIFY:
4574 case GDK_PROXIMITY_OUT:
4578 /* Remaining events would make sense on an not-viewable window,
4579 * or don't have an associated window.
4586 gtk_widget_event_internal (GtkWidget *widget,
4589 gboolean return_val = FALSE;
4591 /* We check only once for is-still-visible; if someone
4592 * hides the window in on of the signals on the widget,
4593 * they are responsible for returning TRUE to terminate
4596 if (!event_window_is_still_viewable (event))
4599 g_object_ref (widget);
4601 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4602 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4607 switch (event->type)
4612 case GDK_BUTTON_PRESS:
4613 case GDK_2BUTTON_PRESS:
4614 case GDK_3BUTTON_PRESS:
4615 signal_num = BUTTON_PRESS_EVENT;
4618 signal_num = SCROLL_EVENT;
4620 case GDK_BUTTON_RELEASE:
4621 signal_num = BUTTON_RELEASE_EVENT;
4623 case GDK_MOTION_NOTIFY:
4624 signal_num = MOTION_NOTIFY_EVENT;
4627 signal_num = DELETE_EVENT;
4630 signal_num = DESTROY_EVENT;
4631 _gtk_tooltip_hide (widget);
4634 signal_num = KEY_PRESS_EVENT;
4636 case GDK_KEY_RELEASE:
4637 signal_num = KEY_RELEASE_EVENT;
4639 case GDK_ENTER_NOTIFY:
4640 signal_num = ENTER_NOTIFY_EVENT;
4642 case GDK_LEAVE_NOTIFY:
4643 signal_num = LEAVE_NOTIFY_EVENT;
4645 case GDK_FOCUS_CHANGE:
4646 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4647 if (event->focus_change.in)
4648 _gtk_tooltip_focus_in (widget);
4650 _gtk_tooltip_focus_out (widget);
4653 signal_num = CONFIGURE_EVENT;
4656 signal_num = MAP_EVENT;
4659 signal_num = UNMAP_EVENT;
4661 case GDK_WINDOW_STATE:
4662 signal_num = WINDOW_STATE_EVENT;
4664 case GDK_PROPERTY_NOTIFY:
4665 signal_num = PROPERTY_NOTIFY_EVENT;
4667 case GDK_SELECTION_CLEAR:
4668 signal_num = SELECTION_CLEAR_EVENT;
4670 case GDK_SELECTION_REQUEST:
4671 signal_num = SELECTION_REQUEST_EVENT;
4673 case GDK_SELECTION_NOTIFY:
4674 signal_num = SELECTION_NOTIFY_EVENT;
4676 case GDK_PROXIMITY_IN:
4677 signal_num = PROXIMITY_IN_EVENT;
4679 case GDK_PROXIMITY_OUT:
4680 signal_num = PROXIMITY_OUT_EVENT;
4683 signal_num = NO_EXPOSE_EVENT;
4685 case GDK_CLIENT_EVENT:
4686 signal_num = CLIENT_EVENT;
4689 signal_num = EXPOSE_EVENT;
4691 case GDK_VISIBILITY_NOTIFY:
4692 signal_num = VISIBILITY_NOTIFY_EVENT;
4694 case GDK_GRAB_BROKEN:
4695 signal_num = GRAB_BROKEN;
4698 signal_num = DAMAGE_EVENT;
4701 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4705 if (signal_num != -1)
4706 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4708 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4709 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4713 g_object_unref (widget);
4719 * gtk_widget_activate:
4720 * @widget: a #GtkWidget that's activatable
4722 * For widgets that can be "activated" (buttons, menu items, etc.)
4723 * this function activates them. Activation is what happens when you
4724 * press Enter on a widget during key navigation. If @widget isn't
4725 * activatable, the function returns %FALSE.
4727 * Return value: %TRUE if the widget was activatable
4730 gtk_widget_activate (GtkWidget *widget)
4732 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4734 if (WIDGET_CLASS (widget)->activate_signal)
4736 /* FIXME: we should eventually check the signals signature here */
4737 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4746 * gtk_widget_set_scroll_adjustments:
4747 * @widget: a #GtkWidget
4748 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4749 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4751 * For widgets that support scrolling, sets the scroll adjustments and
4752 * returns %TRUE. For widgets that don't support scrolling, does
4753 * nothing and returns %FALSE. Widgets that don't support scrolling
4754 * can be scrolled by placing them in a #GtkViewport, which does
4755 * support scrolling.
4757 * Return value: %TRUE if the widget supports scrolling
4760 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4761 GtkAdjustment *hadjustment,
4762 GtkAdjustment *vadjustment)
4764 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4766 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4768 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4770 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
4772 /* FIXME: we should eventually check the signals signature here */
4773 g_signal_emit (widget,
4774 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
4775 hadjustment, vadjustment);
4783 gtk_widget_reparent_subwindows (GtkWidget *widget,
4784 GdkWindow *new_window)
4786 if (GTK_WIDGET_NO_WINDOW (widget))
4788 GList *children = gdk_window_get_children (widget->window);
4791 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4793 GdkWindow *window = tmp_list->data;
4796 gdk_window_get_user_data (window, &child);
4797 while (child && child != widget)
4798 child = ((GtkWidget*) child)->parent;
4801 gdk_window_reparent (window, new_window, 0, 0);
4804 g_list_free (children);
4809 GList *tmp_list, *children;
4811 parent = gdk_window_get_parent (widget->window);
4814 gdk_window_reparent (widget->window, new_window, 0, 0);
4817 children = gdk_window_get_children (parent);
4819 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4821 GdkWindow *window = tmp_list->data;
4824 gdk_window_get_user_data (window, &child);
4826 if (child == widget)
4827 gdk_window_reparent (window, new_window, 0, 0);
4830 g_list_free (children);
4836 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4837 gpointer client_data)
4839 g_assert (client_data != NULL);
4841 if (GTK_WIDGET_NO_WINDOW (widget))
4844 g_object_unref (widget->window);
4845 widget->window = (GdkWindow*) client_data;
4847 g_object_ref (widget->window);
4849 if (GTK_IS_CONTAINER (widget))
4850 gtk_container_forall (GTK_CONTAINER (widget),
4851 gtk_widget_reparent_fixup_child,
4857 * gtk_widget_reparent:
4858 * @widget: a #GtkWidget
4859 * @new_parent: a #GtkContainer to move the widget into
4861 * Moves a widget from one #GtkContainer to another, handling reference
4862 * count issues to avoid destroying the widget.
4865 gtk_widget_reparent (GtkWidget *widget,
4866 GtkWidget *new_parent)
4868 g_return_if_fail (GTK_IS_WIDGET (widget));
4869 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4870 g_return_if_fail (widget->parent != NULL);
4872 if (widget->parent != new_parent)
4874 /* First try to see if we can get away without unrealizing
4875 * the widget as we reparent it. if so we set a flag so
4876 * that gtk_widget_unparent doesn't unrealize widget
4878 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4879 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4881 g_object_ref (widget);
4882 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4883 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4884 g_object_unref (widget);
4886 if (GTK_WIDGET_IN_REPARENT (widget))
4888 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4890 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4891 gtk_widget_reparent_fixup_child (widget,
4892 gtk_widget_get_parent_window (widget));
4895 g_object_notify (G_OBJECT (widget), "parent");
4900 * gtk_widget_intersect:
4901 * @widget: a #GtkWidget
4902 * @area: a rectangle
4903 * @intersection: rectangle to store intersection of @widget and @area
4905 * Computes the intersection of a @widget's area and @area, storing
4906 * the intersection in @intersection, and returns %TRUE if there was
4907 * an intersection. @intersection may be %NULL if you're only
4908 * interested in whether there was an intersection.
4910 * Return value: %TRUE if there was an intersection
4913 gtk_widget_intersect (GtkWidget *widget,
4914 const GdkRectangle *area,
4915 GdkRectangle *intersection)
4921 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4922 g_return_val_if_fail (area != NULL, FALSE);
4925 dest = intersection;
4929 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4931 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4933 intersection->x -= widget->allocation.x;
4934 intersection->y -= widget->allocation.y;
4941 * gtk_widget_region_intersect:
4942 * @widget: a #GtkWidget
4943 * @region: a #GdkRegion, in the same coordinate system as
4944 * @widget->allocation. That is, relative to @widget->window
4945 * for %NO_WINDOW widgets; relative to the parent window
4946 * of @widget->window for widgets with their own window.
4947 * @returns: A newly allocated region holding the intersection of @widget
4948 * and @region. The coordinates of the return value are
4949 * relative to @widget->window for %NO_WINDOW widgets, and
4950 * relative to the parent window of @widget->window for
4951 * widgets with their own window.
4953 * Computes the intersection of a @widget's area and @region, returning
4954 * the intersection. The result may be empty, use gdk_region_empty() to
4958 gtk_widget_region_intersect (GtkWidget *widget,
4959 const GdkRegion *region)
4964 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4965 g_return_val_if_fail (region != NULL, NULL);
4967 gtk_widget_get_draw_rectangle (widget, &rect);
4969 dest = gdk_region_rectangle (&rect);
4971 gdk_region_intersect (dest, region);
4977 * _gtk_widget_grab_notify:
4978 * @widget: a #GtkWidget
4979 * @was_grabbed: whether a grab is now in effect
4981 * Emits the #GtkWidget::grab-notify signal on @widget.
4986 _gtk_widget_grab_notify (GtkWidget *widget,
4987 gboolean was_grabbed)
4989 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
4993 * gtk_widget_grab_focus:
4994 * @widget: a #GtkWidget
4996 * Causes @widget to have the keyboard focus for the #GtkWindow it's
4997 * inside. @widget must be a focusable widget, such as a #GtkEntry;
4998 * something like #GtkFrame won't work. (More precisely, it must have the
4999 * %GTK_CAN_FOCUS flag set.)
5002 gtk_widget_grab_focus (GtkWidget *widget)
5004 g_return_if_fail (GTK_IS_WIDGET (widget));
5006 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5009 g_object_ref (widget);
5010 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5011 g_object_notify (G_OBJECT (widget), "has-focus");
5012 g_object_unref (widget);
5016 reset_focus_recurse (GtkWidget *widget,
5019 if (GTK_IS_CONTAINER (widget))
5021 GtkContainer *container;
5023 container = GTK_CONTAINER (widget);
5024 gtk_container_set_focus_child (container, NULL);
5026 gtk_container_foreach (container,
5027 reset_focus_recurse,
5033 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5035 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5037 GtkWidget *toplevel;
5040 /* clear the current focus setting, break if the current widget
5041 * is the focus widget's parent, since containers above that will
5042 * be set by the next loop.
5044 toplevel = gtk_widget_get_toplevel (focus_widget);
5045 if (GTK_WIDGET_TOPLEVEL (toplevel))
5047 widget = GTK_WINDOW (toplevel)->focus_widget;
5049 if (widget == focus_widget)
5051 /* We call _gtk_window_internal_set_focus() here so that the
5052 * toplevel window can request the focus if necessary.
5053 * This is needed when the toplevel is a GtkPlug
5055 if (!GTK_WIDGET_HAS_FOCUS (widget))
5056 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5063 while (widget->parent && widget->parent != focus_widget->parent)
5065 widget = widget->parent;
5066 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5070 else if (toplevel != focus_widget)
5072 /* gtk_widget_grab_focus() operates on a tree without window...
5073 * actually, this is very questionable behaviour.
5076 gtk_container_foreach (GTK_CONTAINER (toplevel),
5077 reset_focus_recurse,
5081 /* now propagate the new focus up the widget tree and finally
5082 * set it on the window
5084 widget = focus_widget;
5085 while (widget->parent)
5087 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5088 widget = widget->parent;
5090 if (GTK_IS_WINDOW (widget))
5091 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5096 gtk_widget_real_query_tooltip (GtkWidget *widget,
5099 gboolean keyboard_tip,
5100 GtkTooltip *tooltip)
5102 gchar *tooltip_markup;
5103 gboolean has_tooltip;
5105 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5106 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5108 if (has_tooltip && tooltip_markup)
5110 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5118 gtk_widget_real_show_help (GtkWidget *widget,
5119 GtkWidgetHelpType help_type)
5121 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5123 _gtk_tooltip_toggle_keyboard_mode (widget);
5132 gtk_widget_real_focus (GtkWidget *widget,
5133 GtkDirectionType direction)
5135 if (!GTK_WIDGET_CAN_FOCUS (widget))
5138 if (!gtk_widget_is_focus (widget))
5140 gtk_widget_grab_focus (widget);
5148 gtk_widget_real_move_focus (GtkWidget *widget,
5149 GtkDirectionType direction)
5151 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5153 if (GTK_IS_WINDOW (toplevel) &&
5154 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5156 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5162 gtk_widget_real_keynav_failed (GtkWidget *widget,
5163 GtkDirectionType direction)
5165 gboolean cursor_only;
5169 case GTK_DIR_TAB_FORWARD:
5170 case GTK_DIR_TAB_BACKWARD:
5177 g_object_get (gtk_widget_get_settings (widget),
5178 "gtk-keynav-cursor-only", &cursor_only,
5185 gtk_widget_error_bell (widget);
5191 * gtk_widget_is_focus:
5192 * @widget: a #GtkWidget
5194 * Determines if the widget is the focus widget within its
5195 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5196 * necessarily set; %HAS_FOCUS will only be set if the
5197 * toplevel widget additionally has the global input focus.)
5199 * Return value: %TRUE if the widget is the focus widget.
5202 gtk_widget_is_focus (GtkWidget *widget)
5204 GtkWidget *toplevel;
5206 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5208 toplevel = gtk_widget_get_toplevel (widget);
5210 if (GTK_IS_WINDOW (toplevel))
5211 return widget == GTK_WINDOW (toplevel)->focus_widget;
5217 * gtk_widget_grab_default:
5218 * @widget: a #GtkWidget
5220 * Causes @widget to become the default widget. @widget must have the
5221 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5222 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5223 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5224 * the user presses Enter in a window. Default widgets must be
5225 * activatable, that is, gtk_widget_activate() should affect them.
5228 gtk_widget_grab_default (GtkWidget *widget)
5232 g_return_if_fail (GTK_IS_WIDGET (widget));
5233 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5235 window = gtk_widget_get_toplevel (widget);
5237 if (window && GTK_WIDGET_TOPLEVEL (window))
5238 gtk_window_set_default (GTK_WINDOW (window), widget);
5240 g_warning (G_STRLOC ": widget not within a GtkWindow");
5244 * gtk_widget_set_name:
5245 * @widget: a #GtkWidget
5246 * @name: name for the widget
5248 * Widgets can be named, which allows you to refer to them from a
5249 * gtkrc file. You can apply a style to widgets with a particular name
5250 * in the gtkrc file. See the documentation for gtkrc files (on the
5251 * same page as the docs for #GtkRcStyle).
5253 * Note that widget names are separated by periods in paths (see
5254 * gtk_widget_path()), so names with embedded periods may cause confusion.
5257 gtk_widget_set_name (GtkWidget *widget,
5262 g_return_if_fail (GTK_IS_WIDGET (widget));
5264 new_name = g_strdup (name);
5265 g_free (widget->name);
5266 widget->name = new_name;
5268 if (GTK_WIDGET_RC_STYLE (widget))
5269 gtk_widget_reset_rc_style (widget);
5271 g_object_notify (G_OBJECT (widget), "name");
5275 * gtk_widget_get_name:
5276 * @widget: a #GtkWidget
5278 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5279 * significance of widget names.
5281 * Return value: name of the widget. This string is owned by GTK+ and
5282 * should not be modified or freed
5284 G_CONST_RETURN gchar*
5285 gtk_widget_get_name (GtkWidget *widget)
5287 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5290 return widget->name;
5291 return g_type_name (GTK_WIDGET_TYPE (widget));
5295 * gtk_widget_set_state:
5296 * @widget: a #GtkWidget
5297 * @state: new state for @widget
5299 * This function is for use in widget implementations. Sets the state
5300 * of a widget (insensitive, prelighted, etc.) Usually you should set
5301 * the state using wrapper functions such as gtk_widget_set_sensitive().
5304 gtk_widget_set_state (GtkWidget *widget,
5307 g_return_if_fail (GTK_IS_WIDGET (widget));
5309 if (state == GTK_WIDGET_STATE (widget))
5312 if (state == GTK_STATE_INSENSITIVE)
5313 gtk_widget_set_sensitive (widget, FALSE);
5319 data.state_restoration = FALSE;
5320 data.use_forall = FALSE;
5322 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5324 data.parent_sensitive = TRUE;
5326 gtk_widget_propagate_state (widget, &data);
5328 if (GTK_WIDGET_DRAWABLE (widget))
5329 gtk_widget_queue_draw (widget);
5335 * gtk_widget_set_app_paintable:
5336 * @widget: a #GtkWidget
5337 * @app_paintable: %TRUE if the application will paint on the widget
5339 * Sets whether the application intends to draw on the widget in
5340 * an #GtkWidget::expose-event handler.
5342 * This is a hint to the widget and does not affect the behavior of
5343 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5344 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5345 * the effect is to suppress default themed drawing of the widget's
5346 * background. (Children of the widget will still be drawn.) The application
5347 * is then entirely responsible for drawing the widget background.
5349 * Note that the background is still drawn when the widget is mapped.
5350 * If this is not suitable (e.g. because you want to make a transparent
5351 * window using an RGBA visual), you can work around this by doing:
5353 * gtk_widget_realize (window);
5354 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5355 * gtk_widget_show (window);
5359 gtk_widget_set_app_paintable (GtkWidget *widget,
5360 gboolean app_paintable)
5362 g_return_if_fail (GTK_IS_WIDGET (widget));
5364 app_paintable = (app_paintable != FALSE);
5366 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5369 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5371 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5373 if (GTK_WIDGET_DRAWABLE (widget))
5374 gtk_widget_queue_draw (widget);
5376 g_object_notify (G_OBJECT (widget), "app-paintable");
5381 * gtk_widget_set_double_buffered:
5382 * @widget: a #GtkWidget
5383 * @double_buffered: %TRUE to double-buffer a widget
5385 * Widgets are double buffered by default; you can use this function
5386 * to turn off the buffering. "Double buffered" simply means that
5387 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5388 * automatically around expose events sent to the
5389 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5390 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5391 * buffer to the screen. The result is that users see the window
5392 * update in one smooth step, and don't see individual graphics
5393 * primitives being rendered.
5395 * In very simple terms, double buffered widgets don't flicker,
5396 * so you would only use this function to turn off double buffering
5397 * if you had special needs and really knew what you were doing.
5399 * Note: if you turn off double-buffering, you have to handle
5400 * expose events, since even the clearing to the background color or
5401 * pixmap will not happen automatically (as it is done in
5402 * gdk_window_begin_paint()).
5405 gtk_widget_set_double_buffered (GtkWidget *widget,
5406 gboolean double_buffered)
5408 g_return_if_fail (GTK_IS_WIDGET (widget));
5410 if (double_buffered)
5411 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5413 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5417 * gtk_widget_set_redraw_on_allocate:
5418 * @widget: a #GtkWidget
5419 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5420 * when it is allocated to a new size. Otherwise, only the
5421 * new portion of the widget will be redrawn.
5423 * Sets whether the entire widget is queued for drawing when its size
5424 * allocation changes. By default, this setting is %TRUE and
5425 * the entire widget is redrawn on every size change. If your widget
5426 * leaves the upper left unchanged when made bigger, turning this
5427 * setting off will improve performance.
5429 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5430 * off all allocation on resizing: the widget will not even redraw if
5431 * its position changes; this is to allow containers that don't draw
5432 * anything to avoid excess invalidations. If you set this flag on a
5433 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5434 * you are responsible for invalidating both the old and new allocation
5435 * of the widget when the widget is moved and responsible for invalidating
5436 * regions newly when the widget increases size.
5439 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5440 gboolean redraw_on_allocate)
5442 g_return_if_fail (GTK_IS_WIDGET (widget));
5444 if (redraw_on_allocate)
5445 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5447 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5451 * gtk_widget_set_sensitive:
5452 * @widget: a #GtkWidget
5453 * @sensitive: %TRUE to make the widget sensitive
5455 * Sets the sensitivity of a widget. A widget is sensitive if the user
5456 * can interact with it. Insensitive widgets are "grayed out" and the
5457 * user can't interact with them. Insensitive widgets are known as
5458 * "inactive", "disabled", or "ghosted" in some other toolkits.
5461 gtk_widget_set_sensitive (GtkWidget *widget,
5466 g_return_if_fail (GTK_IS_WIDGET (widget));
5468 sensitive = (sensitive != FALSE);
5470 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5475 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5476 data.state = GTK_WIDGET_SAVED_STATE (widget);
5480 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5481 data.state = GTK_WIDGET_STATE (widget);
5483 data.state_restoration = TRUE;
5484 data.use_forall = TRUE;
5487 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5489 data.parent_sensitive = TRUE;
5491 gtk_widget_propagate_state (widget, &data);
5492 if (GTK_WIDGET_DRAWABLE (widget))
5493 gtk_widget_queue_draw (widget);
5495 g_object_notify (G_OBJECT (widget), "sensitive");
5499 * gtk_widget_set_parent:
5500 * @widget: a #GtkWidget
5501 * @parent: parent container
5503 * This function is useful only when implementing subclasses of
5505 * Sets the container as the parent of @widget, and takes care of
5506 * some details such as updating the state and style of the child
5507 * to reflect its new location. The opposite function is
5508 * gtk_widget_unparent().
5511 gtk_widget_set_parent (GtkWidget *widget,
5516 g_return_if_fail (GTK_IS_WIDGET (widget));
5517 g_return_if_fail (GTK_IS_WIDGET (parent));
5518 g_return_if_fail (widget != parent);
5519 if (widget->parent != NULL)
5521 g_warning ("Can't set a parent on widget which has a parent\n");
5524 if (GTK_WIDGET_TOPLEVEL (widget))
5526 g_warning ("Can't set a parent on a toplevel widget\n");
5530 /* keep this function in sync with gtk_menu_attach_to_widget()
5533 g_object_ref_sink (widget);
5534 widget->parent = parent;
5536 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5537 data.state = GTK_WIDGET_STATE (parent);
5539 data.state = GTK_WIDGET_STATE (widget);
5540 data.state_restoration = FALSE;
5541 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5542 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5544 gtk_widget_propagate_state (widget, &data);
5546 gtk_widget_reset_rc_styles (widget);
5548 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5549 if (GTK_WIDGET_ANCHORED (widget->parent))
5550 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5551 g_object_notify (G_OBJECT (widget), "parent");
5553 /* Enforce realized/mapped invariants
5555 if (GTK_WIDGET_REALIZED (widget->parent))
5556 gtk_widget_realize (widget);
5558 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5559 GTK_WIDGET_VISIBLE (widget))
5561 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5562 GTK_WIDGET_MAPPED (widget->parent))
5563 gtk_widget_map (widget);
5565 gtk_widget_queue_resize (widget);
5570 * gtk_widget_get_parent:
5571 * @widget: a #GtkWidget
5573 * Returns the parent container of @widget.
5575 * Return value: the parent container of @widget, or %NULL
5578 gtk_widget_get_parent (GtkWidget *widget)
5580 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5582 return widget->parent;
5585 /*****************************************
5587 * see docs/styles.txt
5588 *****************************************/
5591 * gtk_widget_set_style:
5592 * @widget: a #GtkWidget
5593 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5594 * gtk_widget_set_style() and go back to the default style
5596 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5597 * want to use this function; it interacts badly with themes, because
5598 * themes work by replacing the #GtkStyle. Instead, use
5599 * gtk_widget_modify_style().
5602 gtk_widget_set_style (GtkWidget *widget,
5605 g_return_if_fail (GTK_IS_WIDGET (widget));
5609 gboolean initial_emission;
5611 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5613 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5614 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5616 gtk_widget_set_style_internal (widget, style, initial_emission);
5620 if (GTK_WIDGET_USER_STYLE (widget))
5621 gtk_widget_reset_rc_style (widget);
5626 * gtk_widget_ensure_style:
5627 * @widget: a #GtkWidget
5629 * Ensures that @widget has a style (@widget->style). Not a very useful
5630 * function; most of the time, if you want the style, the widget is
5631 * realized, and realized widgets are guaranteed to have a style
5635 gtk_widget_ensure_style (GtkWidget *widget)
5637 g_return_if_fail (GTK_IS_WIDGET (widget));
5639 if (!GTK_WIDGET_USER_STYLE (widget) &&
5640 !GTK_WIDGET_RC_STYLE (widget))
5641 gtk_widget_reset_rc_style (widget);
5644 /* Look up the RC style for this widget, unsetting any user style that
5645 * may be in effect currently
5648 gtk_widget_reset_rc_style (GtkWidget *widget)
5650 GtkStyle *new_style = NULL;
5651 gboolean initial_emission;
5653 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5655 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5656 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5658 if (gtk_widget_has_screen (widget))
5659 new_style = gtk_rc_get_style (widget);
5661 new_style = gtk_widget_get_default_style ();
5663 if (initial_emission || new_style != widget->style)
5664 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5668 * gtk_widget_get_style:
5669 * @widget: a #GtkWidget
5671 * Simply an accessor function that returns @widget->style.
5673 * Return value: the widget's #GtkStyle
5676 gtk_widget_get_style (GtkWidget *widget)
5678 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5680 return widget->style;
5684 * gtk_widget_modify_style:
5685 * @widget: a #GtkWidget
5686 * @style: the #GtkRcStyle holding the style modifications
5688 * Modifies style values on the widget. Modifications made using this
5689 * technique take precedence over style values set via an RC file,
5690 * however, they will be overriden if a style is explicitely set on
5691 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5692 * is designed so each field can either be set or unset, so it is
5693 * possible, using this function, to modify some style values and
5694 * leave the others unchanged.
5696 * Note that modifications made with this function are not cumulative
5697 * with previous calls to gtk_widget_modify_style() or with such
5698 * functions as gtk_widget_modify_fg(). If you wish to retain
5699 * previous values, you must first call gtk_widget_get_modifier_style(),
5700 * make your modifications to the returned style, then call
5701 * gtk_widget_modify_style() with that style. On the other hand,
5702 * if you first call gtk_widget_modify_style(), subsequent calls
5703 * to such functions gtk_widget_modify_fg() will have a cumulative
5704 * effect with the initial modifications.
5707 gtk_widget_modify_style (GtkWidget *widget,
5710 g_return_if_fail (GTK_IS_WIDGET (widget));
5711 g_return_if_fail (GTK_IS_RC_STYLE (style));
5713 g_object_set_qdata_full (G_OBJECT (widget),
5715 gtk_rc_style_copy (style),
5716 (GDestroyNotify) gtk_rc_style_unref);
5718 /* note that "style" may be invalid here if it was the old
5719 * modifier style and the only reference was our own.
5722 if (GTK_WIDGET_RC_STYLE (widget))
5723 gtk_widget_reset_rc_style (widget);
5727 * gtk_widget_get_modifier_style:
5728 * @widget: a #GtkWidget
5730 * Returns the current modifier style for the widget. (As set by
5731 * gtk_widget_modify_style().) If no style has previously set, a new
5732 * #GtkRcStyle will be created with all values unset, and set as the
5733 * modifier style for the widget. If you make changes to this rc
5734 * style, you must call gtk_widget_modify_style(), passing in the
5735 * returned rc style, to make sure that your changes take effect.
5737 * Caution: passing the style back to gtk_widget_modify_style() will
5738 * normally end up destroying it, because gtk_widget_modify_style() copies
5739 * the passed-in style and sets the copy as the new modifier style,
5740 * thus dropping any reference to the old modifier style. Add a reference
5741 * to the modifier style if you want to keep it alive.
5743 * Return value: the modifier style for the widget. This rc style is
5744 * owned by the widget. If you want to keep a pointer to value this
5745 * around, you must add a refcount using g_object_ref().
5748 gtk_widget_get_modifier_style (GtkWidget *widget)
5750 GtkRcStyle *rc_style;
5752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5754 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5758 rc_style = gtk_rc_style_new ();
5759 g_object_set_qdata_full (G_OBJECT (widget),
5762 (GDestroyNotify) gtk_rc_style_unref);
5769 gtk_widget_modify_color_component (GtkWidget *widget,
5770 GtkRcFlags component,
5772 const GdkColor *color)
5774 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5781 rc_style->fg[state] = *color;
5784 rc_style->bg[state] = *color;
5787 rc_style->text[state] = *color;
5790 rc_style->base[state] = *color;
5793 g_assert_not_reached();
5796 rc_style->color_flags[state] |= component;
5799 rc_style->color_flags[state] &= ~component;
5801 gtk_widget_modify_style (widget, rc_style);
5805 * gtk_widget_modify_fg:
5806 * @widget: a #GtkWidget
5807 * @state: the state for which to set the foreground color
5808 * @color: the color to assign (does not need to be allocated),
5809 * or %NULL to undo the effect of previous calls to
5810 * of gtk_widget_modify_fg().
5812 * Sets the foreground color for a widget in a particular state.
5813 * All other style values are left untouched. See also
5814 * gtk_widget_modify_style().
5817 gtk_widget_modify_fg (GtkWidget *widget,
5819 const GdkColor *color)
5821 g_return_if_fail (GTK_IS_WIDGET (widget));
5822 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5824 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5828 * gtk_widget_modify_bg:
5829 * @widget: a #GtkWidget
5830 * @state: the state for which to set the background color
5831 * @color: the color to assign (does not need to be allocated),
5832 * or %NULL to undo the effect of previous calls to
5833 * of gtk_widget_modify_bg().
5835 * Sets the background color for a widget in a particular state.
5836 * All other style values are left untouched. See also
5837 * gtk_widget_modify_style().
5839 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5840 * draw on their parent container's window and thus may not draw any
5841 * background themselves. This is the case for e.g. #GtkLabel. To modify
5842 * the background of such widgets, you have to set the background color
5843 * on their parent; if you want to set the background of a rectangular
5844 * area around a label, try placing the label in a #GtkEventBox widget
5845 * and setting the background color on that.
5848 gtk_widget_modify_bg (GtkWidget *widget,
5850 const GdkColor *color)
5852 g_return_if_fail (GTK_IS_WIDGET (widget));
5853 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5855 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5859 * gtk_widget_modify_text:
5860 * @widget: a #GtkWidget
5861 * @state: the state for which to set the text color
5862 * @color: the color to assign (does not need to be allocated),
5863 * or %NULL to undo the effect of previous calls to
5864 * of gtk_widget_modify_text().
5866 * Sets the text color for a widget in a particular state. All other
5867 * style values are left untouched. The text color is the foreground
5868 * color used along with the base color (see gtk_widget_modify_base())
5869 * for widgets such as #GtkEntry and #GtkTextView. See also
5870 * gtk_widget_modify_style().
5873 gtk_widget_modify_text (GtkWidget *widget,
5875 const GdkColor *color)
5877 g_return_if_fail (GTK_IS_WIDGET (widget));
5878 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5880 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5884 * gtk_widget_modify_base:
5885 * @widget: a #GtkWidget
5886 * @state: the state for which to set the base color
5887 * @color: the color to assign (does not need to be allocated),
5888 * or %NULL to undo the effect of previous calls to
5889 * of gtk_widget_modify_base().
5891 * Sets the base color for a widget in a particular state.
5892 * All other style values are left untouched. The base color
5893 * is the background color used along with the text color
5894 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5895 * and #GtkTextView. See also gtk_widget_modify_style().
5897 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5898 * draw on their parent container's window and thus may not draw any
5899 * background themselves. This is the case for e.g. #GtkLabel. To modify
5900 * the background of such widgets, you have to set the base color on their
5901 * parent; if you want to set the background of a rectangular area around
5902 * a label, try placing the label in a #GtkEventBox widget and setting
5903 * the base color on that.
5906 gtk_widget_modify_base (GtkWidget *widget,
5908 const GdkColor *color)
5910 g_return_if_fail (GTK_IS_WIDGET (widget));
5911 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5913 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5917 modify_color_property (GtkWidget *widget,
5918 GtkRcStyle *rc_style,
5920 const GdkColor *color)
5922 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5923 GQuark property_name = g_quark_from_string (name);
5927 GtkRcProperty rc_property = {0};
5930 rc_property.type_name = type_name;
5931 rc_property.property_name = property_name;
5932 rc_property.origin = NULL;
5934 color_name = gdk_color_to_string (color);
5935 g_value_init (&rc_property.value, G_TYPE_STRING);
5936 g_value_take_string (&rc_property.value, color_name);
5938 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
5940 g_value_unset (&rc_property.value);
5943 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
5947 * gtk_widget_modify_cursor:
5948 * @widget: a #GtkWidget
5949 * @primary: the color to use for primary cursor (does not need to be
5950 * allocated), or %NULL to undo the effect of previous calls to
5951 * of gtk_widget_modify_cursor().
5952 * @secondary: the color to use for secondary cursor (does not need to be
5953 * allocated), or %NULL to undo the effect of previous calls to
5954 * of gtk_widget_modify_cursor().
5956 * Sets the cursor color to use in a widget, overriding the
5957 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
5958 * style properties. All other style values are left untouched.
5959 * See also gtk_widget_modify_style().
5964 gtk_widget_modify_cursor (GtkWidget *widget,
5965 const GdkColor *primary,
5966 const GdkColor *secondary)
5968 GtkRcStyle *rc_style;
5970 g_return_if_fail (GTK_IS_WIDGET (widget));
5972 rc_style = gtk_widget_get_modifier_style (widget);
5974 modify_color_property (widget, rc_style, "cursor-color", primary);
5975 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
5977 gtk_widget_modify_style (widget, rc_style);
5981 * gtk_widget_modify_font:
5982 * @widget: a #GtkWidget
5983 * @font_desc: the font description to use, or %NULL to undo
5984 * the effect of previous calls to gtk_widget_modify_font().
5986 * Sets the font to use for a widget. All other style values are left
5987 * untouched. See also gtk_widget_modify_style().
5990 gtk_widget_modify_font (GtkWidget *widget,
5991 PangoFontDescription *font_desc)
5993 GtkRcStyle *rc_style;
5995 g_return_if_fail (GTK_IS_WIDGET (widget));
5997 rc_style = gtk_widget_get_modifier_style (widget);
5999 if (rc_style->font_desc)
6000 pango_font_description_free (rc_style->font_desc);
6003 rc_style->font_desc = pango_font_description_copy (font_desc);
6005 rc_style->font_desc = NULL;
6007 gtk_widget_modify_style (widget, rc_style);
6011 gtk_widget_direction_changed (GtkWidget *widget,
6012 GtkTextDirection previous_direction)
6014 gtk_widget_queue_resize (widget);
6018 gtk_widget_style_set (GtkWidget *widget,
6019 GtkStyle *previous_style)
6021 if (GTK_WIDGET_REALIZED (widget) &&
6022 !GTK_WIDGET_NO_WINDOW (widget))
6023 gtk_style_set_background (widget->style, widget->window, widget->state);
6027 gtk_widget_set_style_internal (GtkWidget *widget,
6029 gboolean initial_emission)
6031 g_object_ref (widget);
6032 g_object_freeze_notify (G_OBJECT (widget));
6034 if (widget->style != style)
6036 GtkStyle *previous_style;
6038 if (GTK_WIDGET_REALIZED (widget))
6040 gtk_widget_reset_shapes (widget);
6041 gtk_style_detach (widget->style);
6044 previous_style = widget->style;
6045 widget->style = style;
6046 g_object_ref (widget->style);
6048 if (GTK_WIDGET_REALIZED (widget))
6049 widget->style = gtk_style_attach (widget->style, widget->window);
6051 gtk_widget_update_pango_context (widget);
6052 g_signal_emit (widget,
6053 widget_signals[STYLE_SET],
6055 initial_emission ? NULL : previous_style);
6056 g_object_unref (previous_style);
6058 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6059 gtk_widget_queue_resize (widget);
6061 else if (initial_emission)
6063 gtk_widget_update_pango_context (widget);
6064 g_signal_emit (widget,
6065 widget_signals[STYLE_SET],
6069 g_object_notify (G_OBJECT (widget), "style");
6070 g_object_thaw_notify (G_OBJECT (widget));
6071 g_object_unref (widget);
6075 GtkWidget *previous_toplevel;
6076 GdkScreen *previous_screen;
6077 GdkScreen *new_screen;
6078 } HierarchyChangedInfo;
6081 do_screen_change (GtkWidget *widget,
6082 GdkScreen *old_screen,
6083 GdkScreen *new_screen)
6085 if (old_screen != new_screen)
6089 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6091 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6094 _gtk_tooltip_hide (widget);
6095 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6100 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6101 gpointer client_data)
6103 HierarchyChangedInfo *info = client_data;
6104 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6105 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6107 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6109 g_object_ref (widget);
6112 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6114 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6116 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6117 do_screen_change (widget, info->previous_screen, info->new_screen);
6119 if (GTK_IS_CONTAINER (widget))
6120 gtk_container_forall (GTK_CONTAINER (widget),
6121 gtk_widget_propagate_hierarchy_changed_recurse,
6124 g_object_unref (widget);
6129 * _gtk_widget_propagate_hierarchy_changed:
6130 * @widget: a #GtkWidget
6131 * @previous_toplevel: Previous toplevel
6133 * Propagates changes in the anchored state to a widget and all
6134 * children, unsetting or setting the %ANCHORED flag, and
6135 * emitting #GtkWidget::hierarchy-changed.
6138 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6139 GtkWidget *previous_toplevel)
6141 HierarchyChangedInfo info;
6143 info.previous_toplevel = previous_toplevel;
6144 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6146 if (GTK_WIDGET_TOPLEVEL (widget) ||
6147 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6148 info.new_screen = gtk_widget_get_screen (widget);
6150 info.new_screen = NULL;
6152 if (info.previous_screen)
6153 g_object_ref (info.previous_screen);
6154 if (previous_toplevel)
6155 g_object_ref (previous_toplevel);
6157 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6159 if (previous_toplevel)
6160 g_object_unref (previous_toplevel);
6161 if (info.previous_screen)
6162 g_object_unref (info.previous_screen);
6166 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6167 gpointer client_data)
6169 HierarchyChangedInfo *info = client_data;
6171 g_object_ref (widget);
6173 do_screen_change (widget, info->previous_screen, info->new_screen);
6175 if (GTK_IS_CONTAINER (widget))
6176 gtk_container_forall (GTK_CONTAINER (widget),
6177 gtk_widget_propagate_screen_changed_recurse,
6180 g_object_unref (widget);
6184 * gtk_widget_is_composited:
6185 * @widget: a #GtkWidget
6187 * Whether @widget can rely on having its alpha channel
6188 * drawn correctly. On X11 this function returns whether a
6189 * compositing manager is running for @widget's screen.
6191 * Please note that the semantics of this call will change
6192 * in the future if used on a widget that has a composited
6193 * window in its heirarchy (as set by
6194 * gdk_window_set_composited()).
6196 * Return value: %TRUE if the widget can rely on its alpha
6197 * channel being drawn correctly.
6202 gtk_widget_is_composited (GtkWidget *widget)
6206 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6208 screen = gtk_widget_get_screen (widget);
6210 return gdk_screen_is_composited (screen);
6214 propagate_composited_changed (GtkWidget *widget,
6217 if (GTK_IS_CONTAINER (widget))
6219 gtk_container_forall (GTK_CONTAINER (widget),
6220 propagate_composited_changed,
6224 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6228 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6230 propagate_composited_changed (widget, NULL);
6234 * _gtk_widget_propagate_screen_changed:
6235 * @widget: a #GtkWidget
6236 * @previous_screen: Previous screen
6238 * Propagates changes in the screen for a widget to all
6239 * children, emitting #GtkWidget::screen-changed.
6242 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6243 GdkScreen *previous_screen)
6245 HierarchyChangedInfo info;
6247 info.previous_screen = previous_screen;
6248 info.new_screen = gtk_widget_get_screen (widget);
6250 if (previous_screen)
6251 g_object_ref (previous_screen);
6253 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6255 if (previous_screen)
6256 g_object_unref (previous_screen);
6260 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6262 if (GTK_WIDGET_RC_STYLE (widget))
6263 gtk_widget_reset_rc_style (widget);
6265 if (GTK_IS_CONTAINER (widget))
6266 gtk_container_forall (GTK_CONTAINER (widget),
6267 reset_rc_styles_recurse,
6272 gtk_widget_reset_rc_styles (GtkWidget *widget)
6274 g_return_if_fail (GTK_IS_WIDGET (widget));
6276 reset_rc_styles_recurse (widget, NULL);
6280 * gtk_widget_get_default_style:
6282 * Returns the default style used by all widgets initially.
6284 * Returns: the default style. This #GtkStyle object is owned
6285 * by GTK+ and should not be modified or freed.
6288 gtk_widget_get_default_style (void)
6290 if (!gtk_default_style)
6292 gtk_default_style = gtk_style_new ();
6293 g_object_ref (gtk_default_style);
6296 return gtk_default_style;
6299 static PangoContext *
6300 gtk_widget_peek_pango_context (GtkWidget *widget)
6302 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6306 * gtk_widget_get_pango_context:
6307 * @widget: a #GtkWidget
6309 * Gets a #PangoContext with the appropriate font map, font description,
6310 * and base direction for this widget. Unlike the context returned
6311 * by gtk_widget_create_pango_context(), this context is owned by
6312 * the widget (it can be used until the screen for the widget changes
6313 * or the widget is removed from its toplevel), and will be updated to
6314 * match any changes to the widget's attributes.
6316 * If you create and keep a #PangoLayout using this context, you must
6317 * deal with changes to the context by calling pango_layout_context_changed()
6318 * on the layout in response to the #GtkWidget::style-set and
6319 * #GtkWidget::direction-changed signals for the widget.
6321 * Return value: the #PangoContext for the widget.
6324 gtk_widget_get_pango_context (GtkWidget *widget)
6326 PangoContext *context;
6328 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6330 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6333 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6334 g_object_set_qdata_full (G_OBJECT (widget),
6335 quark_pango_context,
6344 update_pango_context (GtkWidget *widget,
6345 PangoContext *context)
6347 pango_context_set_font_description (context, widget->style->font_desc);
6348 pango_context_set_base_dir (context,
6349 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6350 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6354 gtk_widget_update_pango_context (GtkWidget *widget)
6356 PangoContext *context = gtk_widget_peek_pango_context (widget);
6362 update_pango_context (widget, context);
6364 screen = gtk_widget_get_screen_unchecked (widget);
6367 pango_cairo_context_set_resolution (context,
6368 gdk_screen_get_resolution (screen));
6369 pango_cairo_context_set_font_options (context,
6370 gdk_screen_get_font_options (screen));
6376 * gtk_widget_create_pango_context:
6377 * @widget: a #GtkWidget
6379 * Creates a new #PangoContext with the appropriate font map,
6380 * font description, and base direction for drawing text for
6381 * this widget. See also gtk_widget_get_pango_context().
6383 * Return value: the new #PangoContext
6386 gtk_widget_create_pango_context (GtkWidget *widget)
6389 PangoContext *context;
6391 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6393 screen = gtk_widget_get_screen_unchecked (widget);
6396 GTK_NOTE (MULTIHEAD,
6397 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6399 screen = gdk_screen_get_default ();
6402 context = gdk_pango_context_get_for_screen (screen);
6404 update_pango_context (widget, context);
6405 pango_context_set_language (context, gtk_get_default_language ());
6411 * gtk_widget_create_pango_layout:
6412 * @widget: a #GtkWidget
6413 * @text: text to set on the layout (can be %NULL)
6415 * Creates a new #PangoLayout with the appropriate font map,
6416 * font description, and base direction for drawing text for
6419 * If you keep a #PangoLayout created in this way around, in order to
6420 * notify the layout of changes to the base direction or font of this
6421 * widget, you must call pango_layout_context_changed() in response to
6422 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6425 * Return value: the new #PangoLayout
6428 gtk_widget_create_pango_layout (GtkWidget *widget,
6431 PangoLayout *layout;
6432 PangoContext *context;
6434 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6436 context = gtk_widget_get_pango_context (widget);
6437 layout = pango_layout_new (context);
6440 pango_layout_set_text (layout, text, -1);
6446 * gtk_widget_render_icon:
6447 * @widget: a #GtkWidget
6448 * @stock_id: a stock ID
6449 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6450 * the size of the source and don't scale (if there are multiple
6451 * source sizes, GTK+ picks one of the available sizes).
6452 * @detail: render detail to pass to theme engine
6454 * A convenience function that uses the theme engine and RC file
6455 * settings for @widget to look up @stock_id and render it to
6456 * a pixbuf. @stock_id should be a stock icon ID such as
6457 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6458 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6459 * identifies the widget or code doing the rendering, so that
6460 * theme engines can special-case rendering for that widget or code.
6462 * The pixels in the returned #GdkPixbuf are shared with the rest of
6463 * the application and should not be modified. The pixbuf should be freed
6464 * after use with g_object_unref().
6466 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6469 gtk_widget_render_icon (GtkWidget *widget,
6470 const gchar *stock_id,
6472 const gchar *detail)
6474 GtkIconSet *icon_set;
6477 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6478 g_return_val_if_fail (stock_id != NULL, NULL);
6479 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6481 gtk_widget_ensure_style (widget);
6483 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6485 if (icon_set == NULL)
6488 retval = gtk_icon_set_render_icon (icon_set,
6490 gtk_widget_get_direction (widget),
6491 GTK_WIDGET_STATE (widget),
6500 * gtk_widget_set_parent_window:
6501 * @widget: a #GtkWidget.
6502 * @parent_window: the new parent window.
6504 * Sets a non default parent window for @widget.
6507 gtk_widget_set_parent_window (GtkWidget *widget,
6508 GdkWindow *parent_window)
6510 GdkWindow *old_parent_window;
6512 g_return_if_fail (GTK_IS_WIDGET (widget));
6514 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6515 quark_parent_window);
6517 if (parent_window != old_parent_window)
6519 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6521 if (old_parent_window)
6522 g_object_unref (old_parent_window);
6524 g_object_ref (parent_window);
6530 * gtk_widget_set_child_visible:
6531 * @widget: a #GtkWidget
6532 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6534 * Sets whether @widget should be mapped along with its when its parent
6535 * is mapped and @widget has been shown with gtk_widget_show().
6537 * The child visibility can be set for widget before it is added to
6538 * a container with gtk_widget_set_parent(), to avoid mapping
6539 * children unnecessary before immediately unmapping them. However
6540 * it will be reset to its default state of %TRUE when the widget
6541 * is removed from a container.
6543 * Note that changing the child visibility of a widget does not
6544 * queue a resize on the widget. Most of the time, the size of
6545 * a widget is computed from all visible children, whether or
6546 * not they are mapped. If this is not the case, the container
6547 * can queue a resize itself.
6549 * This function is only useful for container implementations and
6550 * never should be called by an application.
6553 gtk_widget_set_child_visible (GtkWidget *widget,
6554 gboolean is_visible)
6556 g_return_if_fail (GTK_IS_WIDGET (widget));
6557 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6559 g_object_ref (widget);
6562 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6565 GtkWidget *toplevel;
6567 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6569 toplevel = gtk_widget_get_toplevel (widget);
6570 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6571 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6574 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6576 if (GTK_WIDGET_MAPPED (widget->parent) &&
6577 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6578 GTK_WIDGET_VISIBLE (widget))
6579 gtk_widget_map (widget);
6581 gtk_widget_unmap (widget);
6584 g_object_unref (widget);
6588 * gtk_widget_get_child_visible:
6589 * @widget: a #GtkWidget
6591 * Gets the value set with gtk_widget_set_child_visible().
6592 * If you feel a need to use this function, your code probably
6593 * needs reorganization.
6595 * This function is only useful for container implementations and
6596 * never should be called by an application.
6598 * Return value: %TRUE if the widget is mapped with the parent.
6601 gtk_widget_get_child_visible (GtkWidget *widget)
6603 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6605 return GTK_WIDGET_CHILD_VISIBLE (widget);
6609 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6611 GtkWidget *toplevel;
6613 toplevel = gtk_widget_get_toplevel (widget);
6615 if (GTK_WIDGET_TOPLEVEL (toplevel))
6617 if (GTK_IS_WINDOW (toplevel))
6618 return GTK_WINDOW (toplevel)->screen;
6619 else if (GTK_IS_INVISIBLE (toplevel))
6620 return GTK_INVISIBLE (widget)->screen;
6627 * gtk_widget_get_screen:
6628 * @widget: a #GtkWidget
6630 * Get the #GdkScreen from the toplevel window associated with
6631 * this widget. This function can only be called after the widget
6632 * has been added to a widget hierarchy with a #GtkWindow
6635 * In general, you should only create screen specific
6636 * resources when a widget has been realized, and you should
6637 * free those resources when the widget is unrealized.
6639 * Return value: the #GdkScreen for the toplevel for this widget.
6644 gtk_widget_get_screen (GtkWidget *widget)
6648 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6650 screen = gtk_widget_get_screen_unchecked (widget);
6657 g_warning (G_STRLOC ": Can't get associated screen"
6658 " for a widget unless it is inside a toplevel GtkWindow\n"
6659 " widget type is %s associated top level type is %s",
6660 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6661 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6663 return gdk_screen_get_default ();
6668 * gtk_widget_has_screen:
6669 * @widget: a #GtkWidget
6671 * Checks whether there is a #GdkScreen is associated with
6672 * this widget. All toplevel widgets have an associated
6673 * screen, and all widgets added into a heirarchy with a toplevel
6674 * window at the top.
6676 * Return value: %TRUE if there is a #GdkScreen associcated
6682 gtk_widget_has_screen (GtkWidget *widget)
6684 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6686 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6690 * gtk_widget_get_display:
6691 * @widget: a #GtkWidget
6693 * Get the #GdkDisplay for the toplevel window associated with
6694 * this widget. This function can only be called after the widget
6695 * has been added to a widget hierarchy with a #GtkWindow at the top.
6697 * In general, you should only create display specific
6698 * resources when a widget has been realized, and you should
6699 * free those resources when the widget is unrealized.
6701 * Return value: the #GdkDisplay for the toplevel for this widget.
6706 gtk_widget_get_display (GtkWidget *widget)
6708 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6710 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6714 * gtk_widget_get_root_window:
6715 * @widget: a #GtkWidget
6717 * Get the root window where this widget is located. This function can
6718 * only be called after the widget has been added to a widget
6719 * heirarchy with #GtkWindow at the top.
6721 * The root window is useful for such purposes as creating a popup
6722 * #GdkWindow associated with the window. In general, you should only
6723 * create display specific resources when a widget has been realized,
6724 * and you should free those resources when the widget is unrealized.
6726 * Return value: the #GdkWindow root window for the toplevel for this widget.
6731 gtk_widget_get_root_window (GtkWidget *widget)
6733 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6735 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6739 * gtk_widget_get_parent_window:
6740 * @widget: a #GtkWidget.
6741 * @returns: the parent window of @widget.
6743 * Gets @widget's parent window.
6746 gtk_widget_get_parent_window (GtkWidget *widget)
6748 GdkWindow *parent_window;
6750 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6752 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6754 return (parent_window != NULL) ? parent_window :
6755 (widget->parent != NULL) ? widget->parent->window : NULL;
6759 * gtk_widget_child_focus:
6760 * @widget: a #GtkWidget
6761 * @direction: direction of focus movement
6763 * This function is used by custom widget implementations; if you're
6764 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6765 * to a particular widget, and gtk_container_set_focus_chain() to
6766 * change the focus tab order. So you may want to investigate those
6767 * functions instead.
6769 * gtk_widget_child_focus() is called by containers as the user moves
6770 * around the window using keyboard shortcuts. @direction indicates
6771 * what kind of motion is taking place (up, down, left, right, tab
6772 * forward, tab backward). gtk_widget_child_focus() emits the
6773 * #GtkWidget::focus" signal; widgets override the default handler
6774 * for this signal in order to implement appropriate focus behavior.
6776 * The default ::focus handler for a widget should return %TRUE if
6777 * moving in @direction left the focus on a focusable location inside
6778 * that widget, and %FALSE if moving in @direction moved the focus
6779 * outside the widget. If returning %TRUE, widgets normally
6780 * call gtk_widget_grab_focus() to place the focus accordingly;
6781 * if returning %FALSE, they don't modify the current focus location.
6783 * This function replaces gtk_container_focus() from GTK+ 1.2.
6784 * It was necessary to check that the child was visible, sensitive,
6785 * and focusable before calling gtk_container_focus().
6786 * gtk_widget_child_focus() returns %FALSE if the widget is not
6787 * currently in a focusable state, so there's no need for those checks.
6789 * Return value: %TRUE if focus ended up inside @widget
6792 gtk_widget_child_focus (GtkWidget *widget,
6793 GtkDirectionType direction)
6795 gboolean return_val;
6797 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6799 if (!GTK_WIDGET_VISIBLE (widget) ||
6800 !GTK_WIDGET_IS_SENSITIVE (widget))
6803 /* child widgets must set CAN_FOCUS, containers
6804 * don't have to though.
6806 if (!GTK_IS_CONTAINER (widget) &&
6807 !GTK_WIDGET_CAN_FOCUS (widget))
6810 g_signal_emit (widget,
6811 widget_signals[FOCUS],
6813 direction, &return_val);
6819 * gtk_widget_keynav_failed:
6820 * @widget: a #GtkWidget
6821 * @direction: direction of focus movement
6823 * This function should be called whenever keyboard navigation within
6824 * a single widget hits a boundary. The function emits the
6825 * #GtkWidget::keynav-failed signal on the widget and its return
6826 * value should be interpreted in a way similar to the return value of
6827 * gtk_widget_child_focus():
6829 * When %TRUE is returned, stay in the widget, the failed keyboard
6830 * navigation is Ok and/or there is nowhere we can/should move the
6833 * When %FALSE is returned, the caller should continue with keyboard
6834 * navigation outside the widget, e.g. by calling
6835 * gtk_widget_child_focus() on the widget's toplevel.
6837 * The default ::keynav-failed handler returns %TRUE for
6838 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6839 * values of #GtkDirectionType, it looks at the
6840 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6841 * if the setting is %TRUE. This way the entire user interface
6842 * becomes cursor-navigatable on input devices such as mobile phones
6843 * which only have cursor keys but no tab key.
6845 * Whenever the default handler returns %TRUE, it also calls
6846 * gtk_widget_error_bell() to notify the user of the failed keyboard
6849 * A use case for providing an own implementation of ::keynav-failed
6850 * (either by connecting to it or by overriding it) would be a row of
6851 * #GtkEntry widgets where the user should be able to navigate the
6852 * entire row with the cursor keys, as e.g. known from user interfaces
6853 * that require entering license keys.
6855 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6856 * if the emitting widget should try to handle the keyboard
6857 * navigation attempt in its parent container(s).
6862 gtk_widget_keynav_failed (GtkWidget *widget,
6863 GtkDirectionType direction)
6865 gboolean return_val;
6867 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6869 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6870 direction, &return_val);
6876 * gtk_widget_error_bell:
6877 * @widget: a #GtkWidget
6879 * Notifies the user about an input-related error on this widget.
6880 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6881 * gdk_window_beep(), otherwise it does nothing.
6883 * Note that the effect of gdk_window_beep() can be configured in many
6884 * ways, depending on the windowing backend and the desktop environment
6885 * or window manager that is used.
6890 gtk_widget_error_bell (GtkWidget *widget)
6894 g_return_if_fail (GTK_IS_WIDGET (widget));
6896 g_object_get (gtk_widget_get_settings (widget),
6897 "gtk-error-bell", &beep,
6900 if (beep && widget->window)
6901 gdk_window_beep (widget->window);
6905 * gtk_widget_set_uposition:
6906 * @widget: a #GtkWidget
6907 * @x: x position; -1 to unset x; -2 to leave x unchanged
6908 * @y: y position; -1 to unset y; -2 to leave y unchanged
6911 * Sets the position of a widget. The funny "u" in the name comes from
6912 * the "user position" hint specified by the X Window System, and
6913 * exists for legacy reasons. This function doesn't work if a widget
6914 * is inside a container; it's only really useful on #GtkWindow.
6916 * Don't use this function to center dialogs over the main application
6917 * window; most window managers will do the centering on your behalf
6918 * if you call gtk_window_set_transient_for(), and it's really not
6919 * possible to get the centering to work correctly in all cases from
6920 * application code. But if you insist, use gtk_window_set_position()
6921 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6924 * Note that although @x and @y can be individually unset, the position
6925 * is not honoured unless both @x and @y are set.
6928 gtk_widget_set_uposition (GtkWidget *widget,
6932 /* FIXME this function is the only place that aux_info->x and
6933 * aux_info->y are even used I believe, and this function is
6934 * deprecated. Should be cleaned up.
6936 * (Actually, size_allocate uses them) -Yosh
6939 GtkWidgetAuxInfo *aux_info;
6941 g_return_if_fail (GTK_IS_WIDGET (widget));
6943 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
6948 aux_info->x_set = FALSE;
6951 aux_info->x_set = TRUE;
6959 aux_info->y_set = FALSE;
6962 aux_info->y_set = TRUE;
6967 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
6968 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
6970 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
6971 gtk_widget_size_allocate (widget, &widget->allocation);
6975 gtk_widget_set_usize_internal (GtkWidget *widget,
6979 GtkWidgetAuxInfo *aux_info;
6980 gboolean changed = FALSE;
6982 g_object_freeze_notify (G_OBJECT (widget));
6984 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
6986 if (width > -2 && aux_info->width != width)
6988 g_object_notify (G_OBJECT (widget), "width-request");
6989 aux_info->width = width;
6992 if (height > -2 && aux_info->height != height)
6994 g_object_notify (G_OBJECT (widget), "height-request");
6995 aux_info->height = height;
6999 if (GTK_WIDGET_VISIBLE (widget) && changed)
7000 gtk_widget_queue_resize (widget);
7002 g_object_thaw_notify (G_OBJECT (widget));
7006 * gtk_widget_set_usize:
7007 * @widget: a #GtkWidget
7008 * @width: minimum width, or -1 to unset
7009 * @height: minimum height, or -1 to unset
7011 * Sets the minimum size of a widget; that is, the widget's size
7012 * request will be @width by @height. You can use this function to
7013 * force a widget to be either larger or smaller than it is. The
7014 * strange "usize" name dates from the early days of GTK+, and derives
7015 * from X Window System terminology. In many cases,
7016 * gtk_window_set_default_size() is a better choice for toplevel
7017 * windows than this function; setting the default size will still
7018 * allow users to shrink the window. Setting the usize will force them
7019 * to leave the window at least as large as the usize. When dealing
7020 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7023 * Note the inherent danger of setting any fixed size - themes,
7024 * translations into other languages, different fonts, and user action
7025 * can all change the appropriate size for a given widget. So, it's
7026 * basically impossible to hardcode a size that will always be
7029 * Deprecated: Use gtk_widget_set_size_request() instead.
7032 gtk_widget_set_usize (GtkWidget *widget,
7036 g_return_if_fail (GTK_IS_WIDGET (widget));
7038 gtk_widget_set_usize_internal (widget, width, height);
7042 * gtk_widget_set_size_request:
7043 * @widget: a #GtkWidget
7044 * @width: width @widget should request, or -1 to unset
7045 * @height: height @widget should request, or -1 to unset
7047 * Sets the minimum size of a widget; that is, the widget's size
7048 * request will be @width by @height. You can use this function to
7049 * force a widget to be either larger or smaller than it normally
7052 * In most cases, gtk_window_set_default_size() is a better choice for
7053 * toplevel windows than this function; setting the default size will
7054 * still allow users to shrink the window. Setting the size request
7055 * will force them to leave the window at least as large as the size
7056 * request. When dealing with window sizes,
7057 * gtk_window_set_geometry_hints() can be a useful function as well.
7059 * Note the inherent danger of setting any fixed size - themes,
7060 * translations into other languages, different fonts, and user action
7061 * can all change the appropriate size for a given widget. So, it's
7062 * basically impossible to hardcode a size that will always be
7065 * The size request of a widget is the smallest size a widget can
7066 * accept while still functioning well and drawing itself correctly.
7067 * However in some strange cases a widget may be allocated less than
7068 * its requested size, and in many cases a widget may be allocated more
7069 * space than it requested.
7071 * If the size request in a given direction is -1 (unset), then
7072 * the "natural" size request of the widget will be used instead.
7074 * Widgets can't actually be allocated a size less than 1 by 1, but
7075 * you can pass 0,0 to this function to mean "as small as possible."
7078 gtk_widget_set_size_request (GtkWidget *widget,
7082 g_return_if_fail (GTK_IS_WIDGET (widget));
7083 g_return_if_fail (width >= -1);
7084 g_return_if_fail (height >= -1);
7091 gtk_widget_set_usize_internal (widget, width, height);
7096 * gtk_widget_get_size_request:
7097 * @widget: a #GtkWidget
7098 * @width: return location for width, or %NULL
7099 * @height: return location for height, or %NULL
7101 * Gets the size request that was explicitly set for the widget using
7102 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7103 * @height indicates that that dimension has not been set explicitly
7104 * and the natural requisition of the widget will be used intead. See
7105 * gtk_widget_set_size_request(). To get the size a widget will
7106 * actually use, call gtk_widget_size_request() instead of
7110 gtk_widget_get_size_request (GtkWidget *widget,
7114 GtkWidgetAuxInfo *aux_info;
7116 g_return_if_fail (GTK_IS_WIDGET (widget));
7118 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7121 *width = aux_info ? aux_info->width : -1;
7124 *height = aux_info ? aux_info->height : -1;
7128 * gtk_widget_set_events:
7129 * @widget: a #GtkWidget
7130 * @events: event mask
7132 * Sets the event mask (see #GdkEventMask) for a widget. The event
7133 * mask determines which events a widget will receive. Keep in mind
7134 * that different widgets have different default event masks, and by
7135 * changing the event mask you may disrupt a widget's functionality,
7136 * so be careful. This function must be called while a widget is
7137 * unrealized. Consider gtk_widget_add_events() for widgets that are
7138 * already realized, or if you want to preserve the existing event
7139 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7140 * to get events on those widgets, place them inside a #GtkEventBox
7141 * and receive events on the event box.
7144 gtk_widget_set_events (GtkWidget *widget,
7147 g_return_if_fail (GTK_IS_WIDGET (widget));
7148 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7150 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7151 GINT_TO_POINTER (events));
7152 g_object_notify (G_OBJECT (widget), "events");
7156 gtk_widget_add_events_internal (GtkWidget *widget,
7162 for (l = window_list; l != NULL; l = l->next)
7164 GdkWindow *window = l->data;
7167 gdk_window_get_user_data (window, &user_data);
7168 if (user_data == widget)
7172 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7174 children = gdk_window_get_children (window);
7175 gtk_widget_add_events_internal (widget, events, children);
7176 g_list_free (children);
7182 * gtk_widget_add_events:
7183 * @widget: a #GtkWidget
7184 * @events: an event mask, see #GdkEventMask
7186 * Adds the events in the bitfield @events to the event mask for
7187 * @widget. See gtk_widget_set_events() for details.
7190 gtk_widget_add_events (GtkWidget *widget,
7195 g_return_if_fail (GTK_IS_WIDGET (widget));
7197 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7198 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7199 GINT_TO_POINTER (old_events | events));
7201 if (GTK_WIDGET_REALIZED (widget))
7205 if (GTK_WIDGET_NO_WINDOW (widget))
7206 window_list = gdk_window_get_children (widget->window);
7208 window_list = g_list_prepend (NULL, widget->window);
7210 gtk_widget_add_events_internal (widget, events, window_list);
7212 g_list_free (window_list);
7215 g_object_notify (G_OBJECT (widget), "events");
7219 * gtk_widget_set_extension_events:
7220 * @widget: a #GtkWidget
7221 * @mode: bitfield of extension events to receive
7223 * Sets the extension events mask to @mode. See #GdkExtensionMode
7224 * and gdk_input_set_extension_events().
7227 gtk_widget_set_extension_events (GtkWidget *widget,
7228 GdkExtensionMode mode)
7230 g_return_if_fail (GTK_IS_WIDGET (widget));
7232 if (GTK_WIDGET_REALIZED (widget))
7233 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7235 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7236 GINT_TO_POINTER (mode));
7237 g_object_notify (G_OBJECT (widget), "extension-events");
7241 * gtk_widget_get_toplevel:
7242 * @widget: a #GtkWidget
7244 * This function returns the topmost widget in the container hierarchy
7245 * @widget is a part of. If @widget has no parent widgets, it will be
7246 * returned as the topmost widget. No reference will be added to the
7247 * returned widget; it should not be unreferenced.
7249 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7250 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7252 * %NULL if @widget wasn't inside a toplevel window, and if the
7253 * window was inside a #GtkWindow-derived widget which was in turn
7254 * inside the toplevel #GtkWindow. While the second case may
7255 * seem unlikely, it actually happens when a #GtkPlug is embedded
7256 * inside a #GtkSocket within the same application.
7258 * To reliably find the toplevel #GtkWindow, use
7259 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7260 * is set on the result.
7262 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7263 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7265 * /* Perform action on toplevel. */
7269 * Return value: the topmost ancestor of @widget, or @widget itself
7270 * if there's no ancestor.
7273 gtk_widget_get_toplevel (GtkWidget *widget)
7275 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7277 while (widget->parent)
7278 widget = widget->parent;
7284 * gtk_widget_get_ancestor:
7285 * @widget: a #GtkWidget
7286 * @widget_type: ancestor type
7288 * Gets the first ancestor of @widget with type @widget_type. For example,
7289 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7290 * the first #GtkBox that's an ancestor of @widget. No reference will be
7291 * added to the returned widget; it should not be unreferenced. See note
7292 * about checking for a toplevel #GtkWindow in the docs for
7293 * gtk_widget_get_toplevel().
7295 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7296 * considers @widget to be an ancestor of itself.
7298 * Return value: the ancestor widget, or %NULL if not found
7301 gtk_widget_get_ancestor (GtkWidget *widget,
7304 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7306 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7307 widget = widget->parent;
7309 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7316 * gtk_widget_get_colormap:
7317 * @widget: a #GtkWidget
7319 * Gets the colormap that will be used to render @widget. No reference will
7320 * be added to the returned colormap; it should not be unreferenced.
7322 * Return value: the colormap used by @widget
7325 gtk_widget_get_colormap (GtkWidget *widget)
7327 GdkColormap *colormap;
7328 GtkWidget *tmp_widget;
7330 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7334 colormap = gdk_drawable_get_colormap (widget->window);
7335 /* If window was destroyed previously, we'll get NULL here */
7340 tmp_widget = widget;
7343 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7347 tmp_widget= tmp_widget->parent;
7350 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7354 * gtk_widget_get_visual:
7355 * @widget: a #GtkWidget
7357 * Gets the visual that will be used to render @widget.
7359 * Return value: the visual for @widget
7362 gtk_widget_get_visual (GtkWidget *widget)
7364 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7366 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7370 * gtk_widget_get_settings:
7371 * @widget: a #GtkWidget
7373 * Gets the settings object holding the settings (global property
7374 * settings, RC file information, etc) used for this widget.
7376 * Note that this function can only be called when the #GtkWidget
7377 * is attached to a toplevel, since the settings object is specific
7378 * to a particular #GdkScreen.
7380 * Return value: the relevant #GtkSettings object
7383 gtk_widget_get_settings (GtkWidget *widget)
7385 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7387 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7391 * gtk_widget_set_colormap:
7392 * @widget: a #GtkWidget
7393 * @colormap: a colormap
7395 * Sets the colormap for the widget to the given value. Widget must not
7396 * have been previously realized. This probably should only be used
7397 * from an <function>init()</function> function (i.e. from the constructor
7401 gtk_widget_set_colormap (GtkWidget *widget,
7402 GdkColormap *colormap)
7404 g_return_if_fail (GTK_IS_WIDGET (widget));
7405 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7406 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7408 g_object_ref (colormap);
7410 g_object_set_qdata_full (G_OBJECT (widget),
7417 * gtk_widget_get_events:
7418 * @widget: a #GtkWidget
7420 * Returns the event mask for the widget (a bitfield containing flags
7421 * from the #GdkEventMask enumeration). These are the events that the widget
7424 * Return value: event mask for @widget
7427 gtk_widget_get_events (GtkWidget *widget)
7429 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7431 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7435 * gtk_widget_get_extension_events:
7436 * @widget: a #GtkWidget
7438 * Retrieves the extension events the widget will receive; see
7439 * gdk_input_set_extension_events().
7441 * Return value: extension events for @widget
7444 gtk_widget_get_extension_events (GtkWidget *widget)
7446 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7448 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7452 * gtk_widget_get_pointer:
7453 * @widget: a #GtkWidget
7454 * @x: return location for the X coordinate, or %NULL
7455 * @y: return location for the Y coordinate, or %NULL
7457 * Obtains the location of the mouse pointer in widget coordinates.
7458 * Widget coordinates are a bit odd; for historical reasons, they are
7459 * defined as @widget->window coordinates for widgets that are not
7460 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7461 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7464 gtk_widget_get_pointer (GtkWidget *widget,
7468 g_return_if_fail (GTK_IS_WIDGET (widget));
7475 if (GTK_WIDGET_REALIZED (widget))
7477 gdk_window_get_pointer (widget->window, x, y, NULL);
7479 if (GTK_WIDGET_NO_WINDOW (widget))
7482 *x -= widget->allocation.x;
7484 *y -= widget->allocation.y;
7490 * gtk_widget_is_ancestor:
7491 * @widget: a #GtkWidget
7492 * @ancestor: another #GtkWidget
7494 * Determines whether @widget is somewhere inside @ancestor, possibly with
7495 * intermediate containers.
7497 * Return value: %TRUE if @ancestor contains @widget as a child,
7498 * grandchild, great grandchild, etc.
7501 gtk_widget_is_ancestor (GtkWidget *widget,
7502 GtkWidget *ancestor)
7504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7505 g_return_val_if_fail (ancestor != NULL, FALSE);
7509 if (widget->parent == ancestor)
7511 widget = widget->parent;
7517 static GQuark quark_composite_name = 0;
7520 * gtk_widget_set_composite_name:
7521 * @widget: a #GtkWidget.
7522 * @name: the name to set
7524 * Sets a widgets composite name. The widget must be
7525 * a composite child of its parent; see gtk_widget_push_composite_child().
7528 gtk_widget_set_composite_name (GtkWidget *widget,
7531 g_return_if_fail (GTK_IS_WIDGET (widget));
7532 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7533 g_return_if_fail (name != NULL);
7535 if (!quark_composite_name)
7536 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7538 g_object_set_qdata_full (G_OBJECT (widget),
7539 quark_composite_name,
7545 * gtk_widget_get_composite_name:
7546 * @widget: a #GtkWidget
7547 * @returns: the composite name of @widget, or %NULL if @widget is not
7548 * a composite child. The string should not be freed when it is no
7551 * Obtains the composite name of a widget.
7554 gtk_widget_get_composite_name (GtkWidget *widget)
7556 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7558 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7559 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7566 * gtk_widget_push_composite_child:
7568 * Makes all newly-created widgets as composite children until
7569 * the corresponding gtk_widget_pop_composite_child() call.
7571 * A composite child is a child that's an implementation detail of the
7572 * container it's inside and should not be visible to people using the
7573 * container. Composite children aren't treated differently by GTK (but
7574 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7575 * builders might want to treat them in a different way.
7577 * Here is a simple example:
7579 * gtk_widget_push_composite_child ();
7580 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7581 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7582 * gtk_widget_pop_composite_child ();
7583 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7584 * GTK_WIDGET (scrolled_window));
7585 * g_object_ref (scrolled_window->hscrollbar);
7589 gtk_widget_push_composite_child (void)
7591 composite_child_stack++;
7595 * gtk_widget_pop_composite_child:
7597 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7600 gtk_widget_pop_composite_child (void)
7602 if (composite_child_stack)
7603 composite_child_stack--;
7607 * gtk_widget_push_colormap:
7608 * @cmap: a #GdkColormap
7610 * Pushes @cmap onto a global stack of colormaps; the topmost
7611 * colormap on the stack will be used to create all widgets.
7612 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7613 * reason to use this function.
7616 gtk_widget_push_colormap (GdkColormap *cmap)
7618 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7620 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7624 * gtk_widget_pop_colormap:
7626 * Removes a colormap pushed with gtk_widget_push_colormap().
7629 gtk_widget_pop_colormap (void)
7632 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7636 * gtk_widget_set_default_colormap:
7637 * @colormap: a #GdkColormap
7639 * Sets the default colormap to use when creating widgets.
7640 * gtk_widget_push_colormap() is a better function to use if
7641 * you only want to affect a few widgets, rather than all widgets.
7644 gtk_widget_set_default_colormap (GdkColormap *colormap)
7646 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7648 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7653 * gtk_widget_get_default_colormap:
7655 * Obtains the default colormap used to create widgets.
7657 * Return value: default widget colormap
7660 gtk_widget_get_default_colormap (void)
7662 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7666 * gtk_widget_get_default_visual:
7668 * Obtains the visual of the default colormap. Not really useful;
7669 * used to be useful before gdk_colormap_get_visual() existed.
7671 * Return value: visual of the default colormap
7674 gtk_widget_get_default_visual (void)
7676 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7680 gtk_widget_emit_direction_changed (GtkWidget *widget,
7681 GtkTextDirection old_dir)
7683 gtk_widget_update_pango_context (widget);
7685 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7689 * gtk_widget_set_direction:
7690 * @widget: a #GtkWidget
7691 * @dir: the new direction
7693 * Sets the reading direction on a particular widget. This direction
7694 * controls the primary direction for widgets containing text,
7695 * and also the direction in which the children of a container are
7696 * packed. The ability to set the direction is present in order
7697 * so that correct localization into languages with right-to-left
7698 * reading directions can be done. Generally, applications will
7699 * let the default reading direction present, except for containers
7700 * where the containers are arranged in an order that is explicitely
7701 * visual rather than logical (such as buttons for text justification).
7703 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7704 * set by gtk_widget_set_default_direction() will be used.
7707 gtk_widget_set_direction (GtkWidget *widget,
7708 GtkTextDirection dir)
7710 GtkTextDirection old_dir;
7712 g_return_if_fail (GTK_IS_WIDGET (widget));
7713 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7715 old_dir = gtk_widget_get_direction (widget);
7717 if (dir == GTK_TEXT_DIR_NONE)
7718 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7721 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7722 if (dir == GTK_TEXT_DIR_LTR)
7723 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7725 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7728 if (old_dir != gtk_widget_get_direction (widget))
7729 gtk_widget_emit_direction_changed (widget, old_dir);
7733 * gtk_widget_get_direction:
7734 * @widget: a #GtkWidget
7736 * Gets the reading direction for a particular widget. See
7737 * gtk_widget_set_direction().
7739 * Return value: the reading direction for the widget.
7742 gtk_widget_get_direction (GtkWidget *widget)
7744 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7746 if (GTK_WIDGET_DIRECTION_SET (widget))
7747 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7749 return gtk_default_direction;
7753 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7755 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7757 g_object_ref (widget);
7759 if (!GTK_WIDGET_DIRECTION_SET (widget))
7760 gtk_widget_emit_direction_changed (widget, old_dir);
7762 if (GTK_IS_CONTAINER (widget))
7763 gtk_container_forall (GTK_CONTAINER (widget),
7764 gtk_widget_set_default_direction_recurse,
7767 g_object_unref (widget);
7771 * gtk_widget_set_default_direction:
7772 * @dir: the new default direction. This cannot be
7773 * %GTK_TEXT_DIR_NONE.
7775 * Sets the default reading direction for widgets where the
7776 * direction has not been explicitly set by gtk_widget_set_direction().
7779 gtk_widget_set_default_direction (GtkTextDirection dir)
7781 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7783 if (dir != gtk_default_direction)
7785 GList *toplevels, *tmp_list;
7786 GtkTextDirection old_dir = gtk_default_direction;
7788 gtk_default_direction = dir;
7790 tmp_list = toplevels = gtk_window_list_toplevels ();
7791 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7795 gtk_widget_set_default_direction_recurse (tmp_list->data,
7796 GUINT_TO_POINTER (old_dir));
7797 g_object_unref (tmp_list->data);
7798 tmp_list = tmp_list->next;
7801 g_list_free (toplevels);
7806 * gtk_widget_get_default_direction:
7808 * Obtains the current default reading direction. See
7809 * gtk_widget_set_default_direction().
7811 * Return value: the current default direction.
7814 gtk_widget_get_default_direction (void)
7816 return gtk_default_direction;
7820 gtk_widget_dispose (GObject *object)
7822 GtkWidget *widget = GTK_WIDGET (object);
7825 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7826 else if (GTK_WIDGET_VISIBLE (widget))
7827 gtk_widget_hide (widget);
7829 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7830 if (GTK_WIDGET_REALIZED (widget))
7831 gtk_widget_unrealize (widget);
7833 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7837 gtk_widget_real_destroy (GtkObject *object)
7839 /* gtk_object_destroy() will already hold a refcount on object */
7840 GtkWidget *widget = GTK_WIDGET (object);
7842 /* wipe accelerator closures (keep order) */
7843 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7844 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7846 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7847 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7849 gtk_grab_remove (widget);
7851 g_object_unref (widget->style);
7852 widget->style = gtk_widget_get_default_style ();
7853 g_object_ref (widget->style);
7855 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7859 gtk_widget_finalize (GObject *object)
7861 GtkWidget *widget = GTK_WIDGET (object);
7862 GtkWidgetAuxInfo *aux_info;
7863 GtkAccessible *accessible;
7865 gtk_grab_remove (widget);
7867 g_object_unref (widget->style);
7868 widget->style = NULL;
7870 g_free (widget->name);
7872 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7874 gtk_widget_aux_info_destroy (aux_info);
7876 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7878 g_object_unref (accessible);
7880 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7883 /*****************************************
7884 * gtk_widget_real_map:
7889 *****************************************/
7892 gtk_widget_real_map (GtkWidget *widget)
7894 g_assert (GTK_WIDGET_REALIZED (widget));
7896 if (!GTK_WIDGET_MAPPED (widget))
7898 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7900 if (!GTK_WIDGET_NO_WINDOW (widget))
7901 gdk_window_show (widget->window);
7905 /*****************************************
7906 * gtk_widget_real_unmap:
7911 *****************************************/
7914 gtk_widget_real_unmap (GtkWidget *widget)
7916 if (GTK_WIDGET_MAPPED (widget))
7918 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7920 if (!GTK_WIDGET_NO_WINDOW (widget))
7921 gdk_window_hide (widget->window);
7925 /*****************************************
7926 * gtk_widget_real_realize:
7931 *****************************************/
7934 gtk_widget_real_realize (GtkWidget *widget)
7936 g_assert (GTK_WIDGET_NO_WINDOW (widget));
7938 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7941 widget->window = gtk_widget_get_parent_window (widget);
7942 g_object_ref (widget->window);
7944 widget->style = gtk_style_attach (widget->style, widget->window);
7947 /*****************************************
7948 * gtk_widget_real_unrealize:
7953 *****************************************/
7956 gtk_widget_real_unrealize (GtkWidget *widget)
7958 if (GTK_WIDGET_MAPPED (widget))
7959 gtk_widget_real_unmap (widget);
7961 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7963 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
7966 /* We must do unrealize child widget BEFORE container widget.
7967 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
7968 * So, unrealizing container widget bofore its children causes the problem
7969 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
7972 if (GTK_IS_CONTAINER (widget))
7973 gtk_container_forall (GTK_CONTAINER (widget),
7974 (GtkCallback) gtk_widget_unrealize,
7977 gtk_style_detach (widget->style);
7978 if (!GTK_WIDGET_NO_WINDOW (widget))
7980 gdk_window_set_user_data (widget->window, NULL);
7981 gdk_window_destroy (widget->window);
7982 widget->window = NULL;
7986 g_object_unref (widget->window);
7987 widget->window = NULL;
7990 gtk_selection_remove_all (widget);
7992 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
7996 gtk_widget_real_size_request (GtkWidget *widget,
7997 GtkRequisition *requisition)
7999 requisition->width = widget->requisition.width;
8000 requisition->height = widget->requisition.height;
8004 * _gtk_widget_peek_colormap:
8006 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8008 * Return value: the currently pushed colormap, or %NULL if there is none.
8011 _gtk_widget_peek_colormap (void)
8014 return (GdkColormap*) colormap_stack->data;
8019 gtk_widget_propagate_state (GtkWidget *widget,
8022 guint8 old_state = GTK_WIDGET_STATE (widget);
8023 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8025 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8026 * parent_sensitive==TRUE on a sensitive widget
8030 if (data->parent_sensitive)
8031 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8033 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8035 if (GTK_WIDGET_IS_SENSITIVE (widget))
8037 if (data->state_restoration)
8038 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8040 GTK_WIDGET_STATE (widget) = data->state;
8044 if (!data->state_restoration)
8046 if (data->state != GTK_STATE_INSENSITIVE)
8047 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8049 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8050 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8051 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8054 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8058 window = gtk_widget_get_toplevel (widget);
8059 if (window && GTK_WIDGET_TOPLEVEL (window))
8060 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8063 if (old_state != GTK_WIDGET_STATE (widget) ||
8064 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8066 g_object_ref (widget);
8068 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8069 gtk_grab_remove (widget);
8071 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8073 if (GTK_IS_CONTAINER (widget))
8075 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8076 if (data->use_forall)
8077 gtk_container_forall (GTK_CONTAINER (widget),
8078 (GtkCallback) gtk_widget_propagate_state,
8081 gtk_container_foreach (GTK_CONTAINER (widget),
8082 (GtkCallback) gtk_widget_propagate_state,
8085 g_object_unref (widget);
8090 * _gtk_widget_get_aux_info:
8091 * @widget: a #GtkWidget
8092 * @create: if %TRUE, create the structure if it doesn't exist
8094 * Get the #GtkWidgetAuxInfo structure for the widget.
8096 * Return value: the #GtkAuxInfo structure for the widget, or
8097 * %NULL if @create is %FALSE and one doesn't already exist.
8100 _gtk_widget_get_aux_info (GtkWidget *widget,
8103 GtkWidgetAuxInfo *aux_info;
8105 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8106 if (!aux_info && create)
8108 aux_info = g_slice_new (GtkWidgetAuxInfo);
8110 aux_info->width = -1;
8111 aux_info->height = -1;
8114 aux_info->x_set = FALSE;
8115 aux_info->y_set = FALSE;
8116 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8122 /*****************************************
8123 * gtk_widget_aux_info_destroy:
8128 *****************************************/
8131 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8133 g_slice_free (GtkWidgetAuxInfo, aux_info);
8137 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8139 g_object_unref (info->shape_mask);
8140 g_slice_free (GtkWidgetShapeInfo, info);
8144 * gtk_widget_shape_combine_mask:
8145 * @widget: a #GtkWidget
8146 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8147 * @offset_x: X position of shape mask with respect to @window
8148 * @offset_y: Y position of shape mask with respect to @window
8150 * Sets a shape for this widget's GDK window. This allows for
8151 * transparent windows etc., see gdk_window_shape_combine_mask()
8152 * for more information.
8155 gtk_widget_shape_combine_mask (GtkWidget *widget,
8156 GdkBitmap *shape_mask,
8160 GtkWidgetShapeInfo* shape_info;
8162 g_return_if_fail (GTK_IS_WIDGET (widget));
8163 /* set_shape doesn't work on widgets without gdk window */
8164 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8168 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8171 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8173 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8177 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8179 shape_info = g_slice_new (GtkWidgetShapeInfo);
8180 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8181 (GDestroyNotify) gtk_widget_shape_info_destroy);
8183 shape_info->shape_mask = g_object_ref (shape_mask);
8184 shape_info->offset_x = offset_x;
8185 shape_info->offset_y = offset_y;
8187 /* set shape if widget has a gdk window already.
8188 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8191 gdk_window_shape_combine_mask (widget->window, shape_mask,
8192 offset_x, offset_y);
8197 * gtk_widget_input_shape_combine_mask:
8198 * @widget: a #GtkWidget
8199 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8200 * @offset_x: X position of shape mask with respect to @window
8201 * @offset_y: Y position of shape mask with respect to @window
8203 * Sets an input shape for this widget's GDK window. This allows for
8204 * windows which react to mouse click in a nonrectangular region, see
8205 * gdk_window_input_shape_combine_mask() for more information.
8210 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8211 GdkBitmap *shape_mask,
8215 GtkWidgetShapeInfo* shape_info;
8217 g_return_if_fail (GTK_IS_WIDGET (widget));
8218 /* set_shape doesn't work on widgets without gdk window */
8219 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8224 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8226 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8230 shape_info = g_slice_new (GtkWidgetShapeInfo);
8231 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8233 (GDestroyNotify) gtk_widget_shape_info_destroy);
8235 shape_info->shape_mask = g_object_ref (shape_mask);
8236 shape_info->offset_x = offset_x;
8237 shape_info->offset_y = offset_y;
8239 /* set shape if widget has a gdk window already.
8240 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8243 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8244 offset_x, offset_y);
8250 gtk_reset_shapes_recurse (GtkWidget *widget,
8256 gdk_window_get_user_data (window, &data);
8260 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8261 for (list = gdk_window_peek_children (window); list; list = list->next)
8262 gtk_reset_shapes_recurse (widget, list->data);
8266 * gtk_widget_reset_shapes:
8267 * @widget: a #GtkWidget
8269 * Recursively resets the shape on this widget and its descendants.
8272 gtk_widget_reset_shapes (GtkWidget *widget)
8274 g_return_if_fail (GTK_IS_WIDGET (widget));
8275 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8277 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8278 gtk_reset_shapes_recurse (widget, widget->window);
8283 * @widget: a #GtkWidget
8285 * Adds a reference to a widget. This function is exactly the same
8286 * as calling g_object_ref(), and exists mostly for historical
8287 * reasons. It can still be convenient to avoid casting a widget
8288 * to a #GObject, it saves a small amount of typing.
8290 * Return value: the widget that was referenced
8292 * Deprecated:2.12: Use g_object_ref() instead.
8295 gtk_widget_ref (GtkWidget *widget)
8297 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8299 return (GtkWidget*) g_object_ref ((GObject*) widget);
8304 * @widget: a #GtkWidget
8306 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8308 * Deprecated:2.12: Use g_object_unref() instead.
8311 gtk_widget_unref (GtkWidget *widget)
8313 g_return_if_fail (GTK_IS_WIDGET (widget));
8315 g_object_unref ((GObject*) widget);
8319 * gtk_widget_get_snapshot:
8320 * @widget: a #GtkWidget
8321 * @clip_rect: a #GdkRectangle or %NULL
8323 * Create a #GdkPixmap of the contents of the widget and its children.
8325 * Works even if the widget is obscured. The depth and visual of the
8326 * resulting pixmap is dependent on the widget being snapshot and likely
8327 * differs from those of a target widget displaying the pixmap.
8328 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8329 * the pixmap to a visual independant representation.
8331 * The snapshot area used by this function is the @widget's allocation plus
8332 * any extra space occupied by additional windows belonging to this widget
8333 * (such as the arrows of a spin button).
8334 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8336 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8337 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8338 * interpreted widget relative. If width or height of @clip_rect are 0 or
8339 * negative, the width or height of the resulting pixmap will be shrunken
8340 * by the respective amount.
8341 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8342 * chop off 5 pixels at each side of the snapshot pixmap.
8343 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8344 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8345 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8346 * as a pure output parameter.
8348 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8350 * Return value: #GdkPixmap snapshot of the widget
8355 gtk_widget_get_snapshot (GtkWidget *widget,
8356 GdkRectangle *clip_rect)
8358 int x, y, width, height;
8359 GdkWindow *parent_window = NULL;
8361 GList *windows = NULL, *list;
8363 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8364 if (!GTK_WIDGET_VISIBLE (widget))
8367 /* the widget (and parent_window) must be realized to be drawable */
8368 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8369 gtk_widget_realize (widget->parent);
8370 if (!GTK_WIDGET_REALIZED (widget))
8371 gtk_widget_realize (widget);
8373 /* determine snapshot rectangle */
8374 x = widget->allocation.x;
8375 y = widget->allocation.y;
8376 width = widget->allocation.width;
8377 height = widget->allocation.height;
8379 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8381 /* grow snapshot rectangle to cover all widget windows */
8382 parent_window = gtk_widget_get_parent_window (widget);
8383 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8385 GdkWindow *subwin = list->data;
8388 gdk_window_get_user_data (subwin, &windata);
8389 if (windata != widget)
8391 windows = g_list_prepend (windows, subwin);
8392 gdk_window_get_position (subwin, &wx, &wy);
8393 gdk_drawable_get_size (subwin, &ww, &wh);
8394 /* grow snapshot rectangle by extra widget sub window */
8405 if (x + width < wx + ww)
8406 width += wx + ww - (x + width);
8407 if (y + height < wy + wh)
8408 height += wy + wh - (y + height);
8411 else if (!widget->parent)
8412 x = y = 0; /* toplevel */
8414 /* at this point, (x,y,width,height) is the parent_window relative
8415 * snapshot area covering all of widget's windows.
8418 /* shrink snapshot size by clip_rectangle */
8421 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8422 clip.x = clip.x < 0 ? x : clip.x;
8423 clip.y = clip.y < 0 ? y : clip.y;
8424 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8425 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8428 /* offset clip_rect, so it's parent_window relative */
8429 if (clip_rect->x >= 0)
8430 clip.x += widget->allocation.x;
8431 if (clip_rect->y >= 0)
8432 clip.y += widget->allocation.y;
8434 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8436 g_list_free (windows);
8437 clip_rect->width = clip_rect->height = 0;
8438 return NULL; /* empty snapshot area */
8443 height = snap.height;
8446 /* render snapshot */
8447 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8448 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8450 GdkWindow *subwin = list->data;
8452 gdk_window_get_position (subwin, &wx, &wy);
8453 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8454 MAX (0, wx - x), MAX (0, wy - y), width, height);
8455 gdk_window_invalidate_rect (subwin, NULL, TRUE);
8457 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8459 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8460 gdk_window_invalidate_rect (widget->window, NULL, TRUE);
8462 gtk_widget_queue_draw (widget);
8464 gdk_window_process_updates (parent_window, TRUE);
8465 for (list = windows; list; list = list->next)
8466 gdk_window_process_updates (list->data, TRUE);
8467 gdk_window_process_updates (widget->window, TRUE);
8468 for (list = windows; list; list = list->next)
8469 gdk_window_remove_redirection (list->data);
8470 if (!windows) /* NO_WINDOW || toplevel */
8471 gdk_window_remove_redirection (widget->window);
8472 g_list_free (windows);
8474 /* return pixmap and snapshot rectangle coordinates */
8479 clip_rect->width = width;
8480 clip_rect->height = height;
8483 /* offset clip_rect from parent_window so it's widget relative */
8484 clip_rect->x -= widget->allocation.x;
8485 clip_rect->y -= widget->allocation.y;
8488 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8489 G_OBJECT_TYPE_NAME (widget),
8490 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8499 * gtk_widget_class_install_style_property_parser:
8500 * @klass: a #GtkWidgetClass
8501 * @pspec: the #GParamSpec for the style property
8502 * @parser: the parser for the style property
8504 * Installs a style property on a widget class.
8507 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8509 GtkRcPropertyParser parser)
8511 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8512 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8513 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8514 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8516 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8518 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8519 G_OBJECT_CLASS_NAME (klass),
8524 g_param_spec_ref_sink (pspec);
8525 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8526 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8530 * gtk_widget_class_install_style_property:
8531 * @klass: a #GtkWidgetClass
8532 * @pspec: the #GParamSpec for the property
8534 * Installs a style property on a widget class. The parser for the
8535 * style property is determined by the value type of @pspec.
8538 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8541 GtkRcPropertyParser parser;
8543 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8544 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8546 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8548 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8552 * gtk_widget_class_find_style_property:
8553 * @klass: a #GtkWidgetClass
8554 * @property_name: the name of the style property to find
8555 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8556 * style property with that name.
8558 * Finds a style property of a widget class by name.
8563 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8564 const gchar *property_name)
8566 g_return_val_if_fail (property_name != NULL, NULL);
8568 return g_param_spec_pool_lookup (style_property_spec_pool,
8570 G_OBJECT_CLASS_TYPE (klass),
8575 * gtk_widget_class_list_style_properties:
8576 * @klass: a #GtkWidgetClass
8577 * @n_properties: location to return the number of style properties found
8578 * @returns: an newly allocated array of #GParamSpec*. The array must
8579 * be freed with g_free().
8581 * Returns all style properties of a widget class.
8586 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
8587 guint *n_properties)
8589 GParamSpec **pspecs;
8592 pspecs = g_param_spec_pool_list (style_property_spec_pool,
8593 G_OBJECT_CLASS_TYPE (klass),
8602 * gtk_widget_style_get_property:
8603 * @widget: a #GtkWidget
8604 * @property_name: the name of a style property
8605 * @value: location to return the property value
8607 * Gets the value of a style property of @widget.
8610 gtk_widget_style_get_property (GtkWidget *widget,
8611 const gchar *property_name,
8616 g_return_if_fail (GTK_IS_WIDGET (widget));
8617 g_return_if_fail (property_name != NULL);
8618 g_return_if_fail (G_IS_VALUE (value));
8620 g_object_ref (widget);
8621 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8623 G_OBJECT_TYPE (widget),
8626 g_warning ("%s: widget class `%s' has no property named `%s'",
8628 G_OBJECT_TYPE_NAME (widget),
8632 const GValue *peek_value;
8634 peek_value = _gtk_style_peek_property_value (widget->style,
8635 G_OBJECT_TYPE (widget),
8637 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8639 /* auto-conversion of the caller's value type
8641 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
8642 g_value_copy (peek_value, value);
8643 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
8644 g_value_transform (peek_value, value);
8646 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
8648 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
8649 G_VALUE_TYPE_NAME (value));
8651 g_object_unref (widget);
8655 * gtk_widget_style_get_valist:
8656 * @widget: a #GtkWidget
8657 * @first_property_name: the name of the first property to get
8658 * @var_args: a <type>va_list</type> of pairs of property names and
8659 * locations to return the property values, starting with the location
8660 * for @first_property_name.
8662 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
8666 gtk_widget_style_get_valist (GtkWidget *widget,
8667 const gchar *first_property_name,
8672 g_return_if_fail (GTK_IS_WIDGET (widget));
8674 g_object_ref (widget);
8676 name = first_property_name;
8679 const GValue *peek_value;
8683 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8685 G_OBJECT_TYPE (widget),
8689 g_warning ("%s: widget class `%s' has no property named `%s'",
8691 G_OBJECT_TYPE_NAME (widget),
8695 /* style pspecs are always readable so we can spare that check here */
8697 peek_value = _gtk_style_peek_property_value (widget->style,
8698 G_OBJECT_TYPE (widget),
8700 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8701 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
8704 g_warning ("%s: %s", G_STRLOC, error);
8709 name = va_arg (var_args, gchar*);
8712 g_object_unref (widget);
8716 * gtk_widget_style_get:
8717 * @widget: a #GtkWidget
8718 * @first_property_name: the name of the first property to get
8719 * @Varargs: pairs of property names and locations to
8720 * return the property values, starting with the location for
8721 * @first_property_name, terminated by %NULL.
8723 * Gets the values of a multiple style properties of @widget.
8726 gtk_widget_style_get (GtkWidget *widget,
8727 const gchar *first_property_name,
8732 g_return_if_fail (GTK_IS_WIDGET (widget));
8734 va_start (var_args, first_property_name);
8735 gtk_widget_style_get_valist (widget, first_property_name, var_args);
8741 * @widget: a #GtkWidget
8742 * @path_length: location to store length of the path, or %NULL
8743 * @path: location to store allocated path string, or %NULL
8744 * @path_reversed: location to store allocated reverse path string, or %NULL
8746 * Obtains the full path to @widget. The path is simply the name of a
8747 * widget and all its parents in the container hierarchy, separated by
8748 * periods. The name of a widget comes from
8749 * gtk_widget_get_name(). Paths are used to apply styles to a widget
8750 * in gtkrc configuration files. Widget names are the type of the
8751 * widget by default (e.g. "GtkButton") or can be set to an
8752 * application-specific value with gtk_widget_set_name(). By setting
8753 * the name of a widget, you allow users or theme authors to apply
8754 * styles to that specific widget in their gtkrc
8755 * file. @path_reversed_p fills in the path in reverse order,
8756 * i.e. starting with @widget's name instead of starting with the name
8757 * of @widget's outermost ancestor.
8760 gtk_widget_path (GtkWidget *widget,
8763 gchar **path_reversed)
8765 static gchar *rev_path = NULL;
8766 static guint tmp_path_len = 0;
8769 g_return_if_fail (GTK_IS_WIDGET (widget));
8774 const gchar *string;
8779 string = gtk_widget_get_name (widget);
8780 l = strlen (string);
8781 while (tmp_path_len <= len + l + 1)
8783 tmp_path_len += INIT_PATH_SIZE;
8784 rev_path = g_realloc (rev_path, tmp_path_len);
8792 widget = widget->parent;
8795 rev_path[len++] = '.';
8797 rev_path[len++] = 0;
8802 *path_length = len - 1;
8804 *path_reversed = g_strdup (rev_path);
8807 *path = g_strdup (rev_path);
8808 g_strreverse (*path);
8813 * gtk_widget_class_path:
8814 * @widget: a #GtkWidget
8815 * @path_length: location to store the length of the class path, or %NULL
8816 * @path: location to store the class path as an allocated string, or %NULL
8817 * @path_reversed: location to store the reverse class path as an allocated
8820 * Same as gtk_widget_path(), but always uses the name of a widget's type,
8821 * never uses a custom name set with gtk_widget_set_name().
8825 gtk_widget_class_path (GtkWidget *widget,
8828 gchar **path_reversed)
8830 static gchar *rev_path = NULL;
8831 static guint tmp_path_len = 0;
8834 g_return_if_fail (GTK_IS_WIDGET (widget));
8839 const gchar *string;
8844 string = g_type_name (GTK_WIDGET_TYPE (widget));
8845 l = strlen (string);
8846 while (tmp_path_len <= len + l + 1)
8848 tmp_path_len += INIT_PATH_SIZE;
8849 rev_path = g_realloc (rev_path, tmp_path_len);
8857 widget = widget->parent;
8860 rev_path[len++] = '.';
8862 rev_path[len++] = 0;
8867 *path_length = len - 1;
8869 *path_reversed = g_strdup (rev_path);
8872 *path = g_strdup (rev_path);
8873 g_strreverse (*path);
8878 * gtk_requisition_copy:
8879 * @requisition: a #GtkRequisition
8881 * Copies a #GtkRequisition.
8883 * Returns: a copy of @requisition
8886 gtk_requisition_copy (const GtkRequisition *requisition)
8888 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
8892 * gtk_requisition_free:
8893 * @requisition: a #GtkRequisition
8895 * Frees a #GtkRequisition.
8898 gtk_requisition_free (GtkRequisition *requisition)
8900 g_free (requisition);
8904 gtk_requisition_get_type (void)
8906 static GType our_type = 0;
8909 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
8910 (GBoxedCopyFunc) gtk_requisition_copy,
8911 (GBoxedFreeFunc) gtk_requisition_free);
8917 * gtk_widget_get_accessible:
8918 * @widget: a #GtkWidget
8920 * Returns the accessible object that describes the widget to an
8921 * assistive technology.
8923 * If no accessibility library is loaded (i.e. no ATK implementation library is
8924 * loaded via <envar>GTK_MODULES</envar> or via another application library,
8925 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
8926 * if no class-specific #AtkObject implementation is available for the widget
8927 * instance in question, it will inherit an #AtkObject implementation from the
8928 * first ancestor class for which such an implementation is defined.
8930 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
8931 * library contains more information about accessible objects and their uses.
8933 * Returns: the #AtkObject associated with @widget
8936 gtk_widget_get_accessible (GtkWidget *widget)
8938 GtkWidgetClass *klass;
8940 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8942 klass = GTK_WIDGET_GET_CLASS (widget);
8944 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
8946 return klass->get_accessible (widget);
8950 gtk_widget_real_get_accessible (GtkWidget *widget)
8952 AtkObject* accessible;
8954 accessible = g_object_get_qdata (G_OBJECT (widget),
8955 quark_accessible_object);
8958 AtkObjectFactory *factory;
8959 AtkRegistry *default_registry;
8961 default_registry = atk_get_default_registry ();
8962 factory = atk_registry_get_factory (default_registry,
8963 G_TYPE_FROM_INSTANCE (widget));
8965 atk_object_factory_create_accessible (factory,
8967 g_object_set_qdata (G_OBJECT (widget),
8968 quark_accessible_object,
8975 * Initialize a AtkImplementorIface instance's virtual pointers as
8976 * appropriate to this implementor's class (GtkWidget).
8979 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
8981 iface->ref_accessible = gtk_widget_ref_accessible;
8985 gtk_widget_ref_accessible (AtkImplementor *implementor)
8987 AtkObject *accessible;
8989 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
8991 g_object_ref (accessible);
8996 * GtkBuildable implementation
8998 static GQuark quark_builder_has_default = 0;
8999 static GQuark quark_builder_has_focus = 0;
9000 static GQuark quark_builder_atk_relations = 0;
9003 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9005 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9006 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9007 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9009 iface->set_name = gtk_widget_buildable_set_name;
9010 iface->get_name = gtk_widget_buildable_get_name;
9011 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9012 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9013 iface->parser_finished = gtk_widget_buildable_parser_finished;
9014 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9015 iface->custom_finished = gtk_widget_buildable_custom_finished;
9019 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9022 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9025 static const gchar *
9026 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9028 return gtk_widget_get_name (GTK_WIDGET (buildable));
9032 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9033 GtkBuilder *builder,
9034 const gchar *childname)
9036 if (strcmp (childname, "accessible") == 0)
9037 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9043 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9044 GtkBuilder *builder,
9046 const GValue *value)
9048 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9049 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9050 GINT_TO_POINTER (TRUE));
9051 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9052 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9053 GINT_TO_POINTER (TRUE));
9055 g_object_set_property (G_OBJECT (buildable), name, value);
9069 free_action (AtkActionData *data, gpointer user_data)
9071 g_free (data->action_name);
9072 g_free (data->description);
9073 g_slice_free (AtkActionData, data);
9077 free_relation (AtkRelationData *data, gpointer user_data)
9079 g_free (data->target);
9080 g_free (data->type);
9081 g_slice_free (AtkRelationData, data);
9085 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9086 GtkBuilder *builder)
9088 GSList *atk_relations;
9090 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9091 gtk_widget_grab_default (GTK_WIDGET (buildable));
9092 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9093 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9095 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9096 quark_builder_atk_relations);
9099 AtkObject *accessible;
9100 AtkRelationSet *relation_set;
9103 AtkRelationType relation_type;
9104 AtkObject *target_accessible;
9106 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9107 relation_set = atk_object_ref_relation_set (accessible);
9109 for (l = atk_relations; l; l = l->next)
9111 AtkRelationData *relation = (AtkRelationData*)l->data;
9113 target = gtk_builder_get_object (builder, relation->target);
9116 g_warning ("Target object %s in <relation> does not exist",
9120 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9121 g_assert (target_accessible != NULL);
9123 relation_type = atk_relation_type_for_name (relation->type);
9124 if (relation_type == ATK_RELATION_NULL)
9126 g_warning ("<relation> type %s not found",
9130 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9133 g_object_unref (relation_set);
9135 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9136 g_slist_free (atk_relations);
9137 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9146 } AccessibilitySubParserData;
9149 accessibility_start_element (GMarkupParseContext *context,
9150 const gchar *element_name,
9151 const gchar **names,
9152 const gchar **values,
9156 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9158 gint line_number, char_number;
9160 if (strcmp (element_name, "relation") == 0)
9162 gchar *target = NULL;
9164 AtkRelationData *relation;
9166 for (i = 0; names[i]; i++)
9168 if (strcmp (names[i], "target") == 0)
9169 target = g_strdup (values[i]);
9170 else if (strcmp (names[i], "type") == 0)
9171 type = g_strdup (values[i]);
9174 g_markup_parse_context_get_position (context,
9179 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9180 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9182 line_number, char_number, names[i], "relation");
9189 if (!target || !type)
9191 g_markup_parse_context_get_position (context,
9196 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9197 "%s:%d:%d <%s> requires attribute \"%s\"",
9199 line_number, char_number, "relation",
9200 type ? "target" : "type");
9206 relation = g_slice_new (AtkRelationData);
9207 relation->target = target;
9208 relation->type = type;
9210 data->relations = g_slist_prepend (data->relations, relation);
9212 else if (strcmp (element_name, "action") == 0)
9214 gchar *action_name = NULL;
9215 gchar *description = NULL;
9216 AtkActionData *action;
9218 for (i = 0; names[i]; i++)
9220 if (strcmp (names[i], "action_name") == 0)
9221 action_name = g_strdup (values[i]);
9222 else if (strcmp (names[i], "description") == 0)
9223 description = g_strdup (values[i]);
9226 g_markup_parse_context_get_position (context,
9231 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9232 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9234 line_number, char_number, names[i], "action");
9235 g_free (action_name);
9236 g_free (description);
9241 if (!action_name || !description)
9243 g_markup_parse_context_get_position (context,
9248 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9249 "%s:%d:%d <%s> requires attribute \"%s\"",
9251 line_number, char_number, "action",
9252 description ? "action_name" : "description");
9253 g_free (action_name);
9254 g_free (description);
9258 action = g_slice_new (AtkActionData);
9259 action->action_name = action_name;
9260 action->description = description;
9262 data->actions = g_slist_prepend (data->actions, action);
9264 else if (strcmp (element_name, "accessibility") == 0)
9267 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9270 static const GMarkupParser accessibility_parser =
9272 accessibility_start_element,
9280 } AccelGroupParserData;
9283 accel_group_start_element (GMarkupParseContext *context,
9284 const gchar *element_name,
9285 const gchar **names,
9286 const gchar **values,
9292 guint modifiers = 0;
9293 gchar *signal = NULL;
9294 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9296 for (i = 0; names[i]; i++)
9298 if (strcmp (names[i], "key") == 0)
9299 key = gdk_keyval_from_name (values[i]);
9300 else if (strcmp (names[i], "modifiers") == 0)
9302 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9308 else if (strcmp (names[i], "signal") == 0)
9309 signal = g_strdup (values[i]);
9312 if (key == 0 || signal == NULL)
9314 g_warning ("<accelerator> requires key and signal attributes");
9317 parser_data->key = key;
9318 parser_data->modifiers = modifiers;
9319 parser_data->signal = signal;
9322 static const GMarkupParser accel_group_parser =
9324 accel_group_start_element,
9328 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9329 GtkBuilder *builder,
9331 const gchar *tagname,
9332 GMarkupParser *parser,
9335 g_assert (buildable);
9337 if (strcmp (tagname, "accelerator") == 0)
9339 AccelGroupParserData *parser_data;
9341 parser_data = g_slice_new0 (AccelGroupParserData);
9342 parser_data->object = g_object_ref (buildable);
9343 *parser = accel_group_parser;
9344 *data = parser_data;
9347 if (strcmp (tagname, "accessibility") == 0)
9349 AccessibilitySubParserData *parser_data;
9351 parser_data = g_slice_new0 (AccessibilitySubParserData);
9352 *parser = accessibility_parser;
9353 *data = parser_data;
9360 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9361 GtkBuilder *builder,
9363 const gchar *tagname,
9366 AccelGroupParserData *accel_data;
9367 AccessibilitySubParserData *a11y_data;
9368 GtkWidget *toplevel;
9369 GSList *accel_groups;
9370 GtkAccelGroup *accel_group;
9372 if (strcmp (tagname, "accelerator") == 0)
9374 accel_data = (AccelGroupParserData*)user_data;
9375 g_assert (accel_data->object);
9377 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9378 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9379 if (g_slist_length (accel_groups) == 0)
9381 accel_group = gtk_accel_group_new ();
9382 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9386 g_assert (g_slist_length (accel_groups) == 1);
9387 accel_group = g_slist_nth_data (accel_groups, 0);
9389 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9393 accel_data->modifiers,
9395 g_object_unref (accel_data->object);
9396 g_free (accel_data->signal);
9397 g_slice_free (AccelGroupParserData, accel_data);
9399 else if (strcmp (tagname, "accessibility") == 0)
9401 a11y_data = (AccessibilitySubParserData*)user_data;
9403 if (a11y_data->actions)
9405 AtkObject *accessible;
9410 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9412 action = ATK_ACTION (accessible);
9413 n_actions = atk_action_get_n_actions (action);
9415 for (l = a11y_data->actions; l; l = l->next)
9417 AtkActionData *action_data = (AtkActionData*)l->data;
9419 for (i = 0; i < n_actions; i++)
9420 if (strcmp (atk_action_get_name (action, i),
9421 action_data->action_name) == 0)
9425 atk_action_set_description (action, i,
9426 action_data->description);
9429 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9430 g_slist_free (a11y_data->actions);
9433 if (a11y_data->relations)
9434 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9435 a11y_data->relations);
9437 g_slice_free (AccessibilitySubParserData, a11y_data);
9444 * gtk_widget_get_clipboard:
9445 * @widget: a #GtkWidget
9446 * @selection: a #GdkAtom which identifies the clipboard
9447 * to use. %GDK_SELECTION_CLIPBOARD gives the
9448 * default clipboard. Another common value
9449 * is %GDK_SELECTION_PRIMARY, which gives
9450 * the primary X selection.
9452 * Returns the clipboard object for the given selection to
9453 * be used with @widget. @widget must have a #GdkDisplay
9454 * associated with it, so must be attached to a toplevel
9457 * Return value: the appropriate clipboard object. If no
9458 * clipboard already exists, a new one will
9459 * be created. Once a clipboard object has
9460 * been created, it is persistent for all time.
9465 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9467 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9468 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9470 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9475 * gtk_widget_list_mnemonic_labels:
9476 * @widget: a #GtkWidget
9478 * Returns a newly allocated list of the widgets, normally labels, for
9479 * which this widget is a the target of a mnemonic (see for example,
9480 * gtk_label_set_mnemonic_widget()).
9482 * The widgets in the list are not individually referenced. If you
9483 * want to iterate through the list and perform actions involving
9484 * callbacks that might destroy the widgets, you
9485 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9486 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9487 * widgets afterwards.
9489 * Return value: the list of mnemonic labels; free this list
9490 * with g_list_free() when you are done with it.
9495 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9500 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9502 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9503 list = g_list_prepend (list, l->data);
9509 * gtk_widget_add_mnemonic_label:
9510 * @widget: a #GtkWidget
9511 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9513 * Adds a widget to the list of mnemonic labels for
9514 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9515 * list of mnemonic labels for the widget is cleared when the
9516 * widget is destroyed, so the caller must make sure to update
9517 * its internal state at this point as well, by using a connection
9518 * to the #GtkWidget::destroy signal or a weak notifier.
9523 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9526 GSList *old_list, *new_list;
9528 g_return_if_fail (GTK_IS_WIDGET (widget));
9529 g_return_if_fail (GTK_IS_WIDGET (label));
9531 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9532 new_list = g_slist_prepend (old_list, label);
9534 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9535 new_list, (GDestroyNotify) g_slist_free);
9539 * gtk_widget_remove_mnemonic_label:
9540 * @widget: a #GtkWidget
9541 * @label: a #GtkWidget that was previously set as a mnemnic label for
9542 * @widget with gtk_widget_add_mnemonic_label().
9544 * Removes a widget from the list of mnemonic labels for
9545 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
9546 * must have previously been added to the list with
9547 * gtk_widget_add_mnemonic_label().
9552 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
9555 GSList *old_list, *new_list;
9557 g_return_if_fail (GTK_IS_WIDGET (widget));
9558 g_return_if_fail (GTK_IS_WIDGET (label));
9560 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9561 new_list = g_slist_remove (old_list, label);
9564 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9565 new_list, (GDestroyNotify) g_slist_free);
9569 * gtk_widget_get_no_show_all:
9570 * @widget: a #GtkWidget
9572 * Returns the current value of the GtkWidget:no-show-all property,
9573 * which determines whether calls to gtk_widget_show_all() and
9574 * gtk_widget_hide_all() will affect this widget.
9576 * Return value: the current value of the "no-show-all" property.
9581 gtk_widget_get_no_show_all (GtkWidget *widget)
9583 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9585 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
9589 * gtk_widget_set_no_show_all:
9590 * @widget: a #GtkWidget
9591 * @no_show_all: the new value for the "no-show-all" property
9593 * Sets the #GtkWidget:no-show-all property, which determines whether
9594 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
9597 * This is mostly for use in constructing widget hierarchies with externally
9598 * controlled visibility, see #GtkUIManager.
9603 gtk_widget_set_no_show_all (GtkWidget *widget,
9604 gboolean no_show_all)
9606 g_return_if_fail (GTK_IS_WIDGET (widget));
9608 no_show_all = (no_show_all != FALSE);
9610 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
9614 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
9616 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
9618 g_object_notify (G_OBJECT (widget), "no-show-all");
9623 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
9624 gboolean has_tooltip,
9627 gboolean priv_has_tooltip;
9629 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
9630 quark_has_tooltip));
9632 if (priv_has_tooltip != has_tooltip || force)
9634 priv_has_tooltip = has_tooltip;
9636 if (priv_has_tooltip)
9638 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
9639 gdk_window_set_events (widget->window,
9640 gdk_window_get_events (widget->window) |
9641 GDK_LEAVE_NOTIFY_MASK |
9642 GDK_POINTER_MOTION_MASK |
9643 GDK_POINTER_MOTION_HINT_MASK);
9645 if (!GTK_WIDGET_NO_WINDOW (widget))
9646 gtk_widget_add_events (widget,
9647 GDK_LEAVE_NOTIFY_MASK |
9648 GDK_POINTER_MOTION_MASK |
9649 GDK_POINTER_MOTION_HINT_MASK);
9652 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
9653 GUINT_TO_POINTER (priv_has_tooltip));
9658 * gtk_widget_set_tooltip_window:
9659 * @widget: a #GtkWidget
9660 * @custom_window: a #GtkWindow, or %NULL
9662 * Replaces the default, usually yellow, window used for displaying
9663 * tooltips with @custom_window. GTK+ will take care of showing and
9664 * hiding @custom_window at the right moment, to behave likewise as
9665 * the default tooltip window. If @custom_window is %NULL, the default
9666 * tooltip window will be used.
9671 gtk_widget_set_tooltip_window (GtkWidget *widget,
9672 GtkWindow *custom_window)
9675 gchar *tooltip_markup;
9676 GtkWindow *tooltip_window;
9678 g_return_if_fail (GTK_IS_WIDGET (widget));
9680 g_return_if_fail (GTK_IS_WINDOW (custom_window));
9682 tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9683 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
9686 g_object_ref (custom_window);
9688 tooltip_window = custom_window;
9689 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
9690 tooltip_window, g_object_unref);
9692 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
9693 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
9696 gtk_widget_trigger_tooltip_query (widget);
9700 * gtk_widget_get_tooltip_window:
9701 * @widget: a #GtkWidget
9703 * Returns the #GtkWindow of the current tooltip. This can be the
9704 * GtkWindow created by default, or the custom tooltip window set
9705 * using gtk_widget_set_tooltip_window().
9707 * Return value: The #GtkWindow of the current tooltip.
9712 gtk_widget_get_tooltip_window (GtkWidget *widget)
9714 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9716 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9720 * gtk_widget_trigger_tooltip_query:
9721 * @widget: a #GtkWidget
9723 * Triggers a tooltip query on the display where the toplevel of @widget
9724 * is located. See gtk_tooltip_trigger_tooltip_query() for more
9730 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
9732 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
9736 * gtk_widget_set_tooltip_text:
9737 * @widget: a #GtkWidget
9738 * @text: the contents of the tooltip for @widget
9740 * Sets @text as the contents of the tooltip. This function will take
9741 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
9742 * handler for the GtkWidget::query-tooltip signal.
9744 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
9749 gtk_widget_set_tooltip_text (GtkWidget *widget,
9752 g_return_if_fail (GTK_IS_WIDGET (widget));
9754 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
9758 * gtk_widget_get_tooltip_text:
9759 * @widget: a #GtkWidget
9761 * Gets the contents of the tooltip for @widget.
9763 * Return value: the tooltip text, or %NULL. You should free the
9764 * returned string with g_free() when done.
9769 gtk_widget_get_tooltip_text (GtkWidget *widget)
9773 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9775 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
9781 * gtk_widget_set_tooltip_markup:
9782 * @widget: a #GtkWidget
9783 * @markup: the contents of the tooltip for @widget, or %NULL
9785 * Sets @markup as the contents of the tooltip, which is marked up with
9786 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
9788 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
9789 * and of the default handler for the GtkWidget::query-tooltip signal.
9791 * See also the GtkWidget:tooltip-markup property and
9792 * gtk_tooltip_set_markup().
9797 gtk_widget_set_tooltip_markup (GtkWidget *widget,
9798 const gchar *markup)
9800 g_return_if_fail (GTK_IS_WIDGET (widget));
9802 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
9806 * gtk_widget_get_tooltip_markup:
9807 * @widget: a #GtkWidget
9809 * Gets the contents of the tooltip for @widget.
9811 * Return value: the tooltip text, or %NULL. You should free the
9812 * returned string with g_free() when done.
9817 gtk_widget_get_tooltip_markup (GtkWidget *widget)
9821 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9823 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
9829 * gtk_widget_set_has_tooltip:
9830 * @widget: a #GtkWidget
9831 * @has_tooltip: whether or not @widget has a tooltip.
9833 * Sets the has-tooltip property on @widget to @has_tooltip. See
9834 * GtkWidget:has-tooltip for more information.
9839 gtk_widget_set_has_tooltip (GtkWidget *widget,
9840 gboolean has_tooltip)
9842 g_return_if_fail (GTK_IS_WIDGET (widget));
9844 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
9848 * gtk_widget_get_has_tooltip:
9849 * @widget: a #GtkWidget
9851 * Returns the current value of the has-tooltip property. See
9852 * GtkWidget:has-tooltip for more information.
9854 * Return value: current value of has-tooltip on @widget.
9859 gtk_widget_get_has_tooltip (GtkWidget *widget)
9861 gboolean has_tooltip = FALSE;
9863 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9865 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
9870 #define __GTK_WIDGET_C__
9871 #include "gtkaliasdef.c"