1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
58 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
59 #define INIT_PATH_SIZE (512)
100 PROPERTY_NOTIFY_EVENT,
101 SELECTION_CLEAR_EVENT,
102 SELECTION_REQUEST_EVENT,
103 SELECTION_NOTIFY_EVENT,
118 VISIBILITY_NOTIFY_EVENT,
122 ACCEL_CLOSURES_CHANGED,
148 PROP_RECEIVES_DEFAULT,
149 PROP_COMPOSITE_CHILD,
152 PROP_EXTENSION_EVENTS,
160 typedef struct _GtkStateData GtkStateData;
165 guint state_restoration : 1;
166 guint parent_sensitive : 1;
167 guint use_forall : 1;
170 /* --- prototypes --- */
171 static void gtk_widget_class_init (GtkWidgetClass *klass);
172 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
173 static void gtk_widget_init (GtkWidget *widget);
174 static void gtk_widget_set_property (GObject *object,
178 static void gtk_widget_get_property (GObject *object,
182 static void gtk_widget_dispose (GObject *object);
183 static void gtk_widget_real_destroy (GtkObject *object);
184 static void gtk_widget_finalize (GObject *object);
185 static void gtk_widget_real_show (GtkWidget *widget);
186 static void gtk_widget_real_hide (GtkWidget *widget);
187 static void gtk_widget_real_map (GtkWidget *widget);
188 static void gtk_widget_real_unmap (GtkWidget *widget);
189 static void gtk_widget_real_realize (GtkWidget *widget);
190 static void gtk_widget_real_unrealize (GtkWidget *widget);
191 static void gtk_widget_real_size_request (GtkWidget *widget,
192 GtkRequisition *requisition);
193 static void gtk_widget_real_size_allocate (GtkWidget *widget,
194 GtkAllocation *allocation);
195 static void gtk_widget_style_set (GtkWidget *widget,
196 GtkStyle *previous_style);
197 static void gtk_widget_direction_changed (GtkWidget *widget,
198 GtkTextDirection previous_direction);
200 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
201 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
204 gboolean keyboard_tip,
205 GtkTooltip *tooltip);
206 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
207 GtkWidgetHelpType help_type);
209 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
211 GParamSpec **pspecs);
212 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
214 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
216 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
217 GdkEventFocus *event);
218 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
219 GdkEventFocus *event);
220 static gboolean gtk_widget_real_focus (GtkWidget *widget,
221 GtkDirectionType direction);
222 static void gtk_widget_real_move_focus (GtkWidget *widget,
223 GtkDirectionType direction);
224 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
225 GtkDirectionType direction);
226 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
227 static void gtk_widget_update_pango_context (GtkWidget *widget);
228 static void gtk_widget_propagate_state (GtkWidget *widget,
230 static void gtk_widget_reset_rc_style (GtkWidget *widget);
231 static void gtk_widget_set_style_internal (GtkWidget *widget,
233 gboolean initial_emission);
234 static gint gtk_widget_event_internal (GtkWidget *widget,
236 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
237 gboolean group_cycling);
238 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
239 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
240 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
241 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
242 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
244 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
245 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
246 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
249 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
250 gboolean has_tooltip,
252 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
253 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
255 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
256 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
258 const gchar *childname);
259 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
262 const GValue *value);
263 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
266 const gchar *tagname,
267 GMarkupParser *parser,
269 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
272 const gchar *tagname,
274 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
275 GtkBuilder *builder);
278 static void gtk_widget_set_usize_internal (GtkWidget *widget,
281 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
285 /* --- variables --- */
286 static gpointer gtk_widget_parent_class = NULL;
287 static guint widget_signals[LAST_SIGNAL] = { 0 };
288 static GtkStyle *gtk_default_style = NULL;
289 static GSList *colormap_stack = NULL;
290 static guint composite_child_stack = 0;
291 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
292 static GParamSpecPool *style_property_spec_pool = NULL;
294 static GQuark quark_property_parser = 0;
295 static GQuark quark_aux_info = 0;
296 static GQuark quark_accel_path = 0;
297 static GQuark quark_accel_closures = 0;
298 static GQuark quark_event_mask = 0;
299 static GQuark quark_extension_event_mode = 0;
300 static GQuark quark_parent_window = 0;
301 static GQuark quark_shape_info = 0;
302 static GQuark quark_input_shape_info = 0;
303 static GQuark quark_colormap = 0;
304 static GQuark quark_pango_context = 0;
305 static GQuark quark_rc_style = 0;
306 static GQuark quark_accessible_object = 0;
307 static GQuark quark_mnemonic_labels = 0;
308 static GQuark quark_tooltip_markup = 0;
309 static GQuark quark_has_tooltip = 0;
310 static GQuark quark_tooltip_window = 0;
311 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
312 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
314 /* --- functions --- */
316 gtk_widget_get_type (void)
318 static GType widget_type = 0;
320 if (G_UNLIKELY (widget_type == 0))
322 const GTypeInfo widget_info =
324 sizeof (GtkWidgetClass),
325 NULL, /* base_init */
326 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
327 (GClassInitFunc) gtk_widget_class_init,
328 NULL, /* class_finalize */
329 NULL, /* class_init */
332 (GInstanceInitFunc) gtk_widget_init,
333 NULL, /* value_table */
336 const GInterfaceInfo accessibility_info =
338 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
339 (GInterfaceFinalizeFunc) NULL,
340 NULL /* interface data */
343 const GInterfaceInfo buildable_info =
345 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
346 (GInterfaceFinalizeFunc) NULL,
347 NULL /* interface data */
350 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
351 &widget_info, G_TYPE_FLAG_ABSTRACT);
353 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
354 &accessibility_info) ;
355 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
364 child_property_notify_dispatcher (GObject *object,
368 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
372 gtk_widget_class_init (GtkWidgetClass *klass)
374 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
375 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
376 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
377 GtkBindingSet *binding_set;
379 gtk_widget_parent_class = g_type_class_peek_parent (klass);
381 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
382 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
383 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
384 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
385 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
386 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
387 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
388 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
389 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
390 quark_colormap = g_quark_from_static_string ("gtk-colormap");
391 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
392 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
393 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
394 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
395 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
396 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
397 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
399 style_property_spec_pool = g_param_spec_pool_new (FALSE);
400 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
401 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
402 cpn_context.dispatcher = child_property_notify_dispatcher;
403 _gtk_widget_child_property_notify_context = &cpn_context;
405 gobject_class->dispose = gtk_widget_dispose;
406 gobject_class->finalize = gtk_widget_finalize;
407 gobject_class->set_property = gtk_widget_set_property;
408 gobject_class->get_property = gtk_widget_get_property;
410 object_class->destroy = gtk_widget_real_destroy;
412 klass->activate_signal = 0;
413 klass->set_scroll_adjustments_signal = 0;
414 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
415 klass->show = gtk_widget_real_show;
416 klass->show_all = gtk_widget_show;
417 klass->hide = gtk_widget_real_hide;
418 klass->hide_all = gtk_widget_hide;
419 klass->map = gtk_widget_real_map;
420 klass->unmap = gtk_widget_real_unmap;
421 klass->realize = gtk_widget_real_realize;
422 klass->unrealize = gtk_widget_real_unrealize;
423 klass->size_request = gtk_widget_real_size_request;
424 klass->size_allocate = gtk_widget_real_size_allocate;
425 klass->state_changed = NULL;
426 klass->parent_set = NULL;
427 klass->hierarchy_changed = NULL;
428 klass->style_set = gtk_widget_style_set;
429 klass->direction_changed = gtk_widget_direction_changed;
430 klass->grab_notify = NULL;
431 klass->child_notify = NULL;
432 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
433 klass->grab_focus = gtk_widget_real_grab_focus;
434 klass->focus = gtk_widget_real_focus;
436 klass->button_press_event = NULL;
437 klass->button_release_event = NULL;
438 klass->motion_notify_event = NULL;
439 klass->delete_event = NULL;
440 klass->destroy_event = NULL;
441 klass->expose_event = NULL;
442 klass->key_press_event = gtk_widget_real_key_press_event;
443 klass->key_release_event = gtk_widget_real_key_release_event;
444 klass->enter_notify_event = NULL;
445 klass->leave_notify_event = NULL;
446 klass->configure_event = NULL;
447 klass->focus_in_event = gtk_widget_real_focus_in_event;
448 klass->focus_out_event = gtk_widget_real_focus_out_event;
449 klass->map_event = NULL;
450 klass->unmap_event = NULL;
451 klass->window_state_event = NULL;
452 klass->property_notify_event = _gtk_selection_property_notify;
453 klass->selection_clear_event = gtk_selection_clear;
454 klass->selection_request_event = _gtk_selection_request;
455 klass->selection_notify_event = _gtk_selection_notify;
456 klass->selection_received = NULL;
457 klass->proximity_in_event = NULL;
458 klass->proximity_out_event = NULL;
459 klass->drag_begin = NULL;
460 klass->drag_end = NULL;
461 klass->drag_data_delete = NULL;
462 klass->drag_leave = NULL;
463 klass->drag_motion = NULL;
464 klass->drag_drop = NULL;
465 klass->drag_data_received = NULL;
466 klass->screen_changed = NULL;
467 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
468 klass->grab_broken_event = NULL;
469 klass->query_tooltip = gtk_widget_real_query_tooltip;
471 klass->show_help = gtk_widget_real_show_help;
473 /* Accessibility support */
474 klass->get_accessible = gtk_widget_real_get_accessible;
476 klass->no_expose_event = NULL;
478 g_object_class_install_property (gobject_class,
480 g_param_spec_string ("name",
482 P_("The name of the widget"),
484 GTK_PARAM_READWRITE));
485 g_object_class_install_property (gobject_class,
487 g_param_spec_object ("parent",
489 P_("The parent widget of this widget. Must be a Container widget"),
491 GTK_PARAM_READWRITE));
493 g_object_class_install_property (gobject_class,
495 g_param_spec_int ("width-request",
497 P_("Override for width request of the widget, or -1 if natural request should be used"),
501 GTK_PARAM_READWRITE));
502 g_object_class_install_property (gobject_class,
504 g_param_spec_int ("height-request",
505 P_("Height request"),
506 P_("Override for height request of the widget, or -1 if natural request should be used"),
510 GTK_PARAM_READWRITE));
511 g_object_class_install_property (gobject_class,
513 g_param_spec_boolean ("visible",
515 P_("Whether the widget is visible"),
517 GTK_PARAM_READWRITE));
518 g_object_class_install_property (gobject_class,
520 g_param_spec_boolean ("sensitive",
522 P_("Whether the widget responds to input"),
524 GTK_PARAM_READWRITE));
525 g_object_class_install_property (gobject_class,
527 g_param_spec_boolean ("app-paintable",
528 P_("Application paintable"),
529 P_("Whether the application will paint directly on the widget"),
531 GTK_PARAM_READWRITE));
532 g_object_class_install_property (gobject_class,
534 g_param_spec_boolean ("can-focus",
536 P_("Whether the widget can accept the input focus"),
538 GTK_PARAM_READWRITE));
539 g_object_class_install_property (gobject_class,
541 g_param_spec_boolean ("has-focus",
543 P_("Whether the widget has the input focus"),
545 GTK_PARAM_READWRITE));
546 g_object_class_install_property (gobject_class,
548 g_param_spec_boolean ("is-focus",
550 P_("Whether the widget is the focus widget within the toplevel"),
552 GTK_PARAM_READWRITE));
553 g_object_class_install_property (gobject_class,
555 g_param_spec_boolean ("can-default",
557 P_("Whether the widget can be the default widget"),
559 GTK_PARAM_READWRITE));
560 g_object_class_install_property (gobject_class,
562 g_param_spec_boolean ("has-default",
564 P_("Whether the widget is the default widget"),
566 GTK_PARAM_READWRITE));
567 g_object_class_install_property (gobject_class,
568 PROP_RECEIVES_DEFAULT,
569 g_param_spec_boolean ("receives-default",
570 P_("Receives default"),
571 P_("If TRUE, the widget will receive the default action when it is focused"),
573 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
575 PROP_COMPOSITE_CHILD,
576 g_param_spec_boolean ("composite-child",
577 P_("Composite child"),
578 P_("Whether the widget is part of a composite widget"),
580 GTK_PARAM_READABLE));
581 g_object_class_install_property (gobject_class,
583 g_param_spec_object ("style",
585 P_("The style of the widget, which contains information about how it will look (colors etc)"),
587 GTK_PARAM_READWRITE));
588 g_object_class_install_property (gobject_class,
590 g_param_spec_flags ("events",
592 P_("The event mask that decides what kind of GdkEvents this widget gets"),
595 GTK_PARAM_READWRITE));
596 g_object_class_install_property (gobject_class,
597 PROP_EXTENSION_EVENTS,
598 g_param_spec_enum ("extension-events",
599 P_("Extension events"),
600 P_("The mask that decides what kind of extension events this widget gets"),
601 GDK_TYPE_EXTENSION_MODE,
602 GDK_EXTENSION_EVENTS_NONE,
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_boolean ("no-show-all",
608 P_("Whether gtk_widget_show_all() should not affect this widget"),
610 GTK_PARAM_READWRITE));
613 * GtkWidget:has-tooltip:
615 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
616 * A value of %TRUE indicates that @widget can have a tooltip, in this case
617 * the widget will be queried using #GtkWidget::query-tooltip to determine
618 * whether it will provide a tooltip or not.
620 * Note that setting this property to %TRUE for the first time will change
621 * the event masks of the GdkWindows of this widget to include leave-notify
622 * and motion-notify events. This cannot and will not be undone when the
623 * property is set to %FALSE again.
627 g_object_class_install_property (gobject_class,
629 g_param_spec_boolean ("has-tooltip",
631 P_("Whether this widget has a tooltip"),
633 GTK_PARAM_READWRITE));
635 * GtkWidget:tooltip-text:
637 * Sets the text of tooltip to be the given string.
639 * Also see gtk_tooltip_set_text().
641 * This is a convenience property which will take care of getting the
642 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
643 * will automatically be set to %TRUE and there will be taken care of
644 * #GtkWidget::query-tooltip in the default signal handler.
648 g_object_class_install_property (gobject_class,
650 g_param_spec_string ("tooltip-text",
652 P_("The contents of the tooltip for this widget"),
654 GTK_PARAM_READWRITE));
656 * GtkWidget:tooltip-markup:
658 * Sets the text of tooltip to be the given string, which is marked up
659 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
660 * Also see gtk_tooltip_set_markup().
662 * This is a convenience property which will take care of getting the
663 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
664 * will automatically be set to %TRUE and there will be taken care of
665 * #GtkWidget::query-tooltip in the default signal handler.
669 g_object_class_install_property (gobject_class,
671 g_param_spec_string ("tooltip-markup",
672 P_("Tooltip markup"),
673 P_("The contents of the tooltip for this widget"),
675 GTK_PARAM_READWRITE));
680 * The widget's window or its parent window if it does not have a
681 * window (as indicated by the GTK_NO_WINDOW flag).
683 * Since: GSEAL-branch
685 g_object_class_install_property (gobject_class,
687 g_param_spec_object ("window",
689 P_("The widget's window or its parent window"),
691 GTK_PARAM_READABLE));
693 widget_signals[SHOW] =
694 g_signal_new (I_("show"),
695 G_TYPE_FROM_CLASS (gobject_class),
697 G_STRUCT_OFFSET (GtkWidgetClass, show),
699 _gtk_marshal_VOID__VOID,
701 widget_signals[HIDE] =
702 g_signal_new (I_("hide"),
703 G_TYPE_FROM_CLASS (gobject_class),
705 G_STRUCT_OFFSET (GtkWidgetClass, hide),
707 _gtk_marshal_VOID__VOID,
709 widget_signals[MAP] =
710 g_signal_new (I_("map"),
711 G_TYPE_FROM_CLASS (gobject_class),
713 G_STRUCT_OFFSET (GtkWidgetClass, map),
715 _gtk_marshal_VOID__VOID,
717 widget_signals[UNMAP] =
718 g_signal_new (I_("unmap"),
719 G_TYPE_FROM_CLASS (gobject_class),
721 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
723 _gtk_marshal_VOID__VOID,
725 widget_signals[REALIZE] =
726 g_signal_new (I_("realize"),
727 G_TYPE_FROM_CLASS (gobject_class),
729 G_STRUCT_OFFSET (GtkWidgetClass, realize),
731 _gtk_marshal_VOID__VOID,
733 widget_signals[UNREALIZE] =
734 g_signal_new (I_("unrealize"),
735 G_TYPE_FROM_CLASS (gobject_class),
737 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
739 _gtk_marshal_VOID__VOID,
741 widget_signals[SIZE_REQUEST] =
742 g_signal_new (I_("size_request"),
743 G_TYPE_FROM_CLASS (gobject_class),
745 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
747 _gtk_marshal_VOID__BOXED,
749 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
750 widget_signals[SIZE_ALLOCATE] =
751 g_signal_new (I_("size_allocate"),
752 G_TYPE_FROM_CLASS (gobject_class),
754 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
756 _gtk_marshal_VOID__BOXED,
758 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
760 widget_signals[STATE_CHANGED] =
761 g_signal_new (I_("state_changed"),
762 G_TYPE_FROM_CLASS (gobject_class),
764 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
766 _gtk_marshal_VOID__ENUM,
768 GTK_TYPE_STATE_TYPE);
771 * GtkWidget::parent-set:
772 * @widget: the object on which the signal is emitted
773 * @old_parent: the previous parent, or %NULL if the widget
774 * just got its initial parent.
776 * The ::parent-set signal is emitted when a new parent
777 * has been set on a widget.
779 widget_signals[PARENT_SET] =
780 g_signal_new (I_("parent_set"),
781 G_TYPE_FROM_CLASS (gobject_class),
783 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
785 _gtk_marshal_VOID__OBJECT,
790 * GtkWidget::hierarchy-changed:
791 * @widget: the object on which the signal is emitted
792 * @previous_toplevel: the previous toplevel ancestor, or %NULL
793 * if the widget was previously unanchored
795 * The ::hierarchy-changed signal is emitted when the
796 * anchored state of a widget changes. A widget is
797 * <firstterm>anchored</firstterm> when its toplevel
798 * ancestor is a #GtkWindow. This signal is emitted when
799 * a widget changes from un-anchored to anchored or vice-versa.
801 widget_signals[HIERARCHY_CHANGED] =
802 g_signal_new (I_("hierarchy_changed"),
803 G_TYPE_FROM_CLASS (gobject_class),
805 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
807 _gtk_marshal_VOID__OBJECT,
812 * GtkWidget::style-set:
813 * @widget: the object on which the signal is emitted
814 * @previous_style: the previous style, or %NULL if the widget
815 * just got its initial style
817 * The ::style-set signal is emitted when a new style has been set
818 * on a widget. Note that style-modifying functions like
819 * gtk_widget_modify_base() also cause this signal to be emitted.
821 widget_signals[STYLE_SET] =
822 g_signal_new (I_("style_set"),
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
827 _gtk_marshal_VOID__OBJECT,
831 * GtkWidget::direction-changed:
832 * @widget: the object on which the signal is emitted
833 * @previous_direction: the previous text direction of @widget
835 * The ::direction-changed signal is emitted when the text direction
836 * of a widget changes.
838 widget_signals[DIRECTION_CHANGED] =
839 g_signal_new (I_("direction_changed"),
840 G_TYPE_FROM_CLASS (gobject_class),
842 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
844 _gtk_marshal_VOID__ENUM,
846 GTK_TYPE_TEXT_DIRECTION);
849 * GtkWidget::grab-notify:
850 * @widget: the object which received the signal
851 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
852 * if it becomes unshadowed
854 * The ::grab-notify signal is emitted when a widget becomes
855 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
856 * another widget, or when it becomes unshadowed due to a grab
859 * A widget is shadowed by a gtk_grab_add() when the topmost
860 * grab widget in the grab stack of its window group is not
863 widget_signals[GRAB_NOTIFY] =
864 g_signal_new (I_("grab_notify"),
865 G_TYPE_FROM_CLASS (gobject_class),
867 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
869 _gtk_marshal_VOID__BOOLEAN,
874 * GtkWidget::child-notify:
875 * @widget: the object which received the signal
876 * @pspec: the #GParamSpec of the changed child property
878 * The ::child-notify signal is emitted for each
879 * <link linkend="child-properties">child property</link> that has
880 * changed on an object. The signal's detail holds the property name.
882 widget_signals[CHILD_NOTIFY] =
883 g_signal_new (I_("child_notify"),
884 G_TYPE_FROM_CLASS (gobject_class),
885 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
886 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
888 g_cclosure_marshal_VOID__PARAM,
891 widget_signals[MNEMONIC_ACTIVATE] =
892 g_signal_new (I_("mnemonic_activate"),
893 G_TYPE_FROM_CLASS (gobject_class),
895 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
896 _gtk_boolean_handled_accumulator, NULL,
897 _gtk_marshal_BOOLEAN__BOOLEAN,
900 widget_signals[GRAB_FOCUS] =
901 g_signal_new (I_("grab_focus"),
902 G_TYPE_FROM_CLASS (gobject_class),
903 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
904 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
906 _gtk_marshal_VOID__VOID,
908 widget_signals[FOCUS] =
909 g_signal_new (I_("focus"),
910 G_TYPE_FROM_CLASS (object_class),
912 G_STRUCT_OFFSET (GtkWidgetClass, focus),
913 _gtk_boolean_handled_accumulator, NULL,
914 _gtk_marshal_BOOLEAN__ENUM,
916 GTK_TYPE_DIRECTION_TYPE);
917 widget_signals[MOVE_FOCUS] =
918 _gtk_binding_signal_new (I_("move_focus"),
919 G_TYPE_FROM_CLASS (object_class),
920 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
921 G_CALLBACK (gtk_widget_real_move_focus),
923 _gtk_marshal_VOID__ENUM,
926 GTK_TYPE_DIRECTION_TYPE);
929 * @widget: the object which received the signal.
930 * @event: the #GdkEvent which triggered this signal
932 * The GTK+ main loop will emit three signals for each GDK event delivered
933 * to a widget: one generic ::event signal, another, more specific,
934 * signal that matches the type of event delivered (e.g.
935 * #GtkWidget::key-press-event) and finally a generic
936 * #GtkWidget::event-after signal.
938 * Returns: %TRUE to stop other handlers from being invoked for the event
939 * and to cancel the emission of the second specific ::event signal.
940 * %FALSE to propagate the event further and to allow the emission of
941 * the second signal. The ::event-after signal is emitted regardless of
944 widget_signals[EVENT] =
945 g_signal_new (I_("event"),
946 G_TYPE_FROM_CLASS (gobject_class),
948 G_STRUCT_OFFSET (GtkWidgetClass, event),
949 _gtk_boolean_handled_accumulator, NULL,
950 _gtk_marshal_BOOLEAN__BOXED,
952 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
955 * GtkWidget::event-after:
956 * @widget: the object which received the signal.
957 * @event: the #GdkEvent which triggered this signal
959 * After the emission of the #GtkWidget::event signal and (optionally)
960 * the second more specific signal, ::event-after will be emitted
961 * regardless of the previous two signals handlers return values.
964 widget_signals[EVENT_AFTER] =
965 g_signal_new (I_("event_after"),
966 G_TYPE_FROM_CLASS (gobject_class),
970 _gtk_marshal_VOID__BOXED,
972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
975 * GtkWidget::button-press-event:
976 * @widget: the object which received the signal.
977 * @event: the #GdkEventButton which triggered this signal
979 * The ::button-press-event signal will be emitted when a button
980 * (typically from a mouse) is pressed.
982 * To receive this signal, the #GdkWindow associated to the
983 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
985 * This signal will be sent to the grab widget if there is one.
987 * Returns: %TRUE to stop other handlers from being invoked for the event.
988 * %FALSE to propagate the event further.
990 widget_signals[BUTTON_PRESS_EVENT] =
991 g_signal_new (I_("button_press_event"),
992 G_TYPE_FROM_CLASS (gobject_class),
994 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
995 _gtk_boolean_handled_accumulator, NULL,
996 _gtk_marshal_BOOLEAN__BOXED,
998 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1001 * GtkWidget::button-release-event:
1002 * @widget: the object which received the signal.
1003 * @event: the #GdkEventButton which triggered this signal
1005 * The ::button-release-event signal will be emitted when a button
1006 * (typically from a mouse) is released.
1008 * To receive this signal, the #GdkWindow associated to the
1009 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1011 * This signal will be sent to the grab widget if there is one.
1013 * Returns: %TRUE to stop other handlers from being invoked for the event.
1014 * %FALSE to propagate the event further.
1016 widget_signals[BUTTON_RELEASE_EVENT] =
1017 g_signal_new (I_("button_release_event"),
1018 G_TYPE_FROM_CLASS (gobject_class),
1020 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1021 _gtk_boolean_handled_accumulator, NULL,
1022 _gtk_marshal_BOOLEAN__BOXED,
1024 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1027 * GtkWidget::scroll-event:
1028 * @widget: the object which received the signal.
1029 * @event: the #GdkEventScroll which triggered this signal
1031 * The ::scroll-event signal is emitted when a button in the 4 to 7
1032 * range is pressed. Wheel mice are usually configured to generate
1033 * button press events for buttons 4 and 5 when the wheel is turned.
1035 * To receive this signal, the #GdkWindow associated to the widget needs
1036 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1038 * This signal will be sent to the grab widget if there is one.
1040 * Returns: %TRUE to stop other handlers from being invoked for the event.
1041 * %FALSE to propagate the event further.
1043 widget_signals[SCROLL_EVENT] =
1044 g_signal_new (I_("scroll_event"),
1045 G_TYPE_FROM_CLASS (gobject_class),
1047 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1048 _gtk_boolean_handled_accumulator, NULL,
1049 _gtk_marshal_BOOLEAN__BOXED,
1051 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1053 * GtkWidget::motion-notify-event:
1054 * @widget: the object which received the signal.
1055 * @event: the #GdkEventMotion which triggered this signal
1057 * The ::motion-notify-event signal is emitted when the pointer moves
1058 * over the widget's #GdkWindow.
1060 * To receive this signal, the #GdkWindow associated to the widget
1061 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1063 * This signal will be sent to the grab widget if there is one.
1065 * Returns: %TRUE to stop other handlers from being invoked for the event.
1066 * %FALSE to propagate the event further.
1068 widget_signals[MOTION_NOTIFY_EVENT] =
1069 g_signal_new (I_("motion_notify_event"),
1070 G_TYPE_FROM_CLASS (gobject_class),
1072 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1073 _gtk_boolean_handled_accumulator, NULL,
1074 _gtk_marshal_BOOLEAN__BOXED,
1076 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1079 * GtkWidget::composited-changed:
1080 * @widget: the object on which the signal is emitted
1082 * The ::composited-changed signal is emitted when the composited
1083 * status of @widget<!-- -->s screen changes.
1084 * See gdk_screen_is_composited().
1086 widget_signals[COMPOSITED_CHANGED] =
1087 g_signal_new (I_("composited_changed"),
1088 G_TYPE_FROM_CLASS (gobject_class),
1089 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1090 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1092 _gtk_marshal_VOID__VOID,
1096 * GtkWidget::keynav-failed:
1097 * @widget: the object which received the signal
1098 * @direction: the direction of movement
1100 * Gets emitted if keyboard navigation fails.
1101 * See gtk_widget_keynav_failed() for details.
1103 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1104 * if the emitting widget should try to handle the keyboard
1105 * navigation attempt in its parent container(s).
1109 widget_signals[KEYNAV_FAILED] =
1110 _gtk_binding_signal_new (I_("keynav-failed"),
1111 G_TYPE_FROM_CLASS (gobject_class),
1113 G_CALLBACK (gtk_widget_real_keynav_failed),
1114 _gtk_boolean_handled_accumulator, NULL,
1115 _gtk_marshal_BOOLEAN__ENUM,
1117 GTK_TYPE_DIRECTION_TYPE);
1120 * GtkWidget::delete-event:
1121 * @widget: the object which received the signal
1122 * @event: the event which triggered this signal
1124 * The ::delete-event signal is emitted if a user requests that
1125 * a toplevel window is closed. The default handler for this signal
1126 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1127 * this signal will cause the window to be hidden instead, so that
1128 * it can later be shown again without reconstructing it.
1130 * Returns: %TRUE to stop other handlers from being invoked for the event.
1131 * %FALSE to propagate the event further.
1133 widget_signals[DELETE_EVENT] =
1134 g_signal_new (I_("delete_event"),
1135 G_TYPE_FROM_CLASS (gobject_class),
1137 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1138 _gtk_boolean_handled_accumulator, NULL,
1139 _gtk_marshal_BOOLEAN__BOXED,
1141 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1144 * GtkWidget::destroy-event:
1145 * @widget: the object which received the signal.
1146 * @event: the event which triggered this signal
1148 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1149 * You rarely get this signal, because most widgets disconnect themselves
1150 * from their window before they destroy it, so no widget owns the
1151 * window at destroy time.
1153 * To receive this signal, the #GdkWindow associated to the widget needs
1154 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1155 * automatically for all new windows.
1157 * Returns: %TRUE to stop other handlers from being invoked for the event.
1158 * %FALSE to propagate the event further.
1160 widget_signals[DESTROY_EVENT] =
1161 g_signal_new (I_("destroy_event"),
1162 G_TYPE_FROM_CLASS (gobject_class),
1164 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1165 _gtk_boolean_handled_accumulator, NULL,
1166 _gtk_marshal_BOOLEAN__BOXED,
1168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1171 * GtkWidget::expose-event:
1172 * @widget: the object which received the signal.
1173 * @event: the #GdkEventExpose which triggered this signal
1175 * The ::expose-event signal is emitted when an area of a previously
1176 * obscured #GdkWindow is made visible and needs to be redrawn.
1177 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1180 * To receive this signal, the #GdkWindow associated to the widget needs
1181 * to enable the #GDK_EXPOSURE_MASK mask.
1183 * Returns: %TRUE to stop other handlers from being invoked for the event.
1184 * %FALSE to propagate the event further.
1186 widget_signals[EXPOSE_EVENT] =
1187 g_signal_new (I_("expose_event"),
1188 G_TYPE_FROM_CLASS (gobject_class),
1190 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1191 _gtk_boolean_handled_accumulator, NULL,
1192 _gtk_marshal_BOOLEAN__BOXED,
1194 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1197 * GtkWidget::key-press-event:
1198 * @widget: the object which received the signal
1199 * @event: the #GdkEventKey which triggered this signal
1201 * The ::key-press-event signal is emitted when a key is pressed.
1203 * To receive this signal, the #GdkWindow associated to the widget needs
1204 * to enable the #GDK_KEY_PRESS_MASK mask.
1206 * This signal will be sent to the grab widget if there is one.
1208 * Returns: %TRUE to stop other handlers from being invoked for the event.
1209 * %FALSE to propagate the event further.
1211 widget_signals[KEY_PRESS_EVENT] =
1212 g_signal_new (I_("key_press_event"),
1213 G_TYPE_FROM_CLASS (gobject_class),
1215 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1216 _gtk_boolean_handled_accumulator, NULL,
1217 _gtk_marshal_BOOLEAN__BOXED,
1219 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1222 * GtkWidget::key-release-event:
1223 * @widget: the object which received the signal
1224 * @event: the #GdkEventKey which triggered this signal
1226 * The ::key-release-event signal is emitted when a key is pressed.
1228 * To receive this signal, the #GdkWindow associated to the widget needs
1229 * to enable the #GDK_KEY_RELEASE_MASK mask.
1231 * This signal will be sent to the grab widget if there is one.
1233 * Returns: %TRUE to stop other handlers from being invoked for the event.
1234 * %FALSE to propagate the event further.
1236 widget_signals[KEY_RELEASE_EVENT] =
1237 g_signal_new (I_("key_release_event"),
1238 G_TYPE_FROM_CLASS (gobject_class),
1240 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1241 _gtk_boolean_handled_accumulator, NULL,
1242 _gtk_marshal_BOOLEAN__BOXED,
1244 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1247 * GtkWidget::enter-notify-event:
1248 * @widget: the object which received the signal
1249 * @event: the #GdkEventCrossing which triggered this signal
1251 * The ::enter-notify-event will be emitted when the pointer enters
1252 * the @widget's window.
1254 * To receive this signal, the #GdkWindow associated to the widget needs
1255 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1257 * This signal will be sent to the grab widget if there is one.
1259 * Returns: %TRUE to stop other handlers from being invoked for the event.
1260 * %FALSE to propagate the event further.
1262 widget_signals[ENTER_NOTIFY_EVENT] =
1263 g_signal_new (I_("enter_notify_event"),
1264 G_TYPE_FROM_CLASS (gobject_class),
1266 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1267 _gtk_boolean_handled_accumulator, NULL,
1268 _gtk_marshal_BOOLEAN__BOXED,
1270 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1273 * GtkWidget::leave-notify-event:
1274 * @widget: the object which received the signal
1275 * @event: the #GdkEventCrossing which triggered this signal
1277 * The ::leave-notify-event will be emitted when the pointer leaves
1278 * the @widget's window.
1280 * To receive this signal, the #GdkWindow associated to the widget needs
1281 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1283 * This signal will be sent to the grab widget if there is one.
1285 * Returns: %TRUE to stop other handlers from being invoked for the event.
1286 * %FALSE to propagate the event further.
1288 widget_signals[LEAVE_NOTIFY_EVENT] =
1289 g_signal_new (I_("leave_notify_event"),
1290 G_TYPE_FROM_CLASS (gobject_class),
1292 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1293 _gtk_boolean_handled_accumulator, NULL,
1294 _gtk_marshal_BOOLEAN__BOXED,
1296 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1299 * GtkWidget::configure-event
1300 * @widget: the object which received the signal
1301 * @event: the #GdkEventConfigure which triggered this signal
1303 * The ::configure-event signal will be emitted when the size, position or
1304 * stacking of the @widget's window has changed.
1306 * To receive this signal, the #GdkWindow associated to the widget needs
1307 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1308 * automatically for all new windows.
1310 * Returns: %TRUE to stop other handlers from being invoked for the event.
1311 * %FALSE to propagate the event further.
1313 widget_signals[CONFIGURE_EVENT] =
1314 g_signal_new (I_("configure_event"),
1315 G_TYPE_FROM_CLASS (gobject_class),
1317 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1318 _gtk_boolean_handled_accumulator, NULL,
1319 _gtk_marshal_BOOLEAN__BOXED,
1321 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1324 * GtkWidget::focus-in-event
1325 * @widget: the object which received the signal
1326 * @event: the #GdkEventFocus which triggered this signal
1328 * The ::focus-in-event signal will be emitted when the keyboard focus
1329 * enters the @widget's window.
1331 * To receive this signal, the #GdkWindow associated to the widget needs
1332 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1334 * Returns: %TRUE to stop other handlers from being invoked for the event.
1335 * %FALSE to propagate the event further.
1337 widget_signals[FOCUS_IN_EVENT] =
1338 g_signal_new (I_("focus_in_event"),
1339 G_TYPE_FROM_CLASS (gobject_class),
1341 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1342 _gtk_boolean_handled_accumulator, NULL,
1343 _gtk_marshal_BOOLEAN__BOXED,
1345 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1348 * GtkWidget::focus-out-event
1349 * @widget: the object which received the signal
1350 * @event: the #GdkEventFocus which triggered this signal
1352 * The ::focus-out-event signal will be emitted when the keyboard focus
1353 * leaves the @widget's window.
1355 * To receive this signal, the #GdkWindow associated to the widget needs
1356 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1358 * Returns: %TRUE to stop other handlers from being invoked for the event.
1359 * %FALSE to propagate the event further.
1361 widget_signals[FOCUS_OUT_EVENT] =
1362 g_signal_new (I_("focus_out_event"),
1363 G_TYPE_FROM_CLASS (gobject_class),
1365 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1366 _gtk_boolean_handled_accumulator, NULL,
1367 _gtk_marshal_BOOLEAN__BOXED,
1369 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1372 * GtkWidget::map-event
1373 * @widget: the object which received the signal
1374 * @event: the #GdkEventAny which triggered this signal
1376 * The ::map-event signal will be emitted when the @widget's window is
1377 * mapped. A window is mapped when it becomes visible on the screen.
1379 * To receive this signal, the #GdkWindow associated to the widget needs
1380 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1381 * automatically for all new windows.
1383 * Returns: %TRUE to stop other handlers from being invoked for the event.
1384 * %FALSE to propagate the event further.
1386 widget_signals[MAP_EVENT] =
1387 g_signal_new (I_("map_event"),
1388 G_TYPE_FROM_CLASS (gobject_class),
1390 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1391 _gtk_boolean_handled_accumulator, NULL,
1392 _gtk_marshal_BOOLEAN__BOXED,
1394 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1397 * GtkWidget::unmap-event
1398 * @widget: the object which received the signal
1399 * @event: the #GdkEventAny which triggered this signal
1401 * The ::unmap-event signal will be emitted when the @widget's window is
1402 * unmapped. A window is unmapped when it becomes invisible on the screen.
1404 * To receive this signal, the #GdkWindow associated to the widget needs
1405 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1406 * automatically for all new windows.
1408 * Returns: %TRUE to stop other handlers from being invoked for the event.
1409 * %FALSE to propagate the event further.
1411 widget_signals[UNMAP_EVENT] =
1412 g_signal_new (I_("unmap_event"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1415 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1416 _gtk_boolean_handled_accumulator, NULL,
1417 _gtk_marshal_BOOLEAN__BOXED,
1419 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1422 * GtkWidget::property-notify-event
1423 * @widget: the object which received the signal
1424 * @event: the #GdkEventProperty which triggered this signal
1426 * The ::property-notify-event signal will be emitted when a property on
1427 * the @widget's window has been changed or deleted.
1429 * To receive this signal, the #GdkWindow associated to the widget needs
1430 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1432 * Returns: %TRUE to stop other handlers from being invoked for the event.
1433 * %FALSE to propagate the event further.
1435 widget_signals[PROPERTY_NOTIFY_EVENT] =
1436 g_signal_new (I_("property_notify_event"),
1437 G_TYPE_FROM_CLASS (gobject_class),
1439 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1440 _gtk_boolean_handled_accumulator, NULL,
1441 _gtk_marshal_BOOLEAN__BOXED,
1443 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1446 * GtkWidget::selection-clear-event
1447 * @widget: the object which received the signal
1448 * @event: the #GdkEventSelection which triggered this signal
1450 * The ::selection-clear-event signal will be emitted when the
1451 * the @widget's window has lost ownership of a selection.
1453 * Returns: %TRUE to stop other handlers from being invoked for the event.
1454 * %FALSE to propagate the event further.
1456 widget_signals[SELECTION_CLEAR_EVENT] =
1457 g_signal_new (I_("selection_clear_event"),
1458 G_TYPE_FROM_CLASS (gobject_class),
1460 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1461 _gtk_boolean_handled_accumulator, NULL,
1462 _gtk_marshal_BOOLEAN__BOXED,
1464 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1467 * GtkWidget::selection-request-event
1468 * @widget: the object which received the signal
1469 * @event: the #GdkEventSelection which triggered this signal
1471 * The ::selection-request-event signal will be emitted when
1472 * another client requests ownership of the selection owned by
1473 * the @widget's window.
1475 * Returns: %TRUE to stop other handlers from being invoked for the event.
1476 * %FALSE to propagate the event further.
1478 widget_signals[SELECTION_REQUEST_EVENT] =
1479 g_signal_new (I_("selection_request_event"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1482 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1483 _gtk_boolean_handled_accumulator, NULL,
1484 _gtk_marshal_BOOLEAN__BOXED,
1486 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1488 widget_signals[SELECTION_NOTIFY_EVENT] =
1489 g_signal_new (I_("selection_notify_event"),
1490 G_TYPE_FROM_CLASS (gobject_class),
1492 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1493 _gtk_boolean_handled_accumulator, NULL,
1494 _gtk_marshal_BOOLEAN__BOXED,
1496 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1498 widget_signals[SELECTION_RECEIVED] =
1499 g_signal_new (I_("selection_received"),
1500 G_TYPE_FROM_CLASS (gobject_class),
1502 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1504 _gtk_marshal_VOID__BOXED_UINT,
1506 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1509 widget_signals[SELECTION_GET] =
1510 g_signal_new (I_("selection_get"),
1511 G_TYPE_FROM_CLASS (gobject_class),
1513 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1515 _gtk_marshal_VOID__BOXED_UINT_UINT,
1517 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1522 * GtkWidget::proximity-in-event
1523 * @widget: the object which received the signal
1524 * @event: the #GdkEventProximity which triggered this signal
1526 * To receive this signal the #GdkWindow associated to the widget needs
1527 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1529 * This signal will be sent to the grab widget if there is one.
1531 * Returns: %TRUE to stop other handlers from being invoked for the event.
1532 * %FALSE to propagate the event further.
1534 widget_signals[PROXIMITY_IN_EVENT] =
1535 g_signal_new (I_("proximity_in_event"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1539 _gtk_boolean_handled_accumulator, NULL,
1540 _gtk_marshal_BOOLEAN__BOXED,
1542 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1545 * GtkWidget::proximity-out-event
1546 * @widget: the object which received the signal
1547 * @event: the #GdkEventProximity which triggered this signal
1549 * To receive this signal the #GdkWindow associated to the widget needs
1550 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1552 * This signal will be sent to the grab widget if there is one.
1554 * Returns: %TRUE to stop other handlers from being invoked for the event.
1555 * %FALSE to propagate the event further.
1557 widget_signals[PROXIMITY_OUT_EVENT] =
1558 g_signal_new (I_("proximity_out_event"),
1559 G_TYPE_FROM_CLASS (gobject_class),
1561 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1562 _gtk_boolean_handled_accumulator, NULL,
1563 _gtk_marshal_BOOLEAN__BOXED,
1565 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1568 * GtkWidget::drag-leave:
1569 * @widget: the object which received the signal.
1570 * @drag_context: the drag context
1571 * @time: the timestamp of the motion event
1573 * The ::drag-leave signal is emitted on the drop site when the cursor
1574 * leaves the widget. A typical reason to connect to this signal is to
1575 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1576 * with gtk_drag_unhighlight()
1578 widget_signals[DRAG_LEAVE] =
1579 g_signal_new (I_("drag_leave"),
1580 G_TYPE_FROM_CLASS (gobject_class),
1582 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1584 _gtk_marshal_VOID__OBJECT_UINT,
1586 GDK_TYPE_DRAG_CONTEXT,
1590 * GtkWidget::drag-begin:
1591 * @widget: the object which received the signal
1592 * @drag_context: the drag context
1594 * The ::drag-begin signal is emitted on the drag source when a drag is
1595 * started. A typical reason to connect to this signal is to set up a
1596 * custom drag icon with gtk_drag_source_set_icon().
1598 widget_signals[DRAG_BEGIN] =
1599 g_signal_new (I_("drag_begin"),
1600 G_TYPE_FROM_CLASS (gobject_class),
1602 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1604 _gtk_marshal_VOID__OBJECT,
1606 GDK_TYPE_DRAG_CONTEXT);
1609 * GtkWidget::drag-end:
1610 * @widget: the object which received the signal
1611 * @drag_context: the drag context
1613 * The ::drag-end signal is emitted on the drag source when a drag is
1614 * finished. A typical reason to connect to this signal is to undo
1615 * things done in #GtkWidget::drag-begin.
1617 widget_signals[DRAG_END] =
1618 g_signal_new (I_("drag_end"),
1619 G_TYPE_FROM_CLASS (gobject_class),
1621 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1623 _gtk_marshal_VOID__OBJECT,
1625 GDK_TYPE_DRAG_CONTEXT);
1628 * GtkWidget::drag-data-delete:
1629 * @widget: the object which received the signal
1630 * @drag_context: the drag context
1632 * The ::drag-data-delete signal is emitted on the drag source when a drag
1633 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1634 * handler is responsible for deleting the data that has been dropped. What
1635 * "delete" means depends on the context of the drag operation.
1637 widget_signals[DRAG_DATA_DELETE] =
1638 g_signal_new (I_("drag_data_delete"),
1639 G_TYPE_FROM_CLASS (gobject_class),
1641 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1643 _gtk_marshal_VOID__OBJECT,
1645 GDK_TYPE_DRAG_CONTEXT);
1648 * GtkWidget::drag-failed:
1649 * @widget: the object which received the signal
1650 * @drag_context: the drag context
1651 * @result: the result of the drag operation
1653 * The ::drag-failed signal is emitted on the drag source when a drag has
1654 * failed. The signal handler may hook custom code to handle a failed DND
1655 * operation based on the type of error, it returns %TRUE is the failure has
1656 * been already handled (not showing the default "drag operation failed"
1657 * animation), otherwise it returns %FALSE.
1659 * Return value: %TRUE if the failed drag operation has been already handled.
1663 widget_signals[DRAG_FAILED] =
1664 g_signal_new (I_("drag_failed"),
1665 G_TYPE_FROM_CLASS (gobject_class),
1667 0, _gtk_boolean_handled_accumulator, NULL,
1668 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1670 GDK_TYPE_DRAG_CONTEXT,
1671 GTK_TYPE_DRAG_RESULT);
1674 * GtkWidget::drag-motion:
1675 * @widget: the object which received the signal
1676 * @drag_context: the drag context
1677 * @x: the x coordinate of the current cursor position
1678 * @y: the y coordinate of the current cursor position
1679 * @time: the timestamp of the motion event
1680 * @returns: whether the cursor position is in a drop zone
1682 * The drag-motion signal is emitted on the drop site when the user
1683 * moves the cursor over the widget during a drag. The signal handler
1684 * must determine whether the cursor position is in a drop zone or not.
1685 * If it is not in a drop zone, it returns %FALSE and no further processing
1686 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1687 * handler is responsible for providing the necessary information for
1688 * displaying feedback to the user, by calling gdk_drag_status().
1690 * If the decision whether the drop will be accepted or rejected can't be
1691 * made based solely on the cursor position and the type of the data, the
1692 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1693 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1694 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1695 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1696 * when using the drag-motion signal that way.
1698 * Also note that there is no drag-enter signal. The drag receiver has to
1699 * keep track of whether he has received any drag-motion signals since the
1700 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1701 * an "enter" signal. Upon an "enter", the handler will typically highlight
1702 * the drop site with gtk_drag_highlight().
1705 * drag_motion (GtkWidget *widget,
1706 * GdkDragContext *context,
1713 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1715 * if (!private_data->drag_highlight)
1717 * private_data->drag_highlight = 1;
1718 * gtk_drag_highlight (widget);
1721 * target = gtk_drag_dest_find_target (widget, context, NULL);
1722 * if (target == GDK_NONE)
1723 * gdk_drag_status (context, 0, time);
1726 * private_data->pending_status = context->suggested_action;
1727 * gtk_drag_get_data (widget, context, target, time);
1734 * drag_data_received (GtkWidget *widget,
1735 * GdkDragContext *context,
1738 * GtkSelectionData *selection_data,
1742 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1744 * if (private_data->suggested_action)
1746 * private_data->suggested_action = 0;
1748 * /* We are getting this data due to a request in drag_motion,
1749 * * rather than due to a request in drag_drop, so we are just
1750 * * supposed to call gdk_drag_status (), not actually paste in
1753 * str = gtk_selection_data_get_text (selection_data);
1754 * if (!data_is_acceptable (str))
1755 * gdk_drag_status (context, 0, time);
1757 * gdk_drag_status (context, private_data->suggested_action, time);
1761 * /* accept the drop */
1766 widget_signals[DRAG_MOTION] =
1767 g_signal_new (I_("drag_motion"),
1768 G_TYPE_FROM_CLASS (gobject_class),
1770 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1771 _gtk_boolean_handled_accumulator, NULL,
1772 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1774 GDK_TYPE_DRAG_CONTEXT,
1780 * GtkWidget::drag-drop:
1781 * @widget: the object which received the signal
1782 * @drag_context: the drag context
1783 * @x: the x coordinate of the current cursor position
1784 * @y: the y coordinate of the current cursor position
1785 * @time: the timestamp of the motion event
1786 * @returns: whether the cursor position is in a drop zone
1788 * The ::drag-drop signal is emitted on the drop site when the user drops
1789 * the data onto the widget. The signal handler must determine whether
1790 * the cursor position is in a drop zone or not. If it is not in a drop
1791 * zone, it returns %FALSE and no further processing is necessary.
1792 * Otherwise, the handler returns %TRUE. In this case, the handler must
1793 * ensure that gtk_drag_finish() is called to let the source know that
1794 * the drop is done. The call to gtk_drag_finish() can be done either
1795 * directly or in a #GtkWidget::drag-data-received handler which gets
1796 * triggered by calling gtk_drag_get_data() to receive the data for one
1797 * or more of the supported targets.
1799 widget_signals[DRAG_DROP] =
1800 g_signal_new (I_("drag_drop"),
1801 G_TYPE_FROM_CLASS (gobject_class),
1803 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1804 _gtk_boolean_handled_accumulator, NULL,
1805 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1807 GDK_TYPE_DRAG_CONTEXT,
1813 * GtkWidget::drag-data-get:
1814 * @widget: the object which received the signal
1815 * @drag_context: the drag context
1816 * @data: the #GtkSelectionData to be filled with the dragged data
1817 * @info: the info that has been registered with the target in the
1819 * @time: the timestamp at which the data was requested
1821 * The ::drag-data-get signal is emitted on the drag source when the drop
1822 * site requests the data which is dragged. It is the responsibility of
1823 * the signal handler to fill @data with the data in the format which
1824 * is indicated by @info. See gtk_selection_data_set() and
1825 * gtk_selection_data_set_text().
1827 widget_signals[DRAG_DATA_GET] =
1828 g_signal_new (I_("drag_data_get"),
1829 G_TYPE_FROM_CLASS (gobject_class),
1831 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1833 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1835 GDK_TYPE_DRAG_CONTEXT,
1836 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1841 * GtkWidget::drag-data-received:
1842 * @widget: the object which received the signal
1843 * @drag_context: the drag context
1844 * @x: where the drop happened
1845 * @y: where the drop happened
1846 * @data: the received data
1847 * @info: the info that has been registered with the target in the
1849 * @time: the timestamp at which the data was received
1851 * The ::drag-data-received signal is emitted on the drop site when the
1852 * dragged data has been received. If the data was received in order to
1853 * determine whether the drop will be accepted, the handler is expected
1854 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1855 * If the data was received in response to a #GtkWidget::drag-drop signal
1856 * (and this is the last target to be received), the handler for this
1857 * signal is expected to process the received data and then call
1858 * gtk_drag_finish(), setting the @success parameter depending on whether
1859 * the data was processed successfully.
1861 * The handler may inspect and modify @drag_context->action before calling
1862 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1863 * following example:
1866 * drag_data_received (GtkWidget *widget,
1867 * GdkDragContext *drag_context,
1870 * GtkSelectionData *data,
1874 * if ((data->length >= 0) && (data->format == 8))
1876 * if (drag_context->action == GDK_ACTION_ASK)
1878 * GtkWidget *dialog;
1881 * dialog = gtk_message_dialog_new (NULL,
1882 * GTK_DIALOG_MODAL |
1883 * GTK_DIALOG_DESTROY_WITH_PARENT,
1885 * GTK_BUTTONS_YES_NO,
1886 * "Move the data ?\n");
1887 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1888 * gtk_widget_destroy (dialog);
1890 * if (response == GTK_RESPONSE_YES)
1891 * drag_context->action = GDK_ACTION_MOVE;
1893 * drag_context->action = GDK_ACTION_COPY;
1896 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1900 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1904 widget_signals[DRAG_DATA_RECEIVED] =
1905 g_signal_new (I_("drag_data_received"),
1906 G_TYPE_FROM_CLASS (gobject_class),
1908 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1910 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1912 GDK_TYPE_DRAG_CONTEXT,
1915 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1920 * GtkWidget::visibility-notify-event:
1921 * @widget: the object which received the signal
1922 * @event: the #GdkEventVisibility which triggered this signal
1924 * The ::visibility-notify-event will be emitted when the @widget's window
1925 * is obscured or unobscured.
1927 * To receive this signal the #GdkWindow associated to the widget needs
1928 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1930 * Returns: %TRUE to stop other handlers from being invoked for the event.
1931 * %FALSE to propagate the event further.
1933 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1934 g_signal_new (I_("visibility_notify_event"),
1935 G_TYPE_FROM_CLASS (gobject_class),
1937 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1938 _gtk_boolean_handled_accumulator, NULL,
1939 _gtk_marshal_BOOLEAN__BOXED,
1941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1944 * GtkWidget::client-event:
1945 * @widget: the object which received the signal
1946 * @event: the #GdkEventClient which triggered this signal
1948 * The ::client-event will be emitted when the @widget's window
1949 * receives a message (via a ClientMessage event) from another
1952 * Returns: %TRUE to stop other handlers from being invoked for
1953 * the event. %FALSE to propagate the event further.
1955 widget_signals[CLIENT_EVENT] =
1956 g_signal_new (I_("client_event"),
1957 G_TYPE_FROM_CLASS (gobject_class),
1959 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1960 _gtk_boolean_handled_accumulator, NULL,
1961 _gtk_marshal_BOOLEAN__BOXED,
1963 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1966 * GtkWidget::no-expose-event:
1967 * @widget: the object which received the signal
1968 * @event: the #GdkEventNoExpose which triggered this signal
1970 * The ::no-expose-event will be emitted when the @widget's window is
1971 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1972 * gdk_window_copy_area()) which was completely unobscured. If the source
1973 * window was partially obscured #GdkEventExpose events will be generated
1976 * Returns: %TRUE to stop other handlers from being invoked for the event.
1977 * %FALSE to propagate the event further.
1979 widget_signals[NO_EXPOSE_EVENT] =
1980 g_signal_new (I_("no_expose_event"),
1981 G_TYPE_FROM_CLASS (gobject_class),
1983 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1984 _gtk_boolean_handled_accumulator, NULL,
1985 _gtk_marshal_BOOLEAN__BOXED,
1987 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1990 * GtkWidget::window-state-event:
1991 * @widget: the object which received the signal
1992 * @event: the #GdkEventWindowState which triggered this signal
1994 * The ::window-state-event will be emitted when the state of the
1995 * toplevel window associated to the @widget changes.
1997 * To receive this signal the #GdkWindow associated to the widget
1998 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
1999 * this mask automatically for all new windows.
2001 * Returns: %TRUE to stop other handlers from being invoked for the
2002 * event. %FALSE to propagate the event further.
2004 widget_signals[WINDOW_STATE_EVENT] =
2005 g_signal_new (I_("window_state_event"),
2006 G_TYPE_FROM_CLASS (gobject_class),
2008 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2009 _gtk_boolean_handled_accumulator, NULL,
2010 _gtk_marshal_BOOLEAN__BOXED,
2012 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2015 * GtkWidget::damage-event:
2016 * @widget: the object which received the signal
2017 * @event: the #GdkEventExpose event
2019 * Emitted when a redirected window belonging to @widget gets drawn into.
2020 * The region/area members of the event shows what area of the redirected
2021 * drawable was drawn into.
2023 * Returns: %TRUE to stop other handlers from being invoked for the event.
2024 * %FALSE to propagate the event further.
2028 widget_signals[DAMAGE_EVENT] =
2029 g_signal_new ("damage_event",
2030 G_TYPE_FROM_CLASS (gobject_class),
2031 G_SIGNAL_RUN_LAST, 0,
2032 _gtk_boolean_handled_accumulator, NULL,
2033 _gtk_marshal_BOOLEAN__BOXED,
2035 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2037 * GtkWidget::grab-broken-event:
2038 * @widget: the object which received the signal
2039 * @event: the #GdkEventGrabBroken event
2041 * Emitted when a pointer or keyboard grab on a window belonging
2042 * to @widget gets broken.
2044 * On X11, this happens when the grab window becomes unviewable
2045 * (i.e. it or one of its ancestors is unmapped), or if the same
2046 * application grabs the pointer or keyboard again.
2048 * Returns: %TRUE to stop other handlers from being invoked for
2049 * the event. %FALSE to propagate the event further.
2053 widget_signals[GRAB_BROKEN] =
2054 g_signal_new (I_("grab_broken_event"),
2055 G_TYPE_FROM_CLASS (gobject_class),
2057 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2058 _gtk_boolean_handled_accumulator, NULL,
2059 _gtk_marshal_BOOLEAN__BOXED,
2061 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2063 * GtkWidget::query-tooltip:
2064 * @widget: the object which received the signal
2065 * @x: the x coordinate of the cursor position where the request has
2066 * been emitted, relative to @widget->window
2067 * @y: the y coordinate of the cursor position where the request has
2068 * been emitted, relative to @widget->window
2069 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2070 * @tooltip: a #GtkTooltip
2072 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with
2073 * the cursor hovering "above" @widget; or emitted when @widget got
2074 * focus in keyboard mode.
2076 * Using the given coordinates, the signal handler should determine
2077 * whether a tooltip should be shown for @widget. If this is the case
2078 * %TRUE should be returned, %FALSE otherwise. Note that if
2079 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2080 * should not be used.
2082 * The signal handler is free to manipulate @tooltip with the therefore
2083 * destined function calls.
2085 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2089 widget_signals[QUERY_TOOLTIP] =
2090 g_signal_new (I_("query-tooltip"),
2091 G_TYPE_FROM_CLASS (gobject_class),
2093 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2094 _gtk_boolean_handled_accumulator, NULL,
2095 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2103 * GtkWidget::popup-menu
2104 * @widget: the object which received the signal
2106 * This signal gets emitted whenever a widget should pop up a context
2107 * menu. This usually happens through the standard key binding mechanism;
2108 * by pressing a certain key while a widget is focused, the user can cause
2109 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2110 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2111 * for an example of how to use this signal.
2113 * Returns: %TRUE if a menu was activated
2115 widget_signals[POPUP_MENU] =
2116 g_signal_new (I_("popup_menu"),
2117 G_TYPE_FROM_CLASS (gobject_class),
2118 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2119 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2120 _gtk_boolean_handled_accumulator, NULL,
2121 _gtk_marshal_BOOLEAN__VOID,
2123 widget_signals[SHOW_HELP] =
2124 g_signal_new (I_("show_help"),
2125 G_TYPE_FROM_CLASS (gobject_class),
2126 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2127 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2128 _gtk_boolean_handled_accumulator, NULL,
2129 _gtk_marshal_BOOLEAN__ENUM,
2131 GTK_TYPE_WIDGET_HELP_TYPE);
2132 widget_signals[ACCEL_CLOSURES_CHANGED] =
2133 g_signal_new (I_("accel_closures_changed"),
2134 G_TYPE_FROM_CLASS (gobject_class),
2138 _gtk_marshal_NONE__NONE,
2142 * GtkWidget::screen-changed:
2143 * @widget: the object on which the signal is emitted
2144 * @previous_screen: the previous screen, or %NULL if the
2145 * widget was not associated with a screen before
2147 * The ::screen-changed signal gets emitted when the
2148 * screen of a widget has changed.
2150 widget_signals[SCREEN_CHANGED] =
2151 g_signal_new (I_("screen_changed"),
2152 G_TYPE_FROM_CLASS (gobject_class),
2154 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2156 _gtk_marshal_VOID__OBJECT,
2160 * GtkWidget::can-activate-accel:
2161 * @widget: the object which received the signal
2162 * @signal_id: the ID of a signal installed on @widget
2164 * Determines whether an accelerator that activates the signal
2165 * identified by @signal_id can currently be activated.
2166 * This signal is present to allow applications and derived
2167 * widgets to override the default #GtkWidget handling
2168 * for determining whether an accelerator can be activated.
2170 * Returns: %TRUE if the signal can be activated.
2172 widget_signals[CAN_ACTIVATE_ACCEL] =
2173 g_signal_new (I_("can_activate_accel"),
2174 G_TYPE_FROM_CLASS (gobject_class),
2176 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2177 _gtk_boolean_handled_accumulator, NULL,
2178 _gtk_marshal_BOOLEAN__UINT,
2179 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2181 binding_set = gtk_binding_set_by_class (klass);
2182 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2184 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2187 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2189 GTK_TYPE_WIDGET_HELP_TYPE,
2190 GTK_WIDGET_HELP_TOOLTIP);
2191 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2193 GTK_TYPE_WIDGET_HELP_TYPE,
2194 GTK_WIDGET_HELP_TOOLTIP);
2195 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2197 GTK_TYPE_WIDGET_HELP_TYPE,
2198 GTK_WIDGET_HELP_WHATS_THIS);
2199 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2201 GTK_TYPE_WIDGET_HELP_TYPE,
2202 GTK_WIDGET_HELP_WHATS_THIS);
2204 gtk_widget_class_install_style_property (klass,
2205 g_param_spec_boolean ("interior-focus",
2206 P_("Interior Focus"),
2207 P_("Whether to draw the focus indicator inside widgets"),
2209 GTK_PARAM_READABLE));
2211 gtk_widget_class_install_style_property (klass,
2212 g_param_spec_int ("focus-line-width",
2213 P_("Focus linewidth"),
2214 P_("Width, in pixels, of the focus indicator line"),
2216 GTK_PARAM_READABLE));
2218 gtk_widget_class_install_style_property (klass,
2219 g_param_spec_string ("focus-line-pattern",
2220 P_("Focus line dash pattern"),
2221 P_("Dash pattern used to draw the focus indicator"),
2223 GTK_PARAM_READABLE));
2224 gtk_widget_class_install_style_property (klass,
2225 g_param_spec_int ("focus-padding",
2226 P_("Focus padding"),
2227 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2229 GTK_PARAM_READABLE));
2230 gtk_widget_class_install_style_property (klass,
2231 g_param_spec_boxed ("cursor-color",
2233 P_("Color with which to draw insertion cursor"),
2235 GTK_PARAM_READABLE));
2236 gtk_widget_class_install_style_property (klass,
2237 g_param_spec_boxed ("secondary-cursor-color",
2238 P_("Secondary cursor color"),
2239 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2241 GTK_PARAM_READABLE));
2242 gtk_widget_class_install_style_property (klass,
2243 g_param_spec_float ("cursor-aspect-ratio",
2244 P_("Cursor line aspect ratio"),
2245 P_("Aspect ratio with which to draw insertion cursor"),
2247 GTK_PARAM_READABLE));
2250 * GtkWidget:draw-border:
2252 * The "draw-border" style property defines the size of areas outside
2253 * the widget's allocation to draw.
2257 gtk_widget_class_install_style_property (klass,
2258 g_param_spec_boxed ("draw-border",
2260 P_("Size of areas outside the widget's allocation to draw"),
2262 GTK_PARAM_READABLE));
2265 * GtkWidget:link-color:
2267 * The "link-color" style property defines the color of unvisited links.
2271 gtk_widget_class_install_style_property (klass,
2272 g_param_spec_boxed ("link-color",
2273 P_("Unvisited Link Color"),
2274 P_("Color of unvisited links"),
2276 GTK_PARAM_READABLE));
2279 * GtkWidget:visited-link-color:
2281 * The "visited-link-color" style property defines the color of visited links.
2285 gtk_widget_class_install_style_property (klass,
2286 g_param_spec_boxed ("visited-link-color",
2287 P_("Visited Link Color"),
2288 P_("Color of visited links"),
2290 GTK_PARAM_READABLE));
2293 * GtkWidget:wide-separators:
2295 * The "wide-separators" style property defines whether separators have
2296 * configurable width and should be drawn using a box instead of a line.
2300 gtk_widget_class_install_style_property (klass,
2301 g_param_spec_boolean ("wide-separators",
2302 P_("Wide Separators"),
2303 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2305 GTK_PARAM_READABLE));
2308 * GtkWidget:separator-width:
2310 * The "separator-width" style property defines the width of separators.
2311 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2315 gtk_widget_class_install_style_property (klass,
2316 g_param_spec_int ("separator-width",
2317 P_("Separator Width"),
2318 P_("The width of separators if wide-separators is TRUE"),
2320 GTK_PARAM_READABLE));
2323 * GtkWidget:separator-height:
2325 * The "separator-height" style property defines the height of separators.
2326 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2330 gtk_widget_class_install_style_property (klass,
2331 g_param_spec_int ("separator-height",
2332 P_("Separator Height"),
2333 P_("The height of separators if \"wide-separators\" is TRUE"),
2335 GTK_PARAM_READABLE));
2338 * GtkWidget:scroll-arrow-hlength:
2340 * The "scroll-arrow-hlength" style property defines the length of
2341 * horizontal scroll arrows.
2345 gtk_widget_class_install_style_property (klass,
2346 g_param_spec_int ("scroll-arrow-hlength",
2347 P_("Horizontal Scroll Arrow Length"),
2348 P_("The length of horizontal scroll arrows"),
2350 GTK_PARAM_READABLE));
2353 * GtkWidget:scroll-arrow-vlength:
2355 * The "scroll-arrow-vlength" style property defines the length of
2356 * vertical scroll arrows.
2360 gtk_widget_class_install_style_property (klass,
2361 g_param_spec_int ("scroll-arrow-vlength",
2362 P_("Vertical Scroll Arrow Length"),
2363 P_("The length of vertical scroll arrows"),
2365 GTK_PARAM_READABLE));
2369 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2373 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2374 for (node = list; node; node = node->next)
2376 GParamSpec *pspec = node->data;
2378 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2379 g_param_spec_unref (pspec);
2385 gtk_widget_set_property (GObject *object,
2387 const GValue *value,
2390 GtkWidget *widget = GTK_WIDGET (object);
2395 guint32 saved_flags;
2396 gchar *tooltip_markup;
2397 const gchar *tooltip_text;
2398 GtkWindow *tooltip_window;
2401 gtk_widget_set_name (widget, g_value_get_string (value));
2404 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2406 case PROP_WIDTH_REQUEST:
2407 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2409 case PROP_HEIGHT_REQUEST:
2410 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2413 if (g_value_get_boolean (value))
2414 gtk_widget_show (widget);
2416 gtk_widget_hide (widget);
2418 case PROP_SENSITIVE:
2419 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2421 case PROP_APP_PAINTABLE:
2422 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2424 case PROP_CAN_FOCUS:
2425 saved_flags = GTK_WIDGET_FLAGS (widget);
2426 if (g_value_get_boolean (value))
2427 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2429 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2430 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2431 gtk_widget_queue_resize (widget);
2433 case PROP_HAS_FOCUS:
2434 if (g_value_get_boolean (value))
2435 gtk_widget_grab_focus (widget);
2438 if (g_value_get_boolean (value))
2439 gtk_widget_grab_focus (widget);
2441 case PROP_CAN_DEFAULT:
2442 saved_flags = GTK_WIDGET_FLAGS (widget);
2443 if (g_value_get_boolean (value))
2444 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2446 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2447 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2448 gtk_widget_queue_resize (widget);
2450 case PROP_HAS_DEFAULT:
2451 if (g_value_get_boolean (value))
2452 gtk_widget_grab_default (widget);
2454 case PROP_RECEIVES_DEFAULT:
2455 if (g_value_get_boolean (value))
2456 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2458 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2461 gtk_widget_set_style (widget, g_value_get_object (value));
2464 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2465 gtk_widget_set_events (widget, g_value_get_flags (value));
2467 case PROP_EXTENSION_EVENTS:
2468 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2470 case PROP_NO_SHOW_ALL:
2471 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2473 case PROP_HAS_TOOLTIP:
2474 gtk_widget_real_set_has_tooltip (widget,
2475 g_value_get_boolean (value), FALSE);
2477 case PROP_TOOLTIP_MARKUP:
2478 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2479 tooltip_markup = g_value_dup_string (value);
2481 g_object_set_qdata_full (object, quark_tooltip_markup,
2482 tooltip_markup, g_free);
2484 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2485 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2487 case PROP_TOOLTIP_TEXT:
2488 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2489 tooltip_text = g_value_get_string (value);
2490 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2492 g_object_set_qdata_full (object, quark_tooltip_markup,
2493 tooltip_markup, g_free);
2495 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2496 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2499 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2505 gtk_widget_get_property (GObject *object,
2510 GtkWidget *widget = GTK_WIDGET (object);
2519 g_value_set_string (value, widget->name);
2521 g_value_set_static_string (value, "");
2525 g_value_set_object (value, widget->parent);
2527 g_value_set_object (value, NULL);
2529 case PROP_WIDTH_REQUEST:
2532 gtk_widget_get_size_request (widget, &w, NULL);
2533 g_value_set_int (value, w);
2536 case PROP_HEIGHT_REQUEST:
2539 gtk_widget_get_size_request (widget, NULL, &h);
2540 g_value_set_int (value, h);
2544 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2546 case PROP_SENSITIVE:
2547 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2549 case PROP_APP_PAINTABLE:
2550 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2552 case PROP_CAN_FOCUS:
2553 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2555 case PROP_HAS_FOCUS:
2556 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2559 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2561 case PROP_CAN_DEFAULT:
2562 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2564 case PROP_HAS_DEFAULT:
2565 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2567 case PROP_RECEIVES_DEFAULT:
2568 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2570 case PROP_COMPOSITE_CHILD:
2571 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2574 g_value_set_object (value, gtk_widget_get_style (widget));
2577 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2578 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2580 case PROP_EXTENSION_EVENTS:
2581 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2582 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2584 case PROP_NO_SHOW_ALL:
2585 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2587 case PROP_HAS_TOOLTIP:
2588 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2590 case PROP_TOOLTIP_TEXT:
2592 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2595 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2596 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2598 g_value_set_string (value, text);
2602 case PROP_TOOLTIP_MARKUP:
2603 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2606 g_value_set_object (value, gtk_widget_get_window (widget));
2609 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2615 gtk_widget_init (GtkWidget *widget)
2617 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2618 widget->state = GTK_STATE_NORMAL;
2619 widget->saved_state = GTK_STATE_NORMAL;
2620 widget->name = NULL;
2621 widget->requisition.width = 0;
2622 widget->requisition.height = 0;
2623 widget->allocation.x = -1;
2624 widget->allocation.y = -1;
2625 widget->allocation.width = 1;
2626 widget->allocation.height = 1;
2627 widget->window = NULL;
2628 widget->parent = NULL;
2630 GTK_WIDGET_SET_FLAGS (widget,
2632 GTK_PARENT_SENSITIVE |
2633 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2634 GTK_DOUBLE_BUFFERED);
2636 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2637 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2638 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2640 widget->style = gtk_widget_get_default_style ();
2641 g_object_ref (widget->style);
2646 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2648 GParamSpec **pspecs)
2650 GtkWidget *container = widget->parent;
2653 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2654 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2658 * gtk_widget_freeze_child_notify:
2659 * @widget: a #GtkWidget
2661 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2662 * signals are queued until gtk_widget_thaw_child_notify() is called
2665 * This is the analogue of g_object_freeze_notify() for child properties.
2668 gtk_widget_freeze_child_notify (GtkWidget *widget)
2670 g_return_if_fail (GTK_IS_WIDGET (widget));
2672 if (!G_OBJECT (widget)->ref_count)
2675 g_object_ref (widget);
2676 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2677 g_object_unref (widget);
2681 * gtk_widget_child_notify:
2682 * @widget: a #GtkWidget
2683 * @child_property: the name of a child property installed on the
2684 * class of @widget<!-- -->'s parent
2686 * Emits a #GtkWidget::child-notify signal for the
2687 * <link linkend="child-properties">child property</link> @child_property
2690 * This is the analogue of g_object_notify() for child properties.
2693 gtk_widget_child_notify (GtkWidget *widget,
2694 const gchar *child_property)
2698 g_return_if_fail (GTK_IS_WIDGET (widget));
2699 g_return_if_fail (child_property != NULL);
2700 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2703 g_object_ref (widget);
2704 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2706 G_OBJECT_TYPE (widget->parent),
2709 g_warning ("%s: container class `%s' has no child property named `%s'",
2711 G_OBJECT_TYPE_NAME (widget->parent),
2715 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2717 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2718 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2720 g_object_unref (widget);
2724 * gtk_widget_thaw_child_notify:
2725 * @widget: a #GtkWidget
2727 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2728 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2732 gtk_widget_thaw_child_notify (GtkWidget *widget)
2734 GObjectNotifyQueue *nqueue;
2736 g_return_if_fail (GTK_IS_WIDGET (widget));
2738 if (!G_OBJECT (widget)->ref_count)
2741 g_object_ref (widget);
2742 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2743 if (!nqueue || !nqueue->freeze_count)
2744 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2745 G_OBJECT_TYPE_NAME (widget), widget);
2747 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2748 g_object_unref (widget);
2754 * @type: type ID of the widget to create
2755 * @first_property_name: name of first property to set
2756 * @Varargs: value of first property, followed by more properties,
2759 * This is a convenience function for creating a widget and setting
2760 * its properties in one go. For example you might write:
2761 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2762 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2763 * g_object_new(), but returns a widget so you don't have to
2764 * cast the object yourself.
2766 * Return value: a new #GtkWidget of type @widget_type
2769 gtk_widget_new (GType type,
2770 const gchar *first_property_name,
2776 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2778 va_start (var_args, first_property_name);
2779 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2787 * @widget: a #GtkWidget
2788 * @first_property_name: name of first property to set
2789 * @Varargs: value of first property, followed by more properties,
2792 * Precursor of g_object_set().
2794 * Deprecated: 2.0: Use g_object_set() instead.
2797 gtk_widget_set (GtkWidget *widget,
2798 const gchar *first_property_name,
2803 g_return_if_fail (GTK_IS_WIDGET (widget));
2805 va_start (var_args, first_property_name);
2806 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2811 gtk_widget_queue_draw_child (GtkWidget *widget)
2815 parent = widget->parent;
2816 if (parent && GTK_WIDGET_DRAWABLE (parent))
2817 gtk_widget_queue_draw_area (parent,
2818 widget->allocation.x,
2819 widget->allocation.y,
2820 widget->allocation.width,
2821 widget->allocation.height);
2825 * gtk_widget_unparent:
2826 * @widget: a #GtkWidget
2828 * This function is only for use in widget implementations.
2829 * Should be called by implementations of the remove method
2830 * on #GtkContainer, to dissociate a child from the container.
2833 gtk_widget_unparent (GtkWidget *widget)
2835 GObjectNotifyQueue *nqueue;
2836 GtkWidget *toplevel;
2837 GtkWidget *old_parent;
2839 g_return_if_fail (GTK_IS_WIDGET (widget));
2840 if (widget->parent == NULL)
2843 /* keep this function in sync with gtk_menu_detach()
2846 g_object_freeze_notify (G_OBJECT (widget));
2847 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2849 toplevel = gtk_widget_get_toplevel (widget);
2850 if (GTK_WIDGET_TOPLEVEL (toplevel))
2851 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2853 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2854 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2856 /* If we are unanchoring the child, we save around the toplevel
2857 * to emit hierarchy changed
2859 if (GTK_WIDGET_ANCHORED (widget->parent))
2860 g_object_ref (toplevel);
2864 gtk_widget_queue_draw_child (widget);
2866 /* Reset the width and height here, to force reallocation if we
2867 * get added back to a new parent. This won't work if our new
2868 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2869 * (would 0x0 be OK here?)
2871 widget->allocation.width = 1;
2872 widget->allocation.height = 1;
2874 if (GTK_WIDGET_REALIZED (widget))
2876 if (GTK_WIDGET_IN_REPARENT (widget))
2877 gtk_widget_unmap (widget);
2879 gtk_widget_unrealize (widget);
2882 /* Removing a widget from a container restores the child visible
2883 * flag to the default state, so it doesn't affect the child
2884 * in the next parent.
2886 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2888 old_parent = widget->parent;
2889 widget->parent = NULL;
2890 gtk_widget_set_parent_window (widget, NULL);
2891 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2894 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2895 g_object_unref (toplevel);
2898 g_object_notify (G_OBJECT (widget), "parent");
2899 g_object_thaw_notify (G_OBJECT (widget));
2900 if (!widget->parent)
2901 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2902 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2903 g_object_unref (widget);
2907 * gtk_widget_destroy:
2908 * @widget: a #GtkWidget
2910 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2911 * you don't have to cast the widget to #GtkObject. When a widget is
2912 * destroyed, it will break any references it holds to other objects.
2913 * If the widget is inside a container, the widget will be removed
2914 * from the container. If the widget is a toplevel (derived from
2915 * #GtkWindow), it will be removed from the list of toplevels, and the
2916 * reference GTK+ holds to it will be removed. Removing a
2917 * widget from its container or the list of toplevels results in the
2918 * widget being finalized, unless you've added additional references
2919 * to the widget with g_object_ref().
2921 * In most cases, only toplevel widgets (windows) require explicit
2922 * destruction, because when you destroy a toplevel its children will
2923 * be destroyed as well.
2926 gtk_widget_destroy (GtkWidget *widget)
2928 g_return_if_fail (GTK_IS_WIDGET (widget));
2930 gtk_object_destroy ((GtkObject*) widget);
2934 * gtk_widget_destroyed:
2935 * @widget: a #GtkWidget
2936 * @widget_pointer: address of a variable that contains @widget
2938 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2939 * %NULL. It's intended to be used as a callback connected to the
2940 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2941 * as a signal handler, and pass the address of your widget variable
2942 * as user data. Then when the widget is destroyed, the variable will
2943 * be set to %NULL. Useful for example to avoid multiple copies
2944 * of the same dialog.
2947 gtk_widget_destroyed (GtkWidget *widget,
2948 GtkWidget **widget_pointer)
2950 /* Don't make any assumptions about the
2952 * Even check widget_pointer.
2955 *widget_pointer = NULL;
2960 * @widget: a #GtkWidget
2962 * Flags a widget to be displayed. Any widget that isn't shown will
2963 * not appear on the screen. If you want to show all the widgets in a
2964 * container, it's easier to call gtk_widget_show_all() on the
2965 * container, instead of individually showing the widgets.
2967 * Remember that you have to show the containers containing a widget,
2968 * in addition to the widget itself, before it will appear onscreen.
2970 * When a toplevel container is shown, it is immediately realized and
2971 * mapped; other shown widgets are realized and mapped when their
2972 * toplevel container is realized and mapped.
2975 gtk_widget_show (GtkWidget *widget)
2977 g_return_if_fail (GTK_IS_WIDGET (widget));
2979 if (!GTK_WIDGET_VISIBLE (widget))
2981 g_object_ref (widget);
2982 if (!GTK_WIDGET_TOPLEVEL (widget))
2983 gtk_widget_queue_resize (widget);
2984 g_signal_emit (widget, widget_signals[SHOW], 0);
2985 g_object_notify (G_OBJECT (widget), "visible");
2986 g_object_unref (widget);
2991 gtk_widget_real_show (GtkWidget *widget)
2993 if (!GTK_WIDGET_VISIBLE (widget))
2995 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2997 if (widget->parent &&
2998 GTK_WIDGET_MAPPED (widget->parent) &&
2999 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3000 !GTK_WIDGET_MAPPED (widget))
3001 gtk_widget_map (widget);
3006 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3009 g_signal_handlers_disconnect_by_func (widget,
3010 gtk_widget_show_map_callback,
3015 * gtk_widget_show_now:
3016 * @widget: a #GtkWidget
3018 * Shows a widget. If the widget is an unmapped toplevel widget
3019 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3020 * loop and wait for the window to actually be mapped. Be careful;
3021 * because the main loop is running, anything can happen during
3025 gtk_widget_show_now (GtkWidget *widget)
3029 g_return_if_fail (GTK_IS_WIDGET (widget));
3031 /* make sure we will get event */
3032 if (!GTK_WIDGET_MAPPED (widget) &&
3033 GTK_WIDGET_TOPLEVEL (widget))
3035 gtk_widget_show (widget);
3037 g_signal_connect (widget, "map_event",
3038 G_CALLBACK (gtk_widget_show_map_callback),
3042 gtk_main_iteration ();
3045 gtk_widget_show (widget);
3050 * @widget: a #GtkWidget
3052 * Reverses the effects of gtk_widget_show(), causing the widget to be
3053 * hidden (invisible to the user).
3056 gtk_widget_hide (GtkWidget *widget)
3058 g_return_if_fail (GTK_IS_WIDGET (widget));
3060 if (GTK_WIDGET_VISIBLE (widget))
3062 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3064 g_object_ref (widget);
3065 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3066 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3068 g_signal_emit (widget, widget_signals[HIDE], 0);
3069 if (!GTK_WIDGET_TOPLEVEL (widget))
3070 gtk_widget_queue_resize (widget);
3071 g_object_notify (G_OBJECT (widget), "visible");
3072 g_object_unref (widget);
3077 gtk_widget_real_hide (GtkWidget *widget)
3079 if (GTK_WIDGET_VISIBLE (widget))
3081 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3083 if (GTK_WIDGET_MAPPED (widget))
3084 gtk_widget_unmap (widget);
3089 * gtk_widget_hide_on_delete:
3090 * @widget: a #GtkWidget
3092 * Utility function; intended to be connected to the #GtkWidget::delete-event
3093 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3094 * argument, then returns %TRUE. If connected to ::delete-event, the
3095 * result is that clicking the close button for a window (on the
3096 * window frame, top right corner usually) will hide but not destroy
3097 * the window. By default, GTK+ destroys windows when ::delete-event
3100 * Return value: %TRUE
3103 gtk_widget_hide_on_delete (GtkWidget *widget)
3105 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3107 gtk_widget_hide (widget);
3113 * gtk_widget_show_all:
3114 * @widget: a #GtkWidget
3116 * Recursively shows a widget, and any child widgets (if the widget is
3120 gtk_widget_show_all (GtkWidget *widget)
3122 GtkWidgetClass *class;
3124 g_return_if_fail (GTK_IS_WIDGET (widget));
3126 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3129 class = GTK_WIDGET_GET_CLASS (widget);
3131 if (class->show_all)
3132 class->show_all (widget);
3136 * gtk_widget_hide_all:
3137 * @widget: a #GtkWidget
3139 * Recursively hides a widget and any child widgets.
3142 gtk_widget_hide_all (GtkWidget *widget)
3144 GtkWidgetClass *class;
3146 g_return_if_fail (GTK_IS_WIDGET (widget));
3148 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3151 class = GTK_WIDGET_GET_CLASS (widget);
3153 if (class->hide_all)
3154 class->hide_all (widget);
3159 * @widget: a #GtkWidget
3161 * This function is only for use in widget implementations. Causes
3162 * a widget to be mapped if it isn't already.
3165 gtk_widget_map (GtkWidget *widget)
3167 g_return_if_fail (GTK_IS_WIDGET (widget));
3168 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3169 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3171 if (!GTK_WIDGET_MAPPED (widget))
3173 if (!GTK_WIDGET_REALIZED (widget))
3174 gtk_widget_realize (widget);
3176 g_signal_emit (widget, widget_signals[MAP], 0);
3178 if (GTK_WIDGET_NO_WINDOW (widget))
3179 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3185 * @widget: a #GtkWidget
3187 * This function is only for use in widget implementations. Causes
3188 * a widget to be unmapped if it's currently mapped.
3191 gtk_widget_unmap (GtkWidget *widget)
3193 g_return_if_fail (GTK_IS_WIDGET (widget));
3195 if (GTK_WIDGET_MAPPED (widget))
3197 if (GTK_WIDGET_NO_WINDOW (widget))
3198 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3199 _gtk_tooltip_hide (widget);
3200 g_signal_emit (widget, widget_signals[UNMAP], 0);
3205 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3206 GdkExtensionMode mode,
3209 GList *free_list = NULL;
3212 if (window_list == NULL)
3214 if (!GTK_WIDGET_NO_WINDOW (widget))
3215 window_list = g_list_prepend (NULL, widget->window);
3217 window_list = gdk_window_get_children (widget->window);
3219 free_list = window_list;
3222 for (l = window_list; l != NULL; l = l->next)
3224 GdkWindow *window = l->data;
3227 gdk_window_get_user_data (window, &user_data);
3228 if (user_data == widget)
3232 gdk_input_set_extension_events (window,
3233 gdk_window_get_events (window),
3236 children = gdk_window_get_children (window);
3239 gtk_widget_set_extension_events_internal (widget, mode, children);
3240 g_list_free (children);
3246 g_list_free (free_list);
3250 * gtk_widget_realize:
3251 * @widget: a #GtkWidget
3253 * Creates the GDK (windowing system) resources associated with a
3254 * widget. For example, @widget->window will be created when a widget
3255 * is realized. Normally realization happens implicitly; if you show
3256 * a widget and all its parent containers, then the widget will be
3257 * realized and mapped automatically.
3259 * Realizing a widget requires all
3260 * the widget's parent widgets to be realized; calling
3261 * gtk_widget_realize() realizes the widget's parents in addition to
3262 * @widget itself. If a widget is not yet inside a toplevel window
3263 * when you realize it, bad things will happen.
3265 * This function is primarily used in widget implementations, and
3266 * isn't very useful otherwise. Many times when you think you might
3267 * need it, a better approach is to connect to a signal that will be
3268 * called after the widget is realized automatically, such as
3269 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3270 * GtkWidget::realize signal.
3273 gtk_widget_realize (GtkWidget *widget)
3275 GdkExtensionMode mode;
3276 GtkWidgetShapeInfo *shape_info;
3278 g_return_if_fail (GTK_IS_WIDGET (widget));
3279 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3280 GTK_IS_INVISIBLE (widget));
3282 if (!GTK_WIDGET_REALIZED (widget))
3285 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3286 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3289 if (widget->parent == NULL &&
3290 !GTK_WIDGET_TOPLEVEL (widget))
3291 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3292 "inside a toplevel window is not going to work very well. "
3293 "Widgets must be inside a toplevel container before realizing them.");
3295 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3296 gtk_widget_realize (widget->parent);
3298 gtk_widget_ensure_style (widget);
3300 g_signal_emit (widget, widget_signals[REALIZE], 0);
3302 gtk_widget_real_set_has_tooltip (widget,
3303 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3306 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3308 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3309 gdk_window_shape_combine_mask (widget->window,
3310 shape_info->shape_mask,
3311 shape_info->offset_x,
3312 shape_info->offset_y);
3315 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3317 gdk_window_input_shape_combine_mask (widget->window,
3318 shape_info->shape_mask,
3319 shape_info->offset_x,
3320 shape_info->offset_y);
3322 mode = gtk_widget_get_extension_events (widget);
3323 if (mode != GDK_EXTENSION_EVENTS_NONE)
3324 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3329 * gtk_widget_unrealize:
3330 * @widget: a #GtkWidget
3332 * This function is only useful in widget implementations.
3333 * Causes a widget to be unrealized (frees all GDK resources
3334 * associated with the widget, such as @widget->window).
3337 gtk_widget_unrealize (GtkWidget *widget)
3339 g_return_if_fail (GTK_IS_WIDGET (widget));
3341 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3342 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3344 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3345 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3347 if (GTK_WIDGET_REALIZED (widget))
3349 g_object_ref (widget);
3350 _gtk_tooltip_hide (widget);
3351 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3352 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3353 g_object_unref (widget);
3357 /*****************************************
3359 *****************************************/
3362 * gtk_widget_queue_draw_area:
3363 * @widget: a #GtkWidget
3364 * @x: x coordinate of upper-left corner of rectangle to redraw
3365 * @y: y coordinate of upper-left corner of rectangle to redraw
3366 * @width: width of region to draw
3367 * @height: height of region to draw
3369 * Invalidates the rectangular area of @widget defined by @x, @y,
3370 * @width and @height by calling gdk_window_invalidate_rect() on the
3371 * widget's window and all its child windows. Once the main loop
3372 * becomes idle (after the current batch of events has been processed,
3373 * roughly), the window will receive expose events for the union of
3374 * all regions that have been invalidated.
3376 * Normally you would only use this function in widget
3377 * implementations. You might also use it, or
3378 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3379 * #GtkDrawingArea or some portion thereof.
3381 * Frequently you can just call gdk_window_invalidate_rect() or
3382 * gdk_window_invalidate_region() instead of this function. Those
3383 * functions will invalidate only a single window, instead of the
3384 * widget and all its children.
3386 * The advantage of adding to the invalidated region compared to
3387 * simply drawing immediately is efficiency; using an invalid region
3388 * ensures that you only have to redraw one time.
3391 gtk_widget_queue_draw_area (GtkWidget *widget,
3397 GdkRectangle invalid_rect;
3400 g_return_if_fail (GTK_IS_WIDGET (widget));
3402 if (!GTK_WIDGET_REALIZED (widget))
3405 /* Just return if the widget or one of its ancestors isn't mapped */
3406 for (w = widget; w != NULL; w = w->parent)
3407 if (!GTK_WIDGET_MAPPED (w))
3410 /* Find the correct widget */
3412 if (!GTK_WIDGET_NO_WINDOW (widget))
3416 /* Translate widget relative to window-relative */
3418 gint wx, wy, wwidth, wheight;
3420 gdk_window_get_position (widget->window, &wx, &wy);
3421 x -= wx - widget->allocation.x;
3422 y -= wy - widget->allocation.y;
3424 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3426 if (x + width <= 0 || y + height <= 0 ||
3427 x >= wwidth || y >= wheight)
3438 if (x + width > wwidth)
3440 if (y + height > wheight)
3441 height = wheight - y;
3447 invalid_rect.width = width;
3448 invalid_rect.height = height;
3450 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3454 widget_add_child_draw_rectangle (GtkWidget *widget,
3457 GdkRectangle child_rect;
3459 if (!GTK_WIDGET_MAPPED (widget) ||
3460 widget->window != widget->parent->window)
3463 gtk_widget_get_draw_rectangle (widget, &child_rect);
3464 gdk_rectangle_union (rect, &child_rect, rect);
3468 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3471 if (GTK_WIDGET_NO_WINDOW (widget))
3473 GtkBorder *draw_border = NULL;
3475 *rect = widget->allocation;
3477 gtk_widget_style_get (widget,
3478 "draw-border", &draw_border,
3482 rect->x -= draw_border->top;
3483 rect->y -= draw_border->left;
3484 rect->width += draw_border->left + draw_border->right;
3485 rect->height += draw_border->top + draw_border->bottom;
3487 gtk_border_free (draw_border);
3490 if (GTK_IS_CONTAINER (widget))
3491 gtk_container_forall (GTK_CONTAINER (widget),
3492 (GtkCallback)widget_add_child_draw_rectangle,
3499 rect->width = widget->allocation.width;
3500 rect->height = widget->allocation.height;
3505 * gtk_widget_queue_draw:
3506 * @widget: a #GtkWidget
3508 * Equivalent to calling gtk_widget_queue_draw_area() for the
3509 * entire area of a widget.
3512 gtk_widget_queue_draw (GtkWidget *widget)
3516 g_return_if_fail (GTK_IS_WIDGET (widget));
3518 gtk_widget_get_draw_rectangle (widget, &rect);
3520 gtk_widget_queue_draw_area (widget,
3522 rect.width, rect.height);
3525 /* Invalidates the given area (allocation-relative-coordinates)
3526 * in all of the widget's windows
3529 * gtk_widget_queue_clear_area:
3530 * @widget: a #GtkWidget
3531 * @x: x coordinate of upper-left corner of rectangle to redraw
3532 * @y: y coordinate of upper-left corner of rectangle to redraw
3533 * @width: width of region to draw
3534 * @height: height of region to draw
3536 * This function is no longer different from
3537 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3538 * gtk_widget_queue_draw_area(). Originally
3539 * gtk_widget_queue_clear_area() would force a redraw of the
3540 * background for %GTK_NO_WINDOW widgets, and
3541 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3542 * the background will be redrawn.
3544 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3547 gtk_widget_queue_clear_area (GtkWidget *widget,
3553 g_return_if_fail (GTK_IS_WIDGET (widget));
3555 gtk_widget_queue_draw_area (widget, x, y, width, height);
3559 * gtk_widget_queue_clear:
3560 * @widget: a #GtkWidget
3562 * This function does the same as gtk_widget_queue_draw().
3564 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3567 gtk_widget_queue_clear (GtkWidget *widget)
3569 g_return_if_fail (GTK_IS_WIDGET (widget));
3571 gtk_widget_queue_draw (widget);
3575 * gtk_widget_queue_resize:
3576 * @widget: a #GtkWidget
3578 * This function is only for use in widget implementations.
3579 * Flags a widget to have its size renegotiated; should
3580 * be called when a widget for some reason has a new size request.
3581 * For example, when you change the text in a #GtkLabel, #GtkLabel
3582 * queues a resize to ensure there's enough space for the new text.
3585 gtk_widget_queue_resize (GtkWidget *widget)
3587 g_return_if_fail (GTK_IS_WIDGET (widget));
3589 if (GTK_WIDGET_REALIZED (widget))
3590 gtk_widget_queue_shallow_draw (widget);
3592 _gtk_size_group_queue_resize (widget);
3596 * gtk_widget_queue_resize_no_redraw:
3597 * @widget: a #GtkWidget
3599 * This function works like gtk_widget_queue_resize(),
3600 * except that the widget is not invalidated.
3605 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3607 g_return_if_fail (GTK_IS_WIDGET (widget));
3609 _gtk_size_group_queue_resize (widget);
3614 * @widget: a #GtkWidget
3615 * @area: area to draw
3617 * In GTK+ 1.2, this function would immediately render the
3618 * region @area of a widget, by invoking the virtual draw method of a
3619 * widget. In GTK+ 2.0, the draw method is gone, and instead
3620 * gtk_widget_draw() simply invalidates the specified region of the
3621 * widget, then updates the invalid region of the widget immediately.
3622 * Usually you don't want to update the region immediately for
3623 * performance reasons, so in general gtk_widget_queue_draw_area() is
3624 * a better choice if you want to draw a region of a widget.
3627 gtk_widget_draw (GtkWidget *widget,
3628 const GdkRectangle *area)
3630 g_return_if_fail (GTK_IS_WIDGET (widget));
3632 if (GTK_WIDGET_DRAWABLE (widget))
3635 gtk_widget_queue_draw_area (widget,
3637 area->width, area->height);
3639 gtk_widget_queue_draw (widget);
3641 gdk_window_process_updates (widget->window, TRUE);
3646 * gtk_widget_size_request:
3647 * @widget: a #GtkWidget
3648 * @requisition: a #GtkRequisition to be filled in
3650 * This function is typically used when implementing a #GtkContainer
3651 * subclass. Obtains the preferred size of a widget. The container
3652 * uses this information to arrange its child widgets and decide what
3653 * size allocations to give them with gtk_widget_size_allocate().
3655 * You can also call this function from an application, with some
3656 * caveats. Most notably, getting a size request requires the widget
3657 * to be associated with a screen, because font information may be
3658 * needed. Multihead-aware applications should keep this in mind.
3660 * Also remember that the size request is not necessarily the size
3661 * a widget will actually be allocated.
3663 * See also gtk_widget_get_child_requisition().
3666 gtk_widget_size_request (GtkWidget *widget,
3667 GtkRequisition *requisition)
3669 g_return_if_fail (GTK_IS_WIDGET (widget));
3671 #ifdef G_ENABLE_DEBUG
3672 if (requisition == &widget->requisition)
3673 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.");
3674 #endif /* G_ENABLE_DEBUG */
3676 _gtk_size_group_compute_requisition (widget, requisition);
3680 * gtk_widget_get_child_requisition:
3681 * @widget: a #GtkWidget
3682 * @requisition: a #GtkRequisition to be filled in
3684 * This function is only for use in widget implementations. Obtains
3685 * @widget->requisition, unless someone has forced a particular
3686 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3687 * in which case it returns that geometry instead of the widget's
3690 * This function differs from gtk_widget_size_request() in that
3691 * it retrieves the last size request value from @widget->requisition,
3692 * while gtk_widget_size_request() actually calls the "size_request" method
3693 * on @widget to compute the size request and fill in @widget->requisition,
3694 * and only then returns @widget->requisition.
3696 * Because this function does not call the "size_request" method, it
3697 * can only be used when you know that @widget->requisition is
3698 * up-to-date, that is, gtk_widget_size_request() has been called
3699 * since the last time a resize was queued. In general, only container
3700 * implementations have this information; applications should use
3701 * gtk_widget_size_request().
3704 gtk_widget_get_child_requisition (GtkWidget *widget,
3705 GtkRequisition *requisition)
3707 _gtk_size_group_get_child_requisition (widget, requisition);
3711 invalidate_predicate (GdkWindow *window,
3716 gdk_window_get_user_data (window, &user_data);
3718 return (user_data == data);
3721 /* Invalidate @region in widget->window and all children
3722 * of widget->window owned by widget. @region is in the
3723 * same coordinates as widget->allocation and will be
3724 * modified by this call.
3727 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3730 if (!GTK_WIDGET_REALIZED (widget))
3733 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3737 gdk_window_get_position (widget->window, &x, &y);
3738 gdk_region_offset (region, -x, -y);
3741 gdk_window_invalidate_maybe_recurse (widget->window, region,
3742 invalidate_predicate, widget);
3746 * gtk_widget_queue_shallow_draw:
3747 * @widget: a #GtkWidget
3749 * Like gtk_widget_queue_draw(), but only windows owned
3750 * by @widget are invalidated.
3753 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3758 if (!GTK_WIDGET_REALIZED (widget))
3761 gtk_widget_get_draw_rectangle (widget, &rect);
3763 /* get_draw_rectangle() gives us window coordinates, we
3764 * need to convert to the coordinates that widget->allocation
3767 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3771 gdk_window_get_position (widget->window, &wx, &wy);
3777 region = gdk_region_rectangle (&rect);
3778 gtk_widget_invalidate_widget_windows (widget, region);
3779 gdk_region_destroy (region);
3783 * gtk_widget_size_allocate:
3784 * @widget: a #GtkWidget
3785 * @allocation: position and size to be allocated to @widget
3787 * This function is only used by #GtkContainer subclasses, to assign a size
3788 * and position to their child widgets.
3791 gtk_widget_size_allocate (GtkWidget *widget,
3792 GtkAllocation *allocation)
3794 GtkWidgetAuxInfo *aux_info;
3795 GdkRectangle real_allocation;
3796 GdkRectangle old_allocation;
3797 gboolean alloc_needed;
3798 gboolean size_changed;
3799 gboolean position_changed;
3801 g_return_if_fail (GTK_IS_WIDGET (widget));
3803 #ifdef G_ENABLE_DEBUG
3804 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3815 parent = gtk_widget_get_parent (parent);
3818 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3819 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3820 2 * depth, " ", name,
3821 allocation->width, allocation->height);
3823 #endif /* G_ENABLE_DEBUG */
3825 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3826 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3827 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3829 old_allocation = widget->allocation;
3830 real_allocation = *allocation;
3831 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3835 if (aux_info->x_set)
3836 real_allocation.x = aux_info->x;
3837 if (aux_info->y_set)
3838 real_allocation.y = aux_info->y;
3841 if (real_allocation.width < 0 || real_allocation.height < 0)
3843 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3844 real_allocation.width,
3845 real_allocation.height);
3848 real_allocation.width = MAX (real_allocation.width, 1);
3849 real_allocation.height = MAX (real_allocation.height, 1);
3851 size_changed = (old_allocation.width != real_allocation.width ||
3852 old_allocation.height != real_allocation.height);
3853 position_changed = (old_allocation.x != real_allocation.x ||
3854 old_allocation.y != real_allocation.y);
3856 if (!alloc_needed && !size_changed && !position_changed)
3859 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3861 if (GTK_WIDGET_MAPPED (widget))
3863 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3865 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3867 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3868 gdk_region_union_with_rect (invalidate, &old_allocation);
3870 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3871 gdk_region_destroy (invalidate);
3876 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3878 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3880 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3881 gdk_region_union_with_rect (invalidate, &old_allocation);
3883 gtk_widget_invalidate_widget_windows (widget, invalidate);
3884 gdk_region_destroy (invalidate);
3889 if ((size_changed || position_changed) && widget->parent &&
3890 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3892 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3893 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3894 gdk_region_destroy (invalidate);
3899 * gtk_widget_common_ancestor:
3900 * @widget_a: a #GtkWidget
3901 * @widget_b: a #GtkWidget
3903 * Find the common ancestor of @widget_a and @widget_b that
3904 * is closest to the two widgets.
3906 * Return value: the closest common ancestor of @widget_a and
3907 * @widget_b or %NULL if @widget_a and @widget_b do not
3908 * share a common ancestor.
3911 gtk_widget_common_ancestor (GtkWidget *widget_a,
3912 GtkWidget *widget_b)
3914 GtkWidget *parent_a;
3915 GtkWidget *parent_b;
3919 parent_a = widget_a;
3920 while (parent_a->parent)
3922 parent_a = parent_a->parent;
3926 parent_b = widget_b;
3927 while (parent_b->parent)
3929 parent_b = parent_b->parent;
3933 if (parent_a != parent_b)
3936 while (depth_a > depth_b)
3938 widget_a = widget_a->parent;
3942 while (depth_b > depth_a)
3944 widget_b = widget_b->parent;
3948 while (widget_a != widget_b)
3950 widget_a = widget_a->parent;
3951 widget_b = widget_b->parent;
3958 * gtk_widget_translate_coordinates:
3959 * @src_widget: a #GtkWidget
3960 * @dest_widget: a #GtkWidget
3961 * @src_x: X position relative to @src_widget
3962 * @src_y: Y position relative to @src_widget
3963 * @dest_x: location to store X position relative to @dest_widget
3964 * @dest_y: location to store Y position relative to @dest_widget
3966 * Translate coordinates relative to @src_widget's allocation to coordinates
3967 * relative to @dest_widget's allocations. In order to perform this
3968 * operation, both widgets must be realized, and must share a common
3971 * Return value: %FALSE if either widget was not realized, or there
3972 * was no common ancestor. In this case, nothing is stored in
3973 * *@dest_x and *@dest_y. Otherwise %TRUE.
3976 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3977 GtkWidget *dest_widget,
3983 GtkWidget *ancestor;
3986 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3987 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3989 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3990 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3993 /* Translate from allocation relative to window relative */
3994 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3997 gdk_window_get_position (src_widget->window, &wx, &wy);
3999 src_x -= wx - src_widget->allocation.x;
4000 src_y -= wy - src_widget->allocation.y;
4004 src_x += src_widget->allocation.x;
4005 src_y += src_widget->allocation.y;
4008 /* Translate to the common ancestor */
4009 window = src_widget->window;
4010 while (window != ancestor->window)
4014 gdk_window_get_position (window, &dx, &dy);
4019 window = gdk_window_get_parent (window);
4021 if (!window) /* Handle GtkHandleBox */
4026 window = dest_widget->window;
4027 while (window != ancestor->window)
4031 gdk_window_get_position (window, &dx, &dy);
4036 window = gdk_window_get_parent (window);
4038 if (!window) /* Handle GtkHandleBox */
4042 /* Translate from window relative to allocation relative */
4043 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4046 gdk_window_get_position (dest_widget->window, &wx, &wy);
4048 src_x += wx - dest_widget->allocation.x;
4049 src_y += wy - dest_widget->allocation.y;
4053 src_x -= dest_widget->allocation.x;
4054 src_y -= dest_widget->allocation.y;
4066 gtk_widget_real_size_allocate (GtkWidget *widget,
4067 GtkAllocation *allocation)
4069 widget->allocation = *allocation;
4071 if (GTK_WIDGET_REALIZED (widget) &&
4072 !GTK_WIDGET_NO_WINDOW (widget))
4074 gdk_window_move_resize (widget->window,
4075 allocation->x, allocation->y,
4076 allocation->width, allocation->height);
4081 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4084 /* widgets must be onscreen for accels to take effect */
4085 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4089 * gtk_widget_can_activate_accel:
4090 * @widget: a #GtkWidget
4091 * @signal_id: the ID of a signal installed on @widget
4093 * Determines whether an accelerator that activates the signal
4094 * identified by @signal_id can currently be activated.
4095 * This is done by emitting the #GtkWidget::can-activate-accel
4096 * signal on @widget; if the signal isn't overridden by a
4097 * handler or in a derived widget, then the default check is
4098 * that the widget must be sensitive, and the widget and all
4099 * its ancestors mapped.
4101 * Return value: %TRUE if the accelerator can be activated.
4106 gtk_widget_can_activate_accel (GtkWidget *widget,
4109 gboolean can_activate = FALSE;
4110 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4111 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4112 return can_activate;
4121 closure_accel_activate (GClosure *closure,
4122 GValue *return_value,
4123 guint n_param_values,
4124 const GValue *param_values,
4125 gpointer invocation_hint,
4126 gpointer marshal_data)
4128 AccelClosure *aclosure = (AccelClosure*) closure;
4129 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4132 g_signal_emit (closure->data, aclosure->signal_id, 0);
4134 /* whether accelerator was handled */
4135 g_value_set_boolean (return_value, can_activate);
4139 closures_destroy (gpointer data)
4141 GSList *slist, *closures = data;
4143 for (slist = closures; slist; slist = slist->next)
4145 g_closure_invalidate (slist->data);
4146 g_closure_unref (slist->data);
4148 g_slist_free (closures);
4152 widget_new_accel_closure (GtkWidget *widget,
4155 AccelClosure *aclosure;
4156 GClosure *closure = NULL;
4157 GSList *slist, *closures;
4159 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4160 for (slist = closures; slist; slist = slist->next)
4161 if (!gtk_accel_group_from_accel_closure (slist->data))
4163 /* reuse this closure */
4164 closure = slist->data;
4169 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4170 closures = g_slist_prepend (closures, g_closure_ref (closure));
4171 g_closure_sink (closure);
4172 g_closure_set_marshal (closure, closure_accel_activate);
4174 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4176 aclosure = (AccelClosure*) closure;
4177 g_assert (closure->data == widget);
4178 g_assert (closure->marshal == closure_accel_activate);
4179 aclosure->signal_id = signal_id;
4185 * gtk_widget_add_accelerator
4186 * @widget: widget to install an accelerator on
4187 * @accel_signal: widget signal to emit on accelerator activation
4188 * @accel_group: accel group for this widget, added to its toplevel
4189 * @accel_key: GDK keyval of the accelerator
4190 * @accel_mods: modifier key combination of the accelerator
4191 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4193 * Installs an accelerator for this @widget in @accel_group that causes
4194 * @accel_signal to be emitted if the accelerator is activated.
4195 * The @accel_group needs to be added to the widget's toplevel via
4196 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4197 * Accelerators added through this function are not user changeable during
4198 * runtime. If you want to support accelerators that can be changed by the
4199 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4200 * gtk_menu_item_set_accel_path() instead.
4203 gtk_widget_add_accelerator (GtkWidget *widget,
4204 const gchar *accel_signal,
4205 GtkAccelGroup *accel_group,
4207 GdkModifierType accel_mods,
4208 GtkAccelFlags accel_flags)
4213 g_return_if_fail (GTK_IS_WIDGET (widget));
4214 g_return_if_fail (accel_signal != NULL);
4215 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4217 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4218 if (!query.signal_id ||
4219 !(query.signal_flags & G_SIGNAL_ACTION) ||
4220 query.return_type != G_TYPE_NONE ||
4223 /* hmm, should be elaborate enough */
4224 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4225 G_OBJECT_TYPE_NAME (widget), accel_signal);
4229 closure = widget_new_accel_closure (widget, query.signal_id);
4231 g_object_ref (widget);
4233 /* install the accelerator. since we don't map this onto an accel_path,
4234 * the accelerator will automatically be locked.
4236 gtk_accel_group_connect (accel_group,
4239 accel_flags | GTK_ACCEL_LOCKED,
4242 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4244 g_object_unref (widget);
4248 * gtk_widget_remove_accelerator:
4249 * @widget: widget to install an accelerator on
4250 * @accel_group: accel group for this widget
4251 * @accel_key: GDK keyval of the accelerator
4252 * @accel_mods: modifier key combination of the accelerator
4253 * @returns: whether an accelerator was installed and could be removed
4255 * Removes an accelerator from @widget, previously installed with
4256 * gtk_widget_add_accelerator().
4259 gtk_widget_remove_accelerator (GtkWidget *widget,
4260 GtkAccelGroup *accel_group,
4262 GdkModifierType accel_mods)
4264 GtkAccelGroupEntry *ag_entry;
4265 GList *slist, *clist;
4268 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4269 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4271 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4272 clist = gtk_widget_list_accel_closures (widget);
4273 for (slist = clist; slist; slist = slist->next)
4277 for (i = 0; i < n; i++)
4278 if (slist->data == (gpointer) ag_entry[i].closure)
4280 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4282 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4284 g_list_free (clist);
4289 g_list_free (clist);
4291 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4292 accel_key, accel_mods, accel_group,
4293 G_OBJECT_TYPE_NAME (widget), widget);
4299 * gtk_widget_list_accel_closures
4300 * @widget: widget to list accelerator closures for
4301 * @returns: a newly allocated #GList of closures
4303 * Lists the closures used by @widget for accelerator group connections
4304 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4305 * The closures can be used to monitor accelerator changes on @widget,
4306 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4307 * #GtkAccelGroup of a closure which can be found out with
4308 * gtk_accel_group_from_accel_closure().
4311 gtk_widget_list_accel_closures (GtkWidget *widget)
4314 GList *clist = NULL;
4316 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4318 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4319 if (gtk_accel_group_from_accel_closure (slist->data))
4320 clist = g_list_prepend (clist, slist->data);
4326 GtkAccelGroup *accel_group;
4331 destroy_accel_path (gpointer data)
4333 AccelPath *apath = data;
4335 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4337 /* closures_destroy takes care of unrefing the closure */
4338 g_object_unref (apath->accel_group);
4340 g_slice_free (AccelPath, apath);
4345 * gtk_widget_set_accel_path:
4346 * @widget: a #GtkWidget
4347 * @accel_path: path used to look up the accelerator
4348 * @accel_group: a #GtkAccelGroup.
4350 * Given an accelerator group, @accel_group, and an accelerator path,
4351 * @accel_path, sets up an accelerator in @accel_group so whenever the
4352 * key binding that is defined for @accel_path is pressed, @widget
4353 * will be activated. This removes any accelerators (for any
4354 * accelerator group) installed by previous calls to
4355 * gtk_widget_set_accel_path(). Associating accelerators with
4356 * paths allows them to be modified by the user and the modifications
4357 * to be saved for future use. (See gtk_accel_map_save().)
4359 * This function is a low level function that would most likely
4360 * be used by a menu creation system like #GtkUIManager. If you
4361 * use #GtkUIManager, setting up accelerator paths will be done
4364 * Even when you you aren't using #GtkUIManager, if you only want to
4365 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4366 * provides a somewhat more convenient interface.
4368 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4369 * pass a static string, you can save some memory by interning it first with
4370 * g_intern_static_string().
4373 gtk_widget_set_accel_path (GtkWidget *widget,
4374 const gchar *accel_path,
4375 GtkAccelGroup *accel_group)
4379 g_return_if_fail (GTK_IS_WIDGET (widget));
4380 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4384 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4385 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4387 gtk_accel_map_add_entry (accel_path, 0, 0);
4388 apath = g_slice_new (AccelPath);
4389 apath->accel_group = g_object_ref (accel_group);
4390 apath->path_quark = g_quark_from_string (accel_path);
4391 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4396 /* also removes possible old settings */
4397 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4400 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4402 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4406 _gtk_widget_get_accel_path (GtkWidget *widget,
4411 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4413 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4415 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4416 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4420 gtk_widget_mnemonic_activate (GtkWidget *widget,
4421 gboolean group_cycling)
4425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4427 group_cycling = group_cycling != FALSE;
4428 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4431 g_signal_emit (widget,
4432 widget_signals[MNEMONIC_ACTIVATE],
4440 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4441 gboolean group_cycling)
4443 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4444 gtk_widget_activate (widget);
4445 else if (GTK_WIDGET_CAN_FOCUS (widget))
4446 gtk_widget_grab_focus (widget);
4449 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4450 G_OBJECT_TYPE_NAME (widget));
4451 gtk_widget_error_bell (widget);
4457 gtk_widget_real_key_press_event (GtkWidget *widget,
4460 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4464 gtk_widget_real_key_release_event (GtkWidget *widget,
4467 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4471 gtk_widget_real_focus_in_event (GtkWidget *widget,
4472 GdkEventFocus *event)
4474 gtk_widget_queue_shallow_draw (widget);
4480 gtk_widget_real_focus_out_event (GtkWidget *widget,
4481 GdkEventFocus *event)
4483 gtk_widget_queue_shallow_draw (widget);
4488 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4489 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4493 * @widget: a #GtkWidget
4494 * @event: a #GdkEvent
4496 * Rarely-used function. This function is used to emit
4497 * the event signals on a widget (those signals should never
4498 * be emitted without using this function to do so).
4499 * If you want to synthesize an event though, don't use this function;
4500 * instead, use gtk_main_do_event() so the event will behave as if
4501 * it were in the event queue. Don't synthesize expose events; instead,
4502 * use gdk_window_invalidate_rect() to invalidate a region of the
4505 * Return value: return from the event signal emission (%TRUE if
4506 * the event was handled)
4509 gtk_widget_event (GtkWidget *widget,
4512 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4513 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4515 if (event->type == GDK_EXPOSE)
4517 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4518 "the same effect, call gdk_window_invalidate_rect/region(), "
4519 "followed by gdk_window_process_updates().");
4523 return gtk_widget_event_internal (widget, event);
4528 * gtk_widget_send_expose:
4529 * @widget: a #GtkWidget
4530 * @event: a expose #GdkEvent
4532 * Very rarely-used function. This function is used to emit
4533 * an expose event signals on a widget. This function is not
4534 * normally used directly. The only time it is used is when
4535 * propagating an expose event to a child %NO_WINDOW widget, and
4536 * that is normally done using gtk_container_propagate_expose().
4538 * If you want to force an area of a window to be redrawn,
4539 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4540 * To cause the redraw to be done immediately, follow that call
4541 * with a call to gdk_window_process_updates().
4543 * Return value: return from the event signal emission (%TRUE if
4544 * the event was handled)
4547 gtk_widget_send_expose (GtkWidget *widget,
4550 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4551 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4552 g_return_val_if_fail (event != NULL, TRUE);
4553 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4555 return gtk_widget_event_internal (widget, event);
4559 event_window_is_still_viewable (GdkEvent *event)
4561 /* Some programs, such as gnome-theme-manager, fake widgets
4562 * into exposing onto a pixmap by sending expose events with
4563 * event->window pointing to a pixmap
4565 if (GDK_IS_PIXMAP (event->any.window))
4566 return event->type == GDK_EXPOSE;
4568 /* Check that we think the event's window is viewable before
4569 * delivering the event, to prevent suprises. We do this here
4570 * at the last moment, since the event may have been queued
4571 * up behind other events, held over a recursive main loop, etc.
4573 switch (event->type)
4576 case GDK_MOTION_NOTIFY:
4577 case GDK_BUTTON_PRESS:
4578 case GDK_2BUTTON_PRESS:
4579 case GDK_3BUTTON_PRESS:
4581 case GDK_ENTER_NOTIFY:
4582 case GDK_PROXIMITY_IN:
4584 return event->any.window && gdk_window_is_viewable (event->any.window);
4587 /* The following events are the second half of paired events;
4588 * we always deliver them to deal with widgets that clean up
4589 * on the second half.
4591 case GDK_BUTTON_RELEASE:
4592 case GDK_KEY_RELEASE:
4593 case GDK_LEAVE_NOTIFY:
4594 case GDK_PROXIMITY_OUT:
4598 /* Remaining events would make sense on an not-viewable window,
4599 * or don't have an associated window.
4606 gtk_widget_event_internal (GtkWidget *widget,
4609 gboolean return_val = FALSE;
4611 /* We check only once for is-still-visible; if someone
4612 * hides the window in on of the signals on the widget,
4613 * they are responsible for returning TRUE to terminate
4616 if (!event_window_is_still_viewable (event))
4619 g_object_ref (widget);
4621 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4622 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4627 switch (event->type)
4632 case GDK_BUTTON_PRESS:
4633 case GDK_2BUTTON_PRESS:
4634 case GDK_3BUTTON_PRESS:
4635 signal_num = BUTTON_PRESS_EVENT;
4638 signal_num = SCROLL_EVENT;
4640 case GDK_BUTTON_RELEASE:
4641 signal_num = BUTTON_RELEASE_EVENT;
4643 case GDK_MOTION_NOTIFY:
4644 signal_num = MOTION_NOTIFY_EVENT;
4647 signal_num = DELETE_EVENT;
4650 signal_num = DESTROY_EVENT;
4651 _gtk_tooltip_hide (widget);
4654 signal_num = KEY_PRESS_EVENT;
4656 case GDK_KEY_RELEASE:
4657 signal_num = KEY_RELEASE_EVENT;
4659 case GDK_ENTER_NOTIFY:
4660 signal_num = ENTER_NOTIFY_EVENT;
4662 case GDK_LEAVE_NOTIFY:
4663 signal_num = LEAVE_NOTIFY_EVENT;
4665 case GDK_FOCUS_CHANGE:
4666 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4667 if (event->focus_change.in)
4668 _gtk_tooltip_focus_in (widget);
4670 _gtk_tooltip_focus_out (widget);
4673 signal_num = CONFIGURE_EVENT;
4676 signal_num = MAP_EVENT;
4679 signal_num = UNMAP_EVENT;
4681 case GDK_WINDOW_STATE:
4682 signal_num = WINDOW_STATE_EVENT;
4684 case GDK_PROPERTY_NOTIFY:
4685 signal_num = PROPERTY_NOTIFY_EVENT;
4687 case GDK_SELECTION_CLEAR:
4688 signal_num = SELECTION_CLEAR_EVENT;
4690 case GDK_SELECTION_REQUEST:
4691 signal_num = SELECTION_REQUEST_EVENT;
4693 case GDK_SELECTION_NOTIFY:
4694 signal_num = SELECTION_NOTIFY_EVENT;
4696 case GDK_PROXIMITY_IN:
4697 signal_num = PROXIMITY_IN_EVENT;
4699 case GDK_PROXIMITY_OUT:
4700 signal_num = PROXIMITY_OUT_EVENT;
4703 signal_num = NO_EXPOSE_EVENT;
4705 case GDK_CLIENT_EVENT:
4706 signal_num = CLIENT_EVENT;
4709 signal_num = EXPOSE_EVENT;
4711 case GDK_VISIBILITY_NOTIFY:
4712 signal_num = VISIBILITY_NOTIFY_EVENT;
4714 case GDK_GRAB_BROKEN:
4715 signal_num = GRAB_BROKEN;
4718 signal_num = DAMAGE_EVENT;
4721 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4725 if (signal_num != -1)
4726 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4728 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4729 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4733 g_object_unref (widget);
4739 * gtk_widget_activate:
4740 * @widget: a #GtkWidget that's activatable
4742 * For widgets that can be "activated" (buttons, menu items, etc.)
4743 * this function activates them. Activation is what happens when you
4744 * press Enter on a widget during key navigation. If @widget isn't
4745 * activatable, the function returns %FALSE.
4747 * Return value: %TRUE if the widget was activatable
4750 gtk_widget_activate (GtkWidget *widget)
4752 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4754 if (WIDGET_CLASS (widget)->activate_signal)
4756 /* FIXME: we should eventually check the signals signature here */
4757 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4766 * gtk_widget_set_scroll_adjustments:
4767 * @widget: a #GtkWidget
4768 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4769 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4771 * For widgets that support scrolling, sets the scroll adjustments and
4772 * returns %TRUE. For widgets that don't support scrolling, does
4773 * nothing and returns %FALSE. Widgets that don't support scrolling
4774 * can be scrolled by placing them in a #GtkViewport, which does
4775 * support scrolling.
4777 * Return value: %TRUE if the widget supports scrolling
4780 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4781 GtkAdjustment *hadjustment,
4782 GtkAdjustment *vadjustment)
4784 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4786 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4788 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4790 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
4792 /* FIXME: we should eventually check the signals signature here */
4793 g_signal_emit (widget,
4794 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
4795 hadjustment, vadjustment);
4803 gtk_widget_reparent_subwindows (GtkWidget *widget,
4804 GdkWindow *new_window)
4806 if (GTK_WIDGET_NO_WINDOW (widget))
4808 GList *children = gdk_window_get_children (widget->window);
4811 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4813 GdkWindow *window = tmp_list->data;
4816 gdk_window_get_user_data (window, &child);
4817 while (child && child != widget)
4818 child = ((GtkWidget*) child)->parent;
4821 gdk_window_reparent (window, new_window, 0, 0);
4824 g_list_free (children);
4829 GList *tmp_list, *children;
4831 parent = gdk_window_get_parent (widget->window);
4834 gdk_window_reparent (widget->window, new_window, 0, 0);
4837 children = gdk_window_get_children (parent);
4839 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4841 GdkWindow *window = tmp_list->data;
4844 gdk_window_get_user_data (window, &child);
4846 if (child == widget)
4847 gdk_window_reparent (window, new_window, 0, 0);
4850 g_list_free (children);
4856 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4857 gpointer client_data)
4859 g_assert (client_data != NULL);
4861 if (GTK_WIDGET_NO_WINDOW (widget))
4864 g_object_unref (widget->window);
4865 widget->window = (GdkWindow*) client_data;
4867 g_object_ref (widget->window);
4869 if (GTK_IS_CONTAINER (widget))
4870 gtk_container_forall (GTK_CONTAINER (widget),
4871 gtk_widget_reparent_fixup_child,
4877 * gtk_widget_reparent:
4878 * @widget: a #GtkWidget
4879 * @new_parent: a #GtkContainer to move the widget into
4881 * Moves a widget from one #GtkContainer to another, handling reference
4882 * count issues to avoid destroying the widget.
4885 gtk_widget_reparent (GtkWidget *widget,
4886 GtkWidget *new_parent)
4888 g_return_if_fail (GTK_IS_WIDGET (widget));
4889 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4890 g_return_if_fail (widget->parent != NULL);
4892 if (widget->parent != new_parent)
4894 /* First try to see if we can get away without unrealizing
4895 * the widget as we reparent it. if so we set a flag so
4896 * that gtk_widget_unparent doesn't unrealize widget
4898 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4899 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4901 g_object_ref (widget);
4902 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4903 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4904 g_object_unref (widget);
4906 if (GTK_WIDGET_IN_REPARENT (widget))
4908 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4910 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4911 gtk_widget_reparent_fixup_child (widget,
4912 gtk_widget_get_parent_window (widget));
4915 g_object_notify (G_OBJECT (widget), "parent");
4920 * gtk_widget_intersect:
4921 * @widget: a #GtkWidget
4922 * @area: a rectangle
4923 * @intersection: rectangle to store intersection of @widget and @area
4925 * Computes the intersection of a @widget's area and @area, storing
4926 * the intersection in @intersection, and returns %TRUE if there was
4927 * an intersection. @intersection may be %NULL if you're only
4928 * interested in whether there was an intersection.
4930 * Return value: %TRUE if there was an intersection
4933 gtk_widget_intersect (GtkWidget *widget,
4934 const GdkRectangle *area,
4935 GdkRectangle *intersection)
4941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4942 g_return_val_if_fail (area != NULL, FALSE);
4945 dest = intersection;
4949 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4951 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4953 intersection->x -= widget->allocation.x;
4954 intersection->y -= widget->allocation.y;
4961 * gtk_widget_region_intersect:
4962 * @widget: a #GtkWidget
4963 * @region: a #GdkRegion, in the same coordinate system as
4964 * @widget->allocation. That is, relative to @widget->window
4965 * for %NO_WINDOW widgets; relative to the parent window
4966 * of @widget->window for widgets with their own window.
4967 * @returns: A newly allocated region holding the intersection of @widget
4968 * and @region. The coordinates of the return value are
4969 * relative to @widget->window for %NO_WINDOW widgets, and
4970 * relative to the parent window of @widget->window for
4971 * widgets with their own window.
4973 * Computes the intersection of a @widget's area and @region, returning
4974 * the intersection. The result may be empty, use gdk_region_empty() to
4978 gtk_widget_region_intersect (GtkWidget *widget,
4979 const GdkRegion *region)
4984 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4985 g_return_val_if_fail (region != NULL, NULL);
4987 gtk_widget_get_draw_rectangle (widget, &rect);
4989 dest = gdk_region_rectangle (&rect);
4991 gdk_region_intersect (dest, region);
4997 * _gtk_widget_grab_notify:
4998 * @widget: a #GtkWidget
4999 * @was_grabbed: whether a grab is now in effect
5001 * Emits the #GtkWidget::grab-notify signal on @widget.
5006 _gtk_widget_grab_notify (GtkWidget *widget,
5007 gboolean was_grabbed)
5009 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5013 * gtk_widget_grab_focus:
5014 * @widget: a #GtkWidget
5016 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5017 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5018 * something like #GtkFrame won't work. (More precisely, it must have the
5019 * %GTK_CAN_FOCUS flag set.)
5022 gtk_widget_grab_focus (GtkWidget *widget)
5024 g_return_if_fail (GTK_IS_WIDGET (widget));
5026 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5029 g_object_ref (widget);
5030 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5031 g_object_notify (G_OBJECT (widget), "has-focus");
5032 g_object_unref (widget);
5036 reset_focus_recurse (GtkWidget *widget,
5039 if (GTK_IS_CONTAINER (widget))
5041 GtkContainer *container;
5043 container = GTK_CONTAINER (widget);
5044 gtk_container_set_focus_child (container, NULL);
5046 gtk_container_foreach (container,
5047 reset_focus_recurse,
5053 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5055 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5057 GtkWidget *toplevel;
5060 /* clear the current focus setting, break if the current widget
5061 * is the focus widget's parent, since containers above that will
5062 * be set by the next loop.
5064 toplevel = gtk_widget_get_toplevel (focus_widget);
5065 if (GTK_WIDGET_TOPLEVEL (toplevel))
5067 widget = GTK_WINDOW (toplevel)->focus_widget;
5069 if (widget == focus_widget)
5071 /* We call _gtk_window_internal_set_focus() here so that the
5072 * toplevel window can request the focus if necessary.
5073 * This is needed when the toplevel is a GtkPlug
5075 if (!GTK_WIDGET_HAS_FOCUS (widget))
5076 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5083 while (widget->parent && widget->parent != focus_widget->parent)
5085 widget = widget->parent;
5086 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5090 else if (toplevel != focus_widget)
5092 /* gtk_widget_grab_focus() operates on a tree without window...
5093 * actually, this is very questionable behaviour.
5096 gtk_container_foreach (GTK_CONTAINER (toplevel),
5097 reset_focus_recurse,
5101 /* now propagate the new focus up the widget tree and finally
5102 * set it on the window
5104 widget = focus_widget;
5105 while (widget->parent)
5107 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5108 widget = widget->parent;
5110 if (GTK_IS_WINDOW (widget))
5111 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5116 gtk_widget_real_query_tooltip (GtkWidget *widget,
5119 gboolean keyboard_tip,
5120 GtkTooltip *tooltip)
5122 gchar *tooltip_markup;
5123 gboolean has_tooltip;
5125 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5126 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5128 if (has_tooltip && tooltip_markup)
5130 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5138 gtk_widget_real_show_help (GtkWidget *widget,
5139 GtkWidgetHelpType help_type)
5141 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5143 _gtk_tooltip_toggle_keyboard_mode (widget);
5152 gtk_widget_real_focus (GtkWidget *widget,
5153 GtkDirectionType direction)
5155 if (!GTK_WIDGET_CAN_FOCUS (widget))
5158 if (!gtk_widget_is_focus (widget))
5160 gtk_widget_grab_focus (widget);
5168 gtk_widget_real_move_focus (GtkWidget *widget,
5169 GtkDirectionType direction)
5171 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5173 if (GTK_IS_WINDOW (toplevel) &&
5174 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5176 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5182 gtk_widget_real_keynav_failed (GtkWidget *widget,
5183 GtkDirectionType direction)
5185 gboolean cursor_only;
5189 case GTK_DIR_TAB_FORWARD:
5190 case GTK_DIR_TAB_BACKWARD:
5197 g_object_get (gtk_widget_get_settings (widget),
5198 "gtk-keynav-cursor-only", &cursor_only,
5205 gtk_widget_error_bell (widget);
5211 * gtk_widget_is_focus:
5212 * @widget: a #GtkWidget
5214 * Determines if the widget is the focus widget within its
5215 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5216 * necessarily set; %HAS_FOCUS will only be set if the
5217 * toplevel widget additionally has the global input focus.)
5219 * Return value: %TRUE if the widget is the focus widget.
5222 gtk_widget_is_focus (GtkWidget *widget)
5224 GtkWidget *toplevel;
5226 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5228 toplevel = gtk_widget_get_toplevel (widget);
5230 if (GTK_IS_WINDOW (toplevel))
5231 return widget == GTK_WINDOW (toplevel)->focus_widget;
5237 * gtk_widget_grab_default:
5238 * @widget: a #GtkWidget
5240 * Causes @widget to become the default widget. @widget must have the
5241 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5242 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5243 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5244 * the user presses Enter in a window. Default widgets must be
5245 * activatable, that is, gtk_widget_activate() should affect them.
5248 gtk_widget_grab_default (GtkWidget *widget)
5252 g_return_if_fail (GTK_IS_WIDGET (widget));
5253 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5255 window = gtk_widget_get_toplevel (widget);
5257 if (window && GTK_WIDGET_TOPLEVEL (window))
5258 gtk_window_set_default (GTK_WINDOW (window), widget);
5260 g_warning (G_STRLOC ": widget not within a GtkWindow");
5264 * gtk_widget_set_name:
5265 * @widget: a #GtkWidget
5266 * @name: name for the widget
5268 * Widgets can be named, which allows you to refer to them from a
5269 * gtkrc file. You can apply a style to widgets with a particular name
5270 * in the gtkrc file. See the documentation for gtkrc files (on the
5271 * same page as the docs for #GtkRcStyle).
5273 * Note that widget names are separated by periods in paths (see
5274 * gtk_widget_path()), so names with embedded periods may cause confusion.
5277 gtk_widget_set_name (GtkWidget *widget,
5282 g_return_if_fail (GTK_IS_WIDGET (widget));
5284 new_name = g_strdup (name);
5285 g_free (widget->name);
5286 widget->name = new_name;
5288 if (GTK_WIDGET_RC_STYLE (widget))
5289 gtk_widget_reset_rc_style (widget);
5291 g_object_notify (G_OBJECT (widget), "name");
5295 * gtk_widget_get_name:
5296 * @widget: a #GtkWidget
5298 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5299 * significance of widget names.
5301 * Return value: name of the widget. This string is owned by GTK+ and
5302 * should not be modified or freed
5304 G_CONST_RETURN gchar*
5305 gtk_widget_get_name (GtkWidget *widget)
5307 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5310 return widget->name;
5311 return g_type_name (GTK_WIDGET_TYPE (widget));
5315 * gtk_widget_set_state:
5316 * @widget: a #GtkWidget
5317 * @state: new state for @widget
5319 * This function is for use in widget implementations. Sets the state
5320 * of a widget (insensitive, prelighted, etc.) Usually you should set
5321 * the state using wrapper functions such as gtk_widget_set_sensitive().
5324 gtk_widget_set_state (GtkWidget *widget,
5327 g_return_if_fail (GTK_IS_WIDGET (widget));
5329 if (state == GTK_WIDGET_STATE (widget))
5332 if (state == GTK_STATE_INSENSITIVE)
5333 gtk_widget_set_sensitive (widget, FALSE);
5339 data.state_restoration = FALSE;
5340 data.use_forall = FALSE;
5342 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5344 data.parent_sensitive = TRUE;
5346 gtk_widget_propagate_state (widget, &data);
5348 if (GTK_WIDGET_DRAWABLE (widget))
5349 gtk_widget_queue_draw (widget);
5355 * gtk_widget_set_app_paintable:
5356 * @widget: a #GtkWidget
5357 * @app_paintable: %TRUE if the application will paint on the widget
5359 * Sets whether the application intends to draw on the widget in
5360 * an #GtkWidget::expose-event handler.
5362 * This is a hint to the widget and does not affect the behavior of
5363 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5364 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5365 * the effect is to suppress default themed drawing of the widget's
5366 * background. (Children of the widget will still be drawn.) The application
5367 * is then entirely responsible for drawing the widget background.
5369 * Note that the background is still drawn when the widget is mapped.
5370 * If this is not suitable (e.g. because you want to make a transparent
5371 * window using an RGBA visual), you can work around this by doing:
5373 * gtk_widget_realize (window);
5374 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5375 * gtk_widget_show (window);
5379 gtk_widget_set_app_paintable (GtkWidget *widget,
5380 gboolean app_paintable)
5382 g_return_if_fail (GTK_IS_WIDGET (widget));
5384 app_paintable = (app_paintable != FALSE);
5386 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5389 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5391 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5393 if (GTK_WIDGET_DRAWABLE (widget))
5394 gtk_widget_queue_draw (widget);
5396 g_object_notify (G_OBJECT (widget), "app-paintable");
5401 * gtk_widget_set_double_buffered:
5402 * @widget: a #GtkWidget
5403 * @double_buffered: %TRUE to double-buffer a widget
5405 * Widgets are double buffered by default; you can use this function
5406 * to turn off the buffering. "Double buffered" simply means that
5407 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5408 * automatically around expose events sent to the
5409 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5410 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5411 * buffer to the screen. The result is that users see the window
5412 * update in one smooth step, and don't see individual graphics
5413 * primitives being rendered.
5415 * In very simple terms, double buffered widgets don't flicker,
5416 * so you would only use this function to turn off double buffering
5417 * if you had special needs and really knew what you were doing.
5419 * Note: if you turn off double-buffering, you have to handle
5420 * expose events, since even the clearing to the background color or
5421 * pixmap will not happen automatically (as it is done in
5422 * gdk_window_begin_paint()).
5425 gtk_widget_set_double_buffered (GtkWidget *widget,
5426 gboolean double_buffered)
5428 g_return_if_fail (GTK_IS_WIDGET (widget));
5430 if (double_buffered)
5431 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5433 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5437 * gtk_widget_set_redraw_on_allocate:
5438 * @widget: a #GtkWidget
5439 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5440 * when it is allocated to a new size. Otherwise, only the
5441 * new portion of the widget will be redrawn.
5443 * Sets whether the entire widget is queued for drawing when its size
5444 * allocation changes. By default, this setting is %TRUE and
5445 * the entire widget is redrawn on every size change. If your widget
5446 * leaves the upper left unchanged when made bigger, turning this
5447 * setting off will improve performance.
5449 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5450 * off all allocation on resizing: the widget will not even redraw if
5451 * its position changes; this is to allow containers that don't draw
5452 * anything to avoid excess invalidations. If you set this flag on a
5453 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5454 * you are responsible for invalidating both the old and new allocation
5455 * of the widget when the widget is moved and responsible for invalidating
5456 * regions newly when the widget increases size.
5459 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5460 gboolean redraw_on_allocate)
5462 g_return_if_fail (GTK_IS_WIDGET (widget));
5464 if (redraw_on_allocate)
5465 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5467 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5471 * gtk_widget_set_sensitive:
5472 * @widget: a #GtkWidget
5473 * @sensitive: %TRUE to make the widget sensitive
5475 * Sets the sensitivity of a widget. A widget is sensitive if the user
5476 * can interact with it. Insensitive widgets are "grayed out" and the
5477 * user can't interact with them. Insensitive widgets are known as
5478 * "inactive", "disabled", or "ghosted" in some other toolkits.
5481 gtk_widget_set_sensitive (GtkWidget *widget,
5486 g_return_if_fail (GTK_IS_WIDGET (widget));
5488 sensitive = (sensitive != FALSE);
5490 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5495 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5496 data.state = GTK_WIDGET_SAVED_STATE (widget);
5500 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5501 data.state = GTK_WIDGET_STATE (widget);
5503 data.state_restoration = TRUE;
5504 data.use_forall = TRUE;
5507 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5509 data.parent_sensitive = TRUE;
5511 gtk_widget_propagate_state (widget, &data);
5512 if (GTK_WIDGET_DRAWABLE (widget))
5513 gtk_widget_queue_draw (widget);
5515 g_object_notify (G_OBJECT (widget), "sensitive");
5519 * gtk_widget_set_parent:
5520 * @widget: a #GtkWidget
5521 * @parent: parent container
5523 * This function is useful only when implementing subclasses of
5525 * Sets the container as the parent of @widget, and takes care of
5526 * some details such as updating the state and style of the child
5527 * to reflect its new location. The opposite function is
5528 * gtk_widget_unparent().
5531 gtk_widget_set_parent (GtkWidget *widget,
5536 g_return_if_fail (GTK_IS_WIDGET (widget));
5537 g_return_if_fail (GTK_IS_WIDGET (parent));
5538 g_return_if_fail (widget != parent);
5539 if (widget->parent != NULL)
5541 g_warning ("Can't set a parent on widget which has a parent\n");
5544 if (GTK_WIDGET_TOPLEVEL (widget))
5546 g_warning ("Can't set a parent on a toplevel widget\n");
5550 /* keep this function in sync with gtk_menu_attach_to_widget()
5553 g_object_ref_sink (widget);
5554 widget->parent = parent;
5556 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5557 data.state = GTK_WIDGET_STATE (parent);
5559 data.state = GTK_WIDGET_STATE (widget);
5560 data.state_restoration = FALSE;
5561 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5562 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5564 gtk_widget_propagate_state (widget, &data);
5566 gtk_widget_reset_rc_styles (widget);
5568 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5569 if (GTK_WIDGET_ANCHORED (widget->parent))
5570 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5571 g_object_notify (G_OBJECT (widget), "parent");
5573 /* Enforce realized/mapped invariants
5575 if (GTK_WIDGET_REALIZED (widget->parent))
5576 gtk_widget_realize (widget);
5578 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5579 GTK_WIDGET_VISIBLE (widget))
5581 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5582 GTK_WIDGET_MAPPED (widget->parent))
5583 gtk_widget_map (widget);
5585 gtk_widget_queue_resize (widget);
5590 * gtk_widget_get_parent:
5591 * @widget: a #GtkWidget
5593 * Returns the parent container of @widget.
5595 * Return value: the parent container of @widget, or %NULL
5598 gtk_widget_get_parent (GtkWidget *widget)
5600 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5602 return widget->parent;
5605 /*****************************************
5607 * see docs/styles.txt
5608 *****************************************/
5611 * gtk_widget_set_style:
5612 * @widget: a #GtkWidget
5613 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5614 * gtk_widget_set_style() and go back to the default style
5616 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5617 * want to use this function; it interacts badly with themes, because
5618 * themes work by replacing the #GtkStyle. Instead, use
5619 * gtk_widget_modify_style().
5622 gtk_widget_set_style (GtkWidget *widget,
5625 g_return_if_fail (GTK_IS_WIDGET (widget));
5629 gboolean initial_emission;
5631 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5633 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5634 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5636 gtk_widget_set_style_internal (widget, style, initial_emission);
5640 if (GTK_WIDGET_USER_STYLE (widget))
5641 gtk_widget_reset_rc_style (widget);
5646 * gtk_widget_ensure_style:
5647 * @widget: a #GtkWidget
5649 * Ensures that @widget has a style (@widget->style). Not a very useful
5650 * function; most of the time, if you want the style, the widget is
5651 * realized, and realized widgets are guaranteed to have a style
5655 gtk_widget_ensure_style (GtkWidget *widget)
5657 g_return_if_fail (GTK_IS_WIDGET (widget));
5659 if (!GTK_WIDGET_USER_STYLE (widget) &&
5660 !GTK_WIDGET_RC_STYLE (widget))
5661 gtk_widget_reset_rc_style (widget);
5664 /* Look up the RC style for this widget, unsetting any user style that
5665 * may be in effect currently
5668 gtk_widget_reset_rc_style (GtkWidget *widget)
5670 GtkStyle *new_style = NULL;
5671 gboolean initial_emission;
5673 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5675 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5676 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5678 if (gtk_widget_has_screen (widget))
5679 new_style = gtk_rc_get_style (widget);
5681 new_style = gtk_widget_get_default_style ();
5683 if (initial_emission || new_style != widget->style)
5684 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5688 * gtk_widget_get_style:
5689 * @widget: a #GtkWidget
5691 * Simply an accessor function that returns @widget->style.
5693 * Return value: the widget's #GtkStyle
5696 gtk_widget_get_style (GtkWidget *widget)
5698 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5700 return widget->style;
5704 * gtk_widget_modify_style:
5705 * @widget: a #GtkWidget
5706 * @style: the #GtkRcStyle holding the style modifications
5708 * Modifies style values on the widget. Modifications made using this
5709 * technique take precedence over style values set via an RC file,
5710 * however, they will be overriden if a style is explicitely set on
5711 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5712 * is designed so each field can either be set or unset, so it is
5713 * possible, using this function, to modify some style values and
5714 * leave the others unchanged.
5716 * Note that modifications made with this function are not cumulative
5717 * with previous calls to gtk_widget_modify_style() or with such
5718 * functions as gtk_widget_modify_fg(). If you wish to retain
5719 * previous values, you must first call gtk_widget_get_modifier_style(),
5720 * make your modifications to the returned style, then call
5721 * gtk_widget_modify_style() with that style. On the other hand,
5722 * if you first call gtk_widget_modify_style(), subsequent calls
5723 * to such functions gtk_widget_modify_fg() will have a cumulative
5724 * effect with the initial modifications.
5727 gtk_widget_modify_style (GtkWidget *widget,
5730 g_return_if_fail (GTK_IS_WIDGET (widget));
5731 g_return_if_fail (GTK_IS_RC_STYLE (style));
5733 g_object_set_qdata_full (G_OBJECT (widget),
5735 gtk_rc_style_copy (style),
5736 (GDestroyNotify) g_object_unref);
5738 /* note that "style" may be invalid here if it was the old
5739 * modifier style and the only reference was our own.
5742 if (GTK_WIDGET_RC_STYLE (widget))
5743 gtk_widget_reset_rc_style (widget);
5747 * gtk_widget_get_modifier_style:
5748 * @widget: a #GtkWidget
5750 * Returns the current modifier style for the widget. (As set by
5751 * gtk_widget_modify_style().) If no style has previously set, a new
5752 * #GtkRcStyle will be created with all values unset, and set as the
5753 * modifier style for the widget. If you make changes to this rc
5754 * style, you must call gtk_widget_modify_style(), passing in the
5755 * returned rc style, to make sure that your changes take effect.
5757 * Caution: passing the style back to gtk_widget_modify_style() will
5758 * normally end up destroying it, because gtk_widget_modify_style() copies
5759 * the passed-in style and sets the copy as the new modifier style,
5760 * thus dropping any reference to the old modifier style. Add a reference
5761 * to the modifier style if you want to keep it alive.
5763 * Return value: the modifier style for the widget. This rc style is
5764 * owned by the widget. If you want to keep a pointer to value this
5765 * around, you must add a refcount using g_object_ref().
5768 gtk_widget_get_modifier_style (GtkWidget *widget)
5770 GtkRcStyle *rc_style;
5772 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5774 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5778 rc_style = gtk_rc_style_new ();
5779 g_object_set_qdata_full (G_OBJECT (widget),
5782 (GDestroyNotify) g_object_unref);
5789 gtk_widget_modify_color_component (GtkWidget *widget,
5790 GtkRcFlags component,
5792 const GdkColor *color)
5794 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5801 rc_style->fg[state] = *color;
5804 rc_style->bg[state] = *color;
5807 rc_style->text[state] = *color;
5810 rc_style->base[state] = *color;
5813 g_assert_not_reached();
5816 rc_style->color_flags[state] |= component;
5819 rc_style->color_flags[state] &= ~component;
5821 gtk_widget_modify_style (widget, rc_style);
5825 * gtk_widget_modify_fg:
5826 * @widget: a #GtkWidget
5827 * @state: the state for which to set the foreground color
5828 * @color: the color to assign (does not need to be allocated),
5829 * or %NULL to undo the effect of previous calls to
5830 * of gtk_widget_modify_fg().
5832 * Sets the foreground color for a widget in a particular state.
5833 * All other style values are left untouched. See also
5834 * gtk_widget_modify_style().
5837 gtk_widget_modify_fg (GtkWidget *widget,
5839 const GdkColor *color)
5841 g_return_if_fail (GTK_IS_WIDGET (widget));
5842 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5844 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5848 * gtk_widget_modify_bg:
5849 * @widget: a #GtkWidget
5850 * @state: the state for which to set the background color
5851 * @color: the color to assign (does not need to be allocated),
5852 * or %NULL to undo the effect of previous calls to
5853 * of gtk_widget_modify_bg().
5855 * Sets the background color for a widget in a particular state.
5856 * All other style values are left untouched. See also
5857 * gtk_widget_modify_style().
5859 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5860 * draw on their parent container's window and thus may not draw any
5861 * background themselves. This is the case for e.g. #GtkLabel. To modify
5862 * the background of such widgets, you have to set the background color
5863 * on their parent; if you want to set the background of a rectangular
5864 * area around a label, try placing the label in a #GtkEventBox widget
5865 * and setting the background color on that.
5868 gtk_widget_modify_bg (GtkWidget *widget,
5870 const GdkColor *color)
5872 g_return_if_fail (GTK_IS_WIDGET (widget));
5873 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5875 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5879 * gtk_widget_modify_text:
5880 * @widget: a #GtkWidget
5881 * @state: the state for which to set the text color
5882 * @color: the color to assign (does not need to be allocated),
5883 * or %NULL to undo the effect of previous calls to
5884 * of gtk_widget_modify_text().
5886 * Sets the text color for a widget in a particular state. All other
5887 * style values are left untouched. The text color is the foreground
5888 * color used along with the base color (see gtk_widget_modify_base())
5889 * for widgets such as #GtkEntry and #GtkTextView. See also
5890 * gtk_widget_modify_style().
5893 gtk_widget_modify_text (GtkWidget *widget,
5895 const GdkColor *color)
5897 g_return_if_fail (GTK_IS_WIDGET (widget));
5898 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5900 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5904 * gtk_widget_modify_base:
5905 * @widget: a #GtkWidget
5906 * @state: the state for which to set the base color
5907 * @color: the color to assign (does not need to be allocated),
5908 * or %NULL to undo the effect of previous calls to
5909 * of gtk_widget_modify_base().
5911 * Sets the base color for a widget in a particular state.
5912 * All other style values are left untouched. The base color
5913 * is the background color used along with the text color
5914 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5915 * and #GtkTextView. See also gtk_widget_modify_style().
5917 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5918 * draw on their parent container's window and thus may not draw any
5919 * background themselves. This is the case for e.g. #GtkLabel. To modify
5920 * the background of such widgets, you have to set the base color on their
5921 * parent; if you want to set the background of a rectangular area around
5922 * a label, try placing the label in a #GtkEventBox widget and setting
5923 * the base color on that.
5926 gtk_widget_modify_base (GtkWidget *widget,
5928 const GdkColor *color)
5930 g_return_if_fail (GTK_IS_WIDGET (widget));
5931 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5933 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5937 modify_color_property (GtkWidget *widget,
5938 GtkRcStyle *rc_style,
5940 const GdkColor *color)
5942 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5943 GQuark property_name = g_quark_from_string (name);
5947 GtkRcProperty rc_property = {0};
5950 rc_property.type_name = type_name;
5951 rc_property.property_name = property_name;
5952 rc_property.origin = NULL;
5954 color_name = gdk_color_to_string (color);
5955 g_value_init (&rc_property.value, G_TYPE_STRING);
5956 g_value_take_string (&rc_property.value, color_name);
5958 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
5960 g_value_unset (&rc_property.value);
5963 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
5967 * gtk_widget_modify_cursor:
5968 * @widget: a #GtkWidget
5969 * @primary: the color to use for primary cursor (does not need to be
5970 * allocated), or %NULL to undo the effect of previous calls to
5971 * of gtk_widget_modify_cursor().
5972 * @secondary: the color to use for secondary cursor (does not need to be
5973 * allocated), or %NULL to undo the effect of previous calls to
5974 * of gtk_widget_modify_cursor().
5976 * Sets the cursor color to use in a widget, overriding the
5977 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
5978 * style properties. All other style values are left untouched.
5979 * See also gtk_widget_modify_style().
5984 gtk_widget_modify_cursor (GtkWidget *widget,
5985 const GdkColor *primary,
5986 const GdkColor *secondary)
5988 GtkRcStyle *rc_style;
5990 g_return_if_fail (GTK_IS_WIDGET (widget));
5992 rc_style = gtk_widget_get_modifier_style (widget);
5994 modify_color_property (widget, rc_style, "cursor-color", primary);
5995 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
5997 gtk_widget_modify_style (widget, rc_style);
6001 * gtk_widget_modify_font:
6002 * @widget: a #GtkWidget
6003 * @font_desc: the font description to use, or %NULL to undo
6004 * the effect of previous calls to gtk_widget_modify_font().
6006 * Sets the font to use for a widget. All other style values are left
6007 * untouched. See also gtk_widget_modify_style().
6010 gtk_widget_modify_font (GtkWidget *widget,
6011 PangoFontDescription *font_desc)
6013 GtkRcStyle *rc_style;
6015 g_return_if_fail (GTK_IS_WIDGET (widget));
6017 rc_style = gtk_widget_get_modifier_style (widget);
6019 if (rc_style->font_desc)
6020 pango_font_description_free (rc_style->font_desc);
6023 rc_style->font_desc = pango_font_description_copy (font_desc);
6025 rc_style->font_desc = NULL;
6027 gtk_widget_modify_style (widget, rc_style);
6031 gtk_widget_direction_changed (GtkWidget *widget,
6032 GtkTextDirection previous_direction)
6034 gtk_widget_queue_resize (widget);
6038 gtk_widget_style_set (GtkWidget *widget,
6039 GtkStyle *previous_style)
6041 if (GTK_WIDGET_REALIZED (widget) &&
6042 !GTK_WIDGET_NO_WINDOW (widget))
6043 gtk_style_set_background (widget->style, widget->window, widget->state);
6047 gtk_widget_set_style_internal (GtkWidget *widget,
6049 gboolean initial_emission)
6051 g_object_ref (widget);
6052 g_object_freeze_notify (G_OBJECT (widget));
6054 if (widget->style != style)
6056 GtkStyle *previous_style;
6058 if (GTK_WIDGET_REALIZED (widget))
6060 gtk_widget_reset_shapes (widget);
6061 gtk_style_detach (widget->style);
6064 previous_style = widget->style;
6065 widget->style = style;
6066 g_object_ref (widget->style);
6068 if (GTK_WIDGET_REALIZED (widget))
6069 widget->style = gtk_style_attach (widget->style, widget->window);
6071 gtk_widget_update_pango_context (widget);
6072 g_signal_emit (widget,
6073 widget_signals[STYLE_SET],
6075 initial_emission ? NULL : previous_style);
6076 g_object_unref (previous_style);
6078 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6079 gtk_widget_queue_resize (widget);
6081 else if (initial_emission)
6083 gtk_widget_update_pango_context (widget);
6084 g_signal_emit (widget,
6085 widget_signals[STYLE_SET],
6089 g_object_notify (G_OBJECT (widget), "style");
6090 g_object_thaw_notify (G_OBJECT (widget));
6091 g_object_unref (widget);
6095 GtkWidget *previous_toplevel;
6096 GdkScreen *previous_screen;
6097 GdkScreen *new_screen;
6098 } HierarchyChangedInfo;
6101 do_screen_change (GtkWidget *widget,
6102 GdkScreen *old_screen,
6103 GdkScreen *new_screen)
6105 if (old_screen != new_screen)
6109 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6111 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6114 _gtk_tooltip_hide (widget);
6115 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6120 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6121 gpointer client_data)
6123 HierarchyChangedInfo *info = client_data;
6124 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6125 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6127 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6129 g_object_ref (widget);
6132 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6134 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6136 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6137 do_screen_change (widget, info->previous_screen, info->new_screen);
6139 if (GTK_IS_CONTAINER (widget))
6140 gtk_container_forall (GTK_CONTAINER (widget),
6141 gtk_widget_propagate_hierarchy_changed_recurse,
6144 g_object_unref (widget);
6149 * _gtk_widget_propagate_hierarchy_changed:
6150 * @widget: a #GtkWidget
6151 * @previous_toplevel: Previous toplevel
6153 * Propagates changes in the anchored state to a widget and all
6154 * children, unsetting or setting the %ANCHORED flag, and
6155 * emitting #GtkWidget::hierarchy-changed.
6158 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6159 GtkWidget *previous_toplevel)
6161 HierarchyChangedInfo info;
6163 info.previous_toplevel = previous_toplevel;
6164 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6166 if (GTK_WIDGET_TOPLEVEL (widget) ||
6167 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6168 info.new_screen = gtk_widget_get_screen (widget);
6170 info.new_screen = NULL;
6172 if (info.previous_screen)
6173 g_object_ref (info.previous_screen);
6174 if (previous_toplevel)
6175 g_object_ref (previous_toplevel);
6177 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6179 if (previous_toplevel)
6180 g_object_unref (previous_toplevel);
6181 if (info.previous_screen)
6182 g_object_unref (info.previous_screen);
6186 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6187 gpointer client_data)
6189 HierarchyChangedInfo *info = client_data;
6191 g_object_ref (widget);
6193 do_screen_change (widget, info->previous_screen, info->new_screen);
6195 if (GTK_IS_CONTAINER (widget))
6196 gtk_container_forall (GTK_CONTAINER (widget),
6197 gtk_widget_propagate_screen_changed_recurse,
6200 g_object_unref (widget);
6204 * gtk_widget_is_composited:
6205 * @widget: a #GtkWidget
6207 * Whether @widget can rely on having its alpha channel
6208 * drawn correctly. On X11 this function returns whether a
6209 * compositing manager is running for @widget's screen.
6211 * Please note that the semantics of this call will change
6212 * in the future if used on a widget that has a composited
6213 * window in its heirarchy (as set by
6214 * gdk_window_set_composited()).
6216 * Return value: %TRUE if the widget can rely on its alpha
6217 * channel being drawn correctly.
6222 gtk_widget_is_composited (GtkWidget *widget)
6226 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6228 screen = gtk_widget_get_screen (widget);
6230 return gdk_screen_is_composited (screen);
6234 propagate_composited_changed (GtkWidget *widget,
6237 if (GTK_IS_CONTAINER (widget))
6239 gtk_container_forall (GTK_CONTAINER (widget),
6240 propagate_composited_changed,
6244 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6248 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6250 propagate_composited_changed (widget, NULL);
6254 * _gtk_widget_propagate_screen_changed:
6255 * @widget: a #GtkWidget
6256 * @previous_screen: Previous screen
6258 * Propagates changes in the screen for a widget to all
6259 * children, emitting #GtkWidget::screen-changed.
6262 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6263 GdkScreen *previous_screen)
6265 HierarchyChangedInfo info;
6267 info.previous_screen = previous_screen;
6268 info.new_screen = gtk_widget_get_screen (widget);
6270 if (previous_screen)
6271 g_object_ref (previous_screen);
6273 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6275 if (previous_screen)
6276 g_object_unref (previous_screen);
6280 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6282 if (GTK_WIDGET_RC_STYLE (widget))
6283 gtk_widget_reset_rc_style (widget);
6285 if (GTK_IS_CONTAINER (widget))
6286 gtk_container_forall (GTK_CONTAINER (widget),
6287 reset_rc_styles_recurse,
6292 gtk_widget_reset_rc_styles (GtkWidget *widget)
6294 g_return_if_fail (GTK_IS_WIDGET (widget));
6296 reset_rc_styles_recurse (widget, NULL);
6300 * gtk_widget_get_default_style:
6302 * Returns the default style used by all widgets initially.
6304 * Returns: the default style. This #GtkStyle object is owned
6305 * by GTK+ and should not be modified or freed.
6308 gtk_widget_get_default_style (void)
6310 if (!gtk_default_style)
6312 gtk_default_style = gtk_style_new ();
6313 g_object_ref (gtk_default_style);
6316 return gtk_default_style;
6319 static PangoContext *
6320 gtk_widget_peek_pango_context (GtkWidget *widget)
6322 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6326 * gtk_widget_get_pango_context:
6327 * @widget: a #GtkWidget
6329 * Gets a #PangoContext with the appropriate font map, font description,
6330 * and base direction for this widget. Unlike the context returned
6331 * by gtk_widget_create_pango_context(), this context is owned by
6332 * the widget (it can be used until the screen for the widget changes
6333 * or the widget is removed from its toplevel), and will be updated to
6334 * match any changes to the widget's attributes.
6336 * If you create and keep a #PangoLayout using this context, you must
6337 * deal with changes to the context by calling pango_layout_context_changed()
6338 * on the layout in response to the #GtkWidget::style-set and
6339 * #GtkWidget::direction-changed signals for the widget.
6341 * Return value: the #PangoContext for the widget.
6344 gtk_widget_get_pango_context (GtkWidget *widget)
6346 PangoContext *context;
6348 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6350 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6353 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6354 g_object_set_qdata_full (G_OBJECT (widget),
6355 quark_pango_context,
6364 update_pango_context (GtkWidget *widget,
6365 PangoContext *context)
6367 pango_context_set_font_description (context, widget->style->font_desc);
6368 pango_context_set_base_dir (context,
6369 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6370 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6374 gtk_widget_update_pango_context (GtkWidget *widget)
6376 PangoContext *context = gtk_widget_peek_pango_context (widget);
6382 update_pango_context (widget, context);
6384 screen = gtk_widget_get_screen_unchecked (widget);
6387 pango_cairo_context_set_resolution (context,
6388 gdk_screen_get_resolution (screen));
6389 pango_cairo_context_set_font_options (context,
6390 gdk_screen_get_font_options (screen));
6396 * gtk_widget_create_pango_context:
6397 * @widget: a #GtkWidget
6399 * Creates a new #PangoContext with the appropriate font map,
6400 * font description, and base direction for drawing text for
6401 * this widget. See also gtk_widget_get_pango_context().
6403 * Return value: the new #PangoContext
6406 gtk_widget_create_pango_context (GtkWidget *widget)
6409 PangoContext *context;
6411 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6413 screen = gtk_widget_get_screen_unchecked (widget);
6416 GTK_NOTE (MULTIHEAD,
6417 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6419 screen = gdk_screen_get_default ();
6422 context = gdk_pango_context_get_for_screen (screen);
6424 update_pango_context (widget, context);
6425 pango_context_set_language (context, gtk_get_default_language ());
6431 * gtk_widget_create_pango_layout:
6432 * @widget: a #GtkWidget
6433 * @text: text to set on the layout (can be %NULL)
6435 * Creates a new #PangoLayout with the appropriate font map,
6436 * font description, and base direction for drawing text for
6439 * If you keep a #PangoLayout created in this way around, in order to
6440 * notify the layout of changes to the base direction or font of this
6441 * widget, you must call pango_layout_context_changed() in response to
6442 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6445 * Return value: the new #PangoLayout
6448 gtk_widget_create_pango_layout (GtkWidget *widget,
6451 PangoLayout *layout;
6452 PangoContext *context;
6454 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6456 context = gtk_widget_get_pango_context (widget);
6457 layout = pango_layout_new (context);
6460 pango_layout_set_text (layout, text, -1);
6466 * gtk_widget_render_icon:
6467 * @widget: a #GtkWidget
6468 * @stock_id: a stock ID
6469 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6470 * the size of the source and don't scale (if there are multiple
6471 * source sizes, GTK+ picks one of the available sizes).
6472 * @detail: render detail to pass to theme engine
6474 * A convenience function that uses the theme engine and RC file
6475 * settings for @widget to look up @stock_id and render it to
6476 * a pixbuf. @stock_id should be a stock icon ID such as
6477 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6478 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6479 * identifies the widget or code doing the rendering, so that
6480 * theme engines can special-case rendering for that widget or code.
6482 * The pixels in the returned #GdkPixbuf are shared with the rest of
6483 * the application and should not be modified. The pixbuf should be freed
6484 * after use with g_object_unref().
6486 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6489 gtk_widget_render_icon (GtkWidget *widget,
6490 const gchar *stock_id,
6492 const gchar *detail)
6494 GtkIconSet *icon_set;
6497 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6498 g_return_val_if_fail (stock_id != NULL, NULL);
6499 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6501 gtk_widget_ensure_style (widget);
6503 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6505 if (icon_set == NULL)
6508 retval = gtk_icon_set_render_icon (icon_set,
6510 gtk_widget_get_direction (widget),
6511 GTK_WIDGET_STATE (widget),
6520 * gtk_widget_set_parent_window:
6521 * @widget: a #GtkWidget.
6522 * @parent_window: the new parent window.
6524 * Sets a non default parent window for @widget.
6527 gtk_widget_set_parent_window (GtkWidget *widget,
6528 GdkWindow *parent_window)
6530 GdkWindow *old_parent_window;
6532 g_return_if_fail (GTK_IS_WIDGET (widget));
6534 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6535 quark_parent_window);
6537 if (parent_window != old_parent_window)
6539 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6541 if (old_parent_window)
6542 g_object_unref (old_parent_window);
6544 g_object_ref (parent_window);
6550 * gtk_widget_set_child_visible:
6551 * @widget: a #GtkWidget
6552 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6554 * Sets whether @widget should be mapped along with its when its parent
6555 * is mapped and @widget has been shown with gtk_widget_show().
6557 * The child visibility can be set for widget before it is added to
6558 * a container with gtk_widget_set_parent(), to avoid mapping
6559 * children unnecessary before immediately unmapping them. However
6560 * it will be reset to its default state of %TRUE when the widget
6561 * is removed from a container.
6563 * Note that changing the child visibility of a widget does not
6564 * queue a resize on the widget. Most of the time, the size of
6565 * a widget is computed from all visible children, whether or
6566 * not they are mapped. If this is not the case, the container
6567 * can queue a resize itself.
6569 * This function is only useful for container implementations and
6570 * never should be called by an application.
6573 gtk_widget_set_child_visible (GtkWidget *widget,
6574 gboolean is_visible)
6576 g_return_if_fail (GTK_IS_WIDGET (widget));
6577 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6579 g_object_ref (widget);
6582 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6585 GtkWidget *toplevel;
6587 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6589 toplevel = gtk_widget_get_toplevel (widget);
6590 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6591 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6594 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6596 if (GTK_WIDGET_MAPPED (widget->parent) &&
6597 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6598 GTK_WIDGET_VISIBLE (widget))
6599 gtk_widget_map (widget);
6601 gtk_widget_unmap (widget);
6604 g_object_unref (widget);
6608 * gtk_widget_get_child_visible:
6609 * @widget: a #GtkWidget
6611 * Gets the value set with gtk_widget_set_child_visible().
6612 * If you feel a need to use this function, your code probably
6613 * needs reorganization.
6615 * This function is only useful for container implementations and
6616 * never should be called by an application.
6618 * Return value: %TRUE if the widget is mapped with the parent.
6621 gtk_widget_get_child_visible (GtkWidget *widget)
6623 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6625 return GTK_WIDGET_CHILD_VISIBLE (widget);
6629 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6631 GtkWidget *toplevel;
6633 toplevel = gtk_widget_get_toplevel (widget);
6635 if (GTK_WIDGET_TOPLEVEL (toplevel))
6637 if (GTK_IS_WINDOW (toplevel))
6638 return GTK_WINDOW (toplevel)->screen;
6639 else if (GTK_IS_INVISIBLE (toplevel))
6640 return GTK_INVISIBLE (widget)->screen;
6647 * gtk_widget_get_screen:
6648 * @widget: a #GtkWidget
6650 * Get the #GdkScreen from the toplevel window associated with
6651 * this widget. This function can only be called after the widget
6652 * has been added to a widget hierarchy with a #GtkWindow
6655 * In general, you should only create screen specific
6656 * resources when a widget has been realized, and you should
6657 * free those resources when the widget is unrealized.
6659 * Return value: the #GdkScreen for the toplevel for this widget.
6664 gtk_widget_get_screen (GtkWidget *widget)
6668 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6670 screen = gtk_widget_get_screen_unchecked (widget);
6677 g_warning (G_STRLOC ": Can't get associated screen"
6678 " for a widget unless it is inside a toplevel GtkWindow\n"
6679 " widget type is %s associated top level type is %s",
6680 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6681 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6683 return gdk_screen_get_default ();
6688 * gtk_widget_has_screen:
6689 * @widget: a #GtkWidget
6691 * Checks whether there is a #GdkScreen is associated with
6692 * this widget. All toplevel widgets have an associated
6693 * screen, and all widgets added into a heirarchy with a toplevel
6694 * window at the top.
6696 * Return value: %TRUE if there is a #GdkScreen associcated
6702 gtk_widget_has_screen (GtkWidget *widget)
6704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6706 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6710 * gtk_widget_get_display:
6711 * @widget: a #GtkWidget
6713 * Get the #GdkDisplay for the toplevel window associated with
6714 * this widget. This function can only be called after the widget
6715 * has been added to a widget hierarchy with a #GtkWindow at the top.
6717 * In general, you should only create display specific
6718 * resources when a widget has been realized, and you should
6719 * free those resources when the widget is unrealized.
6721 * Return value: the #GdkDisplay for the toplevel for this widget.
6726 gtk_widget_get_display (GtkWidget *widget)
6728 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6730 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6734 * gtk_widget_get_root_window:
6735 * @widget: a #GtkWidget
6737 * Get the root window where this widget is located. This function can
6738 * only be called after the widget has been added to a widget
6739 * heirarchy with #GtkWindow at the top.
6741 * The root window is useful for such purposes as creating a popup
6742 * #GdkWindow associated with the window. In general, you should only
6743 * create display specific resources when a widget has been realized,
6744 * and you should free those resources when the widget is unrealized.
6746 * Return value: the #GdkWindow root window for the toplevel for this widget.
6751 gtk_widget_get_root_window (GtkWidget *widget)
6753 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6755 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6759 * gtk_widget_get_parent_window:
6760 * @widget: a #GtkWidget.
6761 * @returns: the parent window of @widget.
6763 * Gets @widget's parent window.
6766 gtk_widget_get_parent_window (GtkWidget *widget)
6768 GdkWindow *parent_window;
6770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6772 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6774 return (parent_window != NULL) ? parent_window :
6775 (widget->parent != NULL) ? widget->parent->window : NULL;
6779 * gtk_widget_child_focus:
6780 * @widget: a #GtkWidget
6781 * @direction: direction of focus movement
6783 * This function is used by custom widget implementations; if you're
6784 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6785 * to a particular widget, and gtk_container_set_focus_chain() to
6786 * change the focus tab order. So you may want to investigate those
6787 * functions instead.
6789 * gtk_widget_child_focus() is called by containers as the user moves
6790 * around the window using keyboard shortcuts. @direction indicates
6791 * what kind of motion is taking place (up, down, left, right, tab
6792 * forward, tab backward). gtk_widget_child_focus() emits the
6793 * #GtkWidget::focus" signal; widgets override the default handler
6794 * for this signal in order to implement appropriate focus behavior.
6796 * The default ::focus handler for a widget should return %TRUE if
6797 * moving in @direction left the focus on a focusable location inside
6798 * that widget, and %FALSE if moving in @direction moved the focus
6799 * outside the widget. If returning %TRUE, widgets normally
6800 * call gtk_widget_grab_focus() to place the focus accordingly;
6801 * if returning %FALSE, they don't modify the current focus location.
6803 * This function replaces gtk_container_focus() from GTK+ 1.2.
6804 * It was necessary to check that the child was visible, sensitive,
6805 * and focusable before calling gtk_container_focus().
6806 * gtk_widget_child_focus() returns %FALSE if the widget is not
6807 * currently in a focusable state, so there's no need for those checks.
6809 * Return value: %TRUE if focus ended up inside @widget
6812 gtk_widget_child_focus (GtkWidget *widget,
6813 GtkDirectionType direction)
6815 gboolean return_val;
6817 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6819 if (!GTK_WIDGET_VISIBLE (widget) ||
6820 !GTK_WIDGET_IS_SENSITIVE (widget))
6823 /* child widgets must set CAN_FOCUS, containers
6824 * don't have to though.
6826 if (!GTK_IS_CONTAINER (widget) &&
6827 !GTK_WIDGET_CAN_FOCUS (widget))
6830 g_signal_emit (widget,
6831 widget_signals[FOCUS],
6833 direction, &return_val);
6839 * gtk_widget_keynav_failed:
6840 * @widget: a #GtkWidget
6841 * @direction: direction of focus movement
6843 * This function should be called whenever keyboard navigation within
6844 * a single widget hits a boundary. The function emits the
6845 * #GtkWidget::keynav-failed signal on the widget and its return
6846 * value should be interpreted in a way similar to the return value of
6847 * gtk_widget_child_focus():
6849 * When %TRUE is returned, stay in the widget, the failed keyboard
6850 * navigation is Ok and/or there is nowhere we can/should move the
6853 * When %FALSE is returned, the caller should continue with keyboard
6854 * navigation outside the widget, e.g. by calling
6855 * gtk_widget_child_focus() on the widget's toplevel.
6857 * The default ::keynav-failed handler returns %TRUE for
6858 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6859 * values of #GtkDirectionType, it looks at the
6860 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6861 * if the setting is %TRUE. This way the entire user interface
6862 * becomes cursor-navigatable on input devices such as mobile phones
6863 * which only have cursor keys but no tab key.
6865 * Whenever the default handler returns %TRUE, it also calls
6866 * gtk_widget_error_bell() to notify the user of the failed keyboard
6869 * A use case for providing an own implementation of ::keynav-failed
6870 * (either by connecting to it or by overriding it) would be a row of
6871 * #GtkEntry widgets where the user should be able to navigate the
6872 * entire row with the cursor keys, as e.g. known from user interfaces
6873 * that require entering license keys.
6875 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6876 * if the emitting widget should try to handle the keyboard
6877 * navigation attempt in its parent container(s).
6882 gtk_widget_keynav_failed (GtkWidget *widget,
6883 GtkDirectionType direction)
6885 gboolean return_val;
6887 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6889 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6890 direction, &return_val);
6896 * gtk_widget_error_bell:
6897 * @widget: a #GtkWidget
6899 * Notifies the user about an input-related error on this widget.
6900 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6901 * gdk_window_beep(), otherwise it does nothing.
6903 * Note that the effect of gdk_window_beep() can be configured in many
6904 * ways, depending on the windowing backend and the desktop environment
6905 * or window manager that is used.
6910 gtk_widget_error_bell (GtkWidget *widget)
6914 g_return_if_fail (GTK_IS_WIDGET (widget));
6916 g_object_get (gtk_widget_get_settings (widget),
6917 "gtk-error-bell", &beep,
6920 if (beep && widget->window)
6921 gdk_window_beep (widget->window);
6925 * gtk_widget_set_uposition:
6926 * @widget: a #GtkWidget
6927 * @x: x position; -1 to unset x; -2 to leave x unchanged
6928 * @y: y position; -1 to unset y; -2 to leave y unchanged
6931 * Sets the position of a widget. The funny "u" in the name comes from
6932 * the "user position" hint specified by the X Window System, and
6933 * exists for legacy reasons. This function doesn't work if a widget
6934 * is inside a container; it's only really useful on #GtkWindow.
6936 * Don't use this function to center dialogs over the main application
6937 * window; most window managers will do the centering on your behalf
6938 * if you call gtk_window_set_transient_for(), and it's really not
6939 * possible to get the centering to work correctly in all cases from
6940 * application code. But if you insist, use gtk_window_set_position()
6941 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6944 * Note that although @x and @y can be individually unset, the position
6945 * is not honoured unless both @x and @y are set.
6948 gtk_widget_set_uposition (GtkWidget *widget,
6952 /* FIXME this function is the only place that aux_info->x and
6953 * aux_info->y are even used I believe, and this function is
6954 * deprecated. Should be cleaned up.
6956 * (Actually, size_allocate uses them) -Yosh
6959 GtkWidgetAuxInfo *aux_info;
6961 g_return_if_fail (GTK_IS_WIDGET (widget));
6963 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
6968 aux_info->x_set = FALSE;
6971 aux_info->x_set = TRUE;
6979 aux_info->y_set = FALSE;
6982 aux_info->y_set = TRUE;
6987 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
6988 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
6990 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
6991 gtk_widget_size_allocate (widget, &widget->allocation);
6995 gtk_widget_set_usize_internal (GtkWidget *widget,
6999 GtkWidgetAuxInfo *aux_info;
7000 gboolean changed = FALSE;
7002 g_object_freeze_notify (G_OBJECT (widget));
7004 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7006 if (width > -2 && aux_info->width != width)
7008 g_object_notify (G_OBJECT (widget), "width-request");
7009 aux_info->width = width;
7012 if (height > -2 && aux_info->height != height)
7014 g_object_notify (G_OBJECT (widget), "height-request");
7015 aux_info->height = height;
7019 if (GTK_WIDGET_VISIBLE (widget) && changed)
7020 gtk_widget_queue_resize (widget);
7022 g_object_thaw_notify (G_OBJECT (widget));
7026 * gtk_widget_set_usize:
7027 * @widget: a #GtkWidget
7028 * @width: minimum width, or -1 to unset
7029 * @height: minimum height, or -1 to unset
7031 * Sets the minimum size of a widget; that is, the widget's size
7032 * request will be @width by @height. You can use this function to
7033 * force a widget to be either larger or smaller than it is. The
7034 * strange "usize" name dates from the early days of GTK+, and derives
7035 * from X Window System terminology. In many cases,
7036 * gtk_window_set_default_size() is a better choice for toplevel
7037 * windows than this function; setting the default size will still
7038 * allow users to shrink the window. Setting the usize will force them
7039 * to leave the window at least as large as the usize. When dealing
7040 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7043 * Note the inherent danger of setting any fixed size - themes,
7044 * translations into other languages, different fonts, and user action
7045 * can all change the appropriate size for a given widget. So, it's
7046 * basically impossible to hardcode a size that will always be
7049 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7052 gtk_widget_set_usize (GtkWidget *widget,
7056 g_return_if_fail (GTK_IS_WIDGET (widget));
7058 gtk_widget_set_usize_internal (widget, width, height);
7062 * gtk_widget_set_size_request:
7063 * @widget: a #GtkWidget
7064 * @width: width @widget should request, or -1 to unset
7065 * @height: height @widget should request, or -1 to unset
7067 * Sets the minimum size of a widget; that is, the widget's size
7068 * request will be @width by @height. You can use this function to
7069 * force a widget to be either larger or smaller than it normally
7072 * In most cases, gtk_window_set_default_size() is a better choice for
7073 * toplevel windows than this function; setting the default size will
7074 * still allow users to shrink the window. Setting the size request
7075 * will force them to leave the window at least as large as the size
7076 * request. When dealing with window sizes,
7077 * gtk_window_set_geometry_hints() can be a useful function as well.
7079 * Note the inherent danger of setting any fixed size - themes,
7080 * translations into other languages, different fonts, and user action
7081 * can all change the appropriate size for a given widget. So, it's
7082 * basically impossible to hardcode a size that will always be
7085 * The size request of a widget is the smallest size a widget can
7086 * accept while still functioning well and drawing itself correctly.
7087 * However in some strange cases a widget may be allocated less than
7088 * its requested size, and in many cases a widget may be allocated more
7089 * space than it requested.
7091 * If the size request in a given direction is -1 (unset), then
7092 * the "natural" size request of the widget will be used instead.
7094 * Widgets can't actually be allocated a size less than 1 by 1, but
7095 * you can pass 0,0 to this function to mean "as small as possible."
7098 gtk_widget_set_size_request (GtkWidget *widget,
7102 g_return_if_fail (GTK_IS_WIDGET (widget));
7103 g_return_if_fail (width >= -1);
7104 g_return_if_fail (height >= -1);
7111 gtk_widget_set_usize_internal (widget, width, height);
7116 * gtk_widget_get_size_request:
7117 * @widget: a #GtkWidget
7118 * @width: return location for width, or %NULL
7119 * @height: return location for height, or %NULL
7121 * Gets the size request that was explicitly set for the widget using
7122 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7123 * @height indicates that that dimension has not been set explicitly
7124 * and the natural requisition of the widget will be used intead. See
7125 * gtk_widget_set_size_request(). To get the size a widget will
7126 * actually use, call gtk_widget_size_request() instead of
7130 gtk_widget_get_size_request (GtkWidget *widget,
7134 GtkWidgetAuxInfo *aux_info;
7136 g_return_if_fail (GTK_IS_WIDGET (widget));
7138 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7141 *width = aux_info ? aux_info->width : -1;
7144 *height = aux_info ? aux_info->height : -1;
7148 * gtk_widget_set_events:
7149 * @widget: a #GtkWidget
7150 * @events: event mask
7152 * Sets the event mask (see #GdkEventMask) for a widget. The event
7153 * mask determines which events a widget will receive. Keep in mind
7154 * that different widgets have different default event masks, and by
7155 * changing the event mask you may disrupt a widget's functionality,
7156 * so be careful. This function must be called while a widget is
7157 * unrealized. Consider gtk_widget_add_events() for widgets that are
7158 * already realized, or if you want to preserve the existing event
7159 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7160 * to get events on those widgets, place them inside a #GtkEventBox
7161 * and receive events on the event box.
7164 gtk_widget_set_events (GtkWidget *widget,
7167 g_return_if_fail (GTK_IS_WIDGET (widget));
7168 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7170 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7171 GINT_TO_POINTER (events));
7172 g_object_notify (G_OBJECT (widget), "events");
7176 gtk_widget_add_events_internal (GtkWidget *widget,
7182 for (l = window_list; l != NULL; l = l->next)
7184 GdkWindow *window = l->data;
7187 gdk_window_get_user_data (window, &user_data);
7188 if (user_data == widget)
7192 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7194 children = gdk_window_get_children (window);
7195 gtk_widget_add_events_internal (widget, events, children);
7196 g_list_free (children);
7202 * gtk_widget_add_events:
7203 * @widget: a #GtkWidget
7204 * @events: an event mask, see #GdkEventMask
7206 * Adds the events in the bitfield @events to the event mask for
7207 * @widget. See gtk_widget_set_events() for details.
7210 gtk_widget_add_events (GtkWidget *widget,
7215 g_return_if_fail (GTK_IS_WIDGET (widget));
7217 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7218 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7219 GINT_TO_POINTER (old_events | events));
7221 if (GTK_WIDGET_REALIZED (widget))
7225 if (GTK_WIDGET_NO_WINDOW (widget))
7226 window_list = gdk_window_get_children (widget->window);
7228 window_list = g_list_prepend (NULL, widget->window);
7230 gtk_widget_add_events_internal (widget, events, window_list);
7232 g_list_free (window_list);
7235 g_object_notify (G_OBJECT (widget), "events");
7239 * gtk_widget_set_extension_events:
7240 * @widget: a #GtkWidget
7241 * @mode: bitfield of extension events to receive
7243 * Sets the extension events mask to @mode. See #GdkExtensionMode
7244 * and gdk_input_set_extension_events().
7247 gtk_widget_set_extension_events (GtkWidget *widget,
7248 GdkExtensionMode mode)
7250 g_return_if_fail (GTK_IS_WIDGET (widget));
7252 if (GTK_WIDGET_REALIZED (widget))
7253 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7255 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7256 GINT_TO_POINTER (mode));
7257 g_object_notify (G_OBJECT (widget), "extension-events");
7261 * gtk_widget_get_toplevel:
7262 * @widget: a #GtkWidget
7264 * This function returns the topmost widget in the container hierarchy
7265 * @widget is a part of. If @widget has no parent widgets, it will be
7266 * returned as the topmost widget. No reference will be added to the
7267 * returned widget; it should not be unreferenced.
7269 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7270 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7272 * %NULL if @widget wasn't inside a toplevel window, and if the
7273 * window was inside a #GtkWindow-derived widget which was in turn
7274 * inside the toplevel #GtkWindow. While the second case may
7275 * seem unlikely, it actually happens when a #GtkPlug is embedded
7276 * inside a #GtkSocket within the same application.
7278 * To reliably find the toplevel #GtkWindow, use
7279 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7280 * is set on the result.
7282 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7283 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7285 * /* Perform action on toplevel. */
7289 * Return value: the topmost ancestor of @widget, or @widget itself
7290 * if there's no ancestor.
7293 gtk_widget_get_toplevel (GtkWidget *widget)
7295 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7297 while (widget->parent)
7298 widget = widget->parent;
7304 * gtk_widget_get_ancestor:
7305 * @widget: a #GtkWidget
7306 * @widget_type: ancestor type
7308 * Gets the first ancestor of @widget with type @widget_type. For example,
7309 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7310 * the first #GtkBox that's an ancestor of @widget. No reference will be
7311 * added to the returned widget; it should not be unreferenced. See note
7312 * about checking for a toplevel #GtkWindow in the docs for
7313 * gtk_widget_get_toplevel().
7315 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7316 * considers @widget to be an ancestor of itself.
7318 * Return value: the ancestor widget, or %NULL if not found
7321 gtk_widget_get_ancestor (GtkWidget *widget,
7324 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7326 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7327 widget = widget->parent;
7329 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7336 * gtk_widget_get_colormap:
7337 * @widget: a #GtkWidget
7339 * Gets the colormap that will be used to render @widget. No reference will
7340 * be added to the returned colormap; it should not be unreferenced.
7342 * Return value: the colormap used by @widget
7345 gtk_widget_get_colormap (GtkWidget *widget)
7347 GdkColormap *colormap;
7348 GtkWidget *tmp_widget;
7350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7354 colormap = gdk_drawable_get_colormap (widget->window);
7355 /* If window was destroyed previously, we'll get NULL here */
7360 tmp_widget = widget;
7363 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7367 tmp_widget= tmp_widget->parent;
7370 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7374 * gtk_widget_get_visual:
7375 * @widget: a #GtkWidget
7377 * Gets the visual that will be used to render @widget.
7379 * Return value: the visual for @widget
7382 gtk_widget_get_visual (GtkWidget *widget)
7384 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7386 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7390 * gtk_widget_get_settings:
7391 * @widget: a #GtkWidget
7393 * Gets the settings object holding the settings (global property
7394 * settings, RC file information, etc) used for this widget.
7396 * Note that this function can only be called when the #GtkWidget
7397 * is attached to a toplevel, since the settings object is specific
7398 * to a particular #GdkScreen.
7400 * Return value: the relevant #GtkSettings object
7403 gtk_widget_get_settings (GtkWidget *widget)
7405 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7407 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7411 * gtk_widget_set_colormap:
7412 * @widget: a #GtkWidget
7413 * @colormap: a colormap
7415 * Sets the colormap for the widget to the given value. Widget must not
7416 * have been previously realized. This probably should only be used
7417 * from an <function>init()</function> function (i.e. from the constructor
7421 gtk_widget_set_colormap (GtkWidget *widget,
7422 GdkColormap *colormap)
7424 g_return_if_fail (GTK_IS_WIDGET (widget));
7425 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7426 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7428 g_object_ref (colormap);
7430 g_object_set_qdata_full (G_OBJECT (widget),
7437 * gtk_widget_get_events:
7438 * @widget: a #GtkWidget
7440 * Returns the event mask for the widget (a bitfield containing flags
7441 * from the #GdkEventMask enumeration). These are the events that the widget
7444 * Return value: event mask for @widget
7447 gtk_widget_get_events (GtkWidget *widget)
7449 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7451 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7455 * gtk_widget_get_extension_events:
7456 * @widget: a #GtkWidget
7458 * Retrieves the extension events the widget will receive; see
7459 * gdk_input_set_extension_events().
7461 * Return value: extension events for @widget
7464 gtk_widget_get_extension_events (GtkWidget *widget)
7466 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7468 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7472 * gtk_widget_get_pointer:
7473 * @widget: a #GtkWidget
7474 * @x: return location for the X coordinate, or %NULL
7475 * @y: return location for the Y coordinate, or %NULL
7477 * Obtains the location of the mouse pointer in widget coordinates.
7478 * Widget coordinates are a bit odd; for historical reasons, they are
7479 * defined as @widget->window coordinates for widgets that are not
7480 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7481 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7484 gtk_widget_get_pointer (GtkWidget *widget,
7488 g_return_if_fail (GTK_IS_WIDGET (widget));
7495 if (GTK_WIDGET_REALIZED (widget))
7497 gdk_window_get_pointer (widget->window, x, y, NULL);
7499 if (GTK_WIDGET_NO_WINDOW (widget))
7502 *x -= widget->allocation.x;
7504 *y -= widget->allocation.y;
7510 * gtk_widget_is_ancestor:
7511 * @widget: a #GtkWidget
7512 * @ancestor: another #GtkWidget
7514 * Determines whether @widget is somewhere inside @ancestor, possibly with
7515 * intermediate containers.
7517 * Return value: %TRUE if @ancestor contains @widget as a child,
7518 * grandchild, great grandchild, etc.
7521 gtk_widget_is_ancestor (GtkWidget *widget,
7522 GtkWidget *ancestor)
7524 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7525 g_return_val_if_fail (ancestor != NULL, FALSE);
7529 if (widget->parent == ancestor)
7531 widget = widget->parent;
7537 static GQuark quark_composite_name = 0;
7540 * gtk_widget_set_composite_name:
7541 * @widget: a #GtkWidget.
7542 * @name: the name to set
7544 * Sets a widgets composite name. The widget must be
7545 * a composite child of its parent; see gtk_widget_push_composite_child().
7548 gtk_widget_set_composite_name (GtkWidget *widget,
7551 g_return_if_fail (GTK_IS_WIDGET (widget));
7552 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7553 g_return_if_fail (name != NULL);
7555 if (!quark_composite_name)
7556 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7558 g_object_set_qdata_full (G_OBJECT (widget),
7559 quark_composite_name,
7565 * gtk_widget_get_composite_name:
7566 * @widget: a #GtkWidget
7567 * @returns: the composite name of @widget, or %NULL if @widget is not
7568 * a composite child. The string should not be freed when it is no
7571 * Obtains the composite name of a widget.
7574 gtk_widget_get_composite_name (GtkWidget *widget)
7576 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7578 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7579 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7586 * gtk_widget_push_composite_child:
7588 * Makes all newly-created widgets as composite children until
7589 * the corresponding gtk_widget_pop_composite_child() call.
7591 * A composite child is a child that's an implementation detail of the
7592 * container it's inside and should not be visible to people using the
7593 * container. Composite children aren't treated differently by GTK (but
7594 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7595 * builders might want to treat them in a different way.
7597 * Here is a simple example:
7599 * gtk_widget_push_composite_child ();
7600 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7601 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7602 * gtk_widget_pop_composite_child ();
7603 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7604 * GTK_WIDGET (scrolled_window));
7605 * g_object_ref (scrolled_window->hscrollbar);
7609 gtk_widget_push_composite_child (void)
7611 composite_child_stack++;
7615 * gtk_widget_pop_composite_child:
7617 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7620 gtk_widget_pop_composite_child (void)
7622 if (composite_child_stack)
7623 composite_child_stack--;
7627 * gtk_widget_push_colormap:
7628 * @cmap: a #GdkColormap
7630 * Pushes @cmap onto a global stack of colormaps; the topmost
7631 * colormap on the stack will be used to create all widgets.
7632 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7633 * reason to use this function.
7636 gtk_widget_push_colormap (GdkColormap *cmap)
7638 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7640 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7644 * gtk_widget_pop_colormap:
7646 * Removes a colormap pushed with gtk_widget_push_colormap().
7649 gtk_widget_pop_colormap (void)
7652 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7656 * gtk_widget_set_default_colormap:
7657 * @colormap: a #GdkColormap
7659 * Sets the default colormap to use when creating widgets.
7660 * gtk_widget_push_colormap() is a better function to use if
7661 * you only want to affect a few widgets, rather than all widgets.
7664 gtk_widget_set_default_colormap (GdkColormap *colormap)
7666 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7668 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7673 * gtk_widget_get_default_colormap:
7675 * Obtains the default colormap used to create widgets.
7677 * Return value: default widget colormap
7680 gtk_widget_get_default_colormap (void)
7682 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7686 * gtk_widget_get_default_visual:
7688 * Obtains the visual of the default colormap. Not really useful;
7689 * used to be useful before gdk_colormap_get_visual() existed.
7691 * Return value: visual of the default colormap
7694 gtk_widget_get_default_visual (void)
7696 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7700 gtk_widget_emit_direction_changed (GtkWidget *widget,
7701 GtkTextDirection old_dir)
7703 gtk_widget_update_pango_context (widget);
7705 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7709 * gtk_widget_set_direction:
7710 * @widget: a #GtkWidget
7711 * @dir: the new direction
7713 * Sets the reading direction on a particular widget. This direction
7714 * controls the primary direction for widgets containing text,
7715 * and also the direction in which the children of a container are
7716 * packed. The ability to set the direction is present in order
7717 * so that correct localization into languages with right-to-left
7718 * reading directions can be done. Generally, applications will
7719 * let the default reading direction present, except for containers
7720 * where the containers are arranged in an order that is explicitely
7721 * visual rather than logical (such as buttons for text justification).
7723 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7724 * set by gtk_widget_set_default_direction() will be used.
7727 gtk_widget_set_direction (GtkWidget *widget,
7728 GtkTextDirection dir)
7730 GtkTextDirection old_dir;
7732 g_return_if_fail (GTK_IS_WIDGET (widget));
7733 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7735 old_dir = gtk_widget_get_direction (widget);
7737 if (dir == GTK_TEXT_DIR_NONE)
7738 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7741 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7742 if (dir == GTK_TEXT_DIR_LTR)
7743 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7745 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7748 if (old_dir != gtk_widget_get_direction (widget))
7749 gtk_widget_emit_direction_changed (widget, old_dir);
7753 * gtk_widget_get_direction:
7754 * @widget: a #GtkWidget
7756 * Gets the reading direction for a particular widget. See
7757 * gtk_widget_set_direction().
7759 * Return value: the reading direction for the widget.
7762 gtk_widget_get_direction (GtkWidget *widget)
7764 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7766 if (GTK_WIDGET_DIRECTION_SET (widget))
7767 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7769 return gtk_default_direction;
7773 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7775 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7777 g_object_ref (widget);
7779 if (!GTK_WIDGET_DIRECTION_SET (widget))
7780 gtk_widget_emit_direction_changed (widget, old_dir);
7782 if (GTK_IS_CONTAINER (widget))
7783 gtk_container_forall (GTK_CONTAINER (widget),
7784 gtk_widget_set_default_direction_recurse,
7787 g_object_unref (widget);
7791 * gtk_widget_set_default_direction:
7792 * @dir: the new default direction. This cannot be
7793 * %GTK_TEXT_DIR_NONE.
7795 * Sets the default reading direction for widgets where the
7796 * direction has not been explicitly set by gtk_widget_set_direction().
7799 gtk_widget_set_default_direction (GtkTextDirection dir)
7801 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7803 if (dir != gtk_default_direction)
7805 GList *toplevels, *tmp_list;
7806 GtkTextDirection old_dir = gtk_default_direction;
7808 gtk_default_direction = dir;
7810 tmp_list = toplevels = gtk_window_list_toplevels ();
7811 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7815 gtk_widget_set_default_direction_recurse (tmp_list->data,
7816 GUINT_TO_POINTER (old_dir));
7817 g_object_unref (tmp_list->data);
7818 tmp_list = tmp_list->next;
7821 g_list_free (toplevels);
7826 * gtk_widget_get_default_direction:
7828 * Obtains the current default reading direction. See
7829 * gtk_widget_set_default_direction().
7831 * Return value: the current default direction.
7834 gtk_widget_get_default_direction (void)
7836 return gtk_default_direction;
7840 gtk_widget_dispose (GObject *object)
7842 GtkWidget *widget = GTK_WIDGET (object);
7845 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7846 else if (GTK_WIDGET_VISIBLE (widget))
7847 gtk_widget_hide (widget);
7849 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7850 if (GTK_WIDGET_REALIZED (widget))
7851 gtk_widget_unrealize (widget);
7853 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7857 gtk_widget_real_destroy (GtkObject *object)
7859 /* gtk_object_destroy() will already hold a refcount on object */
7860 GtkWidget *widget = GTK_WIDGET (object);
7862 /* wipe accelerator closures (keep order) */
7863 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7864 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7866 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7867 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7869 gtk_grab_remove (widget);
7871 g_object_unref (widget->style);
7872 widget->style = gtk_widget_get_default_style ();
7873 g_object_ref (widget->style);
7875 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7879 gtk_widget_finalize (GObject *object)
7881 GtkWidget *widget = GTK_WIDGET (object);
7882 GtkWidgetAuxInfo *aux_info;
7883 GtkAccessible *accessible;
7885 gtk_grab_remove (widget);
7887 g_object_unref (widget->style);
7888 widget->style = NULL;
7890 g_free (widget->name);
7892 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7894 gtk_widget_aux_info_destroy (aux_info);
7896 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7898 g_object_unref (accessible);
7900 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7903 /*****************************************
7904 * gtk_widget_real_map:
7909 *****************************************/
7912 gtk_widget_real_map (GtkWidget *widget)
7914 g_assert (GTK_WIDGET_REALIZED (widget));
7916 if (!GTK_WIDGET_MAPPED (widget))
7918 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7920 if (!GTK_WIDGET_NO_WINDOW (widget))
7921 gdk_window_show (widget->window);
7925 /*****************************************
7926 * gtk_widget_real_unmap:
7931 *****************************************/
7934 gtk_widget_real_unmap (GtkWidget *widget)
7936 if (GTK_WIDGET_MAPPED (widget))
7938 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7940 if (!GTK_WIDGET_NO_WINDOW (widget))
7941 gdk_window_hide (widget->window);
7945 /*****************************************
7946 * gtk_widget_real_realize:
7951 *****************************************/
7954 gtk_widget_real_realize (GtkWidget *widget)
7956 g_assert (GTK_WIDGET_NO_WINDOW (widget));
7958 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7961 widget->window = gtk_widget_get_parent_window (widget);
7962 g_object_ref (widget->window);
7964 widget->style = gtk_style_attach (widget->style, widget->window);
7967 /*****************************************
7968 * gtk_widget_real_unrealize:
7973 *****************************************/
7976 gtk_widget_real_unrealize (GtkWidget *widget)
7978 if (GTK_WIDGET_MAPPED (widget))
7979 gtk_widget_real_unmap (widget);
7981 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7983 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
7986 /* We must do unrealize child widget BEFORE container widget.
7987 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
7988 * So, unrealizing container widget bofore its children causes the problem
7989 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
7992 if (GTK_IS_CONTAINER (widget))
7993 gtk_container_forall (GTK_CONTAINER (widget),
7994 (GtkCallback) gtk_widget_unrealize,
7997 gtk_style_detach (widget->style);
7998 if (!GTK_WIDGET_NO_WINDOW (widget))
8000 gdk_window_set_user_data (widget->window, NULL);
8001 gdk_window_destroy (widget->window);
8002 widget->window = NULL;
8006 g_object_unref (widget->window);
8007 widget->window = NULL;
8010 gtk_selection_remove_all (widget);
8012 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8016 gtk_widget_real_size_request (GtkWidget *widget,
8017 GtkRequisition *requisition)
8019 requisition->width = widget->requisition.width;
8020 requisition->height = widget->requisition.height;
8024 * _gtk_widget_peek_colormap:
8026 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8028 * Return value: the currently pushed colormap, or %NULL if there is none.
8031 _gtk_widget_peek_colormap (void)
8034 return (GdkColormap*) colormap_stack->data;
8039 gtk_widget_propagate_state (GtkWidget *widget,
8042 guint8 old_state = GTK_WIDGET_STATE (widget);
8043 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8045 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8046 * parent_sensitive==TRUE on a sensitive widget
8050 if (data->parent_sensitive)
8051 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8053 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8055 if (GTK_WIDGET_IS_SENSITIVE (widget))
8057 if (data->state_restoration)
8058 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8060 GTK_WIDGET_STATE (widget) = data->state;
8064 if (!data->state_restoration)
8066 if (data->state != GTK_STATE_INSENSITIVE)
8067 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8069 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8070 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8071 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8074 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8078 window = gtk_widget_get_toplevel (widget);
8079 if (window && GTK_WIDGET_TOPLEVEL (window))
8080 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8083 if (old_state != GTK_WIDGET_STATE (widget) ||
8084 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8086 g_object_ref (widget);
8088 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8089 gtk_grab_remove (widget);
8091 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8093 if (GTK_IS_CONTAINER (widget))
8095 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8096 if (data->use_forall)
8097 gtk_container_forall (GTK_CONTAINER (widget),
8098 (GtkCallback) gtk_widget_propagate_state,
8101 gtk_container_foreach (GTK_CONTAINER (widget),
8102 (GtkCallback) gtk_widget_propagate_state,
8105 g_object_unref (widget);
8110 * _gtk_widget_get_aux_info:
8111 * @widget: a #GtkWidget
8112 * @create: if %TRUE, create the structure if it doesn't exist
8114 * Get the #GtkWidgetAuxInfo structure for the widget.
8116 * Return value: the #GtkAuxInfo structure for the widget, or
8117 * %NULL if @create is %FALSE and one doesn't already exist.
8120 _gtk_widget_get_aux_info (GtkWidget *widget,
8123 GtkWidgetAuxInfo *aux_info;
8125 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8126 if (!aux_info && create)
8128 aux_info = g_slice_new (GtkWidgetAuxInfo);
8130 aux_info->width = -1;
8131 aux_info->height = -1;
8134 aux_info->x_set = FALSE;
8135 aux_info->y_set = FALSE;
8136 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8142 /*****************************************
8143 * gtk_widget_aux_info_destroy:
8148 *****************************************/
8151 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8153 g_slice_free (GtkWidgetAuxInfo, aux_info);
8157 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8159 g_object_unref (info->shape_mask);
8160 g_slice_free (GtkWidgetShapeInfo, info);
8164 * gtk_widget_shape_combine_mask:
8165 * @widget: a #GtkWidget
8166 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8167 * @offset_x: X position of shape mask with respect to @window
8168 * @offset_y: Y position of shape mask with respect to @window
8170 * Sets a shape for this widget's GDK window. This allows for
8171 * transparent windows etc., see gdk_window_shape_combine_mask()
8172 * for more information.
8175 gtk_widget_shape_combine_mask (GtkWidget *widget,
8176 GdkBitmap *shape_mask,
8180 GtkWidgetShapeInfo* shape_info;
8182 g_return_if_fail (GTK_IS_WIDGET (widget));
8183 /* set_shape doesn't work on widgets without gdk window */
8184 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8188 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8191 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8193 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8197 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8199 shape_info = g_slice_new (GtkWidgetShapeInfo);
8200 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8201 (GDestroyNotify) gtk_widget_shape_info_destroy);
8203 shape_info->shape_mask = g_object_ref (shape_mask);
8204 shape_info->offset_x = offset_x;
8205 shape_info->offset_y = offset_y;
8207 /* set shape if widget has a gdk window already.
8208 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8211 gdk_window_shape_combine_mask (widget->window, shape_mask,
8212 offset_x, offset_y);
8217 * gtk_widget_input_shape_combine_mask:
8218 * @widget: a #GtkWidget
8219 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8220 * @offset_x: X position of shape mask with respect to @window
8221 * @offset_y: Y position of shape mask with respect to @window
8223 * Sets an input shape for this widget's GDK window. This allows for
8224 * windows which react to mouse click in a nonrectangular region, see
8225 * gdk_window_input_shape_combine_mask() for more information.
8230 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8231 GdkBitmap *shape_mask,
8235 GtkWidgetShapeInfo* shape_info;
8237 g_return_if_fail (GTK_IS_WIDGET (widget));
8238 /* set_shape doesn't work on widgets without gdk window */
8239 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8244 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8246 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8250 shape_info = g_slice_new (GtkWidgetShapeInfo);
8251 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8253 (GDestroyNotify) gtk_widget_shape_info_destroy);
8255 shape_info->shape_mask = g_object_ref (shape_mask);
8256 shape_info->offset_x = offset_x;
8257 shape_info->offset_y = offset_y;
8259 /* set shape if widget has a gdk window already.
8260 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8263 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8264 offset_x, offset_y);
8270 gtk_reset_shapes_recurse (GtkWidget *widget,
8276 gdk_window_get_user_data (window, &data);
8280 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8281 for (list = gdk_window_peek_children (window); list; list = list->next)
8282 gtk_reset_shapes_recurse (widget, list->data);
8286 * gtk_widget_reset_shapes:
8287 * @widget: a #GtkWidget
8289 * Recursively resets the shape on this widget and its descendants.
8292 gtk_widget_reset_shapes (GtkWidget *widget)
8294 g_return_if_fail (GTK_IS_WIDGET (widget));
8295 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8297 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8298 gtk_reset_shapes_recurse (widget, widget->window);
8303 * @widget: a #GtkWidget
8305 * Adds a reference to a widget. This function is exactly the same
8306 * as calling g_object_ref(), and exists mostly for historical
8307 * reasons. It can still be convenient to avoid casting a widget
8308 * to a #GObject, it saves a small amount of typing.
8310 * Return value: the widget that was referenced
8312 * Deprecated: 2.12: Use g_object_ref() instead.
8315 gtk_widget_ref (GtkWidget *widget)
8317 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8319 return (GtkWidget*) g_object_ref ((GObject*) widget);
8324 * @widget: a #GtkWidget
8326 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8328 * Deprecated: 2.12: Use g_object_unref() instead.
8331 gtk_widget_unref (GtkWidget *widget)
8333 g_return_if_fail (GTK_IS_WIDGET (widget));
8335 g_object_unref ((GObject*) widget);
8339 * gtk_widget_get_snapshot:
8340 * @widget: a #GtkWidget
8341 * @clip_rect: a #GdkRectangle or %NULL
8343 * Create a #GdkPixmap of the contents of the widget and its children.
8345 * Works even if the widget is obscured. The depth and visual of the
8346 * resulting pixmap is dependent on the widget being snapshot and likely
8347 * differs from those of a target widget displaying the pixmap.
8348 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8349 * the pixmap to a visual independant representation.
8351 * The snapshot area used by this function is the @widget's allocation plus
8352 * any extra space occupied by additional windows belonging to this widget
8353 * (such as the arrows of a spin button).
8354 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8356 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8357 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8358 * interpreted widget relative. If width or height of @clip_rect are 0 or
8359 * negative, the width or height of the resulting pixmap will be shrunken
8360 * by the respective amount.
8361 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8362 * chop off 5 pixels at each side of the snapshot pixmap.
8363 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8364 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8365 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8366 * as a pure output parameter.
8368 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8370 * Return value: #GdkPixmap snapshot of the widget
8375 gtk_widget_get_snapshot (GtkWidget *widget,
8376 GdkRectangle *clip_rect)
8378 int x, y, width, height;
8379 GdkWindow *parent_window = NULL;
8381 GList *windows = NULL, *list;
8383 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8384 if (!GTK_WIDGET_VISIBLE (widget))
8387 /* the widget (and parent_window) must be realized to be drawable */
8388 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8389 gtk_widget_realize (widget->parent);
8390 if (!GTK_WIDGET_REALIZED (widget))
8391 gtk_widget_realize (widget);
8393 /* determine snapshot rectangle */
8394 x = widget->allocation.x;
8395 y = widget->allocation.y;
8396 width = widget->allocation.width;
8397 height = widget->allocation.height;
8399 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8401 /* grow snapshot rectangle to cover all widget windows */
8402 parent_window = gtk_widget_get_parent_window (widget);
8403 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8405 GdkWindow *subwin = list->data;
8408 gdk_window_get_user_data (subwin, &windata);
8409 if (windata != widget)
8411 windows = g_list_prepend (windows, subwin);
8412 gdk_window_get_position (subwin, &wx, &wy);
8413 gdk_drawable_get_size (subwin, &ww, &wh);
8414 /* grow snapshot rectangle by extra widget sub window */
8425 if (x + width < wx + ww)
8426 width += wx + ww - (x + width);
8427 if (y + height < wy + wh)
8428 height += wy + wh - (y + height);
8431 else if (!widget->parent)
8432 x = y = 0; /* toplevel */
8434 /* at this point, (x,y,width,height) is the parent_window relative
8435 * snapshot area covering all of widget's windows.
8438 /* shrink snapshot size by clip_rectangle */
8441 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8442 clip.x = clip.x < 0 ? x : clip.x;
8443 clip.y = clip.y < 0 ? y : clip.y;
8444 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8445 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8448 /* offset clip_rect, so it's parent_window relative */
8449 if (clip_rect->x >= 0)
8450 clip.x += widget->allocation.x;
8451 if (clip_rect->y >= 0)
8452 clip.y += widget->allocation.y;
8454 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8456 g_list_free (windows);
8457 clip_rect->width = clip_rect->height = 0;
8458 return NULL; /* empty snapshot area */
8463 height = snap.height;
8466 /* render snapshot */
8467 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8468 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8470 GdkWindow *subwin = list->data;
8472 gdk_window_get_position (subwin, &wx, &wy);
8473 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8474 MAX (0, wx - x), MAX (0, wy - y), width, height);
8475 gdk_window_invalidate_rect (subwin, NULL, TRUE);
8477 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8479 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8480 gdk_window_invalidate_rect (widget->window, NULL, TRUE);
8482 gtk_widget_queue_draw (widget);
8484 gdk_window_process_updates (parent_window, TRUE);
8485 for (list = windows; list; list = list->next)
8486 gdk_window_process_updates (list->data, TRUE);
8487 gdk_window_process_updates (widget->window, TRUE);
8488 for (list = windows; list; list = list->next)
8489 gdk_window_remove_redirection (list->data);
8490 if (!windows) /* NO_WINDOW || toplevel */
8491 gdk_window_remove_redirection (widget->window);
8492 g_list_free (windows);
8494 /* return pixmap and snapshot rectangle coordinates */
8499 clip_rect->width = width;
8500 clip_rect->height = height;
8503 /* offset clip_rect from parent_window so it's widget relative */
8504 clip_rect->x -= widget->allocation.x;
8505 clip_rect->y -= widget->allocation.y;
8508 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8509 G_OBJECT_TYPE_NAME (widget),
8510 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8519 * gtk_widget_class_install_style_property_parser:
8520 * @klass: a #GtkWidgetClass
8521 * @pspec: the #GParamSpec for the style property
8522 * @parser: the parser for the style property
8524 * Installs a style property on a widget class.
8527 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8529 GtkRcPropertyParser parser)
8531 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8532 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8533 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8534 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8536 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8538 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8539 G_OBJECT_CLASS_NAME (klass),
8544 g_param_spec_ref_sink (pspec);
8545 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8546 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8550 * gtk_widget_class_install_style_property:
8551 * @klass: a #GtkWidgetClass
8552 * @pspec: the #GParamSpec for the property
8554 * Installs a style property on a widget class. The parser for the
8555 * style property is determined by the value type of @pspec.
8558 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8561 GtkRcPropertyParser parser;
8563 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8564 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8566 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8568 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8572 * gtk_widget_class_find_style_property:
8573 * @klass: a #GtkWidgetClass
8574 * @property_name: the name of the style property to find
8575 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8576 * style property with that name.
8578 * Finds a style property of a widget class by name.
8583 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8584 const gchar *property_name)
8586 g_return_val_if_fail (property_name != NULL, NULL);
8588 return g_param_spec_pool_lookup (style_property_spec_pool,
8590 G_OBJECT_CLASS_TYPE (klass),
8595 * gtk_widget_class_list_style_properties:
8596 * @klass: a #GtkWidgetClass
8597 * @n_properties: location to return the number of style properties found
8598 * @returns: an newly allocated array of #GParamSpec*. The array must
8599 * be freed with g_free().
8601 * Returns all style properties of a widget class.
8606 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
8607 guint *n_properties)
8609 GParamSpec **pspecs;
8612 pspecs = g_param_spec_pool_list (style_property_spec_pool,
8613 G_OBJECT_CLASS_TYPE (klass),
8622 * gtk_widget_style_get_property:
8623 * @widget: a #GtkWidget
8624 * @property_name: the name of a style property
8625 * @value: location to return the property value
8627 * Gets the value of a style property of @widget.
8630 gtk_widget_style_get_property (GtkWidget *widget,
8631 const gchar *property_name,
8636 g_return_if_fail (GTK_IS_WIDGET (widget));
8637 g_return_if_fail (property_name != NULL);
8638 g_return_if_fail (G_IS_VALUE (value));
8640 g_object_ref (widget);
8641 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8643 G_OBJECT_TYPE (widget),
8646 g_warning ("%s: widget class `%s' has no property named `%s'",
8648 G_OBJECT_TYPE_NAME (widget),
8652 const GValue *peek_value;
8654 peek_value = _gtk_style_peek_property_value (widget->style,
8655 G_OBJECT_TYPE (widget),
8657 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8659 /* auto-conversion of the caller's value type
8661 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
8662 g_value_copy (peek_value, value);
8663 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
8664 g_value_transform (peek_value, value);
8666 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
8668 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
8669 G_VALUE_TYPE_NAME (value));
8671 g_object_unref (widget);
8675 * gtk_widget_style_get_valist:
8676 * @widget: a #GtkWidget
8677 * @first_property_name: the name of the first property to get
8678 * @var_args: a <type>va_list</type> of pairs of property names and
8679 * locations to return the property values, starting with the location
8680 * for @first_property_name.
8682 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
8686 gtk_widget_style_get_valist (GtkWidget *widget,
8687 const gchar *first_property_name,
8692 g_return_if_fail (GTK_IS_WIDGET (widget));
8694 g_object_ref (widget);
8696 name = first_property_name;
8699 const GValue *peek_value;
8703 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8705 G_OBJECT_TYPE (widget),
8709 g_warning ("%s: widget class `%s' has no property named `%s'",
8711 G_OBJECT_TYPE_NAME (widget),
8715 /* style pspecs are always readable so we can spare that check here */
8717 peek_value = _gtk_style_peek_property_value (widget->style,
8718 G_OBJECT_TYPE (widget),
8720 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8721 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
8724 g_warning ("%s: %s", G_STRLOC, error);
8729 name = va_arg (var_args, gchar*);
8732 g_object_unref (widget);
8736 * gtk_widget_style_get:
8737 * @widget: a #GtkWidget
8738 * @first_property_name: the name of the first property to get
8739 * @Varargs: pairs of property names and locations to
8740 * return the property values, starting with the location for
8741 * @first_property_name, terminated by %NULL.
8743 * Gets the values of a multiple style properties of @widget.
8746 gtk_widget_style_get (GtkWidget *widget,
8747 const gchar *first_property_name,
8752 g_return_if_fail (GTK_IS_WIDGET (widget));
8754 va_start (var_args, first_property_name);
8755 gtk_widget_style_get_valist (widget, first_property_name, var_args);
8761 * @widget: a #GtkWidget
8762 * @path_length: location to store length of the path, or %NULL
8763 * @path: location to store allocated path string, or %NULL
8764 * @path_reversed: location to store allocated reverse path string, or %NULL
8766 * Obtains the full path to @widget. The path is simply the name of a
8767 * widget and all its parents in the container hierarchy, separated by
8768 * periods. The name of a widget comes from
8769 * gtk_widget_get_name(). Paths are used to apply styles to a widget
8770 * in gtkrc configuration files. Widget names are the type of the
8771 * widget by default (e.g. "GtkButton") or can be set to an
8772 * application-specific value with gtk_widget_set_name(). By setting
8773 * the name of a widget, you allow users or theme authors to apply
8774 * styles to that specific widget in their gtkrc
8775 * file. @path_reversed_p fills in the path in reverse order,
8776 * i.e. starting with @widget's name instead of starting with the name
8777 * of @widget's outermost ancestor.
8780 gtk_widget_path (GtkWidget *widget,
8783 gchar **path_reversed)
8785 static gchar *rev_path = NULL;
8786 static guint tmp_path_len = 0;
8789 g_return_if_fail (GTK_IS_WIDGET (widget));
8794 const gchar *string;
8799 string = gtk_widget_get_name (widget);
8800 l = strlen (string);
8801 while (tmp_path_len <= len + l + 1)
8803 tmp_path_len += INIT_PATH_SIZE;
8804 rev_path = g_realloc (rev_path, tmp_path_len);
8812 widget = widget->parent;
8815 rev_path[len++] = '.';
8817 rev_path[len++] = 0;
8822 *path_length = len - 1;
8824 *path_reversed = g_strdup (rev_path);
8827 *path = g_strdup (rev_path);
8828 g_strreverse (*path);
8833 * gtk_widget_class_path:
8834 * @widget: a #GtkWidget
8835 * @path_length: location to store the length of the class path, or %NULL
8836 * @path: location to store the class path as an allocated string, or %NULL
8837 * @path_reversed: location to store the reverse class path as an allocated
8840 * Same as gtk_widget_path(), but always uses the name of a widget's type,
8841 * never uses a custom name set with gtk_widget_set_name().
8845 gtk_widget_class_path (GtkWidget *widget,
8848 gchar **path_reversed)
8850 static gchar *rev_path = NULL;
8851 static guint tmp_path_len = 0;
8854 g_return_if_fail (GTK_IS_WIDGET (widget));
8859 const gchar *string;
8864 string = g_type_name (GTK_WIDGET_TYPE (widget));
8865 l = strlen (string);
8866 while (tmp_path_len <= len + l + 1)
8868 tmp_path_len += INIT_PATH_SIZE;
8869 rev_path = g_realloc (rev_path, tmp_path_len);
8877 widget = widget->parent;
8880 rev_path[len++] = '.';
8882 rev_path[len++] = 0;
8887 *path_length = len - 1;
8889 *path_reversed = g_strdup (rev_path);
8892 *path = g_strdup (rev_path);
8893 g_strreverse (*path);
8898 * gtk_requisition_copy:
8899 * @requisition: a #GtkRequisition
8901 * Copies a #GtkRequisition.
8903 * Returns: a copy of @requisition
8906 gtk_requisition_copy (const GtkRequisition *requisition)
8908 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
8912 * gtk_requisition_free:
8913 * @requisition: a #GtkRequisition
8915 * Frees a #GtkRequisition.
8918 gtk_requisition_free (GtkRequisition *requisition)
8920 g_free (requisition);
8924 gtk_requisition_get_type (void)
8926 static GType our_type = 0;
8929 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
8930 (GBoxedCopyFunc) gtk_requisition_copy,
8931 (GBoxedFreeFunc) gtk_requisition_free);
8937 * gtk_widget_get_accessible:
8938 * @widget: a #GtkWidget
8940 * Returns the accessible object that describes the widget to an
8941 * assistive technology.
8943 * If no accessibility library is loaded (i.e. no ATK implementation library is
8944 * loaded via <envar>GTK_MODULES</envar> or via another application library,
8945 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
8946 * if no class-specific #AtkObject implementation is available for the widget
8947 * instance in question, it will inherit an #AtkObject implementation from the
8948 * first ancestor class for which such an implementation is defined.
8950 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
8951 * library contains more information about accessible objects and their uses.
8953 * Returns: the #AtkObject associated with @widget
8956 gtk_widget_get_accessible (GtkWidget *widget)
8958 GtkWidgetClass *klass;
8960 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8962 klass = GTK_WIDGET_GET_CLASS (widget);
8964 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
8966 return klass->get_accessible (widget);
8970 gtk_widget_real_get_accessible (GtkWidget *widget)
8972 AtkObject* accessible;
8974 accessible = g_object_get_qdata (G_OBJECT (widget),
8975 quark_accessible_object);
8978 AtkObjectFactory *factory;
8979 AtkRegistry *default_registry;
8981 default_registry = atk_get_default_registry ();
8982 factory = atk_registry_get_factory (default_registry,
8983 G_TYPE_FROM_INSTANCE (widget));
8985 atk_object_factory_create_accessible (factory,
8987 g_object_set_qdata (G_OBJECT (widget),
8988 quark_accessible_object,
8995 * Initialize a AtkImplementorIface instance's virtual pointers as
8996 * appropriate to this implementor's class (GtkWidget).
8999 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9001 iface->ref_accessible = gtk_widget_ref_accessible;
9005 gtk_widget_ref_accessible (AtkImplementor *implementor)
9007 AtkObject *accessible;
9009 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9011 g_object_ref (accessible);
9016 * GtkBuildable implementation
9018 static GQuark quark_builder_has_default = 0;
9019 static GQuark quark_builder_has_focus = 0;
9020 static GQuark quark_builder_atk_relations = 0;
9023 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9025 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9026 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9027 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9029 iface->set_name = gtk_widget_buildable_set_name;
9030 iface->get_name = gtk_widget_buildable_get_name;
9031 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9032 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9033 iface->parser_finished = gtk_widget_buildable_parser_finished;
9034 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9035 iface->custom_finished = gtk_widget_buildable_custom_finished;
9039 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9042 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9045 static const gchar *
9046 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9048 return gtk_widget_get_name (GTK_WIDGET (buildable));
9052 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9053 GtkBuilder *builder,
9054 const gchar *childname)
9056 if (strcmp (childname, "accessible") == 0)
9057 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9063 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9064 GtkBuilder *builder,
9066 const GValue *value)
9068 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9069 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9070 GINT_TO_POINTER (TRUE));
9071 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9072 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9073 GINT_TO_POINTER (TRUE));
9075 g_object_set_property (G_OBJECT (buildable), name, value);
9089 free_action (AtkActionData *data, gpointer user_data)
9091 g_free (data->action_name);
9092 g_free (data->description);
9093 g_slice_free (AtkActionData, data);
9097 free_relation (AtkRelationData *data, gpointer user_data)
9099 g_free (data->target);
9100 g_free (data->type);
9101 g_slice_free (AtkRelationData, data);
9105 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9106 GtkBuilder *builder)
9108 GSList *atk_relations;
9110 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9111 gtk_widget_grab_default (GTK_WIDGET (buildable));
9112 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9113 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9115 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9116 quark_builder_atk_relations);
9119 AtkObject *accessible;
9120 AtkRelationSet *relation_set;
9123 AtkRelationType relation_type;
9124 AtkObject *target_accessible;
9126 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9127 relation_set = atk_object_ref_relation_set (accessible);
9129 for (l = atk_relations; l; l = l->next)
9131 AtkRelationData *relation = (AtkRelationData*)l->data;
9133 target = gtk_builder_get_object (builder, relation->target);
9136 g_warning ("Target object %s in <relation> does not exist",
9140 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9141 g_assert (target_accessible != NULL);
9143 relation_type = atk_relation_type_for_name (relation->type);
9144 if (relation_type == ATK_RELATION_NULL)
9146 g_warning ("<relation> type %s not found",
9150 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9153 g_object_unref (relation_set);
9155 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9156 g_slist_free (atk_relations);
9157 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9166 } AccessibilitySubParserData;
9169 accessibility_start_element (GMarkupParseContext *context,
9170 const gchar *element_name,
9171 const gchar **names,
9172 const gchar **values,
9176 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9178 gint line_number, char_number;
9180 if (strcmp (element_name, "relation") == 0)
9182 gchar *target = NULL;
9184 AtkRelationData *relation;
9186 for (i = 0; names[i]; i++)
9188 if (strcmp (names[i], "target") == 0)
9189 target = g_strdup (values[i]);
9190 else if (strcmp (names[i], "type") == 0)
9191 type = g_strdup (values[i]);
9194 g_markup_parse_context_get_position (context,
9199 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9200 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9202 line_number, char_number, names[i], "relation");
9209 if (!target || !type)
9211 g_markup_parse_context_get_position (context,
9216 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9217 "%s:%d:%d <%s> requires attribute \"%s\"",
9219 line_number, char_number, "relation",
9220 type ? "target" : "type");
9226 relation = g_slice_new (AtkRelationData);
9227 relation->target = target;
9228 relation->type = type;
9230 data->relations = g_slist_prepend (data->relations, relation);
9232 else if (strcmp (element_name, "action") == 0)
9234 gchar *action_name = NULL;
9235 gchar *description = NULL;
9236 AtkActionData *action;
9238 for (i = 0; names[i]; i++)
9240 if (strcmp (names[i], "action_name") == 0)
9241 action_name = g_strdup (values[i]);
9242 else if (strcmp (names[i], "description") == 0)
9243 description = g_strdup (values[i]);
9246 g_markup_parse_context_get_position (context,
9251 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9252 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9254 line_number, char_number, names[i], "action");
9255 g_free (action_name);
9256 g_free (description);
9261 if (!action_name || !description)
9263 g_markup_parse_context_get_position (context,
9268 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9269 "%s:%d:%d <%s> requires attribute \"%s\"",
9271 line_number, char_number, "action",
9272 description ? "action_name" : "description");
9273 g_free (action_name);
9274 g_free (description);
9278 action = g_slice_new (AtkActionData);
9279 action->action_name = action_name;
9280 action->description = description;
9282 data->actions = g_slist_prepend (data->actions, action);
9284 else if (strcmp (element_name, "accessibility") == 0)
9287 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9290 static const GMarkupParser accessibility_parser =
9292 accessibility_start_element,
9300 } AccelGroupParserData;
9303 accel_group_start_element (GMarkupParseContext *context,
9304 const gchar *element_name,
9305 const gchar **names,
9306 const gchar **values,
9312 guint modifiers = 0;
9313 gchar *signal = NULL;
9314 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9316 for (i = 0; names[i]; i++)
9318 if (strcmp (names[i], "key") == 0)
9319 key = gdk_keyval_from_name (values[i]);
9320 else if (strcmp (names[i], "modifiers") == 0)
9322 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9328 else if (strcmp (names[i], "signal") == 0)
9329 signal = g_strdup (values[i]);
9332 if (key == 0 || signal == NULL)
9334 g_warning ("<accelerator> requires key and signal attributes");
9337 parser_data->key = key;
9338 parser_data->modifiers = modifiers;
9339 parser_data->signal = signal;
9342 static const GMarkupParser accel_group_parser =
9344 accel_group_start_element,
9348 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9349 GtkBuilder *builder,
9351 const gchar *tagname,
9352 GMarkupParser *parser,
9355 g_assert (buildable);
9357 if (strcmp (tagname, "accelerator") == 0)
9359 AccelGroupParserData *parser_data;
9361 parser_data = g_slice_new0 (AccelGroupParserData);
9362 parser_data->object = g_object_ref (buildable);
9363 *parser = accel_group_parser;
9364 *data = parser_data;
9367 if (strcmp (tagname, "accessibility") == 0)
9369 AccessibilitySubParserData *parser_data;
9371 parser_data = g_slice_new0 (AccessibilitySubParserData);
9372 *parser = accessibility_parser;
9373 *data = parser_data;
9380 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9381 GtkBuilder *builder,
9383 const gchar *tagname,
9386 AccelGroupParserData *accel_data;
9387 AccessibilitySubParserData *a11y_data;
9388 GtkWidget *toplevel;
9389 GSList *accel_groups;
9390 GtkAccelGroup *accel_group;
9392 if (strcmp (tagname, "accelerator") == 0)
9394 accel_data = (AccelGroupParserData*)user_data;
9395 g_assert (accel_data->object);
9397 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9398 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9399 if (g_slist_length (accel_groups) == 0)
9401 accel_group = gtk_accel_group_new ();
9402 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9406 g_assert (g_slist_length (accel_groups) == 1);
9407 accel_group = g_slist_nth_data (accel_groups, 0);
9409 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9413 accel_data->modifiers,
9415 g_object_unref (accel_data->object);
9416 g_free (accel_data->signal);
9417 g_slice_free (AccelGroupParserData, accel_data);
9419 else if (strcmp (tagname, "accessibility") == 0)
9421 a11y_data = (AccessibilitySubParserData*)user_data;
9423 if (a11y_data->actions)
9425 AtkObject *accessible;
9430 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9432 action = ATK_ACTION (accessible);
9433 n_actions = atk_action_get_n_actions (action);
9435 for (l = a11y_data->actions; l; l = l->next)
9437 AtkActionData *action_data = (AtkActionData*)l->data;
9439 for (i = 0; i < n_actions; i++)
9440 if (strcmp (atk_action_get_name (action, i),
9441 action_data->action_name) == 0)
9445 atk_action_set_description (action, i,
9446 action_data->description);
9449 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9450 g_slist_free (a11y_data->actions);
9453 if (a11y_data->relations)
9454 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9455 a11y_data->relations);
9457 g_slice_free (AccessibilitySubParserData, a11y_data);
9464 * gtk_widget_get_clipboard:
9465 * @widget: a #GtkWidget
9466 * @selection: a #GdkAtom which identifies the clipboard
9467 * to use. %GDK_SELECTION_CLIPBOARD gives the
9468 * default clipboard. Another common value
9469 * is %GDK_SELECTION_PRIMARY, which gives
9470 * the primary X selection.
9472 * Returns the clipboard object for the given selection to
9473 * be used with @widget. @widget must have a #GdkDisplay
9474 * associated with it, so must be attached to a toplevel
9477 * Return value: the appropriate clipboard object. If no
9478 * clipboard already exists, a new one will
9479 * be created. Once a clipboard object has
9480 * been created, it is persistent for all time.
9485 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9487 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9488 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9490 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9495 * gtk_widget_list_mnemonic_labels:
9496 * @widget: a #GtkWidget
9498 * Returns a newly allocated list of the widgets, normally labels, for
9499 * which this widget is a the target of a mnemonic (see for example,
9500 * gtk_label_set_mnemonic_widget()).
9502 * The widgets in the list are not individually referenced. If you
9503 * want to iterate through the list and perform actions involving
9504 * callbacks that might destroy the widgets, you
9505 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9506 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9507 * widgets afterwards.
9509 * Return value: the list of mnemonic labels; free this list
9510 * with g_list_free() when you are done with it.
9515 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9520 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9522 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9523 list = g_list_prepend (list, l->data);
9529 * gtk_widget_add_mnemonic_label:
9530 * @widget: a #GtkWidget
9531 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9533 * Adds a widget to the list of mnemonic labels for
9534 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9535 * list of mnemonic labels for the widget is cleared when the
9536 * widget is destroyed, so the caller must make sure to update
9537 * its internal state at this point as well, by using a connection
9538 * to the #GtkWidget::destroy signal or a weak notifier.
9543 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9546 GSList *old_list, *new_list;
9548 g_return_if_fail (GTK_IS_WIDGET (widget));
9549 g_return_if_fail (GTK_IS_WIDGET (label));
9551 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9552 new_list = g_slist_prepend (old_list, label);
9554 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9555 new_list, (GDestroyNotify) g_slist_free);
9559 * gtk_widget_remove_mnemonic_label:
9560 * @widget: a #GtkWidget
9561 * @label: a #GtkWidget that was previously set as a mnemnic label for
9562 * @widget with gtk_widget_add_mnemonic_label().
9564 * Removes a widget from the list of mnemonic labels for
9565 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
9566 * must have previously been added to the list with
9567 * gtk_widget_add_mnemonic_label().
9572 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
9575 GSList *old_list, *new_list;
9577 g_return_if_fail (GTK_IS_WIDGET (widget));
9578 g_return_if_fail (GTK_IS_WIDGET (label));
9580 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9581 new_list = g_slist_remove (old_list, label);
9584 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9585 new_list, (GDestroyNotify) g_slist_free);
9589 * gtk_widget_get_no_show_all:
9590 * @widget: a #GtkWidget
9592 * Returns the current value of the GtkWidget:no-show-all property,
9593 * which determines whether calls to gtk_widget_show_all() and
9594 * gtk_widget_hide_all() will affect this widget.
9596 * Return value: the current value of the "no-show-all" property.
9601 gtk_widget_get_no_show_all (GtkWidget *widget)
9603 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9605 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
9609 * gtk_widget_set_no_show_all:
9610 * @widget: a #GtkWidget
9611 * @no_show_all: the new value for the "no-show-all" property
9613 * Sets the #GtkWidget:no-show-all property, which determines whether
9614 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
9617 * This is mostly for use in constructing widget hierarchies with externally
9618 * controlled visibility, see #GtkUIManager.
9623 gtk_widget_set_no_show_all (GtkWidget *widget,
9624 gboolean no_show_all)
9626 g_return_if_fail (GTK_IS_WIDGET (widget));
9628 no_show_all = (no_show_all != FALSE);
9630 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
9634 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
9636 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
9638 g_object_notify (G_OBJECT (widget), "no-show-all");
9643 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
9644 gboolean has_tooltip,
9647 gboolean priv_has_tooltip;
9649 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
9650 quark_has_tooltip));
9652 if (priv_has_tooltip != has_tooltip || force)
9654 priv_has_tooltip = has_tooltip;
9656 if (priv_has_tooltip)
9658 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
9659 gdk_window_set_events (widget->window,
9660 gdk_window_get_events (widget->window) |
9661 GDK_LEAVE_NOTIFY_MASK |
9662 GDK_POINTER_MOTION_MASK |
9663 GDK_POINTER_MOTION_HINT_MASK);
9665 if (!GTK_WIDGET_NO_WINDOW (widget))
9666 gtk_widget_add_events (widget,
9667 GDK_LEAVE_NOTIFY_MASK |
9668 GDK_POINTER_MOTION_MASK |
9669 GDK_POINTER_MOTION_HINT_MASK);
9672 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
9673 GUINT_TO_POINTER (priv_has_tooltip));
9678 * gtk_widget_set_tooltip_window:
9679 * @widget: a #GtkWidget
9680 * @custom_window: a #GtkWindow, or %NULL
9682 * Replaces the default, usually yellow, window used for displaying
9683 * tooltips with @custom_window. GTK+ will take care of showing and
9684 * hiding @custom_window at the right moment, to behave likewise as
9685 * the default tooltip window. If @custom_window is %NULL, the default
9686 * tooltip window will be used.
9691 gtk_widget_set_tooltip_window (GtkWidget *widget,
9692 GtkWindow *custom_window)
9695 gchar *tooltip_markup;
9696 GtkWindow *tooltip_window;
9698 g_return_if_fail (GTK_IS_WIDGET (widget));
9700 g_return_if_fail (GTK_IS_WINDOW (custom_window));
9702 tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9703 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
9706 g_object_ref (custom_window);
9708 tooltip_window = custom_window;
9709 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
9710 tooltip_window, g_object_unref);
9712 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
9713 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
9716 gtk_widget_trigger_tooltip_query (widget);
9720 * gtk_widget_get_tooltip_window:
9721 * @widget: a #GtkWidget
9723 * Returns the #GtkWindow of the current tooltip. This can be the
9724 * GtkWindow created by default, or the custom tooltip window set
9725 * using gtk_widget_set_tooltip_window().
9727 * Return value: The #GtkWindow of the current tooltip.
9732 gtk_widget_get_tooltip_window (GtkWidget *widget)
9734 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9736 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9740 * gtk_widget_trigger_tooltip_query:
9741 * @widget: a #GtkWidget
9743 * Triggers a tooltip query on the display where the toplevel of @widget
9744 * is located. See gtk_tooltip_trigger_tooltip_query() for more
9750 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
9752 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
9756 * gtk_widget_set_tooltip_text:
9757 * @widget: a #GtkWidget
9758 * @text: the contents of the tooltip for @widget
9760 * Sets @text as the contents of the tooltip. This function will take
9761 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
9762 * handler for the GtkWidget::query-tooltip signal.
9764 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
9769 gtk_widget_set_tooltip_text (GtkWidget *widget,
9772 g_return_if_fail (GTK_IS_WIDGET (widget));
9774 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
9778 * gtk_widget_get_tooltip_text:
9779 * @widget: a #GtkWidget
9781 * Gets the contents of the tooltip for @widget.
9783 * Return value: the tooltip text, or %NULL. You should free the
9784 * returned string with g_free() when done.
9789 gtk_widget_get_tooltip_text (GtkWidget *widget)
9793 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9795 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
9801 * gtk_widget_set_tooltip_markup:
9802 * @widget: a #GtkWidget
9803 * @markup: the contents of the tooltip for @widget, or %NULL
9805 * Sets @markup as the contents of the tooltip, which is marked up with
9806 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
9808 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
9809 * and of the default handler for the GtkWidget::query-tooltip signal.
9811 * See also the GtkWidget:tooltip-markup property and
9812 * gtk_tooltip_set_markup().
9817 gtk_widget_set_tooltip_markup (GtkWidget *widget,
9818 const gchar *markup)
9820 g_return_if_fail (GTK_IS_WIDGET (widget));
9822 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
9826 * gtk_widget_get_tooltip_markup:
9827 * @widget: a #GtkWidget
9829 * Gets the contents of the tooltip for @widget.
9831 * Return value: the tooltip text, or %NULL. You should free the
9832 * returned string with g_free() when done.
9837 gtk_widget_get_tooltip_markup (GtkWidget *widget)
9841 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9843 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
9849 * gtk_widget_set_has_tooltip:
9850 * @widget: a #GtkWidget
9851 * @has_tooltip: whether or not @widget has a tooltip.
9853 * Sets the has-tooltip property on @widget to @has_tooltip. See
9854 * GtkWidget:has-tooltip for more information.
9859 gtk_widget_set_has_tooltip (GtkWidget *widget,
9860 gboolean has_tooltip)
9862 g_return_if_fail (GTK_IS_WIDGET (widget));
9864 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
9868 * gtk_widget_get_has_tooltip:
9869 * @widget: a #GtkWidget
9871 * Returns the current value of the has-tooltip property. See
9872 * GtkWidget:has-tooltip for more information.
9874 * Return value: current value of has-tooltip on @widget.
9879 gtk_widget_get_has_tooltip (GtkWidget *widget)
9881 gboolean has_tooltip = FALSE;
9883 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9885 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
9891 * gtk_widget_get_allocation:
9892 * @widget: a #GtkWidget
9893 * @allocation: a #GtkAllocation
9895 * Fills @allocation with the widget's allocation as provided by its parent.
9897 * Since: GSEAL-branch
9900 gtk_widget_get_allocation (GtkWidget *widget,
9901 GtkAllocation *allocation)
9903 g_return_if_fail (GTK_IS_WIDGET (widget));
9904 g_return_if_fail (allocation != NULL);
9906 allocation->x = widget->allocation.x;
9907 allocation->y = widget->allocation.y;
9908 allocation->width = widget->allocation.width;
9909 allocation->height = widget->allocation.height;
9913 * gtk_widget_get_window:
9914 * @widget: a #GtkWidget
9916 * Returns the widget's window or the parent window.
9918 * Return value: @widget's window.
9920 * Since: GSEAL-branch
9923 gtk_widget_get_window (GtkWidget *widget)
9925 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9927 return widget->window;
9930 #define __GTK_WIDGET_C__
9931 #include "gtkaliasdef.c"