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 (I_("damage_event"),
2029 G_TYPE_FROM_CLASS (gobject_class),
2032 _gtk_boolean_handled_accumulator, NULL,
2033 _gtk_marshal_BOOLEAN__BOXED,
2035 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2037 * GtkWidget::grab-broken-event:
2038 * @widget: the object which received the signal
2039 * @event: the #GdkEventGrabBroken event
2041 * Emitted when a pointer or keyboard grab on a window belonging
2042 * to @widget gets broken.
2044 * On X11, this happens when the grab window becomes unviewable
2045 * (i.e. it or one of its ancestors is unmapped), or if the same
2046 * application grabs the pointer or keyboard again.
2048 * Returns: %TRUE to stop other handlers from being invoked for
2049 * the event. %FALSE to propagate the event further.
2053 widget_signals[GRAB_BROKEN] =
2054 g_signal_new (I_("grab_broken_event"),
2055 G_TYPE_FROM_CLASS (gobject_class),
2057 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2058 _gtk_boolean_handled_accumulator, NULL,
2059 _gtk_marshal_BOOLEAN__BOXED,
2061 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2063 * GtkWidget::query-tooltip:
2064 * @widget: the object which received the signal
2065 * @x: the x coordinate of the cursor position where the request has
2066 * been emitted, relative to @widget->window
2067 * @y: the y coordinate of the cursor position where the request has
2068 * been emitted, relative to @widget->window
2069 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2070 * @tooltip: a #GtkTooltip
2072 * Emitted when the #GtkSettings:gtk-tooltip-timeout has expired with
2073 * the cursor hovering "above" @widget; or emitted when @widget got
2074 * focus in keyboard mode.
2076 * Using the given coordinates, the signal handler should determine
2077 * whether a tooltip should be shown for @widget. If this is the case
2078 * %TRUE should be returned, %FALSE otherwise. Note that if
2079 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2080 * should not be used.
2082 * The signal handler is free to manipulate @tooltip with the therefore
2083 * destined function calls.
2085 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2089 widget_signals[QUERY_TOOLTIP] =
2090 g_signal_new (I_("query-tooltip"),
2091 G_TYPE_FROM_CLASS (gobject_class),
2093 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2094 _gtk_boolean_handled_accumulator, NULL,
2095 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2103 * GtkWidget::popup-menu
2104 * @widget: the object which received the signal
2106 * This signal gets emitted whenever a widget should pop up a context
2107 * menu. This usually happens through the standard key binding mechanism;
2108 * by pressing a certain key while a widget is focused, the user can cause
2109 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2110 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2111 * for an example of how to use this signal.
2113 * Returns: %TRUE if a menu was activated
2115 widget_signals[POPUP_MENU] =
2116 g_signal_new (I_("popup_menu"),
2117 G_TYPE_FROM_CLASS (gobject_class),
2118 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2119 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2120 _gtk_boolean_handled_accumulator, NULL,
2121 _gtk_marshal_BOOLEAN__VOID,
2123 widget_signals[SHOW_HELP] =
2124 g_signal_new (I_("show_help"),
2125 G_TYPE_FROM_CLASS (gobject_class),
2126 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2127 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2128 _gtk_boolean_handled_accumulator, NULL,
2129 _gtk_marshal_BOOLEAN__ENUM,
2131 GTK_TYPE_WIDGET_HELP_TYPE);
2132 widget_signals[ACCEL_CLOSURES_CHANGED] =
2133 g_signal_new (I_("accel_closures_changed"),
2134 G_TYPE_FROM_CLASS (gobject_class),
2138 _gtk_marshal_NONE__NONE,
2142 * GtkWidget::screen-changed:
2143 * @widget: the object on which the signal is emitted
2144 * @previous_screen: the previous screen, or %NULL if the
2145 * widget was not associated with a screen before
2147 * The ::screen-changed signal gets emitted when the
2148 * screen of a widget has changed.
2150 widget_signals[SCREEN_CHANGED] =
2151 g_signal_new (I_("screen_changed"),
2152 G_TYPE_FROM_CLASS (gobject_class),
2154 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2156 _gtk_marshal_VOID__OBJECT,
2160 * GtkWidget::can-activate-accel:
2161 * @widget: the object which received the signal
2162 * @signal_id: the ID of a signal installed on @widget
2164 * Determines whether an accelerator that activates the signal
2165 * identified by @signal_id can currently be activated.
2166 * This signal is present to allow applications and derived
2167 * widgets to override the default #GtkWidget handling
2168 * for determining whether an accelerator can be activated.
2170 * Returns: %TRUE if the signal can be activated.
2172 widget_signals[CAN_ACTIVATE_ACCEL] =
2173 g_signal_new (I_("can_activate_accel"),
2174 G_TYPE_FROM_CLASS (gobject_class),
2176 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2177 _gtk_boolean_handled_accumulator, NULL,
2178 _gtk_marshal_BOOLEAN__UINT,
2179 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2181 binding_set = gtk_binding_set_by_class (klass);
2182 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
2184 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
2187 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
2189 GTK_TYPE_WIDGET_HELP_TYPE,
2190 GTK_WIDGET_HELP_TOOLTIP);
2191 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
2193 GTK_TYPE_WIDGET_HELP_TYPE,
2194 GTK_WIDGET_HELP_TOOLTIP);
2195 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
2197 GTK_TYPE_WIDGET_HELP_TYPE,
2198 GTK_WIDGET_HELP_WHATS_THIS);
2199 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
2201 GTK_TYPE_WIDGET_HELP_TYPE,
2202 GTK_WIDGET_HELP_WHATS_THIS);
2204 gtk_widget_class_install_style_property (klass,
2205 g_param_spec_boolean ("interior-focus",
2206 P_("Interior Focus"),
2207 P_("Whether to draw the focus indicator inside widgets"),
2209 GTK_PARAM_READABLE));
2211 gtk_widget_class_install_style_property (klass,
2212 g_param_spec_int ("focus-line-width",
2213 P_("Focus linewidth"),
2214 P_("Width, in pixels, of the focus indicator line"),
2216 GTK_PARAM_READABLE));
2218 gtk_widget_class_install_style_property (klass,
2219 g_param_spec_string ("focus-line-pattern",
2220 P_("Focus line dash pattern"),
2221 P_("Dash pattern used to draw the focus indicator"),
2223 GTK_PARAM_READABLE));
2224 gtk_widget_class_install_style_property (klass,
2225 g_param_spec_int ("focus-padding",
2226 P_("Focus padding"),
2227 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2229 GTK_PARAM_READABLE));
2230 gtk_widget_class_install_style_property (klass,
2231 g_param_spec_boxed ("cursor-color",
2233 P_("Color with which to draw insertion cursor"),
2235 GTK_PARAM_READABLE));
2236 gtk_widget_class_install_style_property (klass,
2237 g_param_spec_boxed ("secondary-cursor-color",
2238 P_("Secondary cursor color"),
2239 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2241 GTK_PARAM_READABLE));
2242 gtk_widget_class_install_style_property (klass,
2243 g_param_spec_float ("cursor-aspect-ratio",
2244 P_("Cursor line aspect ratio"),
2245 P_("Aspect ratio with which to draw insertion cursor"),
2247 GTK_PARAM_READABLE));
2250 * GtkWidget:draw-border:
2252 * The "draw-border" style property defines the size of areas outside
2253 * the widget's allocation to draw.
2257 gtk_widget_class_install_style_property (klass,
2258 g_param_spec_boxed ("draw-border",
2260 P_("Size of areas outside the widget's allocation to draw"),
2262 GTK_PARAM_READABLE));
2265 * GtkWidget:link-color:
2267 * The "link-color" style property defines the color of unvisited links.
2271 gtk_widget_class_install_style_property (klass,
2272 g_param_spec_boxed ("link-color",
2273 P_("Unvisited Link Color"),
2274 P_("Color of unvisited links"),
2276 GTK_PARAM_READABLE));
2279 * GtkWidget:visited-link-color:
2281 * The "visited-link-color" style property defines the color of visited links.
2285 gtk_widget_class_install_style_property (klass,
2286 g_param_spec_boxed ("visited-link-color",
2287 P_("Visited Link Color"),
2288 P_("Color of visited links"),
2290 GTK_PARAM_READABLE));
2293 * GtkWidget:wide-separators:
2295 * The "wide-separators" style property defines whether separators have
2296 * configurable width and should be drawn using a box instead of a line.
2300 gtk_widget_class_install_style_property (klass,
2301 g_param_spec_boolean ("wide-separators",
2302 P_("Wide Separators"),
2303 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2305 GTK_PARAM_READABLE));
2308 * GtkWidget:separator-width:
2310 * The "separator-width" style property defines the width of separators.
2311 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2315 gtk_widget_class_install_style_property (klass,
2316 g_param_spec_int ("separator-width",
2317 P_("Separator Width"),
2318 P_("The width of separators if wide-separators is TRUE"),
2320 GTK_PARAM_READABLE));
2323 * GtkWidget:separator-height:
2325 * The "separator-height" style property defines the height of separators.
2326 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2330 gtk_widget_class_install_style_property (klass,
2331 g_param_spec_int ("separator-height",
2332 P_("Separator Height"),
2333 P_("The height of separators if \"wide-separators\" is TRUE"),
2335 GTK_PARAM_READABLE));
2338 * GtkWidget:scroll-arrow-hlength:
2340 * The "scroll-arrow-hlength" style property defines the length of
2341 * horizontal scroll arrows.
2345 gtk_widget_class_install_style_property (klass,
2346 g_param_spec_int ("scroll-arrow-hlength",
2347 P_("Horizontal Scroll Arrow Length"),
2348 P_("The length of horizontal scroll arrows"),
2350 GTK_PARAM_READABLE));
2353 * GtkWidget:scroll-arrow-vlength:
2355 * The "scroll-arrow-vlength" style property defines the length of
2356 * vertical scroll arrows.
2360 gtk_widget_class_install_style_property (klass,
2361 g_param_spec_int ("scroll-arrow-vlength",
2362 P_("Vertical Scroll Arrow Length"),
2363 P_("The length of vertical scroll arrows"),
2365 GTK_PARAM_READABLE));
2369 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2373 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2374 for (node = list; node; node = node->next)
2376 GParamSpec *pspec = node->data;
2378 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2379 g_param_spec_unref (pspec);
2385 gtk_widget_set_property (GObject *object,
2387 const GValue *value,
2390 GtkWidget *widget = GTK_WIDGET (object);
2395 guint32 saved_flags;
2396 gchar *tooltip_markup;
2397 const gchar *tooltip_text;
2398 GtkWindow *tooltip_window;
2401 gtk_widget_set_name (widget, g_value_get_string (value));
2404 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2406 case PROP_WIDTH_REQUEST:
2407 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2409 case PROP_HEIGHT_REQUEST:
2410 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2413 if (g_value_get_boolean (value))
2414 gtk_widget_show (widget);
2416 gtk_widget_hide (widget);
2418 case PROP_SENSITIVE:
2419 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2421 case PROP_APP_PAINTABLE:
2422 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2424 case PROP_CAN_FOCUS:
2425 saved_flags = GTK_WIDGET_FLAGS (widget);
2426 if (g_value_get_boolean (value))
2427 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
2429 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
2430 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2431 gtk_widget_queue_resize (widget);
2433 case PROP_HAS_FOCUS:
2434 if (g_value_get_boolean (value))
2435 gtk_widget_grab_focus (widget);
2438 if (g_value_get_boolean (value))
2439 gtk_widget_grab_focus (widget);
2441 case PROP_CAN_DEFAULT:
2442 saved_flags = GTK_WIDGET_FLAGS (widget);
2443 if (g_value_get_boolean (value))
2444 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
2446 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
2447 if (saved_flags != GTK_WIDGET_FLAGS (widget))
2448 gtk_widget_queue_resize (widget);
2450 case PROP_HAS_DEFAULT:
2451 if (g_value_get_boolean (value))
2452 gtk_widget_grab_default (widget);
2454 case PROP_RECEIVES_DEFAULT:
2455 if (g_value_get_boolean (value))
2456 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2458 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
2461 gtk_widget_set_style (widget, g_value_get_object (value));
2464 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2465 gtk_widget_set_events (widget, g_value_get_flags (value));
2467 case PROP_EXTENSION_EVENTS:
2468 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2470 case PROP_NO_SHOW_ALL:
2471 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2473 case PROP_HAS_TOOLTIP:
2474 gtk_widget_real_set_has_tooltip (widget,
2475 g_value_get_boolean (value), FALSE);
2477 case PROP_TOOLTIP_MARKUP:
2478 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2479 tooltip_markup = g_value_dup_string (value);
2481 /* Treat an empty string as a NULL string,
2482 * because an empty string would be useless for a tooltip:
2484 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2486 g_free (tooltip_markup);
2487 tooltip_markup = NULL;
2490 g_object_set_qdata_full (object, quark_tooltip_markup,
2491 tooltip_markup, g_free);
2493 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2494 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2496 case PROP_TOOLTIP_TEXT:
2497 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2499 tooltip_text = g_value_get_string (value);
2501 /* Treat an empty string as a NULL string,
2502 * because an empty string would be useless for a tooltip:
2504 if (tooltip_text && (strlen (tooltip_text) == 0))
2505 tooltip_text = NULL;
2507 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2509 g_object_set_qdata_full (object, quark_tooltip_markup,
2510 tooltip_markup, g_free);
2512 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2513 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2516 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2522 gtk_widget_get_property (GObject *object,
2527 GtkWidget *widget = GTK_WIDGET (object);
2536 g_value_set_string (value, widget->name);
2538 g_value_set_static_string (value, "");
2542 g_value_set_object (value, widget->parent);
2544 g_value_set_object (value, NULL);
2546 case PROP_WIDTH_REQUEST:
2549 gtk_widget_get_size_request (widget, &w, NULL);
2550 g_value_set_int (value, w);
2553 case PROP_HEIGHT_REQUEST:
2556 gtk_widget_get_size_request (widget, NULL, &h);
2557 g_value_set_int (value, h);
2561 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
2563 case PROP_SENSITIVE:
2564 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
2566 case PROP_APP_PAINTABLE:
2567 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
2569 case PROP_CAN_FOCUS:
2570 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
2572 case PROP_HAS_FOCUS:
2573 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
2576 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
2578 case PROP_CAN_DEFAULT:
2579 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
2581 case PROP_HAS_DEFAULT:
2582 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
2584 case PROP_RECEIVES_DEFAULT:
2585 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
2587 case PROP_COMPOSITE_CHILD:
2588 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
2591 g_value_set_object (value, gtk_widget_get_style (widget));
2594 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
2595 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
2597 case PROP_EXTENSION_EVENTS:
2598 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
2599 g_value_set_enum (value, GPOINTER_TO_INT (modep));
2601 case PROP_NO_SHOW_ALL:
2602 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
2604 case PROP_HAS_TOOLTIP:
2605 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
2607 case PROP_TOOLTIP_TEXT:
2609 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
2612 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
2613 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
2615 g_value_set_string (value, text);
2619 case PROP_TOOLTIP_MARKUP:
2620 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
2623 g_value_set_object (value, gtk_widget_get_window (widget));
2626 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2632 gtk_widget_init (GtkWidget *widget)
2634 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
2635 widget->state = GTK_STATE_NORMAL;
2636 widget->saved_state = GTK_STATE_NORMAL;
2637 widget->name = NULL;
2638 widget->requisition.width = 0;
2639 widget->requisition.height = 0;
2640 widget->allocation.x = -1;
2641 widget->allocation.y = -1;
2642 widget->allocation.width = 1;
2643 widget->allocation.height = 1;
2644 widget->window = NULL;
2645 widget->parent = NULL;
2647 GTK_WIDGET_SET_FLAGS (widget,
2649 GTK_PARENT_SENSITIVE |
2650 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
2651 GTK_DOUBLE_BUFFERED);
2653 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
2654 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
2655 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
2657 widget->style = gtk_widget_get_default_style ();
2658 g_object_ref (widget->style);
2663 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
2665 GParamSpec **pspecs)
2667 GtkWidget *container = widget->parent;
2670 for (i = 0; widget->parent == container && i < n_pspecs; i++)
2671 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
2675 * gtk_widget_freeze_child_notify:
2676 * @widget: a #GtkWidget
2678 * Stops emission of #GtkWidget::child-notify signals on @widget. The
2679 * signals are queued until gtk_widget_thaw_child_notify() is called
2682 * This is the analogue of g_object_freeze_notify() for child properties.
2685 gtk_widget_freeze_child_notify (GtkWidget *widget)
2687 g_return_if_fail (GTK_IS_WIDGET (widget));
2689 if (!G_OBJECT (widget)->ref_count)
2692 g_object_ref (widget);
2693 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2694 g_object_unref (widget);
2698 * gtk_widget_child_notify:
2699 * @widget: a #GtkWidget
2700 * @child_property: the name of a child property installed on the
2701 * class of @widget<!-- -->'s parent
2703 * Emits a #GtkWidget::child-notify signal for the
2704 * <link linkend="child-properties">child property</link> @child_property
2707 * This is the analogue of g_object_notify() for child properties.
2710 gtk_widget_child_notify (GtkWidget *widget,
2711 const gchar *child_property)
2715 g_return_if_fail (GTK_IS_WIDGET (widget));
2716 g_return_if_fail (child_property != NULL);
2717 if (!G_OBJECT (widget)->ref_count || !widget->parent)
2720 g_object_ref (widget);
2721 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
2723 G_OBJECT_TYPE (widget->parent),
2726 g_warning ("%s: container class `%s' has no child property named `%s'",
2728 G_OBJECT_TYPE_NAME (widget->parent),
2732 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2734 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
2735 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2737 g_object_unref (widget);
2741 * gtk_widget_thaw_child_notify:
2742 * @widget: a #GtkWidget
2744 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
2745 * This causes all queued #GtkWidget::child-notify signals on @widget to be
2749 gtk_widget_thaw_child_notify (GtkWidget *widget)
2751 GObjectNotifyQueue *nqueue;
2753 g_return_if_fail (GTK_IS_WIDGET (widget));
2755 if (!G_OBJECT (widget)->ref_count)
2758 g_object_ref (widget);
2759 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2760 if (!nqueue || !nqueue->freeze_count)
2761 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
2762 G_OBJECT_TYPE_NAME (widget), widget);
2764 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2765 g_object_unref (widget);
2771 * @type: type ID of the widget to create
2772 * @first_property_name: name of first property to set
2773 * @Varargs: value of first property, followed by more properties,
2776 * This is a convenience function for creating a widget and setting
2777 * its properties in one go. For example you might write:
2778 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
2779 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
2780 * g_object_new(), but returns a widget so you don't have to
2781 * cast the object yourself.
2783 * Return value: a new #GtkWidget of type @widget_type
2786 gtk_widget_new (GType type,
2787 const gchar *first_property_name,
2793 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
2795 va_start (var_args, first_property_name);
2796 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
2804 * @widget: a #GtkWidget
2805 * @first_property_name: name of first property to set
2806 * @Varargs: value of first property, followed by more properties,
2809 * Precursor of g_object_set().
2811 * Deprecated: 2.0: Use g_object_set() instead.
2814 gtk_widget_set (GtkWidget *widget,
2815 const gchar *first_property_name,
2820 g_return_if_fail (GTK_IS_WIDGET (widget));
2822 va_start (var_args, first_property_name);
2823 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
2828 gtk_widget_queue_draw_child (GtkWidget *widget)
2832 parent = widget->parent;
2833 if (parent && GTK_WIDGET_DRAWABLE (parent))
2834 gtk_widget_queue_draw_area (parent,
2835 widget->allocation.x,
2836 widget->allocation.y,
2837 widget->allocation.width,
2838 widget->allocation.height);
2842 * gtk_widget_unparent:
2843 * @widget: a #GtkWidget
2845 * This function is only for use in widget implementations.
2846 * Should be called by implementations of the remove method
2847 * on #GtkContainer, to dissociate a child from the container.
2850 gtk_widget_unparent (GtkWidget *widget)
2852 GObjectNotifyQueue *nqueue;
2853 GtkWidget *toplevel;
2854 GtkWidget *old_parent;
2856 g_return_if_fail (GTK_IS_WIDGET (widget));
2857 if (widget->parent == NULL)
2860 /* keep this function in sync with gtk_menu_detach()
2863 g_object_freeze_notify (G_OBJECT (widget));
2864 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
2866 toplevel = gtk_widget_get_toplevel (widget);
2867 if (GTK_WIDGET_TOPLEVEL (toplevel))
2868 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2870 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
2871 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
2873 /* If we are unanchoring the child, we save around the toplevel
2874 * to emit hierarchy changed
2876 if (GTK_WIDGET_ANCHORED (widget->parent))
2877 g_object_ref (toplevel);
2881 gtk_widget_queue_draw_child (widget);
2883 /* Reset the width and height here, to force reallocation if we
2884 * get added back to a new parent. This won't work if our new
2885 * allocation is smaller than 1x1 and we actually want a size of 1x1...
2886 * (would 0x0 be OK here?)
2888 widget->allocation.width = 1;
2889 widget->allocation.height = 1;
2891 if (GTK_WIDGET_REALIZED (widget))
2893 if (GTK_WIDGET_IN_REPARENT (widget))
2894 gtk_widget_unmap (widget);
2896 gtk_widget_unrealize (widget);
2899 /* Removing a widget from a container restores the child visible
2900 * flag to the default state, so it doesn't affect the child
2901 * in the next parent.
2903 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
2905 old_parent = widget->parent;
2906 widget->parent = NULL;
2907 gtk_widget_set_parent_window (widget, NULL);
2908 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
2911 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
2912 g_object_unref (toplevel);
2915 g_object_notify (G_OBJECT (widget), "parent");
2916 g_object_thaw_notify (G_OBJECT (widget));
2917 if (!widget->parent)
2918 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
2919 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
2920 g_object_unref (widget);
2924 * gtk_widget_destroy:
2925 * @widget: a #GtkWidget
2927 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
2928 * you don't have to cast the widget to #GtkObject. When a widget is
2929 * destroyed, it will break any references it holds to other objects.
2930 * If the widget is inside a container, the widget will be removed
2931 * from the container. If the widget is a toplevel (derived from
2932 * #GtkWindow), it will be removed from the list of toplevels, and the
2933 * reference GTK+ holds to it will be removed. Removing a
2934 * widget from its container or the list of toplevels results in the
2935 * widget being finalized, unless you've added additional references
2936 * to the widget with g_object_ref().
2938 * In most cases, only toplevel widgets (windows) require explicit
2939 * destruction, because when you destroy a toplevel its children will
2940 * be destroyed as well.
2943 gtk_widget_destroy (GtkWidget *widget)
2945 g_return_if_fail (GTK_IS_WIDGET (widget));
2947 gtk_object_destroy ((GtkObject*) widget);
2951 * gtk_widget_destroyed:
2952 * @widget: a #GtkWidget
2953 * @widget_pointer: address of a variable that contains @widget
2955 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
2956 * %NULL. It's intended to be used as a callback connected to the
2957 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
2958 * as a signal handler, and pass the address of your widget variable
2959 * as user data. Then when the widget is destroyed, the variable will
2960 * be set to %NULL. Useful for example to avoid multiple copies
2961 * of the same dialog.
2964 gtk_widget_destroyed (GtkWidget *widget,
2965 GtkWidget **widget_pointer)
2967 /* Don't make any assumptions about the
2969 * Even check widget_pointer.
2972 *widget_pointer = NULL;
2977 * @widget: a #GtkWidget
2979 * Flags a widget to be displayed. Any widget that isn't shown will
2980 * not appear on the screen. If you want to show all the widgets in a
2981 * container, it's easier to call gtk_widget_show_all() on the
2982 * container, instead of individually showing the widgets.
2984 * Remember that you have to show the containers containing a widget,
2985 * in addition to the widget itself, before it will appear onscreen.
2987 * When a toplevel container is shown, it is immediately realized and
2988 * mapped; other shown widgets are realized and mapped when their
2989 * toplevel container is realized and mapped.
2992 gtk_widget_show (GtkWidget *widget)
2994 g_return_if_fail (GTK_IS_WIDGET (widget));
2996 if (!GTK_WIDGET_VISIBLE (widget))
2998 g_object_ref (widget);
2999 if (!GTK_WIDGET_TOPLEVEL (widget))
3000 gtk_widget_queue_resize (widget);
3001 g_signal_emit (widget, widget_signals[SHOW], 0);
3002 g_object_notify (G_OBJECT (widget), "visible");
3003 g_object_unref (widget);
3008 gtk_widget_real_show (GtkWidget *widget)
3010 if (!GTK_WIDGET_VISIBLE (widget))
3012 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3014 if (widget->parent &&
3015 GTK_WIDGET_MAPPED (widget->parent) &&
3016 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3017 !GTK_WIDGET_MAPPED (widget))
3018 gtk_widget_map (widget);
3023 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3026 g_signal_handlers_disconnect_by_func (widget,
3027 gtk_widget_show_map_callback,
3032 * gtk_widget_show_now:
3033 * @widget: a #GtkWidget
3035 * Shows a widget. If the widget is an unmapped toplevel widget
3036 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3037 * loop and wait for the window to actually be mapped. Be careful;
3038 * because the main loop is running, anything can happen during
3042 gtk_widget_show_now (GtkWidget *widget)
3046 g_return_if_fail (GTK_IS_WIDGET (widget));
3048 /* make sure we will get event */
3049 if (!GTK_WIDGET_MAPPED (widget) &&
3050 GTK_WIDGET_TOPLEVEL (widget))
3052 gtk_widget_show (widget);
3054 g_signal_connect (widget, "map_event",
3055 G_CALLBACK (gtk_widget_show_map_callback),
3059 gtk_main_iteration ();
3062 gtk_widget_show (widget);
3067 * @widget: a #GtkWidget
3069 * Reverses the effects of gtk_widget_show(), causing the widget to be
3070 * hidden (invisible to the user).
3073 gtk_widget_hide (GtkWidget *widget)
3075 g_return_if_fail (GTK_IS_WIDGET (widget));
3077 if (GTK_WIDGET_VISIBLE (widget))
3079 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3081 g_object_ref (widget);
3082 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
3083 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3085 g_signal_emit (widget, widget_signals[HIDE], 0);
3086 if (!GTK_WIDGET_TOPLEVEL (widget))
3087 gtk_widget_queue_resize (widget);
3088 g_object_notify (G_OBJECT (widget), "visible");
3089 g_object_unref (widget);
3094 gtk_widget_real_hide (GtkWidget *widget)
3096 if (GTK_WIDGET_VISIBLE (widget))
3098 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3100 if (GTK_WIDGET_MAPPED (widget))
3101 gtk_widget_unmap (widget);
3106 * gtk_widget_hide_on_delete:
3107 * @widget: a #GtkWidget
3109 * Utility function; intended to be connected to the #GtkWidget::delete-event
3110 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3111 * argument, then returns %TRUE. If connected to ::delete-event, the
3112 * result is that clicking the close button for a window (on the
3113 * window frame, top right corner usually) will hide but not destroy
3114 * the window. By default, GTK+ destroys windows when ::delete-event
3117 * Return value: %TRUE
3120 gtk_widget_hide_on_delete (GtkWidget *widget)
3122 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3124 gtk_widget_hide (widget);
3130 * gtk_widget_show_all:
3131 * @widget: a #GtkWidget
3133 * Recursively shows a widget, and any child widgets (if the widget is
3137 gtk_widget_show_all (GtkWidget *widget)
3139 GtkWidgetClass *class;
3141 g_return_if_fail (GTK_IS_WIDGET (widget));
3143 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3146 class = GTK_WIDGET_GET_CLASS (widget);
3148 if (class->show_all)
3149 class->show_all (widget);
3153 * gtk_widget_hide_all:
3154 * @widget: a #GtkWidget
3156 * Recursively hides a widget and any child widgets.
3159 gtk_widget_hide_all (GtkWidget *widget)
3161 GtkWidgetClass *class;
3163 g_return_if_fail (GTK_IS_WIDGET (widget));
3165 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
3168 class = GTK_WIDGET_GET_CLASS (widget);
3170 if (class->hide_all)
3171 class->hide_all (widget);
3176 * @widget: a #GtkWidget
3178 * This function is only for use in widget implementations. Causes
3179 * a widget to be mapped if it isn't already.
3182 gtk_widget_map (GtkWidget *widget)
3184 g_return_if_fail (GTK_IS_WIDGET (widget));
3185 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
3186 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3188 if (!GTK_WIDGET_MAPPED (widget))
3190 if (!GTK_WIDGET_REALIZED (widget))
3191 gtk_widget_realize (widget);
3193 g_signal_emit (widget, widget_signals[MAP], 0);
3195 if (GTK_WIDGET_NO_WINDOW (widget))
3196 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3202 * @widget: a #GtkWidget
3204 * This function is only for use in widget implementations. Causes
3205 * a widget to be unmapped if it's currently mapped.
3208 gtk_widget_unmap (GtkWidget *widget)
3210 g_return_if_fail (GTK_IS_WIDGET (widget));
3212 if (GTK_WIDGET_MAPPED (widget))
3214 if (GTK_WIDGET_NO_WINDOW (widget))
3215 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
3216 _gtk_tooltip_hide (widget);
3217 g_signal_emit (widget, widget_signals[UNMAP], 0);
3222 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3223 GdkExtensionMode mode,
3226 GList *free_list = NULL;
3229 if (window_list == NULL)
3231 if (!GTK_WIDGET_NO_WINDOW (widget))
3232 window_list = g_list_prepend (NULL, widget->window);
3234 window_list = gdk_window_get_children (widget->window);
3236 free_list = window_list;
3239 for (l = window_list; l != NULL; l = l->next)
3241 GdkWindow *window = l->data;
3244 gdk_window_get_user_data (window, &user_data);
3245 if (user_data == widget)
3249 gdk_input_set_extension_events (window,
3250 gdk_window_get_events (window),
3253 children = gdk_window_get_children (window);
3256 gtk_widget_set_extension_events_internal (widget, mode, children);
3257 g_list_free (children);
3263 g_list_free (free_list);
3267 * gtk_widget_realize:
3268 * @widget: a #GtkWidget
3270 * Creates the GDK (windowing system) resources associated with a
3271 * widget. For example, @widget->window will be created when a widget
3272 * is realized. Normally realization happens implicitly; if you show
3273 * a widget and all its parent containers, then the widget will be
3274 * realized and mapped automatically.
3276 * Realizing a widget requires all
3277 * the widget's parent widgets to be realized; calling
3278 * gtk_widget_realize() realizes the widget's parents in addition to
3279 * @widget itself. If a widget is not yet inside a toplevel window
3280 * when you realize it, bad things will happen.
3282 * This function is primarily used in widget implementations, and
3283 * isn't very useful otherwise. Many times when you think you might
3284 * need it, a better approach is to connect to a signal that will be
3285 * called after the widget is realized automatically, such as
3286 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3287 * GtkWidget::realize signal.
3290 gtk_widget_realize (GtkWidget *widget)
3292 GdkExtensionMode mode;
3293 GtkWidgetShapeInfo *shape_info;
3295 g_return_if_fail (GTK_IS_WIDGET (widget));
3296 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3297 GTK_IS_INVISIBLE (widget));
3299 if (!GTK_WIDGET_REALIZED (widget))
3302 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
3303 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
3306 if (widget->parent == NULL &&
3307 !GTK_WIDGET_TOPLEVEL (widget))
3308 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3309 "inside a toplevel window is not going to work very well. "
3310 "Widgets must be inside a toplevel container before realizing them.");
3312 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
3313 gtk_widget_realize (widget->parent);
3315 gtk_widget_ensure_style (widget);
3317 g_signal_emit (widget, widget_signals[REALIZE], 0);
3319 gtk_widget_real_set_has_tooltip (widget,
3320 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3323 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3325 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3326 gdk_window_shape_combine_mask (widget->window,
3327 shape_info->shape_mask,
3328 shape_info->offset_x,
3329 shape_info->offset_y);
3332 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3334 gdk_window_input_shape_combine_mask (widget->window,
3335 shape_info->shape_mask,
3336 shape_info->offset_x,
3337 shape_info->offset_y);
3339 mode = gtk_widget_get_extension_events (widget);
3340 if (mode != GDK_EXTENSION_EVENTS_NONE)
3341 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3346 * gtk_widget_unrealize:
3347 * @widget: a #GtkWidget
3349 * This function is only useful in widget implementations.
3350 * Causes a widget to be unrealized (frees all GDK resources
3351 * associated with the widget, such as @widget->window).
3354 gtk_widget_unrealize (GtkWidget *widget)
3356 g_return_if_fail (GTK_IS_WIDGET (widget));
3358 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3359 gtk_widget_shape_combine_mask (widget, NULL, 0, 0);
3361 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3362 gtk_widget_input_shape_combine_mask (widget, NULL, 0, 0);
3364 if (GTK_WIDGET_REALIZED (widget))
3366 g_object_ref (widget);
3367 _gtk_tooltip_hide (widget);
3368 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3369 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
3370 g_object_unref (widget);
3374 /*****************************************
3376 *****************************************/
3379 * gtk_widget_queue_draw_area:
3380 * @widget: a #GtkWidget
3381 * @x: x coordinate of upper-left corner of rectangle to redraw
3382 * @y: y coordinate of upper-left corner of rectangle to redraw
3383 * @width: width of region to draw
3384 * @height: height of region to draw
3386 * Invalidates the rectangular area of @widget defined by @x, @y,
3387 * @width and @height by calling gdk_window_invalidate_rect() on the
3388 * widget's window and all its child windows. Once the main loop
3389 * becomes idle (after the current batch of events has been processed,
3390 * roughly), the window will receive expose events for the union of
3391 * all regions that have been invalidated.
3393 * Normally you would only use this function in widget
3394 * implementations. You might also use it, or
3395 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3396 * #GtkDrawingArea or some portion thereof.
3398 * Frequently you can just call gdk_window_invalidate_rect() or
3399 * gdk_window_invalidate_region() instead of this function. Those
3400 * functions will invalidate only a single window, instead of the
3401 * widget and all its children.
3403 * The advantage of adding to the invalidated region compared to
3404 * simply drawing immediately is efficiency; using an invalid region
3405 * ensures that you only have to redraw one time.
3408 gtk_widget_queue_draw_area (GtkWidget *widget,
3414 GdkRectangle invalid_rect;
3417 g_return_if_fail (GTK_IS_WIDGET (widget));
3419 if (!GTK_WIDGET_REALIZED (widget))
3422 /* Just return if the widget or one of its ancestors isn't mapped */
3423 for (w = widget; w != NULL; w = w->parent)
3424 if (!GTK_WIDGET_MAPPED (w))
3427 /* Find the correct widget */
3429 if (!GTK_WIDGET_NO_WINDOW (widget))
3433 /* Translate widget relative to window-relative */
3435 gint wx, wy, wwidth, wheight;
3437 gdk_window_get_position (widget->window, &wx, &wy);
3438 x -= wx - widget->allocation.x;
3439 y -= wy - widget->allocation.y;
3441 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
3443 if (x + width <= 0 || y + height <= 0 ||
3444 x >= wwidth || y >= wheight)
3455 if (x + width > wwidth)
3457 if (y + height > wheight)
3458 height = wheight - y;
3464 invalid_rect.width = width;
3465 invalid_rect.height = height;
3467 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
3471 widget_add_child_draw_rectangle (GtkWidget *widget,
3474 GdkRectangle child_rect;
3476 if (!GTK_WIDGET_MAPPED (widget) ||
3477 widget->window != widget->parent->window)
3480 gtk_widget_get_draw_rectangle (widget, &child_rect);
3481 gdk_rectangle_union (rect, &child_rect, rect);
3485 gtk_widget_get_draw_rectangle (GtkWidget *widget,
3488 if (GTK_WIDGET_NO_WINDOW (widget))
3490 GtkBorder *draw_border = NULL;
3492 *rect = widget->allocation;
3494 gtk_widget_style_get (widget,
3495 "draw-border", &draw_border,
3499 rect->x -= draw_border->top;
3500 rect->y -= draw_border->left;
3501 rect->width += draw_border->left + draw_border->right;
3502 rect->height += draw_border->top + draw_border->bottom;
3504 gtk_border_free (draw_border);
3507 if (GTK_IS_CONTAINER (widget))
3508 gtk_container_forall (GTK_CONTAINER (widget),
3509 (GtkCallback)widget_add_child_draw_rectangle,
3516 rect->width = widget->allocation.width;
3517 rect->height = widget->allocation.height;
3522 * gtk_widget_queue_draw:
3523 * @widget: a #GtkWidget
3525 * Equivalent to calling gtk_widget_queue_draw_area() for the
3526 * entire area of a widget.
3529 gtk_widget_queue_draw (GtkWidget *widget)
3533 g_return_if_fail (GTK_IS_WIDGET (widget));
3535 gtk_widget_get_draw_rectangle (widget, &rect);
3537 gtk_widget_queue_draw_area (widget,
3539 rect.width, rect.height);
3542 /* Invalidates the given area (allocation-relative-coordinates)
3543 * in all of the widget's windows
3546 * gtk_widget_queue_clear_area:
3547 * @widget: a #GtkWidget
3548 * @x: x coordinate of upper-left corner of rectangle to redraw
3549 * @y: y coordinate of upper-left corner of rectangle to redraw
3550 * @width: width of region to draw
3551 * @height: height of region to draw
3553 * This function is no longer different from
3554 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
3555 * gtk_widget_queue_draw_area(). Originally
3556 * gtk_widget_queue_clear_area() would force a redraw of the
3557 * background for %GTK_NO_WINDOW widgets, and
3558 * gtk_widget_queue_draw_area() would not. Now both functions ensure
3559 * the background will be redrawn.
3561 * Deprecated: 2.2: Use gtk_widget_queue_draw_area() instead.
3564 gtk_widget_queue_clear_area (GtkWidget *widget,
3570 g_return_if_fail (GTK_IS_WIDGET (widget));
3572 gtk_widget_queue_draw_area (widget, x, y, width, height);
3576 * gtk_widget_queue_clear:
3577 * @widget: a #GtkWidget
3579 * This function does the same as gtk_widget_queue_draw().
3581 * Deprecated: 2.2: Use gtk_widget_queue_draw() instead.
3584 gtk_widget_queue_clear (GtkWidget *widget)
3586 g_return_if_fail (GTK_IS_WIDGET (widget));
3588 gtk_widget_queue_draw (widget);
3592 * gtk_widget_queue_resize:
3593 * @widget: a #GtkWidget
3595 * This function is only for use in widget implementations.
3596 * Flags a widget to have its size renegotiated; should
3597 * be called when a widget for some reason has a new size request.
3598 * For example, when you change the text in a #GtkLabel, #GtkLabel
3599 * queues a resize to ensure there's enough space for the new text.
3602 gtk_widget_queue_resize (GtkWidget *widget)
3604 g_return_if_fail (GTK_IS_WIDGET (widget));
3606 if (GTK_WIDGET_REALIZED (widget))
3607 gtk_widget_queue_shallow_draw (widget);
3609 _gtk_size_group_queue_resize (widget);
3613 * gtk_widget_queue_resize_no_redraw:
3614 * @widget: a #GtkWidget
3616 * This function works like gtk_widget_queue_resize(),
3617 * except that the widget is not invalidated.
3622 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
3624 g_return_if_fail (GTK_IS_WIDGET (widget));
3626 _gtk_size_group_queue_resize (widget);
3631 * @widget: a #GtkWidget
3632 * @area: area to draw
3634 * In GTK+ 1.2, this function would immediately render the
3635 * region @area of a widget, by invoking the virtual draw method of a
3636 * widget. In GTK+ 2.0, the draw method is gone, and instead
3637 * gtk_widget_draw() simply invalidates the specified region of the
3638 * widget, then updates the invalid region of the widget immediately.
3639 * Usually you don't want to update the region immediately for
3640 * performance reasons, so in general gtk_widget_queue_draw_area() is
3641 * a better choice if you want to draw a region of a widget.
3644 gtk_widget_draw (GtkWidget *widget,
3645 const GdkRectangle *area)
3647 g_return_if_fail (GTK_IS_WIDGET (widget));
3649 if (GTK_WIDGET_DRAWABLE (widget))
3652 gtk_widget_queue_draw_area (widget,
3654 area->width, area->height);
3656 gtk_widget_queue_draw (widget);
3658 gdk_window_process_updates (widget->window, TRUE);
3663 * gtk_widget_size_request:
3664 * @widget: a #GtkWidget
3665 * @requisition: a #GtkRequisition to be filled in
3667 * This function is typically used when implementing a #GtkContainer
3668 * subclass. Obtains the preferred size of a widget. The container
3669 * uses this information to arrange its child widgets and decide what
3670 * size allocations to give them with gtk_widget_size_allocate().
3672 * You can also call this function from an application, with some
3673 * caveats. Most notably, getting a size request requires the widget
3674 * to be associated with a screen, because font information may be
3675 * needed. Multihead-aware applications should keep this in mind.
3677 * Also remember that the size request is not necessarily the size
3678 * a widget will actually be allocated.
3680 * See also gtk_widget_get_child_requisition().
3683 gtk_widget_size_request (GtkWidget *widget,
3684 GtkRequisition *requisition)
3686 g_return_if_fail (GTK_IS_WIDGET (widget));
3688 #ifdef G_ENABLE_DEBUG
3689 if (requisition == &widget->requisition)
3690 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.");
3691 #endif /* G_ENABLE_DEBUG */
3693 _gtk_size_group_compute_requisition (widget, requisition);
3697 * gtk_widget_get_child_requisition:
3698 * @widget: a #GtkWidget
3699 * @requisition: a #GtkRequisition to be filled in
3701 * This function is only for use in widget implementations. Obtains
3702 * @widget->requisition, unless someone has forced a particular
3703 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
3704 * in which case it returns that geometry instead of the widget's
3707 * This function differs from gtk_widget_size_request() in that
3708 * it retrieves the last size request value from @widget->requisition,
3709 * while gtk_widget_size_request() actually calls the "size_request" method
3710 * on @widget to compute the size request and fill in @widget->requisition,
3711 * and only then returns @widget->requisition.
3713 * Because this function does not call the "size_request" method, it
3714 * can only be used when you know that @widget->requisition is
3715 * up-to-date, that is, gtk_widget_size_request() has been called
3716 * since the last time a resize was queued. In general, only container
3717 * implementations have this information; applications should use
3718 * gtk_widget_size_request().
3721 gtk_widget_get_child_requisition (GtkWidget *widget,
3722 GtkRequisition *requisition)
3724 _gtk_size_group_get_child_requisition (widget, requisition);
3728 invalidate_predicate (GdkWindow *window,
3733 gdk_window_get_user_data (window, &user_data);
3735 return (user_data == data);
3738 /* Invalidate @region in widget->window and all children
3739 * of widget->window owned by widget. @region is in the
3740 * same coordinates as widget->allocation and will be
3741 * modified by this call.
3744 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
3747 if (!GTK_WIDGET_REALIZED (widget))
3750 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3754 gdk_window_get_position (widget->window, &x, &y);
3755 gdk_region_offset (region, -x, -y);
3758 gdk_window_invalidate_maybe_recurse (widget->window, region,
3759 invalidate_predicate, widget);
3763 * gtk_widget_queue_shallow_draw:
3764 * @widget: a #GtkWidget
3766 * Like gtk_widget_queue_draw(), but only windows owned
3767 * by @widget are invalidated.
3770 gtk_widget_queue_shallow_draw (GtkWidget *widget)
3775 if (!GTK_WIDGET_REALIZED (widget))
3778 gtk_widget_get_draw_rectangle (widget, &rect);
3780 /* get_draw_rectangle() gives us window coordinates, we
3781 * need to convert to the coordinates that widget->allocation
3784 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
3788 gdk_window_get_position (widget->window, &wx, &wy);
3794 region = gdk_region_rectangle (&rect);
3795 gtk_widget_invalidate_widget_windows (widget, region);
3796 gdk_region_destroy (region);
3800 * gtk_widget_size_allocate:
3801 * @widget: a #GtkWidget
3802 * @allocation: position and size to be allocated to @widget
3804 * This function is only used by #GtkContainer subclasses, to assign a size
3805 * and position to their child widgets.
3808 gtk_widget_size_allocate (GtkWidget *widget,
3809 GtkAllocation *allocation)
3811 GtkWidgetAuxInfo *aux_info;
3812 GdkRectangle real_allocation;
3813 GdkRectangle old_allocation;
3814 gboolean alloc_needed;
3815 gboolean size_changed;
3816 gboolean position_changed;
3818 g_return_if_fail (GTK_IS_WIDGET (widget));
3820 #ifdef G_ENABLE_DEBUG
3821 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
3832 parent = gtk_widget_get_parent (parent);
3835 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
3836 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
3837 2 * depth, " ", name,
3838 allocation->width, allocation->height);
3840 #endif /* G_ENABLE_DEBUG */
3842 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
3843 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
3844 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
3846 old_allocation = widget->allocation;
3847 real_allocation = *allocation;
3848 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
3852 if (aux_info->x_set)
3853 real_allocation.x = aux_info->x;
3854 if (aux_info->y_set)
3855 real_allocation.y = aux_info->y;
3858 if (real_allocation.width < 0 || real_allocation.height < 0)
3860 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
3861 real_allocation.width,
3862 real_allocation.height);
3865 real_allocation.width = MAX (real_allocation.width, 1);
3866 real_allocation.height = MAX (real_allocation.height, 1);
3868 size_changed = (old_allocation.width != real_allocation.width ||
3869 old_allocation.height != real_allocation.height);
3870 position_changed = (old_allocation.x != real_allocation.x ||
3871 old_allocation.y != real_allocation.y);
3873 if (!alloc_needed && !size_changed && !position_changed)
3876 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
3878 if (GTK_WIDGET_MAPPED (widget))
3880 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
3882 /* Invalidate union(old_allaction,widget->allocation) in widget->window
3884 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3885 gdk_region_union_with_rect (invalidate, &old_allocation);
3887 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
3888 gdk_region_destroy (invalidate);
3893 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
3895 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
3897 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
3898 gdk_region_union_with_rect (invalidate, &old_allocation);
3900 gtk_widget_invalidate_widget_windows (widget, invalidate);
3901 gdk_region_destroy (invalidate);
3906 if ((size_changed || position_changed) && widget->parent &&
3907 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
3909 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
3910 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
3911 gdk_region_destroy (invalidate);
3916 * gtk_widget_common_ancestor:
3917 * @widget_a: a #GtkWidget
3918 * @widget_b: a #GtkWidget
3920 * Find the common ancestor of @widget_a and @widget_b that
3921 * is closest to the two widgets.
3923 * Return value: the closest common ancestor of @widget_a and
3924 * @widget_b or %NULL if @widget_a and @widget_b do not
3925 * share a common ancestor.
3928 gtk_widget_common_ancestor (GtkWidget *widget_a,
3929 GtkWidget *widget_b)
3931 GtkWidget *parent_a;
3932 GtkWidget *parent_b;
3936 parent_a = widget_a;
3937 while (parent_a->parent)
3939 parent_a = parent_a->parent;
3943 parent_b = widget_b;
3944 while (parent_b->parent)
3946 parent_b = parent_b->parent;
3950 if (parent_a != parent_b)
3953 while (depth_a > depth_b)
3955 widget_a = widget_a->parent;
3959 while (depth_b > depth_a)
3961 widget_b = widget_b->parent;
3965 while (widget_a != widget_b)
3967 widget_a = widget_a->parent;
3968 widget_b = widget_b->parent;
3975 * gtk_widget_translate_coordinates:
3976 * @src_widget: a #GtkWidget
3977 * @dest_widget: a #GtkWidget
3978 * @src_x: X position relative to @src_widget
3979 * @src_y: Y position relative to @src_widget
3980 * @dest_x: location to store X position relative to @dest_widget
3981 * @dest_y: location to store Y position relative to @dest_widget
3983 * Translate coordinates relative to @src_widget's allocation to coordinates
3984 * relative to @dest_widget's allocations. In order to perform this
3985 * operation, both widgets must be realized, and must share a common
3988 * Return value: %FALSE if either widget was not realized, or there
3989 * was no common ancestor. In this case, nothing is stored in
3990 * *@dest_x and *@dest_y. Otherwise %TRUE.
3993 gtk_widget_translate_coordinates (GtkWidget *src_widget,
3994 GtkWidget *dest_widget,
4000 GtkWidget *ancestor;
4003 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4004 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4006 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4007 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
4010 /* Translate from allocation relative to window relative */
4011 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
4014 gdk_window_get_position (src_widget->window, &wx, &wy);
4016 src_x -= wx - src_widget->allocation.x;
4017 src_y -= wy - src_widget->allocation.y;
4021 src_x += src_widget->allocation.x;
4022 src_y += src_widget->allocation.y;
4025 /* Translate to the common ancestor */
4026 window = src_widget->window;
4027 while (window != ancestor->window)
4031 gdk_window_get_position (window, &dx, &dy);
4036 window = gdk_window_get_parent (window);
4038 if (!window) /* Handle GtkHandleBox */
4043 window = dest_widget->window;
4044 while (window != ancestor->window)
4048 gdk_window_get_position (window, &dx, &dy);
4053 window = gdk_window_get_parent (window);
4055 if (!window) /* Handle GtkHandleBox */
4059 /* Translate from window relative to allocation relative */
4060 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
4063 gdk_window_get_position (dest_widget->window, &wx, &wy);
4065 src_x += wx - dest_widget->allocation.x;
4066 src_y += wy - dest_widget->allocation.y;
4070 src_x -= dest_widget->allocation.x;
4071 src_y -= dest_widget->allocation.y;
4083 gtk_widget_real_size_allocate (GtkWidget *widget,
4084 GtkAllocation *allocation)
4086 widget->allocation = *allocation;
4088 if (GTK_WIDGET_REALIZED (widget) &&
4089 !GTK_WIDGET_NO_WINDOW (widget))
4091 gdk_window_move_resize (widget->window,
4092 allocation->x, allocation->y,
4093 allocation->width, allocation->height);
4098 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4101 /* widgets must be onscreen for accels to take effect */
4102 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
4106 * gtk_widget_can_activate_accel:
4107 * @widget: a #GtkWidget
4108 * @signal_id: the ID of a signal installed on @widget
4110 * Determines whether an accelerator that activates the signal
4111 * identified by @signal_id can currently be activated.
4112 * This is done by emitting the #GtkWidget::can-activate-accel
4113 * signal on @widget; if the signal isn't overridden by a
4114 * handler or in a derived widget, then the default check is
4115 * that the widget must be sensitive, and the widget and all
4116 * its ancestors mapped.
4118 * Return value: %TRUE if the accelerator can be activated.
4123 gtk_widget_can_activate_accel (GtkWidget *widget,
4126 gboolean can_activate = FALSE;
4127 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4128 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4129 return can_activate;
4138 closure_accel_activate (GClosure *closure,
4139 GValue *return_value,
4140 guint n_param_values,
4141 const GValue *param_values,
4142 gpointer invocation_hint,
4143 gpointer marshal_data)
4145 AccelClosure *aclosure = (AccelClosure*) closure;
4146 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4149 g_signal_emit (closure->data, aclosure->signal_id, 0);
4151 /* whether accelerator was handled */
4152 g_value_set_boolean (return_value, can_activate);
4156 closures_destroy (gpointer data)
4158 GSList *slist, *closures = data;
4160 for (slist = closures; slist; slist = slist->next)
4162 g_closure_invalidate (slist->data);
4163 g_closure_unref (slist->data);
4165 g_slist_free (closures);
4169 widget_new_accel_closure (GtkWidget *widget,
4172 AccelClosure *aclosure;
4173 GClosure *closure = NULL;
4174 GSList *slist, *closures;
4176 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4177 for (slist = closures; slist; slist = slist->next)
4178 if (!gtk_accel_group_from_accel_closure (slist->data))
4180 /* reuse this closure */
4181 closure = slist->data;
4186 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4187 closures = g_slist_prepend (closures, g_closure_ref (closure));
4188 g_closure_sink (closure);
4189 g_closure_set_marshal (closure, closure_accel_activate);
4191 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4193 aclosure = (AccelClosure*) closure;
4194 g_assert (closure->data == widget);
4195 g_assert (closure->marshal == closure_accel_activate);
4196 aclosure->signal_id = signal_id;
4202 * gtk_widget_add_accelerator
4203 * @widget: widget to install an accelerator on
4204 * @accel_signal: widget signal to emit on accelerator activation
4205 * @accel_group: accel group for this widget, added to its toplevel
4206 * @accel_key: GDK keyval of the accelerator
4207 * @accel_mods: modifier key combination of the accelerator
4208 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4210 * Installs an accelerator for this @widget in @accel_group that causes
4211 * @accel_signal to be emitted if the accelerator is activated.
4212 * The @accel_group needs to be added to the widget's toplevel via
4213 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4214 * Accelerators added through this function are not user changeable during
4215 * runtime. If you want to support accelerators that can be changed by the
4216 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4217 * gtk_menu_item_set_accel_path() instead.
4220 gtk_widget_add_accelerator (GtkWidget *widget,
4221 const gchar *accel_signal,
4222 GtkAccelGroup *accel_group,
4224 GdkModifierType accel_mods,
4225 GtkAccelFlags accel_flags)
4230 g_return_if_fail (GTK_IS_WIDGET (widget));
4231 g_return_if_fail (accel_signal != NULL);
4232 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4234 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4235 if (!query.signal_id ||
4236 !(query.signal_flags & G_SIGNAL_ACTION) ||
4237 query.return_type != G_TYPE_NONE ||
4240 /* hmm, should be elaborate enough */
4241 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4242 G_OBJECT_TYPE_NAME (widget), accel_signal);
4246 closure = widget_new_accel_closure (widget, query.signal_id);
4248 g_object_ref (widget);
4250 /* install the accelerator. since we don't map this onto an accel_path,
4251 * the accelerator will automatically be locked.
4253 gtk_accel_group_connect (accel_group,
4256 accel_flags | GTK_ACCEL_LOCKED,
4259 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4261 g_object_unref (widget);
4265 * gtk_widget_remove_accelerator:
4266 * @widget: widget to install an accelerator on
4267 * @accel_group: accel group for this widget
4268 * @accel_key: GDK keyval of the accelerator
4269 * @accel_mods: modifier key combination of the accelerator
4270 * @returns: whether an accelerator was installed and could be removed
4272 * Removes an accelerator from @widget, previously installed with
4273 * gtk_widget_add_accelerator().
4276 gtk_widget_remove_accelerator (GtkWidget *widget,
4277 GtkAccelGroup *accel_group,
4279 GdkModifierType accel_mods)
4281 GtkAccelGroupEntry *ag_entry;
4282 GList *slist, *clist;
4285 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4286 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4288 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4289 clist = gtk_widget_list_accel_closures (widget);
4290 for (slist = clist; slist; slist = slist->next)
4294 for (i = 0; i < n; i++)
4295 if (slist->data == (gpointer) ag_entry[i].closure)
4297 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4299 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4301 g_list_free (clist);
4306 g_list_free (clist);
4308 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4309 accel_key, accel_mods, accel_group,
4310 G_OBJECT_TYPE_NAME (widget), widget);
4316 * gtk_widget_list_accel_closures
4317 * @widget: widget to list accelerator closures for
4318 * @returns: a newly allocated #GList of closures
4320 * Lists the closures used by @widget for accelerator group connections
4321 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4322 * The closures can be used to monitor accelerator changes on @widget,
4323 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4324 * #GtkAccelGroup of a closure which can be found out with
4325 * gtk_accel_group_from_accel_closure().
4328 gtk_widget_list_accel_closures (GtkWidget *widget)
4331 GList *clist = NULL;
4333 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4335 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4336 if (gtk_accel_group_from_accel_closure (slist->data))
4337 clist = g_list_prepend (clist, slist->data);
4343 GtkAccelGroup *accel_group;
4348 destroy_accel_path (gpointer data)
4350 AccelPath *apath = data;
4352 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4354 /* closures_destroy takes care of unrefing the closure */
4355 g_object_unref (apath->accel_group);
4357 g_slice_free (AccelPath, apath);
4362 * gtk_widget_set_accel_path:
4363 * @widget: a #GtkWidget
4364 * @accel_path: path used to look up the accelerator
4365 * @accel_group: a #GtkAccelGroup.
4367 * Given an accelerator group, @accel_group, and an accelerator path,
4368 * @accel_path, sets up an accelerator in @accel_group so whenever the
4369 * key binding that is defined for @accel_path is pressed, @widget
4370 * will be activated. This removes any accelerators (for any
4371 * accelerator group) installed by previous calls to
4372 * gtk_widget_set_accel_path(). Associating accelerators with
4373 * paths allows them to be modified by the user and the modifications
4374 * to be saved for future use. (See gtk_accel_map_save().)
4376 * This function is a low level function that would most likely
4377 * be used by a menu creation system like #GtkUIManager. If you
4378 * use #GtkUIManager, setting up accelerator paths will be done
4381 * Even when you you aren't using #GtkUIManager, if you only want to
4382 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4383 * provides a somewhat more convenient interface.
4385 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4386 * pass a static string, you can save some memory by interning it first with
4387 * g_intern_static_string().
4390 gtk_widget_set_accel_path (GtkWidget *widget,
4391 const gchar *accel_path,
4392 GtkAccelGroup *accel_group)
4396 g_return_if_fail (GTK_IS_WIDGET (widget));
4397 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4401 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4402 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4404 gtk_accel_map_add_entry (accel_path, 0, 0);
4405 apath = g_slice_new (AccelPath);
4406 apath->accel_group = g_object_ref (accel_group);
4407 apath->path_quark = g_quark_from_string (accel_path);
4408 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4413 /* also removes possible old settings */
4414 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4417 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4419 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4423 _gtk_widget_get_accel_path (GtkWidget *widget,
4428 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4430 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4432 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
4433 return apath ? g_quark_to_string (apath->path_quark) : NULL;
4437 gtk_widget_mnemonic_activate (GtkWidget *widget,
4438 gboolean group_cycling)
4442 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4444 group_cycling = group_cycling != FALSE;
4445 if (!GTK_WIDGET_IS_SENSITIVE (widget))
4448 g_signal_emit (widget,
4449 widget_signals[MNEMONIC_ACTIVATE],
4457 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
4458 gboolean group_cycling)
4460 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
4461 gtk_widget_activate (widget);
4462 else if (GTK_WIDGET_CAN_FOCUS (widget))
4463 gtk_widget_grab_focus (widget);
4466 g_warning ("widget `%s' isn't suitable for mnemonic activation",
4467 G_OBJECT_TYPE_NAME (widget));
4468 gtk_widget_error_bell (widget);
4474 gtk_widget_real_key_press_event (GtkWidget *widget,
4477 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4481 gtk_widget_real_key_release_event (GtkWidget *widget,
4484 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
4488 gtk_widget_real_focus_in_event (GtkWidget *widget,
4489 GdkEventFocus *event)
4491 gtk_widget_queue_shallow_draw (widget);
4497 gtk_widget_real_focus_out_event (GtkWidget *widget,
4498 GdkEventFocus *event)
4500 gtk_widget_queue_shallow_draw (widget);
4505 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
4506 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
4510 * @widget: a #GtkWidget
4511 * @event: a #GdkEvent
4513 * Rarely-used function. This function is used to emit
4514 * the event signals on a widget (those signals should never
4515 * be emitted without using this function to do so).
4516 * If you want to synthesize an event though, don't use this function;
4517 * instead, use gtk_main_do_event() so the event will behave as if
4518 * it were in the event queue. Don't synthesize expose events; instead,
4519 * use gdk_window_invalidate_rect() to invalidate a region of the
4522 * Return value: return from the event signal emission (%TRUE if
4523 * the event was handled)
4526 gtk_widget_event (GtkWidget *widget,
4529 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4530 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
4532 if (event->type == GDK_EXPOSE)
4534 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
4535 "the same effect, call gdk_window_invalidate_rect/region(), "
4536 "followed by gdk_window_process_updates().");
4540 return gtk_widget_event_internal (widget, event);
4545 * gtk_widget_send_expose:
4546 * @widget: a #GtkWidget
4547 * @event: a expose #GdkEvent
4549 * Very rarely-used function. This function is used to emit
4550 * an expose event signals on a widget. This function is not
4551 * normally used directly. The only time it is used is when
4552 * propagating an expose event to a child %NO_WINDOW widget, and
4553 * that is normally done using gtk_container_propagate_expose().
4555 * If you want to force an area of a window to be redrawn,
4556 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
4557 * To cause the redraw to be done immediately, follow that call
4558 * with a call to gdk_window_process_updates().
4560 * Return value: return from the event signal emission (%TRUE if
4561 * the event was handled)
4564 gtk_widget_send_expose (GtkWidget *widget,
4567 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
4568 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
4569 g_return_val_if_fail (event != NULL, TRUE);
4570 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
4572 return gtk_widget_event_internal (widget, event);
4576 event_window_is_still_viewable (GdkEvent *event)
4578 /* Some programs, such as gnome-theme-manager, fake widgets
4579 * into exposing onto a pixmap by sending expose events with
4580 * event->window pointing to a pixmap
4582 if (GDK_IS_PIXMAP (event->any.window))
4583 return event->type == GDK_EXPOSE;
4585 /* Check that we think the event's window is viewable before
4586 * delivering the event, to prevent suprises. We do this here
4587 * at the last moment, since the event may have been queued
4588 * up behind other events, held over a recursive main loop, etc.
4590 switch (event->type)
4593 case GDK_MOTION_NOTIFY:
4594 case GDK_BUTTON_PRESS:
4595 case GDK_2BUTTON_PRESS:
4596 case GDK_3BUTTON_PRESS:
4598 case GDK_ENTER_NOTIFY:
4599 case GDK_PROXIMITY_IN:
4601 return event->any.window && gdk_window_is_viewable (event->any.window);
4604 /* The following events are the second half of paired events;
4605 * we always deliver them to deal with widgets that clean up
4606 * on the second half.
4608 case GDK_BUTTON_RELEASE:
4609 case GDK_KEY_RELEASE:
4610 case GDK_LEAVE_NOTIFY:
4611 case GDK_PROXIMITY_OUT:
4615 /* Remaining events would make sense on an not-viewable window,
4616 * or don't have an associated window.
4623 gtk_widget_event_internal (GtkWidget *widget,
4626 gboolean return_val = FALSE;
4628 /* We check only once for is-still-visible; if someone
4629 * hides the window in on of the signals on the widget,
4630 * they are responsible for returning TRUE to terminate
4633 if (!event_window_is_still_viewable (event))
4636 g_object_ref (widget);
4638 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
4639 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
4644 switch (event->type)
4649 case GDK_BUTTON_PRESS:
4650 case GDK_2BUTTON_PRESS:
4651 case GDK_3BUTTON_PRESS:
4652 signal_num = BUTTON_PRESS_EVENT;
4655 signal_num = SCROLL_EVENT;
4657 case GDK_BUTTON_RELEASE:
4658 signal_num = BUTTON_RELEASE_EVENT;
4660 case GDK_MOTION_NOTIFY:
4661 signal_num = MOTION_NOTIFY_EVENT;
4664 signal_num = DELETE_EVENT;
4667 signal_num = DESTROY_EVENT;
4668 _gtk_tooltip_hide (widget);
4671 signal_num = KEY_PRESS_EVENT;
4673 case GDK_KEY_RELEASE:
4674 signal_num = KEY_RELEASE_EVENT;
4676 case GDK_ENTER_NOTIFY:
4677 signal_num = ENTER_NOTIFY_EVENT;
4679 case GDK_LEAVE_NOTIFY:
4680 signal_num = LEAVE_NOTIFY_EVENT;
4682 case GDK_FOCUS_CHANGE:
4683 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
4684 if (event->focus_change.in)
4685 _gtk_tooltip_focus_in (widget);
4687 _gtk_tooltip_focus_out (widget);
4690 signal_num = CONFIGURE_EVENT;
4693 signal_num = MAP_EVENT;
4696 signal_num = UNMAP_EVENT;
4698 case GDK_WINDOW_STATE:
4699 signal_num = WINDOW_STATE_EVENT;
4701 case GDK_PROPERTY_NOTIFY:
4702 signal_num = PROPERTY_NOTIFY_EVENT;
4704 case GDK_SELECTION_CLEAR:
4705 signal_num = SELECTION_CLEAR_EVENT;
4707 case GDK_SELECTION_REQUEST:
4708 signal_num = SELECTION_REQUEST_EVENT;
4710 case GDK_SELECTION_NOTIFY:
4711 signal_num = SELECTION_NOTIFY_EVENT;
4713 case GDK_PROXIMITY_IN:
4714 signal_num = PROXIMITY_IN_EVENT;
4716 case GDK_PROXIMITY_OUT:
4717 signal_num = PROXIMITY_OUT_EVENT;
4720 signal_num = NO_EXPOSE_EVENT;
4722 case GDK_CLIENT_EVENT:
4723 signal_num = CLIENT_EVENT;
4726 signal_num = EXPOSE_EVENT;
4728 case GDK_VISIBILITY_NOTIFY:
4729 signal_num = VISIBILITY_NOTIFY_EVENT;
4731 case GDK_GRAB_BROKEN:
4732 signal_num = GRAB_BROKEN;
4735 signal_num = DAMAGE_EVENT;
4738 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
4742 if (signal_num != -1)
4743 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
4745 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
4746 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
4750 g_object_unref (widget);
4756 * gtk_widget_activate:
4757 * @widget: a #GtkWidget that's activatable
4759 * For widgets that can be "activated" (buttons, menu items, etc.)
4760 * this function activates them. Activation is what happens when you
4761 * press Enter on a widget during key navigation. If @widget isn't
4762 * activatable, the function returns %FALSE.
4764 * Return value: %TRUE if the widget was activatable
4767 gtk_widget_activate (GtkWidget *widget)
4769 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4771 if (WIDGET_CLASS (widget)->activate_signal)
4773 /* FIXME: we should eventually check the signals signature here */
4774 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
4783 * gtk_widget_set_scroll_adjustments:
4784 * @widget: a #GtkWidget
4785 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
4786 * @vadjustment: an adjustment for vertical scrolling, or %NULL
4788 * For widgets that support scrolling, sets the scroll adjustments and
4789 * returns %TRUE. For widgets that don't support scrolling, does
4790 * nothing and returns %FALSE. Widgets that don't support scrolling
4791 * can be scrolled by placing them in a #GtkViewport, which does
4792 * support scrolling.
4794 * Return value: %TRUE if the widget supports scrolling
4797 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
4798 GtkAdjustment *hadjustment,
4799 GtkAdjustment *vadjustment)
4801 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4803 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
4805 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
4807 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
4809 /* FIXME: we should eventually check the signals signature here */
4810 g_signal_emit (widget,
4811 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
4812 hadjustment, vadjustment);
4820 gtk_widget_reparent_subwindows (GtkWidget *widget,
4821 GdkWindow *new_window)
4823 if (GTK_WIDGET_NO_WINDOW (widget))
4825 GList *children = gdk_window_get_children (widget->window);
4828 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4830 GdkWindow *window = tmp_list->data;
4833 gdk_window_get_user_data (window, &child);
4834 while (child && child != widget)
4835 child = ((GtkWidget*) child)->parent;
4838 gdk_window_reparent (window, new_window, 0, 0);
4841 g_list_free (children);
4846 GList *tmp_list, *children;
4848 parent = gdk_window_get_parent (widget->window);
4851 gdk_window_reparent (widget->window, new_window, 0, 0);
4854 children = gdk_window_get_children (parent);
4856 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
4858 GdkWindow *window = tmp_list->data;
4861 gdk_window_get_user_data (window, &child);
4863 if (child == widget)
4864 gdk_window_reparent (window, new_window, 0, 0);
4867 g_list_free (children);
4873 gtk_widget_reparent_fixup_child (GtkWidget *widget,
4874 gpointer client_data)
4876 g_assert (client_data != NULL);
4878 if (GTK_WIDGET_NO_WINDOW (widget))
4881 g_object_unref (widget->window);
4882 widget->window = (GdkWindow*) client_data;
4884 g_object_ref (widget->window);
4886 if (GTK_IS_CONTAINER (widget))
4887 gtk_container_forall (GTK_CONTAINER (widget),
4888 gtk_widget_reparent_fixup_child,
4894 * gtk_widget_reparent:
4895 * @widget: a #GtkWidget
4896 * @new_parent: a #GtkContainer to move the widget into
4898 * Moves a widget from one #GtkContainer to another, handling reference
4899 * count issues to avoid destroying the widget.
4902 gtk_widget_reparent (GtkWidget *widget,
4903 GtkWidget *new_parent)
4905 g_return_if_fail (GTK_IS_WIDGET (widget));
4906 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
4907 g_return_if_fail (widget->parent != NULL);
4909 if (widget->parent != new_parent)
4911 /* First try to see if we can get away without unrealizing
4912 * the widget as we reparent it. if so we set a flag so
4913 * that gtk_widget_unparent doesn't unrealize widget
4915 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
4916 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
4918 g_object_ref (widget);
4919 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
4920 gtk_container_add (GTK_CONTAINER (new_parent), widget);
4921 g_object_unref (widget);
4923 if (GTK_WIDGET_IN_REPARENT (widget))
4925 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
4927 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
4928 gtk_widget_reparent_fixup_child (widget,
4929 gtk_widget_get_parent_window (widget));
4932 g_object_notify (G_OBJECT (widget), "parent");
4937 * gtk_widget_intersect:
4938 * @widget: a #GtkWidget
4939 * @area: a rectangle
4940 * @intersection: rectangle to store intersection of @widget and @area
4942 * Computes the intersection of a @widget's area and @area, storing
4943 * the intersection in @intersection, and returns %TRUE if there was
4944 * an intersection. @intersection may be %NULL if you're only
4945 * interested in whether there was an intersection.
4947 * Return value: %TRUE if there was an intersection
4950 gtk_widget_intersect (GtkWidget *widget,
4951 const GdkRectangle *area,
4952 GdkRectangle *intersection)
4958 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4959 g_return_val_if_fail (area != NULL, FALSE);
4962 dest = intersection;
4966 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
4968 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
4970 intersection->x -= widget->allocation.x;
4971 intersection->y -= widget->allocation.y;
4978 * gtk_widget_region_intersect:
4979 * @widget: a #GtkWidget
4980 * @region: a #GdkRegion, in the same coordinate system as
4981 * @widget->allocation. That is, relative to @widget->window
4982 * for %NO_WINDOW widgets; relative to the parent window
4983 * of @widget->window for widgets with their own window.
4984 * @returns: A newly allocated region holding the intersection of @widget
4985 * and @region. The coordinates of the return value are
4986 * relative to @widget->window for %NO_WINDOW widgets, and
4987 * relative to the parent window of @widget->window for
4988 * widgets with their own window.
4990 * Computes the intersection of a @widget's area and @region, returning
4991 * the intersection. The result may be empty, use gdk_region_empty() to
4995 gtk_widget_region_intersect (GtkWidget *widget,
4996 const GdkRegion *region)
5001 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5002 g_return_val_if_fail (region != NULL, NULL);
5004 gtk_widget_get_draw_rectangle (widget, &rect);
5006 dest = gdk_region_rectangle (&rect);
5008 gdk_region_intersect (dest, region);
5014 * _gtk_widget_grab_notify:
5015 * @widget: a #GtkWidget
5016 * @was_grabbed: whether a grab is now in effect
5018 * Emits the #GtkWidget::grab-notify signal on @widget.
5023 _gtk_widget_grab_notify (GtkWidget *widget,
5024 gboolean was_grabbed)
5026 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5030 * gtk_widget_grab_focus:
5031 * @widget: a #GtkWidget
5033 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5034 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5035 * something like #GtkFrame won't work. (More precisely, it must have the
5036 * %GTK_CAN_FOCUS flag set.)
5039 gtk_widget_grab_focus (GtkWidget *widget)
5041 g_return_if_fail (GTK_IS_WIDGET (widget));
5043 if (!GTK_WIDGET_IS_SENSITIVE (widget))
5046 g_object_ref (widget);
5047 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5048 g_object_notify (G_OBJECT (widget), "has-focus");
5049 g_object_unref (widget);
5053 reset_focus_recurse (GtkWidget *widget,
5056 if (GTK_IS_CONTAINER (widget))
5058 GtkContainer *container;
5060 container = GTK_CONTAINER (widget);
5061 gtk_container_set_focus_child (container, NULL);
5063 gtk_container_foreach (container,
5064 reset_focus_recurse,
5070 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5072 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
5074 GtkWidget *toplevel;
5077 /* clear the current focus setting, break if the current widget
5078 * is the focus widget's parent, since containers above that will
5079 * be set by the next loop.
5081 toplevel = gtk_widget_get_toplevel (focus_widget);
5082 if (GTK_WIDGET_TOPLEVEL (toplevel))
5084 widget = GTK_WINDOW (toplevel)->focus_widget;
5086 if (widget == focus_widget)
5088 /* We call _gtk_window_internal_set_focus() here so that the
5089 * toplevel window can request the focus if necessary.
5090 * This is needed when the toplevel is a GtkPlug
5092 if (!GTK_WIDGET_HAS_FOCUS (widget))
5093 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5100 while (widget->parent && widget->parent != focus_widget->parent)
5102 widget = widget->parent;
5103 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5107 else if (toplevel != focus_widget)
5109 /* gtk_widget_grab_focus() operates on a tree without window...
5110 * actually, this is very questionable behaviour.
5113 gtk_container_foreach (GTK_CONTAINER (toplevel),
5114 reset_focus_recurse,
5118 /* now propagate the new focus up the widget tree and finally
5119 * set it on the window
5121 widget = focus_widget;
5122 while (widget->parent)
5124 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
5125 widget = widget->parent;
5127 if (GTK_IS_WINDOW (widget))
5128 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5133 gtk_widget_real_query_tooltip (GtkWidget *widget,
5136 gboolean keyboard_tip,
5137 GtkTooltip *tooltip)
5139 gchar *tooltip_markup;
5140 gboolean has_tooltip;
5142 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5143 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5145 if (has_tooltip && tooltip_markup)
5147 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5155 gtk_widget_real_show_help (GtkWidget *widget,
5156 GtkWidgetHelpType help_type)
5158 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5160 _gtk_tooltip_toggle_keyboard_mode (widget);
5169 gtk_widget_real_focus (GtkWidget *widget,
5170 GtkDirectionType direction)
5172 if (!GTK_WIDGET_CAN_FOCUS (widget))
5175 if (!gtk_widget_is_focus (widget))
5177 gtk_widget_grab_focus (widget);
5185 gtk_widget_real_move_focus (GtkWidget *widget,
5186 GtkDirectionType direction)
5188 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5190 if (GTK_IS_WINDOW (toplevel) &&
5191 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5193 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5199 gtk_widget_real_keynav_failed (GtkWidget *widget,
5200 GtkDirectionType direction)
5202 gboolean cursor_only;
5206 case GTK_DIR_TAB_FORWARD:
5207 case GTK_DIR_TAB_BACKWARD:
5214 g_object_get (gtk_widget_get_settings (widget),
5215 "gtk-keynav-cursor-only", &cursor_only,
5222 gtk_widget_error_bell (widget);
5228 * gtk_widget_is_focus:
5229 * @widget: a #GtkWidget
5231 * Determines if the widget is the focus widget within its
5232 * toplevel. (This does not mean that the %HAS_FOCUS flag is
5233 * necessarily set; %HAS_FOCUS will only be set if the
5234 * toplevel widget additionally has the global input focus.)
5236 * Return value: %TRUE if the widget is the focus widget.
5239 gtk_widget_is_focus (GtkWidget *widget)
5241 GtkWidget *toplevel;
5243 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5245 toplevel = gtk_widget_get_toplevel (widget);
5247 if (GTK_IS_WINDOW (toplevel))
5248 return widget == GTK_WINDOW (toplevel)->focus_widget;
5254 * gtk_widget_grab_default:
5255 * @widget: a #GtkWidget
5257 * Causes @widget to become the default widget. @widget must have the
5258 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
5259 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
5260 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when
5261 * the user presses Enter in a window. Default widgets must be
5262 * activatable, that is, gtk_widget_activate() should affect them.
5265 gtk_widget_grab_default (GtkWidget *widget)
5269 g_return_if_fail (GTK_IS_WIDGET (widget));
5270 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
5272 window = gtk_widget_get_toplevel (widget);
5274 if (window && GTK_WIDGET_TOPLEVEL (window))
5275 gtk_window_set_default (GTK_WINDOW (window), widget);
5277 g_warning (G_STRLOC ": widget not within a GtkWindow");
5281 * gtk_widget_set_name:
5282 * @widget: a #GtkWidget
5283 * @name: name for the widget
5285 * Widgets can be named, which allows you to refer to them from a
5286 * gtkrc file. You can apply a style to widgets with a particular name
5287 * in the gtkrc file. See the documentation for gtkrc files (on the
5288 * same page as the docs for #GtkRcStyle).
5290 * Note that widget names are separated by periods in paths (see
5291 * gtk_widget_path()), so names with embedded periods may cause confusion.
5294 gtk_widget_set_name (GtkWidget *widget,
5299 g_return_if_fail (GTK_IS_WIDGET (widget));
5301 new_name = g_strdup (name);
5302 g_free (widget->name);
5303 widget->name = new_name;
5305 if (GTK_WIDGET_RC_STYLE (widget))
5306 gtk_widget_reset_rc_style (widget);
5308 g_object_notify (G_OBJECT (widget), "name");
5312 * gtk_widget_get_name:
5313 * @widget: a #GtkWidget
5315 * Retrieves the name of a widget. See gtk_widget_set_name() for the
5316 * significance of widget names.
5318 * Return value: name of the widget. This string is owned by GTK+ and
5319 * should not be modified or freed
5321 G_CONST_RETURN gchar*
5322 gtk_widget_get_name (GtkWidget *widget)
5324 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5327 return widget->name;
5328 return g_type_name (GTK_WIDGET_TYPE (widget));
5332 * gtk_widget_set_state:
5333 * @widget: a #GtkWidget
5334 * @state: new state for @widget
5336 * This function is for use in widget implementations. Sets the state
5337 * of a widget (insensitive, prelighted, etc.) Usually you should set
5338 * the state using wrapper functions such as gtk_widget_set_sensitive().
5341 gtk_widget_set_state (GtkWidget *widget,
5344 g_return_if_fail (GTK_IS_WIDGET (widget));
5346 if (state == GTK_WIDGET_STATE (widget))
5349 if (state == GTK_STATE_INSENSITIVE)
5350 gtk_widget_set_sensitive (widget, FALSE);
5356 data.state_restoration = FALSE;
5357 data.use_forall = FALSE;
5359 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5361 data.parent_sensitive = TRUE;
5363 gtk_widget_propagate_state (widget, &data);
5365 if (GTK_WIDGET_DRAWABLE (widget))
5366 gtk_widget_queue_draw (widget);
5372 * gtk_widget_set_app_paintable:
5373 * @widget: a #GtkWidget
5374 * @app_paintable: %TRUE if the application will paint on the widget
5376 * Sets whether the application intends to draw on the widget in
5377 * an #GtkWidget::expose-event handler.
5379 * This is a hint to the widget and does not affect the behavior of
5380 * the GTK+ core; many widgets ignore this flag entirely. For widgets
5381 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
5382 * the effect is to suppress default themed drawing of the widget's
5383 * background. (Children of the widget will still be drawn.) The application
5384 * is then entirely responsible for drawing the widget background.
5386 * Note that the background is still drawn when the widget is mapped.
5387 * If this is not suitable (e.g. because you want to make a transparent
5388 * window using an RGBA visual), you can work around this by doing:
5390 * gtk_widget_realize (window);
5391 * gdk_window_set_back_pixmap (window->window, NULL, FALSE);
5392 * gtk_widget_show (window);
5396 gtk_widget_set_app_paintable (GtkWidget *widget,
5397 gboolean app_paintable)
5399 g_return_if_fail (GTK_IS_WIDGET (widget));
5401 app_paintable = (app_paintable != FALSE);
5403 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
5406 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
5408 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
5410 if (GTK_WIDGET_DRAWABLE (widget))
5411 gtk_widget_queue_draw (widget);
5413 g_object_notify (G_OBJECT (widget), "app-paintable");
5418 * gtk_widget_set_double_buffered:
5419 * @widget: a #GtkWidget
5420 * @double_buffered: %TRUE to double-buffer a widget
5422 * Widgets are double buffered by default; you can use this function
5423 * to turn off the buffering. "Double buffered" simply means that
5424 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
5425 * automatically around expose events sent to the
5426 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
5427 * window to an offscreen buffer, and gdk_window_end_paint() draws the
5428 * buffer to the screen. The result is that users see the window
5429 * update in one smooth step, and don't see individual graphics
5430 * primitives being rendered.
5432 * In very simple terms, double buffered widgets don't flicker,
5433 * so you would only use this function to turn off double buffering
5434 * if you had special needs and really knew what you were doing.
5436 * Note: if you turn off double-buffering, you have to handle
5437 * expose events, since even the clearing to the background color or
5438 * pixmap will not happen automatically (as it is done in
5439 * gdk_window_begin_paint()).
5442 gtk_widget_set_double_buffered (GtkWidget *widget,
5443 gboolean double_buffered)
5445 g_return_if_fail (GTK_IS_WIDGET (widget));
5447 if (double_buffered)
5448 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5450 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
5454 * gtk_widget_set_redraw_on_allocate:
5455 * @widget: a #GtkWidget
5456 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
5457 * when it is allocated to a new size. Otherwise, only the
5458 * new portion of the widget will be redrawn.
5460 * Sets whether the entire widget is queued for drawing when its size
5461 * allocation changes. By default, this setting is %TRUE and
5462 * the entire widget is redrawn on every size change. If your widget
5463 * leaves the upper left unchanged when made bigger, turning this
5464 * setting off will improve performance.
5466 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
5467 * off all allocation on resizing: the widget will not even redraw if
5468 * its position changes; this is to allow containers that don't draw
5469 * anything to avoid excess invalidations. If you set this flag on a
5470 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
5471 * you are responsible for invalidating both the old and new allocation
5472 * of the widget when the widget is moved and responsible for invalidating
5473 * regions newly when the widget increases size.
5476 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
5477 gboolean redraw_on_allocate)
5479 g_return_if_fail (GTK_IS_WIDGET (widget));
5481 if (redraw_on_allocate)
5482 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5484 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
5488 * gtk_widget_set_sensitive:
5489 * @widget: a #GtkWidget
5490 * @sensitive: %TRUE to make the widget sensitive
5492 * Sets the sensitivity of a widget. A widget is sensitive if the user
5493 * can interact with it. Insensitive widgets are "grayed out" and the
5494 * user can't interact with them. Insensitive widgets are known as
5495 * "inactive", "disabled", or "ghosted" in some other toolkits.
5498 gtk_widget_set_sensitive (GtkWidget *widget,
5503 g_return_if_fail (GTK_IS_WIDGET (widget));
5505 sensitive = (sensitive != FALSE);
5507 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
5512 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
5513 data.state = GTK_WIDGET_SAVED_STATE (widget);
5517 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
5518 data.state = GTK_WIDGET_STATE (widget);
5520 data.state_restoration = TRUE;
5521 data.use_forall = TRUE;
5524 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
5526 data.parent_sensitive = TRUE;
5528 gtk_widget_propagate_state (widget, &data);
5529 if (GTK_WIDGET_DRAWABLE (widget))
5530 gtk_widget_queue_draw (widget);
5532 g_object_notify (G_OBJECT (widget), "sensitive");
5536 * gtk_widget_set_parent:
5537 * @widget: a #GtkWidget
5538 * @parent: parent container
5540 * This function is useful only when implementing subclasses of
5542 * Sets the container as the parent of @widget, and takes care of
5543 * some details such as updating the state and style of the child
5544 * to reflect its new location. The opposite function is
5545 * gtk_widget_unparent().
5548 gtk_widget_set_parent (GtkWidget *widget,
5553 g_return_if_fail (GTK_IS_WIDGET (widget));
5554 g_return_if_fail (GTK_IS_WIDGET (parent));
5555 g_return_if_fail (widget != parent);
5556 if (widget->parent != NULL)
5558 g_warning ("Can't set a parent on widget which has a parent\n");
5561 if (GTK_WIDGET_TOPLEVEL (widget))
5563 g_warning ("Can't set a parent on a toplevel widget\n");
5567 /* keep this function in sync with gtk_menu_attach_to_widget()
5570 g_object_ref_sink (widget);
5571 widget->parent = parent;
5573 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
5574 data.state = GTK_WIDGET_STATE (parent);
5576 data.state = GTK_WIDGET_STATE (widget);
5577 data.state_restoration = FALSE;
5578 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
5579 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
5581 gtk_widget_propagate_state (widget, &data);
5583 gtk_widget_reset_rc_styles (widget);
5585 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
5586 if (GTK_WIDGET_ANCHORED (widget->parent))
5587 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
5588 g_object_notify (G_OBJECT (widget), "parent");
5590 /* Enforce realized/mapped invariants
5592 if (GTK_WIDGET_REALIZED (widget->parent))
5593 gtk_widget_realize (widget);
5595 if (GTK_WIDGET_VISIBLE (widget->parent) &&
5596 GTK_WIDGET_VISIBLE (widget))
5598 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
5599 GTK_WIDGET_MAPPED (widget->parent))
5600 gtk_widget_map (widget);
5602 gtk_widget_queue_resize (widget);
5607 * gtk_widget_get_parent:
5608 * @widget: a #GtkWidget
5610 * Returns the parent container of @widget.
5612 * Return value: the parent container of @widget, or %NULL
5615 gtk_widget_get_parent (GtkWidget *widget)
5617 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5619 return widget->parent;
5622 /*****************************************
5624 * see docs/styles.txt
5625 *****************************************/
5628 * gtk_widget_set_style:
5629 * @widget: a #GtkWidget
5630 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
5631 * gtk_widget_set_style() and go back to the default style
5633 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
5634 * want to use this function; it interacts badly with themes, because
5635 * themes work by replacing the #GtkStyle. Instead, use
5636 * gtk_widget_modify_style().
5639 gtk_widget_set_style (GtkWidget *widget,
5642 g_return_if_fail (GTK_IS_WIDGET (widget));
5646 gboolean initial_emission;
5648 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5650 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
5651 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
5653 gtk_widget_set_style_internal (widget, style, initial_emission);
5657 if (GTK_WIDGET_USER_STYLE (widget))
5658 gtk_widget_reset_rc_style (widget);
5663 * gtk_widget_ensure_style:
5664 * @widget: a #GtkWidget
5666 * Ensures that @widget has a style (@widget->style). Not a very useful
5667 * function; most of the time, if you want the style, the widget is
5668 * realized, and realized widgets are guaranteed to have a style
5672 gtk_widget_ensure_style (GtkWidget *widget)
5674 g_return_if_fail (GTK_IS_WIDGET (widget));
5676 if (!GTK_WIDGET_USER_STYLE (widget) &&
5677 !GTK_WIDGET_RC_STYLE (widget))
5678 gtk_widget_reset_rc_style (widget);
5681 /* Look up the RC style for this widget, unsetting any user style that
5682 * may be in effect currently
5685 gtk_widget_reset_rc_style (GtkWidget *widget)
5687 GtkStyle *new_style = NULL;
5688 gboolean initial_emission;
5690 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
5692 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
5693 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
5695 if (gtk_widget_has_screen (widget))
5696 new_style = gtk_rc_get_style (widget);
5698 new_style = gtk_widget_get_default_style ();
5700 if (initial_emission || new_style != widget->style)
5701 gtk_widget_set_style_internal (widget, new_style, initial_emission);
5705 * gtk_widget_get_style:
5706 * @widget: a #GtkWidget
5708 * Simply an accessor function that returns @widget->style.
5710 * Return value: the widget's #GtkStyle
5713 gtk_widget_get_style (GtkWidget *widget)
5715 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5717 return widget->style;
5721 * gtk_widget_modify_style:
5722 * @widget: a #GtkWidget
5723 * @style: the #GtkRcStyle holding the style modifications
5725 * Modifies style values on the widget. Modifications made using this
5726 * technique take precedence over style values set via an RC file,
5727 * however, they will be overriden if a style is explicitely set on
5728 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
5729 * is designed so each field can either be set or unset, so it is
5730 * possible, using this function, to modify some style values and
5731 * leave the others unchanged.
5733 * Note that modifications made with this function are not cumulative
5734 * with previous calls to gtk_widget_modify_style() or with such
5735 * functions as gtk_widget_modify_fg(). If you wish to retain
5736 * previous values, you must first call gtk_widget_get_modifier_style(),
5737 * make your modifications to the returned style, then call
5738 * gtk_widget_modify_style() with that style. On the other hand,
5739 * if you first call gtk_widget_modify_style(), subsequent calls
5740 * to such functions gtk_widget_modify_fg() will have a cumulative
5741 * effect with the initial modifications.
5744 gtk_widget_modify_style (GtkWidget *widget,
5747 g_return_if_fail (GTK_IS_WIDGET (widget));
5748 g_return_if_fail (GTK_IS_RC_STYLE (style));
5750 g_object_set_qdata_full (G_OBJECT (widget),
5752 gtk_rc_style_copy (style),
5753 (GDestroyNotify) g_object_unref);
5755 /* note that "style" may be invalid here if it was the old
5756 * modifier style and the only reference was our own.
5759 if (GTK_WIDGET_RC_STYLE (widget))
5760 gtk_widget_reset_rc_style (widget);
5764 * gtk_widget_get_modifier_style:
5765 * @widget: a #GtkWidget
5767 * Returns the current modifier style for the widget. (As set by
5768 * gtk_widget_modify_style().) If no style has previously set, a new
5769 * #GtkRcStyle will be created with all values unset, and set as the
5770 * modifier style for the widget. If you make changes to this rc
5771 * style, you must call gtk_widget_modify_style(), passing in the
5772 * returned rc style, to make sure that your changes take effect.
5774 * Caution: passing the style back to gtk_widget_modify_style() will
5775 * normally end up destroying it, because gtk_widget_modify_style() copies
5776 * the passed-in style and sets the copy as the new modifier style,
5777 * thus dropping any reference to the old modifier style. Add a reference
5778 * to the modifier style if you want to keep it alive.
5780 * Return value: the modifier style for the widget. This rc style is
5781 * owned by the widget. If you want to keep a pointer to value this
5782 * around, you must add a refcount using g_object_ref().
5785 gtk_widget_get_modifier_style (GtkWidget *widget)
5787 GtkRcStyle *rc_style;
5789 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5791 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
5795 rc_style = gtk_rc_style_new ();
5796 g_object_set_qdata_full (G_OBJECT (widget),
5799 (GDestroyNotify) g_object_unref);
5806 gtk_widget_modify_color_component (GtkWidget *widget,
5807 GtkRcFlags component,
5809 const GdkColor *color)
5811 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
5818 rc_style->fg[state] = *color;
5821 rc_style->bg[state] = *color;
5824 rc_style->text[state] = *color;
5827 rc_style->base[state] = *color;
5830 g_assert_not_reached();
5833 rc_style->color_flags[state] |= component;
5836 rc_style->color_flags[state] &= ~component;
5838 gtk_widget_modify_style (widget, rc_style);
5842 * gtk_widget_modify_fg:
5843 * @widget: a #GtkWidget
5844 * @state: the state for which to set the foreground color
5845 * @color: the color to assign (does not need to be allocated),
5846 * or %NULL to undo the effect of previous calls to
5847 * of gtk_widget_modify_fg().
5849 * Sets the foreground color for a widget in a particular state.
5850 * All other style values are left untouched. See also
5851 * gtk_widget_modify_style().
5854 gtk_widget_modify_fg (GtkWidget *widget,
5856 const GdkColor *color)
5858 g_return_if_fail (GTK_IS_WIDGET (widget));
5859 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5861 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
5865 * gtk_widget_modify_bg:
5866 * @widget: a #GtkWidget
5867 * @state: the state for which to set the background color
5868 * @color: the color to assign (does not need to be allocated),
5869 * or %NULL to undo the effect of previous calls to
5870 * of gtk_widget_modify_bg().
5872 * Sets the background color for a widget in a particular state.
5873 * All other style values are left untouched. See also
5874 * gtk_widget_modify_style().
5876 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5877 * draw on their parent container's window and thus may not draw any
5878 * background themselves. This is the case for e.g. #GtkLabel. To modify
5879 * the background of such widgets, you have to set the background color
5880 * on their parent; if you want to set the background of a rectangular
5881 * area around a label, try placing the label in a #GtkEventBox widget
5882 * and setting the background color on that.
5885 gtk_widget_modify_bg (GtkWidget *widget,
5887 const GdkColor *color)
5889 g_return_if_fail (GTK_IS_WIDGET (widget));
5890 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5892 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
5896 * gtk_widget_modify_text:
5897 * @widget: a #GtkWidget
5898 * @state: the state for which to set the text color
5899 * @color: the color to assign (does not need to be allocated),
5900 * or %NULL to undo the effect of previous calls to
5901 * of gtk_widget_modify_text().
5903 * Sets the text color for a widget in a particular state. All other
5904 * style values are left untouched. The text color is the foreground
5905 * color used along with the base color (see gtk_widget_modify_base())
5906 * for widgets such as #GtkEntry and #GtkTextView. See also
5907 * gtk_widget_modify_style().
5910 gtk_widget_modify_text (GtkWidget *widget,
5912 const GdkColor *color)
5914 g_return_if_fail (GTK_IS_WIDGET (widget));
5915 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5917 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
5921 * gtk_widget_modify_base:
5922 * @widget: a #GtkWidget
5923 * @state: the state for which to set the base color
5924 * @color: the color to assign (does not need to be allocated),
5925 * or %NULL to undo the effect of previous calls to
5926 * of gtk_widget_modify_base().
5928 * Sets the base color for a widget in a particular state.
5929 * All other style values are left untouched. The base color
5930 * is the background color used along with the text color
5931 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
5932 * and #GtkTextView. See also gtk_widget_modify_style().
5934 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
5935 * draw on their parent container's window and thus may not draw any
5936 * background themselves. This is the case for e.g. #GtkLabel. To modify
5937 * the background of such widgets, you have to set the base color on their
5938 * parent; if you want to set the background of a rectangular area around
5939 * a label, try placing the label in a #GtkEventBox widget and setting
5940 * the base color on that.
5943 gtk_widget_modify_base (GtkWidget *widget,
5945 const GdkColor *color)
5947 g_return_if_fail (GTK_IS_WIDGET (widget));
5948 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
5950 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
5954 modify_color_property (GtkWidget *widget,
5955 GtkRcStyle *rc_style,
5957 const GdkColor *color)
5959 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
5960 GQuark property_name = g_quark_from_string (name);
5964 GtkRcProperty rc_property = {0};
5967 rc_property.type_name = type_name;
5968 rc_property.property_name = property_name;
5969 rc_property.origin = NULL;
5971 color_name = gdk_color_to_string (color);
5972 g_value_init (&rc_property.value, G_TYPE_STRING);
5973 g_value_take_string (&rc_property.value, color_name);
5975 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
5977 g_value_unset (&rc_property.value);
5980 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
5984 * gtk_widget_modify_cursor:
5985 * @widget: a #GtkWidget
5986 * @primary: the color to use for primary cursor (does not need to be
5987 * allocated), or %NULL to undo the effect of previous calls to
5988 * of gtk_widget_modify_cursor().
5989 * @secondary: the color to use for secondary cursor (does not need to be
5990 * allocated), or %NULL to undo the effect of previous calls to
5991 * of gtk_widget_modify_cursor().
5993 * Sets the cursor color to use in a widget, overriding the
5994 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
5995 * style properties. All other style values are left untouched.
5996 * See also gtk_widget_modify_style().
6001 gtk_widget_modify_cursor (GtkWidget *widget,
6002 const GdkColor *primary,
6003 const GdkColor *secondary)
6005 GtkRcStyle *rc_style;
6007 g_return_if_fail (GTK_IS_WIDGET (widget));
6009 rc_style = gtk_widget_get_modifier_style (widget);
6011 modify_color_property (widget, rc_style, "cursor-color", primary);
6012 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
6014 gtk_widget_modify_style (widget, rc_style);
6018 * gtk_widget_modify_font:
6019 * @widget: a #GtkWidget
6020 * @font_desc: the font description to use, or %NULL to undo
6021 * the effect of previous calls to gtk_widget_modify_font().
6023 * Sets the font to use for a widget. All other style values are left
6024 * untouched. See also gtk_widget_modify_style().
6027 gtk_widget_modify_font (GtkWidget *widget,
6028 PangoFontDescription *font_desc)
6030 GtkRcStyle *rc_style;
6032 g_return_if_fail (GTK_IS_WIDGET (widget));
6034 rc_style = gtk_widget_get_modifier_style (widget);
6036 if (rc_style->font_desc)
6037 pango_font_description_free (rc_style->font_desc);
6040 rc_style->font_desc = pango_font_description_copy (font_desc);
6042 rc_style->font_desc = NULL;
6044 gtk_widget_modify_style (widget, rc_style);
6048 gtk_widget_direction_changed (GtkWidget *widget,
6049 GtkTextDirection previous_direction)
6051 gtk_widget_queue_resize (widget);
6055 gtk_widget_style_set (GtkWidget *widget,
6056 GtkStyle *previous_style)
6058 if (GTK_WIDGET_REALIZED (widget) &&
6059 !GTK_WIDGET_NO_WINDOW (widget))
6060 gtk_style_set_background (widget->style, widget->window, widget->state);
6064 gtk_widget_set_style_internal (GtkWidget *widget,
6066 gboolean initial_emission)
6068 g_object_ref (widget);
6069 g_object_freeze_notify (G_OBJECT (widget));
6071 if (widget->style != style)
6073 GtkStyle *previous_style;
6075 if (GTK_WIDGET_REALIZED (widget))
6077 gtk_widget_reset_shapes (widget);
6078 gtk_style_detach (widget->style);
6081 previous_style = widget->style;
6082 widget->style = style;
6083 g_object_ref (widget->style);
6085 if (GTK_WIDGET_REALIZED (widget))
6086 widget->style = gtk_style_attach (widget->style, widget->window);
6088 gtk_widget_update_pango_context (widget);
6089 g_signal_emit (widget,
6090 widget_signals[STYLE_SET],
6092 initial_emission ? NULL : previous_style);
6093 g_object_unref (previous_style);
6095 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
6096 gtk_widget_queue_resize (widget);
6098 else if (initial_emission)
6100 gtk_widget_update_pango_context (widget);
6101 g_signal_emit (widget,
6102 widget_signals[STYLE_SET],
6106 g_object_notify (G_OBJECT (widget), "style");
6107 g_object_thaw_notify (G_OBJECT (widget));
6108 g_object_unref (widget);
6112 GtkWidget *previous_toplevel;
6113 GdkScreen *previous_screen;
6114 GdkScreen *new_screen;
6115 } HierarchyChangedInfo;
6118 do_screen_change (GtkWidget *widget,
6119 GdkScreen *old_screen,
6120 GdkScreen *new_screen)
6122 if (old_screen != new_screen)
6126 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6128 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
6131 _gtk_tooltip_hide (widget);
6132 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
6137 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
6138 gpointer client_data)
6140 HierarchyChangedInfo *info = client_data;
6141 gboolean new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
6142 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
6144 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
6146 g_object_ref (widget);
6149 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
6151 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
6153 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
6154 do_screen_change (widget, info->previous_screen, info->new_screen);
6156 if (GTK_IS_CONTAINER (widget))
6157 gtk_container_forall (GTK_CONTAINER (widget),
6158 gtk_widget_propagate_hierarchy_changed_recurse,
6161 g_object_unref (widget);
6166 * _gtk_widget_propagate_hierarchy_changed:
6167 * @widget: a #GtkWidget
6168 * @previous_toplevel: Previous toplevel
6170 * Propagates changes in the anchored state to a widget and all
6171 * children, unsetting or setting the %ANCHORED flag, and
6172 * emitting #GtkWidget::hierarchy-changed.
6175 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
6176 GtkWidget *previous_toplevel)
6178 HierarchyChangedInfo info;
6180 info.previous_toplevel = previous_toplevel;
6181 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
6183 if (GTK_WIDGET_TOPLEVEL (widget) ||
6184 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
6185 info.new_screen = gtk_widget_get_screen (widget);
6187 info.new_screen = NULL;
6189 if (info.previous_screen)
6190 g_object_ref (info.previous_screen);
6191 if (previous_toplevel)
6192 g_object_ref (previous_toplevel);
6194 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
6196 if (previous_toplevel)
6197 g_object_unref (previous_toplevel);
6198 if (info.previous_screen)
6199 g_object_unref (info.previous_screen);
6203 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
6204 gpointer client_data)
6206 HierarchyChangedInfo *info = client_data;
6208 g_object_ref (widget);
6210 do_screen_change (widget, info->previous_screen, info->new_screen);
6212 if (GTK_IS_CONTAINER (widget))
6213 gtk_container_forall (GTK_CONTAINER (widget),
6214 gtk_widget_propagate_screen_changed_recurse,
6217 g_object_unref (widget);
6221 * gtk_widget_is_composited:
6222 * @widget: a #GtkWidget
6224 * Whether @widget can rely on having its alpha channel
6225 * drawn correctly. On X11 this function returns whether a
6226 * compositing manager is running for @widget's screen.
6228 * Please note that the semantics of this call will change
6229 * in the future if used on a widget that has a composited
6230 * window in its heirarchy (as set by
6231 * gdk_window_set_composited()).
6233 * Return value: %TRUE if the widget can rely on its alpha
6234 * channel being drawn correctly.
6239 gtk_widget_is_composited (GtkWidget *widget)
6243 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6245 screen = gtk_widget_get_screen (widget);
6247 return gdk_screen_is_composited (screen);
6251 propagate_composited_changed (GtkWidget *widget,
6254 if (GTK_IS_CONTAINER (widget))
6256 gtk_container_forall (GTK_CONTAINER (widget),
6257 propagate_composited_changed,
6261 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
6265 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
6267 propagate_composited_changed (widget, NULL);
6271 * _gtk_widget_propagate_screen_changed:
6272 * @widget: a #GtkWidget
6273 * @previous_screen: Previous screen
6275 * Propagates changes in the screen for a widget to all
6276 * children, emitting #GtkWidget::screen-changed.
6279 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
6280 GdkScreen *previous_screen)
6282 HierarchyChangedInfo info;
6284 info.previous_screen = previous_screen;
6285 info.new_screen = gtk_widget_get_screen (widget);
6287 if (previous_screen)
6288 g_object_ref (previous_screen);
6290 gtk_widget_propagate_screen_changed_recurse (widget, &info);
6292 if (previous_screen)
6293 g_object_unref (previous_screen);
6297 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
6299 if (GTK_WIDGET_RC_STYLE (widget))
6300 gtk_widget_reset_rc_style (widget);
6302 if (GTK_IS_CONTAINER (widget))
6303 gtk_container_forall (GTK_CONTAINER (widget),
6304 reset_rc_styles_recurse,
6309 gtk_widget_reset_rc_styles (GtkWidget *widget)
6311 g_return_if_fail (GTK_IS_WIDGET (widget));
6313 reset_rc_styles_recurse (widget, NULL);
6317 * gtk_widget_get_default_style:
6319 * Returns the default style used by all widgets initially.
6321 * Returns: the default style. This #GtkStyle object is owned
6322 * by GTK+ and should not be modified or freed.
6325 gtk_widget_get_default_style (void)
6327 if (!gtk_default_style)
6329 gtk_default_style = gtk_style_new ();
6330 g_object_ref (gtk_default_style);
6333 return gtk_default_style;
6336 static PangoContext *
6337 gtk_widget_peek_pango_context (GtkWidget *widget)
6339 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6343 * gtk_widget_get_pango_context:
6344 * @widget: a #GtkWidget
6346 * Gets a #PangoContext with the appropriate font map, font description,
6347 * and base direction for this widget. Unlike the context returned
6348 * by gtk_widget_create_pango_context(), this context is owned by
6349 * the widget (it can be used until the screen for the widget changes
6350 * or the widget is removed from its toplevel), and will be updated to
6351 * match any changes to the widget's attributes.
6353 * If you create and keep a #PangoLayout using this context, you must
6354 * deal with changes to the context by calling pango_layout_context_changed()
6355 * on the layout in response to the #GtkWidget::style-set and
6356 * #GtkWidget::direction-changed signals for the widget.
6358 * Return value: the #PangoContext for the widget.
6361 gtk_widget_get_pango_context (GtkWidget *widget)
6363 PangoContext *context;
6365 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6367 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
6370 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
6371 g_object_set_qdata_full (G_OBJECT (widget),
6372 quark_pango_context,
6381 update_pango_context (GtkWidget *widget,
6382 PangoContext *context)
6384 pango_context_set_font_description (context, widget->style->font_desc);
6385 pango_context_set_base_dir (context,
6386 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6387 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6391 gtk_widget_update_pango_context (GtkWidget *widget)
6393 PangoContext *context = gtk_widget_peek_pango_context (widget);
6399 update_pango_context (widget, context);
6401 screen = gtk_widget_get_screen_unchecked (widget);
6404 pango_cairo_context_set_resolution (context,
6405 gdk_screen_get_resolution (screen));
6406 pango_cairo_context_set_font_options (context,
6407 gdk_screen_get_font_options (screen));
6413 * gtk_widget_create_pango_context:
6414 * @widget: a #GtkWidget
6416 * Creates a new #PangoContext with the appropriate font map,
6417 * font description, and base direction for drawing text for
6418 * this widget. See also gtk_widget_get_pango_context().
6420 * Return value: the new #PangoContext
6423 gtk_widget_create_pango_context (GtkWidget *widget)
6426 PangoContext *context;
6428 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6430 screen = gtk_widget_get_screen_unchecked (widget);
6433 GTK_NOTE (MULTIHEAD,
6434 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
6436 screen = gdk_screen_get_default ();
6439 context = gdk_pango_context_get_for_screen (screen);
6441 update_pango_context (widget, context);
6442 pango_context_set_language (context, gtk_get_default_language ());
6448 * gtk_widget_create_pango_layout:
6449 * @widget: a #GtkWidget
6450 * @text: text to set on the layout (can be %NULL)
6452 * Creates a new #PangoLayout with the appropriate font map,
6453 * font description, and base direction for drawing text for
6456 * If you keep a #PangoLayout created in this way around, in order to
6457 * notify the layout of changes to the base direction or font of this
6458 * widget, you must call pango_layout_context_changed() in response to
6459 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
6462 * Return value: the new #PangoLayout
6465 gtk_widget_create_pango_layout (GtkWidget *widget,
6468 PangoLayout *layout;
6469 PangoContext *context;
6471 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6473 context = gtk_widget_get_pango_context (widget);
6474 layout = pango_layout_new (context);
6477 pango_layout_set_text (layout, text, -1);
6483 * gtk_widget_render_icon:
6484 * @widget: a #GtkWidget
6485 * @stock_id: a stock ID
6486 * @size: a stock size. A size of (GtkIconSize)-1 means render at
6487 * the size of the source and don't scale (if there are multiple
6488 * source sizes, GTK+ picks one of the available sizes).
6489 * @detail: render detail to pass to theme engine
6491 * A convenience function that uses the theme engine and RC file
6492 * settings for @widget to look up @stock_id and render it to
6493 * a pixbuf. @stock_id should be a stock icon ID such as
6494 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
6495 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
6496 * identifies the widget or code doing the rendering, so that
6497 * theme engines can special-case rendering for that widget or code.
6499 * The pixels in the returned #GdkPixbuf are shared with the rest of
6500 * the application and should not be modified. The pixbuf should be freed
6501 * after use with g_object_unref().
6503 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
6506 gtk_widget_render_icon (GtkWidget *widget,
6507 const gchar *stock_id,
6509 const gchar *detail)
6511 GtkIconSet *icon_set;
6514 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6515 g_return_val_if_fail (stock_id != NULL, NULL);
6516 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
6518 gtk_widget_ensure_style (widget);
6520 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
6522 if (icon_set == NULL)
6525 retval = gtk_icon_set_render_icon (icon_set,
6527 gtk_widget_get_direction (widget),
6528 GTK_WIDGET_STATE (widget),
6537 * gtk_widget_set_parent_window:
6538 * @widget: a #GtkWidget.
6539 * @parent_window: the new parent window.
6541 * Sets a non default parent window for @widget.
6544 gtk_widget_set_parent_window (GtkWidget *widget,
6545 GdkWindow *parent_window)
6547 GdkWindow *old_parent_window;
6549 g_return_if_fail (GTK_IS_WIDGET (widget));
6551 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
6552 quark_parent_window);
6554 if (parent_window != old_parent_window)
6556 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
6558 if (old_parent_window)
6559 g_object_unref (old_parent_window);
6561 g_object_ref (parent_window);
6567 * gtk_widget_set_child_visible:
6568 * @widget: a #GtkWidget
6569 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
6571 * Sets whether @widget should be mapped along with its when its parent
6572 * is mapped and @widget has been shown with gtk_widget_show().
6574 * The child visibility can be set for widget before it is added to
6575 * a container with gtk_widget_set_parent(), to avoid mapping
6576 * children unnecessary before immediately unmapping them. However
6577 * it will be reset to its default state of %TRUE when the widget
6578 * is removed from a container.
6580 * Note that changing the child visibility of a widget does not
6581 * queue a resize on the widget. Most of the time, the size of
6582 * a widget is computed from all visible children, whether or
6583 * not they are mapped. If this is not the case, the container
6584 * can queue a resize itself.
6586 * This function is only useful for container implementations and
6587 * never should be called by an application.
6590 gtk_widget_set_child_visible (GtkWidget *widget,
6591 gboolean is_visible)
6593 g_return_if_fail (GTK_IS_WIDGET (widget));
6594 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
6596 g_object_ref (widget);
6599 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
6602 GtkWidget *toplevel;
6604 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
6606 toplevel = gtk_widget_get_toplevel (widget);
6607 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
6608 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
6611 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
6613 if (GTK_WIDGET_MAPPED (widget->parent) &&
6614 GTK_WIDGET_CHILD_VISIBLE (widget) &&
6615 GTK_WIDGET_VISIBLE (widget))
6616 gtk_widget_map (widget);
6618 gtk_widget_unmap (widget);
6621 g_object_unref (widget);
6625 * gtk_widget_get_child_visible:
6626 * @widget: a #GtkWidget
6628 * Gets the value set with gtk_widget_set_child_visible().
6629 * If you feel a need to use this function, your code probably
6630 * needs reorganization.
6632 * This function is only useful for container implementations and
6633 * never should be called by an application.
6635 * Return value: %TRUE if the widget is mapped with the parent.
6638 gtk_widget_get_child_visible (GtkWidget *widget)
6640 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6642 return GTK_WIDGET_CHILD_VISIBLE (widget);
6646 gtk_widget_get_screen_unchecked (GtkWidget *widget)
6648 GtkWidget *toplevel;
6650 toplevel = gtk_widget_get_toplevel (widget);
6652 if (GTK_WIDGET_TOPLEVEL (toplevel))
6654 if (GTK_IS_WINDOW (toplevel))
6655 return GTK_WINDOW (toplevel)->screen;
6656 else if (GTK_IS_INVISIBLE (toplevel))
6657 return GTK_INVISIBLE (widget)->screen;
6664 * gtk_widget_get_screen:
6665 * @widget: a #GtkWidget
6667 * Get the #GdkScreen from the toplevel window associated with
6668 * this widget. This function can only be called after the widget
6669 * has been added to a widget hierarchy with a #GtkWindow
6672 * In general, you should only create screen specific
6673 * resources when a widget has been realized, and you should
6674 * free those resources when the widget is unrealized.
6676 * Return value: the #GdkScreen for the toplevel for this widget.
6681 gtk_widget_get_screen (GtkWidget *widget)
6685 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6687 screen = gtk_widget_get_screen_unchecked (widget);
6694 g_warning (G_STRLOC ": Can't get associated screen"
6695 " for a widget unless it is inside a toplevel GtkWindow\n"
6696 " widget type is %s associated top level type is %s",
6697 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
6698 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
6700 return gdk_screen_get_default ();
6705 * gtk_widget_has_screen:
6706 * @widget: a #GtkWidget
6708 * Checks whether there is a #GdkScreen is associated with
6709 * this widget. All toplevel widgets have an associated
6710 * screen, and all widgets added into a heirarchy with a toplevel
6711 * window at the top.
6713 * Return value: %TRUE if there is a #GdkScreen associcated
6719 gtk_widget_has_screen (GtkWidget *widget)
6721 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6723 return (gtk_widget_get_screen_unchecked (widget) != NULL);
6727 * gtk_widget_get_display:
6728 * @widget: a #GtkWidget
6730 * Get the #GdkDisplay for the toplevel window associated with
6731 * this widget. This function can only be called after the widget
6732 * has been added to a widget hierarchy with a #GtkWindow at the top.
6734 * In general, you should only create display specific
6735 * resources when a widget has been realized, and you should
6736 * free those resources when the widget is unrealized.
6738 * Return value: the #GdkDisplay for the toplevel for this widget.
6743 gtk_widget_get_display (GtkWidget *widget)
6745 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6747 return gdk_screen_get_display (gtk_widget_get_screen (widget));
6751 * gtk_widget_get_root_window:
6752 * @widget: a #GtkWidget
6754 * Get the root window where this widget is located. This function can
6755 * only be called after the widget has been added to a widget
6756 * heirarchy with #GtkWindow at the top.
6758 * The root window is useful for such purposes as creating a popup
6759 * #GdkWindow associated with the window. In general, you should only
6760 * create display specific resources when a widget has been realized,
6761 * and you should free those resources when the widget is unrealized.
6763 * Return value: the #GdkWindow root window for the toplevel for this widget.
6768 gtk_widget_get_root_window (GtkWidget *widget)
6770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6772 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
6776 * gtk_widget_get_parent_window:
6777 * @widget: a #GtkWidget.
6778 * @returns: the parent window of @widget.
6780 * Gets @widget's parent window.
6783 gtk_widget_get_parent_window (GtkWidget *widget)
6785 GdkWindow *parent_window;
6787 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6789 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
6791 return (parent_window != NULL) ? parent_window :
6792 (widget->parent != NULL) ? widget->parent->window : NULL;
6796 * gtk_widget_child_focus:
6797 * @widget: a #GtkWidget
6798 * @direction: direction of focus movement
6800 * This function is used by custom widget implementations; if you're
6801 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
6802 * to a particular widget, and gtk_container_set_focus_chain() to
6803 * change the focus tab order. So you may want to investigate those
6804 * functions instead.
6806 * gtk_widget_child_focus() is called by containers as the user moves
6807 * around the window using keyboard shortcuts. @direction indicates
6808 * what kind of motion is taking place (up, down, left, right, tab
6809 * forward, tab backward). gtk_widget_child_focus() emits the
6810 * #GtkWidget::focus" signal; widgets override the default handler
6811 * for this signal in order to implement appropriate focus behavior.
6813 * The default ::focus handler for a widget should return %TRUE if
6814 * moving in @direction left the focus on a focusable location inside
6815 * that widget, and %FALSE if moving in @direction moved the focus
6816 * outside the widget. If returning %TRUE, widgets normally
6817 * call gtk_widget_grab_focus() to place the focus accordingly;
6818 * if returning %FALSE, they don't modify the current focus location.
6820 * This function replaces gtk_container_focus() from GTK+ 1.2.
6821 * It was necessary to check that the child was visible, sensitive,
6822 * and focusable before calling gtk_container_focus().
6823 * gtk_widget_child_focus() returns %FALSE if the widget is not
6824 * currently in a focusable state, so there's no need for those checks.
6826 * Return value: %TRUE if focus ended up inside @widget
6829 gtk_widget_child_focus (GtkWidget *widget,
6830 GtkDirectionType direction)
6832 gboolean return_val;
6834 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6836 if (!GTK_WIDGET_VISIBLE (widget) ||
6837 !GTK_WIDGET_IS_SENSITIVE (widget))
6840 /* child widgets must set CAN_FOCUS, containers
6841 * don't have to though.
6843 if (!GTK_IS_CONTAINER (widget) &&
6844 !GTK_WIDGET_CAN_FOCUS (widget))
6847 g_signal_emit (widget,
6848 widget_signals[FOCUS],
6850 direction, &return_val);
6856 * gtk_widget_keynav_failed:
6857 * @widget: a #GtkWidget
6858 * @direction: direction of focus movement
6860 * This function should be called whenever keyboard navigation within
6861 * a single widget hits a boundary. The function emits the
6862 * #GtkWidget::keynav-failed signal on the widget and its return
6863 * value should be interpreted in a way similar to the return value of
6864 * gtk_widget_child_focus():
6866 * When %TRUE is returned, stay in the widget, the failed keyboard
6867 * navigation is Ok and/or there is nowhere we can/should move the
6870 * When %FALSE is returned, the caller should continue with keyboard
6871 * navigation outside the widget, e.g. by calling
6872 * gtk_widget_child_focus() on the widget's toplevel.
6874 * The default ::keynav-failed handler returns %TRUE for
6875 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
6876 * values of #GtkDirectionType, it looks at the
6877 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
6878 * if the setting is %TRUE. This way the entire user interface
6879 * becomes cursor-navigatable on input devices such as mobile phones
6880 * which only have cursor keys but no tab key.
6882 * Whenever the default handler returns %TRUE, it also calls
6883 * gtk_widget_error_bell() to notify the user of the failed keyboard
6886 * A use case for providing an own implementation of ::keynav-failed
6887 * (either by connecting to it or by overriding it) would be a row of
6888 * #GtkEntry widgets where the user should be able to navigate the
6889 * entire row with the cursor keys, as e.g. known from user interfaces
6890 * that require entering license keys.
6892 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
6893 * if the emitting widget should try to handle the keyboard
6894 * navigation attempt in its parent container(s).
6899 gtk_widget_keynav_failed (GtkWidget *widget,
6900 GtkDirectionType direction)
6902 gboolean return_val;
6904 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6906 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
6907 direction, &return_val);
6913 * gtk_widget_error_bell:
6914 * @widget: a #GtkWidget
6916 * Notifies the user about an input-related error on this widget.
6917 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
6918 * gdk_window_beep(), otherwise it does nothing.
6920 * Note that the effect of gdk_window_beep() can be configured in many
6921 * ways, depending on the windowing backend and the desktop environment
6922 * or window manager that is used.
6927 gtk_widget_error_bell (GtkWidget *widget)
6931 g_return_if_fail (GTK_IS_WIDGET (widget));
6933 g_object_get (gtk_widget_get_settings (widget),
6934 "gtk-error-bell", &beep,
6937 if (beep && widget->window)
6938 gdk_window_beep (widget->window);
6942 * gtk_widget_set_uposition:
6943 * @widget: a #GtkWidget
6944 * @x: x position; -1 to unset x; -2 to leave x unchanged
6945 * @y: y position; -1 to unset y; -2 to leave y unchanged
6948 * Sets the position of a widget. The funny "u" in the name comes from
6949 * the "user position" hint specified by the X Window System, and
6950 * exists for legacy reasons. This function doesn't work if a widget
6951 * is inside a container; it's only really useful on #GtkWindow.
6953 * Don't use this function to center dialogs over the main application
6954 * window; most window managers will do the centering on your behalf
6955 * if you call gtk_window_set_transient_for(), and it's really not
6956 * possible to get the centering to work correctly in all cases from
6957 * application code. But if you insist, use gtk_window_set_position()
6958 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
6961 * Note that although @x and @y can be individually unset, the position
6962 * is not honoured unless both @x and @y are set.
6965 gtk_widget_set_uposition (GtkWidget *widget,
6969 /* FIXME this function is the only place that aux_info->x and
6970 * aux_info->y are even used I believe, and this function is
6971 * deprecated. Should be cleaned up.
6973 * (Actually, size_allocate uses them) -Yosh
6976 GtkWidgetAuxInfo *aux_info;
6978 g_return_if_fail (GTK_IS_WIDGET (widget));
6980 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
6985 aux_info->x_set = FALSE;
6988 aux_info->x_set = TRUE;
6996 aux_info->y_set = FALSE;
6999 aux_info->y_set = TRUE;
7004 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
7005 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
7007 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
7008 gtk_widget_size_allocate (widget, &widget->allocation);
7012 gtk_widget_set_usize_internal (GtkWidget *widget,
7016 GtkWidgetAuxInfo *aux_info;
7017 gboolean changed = FALSE;
7019 g_object_freeze_notify (G_OBJECT (widget));
7021 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
7023 if (width > -2 && aux_info->width != width)
7025 g_object_notify (G_OBJECT (widget), "width-request");
7026 aux_info->width = width;
7029 if (height > -2 && aux_info->height != height)
7031 g_object_notify (G_OBJECT (widget), "height-request");
7032 aux_info->height = height;
7036 if (GTK_WIDGET_VISIBLE (widget) && changed)
7037 gtk_widget_queue_resize (widget);
7039 g_object_thaw_notify (G_OBJECT (widget));
7043 * gtk_widget_set_usize:
7044 * @widget: a #GtkWidget
7045 * @width: minimum width, or -1 to unset
7046 * @height: minimum height, or -1 to unset
7048 * Sets the minimum size of a widget; that is, the widget's size
7049 * request will be @width by @height. You can use this function to
7050 * force a widget to be either larger or smaller than it is. The
7051 * strange "usize" name dates from the early days of GTK+, and derives
7052 * from X Window System terminology. In many cases,
7053 * gtk_window_set_default_size() is a better choice for toplevel
7054 * windows than this function; setting the default size will still
7055 * allow users to shrink the window. Setting the usize will force them
7056 * to leave the window at least as large as the usize. When dealing
7057 * with window sizes, gtk_window_set_geometry_hints() can be a useful
7060 * Note the inherent danger of setting any fixed size - themes,
7061 * translations into other languages, different fonts, and user action
7062 * can all change the appropriate size for a given widget. So, it's
7063 * basically impossible to hardcode a size that will always be
7066 * Deprecated: 2.2: Use gtk_widget_set_size_request() instead.
7069 gtk_widget_set_usize (GtkWidget *widget,
7073 g_return_if_fail (GTK_IS_WIDGET (widget));
7075 gtk_widget_set_usize_internal (widget, width, height);
7079 * gtk_widget_set_size_request:
7080 * @widget: a #GtkWidget
7081 * @width: width @widget should request, or -1 to unset
7082 * @height: height @widget should request, or -1 to unset
7084 * Sets the minimum size of a widget; that is, the widget's size
7085 * request will be @width by @height. You can use this function to
7086 * force a widget to be either larger or smaller than it normally
7089 * In most cases, gtk_window_set_default_size() is a better choice for
7090 * toplevel windows than this function; setting the default size will
7091 * still allow users to shrink the window. Setting the size request
7092 * will force them to leave the window at least as large as the size
7093 * request. When dealing with window sizes,
7094 * gtk_window_set_geometry_hints() can be a useful function as well.
7096 * Note the inherent danger of setting any fixed size - themes,
7097 * translations into other languages, different fonts, and user action
7098 * can all change the appropriate size for a given widget. So, it's
7099 * basically impossible to hardcode a size that will always be
7102 * The size request of a widget is the smallest size a widget can
7103 * accept while still functioning well and drawing itself correctly.
7104 * However in some strange cases a widget may be allocated less than
7105 * its requested size, and in many cases a widget may be allocated more
7106 * space than it requested.
7108 * If the size request in a given direction is -1 (unset), then
7109 * the "natural" size request of the widget will be used instead.
7111 * Widgets can't actually be allocated a size less than 1 by 1, but
7112 * you can pass 0,0 to this function to mean "as small as possible."
7115 gtk_widget_set_size_request (GtkWidget *widget,
7119 g_return_if_fail (GTK_IS_WIDGET (widget));
7120 g_return_if_fail (width >= -1);
7121 g_return_if_fail (height >= -1);
7128 gtk_widget_set_usize_internal (widget, width, height);
7133 * gtk_widget_get_size_request:
7134 * @widget: a #GtkWidget
7135 * @width: return location for width, or %NULL
7136 * @height: return location for height, or %NULL
7138 * Gets the size request that was explicitly set for the widget using
7139 * gtk_widget_set_size_request(). A value of -1 stored in @width or
7140 * @height indicates that that dimension has not been set explicitly
7141 * and the natural requisition of the widget will be used intead. See
7142 * gtk_widget_set_size_request(). To get the size a widget will
7143 * actually use, call gtk_widget_size_request() instead of
7147 gtk_widget_get_size_request (GtkWidget *widget,
7151 GtkWidgetAuxInfo *aux_info;
7153 g_return_if_fail (GTK_IS_WIDGET (widget));
7155 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
7158 *width = aux_info ? aux_info->width : -1;
7161 *height = aux_info ? aux_info->height : -1;
7165 * gtk_widget_set_events:
7166 * @widget: a #GtkWidget
7167 * @events: event mask
7169 * Sets the event mask (see #GdkEventMask) for a widget. The event
7170 * mask determines which events a widget will receive. Keep in mind
7171 * that different widgets have different default event masks, and by
7172 * changing the event mask you may disrupt a widget's functionality,
7173 * so be careful. This function must be called while a widget is
7174 * unrealized. Consider gtk_widget_add_events() for widgets that are
7175 * already realized, or if you want to preserve the existing event
7176 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
7177 * to get events on those widgets, place them inside a #GtkEventBox
7178 * and receive events on the event box.
7181 gtk_widget_set_events (GtkWidget *widget,
7184 g_return_if_fail (GTK_IS_WIDGET (widget));
7185 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7187 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7188 GINT_TO_POINTER (events));
7189 g_object_notify (G_OBJECT (widget), "events");
7193 gtk_widget_add_events_internal (GtkWidget *widget,
7199 for (l = window_list; l != NULL; l = l->next)
7201 GdkWindow *window = l->data;
7204 gdk_window_get_user_data (window, &user_data);
7205 if (user_data == widget)
7209 gdk_window_set_events (window, gdk_window_get_events (window) | events);
7211 children = gdk_window_get_children (window);
7212 gtk_widget_add_events_internal (widget, events, children);
7213 g_list_free (children);
7219 * gtk_widget_add_events:
7220 * @widget: a #GtkWidget
7221 * @events: an event mask, see #GdkEventMask
7223 * Adds the events in the bitfield @events to the event mask for
7224 * @widget. See gtk_widget_set_events() for details.
7227 gtk_widget_add_events (GtkWidget *widget,
7232 g_return_if_fail (GTK_IS_WIDGET (widget));
7234 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7235 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
7236 GINT_TO_POINTER (old_events | events));
7238 if (GTK_WIDGET_REALIZED (widget))
7242 if (GTK_WIDGET_NO_WINDOW (widget))
7243 window_list = gdk_window_get_children (widget->window);
7245 window_list = g_list_prepend (NULL, widget->window);
7247 gtk_widget_add_events_internal (widget, events, window_list);
7249 g_list_free (window_list);
7252 g_object_notify (G_OBJECT (widget), "events");
7256 * gtk_widget_set_extension_events:
7257 * @widget: a #GtkWidget
7258 * @mode: bitfield of extension events to receive
7260 * Sets the extension events mask to @mode. See #GdkExtensionMode
7261 * and gdk_input_set_extension_events().
7264 gtk_widget_set_extension_events (GtkWidget *widget,
7265 GdkExtensionMode mode)
7267 g_return_if_fail (GTK_IS_WIDGET (widget));
7269 if (GTK_WIDGET_REALIZED (widget))
7270 gtk_widget_set_extension_events_internal (widget, mode, NULL);
7272 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
7273 GINT_TO_POINTER (mode));
7274 g_object_notify (G_OBJECT (widget), "extension-events");
7278 * gtk_widget_get_toplevel:
7279 * @widget: a #GtkWidget
7281 * This function returns the topmost widget in the container hierarchy
7282 * @widget is a part of. If @widget has no parent widgets, it will be
7283 * returned as the topmost widget. No reference will be added to the
7284 * returned widget; it should not be unreferenced.
7286 * Note the difference in behavior vs. gtk_widget_get_ancestor();
7287 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
7289 * %NULL if @widget wasn't inside a toplevel window, and if the
7290 * window was inside a #GtkWindow-derived widget which was in turn
7291 * inside the toplevel #GtkWindow. While the second case may
7292 * seem unlikely, it actually happens when a #GtkPlug is embedded
7293 * inside a #GtkSocket within the same application.
7295 * To reliably find the toplevel #GtkWindow, use
7296 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
7297 * is set on the result.
7299 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7300 * if (GTK_WIDGET_TOPLEVEL (toplevel))
7302 * /* Perform action on toplevel. */
7306 * Return value: the topmost ancestor of @widget, or @widget itself
7307 * if there's no ancestor.
7310 gtk_widget_get_toplevel (GtkWidget *widget)
7312 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7314 while (widget->parent)
7315 widget = widget->parent;
7321 * gtk_widget_get_ancestor:
7322 * @widget: a #GtkWidget
7323 * @widget_type: ancestor type
7325 * Gets the first ancestor of @widget with type @widget_type. For example,
7326 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
7327 * the first #GtkBox that's an ancestor of @widget. No reference will be
7328 * added to the returned widget; it should not be unreferenced. See note
7329 * about checking for a toplevel #GtkWindow in the docs for
7330 * gtk_widget_get_toplevel().
7332 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
7333 * considers @widget to be an ancestor of itself.
7335 * Return value: the ancestor widget, or %NULL if not found
7338 gtk_widget_get_ancestor (GtkWidget *widget,
7341 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7343 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
7344 widget = widget->parent;
7346 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
7353 * gtk_widget_get_colormap:
7354 * @widget: a #GtkWidget
7356 * Gets the colormap that will be used to render @widget. No reference will
7357 * be added to the returned colormap; it should not be unreferenced.
7359 * Return value: the colormap used by @widget
7362 gtk_widget_get_colormap (GtkWidget *widget)
7364 GdkColormap *colormap;
7365 GtkWidget *tmp_widget;
7367 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7371 colormap = gdk_drawable_get_colormap (widget->window);
7372 /* If window was destroyed previously, we'll get NULL here */
7377 tmp_widget = widget;
7380 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
7384 tmp_widget= tmp_widget->parent;
7387 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
7391 * gtk_widget_get_visual:
7392 * @widget: a #GtkWidget
7394 * Gets the visual that will be used to render @widget.
7396 * Return value: the visual for @widget
7399 gtk_widget_get_visual (GtkWidget *widget)
7401 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7403 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
7407 * gtk_widget_get_settings:
7408 * @widget: a #GtkWidget
7410 * Gets the settings object holding the settings (global property
7411 * settings, RC file information, etc) used for this widget.
7413 * Note that this function can only be called when the #GtkWidget
7414 * is attached to a toplevel, since the settings object is specific
7415 * to a particular #GdkScreen.
7417 * Return value: the relevant #GtkSettings object
7420 gtk_widget_get_settings (GtkWidget *widget)
7422 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7424 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
7428 * gtk_widget_set_colormap:
7429 * @widget: a #GtkWidget
7430 * @colormap: a colormap
7432 * Sets the colormap for the widget to the given value. Widget must not
7433 * have been previously realized. This probably should only be used
7434 * from an <function>init()</function> function (i.e. from the constructor
7438 gtk_widget_set_colormap (GtkWidget *widget,
7439 GdkColormap *colormap)
7441 g_return_if_fail (GTK_IS_WIDGET (widget));
7442 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
7443 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7445 g_object_ref (colormap);
7447 g_object_set_qdata_full (G_OBJECT (widget),
7454 * gtk_widget_get_events:
7455 * @widget: a #GtkWidget
7457 * Returns the event mask for the widget (a bitfield containing flags
7458 * from the #GdkEventMask enumeration). These are the events that the widget
7461 * Return value: event mask for @widget
7464 gtk_widget_get_events (GtkWidget *widget)
7466 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7468 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
7472 * gtk_widget_get_extension_events:
7473 * @widget: a #GtkWidget
7475 * Retrieves the extension events the widget will receive; see
7476 * gdk_input_set_extension_events().
7478 * Return value: extension events for @widget
7481 gtk_widget_get_extension_events (GtkWidget *widget)
7483 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7485 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
7489 * gtk_widget_get_pointer:
7490 * @widget: a #GtkWidget
7491 * @x: return location for the X coordinate, or %NULL
7492 * @y: return location for the Y coordinate, or %NULL
7494 * Obtains the location of the mouse pointer in widget coordinates.
7495 * Widget coordinates are a bit odd; for historical reasons, they are
7496 * defined as @widget->window coordinates for widgets that are not
7497 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
7498 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
7501 gtk_widget_get_pointer (GtkWidget *widget,
7505 g_return_if_fail (GTK_IS_WIDGET (widget));
7512 if (GTK_WIDGET_REALIZED (widget))
7514 gdk_window_get_pointer (widget->window, x, y, NULL);
7516 if (GTK_WIDGET_NO_WINDOW (widget))
7519 *x -= widget->allocation.x;
7521 *y -= widget->allocation.y;
7527 * gtk_widget_is_ancestor:
7528 * @widget: a #GtkWidget
7529 * @ancestor: another #GtkWidget
7531 * Determines whether @widget is somewhere inside @ancestor, possibly with
7532 * intermediate containers.
7534 * Return value: %TRUE if @ancestor contains @widget as a child,
7535 * grandchild, great grandchild, etc.
7538 gtk_widget_is_ancestor (GtkWidget *widget,
7539 GtkWidget *ancestor)
7541 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7542 g_return_val_if_fail (ancestor != NULL, FALSE);
7546 if (widget->parent == ancestor)
7548 widget = widget->parent;
7554 static GQuark quark_composite_name = 0;
7557 * gtk_widget_set_composite_name:
7558 * @widget: a #GtkWidget.
7559 * @name: the name to set
7561 * Sets a widgets composite name. The widget must be
7562 * a composite child of its parent; see gtk_widget_push_composite_child().
7565 gtk_widget_set_composite_name (GtkWidget *widget,
7568 g_return_if_fail (GTK_IS_WIDGET (widget));
7569 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
7570 g_return_if_fail (name != NULL);
7572 if (!quark_composite_name)
7573 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
7575 g_object_set_qdata_full (G_OBJECT (widget),
7576 quark_composite_name,
7582 * gtk_widget_get_composite_name:
7583 * @widget: a #GtkWidget
7585 * Obtains the composite name of a widget.
7587 * Returns: the composite name of @widget, or %NULL if @widget is not
7588 * a composite child. The string should be freed when it is no
7592 gtk_widget_get_composite_name (GtkWidget *widget)
7594 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7596 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
7597 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
7604 * gtk_widget_push_composite_child:
7606 * Makes all newly-created widgets as composite children until
7607 * the corresponding gtk_widget_pop_composite_child() call.
7609 * A composite child is a child that's an implementation detail of the
7610 * container it's inside and should not be visible to people using the
7611 * container. Composite children aren't treated differently by GTK (but
7612 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
7613 * builders might want to treat them in a different way.
7615 * Here is a simple example:
7617 * gtk_widget_push_composite_child ();
7618 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
7619 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
7620 * gtk_widget_pop_composite_child ();
7621 * gtk_widget_set_parent (scrolled_window->hscrollbar,
7622 * GTK_WIDGET (scrolled_window));
7623 * g_object_ref (scrolled_window->hscrollbar);
7627 gtk_widget_push_composite_child (void)
7629 composite_child_stack++;
7633 * gtk_widget_pop_composite_child:
7635 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
7638 gtk_widget_pop_composite_child (void)
7640 if (composite_child_stack)
7641 composite_child_stack--;
7645 * gtk_widget_push_colormap:
7646 * @cmap: a #GdkColormap
7648 * Pushes @cmap onto a global stack of colormaps; the topmost
7649 * colormap on the stack will be used to create all widgets.
7650 * Remove @cmap with gtk_widget_pop_colormap(). There's little
7651 * reason to use this function.
7654 gtk_widget_push_colormap (GdkColormap *cmap)
7656 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
7658 colormap_stack = g_slist_prepend (colormap_stack, cmap);
7662 * gtk_widget_pop_colormap:
7664 * Removes a colormap pushed with gtk_widget_push_colormap().
7667 gtk_widget_pop_colormap (void)
7670 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
7674 * gtk_widget_set_default_colormap:
7675 * @colormap: a #GdkColormap
7677 * Sets the default colormap to use when creating widgets.
7678 * gtk_widget_push_colormap() is a better function to use if
7679 * you only want to affect a few widgets, rather than all widgets.
7682 gtk_widget_set_default_colormap (GdkColormap *colormap)
7684 g_return_if_fail (GDK_IS_COLORMAP (colormap));
7686 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
7691 * gtk_widget_get_default_colormap:
7693 * Obtains the default colormap used to create widgets.
7695 * Return value: default widget colormap
7698 gtk_widget_get_default_colormap (void)
7700 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
7704 * gtk_widget_get_default_visual:
7706 * Obtains the visual of the default colormap. Not really useful;
7707 * used to be useful before gdk_colormap_get_visual() existed.
7709 * Return value: visual of the default colormap
7712 gtk_widget_get_default_visual (void)
7714 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
7718 gtk_widget_emit_direction_changed (GtkWidget *widget,
7719 GtkTextDirection old_dir)
7721 gtk_widget_update_pango_context (widget);
7723 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
7727 * gtk_widget_set_direction:
7728 * @widget: a #GtkWidget
7729 * @dir: the new direction
7731 * Sets the reading direction on a particular widget. This direction
7732 * controls the primary direction for widgets containing text,
7733 * and also the direction in which the children of a container are
7734 * packed. The ability to set the direction is present in order
7735 * so that correct localization into languages with right-to-left
7736 * reading directions can be done. Generally, applications will
7737 * let the default reading direction present, except for containers
7738 * where the containers are arranged in an order that is explicitely
7739 * visual rather than logical (such as buttons for text justification).
7741 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
7742 * set by gtk_widget_set_default_direction() will be used.
7745 gtk_widget_set_direction (GtkWidget *widget,
7746 GtkTextDirection dir)
7748 GtkTextDirection old_dir;
7750 g_return_if_fail (GTK_IS_WIDGET (widget));
7751 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
7753 old_dir = gtk_widget_get_direction (widget);
7755 if (dir == GTK_TEXT_DIR_NONE)
7756 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
7759 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
7760 if (dir == GTK_TEXT_DIR_LTR)
7761 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
7763 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
7766 if (old_dir != gtk_widget_get_direction (widget))
7767 gtk_widget_emit_direction_changed (widget, old_dir);
7771 * gtk_widget_get_direction:
7772 * @widget: a #GtkWidget
7774 * Gets the reading direction for a particular widget. See
7775 * gtk_widget_set_direction().
7777 * Return value: the reading direction for the widget.
7780 gtk_widget_get_direction (GtkWidget *widget)
7782 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
7784 if (GTK_WIDGET_DIRECTION_SET (widget))
7785 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
7787 return gtk_default_direction;
7791 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
7793 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
7795 g_object_ref (widget);
7797 if (!GTK_WIDGET_DIRECTION_SET (widget))
7798 gtk_widget_emit_direction_changed (widget, old_dir);
7800 if (GTK_IS_CONTAINER (widget))
7801 gtk_container_forall (GTK_CONTAINER (widget),
7802 gtk_widget_set_default_direction_recurse,
7805 g_object_unref (widget);
7809 * gtk_widget_set_default_direction:
7810 * @dir: the new default direction. This cannot be
7811 * %GTK_TEXT_DIR_NONE.
7813 * Sets the default reading direction for widgets where the
7814 * direction has not been explicitly set by gtk_widget_set_direction().
7817 gtk_widget_set_default_direction (GtkTextDirection dir)
7819 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
7821 if (dir != gtk_default_direction)
7823 GList *toplevels, *tmp_list;
7824 GtkTextDirection old_dir = gtk_default_direction;
7826 gtk_default_direction = dir;
7828 tmp_list = toplevels = gtk_window_list_toplevels ();
7829 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
7833 gtk_widget_set_default_direction_recurse (tmp_list->data,
7834 GUINT_TO_POINTER (old_dir));
7835 g_object_unref (tmp_list->data);
7836 tmp_list = tmp_list->next;
7839 g_list_free (toplevels);
7844 * gtk_widget_get_default_direction:
7846 * Obtains the current default reading direction. See
7847 * gtk_widget_set_default_direction().
7849 * Return value: the current default direction.
7852 gtk_widget_get_default_direction (void)
7854 return gtk_default_direction;
7858 gtk_widget_dispose (GObject *object)
7860 GtkWidget *widget = GTK_WIDGET (object);
7863 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
7864 else if (GTK_WIDGET_VISIBLE (widget))
7865 gtk_widget_hide (widget);
7867 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
7868 if (GTK_WIDGET_REALIZED (widget))
7869 gtk_widget_unrealize (widget);
7871 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
7875 gtk_widget_real_destroy (GtkObject *object)
7877 /* gtk_object_destroy() will already hold a refcount on object */
7878 GtkWidget *widget = GTK_WIDGET (object);
7880 /* wipe accelerator closures (keep order) */
7881 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
7882 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
7884 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
7885 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
7887 gtk_grab_remove (widget);
7889 g_object_unref (widget->style);
7890 widget->style = gtk_widget_get_default_style ();
7891 g_object_ref (widget->style);
7893 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
7897 gtk_widget_finalize (GObject *object)
7899 GtkWidget *widget = GTK_WIDGET (object);
7900 GtkWidgetAuxInfo *aux_info;
7901 GtkAccessible *accessible;
7903 gtk_grab_remove (widget);
7905 g_object_unref (widget->style);
7906 widget->style = NULL;
7908 g_free (widget->name);
7910 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
7912 gtk_widget_aux_info_destroy (aux_info);
7914 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
7916 g_object_unref (accessible);
7918 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
7921 /*****************************************
7922 * gtk_widget_real_map:
7927 *****************************************/
7930 gtk_widget_real_map (GtkWidget *widget)
7932 g_assert (GTK_WIDGET_REALIZED (widget));
7934 if (!GTK_WIDGET_MAPPED (widget))
7936 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
7938 if (!GTK_WIDGET_NO_WINDOW (widget))
7939 gdk_window_show (widget->window);
7943 /*****************************************
7944 * gtk_widget_real_unmap:
7949 *****************************************/
7952 gtk_widget_real_unmap (GtkWidget *widget)
7954 if (GTK_WIDGET_MAPPED (widget))
7956 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
7958 if (!GTK_WIDGET_NO_WINDOW (widget))
7959 gdk_window_hide (widget->window);
7963 /*****************************************
7964 * gtk_widget_real_realize:
7969 *****************************************/
7972 gtk_widget_real_realize (GtkWidget *widget)
7974 g_assert (GTK_WIDGET_NO_WINDOW (widget));
7976 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
7979 widget->window = gtk_widget_get_parent_window (widget);
7980 g_object_ref (widget->window);
7982 widget->style = gtk_style_attach (widget->style, widget->window);
7985 /*****************************************
7986 * gtk_widget_real_unrealize:
7991 *****************************************/
7994 gtk_widget_real_unrealize (GtkWidget *widget)
7996 if (GTK_WIDGET_MAPPED (widget))
7997 gtk_widget_real_unmap (widget);
7999 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
8001 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
8004 /* We must do unrealize child widget BEFORE container widget.
8005 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
8006 * So, unrealizing container widget bofore its children causes the problem
8007 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
8010 if (GTK_IS_CONTAINER (widget))
8011 gtk_container_forall (GTK_CONTAINER (widget),
8012 (GtkCallback) gtk_widget_unrealize,
8015 gtk_style_detach (widget->style);
8016 if (!GTK_WIDGET_NO_WINDOW (widget))
8018 gdk_window_set_user_data (widget->window, NULL);
8019 gdk_window_destroy (widget->window);
8020 widget->window = NULL;
8024 g_object_unref (widget->window);
8025 widget->window = NULL;
8028 gtk_selection_remove_all (widget);
8030 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
8034 gtk_widget_real_size_request (GtkWidget *widget,
8035 GtkRequisition *requisition)
8037 requisition->width = widget->requisition.width;
8038 requisition->height = widget->requisition.height;
8042 * _gtk_widget_peek_colormap:
8044 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
8046 * Return value: the currently pushed colormap, or %NULL if there is none.
8049 _gtk_widget_peek_colormap (void)
8052 return (GdkColormap*) colormap_stack->data;
8057 gtk_widget_propagate_state (GtkWidget *widget,
8060 guint8 old_state = GTK_WIDGET_STATE (widget);
8061 guint8 old_saved_state = GTK_WIDGET_SAVED_STATE (widget);
8063 /* don't call this function with state==GTK_STATE_INSENSITIVE,
8064 * parent_sensitive==TRUE on a sensitive widget
8068 if (data->parent_sensitive)
8069 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8071 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
8073 if (GTK_WIDGET_IS_SENSITIVE (widget))
8075 if (data->state_restoration)
8076 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
8078 GTK_WIDGET_STATE (widget) = data->state;
8082 if (!data->state_restoration)
8084 if (data->state != GTK_STATE_INSENSITIVE)
8085 GTK_WIDGET_SAVED_STATE (widget) = data->state;
8087 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
8088 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
8089 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
8092 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
8096 window = gtk_widget_get_toplevel (widget);
8097 if (window && GTK_WIDGET_TOPLEVEL (window))
8098 gtk_window_set_focus (GTK_WINDOW (window), NULL);
8101 if (old_state != GTK_WIDGET_STATE (widget) ||
8102 old_saved_state != GTK_WIDGET_SAVED_STATE (widget))
8104 g_object_ref (widget);
8106 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
8107 gtk_grab_remove (widget);
8109 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
8111 if (GTK_IS_CONTAINER (widget))
8113 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
8114 if (data->use_forall)
8115 gtk_container_forall (GTK_CONTAINER (widget),
8116 (GtkCallback) gtk_widget_propagate_state,
8119 gtk_container_foreach (GTK_CONTAINER (widget),
8120 (GtkCallback) gtk_widget_propagate_state,
8123 g_object_unref (widget);
8128 * _gtk_widget_get_aux_info:
8129 * @widget: a #GtkWidget
8130 * @create: if %TRUE, create the structure if it doesn't exist
8132 * Get the #GtkWidgetAuxInfo structure for the widget.
8134 * Return value: the #GtkAuxInfo structure for the widget, or
8135 * %NULL if @create is %FALSE and one doesn't already exist.
8138 _gtk_widget_get_aux_info (GtkWidget *widget,
8141 GtkWidgetAuxInfo *aux_info;
8143 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
8144 if (!aux_info && create)
8146 aux_info = g_slice_new (GtkWidgetAuxInfo);
8148 aux_info->width = -1;
8149 aux_info->height = -1;
8152 aux_info->x_set = FALSE;
8153 aux_info->y_set = FALSE;
8154 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
8160 /*****************************************
8161 * gtk_widget_aux_info_destroy:
8166 *****************************************/
8169 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
8171 g_slice_free (GtkWidgetAuxInfo, aux_info);
8175 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
8177 g_object_unref (info->shape_mask);
8178 g_slice_free (GtkWidgetShapeInfo, info);
8182 * gtk_widget_shape_combine_mask:
8183 * @widget: a #GtkWidget
8184 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8185 * @offset_x: X position of shape mask with respect to @window
8186 * @offset_y: Y position of shape mask with respect to @window
8188 * Sets a shape for this widget's GDK window. This allows for
8189 * transparent windows etc., see gdk_window_shape_combine_mask()
8190 * for more information.
8193 gtk_widget_shape_combine_mask (GtkWidget *widget,
8194 GdkBitmap *shape_mask,
8198 GtkWidgetShapeInfo* shape_info;
8200 g_return_if_fail (GTK_IS_WIDGET (widget));
8201 /* set_shape doesn't work on widgets without gdk window */
8202 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8206 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8209 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
8211 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
8215 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
8217 shape_info = g_slice_new (GtkWidgetShapeInfo);
8218 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
8219 (GDestroyNotify) gtk_widget_shape_info_destroy);
8221 shape_info->shape_mask = g_object_ref (shape_mask);
8222 shape_info->offset_x = offset_x;
8223 shape_info->offset_y = offset_y;
8225 /* set shape if widget has a gdk window already.
8226 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8229 gdk_window_shape_combine_mask (widget->window, shape_mask,
8230 offset_x, offset_y);
8235 * gtk_widget_input_shape_combine_mask:
8236 * @widget: a #GtkWidget
8237 * @shape_mask: shape to be added, or %NULL to remove an existing shape
8238 * @offset_x: X position of shape mask with respect to @window
8239 * @offset_y: Y position of shape mask with respect to @window
8241 * Sets an input shape for this widget's GDK window. This allows for
8242 * windows which react to mouse click in a nonrectangular region, see
8243 * gdk_window_input_shape_combine_mask() for more information.
8248 gtk_widget_input_shape_combine_mask (GtkWidget *widget,
8249 GdkBitmap *shape_mask,
8253 GtkWidgetShapeInfo* shape_info;
8255 g_return_if_fail (GTK_IS_WIDGET (widget));
8256 /* set_shape doesn't work on widgets without gdk window */
8257 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
8262 gdk_window_input_shape_combine_mask (widget->window, NULL, 0, 0);
8264 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
8268 shape_info = g_slice_new (GtkWidgetShapeInfo);
8269 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
8271 (GDestroyNotify) gtk_widget_shape_info_destroy);
8273 shape_info->shape_mask = g_object_ref (shape_mask);
8274 shape_info->offset_x = offset_x;
8275 shape_info->offset_y = offset_y;
8277 /* set shape if widget has a gdk window already.
8278 * otherwise the shape is scheduled to be set by gtk_widget_realize().
8281 gdk_window_input_shape_combine_mask (widget->window, shape_mask,
8282 offset_x, offset_y);
8288 gtk_reset_shapes_recurse (GtkWidget *widget,
8294 gdk_window_get_user_data (window, &data);
8298 gdk_window_shape_combine_mask (window, NULL, 0, 0);
8299 for (list = gdk_window_peek_children (window); list; list = list->next)
8300 gtk_reset_shapes_recurse (widget, list->data);
8304 * gtk_widget_reset_shapes:
8305 * @widget: a #GtkWidget
8307 * Recursively resets the shape on this widget and its descendants.
8310 gtk_widget_reset_shapes (GtkWidget *widget)
8312 g_return_if_fail (GTK_IS_WIDGET (widget));
8313 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
8315 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
8316 gtk_reset_shapes_recurse (widget, widget->window);
8321 * @widget: a #GtkWidget
8323 * Adds a reference to a widget. This function is exactly the same
8324 * as calling g_object_ref(), and exists mostly for historical
8325 * reasons. It can still be convenient to avoid casting a widget
8326 * to a #GObject, it saves a small amount of typing.
8328 * Return value: the widget that was referenced
8330 * Deprecated: 2.12: Use g_object_ref() instead.
8333 gtk_widget_ref (GtkWidget *widget)
8335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8337 return (GtkWidget*) g_object_ref ((GObject*) widget);
8342 * @widget: a #GtkWidget
8344 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
8346 * Deprecated: 2.12: Use g_object_unref() instead.
8349 gtk_widget_unref (GtkWidget *widget)
8351 g_return_if_fail (GTK_IS_WIDGET (widget));
8353 g_object_unref ((GObject*) widget);
8357 * gtk_widget_get_snapshot:
8358 * @widget: a #GtkWidget
8359 * @clip_rect: a #GdkRectangle or %NULL
8361 * Create a #GdkPixmap of the contents of the widget and its children.
8363 * Works even if the widget is obscured. The depth and visual of the
8364 * resulting pixmap is dependent on the widget being snapshot and likely
8365 * differs from those of a target widget displaying the pixmap.
8366 * The function gdk_pixbuf_get_from_drawable() can be used to convert
8367 * the pixmap to a visual independant representation.
8369 * The snapshot area used by this function is the @widget's allocation plus
8370 * any extra space occupied by additional windows belonging to this widget
8371 * (such as the arrows of a spin button).
8372 * Thus, the resulting snapshot pixmap is possibly larger than the allocation.
8374 * If @clip_rect is non-%NULL, the resulting pixmap is shrunken to
8375 * match the specified clip_rect. The (x,y) coordinates of @clip_rect are
8376 * interpreted widget relative. If width or height of @clip_rect are 0 or
8377 * negative, the width or height of the resulting pixmap will be shrunken
8378 * by the respective amount.
8379 * For instance a @clip_rect <literal>{ +5, +5, -10, -10 }</literal> will
8380 * chop off 5 pixels at each side of the snapshot pixmap.
8381 * If non-%NULL, @clip_rect will contain the exact widget-relative snapshot
8382 * coordinates upon return. A @clip_rect of <literal>{ -1, -1, 0, 0 }</literal>
8383 * can be used to preserve the auto-grown snapshot area and use @clip_rect
8384 * as a pure output parameter.
8386 * The returned pixmap can be %NULL, if the resulting @clip_area was empty.
8388 * Return value: #GdkPixmap snapshot of the widget
8393 gtk_widget_get_snapshot (GtkWidget *widget,
8394 GdkRectangle *clip_rect)
8396 int x, y, width, height;
8397 GdkWindow *parent_window = NULL;
8399 GList *windows = NULL, *list;
8401 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8402 if (!GTK_WIDGET_VISIBLE (widget))
8405 /* the widget (and parent_window) must be realized to be drawable */
8406 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
8407 gtk_widget_realize (widget->parent);
8408 if (!GTK_WIDGET_REALIZED (widget))
8409 gtk_widget_realize (widget);
8411 /* determine snapshot rectangle */
8412 x = widget->allocation.x;
8413 y = widget->allocation.y;
8414 width = widget->allocation.width;
8415 height = widget->allocation.height;
8417 if (widget->parent && !GTK_WIDGET_NO_WINDOW (widget))
8419 /* grow snapshot rectangle to cover all widget windows */
8420 parent_window = gtk_widget_get_parent_window (widget);
8421 for (list = gdk_window_peek_children (parent_window); list; list = list->next)
8423 GdkWindow *subwin = list->data;
8426 gdk_window_get_user_data (subwin, &windata);
8427 if (windata != widget)
8429 windows = g_list_prepend (windows, subwin);
8430 gdk_window_get_position (subwin, &wx, &wy);
8431 gdk_drawable_get_size (subwin, &ww, &wh);
8432 /* grow snapshot rectangle by extra widget sub window */
8443 if (x + width < wx + ww)
8444 width += wx + ww - (x + width);
8445 if (y + height < wy + wh)
8446 height += wy + wh - (y + height);
8449 else if (!widget->parent)
8450 x = y = 0; /* toplevel */
8452 /* at this point, (x,y,width,height) is the parent_window relative
8453 * snapshot area covering all of widget's windows.
8456 /* shrink snapshot size by clip_rectangle */
8459 GdkRectangle snap = { x, y, width, height }, clip = *clip_rect;
8460 clip.x = clip.x < 0 ? x : clip.x;
8461 clip.y = clip.y < 0 ? y : clip.y;
8462 clip.width = clip.width <= 0 ? MAX (0, width + clip.width) : clip.width;
8463 clip.height = clip.height <= 0 ? MAX (0, height + clip.height) : clip.height;
8466 /* offset clip_rect, so it's parent_window relative */
8467 if (clip_rect->x >= 0)
8468 clip.x += widget->allocation.x;
8469 if (clip_rect->y >= 0)
8470 clip.y += widget->allocation.y;
8472 if (!gdk_rectangle_intersect (&snap, &clip, &snap))
8474 g_list_free (windows);
8475 clip_rect->width = clip_rect->height = 0;
8476 return NULL; /* empty snapshot area */
8481 height = snap.height;
8484 /* render snapshot */
8485 pixmap = gdk_pixmap_new (widget->window, width, height, gdk_drawable_get_depth (widget->window));
8486 for (list = windows; list; list = list->next) /* !NO_WINDOW widgets */
8488 GdkWindow *subwin = list->data;
8490 gdk_window_get_position (subwin, &wx, &wy);
8491 gdk_window_redirect_to_drawable (subwin, pixmap, MAX (0, x - wx), MAX (0, y - wy),
8492 MAX (0, wx - x), MAX (0, wy - y), width, height);
8493 gdk_window_invalidate_rect (subwin, NULL, TRUE);
8495 if (!windows) /* NO_WINDOW || toplevel => parent_window == NULL || parent_window == widget->window */
8497 gdk_window_redirect_to_drawable (widget->window, pixmap, x, y, 0, 0, width, height);
8498 gdk_window_invalidate_rect (widget->window, NULL, TRUE);
8500 gtk_widget_queue_draw (widget);
8502 gdk_window_process_updates (parent_window, TRUE);
8503 for (list = windows; list; list = list->next)
8504 gdk_window_process_updates (list->data, TRUE);
8505 gdk_window_process_updates (widget->window, TRUE);
8506 for (list = windows; list; list = list->next)
8507 gdk_window_remove_redirection (list->data);
8508 if (!windows) /* NO_WINDOW || toplevel */
8509 gdk_window_remove_redirection (widget->window);
8510 g_list_free (windows);
8512 /* return pixmap and snapshot rectangle coordinates */
8517 clip_rect->width = width;
8518 clip_rect->height = height;
8521 /* offset clip_rect from parent_window so it's widget relative */
8522 clip_rect->x -= widget->allocation.x;
8523 clip_rect->y -= widget->allocation.y;
8526 g_printerr ("gtk_widget_get_snapshot: %s (%d,%d, %dx%d)\n",
8527 G_OBJECT_TYPE_NAME (widget),
8528 clip_rect->x, clip_rect->y, clip_rect->width, clip_rect->height);
8537 * gtk_widget_class_install_style_property_parser:
8538 * @klass: a #GtkWidgetClass
8539 * @pspec: the #GParamSpec for the style property
8540 * @parser: the parser for the style property
8542 * Installs a style property on a widget class.
8545 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
8547 GtkRcPropertyParser parser)
8549 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8550 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8551 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
8552 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
8554 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
8556 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
8557 G_OBJECT_CLASS_NAME (klass),
8562 g_param_spec_ref_sink (pspec);
8563 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
8564 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
8568 * gtk_widget_class_install_style_property:
8569 * @klass: a #GtkWidgetClass
8570 * @pspec: the #GParamSpec for the property
8572 * Installs a style property on a widget class. The parser for the
8573 * style property is determined by the value type of @pspec.
8576 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
8579 GtkRcPropertyParser parser;
8581 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
8582 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
8584 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
8586 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
8590 * gtk_widget_class_find_style_property:
8591 * @klass: a #GtkWidgetClass
8592 * @property_name: the name of the style property to find
8593 * @returns: the #GParamSpec of the style property or %NULL if @class has no
8594 * style property with that name.
8596 * Finds a style property of a widget class by name.
8601 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
8602 const gchar *property_name)
8604 g_return_val_if_fail (property_name != NULL, NULL);
8606 return g_param_spec_pool_lookup (style_property_spec_pool,
8608 G_OBJECT_CLASS_TYPE (klass),
8613 * gtk_widget_class_list_style_properties:
8614 * @klass: a #GtkWidgetClass
8615 * @n_properties: location to return the number of style properties found
8616 * @returns: an newly allocated array of #GParamSpec*. The array must
8617 * be freed with g_free().
8619 * Returns all style properties of a widget class.
8624 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
8625 guint *n_properties)
8627 GParamSpec **pspecs;
8630 pspecs = g_param_spec_pool_list (style_property_spec_pool,
8631 G_OBJECT_CLASS_TYPE (klass),
8640 * gtk_widget_style_get_property:
8641 * @widget: a #GtkWidget
8642 * @property_name: the name of a style property
8643 * @value: location to return the property value
8645 * Gets the value of a style property of @widget.
8648 gtk_widget_style_get_property (GtkWidget *widget,
8649 const gchar *property_name,
8654 g_return_if_fail (GTK_IS_WIDGET (widget));
8655 g_return_if_fail (property_name != NULL);
8656 g_return_if_fail (G_IS_VALUE (value));
8658 g_object_ref (widget);
8659 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8661 G_OBJECT_TYPE (widget),
8664 g_warning ("%s: widget class `%s' has no property named `%s'",
8666 G_OBJECT_TYPE_NAME (widget),
8670 const GValue *peek_value;
8672 peek_value = _gtk_style_peek_property_value (widget->style,
8673 G_OBJECT_TYPE (widget),
8675 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8677 /* auto-conversion of the caller's value type
8679 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
8680 g_value_copy (peek_value, value);
8681 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
8682 g_value_transform (peek_value, value);
8684 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
8686 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
8687 G_VALUE_TYPE_NAME (value));
8689 g_object_unref (widget);
8693 * gtk_widget_style_get_valist:
8694 * @widget: a #GtkWidget
8695 * @first_property_name: the name of the first property to get
8696 * @var_args: a <type>va_list</type> of pairs of property names and
8697 * locations to return the property values, starting with the location
8698 * for @first_property_name.
8700 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
8704 gtk_widget_style_get_valist (GtkWidget *widget,
8705 const gchar *first_property_name,
8710 g_return_if_fail (GTK_IS_WIDGET (widget));
8712 g_object_ref (widget);
8714 name = first_property_name;
8717 const GValue *peek_value;
8721 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
8723 G_OBJECT_TYPE (widget),
8727 g_warning ("%s: widget class `%s' has no property named `%s'",
8729 G_OBJECT_TYPE_NAME (widget),
8733 /* style pspecs are always readable so we can spare that check here */
8735 peek_value = _gtk_style_peek_property_value (widget->style,
8736 G_OBJECT_TYPE (widget),
8738 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
8739 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
8742 g_warning ("%s: %s", G_STRLOC, error);
8747 name = va_arg (var_args, gchar*);
8750 g_object_unref (widget);
8754 * gtk_widget_style_get:
8755 * @widget: a #GtkWidget
8756 * @first_property_name: the name of the first property to get
8757 * @Varargs: pairs of property names and locations to
8758 * return the property values, starting with the location for
8759 * @first_property_name, terminated by %NULL.
8761 * Gets the values of a multiple style properties of @widget.
8764 gtk_widget_style_get (GtkWidget *widget,
8765 const gchar *first_property_name,
8770 g_return_if_fail (GTK_IS_WIDGET (widget));
8772 va_start (var_args, first_property_name);
8773 gtk_widget_style_get_valist (widget, first_property_name, var_args);
8779 * @widget: a #GtkWidget
8780 * @path_length: location to store length of the path, or %NULL
8781 * @path: location to store allocated path string, or %NULL
8782 * @path_reversed: location to store allocated reverse path string, or %NULL
8784 * Obtains the full path to @widget. The path is simply the name of a
8785 * widget and all its parents in the container hierarchy, separated by
8786 * periods. The name of a widget comes from
8787 * gtk_widget_get_name(). Paths are used to apply styles to a widget
8788 * in gtkrc configuration files. Widget names are the type of the
8789 * widget by default (e.g. "GtkButton") or can be set to an
8790 * application-specific value with gtk_widget_set_name(). By setting
8791 * the name of a widget, you allow users or theme authors to apply
8792 * styles to that specific widget in their gtkrc
8793 * file. @path_reversed_p fills in the path in reverse order,
8794 * i.e. starting with @widget's name instead of starting with the name
8795 * of @widget's outermost ancestor.
8798 gtk_widget_path (GtkWidget *widget,
8801 gchar **path_reversed)
8803 static gchar *rev_path = NULL;
8804 static guint tmp_path_len = 0;
8807 g_return_if_fail (GTK_IS_WIDGET (widget));
8812 const gchar *string;
8817 string = gtk_widget_get_name (widget);
8818 l = strlen (string);
8819 while (tmp_path_len <= len + l + 1)
8821 tmp_path_len += INIT_PATH_SIZE;
8822 rev_path = g_realloc (rev_path, tmp_path_len);
8830 widget = widget->parent;
8833 rev_path[len++] = '.';
8835 rev_path[len++] = 0;
8840 *path_length = len - 1;
8842 *path_reversed = g_strdup (rev_path);
8845 *path = g_strdup (rev_path);
8846 g_strreverse (*path);
8851 * gtk_widget_class_path:
8852 * @widget: a #GtkWidget
8853 * @path_length: location to store the length of the class path, or %NULL
8854 * @path: location to store the class path as an allocated string, or %NULL
8855 * @path_reversed: location to store the reverse class path as an allocated
8858 * Same as gtk_widget_path(), but always uses the name of a widget's type,
8859 * never uses a custom name set with gtk_widget_set_name().
8863 gtk_widget_class_path (GtkWidget *widget,
8866 gchar **path_reversed)
8868 static gchar *rev_path = NULL;
8869 static guint tmp_path_len = 0;
8872 g_return_if_fail (GTK_IS_WIDGET (widget));
8877 const gchar *string;
8882 string = g_type_name (GTK_WIDGET_TYPE (widget));
8883 l = strlen (string);
8884 while (tmp_path_len <= len + l + 1)
8886 tmp_path_len += INIT_PATH_SIZE;
8887 rev_path = g_realloc (rev_path, tmp_path_len);
8895 widget = widget->parent;
8898 rev_path[len++] = '.';
8900 rev_path[len++] = 0;
8905 *path_length = len - 1;
8907 *path_reversed = g_strdup (rev_path);
8910 *path = g_strdup (rev_path);
8911 g_strreverse (*path);
8916 * gtk_requisition_copy:
8917 * @requisition: a #GtkRequisition
8919 * Copies a #GtkRequisition.
8921 * Returns: a copy of @requisition
8924 gtk_requisition_copy (const GtkRequisition *requisition)
8926 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
8930 * gtk_requisition_free:
8931 * @requisition: a #GtkRequisition
8933 * Frees a #GtkRequisition.
8936 gtk_requisition_free (GtkRequisition *requisition)
8938 g_free (requisition);
8942 gtk_requisition_get_type (void)
8944 static GType our_type = 0;
8947 our_type = g_boxed_type_register_static (I_("GtkRequisition"),
8948 (GBoxedCopyFunc) gtk_requisition_copy,
8949 (GBoxedFreeFunc) gtk_requisition_free);
8955 * gtk_widget_get_accessible:
8956 * @widget: a #GtkWidget
8958 * Returns the accessible object that describes the widget to an
8959 * assistive technology.
8961 * If no accessibility library is loaded (i.e. no ATK implementation library is
8962 * loaded via <envar>GTK_MODULES</envar> or via another application library,
8963 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
8964 * if no class-specific #AtkObject implementation is available for the widget
8965 * instance in question, it will inherit an #AtkObject implementation from the
8966 * first ancestor class for which such an implementation is defined.
8968 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
8969 * library contains more information about accessible objects and their uses.
8971 * Returns: the #AtkObject associated with @widget
8974 gtk_widget_get_accessible (GtkWidget *widget)
8976 GtkWidgetClass *klass;
8978 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8980 klass = GTK_WIDGET_GET_CLASS (widget);
8982 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
8984 return klass->get_accessible (widget);
8988 gtk_widget_real_get_accessible (GtkWidget *widget)
8990 AtkObject* accessible;
8992 accessible = g_object_get_qdata (G_OBJECT (widget),
8993 quark_accessible_object);
8996 AtkObjectFactory *factory;
8997 AtkRegistry *default_registry;
8999 default_registry = atk_get_default_registry ();
9000 factory = atk_registry_get_factory (default_registry,
9001 G_TYPE_FROM_INSTANCE (widget));
9003 atk_object_factory_create_accessible (factory,
9005 g_object_set_qdata (G_OBJECT (widget),
9006 quark_accessible_object,
9013 * Initialize a AtkImplementorIface instance's virtual pointers as
9014 * appropriate to this implementor's class (GtkWidget).
9017 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
9019 iface->ref_accessible = gtk_widget_ref_accessible;
9023 gtk_widget_ref_accessible (AtkImplementor *implementor)
9025 AtkObject *accessible;
9027 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
9029 g_object_ref (accessible);
9034 * GtkBuildable implementation
9036 static GQuark quark_builder_has_default = 0;
9037 static GQuark quark_builder_has_focus = 0;
9038 static GQuark quark_builder_atk_relations = 0;
9041 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
9043 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
9044 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
9045 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
9047 iface->set_name = gtk_widget_buildable_set_name;
9048 iface->get_name = gtk_widget_buildable_get_name;
9049 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
9050 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
9051 iface->parser_finished = gtk_widget_buildable_parser_finished;
9052 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
9053 iface->custom_finished = gtk_widget_buildable_custom_finished;
9057 gtk_widget_buildable_set_name (GtkBuildable *buildable,
9060 gtk_widget_set_name (GTK_WIDGET (buildable), name);
9063 static const gchar *
9064 gtk_widget_buildable_get_name (GtkBuildable *buildable)
9066 return gtk_widget_get_name (GTK_WIDGET (buildable));
9070 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
9071 GtkBuilder *builder,
9072 const gchar *childname)
9074 if (strcmp (childname, "accessible") == 0)
9075 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
9081 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
9082 GtkBuilder *builder,
9084 const GValue *value)
9086 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
9087 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
9088 GINT_TO_POINTER (TRUE));
9089 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
9090 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
9091 GINT_TO_POINTER (TRUE));
9093 g_object_set_property (G_OBJECT (buildable), name, value);
9107 free_action (AtkActionData *data, gpointer user_data)
9109 g_free (data->action_name);
9110 g_free (data->description);
9111 g_slice_free (AtkActionData, data);
9115 free_relation (AtkRelationData *data, gpointer user_data)
9117 g_free (data->target);
9118 g_free (data->type);
9119 g_slice_free (AtkRelationData, data);
9123 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
9124 GtkBuilder *builder)
9126 GSList *atk_relations;
9128 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
9129 gtk_widget_grab_default (GTK_WIDGET (buildable));
9130 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
9131 gtk_widget_grab_focus (GTK_WIDGET (buildable));
9133 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
9134 quark_builder_atk_relations);
9137 AtkObject *accessible;
9138 AtkRelationSet *relation_set;
9141 AtkRelationType relation_type;
9142 AtkObject *target_accessible;
9144 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9145 relation_set = atk_object_ref_relation_set (accessible);
9147 for (l = atk_relations; l; l = l->next)
9149 AtkRelationData *relation = (AtkRelationData*)l->data;
9151 target = gtk_builder_get_object (builder, relation->target);
9154 g_warning ("Target object %s in <relation> does not exist",
9158 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
9159 g_assert (target_accessible != NULL);
9161 relation_type = atk_relation_type_for_name (relation->type);
9162 if (relation_type == ATK_RELATION_NULL)
9164 g_warning ("<relation> type %s not found",
9168 atk_relation_set_add_relation_by_type (relation_set, relation_type,
9171 g_object_unref (relation_set);
9173 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
9174 g_slist_free (atk_relations);
9175 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9184 } AccessibilitySubParserData;
9187 accessibility_start_element (GMarkupParseContext *context,
9188 const gchar *element_name,
9189 const gchar **names,
9190 const gchar **values,
9194 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
9196 gint line_number, char_number;
9198 if (strcmp (element_name, "relation") == 0)
9200 gchar *target = NULL;
9202 AtkRelationData *relation;
9204 for (i = 0; names[i]; i++)
9206 if (strcmp (names[i], "target") == 0)
9207 target = g_strdup (values[i]);
9208 else if (strcmp (names[i], "type") == 0)
9209 type = g_strdup (values[i]);
9212 g_markup_parse_context_get_position (context,
9217 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9218 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9220 line_number, char_number, names[i], "relation");
9227 if (!target || !type)
9229 g_markup_parse_context_get_position (context,
9234 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9235 "%s:%d:%d <%s> requires attribute \"%s\"",
9237 line_number, char_number, "relation",
9238 type ? "target" : "type");
9244 relation = g_slice_new (AtkRelationData);
9245 relation->target = target;
9246 relation->type = type;
9248 data->relations = g_slist_prepend (data->relations, relation);
9250 else if (strcmp (element_name, "action") == 0)
9252 gchar *action_name = NULL;
9253 gchar *description = NULL;
9254 AtkActionData *action;
9256 for (i = 0; names[i]; i++)
9258 if (strcmp (names[i], "action_name") == 0)
9259 action_name = g_strdup (values[i]);
9260 else if (strcmp (names[i], "description") == 0)
9261 description = g_strdup (values[i]);
9264 g_markup_parse_context_get_position (context,
9269 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
9270 "%s:%d:%d '%s' is not a valid attribute of <%s>",
9272 line_number, char_number, names[i], "action");
9273 g_free (action_name);
9274 g_free (description);
9279 if (!action_name || !description)
9281 g_markup_parse_context_get_position (context,
9286 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
9287 "%s:%d:%d <%s> requires attribute \"%s\"",
9289 line_number, char_number, "action",
9290 description ? "action_name" : "description");
9291 g_free (action_name);
9292 g_free (description);
9296 action = g_slice_new (AtkActionData);
9297 action->action_name = action_name;
9298 action->description = description;
9300 data->actions = g_slist_prepend (data->actions, action);
9302 else if (strcmp (element_name, "accessibility") == 0)
9305 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
9308 static const GMarkupParser accessibility_parser =
9310 accessibility_start_element,
9318 } AccelGroupParserData;
9321 accel_group_start_element (GMarkupParseContext *context,
9322 const gchar *element_name,
9323 const gchar **names,
9324 const gchar **values,
9330 guint modifiers = 0;
9331 gchar *signal = NULL;
9332 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
9334 for (i = 0; names[i]; i++)
9336 if (strcmp (names[i], "key") == 0)
9337 key = gdk_keyval_from_name (values[i]);
9338 else if (strcmp (names[i], "modifiers") == 0)
9340 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
9346 else if (strcmp (names[i], "signal") == 0)
9347 signal = g_strdup (values[i]);
9350 if (key == 0 || signal == NULL)
9352 g_warning ("<accelerator> requires key and signal attributes");
9355 parser_data->key = key;
9356 parser_data->modifiers = modifiers;
9357 parser_data->signal = signal;
9360 static const GMarkupParser accel_group_parser =
9362 accel_group_start_element,
9366 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
9367 GtkBuilder *builder,
9369 const gchar *tagname,
9370 GMarkupParser *parser,
9373 g_assert (buildable);
9375 if (strcmp (tagname, "accelerator") == 0)
9377 AccelGroupParserData *parser_data;
9379 parser_data = g_slice_new0 (AccelGroupParserData);
9380 parser_data->object = g_object_ref (buildable);
9381 *parser = accel_group_parser;
9382 *data = parser_data;
9385 if (strcmp (tagname, "accessibility") == 0)
9387 AccessibilitySubParserData *parser_data;
9389 parser_data = g_slice_new0 (AccessibilitySubParserData);
9390 *parser = accessibility_parser;
9391 *data = parser_data;
9398 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
9399 GtkBuilder *builder,
9401 const gchar *tagname,
9404 AccelGroupParserData *accel_data;
9405 AccessibilitySubParserData *a11y_data;
9406 GtkWidget *toplevel;
9407 GSList *accel_groups;
9408 GtkAccelGroup *accel_group;
9410 if (strcmp (tagname, "accelerator") == 0)
9412 accel_data = (AccelGroupParserData*)user_data;
9413 g_assert (accel_data->object);
9415 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
9416 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
9417 if (g_slist_length (accel_groups) == 0)
9419 accel_group = gtk_accel_group_new ();
9420 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
9424 g_assert (g_slist_length (accel_groups) == 1);
9425 accel_group = g_slist_nth_data (accel_groups, 0);
9427 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
9431 accel_data->modifiers,
9433 g_object_unref (accel_data->object);
9434 g_free (accel_data->signal);
9435 g_slice_free (AccelGroupParserData, accel_data);
9437 else if (strcmp (tagname, "accessibility") == 0)
9439 a11y_data = (AccessibilitySubParserData*)user_data;
9441 if (a11y_data->actions)
9443 AtkObject *accessible;
9448 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
9450 action = ATK_ACTION (accessible);
9451 n_actions = atk_action_get_n_actions (action);
9453 for (l = a11y_data->actions; l; l = l->next)
9455 AtkActionData *action_data = (AtkActionData*)l->data;
9457 for (i = 0; i < n_actions; i++)
9458 if (strcmp (atk_action_get_name (action, i),
9459 action_data->action_name) == 0)
9463 atk_action_set_description (action, i,
9464 action_data->description);
9467 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
9468 g_slist_free (a11y_data->actions);
9471 if (a11y_data->relations)
9472 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
9473 a11y_data->relations);
9475 g_slice_free (AccessibilitySubParserData, a11y_data);
9482 * gtk_widget_get_clipboard:
9483 * @widget: a #GtkWidget
9484 * @selection: a #GdkAtom which identifies the clipboard
9485 * to use. %GDK_SELECTION_CLIPBOARD gives the
9486 * default clipboard. Another common value
9487 * is %GDK_SELECTION_PRIMARY, which gives
9488 * the primary X selection.
9490 * Returns the clipboard object for the given selection to
9491 * be used with @widget. @widget must have a #GdkDisplay
9492 * associated with it, so must be attached to a toplevel
9495 * Return value: the appropriate clipboard object. If no
9496 * clipboard already exists, a new one will
9497 * be created. Once a clipboard object has
9498 * been created, it is persistent for all time.
9503 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
9505 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9506 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
9508 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
9513 * gtk_widget_list_mnemonic_labels:
9514 * @widget: a #GtkWidget
9516 * Returns a newly allocated list of the widgets, normally labels, for
9517 * which this widget is a the target of a mnemonic (see for example,
9518 * gtk_label_set_mnemonic_widget()).
9520 * The widgets in the list are not individually referenced. If you
9521 * want to iterate through the list and perform actions involving
9522 * callbacks that might destroy the widgets, you
9523 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
9524 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
9525 * widgets afterwards.
9527 * Return value: the list of mnemonic labels; free this list
9528 * with g_list_free() when you are done with it.
9533 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
9538 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9540 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
9541 list = g_list_prepend (list, l->data);
9547 * gtk_widget_add_mnemonic_label:
9548 * @widget: a #GtkWidget
9549 * @label: a #GtkWidget that acts as a mnemonic label for @widget
9551 * Adds a widget to the list of mnemonic labels for
9552 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
9553 * list of mnemonic labels for the widget is cleared when the
9554 * widget is destroyed, so the caller must make sure to update
9555 * its internal state at this point as well, by using a connection
9556 * to the #GtkWidget::destroy signal or a weak notifier.
9561 gtk_widget_add_mnemonic_label (GtkWidget *widget,
9564 GSList *old_list, *new_list;
9566 g_return_if_fail (GTK_IS_WIDGET (widget));
9567 g_return_if_fail (GTK_IS_WIDGET (label));
9569 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9570 new_list = g_slist_prepend (old_list, label);
9572 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9573 new_list, (GDestroyNotify) g_slist_free);
9577 * gtk_widget_remove_mnemonic_label:
9578 * @widget: a #GtkWidget
9579 * @label: a #GtkWidget that was previously set as a mnemnic label for
9580 * @widget with gtk_widget_add_mnemonic_label().
9582 * Removes a widget from the list of mnemonic labels for
9583 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
9584 * must have previously been added to the list with
9585 * gtk_widget_add_mnemonic_label().
9590 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
9593 GSList *old_list, *new_list;
9595 g_return_if_fail (GTK_IS_WIDGET (widget));
9596 g_return_if_fail (GTK_IS_WIDGET (label));
9598 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
9599 new_list = g_slist_remove (old_list, label);
9602 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
9603 new_list, (GDestroyNotify) g_slist_free);
9607 * gtk_widget_get_no_show_all:
9608 * @widget: a #GtkWidget
9610 * Returns the current value of the GtkWidget:no-show-all property,
9611 * which determines whether calls to gtk_widget_show_all() and
9612 * gtk_widget_hide_all() will affect this widget.
9614 * Return value: the current value of the "no-show-all" property.
9619 gtk_widget_get_no_show_all (GtkWidget *widget)
9621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9623 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
9627 * gtk_widget_set_no_show_all:
9628 * @widget: a #GtkWidget
9629 * @no_show_all: the new value for the "no-show-all" property
9631 * Sets the #GtkWidget:no-show-all property, which determines whether
9632 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
9635 * This is mostly for use in constructing widget hierarchies with externally
9636 * controlled visibility, see #GtkUIManager.
9641 gtk_widget_set_no_show_all (GtkWidget *widget,
9642 gboolean no_show_all)
9644 g_return_if_fail (GTK_IS_WIDGET (widget));
9646 no_show_all = (no_show_all != FALSE);
9648 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
9652 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
9654 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
9656 g_object_notify (G_OBJECT (widget), "no-show-all");
9661 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
9662 gboolean has_tooltip,
9665 gboolean priv_has_tooltip;
9667 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
9668 quark_has_tooltip));
9670 if (priv_has_tooltip != has_tooltip || force)
9672 priv_has_tooltip = has_tooltip;
9674 if (priv_has_tooltip)
9676 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_NO_WINDOW (widget))
9677 gdk_window_set_events (widget->window,
9678 gdk_window_get_events (widget->window) |
9679 GDK_LEAVE_NOTIFY_MASK |
9680 GDK_POINTER_MOTION_MASK |
9681 GDK_POINTER_MOTION_HINT_MASK);
9683 if (!GTK_WIDGET_NO_WINDOW (widget))
9684 gtk_widget_add_events (widget,
9685 GDK_LEAVE_NOTIFY_MASK |
9686 GDK_POINTER_MOTION_MASK |
9687 GDK_POINTER_MOTION_HINT_MASK);
9690 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
9691 GUINT_TO_POINTER (priv_has_tooltip));
9696 * gtk_widget_set_tooltip_window:
9697 * @widget: a #GtkWidget
9698 * @custom_window: a #GtkWindow, or %NULL
9700 * Replaces the default, usually yellow, window used for displaying
9701 * tooltips with @custom_window. GTK+ will take care of showing and
9702 * hiding @custom_window at the right moment, to behave likewise as
9703 * the default tooltip window. If @custom_window is %NULL, the default
9704 * tooltip window will be used.
9709 gtk_widget_set_tooltip_window (GtkWidget *widget,
9710 GtkWindow *custom_window)
9713 gchar *tooltip_markup;
9714 GtkWindow *tooltip_window;
9716 g_return_if_fail (GTK_IS_WIDGET (widget));
9718 g_return_if_fail (GTK_IS_WINDOW (custom_window));
9720 tooltip_window = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9721 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
9724 g_object_ref (custom_window);
9726 tooltip_window = custom_window;
9727 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
9728 tooltip_window, g_object_unref);
9730 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
9731 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
9734 gtk_widget_trigger_tooltip_query (widget);
9738 * gtk_widget_get_tooltip_window:
9739 * @widget: a #GtkWidget
9741 * Returns the #GtkWindow of the current tooltip. This can be the
9742 * GtkWindow created by default, or the custom tooltip window set
9743 * using gtk_widget_set_tooltip_window().
9745 * Return value: The #GtkWindow of the current tooltip.
9750 gtk_widget_get_tooltip_window (GtkWidget *widget)
9752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9754 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
9758 * gtk_widget_trigger_tooltip_query:
9759 * @widget: a #GtkWidget
9761 * Triggers a tooltip query on the display where the toplevel of @widget
9762 * is located. See gtk_tooltip_trigger_tooltip_query() for more
9768 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
9770 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
9774 * gtk_widget_set_tooltip_text:
9775 * @widget: a #GtkWidget
9776 * @text: the contents of the tooltip for @widget
9778 * Sets @text as the contents of the tooltip. This function will take
9779 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
9780 * handler for the GtkWidget::query-tooltip signal.
9782 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
9787 gtk_widget_set_tooltip_text (GtkWidget *widget,
9790 g_return_if_fail (GTK_IS_WIDGET (widget));
9792 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
9796 * gtk_widget_get_tooltip_text:
9797 * @widget: a #GtkWidget
9799 * Gets the contents of the tooltip for @widget.
9801 * Return value: the tooltip text, or %NULL. You should free the
9802 * returned string with g_free() when done.
9807 gtk_widget_get_tooltip_text (GtkWidget *widget)
9811 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9813 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
9819 * gtk_widget_set_tooltip_markup:
9820 * @widget: a #GtkWidget
9821 * @markup: the contents of the tooltip for @widget, or %NULL
9823 * Sets @markup as the contents of the tooltip, which is marked up with
9824 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
9826 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
9827 * and of the default handler for the GtkWidget::query-tooltip signal.
9829 * See also the GtkWidget:tooltip-markup property and
9830 * gtk_tooltip_set_markup().
9835 gtk_widget_set_tooltip_markup (GtkWidget *widget,
9836 const gchar *markup)
9838 g_return_if_fail (GTK_IS_WIDGET (widget));
9840 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
9844 * gtk_widget_get_tooltip_markup:
9845 * @widget: a #GtkWidget
9847 * Gets the contents of the tooltip for @widget.
9849 * Return value: the tooltip text, or %NULL. You should free the
9850 * returned string with g_free() when done.
9855 gtk_widget_get_tooltip_markup (GtkWidget *widget)
9859 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9861 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
9867 * gtk_widget_set_has_tooltip:
9868 * @widget: a #GtkWidget
9869 * @has_tooltip: whether or not @widget has a tooltip.
9871 * Sets the has-tooltip property on @widget to @has_tooltip. See
9872 * GtkWidget:has-tooltip for more information.
9877 gtk_widget_set_has_tooltip (GtkWidget *widget,
9878 gboolean has_tooltip)
9880 g_return_if_fail (GTK_IS_WIDGET (widget));
9882 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
9886 * gtk_widget_get_has_tooltip:
9887 * @widget: a #GtkWidget
9889 * Returns the current value of the has-tooltip property. See
9890 * GtkWidget:has-tooltip for more information.
9892 * Return value: current value of has-tooltip on @widget.
9897 gtk_widget_get_has_tooltip (GtkWidget *widget)
9899 gboolean has_tooltip = FALSE;
9901 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9903 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
9909 * gtk_widget_get_allocation:
9910 * @widget: a #GtkWidget
9912 * Retrieves the widget's allocation.
9914 * Return value: widget's allocation
9919 gtk_widget_get_allocation (GtkWidget *widget)
9921 static GtkAllocation allocation = { 0 };
9922 g_return_val_if_fail (GTK_IS_WIDGET (widget), allocation);
9924 return widget->allocation;
9928 * gtk_widget_get_window:
9929 * @widget: a #GtkWidget
9931 * Returns the widget's window if it is realized, %NULL otherwise
9933 * Return value: @widget's window.
9938 gtk_widget_get_window (GtkWidget *widget)
9940 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9942 return widget->window;
9945 #define __GTK_WIDGET_C__
9946 #include "gtkaliasdef.c"