1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
58 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
59 #define INIT_PATH_SIZE (512)
100 PROPERTY_NOTIFY_EVENT,
101 SELECTION_CLEAR_EVENT,
102 SELECTION_REQUEST_EVENT,
103 SELECTION_NOTIFY_EVENT,
118 VISIBILITY_NOTIFY_EVENT,
122 ACCEL_CLOSURES_CHANGED,
148 PROP_RECEIVES_DEFAULT,
149 PROP_COMPOSITE_CHILD,
152 PROP_EXTENSION_EVENTS,
160 typedef struct _GtkStateData GtkStateData;
165 guint state_restoration : 1;
166 guint parent_sensitive : 1;
167 guint use_forall : 1;
170 /* --- prototypes --- */
171 static void gtk_widget_class_init (GtkWidgetClass *klass);
172 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
173 static void gtk_widget_init (GtkWidget *widget);
174 static void gtk_widget_set_property (GObject *object,
178 static void gtk_widget_get_property (GObject *object,
182 static void gtk_widget_dispose (GObject *object);
183 static void gtk_widget_real_destroy (GtkObject *object);
184 static void gtk_widget_finalize (GObject *object);
185 static void gtk_widget_real_show (GtkWidget *widget);
186 static void gtk_widget_real_hide (GtkWidget *widget);
187 static void gtk_widget_real_map (GtkWidget *widget);
188 static void gtk_widget_real_unmap (GtkWidget *widget);
189 static void gtk_widget_real_realize (GtkWidget *widget);
190 static void gtk_widget_real_unrealize (GtkWidget *widget);
191 static void gtk_widget_real_size_request (GtkWidget *widget,
192 GtkRequisition *requisition);
193 static void gtk_widget_real_size_allocate (GtkWidget *widget,
194 GtkAllocation *allocation);
195 static void gtk_widget_real_style_set (GtkWidget *widget,
196 GtkStyle *previous_style);
197 static void gtk_widget_real_direction_changed(GtkWidget *widget,
198 GtkTextDirection previous_direction);
200 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
201 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
204 gboolean keyboard_tip,
205 GtkTooltip *tooltip);
206 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
207 GtkWidgetHelpType help_type);
209 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
211 GParamSpec **pspecs);
212 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
214 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
216 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
217 GdkEventFocus *event);
218 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
219 GdkEventFocus *event);
220 static gboolean gtk_widget_real_focus (GtkWidget *widget,
221 GtkDirectionType direction);
222 static void gtk_widget_real_move_focus (GtkWidget *widget,
223 GtkDirectionType direction);
224 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
225 GtkDirectionType direction);
226 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
227 static void gtk_widget_update_pango_context (GtkWidget *widget);
228 static void gtk_widget_propagate_state (GtkWidget *widget,
230 static void gtk_widget_reset_rc_style (GtkWidget *widget);
231 static void gtk_widget_set_style_internal (GtkWidget *widget,
233 gboolean initial_emission);
234 static gint gtk_widget_event_internal (GtkWidget *widget,
236 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
237 gboolean group_cycling);
238 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
239 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
240 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
241 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
242 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
244 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
245 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
246 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
249 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
250 gboolean has_tooltip,
252 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
253 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
255 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
256 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
258 const gchar *childname);
259 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
262 const GValue *value);
263 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
266 const gchar *tagname,
267 GMarkupParser *parser,
269 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
272 const gchar *tagname,
274 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
275 GtkBuilder *builder);
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_pointer_window = 0;
302 static GQuark quark_shape_info = 0;
303 static GQuark quark_input_shape_info = 0;
304 static GQuark quark_colormap = 0;
305 static GQuark quark_pango_context = 0;
306 static GQuark quark_rc_style = 0;
307 static GQuark quark_accessible_object = 0;
308 static GQuark quark_mnemonic_labels = 0;
309 static GQuark quark_tooltip_markup = 0;
310 static GQuark quark_has_tooltip = 0;
311 static GQuark quark_tooltip_window = 0;
312 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
313 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
315 /* --- functions --- */
317 gtk_widget_get_type (void)
319 static GType widget_type = 0;
321 if (G_UNLIKELY (widget_type == 0))
323 const GTypeInfo widget_info =
325 sizeof (GtkWidgetClass),
326 NULL, /* base_init */
327 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
328 (GClassInitFunc) gtk_widget_class_init,
329 NULL, /* class_finalize */
330 NULL, /* class_init */
333 (GInstanceInitFunc) gtk_widget_init,
334 NULL, /* value_table */
337 const GInterfaceInfo accessibility_info =
339 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
340 (GInterfaceFinalizeFunc) NULL,
341 NULL /* interface data */
344 const GInterfaceInfo buildable_info =
346 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
347 (GInterfaceFinalizeFunc) NULL,
348 NULL /* interface data */
351 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
352 &widget_info, G_TYPE_FLAG_ABSTRACT);
354 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
355 &accessibility_info) ;
356 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
365 child_property_notify_dispatcher (GObject *object,
369 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
373 gtk_widget_class_init (GtkWidgetClass *klass)
375 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
376 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
377 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
378 GtkBindingSet *binding_set;
380 gtk_widget_parent_class = g_type_class_peek_parent (klass);
382 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
383 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
384 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
385 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
386 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
387 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
388 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
389 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
390 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
391 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
392 quark_colormap = g_quark_from_static_string ("gtk-colormap");
393 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
394 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
395 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
396 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
397 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
398 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
399 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
401 style_property_spec_pool = g_param_spec_pool_new (FALSE);
402 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
403 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
404 cpn_context.dispatcher = child_property_notify_dispatcher;
405 _gtk_widget_child_property_notify_context = &cpn_context;
407 gobject_class->dispose = gtk_widget_dispose;
408 gobject_class->finalize = gtk_widget_finalize;
409 gobject_class->set_property = gtk_widget_set_property;
410 gobject_class->get_property = gtk_widget_get_property;
412 object_class->destroy = gtk_widget_real_destroy;
414 klass->activate_signal = 0;
415 klass->set_scroll_adjustments_signal = 0;
416 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
417 klass->show = gtk_widget_real_show;
418 klass->show_all = gtk_widget_show;
419 klass->hide = gtk_widget_real_hide;
420 klass->hide_all = gtk_widget_hide;
421 klass->map = gtk_widget_real_map;
422 klass->unmap = gtk_widget_real_unmap;
423 klass->realize = gtk_widget_real_realize;
424 klass->unrealize = gtk_widget_real_unrealize;
425 klass->size_request = gtk_widget_real_size_request;
426 klass->size_allocate = gtk_widget_real_size_allocate;
427 klass->state_changed = NULL;
428 klass->parent_set = NULL;
429 klass->hierarchy_changed = NULL;
430 klass->style_set = gtk_widget_real_style_set;
431 klass->direction_changed = gtk_widget_real_direction_changed;
432 klass->grab_notify = NULL;
433 klass->child_notify = NULL;
434 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
435 klass->grab_focus = gtk_widget_real_grab_focus;
436 klass->focus = gtk_widget_real_focus;
438 klass->button_press_event = NULL;
439 klass->button_release_event = NULL;
440 klass->motion_notify_event = NULL;
441 klass->delete_event = NULL;
442 klass->destroy_event = NULL;
443 klass->expose_event = NULL;
444 klass->key_press_event = gtk_widget_real_key_press_event;
445 klass->key_release_event = gtk_widget_real_key_release_event;
446 klass->enter_notify_event = NULL;
447 klass->leave_notify_event = NULL;
448 klass->configure_event = NULL;
449 klass->focus_in_event = gtk_widget_real_focus_in_event;
450 klass->focus_out_event = gtk_widget_real_focus_out_event;
451 klass->map_event = NULL;
452 klass->unmap_event = NULL;
453 klass->window_state_event = NULL;
454 klass->property_notify_event = _gtk_selection_property_notify;
455 klass->selection_clear_event = gtk_selection_clear;
456 klass->selection_request_event = _gtk_selection_request;
457 klass->selection_notify_event = _gtk_selection_notify;
458 klass->selection_received = NULL;
459 klass->proximity_in_event = NULL;
460 klass->proximity_out_event = NULL;
461 klass->drag_begin = NULL;
462 klass->drag_end = NULL;
463 klass->drag_data_delete = NULL;
464 klass->drag_leave = NULL;
465 klass->drag_motion = NULL;
466 klass->drag_drop = NULL;
467 klass->drag_data_received = NULL;
468 klass->screen_changed = NULL;
469 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
470 klass->grab_broken_event = NULL;
471 klass->query_tooltip = gtk_widget_real_query_tooltip;
473 klass->show_help = gtk_widget_real_show_help;
475 /* Accessibility support */
476 klass->get_accessible = gtk_widget_real_get_accessible;
478 klass->no_expose_event = NULL;
480 g_object_class_install_property (gobject_class,
482 g_param_spec_string ("name",
484 P_("The name of the widget"),
486 GTK_PARAM_READWRITE));
487 g_object_class_install_property (gobject_class,
489 g_param_spec_object ("parent",
491 P_("The parent widget of this widget. Must be a Container widget"),
493 GTK_PARAM_READWRITE));
495 g_object_class_install_property (gobject_class,
497 g_param_spec_int ("width-request",
499 P_("Override for width request of the widget, or -1 if natural request should be used"),
503 GTK_PARAM_READWRITE));
504 g_object_class_install_property (gobject_class,
506 g_param_spec_int ("height-request",
507 P_("Height request"),
508 P_("Override for height request of the widget, or -1 if natural request should be used"),
512 GTK_PARAM_READWRITE));
513 g_object_class_install_property (gobject_class,
515 g_param_spec_boolean ("visible",
517 P_("Whether the widget is visible"),
519 GTK_PARAM_READWRITE));
520 g_object_class_install_property (gobject_class,
522 g_param_spec_boolean ("sensitive",
524 P_("Whether the widget responds to input"),
526 GTK_PARAM_READWRITE));
527 g_object_class_install_property (gobject_class,
529 g_param_spec_boolean ("app-paintable",
530 P_("Application paintable"),
531 P_("Whether the application will paint directly on the widget"),
533 GTK_PARAM_READWRITE));
534 g_object_class_install_property (gobject_class,
536 g_param_spec_boolean ("can-focus",
538 P_("Whether the widget can accept the input focus"),
540 GTK_PARAM_READWRITE));
541 g_object_class_install_property (gobject_class,
543 g_param_spec_boolean ("has-focus",
545 P_("Whether the widget has the input focus"),
547 GTK_PARAM_READWRITE));
548 g_object_class_install_property (gobject_class,
550 g_param_spec_boolean ("is-focus",
552 P_("Whether the widget is the focus widget within the toplevel"),
554 GTK_PARAM_READWRITE));
555 g_object_class_install_property (gobject_class,
557 g_param_spec_boolean ("can-default",
559 P_("Whether the widget can be the default widget"),
561 GTK_PARAM_READWRITE));
562 g_object_class_install_property (gobject_class,
564 g_param_spec_boolean ("has-default",
566 P_("Whether the widget is the default widget"),
568 GTK_PARAM_READWRITE));
569 g_object_class_install_property (gobject_class,
570 PROP_RECEIVES_DEFAULT,
571 g_param_spec_boolean ("receives-default",
572 P_("Receives default"),
573 P_("If TRUE, the widget will receive the default action when it is focused"),
575 GTK_PARAM_READWRITE));
576 g_object_class_install_property (gobject_class,
577 PROP_COMPOSITE_CHILD,
578 g_param_spec_boolean ("composite-child",
579 P_("Composite child"),
580 P_("Whether the widget is part of a composite widget"),
582 GTK_PARAM_READABLE));
583 g_object_class_install_property (gobject_class,
585 g_param_spec_object ("style",
587 P_("The style of the widget, which contains information about how it will look (colors etc)"),
589 GTK_PARAM_READWRITE));
590 g_object_class_install_property (gobject_class,
592 g_param_spec_flags ("events",
594 P_("The event mask that decides what kind of GdkEvents this widget gets"),
597 GTK_PARAM_READWRITE));
598 g_object_class_install_property (gobject_class,
599 PROP_EXTENSION_EVENTS,
600 g_param_spec_enum ("extension-events",
601 P_("Extension events"),
602 P_("The mask that decides what kind of extension events this widget gets"),
603 GDK_TYPE_EXTENSION_MODE,
604 GDK_EXTENSION_EVENTS_NONE,
605 GTK_PARAM_READWRITE));
606 g_object_class_install_property (gobject_class,
608 g_param_spec_boolean ("no-show-all",
610 P_("Whether gtk_widget_show_all() should not affect this widget"),
612 GTK_PARAM_READWRITE));
615 * GtkWidget:has-tooltip:
617 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
618 * A value of %TRUE indicates that @widget can have a tooltip, in this case
619 * the widget will be queried using #GtkWidget::query-tooltip to determine
620 * whether it will provide a tooltip or not.
622 * Note that setting this property to %TRUE for the first time will change
623 * the event masks of the GdkWindows of this widget to include leave-notify
624 * and motion-notify events. This cannot and will not be undone when the
625 * property is set to %FALSE again.
629 g_object_class_install_property (gobject_class,
631 g_param_spec_boolean ("has-tooltip",
633 P_("Whether this widget has a tooltip"),
635 GTK_PARAM_READWRITE));
637 * GtkWidget:tooltip-text:
639 * Sets the text of tooltip to be the given string.
641 * Also see gtk_tooltip_set_text().
643 * This is a convenience property which will take care of getting the
644 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
645 * will automatically be set to %TRUE and there will be taken care of
646 * #GtkWidget::query-tooltip in the default signal handler.
650 g_object_class_install_property (gobject_class,
652 g_param_spec_string ("tooltip-text",
654 P_("The contents of the tooltip for this widget"),
656 GTK_PARAM_READWRITE));
658 * GtkWidget:tooltip-markup:
660 * Sets the text of tooltip to be the given string, which is marked up
661 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
662 * Also see gtk_tooltip_set_markup().
664 * This is a convenience property which will take care of getting the
665 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
666 * will automatically be set to %TRUE and there will be taken care of
667 * #GtkWidget::query-tooltip in the default signal handler.
671 g_object_class_install_property (gobject_class,
673 g_param_spec_string ("tooltip-markup",
674 P_("Tooltip markup"),
675 P_("The contents of the tooltip for this widget"),
677 GTK_PARAM_READWRITE));
682 * The widget's window if it is realized, %NULL otherwise.
686 g_object_class_install_property (gobject_class,
688 g_param_spec_object ("window",
690 P_("The widget's window if it is realized"),
692 GTK_PARAM_READABLE));
694 widget_signals[SHOW] =
695 g_signal_new (I_("show"),
696 G_TYPE_FROM_CLASS (gobject_class),
698 G_STRUCT_OFFSET (GtkWidgetClass, show),
700 _gtk_marshal_VOID__VOID,
702 widget_signals[HIDE] =
703 g_signal_new (I_("hide"),
704 G_TYPE_FROM_CLASS (gobject_class),
706 G_STRUCT_OFFSET (GtkWidgetClass, hide),
708 _gtk_marshal_VOID__VOID,
710 widget_signals[MAP] =
711 g_signal_new (I_("map"),
712 G_TYPE_FROM_CLASS (gobject_class),
714 G_STRUCT_OFFSET (GtkWidgetClass, map),
716 _gtk_marshal_VOID__VOID,
718 widget_signals[UNMAP] =
719 g_signal_new (I_("unmap"),
720 G_TYPE_FROM_CLASS (gobject_class),
722 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
724 _gtk_marshal_VOID__VOID,
726 widget_signals[REALIZE] =
727 g_signal_new (I_("realize"),
728 G_TYPE_FROM_CLASS (gobject_class),
730 G_STRUCT_OFFSET (GtkWidgetClass, realize),
732 _gtk_marshal_VOID__VOID,
734 widget_signals[UNREALIZE] =
735 g_signal_new (I_("unrealize"),
736 G_TYPE_FROM_CLASS (gobject_class),
738 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
740 _gtk_marshal_VOID__VOID,
742 widget_signals[SIZE_REQUEST] =
743 g_signal_new (I_("size-request"),
744 G_TYPE_FROM_CLASS (gobject_class),
746 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
748 _gtk_marshal_VOID__BOXED,
750 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
751 widget_signals[SIZE_ALLOCATE] =
752 g_signal_new (I_("size-allocate"),
753 G_TYPE_FROM_CLASS (gobject_class),
755 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
757 _gtk_marshal_VOID__BOXED,
759 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
761 widget_signals[STATE_CHANGED] =
762 g_signal_new (I_("state-changed"),
763 G_TYPE_FROM_CLASS (gobject_class),
765 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
767 _gtk_marshal_VOID__ENUM,
769 GTK_TYPE_STATE_TYPE);
772 * GtkWidget::parent-set:
773 * @widget: the object on which the signal is emitted
774 * @old_parent: the previous parent, or %NULL if the widget
775 * just got its initial parent.
777 * The ::parent-set signal is emitted when a new parent
778 * has been set on a widget.
780 widget_signals[PARENT_SET] =
781 g_signal_new (I_("parent-set"),
782 G_TYPE_FROM_CLASS (gobject_class),
784 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
786 _gtk_marshal_VOID__OBJECT,
791 * GtkWidget::hierarchy-changed:
792 * @widget: the object on which the signal is emitted
793 * @previous_toplevel: the previous toplevel ancestor, or %NULL
794 * if the widget was previously unanchored
796 * The ::hierarchy-changed signal is emitted when the
797 * anchored state of a widget changes. A widget is
798 * <firstterm>anchored</firstterm> when its toplevel
799 * ancestor is a #GtkWindow. This signal is emitted when
800 * a widget changes from un-anchored to anchored or vice-versa.
802 widget_signals[HIERARCHY_CHANGED] =
803 g_signal_new (I_("hierarchy-changed"),
804 G_TYPE_FROM_CLASS (gobject_class),
806 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
808 _gtk_marshal_VOID__OBJECT,
813 * GtkWidget::style-set:
814 * @widget: the object on which the signal is emitted
815 * @previous_style: the previous style, or %NULL if the widget
816 * just got its initial style
818 * The ::style-set signal is emitted when a new style has been set
819 * on a widget. Note that style-modifying functions like
820 * gtk_widget_modify_base() also cause this signal to be emitted.
822 widget_signals[STYLE_SET] =
823 g_signal_new (I_("style-set"),
824 G_TYPE_FROM_CLASS (gobject_class),
826 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
828 _gtk_marshal_VOID__OBJECT,
832 * GtkWidget::direction-changed:
833 * @widget: the object on which the signal is emitted
834 * @previous_direction: the previous text direction of @widget
836 * The ::direction-changed signal is emitted when the text direction
837 * of a widget changes.
839 widget_signals[DIRECTION_CHANGED] =
840 g_signal_new (I_("direction-changed"),
841 G_TYPE_FROM_CLASS (gobject_class),
843 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
845 _gtk_marshal_VOID__ENUM,
847 GTK_TYPE_TEXT_DIRECTION);
850 * GtkWidget::grab-notify:
851 * @widget: the object which received the signal
852 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
853 * if it becomes unshadowed
855 * The ::grab-notify signal is emitted when a widget becomes
856 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
857 * another widget, or when it becomes unshadowed due to a grab
860 * A widget is shadowed by a gtk_grab_add() when the topmost
861 * grab widget in the grab stack of its window group is not
864 widget_signals[GRAB_NOTIFY] =
865 g_signal_new (I_("grab-notify"),
866 G_TYPE_FROM_CLASS (gobject_class),
868 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
870 _gtk_marshal_VOID__BOOLEAN,
875 * GtkWidget::child-notify:
876 * @widget: the object which received the signal
877 * @pspec: the #GParamSpec of the changed child property
879 * The ::child-notify signal is emitted for each
880 * <link linkend="child-properties">child property</link> that has
881 * changed on an object. The signal's detail holds the property name.
883 widget_signals[CHILD_NOTIFY] =
884 g_signal_new (I_("child-notify"),
885 G_TYPE_FROM_CLASS (gobject_class),
886 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
887 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
889 g_cclosure_marshal_VOID__PARAM,
892 widget_signals[MNEMONIC_ACTIVATE] =
893 g_signal_new (I_("mnemonic-activate"),
894 G_TYPE_FROM_CLASS (gobject_class),
896 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
897 _gtk_boolean_handled_accumulator, NULL,
898 _gtk_marshal_BOOLEAN__BOOLEAN,
901 widget_signals[GRAB_FOCUS] =
902 g_signal_new (I_("grab-focus"),
903 G_TYPE_FROM_CLASS (gobject_class),
904 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
905 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
907 _gtk_marshal_VOID__VOID,
909 widget_signals[FOCUS] =
910 g_signal_new (I_("focus"),
911 G_TYPE_FROM_CLASS (object_class),
913 G_STRUCT_OFFSET (GtkWidgetClass, focus),
914 _gtk_boolean_handled_accumulator, NULL,
915 _gtk_marshal_BOOLEAN__ENUM,
917 GTK_TYPE_DIRECTION_TYPE);
918 widget_signals[MOVE_FOCUS] =
919 g_signal_new_class_handler (I_("move-focus"),
920 G_TYPE_FROM_CLASS (object_class),
921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
922 G_CALLBACK (gtk_widget_real_move_focus),
924 _gtk_marshal_VOID__ENUM,
927 GTK_TYPE_DIRECTION_TYPE);
930 * @widget: the object which received the signal.
931 * @event: the #GdkEvent which triggered this signal
933 * The GTK+ main loop will emit three signals for each GDK event delivered
934 * to a widget: one generic ::event signal, another, more specific,
935 * signal that matches the type of event delivered (e.g.
936 * #GtkWidget::key-press-event) and finally a generic
937 * #GtkWidget::event-after signal.
939 * Returns: %TRUE to stop other handlers from being invoked for the event
940 * and to cancel the emission of the second specific ::event signal.
941 * %FALSE to propagate the event further and to allow the emission of
942 * the second signal. The ::event-after signal is emitted regardless of
945 widget_signals[EVENT] =
946 g_signal_new (I_("event"),
947 G_TYPE_FROM_CLASS (gobject_class),
949 G_STRUCT_OFFSET (GtkWidgetClass, event),
950 _gtk_boolean_handled_accumulator, NULL,
951 _gtk_marshal_BOOLEAN__BOXED,
953 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
956 * GtkWidget::event-after:
957 * @widget: the object which received the signal.
958 * @event: the #GdkEvent which triggered this signal
960 * After the emission of the #GtkWidget::event signal and (optionally)
961 * the second more specific signal, ::event-after will be emitted
962 * regardless of the previous two signals handlers return values.
965 widget_signals[EVENT_AFTER] =
966 g_signal_new (I_("event-after"),
967 G_TYPE_FROM_CLASS (gobject_class),
971 _gtk_marshal_VOID__BOXED,
973 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
976 * GtkWidget::button-press-event:
977 * @widget: the object which received the signal.
978 * @event: the #GdkEventButton which triggered this signal
980 * The ::button-press-event signal will be emitted when a button
981 * (typically from a mouse) is pressed.
983 * To receive this signal, the #GdkWindow associated to the
984 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
986 * This signal will be sent to the grab widget if there is one.
988 * Returns: %TRUE to stop other handlers from being invoked for the event.
989 * %FALSE to propagate the event further.
991 widget_signals[BUTTON_PRESS_EVENT] =
992 g_signal_new (I_("button-press-event"),
993 G_TYPE_FROM_CLASS (gobject_class),
995 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
996 _gtk_boolean_handled_accumulator, NULL,
997 _gtk_marshal_BOOLEAN__BOXED,
999 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1002 * GtkWidget::button-release-event:
1003 * @widget: the object which received the signal.
1004 * @event: the #GdkEventButton which triggered this signal
1006 * The ::button-release-event signal will be emitted when a button
1007 * (typically from a mouse) is released.
1009 * To receive this signal, the #GdkWindow associated to the
1010 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1012 * This signal will be sent to the grab widget if there is one.
1014 * Returns: %TRUE to stop other handlers from being invoked for the event.
1015 * %FALSE to propagate the event further.
1017 widget_signals[BUTTON_RELEASE_EVENT] =
1018 g_signal_new (I_("button-release-event"),
1019 G_TYPE_FROM_CLASS (gobject_class),
1021 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1022 _gtk_boolean_handled_accumulator, NULL,
1023 _gtk_marshal_BOOLEAN__BOXED,
1025 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1028 * GtkWidget::scroll-event:
1029 * @widget: the object which received the signal.
1030 * @event: the #GdkEventScroll which triggered this signal
1032 * The ::scroll-event signal is emitted when a button in the 4 to 7
1033 * range is pressed. Wheel mice are usually configured to generate
1034 * button press events for buttons 4 and 5 when the wheel is turned.
1036 * To receive this signal, the #GdkWindow associated to the widget needs
1037 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1039 * This signal will be sent to the grab widget if there is one.
1041 * Returns: %TRUE to stop other handlers from being invoked for the event.
1042 * %FALSE to propagate the event further.
1044 widget_signals[SCROLL_EVENT] =
1045 g_signal_new (I_("scroll-event"),
1046 G_TYPE_FROM_CLASS (gobject_class),
1048 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1049 _gtk_boolean_handled_accumulator, NULL,
1050 _gtk_marshal_BOOLEAN__BOXED,
1052 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1054 * GtkWidget::motion-notify-event:
1055 * @widget: the object which received the signal.
1056 * @event: the #GdkEventMotion which triggered this signal
1058 * The ::motion-notify-event signal is emitted when the pointer moves
1059 * over the widget's #GdkWindow.
1061 * To receive this signal, the #GdkWindow associated to the widget
1062 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1064 * This signal will be sent to the grab widget if there is one.
1066 * Returns: %TRUE to stop other handlers from being invoked for the event.
1067 * %FALSE to propagate the event further.
1069 widget_signals[MOTION_NOTIFY_EVENT] =
1070 g_signal_new (I_("motion-notify-event"),
1071 G_TYPE_FROM_CLASS (gobject_class),
1073 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1074 _gtk_boolean_handled_accumulator, NULL,
1075 _gtk_marshal_BOOLEAN__BOXED,
1077 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1080 * GtkWidget::composited-changed:
1081 * @widget: the object on which the signal is emitted
1083 * The ::composited-changed signal is emitted when the composited
1084 * status of @widget<!-- -->s screen changes.
1085 * See gdk_screen_is_composited().
1087 widget_signals[COMPOSITED_CHANGED] =
1088 g_signal_new (I_("composited-changed"),
1089 G_TYPE_FROM_CLASS (gobject_class),
1090 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1091 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1093 _gtk_marshal_VOID__VOID,
1097 * GtkWidget::keynav-failed:
1098 * @widget: the object which received the signal
1099 * @direction: the direction of movement
1101 * Gets emitted if keyboard navigation fails.
1102 * See gtk_widget_keynav_failed() for details.
1104 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1105 * if the emitting widget should try to handle the keyboard
1106 * navigation attempt in its parent container(s).
1110 widget_signals[KEYNAV_FAILED] =
1111 g_signal_new_class_handler (I_("keynav-failed"),
1112 G_TYPE_FROM_CLASS (gobject_class),
1114 G_CALLBACK (gtk_widget_real_keynav_failed),
1115 _gtk_boolean_handled_accumulator, NULL,
1116 _gtk_marshal_BOOLEAN__ENUM,
1118 GTK_TYPE_DIRECTION_TYPE);
1121 * GtkWidget::delete-event:
1122 * @widget: the object which received the signal
1123 * @event: the event which triggered this signal
1125 * The ::delete-event signal is emitted if a user requests that
1126 * a toplevel window is closed. The default handler for this signal
1127 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1128 * this signal will cause the window to be hidden instead, so that
1129 * it can later be shown again without reconstructing it.
1131 * Returns: %TRUE to stop other handlers from being invoked for the event.
1132 * %FALSE to propagate the event further.
1134 widget_signals[DELETE_EVENT] =
1135 g_signal_new (I_("delete-event"),
1136 G_TYPE_FROM_CLASS (gobject_class),
1138 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1139 _gtk_boolean_handled_accumulator, NULL,
1140 _gtk_marshal_BOOLEAN__BOXED,
1142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1145 * GtkWidget::destroy-event:
1146 * @widget: the object which received the signal.
1147 * @event: the event which triggered this signal
1149 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1150 * You rarely get this signal, because most widgets disconnect themselves
1151 * from their window before they destroy it, so no widget owns the
1152 * window at destroy time.
1154 * To receive this signal, the #GdkWindow associated to the widget needs
1155 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1156 * automatically for all new windows.
1158 * Returns: %TRUE to stop other handlers from being invoked for the event.
1159 * %FALSE to propagate the event further.
1161 widget_signals[DESTROY_EVENT] =
1162 g_signal_new (I_("destroy-event"),
1163 G_TYPE_FROM_CLASS (gobject_class),
1165 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1166 _gtk_boolean_handled_accumulator, NULL,
1167 _gtk_marshal_BOOLEAN__BOXED,
1169 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1172 * GtkWidget::expose-event:
1173 * @widget: the object which received the signal.
1174 * @event: the #GdkEventExpose which triggered this signal
1176 * The ::expose-event signal is emitted when an area of a previously
1177 * obscured #GdkWindow is made visible and needs to be redrawn.
1178 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1181 * To receive this signal, the #GdkWindow associated to the widget needs
1182 * to enable the #GDK_EXPOSURE_MASK mask.
1184 * Returns: %TRUE to stop other handlers from being invoked for the event.
1185 * %FALSE to propagate the event further.
1187 widget_signals[EXPOSE_EVENT] =
1188 g_signal_new (I_("expose-event"),
1189 G_TYPE_FROM_CLASS (gobject_class),
1191 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1192 _gtk_boolean_handled_accumulator, NULL,
1193 _gtk_marshal_BOOLEAN__BOXED,
1195 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1198 * GtkWidget::key-press-event:
1199 * @widget: the object which received the signal
1200 * @event: the #GdkEventKey which triggered this signal
1202 * The ::key-press-event signal is emitted when a key is pressed.
1204 * To receive this signal, the #GdkWindow associated to the widget needs
1205 * to enable the #GDK_KEY_PRESS_MASK mask.
1207 * This signal will be sent to the grab widget if there is one.
1209 * Returns: %TRUE to stop other handlers from being invoked for the event.
1210 * %FALSE to propagate the event further.
1212 widget_signals[KEY_PRESS_EVENT] =
1213 g_signal_new (I_("key-press-event"),
1214 G_TYPE_FROM_CLASS (gobject_class),
1216 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1217 _gtk_boolean_handled_accumulator, NULL,
1218 _gtk_marshal_BOOLEAN__BOXED,
1220 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1223 * GtkWidget::key-release-event:
1224 * @widget: the object which received the signal
1225 * @event: the #GdkEventKey which triggered this signal
1227 * The ::key-release-event signal is emitted when a key is pressed.
1229 * To receive this signal, the #GdkWindow associated to the widget needs
1230 * to enable the #GDK_KEY_RELEASE_MASK mask.
1232 * This signal will be sent to the grab widget if there is one.
1234 * Returns: %TRUE to stop other handlers from being invoked for the event.
1235 * %FALSE to propagate the event further.
1237 widget_signals[KEY_RELEASE_EVENT] =
1238 g_signal_new (I_("key-release-event"),
1239 G_TYPE_FROM_CLASS (gobject_class),
1241 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1242 _gtk_boolean_handled_accumulator, NULL,
1243 _gtk_marshal_BOOLEAN__BOXED,
1245 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1248 * GtkWidget::enter-notify-event:
1249 * @widget: the object which received the signal
1250 * @event: the #GdkEventCrossing which triggered this signal
1252 * The ::enter-notify-event will be emitted when the pointer enters
1253 * the @widget's window.
1255 * To receive this signal, the #GdkWindow associated to the widget needs
1256 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1258 * This signal will be sent to the grab widget if there is one.
1260 * Returns: %TRUE to stop other handlers from being invoked for the event.
1261 * %FALSE to propagate the event further.
1263 widget_signals[ENTER_NOTIFY_EVENT] =
1264 g_signal_new (I_("enter-notify-event"),
1265 G_TYPE_FROM_CLASS (gobject_class),
1267 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1268 _gtk_boolean_handled_accumulator, NULL,
1269 _gtk_marshal_BOOLEAN__BOXED,
1271 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1274 * GtkWidget::leave-notify-event:
1275 * @widget: the object which received the signal
1276 * @event: the #GdkEventCrossing which triggered this signal
1278 * The ::leave-notify-event will be emitted when the pointer leaves
1279 * the @widget's window.
1281 * To receive this signal, the #GdkWindow associated to the widget needs
1282 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1284 * This signal will be sent to the grab widget if there is one.
1286 * Returns: %TRUE to stop other handlers from being invoked for the event.
1287 * %FALSE to propagate the event further.
1289 widget_signals[LEAVE_NOTIFY_EVENT] =
1290 g_signal_new (I_("leave-notify-event"),
1291 G_TYPE_FROM_CLASS (gobject_class),
1293 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1294 _gtk_boolean_handled_accumulator, NULL,
1295 _gtk_marshal_BOOLEAN__BOXED,
1297 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1300 * GtkWidget::configure-event
1301 * @widget: the object which received the signal
1302 * @event: the #GdkEventConfigure which triggered this signal
1304 * The ::configure-event signal will be emitted when the size, position or
1305 * stacking of the @widget's window has changed.
1307 * To receive this signal, the #GdkWindow associated to the widget needs
1308 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1309 * automatically for all new windows.
1311 * Returns: %TRUE to stop other handlers from being invoked for the event.
1312 * %FALSE to propagate the event further.
1314 widget_signals[CONFIGURE_EVENT] =
1315 g_signal_new (I_("configure-event"),
1316 G_TYPE_FROM_CLASS (gobject_class),
1318 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1319 _gtk_boolean_handled_accumulator, NULL,
1320 _gtk_marshal_BOOLEAN__BOXED,
1322 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1325 * GtkWidget::focus-in-event
1326 * @widget: the object which received the signal
1327 * @event: the #GdkEventFocus which triggered this signal
1329 * The ::focus-in-event signal will be emitted when the keyboard focus
1330 * enters the @widget's window.
1332 * To receive this signal, the #GdkWindow associated to the widget needs
1333 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1335 * Returns: %TRUE to stop other handlers from being invoked for the event.
1336 * %FALSE to propagate the event further.
1338 widget_signals[FOCUS_IN_EVENT] =
1339 g_signal_new (I_("focus-in-event"),
1340 G_TYPE_FROM_CLASS (gobject_class),
1342 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1343 _gtk_boolean_handled_accumulator, NULL,
1344 _gtk_marshal_BOOLEAN__BOXED,
1346 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1349 * GtkWidget::focus-out-event
1350 * @widget: the object which received the signal
1351 * @event: the #GdkEventFocus which triggered this signal
1353 * The ::focus-out-event signal will be emitted when the keyboard focus
1354 * leaves the @widget's window.
1356 * To receive this signal, the #GdkWindow associated to the widget needs
1357 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1359 * Returns: %TRUE to stop other handlers from being invoked for the event.
1360 * %FALSE to propagate the event further.
1362 widget_signals[FOCUS_OUT_EVENT] =
1363 g_signal_new (I_("focus-out-event"),
1364 G_TYPE_FROM_CLASS (gobject_class),
1366 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1367 _gtk_boolean_handled_accumulator, NULL,
1368 _gtk_marshal_BOOLEAN__BOXED,
1370 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1373 * GtkWidget::map-event
1374 * @widget: the object which received the signal
1375 * @event: the #GdkEventAny which triggered this signal
1377 * The ::map-event signal will be emitted when the @widget's window is
1378 * mapped. A window is mapped when it becomes visible on the screen.
1380 * To receive this signal, the #GdkWindow associated to the widget needs
1381 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1382 * automatically for all new windows.
1384 * Returns: %TRUE to stop other handlers from being invoked for the event.
1385 * %FALSE to propagate the event further.
1387 widget_signals[MAP_EVENT] =
1388 g_signal_new (I_("map-event"),
1389 G_TYPE_FROM_CLASS (gobject_class),
1391 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1392 _gtk_boolean_handled_accumulator, NULL,
1393 _gtk_marshal_BOOLEAN__BOXED,
1395 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1398 * GtkWidget::unmap-event
1399 * @widget: the object which received the signal
1400 * @event: the #GdkEventAny which triggered this signal
1402 * The ::unmap-event signal will be emitted when the @widget's window is
1403 * unmapped. A window is unmapped when it becomes invisible on the screen.
1405 * To receive this signal, the #GdkWindow associated to the widget needs
1406 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1407 * automatically for all new windows.
1409 * Returns: %TRUE to stop other handlers from being invoked for the event.
1410 * %FALSE to propagate the event further.
1412 widget_signals[UNMAP_EVENT] =
1413 g_signal_new (I_("unmap-event"),
1414 G_TYPE_FROM_CLASS (gobject_class),
1416 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1417 _gtk_boolean_handled_accumulator, NULL,
1418 _gtk_marshal_BOOLEAN__BOXED,
1420 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1423 * GtkWidget::property-notify-event
1424 * @widget: the object which received the signal
1425 * @event: the #GdkEventProperty which triggered this signal
1427 * The ::property-notify-event signal will be emitted when a property on
1428 * the @widget's window has been changed or deleted.
1430 * To receive this signal, the #GdkWindow associated to the widget needs
1431 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1433 * Returns: %TRUE to stop other handlers from being invoked for the event.
1434 * %FALSE to propagate the event further.
1436 widget_signals[PROPERTY_NOTIFY_EVENT] =
1437 g_signal_new (I_("property-notify-event"),
1438 G_TYPE_FROM_CLASS (gobject_class),
1440 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1441 _gtk_boolean_handled_accumulator, NULL,
1442 _gtk_marshal_BOOLEAN__BOXED,
1444 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1447 * GtkWidget::selection-clear-event
1448 * @widget: the object which received the signal
1449 * @event: the #GdkEventSelection which triggered this signal
1451 * The ::selection-clear-event signal will be emitted when the
1452 * the @widget's window has lost ownership of a selection.
1454 * Returns: %TRUE to stop other handlers from being invoked for the event.
1455 * %FALSE to propagate the event further.
1457 widget_signals[SELECTION_CLEAR_EVENT] =
1458 g_signal_new (I_("selection-clear-event"),
1459 G_TYPE_FROM_CLASS (gobject_class),
1461 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1462 _gtk_boolean_handled_accumulator, NULL,
1463 _gtk_marshal_BOOLEAN__BOXED,
1465 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1468 * GtkWidget::selection-request-event
1469 * @widget: the object which received the signal
1470 * @event: the #GdkEventSelection which triggered this signal
1472 * The ::selection-request-event signal will be emitted when
1473 * another client requests ownership of the selection owned by
1474 * the @widget's window.
1476 * Returns: %TRUE to stop other handlers from being invoked for the event.
1477 * %FALSE to propagate the event further.
1479 widget_signals[SELECTION_REQUEST_EVENT] =
1480 g_signal_new (I_("selection-request-event"),
1481 G_TYPE_FROM_CLASS (gobject_class),
1483 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1484 _gtk_boolean_handled_accumulator, NULL,
1485 _gtk_marshal_BOOLEAN__BOXED,
1487 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1489 widget_signals[SELECTION_NOTIFY_EVENT] =
1490 g_signal_new (I_("selection-notify-event"),
1491 G_TYPE_FROM_CLASS (gobject_class),
1493 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1494 _gtk_boolean_handled_accumulator, NULL,
1495 _gtk_marshal_BOOLEAN__BOXED,
1497 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1499 widget_signals[SELECTION_RECEIVED] =
1500 g_signal_new (I_("selection-received"),
1501 G_TYPE_FROM_CLASS (gobject_class),
1503 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1505 _gtk_marshal_VOID__BOXED_UINT,
1507 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1510 widget_signals[SELECTION_GET] =
1511 g_signal_new (I_("selection-get"),
1512 G_TYPE_FROM_CLASS (gobject_class),
1514 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1516 _gtk_marshal_VOID__BOXED_UINT_UINT,
1518 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1523 * GtkWidget::proximity-in-event
1524 * @widget: the object which received the signal
1525 * @event: the #GdkEventProximity which triggered this signal
1527 * To receive this signal the #GdkWindow associated to the widget needs
1528 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1530 * This signal will be sent to the grab widget if there is one.
1532 * Returns: %TRUE to stop other handlers from being invoked for the event.
1533 * %FALSE to propagate the event further.
1535 widget_signals[PROXIMITY_IN_EVENT] =
1536 g_signal_new (I_("proximity-in-event"),
1537 G_TYPE_FROM_CLASS (gobject_class),
1539 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1540 _gtk_boolean_handled_accumulator, NULL,
1541 _gtk_marshal_BOOLEAN__BOXED,
1543 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1546 * GtkWidget::proximity-out-event
1547 * @widget: the object which received the signal
1548 * @event: the #GdkEventProximity which triggered this signal
1550 * To receive this signal the #GdkWindow associated to the widget needs
1551 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1553 * This signal will be sent to the grab widget if there is one.
1555 * Returns: %TRUE to stop other handlers from being invoked for the event.
1556 * %FALSE to propagate the event further.
1558 widget_signals[PROXIMITY_OUT_EVENT] =
1559 g_signal_new (I_("proximity-out-event"),
1560 G_TYPE_FROM_CLASS (gobject_class),
1562 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1563 _gtk_boolean_handled_accumulator, NULL,
1564 _gtk_marshal_BOOLEAN__BOXED,
1566 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1569 * GtkWidget::drag-leave:
1570 * @widget: the object which received the signal.
1571 * @drag_context: the drag context
1572 * @time: the timestamp of the motion event
1574 * The ::drag-leave signal is emitted on the drop site when the cursor
1575 * leaves the widget. A typical reason to connect to this signal is to
1576 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1577 * with gtk_drag_unhighlight()
1579 widget_signals[DRAG_LEAVE] =
1580 g_signal_new (I_("drag-leave"),
1581 G_TYPE_FROM_CLASS (gobject_class),
1583 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1585 _gtk_marshal_VOID__OBJECT_UINT,
1587 GDK_TYPE_DRAG_CONTEXT,
1591 * GtkWidget::drag-begin:
1592 * @widget: the object which received the signal
1593 * @drag_context: the drag context
1595 * The ::drag-begin signal is emitted on the drag source when a drag is
1596 * started. A typical reason to connect to this signal is to set up a
1597 * custom drag icon with gtk_drag_source_set_icon().
1599 widget_signals[DRAG_BEGIN] =
1600 g_signal_new (I_("drag-begin"),
1601 G_TYPE_FROM_CLASS (gobject_class),
1603 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1605 _gtk_marshal_VOID__OBJECT,
1607 GDK_TYPE_DRAG_CONTEXT);
1610 * GtkWidget::drag-end:
1611 * @widget: the object which received the signal
1612 * @drag_context: the drag context
1614 * The ::drag-end signal is emitted on the drag source when a drag is
1615 * finished. A typical reason to connect to this signal is to undo
1616 * things done in #GtkWidget::drag-begin.
1618 widget_signals[DRAG_END] =
1619 g_signal_new (I_("drag-end"),
1620 G_TYPE_FROM_CLASS (gobject_class),
1622 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1624 _gtk_marshal_VOID__OBJECT,
1626 GDK_TYPE_DRAG_CONTEXT);
1629 * GtkWidget::drag-data-delete:
1630 * @widget: the object which received the signal
1631 * @drag_context: the drag context
1633 * The ::drag-data-delete signal is emitted on the drag source when a drag
1634 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1635 * handler is responsible for deleting the data that has been dropped. What
1636 * "delete" means depends on the context of the drag operation.
1638 widget_signals[DRAG_DATA_DELETE] =
1639 g_signal_new (I_("drag-data-delete"),
1640 G_TYPE_FROM_CLASS (gobject_class),
1642 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1644 _gtk_marshal_VOID__OBJECT,
1646 GDK_TYPE_DRAG_CONTEXT);
1649 * GtkWidget::drag-failed:
1650 * @widget: the object which received the signal
1651 * @drag_context: the drag context
1652 * @result: the result of the drag operation
1654 * The ::drag-failed signal is emitted on the drag source when a drag has
1655 * failed. The signal handler may hook custom code to handle a failed DND
1656 * operation based on the type of error, it returns %TRUE is the failure has
1657 * been already handled (not showing the default "drag operation failed"
1658 * animation), otherwise it returns %FALSE.
1660 * Return value: %TRUE if the failed drag operation has been already handled.
1664 widget_signals[DRAG_FAILED] =
1665 g_signal_new (I_("drag-failed"),
1666 G_TYPE_FROM_CLASS (gobject_class),
1668 0, _gtk_boolean_handled_accumulator, NULL,
1669 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1671 GDK_TYPE_DRAG_CONTEXT,
1672 GTK_TYPE_DRAG_RESULT);
1675 * GtkWidget::drag-motion:
1676 * @widget: the object which received the signal
1677 * @drag_context: the drag context
1678 * @x: the x coordinate of the current cursor position
1679 * @y: the y coordinate of the current cursor position
1680 * @time: the timestamp of the motion event
1681 * @returns: whether the cursor position is in a drop zone
1683 * The drag-motion signal is emitted on the drop site when the user
1684 * moves the cursor over the widget during a drag. The signal handler
1685 * must determine whether the cursor position is in a drop zone or not.
1686 * If it is not in a drop zone, it returns %FALSE and no further processing
1687 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1688 * handler is responsible for providing the necessary information for
1689 * displaying feedback to the user, by calling gdk_drag_status().
1691 * If the decision whether the drop will be accepted or rejected can't be
1692 * made based solely on the cursor position and the type of the data, the
1693 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1694 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1695 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1696 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1697 * when using the drag-motion signal that way.
1699 * Also note that there is no drag-enter signal. The drag receiver has to
1700 * keep track of whether he has received any drag-motion signals since the
1701 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1702 * an "enter" signal. Upon an "enter", the handler will typically highlight
1703 * the drop site with gtk_drag_highlight().
1706 * drag_motion (GtkWidget *widget,
1707 * GdkDragContext *context,
1714 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1716 * if (!private_data->drag_highlight)
1718 * private_data->drag_highlight = 1;
1719 * gtk_drag_highlight (widget);
1722 * target = gtk_drag_dest_find_target (widget, context, NULL);
1723 * if (target == GDK_NONE)
1724 * gdk_drag_status (context, 0, time);
1727 * private_data->pending_status = context->suggested_action;
1728 * gtk_drag_get_data (widget, context, target, time);
1735 * drag_data_received (GtkWidget *widget,
1736 * GdkDragContext *context,
1739 * GtkSelectionData *selection_data,
1743 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1745 * if (private_data->suggested_action)
1747 * private_data->suggested_action = 0;
1749 * /* We are getting this data due to a request in drag_motion,
1750 * * rather than due to a request in drag_drop, so we are just
1751 * * supposed to call gdk_drag_status (), not actually paste in
1754 * str = gtk_selection_data_get_text (selection_data);
1755 * if (!data_is_acceptable (str))
1756 * gdk_drag_status (context, 0, time);
1758 * gdk_drag_status (context, private_data->suggested_action, time);
1762 * /* accept the drop */
1767 widget_signals[DRAG_MOTION] =
1768 g_signal_new (I_("drag-motion"),
1769 G_TYPE_FROM_CLASS (gobject_class),
1771 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1772 _gtk_boolean_handled_accumulator, NULL,
1773 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1775 GDK_TYPE_DRAG_CONTEXT,
1781 * GtkWidget::drag-drop:
1782 * @widget: the object which received the signal
1783 * @drag_context: the drag context
1784 * @x: the x coordinate of the current cursor position
1785 * @y: the y coordinate of the current cursor position
1786 * @time: the timestamp of the motion event
1787 * @returns: whether the cursor position is in a drop zone
1789 * The ::drag-drop signal is emitted on the drop site when the user drops
1790 * the data onto the widget. The signal handler must determine whether
1791 * the cursor position is in a drop zone or not. If it is not in a drop
1792 * zone, it returns %FALSE and no further processing is necessary.
1793 * Otherwise, the handler returns %TRUE. In this case, the handler must
1794 * ensure that gtk_drag_finish() is called to let the source know that
1795 * the drop is done. The call to gtk_drag_finish() can be done either
1796 * directly or in a #GtkWidget::drag-data-received handler which gets
1797 * triggered by calling gtk_drag_get_data() to receive the data for one
1798 * or more of the supported targets.
1800 widget_signals[DRAG_DROP] =
1801 g_signal_new (I_("drag-drop"),
1802 G_TYPE_FROM_CLASS (gobject_class),
1804 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1805 _gtk_boolean_handled_accumulator, NULL,
1806 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1808 GDK_TYPE_DRAG_CONTEXT,
1814 * GtkWidget::drag-data-get:
1815 * @widget: the object which received the signal
1816 * @drag_context: the drag context
1817 * @data: the #GtkSelectionData to be filled with the dragged data
1818 * @info: the info that has been registered with the target in the
1820 * @time: the timestamp at which the data was requested
1822 * The ::drag-data-get signal is emitted on the drag source when the drop
1823 * site requests the data which is dragged. It is the responsibility of
1824 * the signal handler to fill @data with the data in the format which
1825 * is indicated by @info. See gtk_selection_data_set() and
1826 * gtk_selection_data_set_text().
1828 widget_signals[DRAG_DATA_GET] =
1829 g_signal_new (I_("drag-data-get"),
1830 G_TYPE_FROM_CLASS (gobject_class),
1832 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1834 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1836 GDK_TYPE_DRAG_CONTEXT,
1837 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1842 * GtkWidget::drag-data-received:
1843 * @widget: the object which received the signal
1844 * @drag_context: the drag context
1845 * @x: where the drop happened
1846 * @y: where the drop happened
1847 * @data: the received data
1848 * @info: the info that has been registered with the target in the
1850 * @time: the timestamp at which the data was received
1852 * The ::drag-data-received signal is emitted on the drop site when the
1853 * dragged data has been received. If the data was received in order to
1854 * determine whether the drop will be accepted, the handler is expected
1855 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1856 * If the data was received in response to a #GtkWidget::drag-drop signal
1857 * (and this is the last target to be received), the handler for this
1858 * signal is expected to process the received data and then call
1859 * gtk_drag_finish(), setting the @success parameter depending on whether
1860 * the data was processed successfully.
1862 * The handler may inspect and modify @drag_context->action before calling
1863 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1864 * following example:
1867 * drag_data_received (GtkWidget *widget,
1868 * GdkDragContext *drag_context,
1871 * GtkSelectionData *data,
1875 * if ((data->length >= 0) && (data->format == 8))
1877 * if (drag_context->action == GDK_ACTION_ASK)
1879 * GtkWidget *dialog;
1882 * dialog = gtk_message_dialog_new (NULL,
1883 * GTK_DIALOG_MODAL |
1884 * GTK_DIALOG_DESTROY_WITH_PARENT,
1886 * GTK_BUTTONS_YES_NO,
1887 * "Move the data ?\n");
1888 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1889 * gtk_widget_destroy (dialog);
1891 * if (response == GTK_RESPONSE_YES)
1892 * drag_context->action = GDK_ACTION_MOVE;
1894 * drag_context->action = GDK_ACTION_COPY;
1897 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1901 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1905 widget_signals[DRAG_DATA_RECEIVED] =
1906 g_signal_new (I_("drag-data-received"),
1907 G_TYPE_FROM_CLASS (gobject_class),
1909 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1911 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1913 GDK_TYPE_DRAG_CONTEXT,
1916 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1921 * GtkWidget::visibility-notify-event:
1922 * @widget: the object which received the signal
1923 * @event: the #GdkEventVisibility which triggered this signal
1925 * The ::visibility-notify-event will be emitted when the @widget's window
1926 * is obscured or unobscured.
1928 * To receive this signal the #GdkWindow associated to the widget needs
1929 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1931 * Returns: %TRUE to stop other handlers from being invoked for the event.
1932 * %FALSE to propagate the event further.
1934 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1935 g_signal_new (I_("visibility-notify-event"),
1936 G_TYPE_FROM_CLASS (gobject_class),
1938 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1939 _gtk_boolean_handled_accumulator, NULL,
1940 _gtk_marshal_BOOLEAN__BOXED,
1942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1945 * GtkWidget::client-event:
1946 * @widget: the object which received the signal
1947 * @event: the #GdkEventClient which triggered this signal
1949 * The ::client-event will be emitted when the @widget's window
1950 * receives a message (via a ClientMessage event) from another
1953 * Returns: %TRUE to stop other handlers from being invoked for
1954 * the event. %FALSE to propagate the event further.
1956 widget_signals[CLIENT_EVENT] =
1957 g_signal_new (I_("client-event"),
1958 G_TYPE_FROM_CLASS (gobject_class),
1960 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1961 _gtk_boolean_handled_accumulator, NULL,
1962 _gtk_marshal_BOOLEAN__BOXED,
1964 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1967 * GtkWidget::no-expose-event:
1968 * @widget: the object which received the signal
1969 * @event: the #GdkEventNoExpose which triggered this signal
1971 * The ::no-expose-event will be emitted when the @widget's window is
1972 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1973 * gdk_window_copy_area()) which was completely unobscured. If the source
1974 * window was partially obscured #GdkEventExpose events will be generated
1977 * Returns: %TRUE to stop other handlers from being invoked for the event.
1978 * %FALSE to propagate the event further.
1980 widget_signals[NO_EXPOSE_EVENT] =
1981 g_signal_new (I_("no-expose-event"),
1982 G_TYPE_FROM_CLASS (gobject_class),
1984 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1985 _gtk_boolean_handled_accumulator, NULL,
1986 _gtk_marshal_BOOLEAN__BOXED,
1988 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1991 * GtkWidget::window-state-event:
1992 * @widget: the object which received the signal
1993 * @event: the #GdkEventWindowState which triggered this signal
1995 * The ::window-state-event will be emitted when the state of the
1996 * toplevel window associated to the @widget changes.
1998 * To receive this signal the #GdkWindow associated to the widget
1999 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2000 * this mask automatically for all new windows.
2002 * Returns: %TRUE to stop other handlers from being invoked for the
2003 * event. %FALSE to propagate the event further.
2005 widget_signals[WINDOW_STATE_EVENT] =
2006 g_signal_new (I_("window-state-event"),
2007 G_TYPE_FROM_CLASS (gobject_class),
2009 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2010 _gtk_boolean_handled_accumulator, NULL,
2011 _gtk_marshal_BOOLEAN__BOXED,
2013 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2016 * GtkWidget::damage-event:
2017 * @widget: the object which received the signal
2018 * @event: the #GdkEventExpose event
2020 * Emitted when a redirected window belonging to @widget gets drawn into.
2021 * The region/area members of the event shows what area of the redirected
2022 * drawable was drawn into.
2024 * Returns: %TRUE to stop other handlers from being invoked for the event.
2025 * %FALSE to propagate the event further.
2029 widget_signals[DAMAGE_EVENT] =
2030 g_signal_new (I_("damage-event"),
2031 G_TYPE_FROM_CLASS (gobject_class),
2034 _gtk_boolean_handled_accumulator, NULL,
2035 _gtk_marshal_BOOLEAN__BOXED,
2037 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2039 * GtkWidget::grab-broken-event:
2040 * @widget: the object which received the signal
2041 * @event: the #GdkEventGrabBroken event
2043 * Emitted when a pointer or keyboard grab on a window belonging
2044 * to @widget gets broken.
2046 * On X11, this happens when the grab window becomes unviewable
2047 * (i.e. it or one of its ancestors is unmapped), or if the same
2048 * application grabs the pointer or keyboard again.
2050 * Returns: %TRUE to stop other handlers from being invoked for
2051 * the event. %FALSE to propagate the event further.
2055 widget_signals[GRAB_BROKEN] =
2056 g_signal_new (I_("grab-broken-event"),
2057 G_TYPE_FROM_CLASS (gobject_class),
2059 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2060 _gtk_boolean_handled_accumulator, NULL,
2061 _gtk_marshal_BOOLEAN__BOXED,
2063 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2065 * GtkWidget::query-tooltip:
2066 * @widget: the object which received the signal
2067 * @x: the x coordinate of the cursor position where the request has
2068 * been emitted, relative to @widget->window
2069 * @y: the y coordinate of the cursor position where the request has
2070 * been emitted, relative to @widget->window
2071 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2072 * @tooltip: a #GtkTooltip
2074 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2075 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2076 * focus in keyboard mode.
2078 * Using the given coordinates, the signal handler should determine
2079 * whether a tooltip should be shown for @widget. If this is the case
2080 * %TRUE should be returned, %FALSE otherwise. Note that if
2081 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2082 * should not be used.
2084 * The signal handler is free to manipulate @tooltip with the therefore
2085 * destined function calls.
2087 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2091 widget_signals[QUERY_TOOLTIP] =
2092 g_signal_new (I_("query-tooltip"),
2093 G_TYPE_FROM_CLASS (gobject_class),
2095 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2096 _gtk_boolean_handled_accumulator, NULL,
2097 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2105 * GtkWidget::popup-menu
2106 * @widget: the object which received the signal
2108 * This signal gets emitted whenever a widget should pop up a context
2109 * menu. This usually happens through the standard key binding mechanism;
2110 * by pressing a certain key while a widget is focused, the user can cause
2111 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2112 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2113 * for an example of how to use this signal.
2115 * Returns: %TRUE if a menu was activated
2117 widget_signals[POPUP_MENU] =
2118 g_signal_new (I_("popup-menu"),
2119 G_TYPE_FROM_CLASS (gobject_class),
2120 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2121 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2122 _gtk_boolean_handled_accumulator, NULL,
2123 _gtk_marshal_BOOLEAN__VOID,
2125 widget_signals[SHOW_HELP] =
2126 g_signal_new (I_("show-help"),
2127 G_TYPE_FROM_CLASS (gobject_class),
2128 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2129 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2130 _gtk_boolean_handled_accumulator, NULL,
2131 _gtk_marshal_BOOLEAN__ENUM,
2133 GTK_TYPE_WIDGET_HELP_TYPE);
2134 widget_signals[ACCEL_CLOSURES_CHANGED] =
2135 g_signal_new (I_("accel-closures-changed"),
2136 G_TYPE_FROM_CLASS (gobject_class),
2140 _gtk_marshal_VOID__VOID,
2144 * GtkWidget::screen-changed:
2145 * @widget: the object on which the signal is emitted
2146 * @previous_screen: the previous screen, or %NULL if the
2147 * widget was not associated with a screen before
2149 * The ::screen-changed signal gets emitted when the
2150 * screen of a widget has changed.
2152 widget_signals[SCREEN_CHANGED] =
2153 g_signal_new (I_("screen-changed"),
2154 G_TYPE_FROM_CLASS (gobject_class),
2156 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2158 _gtk_marshal_VOID__OBJECT,
2162 * GtkWidget::can-activate-accel:
2163 * @widget: the object which received the signal
2164 * @signal_id: the ID of a signal installed on @widget
2166 * Determines whether an accelerator that activates the signal
2167 * identified by @signal_id can currently be activated.
2168 * This signal is present to allow applications and derived
2169 * widgets to override the default #GtkWidget handling
2170 * for determining whether an accelerator can be activated.
2172 * Returns: %TRUE if the signal can be activated.
2174 widget_signals[CAN_ACTIVATE_ACCEL] =
2175 g_signal_new (I_("can-activate-accel"),
2176 G_TYPE_FROM_CLASS (gobject_class),
2178 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2179 _gtk_boolean_handled_accumulator, NULL,
2180 _gtk_marshal_BOOLEAN__UINT,
2181 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2183 binding_set = gtk_binding_set_by_class (klass);
2184 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2186 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2189 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2191 GTK_TYPE_WIDGET_HELP_TYPE,
2192 GTK_WIDGET_HELP_TOOLTIP);
2193 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2195 GTK_TYPE_WIDGET_HELP_TYPE,
2196 GTK_WIDGET_HELP_TOOLTIP);
2197 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2199 GTK_TYPE_WIDGET_HELP_TYPE,
2200 GTK_WIDGET_HELP_WHATS_THIS);
2201 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2203 GTK_TYPE_WIDGET_HELP_TYPE,
2204 GTK_WIDGET_HELP_WHATS_THIS);
2206 gtk_widget_class_install_style_property (klass,
2207 g_param_spec_boolean ("interior-focus",
2208 P_("Interior Focus"),
2209 P_("Whether to draw the focus indicator inside widgets"),
2211 GTK_PARAM_READABLE));
2213 gtk_widget_class_install_style_property (klass,
2214 g_param_spec_int ("focus-line-width",
2215 P_("Focus linewidth"),
2216 P_("Width, in pixels, of the focus indicator line"),
2218 GTK_PARAM_READABLE));
2220 gtk_widget_class_install_style_property (klass,
2221 g_param_spec_string ("focus-line-pattern",
2222 P_("Focus line dash pattern"),
2223 P_("Dash pattern used to draw the focus indicator"),
2225 GTK_PARAM_READABLE));
2226 gtk_widget_class_install_style_property (klass,
2227 g_param_spec_int ("focus-padding",
2228 P_("Focus padding"),
2229 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2231 GTK_PARAM_READABLE));
2232 gtk_widget_class_install_style_property (klass,
2233 g_param_spec_boxed ("cursor-color",
2235 P_("Color with which to draw insertion cursor"),
2237 GTK_PARAM_READABLE));
2238 gtk_widget_class_install_style_property (klass,
2239 g_param_spec_boxed ("secondary-cursor-color",
2240 P_("Secondary cursor color"),
2241 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2243 GTK_PARAM_READABLE));
2244 gtk_widget_class_install_style_property (klass,
2245 g_param_spec_float ("cursor-aspect-ratio",
2246 P_("Cursor line aspect ratio"),
2247 P_("Aspect ratio with which to draw insertion cursor"),
2249 GTK_PARAM_READABLE));
2252 * GtkWidget:draw-border:
2254 * The "draw-border" style property defines the size of areas outside
2255 * the widget's allocation to draw.
2259 gtk_widget_class_install_style_property (klass,
2260 g_param_spec_boxed ("draw-border",
2262 P_("Size of areas outside the widget's allocation to draw"),
2264 GTK_PARAM_READABLE));
2267 * GtkWidget:link-color:
2269 * The "link-color" style property defines the color of unvisited links.
2273 gtk_widget_class_install_style_property (klass,
2274 g_param_spec_boxed ("link-color",
2275 P_("Unvisited Link Color"),
2276 P_("Color of unvisited links"),
2278 GTK_PARAM_READABLE));
2281 * GtkWidget:visited-link-color:
2283 * The "visited-link-color" style property defines the color of visited links.
2287 gtk_widget_class_install_style_property (klass,
2288 g_param_spec_boxed ("visited-link-color",
2289 P_("Visited Link Color"),
2290 P_("Color of visited links"),
2292 GTK_PARAM_READABLE));
2295 * GtkWidget:wide-separators:
2297 * The "wide-separators" style property defines whether separators have
2298 * configurable width and should be drawn using a box instead of a line.
2302 gtk_widget_class_install_style_property (klass,
2303 g_param_spec_boolean ("wide-separators",
2304 P_("Wide Separators"),
2305 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2307 GTK_PARAM_READABLE));
2310 * GtkWidget:separator-width:
2312 * The "separator-width" style property defines the width of separators.
2313 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2317 gtk_widget_class_install_style_property (klass,
2318 g_param_spec_int ("separator-width",
2319 P_("Separator Width"),
2320 P_("The width of separators if wide-separators is TRUE"),
2322 GTK_PARAM_READABLE));
2325 * GtkWidget:separator-height:
2327 * The "separator-height" style property defines the height of separators.
2328 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2332 gtk_widget_class_install_style_property (klass,
2333 g_param_spec_int ("separator-height",
2334 P_("Separator Height"),
2335 P_("The height of separators if \"wide-separators\" is TRUE"),
2337 GTK_PARAM_READABLE));
2340 * GtkWidget:scroll-arrow-hlength:
2342 * The "scroll-arrow-hlength" style property defines the length of
2343 * horizontal scroll arrows.
2347 gtk_widget_class_install_style_property (klass,
2348 g_param_spec_int ("scroll-arrow-hlength",
2349 P_("Horizontal Scroll Arrow Length"),
2350 P_("The length of horizontal scroll arrows"),
2352 GTK_PARAM_READABLE));
2355 * GtkWidget:scroll-arrow-vlength:
2357 * The "scroll-arrow-vlength" style property defines the length of
2358 * vertical scroll arrows.
2362 gtk_widget_class_install_style_property (klass,
2363 g_param_spec_int ("scroll-arrow-vlength",
2364 P_("Vertical Scroll Arrow Length"),
2365 P_("The length of vertical scroll arrows"),
2367 GTK_PARAM_READABLE));
2371 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2375 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2376 for (node = list; node; node = node->next)
2378 GParamSpec *pspec = node->data;
2380 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2381 g_param_spec_unref (pspec);
2387 gtk_widget_set_property (GObject *object,
2389 const GValue *value,
2392 GtkWidget *widget = GTK_WIDGET (object);
2397 guint32 saved_flags;
2398 gchar *tooltip_markup;
2399 const gchar *tooltip_text;
2400 GtkWindow *tooltip_window;
2403 gtk_widget_set_name (widget, g_value_get_string (value));
2406 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2408 case PROP_WIDTH_REQUEST:
2409 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2411 case PROP_HEIGHT_REQUEST:
2412 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2415 if (g_value_get_boolean (value))
2416 gtk_widget_show (widget);
2418 gtk_widget_hide (widget);
2420 case PROP_SENSITIVE:
2421 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2423 case PROP_APP_PAINTABLE:
2424 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2426 case PROP_CAN_FOCUS:
2427 saved_flags = GTK_WIDGET_FLAGS (widget);
2428 if (g_value_get_boolean (value))
2429 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2431 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2432 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2433 gtk_widget_queue_resize (widget);
2435 case PROP_HAS_FOCUS:
2436 if (g_value_get_boolean (value))
2437 gtk_widget_grab_focus (widget);
2440 if (g_value_get_boolean (value))
2441 gtk_widget_grab_focus (widget);
2443 case PROP_CAN_DEFAULT:
2444 saved_flags = GTK_WIDGET_FLAGS (widget);
2445 if (g_value_get_boolean (value))
2446 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2448 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2449 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2450 gtk_widget_queue_resize (widget);
2452 case PROP_HAS_DEFAULT:
2453 if (g_value_get_boolean (value))
2454 gtk_widget_grab_default (widget);
2456 case PROP_RECEIVES_DEFAULT:
2457 if (g_value_get_boolean (value))
2458 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2460 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2463 gtk_widget_set_style (widget, g_value_get_object (value));
2466 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2467 gtk_widget_set_events (widget, g_value_get_flags (value));
2469 case PROP_EXTENSION_EVENTS:
2470 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2472 case PROP_NO_SHOW_ALL:
2473 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2475 case PROP_HAS_TOOLTIP:
2476 gtk_widget_real_set_has_tooltip (widget,
2477 g_value_get_boolean (value), FALSE);
2479 case PROP_TOOLTIP_MARKUP:
2480 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2481 tooltip_markup = g_value_dup_string (value);
2483 /* Treat an empty string as a NULL string,
2484 * because an empty string would be useless for a tooltip:
2486 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2488 g_free (tooltip_markup);
2489 tooltip_markup = 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);
2497 gtk_widget_trigger_tooltip_query (widget);
2499 case PROP_TOOLTIP_TEXT:
2500 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2502 tooltip_text = g_value_get_string (value);
2504 /* Treat an empty string as a NULL string,
2505 * because an empty string would be useless for a tooltip:
2507 if (tooltip_text && (strlen (tooltip_text) == 0))
2508 tooltip_text = NULL;
2510 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2512 g_object_set_qdata_full (object, quark_tooltip_markup,
2513 tooltip_markup, g_free);
2515 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2516 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2517 gtk_widget_trigger_tooltip_query (widget);
2520 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2526 gtk_widget_get_property (GObject *object,
2531 GtkWidget *widget = GTK_WIDGET (object);
2540 g_value_set_string (value, widget->name);
2542 g_value_set_static_string (value, "");
2545 g_value_set_object (value, widget->parent);
2547 case PROP_WIDTH_REQUEST:
2550 gtk_widget_get_size_request (widget, &w, NULL);
2551 g_value_set_int (value, w);
2554 case PROP_HEIGHT_REQUEST:
2557 gtk_widget_get_size_request (widget, NULL, &h);
2558 g_value_set_int (value, h);
2562 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2564 case PROP_SENSITIVE:
2565 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2567 case PROP_APP_PAINTABLE:
2568 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2570 case PROP_CAN_FOCUS:
2571 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2573 case PROP_HAS_FOCUS:
2574 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2577 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2579 case PROP_CAN_DEFAULT:
2580 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2582 case PROP_HAS_DEFAULT:
2583 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2585 case PROP_RECEIVES_DEFAULT:
2586 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2588 case PROP_COMPOSITE_CHILD:
2589 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2592 g_value_set_object (value, gtk_widget_get_style (widget));
2595 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2596 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2598 case PROP_EXTENSION_EVENTS:
2599 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2600 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2602 case PROP_NO_SHOW_ALL:
2603 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2605 case PROP_HAS_TOOLTIP:
2606 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2608 case PROP_TOOLTIP_TEXT:
2610 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2613 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2614 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2616 g_value_set_string (value, text);
2620 case PROP_TOOLTIP_MARKUP:
2621 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2624 g_value_set_object (value, gtk_widget_get_window (widget));
2627 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2633 gtk_widget_init (GtkWidget *widget)
2635 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2636 widget->state = GTK_STATE_NORMAL;
2637 widget->saved_state = GTK_STATE_NORMAL;
2638 widget->name = NULL;
2639 widget->requisition.width = 0;
2640 widget->requisition.height = 0;
2641 widget->allocation.x = -1;
2642 widget->allocation.y = -1;
2643 widget->allocation.width = 1;
2644 widget->allocation.height = 1;
2645 widget->window = NULL;
2646 widget->parent = NULL;
2648 GTK_WIDGET_SET_FLAGS (widget,
2650 GTK_PARENT_SENSITIVE |
2651 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2652 GTK_DOUBLE_BUFFERED);
2654 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2655 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2656 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2658 widget->style = gtk_widget_get_default_style ();
2659 g_object_ref (widget->style);
2664 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2666 GParamSpec **pspecs)
2668 GtkWidget *container = widget->parent;
2671 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2672 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2676 * gtk_widget_freeze_child_notify:
2677 * @widget: a #GtkWidget
2679 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2680 * signals are queued until gtk_widget_thaw_child_notify() is called
2683 * This is the analogue of g_object_freeze_notify() for child properties.
2686 gtk_widget_freeze_child_notify (GtkWidget *widget)
2688 g_return_if_fail (GTK_IS_WIDGET (widget));
2690 if (!G_OBJECT (widget)->ref_count)
2693 g_object_ref (widget);
2694 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2695 g_object_unref (widget);
2699 * gtk_widget_child_notify:
2700 * @widget: a #GtkWidget
2701 * @child_property: the name of a child property installed on the
2702 * class of @widget<!-- -->'s parent
2704 * Emits a #GtkWidget::child-notify signal for the
2705 * <link linkend="child-properties">child property</link> @child_property
2708 * This is the analogue of g_object_notify() for child properties.
2711 gtk_widget_child_notify (GtkWidget *widget,
2712 const gchar *child_property)
2716 g_return_if_fail (GTK_IS_WIDGET (widget));
2717 g_return_if_fail (child_property != NULL);
2718 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2721 g_object_ref (widget);
2722 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2724 G_OBJECT_TYPE (widget->parent),
2727 g_warning ("%s: container class `%s' has no child property named `%s'",
2729 G_OBJECT_TYPE_NAME (widget->parent),
2733 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2735 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2736 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2738 g_object_unref (widget);
2742 * gtk_widget_thaw_child_notify:
2743 * @widget: a #GtkWidget
2745 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2746 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2750 gtk_widget_thaw_child_notify (GtkWidget *widget)
2752 GObjectNotifyQueue *nqueue;
2754 g_return_if_fail (GTK_IS_WIDGET (widget));
2756 if (!G_OBJECT (widget)->ref_count)
2759 g_object_ref (widget);
2760 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2761 if (!nqueue || !nqueue->freeze_count)
2762 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2763 G_OBJECT_TYPE_NAME (widget), widget);
2765 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2766 g_object_unref (widget);
2772 * @type: type ID of the widget to create
2773 * @first_property_name: name of first property to set
2774 * @Varargs: value of first property, followed by more properties,
2777 * This is a convenience function for creating a widget and setting
2778 * its properties in one go. For example you might write:
2779 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2780 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2781 * g_object_new(), but returns a widget so you don't have to
2782 * cast the object yourself.
2784 * Return value: a new #GtkWidget of type @widget_type
2787 gtk_widget_new (GType type,
2788 const gchar *first_property_name,
2794 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2796 va_start (var_args, first_property_name);
2797 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2805 * @widget: a #GtkWidget
2806 * @first_property_name: name of first property to set
2807 * @Varargs: value of first property, followed by more properties,
2810 * Precursor of g_object_set().
2812 * Deprecated: 2.0: Use g_object_set() instead.
2815 gtk_widget_set (GtkWidget *widget,
2816 const gchar *first_property_name,
2821 g_return_if_fail (GTK_IS_WIDGET (widget));
2823 va_start (var_args, first_property_name);
2824 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2829 gtk_widget_queue_draw_child (GtkWidget *widget)
2833 parent = widget->parent;
2834 if (parent && GTK_WIDGET_DRAWABLE (parent))
2835 gtk_widget_queue_draw_area (parent,
2836 widget->allocation.x,
2837 widget->allocation.y,
2838 widget->allocation.width,
2839 widget->allocation.height);
2843 * gtk_widget_unparent:
2844 * @widget: a #GtkWidget
2846 * This function is only for use in widget implementations.
2847 * Should be called by implementations of the remove method
2848 * on #GtkContainer, to dissociate a child from the container.
2851 gtk_widget_unparent (GtkWidget *widget)
2853 GObjectNotifyQueue *nqueue;
2854 GtkWidget *toplevel;
2855 GtkWidget *old_parent;
2857 g_return_if_fail (GTK_IS_WIDGET (widget));
2858 if (widget->parent == NULL)
2861 /* keep this function in sync with gtk_menu_detach()
2864 g_object_freeze_notify (G_OBJECT (widget));
2865 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2867 toplevel = gtk_widget_get_toplevel (widget);
2868 if (GTK_WIDGET_TOPLEVEL (toplevel))
2869 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2871 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2872 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2874 /* If we are unanchoring the child, we save around the toplevel
2875 * to emit hierarchy changed
2877 if (GTK_WIDGET_ANCHORED (widget->parent))
2878 g_object_ref (toplevel);
2882 gtk_widget_queue_draw_child (widget);
2884 /* Reset the width and height here, to force reallocation if we
2885 * get added back to a new parent. This won't work if our new
2886 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2887 * (would 0x0 be OK here?)
2889 widget->allocation.width = 1;
2890 widget->allocation.height = 1;
2892 if (GTK_WIDGET_REALIZED (widget))
2894 if (GTK_WIDGET_IN_REPARENT (widget))
2895 gtk_widget_unmap (widget);
2897 gtk_widget_unrealize (widget);
2900 /* Removing a widget from a container restores the child visible
2901 * flag to the default state, so it doesn't affect the child
2902 * in the next parent.
2904 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2906 old_parent = widget->parent;
2907 widget->parent = NULL;
2908 gtk_widget_set_parent_window (widget, NULL);
2909 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2912 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2913 g_object_unref (toplevel);
2916 g_object_notify (G_OBJECT (widget), "parent");
2917 g_object_thaw_notify (G_OBJECT (widget));
2918 if (!widget->parent)
2919 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2920 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2921 g_object_unref (widget);
2925 * gtk_widget_destroy:
2926 * @widget: a #GtkWidget
2928 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2929 * you don't have to cast the widget to #GtkObject. When a widget is
2930 * destroyed, it will break any references it holds to other objects.
2931 * If the widget is inside a container, the widget will be removed
2932 * from the container. If the widget is a toplevel (derived from
2933 * #GtkWindow), it will be removed from the list of toplevels, and the
2934 * reference GTK+ holds to it will be removed. Removing a
2935 * widget from its container or the list of toplevels results in the
2936 * widget being finalized, unless you've added additional references
2937 * to the widget with g_object_ref().
2939 * In most cases, only toplevel widgets (windows) require explicit
2940 * destruction, because when you destroy a toplevel its children will
2941 * be destroyed as well.
2944 gtk_widget_destroy (GtkWidget *widget)
2946 g_return_if_fail (GTK_IS_WIDGET (widget));
2948 gtk_object_destroy ((GtkObject*) widget);
2952 * gtk_widget_destroyed:
2953 * @widget: a #GtkWidget
2954 * @widget_pointer: address of a variable that contains @widget
2956 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2957 * %NULL. It's intended to be used as a callback connected to the
2958 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2959 * as a signal handler, and pass the address of your widget variable
2960 * as user data. Then when the widget is destroyed, the variable will
2961 * be set to %NULL. Useful for example to avoid multiple copies
2962 * of the same dialog.
2965 gtk_widget_destroyed (GtkWidget *widget,
2966 GtkWidget **widget_pointer)
2968 /* Don't make any assumptions about the
2970 * Even check widget_pointer.
2973 *widget_pointer = NULL;
2978 * @widget: a #GtkWidget
2980 * Flags a widget to be displayed. Any widget that isn't shown will
2981 * not appear on the screen. If you want to show all the widgets in a
2982 * container, it's easier to call gtk_widget_show_all() on the
2983 * container, instead of individually showing the widgets.
2985 * Remember that you have to show the containers containing a widget,
2986 * in addition to the widget itself, before it will appear onscreen.
2988 * When a toplevel container is shown, it is immediately realized and
2989 * mapped; other shown widgets are realized and mapped when their
2990 * toplevel container is realized and mapped.
2993 gtk_widget_show (GtkWidget *widget)
2995 g_return_if_fail (GTK_IS_WIDGET (widget));
2997 if (!GTK_WIDGET_VISIBLE (widget))
2999 g_object_ref (widget);
3000 if (!GTK_WIDGET_TOPLEVEL (widget))
3001 gtk_widget_queue_resize (widget);
3002 g_signal_emit (widget, widget_signals[SHOW], 0);
3003 g_object_notify (G_OBJECT (widget), "visible");
3004 g_object_unref (widget);
3009 gtk_widget_real_show (GtkWidget *widget)
3011 if (!GTK_WIDGET_VISIBLE (widget))
3013 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3015 if (widget->parent &&
3016 GTK_WIDGET_MAPPED (widget->parent) &&
3017 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3018 !GTK_WIDGET_MAPPED (widget))
3019 gtk_widget_map (widget);
3024 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3027 g_signal_handlers_disconnect_by_func (widget,
3028 gtk_widget_show_map_callback,
3033 * gtk_widget_show_now:
3034 * @widget: a #GtkWidget
3036 * Shows a widget. If the widget is an unmapped toplevel widget
3037 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3038 * loop and wait for the window to actually be mapped. Be careful;
3039 * because the main loop is running, anything can happen during
3043 gtk_widget_show_now (GtkWidget *widget)
3047 g_return_if_fail (GTK_IS_WIDGET (widget));
3049 /* make sure we will get event */
3050 if (!GTK_WIDGET_MAPPED (widget) &&
3051 GTK_WIDGET_TOPLEVEL (widget))
3053 gtk_widget_show (widget);
3055 g_signal_connect (widget, "map-event",
3056 G_CALLBACK (gtk_widget_show_map_callback),
3060 gtk_main_iteration ();
3063 gtk_widget_show (widget);
3068 * @widget: a #GtkWidget
3070 * Reverses the effects of gtk_widget_show(), causing the widget to be
3071 * hidden (invisible to the user).
3074 gtk_widget_hide (GtkWidget *widget)
3076 g_return_if_fail (GTK_IS_WIDGET (widget));
3078 if (GTK_WIDGET_VISIBLE (widget))
3080 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3082 g_object_ref (widget);
3083 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3084 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3086 g_signal_emit (widget, widget_signals[HIDE], 0);
3087 if (!GTK_WIDGET_TOPLEVEL (widget))
3088 gtk_widget_queue_resize (widget);
3089 g_object_notify (G_OBJECT (widget), "visible");
3090 g_object_unref (widget);
3095 gtk_widget_real_hide (GtkWidget *widget)
3097 if (GTK_WIDGET_VISIBLE (widget))
3099 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3101 if (GTK_WIDGET_MAPPED (widget))
3102 gtk_widget_unmap (widget);
3107 * gtk_widget_hide_on_delete:
3108 * @widget: a #GtkWidget
3110 * Utility function; intended to be connected to the #GtkWidget::delete-event
3111 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3112 * argument, then returns %TRUE. If connected to ::delete-event, the
3113 * result is that clicking the close button for a window (on the
3114 * window frame, top right corner usually) will hide but not destroy
3115 * the window. By default, GTK+ destroys windows when ::delete-event
3118 * Return value: %TRUE
3121 gtk_widget_hide_on_delete (GtkWidget *widget)
3123 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3125 gtk_widget_hide (widget);
3131 * gtk_widget_show_all:
3132 * @widget: a #GtkWidget
3134 * Recursively shows a widget, and any child widgets (if the widget is
3138 gtk_widget_show_all (GtkWidget *widget)
3140 GtkWidgetClass *class;
3142 g_return_if_fail (GTK_IS_WIDGET (widget));
3144 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3147 class = GTK_WIDGET_GET_CLASS (widget);
3149 if (class->show_all)
3150 class->show_all (widget);
3154 * gtk_widget_hide_all:
3155 * @widget: a #GtkWidget
3157 * Recursively hides a widget and any child widgets.
3160 gtk_widget_hide_all (GtkWidget *widget)
3162 GtkWidgetClass *class;
3164 g_return_if_fail (GTK_IS_WIDGET (widget));
3166 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3169 class = GTK_WIDGET_GET_CLASS (widget);
3171 if (class->hide_all)
3172 class->hide_all (widget);
3177 * @widget: a #GtkWidget
3179 * This function is only for use in widget implementations. Causes
3180 * a widget to be mapped if it isn't already.
3183 gtk_widget_map (GtkWidget *widget)
3185 g_return_if_fail (GTK_IS_WIDGET (widget));
3186 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3187 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3189 if (!GTK_WIDGET_MAPPED (widget))
3191 if (!GTK_WIDGET_REALIZED (widget))
3192 gtk_widget_realize (widget);
3194 g_signal_emit (widget, widget_signals[MAP], 0);
3196 if (GTK_WIDGET_NO_WINDOW (widget))
3197 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3203 * @widget: a #GtkWidget
3205 * This function is only for use in widget implementations. Causes
3206 * a widget to be unmapped if it's currently mapped.
3209 gtk_widget_unmap (GtkWidget *widget)
3211 g_return_if_fail (GTK_IS_WIDGET (widget));
3213 if (GTK_WIDGET_MAPPED (widget))
3215 if (GTK_WIDGET_NO_WINDOW (widget))
3216 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3217 _gtk_tooltip_hide (widget);
3218 g_signal_emit (widget, widget_signals[UNMAP], 0);
3223 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3224 GdkExtensionMode mode,
3227 GList *free_list = NULL;
3230 if (window_list == NULL)
3232 if (!GTK_WIDGET_NO_WINDOW (widget))
3233 window_list = g_list_prepend (NULL, widget->window);
3235 window_list = gdk_window_get_children (widget->window);
3237 free_list = window_list;
3240 for (l = window_list; l != NULL; l = l->next)
3242 GdkWindow *window = l->data;
3245 gdk_window_get_user_data (window, &user_data);
3246 if (user_data == widget)
3250 gdk_input_set_extension_events (window,
3251 gdk_window_get_events (window),
3254 children = gdk_window_get_children (window);
3257 gtk_widget_set_extension_events_internal (widget, mode, children);
3258 g_list_free (children);
3264 g_list_free (free_list);
3268 * gtk_widget_realize:
3269 * @widget: a #GtkWidget
3271 * Creates the GDK (windowing system) resources associated with a
3272 * widget. For example, @widget->window will be created when a widget
3273 * is realized. Normally realization happens implicitly; if you show
3274 * a widget and all its parent containers, then the widget will be
3275 * realized and mapped automatically.
3277 * Realizing a widget requires all
3278 * the widget's parent widgets to be realized; calling
3279 * gtk_widget_realize() realizes the widget's parents in addition to
3280 * @widget itself. If a widget is not yet inside a toplevel window
3281 * when you realize it, bad things will happen.
3283 * This function is primarily used in widget implementations, and
3284 * isn't very useful otherwise. Many times when you think you might
3285 * need it, a better approach is to connect to a signal that will be
3286 * called after the widget is realized automatically, such as
3287 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3288 * GtkWidget::realize signal.
3291 gtk_widget_realize (GtkWidget *widget)
3293 GdkExtensionMode mode;
3294 GtkWidgetShapeInfo *shape_info;
3296 g_return_if_fail (GTK_IS_WIDGET (widget));
3297 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3298 GTK_IS_INVISIBLE (widget));
3300 if (!GTK_WIDGET_REALIZED (widget))
3303 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3304 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3307 if (widget->parent == NULL &&
3308 !GTK_WIDGET_TOPLEVEL (widget))
3309 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3310 "inside a toplevel window is not going to work very well. "
3311 "Widgets must be inside a toplevel container before realizing them.");
3313 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3314 gtk_widget_realize (widget->parent);
3316 gtk_widget_ensure_style (widget);
3318 g_signal_emit (widget, widget_signals[REALIZE], 0);
3320 gtk_widget_real_set_has_tooltip (widget,
3321 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3324 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3326 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3327 gdk_window_shape_combine_mask (widget->window,
3328 shape_info->shape_mask,
3329 shape_info->offset_x,
3330 shape_info->offset_y);
3333 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3335 gdk_window_input_shape_combine_mask (widget->window,
3336 shape_info->shape_mask,
3337 shape_info->offset_x,
3338 shape_info->offset_y);
3340 mode = gtk_widget_get_extension_events (widget);
3341 if (mode != GDK_EXTENSION_EVENTS_NONE)
3342 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3347 * gtk_widget_unrealize:
3348 * @widget: a #GtkWidget
3350 * This function is only useful in widget implementations.
3351 * Causes a widget to be unrealized (frees all GDK resources
3352 * associated with the widget, such as @widget->window).
3355 gtk_widget_unrealize (GtkWidget *widget)
3357 g_return_if_fail (GTK_IS_WIDGET (widget));
3359 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3360 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3362 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3363 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3365 if (GTK_WIDGET_REALIZED (widget))
3367 g_object_ref (widget);
3368 _gtk_tooltip_hide (widget);
3369 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3370 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3371 g_object_unref (widget);
3375 /*****************************************
3377 *****************************************/
3380 * gtk_widget_queue_draw_area:
3381 * @widget: a #GtkWidget
3382 * @x: x coordinate of upper-left corner of rectangle to redraw
3383 * @y: y coordinate of upper-left corner of rectangle to redraw
3384 * @width: width of region to draw
3385 * @height: height of region to draw
3387 * Invalidates the rectangular area of @widget defined by @x, @y,
3388 * @width and @height by calling gdk_window_invalidate_rect() on the
3389 * widget's window and all its child windows. Once the main loop
3390 * becomes idle (after the current batch of events has been processed,
3391 * roughly), the window will receive expose events for the union of
3392 * all regions that have been invalidated.
3394 * Normally you would only use this function in widget
3395 * implementations. You might also use it, or
3396 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3397 * #GtkDrawingArea or some portion thereof.
3399 * Frequently you can just call gdk_window_invalidate_rect() or
3400 * gdk_window_invalidate_region() instead of this function. Those
3401 * functions will invalidate only a single window, instead of the
3402 * widget and all its children.
3404 * The advantage of adding to the invalidated region compared to
3405 * simply drawing immediately is efficiency; using an invalid region
3406 * ensures that you only have to redraw one time.
3409 gtk_widget_queue_draw_area (GtkWidget *widget,
3415 GdkRectangle invalid_rect;
3418 g_return_if_fail (GTK_IS_WIDGET (widget));
3420 if (!GTK_WIDGET_REALIZED (widget))
3423 /* Just return if the widget or one of its ancestors isn't mapped */
3424 for (w = widget; w != NULL; w = w->parent)
3425 if (!GTK_WIDGET_MAPPED (w))
3428 /* Find the correct widget */
3430 if (!GTK_WIDGET_NO_WINDOW (widget))
3434 /* Translate widget relative to window-relative */
3436 gint wx, wy, wwidth, wheight;
3438 gdk_window_get_position (widget->window, &wx, &wy);
3439 x -= wx - widget->allocation.x;
3440 y -= wy - widget->allocation.y;
3442 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3444 if (x + width <= 0 || y + height <= 0 ||
3445 x >= wwidth || y >= wheight)
3456 if (x + width > wwidth)
3458 if (y + height > wheight)
3459 height = wheight - y;
3465 invalid_rect.width = width;
3466 invalid_rect.height = height;
3468 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3472 widget_add_child_draw_rectangle (GtkWidget *widget,
3475 GdkRectangle child_rect;
3477 if (!GTK_WIDGET_MAPPED (widget) ||
3478 widget->window != widget->parent->window)
3481 gtk_widget_get_draw_rectangle (widget, &child_rect);
3482 gdk_rectangle_union (rect, &child_rect, rect);
3486 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3489 if (GTK_WIDGET_NO_WINDOW (widget))
3491 GtkBorder *draw_border = NULL;
3493 *rect = widget->allocation;
3495 gtk_widget_style_get (widget,
3496 "draw-border", &draw_border,
3500 rect->x -= draw_border->left;
3501 rect->y -= draw_border->top;
3502 rect->width += draw_border->left + draw_border->right;
3503 rect->height += draw_border->top + draw_border->bottom;
3505 gtk_border_free (draw_border);
3508 if (GTK_IS_CONTAINER (widget))
3509 gtk_container_forall (GTK_CONTAINER (widget),
3510 (GtkCallback)widget_add_child_draw_rectangle,
3517 rect->width = widget->allocation.width;
3518 rect->height = widget->allocation.height;
3523 * gtk_widget_queue_draw:
3524 * @widget: a #GtkWidget
3526 * Equivalent to calling gtk_widget_queue_draw_area() for the
3527 * entire area of a widget.
3530 gtk_widget_queue_draw (GtkWidget *widget)
3534 g_return_if_fail (GTK_IS_WIDGET (widget));
3536 gtk_widget_get_draw_rectangle (widget, &rect);
3538 gtk_widget_queue_draw_area (widget,
3540 rect.width, rect.height);
3543 /* Invalidates the given area (allocation-relative-coordinates)
3544 * in all of the widget's windows
3547 * gtk_widget_queue_clear_area:
3548 * @widget: a #GtkWidget
3549 * @x: x coordinate of upper-left corner of rectangle to redraw
3550 * @y: y coordinate of upper-left corner of rectangle to redraw
3551 * @width: width of region to draw
3552 * @height: height of region to draw
3554 * This function is no longer different from
3555 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3556 * gtk_widget_queue_draw_area(). Originally
3557 * gtk_widget_queue_clear_area() would force a redraw of the
3558 * background for %GTK_NO_WINDOW widgets, and
3559 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3560 * the background will be redrawn.
3562 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3565 gtk_widget_queue_clear_area (GtkWidget *widget,
3571 g_return_if_fail (GTK_IS_WIDGET (widget));
3573 gtk_widget_queue_draw_area (widget, x, y, width, height);
3577 * gtk_widget_queue_clear:
3578 * @widget: a #GtkWidget
3580 * This function does the same as gtk_widget_queue_draw().
3582 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3585 gtk_widget_queue_clear (GtkWidget *widget)
3587 g_return_if_fail (GTK_IS_WIDGET (widget));
3589 gtk_widget_queue_draw (widget);
3593 * gtk_widget_queue_resize:
3594 * @widget: a #GtkWidget
3596 * This function is only for use in widget implementations.
3597 * Flags a widget to have its size renegotiated; should
3598 * be called when a widget for some reason has a new size request.
3599 * For example, when you change the text in a #GtkLabel, #GtkLabel
3600 * queues a resize to ensure there's enough space for the new text.
3603 gtk_widget_queue_resize (GtkWidget *widget)
3605 g_return_if_fail (GTK_IS_WIDGET (widget));
3607 if (GTK_WIDGET_REALIZED (widget))
3608 gtk_widget_queue_shallow_draw (widget);
3610 _gtk_size_group_queue_resize (widget);
3614 * gtk_widget_queue_resize_no_redraw:
3615 * @widget: a #GtkWidget
3617 * This function works like gtk_widget_queue_resize(),
3618 * except that the widget is not invalidated.
3623 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3625 g_return_if_fail (GTK_IS_WIDGET (widget));
3627 _gtk_size_group_queue_resize (widget);
3632 * @widget: a #GtkWidget
3633 * @area: area to draw
3635 * In GTK+ 1.2, this function would immediately render the
3636 * region @area of a widget, by invoking the virtual draw method of a
3637 * widget. In GTK+ 2.0, the draw method is gone, and instead
3638 * gtk_widget_draw() simply invalidates the specified region of the
3639 * widget, then updates the invalid region of the widget immediately.
3640 * Usually you don't want to update the region immediately for
3641 * performance reasons, so in general gtk_widget_queue_draw_area() is
3642 * a better choice if you want to draw a region of a widget.
3645 gtk_widget_draw (GtkWidget *widget,
3646 const GdkRectangle *area)
3648 g_return_if_fail (GTK_IS_WIDGET (widget));
3650 if (GTK_WIDGET_DRAWABLE (widget))
3653 gtk_widget_queue_draw_area (widget,
3655 area->width, area->height);
3657 gtk_widget_queue_draw (widget);
3659 gdk_window_process_updates (widget->window, TRUE);
3664 * gtk_widget_size_request:
3665 * @widget: a #GtkWidget
3666 * @requisition: a #GtkRequisition to be filled in
3668 * This function is typically used when implementing a #GtkContainer
3669 * subclass. Obtains the preferred size of a widget. The container
3670 * uses this information to arrange its child widgets and decide what
3671 * size allocations to give them with gtk_widget_size_allocate().
3673 * You can also call this function from an application, with some
3674 * caveats. Most notably, getting a size request requires the widget
3675 * to be associated with a screen, because font information may be
3676 * needed. Multihead-aware applications should keep this in mind.
3678 * Also remember that the size request is not necessarily the size
3679 * a widget will actually be allocated.
3681 * See also gtk_widget_get_child_requisition().
3684 gtk_widget_size_request (GtkWidget *widget,
3685 GtkRequisition *requisition)
3687 g_return_if_fail (GTK_IS_WIDGET (widget));
3689 #ifdef G_ENABLE_DEBUG
3690 if (requisition == &widget->requisition)
3691 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.");
3692 #endif /* G_ENABLE_DEBUG */
3694 _gtk_size_group_compute_requisition (widget, requisition);
3698 * gtk_widget_get_child_requisition:
3699 * @widget: a #GtkWidget
3700 * @requisition: a #GtkRequisition to be filled in
3702 * This function is only for use in widget implementations. Obtains
3703 * @widget->requisition, unless someone has forced a particular
3704 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3705 * in which case it returns that geometry instead of the widget's
3708 * This function differs from gtk_widget_size_request() in that
3709 * it retrieves the last size request value from @widget->requisition,
3710 * while gtk_widget_size_request() actually calls the "size_request" method
3711 * on @widget to compute the size request and fill in @widget->requisition,
3712 * and only then returns @widget->requisition.
3714 * Because this function does not call the "size_request" method, it
3715 * can only be used when you know that @widget->requisition is
3716 * up-to-date, that is, gtk_widget_size_request() has been called
3717 * since the last time a resize was queued. In general, only container
3718 * implementations have this information; applications should use
3719 * gtk_widget_size_request().
3722 gtk_widget_get_child_requisition (GtkWidget *widget,
3723 GtkRequisition *requisition)
3725 _gtk_size_group_get_child_requisition (widget, requisition);
3729 invalidate_predicate (GdkWindow *window,
3734 gdk_window_get_user_data (window, &user_data);
3736 return (user_data == data);
3739 /* Invalidate @region in widget->window and all children
3740 * of widget->window owned by widget. @region is in the
3741 * same coordinates as widget->allocation and will be
3742 * modified by this call.
3745 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3748 if (!GTK_WIDGET_REALIZED (widget))
3751 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3755 gdk_window_get_position (widget->window, &x, &y);
3756 gdk_region_offset (region, -x, -y);
3759 gdk_window_invalidate_maybe_recurse (widget->window, region,
3760 invalidate_predicate, widget);
3764 * gtk_widget_queue_shallow_draw:
3765 * @widget: a #GtkWidget
3767 * Like gtk_widget_queue_draw(), but only windows owned
3768 * by @widget are invalidated.
3771 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3776 if (!GTK_WIDGET_REALIZED (widget))
3779 gtk_widget_get_draw_rectangle (widget, &rect);
3781 /* get_draw_rectangle() gives us window coordinates, we
3782 * need to convert to the coordinates that widget->allocation
3785 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3789 gdk_window_get_position (widget->window, &wx, &wy);
3795 region = gdk_region_rectangle (&rect);
3796 gtk_widget_invalidate_widget_windows (widget, region);
3797 gdk_region_destroy (region);
3801 * gtk_widget_size_allocate:
3802 * @widget: a #GtkWidget
3803 * @allocation: position and size to be allocated to @widget
3805 * This function is only used by #GtkContainer subclasses, to assign a size
3806 * and position to their child widgets.
3809 gtk_widget_size_allocate (GtkWidget *widget,
3810 GtkAllocation *allocation)
3812 GtkWidgetAuxInfo *aux_info;
3813 GdkRectangle real_allocation;
3814 GdkRectangle old_allocation;
3815 gboolean alloc_needed;
3816 gboolean size_changed;
3817 gboolean position_changed;
3819 g_return_if_fail (GTK_IS_WIDGET (widget));
3821 #ifdef G_ENABLE_DEBUG
3822 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3833 parent = gtk_widget_get_parent (parent);
3836 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3837 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3838 2 * depth, " ", name,
3839 allocation->width, allocation->height);
3841 #endif /* G_ENABLE_DEBUG */
3843 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3844 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3845 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3847 old_allocation = widget->allocation;
3848 real_allocation = *allocation;
3849 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3853 if (aux_info->x_set)
3854 real_allocation.x = aux_info->x;
3855 if (aux_info->y_set)
3856 real_allocation.y = aux_info->y;
3859 if (real_allocation.width < 0 || real_allocation.height < 0)
3861 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3862 real_allocation.width,
3863 real_allocation.height);
3866 real_allocation.width = MAX (real_allocation.width, 1);
3867 real_allocation.height = MAX (real_allocation.height, 1);
3869 size_changed = (old_allocation.width != real_allocation.width ||
3870 old_allocation.height != real_allocation.height);
3871 position_changed = (old_allocation.x != real_allocation.x ||
3872 old_allocation.y != real_allocation.y);
3874 if (!alloc_needed && !size_changed && !position_changed)
3877 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3879 if (GTK_WIDGET_MAPPED (widget))
3881 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3883 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3885 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3886 gdk_region_union_with_rect (invalidate, &old_allocation);
3888 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3889 gdk_region_destroy (invalidate);
3894 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3896 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3898 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3899 gdk_region_union_with_rect (invalidate, &old_allocation);
3901 gtk_widget_invalidate_widget_windows (widget, invalidate);
3902 gdk_region_destroy (invalidate);
3907 if ((size_changed || position_changed) && widget->parent &&
3908 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3910 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3911 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3912 gdk_region_destroy (invalidate);
3917 * gtk_widget_common_ancestor:
3918 * @widget_a: a #GtkWidget
3919 * @widget_b: a #GtkWidget
3921 * Find the common ancestor of @widget_a and @widget_b that
3922 * is closest to the two widgets.
3924 * Return value: the closest common ancestor of @widget_a and
3925 * @widget_b or %NULL if @widget_a and @widget_b do not
3926 * share a common ancestor.
3929 gtk_widget_common_ancestor (GtkWidget *widget_a,
3930 GtkWidget *widget_b)
3932 GtkWidget *parent_a;
3933 GtkWidget *parent_b;
3937 parent_a = widget_a;
3938 while (parent_a->parent)
3940 parent_a = parent_a->parent;
3944 parent_b = widget_b;
3945 while (parent_b->parent)
3947 parent_b = parent_b->parent;
3951 if (parent_a != parent_b)
3954 while (depth_a > depth_b)
3956 widget_a = widget_a->parent;
3960 while (depth_b > depth_a)
3962 widget_b = widget_b->parent;
3966 while (widget_a != widget_b)
3968 widget_a = widget_a->parent;
3969 widget_b = widget_b->parent;
3976 * gtk_widget_translate_coordinates:
3977 * @src_widget: a #GtkWidget
3978 * @dest_widget: a #GtkWidget
3979 * @src_x: X position relative to @src_widget
3980 * @src_y: Y position relative to @src_widget
3981 * @dest_x: location to store X position relative to @dest_widget
3982 * @dest_y: location to store Y position relative to @dest_widget
3984 * Translate coordinates relative to @src_widget's allocation to coordinates
3985 * relative to @dest_widget's allocations. In order to perform this
3986 * operation, both widgets must be realized, and must share a common
3989 * Return value: %FALSE if either widget was not realized, or there
3990 * was no common ancestor. In this case, nothing is stored in
3991 * *@dest_x and *@dest_y. Otherwise %TRUE.
3994 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3995 GtkWidget *dest_widget,
4001 GtkWidget *ancestor;
4004 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4005 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4007 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4008 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4011 /* Translate from allocation relative to window relative */
4012 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4015 gdk_window_get_position (src_widget->window, &wx, &wy);
4017 src_x -= wx - src_widget->allocation.x;
4018 src_y -= wy - src_widget->allocation.y;
4022 src_x += src_widget->allocation.x;
4023 src_y += src_widget->allocation.y;
4026 /* Translate to the common ancestor */
4027 window = src_widget->window;
4028 while (window != ancestor->window)
4032 gdk_window_get_position (window, &dx, &dy);
4037 window = gdk_window_get_parent (window);
4039 if (!window) /* Handle GtkHandleBox */
4044 window = dest_widget->window;
4045 while (window != ancestor->window)
4049 gdk_window_get_position (window, &dx, &dy);
4054 window = gdk_window_get_parent (window);
4056 if (!window) /* Handle GtkHandleBox */
4060 /* Translate from window relative to allocation relative */
4061 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4064 gdk_window_get_position (dest_widget->window, &wx, &wy);
4066 src_x += wx - dest_widget->allocation.x;
4067 src_y += wy - dest_widget->allocation.y;
4071 src_x -= dest_widget->allocation.x;
4072 src_y -= dest_widget->allocation.y;
4084 gtk_widget_real_size_allocate (GtkWidget *widget,
4085 GtkAllocation *allocation)
4087 widget->allocation = *allocation;
4089 if (GTK_WIDGET_REALIZED (widget) &&
4090 !GTK_WIDGET_NO_WINDOW (widget))
4092 gdk_window_move_resize (widget->window,
4093 allocation->x, allocation->y,
4094 allocation->width, allocation->height);
4099 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4102 /* widgets must be onscreen for accels to take effect */
4103 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4107 * gtk_widget_can_activate_accel:
4108 * @widget: a #GtkWidget
4109 * @signal_id: the ID of a signal installed on @widget
4111 * Determines whether an accelerator that activates the signal
4112 * identified by @signal_id can currently be activated.
4113 * This is done by emitting the #GtkWidget::can-activate-accel
4114 * signal on @widget; if the signal isn't overridden by a
4115 * handler or in a derived widget, then the default check is
4116 * that the widget must be sensitive, and the widget and all
4117 * its ancestors mapped.
4119 * Return value: %TRUE if the accelerator can be activated.
4124 gtk_widget_can_activate_accel (GtkWidget *widget,
4127 gboolean can_activate = FALSE;
4128 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4129 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4130 return can_activate;
4139 closure_accel_activate (GClosure *closure,
4140 GValue *return_value,
4141 guint n_param_values,
4142 const GValue *param_values,
4143 gpointer invocation_hint,
4144 gpointer marshal_data)
4146 AccelClosure *aclosure = (AccelClosure*) closure;
4147 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4150 g_signal_emit (closure->data, aclosure->signal_id, 0);
4152 /* whether accelerator was handled */
4153 g_value_set_boolean (return_value, can_activate);
4157 closures_destroy (gpointer data)
4159 GSList *slist, *closures = data;
4161 for (slist = closures; slist; slist = slist->next)
4163 g_closure_invalidate (slist->data);
4164 g_closure_unref (slist->data);
4166 g_slist_free (closures);
4170 widget_new_accel_closure (GtkWidget *widget,
4173 AccelClosure *aclosure;
4174 GClosure *closure = NULL;
4175 GSList *slist, *closures;
4177 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4178 for (slist = closures; slist; slist = slist->next)
4179 if (!gtk_accel_group_from_accel_closure (slist->data))
4181 /* reuse this closure */
4182 closure = slist->data;
4187 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4188 closures = g_slist_prepend (closures, g_closure_ref (closure));
4189 g_closure_sink (closure);
4190 g_closure_set_marshal (closure, closure_accel_activate);
4192 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4194 aclosure = (AccelClosure*) closure;
4195 g_assert (closure->data == widget);
4196 g_assert (closure->marshal == closure_accel_activate);
4197 aclosure->signal_id = signal_id;
4203 * gtk_widget_add_accelerator
4204 * @widget: widget to install an accelerator on
4205 * @accel_signal: widget signal to emit on accelerator activation
4206 * @accel_group: accel group for this widget, added to its toplevel
4207 * @accel_key: GDK keyval of the accelerator
4208 * @accel_mods: modifier key combination of the accelerator
4209 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4211 * Installs an accelerator for this @widget in @accel_group that causes
4212 * @accel_signal to be emitted if the accelerator is activated.
4213 * The @accel_group needs to be added to the widget's toplevel via
4214 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4215 * Accelerators added through this function are not user changeable during
4216 * runtime. If you want to support accelerators that can be changed by the
4217 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4218 * gtk_menu_item_set_accel_path() instead.
4221 gtk_widget_add_accelerator (GtkWidget *widget,
4222 const gchar *accel_signal,
4223 GtkAccelGroup *accel_group,
4225 GdkModifierType accel_mods,
4226 GtkAccelFlags accel_flags)
4231 g_return_if_fail (GTK_IS_WIDGET (widget));
4232 g_return_if_fail (accel_signal != NULL);
4233 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4235 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4236 if (!query.signal_id ||
4237 !(query.signal_flags & G_SIGNAL_ACTION) ||
4238 query.return_type != G_TYPE_NONE ||
4241 /* hmm, should be elaborate enough */
4242 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4243 G_OBJECT_TYPE_NAME (widget), accel_signal);
4247 closure = widget_new_accel_closure (widget, query.signal_id);
4249 g_object_ref (widget);
4251 /* install the accelerator. since we don't map this onto an accel_path,
4252 * the accelerator will automatically be locked.
4254 gtk_accel_group_connect (accel_group,
4257 accel_flags | GTK_ACCEL_LOCKED,
4260 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4262 g_object_unref (widget);
4266 * gtk_widget_remove_accelerator:
4267 * @widget: widget to install an accelerator on
4268 * @accel_group: accel group for this widget
4269 * @accel_key: GDK keyval of the accelerator
4270 * @accel_mods: modifier key combination of the accelerator
4271 * @returns: whether an accelerator was installed and could be removed
4273 * Removes an accelerator from @widget, previously installed with
4274 * gtk_widget_add_accelerator().
4277 gtk_widget_remove_accelerator (GtkWidget *widget,
4278 GtkAccelGroup *accel_group,
4280 GdkModifierType accel_mods)
4282 GtkAccelGroupEntry *ag_entry;
4283 GList *slist, *clist;
4286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4287 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4289 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4290 clist = gtk_widget_list_accel_closures (widget);
4291 for (slist = clist; slist; slist = slist->next)
4295 for (i = 0; i < n; i++)
4296 if (slist->data == (gpointer) ag_entry[i].closure)
4298 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4300 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4302 g_list_free (clist);
4307 g_list_free (clist);
4309 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4310 accel_key, accel_mods, accel_group,
4311 G_OBJECT_TYPE_NAME (widget), widget);
4317 * gtk_widget_list_accel_closures
4318 * @widget: widget to list accelerator closures for
4319 * @returns: a newly allocated #GList of closures
4321 * Lists the closures used by @widget for accelerator group connections
4322 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4323 * The closures can be used to monitor accelerator changes on @widget,
4324 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4325 * #GtkAccelGroup of a closure which can be found out with
4326 * gtk_accel_group_from_accel_closure().
4329 gtk_widget_list_accel_closures (GtkWidget *widget)
4332 GList *clist = NULL;
4334 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4336 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4337 if (gtk_accel_group_from_accel_closure (slist->data))
4338 clist = g_list_prepend (clist, slist->data);
4344 GtkAccelGroup *accel_group;
4349 destroy_accel_path (gpointer data)
4351 AccelPath *apath = data;
4353 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4355 /* closures_destroy takes care of unrefing the closure */
4356 g_object_unref (apath->accel_group);
4358 g_slice_free (AccelPath, apath);
4363 * gtk_widget_set_accel_path:
4364 * @widget: a #GtkWidget
4365 * @accel_path: path used to look up the accelerator
4366 * @accel_group: a #GtkAccelGroup.
4368 * Given an accelerator group, @accel_group, and an accelerator path,
4369 * @accel_path, sets up an accelerator in @accel_group so whenever the
4370 * key binding that is defined for @accel_path is pressed, @widget
4371 * will be activated. This removes any accelerators (for any
4372 * accelerator group) installed by previous calls to
4373 * gtk_widget_set_accel_path(). Associating accelerators with
4374 * paths allows them to be modified by the user and the modifications
4375 * to be saved for future use. (See gtk_accel_map_save().)
4377 * This function is a low level function that would most likely
4378 * be used by a menu creation system like #GtkUIManager. If you
4379 * use #GtkUIManager, setting up accelerator paths will be done
4382 * Even when you you aren't using #GtkUIManager, if you only want to
4383 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4384 * provides a somewhat more convenient interface.
4386 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4387 * pass a static string, you can save some memory by interning it first with
4388 * g_intern_static_string().
4391 gtk_widget_set_accel_path (GtkWidget *widget,
4392 const gchar *accel_path,
4393 GtkAccelGroup *accel_group)
4397 g_return_if_fail (GTK_IS_WIDGET (widget));
4398 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4402 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4403 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4405 gtk_accel_map_add_entry (accel_path, 0, 0);
4406 apath = g_slice_new (AccelPath);
4407 apath->accel_group = g_object_ref (accel_group);
4408 apath->path_quark = g_quark_from_string (accel_path);
4409 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4414 /* also removes possible old settings */
4415 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4418 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4420 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4424 _gtk_widget_get_accel_path (GtkWidget *widget,
4429 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4431 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4433 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4434 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4438 gtk_widget_mnemonic_activate (GtkWidget *widget,
4439 gboolean group_cycling)
4443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4445 group_cycling = group_cycling != FALSE;
4446 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4449 g_signal_emit (widget,
4450 widget_signals[MNEMONIC_ACTIVATE],
4458 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4459 gboolean group_cycling)
4461 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4462 gtk_widget_activate (widget);
4463 else if (GTK_WIDGET_CAN_FOCUS (widget))
4464 gtk_widget_grab_focus (widget);
4467 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4468 G_OBJECT_TYPE_NAME (widget));
4469 gtk_widget_error_bell (widget);
4475 gtk_widget_real_key_press_event (GtkWidget *widget,
4478 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4482 gtk_widget_real_key_release_event (GtkWidget *widget,
4485 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4489 gtk_widget_real_focus_in_event (GtkWidget *widget,
4490 GdkEventFocus *event)
4492 gtk_widget_queue_shallow_draw (widget);
4498 gtk_widget_real_focus_out_event (GtkWidget *widget,
4499 GdkEventFocus *event)
4501 gtk_widget_queue_shallow_draw (widget);
4506 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4507 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4511 * @widget: a #GtkWidget
4512 * @event: a #GdkEvent
4514 * Rarely-used function. This function is used to emit
4515 * the event signals on a widget (those signals should never
4516 * be emitted without using this function to do so).
4517 * If you want to synthesize an event though, don't use this function;
4518 * instead, use gtk_main_do_event() so the event will behave as if
4519 * it were in the event queue. Don't synthesize expose events; instead,
4520 * use gdk_window_invalidate_rect() to invalidate a region of the
4523 * Return value: return from the event signal emission (%TRUE if
4524 * the event was handled)
4527 gtk_widget_event (GtkWidget *widget,
4530 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4531 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4533 if (event->type == GDK_EXPOSE)
4535 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4536 "the same effect, call gdk_window_invalidate_rect/region(), "
4537 "followed by gdk_window_process_updates().");
4541 return gtk_widget_event_internal (widget, event);
4546 * gtk_widget_send_expose:
4547 * @widget: a #GtkWidget
4548 * @event: a expose #GdkEvent
4550 * Very rarely-used function. This function is used to emit
4551 * an expose event signals on a widget. This function is not
4552 * normally used directly. The only time it is used is when
4553 * propagating an expose event to a child %NO_WINDOW widget, and
4554 * that is normally done using gtk_container_propagate_expose().
4556 * If you want to force an area of a window to be redrawn,
4557 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4558 * To cause the redraw to be done immediately, follow that call
4559 * with a call to gdk_window_process_updates().
4561 * Return value: return from the event signal emission (%TRUE if
4562 * the event was handled)
4565 gtk_widget_send_expose (GtkWidget *widget,
4568 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4569 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4570 g_return_val_if_fail (event != NULL, TRUE);
4571 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4573 return gtk_widget_event_internal (widget, event);
4577 event_window_is_still_viewable (GdkEvent *event)
4579 /* Some programs, such as gnome-theme-manager, fake widgets
4580 * into exposing onto a pixmap by sending expose events with
4581 * event->window pointing to a pixmap
4583 if (GDK_IS_PIXMAP (event->any.window))
4584 return event->type == GDK_EXPOSE;
4586 /* Check that we think the event's window is viewable before
4587 * delivering the event, to prevent suprises. We do this here
4588 * at the last moment, since the event may have been queued
4589 * up behind other events, held over a recursive main loop, etc.
4591 switch (event->type)
4594 case GDK_MOTION_NOTIFY:
4595 case GDK_BUTTON_PRESS:
4596 case GDK_2BUTTON_PRESS:
4597 case GDK_3BUTTON_PRESS:
4599 case GDK_ENTER_NOTIFY:
4600 case GDK_PROXIMITY_IN:
4602 return event->any.window && gdk_window_is_viewable (event->any.window);
4605 /* The following events are the second half of paired events;
4606 * we always deliver them to deal with widgets that clean up
4607 * on the second half.
4609 case GDK_BUTTON_RELEASE:
4610 case GDK_KEY_RELEASE:
4611 case GDK_LEAVE_NOTIFY:
4612 case GDK_PROXIMITY_OUT:
4616 /* Remaining events would make sense on an not-viewable window,
4617 * or don't have an associated window.
4624 gtk_widget_event_internal (GtkWidget *widget,
4627 gboolean return_val = FALSE;
4629 /* We check only once for is-still-visible; if someone
4630 * hides the window in on of the signals on the widget,
4631 * they are responsible for returning TRUE to terminate
4634 if (!event_window_is_still_viewable (event))
4637 g_object_ref (widget);
4639 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4640 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4645 switch (event->type)
4650 case GDK_BUTTON_PRESS:
4651 case GDK_2BUTTON_PRESS:
4652 case GDK_3BUTTON_PRESS:
4653 signal_num = BUTTON_PRESS_EVENT;
4656 signal_num = SCROLL_EVENT;
4658 case GDK_BUTTON_RELEASE:
4659 signal_num = BUTTON_RELEASE_EVENT;
4661 case GDK_MOTION_NOTIFY:
4662 signal_num = MOTION_NOTIFY_EVENT;
4665 signal_num = DELETE_EVENT;
4668 signal_num = DESTROY_EVENT;
4669 _gtk_tooltip_hide (widget);
4672 signal_num = KEY_PRESS_EVENT;
4674 case GDK_KEY_RELEASE:
4675 signal_num = KEY_RELEASE_EVENT;
4677 case GDK_ENTER_NOTIFY:
4678 signal_num = ENTER_NOTIFY_EVENT;
4680 case GDK_LEAVE_NOTIFY:
4681 signal_num = LEAVE_NOTIFY_EVENT;
4683 case GDK_FOCUS_CHANGE:
4684 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4685 if (event->focus_change.in)
4686 _gtk_tooltip_focus_in (widget);
4688 _gtk_tooltip_focus_out (widget);
4691 signal_num = CONFIGURE_EVENT;
4694 signal_num = MAP_EVENT;
4697 signal_num = UNMAP_EVENT;
4699 case GDK_WINDOW_STATE:
4700 signal_num = WINDOW_STATE_EVENT;
4702 case GDK_PROPERTY_NOTIFY:
4703 signal_num = PROPERTY_NOTIFY_EVENT;
4705 case GDK_SELECTION_CLEAR:
4706 signal_num = SELECTION_CLEAR_EVENT;
4708 case GDK_SELECTION_REQUEST:
4709 signal_num = SELECTION_REQUEST_EVENT;
4711 case GDK_SELECTION_NOTIFY:
4712 signal_num = SELECTION_NOTIFY_EVENT;
4714 case GDK_PROXIMITY_IN:
4715 signal_num = PROXIMITY_IN_EVENT;
4717 case GDK_PROXIMITY_OUT:
4718 signal_num = PROXIMITY_OUT_EVENT;
4721 signal_num = NO_EXPOSE_EVENT;
4723 case GDK_CLIENT_EVENT:
4724 signal_num = CLIENT_EVENT;
4727 signal_num = EXPOSE_EVENT;
4729 case GDK_VISIBILITY_NOTIFY:
4730 signal_num = VISIBILITY_NOTIFY_EVENT;
4732 case GDK_GRAB_BROKEN:
4733 signal_num = GRAB_BROKEN;
4736 signal_num = DAMAGE_EVENT;
4739 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4743 if (signal_num != -1)
4744 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4746 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4747 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4751 g_object_unref (widget);
4757 * gtk_widget_activate:
4758 * @widget: a #GtkWidget that's activatable
4760 * For widgets that can be "activated" (buttons, menu items, etc.)
4761 * this function activates them. Activation is what happens when you
4762 * press Enter on a widget during key navigation. If @widget isn't
4763 * activatable, the function returns %FALSE.
4765 * Return value: %TRUE if the widget was activatable
4768 gtk_widget_activate (GtkWidget *widget)
4770 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4772 if (WIDGET_CLASS (widget)->activate_signal)
4774 /* FIXME: we should eventually check the signals signature here */
4775 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4784 * gtk_widget_set_scroll_adjustments:
4785 * @widget: a #GtkWidget
4786 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4787 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4789 * For widgets that support scrolling, sets the scroll adjustments and
4790 * returns %TRUE. For widgets that don't support scrolling, does
4791 * nothing and returns %FALSE. Widgets that don't support scrolling
4792 * can be scrolled by placing them in a #GtkViewport, which does
4793 * support scrolling.
4795 * Return value: %TRUE if the widget supports scrolling
4798 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4799 GtkAdjustment *hadjustment,
4800 GtkAdjustment *vadjustment)
4805 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4808 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4810 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4812 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
4816 g_signal_query (signal_id, &query);
4817 if (!query.signal_id ||
4818 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
4819 query.return_type != G_TYPE_NONE ||
4820 query.n_params != 2 ||
4821 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
4822 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
4824 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
4825 G_OBJECT_TYPE_NAME (widget), query.signal_name);
4829 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
4834 gtk_widget_reparent_subwindows (GtkWidget *widget,
4835 GdkWindow *new_window)
4837 if (GTK_WIDGET_NO_WINDOW (widget))
4839 GList *children = gdk_window_get_children (widget->window);
4842 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4844 GdkWindow *window = tmp_list->data;
4847 gdk_window_get_user_data (window, &child);
4848 while (child && child != widget)
4849 child = ((GtkWidget*) child)->parent;
4852 gdk_window_reparent (window, new_window, 0, 0);
4855 g_list_free (children);
4860 GList *tmp_list, *children;
4862 parent = gdk_window_get_parent (widget->window);
4865 gdk_window_reparent (widget->window, new_window, 0, 0);
4868 children = gdk_window_get_children (parent);
4870 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4872 GdkWindow *window = tmp_list->data;
4875 gdk_window_get_user_data (window, &child);
4877 if (child == widget)
4878 gdk_window_reparent (window, new_window, 0, 0);
4881 g_list_free (children);
4887 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4888 gpointer client_data)
4890 g_assert (client_data != NULL);
4892 if (GTK_WIDGET_NO_WINDOW (widget))
4895 g_object_unref (widget->window);
4896 widget->window = (GdkWindow*) client_data;
4898 g_object_ref (widget->window);
4900 if (GTK_IS_CONTAINER (widget))
4901 gtk_container_forall (GTK_CONTAINER (widget),
4902 gtk_widget_reparent_fixup_child,
4908 * gtk_widget_reparent:
4909 * @widget: a #GtkWidget
4910 * @new_parent: a #GtkContainer to move the widget into
4912 * Moves a widget from one #GtkContainer to another, handling reference
4913 * count issues to avoid destroying the widget.
4916 gtk_widget_reparent (GtkWidget *widget,
4917 GtkWidget *new_parent)
4919 g_return_if_fail (GTK_IS_WIDGET (widget));
4920 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4921 g_return_if_fail (widget->parent != NULL);
4923 if (widget->parent != new_parent)
4925 /* First try to see if we can get away without unrealizing
4926 * the widget as we reparent it. if so we set a flag so
4927 * that gtk_widget_unparent doesn't unrealize widget
4929 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4930 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4932 g_object_ref (widget);
4933 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4934 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4935 g_object_unref (widget);
4937 if (GTK_WIDGET_IN_REPARENT (widget))
4939 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4941 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4942 gtk_widget_reparent_fixup_child (widget,
4943 gtk_widget_get_parent_window (widget));
4946 g_object_notify (G_OBJECT (widget), "parent");
4951 * gtk_widget_intersect:
4952 * @widget: a #GtkWidget
4953 * @area: a rectangle
4954 * @intersection: rectangle to store intersection of @widget and @area
4956 * Computes the intersection of a @widget's area and @area, storing
4957 * the intersection in @intersection, and returns %TRUE if there was
4958 * an intersection. @intersection may be %NULL if you're only
4959 * interested in whether there was an intersection.
4961 * Return value: %TRUE if there was an intersection
4964 gtk_widget_intersect (GtkWidget *widget,
4965 const GdkRectangle *area,
4966 GdkRectangle *intersection)
4972 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4973 g_return_val_if_fail (area != NULL, FALSE);
4976 dest = intersection;
4980 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4982 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4984 intersection->x -= widget->allocation.x;
4985 intersection->y -= widget->allocation.y;
4992 * gtk_widget_region_intersect:
4993 * @widget: a #GtkWidget
4994 * @region: a #GdkRegion, in the same coordinate system as
4995 * @widget->allocation. That is, relative to @widget->window
4996 * for %NO_WINDOW widgets; relative to the parent window
4997 * of @widget->window for widgets with their own window.
4998 * @returns: A newly allocated region holding the intersection of @widget
4999 * and @region. The coordinates of the return value are
5000 * relative to @widget->window for %NO_WINDOW widgets, and
5001 * relative to the parent window of @widget->window for
5002 * widgets with their own window.
5004 * Computes the intersection of a @widget's area and @region, returning
5005 * the intersection. The result may be empty, use gdk_region_empty() to
5009 gtk_widget_region_intersect (GtkWidget *widget,
5010 const GdkRegion *region)
5015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5016 g_return_val_if_fail (region != NULL, NULL);
5018 gtk_widget_get_draw_rectangle (widget, &rect);
5020 dest = gdk_region_rectangle (&rect);
5022 gdk_region_intersect (dest, region);
5028 * _gtk_widget_grab_notify:
5029 * @widget: a #GtkWidget
5030 * @was_grabbed: whether a grab is now in effect
5032 * Emits the #GtkWidget::grab-notify signal on @widget.
5037 _gtk_widget_grab_notify (GtkWidget *widget,
5038 gboolean was_grabbed)
5040 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5044 * gtk_widget_grab_focus:
5045 * @widget: a #GtkWidget
5047 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5048 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5049 * something like #GtkFrame won't work. (More precisely, it must have the
5050 * %GTK_CAN_FOCUS flag set.)
5053 gtk_widget_grab_focus (GtkWidget *widget)
5055 g_return_if_fail (GTK_IS_WIDGET (widget));
5057 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5060 g_object_ref (widget);
5061 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5062 g_object_notify (G_OBJECT (widget), "has-focus");
5063 g_object_unref (widget);
5067 reset_focus_recurse (GtkWidget *widget,
5070 if (GTK_IS_CONTAINER (widget))
5072 GtkContainer *container;
5074 container = GTK_CONTAINER (widget);
5075 gtk_container_set_focus_child (container, NULL);
5077 gtk_container_foreach (container,
5078 reset_focus_recurse,
5084 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5086 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5088 GtkWidget *toplevel;
5091 /* clear the current focus setting, break if the current widget
5092 * is the focus widget's parent, since containers above that will
5093 * be set by the next loop.
5095 toplevel = gtk_widget_get_toplevel (focus_widget);
5096 if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
5098 widget = GTK_WINDOW (toplevel)->focus_widget;
5100 if (widget == focus_widget)
5102 /* We call _gtk_window_internal_set_focus() here so that the
5103 * toplevel window can request the focus if necessary.
5104 * This is needed when the toplevel is a GtkPlug
5106 if (!GTK_WIDGET_HAS_FOCUS (widget))
5107 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5114 while (widget->parent && widget->parent != focus_widget->parent)
5116 widget = widget->parent;
5117 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5121 else if (toplevel != focus_widget)
5123 /* gtk_widget_grab_focus() operates on a tree without window...
5124 * actually, this is very questionable behaviour.
5127 gtk_container_foreach (GTK_CONTAINER (toplevel),
5128 reset_focus_recurse,
5132 /* now propagate the new focus up the widget tree and finally
5133 * set it on the window
5135 widget = focus_widget;
5136 while (widget->parent)
5138 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5139 widget = widget->parent;
5141 if (GTK_IS_WINDOW (widget))
5142 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5147 gtk_widget_real_query_tooltip (GtkWidget *widget,
5150 gboolean keyboard_tip,
5151 GtkTooltip *tooltip)
5153 gchar *tooltip_markup;
5154 gboolean has_tooltip;
5156 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5157 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5159 if (has_tooltip && tooltip_markup)
5161 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5169 gtk_widget_real_show_help (GtkWidget *widget,
5170 GtkWidgetHelpType help_type)
5172 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5174 _gtk_tooltip_toggle_keyboard_mode (widget);
5183 gtk_widget_real_focus (GtkWidget *widget,
5184 GtkDirectionType direction)
5186 if (!GTK_WIDGET_CAN_FOCUS (widget))
5189 if (!gtk_widget_is_focus (widget))
5191 gtk_widget_grab_focus (widget);
5199 gtk_widget_real_move_focus (GtkWidget *widget,
5200 GtkDirectionType direction)
5202 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5204 if (GTK_IS_WINDOW (toplevel) &&
5205 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5207 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5213 gtk_widget_real_keynav_failed (GtkWidget *widget,
5214 GtkDirectionType direction)
5216 gboolean cursor_only;
5220 case GTK_DIR_TAB_FORWARD:
5221 case GTK_DIR_TAB_BACKWARD:
5228 g_object_get (gtk_widget_get_settings (widget),
5229 "gtk-keynav-cursor-only", &cursor_only,
5236 gtk_widget_error_bell (widget);
5242 * gtk_widget_is_focus:
5243 * @widget: a #GtkWidget
5245 * Determines if the widget is the focus widget within its
5246 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5247 * necessarily set; %HAS_FOCUS will only be set if the
5248 * toplevel widget additionally has the global input focus.)
5250 * Return value: %TRUE if the widget is the focus widget.
5253 gtk_widget_is_focus (GtkWidget *widget)
5255 GtkWidget *toplevel;
5257 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5259 toplevel = gtk_widget_get_toplevel (widget);
5261 if (GTK_IS_WINDOW (toplevel))
5262 return widget == GTK_WINDOW (toplevel)->focus_widget;
5268 * gtk_widget_grab_default:
5269 * @widget: a #GtkWidget
5271 * Causes @widget to become the default widget. @widget must have the
5272 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5273 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5274 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5275 * the user presses Enter in a window. Default widgets must be
5276 * activatable, that is, gtk_widget_activate() should affect them.
5279 gtk_widget_grab_default (GtkWidget *widget)
5283 g_return_if_fail (GTK_IS_WIDGET (widget));
5284 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5286 window = gtk_widget_get_toplevel (widget);
5288 if (window && GTK_WIDGET_TOPLEVEL (window))
5289 gtk_window_set_default (GTK_WINDOW (window), widget);
5291 g_warning (G_STRLOC ": widget not within a GtkWindow");
5295 * gtk_widget_set_name:
5296 * @widget: a #GtkWidget
5297 * @name: name for the widget
5299 * Widgets can be named, which allows you to refer to them from a
5300 * gtkrc file. You can apply a style to widgets with a particular name
5301 * in the gtkrc file. See the documentation for gtkrc files (on the
5302 * same page as the docs for #GtkRcStyle).
5304 * Note that widget names are separated by periods in paths (see
5305 * gtk_widget_path()), so names with embedded periods may cause confusion.
5308 gtk_widget_set_name (GtkWidget *widget,
5313 g_return_if_fail (GTK_IS_WIDGET (widget));
5315 new_name = g_strdup (name);
5316 g_free (widget->name);
5317 widget->name = new_name;
5319 if (GTK_WIDGET_RC_STYLE (widget))
5320 gtk_widget_reset_rc_style (widget);
5322 g_object_notify (G_OBJECT (widget), "name");
5326 * gtk_widget_get_name:
5327 * @widget: a #GtkWidget
5329 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5330 * significance of widget names.
5332 * Return value: name of the widget. This string is owned by GTK+ and
5333 * should not be modified or freed
5335 G_CONST_RETURN gchar*
5336 gtk_widget_get_name (GtkWidget *widget)
5338 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5341 return widget->name;
5342 return g_type_name (GTK_WIDGET_TYPE (widget));
5346 * gtk_widget_set_state:
5347 * @widget: a #GtkWidget
5348 * @state: new state for @widget
5350 * This function is for use in widget implementations. Sets the state
5351 * of a widget (insensitive, prelighted, etc.) Usually you should set
5352 * the state using wrapper functions such as gtk_widget_set_sensitive().
5355 gtk_widget_set_state (GtkWidget *widget,
5358 g_return_if_fail (GTK_IS_WIDGET (widget));
5360 if (state == GTK_WIDGET_STATE (widget))
5363 if (state == GTK_STATE_INSENSITIVE)
5364 gtk_widget_set_sensitive (widget, FALSE);
5370 data.state_restoration = FALSE;
5371 data.use_forall = FALSE;
5373 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5375 data.parent_sensitive = TRUE;
5377 gtk_widget_propagate_state (widget, &data);
5379 if (GTK_WIDGET_DRAWABLE (widget))
5380 gtk_widget_queue_draw (widget);
5386 * gtk_widget_set_app_paintable:
5387 * @widget: a #GtkWidget
5388 * @app_paintable: %TRUE if the application will paint on the widget
5390 * Sets whether the application intends to draw on the widget in
5391 * an #GtkWidget::expose-event handler.
5393 * This is a hint to the widget and does not affect the behavior of
5394 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5395 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5396 * the effect is to suppress default themed drawing of the widget's
5397 * background. (Children of the widget will still be drawn.) The application
5398 * is then entirely responsible for drawing the widget background.
5400 * Note that the background is still drawn when the widget is mapped.
5401 * If this is not suitable (e.g. because you want to make a transparent
5402 * window using an RGBA visual), you can work around this by doing:
5404 * gtk_widget_realize (window);
5405 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5406 * gtk_widget_show (window);
5410 gtk_widget_set_app_paintable (GtkWidget *widget,
5411 gboolean app_paintable)
5413 g_return_if_fail (GTK_IS_WIDGET (widget));
5415 app_paintable = (app_paintable != FALSE);
5417 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5420 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5422 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5424 if (GTK_WIDGET_DRAWABLE (widget))
5425 gtk_widget_queue_draw (widget);
5427 g_object_notify (G_OBJECT (widget), "app-paintable");
5432 * gtk_widget_set_double_buffered:
5433 * @widget: a #GtkWidget
5434 * @double_buffered: %TRUE to double-buffer a widget
5436 * Widgets are double buffered by default; you can use this function
5437 * to turn off the buffering. "Double buffered" simply means that
5438 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5439 * automatically around expose events sent to the
5440 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5441 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5442 * buffer to the screen. The result is that users see the window
5443 * update in one smooth step, and don't see individual graphics
5444 * primitives being rendered.
5446 * In very simple terms, double buffered widgets don't flicker,
5447 * so you would only use this function to turn off double buffering
5448 * if you had special needs and really knew what you were doing.
5450 * Note: if you turn off double-buffering, you have to handle
5451 * expose events, since even the clearing to the background color or
5452 * pixmap will not happen automatically (as it is done in
5453 * gdk_window_begin_paint()).
5456 gtk_widget_set_double_buffered (GtkWidget *widget,
5457 gboolean double_buffered)
5459 g_return_if_fail (GTK_IS_WIDGET (widget));
5461 if (double_buffered)
5462 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5464 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5468 * gtk_widget_set_redraw_on_allocate:
5469 * @widget: a #GtkWidget
5470 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5471 * when it is allocated to a new size. Otherwise, only the
5472 * new portion of the widget will be redrawn.
5474 * Sets whether the entire widget is queued for drawing when its size
5475 * allocation changes. By default, this setting is %TRUE and
5476 * the entire widget is redrawn on every size change. If your widget
5477 * leaves the upper left unchanged when made bigger, turning this
5478 * setting off will improve performance.
5480 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5481 * off all allocation on resizing: the widget will not even redraw if
5482 * its position changes; this is to allow containers that don't draw
5483 * anything to avoid excess invalidations. If you set this flag on a
5484 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5485 * you are responsible for invalidating both the old and new allocation
5486 * of the widget when the widget is moved and responsible for invalidating
5487 * regions newly when the widget increases size.
5490 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5491 gboolean redraw_on_allocate)
5493 g_return_if_fail (GTK_IS_WIDGET (widget));
5495 if (redraw_on_allocate)
5496 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5498 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5502 * gtk_widget_set_sensitive:
5503 * @widget: a #GtkWidget
5504 * @sensitive: %TRUE to make the widget sensitive
5506 * Sets the sensitivity of a widget. A widget is sensitive if the user
5507 * can interact with it. Insensitive widgets are "grayed out" and the
5508 * user can't interact with them. Insensitive widgets are known as
5509 * "inactive", "disabled", or "ghosted" in some other toolkits.
5512 gtk_widget_set_sensitive (GtkWidget *widget,
5517 g_return_if_fail (GTK_IS_WIDGET (widget));
5519 sensitive = (sensitive != FALSE);
5521 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5526 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5527 data.state = GTK_WIDGET_SAVED_STATE (widget);
5531 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5532 data.state = GTK_WIDGET_STATE (widget);
5534 data.state_restoration = TRUE;
5535 data.use_forall = TRUE;
5538 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5540 data.parent_sensitive = TRUE;
5542 gtk_widget_propagate_state (widget, &data);
5543 if (GTK_WIDGET_DRAWABLE (widget))
5544 gtk_widget_queue_draw (widget);
5546 g_object_notify (G_OBJECT (widget), "sensitive");
5550 * gtk_widget_set_parent:
5551 * @widget: a #GtkWidget
5552 * @parent: parent container
5554 * This function is useful only when implementing subclasses of
5556 * Sets the container as the parent of @widget, and takes care of
5557 * some details such as updating the state and style of the child
5558 * to reflect its new location. The opposite function is
5559 * gtk_widget_unparent().
5562 gtk_widget_set_parent (GtkWidget *widget,
5567 g_return_if_fail (GTK_IS_WIDGET (widget));
5568 g_return_if_fail (GTK_IS_WIDGET (parent));
5569 g_return_if_fail (widget != parent);
5570 if (widget->parent != NULL)
5572 g_warning ("Can't set a parent on widget which has a parent\n");
5575 if (GTK_WIDGET_TOPLEVEL (widget))
5577 g_warning ("Can't set a parent on a toplevel widget\n");
5581 /* keep this function in sync with gtk_menu_attach_to_widget()
5584 g_object_ref_sink (widget);
5585 widget->parent = parent;
5587 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5588 data.state = GTK_WIDGET_STATE (parent);
5590 data.state = GTK_WIDGET_STATE (widget);
5591 data.state_restoration = FALSE;
5592 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5593 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5595 gtk_widget_propagate_state (widget, &data);
5597 gtk_widget_reset_rc_styles (widget);
5599 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5600 if (GTK_WIDGET_ANCHORED (widget->parent))
5601 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5602 g_object_notify (G_OBJECT (widget), "parent");
5604 /* Enforce realized/mapped invariants
5606 if (GTK_WIDGET_REALIZED (widget->parent))
5607 gtk_widget_realize (widget);
5609 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5610 GTK_WIDGET_VISIBLE (widget))
5612 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5613 GTK_WIDGET_MAPPED (widget->parent))
5614 gtk_widget_map (widget);
5616 gtk_widget_queue_resize (widget);
5621 * gtk_widget_get_parent:
5622 * @widget: a #GtkWidget
5624 * Returns the parent container of @widget.
5626 * Return value: the parent container of @widget, or %NULL
5629 gtk_widget_get_parent (GtkWidget *widget)
5631 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5633 return widget->parent;
5636 /*****************************************
5638 * see docs/styles.txt
5639 *****************************************/
5642 * gtk_widget_set_style:
5643 * @widget: a #GtkWidget
5644 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5645 * gtk_widget_set_style() and go back to the default style
5647 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5648 * want to use this function; it interacts badly with themes, because
5649 * themes work by replacing the #GtkStyle. Instead, use
5650 * gtk_widget_modify_style().
5653 gtk_widget_set_style (GtkWidget *widget,
5656 g_return_if_fail (GTK_IS_WIDGET (widget));
5660 gboolean initial_emission;
5662 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5664 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5665 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5667 gtk_widget_set_style_internal (widget, style, initial_emission);
5671 if (GTK_WIDGET_USER_STYLE (widget))
5672 gtk_widget_reset_rc_style (widget);
5677 * gtk_widget_ensure_style:
5678 * @widget: a #GtkWidget
5680 * Ensures that @widget has a style (@widget->style). Not a very useful
5681 * function; most of the time, if you want the style, the widget is
5682 * realized, and realized widgets are guaranteed to have a style
5686 gtk_widget_ensure_style (GtkWidget *widget)
5688 g_return_if_fail (GTK_IS_WIDGET (widget));
5690 if (!GTK_WIDGET_USER_STYLE (widget) &&
5691 !GTK_WIDGET_RC_STYLE (widget))
5692 gtk_widget_reset_rc_style (widget);
5695 /* Look up the RC style for this widget, unsetting any user style that
5696 * may be in effect currently
5699 gtk_widget_reset_rc_style (GtkWidget *widget)
5701 GtkStyle *new_style = NULL;
5702 gboolean initial_emission;
5704 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5706 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5707 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5709 if (gtk_widget_has_screen (widget))
5710 new_style = gtk_rc_get_style (widget);
5712 new_style = gtk_widget_get_default_style ();
5714 if (initial_emission || new_style != widget->style)
5715 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5719 * gtk_widget_get_style:
5720 * @widget: a #GtkWidget
5722 * Simply an accessor function that returns @widget->style.
5724 * Return value: the widget's #GtkStyle
5727 gtk_widget_get_style (GtkWidget *widget)
5729 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5731 return widget->style;
5735 * gtk_widget_modify_style:
5736 * @widget: a #GtkWidget
5737 * @style: the #GtkRcStyle holding the style modifications
5739 * Modifies style values on the widget. Modifications made using this
5740 * technique take precedence over style values set via an RC file,
5741 * however, they will be overriden if a style is explicitely set on
5742 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5743 * is designed so each field can either be set or unset, so it is
5744 * possible, using this function, to modify some style values and
5745 * leave the others unchanged.
5747 * Note that modifications made with this function are not cumulative
5748 * with previous calls to gtk_widget_modify_style() or with such
5749 * functions as gtk_widget_modify_fg(). If you wish to retain
5750 * previous values, you must first call gtk_widget_get_modifier_style(),
5751 * make your modifications to the returned style, then call
5752 * gtk_widget_modify_style() with that style. On the other hand,
5753 * if you first call gtk_widget_modify_style(), subsequent calls
5754 * to such functions gtk_widget_modify_fg() will have a cumulative
5755 * effect with the initial modifications.
5758 gtk_widget_modify_style (GtkWidget *widget,
5761 g_return_if_fail (GTK_IS_WIDGET (widget));
5762 g_return_if_fail (GTK_IS_RC_STYLE (style));
5764 g_object_set_qdata_full (G_OBJECT (widget),
5766 gtk_rc_style_copy (style),
5767 (GDestroyNotify) g_object_unref);
5769 /* note that "style" may be invalid here if it was the old
5770 * modifier style and the only reference was our own.
5773 if (GTK_WIDGET_RC_STYLE (widget))
5774 gtk_widget_reset_rc_style (widget);
5778 * gtk_widget_get_modifier_style:
5779 * @widget: a #GtkWidget
5781 * Returns the current modifier style for the widget. (As set by
5782 * gtk_widget_modify_style().) If no style has previously set, a new
5783 * #GtkRcStyle will be created with all values unset, and set as the
5784 * modifier style for the widget. If you make changes to this rc
5785 * style, you must call gtk_widget_modify_style(), passing in the
5786 * returned rc style, to make sure that your changes take effect.
5788 * Caution: passing the style back to gtk_widget_modify_style() will
5789 * normally end up destroying it, because gtk_widget_modify_style() copies
5790 * the passed-in style and sets the copy as the new modifier style,
5791 * thus dropping any reference to the old modifier style. Add a reference
5792 * to the modifier style if you want to keep it alive.
5794 * Return value: the modifier style for the widget. This rc style is
5795 * owned by the widget. If you want to keep a pointer to value this
5796 * around, you must add a refcount using g_object_ref().
5799 gtk_widget_get_modifier_style (GtkWidget *widget)
5801 GtkRcStyle *rc_style;
5803 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5805 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5809 rc_style = gtk_rc_style_new ();
5810 g_object_set_qdata_full (G_OBJECT (widget),
5813 (GDestroyNotify) g_object_unref);
5820 gtk_widget_modify_color_component (GtkWidget *widget,
5821 GtkRcFlags component,
5823 const GdkColor *color)
5825 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5832 rc_style->fg[state] = *color;
5835 rc_style->bg[state] = *color;
5838 rc_style->text[state] = *color;
5841 rc_style->base[state] = *color;
5844 g_assert_not_reached();
5847 rc_style->color_flags[state] |= component;
5850 rc_style->color_flags[state] &= ~component;
5852 gtk_widget_modify_style (widget, rc_style);
5856 * gtk_widget_modify_fg:
5857 * @widget: a #GtkWidget
5858 * @state: the state for which to set the foreground color
5859 * @color: the color to assign (does not need to be allocated),
5860 * or %NULL to undo the effect of previous calls to
5861 * of gtk_widget_modify_fg().
5863 * Sets the foreground color for a widget in a particular state.
5864 * All other style values are left untouched. See also
5865 * gtk_widget_modify_style().
5868 gtk_widget_modify_fg (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_FG, state, color);
5879 * gtk_widget_modify_bg:
5880 * @widget: a #GtkWidget
5881 * @state: the state for which to set the background 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_bg().
5886 * Sets the background color for a widget in a particular state.
5887 * All other style values are left untouched. See also
5888 * gtk_widget_modify_style().
5890 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5891 * draw on their parent container's window and thus may not draw any
5892 * background themselves. This is the case for e.g. #GtkLabel. To modify
5893 * the background of such widgets, you have to set the background color
5894 * on their parent; if you want to set the background of a rectangular
5895 * area around a label, try placing the label in a #GtkEventBox widget
5896 * and setting the background color on that.
5899 gtk_widget_modify_bg (GtkWidget *widget,
5901 const GdkColor *color)
5903 g_return_if_fail (GTK_IS_WIDGET (widget));
5904 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5906 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5910 * gtk_widget_modify_text:
5911 * @widget: a #GtkWidget
5912 * @state: the state for which to set the text color
5913 * @color: the color to assign (does not need to be allocated),
5914 * or %NULL to undo the effect of previous calls to
5915 * of gtk_widget_modify_text().
5917 * Sets the text color for a widget in a particular state. All other
5918 * style values are left untouched. The text color is the foreground
5919 * color used along with the base color (see gtk_widget_modify_base())
5920 * for widgets such as #GtkEntry and #GtkTextView. See also
5921 * gtk_widget_modify_style().
5924 gtk_widget_modify_text (GtkWidget *widget,
5926 const GdkColor *color)
5928 g_return_if_fail (GTK_IS_WIDGET (widget));
5929 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5931 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5935 * gtk_widget_modify_base:
5936 * @widget: a #GtkWidget
5937 * @state: the state for which to set the base color
5938 * @color: the color to assign (does not need to be allocated),
5939 * or %NULL to undo the effect of previous calls to
5940 * of gtk_widget_modify_base().
5942 * Sets the base color for a widget in a particular state.
5943 * All other style values are left untouched. The base color
5944 * is the background color used along with the text color
5945 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5946 * and #GtkTextView. See also gtk_widget_modify_style().
5948 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5949 * draw on their parent container's window and thus may not draw any
5950 * background themselves. This is the case for e.g. #GtkLabel. To modify
5951 * the background of such widgets, you have to set the base color on their
5952 * parent; if you want to set the background of a rectangular area around
5953 * a label, try placing the label in a #GtkEventBox widget and setting
5954 * the base color on that.
5957 gtk_widget_modify_base (GtkWidget *widget,
5959 const GdkColor *color)
5961 g_return_if_fail (GTK_IS_WIDGET (widget));
5962 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5964 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5968 modify_color_property (GtkWidget *widget,
5969 GtkRcStyle *rc_style,
5971 const GdkColor *color)
5973 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5974 GQuark property_name = g_quark_from_string (name);
5978 GtkRcProperty rc_property = {0};
5981 rc_property.type_name = type_name;
5982 rc_property.property_name = property_name;
5983 rc_property.origin = NULL;
5985 color_name = gdk_color_to_string (color);
5986 g_value_init (&rc_property.value, G_TYPE_STRING);
5987 g_value_take_string (&rc_property.value, color_name);
5989 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
5991 g_value_unset (&rc_property.value);
5994 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
5998 * gtk_widget_modify_cursor:
5999 * @widget: a #GtkWidget
6000 * @primary: the color to use for primary cursor (does not need to be
6001 * allocated), or %NULL to undo the effect of previous calls to
6002 * of gtk_widget_modify_cursor().
6003 * @secondary: the color to use for secondary cursor (does not need to be
6004 * allocated), or %NULL to undo the effect of previous calls to
6005 * of gtk_widget_modify_cursor().
6007 * Sets the cursor color to use in a widget, overriding the
6008 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
6009 * style properties. All other style values are left untouched.
6010 * See also gtk_widget_modify_style().
6015 gtk_widget_modify_cursor (GtkWidget *widget,
6016 const GdkColor *primary,
6017 const GdkColor *secondary)
6019 GtkRcStyle *rc_style;
6021 g_return_if_fail (GTK_IS_WIDGET (widget));
6023 rc_style = gtk_widget_get_modifier_style (widget);
6025 modify_color_property (widget, rc_style, "cursor-color", primary);
6026 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6028 gtk_widget_modify_style (widget, rc_style);
6032 * gtk_widget_modify_font:
6033 * @widget: a #GtkWidget
6034 * @font_desc: the font description to use, or %NULL to undo
6035 * the effect of previous calls to gtk_widget_modify_font().
6037 * Sets the font to use for a widget. All other style values are left
6038 * untouched. See also gtk_widget_modify_style().
6041 gtk_widget_modify_font (GtkWidget *widget,
6042 PangoFontDescription *font_desc)
6044 GtkRcStyle *rc_style;
6046 g_return_if_fail (GTK_IS_WIDGET (widget));
6048 rc_style = gtk_widget_get_modifier_style (widget);
6050 if (rc_style->font_desc)
6051 pango_font_description_free (rc_style->font_desc);
6054 rc_style->font_desc = pango_font_description_copy (font_desc);
6056 rc_style->font_desc = NULL;
6058 gtk_widget_modify_style (widget, rc_style);
6062 gtk_widget_real_direction_changed (GtkWidget *widget,
6063 GtkTextDirection previous_direction)
6065 gtk_widget_queue_resize (widget);
6069 gtk_widget_real_style_set (GtkWidget *widget,
6070 GtkStyle *previous_style)
6072 if (GTK_WIDGET_REALIZED (widget) &&
6073 !GTK_WIDGET_NO_WINDOW (widget))
6074 gtk_style_set_background (widget->style, widget->window, widget->state);
6078 gtk_widget_set_style_internal (GtkWidget *widget,
6080 gboolean initial_emission)
6082 g_object_ref (widget);
6083 g_object_freeze_notify (G_OBJECT (widget));
6085 if (widget->style != style)
6087 GtkStyle *previous_style;
6089 if (GTK_WIDGET_REALIZED (widget))
6091 gtk_widget_reset_shapes (widget);
6092 gtk_style_detach (widget->style);
6095 previous_style = widget->style;
6096 widget->style = style;
6097 g_object_ref (widget->style);
6099 if (GTK_WIDGET_REALIZED (widget))
6100 widget->style = gtk_style_attach (widget->style, widget->window);
6102 gtk_widget_update_pango_context (widget);
6103 g_signal_emit (widget,
6104 widget_signals[STYLE_SET],
6106 initial_emission ? NULL : previous_style);
6107 g_object_unref (previous_style);
6109 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6110 gtk_widget_queue_resize (widget);
6112 else if (initial_emission)
6114 gtk_widget_update_pango_context (widget);
6115 g_signal_emit (widget,
6116 widget_signals[STYLE_SET],
6120 g_object_notify (G_OBJECT (widget), "style");
6121 g_object_thaw_notify (G_OBJECT (widget));
6122 g_object_unref (widget);
6126 GtkWidget *previous_toplevel;
6127 GdkScreen *previous_screen;
6128 GdkScreen *new_screen;
6129 } HierarchyChangedInfo;
6132 do_screen_change (GtkWidget *widget,
6133 GdkScreen *old_screen,
6134 GdkScreen *new_screen)
6136 if (old_screen != new_screen)
6140 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6142 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6145 _gtk_tooltip_hide (widget);
6146 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6151 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6152 gpointer client_data)
6154 HierarchyChangedInfo *info = client_data;
6155 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6156 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6158 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6160 g_object_ref (widget);
6163 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6165 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6167 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6168 do_screen_change (widget, info->previous_screen, info->new_screen);
6170 if (GTK_IS_CONTAINER (widget))
6171 gtk_container_forall (GTK_CONTAINER (widget),
6172 gtk_widget_propagate_hierarchy_changed_recurse,
6175 g_object_unref (widget);
6180 * _gtk_widget_propagate_hierarchy_changed:
6181 * @widget: a #GtkWidget
6182 * @previous_toplevel: Previous toplevel
6184 * Propagates changes in the anchored state to a widget and all
6185 * children, unsetting or setting the %ANCHORED flag, and
6186 * emitting #GtkWidget::hierarchy-changed.
6189 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6190 GtkWidget *previous_toplevel)
6192 HierarchyChangedInfo info;
6194 info.previous_toplevel = previous_toplevel;
6195 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6197 if (GTK_WIDGET_TOPLEVEL (widget) ||
6198 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6199 info.new_screen = gtk_widget_get_screen (widget);
6201 info.new_screen = NULL;
6203 if (info.previous_screen)
6204 g_object_ref (info.previous_screen);
6205 if (previous_toplevel)
6206 g_object_ref (previous_toplevel);
6208 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6210 if (previous_toplevel)
6211 g_object_unref (previous_toplevel);
6212 if (info.previous_screen)
6213 g_object_unref (info.previous_screen);
6217 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6218 gpointer client_data)
6220 HierarchyChangedInfo *info = client_data;
6222 g_object_ref (widget);
6224 do_screen_change (widget, info->previous_screen, info->new_screen);
6226 if (GTK_IS_CONTAINER (widget))
6227 gtk_container_forall (GTK_CONTAINER (widget),
6228 gtk_widget_propagate_screen_changed_recurse,
6231 g_object_unref (widget);
6235 * gtk_widget_is_composited:
6236 * @widget: a #GtkWidget
6238 * Whether @widget can rely on having its alpha channel
6239 * drawn correctly. On X11 this function returns whether a
6240 * compositing manager is running for @widget's screen.
6242 * Please note that the semantics of this call will change
6243 * in the future if used on a widget that has a composited
6244 * window in its hierarchy (as set by gdk_window_set_composited()).
6246 * Return value: %TRUE if the widget can rely on its alpha
6247 * channel being drawn correctly.
6252 gtk_widget_is_composited (GtkWidget *widget)
6256 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6258 screen = gtk_widget_get_screen (widget);
6260 return gdk_screen_is_composited (screen);
6264 propagate_composited_changed (GtkWidget *widget,
6267 if (GTK_IS_CONTAINER (widget))
6269 gtk_container_forall (GTK_CONTAINER (widget),
6270 propagate_composited_changed,
6274 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6278 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6280 propagate_composited_changed (widget, NULL);
6284 * _gtk_widget_propagate_screen_changed:
6285 * @widget: a #GtkWidget
6286 * @previous_screen: Previous screen
6288 * Propagates changes in the screen for a widget to all
6289 * children, emitting #GtkWidget::screen-changed.
6292 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6293 GdkScreen *previous_screen)
6295 HierarchyChangedInfo info;
6297 info.previous_screen = previous_screen;
6298 info.new_screen = gtk_widget_get_screen (widget);
6300 if (previous_screen)
6301 g_object_ref (previous_screen);
6303 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6305 if (previous_screen)
6306 g_object_unref (previous_screen);
6310 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6312 if (GTK_WIDGET_RC_STYLE (widget))
6313 gtk_widget_reset_rc_style (widget);
6315 if (GTK_IS_CONTAINER (widget))
6316 gtk_container_forall (GTK_CONTAINER (widget),
6317 reset_rc_styles_recurse,
6322 gtk_widget_reset_rc_styles (GtkWidget *widget)
6324 g_return_if_fail (GTK_IS_WIDGET (widget));
6326 reset_rc_styles_recurse (widget, NULL);
6330 * gtk_widget_get_default_style:
6332 * Returns the default style used by all widgets initially.
6334 * Returns: the default style. This #GtkStyle object is owned
6335 * by GTK+ and should not be modified or freed.
6338 gtk_widget_get_default_style (void)
6340 if (!gtk_default_style)
6342 gtk_default_style = gtk_style_new ();
6343 g_object_ref (gtk_default_style);
6346 return gtk_default_style;
6349 static PangoContext *
6350 gtk_widget_peek_pango_context (GtkWidget *widget)
6352 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6356 * gtk_widget_get_pango_context:
6357 * @widget: a #GtkWidget
6359 * Gets a #PangoContext with the appropriate font map, font description,
6360 * and base direction for this widget. Unlike the context returned
6361 * by gtk_widget_create_pango_context(), this context is owned by
6362 * the widget (it can be used until the screen for the widget changes
6363 * or the widget is removed from its toplevel), and will be updated to
6364 * match any changes to the widget's attributes.
6366 * If you create and keep a #PangoLayout using this context, you must
6367 * deal with changes to the context by calling pango_layout_context_changed()
6368 * on the layout in response to the #GtkWidget::style-set and
6369 * #GtkWidget::direction-changed signals for the widget.
6371 * Return value: the #PangoContext for the widget.
6374 gtk_widget_get_pango_context (GtkWidget *widget)
6376 PangoContext *context;
6378 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6380 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6383 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6384 g_object_set_qdata_full (G_OBJECT (widget),
6385 quark_pango_context,
6394 update_pango_context (GtkWidget *widget,
6395 PangoContext *context)
6397 pango_context_set_font_description (context, widget->style->font_desc);
6398 pango_context_set_base_dir (context,
6399 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6400 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6404 gtk_widget_update_pango_context (GtkWidget *widget)
6406 PangoContext *context = gtk_widget_peek_pango_context (widget);
6412 update_pango_context (widget, context);
6414 screen = gtk_widget_get_screen_unchecked (widget);
6417 pango_cairo_context_set_resolution (context,
6418 gdk_screen_get_resolution (screen));
6419 pango_cairo_context_set_font_options (context,
6420 gdk_screen_get_font_options (screen));
6426 * gtk_widget_create_pango_context:
6427 * @widget: a #GtkWidget
6429 * Creates a new #PangoContext with the appropriate font map,
6430 * font description, and base direction for drawing text for
6431 * this widget. See also gtk_widget_get_pango_context().
6433 * Return value: the new #PangoContext
6436 gtk_widget_create_pango_context (GtkWidget *widget)
6439 PangoContext *context;
6441 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6443 screen = gtk_widget_get_screen_unchecked (widget);
6446 GTK_NOTE (MULTIHEAD,
6447 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6449 screen = gdk_screen_get_default ();
6452 context = gdk_pango_context_get_for_screen (screen);
6454 update_pango_context (widget, context);
6455 pango_context_set_language (context, gtk_get_default_language ());
6461 * gtk_widget_create_pango_layout:
6462 * @widget: a #GtkWidget
6463 * @text: text to set on the layout (can be %NULL)
6465 * Creates a new #PangoLayout with the appropriate font map,
6466 * font description, and base direction for drawing text for
6469 * If you keep a #PangoLayout created in this way around, in order to
6470 * notify the layout of changes to the base direction or font of this
6471 * widget, you must call pango_layout_context_changed() in response to
6472 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6475 * Return value: the new #PangoLayout
6478 gtk_widget_create_pango_layout (GtkWidget *widget,
6481 PangoLayout *layout;
6482 PangoContext *context;
6484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6486 context = gtk_widget_get_pango_context (widget);
6487 layout = pango_layout_new (context);
6490 pango_layout_set_text (layout, text, -1);
6496 * gtk_widget_render_icon:
6497 * @widget: a #GtkWidget
6498 * @stock_id: a stock ID
6499 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6500 * the size of the source and don't scale (if there are multiple
6501 * source sizes, GTK+ picks one of the available sizes).
6502 * @detail: render detail to pass to theme engine
6504 * A convenience function that uses the theme engine and RC file
6505 * settings for @widget to look up @stock_id and render it to
6506 * a pixbuf. @stock_id should be a stock icon ID such as
6507 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6508 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6509 * identifies the widget or code doing the rendering, so that
6510 * theme engines can special-case rendering for that widget or code.
6512 * The pixels in the returned #GdkPixbuf are shared with the rest of
6513 * the application and should not be modified. The pixbuf should be freed
6514 * after use with g_object_unref().
6516 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6519 gtk_widget_render_icon (GtkWidget *widget,
6520 const gchar *stock_id,
6522 const gchar *detail)
6524 GtkIconSet *icon_set;
6527 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6528 g_return_val_if_fail (stock_id != NULL, NULL);
6529 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6531 gtk_widget_ensure_style (widget);
6533 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6535 if (icon_set == NULL)
6538 retval = gtk_icon_set_render_icon (icon_set,
6540 gtk_widget_get_direction (widget),
6541 GTK_WIDGET_STATE (widget),
6550 * gtk_widget_set_parent_window:
6551 * @widget: a #GtkWidget.
6552 * @parent_window: the new parent window.
6554 * Sets a non default parent window for @widget.
6557 gtk_widget_set_parent_window (GtkWidget *widget,
6558 GdkWindow *parent_window)
6560 GdkWindow *old_parent_window;
6562 g_return_if_fail (GTK_IS_WIDGET (widget));
6564 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6565 quark_parent_window);
6567 if (parent_window != old_parent_window)
6569 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6571 if (old_parent_window)
6572 g_object_unref (old_parent_window);
6574 g_object_ref (parent_window);
6579 * gtk_widget_get_parent_window:
6580 * @widget: a #GtkWidget.
6581 * @returns: the parent window of @widget.
6583 * Gets @widget's parent window.
6586 gtk_widget_get_parent_window (GtkWidget *widget)
6588 GdkWindow *parent_window;
6590 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6592 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6594 return (parent_window != NULL) ? parent_window :
6595 (widget->parent != NULL) ? widget->parent->window : NULL;
6600 * gtk_widget_set_child_visible:
6601 * @widget: a #GtkWidget
6602 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6604 * Sets whether @widget should be mapped along with its when its parent
6605 * is mapped and @widget has been shown with gtk_widget_show().
6607 * The child visibility can be set for widget before it is added to
6608 * a container with gtk_widget_set_parent(), to avoid mapping
6609 * children unnecessary before immediately unmapping them. However
6610 * it will be reset to its default state of %TRUE when the widget
6611 * is removed from a container.
6613 * Note that changing the child visibility of a widget does not
6614 * queue a resize on the widget. Most of the time, the size of
6615 * a widget is computed from all visible children, whether or
6616 * not they are mapped. If this is not the case, the container
6617 * can queue a resize itself.
6619 * This function is only useful for container implementations and
6620 * never should be called by an application.
6623 gtk_widget_set_child_visible (GtkWidget *widget,
6624 gboolean is_visible)
6626 g_return_if_fail (GTK_IS_WIDGET (widget));
6627 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6629 g_object_ref (widget);
6632 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6635 GtkWidget *toplevel;
6637 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6639 toplevel = gtk_widget_get_toplevel (widget);
6640 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6641 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6644 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6646 if (GTK_WIDGET_MAPPED (widget->parent) &&
6647 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6648 GTK_WIDGET_VISIBLE (widget))
6649 gtk_widget_map (widget);
6651 gtk_widget_unmap (widget);
6654 g_object_unref (widget);
6658 * gtk_widget_get_child_visible:
6659 * @widget: a #GtkWidget
6661 * Gets the value set with gtk_widget_set_child_visible().
6662 * If you feel a need to use this function, your code probably
6663 * needs reorganization.
6665 * This function is only useful for container implementations and
6666 * never should be called by an application.
6668 * Return value: %TRUE if the widget is mapped with the parent.
6671 gtk_widget_get_child_visible (GtkWidget *widget)
6673 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6675 return GTK_WIDGET_CHILD_VISIBLE (widget);
6679 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6681 GtkWidget *toplevel;
6683 toplevel = gtk_widget_get_toplevel (widget);
6685 if (GTK_WIDGET_TOPLEVEL (toplevel))
6687 if (GTK_IS_WINDOW (toplevel))
6688 return GTK_WINDOW (toplevel)->screen;
6689 else if (GTK_IS_INVISIBLE (toplevel))
6690 return GTK_INVISIBLE (widget)->screen;
6697 * gtk_widget_get_screen:
6698 * @widget: a #GtkWidget
6700 * Get the #GdkScreen from the toplevel window associated with
6701 * this widget. This function can only be called after the widget
6702 * has been added to a widget hierarchy with a #GtkWindow
6705 * In general, you should only create screen specific
6706 * resources when a widget has been realized, and you should
6707 * free those resources when the widget is unrealized.
6709 * Return value: the #GdkScreen for the toplevel for this widget.
6714 gtk_widget_get_screen (GtkWidget *widget)
6718 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6720 screen = gtk_widget_get_screen_unchecked (widget);
6727 g_warning (G_STRLOC ": Can't get associated screen"
6728 " for a widget unless it is inside a toplevel GtkWindow\n"
6729 " widget type is %s associated top level type is %s",
6730 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6731 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6733 return gdk_screen_get_default ();
6738 * gtk_widget_has_screen:
6739 * @widget: a #GtkWidget
6741 * Checks whether there is a #GdkScreen is associated with
6742 * this widget. All toplevel widgets have an associated
6743 * screen, and all widgets added into a hierarchy with a toplevel
6744 * window at the top.
6746 * Return value: %TRUE if there is a #GdkScreen associcated
6752 gtk_widget_has_screen (GtkWidget *widget)
6754 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6756 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6760 * gtk_widget_get_display:
6761 * @widget: a #GtkWidget
6763 * Get the #GdkDisplay for the toplevel window associated with
6764 * this widget. This function can only be called after the widget
6765 * has been added to a widget hierarchy with a #GtkWindow at the top.
6767 * In general, you should only create display specific
6768 * resources when a widget has been realized, and you should
6769 * free those resources when the widget is unrealized.
6771 * Return value: the #GdkDisplay for the toplevel for this widget.
6776 gtk_widget_get_display (GtkWidget *widget)
6778 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6780 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6784 * gtk_widget_get_root_window:
6785 * @widget: a #GtkWidget
6787 * Get the root window where this widget is located. This function can
6788 * only be called after the widget has been added to a widget
6789 * hierarchy with #GtkWindow at the top.
6791 * The root window is useful for such purposes as creating a popup
6792 * #GdkWindow associated with the window. In general, you should only
6793 * create display specific resources when a widget has been realized,
6794 * and you should free those resources when the widget is unrealized.
6796 * Return value: the #GdkWindow root window for the toplevel for this widget.
6801 gtk_widget_get_root_window (GtkWidget *widget)
6803 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6805 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6809 * gtk_widget_child_focus:
6810 * @widget: a #GtkWidget
6811 * @direction: direction of focus movement
6813 * This function is used by custom widget implementations; if you're
6814 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6815 * to a particular widget, and gtk_container_set_focus_chain() to
6816 * change the focus tab order. So you may want to investigate those
6817 * functions instead.
6819 * gtk_widget_child_focus() is called by containers as the user moves
6820 * around the window using keyboard shortcuts. @direction indicates
6821 * what kind of motion is taking place (up, down, left, right, tab
6822 * forward, tab backward). gtk_widget_child_focus() emits the
6823 * #GtkWidget::focus" signal; widgets override the default handler
6824 * for this signal in order to implement appropriate focus behavior.
6826 * The default ::focus handler for a widget should return %TRUE if
6827 * moving in @direction left the focus on a focusable location inside
6828 * that widget, and %FALSE if moving in @direction moved the focus
6829 * outside the widget. If returning %TRUE, widgets normally
6830 * call gtk_widget_grab_focus() to place the focus accordingly;
6831 * if returning %FALSE, they don't modify the current focus location.
6833 * This function replaces gtk_container_focus() from GTK+ 1.2.
6834 * It was necessary to check that the child was visible, sensitive,
6835 * and focusable before calling gtk_container_focus().
6836 * gtk_widget_child_focus() returns %FALSE if the widget is not
6837 * currently in a focusable state, so there's no need for those checks.
6839 * Return value: %TRUE if focus ended up inside @widget
6842 gtk_widget_child_focus (GtkWidget *widget,
6843 GtkDirectionType direction)
6845 gboolean return_val;
6847 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6849 if (!GTK_WIDGET_VISIBLE (widget) ||
6850 !GTK_WIDGET_IS_SENSITIVE (widget))
6853 /* child widgets must set CAN_FOCUS, containers
6854 * don't have to though.
6856 if (!GTK_IS_CONTAINER (widget) &&
6857 !GTK_WIDGET_CAN_FOCUS (widget))
6860 g_signal_emit (widget,
6861 widget_signals[FOCUS],
6863 direction, &return_val);
6869 * gtk_widget_keynav_failed:
6870 * @widget: a #GtkWidget
6871 * @direction: direction of focus movement
6873 * This function should be called whenever keyboard navigation within
6874 * a single widget hits a boundary. The function emits the
6875 * #GtkWidget::keynav-failed signal on the widget and its return
6876 * value should be interpreted in a way similar to the return value of
6877 * gtk_widget_child_focus():
6879 * When %TRUE is returned, stay in the widget, the failed keyboard
6880 * navigation is Ok and/or there is nowhere we can/should move the
6883 * When %FALSE is returned, the caller should continue with keyboard
6884 * navigation outside the widget, e.g. by calling
6885 * gtk_widget_child_focus() on the widget's toplevel.
6887 * The default ::keynav-failed handler returns %TRUE for
6888 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6889 * values of #GtkDirectionType, it looks at the
6890 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6891 * if the setting is %TRUE. This way the entire user interface
6892 * becomes cursor-navigatable on input devices such as mobile phones
6893 * which only have cursor keys but no tab key.
6895 * Whenever the default handler returns %TRUE, it also calls
6896 * gtk_widget_error_bell() to notify the user of the failed keyboard
6899 * A use case for providing an own implementation of ::keynav-failed
6900 * (either by connecting to it or by overriding it) would be a row of
6901 * #GtkEntry widgets where the user should be able to navigate the
6902 * entire row with the cursor keys, as e.g. known from user interfaces
6903 * that require entering license keys.
6905 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6906 * if the emitting widget should try to handle the keyboard
6907 * navigation attempt in its parent container(s).
6912 gtk_widget_keynav_failed (GtkWidget *widget,
6913 GtkDirectionType direction)
6915 gboolean return_val;
6917 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6919 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6920 direction, &return_val);
6926 * gtk_widget_error_bell:
6927 * @widget: a #GtkWidget
6929 * Notifies the user about an input-related error on this widget.
6930 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6931 * gdk_window_beep(), otherwise it does nothing.
6933 * Note that the effect of gdk_window_beep() can be configured in many
6934 * ways, depending on the windowing backend and the desktop environment
6935 * or window manager that is used.
6940 gtk_widget_error_bell (GtkWidget *widget)
6942 GtkSettings* settings;
6945 g_return_if_fail (GTK_IS_WIDGET (widget));
6947 settings = gtk_widget_get_settings (widget);
6951 g_object_get (settings,
6952 "gtk-error-bell", &beep,
6955 if (beep && widget->window)
6956 gdk_window_beep (widget->window);
6960 * gtk_widget_set_uposition:
6961 * @widget: a #GtkWidget
6962 * @x: x position; -1 to unset x; -2 to leave x unchanged
6963 * @y: y position; -1 to unset y; -2 to leave y unchanged
6966 * Sets the position of a widget. The funny "u" in the name comes from
6967 * the "user position" hint specified by the X Window System, and
6968 * exists for legacy reasons. This function doesn't work if a widget
6969 * is inside a container; it's only really useful on #GtkWindow.
6971 * Don't use this function to center dialogs over the main application
6972 * window; most window managers will do the centering on your behalf
6973 * if you call gtk_window_set_transient_for(), and it's really not
6974 * possible to get the centering to work correctly in all cases from
6975 * application code. But if you insist, use gtk_window_set_position()
6976 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6979 * Note that although @x and @y can be individually unset, the position
6980 * is not honoured unless both @x and @y are set.
6983 gtk_widget_set_uposition (GtkWidget *widget,
6987 /* FIXME this function is the only place that aux_info->x and
6988 * aux_info->y are even used I believe, and this function is
6989 * deprecated. Should be cleaned up.
6991 * (Actually, size_allocate uses them) -Yosh
6994 GtkWidgetAuxInfo *aux_info;
6996 g_return_if_fail (GTK_IS_WIDGET (widget));
6998 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
7003 aux_info->x_set = FALSE;
7006 aux_info->x_set = TRUE;
7014 aux_info->y_set = FALSE;
7017 aux_info->y_set = TRUE;
7022 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7023 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7025 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7026 gtk_widget_size_allocate (widget, &widget->allocation);
7030 gtk_widget_set_usize_internal (GtkWidget *widget,
7034 GtkWidgetAuxInfo *aux_info;
7035 gboolean changed = FALSE;
7037 g_object_freeze_notify (G_OBJECT (widget));
7039 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7041 if (width > -2 && aux_info->width != width)
7043 g_object_notify (G_OBJECT (widget), "width-request");
7044 aux_info->width = width;
7047 if (height > -2 && aux_info->height != height)
7049 g_object_notify (G_OBJECT (widget), "height-request");
7050 aux_info->height = height;
7054 if (GTK_WIDGET_VISIBLE (widget) && changed)
7055 gtk_widget_queue_resize (widget);
7057 g_object_thaw_notify (G_OBJECT (widget));
7061 * gtk_widget_set_usize:
7062 * @widget: a #GtkWidget
7063 * @width: minimum width, or -1 to unset
7064 * @height: minimum height, or -1 to unset
7066 * Sets the minimum size of a widget; that is, the widget's size
7067 * request will be @width by @height. You can use this function to
7068 * force a widget to be either larger or smaller than it is. The
7069 * strange "usize" name dates from the early days of GTK+, and derives
7070 * from X Window System terminology. In many cases,
7071 * gtk_window_set_default_size() is a better choice for toplevel
7072 * windows than this function; setting the default size will still
7073 * allow users to shrink the window. Setting the usize will force them
7074 * to leave the window at least as large as the usize. When dealing
7075 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7078 * Note the inherent danger of setting any fixed size - themes,
7079 * translations into other languages, different fonts, and user action
7080 * can all change the appropriate size for a given widget. So, it's
7081 * basically impossible to hardcode a size that will always be
7084 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7087 gtk_widget_set_usize (GtkWidget *widget,
7091 g_return_if_fail (GTK_IS_WIDGET (widget));
7093 gtk_widget_set_usize_internal (widget, width, height);
7097 * gtk_widget_set_size_request:
7098 * @widget: a #GtkWidget
7099 * @width: width @widget should request, or -1 to unset
7100 * @height: height @widget should request, or -1 to unset
7102 * Sets the minimum size of a widget; that is, the widget's size
7103 * request will be @width by @height. You can use this function to
7104 * force a widget to be either larger or smaller than it normally
7107 * In most cases, gtk_window_set_default_size() is a better choice for
7108 * toplevel windows than this function; setting the default size will
7109 * still allow users to shrink the window. Setting the size request
7110 * will force them to leave the window at least as large as the size
7111 * request. When dealing with window sizes,
7112 * gtk_window_set_geometry_hints() can be a useful function as well.
7114 * Note the inherent danger of setting any fixed size - themes,
7115 * translations into other languages, different fonts, and user action
7116 * can all change the appropriate size for a given widget. So, it's
7117 * basically impossible to hardcode a size that will always be
7120 * The size request of a widget is the smallest size a widget can
7121 * accept while still functioning well and drawing itself correctly.
7122 * However in some strange cases a widget may be allocated less than
7123 * its requested size, and in many cases a widget may be allocated more
7124 * space than it requested.
7126 * If the size request in a given direction is -1 (unset), then
7127 * the "natural" size request of the widget will be used instead.
7129 * Widgets can't actually be allocated a size less than 1 by 1, but
7130 * you can pass 0,0 to this function to mean "as small as possible."
7133 gtk_widget_set_size_request (GtkWidget *widget,
7137 g_return_if_fail (GTK_IS_WIDGET (widget));
7138 g_return_if_fail (width >= -1);
7139 g_return_if_fail (height >= -1);
7146 gtk_widget_set_usize_internal (widget, width, height);
7151 * gtk_widget_get_size_request:
7152 * @widget: a #GtkWidget
7153 * @width: return location for width, or %NULL
7154 * @height: return location for height, or %NULL
7156 * Gets the size request that was explicitly set for the widget using
7157 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7158 * @height indicates that that dimension has not been set explicitly
7159 * and the natural requisition of the widget will be used intead. See
7160 * gtk_widget_set_size_request(). To get the size a widget will
7161 * actually use, call gtk_widget_size_request() instead of
7165 gtk_widget_get_size_request (GtkWidget *widget,
7169 GtkWidgetAuxInfo *aux_info;
7171 g_return_if_fail (GTK_IS_WIDGET (widget));
7173 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7176 *width = aux_info ? aux_info->width : -1;
7179 *height = aux_info ? aux_info->height : -1;
7183 * gtk_widget_set_events:
7184 * @widget: a #GtkWidget
7185 * @events: event mask
7187 * Sets the event mask (see #GdkEventMask) for a widget. The event
7188 * mask determines which events a widget will receive. Keep in mind
7189 * that different widgets have different default event masks, and by
7190 * changing the event mask you may disrupt a widget's functionality,
7191 * so be careful. This function must be called while a widget is
7192 * unrealized. Consider gtk_widget_add_events() for widgets that are
7193 * already realized, or if you want to preserve the existing event
7194 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7195 * to get events on those widgets, place them inside a #GtkEventBox
7196 * and receive events on the event box.
7199 gtk_widget_set_events (GtkWidget *widget,
7202 g_return_if_fail (GTK_IS_WIDGET (widget));
7203 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7205 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7206 GINT_TO_POINTER (events));
7207 g_object_notify (G_OBJECT (widget), "events");
7211 gtk_widget_add_events_internal (GtkWidget *widget,
7217 for (l = window_list; l != NULL; l = l->next)
7219 GdkWindow *window = l->data;
7222 gdk_window_get_user_data (window, &user_data);
7223 if (user_data == widget)
7227 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7229 children = gdk_window_get_children (window);
7230 gtk_widget_add_events_internal (widget, events, children);
7231 g_list_free (children);
7237 * gtk_widget_add_events:
7238 * @widget: a #GtkWidget
7239 * @events: an event mask, see #GdkEventMask
7241 * Adds the events in the bitfield @events to the event mask for
7242 * @widget. See gtk_widget_set_events() for details.
7245 gtk_widget_add_events (GtkWidget *widget,
7250 g_return_if_fail (GTK_IS_WIDGET (widget));
7252 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7253 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7254 GINT_TO_POINTER (old_events | events));
7256 if (GTK_WIDGET_REALIZED (widget))
7260 if (GTK_WIDGET_NO_WINDOW (widget))
7261 window_list = gdk_window_get_children (widget->window);
7263 window_list = g_list_prepend (NULL, widget->window);
7265 gtk_widget_add_events_internal (widget, events, window_list);
7267 g_list_free (window_list);
7270 g_object_notify (G_OBJECT (widget), "events");
7274 * gtk_widget_set_extension_events:
7275 * @widget: a #GtkWidget
7276 * @mode: bitfield of extension events to receive
7278 * Sets the extension events mask to @mode. See #GdkExtensionMode
7279 * and gdk_input_set_extension_events().
7282 gtk_widget_set_extension_events (GtkWidget *widget,
7283 GdkExtensionMode mode)
7285 g_return_if_fail (GTK_IS_WIDGET (widget));
7287 if (GTK_WIDGET_REALIZED (widget))
7288 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7290 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7291 GINT_TO_POINTER (mode));
7292 g_object_notify (G_OBJECT (widget), "extension-events");
7296 * gtk_widget_get_toplevel:
7297 * @widget: a #GtkWidget
7299 * This function returns the topmost widget in the container hierarchy
7300 * @widget is a part of. If @widget has no parent widgets, it will be
7301 * returned as the topmost widget. No reference will be added to the
7302 * returned widget; it should not be unreferenced.
7304 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7305 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7307 * %NULL if @widget wasn't inside a toplevel window, and if the
7308 * window was inside a #GtkWindow-derived widget which was in turn
7309 * inside the toplevel #GtkWindow. While the second case may
7310 * seem unlikely, it actually happens when a #GtkPlug is embedded
7311 * inside a #GtkSocket within the same application.
7313 * To reliably find the toplevel #GtkWindow, use
7314 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7315 * is set on the result.
7317 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7318 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7320 * /* Perform action on toplevel. */
7324 * Return value: the topmost ancestor of @widget, or @widget itself
7325 * if there's no ancestor.
7328 gtk_widget_get_toplevel (GtkWidget *widget)
7330 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7332 while (widget->parent)
7333 widget = widget->parent;
7339 * gtk_widget_get_ancestor:
7340 * @widget: a #GtkWidget
7341 * @widget_type: ancestor type
7343 * Gets the first ancestor of @widget with type @widget_type. For example,
7344 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7345 * the first #GtkBox that's an ancestor of @widget. No reference will be
7346 * added to the returned widget; it should not be unreferenced. See note
7347 * about checking for a toplevel #GtkWindow in the docs for
7348 * gtk_widget_get_toplevel().
7350 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7351 * considers @widget to be an ancestor of itself.
7353 * Return value: the ancestor widget, or %NULL if not found
7356 gtk_widget_get_ancestor (GtkWidget *widget,
7359 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7361 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7362 widget = widget->parent;
7364 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7371 * gtk_widget_get_colormap:
7372 * @widget: a #GtkWidget
7374 * Gets the colormap that will be used to render @widget. No reference will
7375 * be added to the returned colormap; it should not be unreferenced.
7377 * Return value: the colormap used by @widget
7380 gtk_widget_get_colormap (GtkWidget *widget)
7382 GdkColormap *colormap;
7383 GtkWidget *tmp_widget;
7385 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7389 colormap = gdk_drawable_get_colormap (widget->window);
7390 /* If window was destroyed previously, we'll get NULL here */
7395 tmp_widget = widget;
7398 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7402 tmp_widget= tmp_widget->parent;
7405 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7409 * gtk_widget_get_visual:
7410 * @widget: a #GtkWidget
7412 * Gets the visual that will be used to render @widget.
7414 * Return value: the visual for @widget
7417 gtk_widget_get_visual (GtkWidget *widget)
7419 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7421 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7425 * gtk_widget_get_settings:
7426 * @widget: a #GtkWidget
7428 * Gets the settings object holding the settings (global property
7429 * settings, RC file information, etc) used for this widget.
7431 * Note that this function can only be called when the #GtkWidget
7432 * is attached to a toplevel, since the settings object is specific
7433 * to a particular #GdkScreen.
7435 * Return value: the relevant #GtkSettings object
7438 gtk_widget_get_settings (GtkWidget *widget)
7440 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7442 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7446 * gtk_widget_set_colormap:
7447 * @widget: a #GtkWidget
7448 * @colormap: a colormap
7450 * Sets the colormap for the widget to the given value. Widget must not
7451 * have been previously realized. This probably should only be used
7452 * from an <function>init()</function> function (i.e. from the constructor
7456 gtk_widget_set_colormap (GtkWidget *widget,
7457 GdkColormap *colormap)
7459 g_return_if_fail (GTK_IS_WIDGET (widget));
7460 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7461 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7463 g_object_ref (colormap);
7465 g_object_set_qdata_full (G_OBJECT (widget),
7472 * gtk_widget_get_events:
7473 * @widget: a #GtkWidget
7475 * Returns the event mask for the widget (a bitfield containing flags
7476 * from the #GdkEventMask enumeration). These are the events that the widget
7479 * Return value: event mask for @widget
7482 gtk_widget_get_events (GtkWidget *widget)
7484 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7486 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7490 * gtk_widget_get_extension_events:
7491 * @widget: a #GtkWidget
7493 * Retrieves the extension events the widget will receive; see
7494 * gdk_input_set_extension_events().
7496 * Return value: extension events for @widget
7499 gtk_widget_get_extension_events (GtkWidget *widget)
7501 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7503 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7507 * gtk_widget_get_pointer:
7508 * @widget: a #GtkWidget
7509 * @x: return location for the X coordinate, or %NULL
7510 * @y: return location for the Y coordinate, or %NULL
7512 * Obtains the location of the mouse pointer in widget coordinates.
7513 * Widget coordinates are a bit odd; for historical reasons, they are
7514 * defined as @widget->window coordinates for widgets that are not
7515 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7516 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7519 gtk_widget_get_pointer (GtkWidget *widget,
7523 g_return_if_fail (GTK_IS_WIDGET (widget));
7530 if (GTK_WIDGET_REALIZED (widget))
7532 gdk_window_get_pointer (widget->window, x, y, NULL);
7534 if (GTK_WIDGET_NO_WINDOW (widget))
7537 *x -= widget->allocation.x;
7539 *y -= widget->allocation.y;
7545 * gtk_widget_is_ancestor:
7546 * @widget: a #GtkWidget
7547 * @ancestor: another #GtkWidget
7549 * Determines whether @widget is somewhere inside @ancestor, possibly with
7550 * intermediate containers.
7552 * Return value: %TRUE if @ancestor contains @widget as a child,
7553 * grandchild, great grandchild, etc.
7556 gtk_widget_is_ancestor (GtkWidget *widget,
7557 GtkWidget *ancestor)
7559 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7560 g_return_val_if_fail (ancestor != NULL, FALSE);
7564 if (widget->parent == ancestor)
7566 widget = widget->parent;
7572 static GQuark quark_composite_name = 0;
7575 * gtk_widget_set_composite_name:
7576 * @widget: a #GtkWidget.
7577 * @name: the name to set
7579 * Sets a widgets composite name. The widget must be
7580 * a composite child of its parent; see gtk_widget_push_composite_child().
7583 gtk_widget_set_composite_name (GtkWidget *widget,
7586 g_return_if_fail (GTK_IS_WIDGET (widget));
7587 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7588 g_return_if_fail (name != NULL);
7590 if (!quark_composite_name)
7591 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7593 g_object_set_qdata_full (G_OBJECT (widget),
7594 quark_composite_name,
7600 * gtk_widget_get_composite_name:
7601 * @widget: a #GtkWidget
7603 * Obtains the composite name of a widget.
7605 * Returns: the composite name of @widget, or %NULL if @widget is not
7606 * a composite child. The string should be freed when it is no
7610 gtk_widget_get_composite_name (GtkWidget *widget)
7612 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7614 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7615 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7622 * gtk_widget_push_composite_child:
7624 * Makes all newly-created widgets as composite children until
7625 * the corresponding gtk_widget_pop_composite_child() call.
7627 * A composite child is a child that's an implementation detail of the
7628 * container it's inside and should not be visible to people using the
7629 * container. Composite children aren't treated differently by GTK (but
7630 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7631 * builders might want to treat them in a different way.
7633 * Here is a simple example:
7635 * gtk_widget_push_composite_child ();
7636 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7637 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7638 * gtk_widget_pop_composite_child ();
7639 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7640 * GTK_WIDGET (scrolled_window));
7641 * g_object_ref (scrolled_window->hscrollbar);
7645 gtk_widget_push_composite_child (void)
7647 composite_child_stack++;
7651 * gtk_widget_pop_composite_child:
7653 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7656 gtk_widget_pop_composite_child (void)
7658 if (composite_child_stack)
7659 composite_child_stack--;
7663 * gtk_widget_push_colormap:
7664 * @cmap: a #GdkColormap
7666 * Pushes @cmap onto a global stack of colormaps; the topmost
7667 * colormap on the stack will be used to create all widgets.
7668 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7669 * reason to use this function.
7672 gtk_widget_push_colormap (GdkColormap *cmap)
7674 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7676 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7680 * gtk_widget_pop_colormap:
7682 * Removes a colormap pushed with gtk_widget_push_colormap().
7685 gtk_widget_pop_colormap (void)
7688 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7692 * gtk_widget_set_default_colormap:
7693 * @colormap: a #GdkColormap
7695 * Sets the default colormap to use when creating widgets.
7696 * gtk_widget_push_colormap() is a better function to use if
7697 * you only want to affect a few widgets, rather than all widgets.
7700 gtk_widget_set_default_colormap (GdkColormap *colormap)
7702 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7704 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7709 * gtk_widget_get_default_colormap:
7711 * Obtains the default colormap used to create widgets.
7713 * Return value: default widget colormap
7716 gtk_widget_get_default_colormap (void)
7718 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7722 * gtk_widget_get_default_visual:
7724 * Obtains the visual of the default colormap. Not really useful;
7725 * used to be useful before gdk_colormap_get_visual() existed.
7727 * Return value: visual of the default colormap
7730 gtk_widget_get_default_visual (void)
7732 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7736 gtk_widget_emit_direction_changed (GtkWidget *widget,
7737 GtkTextDirection old_dir)
7739 gtk_widget_update_pango_context (widget);
7741 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7745 * gtk_widget_set_direction:
7746 * @widget: a #GtkWidget
7747 * @dir: the new direction
7749 * Sets the reading direction on a particular widget. This direction
7750 * controls the primary direction for widgets containing text,
7751 * and also the direction in which the children of a container are
7752 * packed. The ability to set the direction is present in order
7753 * so that correct localization into languages with right-to-left
7754 * reading directions can be done. Generally, applications will
7755 * let the default reading direction present, except for containers
7756 * where the containers are arranged in an order that is explicitely
7757 * visual rather than logical (such as buttons for text justification).
7759 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7760 * set by gtk_widget_set_default_direction() will be used.
7763 gtk_widget_set_direction (GtkWidget *widget,
7764 GtkTextDirection dir)
7766 GtkTextDirection old_dir;
7768 g_return_if_fail (GTK_IS_WIDGET (widget));
7769 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7771 old_dir = gtk_widget_get_direction (widget);
7773 if (dir == GTK_TEXT_DIR_NONE)
7774 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7777 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7778 if (dir == GTK_TEXT_DIR_LTR)
7779 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7781 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7784 if (old_dir != gtk_widget_get_direction (widget))
7785 gtk_widget_emit_direction_changed (widget, old_dir);
7789 * gtk_widget_get_direction:
7790 * @widget: a #GtkWidget
7792 * Gets the reading direction for a particular widget. See
7793 * gtk_widget_set_direction().
7795 * Return value: the reading direction for the widget.
7798 gtk_widget_get_direction (GtkWidget *widget)
7800 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7802 if (GTK_WIDGET_DIRECTION_SET (widget))
7803 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7805 return gtk_default_direction;
7809 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7811 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7813 g_object_ref (widget);
7815 if (!GTK_WIDGET_DIRECTION_SET (widget))
7816 gtk_widget_emit_direction_changed (widget, old_dir);
7818 if (GTK_IS_CONTAINER (widget))
7819 gtk_container_forall (GTK_CONTAINER (widget),
7820 gtk_widget_set_default_direction_recurse,
7823 g_object_unref (widget);
7827 * gtk_widget_set_default_direction:
7828 * @dir: the new default direction. This cannot be
7829 * %GTK_TEXT_DIR_NONE.
7831 * Sets the default reading direction for widgets where the
7832 * direction has not been explicitly set by gtk_widget_set_direction().
7835 gtk_widget_set_default_direction (GtkTextDirection dir)
7837 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7839 if (dir != gtk_default_direction)
7841 GList *toplevels, *tmp_list;
7842 GtkTextDirection old_dir = gtk_default_direction;
7844 gtk_default_direction = dir;
7846 tmp_list = toplevels = gtk_window_list_toplevels ();
7847 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7851 gtk_widget_set_default_direction_recurse (tmp_list->data,
7852 GUINT_TO_POINTER (old_dir));
7853 g_object_unref (tmp_list->data);
7854 tmp_list = tmp_list->next;
7857 g_list_free (toplevels);
7862 * gtk_widget_get_default_direction:
7864 * Obtains the current default reading direction. See
7865 * gtk_widget_set_default_direction().
7867 * Return value: the current default direction.
7870 gtk_widget_get_default_direction (void)
7872 return gtk_default_direction;
7876 gtk_widget_dispose (GObject *object)
7878 GtkWidget *widget = GTK_WIDGET (object);
7881 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7882 else if (GTK_WIDGET_VISIBLE (widget))
7883 gtk_widget_hide (widget);
7885 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7886 if (GTK_WIDGET_REALIZED (widget))
7887 gtk_widget_unrealize (widget);
7889 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7893 gtk_widget_real_destroy (GtkObject *object)
7895 /* gtk_object_destroy() will already hold a refcount on object */
7896 GtkWidget *widget = GTK_WIDGET (object);
7898 /* wipe accelerator closures (keep order) */
7899 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7900 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7902 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7903 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7905 gtk_grab_remove (widget);
7907 g_object_unref (widget->style);
7908 widget->style = gtk_widget_get_default_style ();
7909 g_object_ref (widget->style);
7911 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7915 gtk_widget_finalize (GObject *object)
7917 GtkWidget *widget = GTK_WIDGET (object);
7918 GtkWidgetAuxInfo *aux_info;
7919 GtkAccessible *accessible;
7921 gtk_grab_remove (widget);
7923 g_object_unref (widget->style);
7924 widget->style = NULL;
7926 g_free (widget->name);
7928 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7930 gtk_widget_aux_info_destroy (aux_info);
7932 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7934 g_object_unref (accessible);
7936 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7939 /*****************************************
7940 * gtk_widget_real_map:
7945 *****************************************/
7948 gtk_widget_real_map (GtkWidget *widget)
7950 g_assert (GTK_WIDGET_REALIZED (widget));
7952 if (!GTK_WIDGET_MAPPED (widget))
7954 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7956 if (!GTK_WIDGET_NO_WINDOW (widget))
7957 gdk_window_show (widget->window);
7961 /*****************************************
7962 * gtk_widget_real_unmap:
7967 *****************************************/
7970 gtk_widget_real_unmap (GtkWidget *widget)
7972 if (GTK_WIDGET_MAPPED (widget))
7974 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7976 if (!GTK_WIDGET_NO_WINDOW (widget))
7977 gdk_window_hide (widget->window);
7981 /*****************************************
7982 * gtk_widget_real_realize:
7987 *****************************************/
7990 gtk_widget_real_realize (GtkWidget *widget)
7992 g_assert (GTK_WIDGET_NO_WINDOW (widget));
7994 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7997 widget->window = gtk_widget_get_parent_window (widget);
7998 g_object_ref (widget->window);
8000 widget->style = gtk_style_attach (widget->style, widget->window);
8003 /*****************************************
8004 * gtk_widget_real_unrealize:
8009 *****************************************/
8012 gtk_widget_real_unrealize (GtkWidget *widget)
8014 if (GTK_WIDGET_MAPPED (widget))
8015 gtk_widget_real_unmap (widget);
8017 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8019 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8022 /* We must do unrealize child widget BEFORE container widget.
8023 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8024 * So, unrealizing container widget bofore its children causes the problem
8025 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8028 if (GTK_IS_CONTAINER (widget))
8029 gtk_container_forall (GTK_CONTAINER (widget),
8030 (GtkCallback) gtk_widget_unrealize,
8033 gtk_style_detach (widget->style);
8034 if (!GTK_WIDGET_NO_WINDOW (widget))
8036 gdk_window_set_user_data (widget->window, NULL);
8037 gdk_window_destroy (widget->window);
8038 widget->window = NULL;
8042 g_object_unref (widget->window);
8043 widget->window = NULL;
8046 gtk_selection_remove_all (widget);
8048 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8052 gtk_widget_real_size_request (GtkWidget *widget,
8053 GtkRequisition *requisition)
8055 requisition->width = widget->requisition.width;
8056 requisition->height = widget->requisition.height;
8060 * _gtk_widget_peek_colormap:
8062 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8064 * Return value: the currently pushed colormap, or %NULL if there is none.
8067 _gtk_widget_peek_colormap (void)
8070 return (GdkColormap*) colormap_stack->data;
8075 * _gtk_widget_set_pointer_window:
8076 * @widget: a #GtkWidget.
8077 * @pointer_window: the new pointer window.
8079 * Sets pointer window for @widget. Does not ref @pointer_window.
8080 * Actually stores it on the #GdkScreen, but you don't need to know that.
8083 _gtk_widget_set_pointer_window (GtkWidget *widget,
8084 GdkWindow *pointer_window)
8086 g_return_if_fail (GTK_IS_WIDGET (widget));
8088 if (GTK_WIDGET_REALIZED (widget))
8090 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8092 g_object_set_qdata (G_OBJECT (screen), quark_pointer_window,
8098 * _gtk_widget_get_pointer_window:
8099 * @widget: a #GtkWidget.
8101 * Return value: the pointer window set on the #GdkScreen @widget is attached
8105 _gtk_widget_get_pointer_window (GtkWidget *widget)
8107 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8109 if (GTK_WIDGET_REALIZED (widget))
8111 GdkScreen *screen = gdk_drawable_get_screen (widget->window);
8113 return g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
8120 synth_crossing (GtkWidget *widget,
8123 GdkCrossingMode mode,
8124 GdkNotifyType detail)
8128 event = gdk_event_new (type);
8130 event->crossing.window = g_object_ref (window);
8131 event->crossing.send_event = TRUE;
8132 event->crossing.subwindow = g_object_ref (window);
8133 event->crossing.time = GDK_CURRENT_TIME;
8134 event->crossing.x = event->crossing.y = 0;
8135 event->crossing.x_root = event->crossing.y_root = 0;
8136 event->crossing.mode = mode;
8137 event->crossing.detail = detail;
8138 event->crossing.focus = FALSE;
8139 event->crossing.state = 0;
8142 widget = gtk_get_event_widget (event);
8145 gtk_widget_event_internal (widget, event);
8147 gdk_event_free (event);
8151 * _gtk_widget_is_pointer_widget:
8152 * @widget: a #GtkWidget
8154 * Returns %TRUE if the pointer window belongs to @widget.
8158 _gtk_widget_is_pointer_widget (GtkWidget *widget)
8160 if (GTK_WIDGET_HAS_POINTER (widget))
8165 win = _gtk_widget_get_pointer_window (widget);
8168 gdk_window_get_user_data (win, &wid);
8178 * _gtk_widget_synthesize_crossing:
8179 * @from: the #GtkWidget the virtual pointer is leaving.
8180 * @to: the #GtkWidget the virtual pointer is moving to.
8181 * @mode: the #GdkCrossingMode to place on the synthesized events.
8183 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
8185 * The real pointer window is the window that most recently received an enter notify
8186 * event. Windows that don't select for crossing events can't become the real
8187 * poiner window. The real pointer widget that owns the real pointer window. The
8188 * effective pointer window is the same as the real pointer window unless the real
8189 * pointer widget is either insensitive or there is a grab on a widget that is not
8190 * an ancestor of the real pointer widget (in which case the effective pointer
8191 * window should be the root window).
8193 * When the effective pointer window is the same as the real poiner window, we
8194 * receive crossing events from the windowing system. When the effective pointer
8195 * window changes to become different from the real pointer window we synthesize
8196 * crossing events, attempting to follow X protocol rules:
8198 * When the root window becomes the effective pointer window:
8199 * - leave notify on real pointer window, detail Ancestor
8200 * - leave notify on all of its ancestors, detail Virtual
8201 * - enter notify on root window, detail Inferior
8203 * When the root window ceases to be the effective pointer window:
8204 * - leave notify on root window, detail Inferior
8205 * - enter notify on all ancestors of real pointer window, detail Virtual
8206 * - enter notify on real pointer window, detail Ancestor
8209 _gtk_widget_synthesize_crossing (GtkWidget *from,
8211 GdkCrossingMode mode)
8213 GdkWindow *from_window = NULL, *to_window = NULL;
8215 g_return_if_fail (from != NULL || to != NULL);
8218 from_window = GTK_WIDGET_HAS_POINTER (from)
8219 ? _gtk_widget_get_pointer_window (from) : from->window;
8221 to_window = GTK_WIDGET_HAS_POINTER (to)
8222 ? _gtk_widget_get_pointer_window (to) : to->window;
8224 if (from_window == NULL && to_window == NULL)
8226 else if (from_window != NULL && to_window == NULL)
8228 GList *from_ancestors = NULL, *list;
8229 GdkWindow *from_ancestor = from_window;
8231 while (from_ancestor != NULL)
8233 if (from_ancestor != NULL)
8235 from_ancestor = gdk_window_get_parent (from_ancestor);
8236 if (from_ancestor == NULL)
8238 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8242 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8243 mode, GDK_NOTIFY_ANCESTOR);
8244 for (list = g_list_last (from_ancestors); list; list = list->prev)
8246 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8247 mode, GDK_NOTIFY_VIRTUAL);
8250 /* XXX: enter/inferior on root window? */
8252 g_list_free (from_ancestors);
8254 else if (from_window == NULL && to_window != NULL)
8256 GList *to_ancestors = NULL, *list;
8257 GdkWindow *to_ancestor = to_window;
8259 while (to_ancestor != NULL)
8261 if (to_ancestor != NULL)
8263 to_ancestor = gdk_window_get_parent (to_ancestor);
8264 if (to_ancestor == NULL)
8266 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8270 /* XXX: leave/inferior on root window? */
8272 for (list = to_ancestors; list; list = list->next)
8274 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8275 mode, GDK_NOTIFY_VIRTUAL);
8277 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8278 mode, GDK_NOTIFY_ANCESTOR);
8280 g_list_free (to_ancestors);
8282 else if (from_window == to_window)
8286 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
8287 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
8289 while (from_ancestor != NULL || to_ancestor != NULL)
8291 if (from_ancestor != NULL)
8293 from_ancestor = gdk_window_get_parent (from_ancestor);
8294 if (from_ancestor == to_window)
8296 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
8298 if (to_ancestor != NULL)
8300 to_ancestor = gdk_window_get_parent (to_ancestor);
8301 if (to_ancestor == from_window)
8303 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
8306 if (to_ancestor == from_window)
8308 if (mode != GDK_CROSSING_GTK_UNGRAB)
8309 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8310 mode, GDK_NOTIFY_INFERIOR);
8311 for (list = to_ancestors; list; list = list->next)
8312 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8313 mode, GDK_NOTIFY_VIRTUAL);
8314 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8315 mode, GDK_NOTIFY_ANCESTOR);
8317 else if (from_ancestor == to_window)
8319 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8320 mode, GDK_NOTIFY_ANCESTOR);
8321 for (list = g_list_last (from_ancestors); list; list = list->prev)
8323 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8324 mode, GDK_NOTIFY_VIRTUAL);
8326 if (mode != GDK_CROSSING_GTK_GRAB)
8327 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8328 mode, GDK_NOTIFY_INFERIOR);
8332 while (from_ancestors != NULL && to_ancestors != NULL
8333 && from_ancestors->data == to_ancestors->data)
8335 from_ancestors = g_list_delete_link (from_ancestors,
8337 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
8340 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
8341 mode, GDK_NOTIFY_NONLINEAR);
8343 for (list = g_list_last (from_ancestors); list; list = list->prev)
8345 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
8346 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8348 for (list = to_ancestors; list; list = list->next)
8350 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
8351 mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
8353 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
8354 mode, GDK_NOTIFY_NONLINEAR);
8356 g_list_free (from_ancestors);
8357 g_list_free (to_ancestors);
8362 gtk_widget_propagate_state (GtkWidget *widget,
8365 guint8 old_state = GTK_WIDGET_STATE (widget);
8366 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8368 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8369 * parent_sensitive==TRUE on a sensitive widget
8373 if (data->parent_sensitive)
8374 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8376 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8378 if (GTK_WIDGET_IS_SENSITIVE (widget))
8380 if (data->state_restoration)
8381 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8383 GTK_WIDGET_STATE (widget) = data->state;
8387 if (!data->state_restoration)
8389 if (data->state != GTK_STATE_INSENSITIVE)
8390 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8392 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8393 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8394 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8397 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8401 window = gtk_widget_get_toplevel (widget);
8402 if (window && GTK_WIDGET_TOPLEVEL (window))
8403 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8406 if (old_state != GTK_WIDGET_STATE (widget) ||
8407 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8409 g_object_ref (widget);
8411 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8412 gtk_grab_remove (widget);
8414 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8416 if (GTK_WIDGET_HAS_POINTER (widget) && !GTK_WIDGET_SHADOWED (widget))
8418 if (!GTK_WIDGET_IS_SENSITIVE (widget))
8419 _gtk_widget_synthesize_crossing (widget, NULL,
8420 GDK_CROSSING_STATE_CHANGED);
8421 else if (old_state == GTK_STATE_INSENSITIVE)
8422 _gtk_widget_synthesize_crossing (NULL, widget,
8423 GDK_CROSSING_STATE_CHANGED);
8426 if (GTK_IS_CONTAINER (widget))
8428 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8429 if (data->use_forall)
8430 gtk_container_forall (GTK_CONTAINER (widget),
8431 (GtkCallback) gtk_widget_propagate_state,
8434 gtk_container_foreach (GTK_CONTAINER (widget),
8435 (GtkCallback) gtk_widget_propagate_state,
8438 g_object_unref (widget);
8443 * _gtk_widget_get_aux_info:
8444 * @widget: a #GtkWidget
8445 * @create: if %TRUE, create the structure if it doesn't exist
8447 * Get the #GtkWidgetAuxInfo structure for the widget.
8449 * Return value: the #GtkAuxInfo structure for the widget, or
8450 * %NULL if @create is %FALSE and one doesn't already exist.
8453 _gtk_widget_get_aux_info (GtkWidget *widget,
8456 GtkWidgetAuxInfo *aux_info;
8458 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8459 if (!aux_info && create)
8461 aux_info = g_slice_new (GtkWidgetAuxInfo);
8463 aux_info->width = -1;
8464 aux_info->height = -1;
8467 aux_info->x_set = FALSE;
8468 aux_info->y_set = FALSE;
8469 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8475 /*****************************************
8476 * gtk_widget_aux_info_destroy:
8481 *****************************************/
8484 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8486 g_slice_free (GtkWidgetAuxInfo, aux_info);
8490 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8492 g_object_unref (info->shape_mask);
8493 g_slice_free (GtkWidgetShapeInfo, info);
8497 * gtk_widget_shape_combine_mask:
8498 * @widget: a #GtkWidget
8499 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8500 * @offset_x: X position of shape mask with respect to @window
8501 * @offset_y: Y position of shape mask with respect to @window
8503 * Sets a shape for this widget's GDK window. This allows for
8504 * transparent windows etc., see gdk_window_shape_combine_mask()
8505 * for more information.
8508 gtk_widget_shape_combine_mask (GtkWidget *widget,
8509 GdkBitmap *shape_mask,
8513 GtkWidgetShapeInfo* shape_info;
8515 g_return_if_fail (GTK_IS_WIDGET (widget));
8516 /* set_shape doesn't work on widgets without gdk window */
8517 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8521 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8524 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8526 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8530 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8532 shape_info = g_slice_new (GtkWidgetShapeInfo);
8533 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8534 (GDestroyNotify) gtk_widget_shape_info_destroy);
8536 shape_info->shape_mask = g_object_ref (shape_mask);
8537 shape_info->offset_x = offset_x;
8538 shape_info->offset_y = offset_y;
8540 /* set shape if widget has a gdk window already.
8541 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8544 gdk_window_shape_combine_mask (widget->window, shape_mask,
8545 offset_x, offset_y);
8550 * gtk_widget_input_shape_combine_mask:
8551 * @widget: a #GtkWidget
8552 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8553 * @offset_x: X position of shape mask with respect to @window
8554 * @offset_y: Y position of shape mask with respect to @window
8556 * Sets an input shape for this widget's GDK window. This allows for
8557 * windows which react to mouse click in a nonrectangular region, see
8558 * gdk_window_input_shape_combine_mask() for more information.
8563 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8564 GdkBitmap *shape_mask,
8568 GtkWidgetShapeInfo* shape_info;
8570 g_return_if_fail (GTK_IS_WIDGET (widget));
8571 /* set_shape doesn't work on widgets without gdk window */
8572 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8577 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8579 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8583 shape_info = g_slice_new (GtkWidgetShapeInfo);
8584 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8586 (GDestroyNotify) gtk_widget_shape_info_destroy);
8588 shape_info->shape_mask = g_object_ref (shape_mask);
8589 shape_info->offset_x = offset_x;
8590 shape_info->offset_y = offset_y;
8592 /* set shape if widget has a gdk window already.
8593 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8596 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8597 offset_x, offset_y);
8603 gtk_reset_shapes_recurse (GtkWidget *widget,
8609 gdk_window_get_user_data (window, &data);
8613 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8614 for (list = gdk_window_peek_children (window); list; list = list->next)
8615 gtk_reset_shapes_recurse (widget, list->data);
8619 * gtk_widget_reset_shapes:
8620 * @widget: a #GtkWidget
8622 * Recursively resets the shape on this widget and its descendants.
8625 gtk_widget_reset_shapes (GtkWidget *widget)
8627 g_return_if_fail (GTK_IS_WIDGET (widget));
8628 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8630 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8631 gtk_reset_shapes_recurse (widget, widget->window);
8636 * @widget: a #GtkWidget
8638 * Adds a reference to a widget. This function is exactly the same
8639 * as calling g_object_ref(), and exists mostly for historical
8640 * reasons. It can still be convenient to avoid casting a widget
8641 * to a #GObject, it saves a small amount of typing.
8643 * Return value: the widget that was referenced
8645 * Deprecated: 2.12: Use g_object_ref() instead.
8648 gtk_widget_ref (GtkWidget *widget)
8650 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8652 return (GtkWidget*) g_object_ref ((GObject*) widget);
8657 * @widget: a #GtkWidget
8659 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8661 * Deprecated: 2.12: Use g_object_unref() instead.
8664 gtk_widget_unref (GtkWidget *widget)
8666 g_return_if_fail (GTK_IS_WIDGET (widget));
8668 g_object_unref ((GObject*) widget);
8672 * gtk_widget_get_snapshot:
8673 * @widget: a #GtkWidget
8674 * @clip_rect: a #GdkRectangle or %NULL
8676 * Create a #GdkPixmap of the contents of the widget and its children.
8678 * Works even if the widget is obscured. The depth and visual of the
8679 * resulting pixmap is dependent on the widget being snapshot and likely
8680 * differs from those of a target widget displaying the pixmap.
8681 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8682 * the pixmap to a visual independant representation.
8684 * The snapshot area used by this function is the @widget's allocation plus
8685 * any extra space occupied by additional windows belonging to this widget
8686 * (such as the arrows of a spin button).
8687 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8689 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8690 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8691 * interpreted widget relative. If width or height of @clip_rect are 0 or
8692 * negative, the width or height of the resulting pixmap will be shrunken
8693 * by the respective amount.
8694 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8695 * chop off 5 pixels at each side of the snapshot pixmap.
8696 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8697 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8698 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8699 * as a pure output parameter.
8701 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8703 * Return value: #GdkPixmap snapshot of the widget
8708 gtk_widget_get_snapshot (GtkWidget *widget,
8709 GdkRectangle *clip_rect)
8711 int x, y, width, height;
8712 GdkWindow *parent_window = NULL;
8714 GList *windows = NULL, *list;
8716 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8717 if (!GTK_WIDGET_VISIBLE (widget))
8720 /* the widget (and parent_window) must be realized to be drawable */
8721 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8722 gtk_widget_realize (widget->parent);
8723 if (!GTK_WIDGET_REALIZED (widget))
8724 gtk_widget_realize (widget);
8726 /* determine snapshot rectangle */
8727 x = widget->allocation.x;
8728 y = widget->allocation.y;
8729 width = widget->allocation.width;
8730 height = widget->allocation.height;
8732 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8734 /* grow snapshot rectangle to cover all widget windows */
8735 parent_window = gtk_widget_get_parent_window (widget);
8736 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8738 GdkWindow *subwin = list->data;
8741 gdk_window_get_user_data (subwin, &windata);
8742 if (windata != widget)
8744 windows = g_list_prepend (windows, subwin);
8745 gdk_window_get_position (subwin, &wx, &wy);
8746 gdk_drawable_get_size (subwin, &ww, &wh);
8747 /* grow snapshot rectangle by extra widget sub window */
8758 if (x + width < wx + ww)
8759 width += wx + ww - (x + width);
8760 if (y + height < wy + wh)
8761 height += wy + wh - (y + height);
8764 else if (!widget->parent)
8765 x = y = 0; /* toplevel */
8767 /* at this point, (x,y,width,height) is the parent_window relative
8768 * snapshot area covering all of widget's windows.
8771 /* shrink snapshot size by clip_rectangle */
8774 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8775 clip.x = clip.x < 0 ? x : clip.x;
8776 clip.y = clip.y < 0 ? y : clip.y;
8777 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8778 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8781 /* offset clip_rect, so it's parent_window relative */
8782 if (clip_rect->x >= 0)
8783 clip.x += widget->allocation.x;
8784 if (clip_rect->y >= 0)
8785 clip.y += widget->allocation.y;
8787 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8789 g_list_free (windows);
8790 clip_rect->width = clip_rect->height = 0;
8791 return NULL; /* empty snapshot area */
8796 height = snap.height;
8799 /* render snapshot */
8800 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8801 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8803 GdkWindow *subwin = list->data;
8805 gdk_window_get_position (subwin, &wx, &wy);
8806 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8807 MAX (0, wx - x), MAX (0, wy - y), width, height);
8808 gdk_window_invalidate_rect (subwin, NULL, TRUE);
8810 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8812 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8813 gdk_window_invalidate_rect (widget->window, NULL, TRUE);
8815 gtk_widget_queue_draw (widget);
8817 gdk_window_process_updates (parent_window, TRUE);
8818 for (list = windows; list; list = list->next)
8819 gdk_window_process_updates (list->data, TRUE);
8820 gdk_window_process_updates (widget->window, TRUE);
8821 for (list = windows; list; list = list->next)
8822 gdk_window_remove_redirection (list->data);
8823 if (!windows) /* NO_WINDOW || toplevel */
8824 gdk_window_remove_redirection (widget->window);
8825 g_list_free (windows);
8827 /* return pixmap and snapshot rectangle coordinates */
8832 clip_rect->width = width;
8833 clip_rect->height = height;
8836 /* offset clip_rect from parent_window so it's widget relative */
8837 clip_rect->x -= widget->allocation.x;
8838 clip_rect->y -= widget->allocation.y;
8841 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8842 G_OBJECT_TYPE_NAME (widget),
8843 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8852 * gtk_widget_class_install_style_property_parser:
8853 * @klass: a #GtkWidgetClass
8854 * @pspec: the #GParamSpec for the style property
8855 * @parser: the parser for the style property
8857 * Installs a style property on a widget class.
8860 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8862 GtkRcPropertyParser parser)
8864 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8865 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8866 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8867 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8869 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8871 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8872 G_OBJECT_CLASS_NAME (klass),
8877 g_param_spec_ref_sink (pspec);
8878 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8879 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8883 * gtk_widget_class_install_style_property:
8884 * @klass: a #GtkWidgetClass
8885 * @pspec: the #GParamSpec for the property
8887 * Installs a style property on a widget class. The parser for the
8888 * style property is determined by the value type of @pspec.
8891 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8894 GtkRcPropertyParser parser;
8896 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8897 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8899 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8901 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8905 * gtk_widget_class_find_style_property:
8906 * @klass: a #GtkWidgetClass
8907 * @property_name: the name of the style property to find
8908 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8909 * style property with that name.
8911 * Finds a style property of a widget class by name.
8916 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8917 const gchar *property_name)
8919 g_return_val_if_fail (property_name != NULL, NULL);
8921 return g_param_spec_pool_lookup (style_property_spec_pool,
8923 G_OBJECT_CLASS_TYPE (klass),
8928 * gtk_widget_class_list_style_properties:
8929 * @klass: a #GtkWidgetClass
8930 * @n_properties: location to return the number of style properties found
8931 * @returns: an newly allocated array of #GParamSpec*. The array must
8932 * be freed with g_free().
8934 * Returns all style properties of a widget class.
8939 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
8940 guint *n_properties)
8942 GParamSpec **pspecs;
8945 pspecs = g_param_spec_pool_list (style_property_spec_pool,
8946 G_OBJECT_CLASS_TYPE (klass),
8955 * gtk_widget_style_get_property:
8956 * @widget: a #GtkWidget
8957 * @property_name: the name of a style property
8958 * @value: location to return the property value
8960 * Gets the value of a style property of @widget.
8963 gtk_widget_style_get_property (GtkWidget *widget,
8964 const gchar *property_name,
8969 g_return_if_fail (GTK_IS_WIDGET (widget));
8970 g_return_if_fail (property_name != NULL);
8971 g_return_if_fail (G_IS_VALUE (value));
8973 g_object_ref (widget);
8974 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8976 G_OBJECT_TYPE (widget),
8979 g_warning ("%s: widget class `%s' has no property named `%s'",
8981 G_OBJECT_TYPE_NAME (widget),
8985 const GValue *peek_value;
8987 peek_value = _gtk_style_peek_property_value (widget->style,
8988 G_OBJECT_TYPE (widget),
8990 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8992 /* auto-conversion of the caller's value type
8994 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
8995 g_value_copy (peek_value, value);
8996 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
8997 g_value_transform (peek_value, value);
8999 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
9001 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
9002 G_VALUE_TYPE_NAME (value));
9004 g_object_unref (widget);
9008 * gtk_widget_style_get_valist:
9009 * @widget: a #GtkWidget
9010 * @first_property_name: the name of the first property to get
9011 * @var_args: a <type>va_list</type> of pairs of property names and
9012 * locations to return the property values, starting with the location
9013 * for @first_property_name.
9015 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
9019 gtk_widget_style_get_valist (GtkWidget *widget,
9020 const gchar *first_property_name,
9025 g_return_if_fail (GTK_IS_WIDGET (widget));
9027 g_object_ref (widget);
9029 name = first_property_name;
9032 const GValue *peek_value;
9036 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
9038 G_OBJECT_TYPE (widget),
9042 g_warning ("%s: widget class `%s' has no property named `%s'",
9044 G_OBJECT_TYPE_NAME (widget),
9048 /* style pspecs are always readable so we can spare that check here */
9050 peek_value = _gtk_style_peek_property_value (widget->style,
9051 G_OBJECT_TYPE (widget),
9053 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
9054 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
9057 g_warning ("%s: %s", G_STRLOC, error);
9062 name = va_arg (var_args, gchar*);
9065 g_object_unref (widget);
9069 * gtk_widget_style_get:
9070 * @widget: a #GtkWidget
9071 * @first_property_name: the name of the first property to get
9072 * @Varargs: pairs of property names and locations to
9073 * return the property values, starting with the location for
9074 * @first_property_name, terminated by %NULL.
9076 * Gets the values of a multiple style properties of @widget.
9079 gtk_widget_style_get (GtkWidget *widget,
9080 const gchar *first_property_name,
9085 g_return_if_fail (GTK_IS_WIDGET (widget));
9087 va_start (var_args, first_property_name);
9088 gtk_widget_style_get_valist (widget, first_property_name, var_args);
9094 * @widget: a #GtkWidget
9095 * @path_length: location to store length of the path, or %NULL
9096 * @path: location to store allocated path string, or %NULL
9097 * @path_reversed: location to store allocated reverse path string, or %NULL
9099 * Obtains the full path to @widget. The path is simply the name of a
9100 * widget and all its parents in the container hierarchy, separated by
9101 * periods. The name of a widget comes from
9102 * gtk_widget_get_name(). Paths are used to apply styles to a widget
9103 * in gtkrc configuration files. Widget names are the type of the
9104 * widget by default (e.g. "GtkButton") or can be set to an
9105 * application-specific value with gtk_widget_set_name(). By setting
9106 * the name of a widget, you allow users or theme authors to apply
9107 * styles to that specific widget in their gtkrc
9108 * file. @path_reversed_p fills in the path in reverse order,
9109 * i.e. starting with @widget's name instead of starting with the name
9110 * of @widget's outermost ancestor.
9113 gtk_widget_path (GtkWidget *widget,
9116 gchar **path_reversed)
9118 static gchar *rev_path = NULL;
9119 static guint tmp_path_len = 0;
9122 g_return_if_fail (GTK_IS_WIDGET (widget));
9127 const gchar *string;
9132 string = gtk_widget_get_name (widget);
9133 l = strlen (string);
9134 while (tmp_path_len <= len + l + 1)
9136 tmp_path_len += INIT_PATH_SIZE;
9137 rev_path = g_realloc (rev_path, tmp_path_len);
9145 widget = widget->parent;
9148 rev_path[len++] = '.';
9150 rev_path[len++] = 0;
9155 *path_length = len - 1;
9157 *path_reversed = g_strdup (rev_path);
9160 *path = g_strdup (rev_path);
9161 g_strreverse (*path);
9166 * gtk_widget_class_path:
9167 * @widget: a #GtkWidget
9168 * @path_length: location to store the length of the class path, or %NULL
9169 * @path: location to store the class path as an allocated string, or %NULL
9170 * @path_reversed: location to store the reverse class path as an allocated
9173 * Same as gtk_widget_path(), but always uses the name of a widget's type,
9174 * never uses a custom name set with gtk_widget_set_name().
9178 gtk_widget_class_path (GtkWidget *widget,
9181 gchar **path_reversed)
9183 static gchar *rev_path = NULL;
9184 static guint tmp_path_len = 0;
9187 g_return_if_fail (GTK_IS_WIDGET (widget));
9192 const gchar *string;
9197 string = g_type_name (GTK_WIDGET_TYPE (widget));
9198 l = strlen (string);
9199 while (tmp_path_len <= len + l + 1)
9201 tmp_path_len += INIT_PATH_SIZE;
9202 rev_path = g_realloc (rev_path, tmp_path_len);
9210 widget = widget->parent;
9213 rev_path[len++] = '.';
9215 rev_path[len++] = 0;
9220 *path_length = len - 1;
9222 *path_reversed = g_strdup (rev_path);
9225 *path = g_strdup (rev_path);
9226 g_strreverse (*path);
9231 * gtk_requisition_copy:
9232 * @requisition: a #GtkRequisition
9234 * Copies a #GtkRequisition.
9236 * Returns: a copy of @requisition
9239 gtk_requisition_copy (const GtkRequisition *requisition)
9241 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
9245 * gtk_requisition_free:
9246 * @requisition: a #GtkRequisition
9248 * Frees a #GtkRequisition.
9251 gtk_requisition_free (GtkRequisition *requisition)
9253 g_free (requisition);
9257 gtk_requisition_get_type (void)
9259 static GType our_type = 0;
9262 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
9263 (GBoxedCopyFunc) gtk_requisition_copy,
9264 (GBoxedFreeFunc) gtk_requisition_free);
9270 * gtk_widget_get_accessible:
9271 * @widget: a #GtkWidget
9273 * Returns the accessible object that describes the widget to an
9274 * assistive technology.
9276 * If no accessibility library is loaded (i.e. no ATK implementation library is
9277 * loaded via <envar>GTK_MODULES</envar> or via another application library,
9278 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
9279 * if no class-specific #AtkObject implementation is available for the widget
9280 * instance in question, it will inherit an #AtkObject implementation from the
9281 * first ancestor class for which such an implementation is defined.
9283 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
9284 * library contains more information about accessible objects and their uses.
9286 * Returns: the #AtkObject associated with @widget
9289 gtk_widget_get_accessible (GtkWidget *widget)
9291 GtkWidgetClass *klass;
9293 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9295 klass = GTK_WIDGET_GET_CLASS (widget);
9297 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
9299 return klass->get_accessible (widget);
9303 gtk_widget_real_get_accessible (GtkWidget *widget)
9305 AtkObject* accessible;
9307 accessible = g_object_get_qdata (G_OBJECT (widget),
9308 quark_accessible_object);
9311 AtkObjectFactory *factory;
9312 AtkRegistry *default_registry;
9314 default_registry = atk_get_default_registry ();
9315 factory = atk_registry_get_factory (default_registry,
9316 G_TYPE_FROM_INSTANCE (widget));
9318 atk_object_factory_create_accessible (factory,
9320 g_object_set_qdata (G_OBJECT (widget),
9321 quark_accessible_object,
9328 * Initialize a AtkImplementorIface instance's virtual pointers as
9329 * appropriate to this implementor's class (GtkWidget).
9332 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9334 iface->ref_accessible = gtk_widget_ref_accessible;
9338 gtk_widget_ref_accessible (AtkImplementor *implementor)
9340 AtkObject *accessible;
9342 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9344 g_object_ref (accessible);
9349 * GtkBuildable implementation
9351 static GQuark quark_builder_has_default = 0;
9352 static GQuark quark_builder_has_focus = 0;
9353 static GQuark quark_builder_atk_relations = 0;
9356 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9358 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9359 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9360 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9362 iface->set_name = gtk_widget_buildable_set_name;
9363 iface->get_name = gtk_widget_buildable_get_name;
9364 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9365 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9366 iface->parser_finished = gtk_widget_buildable_parser_finished;
9367 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9368 iface->custom_finished = gtk_widget_buildable_custom_finished;
9372 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9375 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9378 static const gchar *
9379 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9381 return gtk_widget_get_name (GTK_WIDGET (buildable));
9385 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9386 GtkBuilder *builder,
9387 const gchar *childname)
9389 if (strcmp (childname, "accessible") == 0)
9390 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9396 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9397 GtkBuilder *builder,
9399 const GValue *value)
9401 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9402 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9403 GINT_TO_POINTER (TRUE));
9404 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9405 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9406 GINT_TO_POINTER (TRUE));
9408 g_object_set_property (G_OBJECT (buildable), name, value);
9422 free_action (AtkActionData *data, gpointer user_data)
9424 g_free (data->action_name);
9425 g_free (data->description);
9426 g_slice_free (AtkActionData, data);
9430 free_relation (AtkRelationData *data, gpointer user_data)
9432 g_free (data->target);
9433 g_free (data->type);
9434 g_slice_free (AtkRelationData, data);
9438 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9439 GtkBuilder *builder)
9441 GSList *atk_relations;
9443 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9444 gtk_widget_grab_default (GTK_WIDGET (buildable));
9445 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9446 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9448 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9449 quark_builder_atk_relations);
9452 AtkObject *accessible;
9453 AtkRelationSet *relation_set;
9456 AtkRelationType relation_type;
9457 AtkObject *target_accessible;
9459 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9460 relation_set = atk_object_ref_relation_set (accessible);
9462 for (l = atk_relations; l; l = l->next)
9464 AtkRelationData *relation = (AtkRelationData*)l->data;
9466 target = gtk_builder_get_object (builder, relation->target);
9469 g_warning ("Target object %s in <relation> does not exist",
9473 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9474 g_assert (target_accessible != NULL);
9476 relation_type = atk_relation_type_for_name (relation->type);
9477 if (relation_type == ATK_RELATION_NULL)
9479 g_warning ("<relation> type %s not found",
9483 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9486 g_object_unref (relation_set);
9488 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9489 g_slist_free (atk_relations);
9490 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9499 } AccessibilitySubParserData;
9502 accessibility_start_element (GMarkupParseContext *context,
9503 const gchar *element_name,
9504 const gchar **names,
9505 const gchar **values,
9509 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9511 gint line_number, char_number;
9513 if (strcmp (element_name, "relation") == 0)
9515 gchar *target = NULL;
9517 AtkRelationData *relation;
9519 for (i = 0; names[i]; i++)
9521 if (strcmp (names[i], "target") == 0)
9522 target = g_strdup (values[i]);
9523 else if (strcmp (names[i], "type") == 0)
9524 type = g_strdup (values[i]);
9527 g_markup_parse_context_get_position (context,
9532 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9533 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9535 line_number, char_number, names[i], "relation");
9542 if (!target || !type)
9544 g_markup_parse_context_get_position (context,
9549 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9550 "%s:%d:%d <%s> requires attribute \"%s\"",
9552 line_number, char_number, "relation",
9553 type ? "target" : "type");
9559 relation = g_slice_new (AtkRelationData);
9560 relation->target = target;
9561 relation->type = type;
9563 data->relations = g_slist_prepend (data->relations, relation);
9565 else if (strcmp (element_name, "action") == 0)
9567 gchar *action_name = NULL;
9568 gchar *description = NULL;
9569 AtkActionData *action;
9571 for (i = 0; names[i]; i++)
9573 if (strcmp (names[i], "action_name") == 0)
9574 action_name = g_strdup (values[i]);
9575 else if (strcmp (names[i], "description") == 0)
9576 description = g_strdup (values[i]);
9579 g_markup_parse_context_get_position (context,
9584 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9585 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9587 line_number, char_number, names[i], "action");
9588 g_free (action_name);
9589 g_free (description);
9594 if (!action_name || !description)
9596 g_markup_parse_context_get_position (context,
9601 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9602 "%s:%d:%d <%s> requires attribute \"%s\"",
9604 line_number, char_number, "action",
9605 description ? "action_name" : "description");
9606 g_free (action_name);
9607 g_free (description);
9611 action = g_slice_new (AtkActionData);
9612 action->action_name = action_name;
9613 action->description = description;
9615 data->actions = g_slist_prepend (data->actions, action);
9617 else if (strcmp (element_name, "accessibility") == 0)
9620 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9623 static const GMarkupParser accessibility_parser =
9625 accessibility_start_element,
9633 } AccelGroupParserData;
9636 accel_group_start_element (GMarkupParseContext *context,
9637 const gchar *element_name,
9638 const gchar **names,
9639 const gchar **values,
9645 guint modifiers = 0;
9646 gchar *signal = NULL;
9647 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9649 for (i = 0; names[i]; i++)
9651 if (strcmp (names[i], "key") == 0)
9652 key = gdk_keyval_from_name (values[i]);
9653 else if (strcmp (names[i], "modifiers") == 0)
9655 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9661 else if (strcmp (names[i], "signal") == 0)
9662 signal = g_strdup (values[i]);
9665 if (key == 0 || signal == NULL)
9667 g_warning ("<accelerator> requires key and signal attributes");
9670 parser_data->key = key;
9671 parser_data->modifiers = modifiers;
9672 parser_data->signal = signal;
9675 static const GMarkupParser accel_group_parser =
9677 accel_group_start_element,
9681 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9682 GtkBuilder *builder,
9684 const gchar *tagname,
9685 GMarkupParser *parser,
9688 g_assert (buildable);
9690 if (strcmp (tagname, "accelerator") == 0)
9692 AccelGroupParserData *parser_data;
9694 parser_data = g_slice_new0 (AccelGroupParserData);
9695 parser_data->object = g_object_ref (buildable);
9696 *parser = accel_group_parser;
9697 *data = parser_data;
9700 if (strcmp (tagname, "accessibility") == 0)
9702 AccessibilitySubParserData *parser_data;
9704 parser_data = g_slice_new0 (AccessibilitySubParserData);
9705 *parser = accessibility_parser;
9706 *data = parser_data;
9713 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9714 GtkBuilder *builder,
9716 const gchar *tagname,
9719 AccelGroupParserData *accel_data;
9720 AccessibilitySubParserData *a11y_data;
9721 GtkWidget *toplevel;
9722 GSList *accel_groups;
9723 GtkAccelGroup *accel_group;
9725 if (strcmp (tagname, "accelerator") == 0)
9727 accel_data = (AccelGroupParserData*)user_data;
9728 g_assert (accel_data->object);
9730 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9731 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9732 if (g_slist_length (accel_groups) == 0)
9734 accel_group = gtk_accel_group_new ();
9735 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9739 g_assert (g_slist_length (accel_groups) == 1);
9740 accel_group = g_slist_nth_data (accel_groups, 0);
9742 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9746 accel_data->modifiers,
9748 g_object_unref (accel_data->object);
9749 g_free (accel_data->signal);
9750 g_slice_free (AccelGroupParserData, accel_data);
9752 else if (strcmp (tagname, "accessibility") == 0)
9754 a11y_data = (AccessibilitySubParserData*)user_data;
9756 if (a11y_data->actions)
9758 AtkObject *accessible;
9763 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9765 action = ATK_ACTION (accessible);
9766 n_actions = atk_action_get_n_actions (action);
9768 for (l = a11y_data->actions; l; l = l->next)
9770 AtkActionData *action_data = (AtkActionData*)l->data;
9772 for (i = 0; i < n_actions; i++)
9773 if (strcmp (atk_action_get_name (action, i),
9774 action_data->action_name) == 0)
9778 atk_action_set_description (action, i,
9779 action_data->description);
9782 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9783 g_slist_free (a11y_data->actions);
9786 if (a11y_data->relations)
9787 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9788 a11y_data->relations);
9790 g_slice_free (AccessibilitySubParserData, a11y_data);
9797 * gtk_widget_get_clipboard:
9798 * @widget: a #GtkWidget
9799 * @selection: a #GdkAtom which identifies the clipboard
9800 * to use. %GDK_SELECTION_CLIPBOARD gives the
9801 * default clipboard. Another common value
9802 * is %GDK_SELECTION_PRIMARY, which gives
9803 * the primary X selection.
9805 * Returns the clipboard object for the given selection to
9806 * be used with @widget. @widget must have a #GdkDisplay
9807 * associated with it, so must be attached to a toplevel
9810 * Return value: the appropriate clipboard object. If no
9811 * clipboard already exists, a new one will
9812 * be created. Once a clipboard object has
9813 * been created, it is persistent for all time.
9818 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9821 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9823 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9828 * gtk_widget_list_mnemonic_labels:
9829 * @widget: a #GtkWidget
9831 * Returns a newly allocated list of the widgets, normally labels, for
9832 * which this widget is a the target of a mnemonic (see for example,
9833 * gtk_label_set_mnemonic_widget()).
9835 * The widgets in the list are not individually referenced. If you
9836 * want to iterate through the list and perform actions involving
9837 * callbacks that might destroy the widgets, you
9838 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9839 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9840 * widgets afterwards.
9842 * Return value: the list of mnemonic labels; free this list
9843 * with g_list_free() when you are done with it.
9848 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9853 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9855 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9856 list = g_list_prepend (list, l->data);
9862 * gtk_widget_add_mnemonic_label:
9863 * @widget: a #GtkWidget
9864 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9866 * Adds a widget to the list of mnemonic labels for
9867 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9868 * list of mnemonic labels for the widget is cleared when the
9869 * widget is destroyed, so the caller must make sure to update
9870 * its internal state at this point as well, by using a connection
9871 * to the #GtkWidget::destroy signal or a weak notifier.
9876 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9879 GSList *old_list, *new_list;
9881 g_return_if_fail (GTK_IS_WIDGET (widget));
9882 g_return_if_fail (GTK_IS_WIDGET (label));
9884 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9885 new_list = g_slist_prepend (old_list, label);
9887 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9888 new_list, (GDestroyNotify) g_slist_free);
9892 * gtk_widget_remove_mnemonic_label:
9893 * @widget: a #GtkWidget
9894 * @label: a #GtkWidget that was previously set as a mnemnic label for
9895 * @widget with gtk_widget_add_mnemonic_label().
9897 * Removes a widget from the list of mnemonic labels for
9898 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
9899 * must have previously been added to the list with
9900 * gtk_widget_add_mnemonic_label().
9905 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
9908 GSList *old_list, *new_list;
9910 g_return_if_fail (GTK_IS_WIDGET (widget));
9911 g_return_if_fail (GTK_IS_WIDGET (label));
9913 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9914 new_list = g_slist_remove (old_list, label);
9917 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9918 new_list, (GDestroyNotify) g_slist_free);
9922 * gtk_widget_get_no_show_all:
9923 * @widget: a #GtkWidget
9925 * Returns the current value of the GtkWidget:no-show-all property,
9926 * which determines whether calls to gtk_widget_show_all() and
9927 * gtk_widget_hide_all() will affect this widget.
9929 * Return value: the current value of the "no-show-all" property.
9934 gtk_widget_get_no_show_all (GtkWidget *widget)
9936 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9938 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
9942 * gtk_widget_set_no_show_all:
9943 * @widget: a #GtkWidget
9944 * @no_show_all: the new value for the "no-show-all" property
9946 * Sets the #GtkWidget:no-show-all property, which determines whether
9947 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
9950 * This is mostly for use in constructing widget hierarchies with externally
9951 * controlled visibility, see #GtkUIManager.
9956 gtk_widget_set_no_show_all (GtkWidget *widget,
9957 gboolean no_show_all)
9959 g_return_if_fail (GTK_IS_WIDGET (widget));
9961 no_show_all = (no_show_all != FALSE);
9963 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
9967 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
9969 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
9971 g_object_notify (G_OBJECT (widget), "no-show-all");
9976 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
9977 gboolean has_tooltip,
9980 gboolean priv_has_tooltip;
9982 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
9983 quark_has_tooltip));
9985 if (priv_has_tooltip != has_tooltip || force)
9987 priv_has_tooltip = has_tooltip;
9989 if (priv_has_tooltip)
9991 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
9992 gdk_window_set_events (widget->window,
9993 gdk_window_get_events (widget->window) |
9994 GDK_LEAVE_NOTIFY_MASK |
9995 GDK_POINTER_MOTION_MASK |
9996 GDK_POINTER_MOTION_HINT_MASK);
9998 if (!GTK_WIDGET_NO_WINDOW (widget))
9999 gtk_widget_add_events (widget,
10000 GDK_LEAVE_NOTIFY_MASK |
10001 GDK_POINTER_MOTION_MASK |
10002 GDK_POINTER_MOTION_HINT_MASK);
10005 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
10006 GUINT_TO_POINTER (priv_has_tooltip));
10011 * gtk_widget_set_tooltip_window:
10012 * @widget: a #GtkWidget
10013 * @custom_window: a #GtkWindow, or %NULL
10015 * Replaces the default, usually yellow, window used for displaying
10016 * tooltips with @custom_window. GTK+ will take care of showing and
10017 * hiding @custom_window at the right moment, to behave likewise as
10018 * the default tooltip window. If @custom_window is %NULL, the default
10019 * tooltip window will be used.
10024 gtk_widget_set_tooltip_window (GtkWidget *widget,
10025 GtkWindow *custom_window)
10028 gchar *tooltip_markup;
10029 GtkWindow *tooltip_window;
10031 g_return_if_fail (GTK_IS_WIDGET (widget));
10033 g_return_if_fail (GTK_IS_WINDOW (custom_window));
10035 tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10036 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
10039 g_object_ref (custom_window);
10041 tooltip_window = custom_window;
10042 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
10043 tooltip_window, g_object_unref);
10045 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
10046 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
10049 gtk_widget_trigger_tooltip_query (widget);
10053 * gtk_widget_get_tooltip_window:
10054 * @widget: a #GtkWidget
10056 * Returns the #GtkWindow of the current tooltip. This can be the
10057 * GtkWindow created by default, or the custom tooltip window set
10058 * using gtk_widget_set_tooltip_window().
10060 * Return value: The #GtkWindow of the current tooltip.
10065 gtk_widget_get_tooltip_window (GtkWidget *widget)
10067 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10069 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
10073 * gtk_widget_trigger_tooltip_query:
10074 * @widget: a #GtkWidget
10076 * Triggers a tooltip query on the display where the toplevel of @widget
10077 * is located. See gtk_tooltip_trigger_tooltip_query() for more
10083 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
10085 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
10089 * gtk_widget_set_tooltip_text:
10090 * @widget: a #GtkWidget
10091 * @text: the contents of the tooltip for @widget
10093 * Sets @text as the contents of the tooltip. This function will take
10094 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
10095 * handler for the GtkWidget::query-tooltip signal.
10097 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
10102 gtk_widget_set_tooltip_text (GtkWidget *widget,
10105 g_return_if_fail (GTK_IS_WIDGET (widget));
10107 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
10111 * gtk_widget_get_tooltip_text:
10112 * @widget: a #GtkWidget
10114 * Gets the contents of the tooltip for @widget.
10116 * Return value: the tooltip text, or %NULL. You should free the
10117 * returned string with g_free() when done.
10122 gtk_widget_get_tooltip_text (GtkWidget *widget)
10124 gchar *text = NULL;
10126 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10128 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
10134 * gtk_widget_set_tooltip_markup:
10135 * @widget: a #GtkWidget
10136 * @markup: the contents of the tooltip for @widget, or %NULL
10138 * Sets @markup as the contents of the tooltip, which is marked up with
10139 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
10141 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
10142 * and of the default handler for the GtkWidget::query-tooltip signal.
10144 * See also the GtkWidget:tooltip-markup property and
10145 * gtk_tooltip_set_markup().
10150 gtk_widget_set_tooltip_markup (GtkWidget *widget,
10151 const gchar *markup)
10153 g_return_if_fail (GTK_IS_WIDGET (widget));
10155 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
10159 * gtk_widget_get_tooltip_markup:
10160 * @widget: a #GtkWidget
10162 * Gets the contents of the tooltip for @widget.
10164 * Return value: the tooltip text, or %NULL. You should free the
10165 * returned string with g_free() when done.
10170 gtk_widget_get_tooltip_markup (GtkWidget *widget)
10172 gchar *text = NULL;
10174 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10176 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
10182 * gtk_widget_set_has_tooltip:
10183 * @widget: a #GtkWidget
10184 * @has_tooltip: whether or not @widget has a tooltip.
10186 * Sets the has-tooltip property on @widget to @has_tooltip. See
10187 * GtkWidget:has-tooltip for more information.
10192 gtk_widget_set_has_tooltip (GtkWidget *widget,
10193 gboolean has_tooltip)
10195 g_return_if_fail (GTK_IS_WIDGET (widget));
10197 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
10201 * gtk_widget_get_has_tooltip:
10202 * @widget: a #GtkWidget
10204 * Returns the current value of the has-tooltip property. See
10205 * GtkWidget:has-tooltip for more information.
10207 * Return value: current value of has-tooltip on @widget.
10212 gtk_widget_get_has_tooltip (GtkWidget *widget)
10214 gboolean has_tooltip = FALSE;
10216 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10218 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
10220 return has_tooltip;
10224 * gtk_widget_get_window:
10225 * @widget: a #GtkWidget
10227 * Returns the widget's window if it is realized, %NULL otherwise
10229 * Return value: @widget's window.
10234 gtk_widget_get_window (GtkWidget *widget)
10236 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10238 return widget->window;
10241 #define __GTK_WIDGET_C__
10242 #include "gtkaliasdef.c"