1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltip.h"
53 #include "gtkinvisible.h"
54 #include "gtkbuildable.h"
55 #include "gtkbuilderprivate.h"
58 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
59 #define INIT_PATH_SIZE (512)
100 PROPERTY_NOTIFY_EVENT,
101 SELECTION_CLEAR_EVENT,
102 SELECTION_REQUEST_EVENT,
103 SELECTION_NOTIFY_EVENT,
118 VISIBILITY_NOTIFY_EVENT,
122 ACCEL_CLOSURES_CHANGED,
148 PROP_RECEIVES_DEFAULT,
149 PROP_COMPOSITE_CHILD,
152 PROP_EXTENSION_EVENTS,
160 typedef struct _GtkStateData GtkStateData;
165 guint state_restoration : 1;
166 guint parent_sensitive : 1;
167 guint use_forall : 1;
170 /* --- prototypes --- */
171 static void gtk_widget_class_init (GtkWidgetClass *klass);
172 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
173 static void gtk_widget_init (GtkWidget *widget);
174 static void gtk_widget_set_property (GObject *object,
178 static void gtk_widget_get_property (GObject *object,
182 static void gtk_widget_dispose (GObject *object);
183 static void gtk_widget_real_destroy (GtkObject *object);
184 static void gtk_widget_finalize (GObject *object);
185 static void gtk_widget_real_show (GtkWidget *widget);
186 static void gtk_widget_real_hide (GtkWidget *widget);
187 static void gtk_widget_real_map (GtkWidget *widget);
188 static void gtk_widget_real_unmap (GtkWidget *widget);
189 static void gtk_widget_real_realize (GtkWidget *widget);
190 static void gtk_widget_real_unrealize (GtkWidget *widget);
191 static void gtk_widget_real_size_request (GtkWidget *widget,
192 GtkRequisition *requisition);
193 static void gtk_widget_real_size_allocate (GtkWidget *widget,
194 GtkAllocation *allocation);
195 static void gtk_widget_style_set (GtkWidget *widget,
196 GtkStyle *previous_style);
197 static void gtk_widget_direction_changed (GtkWidget *widget,
198 GtkTextDirection previous_direction);
200 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
201 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
204 gboolean keyboard_tip,
205 GtkTooltip *tooltip);
206 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
207 GtkWidgetHelpType help_type);
209 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
211 GParamSpec **pspecs);
212 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
214 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
216 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
217 GdkEventFocus *event);
218 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
219 GdkEventFocus *event);
220 static gboolean gtk_widget_real_focus (GtkWidget *widget,
221 GtkDirectionType direction);
222 static void gtk_widget_real_move_focus (GtkWidget *widget,
223 GtkDirectionType direction);
224 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
225 GtkDirectionType direction);
226 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
227 static void gtk_widget_update_pango_context (GtkWidget *widget);
228 static void gtk_widget_propagate_state (GtkWidget *widget,
230 static void gtk_widget_reset_rc_style (GtkWidget *widget);
231 static void gtk_widget_set_style_internal (GtkWidget *widget,
233 gboolean initial_emission);
234 static gint gtk_widget_event_internal (GtkWidget *widget,
236 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
237 gboolean group_cycling);
238 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
239 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
240 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
241 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
242 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
244 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
245 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
246 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
249 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
250 gboolean has_tooltip,
252 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
253 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
255 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
256 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
258 const gchar *childname);
259 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
262 const GValue *value);
263 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
266 const gchar *tagname,
267 GMarkupParser *parser,
269 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
272 const gchar *tagname,
274 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
275 GtkBuilder *builder);
278 static void gtk_widget_set_usize_internal (GtkWidget *widget,
281 static void gtk_widget_get_draw_rectangle (GtkWidget *widget,
285 /* --- variables --- */
286 static gpointer gtk_widget_parent_class = NULL;
287 static guint widget_signals[LAST_SIGNAL] = { 0 };
288 static GtkStyle *gtk_default_style = NULL;
289 static GSList *colormap_stack = NULL;
290 static guint composite_child_stack = 0;
291 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
292 static GParamSpecPool *style_property_spec_pool = NULL;
294 static GQuark quark_property_parser = 0;
295 static GQuark quark_aux_info = 0;
296 static GQuark quark_accel_path = 0;
297 static GQuark quark_accel_closures = 0;
298 static GQuark quark_event_mask = 0;
299 static GQuark quark_extension_event_mode = 0;
300 static GQuark quark_parent_window = 0;
301 static GQuark quark_shape_info = 0;
302 static GQuark quark_input_shape_info = 0;
303 static GQuark quark_colormap = 0;
304 static GQuark quark_pango_context = 0;
305 static GQuark quark_rc_style = 0;
306 static GQuark quark_accessible_object = 0;
307 static GQuark quark_mnemonic_labels = 0;
308 static GQuark quark_tooltip_markup = 0;
309 static GQuark quark_has_tooltip = 0;
310 static GQuark quark_tooltip_window = 0;
311 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
312 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
314 /* --- functions --- */
316 gtk_widget_get_type (void)
318 static GType widget_type = 0;
320 if (G_UNLIKELY (widget_type == 0))
322 const GTypeInfo widget_info =
324 sizeof (GtkWidgetClass),
325 NULL, /* base_init */
326 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
327 (GClassInitFunc) gtk_widget_class_init,
328 NULL, /* class_finalize */
329 NULL, /* class_init */
332 (GInstanceInitFunc) gtk_widget_init,
333 NULL, /* value_table */
336 const GInterfaceInfo accessibility_info =
338 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
339 (GInterfaceFinalizeFunc) NULL,
340 NULL /* interface data */
343 const GInterfaceInfo buildable_info =
345 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
346 (GInterfaceFinalizeFunc) NULL,
347 NULL /* interface data */
350 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
351 &widget_info, G_TYPE_FLAG_ABSTRACT);
353 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
354 &accessibility_info) ;
355 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
364 child_property_notify_dispatcher (GObject *object,
368 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
372 gtk_widget_class_init (GtkWidgetClass *klass)
374 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
375 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
376 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
377 GtkBindingSet *binding_set;
379 gtk_widget_parent_class = g_type_class_peek_parent (klass);
381 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
382 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
383 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
384 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
385 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
386 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
387 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
388 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
389 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
390 quark_colormap = g_quark_from_static_string ("gtk-colormap");
391 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
392 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
393 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
394 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
395 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
396 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
397 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
399 style_property_spec_pool = g_param_spec_pool_new (FALSE);
400 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
401 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
402 cpn_context.dispatcher = child_property_notify_dispatcher;
403 _gtk_widget_child_property_notify_context = &cpn_context;
405 gobject_class->dispose = gtk_widget_dispose;
406 gobject_class->finalize = gtk_widget_finalize;
407 gobject_class->set_property = gtk_widget_set_property;
408 gobject_class->get_property = gtk_widget_get_property;
410 object_class->destroy = gtk_widget_real_destroy;
412 klass->activate_signal = 0;
413 klass->set_scroll_adjustments_signal = 0;
414 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
415 klass->show = gtk_widget_real_show;
416 klass->show_all = gtk_widget_show;
417 klass->hide = gtk_widget_real_hide;
418 klass->hide_all = gtk_widget_hide;
419 klass->map = gtk_widget_real_map;
420 klass->unmap = gtk_widget_real_unmap;
421 klass->realize = gtk_widget_real_realize;
422 klass->unrealize = gtk_widget_real_unrealize;
423 klass->size_request = gtk_widget_real_size_request;
424 klass->size_allocate = gtk_widget_real_size_allocate;
425 klass->state_changed = NULL;
426 klass->parent_set = NULL;
427 klass->hierarchy_changed = NULL;
428 klass->style_set = gtk_widget_style_set;
429 klass->direction_changed = gtk_widget_direction_changed;
430 klass->grab_notify = NULL;
431 klass->child_notify = NULL;
432 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
433 klass->grab_focus = gtk_widget_real_grab_focus;
434 klass->focus = gtk_widget_real_focus;
436 klass->button_press_event = NULL;
437 klass->button_release_event = NULL;
438 klass->motion_notify_event = NULL;
439 klass->delete_event = NULL;
440 klass->destroy_event = NULL;
441 klass->expose_event = NULL;
442 klass->key_press_event = gtk_widget_real_key_press_event;
443 klass->key_release_event = gtk_widget_real_key_release_event;
444 klass->enter_notify_event = NULL;
445 klass->leave_notify_event = NULL;
446 klass->configure_event = NULL;
447 klass->focus_in_event = gtk_widget_real_focus_in_event;
448 klass->focus_out_event = gtk_widget_real_focus_out_event;
449 klass->map_event = NULL;
450 klass->unmap_event = NULL;
451 klass->window_state_event = NULL;
452 klass->property_notify_event = _gtk_selection_property_notify;
453 klass->selection_clear_event = gtk_selection_clear;
454 klass->selection_request_event = _gtk_selection_request;
455 klass->selection_notify_event = _gtk_selection_notify;
456 klass->selection_received = NULL;
457 klass->proximity_in_event = NULL;
458 klass->proximity_out_event = NULL;
459 klass->drag_begin = NULL;
460 klass->drag_end = NULL;
461 klass->drag_data_delete = NULL;
462 klass->drag_leave = NULL;
463 klass->drag_motion = NULL;
464 klass->drag_drop = NULL;
465 klass->drag_data_received = NULL;
466 klass->screen_changed = NULL;
467 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
468 klass->grab_broken_event = NULL;
469 klass->query_tooltip = gtk_widget_real_query_tooltip;
471 klass->show_help = gtk_widget_real_show_help;
473 /* Accessibility support */
474 klass->get_accessible = gtk_widget_real_get_accessible;
476 klass->no_expose_event = NULL;
478 g_object_class_install_property (gobject_class,
480 g_param_spec_string ("name",
482 P_("The name of the widget"),
484 GTK_PARAM_READWRITE));
485 g_object_class_install_property (gobject_class,
487 g_param_spec_object ("parent",
489 P_("The parent widget of this widget. Must be a Container widget"),
491 GTK_PARAM_READWRITE));
493 g_object_class_install_property (gobject_class,
495 g_param_spec_int ("width-request",
497 P_("Override for width request of the widget, or -1 if natural request should be used"),
501 GTK_PARAM_READWRITE));
502 g_object_class_install_property (gobject_class,
504 g_param_spec_int ("height-request",
505 P_("Height request"),
506 P_("Override for height request of the widget, or -1 if natural request should be used"),
510 GTK_PARAM_READWRITE));
511 g_object_class_install_property (gobject_class,
513 g_param_spec_boolean ("visible",
515 P_("Whether the widget is visible"),
517 GTK_PARAM_READWRITE));
518 g_object_class_install_property (gobject_class,
520 g_param_spec_boolean ("sensitive",
522 P_("Whether the widget responds to input"),
524 GTK_PARAM_READWRITE));
525 g_object_class_install_property (gobject_class,
527 g_param_spec_boolean ("app-paintable",
528 P_("Application paintable"),
529 P_("Whether the application will paint directly on the widget"),
531 GTK_PARAM_READWRITE));
532 g_object_class_install_property (gobject_class,
534 g_param_spec_boolean ("can-focus",
536 P_("Whether the widget can accept the input focus"),
538 GTK_PARAM_READWRITE));
539 g_object_class_install_property (gobject_class,
541 g_param_spec_boolean ("has-focus",
543 P_("Whether the widget has the input focus"),
545 GTK_PARAM_READWRITE));
546 g_object_class_install_property (gobject_class,
548 g_param_spec_boolean ("is-focus",
550 P_("Whether the widget is the focus widget within the toplevel"),
552 GTK_PARAM_READWRITE));
553 g_object_class_install_property (gobject_class,
555 g_param_spec_boolean ("can-default",
557 P_("Whether the widget can be the default widget"),
559 GTK_PARAM_READWRITE));
560 g_object_class_install_property (gobject_class,
562 g_param_spec_boolean ("has-default",
564 P_("Whether the widget is the default widget"),
566 GTK_PARAM_READWRITE));
567 g_object_class_install_property (gobject_class,
568 PROP_RECEIVES_DEFAULT,
569 g_param_spec_boolean ("receives-default",
570 P_("Receives default"),
571 P_("If TRUE, the widget will receive the default action when it is focused"),
573 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
575 PROP_COMPOSITE_CHILD,
576 g_param_spec_boolean ("composite-child",
577 P_("Composite child"),
578 P_("Whether the widget is part of a composite widget"),
580 GTK_PARAM_READABLE));
581 g_object_class_install_property (gobject_class,
583 g_param_spec_object ("style",
585 P_("The style of the widget, which contains information about how it will look (colors etc)"),
587 GTK_PARAM_READWRITE));
588 g_object_class_install_property (gobject_class,
590 g_param_spec_flags ("events",
592 P_("The event mask that decides what kind of GdkEvents this widget gets"),
595 GTK_PARAM_READWRITE));
596 g_object_class_install_property (gobject_class,
597 PROP_EXTENSION_EVENTS,
598 g_param_spec_enum ("extension-events",
599 P_("Extension events"),
600 P_("The mask that decides what kind of extension events this widget gets"),
601 GDK_TYPE_EXTENSION_MODE,
602 GDK_EXTENSION_EVENTS_NONE,
603 GTK_PARAM_READWRITE));
604 g_object_class_install_property (gobject_class,
606 g_param_spec_boolean ("no-show-all",
608 P_("Whether gtk_widget_show_all() should not affect this widget"),
610 GTK_PARAM_READWRITE));
613 * GtkWidget:has-tooltip:
615 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
616 * A value of %TRUE indicates that @widget can have a tooltip, in this case
617 * the widget will be queried using #GtkWidget::query-tooltip to determine
618 * whether it will provide a tooltip or not.
620 * Note that setting this property to %TRUE for the first time will change
621 * the event masks of the GdkWindows of this widget to include leave-notify
622 * and motion-notify events. This cannot and will not be undone when the
623 * property is set to %FALSE again.
627 g_object_class_install_property (gobject_class,
629 g_param_spec_boolean ("has-tooltip",
631 P_("Whether this widget has a tooltip"),
633 GTK_PARAM_READWRITE));
635 * GtkWidget:tooltip-text:
637 * Sets the text of tooltip to be the given string.
639 * Also see gtk_tooltip_set_text().
641 * This is a convenience property which will take care of getting the
642 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
643 * will automatically be set to %TRUE and there will be taken care of
644 * #GtkWidget::query-tooltip in the default signal handler.
648 g_object_class_install_property (gobject_class,
650 g_param_spec_string ("tooltip-text",
652 P_("The contents of the tooltip for this widget"),
654 GTK_PARAM_READWRITE));
656 * GtkWidget:tooltip-markup:
658 * Sets the text of tooltip to be the given string, which is marked up
659 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
660 * Also see gtk_tooltip_set_markup().
662 * This is a convenience property which will take care of getting the
663 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
664 * will automatically be set to %TRUE and there will be taken care of
665 * #GtkWidget::query-tooltip in the default signal handler.
669 g_object_class_install_property (gobject_class,
671 g_param_spec_string ("tooltip-markup",
672 P_("Tooltip markup"),
673 P_("The contents of the tooltip for this widget"),
675 GTK_PARAM_READWRITE));
680 * The widget's window if it is realized, %NULL otherwise.
684 g_object_class_install_property (gobject_class,
686 g_param_spec_object ("window",
688 P_("The widget's window if it is realized"),
690 GTK_PARAM_READABLE));
692 widget_signals[SHOW] =
693 g_signal_new (I_("show"),
694 G_TYPE_FROM_CLASS (gobject_class),
696 G_STRUCT_OFFSET (GtkWidgetClass, show),
698 _gtk_marshal_VOID__VOID,
700 widget_signals[HIDE] =
701 g_signal_new (I_("hide"),
702 G_TYPE_FROM_CLASS (gobject_class),
704 G_STRUCT_OFFSET (GtkWidgetClass, hide),
706 _gtk_marshal_VOID__VOID,
708 widget_signals[MAP] =
709 g_signal_new (I_("map"),
710 G_TYPE_FROM_CLASS (gobject_class),
712 G_STRUCT_OFFSET (GtkWidgetClass, map),
714 _gtk_marshal_VOID__VOID,
716 widget_signals[UNMAP] =
717 g_signal_new (I_("unmap"),
718 G_TYPE_FROM_CLASS (gobject_class),
720 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
722 _gtk_marshal_VOID__VOID,
724 widget_signals[REALIZE] =
725 g_signal_new (I_("realize"),
726 G_TYPE_FROM_CLASS (gobject_class),
728 G_STRUCT_OFFSET (GtkWidgetClass, realize),
730 _gtk_marshal_VOID__VOID,
732 widget_signals[UNREALIZE] =
733 g_signal_new (I_("unrealize"),
734 G_TYPE_FROM_CLASS (gobject_class),
736 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
738 _gtk_marshal_VOID__VOID,
740 widget_signals[SIZE_REQUEST] =
741 g_signal_new (I_("size_request"),
742 G_TYPE_FROM_CLASS (gobject_class),
744 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
746 _gtk_marshal_VOID__BOXED,
748 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
749 widget_signals[SIZE_ALLOCATE] =
750 g_signal_new (I_("size_allocate"),
751 G_TYPE_FROM_CLASS (gobject_class),
753 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
755 _gtk_marshal_VOID__BOXED,
757 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
759 widget_signals[STATE_CHANGED] =
760 g_signal_new (I_("state_changed"),
761 G_TYPE_FROM_CLASS (gobject_class),
763 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
765 _gtk_marshal_VOID__ENUM,
767 GTK_TYPE_STATE_TYPE);
770 * GtkWidget::parent-set:
771 * @widget: the object on which the signal is emitted
772 * @old_parent: the previous parent, or %NULL if the widget
773 * just got its initial parent.
775 * The ::parent-set signal is emitted when a new parent
776 * has been set on a widget.
778 widget_signals[PARENT_SET] =
779 g_signal_new (I_("parent_set"),
780 G_TYPE_FROM_CLASS (gobject_class),
782 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
784 _gtk_marshal_VOID__OBJECT,
789 * GtkWidget::hierarchy-changed:
790 * @widget: the object on which the signal is emitted
791 * @previous_toplevel: the previous toplevel ancestor, or %NULL
792 * if the widget was previously unanchored
794 * The ::hierarchy-changed signal is emitted when the
795 * anchored state of a widget changes. A widget is
796 * <firstterm>anchored</firstterm> when its toplevel
797 * ancestor is a #GtkWindow. This signal is emitted when
798 * a widget changes from un-anchored to anchored or vice-versa.
800 widget_signals[HIERARCHY_CHANGED] =
801 g_signal_new (I_("hierarchy_changed"),
802 G_TYPE_FROM_CLASS (gobject_class),
804 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
806 _gtk_marshal_VOID__OBJECT,
811 * GtkWidget::style-set:
812 * @widget: the object on which the signal is emitted
813 * @previous_style: the previous style, or %NULL if the widget
814 * just got its initial style
816 * The ::style-set signal is emitted when a new style has been set
817 * on a widget. Note that style-modifying functions like
818 * gtk_widget_modify_base() also cause this signal to be emitted.
820 widget_signals[STYLE_SET] =
821 g_signal_new (I_("style_set"),
822 G_TYPE_FROM_CLASS (gobject_class),
824 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
826 _gtk_marshal_VOID__OBJECT,
830 * GtkWidget::direction-changed:
831 * @widget: the object on which the signal is emitted
832 * @previous_direction: the previous text direction of @widget
834 * The ::direction-changed signal is emitted when the text direction
835 * of a widget changes.
837 widget_signals[DIRECTION_CHANGED] =
838 g_signal_new (I_("direction_changed"),
839 G_TYPE_FROM_CLASS (gobject_class),
841 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
843 _gtk_marshal_VOID__ENUM,
845 GTK_TYPE_TEXT_DIRECTION);
848 * GtkWidget::grab-notify:
849 * @widget: the object which received the signal
850 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
851 * if it becomes unshadowed
853 * The ::grab-notify signal is emitted when a widget becomes
854 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
855 * another widget, or when it becomes unshadowed due to a grab
858 * A widget is shadowed by a gtk_grab_add() when the topmost
859 * grab widget in the grab stack of its window group is not
862 widget_signals[GRAB_NOTIFY] =
863 g_signal_new (I_("grab_notify"),
864 G_TYPE_FROM_CLASS (gobject_class),
866 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
868 _gtk_marshal_VOID__BOOLEAN,
873 * GtkWidget::child-notify:
874 * @widget: the object which received the signal
875 * @pspec: the #GParamSpec of the changed child property
877 * The ::child-notify signal is emitted for each
878 * <link linkend="child-properties">child property</link> that has
879 * changed on an object. The signal's detail holds the property name.
881 widget_signals[CHILD_NOTIFY] =
882 g_signal_new (I_("child_notify"),
883 G_TYPE_FROM_CLASS (gobject_class),
884 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
885 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
887 g_cclosure_marshal_VOID__PARAM,
890 widget_signals[MNEMONIC_ACTIVATE] =
891 g_signal_new (I_("mnemonic_activate"),
892 G_TYPE_FROM_CLASS (gobject_class),
894 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
895 _gtk_boolean_handled_accumulator, NULL,
896 _gtk_marshal_BOOLEAN__BOOLEAN,
899 widget_signals[GRAB_FOCUS] =
900 g_signal_new (I_("grab_focus"),
901 G_TYPE_FROM_CLASS (gobject_class),
902 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
903 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
905 _gtk_marshal_VOID__VOID,
907 widget_signals[FOCUS] =
908 g_signal_new (I_("focus"),
909 G_TYPE_FROM_CLASS (object_class),
911 G_STRUCT_OFFSET (GtkWidgetClass, focus),
912 _gtk_boolean_handled_accumulator, NULL,
913 _gtk_marshal_BOOLEAN__ENUM,
915 GTK_TYPE_DIRECTION_TYPE);
916 widget_signals[MOVE_FOCUS] =
917 _gtk_binding_signal_new (I_("move_focus"),
918 G_TYPE_FROM_CLASS (object_class),
919 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
920 G_CALLBACK (gtk_widget_real_move_focus),
922 _gtk_marshal_VOID__ENUM,
925 GTK_TYPE_DIRECTION_TYPE);
928 * @widget: the object which received the signal.
929 * @event: the #GdkEvent which triggered this signal
931 * The GTK+ main loop will emit three signals for each GDK event delivered
932 * to a widget: one generic ::event signal, another, more specific,
933 * signal that matches the type of event delivered (e.g.
934 * #GtkWidget::key-press-event) and finally a generic
935 * #GtkWidget::event-after signal.
937 * Returns: %TRUE to stop other handlers from being invoked for the event
938 * and to cancel the emission of the second specific ::event signal.
939 * %FALSE to propagate the event further and to allow the emission of
940 * the second signal. The ::event-after signal is emitted regardless of
943 widget_signals[EVENT] =
944 g_signal_new (I_("event"),
945 G_TYPE_FROM_CLASS (gobject_class),
947 G_STRUCT_OFFSET (GtkWidgetClass, event),
948 _gtk_boolean_handled_accumulator, NULL,
949 _gtk_marshal_BOOLEAN__BOXED,
951 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
954 * GtkWidget::event-after:
955 * @widget: the object which received the signal.
956 * @event: the #GdkEvent which triggered this signal
958 * After the emission of the #GtkWidget::event signal and (optionally)
959 * the second more specific signal, ::event-after will be emitted
960 * regardless of the previous two signals handlers return values.
963 widget_signals[EVENT_AFTER] =
964 g_signal_new (I_("event_after"),
965 G_TYPE_FROM_CLASS (gobject_class),
969 _gtk_marshal_VOID__BOXED,
971 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
974 * GtkWidget::button-press-event:
975 * @widget: the object which received the signal.
976 * @event: the #GdkEventButton which triggered this signal
978 * The ::button-press-event signal will be emitted when a button
979 * (typically from a mouse) is pressed.
981 * To receive this signal, the #GdkWindow associated to the
982 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
984 * This signal will be sent to the grab widget if there is one.
986 * Returns: %TRUE to stop other handlers from being invoked for the event.
987 * %FALSE to propagate the event further.
989 widget_signals[BUTTON_PRESS_EVENT] =
990 g_signal_new (I_("button_press_event"),
991 G_TYPE_FROM_CLASS (gobject_class),
993 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
994 _gtk_boolean_handled_accumulator, NULL,
995 _gtk_marshal_BOOLEAN__BOXED,
997 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1000 * GtkWidget::button-release-event:
1001 * @widget: the object which received the signal.
1002 * @event: the #GdkEventButton which triggered this signal
1004 * The ::button-release-event signal will be emitted when a button
1005 * (typically from a mouse) is released.
1007 * To receive this signal, the #GdkWindow associated to the
1008 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1010 * This signal will be sent to the grab widget if there is one.
1012 * Returns: %TRUE to stop other handlers from being invoked for the event.
1013 * %FALSE to propagate the event further.
1015 widget_signals[BUTTON_RELEASE_EVENT] =
1016 g_signal_new (I_("button_release_event"),
1017 G_TYPE_FROM_CLASS (gobject_class),
1019 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1020 _gtk_boolean_handled_accumulator, NULL,
1021 _gtk_marshal_BOOLEAN__BOXED,
1023 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1026 * GtkWidget::scroll-event:
1027 * @widget: the object which received the signal.
1028 * @event: the #GdkEventScroll which triggered this signal
1030 * The ::scroll-event signal is emitted when a button in the 4 to 7
1031 * range is pressed. Wheel mice are usually configured to generate
1032 * button press events for buttons 4 and 5 when the wheel is turned.
1034 * To receive this signal, the #GdkWindow associated to the widget needs
1035 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1037 * This signal will be sent to the grab widget if there is one.
1039 * Returns: %TRUE to stop other handlers from being invoked for the event.
1040 * %FALSE to propagate the event further.
1042 widget_signals[SCROLL_EVENT] =
1043 g_signal_new (I_("scroll_event"),
1044 G_TYPE_FROM_CLASS (gobject_class),
1046 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1047 _gtk_boolean_handled_accumulator, NULL,
1048 _gtk_marshal_BOOLEAN__BOXED,
1050 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1052 * GtkWidget::motion-notify-event:
1053 * @widget: the object which received the signal.
1054 * @event: the #GdkEventMotion which triggered this signal
1056 * The ::motion-notify-event signal is emitted when the pointer moves
1057 * over the widget's #GdkWindow.
1059 * To receive this signal, the #GdkWindow associated to the widget
1060 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1062 * This signal will be sent to the grab widget if there is one.
1064 * Returns: %TRUE to stop other handlers from being invoked for the event.
1065 * %FALSE to propagate the event further.
1067 widget_signals[MOTION_NOTIFY_EVENT] =
1068 g_signal_new (I_("motion_notify_event"),
1069 G_TYPE_FROM_CLASS (gobject_class),
1071 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1072 _gtk_boolean_handled_accumulator, NULL,
1073 _gtk_marshal_BOOLEAN__BOXED,
1075 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1078 * GtkWidget::composited-changed:
1079 * @widget: the object on which the signal is emitted
1081 * The ::composited-changed signal is emitted when the composited
1082 * status of @widget<!-- -->s screen changes.
1083 * See gdk_screen_is_composited().
1085 widget_signals[COMPOSITED_CHANGED] =
1086 g_signal_new (I_("composited_changed"),
1087 G_TYPE_FROM_CLASS (gobject_class),
1088 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1089 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1091 _gtk_marshal_VOID__VOID,
1095 * GtkWidget::keynav-failed:
1096 * @widget: the object which received the signal
1097 * @direction: the direction of movement
1099 * Gets emitted if keyboard navigation fails.
1100 * See gtk_widget_keynav_failed() for details.
1102 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1103 * if the emitting widget should try to handle the keyboard
1104 * navigation attempt in its parent container(s).
1108 widget_signals[KEYNAV_FAILED] =
1109 _gtk_binding_signal_new (I_("keynav-failed"),
1110 G_TYPE_FROM_CLASS (gobject_class),
1112 G_CALLBACK (gtk_widget_real_keynav_failed),
1113 _gtk_boolean_handled_accumulator, NULL,
1114 _gtk_marshal_BOOLEAN__ENUM,
1116 GTK_TYPE_DIRECTION_TYPE);
1119 * GtkWidget::delete-event:
1120 * @widget: the object which received the signal
1121 * @event: the event which triggered this signal
1123 * The ::delete-event signal is emitted if a user requests that
1124 * a toplevel window is closed. The default handler for this signal
1125 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1126 * this signal will cause the window to be hidden instead, so that
1127 * it can later be shown again without reconstructing it.
1129 * Returns: %TRUE to stop other handlers from being invoked for the event.
1130 * %FALSE to propagate the event further.
1132 widget_signals[DELETE_EVENT] =
1133 g_signal_new (I_("delete_event"),
1134 G_TYPE_FROM_CLASS (gobject_class),
1136 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1137 _gtk_boolean_handled_accumulator, NULL,
1138 _gtk_marshal_BOOLEAN__BOXED,
1140 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1143 * GtkWidget::destroy-event:
1144 * @widget: the object which received the signal.
1145 * @event: the event which triggered this signal
1147 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1148 * You rarely get this signal, because most widgets disconnect themselves
1149 * from their window before they destroy it, so no widget owns the
1150 * window at destroy time.
1152 * To receive this signal, the #GdkWindow associated to the widget needs
1153 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1154 * automatically for all new windows.
1156 * Returns: %TRUE to stop other handlers from being invoked for the event.
1157 * %FALSE to propagate the event further.
1159 widget_signals[DESTROY_EVENT] =
1160 g_signal_new (I_("destroy_event"),
1161 G_TYPE_FROM_CLASS (gobject_class),
1163 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1164 _gtk_boolean_handled_accumulator, NULL,
1165 _gtk_marshal_BOOLEAN__BOXED,
1167 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1170 * GtkWidget::expose-event:
1171 * @widget: the object which received the signal.
1172 * @event: the #GdkEventExpose which triggered this signal
1174 * The ::expose-event signal is emitted when an area of a previously
1175 * obscured #GdkWindow is made visible and needs to be redrawn.
1176 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1179 * To receive this signal, the #GdkWindow associated to the widget needs
1180 * to enable the #GDK_EXPOSURE_MASK mask.
1182 * Returns: %TRUE to stop other handlers from being invoked for the event.
1183 * %FALSE to propagate the event further.
1185 widget_signals[EXPOSE_EVENT] =
1186 g_signal_new (I_("expose_event"),
1187 G_TYPE_FROM_CLASS (gobject_class),
1189 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1190 _gtk_boolean_handled_accumulator, NULL,
1191 _gtk_marshal_BOOLEAN__BOXED,
1193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1196 * GtkWidget::key-press-event:
1197 * @widget: the object which received the signal
1198 * @event: the #GdkEventKey which triggered this signal
1200 * The ::key-press-event signal is emitted when a key is pressed.
1202 * To receive this signal, the #GdkWindow associated to the widget needs
1203 * to enable the #GDK_KEY_PRESS_MASK mask.
1205 * This signal will be sent to the grab widget if there is one.
1207 * Returns: %TRUE to stop other handlers from being invoked for the event.
1208 * %FALSE to propagate the event further.
1210 widget_signals[KEY_PRESS_EVENT] =
1211 g_signal_new (I_("key_press_event"),
1212 G_TYPE_FROM_CLASS (gobject_class),
1214 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1215 _gtk_boolean_handled_accumulator, NULL,
1216 _gtk_marshal_BOOLEAN__BOXED,
1218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1221 * GtkWidget::key-release-event:
1222 * @widget: the object which received the signal
1223 * @event: the #GdkEventKey which triggered this signal
1225 * The ::key-release-event signal is emitted when a key is pressed.
1227 * To receive this signal, the #GdkWindow associated to the widget needs
1228 * to enable the #GDK_KEY_RELEASE_MASK mask.
1230 * This signal will be sent to the grab widget if there is one.
1232 * Returns: %TRUE to stop other handlers from being invoked for the event.
1233 * %FALSE to propagate the event further.
1235 widget_signals[KEY_RELEASE_EVENT] =
1236 g_signal_new (I_("key_release_event"),
1237 G_TYPE_FROM_CLASS (gobject_class),
1239 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1240 _gtk_boolean_handled_accumulator, NULL,
1241 _gtk_marshal_BOOLEAN__BOXED,
1243 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1246 * GtkWidget::enter-notify-event:
1247 * @widget: the object which received the signal
1248 * @event: the #GdkEventCrossing which triggered this signal
1250 * The ::enter-notify-event will be emitted when the pointer enters
1251 * the @widget's window.
1253 * To receive this signal, the #GdkWindow associated to the widget needs
1254 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1256 * This signal will be sent to the grab widget if there is one.
1258 * Returns: %TRUE to stop other handlers from being invoked for the event.
1259 * %FALSE to propagate the event further.
1261 widget_signals[ENTER_NOTIFY_EVENT] =
1262 g_signal_new (I_("enter_notify_event"),
1263 G_TYPE_FROM_CLASS (gobject_class),
1265 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1266 _gtk_boolean_handled_accumulator, NULL,
1267 _gtk_marshal_BOOLEAN__BOXED,
1269 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1272 * GtkWidget::leave-notify-event:
1273 * @widget: the object which received the signal
1274 * @event: the #GdkEventCrossing which triggered this signal
1276 * The ::leave-notify-event will be emitted when the pointer leaves
1277 * the @widget's window.
1279 * To receive this signal, the #GdkWindow associated to the widget needs
1280 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1282 * This signal will be sent to the grab widget if there is one.
1284 * Returns: %TRUE to stop other handlers from being invoked for the event.
1285 * %FALSE to propagate the event further.
1287 widget_signals[LEAVE_NOTIFY_EVENT] =
1288 g_signal_new (I_("leave_notify_event"),
1289 G_TYPE_FROM_CLASS (gobject_class),
1291 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1292 _gtk_boolean_handled_accumulator, NULL,
1293 _gtk_marshal_BOOLEAN__BOXED,
1295 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1298 * GtkWidget::configure-event
1299 * @widget: the object which received the signal
1300 * @event: the #GdkEventConfigure which triggered this signal
1302 * The ::configure-event signal will be emitted when the size, position or
1303 * stacking of the @widget's window has changed.
1305 * To receive this signal, the #GdkWindow associated to the widget needs
1306 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1307 * automatically for all new windows.
1309 * Returns: %TRUE to stop other handlers from being invoked for the event.
1310 * %FALSE to propagate the event further.
1312 widget_signals[CONFIGURE_EVENT] =
1313 g_signal_new (I_("configure_event"),
1314 G_TYPE_FROM_CLASS (gobject_class),
1316 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1317 _gtk_boolean_handled_accumulator, NULL,
1318 _gtk_marshal_BOOLEAN__BOXED,
1320 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1323 * GtkWidget::focus-in-event
1324 * @widget: the object which received the signal
1325 * @event: the #GdkEventFocus which triggered this signal
1327 * The ::focus-in-event signal will be emitted when the keyboard focus
1328 * enters the @widget's window.
1330 * To receive this signal, the #GdkWindow associated to the widget needs
1331 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1333 * Returns: %TRUE to stop other handlers from being invoked for the event.
1334 * %FALSE to propagate the event further.
1336 widget_signals[FOCUS_IN_EVENT] =
1337 g_signal_new (I_("focus_in_event"),
1338 G_TYPE_FROM_CLASS (gobject_class),
1340 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1341 _gtk_boolean_handled_accumulator, NULL,
1342 _gtk_marshal_BOOLEAN__BOXED,
1344 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1347 * GtkWidget::focus-out-event
1348 * @widget: the object which received the signal
1349 * @event: the #GdkEventFocus which triggered this signal
1351 * The ::focus-out-event signal will be emitted when the keyboard focus
1352 * leaves the @widget's window.
1354 * To receive this signal, the #GdkWindow associated to the widget needs
1355 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1357 * Returns: %TRUE to stop other handlers from being invoked for the event.
1358 * %FALSE to propagate the event further.
1360 widget_signals[FOCUS_OUT_EVENT] =
1361 g_signal_new (I_("focus_out_event"),
1362 G_TYPE_FROM_CLASS (gobject_class),
1364 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1365 _gtk_boolean_handled_accumulator, NULL,
1366 _gtk_marshal_BOOLEAN__BOXED,
1368 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1371 * GtkWidget::map-event
1372 * @widget: the object which received the signal
1373 * @event: the #GdkEventAny which triggered this signal
1375 * The ::map-event signal will be emitted when the @widget's window is
1376 * mapped. A window is mapped when it becomes visible on the screen.
1378 * To receive this signal, the #GdkWindow associated to the widget needs
1379 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1380 * automatically for all new windows.
1382 * Returns: %TRUE to stop other handlers from being invoked for the event.
1383 * %FALSE to propagate the event further.
1385 widget_signals[MAP_EVENT] =
1386 g_signal_new (I_("map_event"),
1387 G_TYPE_FROM_CLASS (gobject_class),
1389 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1390 _gtk_boolean_handled_accumulator, NULL,
1391 _gtk_marshal_BOOLEAN__BOXED,
1393 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1396 * GtkWidget::unmap-event
1397 * @widget: the object which received the signal
1398 * @event: the #GdkEventAny which triggered this signal
1400 * The ::unmap-event signal will be emitted when the @widget's window is
1401 * unmapped. A window is unmapped when it becomes invisible on the screen.
1403 * To receive this signal, the #GdkWindow associated to the widget needs
1404 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1405 * automatically for all new windows.
1407 * Returns: %TRUE to stop other handlers from being invoked for the event.
1408 * %FALSE to propagate the event further.
1410 widget_signals[UNMAP_EVENT] =
1411 g_signal_new (I_("unmap_event"),
1412 G_TYPE_FROM_CLASS (gobject_class),
1414 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1415 _gtk_boolean_handled_accumulator, NULL,
1416 _gtk_marshal_BOOLEAN__BOXED,
1418 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1421 * GtkWidget::property-notify-event
1422 * @widget: the object which received the signal
1423 * @event: the #GdkEventProperty which triggered this signal
1425 * The ::property-notify-event signal will be emitted when a property on
1426 * the @widget's window has been changed or deleted.
1428 * To receive this signal, the #GdkWindow associated to the widget needs
1429 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1431 * Returns: %TRUE to stop other handlers from being invoked for the event.
1432 * %FALSE to propagate the event further.
1434 widget_signals[PROPERTY_NOTIFY_EVENT] =
1435 g_signal_new (I_("property_notify_event"),
1436 G_TYPE_FROM_CLASS (gobject_class),
1438 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1439 _gtk_boolean_handled_accumulator, NULL,
1440 _gtk_marshal_BOOLEAN__BOXED,
1442 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1445 * GtkWidget::selection-clear-event
1446 * @widget: the object which received the signal
1447 * @event: the #GdkEventSelection which triggered this signal
1449 * The ::selection-clear-event signal will be emitted when the
1450 * the @widget's window has lost ownership of a selection.
1452 * Returns: %TRUE to stop other handlers from being invoked for the event.
1453 * %FALSE to propagate the event further.
1455 widget_signals[SELECTION_CLEAR_EVENT] =
1456 g_signal_new (I_("selection_clear_event"),
1457 G_TYPE_FROM_CLASS (gobject_class),
1459 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1460 _gtk_boolean_handled_accumulator, NULL,
1461 _gtk_marshal_BOOLEAN__BOXED,
1463 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1466 * GtkWidget::selection-request-event
1467 * @widget: the object which received the signal
1468 * @event: the #GdkEventSelection which triggered this signal
1470 * The ::selection-request-event signal will be emitted when
1471 * another client requests ownership of the selection owned by
1472 * the @widget's window.
1474 * Returns: %TRUE to stop other handlers from being invoked for the event.
1475 * %FALSE to propagate the event further.
1477 widget_signals[SELECTION_REQUEST_EVENT] =
1478 g_signal_new (I_("selection_request_event"),
1479 G_TYPE_FROM_CLASS (gobject_class),
1481 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1482 _gtk_boolean_handled_accumulator, NULL,
1483 _gtk_marshal_BOOLEAN__BOXED,
1485 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1487 widget_signals[SELECTION_NOTIFY_EVENT] =
1488 g_signal_new (I_("selection_notify_event"),
1489 G_TYPE_FROM_CLASS (gobject_class),
1491 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1492 _gtk_boolean_handled_accumulator, NULL,
1493 _gtk_marshal_BOOLEAN__BOXED,
1495 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1497 widget_signals[SELECTION_RECEIVED] =
1498 g_signal_new (I_("selection_received"),
1499 G_TYPE_FROM_CLASS (gobject_class),
1501 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1503 _gtk_marshal_VOID__BOXED_UINT,
1505 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1508 widget_signals[SELECTION_GET] =
1509 g_signal_new (I_("selection_get"),
1510 G_TYPE_FROM_CLASS (gobject_class),
1512 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1514 _gtk_marshal_VOID__BOXED_UINT_UINT,
1516 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1521 * GtkWidget::proximity-in-event
1522 * @widget: the object which received the signal
1523 * @event: the #GdkEventProximity which triggered this signal
1525 * To receive this signal the #GdkWindow associated to the widget needs
1526 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1528 * This signal will be sent to the grab widget if there is one.
1530 * Returns: %TRUE to stop other handlers from being invoked for the event.
1531 * %FALSE to propagate the event further.
1533 widget_signals[PROXIMITY_IN_EVENT] =
1534 g_signal_new (I_("proximity_in_event"),
1535 G_TYPE_FROM_CLASS (gobject_class),
1537 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1538 _gtk_boolean_handled_accumulator, NULL,
1539 _gtk_marshal_BOOLEAN__BOXED,
1541 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1544 * GtkWidget::proximity-out-event
1545 * @widget: the object which received the signal
1546 * @event: the #GdkEventProximity which triggered this signal
1548 * To receive this signal the #GdkWindow associated to the widget needs
1549 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
1551 * This signal will be sent to the grab widget if there is one.
1553 * Returns: %TRUE to stop other handlers from being invoked for the event.
1554 * %FALSE to propagate the event further.
1556 widget_signals[PROXIMITY_OUT_EVENT] =
1557 g_signal_new (I_("proximity_out_event"),
1558 G_TYPE_FROM_CLASS (gobject_class),
1560 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
1561 _gtk_boolean_handled_accumulator, NULL,
1562 _gtk_marshal_BOOLEAN__BOXED,
1564 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1567 * GtkWidget::drag-leave:
1568 * @widget: the object which received the signal.
1569 * @drag_context: the drag context
1570 * @time: the timestamp of the motion event
1572 * The ::drag-leave signal is emitted on the drop site when the cursor
1573 * leaves the widget. A typical reason to connect to this signal is to
1574 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
1575 * with gtk_drag_unhighlight()
1577 widget_signals[DRAG_LEAVE] =
1578 g_signal_new (I_("drag_leave"),
1579 G_TYPE_FROM_CLASS (gobject_class),
1581 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
1583 _gtk_marshal_VOID__OBJECT_UINT,
1585 GDK_TYPE_DRAG_CONTEXT,
1589 * GtkWidget::drag-begin:
1590 * @widget: the object which received the signal
1591 * @drag_context: the drag context
1593 * The ::drag-begin signal is emitted on the drag source when a drag is
1594 * started. A typical reason to connect to this signal is to set up a
1595 * custom drag icon with gtk_drag_source_set_icon().
1597 widget_signals[DRAG_BEGIN] =
1598 g_signal_new (I_("drag_begin"),
1599 G_TYPE_FROM_CLASS (gobject_class),
1601 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1603 _gtk_marshal_VOID__OBJECT,
1605 GDK_TYPE_DRAG_CONTEXT);
1608 * GtkWidget::drag-end:
1609 * @widget: the object which received the signal
1610 * @drag_context: the drag context
1612 * The ::drag-end signal is emitted on the drag source when a drag is
1613 * finished. A typical reason to connect to this signal is to undo
1614 * things done in #GtkWidget::drag-begin.
1616 widget_signals[DRAG_END] =
1617 g_signal_new (I_("drag_end"),
1618 G_TYPE_FROM_CLASS (gobject_class),
1620 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1622 _gtk_marshal_VOID__OBJECT,
1624 GDK_TYPE_DRAG_CONTEXT);
1627 * GtkWidget::drag-data-delete:
1628 * @widget: the object which received the signal
1629 * @drag_context: the drag context
1631 * The ::drag-data-delete signal is emitted on the drag source when a drag
1632 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
1633 * handler is responsible for deleting the data that has been dropped. What
1634 * "delete" means depends on the context of the drag operation.
1636 widget_signals[DRAG_DATA_DELETE] =
1637 g_signal_new (I_("drag_data_delete"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1640 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1642 _gtk_marshal_VOID__OBJECT,
1644 GDK_TYPE_DRAG_CONTEXT);
1647 * GtkWidget::drag-failed:
1648 * @widget: the object which received the signal
1649 * @drag_context: the drag context
1650 * @result: the result of the drag operation
1652 * The ::drag-failed signal is emitted on the drag source when a drag has
1653 * failed. The signal handler may hook custom code to handle a failed DND
1654 * operation based on the type of error, it returns %TRUE is the failure has
1655 * been already handled (not showing the default "drag operation failed"
1656 * animation), otherwise it returns %FALSE.
1658 * Return value: %TRUE if the failed drag operation has been already handled.
1662 widget_signals[DRAG_FAILED] =
1663 g_signal_new (I_("drag_failed"),
1664 G_TYPE_FROM_CLASS (gobject_class),
1666 0, _gtk_boolean_handled_accumulator, NULL,
1667 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
1669 GDK_TYPE_DRAG_CONTEXT,
1670 GTK_TYPE_DRAG_RESULT);
1673 * GtkWidget::drag-motion:
1674 * @widget: the object which received the signal
1675 * @drag_context: the drag context
1676 * @x: the x coordinate of the current cursor position
1677 * @y: the y coordinate of the current cursor position
1678 * @time: the timestamp of the motion event
1679 * @returns: whether the cursor position is in a drop zone
1681 * The drag-motion signal is emitted on the drop site when the user
1682 * moves the cursor over the widget during a drag. The signal handler
1683 * must determine whether the cursor position is in a drop zone or not.
1684 * If it is not in a drop zone, it returns %FALSE and no further processing
1685 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
1686 * handler is responsible for providing the necessary information for
1687 * displaying feedback to the user, by calling gdk_drag_status().
1689 * If the decision whether the drop will be accepted or rejected can't be
1690 * made based solely on the cursor position and the type of the data, the
1691 * handler may inspect the dragged data by calling gtk_drag_get_data() and
1692 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
1693 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
1694 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
1695 * when using the drag-motion signal that way.
1697 * Also note that there is no drag-enter signal. The drag receiver has to
1698 * keep track of whether he has received any drag-motion signals since the
1699 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
1700 * an "enter" signal. Upon an "enter", the handler will typically highlight
1701 * the drop site with gtk_drag_highlight().
1704 * drag_motion (GtkWidget *widget,
1705 * GdkDragContext *context,
1712 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1714 * if (!private_data->drag_highlight)
1716 * private_data->drag_highlight = 1;
1717 * gtk_drag_highlight (widget);
1720 * target = gtk_drag_dest_find_target (widget, context, NULL);
1721 * if (target == GDK_NONE)
1722 * gdk_drag_status (context, 0, time);
1725 * private_data->pending_status = context->suggested_action;
1726 * gtk_drag_get_data (widget, context, target, time);
1733 * drag_data_received (GtkWidget *widget,
1734 * GdkDragContext *context,
1737 * GtkSelectionData *selection_data,
1741 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1743 * if (private_data->suggested_action)
1745 * private_data->suggested_action = 0;
1747 * /* We are getting this data due to a request in drag_motion,
1748 * * rather than due to a request in drag_drop, so we are just
1749 * * supposed to call gdk_drag_status (), not actually paste in
1752 * str = gtk_selection_data_get_text (selection_data);
1753 * if (!data_is_acceptable (str))
1754 * gdk_drag_status (context, 0, time);
1756 * gdk_drag_status (context, private_data->suggested_action, time);
1760 * /* accept the drop */
1765 widget_signals[DRAG_MOTION] =
1766 g_signal_new (I_("drag_motion"),
1767 G_TYPE_FROM_CLASS (gobject_class),
1769 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1770 _gtk_boolean_handled_accumulator, NULL,
1771 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1773 GDK_TYPE_DRAG_CONTEXT,
1779 * GtkWidget::drag-drop:
1780 * @widget: the object which received the signal
1781 * @drag_context: the drag context
1782 * @x: the x coordinate of the current cursor position
1783 * @y: the y coordinate of the current cursor position
1784 * @time: the timestamp of the motion event
1785 * @returns: whether the cursor position is in a drop zone
1787 * The ::drag-drop signal is emitted on the drop site when the user drops
1788 * the data onto the widget. The signal handler must determine whether
1789 * the cursor position is in a drop zone or not. If it is not in a drop
1790 * zone, it returns %FALSE and no further processing is necessary.
1791 * Otherwise, the handler returns %TRUE. In this case, the handler must
1792 * ensure that gtk_drag_finish() is called to let the source know that
1793 * the drop is done. The call to gtk_drag_finish() can be done either
1794 * directly or in a #GtkWidget::drag-data-received handler which gets
1795 * triggered by calling gtk_drag_get_data() to receive the data for one
1796 * or more of the supported targets.
1798 widget_signals[DRAG_DROP] =
1799 g_signal_new (I_("drag_drop"),
1800 G_TYPE_FROM_CLASS (gobject_class),
1802 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1803 _gtk_boolean_handled_accumulator, NULL,
1804 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1806 GDK_TYPE_DRAG_CONTEXT,
1812 * GtkWidget::drag-data-get:
1813 * @widget: the object which received the signal
1814 * @drag_context: the drag context
1815 * @data: the #GtkSelectionData to be filled with the dragged data
1816 * @info: the info that has been registered with the target in the
1818 * @time: the timestamp at which the data was requested
1820 * The ::drag-data-get signal is emitted on the drag source when the drop
1821 * site requests the data which is dragged. It is the responsibility of
1822 * the signal handler to fill @data with the data in the format which
1823 * is indicated by @info. See gtk_selection_data_set() and
1824 * gtk_selection_data_set_text().
1826 widget_signals[DRAG_DATA_GET] =
1827 g_signal_new (I_("drag_data_get"),
1828 G_TYPE_FROM_CLASS (gobject_class),
1830 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1832 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1834 GDK_TYPE_DRAG_CONTEXT,
1835 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1840 * GtkWidget::drag-data-received:
1841 * @widget: the object which received the signal
1842 * @drag_context: the drag context
1843 * @x: where the drop happened
1844 * @y: where the drop happened
1845 * @data: the received data
1846 * @info: the info that has been registered with the target in the
1848 * @time: the timestamp at which the data was received
1850 * The ::drag-data-received signal is emitted on the drop site when the
1851 * dragged data has been received. If the data was received in order to
1852 * determine whether the drop will be accepted, the handler is expected
1853 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1854 * If the data was received in response to a #GtkWidget::drag-drop signal
1855 * (and this is the last target to be received), the handler for this
1856 * signal is expected to process the received data and then call
1857 * gtk_drag_finish(), setting the @success parameter depending on whether
1858 * the data was processed successfully.
1860 * The handler may inspect and modify @drag_context->action before calling
1861 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
1862 * following example:
1865 * drag_data_received (GtkWidget *widget,
1866 * GdkDragContext *drag_context,
1869 * GtkSelectionData *data,
1873 * if ((data->length >= 0) && (data->format == 8))
1875 * if (drag_context->action == GDK_ACTION_ASK)
1877 * GtkWidget *dialog;
1880 * dialog = gtk_message_dialog_new (NULL,
1881 * GTK_DIALOG_MODAL |
1882 * GTK_DIALOG_DESTROY_WITH_PARENT,
1884 * GTK_BUTTONS_YES_NO,
1885 * "Move the data ?\n");
1886 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1887 * gtk_widget_destroy (dialog);
1889 * if (response == GTK_RESPONSE_YES)
1890 * drag_context->action = GDK_ACTION_MOVE;
1892 * drag_context->action = GDK_ACTION_COPY;
1895 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1899 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1903 widget_signals[DRAG_DATA_RECEIVED] =
1904 g_signal_new (I_("drag_data_received"),
1905 G_TYPE_FROM_CLASS (gobject_class),
1907 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1909 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1911 GDK_TYPE_DRAG_CONTEXT,
1914 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1919 * GtkWidget::visibility-notify-event:
1920 * @widget: the object which received the signal
1921 * @event: the #GdkEventVisibility which triggered this signal
1923 * The ::visibility-notify-event will be emitted when the @widget's window
1924 * is obscured or unobscured.
1926 * To receive this signal the #GdkWindow associated to the widget needs
1927 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
1929 * Returns: %TRUE to stop other handlers from being invoked for the event.
1930 * %FALSE to propagate the event further.
1932 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1933 g_signal_new (I_("visibility_notify_event"),
1934 G_TYPE_FROM_CLASS (gobject_class),
1936 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 * GtkWidget::client-event:
1944 * @widget: the object which received the signal
1945 * @event: the #GdkEventClient which triggered this signal
1947 * The ::client-event will be emitted when the @widget's window
1948 * receives a message (via a ClientMessage event) from another
1951 * Returns: %TRUE to stop other handlers from being invoked for
1952 * the event. %FALSE to propagate the event further.
1954 widget_signals[CLIENT_EVENT] =
1955 g_signal_new (I_("client_event"),
1956 G_TYPE_FROM_CLASS (gobject_class),
1958 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::no-expose-event:
1966 * @widget: the object which received the signal
1967 * @event: the #GdkEventNoExpose which triggered this signal
1969 * The ::no-expose-event will be emitted when the @widget's window is
1970 * drawn as a copy of another #GdkDrawable (with gdk_draw_drawable() or
1971 * gdk_window_copy_area()) which was completely unobscured. If the source
1972 * window was partially obscured #GdkEventExpose events will be generated
1975 * Returns: %TRUE to stop other handlers from being invoked for the event.
1976 * %FALSE to propagate the event further.
1978 widget_signals[NO_EXPOSE_EVENT] =
1979 g_signal_new (I_("no_expose_event"),
1980 G_TYPE_FROM_CLASS (gobject_class),
1982 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1983 _gtk_boolean_handled_accumulator, NULL,
1984 _gtk_marshal_BOOLEAN__BOXED,
1986 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1989 * GtkWidget::window-state-event:
1990 * @widget: the object which received the signal
1991 * @event: the #GdkEventWindowState which triggered this signal
1993 * The ::window-state-event will be emitted when the state of the
1994 * toplevel window associated to the @widget changes.
1996 * To receive this signal the #GdkWindow associated to the widget
1997 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
1998 * this mask automatically for all new windows.
2000 * Returns: %TRUE to stop other handlers from being invoked for the
2001 * event. %FALSE to propagate the event further.
2003 widget_signals[WINDOW_STATE_EVENT] =
2004 g_signal_new (I_("window_state_event"),
2005 G_TYPE_FROM_CLASS (gobject_class),
2007 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2008 _gtk_boolean_handled_accumulator, NULL,
2009 _gtk_marshal_BOOLEAN__BOXED,
2011 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2014 * GtkWidget::damage-event:
2015 * @widget: the object which received the signal
2016 * @event: the #GdkEventExpose event
2018 * Emitted when a redirected window belonging to @widget gets drawn into.
2019 * The region/area members of the event shows what area of the redirected
2020 * drawable was drawn into.
2022 * Returns: %TRUE to stop other handlers from being invoked for the event.
2023 * %FALSE to propagate the event further.
2027 widget_signals[DAMAGE_EVENT] =
2028 g_signal_new ("damage_event",
2029 G_TYPE_FROM_CLASS (gobject_class),
2030 G_SIGNAL_RUN_LAST, 0,
2031 _gtk_boolean_handled_accumulator, NULL,
2032 _gtk_marshal_BOOLEAN__BOXED,
2034 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2036 * GtkWidget::grab-broken-event:
2037 * @widget: the object which received the signal
2038 * @event: the #GdkEventGrabBroken event
2040 * Emitted when a pointer or keyboard grab on a window belonging
2041 * to @widget gets broken.
2043 * On X11, this happens when the grab window becomes unviewable
2044 * (i.e. it or one of its ancestors is unmapped), or if the same
2045 * application grabs the pointer or keyboard again.
2047 * Returns: %TRUE to stop other handlers from being invoked for
2048 * the event. %FALSE to propagate the event further.
2052 widget_signals[GRAB_BROKEN] =
2053 g_signal_new (I_("grab_broken_event"),
2054 G_TYPE_FROM_CLASS (gobject_class),
2056 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2057 _gtk_boolean_handled_accumulator, NULL,
2058 _gtk_marshal_BOOLEAN__BOXED,
2060 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2062 * GtkWidget::query-tooltip:
2063 * @widget: the object which received the signal
2064 * @x: the x coordinate of the cursor position where the request has
2065 * been emitted, relative to @widget->window
2066 * @y: the y coordinate of the cursor position where the request has
2067 * been emitted, relative to @widget->window
2068 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2069 * @tooltip: a #GtkTooltip
2071 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with
2072 * the cursor hovering "above" @widget; or emitted when @widget got
2073 * focus in keyboard mode.
2075 * Using the given coordinates, the signal handler should determine
2076 * whether a tooltip should be shown for @widget. If this is the case
2077 * %TRUE should be returned, %FALSE otherwise. Note that if
2078 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2079 * should not be used.
2081 * The signal handler is free to manipulate @tooltip with the therefore
2082 * destined function calls.
2084 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2088 widget_signals[QUERY_TOOLTIP] =
2089 g_signal_new (I_("query-tooltip"),
2090 G_TYPE_FROM_CLASS (gobject_class),
2092 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2093 _gtk_boolean_handled_accumulator, NULL,
2094 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2102 * GtkWidget::popup-menu
2103 * @widget: the object which received the signal
2105 * This signal gets emitted whenever a widget should pop up a context
2106 * menu. This usually happens through the standard key binding mechanism;
2107 * by pressing a certain key while a widget is focused, the user can cause
2108 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2109 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2110 * for an example of how to use this signal.
2112 * Returns: %TRUE if a menu was activated
2114 widget_signals[POPUP_MENU] =
2115 g_signal_new (I_("popup_menu"),
2116 G_TYPE_FROM_CLASS (gobject_class),
2117 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2118 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2119 _gtk_boolean_handled_accumulator, NULL,
2120 _gtk_marshal_BOOLEAN__VOID,
2122 widget_signals[SHOW_HELP] =
2123 g_signal_new (I_("show_help"),
2124 G_TYPE_FROM_CLASS (gobject_class),
2125 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2126 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2127 _gtk_boolean_handled_accumulator, NULL,
2128 _gtk_marshal_BOOLEAN__ENUM,
2130 GTK_TYPE_WIDGET_HELP_TYPE);
2131 widget_signals[ACCEL_CLOSURES_CHANGED] =
2132 g_signal_new (I_("accel_closures_changed"),
2133 G_TYPE_FROM_CLASS (gobject_class),
2137 _gtk_marshal_NONE__NONE,
2141 * GtkWidget::screen-changed:
2142 * @widget: the object on which the signal is emitted
2143 * @previous_screen: the previous screen, or %NULL if the
2144 * widget was not associated with a screen before
2146 * The ::screen-changed signal gets emitted when the
2147 * screen of a widget has changed.
2149 widget_signals[SCREEN_CHANGED] =
2150 g_signal_new (I_("screen_changed"),
2151 G_TYPE_FROM_CLASS (gobject_class),
2153 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2155 _gtk_marshal_VOID__OBJECT,
2159 * GtkWidget::can-activate-accel:
2160 * @widget: the object which received the signal
2161 * @signal_id: the ID of a signal installed on @widget
2163 * Determines whether an accelerator that activates the signal
2164 * identified by @signal_id can currently be activated.
2165 * This signal is present to allow applications and derived
2166 * widgets to override the default #GtkWidget handling
2167 * for determining whether an accelerator can be activated.
2169 * Returns: %TRUE if the signal can be activated.
2171 widget_signals[CAN_ACTIVATE_ACCEL] =
2172 g_signal_new (I_("can_activate_accel"),
2173 G_TYPE_FROM_CLASS (gobject_class),
2175 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2176 _gtk_boolean_handled_accumulator, NULL,
2177 _gtk_marshal_BOOLEAN__UINT,
2178 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2180 binding_set = gtk_binding_set_by_class (klass);
2181 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2183 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2186 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2188 GTK_TYPE_WIDGET_HELP_TYPE,
2189 GTK_WIDGET_HELP_TOOLTIP);
2190 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2192 GTK_TYPE_WIDGET_HELP_TYPE,
2193 GTK_WIDGET_HELP_TOOLTIP);
2194 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2196 GTK_TYPE_WIDGET_HELP_TYPE,
2197 GTK_WIDGET_HELP_WHATS_THIS);
2198 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2200 GTK_TYPE_WIDGET_HELP_TYPE,
2201 GTK_WIDGET_HELP_WHATS_THIS);
2203 gtk_widget_class_install_style_property (klass,
2204 g_param_spec_boolean ("interior-focus",
2205 P_("Interior Focus"),
2206 P_("Whether to draw the focus indicator inside widgets"),
2208 GTK_PARAM_READABLE));
2210 gtk_widget_class_install_style_property (klass,
2211 g_param_spec_int ("focus-line-width",
2212 P_("Focus linewidth"),
2213 P_("Width, in pixels, of the focus indicator line"),
2215 GTK_PARAM_READABLE));
2217 gtk_widget_class_install_style_property (klass,
2218 g_param_spec_string ("focus-line-pattern",
2219 P_("Focus line dash pattern"),
2220 P_("Dash pattern used to draw the focus indicator"),
2222 GTK_PARAM_READABLE));
2223 gtk_widget_class_install_style_property (klass,
2224 g_param_spec_int ("focus-padding",
2225 P_("Focus padding"),
2226 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2228 GTK_PARAM_READABLE));
2229 gtk_widget_class_install_style_property (klass,
2230 g_param_spec_boxed ("cursor-color",
2232 P_("Color with which to draw insertion cursor"),
2234 GTK_PARAM_READABLE));
2235 gtk_widget_class_install_style_property (klass,
2236 g_param_spec_boxed ("secondary-cursor-color",
2237 P_("Secondary cursor color"),
2238 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2240 GTK_PARAM_READABLE));
2241 gtk_widget_class_install_style_property (klass,
2242 g_param_spec_float ("cursor-aspect-ratio",
2243 P_("Cursor line aspect ratio"),
2244 P_("Aspect ratio with which to draw insertion cursor"),
2246 GTK_PARAM_READABLE));
2249 * GtkWidget:draw-border:
2251 * The "draw-border" style property defines the size of areas outside
2252 * the widget's allocation to draw.
2256 gtk_widget_class_install_style_property (klass,
2257 g_param_spec_boxed ("draw-border",
2259 P_("Size of areas outside the widget's allocation to draw"),
2261 GTK_PARAM_READABLE));
2264 * GtkWidget:link-color:
2266 * The "link-color" style property defines the color of unvisited links.
2270 gtk_widget_class_install_style_property (klass,
2271 g_param_spec_boxed ("link-color",
2272 P_("Unvisited Link Color"),
2273 P_("Color of unvisited links"),
2275 GTK_PARAM_READABLE));
2278 * GtkWidget:visited-link-color:
2280 * The "visited-link-color" style property defines the color of visited links.
2284 gtk_widget_class_install_style_property (klass,
2285 g_param_spec_boxed ("visited-link-color",
2286 P_("Visited Link Color"),
2287 P_("Color of visited links"),
2289 GTK_PARAM_READABLE));
2292 * GtkWidget:wide-separators:
2294 * The "wide-separators" style property defines whether separators have
2295 * configurable width and should be drawn using a box instead of a line.
2299 gtk_widget_class_install_style_property (klass,
2300 g_param_spec_boolean ("wide-separators",
2301 P_("Wide Separators"),
2302 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2304 GTK_PARAM_READABLE));
2307 * GtkWidget:separator-width:
2309 * The "separator-width" style property defines the width of separators.
2310 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2314 gtk_widget_class_install_style_property (klass,
2315 g_param_spec_int ("separator-width",
2316 P_("Separator Width"),
2317 P_("The width of separators if wide-separators is TRUE"),
2319 GTK_PARAM_READABLE));
2322 * GtkWidget:separator-height:
2324 * The "separator-height" style property defines the height of separators.
2325 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2329 gtk_widget_class_install_style_property (klass,
2330 g_param_spec_int ("separator-height",
2331 P_("Separator Height"),
2332 P_("The height of separators if \"wide-separators\" is TRUE"),
2334 GTK_PARAM_READABLE));
2337 * GtkWidget:scroll-arrow-hlength:
2339 * The "scroll-arrow-hlength" style property defines the length of
2340 * horizontal scroll arrows.
2344 gtk_widget_class_install_style_property (klass,
2345 g_param_spec_int ("scroll-arrow-hlength",
2346 P_("Horizontal Scroll Arrow Length"),
2347 P_("The length of horizontal scroll arrows"),
2349 GTK_PARAM_READABLE));
2352 * GtkWidget:scroll-arrow-vlength:
2354 * The "scroll-arrow-vlength" style property defines the length of
2355 * vertical scroll arrows.
2359 gtk_widget_class_install_style_property (klass,
2360 g_param_spec_int ("scroll-arrow-vlength",
2361 P_("Vertical Scroll Arrow Length"),
2362 P_("The length of vertical scroll arrows"),
2364 GTK_PARAM_READABLE));
2368 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2372 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2373 for (node = list; node; node = node->next)
2375 GParamSpec *pspec = node->data;
2377 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2378 g_param_spec_unref (pspec);
2384 gtk_widget_set_property (GObject *object,
2386 const GValue *value,
2389 GtkWidget *widget = GTK_WIDGET (object);
2394 guint32 saved_flags;
2395 gchar *tooltip_markup;
2396 const gchar *tooltip_text;
2397 GtkWindow *tooltip_window;
2400 gtk_widget_set_name (widget, g_value_get_string (value));
2403 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2405 case PROP_WIDTH_REQUEST:
2406 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2408 case PROP_HEIGHT_REQUEST:
2409 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2412 if (g_value_get_boolean (value))
2413 gtk_widget_show (widget);
2415 gtk_widget_hide (widget);
2417 case PROP_SENSITIVE:
2418 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2420 case PROP_APP_PAINTABLE:
2421 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2423 case PROP_CAN_FOCUS:
2424 saved_flags = GTK_WIDGET_FLAGS (widget);
2425 if (g_value_get_boolean (value))
2426 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2428 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2429 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2430 gtk_widget_queue_resize (widget);
2432 case PROP_HAS_FOCUS:
2433 if (g_value_get_boolean (value))
2434 gtk_widget_grab_focus (widget);
2437 if (g_value_get_boolean (value))
2438 gtk_widget_grab_focus (widget);
2440 case PROP_CAN_DEFAULT:
2441 saved_flags = GTK_WIDGET_FLAGS (widget);
2442 if (g_value_get_boolean (value))
2443 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2445 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2446 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2447 gtk_widget_queue_resize (widget);
2449 case PROP_HAS_DEFAULT:
2450 if (g_value_get_boolean (value))
2451 gtk_widget_grab_default (widget);
2453 case PROP_RECEIVES_DEFAULT:
2454 if (g_value_get_boolean (value))
2455 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2457 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2460 gtk_widget_set_style (widget, g_value_get_object (value));
2463 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2464 gtk_widget_set_events (widget, g_value_get_flags (value));
2466 case PROP_EXTENSION_EVENTS:
2467 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2469 case PROP_NO_SHOW_ALL:
2470 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2472 case PROP_HAS_TOOLTIP:
2473 gtk_widget_real_set_has_tooltip (widget,
2474 g_value_get_boolean (value), FALSE);
2476 case PROP_TOOLTIP_MARKUP:
2477 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2478 tooltip_markup = g_value_dup_string (value);
2480 g_object_set_qdata_full (object, quark_tooltip_markup,
2481 tooltip_markup, g_free);
2483 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2484 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2486 case PROP_TOOLTIP_TEXT:
2487 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2488 tooltip_text = g_value_get_string (value);
2489 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2491 g_object_set_qdata_full (object, quark_tooltip_markup,
2492 tooltip_markup, g_free);
2494 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2495 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2498 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2504 gtk_widget_get_property (GObject *object,
2509 GtkWidget *widget = GTK_WIDGET (object);
2518 g_value_set_string (value, widget->name);
2520 g_value_set_static_string (value, "");
2524 g_value_set_object (value, widget->parent);
2526 g_value_set_object (value, NULL);
2528 case PROP_WIDTH_REQUEST:
2531 gtk_widget_get_size_request (widget, &w, NULL);
2532 g_value_set_int (value, w);
2535 case PROP_HEIGHT_REQUEST:
2538 gtk_widget_get_size_request (widget, NULL, &h);
2539 g_value_set_int (value, h);
2543 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2545 case PROP_SENSITIVE:
2546 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2548 case PROP_APP_PAINTABLE:
2549 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2551 case PROP_CAN_FOCUS:
2552 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2554 case PROP_HAS_FOCUS:
2555 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2558 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2560 case PROP_CAN_DEFAULT:
2561 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2563 case PROP_HAS_DEFAULT:
2564 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2566 case PROP_RECEIVES_DEFAULT:
2567 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2569 case PROP_COMPOSITE_CHILD:
2570 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2573 g_value_set_object (value, gtk_widget_get_style (widget));
2576 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2577 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2579 case PROP_EXTENSION_EVENTS:
2580 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2581 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2583 case PROP_NO_SHOW_ALL:
2584 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2586 case PROP_HAS_TOOLTIP:
2587 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2589 case PROP_TOOLTIP_TEXT:
2591 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2594 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2595 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2597 g_value_set_string (value, text);
2601 case PROP_TOOLTIP_MARKUP:
2602 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2605 g_value_set_object (value, gtk_widget_get_window (widget));
2608 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2614 gtk_widget_init (GtkWidget *widget)
2616 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2617 widget->state = GTK_STATE_NORMAL;
2618 widget->saved_state = GTK_STATE_NORMAL;
2619 widget->name = NULL;
2620 widget->requisition.width = 0;
2621 widget->requisition.height = 0;
2622 widget->allocation.x = -1;
2623 widget->allocation.y = -1;
2624 widget->allocation.width = 1;
2625 widget->allocation.height = 1;
2626 widget->window = NULL;
2627 widget->parent = NULL;
2629 GTK_WIDGET_SET_FLAGS (widget,
2631 GTK_PARENT_SENSITIVE |
2632 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2633 GTK_DOUBLE_BUFFERED);
2635 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2636 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2637 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2639 widget->style = gtk_widget_get_default_style ();
2640 g_object_ref (widget->style);
2645 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2647 GParamSpec **pspecs)
2649 GtkWidget *container = widget->parent;
2652 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2653 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2657 * gtk_widget_freeze_child_notify:
2658 * @widget: a #GtkWidget
2660 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2661 * signals are queued until gtk_widget_thaw_child_notify() is called
2664 * This is the analogue of g_object_freeze_notify() for child properties.
2667 gtk_widget_freeze_child_notify (GtkWidget *widget)
2669 g_return_if_fail (GTK_IS_WIDGET (widget));
2671 if (!G_OBJECT (widget)->ref_count)
2674 g_object_ref (widget);
2675 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2676 g_object_unref (widget);
2680 * gtk_widget_child_notify:
2681 * @widget: a #GtkWidget
2682 * @child_property: the name of a child property installed on the
2683 * class of @widget<!-- -->'s parent
2685 * Emits a #GtkWidget::child-notify signal for the
2686 * <link linkend="child-properties">child property</link> @child_property
2689 * This is the analogue of g_object_notify() for child properties.
2692 gtk_widget_child_notify (GtkWidget *widget,
2693 const gchar *child_property)
2697 g_return_if_fail (GTK_IS_WIDGET (widget));
2698 g_return_if_fail (child_property != NULL);
2699 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2702 g_object_ref (widget);
2703 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2705 G_OBJECT_TYPE (widget->parent),
2708 g_warning ("%s: container class `%s' has no child property named `%s'",
2710 G_OBJECT_TYPE_NAME (widget->parent),
2714 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2716 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2717 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2719 g_object_unref (widget);
2723 * gtk_widget_thaw_child_notify:
2724 * @widget: a #GtkWidget
2726 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2727 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2731 gtk_widget_thaw_child_notify (GtkWidget *widget)
2733 GObjectNotifyQueue *nqueue;
2735 g_return_if_fail (GTK_IS_WIDGET (widget));
2737 if (!G_OBJECT (widget)->ref_count)
2740 g_object_ref (widget);
2741 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2742 if (!nqueue || !nqueue->freeze_count)
2743 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2744 G_OBJECT_TYPE_NAME (widget), widget);
2746 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2747 g_object_unref (widget);
2753 * @type: type ID of the widget to create
2754 * @first_property_name: name of first property to set
2755 * @Varargs: value of first property, followed by more properties,
2758 * This is a convenience function for creating a widget and setting
2759 * its properties in one go. For example you might write:
2760 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2761 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2762 * g_object_new(), but returns a widget so you don't have to
2763 * cast the object yourself.
2765 * Return value: a new #GtkWidget of type @widget_type
2768 gtk_widget_new (GType type,
2769 const gchar *first_property_name,
2775 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2777 va_start (var_args, first_property_name);
2778 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2786 * @widget: a #GtkWidget
2787 * @first_property_name: name of first property to set
2788 * @Varargs: value of first property, followed by more properties,
2791 * Precursor of g_object_set().
2793 * Deprecated: 2.0: Use g_object_set() instead.
2796 gtk_widget_set (GtkWidget *widget,
2797 const gchar *first_property_name,
2802 g_return_if_fail (GTK_IS_WIDGET (widget));
2804 va_start (var_args, first_property_name);
2805 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2810 gtk_widget_queue_draw_child (GtkWidget *widget)
2814 parent = widget->parent;
2815 if (parent && GTK_WIDGET_DRAWABLE (parent))
2816 gtk_widget_queue_draw_area (parent,
2817 widget->allocation.x,
2818 widget->allocation.y,
2819 widget->allocation.width,
2820 widget->allocation.height);
2824 * gtk_widget_unparent:
2825 * @widget: a #GtkWidget
2827 * This function is only for use in widget implementations.
2828 * Should be called by implementations of the remove method
2829 * on #GtkContainer, to dissociate a child from the container.
2832 gtk_widget_unparent (GtkWidget *widget)
2834 GObjectNotifyQueue *nqueue;
2835 GtkWidget *toplevel;
2836 GtkWidget *old_parent;
2838 g_return_if_fail (GTK_IS_WIDGET (widget));
2839 if (widget->parent == NULL)
2842 /* keep this function in sync with gtk_menu_detach()
2845 g_object_freeze_notify (G_OBJECT (widget));
2846 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2848 toplevel = gtk_widget_get_toplevel (widget);
2849 if (GTK_WIDGET_TOPLEVEL (toplevel))
2850 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2852 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2853 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2855 /* If we are unanchoring the child, we save around the toplevel
2856 * to emit hierarchy changed
2858 if (GTK_WIDGET_ANCHORED (widget->parent))
2859 g_object_ref (toplevel);
2863 gtk_widget_queue_draw_child (widget);
2865 /* Reset the width and height here, to force reallocation if we
2866 * get added back to a new parent. This won't work if our new
2867 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2868 * (would 0x0 be OK here?)
2870 widget->allocation.width = 1;
2871 widget->allocation.height = 1;
2873 if (GTK_WIDGET_REALIZED (widget))
2875 if (GTK_WIDGET_IN_REPARENT (widget))
2876 gtk_widget_unmap (widget);
2878 gtk_widget_unrealize (widget);
2881 /* Removing a widget from a container restores the child visible
2882 * flag to the default state, so it doesn't affect the child
2883 * in the next parent.
2885 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2887 old_parent = widget->parent;
2888 widget->parent = NULL;
2889 gtk_widget_set_parent_window (widget, NULL);
2890 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2893 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2894 g_object_unref (toplevel);
2897 g_object_notify (G_OBJECT (widget), "parent");
2898 g_object_thaw_notify (G_OBJECT (widget));
2899 if (!widget->parent)
2900 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2901 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2902 g_object_unref (widget);
2906 * gtk_widget_destroy:
2907 * @widget: a #GtkWidget
2909 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2910 * you don't have to cast the widget to #GtkObject. When a widget is
2911 * destroyed, it will break any references it holds to other objects.
2912 * If the widget is inside a container, the widget will be removed
2913 * from the container. If the widget is a toplevel (derived from
2914 * #GtkWindow), it will be removed from the list of toplevels, and the
2915 * reference GTK+ holds to it will be removed. Removing a
2916 * widget from its container or the list of toplevels results in the
2917 * widget being finalized, unless you've added additional references
2918 * to the widget with g_object_ref().
2920 * In most cases, only toplevel widgets (windows) require explicit
2921 * destruction, because when you destroy a toplevel its children will
2922 * be destroyed as well.
2925 gtk_widget_destroy (GtkWidget *widget)
2927 g_return_if_fail (GTK_IS_WIDGET (widget));
2929 gtk_object_destroy ((GtkObject*) widget);
2933 * gtk_widget_destroyed:
2934 * @widget: a #GtkWidget
2935 * @widget_pointer: address of a variable that contains @widget
2937 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2938 * %NULL. It's intended to be used as a callback connected to the
2939 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2940 * as a signal handler, and pass the address of your widget variable
2941 * as user data. Then when the widget is destroyed, the variable will
2942 * be set to %NULL. Useful for example to avoid multiple copies
2943 * of the same dialog.
2946 gtk_widget_destroyed (GtkWidget *widget,
2947 GtkWidget **widget_pointer)
2949 /* Don't make any assumptions about the
2951 * Even check widget_pointer.
2954 *widget_pointer = NULL;
2959 * @widget: a #GtkWidget
2961 * Flags a widget to be displayed. Any widget that isn't shown will
2962 * not appear on the screen. If you want to show all the widgets in a
2963 * container, it's easier to call gtk_widget_show_all() on the
2964 * container, instead of individually showing the widgets.
2966 * Remember that you have to show the containers containing a widget,
2967 * in addition to the widget itself, before it will appear onscreen.
2969 * When a toplevel container is shown, it is immediately realized and
2970 * mapped; other shown widgets are realized and mapped when their
2971 * toplevel container is realized and mapped.
2974 gtk_widget_show (GtkWidget *widget)
2976 g_return_if_fail (GTK_IS_WIDGET (widget));
2978 if (!GTK_WIDGET_VISIBLE (widget))
2980 g_object_ref (widget);
2981 if (!GTK_WIDGET_TOPLEVEL (widget))
2982 gtk_widget_queue_resize (widget);
2983 g_signal_emit (widget, widget_signals[SHOW], 0);
2984 g_object_notify (G_OBJECT (widget), "visible");
2985 g_object_unref (widget);
2990 gtk_widget_real_show (GtkWidget *widget)
2992 if (!GTK_WIDGET_VISIBLE (widget))
2994 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2996 if (widget->parent &&
2997 GTK_WIDGET_MAPPED (widget->parent) &&
2998 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2999 !GTK_WIDGET_MAPPED (widget))
3000 gtk_widget_map (widget);
3005 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3008 g_signal_handlers_disconnect_by_func (widget,
3009 gtk_widget_show_map_callback,
3014 * gtk_widget_show_now:
3015 * @widget: a #GtkWidget
3017 * Shows a widget. If the widget is an unmapped toplevel widget
3018 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3019 * loop and wait for the window to actually be mapped. Be careful;
3020 * because the main loop is running, anything can happen during
3024 gtk_widget_show_now (GtkWidget *widget)
3028 g_return_if_fail (GTK_IS_WIDGET (widget));
3030 /* make sure we will get event */
3031 if (!GTK_WIDGET_MAPPED (widget) &&
3032 GTK_WIDGET_TOPLEVEL (widget))
3034 gtk_widget_show (widget);
3036 g_signal_connect (widget, "map_event",
3037 G_CALLBACK (gtk_widget_show_map_callback),
3041 gtk_main_iteration ();
3044 gtk_widget_show (widget);
3049 * @widget: a #GtkWidget
3051 * Reverses the effects of gtk_widget_show(), causing the widget to be
3052 * hidden (invisible to the user).
3055 gtk_widget_hide (GtkWidget *widget)
3057 g_return_if_fail (GTK_IS_WIDGET (widget));
3059 if (GTK_WIDGET_VISIBLE (widget))
3061 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3063 g_object_ref (widget);
3064 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3065 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3067 g_signal_emit (widget, widget_signals[HIDE], 0);
3068 if (!GTK_WIDGET_TOPLEVEL (widget))
3069 gtk_widget_queue_resize (widget);
3070 g_object_notify (G_OBJECT (widget), "visible");
3071 g_object_unref (widget);
3076 gtk_widget_real_hide (GtkWidget *widget)
3078 if (GTK_WIDGET_VISIBLE (widget))
3080 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3082 if (GTK_WIDGET_MAPPED (widget))
3083 gtk_widget_unmap (widget);
3088 * gtk_widget_hide_on_delete:
3089 * @widget: a #GtkWidget
3091 * Utility function; intended to be connected to the #GtkWidget::delete-event
3092 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3093 * argument, then returns %TRUE. If connected to ::delete-event, the
3094 * result is that clicking the close button for a window (on the
3095 * window frame, top right corner usually) will hide but not destroy
3096 * the window. By default, GTK+ destroys windows when ::delete-event
3099 * Return value: %TRUE
3102 gtk_widget_hide_on_delete (GtkWidget *widget)
3104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3106 gtk_widget_hide (widget);
3112 * gtk_widget_show_all:
3113 * @widget: a #GtkWidget
3115 * Recursively shows a widget, and any child widgets (if the widget is
3119 gtk_widget_show_all (GtkWidget *widget)
3121 GtkWidgetClass *class;
3123 g_return_if_fail (GTK_IS_WIDGET (widget));
3125 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3128 class = GTK_WIDGET_GET_CLASS (widget);
3130 if (class->show_all)
3131 class->show_all (widget);
3135 * gtk_widget_hide_all:
3136 * @widget: a #GtkWidget
3138 * Recursively hides a widget and any child widgets.
3141 gtk_widget_hide_all (GtkWidget *widget)
3143 GtkWidgetClass *class;
3145 g_return_if_fail (GTK_IS_WIDGET (widget));
3147 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3150 class = GTK_WIDGET_GET_CLASS (widget);
3152 if (class->hide_all)
3153 class->hide_all (widget);
3158 * @widget: a #GtkWidget
3160 * This function is only for use in widget implementations. Causes
3161 * a widget to be mapped if it isn't already.
3164 gtk_widget_map (GtkWidget *widget)
3166 g_return_if_fail (GTK_IS_WIDGET (widget));
3167 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3168 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3170 if (!GTK_WIDGET_MAPPED (widget))
3172 if (!GTK_WIDGET_REALIZED (widget))
3173 gtk_widget_realize (widget);
3175 g_signal_emit (widget, widget_signals[MAP], 0);
3177 if (GTK_WIDGET_NO_WINDOW (widget))
3178 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3184 * @widget: a #GtkWidget
3186 * This function is only for use in widget implementations. Causes
3187 * a widget to be unmapped if it's currently mapped.
3190 gtk_widget_unmap (GtkWidget *widget)
3192 g_return_if_fail (GTK_IS_WIDGET (widget));
3194 if (GTK_WIDGET_MAPPED (widget))
3196 if (GTK_WIDGET_NO_WINDOW (widget))
3197 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3198 _gtk_tooltip_hide (widget);
3199 g_signal_emit (widget, widget_signals[UNMAP], 0);
3204 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3205 GdkExtensionMode mode,
3208 GList *free_list = NULL;
3211 if (window_list == NULL)
3213 if (!GTK_WIDGET_NO_WINDOW (widget))
3214 window_list = g_list_prepend (NULL, widget->window);
3216 window_list = gdk_window_get_children (widget->window);
3218 free_list = window_list;
3221 for (l = window_list; l != NULL; l = l->next)
3223 GdkWindow *window = l->data;
3226 gdk_window_get_user_data (window, &user_data);
3227 if (user_data == widget)
3231 gdk_input_set_extension_events (window,
3232 gdk_window_get_events (window),
3235 children = gdk_window_get_children (window);
3238 gtk_widget_set_extension_events_internal (widget, mode, children);
3239 g_list_free (children);
3245 g_list_free (free_list);
3249 * gtk_widget_realize:
3250 * @widget: a #GtkWidget
3252 * Creates the GDK (windowing system) resources associated with a
3253 * widget. For example, @widget->window will be created when a widget
3254 * is realized. Normally realization happens implicitly; if you show
3255 * a widget and all its parent containers, then the widget will be
3256 * realized and mapped automatically.
3258 * Realizing a widget requires all
3259 * the widget's parent widgets to be realized; calling
3260 * gtk_widget_realize() realizes the widget's parents in addition to
3261 * @widget itself. If a widget is not yet inside a toplevel window
3262 * when you realize it, bad things will happen.
3264 * This function is primarily used in widget implementations, and
3265 * isn't very useful otherwise. Many times when you think you might
3266 * need it, a better approach is to connect to a signal that will be
3267 * called after the widget is realized automatically, such as
3268 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3269 * GtkWidget::realize signal.
3272 gtk_widget_realize (GtkWidget *widget)
3274 GdkExtensionMode mode;
3275 GtkWidgetShapeInfo *shape_info;
3277 g_return_if_fail (GTK_IS_WIDGET (widget));
3278 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3279 GTK_IS_INVISIBLE (widget));
3281 if (!GTK_WIDGET_REALIZED (widget))
3284 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3285 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3288 if (widget->parent == NULL &&
3289 !GTK_WIDGET_TOPLEVEL (widget))
3290 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3291 "inside a toplevel window is not going to work very well. "
3292 "Widgets must be inside a toplevel container before realizing them.");
3294 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3295 gtk_widget_realize (widget->parent);
3297 gtk_widget_ensure_style (widget);
3299 g_signal_emit (widget, widget_signals[REALIZE], 0);
3301 gtk_widget_real_set_has_tooltip (widget,
3302 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3305 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3307 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3308 gdk_window_shape_combine_mask (widget->window,
3309 shape_info->shape_mask,
3310 shape_info->offset_x,
3311 shape_info->offset_y);
3314 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3316 gdk_window_input_shape_combine_mask (widget->window,
3317 shape_info->shape_mask,
3318 shape_info->offset_x,
3319 shape_info->offset_y);
3321 mode = gtk_widget_get_extension_events (widget);
3322 if (mode != GDK_EXTENSION_EVENTS_NONE)
3323 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3328 * gtk_widget_unrealize:
3329 * @widget: a #GtkWidget
3331 * This function is only useful in widget implementations.
3332 * Causes a widget to be unrealized (frees all GDK resources
3333 * associated with the widget, such as @widget->window).
3336 gtk_widget_unrealize (GtkWidget *widget)
3338 g_return_if_fail (GTK_IS_WIDGET (widget));
3340 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3341 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3343 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3344 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3346 if (GTK_WIDGET_REALIZED (widget))
3348 g_object_ref (widget);
3349 _gtk_tooltip_hide (widget);
3350 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3351 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3352 g_object_unref (widget);
3356 /*****************************************
3358 *****************************************/
3361 * gtk_widget_queue_draw_area:
3362 * @widget: a #GtkWidget
3363 * @x: x coordinate of upper-left corner of rectangle to redraw
3364 * @y: y coordinate of upper-left corner of rectangle to redraw
3365 * @width: width of region to draw
3366 * @height: height of region to draw
3368 * Invalidates the rectangular area of @widget defined by @x, @y,
3369 * @width and @height by calling gdk_window_invalidate_rect() on the
3370 * widget's window and all its child windows. Once the main loop
3371 * becomes idle (after the current batch of events has been processed,
3372 * roughly), the window will receive expose events for the union of
3373 * all regions that have been invalidated.
3375 * Normally you would only use this function in widget
3376 * implementations. You might also use it, or
3377 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3378 * #GtkDrawingArea or some portion thereof.
3380 * Frequently you can just call gdk_window_invalidate_rect() or
3381 * gdk_window_invalidate_region() instead of this function. Those
3382 * functions will invalidate only a single window, instead of the
3383 * widget and all its children.
3385 * The advantage of adding to the invalidated region compared to
3386 * simply drawing immediately is efficiency; using an invalid region
3387 * ensures that you only have to redraw one time.
3390 gtk_widget_queue_draw_area (GtkWidget *widget,
3396 GdkRectangle invalid_rect;
3399 g_return_if_fail (GTK_IS_WIDGET (widget));
3401 if (!GTK_WIDGET_REALIZED (widget))
3404 /* Just return if the widget or one of its ancestors isn't mapped */
3405 for (w = widget; w != NULL; w = w->parent)
3406 if (!GTK_WIDGET_MAPPED (w))
3409 /* Find the correct widget */
3411 if (!GTK_WIDGET_NO_WINDOW (widget))
3415 /* Translate widget relative to window-relative */
3417 gint wx, wy, wwidth, wheight;
3419 gdk_window_get_position (widget->window, &wx, &wy);
3420 x -= wx - widget->allocation.x;
3421 y -= wy - widget->allocation.y;
3423 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3425 if (x + width <= 0 || y + height <= 0 ||
3426 x >= wwidth || y >= wheight)
3437 if (x + width > wwidth)
3439 if (y + height > wheight)
3440 height = wheight - y;
3446 invalid_rect.width = width;
3447 invalid_rect.height = height;
3449 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3453 widget_add_child_draw_rectangle (GtkWidget *widget,
3456 GdkRectangle child_rect;
3458 if (!GTK_WIDGET_MAPPED (widget) ||
3459 widget->window != widget->parent->window)
3462 gtk_widget_get_draw_rectangle (widget, &child_rect);
3463 gdk_rectangle_union (rect, &child_rect, rect);
3467 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3470 if (GTK_WIDGET_NO_WINDOW (widget))
3472 GtkBorder *draw_border = NULL;
3474 *rect = widget->allocation;
3476 gtk_widget_style_get (widget,
3477 "draw-border", &draw_border,
3481 rect->x -= draw_border->top;
3482 rect->y -= draw_border->left;
3483 rect->width += draw_border->left + draw_border->right;
3484 rect->height += draw_border->top + draw_border->bottom;
3486 gtk_border_free (draw_border);
3489 if (GTK_IS_CONTAINER (widget))
3490 gtk_container_forall (GTK_CONTAINER (widget),
3491 (GtkCallback)widget_add_child_draw_rectangle,
3498 rect->width = widget->allocation.width;
3499 rect->height = widget->allocation.height;
3504 * gtk_widget_queue_draw:
3505 * @widget: a #GtkWidget
3507 * Equivalent to calling gtk_widget_queue_draw_area() for the
3508 * entire area of a widget.
3511 gtk_widget_queue_draw (GtkWidget *widget)
3515 g_return_if_fail (GTK_IS_WIDGET (widget));
3517 gtk_widget_get_draw_rectangle (widget, &rect);
3519 gtk_widget_queue_draw_area (widget,
3521 rect.width, rect.height);
3524 /* Invalidates the given area (allocation-relative-coordinates)
3525 * in all of the widget's windows
3528 * gtk_widget_queue_clear_area:
3529 * @widget: a #GtkWidget
3530 * @x: x coordinate of upper-left corner of rectangle to redraw
3531 * @y: y coordinate of upper-left corner of rectangle to redraw
3532 * @width: width of region to draw
3533 * @height: height of region to draw
3535 * This function is no longer different from
3536 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3537 * gtk_widget_queue_draw_area(). Originally
3538 * gtk_widget_queue_clear_area() would force a redraw of the
3539 * background for %GTK_NO_WINDOW widgets, and
3540 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3541 * the background will be redrawn.
3543 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3546 gtk_widget_queue_clear_area (GtkWidget *widget,
3552 g_return_if_fail (GTK_IS_WIDGET (widget));
3554 gtk_widget_queue_draw_area (widget, x, y, width, height);
3558 * gtk_widget_queue_clear:
3559 * @widget: a #GtkWidget
3561 * This function does the same as gtk_widget_queue_draw().
3563 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3566 gtk_widget_queue_clear (GtkWidget *widget)
3568 g_return_if_fail (GTK_IS_WIDGET (widget));
3570 gtk_widget_queue_draw (widget);
3574 * gtk_widget_queue_resize:
3575 * @widget: a #GtkWidget
3577 * This function is only for use in widget implementations.
3578 * Flags a widget to have its size renegotiated; should
3579 * be called when a widget for some reason has a new size request.
3580 * For example, when you change the text in a #GtkLabel, #GtkLabel
3581 * queues a resize to ensure there's enough space for the new text.
3584 gtk_widget_queue_resize (GtkWidget *widget)
3586 g_return_if_fail (GTK_IS_WIDGET (widget));
3588 if (GTK_WIDGET_REALIZED (widget))
3589 gtk_widget_queue_shallow_draw (widget);
3591 _gtk_size_group_queue_resize (widget);
3595 * gtk_widget_queue_resize_no_redraw:
3596 * @widget: a #GtkWidget
3598 * This function works like gtk_widget_queue_resize(),
3599 * except that the widget is not invalidated.
3604 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3606 g_return_if_fail (GTK_IS_WIDGET (widget));
3608 _gtk_size_group_queue_resize (widget);
3613 * @widget: a #GtkWidget
3614 * @area: area to draw
3616 * In GTK+ 1.2, this function would immediately render the
3617 * region @area of a widget, by invoking the virtual draw method of a
3618 * widget. In GTK+ 2.0, the draw method is gone, and instead
3619 * gtk_widget_draw() simply invalidates the specified region of the
3620 * widget, then updates the invalid region of the widget immediately.
3621 * Usually you don't want to update the region immediately for
3622 * performance reasons, so in general gtk_widget_queue_draw_area() is
3623 * a better choice if you want to draw a region of a widget.
3626 gtk_widget_draw (GtkWidget *widget,
3627 const GdkRectangle *area)
3629 g_return_if_fail (GTK_IS_WIDGET (widget));
3631 if (GTK_WIDGET_DRAWABLE (widget))
3634 gtk_widget_queue_draw_area (widget,
3636 area->width, area->height);
3638 gtk_widget_queue_draw (widget);
3640 gdk_window_process_updates (widget->window, TRUE);
3645 * gtk_widget_size_request:
3646 * @widget: a #GtkWidget
3647 * @requisition: a #GtkRequisition to be filled in
3649 * This function is typically used when implementing a #GtkContainer
3650 * subclass. Obtains the preferred size of a widget. The container
3651 * uses this information to arrange its child widgets and decide what
3652 * size allocations to give them with gtk_widget_size_allocate().
3654 * You can also call this function from an application, with some
3655 * caveats. Most notably, getting a size request requires the widget
3656 * to be associated with a screen, because font information may be
3657 * needed. Multihead-aware applications should keep this in mind.
3659 * Also remember that the size request is not necessarily the size
3660 * a widget will actually be allocated.
3662 * See also gtk_widget_get_child_requisition().
3665 gtk_widget_size_request (GtkWidget *widget,
3666 GtkRequisition *requisition)
3668 g_return_if_fail (GTK_IS_WIDGET (widget));
3670 #ifdef G_ENABLE_DEBUG
3671 if (requisition == &widget->requisition)
3672 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.");
3673 #endif /* G_ENABLE_DEBUG */
3675 _gtk_size_group_compute_requisition (widget, requisition);
3679 * gtk_widget_get_child_requisition:
3680 * @widget: a #GtkWidget
3681 * @requisition: a #GtkRequisition to be filled in
3683 * This function is only for use in widget implementations. Obtains
3684 * @widget->requisition, unless someone has forced a particular
3685 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3686 * in which case it returns that geometry instead of the widget's
3689 * This function differs from gtk_widget_size_request() in that
3690 * it retrieves the last size request value from @widget->requisition,
3691 * while gtk_widget_size_request() actually calls the "size_request" method
3692 * on @widget to compute the size request and fill in @widget->requisition,
3693 * and only then returns @widget->requisition.
3695 * Because this function does not call the "size_request" method, it
3696 * can only be used when you know that @widget->requisition is
3697 * up-to-date, that is, gtk_widget_size_request() has been called
3698 * since the last time a resize was queued. In general, only container
3699 * implementations have this information; applications should use
3700 * gtk_widget_size_request().
3703 gtk_widget_get_child_requisition (GtkWidget *widget,
3704 GtkRequisition *requisition)
3706 _gtk_size_group_get_child_requisition (widget, requisition);
3710 invalidate_predicate (GdkWindow *window,
3715 gdk_window_get_user_data (window, &user_data);
3717 return (user_data == data);
3720 /* Invalidate @region in widget->window and all children
3721 * of widget->window owned by widget. @region is in the
3722 * same coordinates as widget->allocation and will be
3723 * modified by this call.
3726 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3729 if (!GTK_WIDGET_REALIZED (widget))
3732 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3736 gdk_window_get_position (widget->window, &x, &y);
3737 gdk_region_offset (region, -x, -y);
3740 gdk_window_invalidate_maybe_recurse (widget->window, region,
3741 invalidate_predicate, widget);
3745 * gtk_widget_queue_shallow_draw:
3746 * @widget: a #GtkWidget
3748 * Like gtk_widget_queue_draw(), but only windows owned
3749 * by @widget are invalidated.
3752 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3757 if (!GTK_WIDGET_REALIZED (widget))
3760 gtk_widget_get_draw_rectangle (widget, &rect);
3762 /* get_draw_rectangle() gives us window coordinates, we
3763 * need to convert to the coordinates that widget->allocation
3766 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3770 gdk_window_get_position (widget->window, &wx, &wy);
3776 region = gdk_region_rectangle (&rect);
3777 gtk_widget_invalidate_widget_windows (widget, region);
3778 gdk_region_destroy (region);
3782 * gtk_widget_size_allocate:
3783 * @widget: a #GtkWidget
3784 * @allocation: position and size to be allocated to @widget
3786 * This function is only used by #GtkContainer subclasses, to assign a size
3787 * and position to their child widgets.
3790 gtk_widget_size_allocate (GtkWidget *widget,
3791 GtkAllocation *allocation)
3793 GtkWidgetAuxInfo *aux_info;
3794 GdkRectangle real_allocation;
3795 GdkRectangle old_allocation;
3796 gboolean alloc_needed;
3797 gboolean size_changed;
3798 gboolean position_changed;
3800 g_return_if_fail (GTK_IS_WIDGET (widget));
3802 #ifdef G_ENABLE_DEBUG
3803 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3814 parent = gtk_widget_get_parent (parent);
3817 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3818 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3819 2 * depth, " ", name,
3820 allocation->width, allocation->height);
3822 #endif /* G_ENABLE_DEBUG */
3824 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3825 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3826 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3828 old_allocation = widget->allocation;
3829 real_allocation = *allocation;
3830 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3834 if (aux_info->x_set)
3835 real_allocation.x = aux_info->x;
3836 if (aux_info->y_set)
3837 real_allocation.y = aux_info->y;
3840 if (real_allocation.width < 0 || real_allocation.height < 0)
3842 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3843 real_allocation.width,
3844 real_allocation.height);
3847 real_allocation.width = MAX (real_allocation.width, 1);
3848 real_allocation.height = MAX (real_allocation.height, 1);
3850 size_changed = (old_allocation.width != real_allocation.width ||
3851 old_allocation.height != real_allocation.height);
3852 position_changed = (old_allocation.x != real_allocation.x ||
3853 old_allocation.y != real_allocation.y);
3855 if (!alloc_needed && !size_changed && !position_changed)
3858 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3860 if (GTK_WIDGET_MAPPED (widget))
3862 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3864 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3866 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3867 gdk_region_union_with_rect (invalidate, &old_allocation);
3869 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3870 gdk_region_destroy (invalidate);
3875 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3877 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3879 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3880 gdk_region_union_with_rect (invalidate, &old_allocation);
3882 gtk_widget_invalidate_widget_windows (widget, invalidate);
3883 gdk_region_destroy (invalidate);
3888 if ((size_changed || position_changed) && widget->parent &&
3889 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3891 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3892 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3893 gdk_region_destroy (invalidate);
3898 * gtk_widget_common_ancestor:
3899 * @widget_a: a #GtkWidget
3900 * @widget_b: a #GtkWidget
3902 * Find the common ancestor of @widget_a and @widget_b that
3903 * is closest to the two widgets.
3905 * Return value: the closest common ancestor of @widget_a and
3906 * @widget_b or %NULL if @widget_a and @widget_b do not
3907 * share a common ancestor.
3910 gtk_widget_common_ancestor (GtkWidget *widget_a,
3911 GtkWidget *widget_b)
3913 GtkWidget *parent_a;
3914 GtkWidget *parent_b;
3918 parent_a = widget_a;
3919 while (parent_a->parent)
3921 parent_a = parent_a->parent;
3925 parent_b = widget_b;
3926 while (parent_b->parent)
3928 parent_b = parent_b->parent;
3932 if (parent_a != parent_b)
3935 while (depth_a > depth_b)
3937 widget_a = widget_a->parent;
3941 while (depth_b > depth_a)
3943 widget_b = widget_b->parent;
3947 while (widget_a != widget_b)
3949 widget_a = widget_a->parent;
3950 widget_b = widget_b->parent;
3957 * gtk_widget_translate_coordinates:
3958 * @src_widget: a #GtkWidget
3959 * @dest_widget: a #GtkWidget
3960 * @src_x: X position relative to @src_widget
3961 * @src_y: Y position relative to @src_widget
3962 * @dest_x: location to store X position relative to @dest_widget
3963 * @dest_y: location to store Y position relative to @dest_widget
3965 * Translate coordinates relative to @src_widget's allocation to coordinates
3966 * relative to @dest_widget's allocations. In order to perform this
3967 * operation, both widgets must be realized, and must share a common
3970 * Return value: %FALSE if either widget was not realized, or there
3971 * was no common ancestor. In this case, nothing is stored in
3972 * *@dest_x and *@dest_y. Otherwise %TRUE.
3975 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3976 GtkWidget *dest_widget,
3982 GtkWidget *ancestor;
3985 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
3986 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
3988 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
3989 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
3992 /* Translate from allocation relative to window relative */
3993 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
3996 gdk_window_get_position (src_widget->window, &wx, &wy);
3998 src_x -= wx - src_widget->allocation.x;
3999 src_y -= wy - src_widget->allocation.y;
4003 src_x += src_widget->allocation.x;
4004 src_y += src_widget->allocation.y;
4007 /* Translate to the common ancestor */
4008 window = src_widget->window;
4009 while (window != ancestor->window)
4013 gdk_window_get_position (window, &dx, &dy);
4018 window = gdk_window_get_parent (window);
4020 if (!window) /* Handle GtkHandleBox */
4025 window = dest_widget->window;
4026 while (window != ancestor->window)
4030 gdk_window_get_position (window, &dx, &dy);
4035 window = gdk_window_get_parent (window);
4037 if (!window) /* Handle GtkHandleBox */
4041 /* Translate from window relative to allocation relative */
4042 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4045 gdk_window_get_position (dest_widget->window, &wx, &wy);
4047 src_x += wx - dest_widget->allocation.x;
4048 src_y += wy - dest_widget->allocation.y;
4052 src_x -= dest_widget->allocation.x;
4053 src_y -= dest_widget->allocation.y;
4065 gtk_widget_real_size_allocate (GtkWidget *widget,
4066 GtkAllocation *allocation)
4068 widget->allocation = *allocation;
4070 if (GTK_WIDGET_REALIZED (widget) &&
4071 !GTK_WIDGET_NO_WINDOW (widget))
4073 gdk_window_move_resize (widget->window,
4074 allocation->x, allocation->y,
4075 allocation->width, allocation->height);
4080 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4083 /* widgets must be onscreen for accels to take effect */
4084 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4088 * gtk_widget_can_activate_accel:
4089 * @widget: a #GtkWidget
4090 * @signal_id: the ID of a signal installed on @widget
4092 * Determines whether an accelerator that activates the signal
4093 * identified by @signal_id can currently be activated.
4094 * This is done by emitting the #GtkWidget::can-activate-accel
4095 * signal on @widget; if the signal isn't overridden by a
4096 * handler or in a derived widget, then the default check is
4097 * that the widget must be sensitive, and the widget and all
4098 * its ancestors mapped.
4100 * Return value: %TRUE if the accelerator can be activated.
4105 gtk_widget_can_activate_accel (GtkWidget *widget,
4108 gboolean can_activate = FALSE;
4109 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4110 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4111 return can_activate;
4120 closure_accel_activate (GClosure *closure,
4121 GValue *return_value,
4122 guint n_param_values,
4123 const GValue *param_values,
4124 gpointer invocation_hint,
4125 gpointer marshal_data)
4127 AccelClosure *aclosure = (AccelClosure*) closure;
4128 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4131 g_signal_emit (closure->data, aclosure->signal_id, 0);
4133 /* whether accelerator was handled */
4134 g_value_set_boolean (return_value, can_activate);
4138 closures_destroy (gpointer data)
4140 GSList *slist, *closures = data;
4142 for (slist = closures; slist; slist = slist->next)
4144 g_closure_invalidate (slist->data);
4145 g_closure_unref (slist->data);
4147 g_slist_free (closures);
4151 widget_new_accel_closure (GtkWidget *widget,
4154 AccelClosure *aclosure;
4155 GClosure *closure = NULL;
4156 GSList *slist, *closures;
4158 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4159 for (slist = closures; slist; slist = slist->next)
4160 if (!gtk_accel_group_from_accel_closure (slist->data))
4162 /* reuse this closure */
4163 closure = slist->data;
4168 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4169 closures = g_slist_prepend (closures, g_closure_ref (closure));
4170 g_closure_sink (closure);
4171 g_closure_set_marshal (closure, closure_accel_activate);
4173 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4175 aclosure = (AccelClosure*) closure;
4176 g_assert (closure->data == widget);
4177 g_assert (closure->marshal == closure_accel_activate);
4178 aclosure->signal_id = signal_id;
4184 * gtk_widget_add_accelerator
4185 * @widget: widget to install an accelerator on
4186 * @accel_signal: widget signal to emit on accelerator activation
4187 * @accel_group: accel group for this widget, added to its toplevel
4188 * @accel_key: GDK keyval of the accelerator
4189 * @accel_mods: modifier key combination of the accelerator
4190 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4192 * Installs an accelerator for this @widget in @accel_group that causes
4193 * @accel_signal to be emitted if the accelerator is activated.
4194 * The @accel_group needs to be added to the widget's toplevel via
4195 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4196 * Accelerators added through this function are not user changeable during
4197 * runtime. If you want to support accelerators that can be changed by the
4198 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4199 * gtk_menu_item_set_accel_path() instead.
4202 gtk_widget_add_accelerator (GtkWidget *widget,
4203 const gchar *accel_signal,
4204 GtkAccelGroup *accel_group,
4206 GdkModifierType accel_mods,
4207 GtkAccelFlags accel_flags)
4212 g_return_if_fail (GTK_IS_WIDGET (widget));
4213 g_return_if_fail (accel_signal != NULL);
4214 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4216 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4217 if (!query.signal_id ||
4218 !(query.signal_flags & G_SIGNAL_ACTION) ||
4219 query.return_type != G_TYPE_NONE ||
4222 /* hmm, should be elaborate enough */
4223 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4224 G_OBJECT_TYPE_NAME (widget), accel_signal);
4228 closure = widget_new_accel_closure (widget, query.signal_id);
4230 g_object_ref (widget);
4232 /* install the accelerator. since we don't map this onto an accel_path,
4233 * the accelerator will automatically be locked.
4235 gtk_accel_group_connect (accel_group,
4238 accel_flags | GTK_ACCEL_LOCKED,
4241 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4243 g_object_unref (widget);
4247 * gtk_widget_remove_accelerator:
4248 * @widget: widget to install an accelerator on
4249 * @accel_group: accel group for this widget
4250 * @accel_key: GDK keyval of the accelerator
4251 * @accel_mods: modifier key combination of the accelerator
4252 * @returns: whether an accelerator was installed and could be removed
4254 * Removes an accelerator from @widget, previously installed with
4255 * gtk_widget_add_accelerator().
4258 gtk_widget_remove_accelerator (GtkWidget *widget,
4259 GtkAccelGroup *accel_group,
4261 GdkModifierType accel_mods)
4263 GtkAccelGroupEntry *ag_entry;
4264 GList *slist, *clist;
4267 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4268 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4270 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4271 clist = gtk_widget_list_accel_closures (widget);
4272 for (slist = clist; slist; slist = slist->next)
4276 for (i = 0; i < n; i++)
4277 if (slist->data == (gpointer) ag_entry[i].closure)
4279 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4281 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4283 g_list_free (clist);
4288 g_list_free (clist);
4290 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4291 accel_key, accel_mods, accel_group,
4292 G_OBJECT_TYPE_NAME (widget), widget);
4298 * gtk_widget_list_accel_closures
4299 * @widget: widget to list accelerator closures for
4300 * @returns: a newly allocated #GList of closures
4302 * Lists the closures used by @widget for accelerator group connections
4303 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4304 * The closures can be used to monitor accelerator changes on @widget,
4305 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4306 * #GtkAccelGroup of a closure which can be found out with
4307 * gtk_accel_group_from_accel_closure().
4310 gtk_widget_list_accel_closures (GtkWidget *widget)
4313 GList *clist = NULL;
4315 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4317 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4318 if (gtk_accel_group_from_accel_closure (slist->data))
4319 clist = g_list_prepend (clist, slist->data);
4325 GtkAccelGroup *accel_group;
4330 destroy_accel_path (gpointer data)
4332 AccelPath *apath = data;
4334 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4336 /* closures_destroy takes care of unrefing the closure */
4337 g_object_unref (apath->accel_group);
4339 g_slice_free (AccelPath, apath);
4344 * gtk_widget_set_accel_path:
4345 * @widget: a #GtkWidget
4346 * @accel_path: path used to look up the accelerator
4347 * @accel_group: a #GtkAccelGroup.
4349 * Given an accelerator group, @accel_group, and an accelerator path,
4350 * @accel_path, sets up an accelerator in @accel_group so whenever the
4351 * key binding that is defined for @accel_path is pressed, @widget
4352 * will be activated. This removes any accelerators (for any
4353 * accelerator group) installed by previous calls to
4354 * gtk_widget_set_accel_path(). Associating accelerators with
4355 * paths allows them to be modified by the user and the modifications
4356 * to be saved for future use. (See gtk_accel_map_save().)
4358 * This function is a low level function that would most likely
4359 * be used by a menu creation system like #GtkUIManager. If you
4360 * use #GtkUIManager, setting up accelerator paths will be done
4363 * Even when you you aren't using #GtkUIManager, if you only want to
4364 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4365 * provides a somewhat more convenient interface.
4367 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4368 * pass a static string, you can save some memory by interning it first with
4369 * g_intern_static_string().
4372 gtk_widget_set_accel_path (GtkWidget *widget,
4373 const gchar *accel_path,
4374 GtkAccelGroup *accel_group)
4378 g_return_if_fail (GTK_IS_WIDGET (widget));
4379 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4383 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4384 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4386 gtk_accel_map_add_entry (accel_path, 0, 0);
4387 apath = g_slice_new (AccelPath);
4388 apath->accel_group = g_object_ref (accel_group);
4389 apath->path_quark = g_quark_from_string (accel_path);
4390 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4395 /* also removes possible old settings */
4396 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4399 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4401 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4405 _gtk_widget_get_accel_path (GtkWidget *widget,
4410 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4412 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4414 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4415 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4419 gtk_widget_mnemonic_activate (GtkWidget *widget,
4420 gboolean group_cycling)
4424 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4426 group_cycling = group_cycling != FALSE;
4427 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4430 g_signal_emit (widget,
4431 widget_signals[MNEMONIC_ACTIVATE],
4439 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4440 gboolean group_cycling)
4442 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4443 gtk_widget_activate (widget);
4444 else if (GTK_WIDGET_CAN_FOCUS (widget))
4445 gtk_widget_grab_focus (widget);
4448 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4449 G_OBJECT_TYPE_NAME (widget));
4450 gtk_widget_error_bell (widget);
4456 gtk_widget_real_key_press_event (GtkWidget *widget,
4459 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4463 gtk_widget_real_key_release_event (GtkWidget *widget,
4466 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4470 gtk_widget_real_focus_in_event (GtkWidget *widget,
4471 GdkEventFocus *event)
4473 gtk_widget_queue_shallow_draw (widget);
4479 gtk_widget_real_focus_out_event (GtkWidget *widget,
4480 GdkEventFocus *event)
4482 gtk_widget_queue_shallow_draw (widget);
4487 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4488 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4492 * @widget: a #GtkWidget
4493 * @event: a #GdkEvent
4495 * Rarely-used function. This function is used to emit
4496 * the event signals on a widget (those signals should never
4497 * be emitted without using this function to do so).
4498 * If you want to synthesize an event though, don't use this function;
4499 * instead, use gtk_main_do_event() so the event will behave as if
4500 * it were in the event queue. Don't synthesize expose events; instead,
4501 * use gdk_window_invalidate_rect() to invalidate a region of the
4504 * Return value: return from the event signal emission (%TRUE if
4505 * the event was handled)
4508 gtk_widget_event (GtkWidget *widget,
4511 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4512 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4514 if (event->type == GDK_EXPOSE)
4516 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4517 "the same effect, call gdk_window_invalidate_rect/region(), "
4518 "followed by gdk_window_process_updates().");
4522 return gtk_widget_event_internal (widget, event);
4527 * gtk_widget_send_expose:
4528 * @widget: a #GtkWidget
4529 * @event: a expose #GdkEvent
4531 * Very rarely-used function. This function is used to emit
4532 * an expose event signals on a widget. This function is not
4533 * normally used directly. The only time it is used is when
4534 * propagating an expose event to a child %NO_WINDOW widget, and
4535 * that is normally done using gtk_container_propagate_expose().
4537 * If you want to force an area of a window to be redrawn,
4538 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4539 * To cause the redraw to be done immediately, follow that call
4540 * with a call to gdk_window_process_updates().
4542 * Return value: return from the event signal emission (%TRUE if
4543 * the event was handled)
4546 gtk_widget_send_expose (GtkWidget *widget,
4549 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4550 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4551 g_return_val_if_fail (event != NULL, TRUE);
4552 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4554 return gtk_widget_event_internal (widget, event);
4558 event_window_is_still_viewable (GdkEvent *event)
4560 /* Some programs, such as gnome-theme-manager, fake widgets
4561 * into exposing onto a pixmap by sending expose events with
4562 * event->window pointing to a pixmap
4564 if (GDK_IS_PIXMAP (event->any.window))
4565 return event->type == GDK_EXPOSE;
4567 /* Check that we think the event's window is viewable before
4568 * delivering the event, to prevent suprises. We do this here
4569 * at the last moment, since the event may have been queued
4570 * up behind other events, held over a recursive main loop, etc.
4572 switch (event->type)
4575 case GDK_MOTION_NOTIFY:
4576 case GDK_BUTTON_PRESS:
4577 case GDK_2BUTTON_PRESS:
4578 case GDK_3BUTTON_PRESS:
4580 case GDK_ENTER_NOTIFY:
4581 case GDK_PROXIMITY_IN:
4583 return event->any.window && gdk_window_is_viewable (event->any.window);
4586 /* The following events are the second half of paired events;
4587 * we always deliver them to deal with widgets that clean up
4588 * on the second half.
4590 case GDK_BUTTON_RELEASE:
4591 case GDK_KEY_RELEASE:
4592 case GDK_LEAVE_NOTIFY:
4593 case GDK_PROXIMITY_OUT:
4597 /* Remaining events would make sense on an not-viewable window,
4598 * or don't have an associated window.
4605 gtk_widget_event_internal (GtkWidget *widget,
4608 gboolean return_val = FALSE;
4610 /* We check only once for is-still-visible; if someone
4611 * hides the window in on of the signals on the widget,
4612 * they are responsible for returning TRUE to terminate
4615 if (!event_window_is_still_viewable (event))
4618 g_object_ref (widget);
4620 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4621 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4626 switch (event->type)
4631 case GDK_BUTTON_PRESS:
4632 case GDK_2BUTTON_PRESS:
4633 case GDK_3BUTTON_PRESS:
4634 signal_num = BUTTON_PRESS_EVENT;
4637 signal_num = SCROLL_EVENT;
4639 case GDK_BUTTON_RELEASE:
4640 signal_num = BUTTON_RELEASE_EVENT;
4642 case GDK_MOTION_NOTIFY:
4643 signal_num = MOTION_NOTIFY_EVENT;
4646 signal_num = DELETE_EVENT;
4649 signal_num = DESTROY_EVENT;
4650 _gtk_tooltip_hide (widget);
4653 signal_num = KEY_PRESS_EVENT;
4655 case GDK_KEY_RELEASE:
4656 signal_num = KEY_RELEASE_EVENT;
4658 case GDK_ENTER_NOTIFY:
4659 signal_num = ENTER_NOTIFY_EVENT;
4661 case GDK_LEAVE_NOTIFY:
4662 signal_num = LEAVE_NOTIFY_EVENT;
4664 case GDK_FOCUS_CHANGE:
4665 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4666 if (event->focus_change.in)
4667 _gtk_tooltip_focus_in (widget);
4669 _gtk_tooltip_focus_out (widget);
4672 signal_num = CONFIGURE_EVENT;
4675 signal_num = MAP_EVENT;
4678 signal_num = UNMAP_EVENT;
4680 case GDK_WINDOW_STATE:
4681 signal_num = WINDOW_STATE_EVENT;
4683 case GDK_PROPERTY_NOTIFY:
4684 signal_num = PROPERTY_NOTIFY_EVENT;
4686 case GDK_SELECTION_CLEAR:
4687 signal_num = SELECTION_CLEAR_EVENT;
4689 case GDK_SELECTION_REQUEST:
4690 signal_num = SELECTION_REQUEST_EVENT;
4692 case GDK_SELECTION_NOTIFY:
4693 signal_num = SELECTION_NOTIFY_EVENT;
4695 case GDK_PROXIMITY_IN:
4696 signal_num = PROXIMITY_IN_EVENT;
4698 case GDK_PROXIMITY_OUT:
4699 signal_num = PROXIMITY_OUT_EVENT;
4702 signal_num = NO_EXPOSE_EVENT;
4704 case GDK_CLIENT_EVENT:
4705 signal_num = CLIENT_EVENT;
4708 signal_num = EXPOSE_EVENT;
4710 case GDK_VISIBILITY_NOTIFY:
4711 signal_num = VISIBILITY_NOTIFY_EVENT;
4713 case GDK_GRAB_BROKEN:
4714 signal_num = GRAB_BROKEN;
4717 signal_num = DAMAGE_EVENT;
4720 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4724 if (signal_num != -1)
4725 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4727 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4728 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4732 g_object_unref (widget);
4738 * gtk_widget_activate:
4739 * @widget: a #GtkWidget that's activatable
4741 * For widgets that can be "activated" (buttons, menu items, etc.)
4742 * this function activates them. Activation is what happens when you
4743 * press Enter on a widget during key navigation. If @widget isn't
4744 * activatable, the function returns %FALSE.
4746 * Return value: %TRUE if the widget was activatable
4749 gtk_widget_activate (GtkWidget *widget)
4751 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4753 if (WIDGET_CLASS (widget)->activate_signal)
4755 /* FIXME: we should eventually check the signals signature here */
4756 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4765 * gtk_widget_set_scroll_adjustments:
4766 * @widget: a #GtkWidget
4767 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4768 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4770 * For widgets that support scrolling, sets the scroll adjustments and
4771 * returns %TRUE. For widgets that don't support scrolling, does
4772 * nothing and returns %FALSE. Widgets that don't support scrolling
4773 * can be scrolled by placing them in a #GtkViewport, which does
4774 * support scrolling.
4776 * Return value: %TRUE if the widget supports scrolling
4779 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4780 GtkAdjustment *hadjustment,
4781 GtkAdjustment *vadjustment)
4783 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4785 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4787 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4789 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
4791 /* FIXME: we should eventually check the signals signature here */
4792 g_signal_emit (widget,
4793 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
4794 hadjustment, vadjustment);
4802 gtk_widget_reparent_subwindows (GtkWidget *widget,
4803 GdkWindow *new_window)
4805 if (GTK_WIDGET_NO_WINDOW (widget))
4807 GList *children = gdk_window_get_children (widget->window);
4810 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4812 GdkWindow *window = tmp_list->data;
4815 gdk_window_get_user_data (window, &child);
4816 while (child && child != widget)
4817 child = ((GtkWidget*) child)->parent;
4820 gdk_window_reparent (window, new_window, 0, 0);
4823 g_list_free (children);
4828 GList *tmp_list, *children;
4830 parent = gdk_window_get_parent (widget->window);
4833 gdk_window_reparent (widget->window, new_window, 0, 0);
4836 children = gdk_window_get_children (parent);
4838 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4840 GdkWindow *window = tmp_list->data;
4843 gdk_window_get_user_data (window, &child);
4845 if (child == widget)
4846 gdk_window_reparent (window, new_window, 0, 0);
4849 g_list_free (children);
4855 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4856 gpointer client_data)
4858 g_assert (client_data != NULL);
4860 if (GTK_WIDGET_NO_WINDOW (widget))
4863 g_object_unref (widget->window);
4864 widget->window = (GdkWindow*) client_data;
4866 g_object_ref (widget->window);
4868 if (GTK_IS_CONTAINER (widget))
4869 gtk_container_forall (GTK_CONTAINER (widget),
4870 gtk_widget_reparent_fixup_child,
4876 * gtk_widget_reparent:
4877 * @widget: a #GtkWidget
4878 * @new_parent: a #GtkContainer to move the widget into
4880 * Moves a widget from one #GtkContainer to another, handling reference
4881 * count issues to avoid destroying the widget.
4884 gtk_widget_reparent (GtkWidget *widget,
4885 GtkWidget *new_parent)
4887 g_return_if_fail (GTK_IS_WIDGET (widget));
4888 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4889 g_return_if_fail (widget->parent != NULL);
4891 if (widget->parent != new_parent)
4893 /* First try to see if we can get away without unrealizing
4894 * the widget as we reparent it. if so we set a flag so
4895 * that gtk_widget_unparent doesn't unrealize widget
4897 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4898 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4900 g_object_ref (widget);
4901 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4902 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4903 g_object_unref (widget);
4905 if (GTK_WIDGET_IN_REPARENT (widget))
4907 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4909 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4910 gtk_widget_reparent_fixup_child (widget,
4911 gtk_widget_get_parent_window (widget));
4914 g_object_notify (G_OBJECT (widget), "parent");
4919 * gtk_widget_intersect:
4920 * @widget: a #GtkWidget
4921 * @area: a rectangle
4922 * @intersection: rectangle to store intersection of @widget and @area
4924 * Computes the intersection of a @widget's area and @area, storing
4925 * the intersection in @intersection, and returns %TRUE if there was
4926 * an intersection. @intersection may be %NULL if you're only
4927 * interested in whether there was an intersection.
4929 * Return value: %TRUE if there was an intersection
4932 gtk_widget_intersect (GtkWidget *widget,
4933 const GdkRectangle *area,
4934 GdkRectangle *intersection)
4940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4941 g_return_val_if_fail (area != NULL, FALSE);
4944 dest = intersection;
4948 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4950 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4952 intersection->x -= widget->allocation.x;
4953 intersection->y -= widget->allocation.y;
4960 * gtk_widget_region_intersect:
4961 * @widget: a #GtkWidget
4962 * @region: a #GdkRegion, in the same coordinate system as
4963 * @widget->allocation. That is, relative to @widget->window
4964 * for %NO_WINDOW widgets; relative to the parent window
4965 * of @widget->window for widgets with their own window.
4966 * @returns: A newly allocated region holding the intersection of @widget
4967 * and @region. The coordinates of the return value are
4968 * relative to @widget->window for %NO_WINDOW widgets, and
4969 * relative to the parent window of @widget->window for
4970 * widgets with their own window.
4972 * Computes the intersection of a @widget's area and @region, returning
4973 * the intersection. The result may be empty, use gdk_region_empty() to
4977 gtk_widget_region_intersect (GtkWidget *widget,
4978 const GdkRegion *region)
4983 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4984 g_return_val_if_fail (region != NULL, NULL);
4986 gtk_widget_get_draw_rectangle (widget, &rect);
4988 dest = gdk_region_rectangle (&rect);
4990 gdk_region_intersect (dest, region);
4996 * _gtk_widget_grab_notify:
4997 * @widget: a #GtkWidget
4998 * @was_grabbed: whether a grab is now in effect
5000 * Emits the #GtkWidget::grab-notify signal on @widget.
5005 _gtk_widget_grab_notify (GtkWidget *widget,
5006 gboolean was_grabbed)
5008 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5012 * gtk_widget_grab_focus:
5013 * @widget: a #GtkWidget
5015 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5016 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5017 * something like #GtkFrame won't work. (More precisely, it must have the
5018 * %GTK_CAN_FOCUS flag set.)
5021 gtk_widget_grab_focus (GtkWidget *widget)
5023 g_return_if_fail (GTK_IS_WIDGET (widget));
5025 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5028 g_object_ref (widget);
5029 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5030 g_object_notify (G_OBJECT (widget), "has-focus");
5031 g_object_unref (widget);
5035 reset_focus_recurse (GtkWidget *widget,
5038 if (GTK_IS_CONTAINER (widget))
5040 GtkContainer *container;
5042 container = GTK_CONTAINER (widget);
5043 gtk_container_set_focus_child (container, NULL);
5045 gtk_container_foreach (container,
5046 reset_focus_recurse,
5052 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5054 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5056 GtkWidget *toplevel;
5059 /* clear the current focus setting, break if the current widget
5060 * is the focus widget's parent, since containers above that will
5061 * be set by the next loop.
5063 toplevel = gtk_widget_get_toplevel (focus_widget);
5064 if (GTK_WIDGET_TOPLEVEL (toplevel))
5066 widget = GTK_WINDOW (toplevel)->focus_widget;
5068 if (widget == focus_widget)
5070 /* We call _gtk_window_internal_set_focus() here so that the
5071 * toplevel window can request the focus if necessary.
5072 * This is needed when the toplevel is a GtkPlug
5074 if (!GTK_WIDGET_HAS_FOCUS (widget))
5075 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5082 while (widget->parent && widget->parent != focus_widget->parent)
5084 widget = widget->parent;
5085 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5089 else if (toplevel != focus_widget)
5091 /* gtk_widget_grab_focus() operates on a tree without window...
5092 * actually, this is very questionable behaviour.
5095 gtk_container_foreach (GTK_CONTAINER (toplevel),
5096 reset_focus_recurse,
5100 /* now propagate the new focus up the widget tree and finally
5101 * set it on the window
5103 widget = focus_widget;
5104 while (widget->parent)
5106 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5107 widget = widget->parent;
5109 if (GTK_IS_WINDOW (widget))
5110 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5115 gtk_widget_real_query_tooltip (GtkWidget *widget,
5118 gboolean keyboard_tip,
5119 GtkTooltip *tooltip)
5121 gchar *tooltip_markup;
5122 gboolean has_tooltip;
5124 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5125 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5127 if (has_tooltip && tooltip_markup)
5129 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5137 gtk_widget_real_show_help (GtkWidget *widget,
5138 GtkWidgetHelpType help_type)
5140 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5142 _gtk_tooltip_toggle_keyboard_mode (widget);
5151 gtk_widget_real_focus (GtkWidget *widget,
5152 GtkDirectionType direction)
5154 if (!GTK_WIDGET_CAN_FOCUS (widget))
5157 if (!gtk_widget_is_focus (widget))
5159 gtk_widget_grab_focus (widget);
5167 gtk_widget_real_move_focus (GtkWidget *widget,
5168 GtkDirectionType direction)
5170 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5172 if (GTK_IS_WINDOW (toplevel) &&
5173 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5175 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5181 gtk_widget_real_keynav_failed (GtkWidget *widget,
5182 GtkDirectionType direction)
5184 gboolean cursor_only;
5188 case GTK_DIR_TAB_FORWARD:
5189 case GTK_DIR_TAB_BACKWARD:
5196 g_object_get (gtk_widget_get_settings (widget),
5197 "gtk-keynav-cursor-only", &cursor_only,
5204 gtk_widget_error_bell (widget);
5210 * gtk_widget_is_focus:
5211 * @widget: a #GtkWidget
5213 * Determines if the widget is the focus widget within its
5214 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5215 * necessarily set; %HAS_FOCUS will only be set if the
5216 * toplevel widget additionally has the global input focus.)
5218 * Return value: %TRUE if the widget is the focus widget.
5221 gtk_widget_is_focus (GtkWidget *widget)
5223 GtkWidget *toplevel;
5225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5227 toplevel = gtk_widget_get_toplevel (widget);
5229 if (GTK_IS_WINDOW (toplevel))
5230 return widget == GTK_WINDOW (toplevel)->focus_widget;
5236 * gtk_widget_grab_default:
5237 * @widget: a #GtkWidget
5239 * Causes @widget to become the default widget. @widget must have the
5240 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5241 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5242 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5243 * the user presses Enter in a window. Default widgets must be
5244 * activatable, that is, gtk_widget_activate() should affect them.
5247 gtk_widget_grab_default (GtkWidget *widget)
5251 g_return_if_fail (GTK_IS_WIDGET (widget));
5252 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5254 window = gtk_widget_get_toplevel (widget);
5256 if (window && GTK_WIDGET_TOPLEVEL (window))
5257 gtk_window_set_default (GTK_WINDOW (window), widget);
5259 g_warning (G_STRLOC ": widget not within a GtkWindow");
5263 * gtk_widget_set_name:
5264 * @widget: a #GtkWidget
5265 * @name: name for the widget
5267 * Widgets can be named, which allows you to refer to them from a
5268 * gtkrc file. You can apply a style to widgets with a particular name
5269 * in the gtkrc file. See the documentation for gtkrc files (on the
5270 * same page as the docs for #GtkRcStyle).
5272 * Note that widget names are separated by periods in paths (see
5273 * gtk_widget_path()), so names with embedded periods may cause confusion.
5276 gtk_widget_set_name (GtkWidget *widget,
5281 g_return_if_fail (GTK_IS_WIDGET (widget));
5283 new_name = g_strdup (name);
5284 g_free (widget->name);
5285 widget->name = new_name;
5287 if (GTK_WIDGET_RC_STYLE (widget))
5288 gtk_widget_reset_rc_style (widget);
5290 g_object_notify (G_OBJECT (widget), "name");
5294 * gtk_widget_get_name:
5295 * @widget: a #GtkWidget
5297 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5298 * significance of widget names.
5300 * Return value: name of the widget. This string is owned by GTK+ and
5301 * should not be modified or freed
5303 G_CONST_RETURN gchar*
5304 gtk_widget_get_name (GtkWidget *widget)
5306 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5309 return widget->name;
5310 return g_type_name (GTK_WIDGET_TYPE (widget));
5314 * gtk_widget_set_state:
5315 * @widget: a #GtkWidget
5316 * @state: new state for @widget
5318 * This function is for use in widget implementations. Sets the state
5319 * of a widget (insensitive, prelighted, etc.) Usually you should set
5320 * the state using wrapper functions such as gtk_widget_set_sensitive().
5323 gtk_widget_set_state (GtkWidget *widget,
5326 g_return_if_fail (GTK_IS_WIDGET (widget));
5328 if (state == GTK_WIDGET_STATE (widget))
5331 if (state == GTK_STATE_INSENSITIVE)
5332 gtk_widget_set_sensitive (widget, FALSE);
5338 data.state_restoration = FALSE;
5339 data.use_forall = FALSE;
5341 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5343 data.parent_sensitive = TRUE;
5345 gtk_widget_propagate_state (widget, &data);
5347 if (GTK_WIDGET_DRAWABLE (widget))
5348 gtk_widget_queue_draw (widget);
5354 * gtk_widget_set_app_paintable:
5355 * @widget: a #GtkWidget
5356 * @app_paintable: %TRUE if the application will paint on the widget
5358 * Sets whether the application intends to draw on the widget in
5359 * an #GtkWidget::expose-event handler.
5361 * This is a hint to the widget and does not affect the behavior of
5362 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5363 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5364 * the effect is to suppress default themed drawing of the widget's
5365 * background. (Children of the widget will still be drawn.) The application
5366 * is then entirely responsible for drawing the widget background.
5368 * Note that the background is still drawn when the widget is mapped.
5369 * If this is not suitable (e.g. because you want to make a transparent
5370 * window using an RGBA visual), you can work around this by doing:
5372 * gtk_widget_realize (window);
5373 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5374 * gtk_widget_show (window);
5378 gtk_widget_set_app_paintable (GtkWidget *widget,
5379 gboolean app_paintable)
5381 g_return_if_fail (GTK_IS_WIDGET (widget));
5383 app_paintable = (app_paintable != FALSE);
5385 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5388 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5390 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5392 if (GTK_WIDGET_DRAWABLE (widget))
5393 gtk_widget_queue_draw (widget);
5395 g_object_notify (G_OBJECT (widget), "app-paintable");
5400 * gtk_widget_set_double_buffered:
5401 * @widget: a #GtkWidget
5402 * @double_buffered: %TRUE to double-buffer a widget
5404 * Widgets are double buffered by default; you can use this function
5405 * to turn off the buffering. "Double buffered" simply means that
5406 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5407 * automatically around expose events sent to the
5408 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5409 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5410 * buffer to the screen. The result is that users see the window
5411 * update in one smooth step, and don't see individual graphics
5412 * primitives being rendered.
5414 * In very simple terms, double buffered widgets don't flicker,
5415 * so you would only use this function to turn off double buffering
5416 * if you had special needs and really knew what you were doing.
5418 * Note: if you turn off double-buffering, you have to handle
5419 * expose events, since even the clearing to the background color or
5420 * pixmap will not happen automatically (as it is done in
5421 * gdk_window_begin_paint()).
5424 gtk_widget_set_double_buffered (GtkWidget *widget,
5425 gboolean double_buffered)
5427 g_return_if_fail (GTK_IS_WIDGET (widget));
5429 if (double_buffered)
5430 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5432 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5436 * gtk_widget_set_redraw_on_allocate:
5437 * @widget: a #GtkWidget
5438 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5439 * when it is allocated to a new size. Otherwise, only the
5440 * new portion of the widget will be redrawn.
5442 * Sets whether the entire widget is queued for drawing when its size
5443 * allocation changes. By default, this setting is %TRUE and
5444 * the entire widget is redrawn on every size change. If your widget
5445 * leaves the upper left unchanged when made bigger, turning this
5446 * setting off will improve performance.
5448 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5449 * off all allocation on resizing: the widget will not even redraw if
5450 * its position changes; this is to allow containers that don't draw
5451 * anything to avoid excess invalidations. If you set this flag on a
5452 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5453 * you are responsible for invalidating both the old and new allocation
5454 * of the widget when the widget is moved and responsible for invalidating
5455 * regions newly when the widget increases size.
5458 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5459 gboolean redraw_on_allocate)
5461 g_return_if_fail (GTK_IS_WIDGET (widget));
5463 if (redraw_on_allocate)
5464 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5466 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5470 * gtk_widget_set_sensitive:
5471 * @widget: a #GtkWidget
5472 * @sensitive: %TRUE to make the widget sensitive
5474 * Sets the sensitivity of a widget. A widget is sensitive if the user
5475 * can interact with it. Insensitive widgets are "grayed out" and the
5476 * user can't interact with them. Insensitive widgets are known as
5477 * "inactive", "disabled", or "ghosted" in some other toolkits.
5480 gtk_widget_set_sensitive (GtkWidget *widget,
5485 g_return_if_fail (GTK_IS_WIDGET (widget));
5487 sensitive = (sensitive != FALSE);
5489 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5494 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5495 data.state = GTK_WIDGET_SAVED_STATE (widget);
5499 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5500 data.state = GTK_WIDGET_STATE (widget);
5502 data.state_restoration = TRUE;
5503 data.use_forall = TRUE;
5506 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5508 data.parent_sensitive = TRUE;
5510 gtk_widget_propagate_state (widget, &data);
5511 if (GTK_WIDGET_DRAWABLE (widget))
5512 gtk_widget_queue_draw (widget);
5514 g_object_notify (G_OBJECT (widget), "sensitive");
5518 * gtk_widget_set_parent:
5519 * @widget: a #GtkWidget
5520 * @parent: parent container
5522 * This function is useful only when implementing subclasses of
5524 * Sets the container as the parent of @widget, and takes care of
5525 * some details such as updating the state and style of the child
5526 * to reflect its new location. The opposite function is
5527 * gtk_widget_unparent().
5530 gtk_widget_set_parent (GtkWidget *widget,
5535 g_return_if_fail (GTK_IS_WIDGET (widget));
5536 g_return_if_fail (GTK_IS_WIDGET (parent));
5537 g_return_if_fail (widget != parent);
5538 if (widget->parent != NULL)
5540 g_warning ("Can't set a parent on widget which has a parent\n");
5543 if (GTK_WIDGET_TOPLEVEL (widget))
5545 g_warning ("Can't set a parent on a toplevel widget\n");
5549 /* keep this function in sync with gtk_menu_attach_to_widget()
5552 g_object_ref_sink (widget);
5553 widget->parent = parent;
5555 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5556 data.state = GTK_WIDGET_STATE (parent);
5558 data.state = GTK_WIDGET_STATE (widget);
5559 data.state_restoration = FALSE;
5560 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5561 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5563 gtk_widget_propagate_state (widget, &data);
5565 gtk_widget_reset_rc_styles (widget);
5567 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5568 if (GTK_WIDGET_ANCHORED (widget->parent))
5569 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5570 g_object_notify (G_OBJECT (widget), "parent");
5572 /* Enforce realized/mapped invariants
5574 if (GTK_WIDGET_REALIZED (widget->parent))
5575 gtk_widget_realize (widget);
5577 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5578 GTK_WIDGET_VISIBLE (widget))
5580 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5581 GTK_WIDGET_MAPPED (widget->parent))
5582 gtk_widget_map (widget);
5584 gtk_widget_queue_resize (widget);
5589 * gtk_widget_get_parent:
5590 * @widget: a #GtkWidget
5592 * Returns the parent container of @widget.
5594 * Return value: the parent container of @widget, or %NULL
5597 gtk_widget_get_parent (GtkWidget *widget)
5599 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5601 return widget->parent;
5604 /*****************************************
5606 * see docs/styles.txt
5607 *****************************************/
5610 * gtk_widget_set_style:
5611 * @widget: a #GtkWidget
5612 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5613 * gtk_widget_set_style() and go back to the default style
5615 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5616 * want to use this function; it interacts badly with themes, because
5617 * themes work by replacing the #GtkStyle. Instead, use
5618 * gtk_widget_modify_style().
5621 gtk_widget_set_style (GtkWidget *widget,
5624 g_return_if_fail (GTK_IS_WIDGET (widget));
5628 gboolean initial_emission;
5630 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5632 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5633 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5635 gtk_widget_set_style_internal (widget, style, initial_emission);
5639 if (GTK_WIDGET_USER_STYLE (widget))
5640 gtk_widget_reset_rc_style (widget);
5645 * gtk_widget_ensure_style:
5646 * @widget: a #GtkWidget
5648 * Ensures that @widget has a style (@widget->style). Not a very useful
5649 * function; most of the time, if you want the style, the widget is
5650 * realized, and realized widgets are guaranteed to have a style
5654 gtk_widget_ensure_style (GtkWidget *widget)
5656 g_return_if_fail (GTK_IS_WIDGET (widget));
5658 if (!GTK_WIDGET_USER_STYLE (widget) &&
5659 !GTK_WIDGET_RC_STYLE (widget))
5660 gtk_widget_reset_rc_style (widget);
5663 /* Look up the RC style for this widget, unsetting any user style that
5664 * may be in effect currently
5667 gtk_widget_reset_rc_style (GtkWidget *widget)
5669 GtkStyle *new_style = NULL;
5670 gboolean initial_emission;
5672 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5674 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5675 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5677 if (gtk_widget_has_screen (widget))
5678 new_style = gtk_rc_get_style (widget);
5680 new_style = gtk_widget_get_default_style ();
5682 if (initial_emission || new_style != widget->style)
5683 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5687 * gtk_widget_get_style:
5688 * @widget: a #GtkWidget
5690 * Simply an accessor function that returns @widget->style.
5692 * Return value: the widget's #GtkStyle
5695 gtk_widget_get_style (GtkWidget *widget)
5697 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5699 return widget->style;
5703 * gtk_widget_modify_style:
5704 * @widget: a #GtkWidget
5705 * @style: the #GtkRcStyle holding the style modifications
5707 * Modifies style values on the widget. Modifications made using this
5708 * technique take precedence over style values set via an RC file,
5709 * however, they will be overriden if a style is explicitely set on
5710 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5711 * is designed so each field can either be set or unset, so it is
5712 * possible, using this function, to modify some style values and
5713 * leave the others unchanged.
5715 * Note that modifications made with this function are not cumulative
5716 * with previous calls to gtk_widget_modify_style() or with such
5717 * functions as gtk_widget_modify_fg(). If you wish to retain
5718 * previous values, you must first call gtk_widget_get_modifier_style(),
5719 * make your modifications to the returned style, then call
5720 * gtk_widget_modify_style() with that style. On the other hand,
5721 * if you first call gtk_widget_modify_style(), subsequent calls
5722 * to such functions gtk_widget_modify_fg() will have a cumulative
5723 * effect with the initial modifications.
5726 gtk_widget_modify_style (GtkWidget *widget,
5729 g_return_if_fail (GTK_IS_WIDGET (widget));
5730 g_return_if_fail (GTK_IS_RC_STYLE (style));
5732 g_object_set_qdata_full (G_OBJECT (widget),
5734 gtk_rc_style_copy (style),
5735 (GDestroyNotify) g_object_unref);
5737 /* note that "style" may be invalid here if it was the old
5738 * modifier style and the only reference was our own.
5741 if (GTK_WIDGET_RC_STYLE (widget))
5742 gtk_widget_reset_rc_style (widget);
5746 * gtk_widget_get_modifier_style:
5747 * @widget: a #GtkWidget
5749 * Returns the current modifier style for the widget. (As set by
5750 * gtk_widget_modify_style().) If no style has previously set, a new
5751 * #GtkRcStyle will be created with all values unset, and set as the
5752 * modifier style for the widget. If you make changes to this rc
5753 * style, you must call gtk_widget_modify_style(), passing in the
5754 * returned rc style, to make sure that your changes take effect.
5756 * Caution: passing the style back to gtk_widget_modify_style() will
5757 * normally end up destroying it, because gtk_widget_modify_style() copies
5758 * the passed-in style and sets the copy as the new modifier style,
5759 * thus dropping any reference to the old modifier style. Add a reference
5760 * to the modifier style if you want to keep it alive.
5762 * Return value: the modifier style for the widget. This rc style is
5763 * owned by the widget. If you want to keep a pointer to value this
5764 * around, you must add a refcount using g_object_ref().
5767 gtk_widget_get_modifier_style (GtkWidget *widget)
5769 GtkRcStyle *rc_style;
5771 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5773 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5777 rc_style = gtk_rc_style_new ();
5778 g_object_set_qdata_full (G_OBJECT (widget),
5781 (GDestroyNotify) g_object_unref);
5788 gtk_widget_modify_color_component (GtkWidget *widget,
5789 GtkRcFlags component,
5791 const GdkColor *color)
5793 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5800 rc_style->fg[state] = *color;
5803 rc_style->bg[state] = *color;
5806 rc_style->text[state] = *color;
5809 rc_style->base[state] = *color;
5812 g_assert_not_reached();
5815 rc_style->color_flags[state] |= component;
5818 rc_style->color_flags[state] &= ~component;
5820 gtk_widget_modify_style (widget, rc_style);
5824 * gtk_widget_modify_fg:
5825 * @widget: a #GtkWidget
5826 * @state: the state for which to set the foreground color
5827 * @color: the color to assign (does not need to be allocated),
5828 * or %NULL to undo the effect of previous calls to
5829 * of gtk_widget_modify_fg().
5831 * Sets the foreground color for a widget in a particular state.
5832 * All other style values are left untouched. See also
5833 * gtk_widget_modify_style().
5836 gtk_widget_modify_fg (GtkWidget *widget,
5838 const GdkColor *color)
5840 g_return_if_fail (GTK_IS_WIDGET (widget));
5841 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5843 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5847 * gtk_widget_modify_bg:
5848 * @widget: a #GtkWidget
5849 * @state: the state for which to set the background color
5850 * @color: the color to assign (does not need to be allocated),
5851 * or %NULL to undo the effect of previous calls to
5852 * of gtk_widget_modify_bg().
5854 * Sets the background color for a widget in a particular state.
5855 * All other style values are left untouched. See also
5856 * gtk_widget_modify_style().
5858 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5859 * draw on their parent container's window and thus may not draw any
5860 * background themselves. This is the case for e.g. #GtkLabel. To modify
5861 * the background of such widgets, you have to set the background color
5862 * on their parent; if you want to set the background of a rectangular
5863 * area around a label, try placing the label in a #GtkEventBox widget
5864 * and setting the background color on that.
5867 gtk_widget_modify_bg (GtkWidget *widget,
5869 const GdkColor *color)
5871 g_return_if_fail (GTK_IS_WIDGET (widget));
5872 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5874 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5878 * gtk_widget_modify_text:
5879 * @widget: a #GtkWidget
5880 * @state: the state for which to set the text color
5881 * @color: the color to assign (does not need to be allocated),
5882 * or %NULL to undo the effect of previous calls to
5883 * of gtk_widget_modify_text().
5885 * Sets the text color for a widget in a particular state. All other
5886 * style values are left untouched. The text color is the foreground
5887 * color used along with the base color (see gtk_widget_modify_base())
5888 * for widgets such as #GtkEntry and #GtkTextView. See also
5889 * gtk_widget_modify_style().
5892 gtk_widget_modify_text (GtkWidget *widget,
5894 const GdkColor *color)
5896 g_return_if_fail (GTK_IS_WIDGET (widget));
5897 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5899 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5903 * gtk_widget_modify_base:
5904 * @widget: a #GtkWidget
5905 * @state: the state for which to set the base color
5906 * @color: the color to assign (does not need to be allocated),
5907 * or %NULL to undo the effect of previous calls to
5908 * of gtk_widget_modify_base().
5910 * Sets the base color for a widget in a particular state.
5911 * All other style values are left untouched. The base color
5912 * is the background color used along with the text color
5913 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5914 * and #GtkTextView. See also gtk_widget_modify_style().
5916 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5917 * draw on their parent container's window and thus may not draw any
5918 * background themselves. This is the case for e.g. #GtkLabel. To modify
5919 * the background of such widgets, you have to set the base color on their
5920 * parent; if you want to set the background of a rectangular area around
5921 * a label, try placing the label in a #GtkEventBox widget and setting
5922 * the base color on that.
5925 gtk_widget_modify_base (GtkWidget *widget,
5927 const GdkColor *color)
5929 g_return_if_fail (GTK_IS_WIDGET (widget));
5930 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5932 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5936 modify_color_property (GtkWidget *widget,
5937 GtkRcStyle *rc_style,
5939 const GdkColor *color)
5941 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5942 GQuark property_name = g_quark_from_string (name);
5946 GtkRcProperty rc_property = {0};
5949 rc_property.type_name = type_name;
5950 rc_property.property_name = property_name;
5951 rc_property.origin = NULL;
5953 color_name = gdk_color_to_string (color);
5954 g_value_init (&rc_property.value, G_TYPE_STRING);
5955 g_value_take_string (&rc_property.value, color_name);
5957 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
5959 g_value_unset (&rc_property.value);
5962 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
5966 * gtk_widget_modify_cursor:
5967 * @widget: a #GtkWidget
5968 * @primary: the color to use for primary cursor (does not need to be
5969 * allocated), or %NULL to undo the effect of previous calls to
5970 * of gtk_widget_modify_cursor().
5971 * @secondary: the color to use for secondary cursor (does not need to be
5972 * allocated), or %NULL to undo the effect of previous calls to
5973 * of gtk_widget_modify_cursor().
5975 * Sets the cursor color to use in a widget, overriding the
5976 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
5977 * style properties. All other style values are left untouched.
5978 * See also gtk_widget_modify_style().
5983 gtk_widget_modify_cursor (GtkWidget *widget,
5984 const GdkColor *primary,
5985 const GdkColor *secondary)
5987 GtkRcStyle *rc_style;
5989 g_return_if_fail (GTK_IS_WIDGET (widget));
5991 rc_style = gtk_widget_get_modifier_style (widget);
5993 modify_color_property (widget, rc_style, "cursor-color", primary);
5994 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
5996 gtk_widget_modify_style (widget, rc_style);
6000 * gtk_widget_modify_font:
6001 * @widget: a #GtkWidget
6002 * @font_desc: the font description to use, or %NULL to undo
6003 * the effect of previous calls to gtk_widget_modify_font().
6005 * Sets the font to use for a widget. All other style values are left
6006 * untouched. See also gtk_widget_modify_style().
6009 gtk_widget_modify_font (GtkWidget *widget,
6010 PangoFontDescription *font_desc)
6012 GtkRcStyle *rc_style;
6014 g_return_if_fail (GTK_IS_WIDGET (widget));
6016 rc_style = gtk_widget_get_modifier_style (widget);
6018 if (rc_style->font_desc)
6019 pango_font_description_free (rc_style->font_desc);
6022 rc_style->font_desc = pango_font_description_copy (font_desc);
6024 rc_style->font_desc = NULL;
6026 gtk_widget_modify_style (widget, rc_style);
6030 gtk_widget_direction_changed (GtkWidget *widget,
6031 GtkTextDirection previous_direction)
6033 gtk_widget_queue_resize (widget);
6037 gtk_widget_style_set (GtkWidget *widget,
6038 GtkStyle *previous_style)
6040 if (GTK_WIDGET_REALIZED (widget) &&
6041 !GTK_WIDGET_NO_WINDOW (widget))
6042 gtk_style_set_background (widget->style, widget->window, widget->state);
6046 gtk_widget_set_style_internal (GtkWidget *widget,
6048 gboolean initial_emission)
6050 g_object_ref (widget);
6051 g_object_freeze_notify (G_OBJECT (widget));
6053 if (widget->style != style)
6055 GtkStyle *previous_style;
6057 if (GTK_WIDGET_REALIZED (widget))
6059 gtk_widget_reset_shapes (widget);
6060 gtk_style_detach (widget->style);
6063 previous_style = widget->style;
6064 widget->style = style;
6065 g_object_ref (widget->style);
6067 if (GTK_WIDGET_REALIZED (widget))
6068 widget->style = gtk_style_attach (widget->style, widget->window);
6070 gtk_widget_update_pango_context (widget);
6071 g_signal_emit (widget,
6072 widget_signals[STYLE_SET],
6074 initial_emission ? NULL : previous_style);
6075 g_object_unref (previous_style);
6077 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6078 gtk_widget_queue_resize (widget);
6080 else if (initial_emission)
6082 gtk_widget_update_pango_context (widget);
6083 g_signal_emit (widget,
6084 widget_signals[STYLE_SET],
6088 g_object_notify (G_OBJECT (widget), "style");
6089 g_object_thaw_notify (G_OBJECT (widget));
6090 g_object_unref (widget);
6094 GtkWidget *previous_toplevel;
6095 GdkScreen *previous_screen;
6096 GdkScreen *new_screen;
6097 } HierarchyChangedInfo;
6100 do_screen_change (GtkWidget *widget,
6101 GdkScreen *old_screen,
6102 GdkScreen *new_screen)
6104 if (old_screen != new_screen)
6108 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6110 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6113 _gtk_tooltip_hide (widget);
6114 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6119 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6120 gpointer client_data)
6122 HierarchyChangedInfo *info = client_data;
6123 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6124 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6126 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6128 g_object_ref (widget);
6131 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6133 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6135 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6136 do_screen_change (widget, info->previous_screen, info->new_screen);
6138 if (GTK_IS_CONTAINER (widget))
6139 gtk_container_forall (GTK_CONTAINER (widget),
6140 gtk_widget_propagate_hierarchy_changed_recurse,
6143 g_object_unref (widget);
6148 * _gtk_widget_propagate_hierarchy_changed:
6149 * @widget: a #GtkWidget
6150 * @previous_toplevel: Previous toplevel
6152 * Propagates changes in the anchored state to a widget and all
6153 * children, unsetting or setting the %ANCHORED flag, and
6154 * emitting #GtkWidget::hierarchy-changed.
6157 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6158 GtkWidget *previous_toplevel)
6160 HierarchyChangedInfo info;
6162 info.previous_toplevel = previous_toplevel;
6163 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6165 if (GTK_WIDGET_TOPLEVEL (widget) ||
6166 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6167 info.new_screen = gtk_widget_get_screen (widget);
6169 info.new_screen = NULL;
6171 if (info.previous_screen)
6172 g_object_ref (info.previous_screen);
6173 if (previous_toplevel)
6174 g_object_ref (previous_toplevel);
6176 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6178 if (previous_toplevel)
6179 g_object_unref (previous_toplevel);
6180 if (info.previous_screen)
6181 g_object_unref (info.previous_screen);
6185 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6186 gpointer client_data)
6188 HierarchyChangedInfo *info = client_data;
6190 g_object_ref (widget);
6192 do_screen_change (widget, info->previous_screen, info->new_screen);
6194 if (GTK_IS_CONTAINER (widget))
6195 gtk_container_forall (GTK_CONTAINER (widget),
6196 gtk_widget_propagate_screen_changed_recurse,
6199 g_object_unref (widget);
6203 * gtk_widget_is_composited:
6204 * @widget: a #GtkWidget
6206 * Whether @widget can rely on having its alpha channel
6207 * drawn correctly. On X11 this function returns whether a
6208 * compositing manager is running for @widget's screen.
6210 * Please note that the semantics of this call will change
6211 * in the future if used on a widget that has a composited
6212 * window in its heirarchy (as set by
6213 * gdk_window_set_composited()).
6215 * Return value: %TRUE if the widget can rely on its alpha
6216 * channel being drawn correctly.
6221 gtk_widget_is_composited (GtkWidget *widget)
6225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6227 screen = gtk_widget_get_screen (widget);
6229 return gdk_screen_is_composited (screen);
6233 propagate_composited_changed (GtkWidget *widget,
6236 if (GTK_IS_CONTAINER (widget))
6238 gtk_container_forall (GTK_CONTAINER (widget),
6239 propagate_composited_changed,
6243 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6247 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6249 propagate_composited_changed (widget, NULL);
6253 * _gtk_widget_propagate_screen_changed:
6254 * @widget: a #GtkWidget
6255 * @previous_screen: Previous screen
6257 * Propagates changes in the screen for a widget to all
6258 * children, emitting #GtkWidget::screen-changed.
6261 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6262 GdkScreen *previous_screen)
6264 HierarchyChangedInfo info;
6266 info.previous_screen = previous_screen;
6267 info.new_screen = gtk_widget_get_screen (widget);
6269 if (previous_screen)
6270 g_object_ref (previous_screen);
6272 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6274 if (previous_screen)
6275 g_object_unref (previous_screen);
6279 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6281 if (GTK_WIDGET_RC_STYLE (widget))
6282 gtk_widget_reset_rc_style (widget);
6284 if (GTK_IS_CONTAINER (widget))
6285 gtk_container_forall (GTK_CONTAINER (widget),
6286 reset_rc_styles_recurse,
6291 gtk_widget_reset_rc_styles (GtkWidget *widget)
6293 g_return_if_fail (GTK_IS_WIDGET (widget));
6295 reset_rc_styles_recurse (widget, NULL);
6299 * gtk_widget_get_default_style:
6301 * Returns the default style used by all widgets initially.
6303 * Returns: the default style. This #GtkStyle object is owned
6304 * by GTK+ and should not be modified or freed.
6307 gtk_widget_get_default_style (void)
6309 if (!gtk_default_style)
6311 gtk_default_style = gtk_style_new ();
6312 g_object_ref (gtk_default_style);
6315 return gtk_default_style;
6318 static PangoContext *
6319 gtk_widget_peek_pango_context (GtkWidget *widget)
6321 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6325 * gtk_widget_get_pango_context:
6326 * @widget: a #GtkWidget
6328 * Gets a #PangoContext with the appropriate font map, font description,
6329 * and base direction for this widget. Unlike the context returned
6330 * by gtk_widget_create_pango_context(), this context is owned by
6331 * the widget (it can be used until the screen for the widget changes
6332 * or the widget is removed from its toplevel), and will be updated to
6333 * match any changes to the widget's attributes.
6335 * If you create and keep a #PangoLayout using this context, you must
6336 * deal with changes to the context by calling pango_layout_context_changed()
6337 * on the layout in response to the #GtkWidget::style-set and
6338 * #GtkWidget::direction-changed signals for the widget.
6340 * Return value: the #PangoContext for the widget.
6343 gtk_widget_get_pango_context (GtkWidget *widget)
6345 PangoContext *context;
6347 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6349 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6352 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6353 g_object_set_qdata_full (G_OBJECT (widget),
6354 quark_pango_context,
6363 update_pango_context (GtkWidget *widget,
6364 PangoContext *context)
6366 pango_context_set_font_description (context, widget->style->font_desc);
6367 pango_context_set_base_dir (context,
6368 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6369 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6373 gtk_widget_update_pango_context (GtkWidget *widget)
6375 PangoContext *context = gtk_widget_peek_pango_context (widget);
6381 update_pango_context (widget, context);
6383 screen = gtk_widget_get_screen_unchecked (widget);
6386 pango_cairo_context_set_resolution (context,
6387 gdk_screen_get_resolution (screen));
6388 pango_cairo_context_set_font_options (context,
6389 gdk_screen_get_font_options (screen));
6395 * gtk_widget_create_pango_context:
6396 * @widget: a #GtkWidget
6398 * Creates a new #PangoContext with the appropriate font map,
6399 * font description, and base direction for drawing text for
6400 * this widget. See also gtk_widget_get_pango_context().
6402 * Return value: the new #PangoContext
6405 gtk_widget_create_pango_context (GtkWidget *widget)
6408 PangoContext *context;
6410 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6412 screen = gtk_widget_get_screen_unchecked (widget);
6415 GTK_NOTE (MULTIHEAD,
6416 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6418 screen = gdk_screen_get_default ();
6421 context = gdk_pango_context_get_for_screen (screen);
6423 update_pango_context (widget, context);
6424 pango_context_set_language (context, gtk_get_default_language ());
6430 * gtk_widget_create_pango_layout:
6431 * @widget: a #GtkWidget
6432 * @text: text to set on the layout (can be %NULL)
6434 * Creates a new #PangoLayout with the appropriate font map,
6435 * font description, and base direction for drawing text for
6438 * If you keep a #PangoLayout created in this way around, in order to
6439 * notify the layout of changes to the base direction or font of this
6440 * widget, you must call pango_layout_context_changed() in response to
6441 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6444 * Return value: the new #PangoLayout
6447 gtk_widget_create_pango_layout (GtkWidget *widget,
6450 PangoLayout *layout;
6451 PangoContext *context;
6453 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6455 context = gtk_widget_get_pango_context (widget);
6456 layout = pango_layout_new (context);
6459 pango_layout_set_text (layout, text, -1);
6465 * gtk_widget_render_icon:
6466 * @widget: a #GtkWidget
6467 * @stock_id: a stock ID
6468 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6469 * the size of the source and don't scale (if there are multiple
6470 * source sizes, GTK+ picks one of the available sizes).
6471 * @detail: render detail to pass to theme engine
6473 * A convenience function that uses the theme engine and RC file
6474 * settings for @widget to look up @stock_id and render it to
6475 * a pixbuf. @stock_id should be a stock icon ID such as
6476 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6477 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6478 * identifies the widget or code doing the rendering, so that
6479 * theme engines can special-case rendering for that widget or code.
6481 * The pixels in the returned #GdkPixbuf are shared with the rest of
6482 * the application and should not be modified. The pixbuf should be freed
6483 * after use with g_object_unref().
6485 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6488 gtk_widget_render_icon (GtkWidget *widget,
6489 const gchar *stock_id,
6491 const gchar *detail)
6493 GtkIconSet *icon_set;
6496 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6497 g_return_val_if_fail (stock_id != NULL, NULL);
6498 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6500 gtk_widget_ensure_style (widget);
6502 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6504 if (icon_set == NULL)
6507 retval = gtk_icon_set_render_icon (icon_set,
6509 gtk_widget_get_direction (widget),
6510 GTK_WIDGET_STATE (widget),
6519 * gtk_widget_set_parent_window:
6520 * @widget: a #GtkWidget.
6521 * @parent_window: the new parent window.
6523 * Sets a non default parent window for @widget.
6526 gtk_widget_set_parent_window (GtkWidget *widget,
6527 GdkWindow *parent_window)
6529 GdkWindow *old_parent_window;
6531 g_return_if_fail (GTK_IS_WIDGET (widget));
6533 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6534 quark_parent_window);
6536 if (parent_window != old_parent_window)
6538 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6540 if (old_parent_window)
6541 g_object_unref (old_parent_window);
6543 g_object_ref (parent_window);
6549 * gtk_widget_set_child_visible:
6550 * @widget: a #GtkWidget
6551 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6553 * Sets whether @widget should be mapped along with its when its parent
6554 * is mapped and @widget has been shown with gtk_widget_show().
6556 * The child visibility can be set for widget before it is added to
6557 * a container with gtk_widget_set_parent(), to avoid mapping
6558 * children unnecessary before immediately unmapping them. However
6559 * it will be reset to its default state of %TRUE when the widget
6560 * is removed from a container.
6562 * Note that changing the child visibility of a widget does not
6563 * queue a resize on the widget. Most of the time, the size of
6564 * a widget is computed from all visible children, whether or
6565 * not they are mapped. If this is not the case, the container
6566 * can queue a resize itself.
6568 * This function is only useful for container implementations and
6569 * never should be called by an application.
6572 gtk_widget_set_child_visible (GtkWidget *widget,
6573 gboolean is_visible)
6575 g_return_if_fail (GTK_IS_WIDGET (widget));
6576 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6578 g_object_ref (widget);
6581 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6584 GtkWidget *toplevel;
6586 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6588 toplevel = gtk_widget_get_toplevel (widget);
6589 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6590 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6593 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6595 if (GTK_WIDGET_MAPPED (widget->parent) &&
6596 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6597 GTK_WIDGET_VISIBLE (widget))
6598 gtk_widget_map (widget);
6600 gtk_widget_unmap (widget);
6603 g_object_unref (widget);
6607 * gtk_widget_get_child_visible:
6608 * @widget: a #GtkWidget
6610 * Gets the value set with gtk_widget_set_child_visible().
6611 * If you feel a need to use this function, your code probably
6612 * needs reorganization.
6614 * This function is only useful for container implementations and
6615 * never should be called by an application.
6617 * Return value: %TRUE if the widget is mapped with the parent.
6620 gtk_widget_get_child_visible (GtkWidget *widget)
6622 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6624 return GTK_WIDGET_CHILD_VISIBLE (widget);
6628 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6630 GtkWidget *toplevel;
6632 toplevel = gtk_widget_get_toplevel (widget);
6634 if (GTK_WIDGET_TOPLEVEL (toplevel))
6636 if (GTK_IS_WINDOW (toplevel))
6637 return GTK_WINDOW (toplevel)->screen;
6638 else if (GTK_IS_INVISIBLE (toplevel))
6639 return GTK_INVISIBLE (widget)->screen;
6646 * gtk_widget_get_screen:
6647 * @widget: a #GtkWidget
6649 * Get the #GdkScreen from the toplevel window associated with
6650 * this widget. This function can only be called after the widget
6651 * has been added to a widget hierarchy with a #GtkWindow
6654 * In general, you should only create screen specific
6655 * resources when a widget has been realized, and you should
6656 * free those resources when the widget is unrealized.
6658 * Return value: the #GdkScreen for the toplevel for this widget.
6663 gtk_widget_get_screen (GtkWidget *widget)
6667 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6669 screen = gtk_widget_get_screen_unchecked (widget);
6676 g_warning (G_STRLOC ": Can't get associated screen"
6677 " for a widget unless it is inside a toplevel GtkWindow\n"
6678 " widget type is %s associated top level type is %s",
6679 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6680 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6682 return gdk_screen_get_default ();
6687 * gtk_widget_has_screen:
6688 * @widget: a #GtkWidget
6690 * Checks whether there is a #GdkScreen is associated with
6691 * this widget. All toplevel widgets have an associated
6692 * screen, and all widgets added into a heirarchy with a toplevel
6693 * window at the top.
6695 * Return value: %TRUE if there is a #GdkScreen associcated
6701 gtk_widget_has_screen (GtkWidget *widget)
6703 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6705 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6709 * gtk_widget_get_display:
6710 * @widget: a #GtkWidget
6712 * Get the #GdkDisplay for the toplevel window associated with
6713 * this widget. This function can only be called after the widget
6714 * has been added to a widget hierarchy with a #GtkWindow at the top.
6716 * In general, you should only create display specific
6717 * resources when a widget has been realized, and you should
6718 * free those resources when the widget is unrealized.
6720 * Return value: the #GdkDisplay for the toplevel for this widget.
6725 gtk_widget_get_display (GtkWidget *widget)
6727 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6729 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6733 * gtk_widget_get_root_window:
6734 * @widget: a #GtkWidget
6736 * Get the root window where this widget is located. This function can
6737 * only be called after the widget has been added to a widget
6738 * heirarchy with #GtkWindow at the top.
6740 * The root window is useful for such purposes as creating a popup
6741 * #GdkWindow associated with the window. In general, you should only
6742 * create display specific resources when a widget has been realized,
6743 * and you should free those resources when the widget is unrealized.
6745 * Return value: the #GdkWindow root window for the toplevel for this widget.
6750 gtk_widget_get_root_window (GtkWidget *widget)
6752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6754 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6758 * gtk_widget_get_parent_window:
6759 * @widget: a #GtkWidget.
6760 * @returns: the parent window of @widget.
6762 * Gets @widget's parent window.
6765 gtk_widget_get_parent_window (GtkWidget *widget)
6767 GdkWindow *parent_window;
6769 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6771 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6773 return (parent_window != NULL) ? parent_window :
6774 (widget->parent != NULL) ? widget->parent->window : NULL;
6778 * gtk_widget_child_focus:
6779 * @widget: a #GtkWidget
6780 * @direction: direction of focus movement
6782 * This function is used by custom widget implementations; if you're
6783 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6784 * to a particular widget, and gtk_container_set_focus_chain() to
6785 * change the focus tab order. So you may want to investigate those
6786 * functions instead.
6788 * gtk_widget_child_focus() is called by containers as the user moves
6789 * around the window using keyboard shortcuts. @direction indicates
6790 * what kind of motion is taking place (up, down, left, right, tab
6791 * forward, tab backward). gtk_widget_child_focus() emits the
6792 * #GtkWidget::focus" signal; widgets override the default handler
6793 * for this signal in order to implement appropriate focus behavior.
6795 * The default ::focus handler for a widget should return %TRUE if
6796 * moving in @direction left the focus on a focusable location inside
6797 * that widget, and %FALSE if moving in @direction moved the focus
6798 * outside the widget. If returning %TRUE, widgets normally
6799 * call gtk_widget_grab_focus() to place the focus accordingly;
6800 * if returning %FALSE, they don't modify the current focus location.
6802 * This function replaces gtk_container_focus() from GTK+ 1.2.
6803 * It was necessary to check that the child was visible, sensitive,
6804 * and focusable before calling gtk_container_focus().
6805 * gtk_widget_child_focus() returns %FALSE if the widget is not
6806 * currently in a focusable state, so there's no need for those checks.
6808 * Return value: %TRUE if focus ended up inside @widget
6811 gtk_widget_child_focus (GtkWidget *widget,
6812 GtkDirectionType direction)
6814 gboolean return_val;
6816 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6818 if (!GTK_WIDGET_VISIBLE (widget) ||
6819 !GTK_WIDGET_IS_SENSITIVE (widget))
6822 /* child widgets must set CAN_FOCUS, containers
6823 * don't have to though.
6825 if (!GTK_IS_CONTAINER (widget) &&
6826 !GTK_WIDGET_CAN_FOCUS (widget))
6829 g_signal_emit (widget,
6830 widget_signals[FOCUS],
6832 direction, &return_val);
6838 * gtk_widget_keynav_failed:
6839 * @widget: a #GtkWidget
6840 * @direction: direction of focus movement
6842 * This function should be called whenever keyboard navigation within
6843 * a single widget hits a boundary. The function emits the
6844 * #GtkWidget::keynav-failed signal on the widget and its return
6845 * value should be interpreted in a way similar to the return value of
6846 * gtk_widget_child_focus():
6848 * When %TRUE is returned, stay in the widget, the failed keyboard
6849 * navigation is Ok and/or there is nowhere we can/should move the
6852 * When %FALSE is returned, the caller should continue with keyboard
6853 * navigation outside the widget, e.g. by calling
6854 * gtk_widget_child_focus() on the widget's toplevel.
6856 * The default ::keynav-failed handler returns %TRUE for
6857 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6858 * values of #GtkDirectionType, it looks at the
6859 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6860 * if the setting is %TRUE. This way the entire user interface
6861 * becomes cursor-navigatable on input devices such as mobile phones
6862 * which only have cursor keys but no tab key.
6864 * Whenever the default handler returns %TRUE, it also calls
6865 * gtk_widget_error_bell() to notify the user of the failed keyboard
6868 * A use case for providing an own implementation of ::keynav-failed
6869 * (either by connecting to it or by overriding it) would be a row of
6870 * #GtkEntry widgets where the user should be able to navigate the
6871 * entire row with the cursor keys, as e.g. known from user interfaces
6872 * that require entering license keys.
6874 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6875 * if the emitting widget should try to handle the keyboard
6876 * navigation attempt in its parent container(s).
6881 gtk_widget_keynav_failed (GtkWidget *widget,
6882 GtkDirectionType direction)
6884 gboolean return_val;
6886 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6888 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6889 direction, &return_val);
6895 * gtk_widget_error_bell:
6896 * @widget: a #GtkWidget
6898 * Notifies the user about an input-related error on this widget.
6899 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6900 * gdk_window_beep(), otherwise it does nothing.
6902 * Note that the effect of gdk_window_beep() can be configured in many
6903 * ways, depending on the windowing backend and the desktop environment
6904 * or window manager that is used.
6909 gtk_widget_error_bell (GtkWidget *widget)
6913 g_return_if_fail (GTK_IS_WIDGET (widget));
6915 g_object_get (gtk_widget_get_settings (widget),
6916 "gtk-error-bell", &beep,
6919 if (beep && widget->window)
6920 gdk_window_beep (widget->window);
6924 * gtk_widget_set_uposition:
6925 * @widget: a #GtkWidget
6926 * @x: x position; -1 to unset x; -2 to leave x unchanged
6927 * @y: y position; -1 to unset y; -2 to leave y unchanged
6930 * Sets the position of a widget. The funny "u" in the name comes from
6931 * the "user position" hint specified by the X Window System, and
6932 * exists for legacy reasons. This function doesn't work if a widget
6933 * is inside a container; it's only really useful on #GtkWindow.
6935 * Don't use this function to center dialogs over the main application
6936 * window; most window managers will do the centering on your behalf
6937 * if you call gtk_window_set_transient_for(), and it's really not
6938 * possible to get the centering to work correctly in all cases from
6939 * application code. But if you insist, use gtk_window_set_position()
6940 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6943 * Note that although @x and @y can be individually unset, the position
6944 * is not honoured unless both @x and @y are set.
6947 gtk_widget_set_uposition (GtkWidget *widget,
6951 /* FIXME this function is the only place that aux_info->x and
6952 * aux_info->y are even used I believe, and this function is
6953 * deprecated. Should be cleaned up.
6955 * (Actually, size_allocate uses them) -Yosh
6958 GtkWidgetAuxInfo *aux_info;
6960 g_return_if_fail (GTK_IS_WIDGET (widget));
6962 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
6967 aux_info->x_set = FALSE;
6970 aux_info->x_set = TRUE;
6978 aux_info->y_set = FALSE;
6981 aux_info->y_set = TRUE;
6986 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
6987 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
6989 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
6990 gtk_widget_size_allocate (widget, &widget->allocation);
6994 gtk_widget_set_usize_internal (GtkWidget *widget,
6998 GtkWidgetAuxInfo *aux_info;
6999 gboolean changed = FALSE;
7001 g_object_freeze_notify (G_OBJECT (widget));
7003 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7005 if (width > -2 && aux_info->width != width)
7007 g_object_notify (G_OBJECT (widget), "width-request");
7008 aux_info->width = width;
7011 if (height > -2 && aux_info->height != height)
7013 g_object_notify (G_OBJECT (widget), "height-request");
7014 aux_info->height = height;
7018 if (GTK_WIDGET_VISIBLE (widget) && changed)
7019 gtk_widget_queue_resize (widget);
7021 g_object_thaw_notify (G_OBJECT (widget));
7025 * gtk_widget_set_usize:
7026 * @widget: a #GtkWidget
7027 * @width: minimum width, or -1 to unset
7028 * @height: minimum height, or -1 to unset
7030 * Sets the minimum size of a widget; that is, the widget's size
7031 * request will be @width by @height. You can use this function to
7032 * force a widget to be either larger or smaller than it is. The
7033 * strange "usize" name dates from the early days of GTK+, and derives
7034 * from X Window System terminology. In many cases,
7035 * gtk_window_set_default_size() is a better choice for toplevel
7036 * windows than this function; setting the default size will still
7037 * allow users to shrink the window. Setting the usize will force them
7038 * to leave the window at least as large as the usize. When dealing
7039 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7042 * Note the inherent danger of setting any fixed size - themes,
7043 * translations into other languages, different fonts, and user action
7044 * can all change the appropriate size for a given widget. So, it's
7045 * basically impossible to hardcode a size that will always be
7048 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7051 gtk_widget_set_usize (GtkWidget *widget,
7055 g_return_if_fail (GTK_IS_WIDGET (widget));
7057 gtk_widget_set_usize_internal (widget, width, height);
7061 * gtk_widget_set_size_request:
7062 * @widget: a #GtkWidget
7063 * @width: width @widget should request, or -1 to unset
7064 * @height: height @widget should request, 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 normally
7071 * In most cases, gtk_window_set_default_size() is a better choice for
7072 * toplevel windows than this function; setting the default size will
7073 * still allow users to shrink the window. Setting the size request
7074 * will force them to leave the window at least as large as the size
7075 * request. When dealing with window sizes,
7076 * gtk_window_set_geometry_hints() can be a useful function as well.
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 * The size request of a widget is the smallest size a widget can
7085 * accept while still functioning well and drawing itself correctly.
7086 * However in some strange cases a widget may be allocated less than
7087 * its requested size, and in many cases a widget may be allocated more
7088 * space than it requested.
7090 * If the size request in a given direction is -1 (unset), then
7091 * the "natural" size request of the widget will be used instead.
7093 * Widgets can't actually be allocated a size less than 1 by 1, but
7094 * you can pass 0,0 to this function to mean "as small as possible."
7097 gtk_widget_set_size_request (GtkWidget *widget,
7101 g_return_if_fail (GTK_IS_WIDGET (widget));
7102 g_return_if_fail (width >= -1);
7103 g_return_if_fail (height >= -1);
7110 gtk_widget_set_usize_internal (widget, width, height);
7115 * gtk_widget_get_size_request:
7116 * @widget: a #GtkWidget
7117 * @width: return location for width, or %NULL
7118 * @height: return location for height, or %NULL
7120 * Gets the size request that was explicitly set for the widget using
7121 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7122 * @height indicates that that dimension has not been set explicitly
7123 * and the natural requisition of the widget will be used intead. See
7124 * gtk_widget_set_size_request(). To get the size a widget will
7125 * actually use, call gtk_widget_size_request() instead of
7129 gtk_widget_get_size_request (GtkWidget *widget,
7133 GtkWidgetAuxInfo *aux_info;
7135 g_return_if_fail (GTK_IS_WIDGET (widget));
7137 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7140 *width = aux_info ? aux_info->width : -1;
7143 *height = aux_info ? aux_info->height : -1;
7147 * gtk_widget_set_events:
7148 * @widget: a #GtkWidget
7149 * @events: event mask
7151 * Sets the event mask (see #GdkEventMask) for a widget. The event
7152 * mask determines which events a widget will receive. Keep in mind
7153 * that different widgets have different default event masks, and by
7154 * changing the event mask you may disrupt a widget's functionality,
7155 * so be careful. This function must be called while a widget is
7156 * unrealized. Consider gtk_widget_add_events() for widgets that are
7157 * already realized, or if you want to preserve the existing event
7158 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7159 * to get events on those widgets, place them inside a #GtkEventBox
7160 * and receive events on the event box.
7163 gtk_widget_set_events (GtkWidget *widget,
7166 g_return_if_fail (GTK_IS_WIDGET (widget));
7167 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7169 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7170 GINT_TO_POINTER (events));
7171 g_object_notify (G_OBJECT (widget), "events");
7175 gtk_widget_add_events_internal (GtkWidget *widget,
7181 for (l = window_list; l != NULL; l = l->next)
7183 GdkWindow *window = l->data;
7186 gdk_window_get_user_data (window, &user_data);
7187 if (user_data == widget)
7191 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7193 children = gdk_window_get_children (window);
7194 gtk_widget_add_events_internal (widget, events, children);
7195 g_list_free (children);
7201 * gtk_widget_add_events:
7202 * @widget: a #GtkWidget
7203 * @events: an event mask, see #GdkEventMask
7205 * Adds the events in the bitfield @events to the event mask for
7206 * @widget. See gtk_widget_set_events() for details.
7209 gtk_widget_add_events (GtkWidget *widget,
7214 g_return_if_fail (GTK_IS_WIDGET (widget));
7216 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7217 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7218 GINT_TO_POINTER (old_events | events));
7220 if (GTK_WIDGET_REALIZED (widget))
7224 if (GTK_WIDGET_NO_WINDOW (widget))
7225 window_list = gdk_window_get_children (widget->window);
7227 window_list = g_list_prepend (NULL, widget->window);
7229 gtk_widget_add_events_internal (widget, events, window_list);
7231 g_list_free (window_list);
7234 g_object_notify (G_OBJECT (widget), "events");
7238 * gtk_widget_set_extension_events:
7239 * @widget: a #GtkWidget
7240 * @mode: bitfield of extension events to receive
7242 * Sets the extension events mask to @mode. See #GdkExtensionMode
7243 * and gdk_input_set_extension_events().
7246 gtk_widget_set_extension_events (GtkWidget *widget,
7247 GdkExtensionMode mode)
7249 g_return_if_fail (GTK_IS_WIDGET (widget));
7251 if (GTK_WIDGET_REALIZED (widget))
7252 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7254 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7255 GINT_TO_POINTER (mode));
7256 g_object_notify (G_OBJECT (widget), "extension-events");
7260 * gtk_widget_get_toplevel:
7261 * @widget: a #GtkWidget
7263 * This function returns the topmost widget in the container hierarchy
7264 * @widget is a part of. If @widget has no parent widgets, it will be
7265 * returned as the topmost widget. No reference will be added to the
7266 * returned widget; it should not be unreferenced.
7268 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7269 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7271 * %NULL if @widget wasn't inside a toplevel window, and if the
7272 * window was inside a #GtkWindow-derived widget which was in turn
7273 * inside the toplevel #GtkWindow. While the second case may
7274 * seem unlikely, it actually happens when a #GtkPlug is embedded
7275 * inside a #GtkSocket within the same application.
7277 * To reliably find the toplevel #GtkWindow, use
7278 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7279 * is set on the result.
7281 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7282 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7284 * /* Perform action on toplevel. */
7288 * Return value: the topmost ancestor of @widget, or @widget itself
7289 * if there's no ancestor.
7292 gtk_widget_get_toplevel (GtkWidget *widget)
7294 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7296 while (widget->parent)
7297 widget = widget->parent;
7303 * gtk_widget_get_ancestor:
7304 * @widget: a #GtkWidget
7305 * @widget_type: ancestor type
7307 * Gets the first ancestor of @widget with type @widget_type. For example,
7308 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7309 * the first #GtkBox that's an ancestor of @widget. No reference will be
7310 * added to the returned widget; it should not be unreferenced. See note
7311 * about checking for a toplevel #GtkWindow in the docs for
7312 * gtk_widget_get_toplevel().
7314 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7315 * considers @widget to be an ancestor of itself.
7317 * Return value: the ancestor widget, or %NULL if not found
7320 gtk_widget_get_ancestor (GtkWidget *widget,
7323 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7325 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7326 widget = widget->parent;
7328 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7335 * gtk_widget_get_colormap:
7336 * @widget: a #GtkWidget
7338 * Gets the colormap that will be used to render @widget. No reference will
7339 * be added to the returned colormap; it should not be unreferenced.
7341 * Return value: the colormap used by @widget
7344 gtk_widget_get_colormap (GtkWidget *widget)
7346 GdkColormap *colormap;
7347 GtkWidget *tmp_widget;
7349 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7353 colormap = gdk_drawable_get_colormap (widget->window);
7354 /* If window was destroyed previously, we'll get NULL here */
7359 tmp_widget = widget;
7362 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7366 tmp_widget= tmp_widget->parent;
7369 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7373 * gtk_widget_get_visual:
7374 * @widget: a #GtkWidget
7376 * Gets the visual that will be used to render @widget.
7378 * Return value: the visual for @widget
7381 gtk_widget_get_visual (GtkWidget *widget)
7383 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7385 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7389 * gtk_widget_get_settings:
7390 * @widget: a #GtkWidget
7392 * Gets the settings object holding the settings (global property
7393 * settings, RC file information, etc) used for this widget.
7395 * Note that this function can only be called when the #GtkWidget
7396 * is attached to a toplevel, since the settings object is specific
7397 * to a particular #GdkScreen.
7399 * Return value: the relevant #GtkSettings object
7402 gtk_widget_get_settings (GtkWidget *widget)
7404 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7406 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7410 * gtk_widget_set_colormap:
7411 * @widget: a #GtkWidget
7412 * @colormap: a colormap
7414 * Sets the colormap for the widget to the given value. Widget must not
7415 * have been previously realized. This probably should only be used
7416 * from an <function>init()</function> function (i.e. from the constructor
7420 gtk_widget_set_colormap (GtkWidget *widget,
7421 GdkColormap *colormap)
7423 g_return_if_fail (GTK_IS_WIDGET (widget));
7424 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7425 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7427 g_object_ref (colormap);
7429 g_object_set_qdata_full (G_OBJECT (widget),
7436 * gtk_widget_get_events:
7437 * @widget: a #GtkWidget
7439 * Returns the event mask for the widget (a bitfield containing flags
7440 * from the #GdkEventMask enumeration). These are the events that the widget
7443 * Return value: event mask for @widget
7446 gtk_widget_get_events (GtkWidget *widget)
7448 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7450 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7454 * gtk_widget_get_extension_events:
7455 * @widget: a #GtkWidget
7457 * Retrieves the extension events the widget will receive; see
7458 * gdk_input_set_extension_events().
7460 * Return value: extension events for @widget
7463 gtk_widget_get_extension_events (GtkWidget *widget)
7465 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7467 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7471 * gtk_widget_get_pointer:
7472 * @widget: a #GtkWidget
7473 * @x: return location for the X coordinate, or %NULL
7474 * @y: return location for the Y coordinate, or %NULL
7476 * Obtains the location of the mouse pointer in widget coordinates.
7477 * Widget coordinates are a bit odd; for historical reasons, they are
7478 * defined as @widget->window coordinates for widgets that are not
7479 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7480 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7483 gtk_widget_get_pointer (GtkWidget *widget,
7487 g_return_if_fail (GTK_IS_WIDGET (widget));
7494 if (GTK_WIDGET_REALIZED (widget))
7496 gdk_window_get_pointer (widget->window, x, y, NULL);
7498 if (GTK_WIDGET_NO_WINDOW (widget))
7501 *x -= widget->allocation.x;
7503 *y -= widget->allocation.y;
7509 * gtk_widget_is_ancestor:
7510 * @widget: a #GtkWidget
7511 * @ancestor: another #GtkWidget
7513 * Determines whether @widget is somewhere inside @ancestor, possibly with
7514 * intermediate containers.
7516 * Return value: %TRUE if @ancestor contains @widget as a child,
7517 * grandchild, great grandchild, etc.
7520 gtk_widget_is_ancestor (GtkWidget *widget,
7521 GtkWidget *ancestor)
7523 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7524 g_return_val_if_fail (ancestor != NULL, FALSE);
7528 if (widget->parent == ancestor)
7530 widget = widget->parent;
7536 static GQuark quark_composite_name = 0;
7539 * gtk_widget_set_composite_name:
7540 * @widget: a #GtkWidget.
7541 * @name: the name to set
7543 * Sets a widgets composite name. The widget must be
7544 * a composite child of its parent; see gtk_widget_push_composite_child().
7547 gtk_widget_set_composite_name (GtkWidget *widget,
7550 g_return_if_fail (GTK_IS_WIDGET (widget));
7551 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7552 g_return_if_fail (name != NULL);
7554 if (!quark_composite_name)
7555 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7557 g_object_set_qdata_full (G_OBJECT (widget),
7558 quark_composite_name,
7564 * gtk_widget_get_composite_name:
7565 * @widget: a #GtkWidget
7566 * @returns: the composite name of @widget, or %NULL if @widget is not
7567 * a composite child. The string should not be freed when it is no
7570 * Obtains the composite name of a widget.
7573 gtk_widget_get_composite_name (GtkWidget *widget)
7575 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7577 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7578 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7585 * gtk_widget_push_composite_child:
7587 * Makes all newly-created widgets as composite children until
7588 * the corresponding gtk_widget_pop_composite_child() call.
7590 * A composite child is a child that's an implementation detail of the
7591 * container it's inside and should not be visible to people using the
7592 * container. Composite children aren't treated differently by GTK (but
7593 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7594 * builders might want to treat them in a different way.
7596 * Here is a simple example:
7598 * gtk_widget_push_composite_child ();
7599 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7600 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7601 * gtk_widget_pop_composite_child ();
7602 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7603 * GTK_WIDGET (scrolled_window));
7604 * g_object_ref (scrolled_window->hscrollbar);
7608 gtk_widget_push_composite_child (void)
7610 composite_child_stack++;
7614 * gtk_widget_pop_composite_child:
7616 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7619 gtk_widget_pop_composite_child (void)
7621 if (composite_child_stack)
7622 composite_child_stack--;
7626 * gtk_widget_push_colormap:
7627 * @cmap: a #GdkColormap
7629 * Pushes @cmap onto a global stack of colormaps; the topmost
7630 * colormap on the stack will be used to create all widgets.
7631 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7632 * reason to use this function.
7635 gtk_widget_push_colormap (GdkColormap *cmap)
7637 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7639 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7643 * gtk_widget_pop_colormap:
7645 * Removes a colormap pushed with gtk_widget_push_colormap().
7648 gtk_widget_pop_colormap (void)
7651 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7655 * gtk_widget_set_default_colormap:
7656 * @colormap: a #GdkColormap
7658 * Sets the default colormap to use when creating widgets.
7659 * gtk_widget_push_colormap() is a better function to use if
7660 * you only want to affect a few widgets, rather than all widgets.
7663 gtk_widget_set_default_colormap (GdkColormap *colormap)
7665 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7667 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7672 * gtk_widget_get_default_colormap:
7674 * Obtains the default colormap used to create widgets.
7676 * Return value: default widget colormap
7679 gtk_widget_get_default_colormap (void)
7681 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7685 * gtk_widget_get_default_visual:
7687 * Obtains the visual of the default colormap. Not really useful;
7688 * used to be useful before gdk_colormap_get_visual() existed.
7690 * Return value: visual of the default colormap
7693 gtk_widget_get_default_visual (void)
7695 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7699 gtk_widget_emit_direction_changed (GtkWidget *widget,
7700 GtkTextDirection old_dir)
7702 gtk_widget_update_pango_context (widget);
7704 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7708 * gtk_widget_set_direction:
7709 * @widget: a #GtkWidget
7710 * @dir: the new direction
7712 * Sets the reading direction on a particular widget. This direction
7713 * controls the primary direction for widgets containing text,
7714 * and also the direction in which the children of a container are
7715 * packed. The ability to set the direction is present in order
7716 * so that correct localization into languages with right-to-left
7717 * reading directions can be done. Generally, applications will
7718 * let the default reading direction present, except for containers
7719 * where the containers are arranged in an order that is explicitely
7720 * visual rather than logical (such as buttons for text justification).
7722 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7723 * set by gtk_widget_set_default_direction() will be used.
7726 gtk_widget_set_direction (GtkWidget *widget,
7727 GtkTextDirection dir)
7729 GtkTextDirection old_dir;
7731 g_return_if_fail (GTK_IS_WIDGET (widget));
7732 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7734 old_dir = gtk_widget_get_direction (widget);
7736 if (dir == GTK_TEXT_DIR_NONE)
7737 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7740 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7741 if (dir == GTK_TEXT_DIR_LTR)
7742 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7744 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7747 if (old_dir != gtk_widget_get_direction (widget))
7748 gtk_widget_emit_direction_changed (widget, old_dir);
7752 * gtk_widget_get_direction:
7753 * @widget: a #GtkWidget
7755 * Gets the reading direction for a particular widget. See
7756 * gtk_widget_set_direction().
7758 * Return value: the reading direction for the widget.
7761 gtk_widget_get_direction (GtkWidget *widget)
7763 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7765 if (GTK_WIDGET_DIRECTION_SET (widget))
7766 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7768 return gtk_default_direction;
7772 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7774 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7776 g_object_ref (widget);
7778 if (!GTK_WIDGET_DIRECTION_SET (widget))
7779 gtk_widget_emit_direction_changed (widget, old_dir);
7781 if (GTK_IS_CONTAINER (widget))
7782 gtk_container_forall (GTK_CONTAINER (widget),
7783 gtk_widget_set_default_direction_recurse,
7786 g_object_unref (widget);
7790 * gtk_widget_set_default_direction:
7791 * @dir: the new default direction. This cannot be
7792 * %GTK_TEXT_DIR_NONE.
7794 * Sets the default reading direction for widgets where the
7795 * direction has not been explicitly set by gtk_widget_set_direction().
7798 gtk_widget_set_default_direction (GtkTextDirection dir)
7800 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7802 if (dir != gtk_default_direction)
7804 GList *toplevels, *tmp_list;
7805 GtkTextDirection old_dir = gtk_default_direction;
7807 gtk_default_direction = dir;
7809 tmp_list = toplevels = gtk_window_list_toplevels ();
7810 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7814 gtk_widget_set_default_direction_recurse (tmp_list->data,
7815 GUINT_TO_POINTER (old_dir));
7816 g_object_unref (tmp_list->data);
7817 tmp_list = tmp_list->next;
7820 g_list_free (toplevels);
7825 * gtk_widget_get_default_direction:
7827 * Obtains the current default reading direction. See
7828 * gtk_widget_set_default_direction().
7830 * Return value: the current default direction.
7833 gtk_widget_get_default_direction (void)
7835 return gtk_default_direction;
7839 gtk_widget_dispose (GObject *object)
7841 GtkWidget *widget = GTK_WIDGET (object);
7844 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7845 else if (GTK_WIDGET_VISIBLE (widget))
7846 gtk_widget_hide (widget);
7848 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7849 if (GTK_WIDGET_REALIZED (widget))
7850 gtk_widget_unrealize (widget);
7852 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7856 gtk_widget_real_destroy (GtkObject *object)
7858 /* gtk_object_destroy() will already hold a refcount on object */
7859 GtkWidget *widget = GTK_WIDGET (object);
7861 /* wipe accelerator closures (keep order) */
7862 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7863 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7865 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7866 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7868 gtk_grab_remove (widget);
7870 g_object_unref (widget->style);
7871 widget->style = gtk_widget_get_default_style ();
7872 g_object_ref (widget->style);
7874 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7878 gtk_widget_finalize (GObject *object)
7880 GtkWidget *widget = GTK_WIDGET (object);
7881 GtkWidgetAuxInfo *aux_info;
7882 GtkAccessible *accessible;
7884 gtk_grab_remove (widget);
7886 g_object_unref (widget->style);
7887 widget->style = NULL;
7889 g_free (widget->name);
7891 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7893 gtk_widget_aux_info_destroy (aux_info);
7895 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7897 g_object_unref (accessible);
7899 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7902 /*****************************************
7903 * gtk_widget_real_map:
7908 *****************************************/
7911 gtk_widget_real_map (GtkWidget *widget)
7913 g_assert (GTK_WIDGET_REALIZED (widget));
7915 if (!GTK_WIDGET_MAPPED (widget))
7917 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7919 if (!GTK_WIDGET_NO_WINDOW (widget))
7920 gdk_window_show (widget->window);
7924 /*****************************************
7925 * gtk_widget_real_unmap:
7930 *****************************************/
7933 gtk_widget_real_unmap (GtkWidget *widget)
7935 if (GTK_WIDGET_MAPPED (widget))
7937 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7939 if (!GTK_WIDGET_NO_WINDOW (widget))
7940 gdk_window_hide (widget->window);
7944 /*****************************************
7945 * gtk_widget_real_realize:
7950 *****************************************/
7953 gtk_widget_real_realize (GtkWidget *widget)
7955 g_assert (GTK_WIDGET_NO_WINDOW (widget));
7957 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7960 widget->window = gtk_widget_get_parent_window (widget);
7961 g_object_ref (widget->window);
7963 widget->style = gtk_style_attach (widget->style, widget->window);
7966 /*****************************************
7967 * gtk_widget_real_unrealize:
7972 *****************************************/
7975 gtk_widget_real_unrealize (GtkWidget *widget)
7977 if (GTK_WIDGET_MAPPED (widget))
7978 gtk_widget_real_unmap (widget);
7980 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7982 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
7985 /* We must do unrealize child widget BEFORE container widget.
7986 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
7987 * So, unrealizing container widget bofore its children causes the problem
7988 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
7991 if (GTK_IS_CONTAINER (widget))
7992 gtk_container_forall (GTK_CONTAINER (widget),
7993 (GtkCallback) gtk_widget_unrealize,
7996 gtk_style_detach (widget->style);
7997 if (!GTK_WIDGET_NO_WINDOW (widget))
7999 gdk_window_set_user_data (widget->window, NULL);
8000 gdk_window_destroy (widget->window);
8001 widget->window = NULL;
8005 g_object_unref (widget->window);
8006 widget->window = NULL;
8009 gtk_selection_remove_all (widget);
8011 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8015 gtk_widget_real_size_request (GtkWidget *widget,
8016 GtkRequisition *requisition)
8018 requisition->width = widget->requisition.width;
8019 requisition->height = widget->requisition.height;
8023 * _gtk_widget_peek_colormap:
8025 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8027 * Return value: the currently pushed colormap, or %NULL if there is none.
8030 _gtk_widget_peek_colormap (void)
8033 return (GdkColormap*) colormap_stack->data;
8038 gtk_widget_propagate_state (GtkWidget *widget,
8041 guint8 old_state = GTK_WIDGET_STATE (widget);
8042 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8044 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8045 * parent_sensitive==TRUE on a sensitive widget
8049 if (data->parent_sensitive)
8050 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8052 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8054 if (GTK_WIDGET_IS_SENSITIVE (widget))
8056 if (data->state_restoration)
8057 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8059 GTK_WIDGET_STATE (widget) = data->state;
8063 if (!data->state_restoration)
8065 if (data->state != GTK_STATE_INSENSITIVE)
8066 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8068 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8069 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8070 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8073 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8077 window = gtk_widget_get_toplevel (widget);
8078 if (window && GTK_WIDGET_TOPLEVEL (window))
8079 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8082 if (old_state != GTK_WIDGET_STATE (widget) ||
8083 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8085 g_object_ref (widget);
8087 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8088 gtk_grab_remove (widget);
8090 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8092 if (GTK_IS_CONTAINER (widget))
8094 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8095 if (data->use_forall)
8096 gtk_container_forall (GTK_CONTAINER (widget),
8097 (GtkCallback) gtk_widget_propagate_state,
8100 gtk_container_foreach (GTK_CONTAINER (widget),
8101 (GtkCallback) gtk_widget_propagate_state,
8104 g_object_unref (widget);
8109 * _gtk_widget_get_aux_info:
8110 * @widget: a #GtkWidget
8111 * @create: if %TRUE, create the structure if it doesn't exist
8113 * Get the #GtkWidgetAuxInfo structure for the widget.
8115 * Return value: the #GtkAuxInfo structure for the widget, or
8116 * %NULL if @create is %FALSE and one doesn't already exist.
8119 _gtk_widget_get_aux_info (GtkWidget *widget,
8122 GtkWidgetAuxInfo *aux_info;
8124 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8125 if (!aux_info && create)
8127 aux_info = g_slice_new (GtkWidgetAuxInfo);
8129 aux_info->width = -1;
8130 aux_info->height = -1;
8133 aux_info->x_set = FALSE;
8134 aux_info->y_set = FALSE;
8135 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8141 /*****************************************
8142 * gtk_widget_aux_info_destroy:
8147 *****************************************/
8150 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8152 g_slice_free (GtkWidgetAuxInfo, aux_info);
8156 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8158 g_object_unref (info->shape_mask);
8159 g_slice_free (GtkWidgetShapeInfo, info);
8163 * gtk_widget_shape_combine_mask:
8164 * @widget: a #GtkWidget
8165 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8166 * @offset_x: X position of shape mask with respect to @window
8167 * @offset_y: Y position of shape mask with respect to @window
8169 * Sets a shape for this widget's GDK window. This allows for
8170 * transparent windows etc., see gdk_window_shape_combine_mask()
8171 * for more information.
8174 gtk_widget_shape_combine_mask (GtkWidget *widget,
8175 GdkBitmap *shape_mask,
8179 GtkWidgetShapeInfo* shape_info;
8181 g_return_if_fail (GTK_IS_WIDGET (widget));
8182 /* set_shape doesn't work on widgets without gdk window */
8183 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8187 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8190 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8192 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8196 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8198 shape_info = g_slice_new (GtkWidgetShapeInfo);
8199 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8200 (GDestroyNotify) gtk_widget_shape_info_destroy);
8202 shape_info->shape_mask = g_object_ref (shape_mask);
8203 shape_info->offset_x = offset_x;
8204 shape_info->offset_y = offset_y;
8206 /* set shape if widget has a gdk window already.
8207 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8210 gdk_window_shape_combine_mask (widget->window, shape_mask,
8211 offset_x, offset_y);
8216 * gtk_widget_input_shape_combine_mask:
8217 * @widget: a #GtkWidget
8218 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8219 * @offset_x: X position of shape mask with respect to @window
8220 * @offset_y: Y position of shape mask with respect to @window
8222 * Sets an input shape for this widget's GDK window. This allows for
8223 * windows which react to mouse click in a nonrectangular region, see
8224 * gdk_window_input_shape_combine_mask() for more information.
8229 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8230 GdkBitmap *shape_mask,
8234 GtkWidgetShapeInfo* shape_info;
8236 g_return_if_fail (GTK_IS_WIDGET (widget));
8237 /* set_shape doesn't work on widgets without gdk window */
8238 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8243 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8245 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8249 shape_info = g_slice_new (GtkWidgetShapeInfo);
8250 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8252 (GDestroyNotify) gtk_widget_shape_info_destroy);
8254 shape_info->shape_mask = g_object_ref (shape_mask);
8255 shape_info->offset_x = offset_x;
8256 shape_info->offset_y = offset_y;
8258 /* set shape if widget has a gdk window already.
8259 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8262 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8263 offset_x, offset_y);
8269 gtk_reset_shapes_recurse (GtkWidget *widget,
8275 gdk_window_get_user_data (window, &data);
8279 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8280 for (list = gdk_window_peek_children (window); list; list = list->next)
8281 gtk_reset_shapes_recurse (widget, list->data);
8285 * gtk_widget_reset_shapes:
8286 * @widget: a #GtkWidget
8288 * Recursively resets the shape on this widget and its descendants.
8291 gtk_widget_reset_shapes (GtkWidget *widget)
8293 g_return_if_fail (GTK_IS_WIDGET (widget));
8294 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8296 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8297 gtk_reset_shapes_recurse (widget, widget->window);
8302 * @widget: a #GtkWidget
8304 * Adds a reference to a widget. This function is exactly the same
8305 * as calling g_object_ref(), and exists mostly for historical
8306 * reasons. It can still be convenient to avoid casting a widget
8307 * to a #GObject, it saves a small amount of typing.
8309 * Return value: the widget that was referenced
8311 * Deprecated: 2.12: Use g_object_ref() instead.
8314 gtk_widget_ref (GtkWidget *widget)
8316 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8318 return (GtkWidget*) g_object_ref ((GObject*) widget);
8323 * @widget: a #GtkWidget
8325 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8327 * Deprecated: 2.12: Use g_object_unref() instead.
8330 gtk_widget_unref (GtkWidget *widget)
8332 g_return_if_fail (GTK_IS_WIDGET (widget));
8334 g_object_unref ((GObject*) widget);
8338 * gtk_widget_get_snapshot:
8339 * @widget: a #GtkWidget
8340 * @clip_rect: a #GdkRectangle or %NULL
8342 * Create a #GdkPixmap of the contents of the widget and its children.
8344 * Works even if the widget is obscured. The depth and visual of the
8345 * resulting pixmap is dependent on the widget being snapshot and likely
8346 * differs from those of a target widget displaying the pixmap.
8347 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8348 * the pixmap to a visual independant representation.
8350 * The snapshot area used by this function is the @widget's allocation plus
8351 * any extra space occupied by additional windows belonging to this widget
8352 * (such as the arrows of a spin button).
8353 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8355 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8356 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8357 * interpreted widget relative. If width or height of @clip_rect are 0 or
8358 * negative, the width or height of the resulting pixmap will be shrunken
8359 * by the respective amount.
8360 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8361 * chop off 5 pixels at each side of the snapshot pixmap.
8362 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8363 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8364 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8365 * as a pure output parameter.
8367 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8369 * Return value: #GdkPixmap snapshot of the widget
8374 gtk_widget_get_snapshot (GtkWidget *widget,
8375 GdkRectangle *clip_rect)
8377 int x, y, width, height;
8378 GdkWindow *parent_window = NULL;
8380 GList *windows = NULL, *list;
8382 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8383 if (!GTK_WIDGET_VISIBLE (widget))
8386 /* the widget (and parent_window) must be realized to be drawable */
8387 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8388 gtk_widget_realize (widget->parent);
8389 if (!GTK_WIDGET_REALIZED (widget))
8390 gtk_widget_realize (widget);
8392 /* determine snapshot rectangle */
8393 x = widget->allocation.x;
8394 y = widget->allocation.y;
8395 width = widget->allocation.width;
8396 height = widget->allocation.height;
8398 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8400 /* grow snapshot rectangle to cover all widget windows */
8401 parent_window = gtk_widget_get_parent_window (widget);
8402 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8404 GdkWindow *subwin = list->data;
8407 gdk_window_get_user_data (subwin, &windata);
8408 if (windata != widget)
8410 windows = g_list_prepend (windows, subwin);
8411 gdk_window_get_position (subwin, &wx, &wy);
8412 gdk_drawable_get_size (subwin, &ww, &wh);
8413 /* grow snapshot rectangle by extra widget sub window */
8424 if (x + width < wx + ww)
8425 width += wx + ww - (x + width);
8426 if (y + height < wy + wh)
8427 height += wy + wh - (y + height);
8430 else if (!widget->parent)
8431 x = y = 0; /* toplevel */
8433 /* at this point, (x,y,width,height) is the parent_window relative
8434 * snapshot area covering all of widget's windows.
8437 /* shrink snapshot size by clip_rectangle */
8440 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8441 clip.x = clip.x < 0 ? x : clip.x;
8442 clip.y = clip.y < 0 ? y : clip.y;
8443 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8444 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8447 /* offset clip_rect, so it's parent_window relative */
8448 if (clip_rect->x >= 0)
8449 clip.x += widget->allocation.x;
8450 if (clip_rect->y >= 0)
8451 clip.y += widget->allocation.y;
8453 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8455 g_list_free (windows);
8456 clip_rect->width = clip_rect->height = 0;
8457 return NULL; /* empty snapshot area */
8462 height = snap.height;
8465 /* render snapshot */
8466 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8467 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8469 GdkWindow *subwin = list->data;
8471 gdk_window_get_position (subwin, &wx, &wy);
8472 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8473 MAX (0, wx - x), MAX (0, wy - y), width, height);
8474 gdk_window_invalidate_rect (subwin, NULL, TRUE);
8476 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8478 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8479 gdk_window_invalidate_rect (widget->window, NULL, TRUE);
8481 gtk_widget_queue_draw (widget);
8483 gdk_window_process_updates (parent_window, TRUE);
8484 for (list = windows; list; list = list->next)
8485 gdk_window_process_updates (list->data, TRUE);
8486 gdk_window_process_updates (widget->window, TRUE);
8487 for (list = windows; list; list = list->next)
8488 gdk_window_remove_redirection (list->data);
8489 if (!windows) /* NO_WINDOW || toplevel */
8490 gdk_window_remove_redirection (widget->window);
8491 g_list_free (windows);
8493 /* return pixmap and snapshot rectangle coordinates */
8498 clip_rect->width = width;
8499 clip_rect->height = height;
8502 /* offset clip_rect from parent_window so it's widget relative */
8503 clip_rect->x -= widget->allocation.x;
8504 clip_rect->y -= widget->allocation.y;
8507 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8508 G_OBJECT_TYPE_NAME (widget),
8509 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8518 * gtk_widget_class_install_style_property_parser:
8519 * @klass: a #GtkWidgetClass
8520 * @pspec: the #GParamSpec for the style property
8521 * @parser: the parser for the style property
8523 * Installs a style property on a widget class.
8526 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8528 GtkRcPropertyParser parser)
8530 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8531 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8532 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8533 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8535 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8537 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8538 G_OBJECT_CLASS_NAME (klass),
8543 g_param_spec_ref_sink (pspec);
8544 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8545 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8549 * gtk_widget_class_install_style_property:
8550 * @klass: a #GtkWidgetClass
8551 * @pspec: the #GParamSpec for the property
8553 * Installs a style property on a widget class. The parser for the
8554 * style property is determined by the value type of @pspec.
8557 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8560 GtkRcPropertyParser parser;
8562 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8563 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8565 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8567 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8571 * gtk_widget_class_find_style_property:
8572 * @klass: a #GtkWidgetClass
8573 * @property_name: the name of the style property to find
8574 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8575 * style property with that name.
8577 * Finds a style property of a widget class by name.
8582 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8583 const gchar *property_name)
8585 g_return_val_if_fail (property_name != NULL, NULL);
8587 return g_param_spec_pool_lookup (style_property_spec_pool,
8589 G_OBJECT_CLASS_TYPE (klass),
8594 * gtk_widget_class_list_style_properties:
8595 * @klass: a #GtkWidgetClass
8596 * @n_properties: location to return the number of style properties found
8597 * @returns: an newly allocated array of #GParamSpec*. The array must
8598 * be freed with g_free().
8600 * Returns all style properties of a widget class.
8605 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
8606 guint *n_properties)
8608 GParamSpec **pspecs;
8611 pspecs = g_param_spec_pool_list (style_property_spec_pool,
8612 G_OBJECT_CLASS_TYPE (klass),
8621 * gtk_widget_style_get_property:
8622 * @widget: a #GtkWidget
8623 * @property_name: the name of a style property
8624 * @value: location to return the property value
8626 * Gets the value of a style property of @widget.
8629 gtk_widget_style_get_property (GtkWidget *widget,
8630 const gchar *property_name,
8635 g_return_if_fail (GTK_IS_WIDGET (widget));
8636 g_return_if_fail (property_name != NULL);
8637 g_return_if_fail (G_IS_VALUE (value));
8639 g_object_ref (widget);
8640 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8642 G_OBJECT_TYPE (widget),
8645 g_warning ("%s: widget class `%s' has no property named `%s'",
8647 G_OBJECT_TYPE_NAME (widget),
8651 const GValue *peek_value;
8653 peek_value = _gtk_style_peek_property_value (widget->style,
8654 G_OBJECT_TYPE (widget),
8656 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8658 /* auto-conversion of the caller's value type
8660 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
8661 g_value_copy (peek_value, value);
8662 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
8663 g_value_transform (peek_value, value);
8665 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
8667 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
8668 G_VALUE_TYPE_NAME (value));
8670 g_object_unref (widget);
8674 * gtk_widget_style_get_valist:
8675 * @widget: a #GtkWidget
8676 * @first_property_name: the name of the first property to get
8677 * @var_args: a <type>va_list</type> of pairs of property names and
8678 * locations to return the property values, starting with the location
8679 * for @first_property_name.
8681 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
8685 gtk_widget_style_get_valist (GtkWidget *widget,
8686 const gchar *first_property_name,
8691 g_return_if_fail (GTK_IS_WIDGET (widget));
8693 g_object_ref (widget);
8695 name = first_property_name;
8698 const GValue *peek_value;
8702 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8704 G_OBJECT_TYPE (widget),
8708 g_warning ("%s: widget class `%s' has no property named `%s'",
8710 G_OBJECT_TYPE_NAME (widget),
8714 /* style pspecs are always readable so we can spare that check here */
8716 peek_value = _gtk_style_peek_property_value (widget->style,
8717 G_OBJECT_TYPE (widget),
8719 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8720 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
8723 g_warning ("%s: %s", G_STRLOC, error);
8728 name = va_arg (var_args, gchar*);
8731 g_object_unref (widget);
8735 * gtk_widget_style_get:
8736 * @widget: a #GtkWidget
8737 * @first_property_name: the name of the first property to get
8738 * @Varargs: pairs of property names and locations to
8739 * return the property values, starting with the location for
8740 * @first_property_name, terminated by %NULL.
8742 * Gets the values of a multiple style properties of @widget.
8745 gtk_widget_style_get (GtkWidget *widget,
8746 const gchar *first_property_name,
8751 g_return_if_fail (GTK_IS_WIDGET (widget));
8753 va_start (var_args, first_property_name);
8754 gtk_widget_style_get_valist (widget, first_property_name, var_args);
8760 * @widget: a #GtkWidget
8761 * @path_length: location to store length of the path, or %NULL
8762 * @path: location to store allocated path string, or %NULL
8763 * @path_reversed: location to store allocated reverse path string, or %NULL
8765 * Obtains the full path to @widget. The path is simply the name of a
8766 * widget and all its parents in the container hierarchy, separated by
8767 * periods. The name of a widget comes from
8768 * gtk_widget_get_name(). Paths are used to apply styles to a widget
8769 * in gtkrc configuration files. Widget names are the type of the
8770 * widget by default (e.g. "GtkButton") or can be set to an
8771 * application-specific value with gtk_widget_set_name(). By setting
8772 * the name of a widget, you allow users or theme authors to apply
8773 * styles to that specific widget in their gtkrc
8774 * file. @path_reversed_p fills in the path in reverse order,
8775 * i.e. starting with @widget's name instead of starting with the name
8776 * of @widget's outermost ancestor.
8779 gtk_widget_path (GtkWidget *widget,
8782 gchar **path_reversed)
8784 static gchar *rev_path = NULL;
8785 static guint tmp_path_len = 0;
8788 g_return_if_fail (GTK_IS_WIDGET (widget));
8793 const gchar *string;
8798 string = gtk_widget_get_name (widget);
8799 l = strlen (string);
8800 while (tmp_path_len <= len + l + 1)
8802 tmp_path_len += INIT_PATH_SIZE;
8803 rev_path = g_realloc (rev_path, tmp_path_len);
8811 widget = widget->parent;
8814 rev_path[len++] = '.';
8816 rev_path[len++] = 0;
8821 *path_length = len - 1;
8823 *path_reversed = g_strdup (rev_path);
8826 *path = g_strdup (rev_path);
8827 g_strreverse (*path);
8832 * gtk_widget_class_path:
8833 * @widget: a #GtkWidget
8834 * @path_length: location to store the length of the class path, or %NULL
8835 * @path: location to store the class path as an allocated string, or %NULL
8836 * @path_reversed: location to store the reverse class path as an allocated
8839 * Same as gtk_widget_path(), but always uses the name of a widget's type,
8840 * never uses a custom name set with gtk_widget_set_name().
8844 gtk_widget_class_path (GtkWidget *widget,
8847 gchar **path_reversed)
8849 static gchar *rev_path = NULL;
8850 static guint tmp_path_len = 0;
8853 g_return_if_fail (GTK_IS_WIDGET (widget));
8858 const gchar *string;
8863 string = g_type_name (GTK_WIDGET_TYPE (widget));
8864 l = strlen (string);
8865 while (tmp_path_len <= len + l + 1)
8867 tmp_path_len += INIT_PATH_SIZE;
8868 rev_path = g_realloc (rev_path, tmp_path_len);
8876 widget = widget->parent;
8879 rev_path[len++] = '.';
8881 rev_path[len++] = 0;
8886 *path_length = len - 1;
8888 *path_reversed = g_strdup (rev_path);
8891 *path = g_strdup (rev_path);
8892 g_strreverse (*path);
8897 * gtk_requisition_copy:
8898 * @requisition: a #GtkRequisition
8900 * Copies a #GtkRequisition.
8902 * Returns: a copy of @requisition
8905 gtk_requisition_copy (const GtkRequisition *requisition)
8907 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
8911 * gtk_requisition_free:
8912 * @requisition: a #GtkRequisition
8914 * Frees a #GtkRequisition.
8917 gtk_requisition_free (GtkRequisition *requisition)
8919 g_free (requisition);
8923 gtk_requisition_get_type (void)
8925 static GType our_type = 0;
8928 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
8929 (GBoxedCopyFunc) gtk_requisition_copy,
8930 (GBoxedFreeFunc) gtk_requisition_free);
8936 * gtk_widget_get_accessible:
8937 * @widget: a #GtkWidget
8939 * Returns the accessible object that describes the widget to an
8940 * assistive technology.
8942 * If no accessibility library is loaded (i.e. no ATK implementation library is
8943 * loaded via <envar>GTK_MODULES</envar> or via another application library,
8944 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
8945 * if no class-specific #AtkObject implementation is available for the widget
8946 * instance in question, it will inherit an #AtkObject implementation from the
8947 * first ancestor class for which such an implementation is defined.
8949 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
8950 * library contains more information about accessible objects and their uses.
8952 * Returns: the #AtkObject associated with @widget
8955 gtk_widget_get_accessible (GtkWidget *widget)
8957 GtkWidgetClass *klass;
8959 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8961 klass = GTK_WIDGET_GET_CLASS (widget);
8963 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
8965 return klass->get_accessible (widget);
8969 gtk_widget_real_get_accessible (GtkWidget *widget)
8971 AtkObject* accessible;
8973 accessible = g_object_get_qdata (G_OBJECT (widget),
8974 quark_accessible_object);
8977 AtkObjectFactory *factory;
8978 AtkRegistry *default_registry;
8980 default_registry = atk_get_default_registry ();
8981 factory = atk_registry_get_factory (default_registry,
8982 G_TYPE_FROM_INSTANCE (widget));
8984 atk_object_factory_create_accessible (factory,
8986 g_object_set_qdata (G_OBJECT (widget),
8987 quark_accessible_object,
8994 * Initialize a AtkImplementorIface instance's virtual pointers as
8995 * appropriate to this implementor's class (GtkWidget).
8998 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9000 iface->ref_accessible = gtk_widget_ref_accessible;
9004 gtk_widget_ref_accessible (AtkImplementor *implementor)
9006 AtkObject *accessible;
9008 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9010 g_object_ref (accessible);
9015 * GtkBuildable implementation
9017 static GQuark quark_builder_has_default = 0;
9018 static GQuark quark_builder_has_focus = 0;
9019 static GQuark quark_builder_atk_relations = 0;
9022 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9024 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9025 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9026 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9028 iface->set_name = gtk_widget_buildable_set_name;
9029 iface->get_name = gtk_widget_buildable_get_name;
9030 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9031 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9032 iface->parser_finished = gtk_widget_buildable_parser_finished;
9033 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9034 iface->custom_finished = gtk_widget_buildable_custom_finished;
9038 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9041 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9044 static const gchar *
9045 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9047 return gtk_widget_get_name (GTK_WIDGET (buildable));
9051 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9052 GtkBuilder *builder,
9053 const gchar *childname)
9055 if (strcmp (childname, "accessible") == 0)
9056 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9062 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9063 GtkBuilder *builder,
9065 const GValue *value)
9067 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9068 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9069 GINT_TO_POINTER (TRUE));
9070 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9071 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9072 GINT_TO_POINTER (TRUE));
9074 g_object_set_property (G_OBJECT (buildable), name, value);
9088 free_action (AtkActionData *data, gpointer user_data)
9090 g_free (data->action_name);
9091 g_free (data->description);
9092 g_slice_free (AtkActionData, data);
9096 free_relation (AtkRelationData *data, gpointer user_data)
9098 g_free (data->target);
9099 g_free (data->type);
9100 g_slice_free (AtkRelationData, data);
9104 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9105 GtkBuilder *builder)
9107 GSList *atk_relations;
9109 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9110 gtk_widget_grab_default (GTK_WIDGET (buildable));
9111 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9112 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9114 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9115 quark_builder_atk_relations);
9118 AtkObject *accessible;
9119 AtkRelationSet *relation_set;
9122 AtkRelationType relation_type;
9123 AtkObject *target_accessible;
9125 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9126 relation_set = atk_object_ref_relation_set (accessible);
9128 for (l = atk_relations; l; l = l->next)
9130 AtkRelationData *relation = (AtkRelationData*)l->data;
9132 target = gtk_builder_get_object (builder, relation->target);
9135 g_warning ("Target object %s in <relation> does not exist",
9139 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9140 g_assert (target_accessible != NULL);
9142 relation_type = atk_relation_type_for_name (relation->type);
9143 if (relation_type == ATK_RELATION_NULL)
9145 g_warning ("<relation> type %s not found",
9149 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9152 g_object_unref (relation_set);
9154 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9155 g_slist_free (atk_relations);
9156 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9165 } AccessibilitySubParserData;
9168 accessibility_start_element (GMarkupParseContext *context,
9169 const gchar *element_name,
9170 const gchar **names,
9171 const gchar **values,
9175 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9177 gint line_number, char_number;
9179 if (strcmp (element_name, "relation") == 0)
9181 gchar *target = NULL;
9183 AtkRelationData *relation;
9185 for (i = 0; names[i]; i++)
9187 if (strcmp (names[i], "target") == 0)
9188 target = g_strdup (values[i]);
9189 else if (strcmp (names[i], "type") == 0)
9190 type = g_strdup (values[i]);
9193 g_markup_parse_context_get_position (context,
9198 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9199 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9201 line_number, char_number, names[i], "relation");
9208 if (!target || !type)
9210 g_markup_parse_context_get_position (context,
9215 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9216 "%s:%d:%d <%s> requires attribute \"%s\"",
9218 line_number, char_number, "relation",
9219 type ? "target" : "type");
9225 relation = g_slice_new (AtkRelationData);
9226 relation->target = target;
9227 relation->type = type;
9229 data->relations = g_slist_prepend (data->relations, relation);
9231 else if (strcmp (element_name, "action") == 0)
9233 gchar *action_name = NULL;
9234 gchar *description = NULL;
9235 AtkActionData *action;
9237 for (i = 0; names[i]; i++)
9239 if (strcmp (names[i], "action_name") == 0)
9240 action_name = g_strdup (values[i]);
9241 else if (strcmp (names[i], "description") == 0)
9242 description = g_strdup (values[i]);
9245 g_markup_parse_context_get_position (context,
9250 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9251 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9253 line_number, char_number, names[i], "action");
9254 g_free (action_name);
9255 g_free (description);
9260 if (!action_name || !description)
9262 g_markup_parse_context_get_position (context,
9267 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9268 "%s:%d:%d <%s> requires attribute \"%s\"",
9270 line_number, char_number, "action",
9271 description ? "action_name" : "description");
9272 g_free (action_name);
9273 g_free (description);
9277 action = g_slice_new (AtkActionData);
9278 action->action_name = action_name;
9279 action->description = description;
9281 data->actions = g_slist_prepend (data->actions, action);
9283 else if (strcmp (element_name, "accessibility") == 0)
9286 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9289 static const GMarkupParser accessibility_parser =
9291 accessibility_start_element,
9299 } AccelGroupParserData;
9302 accel_group_start_element (GMarkupParseContext *context,
9303 const gchar *element_name,
9304 const gchar **names,
9305 const gchar **values,
9311 guint modifiers = 0;
9312 gchar *signal = NULL;
9313 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9315 for (i = 0; names[i]; i++)
9317 if (strcmp (names[i], "key") == 0)
9318 key = gdk_keyval_from_name (values[i]);
9319 else if (strcmp (names[i], "modifiers") == 0)
9321 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9327 else if (strcmp (names[i], "signal") == 0)
9328 signal = g_strdup (values[i]);
9331 if (key == 0 || signal == NULL)
9333 g_warning ("<accelerator> requires key and signal attributes");
9336 parser_data->key = key;
9337 parser_data->modifiers = modifiers;
9338 parser_data->signal = signal;
9341 static const GMarkupParser accel_group_parser =
9343 accel_group_start_element,
9347 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9348 GtkBuilder *builder,
9350 const gchar *tagname,
9351 GMarkupParser *parser,
9354 g_assert (buildable);
9356 if (strcmp (tagname, "accelerator") == 0)
9358 AccelGroupParserData *parser_data;
9360 parser_data = g_slice_new0 (AccelGroupParserData);
9361 parser_data->object = g_object_ref (buildable);
9362 *parser = accel_group_parser;
9363 *data = parser_data;
9366 if (strcmp (tagname, "accessibility") == 0)
9368 AccessibilitySubParserData *parser_data;
9370 parser_data = g_slice_new0 (AccessibilitySubParserData);
9371 *parser = accessibility_parser;
9372 *data = parser_data;
9379 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9380 GtkBuilder *builder,
9382 const gchar *tagname,
9385 AccelGroupParserData *accel_data;
9386 AccessibilitySubParserData *a11y_data;
9387 GtkWidget *toplevel;
9388 GSList *accel_groups;
9389 GtkAccelGroup *accel_group;
9391 if (strcmp (tagname, "accelerator") == 0)
9393 accel_data = (AccelGroupParserData*)user_data;
9394 g_assert (accel_data->object);
9396 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9397 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9398 if (g_slist_length (accel_groups) == 0)
9400 accel_group = gtk_accel_group_new ();
9401 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9405 g_assert (g_slist_length (accel_groups) == 1);
9406 accel_group = g_slist_nth_data (accel_groups, 0);
9408 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9412 accel_data->modifiers,
9414 g_object_unref (accel_data->object);
9415 g_free (accel_data->signal);
9416 g_slice_free (AccelGroupParserData, accel_data);
9418 else if (strcmp (tagname, "accessibility") == 0)
9420 a11y_data = (AccessibilitySubParserData*)user_data;
9422 if (a11y_data->actions)
9424 AtkObject *accessible;
9429 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9431 action = ATK_ACTION (accessible);
9432 n_actions = atk_action_get_n_actions (action);
9434 for (l = a11y_data->actions; l; l = l->next)
9436 AtkActionData *action_data = (AtkActionData*)l->data;
9438 for (i = 0; i < n_actions; i++)
9439 if (strcmp (atk_action_get_name (action, i),
9440 action_data->action_name) == 0)
9444 atk_action_set_description (action, i,
9445 action_data->description);
9448 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9449 g_slist_free (a11y_data->actions);
9452 if (a11y_data->relations)
9453 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9454 a11y_data->relations);
9456 g_slice_free (AccessibilitySubParserData, a11y_data);
9463 * gtk_widget_get_clipboard:
9464 * @widget: a #GtkWidget
9465 * @selection: a #GdkAtom which identifies the clipboard
9466 * to use. %GDK_SELECTION_CLIPBOARD gives the
9467 * default clipboard. Another common value
9468 * is %GDK_SELECTION_PRIMARY, which gives
9469 * the primary X selection.
9471 * Returns the clipboard object for the given selection to
9472 * be used with @widget. @widget must have a #GdkDisplay
9473 * associated with it, so must be attached to a toplevel
9476 * Return value: the appropriate clipboard object. If no
9477 * clipboard already exists, a new one will
9478 * be created. Once a clipboard object has
9479 * been created, it is persistent for all time.
9484 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9486 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9487 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9489 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9494 * gtk_widget_list_mnemonic_labels:
9495 * @widget: a #GtkWidget
9497 * Returns a newly allocated list of the widgets, normally labels, for
9498 * which this widget is a the target of a mnemonic (see for example,
9499 * gtk_label_set_mnemonic_widget()).
9501 * The widgets in the list are not individually referenced. If you
9502 * want to iterate through the list and perform actions involving
9503 * callbacks that might destroy the widgets, you
9504 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9505 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9506 * widgets afterwards.
9508 * Return value: the list of mnemonic labels; free this list
9509 * with g_list_free() when you are done with it.
9514 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9519 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9521 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9522 list = g_list_prepend (list, l->data);
9528 * gtk_widget_add_mnemonic_label:
9529 * @widget: a #GtkWidget
9530 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9532 * Adds a widget to the list of mnemonic labels for
9533 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9534 * list of mnemonic labels for the widget is cleared when the
9535 * widget is destroyed, so the caller must make sure to update
9536 * its internal state at this point as well, by using a connection
9537 * to the #GtkWidget::destroy signal or a weak notifier.
9542 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9545 GSList *old_list, *new_list;
9547 g_return_if_fail (GTK_IS_WIDGET (widget));
9548 g_return_if_fail (GTK_IS_WIDGET (label));
9550 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9551 new_list = g_slist_prepend (old_list, label);
9553 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9554 new_list, (GDestroyNotify) g_slist_free);
9558 * gtk_widget_remove_mnemonic_label:
9559 * @widget: a #GtkWidget
9560 * @label: a #GtkWidget that was previously set as a mnemnic label for
9561 * @widget with gtk_widget_add_mnemonic_label().
9563 * Removes a widget from the list of mnemonic labels for
9564 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
9565 * must have previously been added to the list with
9566 * gtk_widget_add_mnemonic_label().
9571 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
9574 GSList *old_list, *new_list;
9576 g_return_if_fail (GTK_IS_WIDGET (widget));
9577 g_return_if_fail (GTK_IS_WIDGET (label));
9579 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9580 new_list = g_slist_remove (old_list, label);
9583 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9584 new_list, (GDestroyNotify) g_slist_free);
9588 * gtk_widget_get_no_show_all:
9589 * @widget: a #GtkWidget
9591 * Returns the current value of the GtkWidget:no-show-all property,
9592 * which determines whether calls to gtk_widget_show_all() and
9593 * gtk_widget_hide_all() will affect this widget.
9595 * Return value: the current value of the "no-show-all" property.
9600 gtk_widget_get_no_show_all (GtkWidget *widget)
9602 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9604 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
9608 * gtk_widget_set_no_show_all:
9609 * @widget: a #GtkWidget
9610 * @no_show_all: the new value for the "no-show-all" property
9612 * Sets the #GtkWidget:no-show-all property, which determines whether
9613 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
9616 * This is mostly for use in constructing widget hierarchies with externally
9617 * controlled visibility, see #GtkUIManager.
9622 gtk_widget_set_no_show_all (GtkWidget *widget,
9623 gboolean no_show_all)
9625 g_return_if_fail (GTK_IS_WIDGET (widget));
9627 no_show_all = (no_show_all != FALSE);
9629 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
9633 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
9635 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
9637 g_object_notify (G_OBJECT (widget), "no-show-all");
9642 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
9643 gboolean has_tooltip,
9646 gboolean priv_has_tooltip;
9648 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
9649 quark_has_tooltip));
9651 if (priv_has_tooltip != has_tooltip || force)
9653 priv_has_tooltip = has_tooltip;
9655 if (priv_has_tooltip)
9657 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
9658 gdk_window_set_events (widget->window,
9659 gdk_window_get_events (widget->window) |
9660 GDK_LEAVE_NOTIFY_MASK |
9661 GDK_POINTER_MOTION_MASK |
9662 GDK_POINTER_MOTION_HINT_MASK);
9664 if (!GTK_WIDGET_NO_WINDOW (widget))
9665 gtk_widget_add_events (widget,
9666 GDK_LEAVE_NOTIFY_MASK |
9667 GDK_POINTER_MOTION_MASK |
9668 GDK_POINTER_MOTION_HINT_MASK);
9671 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
9672 GUINT_TO_POINTER (priv_has_tooltip));
9677 * gtk_widget_set_tooltip_window:
9678 * @widget: a #GtkWidget
9679 * @custom_window: a #GtkWindow, or %NULL
9681 * Replaces the default, usually yellow, window used for displaying
9682 * tooltips with @custom_window. GTK+ will take care of showing and
9683 * hiding @custom_window at the right moment, to behave likewise as
9684 * the default tooltip window. If @custom_window is %NULL, the default
9685 * tooltip window will be used.
9690 gtk_widget_set_tooltip_window (GtkWidget *widget,
9691 GtkWindow *custom_window)
9694 gchar *tooltip_markup;
9695 GtkWindow *tooltip_window;
9697 g_return_if_fail (GTK_IS_WIDGET (widget));
9699 g_return_if_fail (GTK_IS_WINDOW (custom_window));
9701 tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9702 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
9705 g_object_ref (custom_window);
9707 tooltip_window = custom_window;
9708 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
9709 tooltip_window, g_object_unref);
9711 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
9712 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
9715 gtk_widget_trigger_tooltip_query (widget);
9719 * gtk_widget_get_tooltip_window:
9720 * @widget: a #GtkWidget
9722 * Returns the #GtkWindow of the current tooltip. This can be the
9723 * GtkWindow created by default, or the custom tooltip window set
9724 * using gtk_widget_set_tooltip_window().
9726 * Return value: The #GtkWindow of the current tooltip.
9731 gtk_widget_get_tooltip_window (GtkWidget *widget)
9733 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9735 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9739 * gtk_widget_trigger_tooltip_query:
9740 * @widget: a #GtkWidget
9742 * Triggers a tooltip query on the display where the toplevel of @widget
9743 * is located. See gtk_tooltip_trigger_tooltip_query() for more
9749 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
9751 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
9755 * gtk_widget_set_tooltip_text:
9756 * @widget: a #GtkWidget
9757 * @text: the contents of the tooltip for @widget
9759 * Sets @text as the contents of the tooltip. This function will take
9760 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
9761 * handler for the GtkWidget::query-tooltip signal.
9763 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
9768 gtk_widget_set_tooltip_text (GtkWidget *widget,
9771 g_return_if_fail (GTK_IS_WIDGET (widget));
9773 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
9777 * gtk_widget_get_tooltip_text:
9778 * @widget: a #GtkWidget
9780 * Gets the contents of the tooltip for @widget.
9782 * Return value: the tooltip text, or %NULL. You should free the
9783 * returned string with g_free() when done.
9788 gtk_widget_get_tooltip_text (GtkWidget *widget)
9792 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9794 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
9800 * gtk_widget_set_tooltip_markup:
9801 * @widget: a #GtkWidget
9802 * @markup: the contents of the tooltip for @widget, or %NULL
9804 * Sets @markup as the contents of the tooltip, which is marked up with
9805 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
9807 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
9808 * and of the default handler for the GtkWidget::query-tooltip signal.
9810 * See also the GtkWidget:tooltip-markup property and
9811 * gtk_tooltip_set_markup().
9816 gtk_widget_set_tooltip_markup (GtkWidget *widget,
9817 const gchar *markup)
9819 g_return_if_fail (GTK_IS_WIDGET (widget));
9821 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
9825 * gtk_widget_get_tooltip_markup:
9826 * @widget: a #GtkWidget
9828 * Gets the contents of the tooltip for @widget.
9830 * Return value: the tooltip text, or %NULL. You should free the
9831 * returned string with g_free() when done.
9836 gtk_widget_get_tooltip_markup (GtkWidget *widget)
9840 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9842 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
9848 * gtk_widget_set_has_tooltip:
9849 * @widget: a #GtkWidget
9850 * @has_tooltip: whether or not @widget has a tooltip.
9852 * Sets the has-tooltip property on @widget to @has_tooltip. See
9853 * GtkWidget:has-tooltip for more information.
9858 gtk_widget_set_has_tooltip (GtkWidget *widget,
9859 gboolean has_tooltip)
9861 g_return_if_fail (GTK_IS_WIDGET (widget));
9863 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
9867 * gtk_widget_get_has_tooltip:
9868 * @widget: a #GtkWidget
9870 * Returns the current value of the has-tooltip property. See
9871 * GtkWidget:has-tooltip for more information.
9873 * Return value: current value of has-tooltip on @widget.
9878 gtk_widget_get_has_tooltip (GtkWidget *widget)
9880 gboolean has_tooltip = FALSE;
9882 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9884 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
9890 * gtk_widget_get_allocation:
9891 * @widget: a #GtkWidget
9893 * Retrieves the widget's allocation.
9895 * Return value: widget's allocation
9900 gtk_widget_get_allocation (GtkWidget *widget)
9902 g_return_val_if_fail (GTK_IS_WIDGET (widget), widget);
9904 return widget->allocation;
9908 * gtk_widget_get_window:
9909 * @widget: a #GtkWidget
9911 * Returns the widget's window if it is realized, %NULL otherwise
9913 * Return value: @widget's window.
9918 gtk_widget_get_window (GtkWidget *widget)
9920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9922 return widget->window;
9925 #define __GTK_WIDGET_C__
9926 #include "gtkaliasdef.c"