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/.
30 #include "gtkcontainer.h"
31 #include "gtkaccelmap.h"
32 #include "gtkclipboard.h"
33 #include "gtkiconfactory.h"
36 #include "gtkmarshalers.h"
38 #include "gtkselection.h"
39 #include "gtksettings.h"
40 #include "gtksizegroup.h"
41 #include "gtkwidget.h"
42 #include "gtkwindow.h"
43 #include "gtkbindings.h"
44 #include "gtkprivate.h"
46 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
47 #include <gobject/gvaluecollector.h>
48 #include <gobject/gobjectnotifyqueue.c>
49 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltips.h"
53 #include "gtkinvisible.h"
55 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
56 #define INIT_PATH_SIZE (512)
96 PROPERTY_NOTIFY_EVENT,
97 SELECTION_CLEAR_EVENT,
98 SELECTION_REQUEST_EVENT,
99 SELECTION_NOTIFY_EVENT,
114 VISIBILITY_NOTIFY_EVENT,
118 ACCEL_CLOSURES_CHANGED,
137 PROP_RECEIVES_DEFAULT,
138 PROP_COMPOSITE_CHILD,
141 PROP_EXTENSION_EVENTS
144 typedef struct _GtkStateData GtkStateData;
149 guint state_restoration : 1;
150 guint parent_sensitive : 1;
151 guint use_forall : 1;
155 /* --- prototypes --- */
156 static void gtk_widget_class_init (GtkWidgetClass *klass);
157 static void gtk_widget_init (GtkWidget *widget);
158 static void gtk_widget_set_property (GObject *object,
162 static void gtk_widget_get_property (GObject *object,
166 static void gtk_widget_dispose (GObject *object);
167 static void gtk_widget_real_destroy (GtkObject *object);
168 static void gtk_widget_finalize (GObject *object);
169 static void gtk_widget_real_show (GtkWidget *widget);
170 static void gtk_widget_real_hide (GtkWidget *widget);
171 static void gtk_widget_real_map (GtkWidget *widget);
172 static void gtk_widget_real_unmap (GtkWidget *widget);
173 static void gtk_widget_real_realize (GtkWidget *widget);
174 static void gtk_widget_real_unrealize (GtkWidget *widget);
175 static void gtk_widget_real_size_request (GtkWidget *widget,
176 GtkRequisition *requisition);
177 static void gtk_widget_real_size_allocate (GtkWidget *widget,
178 GtkAllocation *allocation);
179 static void gtk_widget_style_set (GtkWidget *widget,
180 GtkStyle *previous_style);
181 static void gtk_widget_direction_changed (GtkWidget *widget,
182 GtkTextDirection previous_direction);
184 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
185 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
186 GtkWidgetHelpType help_type);
188 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
190 GParamSpec **pspecs);
191 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
193 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
195 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
198 GdkEventFocus *event);
199 static gboolean gtk_widget_real_focus (GtkWidget *widget,
200 GtkDirectionType direction);
201 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
202 static void gtk_widget_propagate_state (GtkWidget *widget,
204 static void gtk_widget_reset_rc_style (GtkWidget *widget);
205 static void gtk_widget_set_style_internal (GtkWidget *widget,
207 gboolean initial_emission);
208 static gint gtk_widget_event_internal (GtkWidget *widget,
210 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
211 gboolean group_cycling);
212 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
213 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
214 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
215 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
216 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
218 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
220 static void gtk_widget_set_usize_internal (GtkWidget *widget,
225 /* --- variables --- */
226 static gpointer parent_class = NULL;
227 static guint widget_signals[LAST_SIGNAL] = { 0 };
228 static GMemChunk *aux_info_mem_chunk = NULL;
229 static GtkStyle *gtk_default_style = NULL;
230 static GSList *colormap_stack = NULL;
231 static guint composite_child_stack = 0;
232 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
233 static GParamSpecPool *style_property_spec_pool = NULL;
235 static GQuark quark_property_parser = 0;
236 static GQuark quark_aux_info = 0;
237 static GQuark quark_accel_path = 0;
238 static GQuark quark_accel_closures = 0;
239 static GQuark quark_event_mask = 0;
240 static GQuark quark_extension_event_mode = 0;
241 static GQuark quark_parent_window = 0;
242 static GQuark quark_shape_info = 0;
243 static GQuark quark_colormap = 0;
244 static GQuark quark_pango_context = 0;
245 static GQuark quark_rc_style = 0;
246 static GQuark quark_accessible_object = 0;
247 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
248 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
250 /* --- functions --- */
252 gtk_widget_get_type (void)
254 static GType widget_type = 0;
258 static const GTypeInfo widget_info =
260 sizeof (GtkWidgetClass),
261 NULL, /* base_init */
262 NULL, /* base_finalize */
263 (GClassInitFunc) gtk_widget_class_init,
264 NULL, /* class_finalize */
265 NULL, /* class_init */
268 (GInstanceInitFunc) gtk_widget_init,
269 NULL, /* value_table */
272 static const GInterfaceInfo accessibility_info =
274 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
275 (GInterfaceFinalizeFunc) NULL,
276 NULL /* interface data */
279 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
280 &widget_info, G_TYPE_FLAG_ABSTRACT);
282 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
283 &accessibility_info) ;
291 child_property_notify_dispatcher (GObject *object,
295 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
299 gtk_widget_class_init (GtkWidgetClass *klass)
301 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
302 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
303 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
304 GtkBindingSet *binding_set;
306 parent_class = g_type_class_peek_parent (klass);
308 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
309 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
310 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
311 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
312 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
313 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
314 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
315 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
316 quark_colormap = g_quark_from_static_string ("gtk-colormap");
317 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
318 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
319 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
321 style_property_spec_pool = g_param_spec_pool_new (FALSE);
322 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
323 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
324 cpn_context.dispatcher = child_property_notify_dispatcher;
325 _gtk_widget_child_property_notify_context = &cpn_context;
327 gobject_class->dispose = gtk_widget_dispose;
328 gobject_class->finalize = gtk_widget_finalize;
329 gobject_class->set_property = gtk_widget_set_property;
330 gobject_class->get_property = gtk_widget_get_property;
332 object_class->destroy = gtk_widget_real_destroy;
334 klass->activate_signal = 0;
335 klass->set_scroll_adjustments_signal = 0;
336 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
337 klass->show = gtk_widget_real_show;
338 klass->show_all = gtk_widget_show;
339 klass->hide = gtk_widget_real_hide;
340 klass->hide_all = gtk_widget_hide;
341 klass->map = gtk_widget_real_map;
342 klass->unmap = gtk_widget_real_unmap;
343 klass->realize = gtk_widget_real_realize;
344 klass->unrealize = gtk_widget_real_unrealize;
345 klass->size_request = gtk_widget_real_size_request;
346 klass->size_allocate = gtk_widget_real_size_allocate;
347 klass->state_changed = NULL;
348 klass->parent_set = NULL;
349 klass->hierarchy_changed = NULL;
350 klass->style_set = gtk_widget_style_set;
351 klass->direction_changed = gtk_widget_direction_changed;
352 klass->grab_notify = NULL;
353 klass->child_notify = NULL;
354 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
355 klass->grab_focus = gtk_widget_real_grab_focus;
356 klass->focus = gtk_widget_real_focus;
358 klass->button_press_event = NULL;
359 klass->button_release_event = NULL;
360 klass->motion_notify_event = NULL;
361 klass->delete_event = NULL;
362 klass->destroy_event = NULL;
363 klass->expose_event = NULL;
364 klass->key_press_event = gtk_widget_real_key_press_event;
365 klass->key_release_event = gtk_widget_real_key_release_event;
366 klass->enter_notify_event = NULL;
367 klass->leave_notify_event = NULL;
368 klass->configure_event = NULL;
369 klass->focus_in_event = gtk_widget_real_focus_in_event;
370 klass->focus_out_event = gtk_widget_real_focus_out_event;
371 klass->map_event = NULL;
372 klass->unmap_event = NULL;
373 klass->window_state_event = NULL;
374 klass->property_notify_event = _gtk_selection_property_notify;
375 klass->selection_clear_event = gtk_selection_clear;
376 klass->selection_request_event = _gtk_selection_request;
377 klass->selection_notify_event = _gtk_selection_notify;
378 klass->selection_received = NULL;
379 klass->proximity_in_event = NULL;
380 klass->proximity_out_event = NULL;
381 klass->drag_begin = NULL;
382 klass->drag_end = NULL;
383 klass->drag_data_delete = NULL;
384 klass->drag_leave = NULL;
385 klass->drag_motion = NULL;
386 klass->drag_drop = NULL;
387 klass->drag_data_received = NULL;
388 klass->screen_changed = NULL;
390 klass->show_help = gtk_widget_real_show_help;
392 /* Accessibility support */
393 klass->get_accessible = gtk_widget_real_get_accessible;
395 klass->no_expose_event = NULL;
397 g_object_class_install_property (gobject_class,
399 g_param_spec_string ("name",
401 _("The name of the widget"),
404 g_object_class_install_property (gobject_class,
406 g_param_spec_object ("parent",
408 _("The parent widget of this widget. Must be a Container widget"),
412 g_object_class_install_property (gobject_class,
414 g_param_spec_int ("width_request",
416 _("Override for width request of the widget, or -1 if natural request should be used"),
421 g_object_class_install_property (gobject_class,
423 g_param_spec_int ("height_request",
425 _("Override for height request of the widget, or -1 if natural request should be used"),
430 g_object_class_install_property (gobject_class,
432 g_param_spec_boolean ("visible",
434 _("Whether the widget is visible"),
437 g_object_class_install_property (gobject_class,
439 g_param_spec_boolean ("sensitive",
441 _("Whether the widget responds to input"),
444 g_object_class_install_property (gobject_class,
446 g_param_spec_boolean ("app_paintable",
447 _("Application paintable"),
448 _("Whether the application will paint directly on the widget"),
451 g_object_class_install_property (gobject_class,
453 g_param_spec_boolean ("can_focus",
455 _("Whether the widget can accept the input focus"),
458 g_object_class_install_property (gobject_class,
460 g_param_spec_boolean ("has_focus",
462 _("Whether the widget has the input focus"),
465 g_object_class_install_property (gobject_class,
467 g_param_spec_boolean ("is_focus",
469 _("Whether the widget is the focus widget within the toplevel"),
472 g_object_class_install_property (gobject_class,
474 g_param_spec_boolean ("can_default",
476 _("Whether the widget can be the default widget"),
479 g_object_class_install_property (gobject_class,
481 g_param_spec_boolean ("has_default",
483 _("Whether the widget is the default widget"),
486 g_object_class_install_property (gobject_class,
487 PROP_RECEIVES_DEFAULT,
488 g_param_spec_boolean ("receives_default",
489 _("Receives default"),
490 _("If TRUE, the widget will receive the default action when it is focused"),
493 g_object_class_install_property (gobject_class,
494 PROP_COMPOSITE_CHILD,
495 g_param_spec_boolean ("composite_child",
496 _("Composite child"),
497 _("Whether the widget is part of a composite widget"),
500 g_object_class_install_property (gobject_class,
502 g_param_spec_object ("style",
504 _("The style of the widget, which contains information about how it will look (colors etc)"),
507 g_object_class_install_property (gobject_class,
509 g_param_spec_flags ("events",
511 _("The event mask that decides what kind of GdkEvents this widget gets"),
515 g_object_class_install_property (gobject_class,
516 PROP_EXTENSION_EVENTS,
517 g_param_spec_enum ("extension_events",
518 _("Extension events"),
519 _("The mask that decides what kind of extension events this widget gets"),
520 GDK_TYPE_EXTENSION_MODE,
521 GDK_EXTENSION_EVENTS_NONE,
523 widget_signals[SHOW] =
524 g_signal_new ("show",
525 G_TYPE_FROM_CLASS (gobject_class),
527 G_STRUCT_OFFSET (GtkWidgetClass, show),
529 _gtk_marshal_VOID__VOID,
531 widget_signals[HIDE] =
532 g_signal_new ("hide",
533 G_TYPE_FROM_CLASS (gobject_class),
535 G_STRUCT_OFFSET (GtkWidgetClass, hide),
537 _gtk_marshal_VOID__VOID,
539 widget_signals[MAP] =
541 G_TYPE_FROM_CLASS (gobject_class),
543 G_STRUCT_OFFSET (GtkWidgetClass, map),
545 _gtk_marshal_VOID__VOID,
547 widget_signals[UNMAP] =
548 g_signal_new ("unmap",
549 G_TYPE_FROM_CLASS (gobject_class),
551 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
553 _gtk_marshal_VOID__VOID,
555 widget_signals[REALIZE] =
556 g_signal_new ("realize",
557 G_TYPE_FROM_CLASS (gobject_class),
559 G_STRUCT_OFFSET (GtkWidgetClass, realize),
561 _gtk_marshal_VOID__VOID,
563 widget_signals[UNREALIZE] =
564 g_signal_new ("unrealize",
565 G_TYPE_FROM_CLASS (gobject_class),
567 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
569 _gtk_marshal_VOID__VOID,
571 widget_signals[SIZE_REQUEST] =
572 g_signal_new ("size_request",
573 G_TYPE_FROM_CLASS (gobject_class),
575 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
577 _gtk_marshal_VOID__BOXED,
579 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
580 widget_signals[SIZE_ALLOCATE] =
581 g_signal_new ("size_allocate",
582 G_TYPE_FROM_CLASS (gobject_class),
584 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
586 _gtk_marshal_VOID__BOXED,
588 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
589 widget_signals[STATE_CHANGED] =
590 g_signal_new ("state_changed",
591 G_TYPE_FROM_CLASS (gobject_class),
593 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
595 _gtk_marshal_VOID__ENUM,
597 GTK_TYPE_STATE_TYPE);
598 widget_signals[PARENT_SET] =
599 g_signal_new ("parent_set",
600 G_TYPE_FROM_CLASS (gobject_class),
602 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
604 _gtk_marshal_VOID__OBJECT,
607 widget_signals[HIERARCHY_CHANGED] =
608 g_signal_new ("hierarchy_changed",
609 G_TYPE_FROM_CLASS (gobject_class),
611 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
613 _gtk_marshal_VOID__OBJECT,
616 widget_signals[STYLE_SET] =
617 g_signal_new ("style_set",
618 G_TYPE_FROM_CLASS (gobject_class),
620 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
622 _gtk_marshal_VOID__OBJECT,
625 widget_signals[DIRECTION_CHANGED] =
626 g_signal_new ("direction_changed",
627 G_TYPE_FROM_CLASS (gobject_class),
629 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
631 _gtk_marshal_VOID__ENUM,
633 GTK_TYPE_TEXT_DIRECTION);
634 widget_signals[GRAB_NOTIFY] =
635 g_signal_new ("grab_notify",
636 G_TYPE_FROM_CLASS (gobject_class),
638 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
640 _gtk_marshal_VOID__BOOLEAN,
643 widget_signals[CHILD_NOTIFY] =
644 g_signal_new ("child_notify",
645 G_TYPE_FROM_CLASS (gobject_class),
646 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
647 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
649 g_cclosure_marshal_VOID__PARAM,
652 widget_signals[MNEMONIC_ACTIVATE] =
653 g_signal_new ("mnemonic_activate",
654 G_TYPE_FROM_CLASS (gobject_class),
656 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
657 _gtk_boolean_handled_accumulator, NULL,
658 _gtk_marshal_BOOLEAN__BOOLEAN,
661 widget_signals[GRAB_FOCUS] =
662 g_signal_new ("grab_focus",
663 G_TYPE_FROM_CLASS (gobject_class),
664 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
665 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
667 _gtk_marshal_VOID__VOID,
669 widget_signals[FOCUS] =
670 g_signal_new ("focus",
671 G_TYPE_FROM_CLASS (object_class),
673 G_STRUCT_OFFSET (GtkWidgetClass, focus),
674 _gtk_boolean_handled_accumulator, NULL,
675 _gtk_marshal_BOOLEAN__ENUM,
677 GTK_TYPE_DIRECTION_TYPE);
678 widget_signals[EVENT] =
679 g_signal_new ("event",
680 G_TYPE_FROM_CLASS (gobject_class),
682 G_STRUCT_OFFSET (GtkWidgetClass, event),
683 _gtk_boolean_handled_accumulator, NULL,
684 _gtk_marshal_BOOLEAN__BOXED,
686 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
687 widget_signals[EVENT_AFTER] =
688 g_signal_new ("event-after",
689 G_TYPE_FROM_CLASS (gobject_class),
693 _gtk_marshal_VOID__BOXED,
695 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
696 widget_signals[BUTTON_PRESS_EVENT] =
697 g_signal_new ("button_press_event",
698 G_TYPE_FROM_CLASS (gobject_class),
700 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
701 _gtk_boolean_handled_accumulator, NULL,
702 _gtk_marshal_BOOLEAN__BOXED,
704 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
705 widget_signals[BUTTON_RELEASE_EVENT] =
706 g_signal_new ("button_release_event",
707 G_TYPE_FROM_CLASS (gobject_class),
709 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
710 _gtk_boolean_handled_accumulator, NULL,
711 _gtk_marshal_BOOLEAN__BOXED,
713 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
714 widget_signals[SCROLL_EVENT] =
715 g_signal_new ("scroll_event",
716 G_TYPE_FROM_CLASS (gobject_class),
718 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
719 _gtk_boolean_handled_accumulator, NULL,
720 _gtk_marshal_BOOLEAN__BOXED,
722 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
723 widget_signals[MOTION_NOTIFY_EVENT] =
724 g_signal_new ("motion_notify_event",
725 G_TYPE_FROM_CLASS (gobject_class),
727 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
728 _gtk_boolean_handled_accumulator, NULL,
729 _gtk_marshal_BOOLEAN__BOXED,
731 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
732 widget_signals[DELETE_EVENT] =
733 g_signal_new ("delete_event",
734 G_TYPE_FROM_CLASS (gobject_class),
736 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
737 _gtk_boolean_handled_accumulator, NULL,
738 _gtk_marshal_BOOLEAN__BOXED,
740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
741 widget_signals[DESTROY_EVENT] =
742 g_signal_new ("destroy_event",
743 G_TYPE_FROM_CLASS (gobject_class),
745 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
746 _gtk_boolean_handled_accumulator, NULL,
747 _gtk_marshal_BOOLEAN__BOXED,
749 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
750 widget_signals[EXPOSE_EVENT] =
751 g_signal_new ("expose_event",
752 G_TYPE_FROM_CLASS (gobject_class),
754 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
755 _gtk_boolean_handled_accumulator, NULL,
756 _gtk_marshal_BOOLEAN__BOXED,
758 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
759 widget_signals[KEY_PRESS_EVENT] =
760 g_signal_new ("key_press_event",
761 G_TYPE_FROM_CLASS (gobject_class),
763 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
764 _gtk_boolean_handled_accumulator, NULL,
765 _gtk_marshal_BOOLEAN__BOXED,
767 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
768 widget_signals[KEY_RELEASE_EVENT] =
769 g_signal_new ("key_release_event",
770 G_TYPE_FROM_CLASS (gobject_class),
772 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
773 _gtk_boolean_handled_accumulator, NULL,
774 _gtk_marshal_BOOLEAN__BOXED,
776 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
777 widget_signals[ENTER_NOTIFY_EVENT] =
778 g_signal_new ("enter_notify_event",
779 G_TYPE_FROM_CLASS (gobject_class),
781 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
782 _gtk_boolean_handled_accumulator, NULL,
783 _gtk_marshal_BOOLEAN__BOXED,
785 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
786 widget_signals[LEAVE_NOTIFY_EVENT] =
787 g_signal_new ("leave_notify_event",
788 G_TYPE_FROM_CLASS (gobject_class),
790 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
791 _gtk_boolean_handled_accumulator, NULL,
792 _gtk_marshal_BOOLEAN__BOXED,
794 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
795 widget_signals[CONFIGURE_EVENT] =
796 g_signal_new ("configure_event",
797 G_TYPE_FROM_CLASS (gobject_class),
799 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
800 _gtk_boolean_handled_accumulator, NULL,
801 _gtk_marshal_BOOLEAN__BOXED,
803 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
804 widget_signals[FOCUS_IN_EVENT] =
805 g_signal_new ("focus_in_event",
806 G_TYPE_FROM_CLASS (gobject_class),
808 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
809 _gtk_boolean_handled_accumulator, NULL,
810 _gtk_marshal_BOOLEAN__BOXED,
812 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
813 widget_signals[FOCUS_OUT_EVENT] =
814 g_signal_new ("focus_out_event",
815 G_TYPE_FROM_CLASS (gobject_class),
817 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
818 _gtk_boolean_handled_accumulator, NULL,
819 _gtk_marshal_BOOLEAN__BOXED,
821 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
822 widget_signals[MAP_EVENT] =
823 g_signal_new ("map_event",
824 G_TYPE_FROM_CLASS (gobject_class),
826 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
827 _gtk_boolean_handled_accumulator, NULL,
828 _gtk_marshal_BOOLEAN__BOXED,
830 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
831 widget_signals[UNMAP_EVENT] =
832 g_signal_new ("unmap_event",
833 G_TYPE_FROM_CLASS (gobject_class),
835 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
836 _gtk_boolean_handled_accumulator, NULL,
837 _gtk_marshal_BOOLEAN__BOXED,
839 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
840 widget_signals[PROPERTY_NOTIFY_EVENT] =
841 g_signal_new ("property_notify_event",
842 G_TYPE_FROM_CLASS (gobject_class),
844 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
845 _gtk_boolean_handled_accumulator, NULL,
846 _gtk_marshal_BOOLEAN__BOXED,
848 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
849 widget_signals[SELECTION_CLEAR_EVENT] =
850 g_signal_new ("selection_clear_event",
851 G_TYPE_FROM_CLASS (gobject_class),
853 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
854 _gtk_boolean_handled_accumulator, NULL,
855 _gtk_marshal_BOOLEAN__BOXED,
857 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
858 widget_signals[SELECTION_REQUEST_EVENT] =
859 g_signal_new ("selection_request_event",
860 G_TYPE_FROM_CLASS (gobject_class),
862 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
863 _gtk_boolean_handled_accumulator, NULL,
864 _gtk_marshal_BOOLEAN__BOXED,
866 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
867 widget_signals[SELECTION_NOTIFY_EVENT] =
868 g_signal_new ("selection_notify_event",
869 G_TYPE_FROM_CLASS (gobject_class),
871 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
872 _gtk_boolean_handled_accumulator, NULL,
873 _gtk_marshal_BOOLEAN__BOXED,
875 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
876 widget_signals[SELECTION_RECEIVED] =
877 g_signal_new ("selection_received",
878 G_TYPE_FROM_CLASS (gobject_class),
880 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
882 _gtk_marshal_VOID__BOXED_UINT,
884 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
886 widget_signals[SELECTION_GET] =
887 g_signal_new ("selection_get",
888 G_TYPE_FROM_CLASS (gobject_class),
890 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
892 _gtk_marshal_VOID__BOXED_UINT_UINT,
894 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
897 widget_signals[PROXIMITY_IN_EVENT] =
898 g_signal_new ("proximity_in_event",
899 G_TYPE_FROM_CLASS (gobject_class),
901 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
902 _gtk_boolean_handled_accumulator, NULL,
903 _gtk_marshal_BOOLEAN__BOXED,
905 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
906 widget_signals[PROXIMITY_OUT_EVENT] =
907 g_signal_new ("proximity_out_event",
908 G_TYPE_FROM_CLASS (gobject_class),
910 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
911 _gtk_boolean_handled_accumulator, NULL,
912 _gtk_marshal_BOOLEAN__BOXED,
914 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
915 widget_signals[DRAG_LEAVE] =
916 g_signal_new ("drag_leave",
917 G_TYPE_FROM_CLASS (gobject_class),
919 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
921 _gtk_marshal_VOID__OBJECT_UINT,
923 GDK_TYPE_DRAG_CONTEXT,
925 widget_signals[DRAG_BEGIN] =
926 g_signal_new ("drag_begin",
927 G_TYPE_FROM_CLASS (gobject_class),
929 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
931 _gtk_marshal_VOID__OBJECT,
933 GDK_TYPE_DRAG_CONTEXT);
934 widget_signals[DRAG_END] =
935 g_signal_new ("drag_end",
936 G_TYPE_FROM_CLASS (gobject_class),
938 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
940 _gtk_marshal_VOID__OBJECT,
942 GDK_TYPE_DRAG_CONTEXT);
943 widget_signals[DRAG_DATA_DELETE] =
944 g_signal_new ("drag_data_delete",
945 G_TYPE_FROM_CLASS (gobject_class),
947 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
949 _gtk_marshal_VOID__OBJECT,
951 GDK_TYPE_DRAG_CONTEXT);
952 widget_signals[DRAG_MOTION] =
953 g_signal_new ("drag_motion",
954 G_TYPE_FROM_CLASS (gobject_class),
956 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
957 _gtk_boolean_handled_accumulator, NULL,
958 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
960 GDK_TYPE_DRAG_CONTEXT,
964 widget_signals[DRAG_DROP] =
965 g_signal_new ("drag_drop",
966 G_TYPE_FROM_CLASS (gobject_class),
968 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
969 _gtk_boolean_handled_accumulator, NULL,
970 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
972 GDK_TYPE_DRAG_CONTEXT,
976 widget_signals[DRAG_DATA_GET] =
977 g_signal_new ("drag_data_get",
978 G_TYPE_FROM_CLASS (gobject_class),
980 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
982 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
984 GDK_TYPE_DRAG_CONTEXT,
985 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
988 widget_signals[DRAG_DATA_RECEIVED] =
989 g_signal_new ("drag_data_received",
990 G_TYPE_FROM_CLASS (gobject_class),
992 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
994 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
996 GDK_TYPE_DRAG_CONTEXT,
999 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1002 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1003 g_signal_new ("visibility_notify_event",
1004 G_TYPE_FROM_CLASS (gobject_class),
1006 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1007 _gtk_boolean_handled_accumulator, NULL,
1008 _gtk_marshal_BOOLEAN__BOXED,
1010 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1011 widget_signals[CLIENT_EVENT] =
1012 g_signal_new ("client_event",
1013 G_TYPE_FROM_CLASS (gobject_class),
1015 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1016 _gtk_boolean_handled_accumulator, NULL,
1017 _gtk_marshal_BOOLEAN__BOXED,
1019 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1020 widget_signals[NO_EXPOSE_EVENT] =
1021 g_signal_new ("no_expose_event",
1022 G_TYPE_FROM_CLASS (gobject_class),
1024 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1025 _gtk_boolean_handled_accumulator, NULL,
1026 _gtk_marshal_BOOLEAN__BOXED,
1028 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1029 widget_signals[WINDOW_STATE_EVENT] =
1030 g_signal_new ("window_state_event",
1031 G_TYPE_FROM_CLASS (gobject_class),
1033 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1034 _gtk_boolean_handled_accumulator, NULL,
1035 _gtk_marshal_BOOLEAN__BOXED,
1037 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1038 widget_signals[POPUP_MENU] =
1039 g_signal_new ("popup_menu",
1040 G_TYPE_FROM_CLASS (gobject_class),
1041 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1042 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1043 _gtk_boolean_handled_accumulator, NULL,
1044 _gtk_marshal_BOOLEAN__VOID,
1046 widget_signals[SHOW_HELP] =
1047 g_signal_new ("show_help",
1048 G_TYPE_FROM_CLASS (gobject_class),
1049 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1050 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1051 _gtk_boolean_handled_accumulator, NULL,
1052 _gtk_marshal_BOOLEAN__ENUM,
1054 GTK_TYPE_WIDGET_HELP_TYPE);
1055 widget_signals[ACCEL_CLOSURES_CHANGED] =
1056 g_signal_new ("accel_closures_changed",
1057 G_TYPE_FROM_CLASS (gobject_class),
1061 _gtk_marshal_NONE__NONE,
1063 widget_signals[SCREEN_CHANGED] =
1064 g_signal_new ("screen_changed",
1065 G_TYPE_FROM_CLASS (gobject_class),
1067 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1069 _gtk_marshal_VOID__OBJECT,
1073 binding_set = gtk_binding_set_by_class (klass);
1074 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1076 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1079 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1081 GTK_TYPE_WIDGET_HELP_TYPE,
1082 GTK_WIDGET_HELP_TOOLTIP);
1083 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1085 GTK_TYPE_WIDGET_HELP_TYPE,
1086 GTK_WIDGET_HELP_TOOLTIP);
1087 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1089 GTK_TYPE_WIDGET_HELP_TYPE,
1090 GTK_WIDGET_HELP_WHATS_THIS);
1091 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1093 GTK_TYPE_WIDGET_HELP_TYPE,
1094 GTK_WIDGET_HELP_WHATS_THIS);
1096 gtk_widget_class_install_style_property (klass,
1097 g_param_spec_boolean ("interior_focus",
1098 _("Interior Focus"),
1099 _("Whether to draw the focus indicator inside widgets"),
1103 gtk_widget_class_install_style_property (klass,
1104 g_param_spec_int ("focus-line-width",
1105 _("Focus linewidth"),
1106 _("Width, in pixels, of the focus indicator line"),
1108 G_PARAM_READWRITE));
1110 gtk_widget_class_install_style_property (klass,
1111 g_param_spec_string ("focus-line-pattern",
1112 _("Focus line dash pattern"),
1113 _("Dash pattern used to draw the focus indicator"),
1115 G_PARAM_READWRITE));
1116 gtk_widget_class_install_style_property (klass,
1117 g_param_spec_int ("focus-padding",
1119 _("Width, in pixels, between focus indicator and the widget 'box'"),
1121 G_PARAM_READWRITE));
1122 gtk_widget_class_install_style_property (klass,
1123 g_param_spec_boxed ("cursor-color",
1125 _("Color with which to draw insertion cursor"),
1128 gtk_widget_class_install_style_property (klass,
1129 g_param_spec_boxed ("secondary-cursor-color",
1130 _("Secondary cursor color"),
1131 _("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1134 gtk_widget_class_install_style_property (klass,
1135 g_param_spec_float ("cursor-aspect-ratio",
1136 _("Cursor line aspect ratio"),
1137 _("Aspect ratio with which to draw insertion cursor"),
1143 gtk_widget_set_property (GObject *object,
1145 const GValue *value,
1148 GtkWidget *widget = GTK_WIDGET (object);
1152 guint32 saved_flags;
1155 gtk_widget_set_name (widget, g_value_get_string (value));
1158 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1160 case PROP_WIDTH_REQUEST:
1161 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1163 case PROP_HEIGHT_REQUEST:
1164 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1167 if (g_value_get_boolean (value))
1168 gtk_widget_show (widget);
1170 gtk_widget_hide (widget);
1172 case PROP_SENSITIVE:
1173 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1175 case PROP_APP_PAINTABLE:
1176 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1178 case PROP_CAN_FOCUS:
1179 saved_flags = GTK_WIDGET_FLAGS (widget);
1180 if (g_value_get_boolean (value))
1181 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1183 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1184 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1185 gtk_widget_queue_resize (widget);
1187 case PROP_HAS_FOCUS:
1188 if (g_value_get_boolean (value))
1189 gtk_widget_grab_focus (widget);
1192 if (g_value_get_boolean (value))
1193 gtk_widget_grab_focus (widget);
1195 case PROP_CAN_DEFAULT:
1196 saved_flags = GTK_WIDGET_FLAGS (widget);
1197 if (g_value_get_boolean (value))
1198 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1200 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1201 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1202 gtk_widget_queue_resize (widget);
1204 case PROP_HAS_DEFAULT:
1205 if (g_value_get_boolean (value))
1206 gtk_widget_grab_default (widget);
1208 case PROP_RECEIVES_DEFAULT:
1209 if (g_value_get_boolean (value))
1210 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1212 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1215 gtk_widget_set_style (widget, g_value_get_object (value));
1218 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1219 gtk_widget_set_events (widget, g_value_get_flags (value));
1221 case PROP_EXTENSION_EVENTS:
1222 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1230 gtk_widget_get_property (GObject *object,
1235 GtkWidget *widget = GTK_WIDGET (object);
1240 GdkExtensionMode *modep;
1244 g_value_set_string (value, widget->name);
1246 g_value_set_string (value, "");
1250 g_value_set_object (value, widget->parent);
1252 g_value_set_object (value, NULL);
1254 case PROP_WIDTH_REQUEST:
1257 gtk_widget_get_size_request (widget, &w, NULL);
1258 g_value_set_int (value, w);
1261 case PROP_HEIGHT_REQUEST:
1264 gtk_widget_get_size_request (widget, NULL, &h);
1265 g_value_set_int (value, h);
1269 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1271 case PROP_SENSITIVE:
1272 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1274 case PROP_APP_PAINTABLE:
1275 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1277 case PROP_CAN_FOCUS:
1278 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1280 case PROP_HAS_FOCUS:
1281 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1284 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1286 case PROP_CAN_DEFAULT:
1287 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1289 case PROP_HAS_DEFAULT:
1290 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1292 case PROP_RECEIVES_DEFAULT:
1293 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1295 case PROP_COMPOSITE_CHILD:
1296 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1299 g_value_set_object (value, gtk_widget_get_style (widget));
1302 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1304 g_value_set_flags (value, 0);
1306 g_value_set_flags (value, *eventp);
1308 case PROP_EXTENSION_EVENTS:
1309 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1311 g_value_set_enum (value, 0);
1313 g_value_set_enum (value, (GdkExtensionMode) *modep);
1316 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1322 gtk_widget_init (GtkWidget *widget)
1324 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1325 widget->state = GTK_STATE_NORMAL;
1326 widget->saved_state = GTK_STATE_NORMAL;
1327 widget->name = NULL;
1328 widget->requisition.width = 0;
1329 widget->requisition.height = 0;
1330 widget->allocation.x = -1;
1331 widget->allocation.y = -1;
1332 widget->allocation.width = 1;
1333 widget->allocation.height = 1;
1334 widget->window = NULL;
1335 widget->parent = NULL;
1337 GTK_WIDGET_SET_FLAGS (widget,
1339 GTK_PARENT_SENSITIVE |
1340 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1341 GTK_DOUBLE_BUFFERED);
1343 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1344 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1345 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1347 widget->style = gtk_widget_get_default_style ();
1348 g_object_ref (widget->style);
1353 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1355 GParamSpec **pspecs)
1357 GtkWidget *container = widget->parent;
1360 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1361 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1365 * gtk_widget_freeze_child_notify:
1366 * @widget: a #GtkWidget
1368 * Stops emission of "child-notify" signals on @widget. The signals are
1369 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1371 * This is the analogue of g_object_freeze_notify() for child properties.
1374 gtk_widget_freeze_child_notify (GtkWidget *widget)
1376 g_return_if_fail (GTK_IS_WIDGET (widget));
1378 if (!G_OBJECT (widget)->ref_count)
1381 g_object_ref (widget);
1382 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1383 g_object_unref (widget);
1387 * gtk_widget_child_notify:
1388 * @widget: a #GtkWidget
1389 * @child_property: the name of a child property installed on the
1390 * class of @widget<!-- -->'s parent.
1392 * Emits a "child-notify" signal for the
1393 * <link linkend="child-properties">child property</link> @child_property
1396 * This is the analogue of g_object_notify() for child properties.
1399 gtk_widget_child_notify (GtkWidget *widget,
1400 const gchar *child_property)
1404 g_return_if_fail (GTK_IS_WIDGET (widget));
1405 g_return_if_fail (child_property != NULL);
1406 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1409 g_object_ref (widget);
1410 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1412 G_OBJECT_TYPE (widget->parent),
1415 g_warning ("%s: container class `%s' has no child property named `%s'",
1417 G_OBJECT_TYPE_NAME (widget->parent),
1421 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1423 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1424 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1426 g_object_unref (widget);
1430 * gtk_widget_thaw_child_notify:
1431 * @widget: a #GtkWidget
1433 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1434 * This causes all queued "child-notify" signals on @widget to be emitted.
1437 gtk_widget_thaw_child_notify (GtkWidget *widget)
1439 GObjectNotifyQueue *nqueue;
1441 g_return_if_fail (GTK_IS_WIDGET (widget));
1443 if (!G_OBJECT (widget)->ref_count)
1446 g_object_ref (widget);
1447 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1448 if (!nqueue || !nqueue->freeze_count)
1449 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1450 G_OBJECT_TYPE_NAME (widget), widget);
1452 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1453 g_object_unref (widget);
1459 * @type: type ID of the widget to create
1460 * @first_property_name: name of first property to set
1461 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1463 * This is a convenience function for creating a widget and setting
1464 * its properties in one go. For example you might write:
1465 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1466 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1467 * g_object_new(), but returns a widget so you don't have to
1468 * cast the object yourself.
1470 * Return value: a new #GtkWidget of type @widget_type
1473 gtk_widget_new (GType type,
1474 const gchar *first_property_name,
1480 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1482 va_start (var_args, first_property_name);
1483 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1491 * @widget: a #GtkWidget
1492 * @first_property_name: name of first property to set
1493 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1495 * Like g_object_set() - there's no reason to use this instead of
1499 gtk_widget_set (GtkWidget *widget,
1500 const gchar *first_property_name,
1505 g_return_if_fail (GTK_IS_WIDGET (widget));
1507 va_start (var_args, first_property_name);
1508 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1513 gtk_widget_queue_draw_child (GtkWidget *widget)
1517 parent = widget->parent;
1518 if (parent && GTK_WIDGET_DRAWABLE (parent))
1519 gtk_widget_queue_draw_area (parent,
1520 widget->allocation.x,
1521 widget->allocation.y,
1522 widget->allocation.width,
1523 widget->allocation.height);
1527 * gtk_widget_unparent:
1528 * @widget: a #GtkWidget
1530 * This function is only for use in widget implementations.
1531 * Should be called by implementations of the remove method
1532 * on #GtkContainer, to dissociate a child from the container.
1535 gtk_widget_unparent (GtkWidget *widget)
1537 GObjectNotifyQueue *nqueue;
1538 GtkWidget *toplevel;
1539 GtkWidget *old_parent;
1541 g_return_if_fail (GTK_IS_WIDGET (widget));
1542 if (widget->parent == NULL)
1545 /* keep this function in sync with gtk_menu_detach()
1548 g_object_freeze_notify (G_OBJECT (widget));
1549 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1551 toplevel = gtk_widget_get_toplevel (widget);
1552 if (GTK_WIDGET_TOPLEVEL (toplevel))
1553 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1555 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1556 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1558 /* If we are unanchoring the child, we save around the toplevel
1559 * to emit hierarchy changed
1561 if (GTK_WIDGET_ANCHORED (widget->parent))
1562 g_object_ref (toplevel);
1566 gtk_widget_queue_draw_child (widget);
1568 /* Reset the width and height here, to force reallocation if we
1569 * get added back to a new parent. This won't work if our new
1570 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1571 * (would 0x0 be OK here?)
1573 widget->allocation.width = 1;
1574 widget->allocation.height = 1;
1576 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1577 gtk_widget_unrealize (widget);
1579 /* Removing a widget from a container restores the child visible
1580 * flag to the default state, so it doesn't affect the child
1581 * in the next parent.
1583 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1585 old_parent = widget->parent;
1586 widget->parent = NULL;
1587 gtk_widget_set_parent_window (widget, NULL);
1588 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1591 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1592 g_object_unref (toplevel);
1595 g_object_notify (G_OBJECT (widget), "parent");
1596 g_object_thaw_notify (G_OBJECT (widget));
1597 if (!widget->parent)
1598 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1599 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1600 g_object_unref (widget);
1604 * gtk_widget_destroy:
1605 * @widget: a #GtkWidget
1607 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1608 * you don't have to cast the widget to #GtkObject. When a widget is
1609 * destroyed, it will break any references it holds to other objects.
1610 * If the widget is inside a container, the widget will be removed
1611 * from the container. If the widget is a toplevel (derived from
1612 * #GtkWindow), it will be removed from the list of toplevels, and the
1613 * reference GTK+ holds to it will be removed. Removing a
1614 * widget from its container or the list of toplevels results in the
1615 * widget being finalized, unless you've added additional references
1616 * to the widget with g_object_ref().
1618 * In most cases, only toplevel widgets (windows) require explicit
1619 * destruction, because when you destroy a toplevel its children will
1620 * be destroyed as well.
1624 gtk_widget_destroy (GtkWidget *widget)
1626 g_return_if_fail (GTK_IS_WIDGET (widget));
1628 gtk_object_destroy ((GtkObject*) widget);
1632 * gtk_widget_destroyed:
1633 * @widget: a #GtkWidget
1634 * @widget_pointer: address of a variable that contains @widget
1636 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1637 * %NULL. It's intended to be used as a callback connected to the
1638 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1639 * as a signal handler, and pass the address of your widget variable
1640 * as user data. Then when the widget is destroyed, the variable will
1641 * be set to %NULL. Useful for example to avoid multiple copies
1642 * of the same dialog.
1646 gtk_widget_destroyed (GtkWidget *widget,
1647 GtkWidget **widget_pointer)
1649 /* Don't make any assumptions about the
1651 * Even check widget_pointer.
1654 *widget_pointer = NULL;
1659 * @widget: a #GtkWidget
1661 * Flags a widget to be displayed. Any widget that isn't shown will
1662 * not appear on the screen. If you want to show all the widgets in a
1663 * container, it's easier to call gtk_widget_show_all() on the
1664 * container, instead of individually showing the widgets.
1666 * Remember that you have to show the containers containing a widget,
1667 * in addition to the widget itself, before it will appear onscreen.
1669 * When a toplevel container is shown, it is immediately realized and
1670 * mapped; other shown widgets are realized and mapped when their
1671 * toplevel container is realized and mapped.
1675 gtk_widget_show (GtkWidget *widget)
1677 if (!GTK_WIDGET_VISIBLE (widget))
1679 g_object_ref (widget);
1680 if (!GTK_WIDGET_TOPLEVEL (widget))
1681 gtk_widget_queue_resize (widget);
1682 g_signal_emit (widget, widget_signals[SHOW], 0);
1683 g_object_notify (G_OBJECT (widget), "visible");
1684 g_object_unref (widget);
1689 gtk_widget_real_show (GtkWidget *widget)
1691 if (!GTK_WIDGET_VISIBLE (widget))
1693 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1695 if (widget->parent &&
1696 GTK_WIDGET_MAPPED (widget->parent) &&
1697 GTK_WIDGET_CHILD_VISIBLE (widget) &&
1698 !GTK_WIDGET_MAPPED (widget))
1699 gtk_widget_map (widget);
1704 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1707 g_signal_handlers_disconnect_by_func (widget,
1708 gtk_widget_show_map_callback,
1713 * gtk_widget_show_now:
1714 * @widget: a #GtkWidget
1716 * Shows a widget. If the widget is an unmapped toplevel widget
1717 * (i.e. a #GtkWindow that has not yet been shown), enter the main
1718 * loop and wait for the window to actually be mapped. Be careful;
1719 * because the main loop is running, anything can happen during
1723 gtk_widget_show_now (GtkWidget *widget)
1727 g_return_if_fail (GTK_IS_WIDGET (widget));
1729 /* make sure we will get event */
1730 if (!GTK_WIDGET_MAPPED (widget) &&
1731 GTK_WIDGET_TOPLEVEL (widget))
1733 gtk_widget_show (widget);
1735 g_signal_connect (widget, "map_event",
1736 G_CALLBACK (gtk_widget_show_map_callback),
1740 gtk_main_iteration ();
1743 gtk_widget_show (widget);
1748 * @widget: a #GtkWidget
1750 * Reverses the effects of gtk_widget_show(), causing the widget to be
1751 * hidden (invisible to the user).
1754 gtk_widget_hide (GtkWidget *widget)
1756 g_return_if_fail (GTK_IS_WIDGET (widget));
1758 if (GTK_WIDGET_VISIBLE (widget))
1760 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
1761 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
1762 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1764 g_object_ref (widget);
1765 g_signal_emit (widget, widget_signals[HIDE], 0);
1766 if (!GTK_WIDGET_TOPLEVEL (widget))
1767 gtk_widget_queue_resize (widget);
1768 g_object_notify (G_OBJECT (widget), "visible");
1769 g_object_unref (widget);
1774 gtk_widget_real_hide (GtkWidget *widget)
1776 if (GTK_WIDGET_VISIBLE (widget))
1778 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1780 if (GTK_WIDGET_MAPPED (widget))
1781 gtk_widget_unmap (widget);
1786 * gtk_widget_hide_on_delete:
1787 * @widget: a #GtkWidget
1789 * Utility function; intended to be connected to the "delete_event"
1790 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
1791 * argument, then returns %TRUE. If connected to "delete_event", the
1792 * result is that clicking the close button for a window (on the
1793 * window frame, top right corner usually) will hide but not destroy
1794 * the window. By default, GTK+ destroys windows when "delete_event"
1797 * Return value: %TRUE
1800 gtk_widget_hide_on_delete (GtkWidget *widget)
1802 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1804 gtk_widget_hide (widget);
1810 * gtk_widget_show_all:
1811 * @widget: a #GtkWidget
1813 * Recursively shows a widget, and any child widgets (if the widget is
1817 gtk_widget_show_all (GtkWidget *widget)
1819 GtkWidgetClass *class;
1821 g_return_if_fail (GTK_IS_WIDGET (widget));
1823 class = GTK_WIDGET_GET_CLASS (widget);
1825 if (class->show_all)
1826 class->show_all (widget);
1830 * gtk_widget_hide_all:
1831 * @widget: a #GtkWidget
1833 * Recursively hides a widget and any child widgets.
1836 gtk_widget_hide_all (GtkWidget *widget)
1838 GtkWidgetClass *class;
1840 g_return_if_fail (GTK_IS_WIDGET (widget));
1842 class = GTK_WIDGET_GET_CLASS (widget);
1844 if (class->hide_all)
1845 class->hide_all (widget);
1850 * @widget: a #GtkWidget
1852 * This function is only for use in widget implementations. Causes
1853 * a widget to be mapped if it isn't already.
1857 gtk_widget_map (GtkWidget *widget)
1859 g_return_if_fail (GTK_IS_WIDGET (widget));
1860 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
1861 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
1863 if (!GTK_WIDGET_MAPPED (widget))
1865 if (!GTK_WIDGET_REALIZED (widget))
1866 gtk_widget_realize (widget);
1868 g_signal_emit (widget, widget_signals[MAP], 0);
1870 if (GTK_WIDGET_NO_WINDOW (widget))
1871 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
1877 * @widget: a #GtkWidget
1879 * This function is only for use in widget implementations. Causes
1880 * a widget to be unmapped if it's currently mapped.
1884 gtk_widget_unmap (GtkWidget *widget)
1886 g_return_if_fail (GTK_IS_WIDGET (widget));
1888 if (GTK_WIDGET_MAPPED (widget))
1890 if (GTK_WIDGET_NO_WINDOW (widget))
1891 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
1892 g_signal_emit (widget, widget_signals[UNMAP], 0);
1897 * gtk_widget_realize:
1898 * @widget: a #GtkWidget
1900 * Creates the GDK (windowing system) resources associated with a
1901 * widget. For example, @widget->window will be created when a widget
1902 * is realized. Normally realization happens implicitly; if you show
1903 * a widget and all its parent containers, then the widget will be
1904 * realized and mapped automatically.
1906 * Realizing a widget requires all
1907 * the widget's parent widgets to be realized; calling
1908 * gtk_widget_realize() realizes the widget's parents in addition to
1909 * @widget itself. If a widget is not yet inside a toplevel window
1910 * when you realize it, bad things will happen.
1912 * This function is primarily used in widget implementations, and
1913 * isn't very useful otherwise. Many times when you think you might
1914 * need it, a better approach is to connect to a signal that will be
1915 * called after the widget is realized automatically, such as
1916 * "expose_event". Or simply g_signal_connect_after() to the
1921 gtk_widget_realize (GtkWidget *widget)
1924 GdkExtensionMode mode;
1925 GtkWidgetShapeInfo *shape_info;
1927 g_return_if_fail (GTK_IS_WIDGET (widget));
1929 if (!GTK_WIDGET_REALIZED (widget))
1932 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1933 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
1936 if (widget->parent == NULL &&
1937 !GTK_WIDGET_TOPLEVEL (widget))
1938 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
1939 "inside a toplevel window is not going to work very well. "
1940 "Widgets must be inside a toplevel container before realizing them.");
1942 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
1943 gtk_widget_realize (widget->parent);
1945 gtk_widget_ensure_style (widget);
1947 g_signal_emit (widget, widget_signals[REALIZE], 0);
1949 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1951 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
1952 gdk_window_shape_combine_mask (widget->window,
1953 shape_info->shape_mask,
1954 shape_info->offset_x,
1955 shape_info->offset_y);
1958 if (!GTK_WIDGET_NO_WINDOW (widget))
1960 mode = gtk_widget_get_extension_events (widget);
1961 if (mode != GDK_EXTENSION_EVENTS_NONE)
1963 events = gtk_widget_get_events (widget);
1964 gdk_input_set_extension_events (widget->window, events, mode);
1972 * gtk_widget_unrealize:
1973 * @widget: a #GtkWidget
1975 * This function is only useful in widget implementations.
1976 * Causes a widget to be unrealized (frees all GDK resources
1977 * associated with the widget, such as @widget->window).
1981 gtk_widget_unrealize (GtkWidget *widget)
1983 g_return_if_fail (GTK_IS_WIDGET (widget));
1985 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1986 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
1988 if (GTK_WIDGET_REALIZED (widget))
1990 g_object_ref (widget);
1991 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
1992 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
1993 g_object_unref (widget);
1997 /*****************************************
1999 *****************************************/
2002 * gtk_widget_queue_draw_area:
2003 * @widget: a #GtkWidget
2004 * @x: x coordinate of upper-left corner of rectangle to redraw
2005 * @y: y coordinate of upper-left corner of rectangle to redraw
2006 * @width: width of region to draw
2007 * @height: height of region to draw
2009 * Invalidates the rectangular area of @widget defined by @x, @y,
2010 * @width and @height by calling gdk_window_invalidate_rect() on the
2011 * widget's window and all its child windows. Once the main loop
2012 * becomes idle (after the current batch of events has been processed,
2013 * roughly), the window will receive expose events for the union of
2014 * all regions that have been invalidated.
2016 * Normally you would only use this function in widget
2017 * implementations. You might also use it, or
2018 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2019 * #GtkDrawingArea or some portion thereof.
2021 * Frequently you can just call gdk_window_invalidate_rect() or
2022 * gdk_window_invalidate_region() instead of this function. Those
2023 * functions will invalidate only a single window, instead of the
2024 * widget and all its children.
2026 * The advantage of adding to the invalidated region compared to
2027 * simply drawing immediately is efficiency; using an invalid region
2028 * ensures that you only have to redraw one time.
2032 gtk_widget_queue_draw_area (GtkWidget *widget,
2038 GdkRectangle invalid_rect;
2041 g_return_if_fail (GTK_IS_WIDGET (widget));
2043 if (!GTK_WIDGET_REALIZED (widget))
2046 /* Just return if the widget or one of its ancestors isn't mapped */
2047 for (w = widget; w != NULL; w = w->parent)
2048 if (!GTK_WIDGET_MAPPED (w))
2051 /* Find the correct widget */
2053 if (!GTK_WIDGET_NO_WINDOW (widget))
2057 /* Translate widget relative to window-relative */
2059 gint wx, wy, wwidth, wheight;
2061 gdk_window_get_position (widget->window, &wx, &wy);
2062 x -= wx - widget->allocation.x;
2063 y -= wy - widget->allocation.y;
2065 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2067 if (x + width <= 0 || y + height <= 0 ||
2068 x >= wwidth || y >= wheight)
2079 if (x + width > wwidth)
2081 if (y + height > wheight)
2082 height = wheight - y;
2088 invalid_rect.width = width;
2089 invalid_rect.height = height;
2091 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2095 * gtk_widget_queue_draw:
2096 * @widget: a #GtkWidget
2098 * Equivalent to calling gtk_widget_queue_draw_area() for the
2099 * entire area of a widget.
2103 gtk_widget_queue_draw (GtkWidget *widget)
2105 g_return_if_fail (GTK_IS_WIDGET (widget));
2107 if (widget->allocation.width || widget->allocation.height)
2109 if (GTK_WIDGET_NO_WINDOW (widget))
2110 gtk_widget_queue_draw_area (widget, widget->allocation.x,
2111 widget->allocation.y,
2112 widget->allocation.width,
2113 widget->allocation.height);
2115 gtk_widget_queue_draw_area (widget, 0, 0,
2116 widget->allocation.width,
2117 widget->allocation.height);
2121 /* Invalidates the given area (allocation-relative-coordinates)
2122 * in all of the widget's windows
2125 * gtk_widget_queue_clear_area:
2126 * @widget: a #GtkWidget
2127 * @x: x coordinate of upper-left corner of rectangle to redraw
2128 * @y: y coordinate of upper-left corner of rectangle to redraw
2129 * @width: width of region to draw
2130 * @height: height of region to draw
2132 * DEPRECATED. This function is no longer different from
2133 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2134 * gtk_widget_queue_draw_area(). Originally
2135 * gtk_widget_queue_clear_area() would force a redraw of the
2136 * background for %GTK_NO_WINDOW widgets, and
2137 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2138 * the background will be redrawn.
2142 gtk_widget_queue_clear_area (GtkWidget *widget,
2148 g_return_if_fail (GTK_IS_WIDGET (widget));
2150 gtk_widget_queue_draw_area (widget, x, y, width, height);
2154 * gtk_widget_queue_clear:
2155 * @widget: a #GtkWidget
2157 * DEPRECATED. Use gtk_widget_queue_draw() instead.
2160 gtk_widget_queue_clear (GtkWidget *widget)
2162 g_return_if_fail (GTK_IS_WIDGET (widget));
2164 gtk_widget_queue_draw (widget);
2168 * gtk_widget_queue_resize:
2169 * @widget: a #GtkWidget
2171 * This function is only for use in widget implementations.
2172 * Flags a widget to have its size renegotiated; should
2173 * be called when a widget for some reason has a new size request.
2174 * For example, when you change the text in a #GtkLabel, #GtkLabel
2175 * queues a resize to ensure there's enough space for the new text.
2179 gtk_widget_queue_resize (GtkWidget *widget)
2183 g_return_if_fail (GTK_IS_WIDGET (widget));
2185 if (GTK_WIDGET_REALIZED (widget))
2187 region = gdk_region_rectangle (&widget->allocation);
2188 gtk_widget_invalidate_widget_windows (widget, region);
2189 gdk_region_destroy (region);
2192 _gtk_size_group_queue_resize (widget);
2197 * @widget: a #GtkWidget
2198 * @area: area to draw
2200 * DEPRECATED. In GTK+ 1.2, this function would immediately render the
2201 * region @area of a widget, by invoking the virtual draw method of a
2202 * widget. In GTK+ 2.0, the draw method is gone, and instead
2203 * gtk_widget_draw() simply invalidates the specified region of the
2204 * widget, then updates the invalid region of the widget immediately.
2205 * Usually you don't want to update the region immediately for
2206 * performance reasons, so in general gtk_widget_queue_draw_area() is
2207 * a better choice if you want to draw a region of a widget.
2211 gtk_widget_draw (GtkWidget *widget,
2214 g_return_if_fail (GTK_IS_WIDGET (widget));
2216 if (GTK_WIDGET_DRAWABLE (widget))
2219 gtk_widget_queue_draw_area (widget,
2221 area->width, area->height);
2223 gtk_widget_queue_draw (widget);
2225 gdk_window_process_updates (widget->window, TRUE);
2230 * gtk_widget_size_request:
2231 * @widget: a #GtkWidget
2232 * @requisition: a #GtkRequisition to be filled in
2234 * This function is typically used when implementing a #GtkContainer
2235 * subclass. Obtains the preferred size of a widget. The container
2236 * uses this information to arrange its child widgets and decide what
2237 * size allocations to give them with gtk_widget_size_allocate().
2239 * You can also call this function from an application, with some
2240 * caveats. Most notably, getting a size request requires the widget
2241 * to be associated with a screen, because font information may be
2242 * needed. Multihead-aware applications should keep this in mind.
2244 * Also remember that the size request is not necessarily the size
2245 * a widget will actually be allocated.
2247 * See also gtk_widget_get_child_requisition().
2250 gtk_widget_size_request (GtkWidget *widget,
2251 GtkRequisition *requisition)
2253 g_return_if_fail (GTK_IS_WIDGET (widget));
2255 #ifdef G_ENABLE_DEBUG
2256 if (requisition == &widget->requisition)
2257 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.");
2258 #endif /* G_ENABLE_DEBUG */
2260 _gtk_size_group_compute_requisition (widget, requisition);
2264 * gtk_widget_get_child_requisition:
2265 * @widget: a #GtkWidget
2266 * @requisition: a #GtkRequisition to be filled in
2268 * This function is only for use in widget implementations. Obtains
2269 * @widget->requisition, unless someone has forced a particular
2270 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2271 * case it returns that geometry instead of the widget's requisition.
2273 * This function differs from gtk_widget_size_request() in that
2274 * it retrieves the last size request value from @widget->requisition,
2275 * while gtk_widget_size_request() actually calls the "size_request" method
2276 * on @widget to compute the size request and fill in @widget->requisition,
2277 * and only then returns @widget->requisition.
2279 * Because this function does not call the "size_request" method, it
2280 * can only be used when you know that @widget->requisition is
2281 * up-to-date, that is, gtk_widget_size_request() has been called
2282 * since the last time a resize was queued. In general, only container
2283 * implementations have this information; applications should use
2284 * gtk_widget_size_request().
2287 gtk_widget_get_child_requisition (GtkWidget *widget,
2288 GtkRequisition *requisition)
2290 _gtk_size_group_get_child_requisition (widget, requisition);
2294 invalidate_predicate (GdkWindow *window,
2299 gdk_window_get_user_data (window, &user_data);
2301 return (user_data == data);
2304 /* Invalidate @region in widget->window and all children
2305 * of widget->window owned by widget. @region is in the
2306 * same coordinates as widget->allocation and will be
2307 * modified by this call.
2310 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2313 if (!GTK_WIDGET_NO_WINDOW (widget))
2317 gdk_window_get_position (widget->window, &x, &y);
2318 gdk_region_offset (region, -x, -y);
2321 gdk_window_invalidate_maybe_recurse (widget->window, region,
2322 invalidate_predicate, widget);
2326 * gtk_widget_size_allocate:
2327 * @widget: a #GtkWidget
2328 * @allocation: position and size to be allocated to @widget
2330 * This function is only used by #GtkContainer subclasses, to assign a size
2331 * and position to their child widgets.
2335 gtk_widget_size_allocate (GtkWidget *widget,
2336 GtkAllocation *allocation)
2338 GtkWidgetAuxInfo *aux_info;
2339 GdkRectangle real_allocation;
2340 GdkRectangle old_allocation;
2341 gboolean alloc_needed;
2342 gboolean size_changed;
2343 gboolean position_changed;
2345 g_return_if_fail (GTK_IS_WIDGET (widget));
2347 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2348 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2350 old_allocation = widget->allocation;
2351 real_allocation = *allocation;
2352 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2356 if (aux_info->x_set)
2357 real_allocation.x = aux_info->x;
2358 if (aux_info->y_set)
2359 real_allocation.y = aux_info->y;
2362 if (real_allocation.width < 0 || real_allocation.height < 0)
2364 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2365 real_allocation.width,
2366 real_allocation.height);
2369 real_allocation.width = MAX (real_allocation.width, 1);
2370 real_allocation.height = MAX (real_allocation.height, 1);
2372 size_changed = (old_allocation.width != real_allocation.width ||
2373 old_allocation.height != real_allocation.height);
2374 position_changed = (old_allocation.x != real_allocation.x ||
2375 old_allocation.y != real_allocation.y);
2377 if (!alloc_needed && !size_changed && !position_changed)
2380 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2382 if (GTK_WIDGET_MAPPED (widget))
2384 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2386 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2388 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2389 gdk_region_union_with_rect (invalidate, &old_allocation);
2391 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2392 gdk_region_destroy (invalidate);
2397 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2399 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2401 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2402 gdk_region_union_with_rect (invalidate, &old_allocation);
2404 gtk_widget_invalidate_widget_windows (widget, invalidate);
2405 gdk_region_destroy (invalidate);
2410 if ((size_changed || position_changed) && widget->parent &&
2411 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2413 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2414 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2415 gdk_region_destroy (invalidate);
2420 * gtk_widget_common_ancestor:
2421 * @widget_a: a #GtkWidget
2422 * @widget_b: a #GtkWidget
2424 * Find the common ancestor of @widget_a and @widget_b that
2425 * is closest to the two widgets.
2427 * Return value: the closest common ancestor of @widget_a and
2428 * @widget_b or %NULL if @widget_a and @widget_b do not
2429 * share a common ancestor.
2432 gtk_widget_common_ancestor (GtkWidget *widget_a,
2433 GtkWidget *widget_b)
2435 GtkWidget *parent_a;
2436 GtkWidget *parent_b;
2440 parent_a = widget_a;
2441 while (parent_a->parent)
2443 parent_a = parent_a->parent;
2447 parent_b = widget_b;
2448 while (parent_b->parent)
2450 parent_b = parent_b->parent;
2454 if (parent_a != parent_b)
2457 while (depth_a > depth_b)
2459 widget_a = widget_a->parent;
2463 while (depth_b > depth_a)
2465 widget_b = widget_b->parent;
2469 while (widget_a != widget_b)
2471 widget_a = widget_a->parent;
2472 widget_b = widget_b->parent;
2479 * gtk_widget_translate_coordinates:
2480 * @src_widget: a #GtkWidget
2481 * @dest_widget: a #GtkWidget
2482 * @src_x: X position relative to @src_widget
2483 * @src_y: Y position relative to @src_widget
2484 * @dest_x: location to store X position relative to @dest_widget
2485 * @dest_y: location to store Y position relative to @dest_widget
2487 * Translate coordinates relative to @src_widget's allocation to coordinates
2488 * relative to @dest_widget's allocations. In order to perform this
2489 * operation, both widgets must be realized, and must share a common
2492 * Return value: %FALSE if either widget was not realized, or there
2493 * was no common ancestor. In this case, nothing is stored in
2494 * *@dest_x and *@dest_y. Otherwise %TRUE.
2497 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2498 GtkWidget *dest_widget,
2504 GtkWidget *ancestor;
2507 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2508 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2510 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2511 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2514 /* Translate from allocation relative to window relative */
2515 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2518 gdk_window_get_position (src_widget->window, &wx, &wy);
2520 src_x -= wx - src_widget->allocation.x;
2521 src_y -= wy - src_widget->allocation.y;
2525 src_x += src_widget->allocation.x;
2526 src_y += src_widget->allocation.y;
2529 /* Translate to the common ancestor */
2530 window = src_widget->window;
2531 while (window != ancestor->window)
2535 gdk_window_get_position (window, &dx, &dy);
2540 window = gdk_window_get_parent (window);
2542 if (!window) /* Handle GtkHandleBox */
2547 window = dest_widget->window;
2548 while (window != ancestor->window)
2552 gdk_window_get_position (window, &dx, &dy);
2557 window = gdk_window_get_parent (window);
2559 if (!window) /* Handle GtkHandleBox */
2563 /* Translate from window relative to allocation relative */
2564 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2567 gdk_window_get_position (dest_widget->window, &wx, &wy);
2569 src_x += wx - dest_widget->allocation.x;
2570 src_y += wy - dest_widget->allocation.y;
2574 src_x -= dest_widget->allocation.x;
2575 src_y -= dest_widget->allocation.y;
2587 gtk_widget_real_size_allocate (GtkWidget *widget,
2588 GtkAllocation *allocation)
2590 widget->allocation = *allocation;
2592 if (GTK_WIDGET_REALIZED (widget) &&
2593 !GTK_WIDGET_NO_WINDOW (widget))
2595 gdk_window_move_resize (widget->window,
2596 allocation->x, allocation->y,
2597 allocation->width, allocation->height);
2607 closure_accel_activate (GClosure *closure,
2608 GValue *return_value,
2609 guint n_param_values,
2610 const GValue *param_values,
2611 gpointer invocation_hint,
2612 gpointer marshal_data)
2614 AccelClosure *aclosure = (AccelClosure*) closure;
2616 if (GTK_WIDGET_IS_SENSITIVE (closure->data))
2617 g_signal_emit (closure->data, aclosure->signal_id, 0);
2619 /* we handled the accelerator */
2620 g_value_set_boolean (return_value, TRUE);
2624 closures_destroy (gpointer data)
2626 GSList *slist, *closures = data;
2628 for (slist = closures; slist; slist = slist->next)
2630 g_closure_invalidate (slist->data);
2631 g_closure_unref (slist->data);
2633 g_slist_free (closures);
2637 widget_new_accel_closure (GtkWidget *widget,
2640 AccelClosure *aclosure;
2641 GClosure *closure = NULL;
2642 GSList *slist, *closures;
2644 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
2645 for (slist = closures; slist; slist = slist->next)
2646 if (!gtk_accel_group_from_accel_closure (slist->data))
2648 /* reuse this closure */
2649 closure = slist->data;
2654 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
2655 closures = g_slist_prepend (closures, g_closure_ref (closure));
2656 g_closure_sink (closure);
2657 g_closure_set_marshal (closure, closure_accel_activate);
2659 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
2661 aclosure = (AccelClosure*) closure;
2662 g_assert (closure->data == widget);
2663 g_assert (closure->marshal == closure_accel_activate);
2664 aclosure->signal_id = signal_id;
2670 * gtk_widget_add_accelerator
2671 * @widget: widget to install an accelerator on
2672 * @accel_signal: widget signal to emit on accelerator activation
2673 * @accel_group: accel group for this widget, added to its toplevel
2674 * @accel_key: GDK keyval of the accelerator
2675 * @accel_mods: modifier key combination of the accelerator
2676 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
2678 * Installs an accelerator for this @widget in @accel_group that causes
2679 * @accel_signal to be emitted if the accelerator is activated.
2680 * The @accel_group needs to be added to the widget's toplevel via
2681 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
2682 * Accelerators added through this function are not user changeable during
2683 * runtime. If you want to support accelerators that can be changed by the
2684 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
2685 * gtk_menu_item_set_accel_path() instead.
2688 gtk_widget_add_accelerator (GtkWidget *widget,
2689 const gchar *accel_signal,
2690 GtkAccelGroup *accel_group,
2692 GdkModifierType accel_mods,
2693 GtkAccelFlags accel_flags)
2698 g_return_if_fail (GTK_IS_WIDGET (widget));
2699 g_return_if_fail (accel_signal != NULL);
2700 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
2702 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
2703 if (!query.signal_id ||
2704 !(query.signal_flags & G_SIGNAL_ACTION) ||
2705 query.return_type != G_TYPE_NONE ||
2708 /* hmm, should be elaborate enough */
2709 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
2710 G_OBJECT_TYPE_NAME (widget), accel_signal);
2714 closure = widget_new_accel_closure (widget, query.signal_id);
2716 g_object_ref (widget);
2718 /* install the accelerator. since we don't map this onto an accel_path,
2719 * the accelerator will automatically be locked.
2721 gtk_accel_group_connect (accel_group,
2724 accel_flags | GTK_ACCEL_LOCKED,
2727 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2729 g_object_unref (widget);
2733 * gtk_widget_remove_accelerator:
2734 * @widget: widget to install an accelerator on
2735 * @accel_group: accel group for this widget
2736 * @accel_key: GDK keyval of the accelerator
2737 * @accel_mods: modifier key combination of the accelerator
2738 * @returns: whether an accelerator was installed and could be removed
2740 * Removes an accelerator from @widget, previously installed with
2741 * gtk_widget_add_accelerator().
2744 gtk_widget_remove_accelerator (GtkWidget *widget,
2745 GtkAccelGroup *accel_group,
2747 GdkModifierType accel_mods)
2749 GtkAccelGroupEntry *ag_entry;
2750 GList *slist, *clist;
2753 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2754 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
2756 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
2757 clist = gtk_widget_list_accel_closures (widget);
2758 for (slist = clist; slist; slist = slist->next)
2762 for (i = 0; i < n; i++)
2763 if (slist->data == (gpointer) ag_entry[i].closure)
2765 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
2767 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2769 g_list_free (clist);
2774 g_list_free (clist);
2776 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
2777 accel_key, accel_mods, accel_group,
2778 G_OBJECT_TYPE_NAME (widget), widget);
2784 * gtk_widget_list_accel_closures
2785 * @widget: widget to list accelerator closures for
2786 * @returns: a newly allocated #GList of closures
2788 * Lists the closures used by @widget for accelerator group connections
2789 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
2790 * The closures can be used to monitor accelerator changes on @widget,
2791 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
2792 * closure which can be found out with gtk_accel_group_from_accel_closure().
2795 gtk_widget_list_accel_closures (GtkWidget *widget)
2798 GList *clist = NULL;
2800 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2802 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
2803 if (gtk_accel_group_from_accel_closure (slist->data))
2804 clist = g_list_prepend (clist, slist->data);
2811 GtkAccelGroup *accel_group;
2816 destroy_accel_path (gpointer data)
2818 AccelPath *apath = data;
2820 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
2822 /* closures_destroy takes care of unrefing the closure */
2823 g_object_unref (apath->accel_group);
2830 * gtk_widget_set_accel_path:
2831 * @widget: a #GtkWidget
2832 * @accel_path: path used to look up the the accelerator
2833 * @accel_group: a #GtkAccelGroup.
2835 * Given an accelerator group, @accel_group, and an accelerator path,
2836 * @accel_path, sets up an accelerator in @accel_group so whenever the
2837 * key binding that is defined for @accel_path is pressed, @widget
2838 * will be activated. This removes any accelerators (for any
2839 * accelerator group) installed by previous calls to
2840 * gtk_widget_set_accel_path(). Associating accelerators with
2841 * paths allows them to be modified by the user and the modifications
2842 * to be saved for future use. (See gtk_accel_map_save().)
2844 * This function is a low level function that would most likely
2845 * be used by a menu creation system like #GtkItemFactory. If you
2846 * use #GtkItemFactory, setting up accelerator paths will be done
2849 * Even when you you aren't using #GtkItemFactory, if you only want to
2850 * set up accelerators on menu items gtk_menu_item_set_accel_path()
2851 * provides a somewhat more convenient interface.
2854 gtk_widget_set_accel_path (GtkWidget *widget,
2855 const gchar *accel_path,
2856 GtkAccelGroup *accel_group)
2860 g_return_if_fail (GTK_IS_WIDGET (widget));
2861 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
2865 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
2866 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
2868 gtk_accel_map_add_entry (accel_path, 0, 0);
2869 apath = g_new (AccelPath, 1);
2870 apath->widget = widget;
2871 apath->accel_group = g_object_ref (accel_group);
2872 apath->path_quark = g_quark_from_string (accel_path);
2873 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
2878 /* also removes possible old settings */
2879 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
2882 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
2884 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2888 _gtk_widget_get_accel_path (GtkWidget *widget,
2893 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2895 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
2897 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
2898 return apath ? g_quark_to_string (apath->path_quark) : NULL;
2902 gtk_widget_mnemonic_activate (GtkWidget *widget,
2903 gboolean group_cycling)
2907 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2909 group_cycling = group_cycling != FALSE;
2910 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2913 g_signal_emit (widget,
2914 widget_signals[MNEMONIC_ACTIVATE],
2922 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
2923 gboolean group_cycling)
2925 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
2926 gtk_widget_activate (widget);
2927 else if (GTK_WIDGET_CAN_FOCUS (widget))
2928 gtk_widget_grab_focus (widget);
2931 g_warning ("widget `%s' isn't suitable for mnemonic activation",
2932 G_OBJECT_TYPE_NAME (widget));
2933 gdk_display_beep (gtk_widget_get_display (widget));
2939 gtk_widget_real_key_press_event (GtkWidget *widget,
2942 return _gtk_bindings_activate_event (GTK_OBJECT (widget), event);
2946 gtk_widget_real_key_release_event (GtkWidget *widget,
2949 return _gtk_bindings_activate_event (GTK_OBJECT (widget), event);
2953 gtk_widget_real_focus_in_event (GtkWidget *widget,
2954 GdkEventFocus *event)
2956 gtk_widget_queue_draw (widget);
2962 gtk_widget_real_focus_out_event (GtkWidget *widget,
2963 GdkEventFocus *event)
2965 gtk_widget_queue_draw (widget);
2970 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
2971 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
2975 * @widget: a #GtkWidget
2976 * @event: a #GdkEvent
2978 * Rarely-used function. This function is used to emit
2979 * the event signals on a widget (those signals should never
2980 * be emitted without using this function to do so).
2981 * If you want to synthesize an event though, don't use this function;
2982 * instead, use gtk_main_do_event() so the event will behave as if
2983 * it were in the event queue. Don't synthesize expose events; instead,
2984 * use gdk_window_invalidate_rect() to invalidate a region of the
2987 * Return value: return from the event signal emission (%TRUE if the event was handled)
2990 gtk_widget_event (GtkWidget *widget,
2993 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2994 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
2996 if (event->type == GDK_EXPOSE)
2998 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
2999 "the same effect, call gdk_window_invalidate_rect/region(), "
3000 "followed by gdk_window_process_updates().");
3004 return gtk_widget_event_internal (widget, event);
3009 * gtk_widget_send_expose:
3010 * @widget: a #GtkWidget
3011 * @event: a expose #GdkEvent
3013 * Very rarely-used function. This function is used to emit
3014 * an expose event signals on a widget. This function is not
3015 * normally used directly. The only time it is used is when
3016 * propagating an expose event to a child %NO_WINDOW widget, and
3017 * that is normally done using gtk_container_propagate_expose().
3019 * If you want to force an area of a window to be redrawn,
3020 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3021 * To cause the redraw to be done immediately, follow that call
3022 * with a call to gdk_window_process_updates().
3024 * Return value: return from the event signal emission (%TRUE if the event was handled)
3027 gtk_widget_send_expose (GtkWidget *widget,
3030 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3031 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3032 g_return_val_if_fail (event != NULL, TRUE);
3033 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3035 if (event->type != GDK_EXPOSE)
3038 return gtk_widget_event_internal (widget, event);
3042 gtk_widget_event_internal (GtkWidget *widget,
3045 gboolean return_val = FALSE;
3047 g_object_ref (widget);
3049 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3050 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3055 switch (event->type)
3060 case GDK_BUTTON_PRESS:
3061 case GDK_2BUTTON_PRESS:
3062 case GDK_3BUTTON_PRESS:
3063 signal_num = BUTTON_PRESS_EVENT;
3066 signal_num = SCROLL_EVENT;
3068 case GDK_BUTTON_RELEASE:
3069 signal_num = BUTTON_RELEASE_EVENT;
3071 case GDK_MOTION_NOTIFY:
3072 signal_num = MOTION_NOTIFY_EVENT;
3075 signal_num = DELETE_EVENT;
3078 signal_num = DESTROY_EVENT;
3081 signal_num = KEY_PRESS_EVENT;
3083 case GDK_KEY_RELEASE:
3084 signal_num = KEY_RELEASE_EVENT;
3086 case GDK_ENTER_NOTIFY:
3087 signal_num = ENTER_NOTIFY_EVENT;
3089 case GDK_LEAVE_NOTIFY:
3090 signal_num = LEAVE_NOTIFY_EVENT;
3092 case GDK_FOCUS_CHANGE:
3093 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3096 signal_num = CONFIGURE_EVENT;
3099 signal_num = MAP_EVENT;
3102 signal_num = UNMAP_EVENT;
3104 case GDK_WINDOW_STATE:
3105 signal_num = WINDOW_STATE_EVENT;
3107 case GDK_PROPERTY_NOTIFY:
3108 signal_num = PROPERTY_NOTIFY_EVENT;
3110 case GDK_SELECTION_CLEAR:
3111 signal_num = SELECTION_CLEAR_EVENT;
3113 case GDK_SELECTION_REQUEST:
3114 signal_num = SELECTION_REQUEST_EVENT;
3116 case GDK_SELECTION_NOTIFY:
3117 signal_num = SELECTION_NOTIFY_EVENT;
3119 case GDK_PROXIMITY_IN:
3120 signal_num = PROXIMITY_IN_EVENT;
3122 case GDK_PROXIMITY_OUT:
3123 signal_num = PROXIMITY_OUT_EVENT;
3126 signal_num = NO_EXPOSE_EVENT;
3128 case GDK_CLIENT_EVENT:
3129 signal_num = CLIENT_EVENT;
3132 signal_num = EXPOSE_EVENT;
3134 case GDK_VISIBILITY_NOTIFY:
3135 signal_num = VISIBILITY_NOTIFY_EVENT;
3138 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3142 if (signal_num != -1)
3143 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3145 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3146 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3150 g_object_unref (widget);
3156 * gtk_widget_activate:
3157 * @widget: a #GtkWidget that's activatable
3159 * For widgets that can be "activated" (buttons, menu items, etc.)
3160 * this function activates them. Activation is what happens when you
3161 * press Enter on a widget during key navigation; clicking a button,
3162 * selecting a menu item, etc. If @widget isn't activatable,
3163 * the function returns %FALSE.
3165 * Return value: %TRUE if the widget was activatable
3168 gtk_widget_activate (GtkWidget *widget)
3170 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3172 if (WIDGET_CLASS (widget)->activate_signal)
3174 /* FIXME: we should eventually check the signals signature here */
3175 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3184 * gtk_widget_set_scroll_adjustments:
3185 * @widget: a #GtkWidget
3186 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3187 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3189 * For widgets that support scrolling, sets the scroll adjustments and
3190 * returns %TRUE. For widgets that don't support scrolling, does
3191 * nothing and returns %FALSE. Widgets that don't support scrolling
3192 * can be scrolled by placing them in a #GtkViewport, which does
3193 * support scrolling.
3195 * Return value: %TRUE if the widget supports scrolling
3198 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3199 GtkAdjustment *hadjustment,
3200 GtkAdjustment *vadjustment)
3202 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3204 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3206 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3208 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3210 /* FIXME: we should eventually check the signals signature here */
3211 g_signal_emit (widget,
3212 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3213 hadjustment, vadjustment);
3221 gtk_widget_reparent_subwindows (GtkWidget *widget,
3222 GdkWindow *new_window)
3224 if (GTK_WIDGET_NO_WINDOW (widget))
3226 GList *children = gdk_window_get_children (widget->window);
3229 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3232 GdkWindow *window = tmp_list->data;
3234 gdk_window_get_user_data (window, (void **)&child);
3235 while (child && child != widget)
3236 child = child->parent;
3239 gdk_window_reparent (window, new_window, 0, 0);
3242 g_list_free (children);
3245 gdk_window_reparent (widget->window, new_window, 0, 0);
3249 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3250 gpointer client_data)
3252 g_return_if_fail (client_data != NULL);
3254 if (GTK_WIDGET_NO_WINDOW (widget))
3257 g_object_unref (widget->window);
3258 widget->window = (GdkWindow*) client_data;
3260 g_object_ref (widget->window);
3262 if (GTK_IS_CONTAINER (widget))
3263 gtk_container_forall (GTK_CONTAINER (widget),
3264 gtk_widget_reparent_fixup_child,
3270 * gtk_widget_reparent:
3271 * @widget: a #GtkWidget
3272 * @new_parent: a #GtkContainer to move the widget into
3274 * Moves a widget from one #GtkContainer to another, handling reference
3275 * count issues to avoid destroying the widget.
3279 gtk_widget_reparent (GtkWidget *widget,
3280 GtkWidget *new_parent)
3282 g_return_if_fail (GTK_IS_WIDGET (widget));
3283 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3284 g_return_if_fail (widget->parent != NULL);
3286 if (widget->parent != new_parent)
3288 /* First try to see if we can get away without unrealizing
3289 * the widget as we reparent it. if so we set a flag so
3290 * that gtk_widget_unparent doesn't unrealize widget
3292 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3293 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3295 g_object_ref (widget);
3296 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3297 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3298 g_object_unref (widget);
3300 if (GTK_WIDGET_IN_REPARENT (widget))
3302 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3304 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3305 gtk_widget_reparent_fixup_child (widget,
3306 gtk_widget_get_parent_window (widget));
3309 g_object_notify (G_OBJECT (widget), "parent");
3314 * gtk_widget_intersect:
3315 * @widget: a #GtkWidget
3316 * @area: a rectangle
3317 * @intersection: rectangle to store intersection of @widget and @area
3319 * Computes the intersection of a @widget's area and @area, storing
3320 * the intersection in @intersection, and returns %TRUE if there was
3321 * an intersection. @intersection may be %NULL if you're only
3322 * interested in whether there was an intersection.
3324 * Return value: %TRUE if there was an intersection
3327 gtk_widget_intersect (GtkWidget *widget,
3329 GdkRectangle *intersection)
3335 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3336 g_return_val_if_fail (area != NULL, FALSE);
3339 dest = intersection;
3343 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3345 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3347 intersection->x -= widget->allocation.x;
3348 intersection->y -= widget->allocation.y;
3355 * gtk_widget_region_intersect:
3356 * @widget: a #GtkWidget
3357 * @region: a #GdkRegion, in the same coordinate system as
3358 * @widget->allocation. That is, relative to @widget->window
3359 * for %NO_WINDOW widgets; relative to the parent window
3360 * of @widget->window for widgets with their own window.
3361 * @returns: A newly allocated region holding the intersection of @widget
3362 * and @region. The coordinates of the return value are
3363 * relative to @widget->window for %NO_WINDOW widgets, and
3364 * relative to the parent window of @widget->window for
3365 * widgets with their own window.
3367 * Computes the intersection of a @widget's area and @region, returning
3368 * the intersection. The result may be empty, use gdk_region_empty() to
3372 gtk_widget_region_intersect (GtkWidget *widget,
3377 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3378 g_return_val_if_fail (region != NULL, NULL);
3380 dest = gdk_region_rectangle (&widget->allocation);
3382 gdk_region_intersect (dest, region);
3388 * gtk_widget_grab_focus:
3389 * @widget: a #GtkWidget
3391 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3392 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3393 * something like #GtkFrame won't work. (More precisely, it must have the
3394 * %GTK_CAN_FOCUS flag set.)
3398 gtk_widget_grab_focus (GtkWidget *widget)
3400 g_return_if_fail (GTK_IS_WIDGET (widget));
3402 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3405 g_object_ref (widget);
3406 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3407 g_object_notify (G_OBJECT (widget), "has_focus");
3408 g_object_unref (widget);
3412 reset_focus_recurse (GtkWidget *widget,
3415 if (GTK_IS_CONTAINER (widget))
3417 GtkContainer *container;
3419 container = GTK_CONTAINER (widget);
3420 gtk_container_set_focus_child (container, NULL);
3422 gtk_container_foreach (container,
3423 reset_focus_recurse,
3429 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3431 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3433 GtkWidget *toplevel;
3436 /* clear the current focus setting, break if the current widget
3437 * is the focus widget's parent, since containers above that will
3438 * be set by the next loop.
3440 toplevel = gtk_widget_get_toplevel (focus_widget);
3441 if (GTK_WIDGET_TOPLEVEL (toplevel))
3443 widget = GTK_WINDOW (toplevel)->focus_widget;
3445 if (widget == focus_widget)
3447 /* We call _gtk_window_internal_set_focus() here so that the
3448 * toplevel window can request the focus if necessary.
3449 * This is needed when the toplevel is a GtkPlug
3451 if (!GTK_WIDGET_HAS_FOCUS (widget))
3452 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3459 while (widget->parent && widget->parent != focus_widget->parent)
3461 widget = widget->parent;
3462 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3466 else if (toplevel != focus_widget)
3468 /* gtk_widget_grab_focus() operates on a tree without window...
3469 * actually, this is very questionable behaviour.
3472 gtk_container_foreach (GTK_CONTAINER (toplevel),
3473 reset_focus_recurse,
3477 /* now propagate the new focus up the widget tree and finally
3478 * set it on the window
3480 widget = focus_widget;
3481 while (widget->parent)
3483 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3484 widget = widget->parent;
3486 if (GTK_IS_WINDOW (widget))
3487 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3492 gtk_widget_real_show_help (GtkWidget *widget,
3493 GtkWidgetHelpType help_type)
3495 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3497 _gtk_tooltips_toggle_keyboard_mode (widget);
3505 gtk_widget_real_focus (GtkWidget *widget,
3506 GtkDirectionType direction)
3508 if (!GTK_WIDGET_CAN_FOCUS (widget))
3511 if (!gtk_widget_is_focus (widget))
3513 gtk_widget_grab_focus (widget);
3521 * gtk_widget_is_focus:
3522 * @widget: a #GtkWidget
3524 * Determines if the widget is the focus widget within its
3525 * toplevel. (This does not mean that the %HAS_FOCUS flag is
3526 * necessarily set; %HAS_FOCUS will only be set if the
3527 * toplevel widget additionally has the global input focus.)
3529 * Return value: %TRUE if the widget is the focus widget.
3532 gtk_widget_is_focus (GtkWidget *widget)
3534 GtkWidget *toplevel;
3536 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3538 toplevel = gtk_widget_get_toplevel (widget);
3540 if (GTK_IS_WINDOW (toplevel))
3541 return widget == GTK_WINDOW (toplevel)->focus_widget;
3547 * gtk_widget_grab_default:
3548 * @widget: a #GtkWidget
3550 * Causes @widget to become the default widget. @widget must have the
3551 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
3552 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
3553 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
3554 * presses Enter in a window. Default widgets must be activatable,
3555 * that is, gtk_widget_activate() should affect them.
3559 gtk_widget_grab_default (GtkWidget *widget)
3563 g_return_if_fail (GTK_IS_WIDGET (widget));
3564 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3566 window = gtk_widget_get_toplevel (widget);
3568 if (window && GTK_WIDGET_TOPLEVEL (window))
3569 gtk_window_set_default (GTK_WINDOW (window), widget);
3571 g_warning (G_STRLOC ": widget not within a GtkWindow");
3575 * gtk_widget_set_name:
3576 * @widget: a #GtkWidget
3577 * @name: name for the widget
3579 * Widgets can be named, which allows you to refer to them from a
3580 * gtkrc file. You can apply a style to widgets with a particular name
3581 * in the gtkrc file. See the documentation for gtkrc files (on the
3582 * same page as the docs for #GtkRcStyle).
3584 * Note that widget names are separated by periods in paths (see
3585 * gtk_widget_path()), so names with embedded periods may cause confusion.
3588 gtk_widget_set_name (GtkWidget *widget,
3591 g_return_if_fail (GTK_IS_WIDGET (widget));
3594 g_free (widget->name);
3595 widget->name = g_strdup (name);
3597 if (GTK_WIDGET_RC_STYLE (widget))
3598 gtk_widget_reset_rc_style (widget);
3600 g_object_notify (G_OBJECT (widget), "name");
3604 * gtk_widget_get_name:
3605 * @widget: a #GtkWidget
3607 * Retrieves the name of a widget. See gtk_widget_set_name() for the
3608 * significance of widget names.
3610 * Return value: name of the widget. This string is owned by GTK+ and
3611 * should not be modified or freed
3613 G_CONST_RETURN gchar*
3614 gtk_widget_get_name (GtkWidget *widget)
3616 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3619 return widget->name;
3620 return g_type_name (GTK_WIDGET_TYPE (widget));
3624 * gtk_widget_set_state:
3625 * @widget: a #GtkWidget
3626 * @state: new state for @widget
3628 * This function is for use in widget implementations. Sets the state
3629 * of a widget (insensitive, prelighted, etc.) Usually you should set
3630 * the state using wrapper functions such as gtk_widget_set_sensitive().
3634 gtk_widget_set_state (GtkWidget *widget,
3637 g_return_if_fail (GTK_IS_WIDGET (widget));
3639 if (state == GTK_WIDGET_STATE (widget))
3642 if (state == GTK_STATE_INSENSITIVE)
3643 gtk_widget_set_sensitive (widget, FALSE);
3649 data.state_restoration = FALSE;
3650 data.use_forall = FALSE;
3652 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3654 data.parent_sensitive = TRUE;
3656 gtk_widget_propagate_state (widget, &data);
3658 if (GTK_WIDGET_DRAWABLE (widget))
3659 gtk_widget_queue_draw (widget);
3664 gtk_widget_set_app_paintable (GtkWidget *widget,
3665 gboolean app_paintable)
3667 g_return_if_fail (GTK_IS_WIDGET (widget));
3669 app_paintable = (app_paintable != FALSE);
3671 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
3674 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
3676 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
3678 if (GTK_WIDGET_DRAWABLE (widget))
3679 gtk_widget_queue_draw (widget);
3681 g_object_notify (G_OBJECT (widget), "app_paintable");
3686 * gtk_widget_set_double_buffered:
3687 * @widget: a #GtkWidget
3688 * @double_buffered: %TRUE to double-buffer a widget
3690 * Widgets are double buffered by default; you can use this function
3691 * to turn off the buffering. "Double buffered" simply means that
3692 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
3693 * automatically around expose events sent to the
3694 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
3695 * window to an offscreen buffer, and gdk_window_end_paint() draws the
3696 * buffer to the screen. The result is that users see the window
3697 * update in one smooth step, and don't see individual graphics
3698 * primitives being rendered.
3700 * In very simple terms, double buffered widgets don't flicker,
3701 * so you would only use this function to turn off double buffering
3702 * if you had special needs and really knew what you were doing.
3706 gtk_widget_set_double_buffered (GtkWidget *widget,
3707 gboolean double_buffered)
3709 g_return_if_fail (GTK_IS_WIDGET (widget));
3711 if (double_buffered)
3712 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3714 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3718 * gtk_widget_set_redraw_on_allocate:
3719 * @widget: a #GtkWidget
3720 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
3721 * when it is allocated to a new size. Otherwise, only the
3722 * new portion of the widget will be redrawn.
3724 * Sets whether a when a widgets size allocation changes, the entire
3725 * widget is queued for drawing. By default, this setting is %TRUE and
3726 * the entire widget is redrawn on every size change. If your widget
3727 * leaves the upper left are unchanged when made bigger, turning this
3728 * setting on will improve performance.
3730 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
3731 * off all allocation on resizing: the widget will not even redraw if
3732 * its position changes; this is to allow containers that don't draw
3733 * anything to avoid excess invalidations. If you set this flag on a
3734 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
3735 * you are responsible for invalidating both the old and new allocation
3736 * of the widget when the widget is moved and responsible for invalidating
3737 * regions newly when the widget increases size.
3740 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
3741 gboolean redraw_on_allocate)
3743 g_return_if_fail (GTK_IS_WIDGET (widget));
3745 if (redraw_on_allocate)
3746 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3748 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3752 * gtk_widget_set_sensitive:
3753 * @widget: a #GtkWidget
3754 * @sensitive: %TRUE to make the widget sensitive
3756 * Sets the sensitivity of a widget. A widget is sensitive if the user
3757 * can interact with it. Insensitive widgets are "grayed out" and the
3758 * user can't interact with them. Insensitive widgets are known as
3759 * "inactive", "disabled", or "ghosted" in some other toolkits.
3763 gtk_widget_set_sensitive (GtkWidget *widget,
3768 g_return_if_fail (GTK_IS_WIDGET (widget));
3770 sensitive = (sensitive != FALSE);
3772 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
3777 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
3778 data.state = GTK_WIDGET_SAVED_STATE (widget);
3782 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
3783 data.state = GTK_WIDGET_STATE (widget);
3785 data.state_restoration = TRUE;
3786 data.use_forall = TRUE;
3789 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3791 data.parent_sensitive = TRUE;
3793 gtk_widget_propagate_state (widget, &data);
3794 if (GTK_WIDGET_DRAWABLE (widget))
3795 gtk_widget_queue_draw (widget);
3797 g_object_notify (G_OBJECT (widget), "sensitive");
3801 * gtk_widget_set_parent:
3802 * @widget: a #GtkWidget
3803 * @parent: parent container
3805 * This function is useful only when implementing subclasses of #GtkContainer.
3806 * Sets the container as the parent of @widget, and takes care of
3807 * some details such as updating the state and style of the child
3808 * to reflect its new location. The opposite function is
3809 * gtk_widget_unparent().
3813 gtk_widget_set_parent (GtkWidget *widget,
3818 g_return_if_fail (GTK_IS_WIDGET (widget));
3819 g_return_if_fail (widget->parent == NULL);
3820 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
3821 g_return_if_fail (GTK_IS_WIDGET (parent));
3822 g_return_if_fail (widget != parent);
3824 /* keep this function in sync with gtk_menu_attach_to_widget()
3827 g_object_ref (widget);
3828 gtk_object_sink (GTK_OBJECT (widget));
3829 widget->parent = parent;
3831 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
3832 data.state = GTK_WIDGET_STATE (parent);
3834 data.state = GTK_WIDGET_STATE (widget);
3835 data.state_restoration = FALSE;
3836 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
3837 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
3839 gtk_widget_propagate_state (widget, &data);
3841 gtk_widget_reset_rc_styles (widget);
3843 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
3844 if (GTK_WIDGET_ANCHORED (widget->parent))
3845 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
3846 g_object_notify (G_OBJECT (widget), "parent");
3848 /* Enforce realized/mapped invariants
3850 if (GTK_WIDGET_REALIZED (widget->parent))
3851 gtk_widget_realize (widget);
3853 if (GTK_WIDGET_VISIBLE (widget->parent) &&
3854 GTK_WIDGET_VISIBLE (widget))
3856 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
3857 GTK_WIDGET_MAPPED (widget->parent))
3858 gtk_widget_map (widget);
3860 gtk_widget_queue_resize (widget);
3865 * gtk_widget_get_parent:
3866 * @widget: a #GtkWidget
3868 * Returns the parent container of @widget.
3870 * Return value: the parent container of @widget, or %NULL
3873 gtk_widget_get_parent (GtkWidget *widget)
3875 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3877 return widget->parent;
3880 /*****************************************
3882 * see docs/styles.txt
3883 *****************************************/
3886 * gtk_widget_set_style:
3887 * @widget: a #GtkWidget
3888 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
3889 * gtk_widget_set_style() and go back to the default style
3891 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
3892 * want to use this function; it interacts badly with themes, because
3893 * themes work by replacing the #GtkStyle. Instead, use
3894 * gtk_widget_modify_style().
3898 gtk_widget_set_style (GtkWidget *widget,
3901 g_return_if_fail (GTK_IS_WIDGET (widget));
3905 gboolean initial_emission;
3907 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3909 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
3910 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
3912 gtk_widget_set_style_internal (widget, style, initial_emission);
3916 if (GTK_WIDGET_USER_STYLE (widget))
3917 gtk_widget_reset_rc_style (widget);
3922 * gtk_widget_ensure_style:
3923 * @widget: a #GtkWidget
3925 * Ensures that @widget has a style (@widget->style). Not a very useful
3926 * function; most of the time, if you want the style, the widget is
3927 * realized, and realized widgets are guaranteed to have a style
3932 gtk_widget_ensure_style (GtkWidget *widget)
3934 g_return_if_fail (GTK_IS_WIDGET (widget));
3936 if (!GTK_WIDGET_USER_STYLE (widget) &&
3937 !GTK_WIDGET_RC_STYLE (widget))
3938 gtk_widget_reset_rc_style (widget);
3941 /* Look up the RC style for this widget, unsetting any user style that
3942 * may be in effect currently
3945 gtk_widget_reset_rc_style (GtkWidget *widget)
3947 GtkStyle *new_style = NULL;
3948 gboolean initial_emission;
3950 g_return_if_fail (GTK_IS_WIDGET (widget));
3952 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3954 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3955 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
3957 if (gtk_widget_has_screen (widget))
3958 new_style = gtk_rc_get_style (widget);
3960 new_style = gtk_widget_get_default_style ();
3962 if (initial_emission || new_style != widget->style)
3963 gtk_widget_set_style_internal (widget, new_style, initial_emission);
3967 * gtk_widget_get_style:
3968 * @widget: a #GtkWidget
3970 * Simply an accessor function that returns @widget->style.
3972 * Return value: the widget's #GtkStyle
3975 gtk_widget_get_style (GtkWidget *widget)
3977 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3979 return widget->style;
3983 * gtk_widget_modify_style:
3984 * @widget: a #GtkWidget
3985 * @style: the #GtkRcStyle holding the style modifications
3987 * Modifies style values on the widget. Modifications made using this
3988 * technique take precedence over style values set via an RC file,
3989 * however, they will be overriden if a style is explicitely set on
3990 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
3991 * is designed so each field can either be set or unset, so it is
3992 * possible, using this function, to modify some style values and
3993 * leave the others unchanged.
3995 * Note that modifications made with this function are not cumulative
3996 * with previous calls to gtk_widget_modify_style() or with such
3997 * functions as gtk_widget_modify_fg(). If you wish to retain
3998 * previous values, you must first call gtk_widget_get_modifier_style(),
3999 * make your modifications to the returned style, then call
4000 * gtk_widget_modify_style() with that style. On the other hand,
4001 * if you first call gtk_widget_modify_style(), subsequent calls
4002 * to such functions gtk_widget_modify_fg() will have a cumulative
4003 * effect with the initial modifications.
4006 gtk_widget_modify_style (GtkWidget *widget,
4009 GtkRcStyle *old_style;
4011 g_return_if_fail (GTK_IS_WIDGET (widget));
4012 g_return_if_fail (GTK_IS_RC_STYLE (style));
4014 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4016 g_object_set_qdata_full (G_OBJECT (widget),
4018 gtk_rc_style_copy (style),
4019 (GDestroyNotify) gtk_rc_style_unref);
4021 /* note that "style" may be invalid here if it was the old
4022 * modifier style and the only reference was our own.
4025 if (GTK_WIDGET_RC_STYLE (widget))
4026 gtk_widget_reset_rc_style (widget);
4030 * gtk_widget_get_modifier_style:
4031 * @widget: a #GtkWidget
4033 * Returns the current modifier style for the widget. (As set by
4034 * gtk_widget_modify_style().) If no style has previously set, a new
4035 * #GtkRcStyle will be created with all values unset, and set as the
4036 * modifier style for the widget. If you make changes to this rc
4037 * style, you must call gtk_widget_modify_style(), passing in the
4038 * returned rc style, to make sure that your changes take effect.
4040 * Caution: passing the style back to gtk_widget_modify_style() will
4041 * normally end up destroying it, because gtk_widget_modify_style() copies
4042 * the passed-in style and sets the copy as the new modifier style,
4043 * thus dropping any reference to the old modifier style. Add a reference
4044 * to the modifier style if you want to keep it alive.
4046 * Return value: the modifier style for the widget. This rc style is
4047 * owned by the widget. If you want to keep a pointer to value this
4048 * around, you must add a refcount using gtk_rc_style_ref().
4051 gtk_widget_get_modifier_style (GtkWidget *widget)
4053 GtkRcStyle *rc_style;
4055 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4057 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4061 rc_style = gtk_rc_style_new ();
4062 g_object_set_qdata_full (G_OBJECT (widget),
4065 (GDestroyNotify) gtk_rc_style_unref);
4072 gtk_widget_modify_color_component (GtkWidget *widget,
4073 GtkRcFlags component,
4077 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4084 rc_style->fg[state] = *color;
4087 rc_style->bg[state] = *color;
4090 rc_style->text[state] = *color;
4093 rc_style->base[state] = *color;
4096 g_assert_not_reached();
4099 rc_style->color_flags[state] |= component;
4102 rc_style->color_flags[state] &= ~component;
4104 gtk_widget_modify_style (widget, rc_style);
4108 * gtk_widget_modify_fg:
4109 * @widget: a #GtkWidget.
4110 * @state: the state for which to set the foreground color.
4111 * @color: the color to assign (does not need to be allocated),
4112 * or %NULL to undo the effect of previous calls to
4113 * of gtk_widget_modify_fg().
4115 * Sets the foreground color for a widget in a particular state. All
4116 * other style values are left untouched. See also
4117 * gtk_widget_modify_style().
4120 gtk_widget_modify_fg (GtkWidget *widget,
4124 g_return_if_fail (GTK_IS_WIDGET (widget));
4125 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4127 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4131 * gtk_widget_modify_bg:
4132 * @widget: a #GtkWidget.
4133 * @state: the state for which to set the background color.
4134 * @color: the color to assign (does not need to be allocated),
4135 * or %NULL to undo the effect of previous calls to
4136 * of gtk_widget_modify_bg().
4138 * Sets the background color for a widget in a particular state. All
4139 * other style values are left untouched. See also
4140 * gtk_widget_modify_style().
4143 gtk_widget_modify_bg (GtkWidget *widget,
4147 g_return_if_fail (GTK_IS_WIDGET (widget));
4148 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4150 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4154 * gtk_widget_modify_text:
4155 * @widget: a #GtkWidget.
4156 * @state: the state for which to set the text color.
4157 * @color: the color to assign (does not need to be allocated),
4158 * or %NULL to undo the effect of previous calls to
4159 * of gtk_widget_modify_text().
4161 * Sets the text color for a widget in a particular state. All other
4162 * style values are left untouched. The text color is the foreground
4163 * color used along with the base color (see gtk_widget_modify_base())
4164 * for widgets such as #GtkEntry and #GtkTextView. See also
4165 * gtk_widget_modify_style().
4168 gtk_widget_modify_text (GtkWidget *widget,
4172 g_return_if_fail (GTK_IS_WIDGET (widget));
4173 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4175 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4179 * gtk_widget_modify_base:
4180 * @widget: a #GtkWidget.
4181 * @state: the state for which to set the base color.
4182 * @color: the color to assign (does not need to be allocated),
4183 * or %NULL to undo the effect of previous calls to
4184 * of gtk_widget_modify_base().
4186 * Sets the base color for a widget in a particular state.
4187 * All other style values are left untouched. The base color
4188 * is the background color used along with the text color
4189 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4190 * and #GtkTextView. See also gtk_widget_modify_style().
4193 gtk_widget_modify_base (GtkWidget *widget,
4197 g_return_if_fail (GTK_IS_WIDGET (widget));
4198 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4200 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4204 * gtk_widget_modify_font:
4205 * @widget: a #GtkWidget
4206 * @font_desc: the font description to use, or %NULL to undo
4207 * the effect of previous calls to gtk_widget_modify_font().
4209 * Sets the font to use for a widget. All other style values are left
4210 * untouched. See also gtk_widget_modify_style().
4213 gtk_widget_modify_font (GtkWidget *widget,
4214 PangoFontDescription *font_desc)
4216 GtkRcStyle *rc_style;
4218 g_return_if_fail (GTK_IS_WIDGET (widget));
4220 rc_style = gtk_widget_get_modifier_style (widget);
4222 if (rc_style->font_desc)
4223 pango_font_description_free (rc_style->font_desc);
4226 rc_style->font_desc = pango_font_description_copy (font_desc);
4228 rc_style->font_desc = NULL;
4230 gtk_widget_modify_style (widget, rc_style);
4234 gtk_widget_direction_changed (GtkWidget *widget,
4235 GtkTextDirection previous_direction)
4237 gtk_widget_queue_resize (widget);
4241 gtk_widget_style_set (GtkWidget *widget,
4242 GtkStyle *previous_style)
4244 if (GTK_WIDGET_REALIZED (widget) &&
4245 !GTK_WIDGET_NO_WINDOW (widget))
4246 gtk_style_set_background (widget->style, widget->window, widget->state);
4250 gtk_widget_set_style_internal (GtkWidget *widget,
4252 gboolean initial_emission)
4254 g_object_ref (widget);
4255 g_object_freeze_notify (G_OBJECT (widget));
4257 if (widget->style != style || initial_emission)
4259 PangoContext *context = gtk_widget_peek_pango_context (widget);
4261 pango_context_set_font_description (context, style->font_desc);
4264 if (widget->style != style)
4266 GtkStyle *previous_style;
4268 if (GTK_WIDGET_REALIZED (widget))
4270 gtk_widget_reset_shapes (widget);
4271 gtk_style_detach (widget->style);
4274 previous_style = widget->style;
4275 widget->style = style;
4276 g_object_ref (widget->style);
4278 if (GTK_WIDGET_REALIZED (widget))
4279 widget->style = gtk_style_attach (widget->style, widget->window);
4281 g_signal_emit (widget,
4282 widget_signals[STYLE_SET],
4284 initial_emission ? NULL : previous_style);
4285 g_object_unref (previous_style);
4287 if (widget->parent && !initial_emission)
4288 gtk_widget_queue_resize (widget);
4290 else if (initial_emission)
4291 g_signal_emit (widget,
4292 widget_signals[STYLE_SET],
4295 g_object_notify (G_OBJECT (widget), "style");
4296 g_object_thaw_notify (G_OBJECT (widget));
4297 g_object_unref (widget);
4301 GtkWidget *previous_toplevel;
4302 GdkScreen *previous_screen;
4303 GdkScreen *new_screen;
4304 } HierarchyChangedInfo;
4307 do_screen_change (GtkWidget *widget,
4308 GdkScreen *old_screen,
4309 GdkScreen *new_screen)
4311 if (old_screen != new_screen)
4315 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4317 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4320 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4325 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4326 gpointer client_data)
4328 gboolean new_anchored;
4329 HierarchyChangedInfo *info = client_data;
4331 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4332 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4334 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4336 g_object_ref (widget);
4339 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4341 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4343 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4344 do_screen_change (widget, info->previous_screen, info->new_screen);
4346 if (GTK_IS_CONTAINER (widget))
4347 gtk_container_forall (GTK_CONTAINER (widget),
4348 gtk_widget_propagate_hierarchy_changed_recurse,
4351 g_object_unref (widget);
4356 * _gtk_widget_propagate_hierarchy_changed:
4357 * @widget: a #GtkWidget
4358 * @previous_toplevel: Previous toplevel
4360 * Propagates changes in the anchored state to a widget and all
4361 * children, unsetting or setting the %ANCHORED flag, and
4362 * emitting ::hierarchy_changed.
4365 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4366 GtkWidget *previous_toplevel)
4368 HierarchyChangedInfo info;
4370 info.previous_toplevel = previous_toplevel;
4371 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4373 if (GTK_WIDGET_TOPLEVEL (widget) ||
4374 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4375 info.new_screen = gtk_widget_get_screen (widget);
4377 info.new_screen = NULL;
4379 if (info.previous_screen)
4380 g_object_ref (info.previous_screen);
4381 if (previous_toplevel)
4382 g_object_ref (previous_toplevel);
4384 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4386 if (previous_toplevel)
4387 g_object_unref (previous_toplevel);
4388 if (info.previous_screen)
4389 g_object_unref (info.previous_screen);
4393 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4394 gpointer client_data)
4396 HierarchyChangedInfo *info = client_data;
4398 g_object_ref (widget);
4400 do_screen_change (widget, info->previous_screen, info->new_screen);
4402 if (GTK_IS_CONTAINER (widget))
4403 gtk_container_forall (GTK_CONTAINER (widget),
4404 gtk_widget_propagate_screen_changed_recurse,
4407 g_object_unref (widget);
4411 * _gtk_widget_propagate_screen_changed:
4412 * @widget: a #GtkWidget
4413 * @previous_screen: Previous screen
4415 * Propagates changes in the screen for a widget to all
4416 * children, emitting ::screen_changed.
4419 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
4420 GdkScreen *previous_screen)
4422 HierarchyChangedInfo info;
4424 info.previous_screen = previous_screen;
4425 info.new_screen = gtk_widget_get_screen (widget);
4427 if (previous_screen)
4428 g_object_ref (previous_screen);
4430 gtk_widget_propagate_screen_changed_recurse (widget, &info);
4432 if (previous_screen)
4433 g_object_unref (previous_screen);
4437 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4439 if (GTK_WIDGET_RC_STYLE (widget))
4440 gtk_widget_reset_rc_style (widget);
4442 if (GTK_IS_CONTAINER (widget))
4443 gtk_container_forall (GTK_CONTAINER (widget),
4444 reset_rc_styles_recurse,
4449 gtk_widget_reset_rc_styles (GtkWidget *widget)
4451 g_return_if_fail (GTK_IS_WIDGET (widget));
4453 reset_rc_styles_recurse (widget, NULL);
4457 * gtk_widget_get_default_style:
4459 * Returns the default style used by all widgets initially.
4461 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4462 * should not be modified or freed.
4465 gtk_widget_get_default_style (void)
4467 if (!gtk_default_style)
4469 gtk_default_style = gtk_style_new ();
4470 g_object_ref (gtk_default_style);
4473 return gtk_default_style;
4476 static PangoContext *
4477 gtk_widget_peek_pango_context (GtkWidget *widget)
4479 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4483 * gtk_widget_get_pango_context:
4484 * @widget: a #GtkWidget
4486 * Gets a #PangoContext with the appropriate colormap, font description
4487 * and base direction for this widget. Unlike the context returned
4488 * by gtk_widget_create_pango_context(), this context is owned by
4489 * the widget (it can be used until the screen for the widget changes
4490 * or the widget is removed from its toplevel), and will be updated to
4491 * match any changes to the widget's attributes.
4493 * If you create and keep a #PangoLayout using this context, you must
4494 * deal with changes to the context by calling pango_layout_context_changed()
4495 * on the layout in response to the ::style_set and ::direction_set signals
4498 * Return value: the #PangoContext for the widget.
4501 gtk_widget_get_pango_context (GtkWidget *widget)
4503 PangoContext *context;
4505 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4507 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4510 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4511 g_object_set_qdata_full (G_OBJECT (widget),
4512 quark_pango_context,
4521 * gtk_widget_create_pango_context:
4522 * @widget: a #GtkWidget
4524 * Creates a new #PangoContext with the appropriate colormap,
4525 * font description, and base direction for drawing text for
4526 * this widget. See also gtk_widget_get_pango_context().
4528 * Return value: the new #PangoContext
4531 gtk_widget_create_pango_context (GtkWidget *widget)
4534 PangoContext *context;
4536 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4538 screen = gtk_widget_get_screen_unchecked (widget);
4541 GTK_NOTE (MULTIHEAD,
4542 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
4544 screen = gdk_screen_get_default ();
4547 context = gdk_pango_context_get_for_screen (screen);
4549 gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
4550 pango_context_set_base_dir (context,
4551 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4552 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4553 pango_context_set_font_description (context, widget->style->font_desc);
4554 pango_context_set_language (context, gtk_get_default_language ());
4560 * gtk_widget_create_pango_layout:
4561 * @widget: a #GtkWidget
4562 * @text: text to set on the layout (can be %NULL)
4564 * Creates a new #PangoLayout with the appropriate colormap,
4565 * font description, and base direction for drawing text for
4568 * If you keep a #PangoLayout created in this way around, in order
4569 * notify the layout of changes to the base direction or font of this
4570 * widget, you must call pango_layout_context_changed() in response to
4571 * the ::style_set and ::direction_set signals for the widget.
4573 * Return value: the new #PangoLayout
4576 gtk_widget_create_pango_layout (GtkWidget *widget,
4579 PangoLayout *layout;
4580 PangoContext *context;
4582 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4584 context = gtk_widget_get_pango_context (widget);
4585 layout = pango_layout_new (context);
4588 pango_layout_set_text (layout, text, -1);
4594 * gtk_widget_render_icon:
4595 * @widget: a #GtkWidget
4596 * @stock_id: a stock ID
4597 * @size: a stock size
4598 * @detail: render detail to pass to theme engine
4600 * A convenience function that uses the theme engine and RC file
4601 * settings for @widget to look up @stock_id and render it to
4602 * a pixbuf. @stock_id should be a stock icon ID such as
4603 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
4604 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
4605 * identifies the widget or code doing the rendering, so that
4606 * theme engines can special-case rendering for that widget or code.
4608 * The pixels in the returned #GdkPixbuf are shared with the rest of
4609 * the application and should not be modified. The pixbuf should be freed
4610 * after use with g_object_unref().
4612 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
4615 gtk_widget_render_icon (GtkWidget *widget,
4616 const gchar *stock_id,
4618 const gchar *detail)
4620 GtkIconSet *icon_set;
4623 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4624 g_return_val_if_fail (stock_id != NULL, NULL);
4625 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
4627 gtk_widget_ensure_style (widget);
4629 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
4631 if (icon_set == NULL)
4634 retval = gtk_icon_set_render_icon (icon_set,
4636 gtk_widget_get_direction (widget),
4637 GTK_WIDGET_STATE (widget),
4646 * gtk_widget_set_parent_window:
4647 * @widget: a #GtkWidget.
4648 * @parent_window: the new parent window.
4650 * Sets a non default parent window for @widget.
4653 gtk_widget_set_parent_window (GtkWidget *widget,
4654 GdkWindow *parent_window)
4656 GdkWindow *old_parent_window;
4658 g_return_if_fail (GTK_IS_WIDGET (widget));
4660 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
4661 quark_parent_window);
4663 if (parent_window != old_parent_window)
4665 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
4667 if (old_parent_window)
4668 g_object_unref (old_parent_window);
4670 g_object_ref (parent_window);
4676 * gtk_widget_set_child_visible:
4677 * @widget: a #GtkWidget
4678 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
4680 * Sets whether @widget should be mapped along with its when its parent
4681 * is mapped and @widget has been shown with gtk_widget_show().
4683 * The child visibility can be set for widget before it is added to
4684 * a container with gtk_widget_set_parent(), to avoid mapping
4685 * children unnecessary before immediately unmapping them. However
4686 * it will be reset to its default state of %TRUE when the widget
4687 * is removed from a container.
4689 * Note that changing the child visibility of a widget does not
4690 * queue a resize on the widget. Most of the time, the size of
4691 * a widget is computed from all visible children, whether or
4692 * not they are mapped. If this is not the case, the container
4693 * can queue a resize itself.
4695 * This function is only useful for container implementations and
4696 * never should be called by an application.
4699 gtk_widget_set_child_visible (GtkWidget *widget,
4700 gboolean is_visible)
4702 g_return_if_fail (GTK_IS_WIDGET (widget));
4703 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
4706 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
4709 GtkWidget *toplevel;
4711 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
4713 toplevel = gtk_widget_get_toplevel (widget);
4714 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
4715 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4718 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
4720 if (GTK_WIDGET_MAPPED (widget->parent) &&
4721 GTK_WIDGET_CHILD_VISIBLE (widget) &&
4722 GTK_WIDGET_VISIBLE (widget))
4723 gtk_widget_map (widget);
4725 gtk_widget_unmap (widget);
4730 * gtk_widget_get_child_visible:
4731 * @widget: a #GtkWidget
4733 * Gets the value set with gtk_widget_set_child_visible().
4734 * If you feel a need to use this function, your code probably
4735 * needs reorganization.
4737 * This function is only useful for container implementations and
4738 * never should be called by an application.
4740 * Return value: %TRUE if the widget is mapped with the parent.
4743 gtk_widget_get_child_visible (GtkWidget *widget)
4745 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4747 return GTK_WIDGET_CHILD_VISIBLE (widget);
4751 gtk_widget_get_screen_unchecked (GtkWidget *widget)
4753 GtkWidget *toplevel;
4755 toplevel = gtk_widget_get_toplevel (widget);
4757 if (GTK_WIDGET_TOPLEVEL (toplevel))
4759 if (GTK_IS_WINDOW (toplevel))
4760 return GTK_WINDOW (toplevel)->screen;
4761 else if (GTK_IS_INVISIBLE (toplevel))
4762 return GTK_INVISIBLE (widget)->screen;
4769 * gtk_widget_get_screen:
4770 * @widget: a #GtkWidget
4772 * Get the #GdkScreen from the toplevel window associated with
4773 * this widget. This function can only be called after the widget
4774 * has been added to a widget hierarchy with a #GtkWindow
4777 * In general, you should only create screen specific
4778 * resources when a widget has been realized, and you should
4779 * free those resources when the widget is unrealized.
4781 * Return value: the #GdkScreen for the toplevel for this widget.
4786 gtk_widget_get_screen (GtkWidget *widget)
4790 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4792 screen = gtk_widget_get_screen_unchecked (widget);
4799 g_warning (G_STRLOC ": Can't get associated screen"
4800 " for a widget unless it is inside a toplevel GtkWindow\n"
4801 " widget type is %s associated top level type is %s",
4802 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
4803 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
4805 return gdk_screen_get_default ();
4810 * gtk_widget_has_screen:
4811 * @widget: a #GtkWidget
4813 * Checks whether there is a #GdkScreen is associated with
4814 * this widget. All toplevel widgets have an associated
4815 * screen, and all widgets added into a heirarchy with a toplevel
4816 * window at the top.
4818 * Return value: %TRUE if there is a #GdkScreen associcated
4824 gtk_widget_has_screen (GtkWidget *widget)
4826 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4828 return (gtk_widget_get_screen_unchecked (widget) != NULL);
4832 * gtk_widget_get_display:
4833 * @widget: a #GtkWidget
4835 * Get the #GdkDisplay for the toplevel window associated with
4836 * this widget. This function can only be called after the widget
4837 * has been added to a widget hierarchy with a #GtkWindow at the top.
4839 * In general, you should only create display specific
4840 * resources when a widget has been realized, and you should
4841 * free those resources when the widget is unrealized.
4843 * Return value: the #GdkDisplay for the toplevel for this widget.
4848 gtk_widget_get_display (GtkWidget *widget)
4850 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4852 return gdk_screen_get_display (gtk_widget_get_screen (widget));
4856 * gtk_widget_get_root_window:
4857 * @widget: a #GtkWidget
4859 * Get the root window where this widget is located. This function can
4860 * only be called after the widget has been added to a widget
4861 * heirarchy with #GtkWindow at the top.
4863 * The root window is useful for such purposes as creating a popup
4864 * #GdkWindow associated with the window. In general, you should only
4865 * create display specific resources when a widget has been realized,
4866 * and you should free those resources when the widget is unrealized.
4868 * Return value: the #GdkWindow root window for the toplevel for this widget.
4873 gtk_widget_get_root_window (GtkWidget *widget)
4875 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4877 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
4881 * gtk_widget_get_parent_window:
4882 * @widget: a #GtkWidget.
4883 * @returns: the parent window of @widget.
4885 * Gets @widget's parent window.
4888 gtk_widget_get_parent_window (GtkWidget *widget)
4890 GdkWindow *parent_window;
4892 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4893 g_return_val_if_fail (widget->parent != NULL, NULL);
4895 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
4897 return (parent_window != NULL) ? parent_window : widget->parent->window;
4901 * gtk_widget_child_focus:
4902 * @widget: a #GtkWidget
4903 * @direction: direction of focus movement
4905 * This function is used by custom widget implementations; if you're
4906 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
4907 * to a particular widget, and gtk_container_set_focus_chain() to
4908 * change the focus tab order. So you may want to investigate those
4909 * functions instead.
4911 * gtk_widget_child_focus() is called by containers as the user moves
4912 * around the window using keyboard shortcuts. @direction indicates
4913 * what kind of motion is taking place (up, down, left, right, tab
4914 * forward, tab backward). gtk_widget_child_focus() invokes the
4915 * "focus" signal on #GtkWidget; widgets override the default handler
4916 * for this signal in order to implement appropriate focus behavior.
4918 * The "focus" default handler for a widget should return %TRUE if
4919 * moving in @direction left the focus on a focusable location inside
4920 * that widget, and %FALSE if moving in @direction moved the focus
4921 * outside the widget. If returning %TRUE, widgets normally
4922 * call gtk_widget_grab_focus() to place the focus accordingly;
4923 * if returning %FALSE, they don't modify the current focus location.
4925 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
4926 * necessary to check that the child was visible, sensitive, and
4927 * focusable before calling
4928 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
4929 * the widget is not currently in a focusable state, so there's no
4930 * need for those checks.
4932 * Return value: %TRUE if focus ended up inside @widget
4935 gtk_widget_child_focus (GtkWidget *widget,
4936 GtkDirectionType direction)
4938 gboolean return_val;
4940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4942 if (!GTK_WIDGET_VISIBLE (widget) ||
4943 !GTK_WIDGET_IS_SENSITIVE (widget))
4946 /* child widgets must set CAN_FOCUS, containers
4947 * don't have to though.
4949 if (!GTK_IS_CONTAINER (widget) &&
4950 !GTK_WIDGET_CAN_FOCUS (widget))
4953 g_signal_emit (widget,
4954 widget_signals[FOCUS],
4956 direction, &return_val);
4962 * gtk_widget_set_uposition:
4963 * @widget: a #GtkWidget
4964 * @x: x position; -1 to unset x; -2 to leave x unchanged
4965 * @y: y position; -1 to unset y; -2 to leave y unchanged
4968 * Sets the position of a widget. The funny "u" in the name comes from
4969 * the "user position" hint specified by the X Window System, and
4970 * exists for legacy reasons. This function doesn't work if a widget
4971 * is inside a container; it's only really useful on #GtkWindow.
4973 * Don't use this function to center dialogs over the main application
4974 * window; most window managers will do the centering on your behalf
4975 * if you call gtk_window_set_transient_for(), and it's really not
4976 * possible to get the centering to work correctly in all cases from
4977 * application code. But if you insist, use gtk_window_set_position()
4978 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
4981 * Note that although @x and @y can be individually unset, the position
4982 * is not honoured unless both @x and @y are set.
4985 gtk_widget_set_uposition (GtkWidget *widget,
4989 /* FIXME this function is the only place that aux_info->x and
4990 * aux_info->y are even used I believe, and this function is
4991 * deprecated. Should be cleaned up.
4993 * (Actually, size_allocate uses them) -Yosh
4996 GtkWidgetAuxInfo *aux_info;
4998 g_return_if_fail (GTK_IS_WIDGET (widget));
5000 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5005 aux_info->x_set = FALSE;
5008 aux_info->x_set = TRUE;
5016 aux_info->y_set = FALSE;
5019 aux_info->y_set = TRUE;
5024 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5025 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5027 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5028 gtk_widget_size_allocate (widget, &widget->allocation);
5032 gtk_widget_set_usize_internal (GtkWidget *widget,
5036 GtkWidgetAuxInfo *aux_info;
5038 g_return_if_fail (GTK_IS_WIDGET (widget));
5040 g_object_freeze_notify (G_OBJECT (widget));
5042 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5046 g_object_notify (G_OBJECT (widget), "width_request");
5047 aux_info->width = width;
5051 g_object_notify (G_OBJECT (widget), "height_request");
5052 aux_info->height = height;
5055 if (GTK_WIDGET_VISIBLE (widget))
5056 gtk_widget_queue_resize (widget);
5058 g_object_thaw_notify (G_OBJECT (widget));
5062 * gtk_widget_set_usize:
5063 * @widget: a #GtkWidget
5064 * @width: minimum width, or -1 to unset
5065 * @height: minimum height, or -1 to unset
5067 * This function is deprecated; use gtk_widget_set_size_request()
5070 * Sets the minimum size of a widget; that is, the widget's size
5071 * request will be @width by @height. You can use this function to
5072 * force a widget to be either larger or smaller than it is. The
5073 * strange "usize" name dates from the early days of GTK+, and derives
5074 * from X Window System terminology. In many cases,
5075 * gtk_window_set_default_size() is a better choice for toplevel
5076 * windows than this function; setting the default size will still
5077 * allow users to shrink the window. Setting the usize will force them
5078 * to leave the window at least as large as the usize. When dealing
5079 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5082 * Note the inherent danger of setting any fixed size - themes,
5083 * translations into other languages, different fonts, and user action
5084 * can all change the appropriate size for a given widget. So, it's
5085 * basically impossible to hardcode a size that will always be
5090 gtk_widget_set_usize (GtkWidget *widget,
5094 g_return_if_fail (GTK_IS_WIDGET (widget));
5096 gtk_widget_set_usize_internal (widget, width, height);
5100 * gtk_widget_set_size_request:
5101 * @widget: a #GtkWidget
5102 * @width: width @widget should request, or -1 to unset
5103 * @height: height @widget should request, or -1 to unset
5105 * Sets the minimum size of a widget; that is, the widget's size
5106 * request will be @width by @height. You can use this function to
5107 * force a widget to be either larger or smaller than it normally
5110 * In most cases, gtk_window_set_default_size() is a better choice for
5111 * toplevel windows than this function; setting the default size will
5112 * still allow users to shrink the window. Setting the size request
5113 * will force them to leave the window at least as large as the size
5114 * request. When dealing with window sizes,
5115 * gtk_window_set_geometry_hints() can be a useful function as well.
5117 * Note the inherent danger of setting any fixed size - themes,
5118 * translations into other languages, different fonts, and user action
5119 * can all change the appropriate size for a given widget. So, it's
5120 * basically impossible to hardcode a size that will always be
5123 * The size request of a widget is the smallest size a widget can
5124 * accept while still functioning well and drawing itself correctly.
5125 * However in some strange cases a widget may be allocated less than
5126 * its requested size, and in many cases a widget may be allocated more
5127 * space than it requested.
5129 * If the size request in a given direction is -1 (unset), then
5130 * the "natural" size request of the widget will be used instead.
5132 * Widgets can't actually be allocated a size less than 1 by 1, but
5133 * you can pass 0,0 to this function to mean "as small as possible."
5136 gtk_widget_set_size_request (GtkWidget *widget,
5140 g_return_if_fail (GTK_IS_WIDGET (widget));
5141 g_return_if_fail (width >= -1);
5142 g_return_if_fail (height >= -1);
5149 gtk_widget_set_usize_internal (widget, width, height);
5154 * gtk_widget_get_size_request:
5155 * @widget: a #GtkWidget
5156 * @width: return location for width, or %NULL
5157 * @height: return location for height, or %NULL
5159 * Gets the size request that was explicitly set for the widget using
5160 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5161 * @height indicates that that dimension has not been set explicitly
5162 * and the natural requisition of the widget will be used intead. See
5163 * gtk_widget_set_size_request(). To get the size a widget will
5164 * actually use, call gtk_widget_size_request() instead of
5170 gtk_widget_get_size_request (GtkWidget *widget,
5174 GtkWidgetAuxInfo *aux_info;
5176 g_return_if_fail (GTK_IS_WIDGET (widget));
5178 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5181 *width = aux_info ? aux_info->width : -1;
5184 *height = aux_info ? aux_info->height : -1;
5188 * gtk_widget_set_events:
5189 * @widget: a #GtkWidget
5190 * @events: event mask
5192 * Sets the event mask (see #GdkEventMask) for a widget. The event
5193 * mask determines which events a widget will receive. Keep in mind
5194 * that different widgets have different default event masks, and by
5195 * changing the event mask you may disrupt a widget's functionality,
5196 * so be careful. This function must be called while a widget is
5197 * unrealized. Consider gtk_widget_add_events() for widgets that are
5198 * already realized, or if you want to preserve the existing event
5199 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5200 * to get events on those widgets, place them inside a #GtkEventBox
5201 * and receive events on the event box.
5205 gtk_widget_set_events (GtkWidget *widget,
5210 g_return_if_fail (GTK_IS_WIDGET (widget));
5211 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5213 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5218 eventp = g_new (gint, 1);
5221 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5226 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5229 g_object_notify (G_OBJECT (widget), "events");
5233 * gtk_widget_add_events:
5234 * @widget: a #GtkWidget
5235 * @events: an event mask, see #GdkEventMask
5237 * Adds the events in the bitfield @events to the event mask for
5238 * @widget. See gtk_widget_set_events() for details.
5242 gtk_widget_add_events (GtkWidget *widget,
5247 g_return_if_fail (GTK_IS_WIDGET (widget));
5249 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5255 eventp = g_new (gint, 1);
5260 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5265 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5268 if (GTK_WIDGET_REALIZED (widget))
5270 if (GTK_WIDGET_NO_WINDOW (widget))
5272 GList *children = gdk_window_get_children (widget->window);
5273 GList *tmp_list = children;
5277 GdkWindow *window = tmp_list->data;
5280 gdk_window_get_user_data (window, &user_data);
5281 if (user_data == widget)
5282 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5283 tmp_list = tmp_list->next;
5286 g_list_free (children);
5290 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5294 g_object_notify (G_OBJECT (widget), "events");
5298 * gtk_widget_set_extension_events:
5299 * @widget: a #GtkWidget
5300 * @mode: bitfield of extension events to receive
5302 * Sets the extension events mask to @mode. See #GdkExtensionMode
5303 * and gdk_input_set_extension_events().
5307 gtk_widget_set_extension_events (GtkWidget *widget,
5308 GdkExtensionMode mode)
5310 GdkExtensionMode *modep;
5312 g_return_if_fail (GTK_IS_WIDGET (widget));
5314 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5317 modep = g_new (GdkExtensionMode, 1);
5320 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5321 g_object_notify (G_OBJECT (widget), "extension_events");
5325 * gtk_widget_get_toplevel:
5326 * @widget: a #GtkWidget
5328 * This function returns the topmost widget in the container hierarchy
5329 * @widget is a part of. If @widget has no parent widgets, it will be
5330 * returned as the topmost widget. No reference will be added to the
5331 * returned widget; it should not be unreferenced.
5333 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5334 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5336 * %NULL if @widget wasn't inside a toplevel window, and if the
5337 * window was inside a #GtkWindow-derived widget which was in turn
5338 * inside the toplevel #GtkWindow. While the second case may
5339 * seem unlikely, it actually happens when a #GtkPlug is embedded
5340 * inside a #GtkSocket within the same application.
5342 * To reliably find the toplevel #GtkWindow, use
5343 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5344 * is set on the result.
5345 * <informalexample><programlisting>
5346 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5347 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5349 * [ Perform action on toplevel. ]
5351 * </programlisting></informalexample>
5353 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5356 gtk_widget_get_toplevel (GtkWidget *widget)
5358 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5360 while (widget->parent)
5361 widget = widget->parent;
5367 * gtk_widget_get_ancestor:
5368 * @widget: a #GtkWidget
5369 * @widget_type: ancestor type
5371 * Gets the first ancestor of @widget with type @widget_type. For example,
5372 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5373 * first #GtkBox that's
5374 * an ancestor of @widget. No reference will be added to the returned widget;
5375 * it should not be unreferenced. See note about checking for a toplevel
5376 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5378 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
5379 * considers @widget to be an ancestor of itself.
5381 * Return value: the ancestor widget, or %NULL if not found
5384 gtk_widget_get_ancestor (GtkWidget *widget,
5387 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5389 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5390 widget = widget->parent;
5392 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5399 * gtk_widget_get_colormap:
5400 * @widget: a #GtkWidget
5402 * Gets the colormap that will be used to render @widget. No reference will
5403 * be added to the returned colormap; it should not be unreferenced.
5405 * Return value: the colormap used by @widget
5408 gtk_widget_get_colormap (GtkWidget *widget)
5410 GdkColormap *colormap;
5411 GtkWidget *tmp_widget;
5413 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5417 colormap = gdk_drawable_get_colormap (widget->window);
5418 /* If window was destroyed previously, we'll get NULL here */
5423 tmp_widget = widget;
5426 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5430 tmp_widget= tmp_widget->parent;
5433 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5437 * gtk_widget_get_visual:
5438 * @widget: a #GtkWidget
5440 * Gets the visual that will be used to render @widget.
5442 * Return value: the visual for @widget
5445 gtk_widget_get_visual (GtkWidget *widget)
5447 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5449 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5453 * gtk_widget_get_settings:
5454 * @widget: a #GtkWidget
5456 * Gets the settings object holding the settings (global property
5457 * settings, RC file information, etc) used for this widget.
5459 * Note that this function can only be called when the #GtkWidget
5460 * is attached to a toplevel, since the settings object is specific
5461 * to a particular #GdkScreen.
5463 * Return value: the relevant #GtkSettings object
5466 gtk_widget_get_settings (GtkWidget *widget)
5468 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5470 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
5474 * gtk_widget_set_colormap:
5475 * @widget: a #GtkWidget
5476 * @colormap: a colormap
5478 * Sets the colormap for the widget to the given value. Widget must not
5479 * have been previously realized. This probably should only be used
5480 * from an <function>init()</function> function (i.e. from the constructor
5485 gtk_widget_set_colormap (GtkWidget *widget,
5486 GdkColormap *colormap)
5488 g_return_if_fail (GTK_IS_WIDGET (widget));
5489 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5490 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5492 g_object_ref (colormap);
5494 g_object_set_qdata_full (G_OBJECT (widget),
5501 * gtk_widget_get_events:
5502 * @widget: a #GtkWidget
5504 * Returns the event mask for the widget (a bitfield containing flags
5505 * from the #GdkEventMask enumeration). These are the events that the widget
5508 * Return value: event mask for @widget
5511 gtk_widget_get_events (GtkWidget *widget)
5515 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5517 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5525 * gtk_widget_get_extension_events:
5526 * @widget: a #GtkWidget
5528 * Retrieves the extension events the widget will receive; see
5529 * gdk_input_set_extension_events().
5531 * Return value: extension events for @widget
5534 gtk_widget_get_extension_events (GtkWidget *widget)
5536 GdkExtensionMode *mode;
5538 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5540 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5548 * gtk_widget_get_pointer:
5549 * @widget: a #GtkWidget
5550 * @x: return location for the X coordinate, or %NULL
5551 * @y: return location for the Y coordinate, or %NULL
5553 * Obtains the location of the mouse pointer in widget coordinates.
5554 * Widget coordinates are a bit odd; for historical reasons, they are
5555 * defined as @widget->window coordinates for widgets that are not
5556 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
5557 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
5561 gtk_widget_get_pointer (GtkWidget *widget,
5565 g_return_if_fail (GTK_IS_WIDGET (widget));
5572 if (GTK_WIDGET_REALIZED (widget))
5574 gdk_window_get_pointer (widget->window, x, y, NULL);
5576 if (GTK_WIDGET_NO_WINDOW (widget))
5579 *x -= widget->allocation.x;
5581 *y -= widget->allocation.y;
5587 * gtk_widget_is_ancestor:
5588 * @widget: a #GtkWidget
5589 * @ancestor: another #GtkWidget
5591 * Determines whether @widget is somewhere inside @ancestor, possibly with
5592 * intermediate containers.
5594 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
5597 gtk_widget_is_ancestor (GtkWidget *widget,
5598 GtkWidget *ancestor)
5600 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5601 g_return_val_if_fail (ancestor != NULL, FALSE);
5605 if (widget->parent == ancestor)
5607 widget = widget->parent;
5613 static GQuark quark_composite_name = 0;
5616 * gtk_widget_set_composite_name:
5617 * @widget: a #GtkWidget.
5618 * @name: the name to set.
5620 * Sets a widgets composite name. The widget must be
5621 * a composite child of its parent; see gtk_widget_push_composite_child().
5624 gtk_widget_set_composite_name (GtkWidget *widget,
5627 g_return_if_fail (GTK_IS_WIDGET (widget));
5628 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
5629 g_return_if_fail (name != NULL);
5631 if (!quark_composite_name)
5632 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
5634 g_object_set_qdata_full (G_OBJECT (widget),
5635 quark_composite_name,
5641 * gtk_widget_get_composite_name:
5642 * @widget: a #GtkWidget.
5643 * @returns: the composite name of @widget, or %NULL if @widget is not
5644 * a composite child. The string should not be freed when it is no
5647 * Obtains the composite name of a widget.
5650 gtk_widget_get_composite_name (GtkWidget *widget)
5652 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5654 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
5655 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
5662 * gtk_widget_push_composite_child:
5664 * Makes all newly-created widgets as composite children until
5665 * the corresponding gtk_widget_pop_composite_child() call.
5667 * A composite child is a child that's an implementation detail of the
5668 * container it's inside and should not be visible to people using the
5669 * container. Composite children aren't treated differently by GTK (but
5670 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
5671 * builders might want to treat them in a different way.
5673 * Here is a simple example:
5674 * <informalexample><programlisting>
5675 * gtk_widget_push_composite_child (<!-- -->);
5676 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
5677 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
5678 * gtk_widget_pop_composite_child (<!-- -->);
5679 * gtk_widget_set_parent (scrolled_window->hscrollbar,
5680 * GTK_WIDGET (scrolled_window));
5681 * g_object_ref (scrolled_window->hscrollbar);
5682 * </programlisting></informalexample>
5685 gtk_widget_push_composite_child (void)
5687 composite_child_stack++;
5691 * gtk_widget_pop_composite_child:
5693 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
5696 gtk_widget_pop_composite_child (void)
5698 if (composite_child_stack)
5699 composite_child_stack--;
5703 * gtk_widget_push_colormap:
5704 * @cmap: a #GdkColormap
5706 * Pushes @cmap onto a global stack of colormaps; the topmost
5707 * colormap on the stack will be used to create all widgets.
5708 * Remove @cmap with gtk_widget_pop_colormap(). There's little
5709 * reason to use this function.
5713 gtk_widget_push_colormap (GdkColormap *cmap)
5715 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
5717 colormap_stack = g_slist_prepend (colormap_stack, cmap);
5721 * gtk_widget_pop_colormap:
5723 * Removes a colormap pushed with gtk_widget_push_colormap().
5727 gtk_widget_pop_colormap (void)
5730 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
5734 * gtk_widget_set_default_colormap:
5735 * @colormap: a #GdkColormap
5737 * Sets the default colormap to use when creating widgets.
5738 * gtk_widget_push_colormap() is a better function to use if
5739 * you only want to affect a few widgets, rather than all widgets.
5742 gtk_widget_set_default_colormap (GdkColormap *colormap)
5744 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5746 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
5751 * gtk_widget_get_default_colormap:
5753 * Obtains the default colormap used to create widgets.
5755 * Return value: default widget colormap
5758 gtk_widget_get_default_colormap (void)
5760 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
5764 * gtk_widget_get_default_visual:
5766 * Obtains the visual of the default colormap. Not really useful;
5767 * used to be useful before gdk_colormap_get_visual() existed.
5769 * Return value: visual of the default colormap
5772 gtk_widget_get_default_visual (void)
5774 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
5778 gtk_widget_emit_direction_changed (GtkWidget *widget,
5779 GtkTextDirection old_dir)
5781 PangoContext *context = gtk_widget_peek_pango_context (widget);
5784 pango_context_set_base_dir (context,
5785 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5786 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5788 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
5792 * gtk_widget_set_direction:
5793 * @widget: a #GtkWidget
5794 * @dir: the new direction
5796 * Sets the reading direction on a particular widget. This direction
5797 * controls the primary direction for widgets containing text,
5798 * and also the direction in which the children of a container are
5799 * packed. The ability to set the direction is present in order
5800 * so that correct localization into languages with right-to-left
5801 * reading directions can be done. Generally, applications will
5802 * let the default reading direction present, except for containers
5803 * where the containers are arranged in an order that is explicitely
5804 * visual rather than logical (such as buttons for text justification).
5806 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
5807 * set by gtk_widget_set_default_direction() will be used.
5810 gtk_widget_set_direction (GtkWidget *widget,
5811 GtkTextDirection dir)
5813 GtkTextDirection old_dir;
5815 g_return_if_fail (GTK_IS_WIDGET (widget));
5816 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
5818 old_dir = gtk_widget_get_direction (widget);
5820 if (dir == GTK_TEXT_DIR_NONE)
5821 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
5824 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
5825 if (dir == GTK_TEXT_DIR_LTR)
5826 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
5828 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
5831 if (old_dir != gtk_widget_get_direction (widget))
5832 gtk_widget_emit_direction_changed (widget, old_dir);
5836 * gtk_widget_get_direction:
5837 * @widget: a #GtkWidget
5839 * Gets the reading direction for a particular widget. See
5840 * gtk_widget_set_direction().
5842 * Return value: the reading direction for the widget.
5845 gtk_widget_get_direction (GtkWidget *widget)
5847 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
5849 if (GTK_WIDGET_DIRECTION_SET (widget))
5850 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
5852 return gtk_default_direction;
5856 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
5858 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
5860 g_object_ref (widget);
5862 if (!GTK_WIDGET_DIRECTION_SET (widget))
5863 gtk_widget_emit_direction_changed (widget, old_dir);
5865 if (GTK_IS_CONTAINER (widget))
5866 gtk_container_forall (GTK_CONTAINER (widget),
5867 gtk_widget_set_default_direction_recurse,
5870 g_object_unref (widget);
5874 * gtk_widget_set_default_direction:
5875 * @dir: the new default direction. This cannot be
5876 * %GTK_TEXT_DIR_NONE.
5878 * Sets the default reading direction for widgets where the
5879 * direction has not been explicitly set by gtk_widget_set_direction().
5882 gtk_widget_set_default_direction (GtkTextDirection dir)
5884 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
5886 if (dir != gtk_default_direction)
5888 GList *toplevels, *tmp_list;
5889 GtkTextDirection old_dir = gtk_default_direction;
5891 gtk_default_direction = dir;
5893 tmp_list = toplevels = gtk_window_list_toplevels ();
5894 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
5898 gtk_widget_set_default_direction_recurse (tmp_list->data,
5899 GUINT_TO_POINTER (old_dir));
5900 g_object_unref (tmp_list->data);
5901 tmp_list = tmp_list->next;
5904 g_list_free (toplevels);
5909 * gtk_widget_get_default_direction:
5911 * Obtains the current default reading direction. See
5912 * gtk_widget_set_default_direction().
5914 * Return value: the current default direction.
5917 gtk_widget_get_default_direction (void)
5919 return gtk_default_direction;
5923 gtk_widget_dispose (GObject *object)
5925 GtkWidget *widget = GTK_WIDGET (object);
5928 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5930 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
5931 if (GTK_WIDGET_REALIZED (widget))
5932 gtk_widget_unrealize (widget);
5934 G_OBJECT_CLASS (parent_class)->dispose (object);
5938 gtk_widget_real_destroy (GtkObject *object)
5940 /* gtk_object_destroy() will already hold a refcount on object */
5941 GtkWidget *widget = GTK_WIDGET (object);
5943 /* wipe accelerator closures (keep order) */
5944 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
5945 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
5947 gtk_grab_remove (widget);
5949 g_object_unref (widget->style);
5950 widget->style = gtk_widget_get_default_style ();
5951 g_object_ref (widget->style);
5953 GTK_OBJECT_CLASS (parent_class)->destroy (object);
5957 gtk_widget_finalize (GObject *object)
5959 GtkWidget *widget = GTK_WIDGET (object);
5960 GtkWidgetAuxInfo *aux_info;
5962 GdkExtensionMode *mode;
5963 GtkAccessible *accessible;
5965 gtk_grab_remove (widget);
5967 g_object_unref (widget->style);
5968 widget->style = NULL;
5971 g_free (widget->name);
5973 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
5975 gtk_widget_aux_info_destroy (aux_info);
5977 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5981 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5985 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
5987 g_object_unref (accessible);
5989 G_OBJECT_CLASS (parent_class)->finalize (object);
5992 /*****************************************
5993 * gtk_widget_real_map:
5998 *****************************************/
6001 gtk_widget_real_map (GtkWidget *widget)
6003 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6005 if (!GTK_WIDGET_MAPPED (widget))
6007 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6009 if (!GTK_WIDGET_NO_WINDOW (widget))
6010 gdk_window_show (widget->window);
6014 /*****************************************
6015 * gtk_widget_real_unmap:
6020 *****************************************/
6023 gtk_widget_real_unmap (GtkWidget *widget)
6025 if (GTK_WIDGET_MAPPED (widget))
6027 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6029 if (!GTK_WIDGET_NO_WINDOW (widget))
6030 gdk_window_hide (widget->window);
6034 /*****************************************
6035 * gtk_widget_real_realize:
6040 *****************************************/
6043 gtk_widget_real_realize (GtkWidget *widget)
6045 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6047 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6050 widget->window = gtk_widget_get_parent_window (widget);
6051 g_object_ref (widget->window);
6053 widget->style = gtk_style_attach (widget->style, widget->window);
6056 /*****************************************
6057 * gtk_widget_real_unrealize:
6062 *****************************************/
6065 gtk_widget_real_unrealize (GtkWidget *widget)
6067 if (GTK_WIDGET_MAPPED (widget))
6068 gtk_widget_real_unmap (widget);
6070 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6072 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6075 /* We must do unrealize child widget BEFORE container widget.
6076 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6077 * So, unrealizing container widget bofore its children causes the problem
6078 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6081 if (GTK_IS_CONTAINER (widget))
6082 gtk_container_forall (GTK_CONTAINER (widget),
6083 (GtkCallback) gtk_widget_unrealize,
6086 gtk_style_detach (widget->style);
6087 if (!GTK_WIDGET_NO_WINDOW (widget))
6089 gdk_window_set_user_data (widget->window, NULL);
6090 gdk_window_destroy (widget->window);
6091 widget->window = NULL;
6095 g_object_unref (widget->window);
6096 widget->window = NULL;
6099 gtk_selection_remove_all (widget);
6101 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6105 gtk_widget_real_size_request (GtkWidget *widget,
6106 GtkRequisition *requisition)
6108 requisition->width = widget->requisition.width;
6109 requisition->height = widget->requisition.height;
6113 * _gtk_widget_peek_colormap:
6115 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6117 * Return value: the currently pushed colormap, or %NULL if there is none.
6120 _gtk_widget_peek_colormap (void)
6123 return (GdkColormap*) colormap_stack->data;
6128 gtk_widget_propagate_state (GtkWidget *widget,
6133 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6134 * parent_sensitive==TRUE on a sensitive widget
6137 old_state = GTK_WIDGET_STATE (widget);
6139 if (data->parent_sensitive)
6141 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6143 if (GTK_WIDGET_IS_SENSITIVE (widget))
6145 if (data->state_restoration)
6146 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6148 GTK_WIDGET_STATE (widget) = data->state;
6152 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6153 if (!data->state_restoration &&
6154 data->state != GTK_STATE_INSENSITIVE)
6155 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6160 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6161 if (!data->state_restoration)
6163 if (data->state != GTK_STATE_INSENSITIVE)
6164 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6166 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6167 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6168 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6171 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6175 window = gtk_widget_get_toplevel (widget);
6176 if (window && GTK_WIDGET_TOPLEVEL (window))
6177 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6180 if (old_state != GTK_WIDGET_STATE (widget))
6182 g_object_ref (widget);
6184 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6185 gtk_grab_remove (widget);
6187 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6189 if (GTK_IS_CONTAINER (widget))
6191 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6192 data->state = GTK_WIDGET_STATE (widget);
6193 if (data->use_forall)
6194 gtk_container_forall (GTK_CONTAINER (widget),
6195 (GtkCallback) gtk_widget_propagate_state,
6198 gtk_container_foreach (GTK_CONTAINER (widget),
6199 (GtkCallback) gtk_widget_propagate_state,
6202 g_object_unref (widget);
6207 * _gtk_widget_get_aux_info:
6208 * @widget: a #GtkWidget
6209 * @create: if %TRUE, create the structure if it doesn't exist
6211 * Get the #GtkWidgetAuxInfo structure for the widget.
6213 * Return value: the #GtkAuxInfo structure for the widget, or
6214 * %NULL if @create is %FALSE and one doesn't already exist.
6217 _gtk_widget_get_aux_info (GtkWidget *widget,
6220 GtkWidgetAuxInfo *aux_info;
6222 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6223 if (!aux_info && create)
6225 if (!aux_info_mem_chunk)
6226 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6227 sizeof (GtkWidgetAuxInfo),
6228 1024, G_ALLOC_AND_FREE);
6229 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6231 aux_info->width = -1;
6232 aux_info->height = -1;
6235 aux_info->x_set = FALSE;
6236 aux_info->y_set = FALSE;
6237 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6243 /*****************************************
6244 * gtk_widget_aux_info_destroy:
6249 *****************************************/
6252 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6254 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6258 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6260 g_object_unref (info->shape_mask);
6265 * gtk_widget_shape_combine_mask:
6266 * @widget: a #GtkWidget.
6267 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6268 * @offset_x: X position of shape mask with respect to @window.
6269 * @offset_y: Y position of shape mask with respect to @window.
6271 * Sets a shape for this widget's GDK window. This allows for
6272 * transparent windows etc., see gdk_window_shape_combine_mask()
6273 * for more information.
6276 gtk_widget_shape_combine_mask (GtkWidget *widget,
6277 GdkBitmap *shape_mask,
6281 GtkWidgetShapeInfo* shape_info;
6283 g_return_if_fail (GTK_IS_WIDGET (widget));
6284 /* set_shape doesn't work on widgets without gdk window */
6285 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6289 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6292 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6294 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6298 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6300 shape_info = g_new (GtkWidgetShapeInfo, 1);
6301 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6302 (GDestroyNotify) gtk_widget_shape_info_destroy);
6304 shape_info->shape_mask = g_object_ref (shape_mask);
6305 shape_info->offset_x = offset_x;
6306 shape_info->offset_y = offset_y;
6308 /* set shape if widget has a gdk window allready.
6309 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6312 gdk_window_shape_combine_mask (widget->window, shape_mask,
6313 offset_x, offset_y);
6318 gtk_reset_shapes_recurse (GtkWidget *widget,
6324 gdk_window_get_user_data (window, &data);
6328 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6329 for (list = gdk_window_peek_children (window); list; list = list->next)
6330 gtk_reset_shapes_recurse (widget, list->data);
6334 * gtk_widget_reset_shapes:
6335 * @widget: a #GtkWidget.
6337 * Recursively resets the shape on this widget and its descendants.
6340 gtk_widget_reset_shapes (GtkWidget *widget)
6342 g_return_if_fail (GTK_IS_WIDGET (widget));
6343 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6345 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6346 gtk_reset_shapes_recurse (widget, widget->window);
6351 * @widget: a #GtkWidget
6353 * Adds a reference to a widget. This function is exactly the same
6354 * as calling g_object_ref(), and exists mostly for historical
6355 * reasons. It can still be convenient to avoid casting a widget
6356 * to a #GObject, it saves a small amount of typing.
6358 * Return value: the widget that was referenced
6361 gtk_widget_ref (GtkWidget *widget)
6363 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6365 return (GtkWidget*) g_object_ref ((GObject*) widget);
6370 * @widget: a #GtkWidget
6372 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6376 gtk_widget_unref (GtkWidget *widget)
6378 g_return_if_fail (GTK_IS_WIDGET (widget));
6380 g_object_unref ((GObject*) widget);
6388 * gtk_widget_class_install_style_property_parser:
6389 * @class: a #GtkWidgetClass
6390 * @pspec: the #GParamSpec for the style property
6391 * @parser: the parser for the style property
6393 * Installs a style property on a widget class.
6396 gtk_widget_class_install_style_property_parser (GtkWidgetClass *class,
6398 GtkRcPropertyParser parser)
6400 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
6401 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6402 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6403 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6405 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
6407 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6408 G_OBJECT_CLASS_NAME (class),
6413 g_param_spec_ref (pspec);
6414 g_param_spec_sink (pspec);
6415 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6416 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
6420 * gtk_widget_class_install_style_property:
6421 * @class: a #GtkWidgetClass
6422 * @pspec: the #GParamSpec for the property
6424 * Installs a style property on a widget class. The parser for the
6425 * style property is determined by the value type of @pspec.
6428 gtk_widget_class_install_style_property (GtkWidgetClass *class,
6431 GtkRcPropertyParser parser;
6433 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
6434 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6436 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6438 gtk_widget_class_install_style_property_parser (class, pspec, parser);
6442 * gtk_widget_class_find_style_property:
6443 * @klass: a #GtkWidgetClass
6444 * @property_name: the name of the style property to find
6445 * @returns: the #GParamSpec of the style property or %NULL if @class has no
6446 * style property with that name.
6448 * Finds a style property of a widget class by name.
6453 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
6454 const gchar *property_name)
6456 g_return_val_if_fail (property_name != NULL, NULL);
6458 return g_param_spec_pool_lookup (style_property_spec_pool,
6460 G_OBJECT_CLASS_TYPE (klass),
6465 * gtk_widget_class_list_style_properties:
6466 * @klass: a #GtkWidgetClass
6467 * @n_properties: location to return the number of style properties found
6468 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
6470 * Returns all style properties of a widget class.
6475 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
6476 guint *n_properties)
6478 GParamSpec **pspecs;
6481 pspecs = g_param_spec_pool_list (style_property_spec_pool,
6482 G_OBJECT_CLASS_TYPE (klass),
6491 * gtk_widget_style_get_property:
6492 * @widget: a #GtkWidget
6493 * @property_name: the name of a style property
6494 * @value: location to return the property value
6496 * Gets the value of a style property of @widget.
6499 gtk_widget_style_get_property (GtkWidget *widget,
6500 const gchar *property_name,
6505 g_return_if_fail (GTK_IS_WIDGET (widget));
6506 g_return_if_fail (property_name != NULL);
6507 g_return_if_fail (G_IS_VALUE (value));
6509 g_object_ref (widget);
6510 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6512 G_OBJECT_TYPE (widget),
6515 g_warning ("%s: widget class `%s' has no property named `%s'",
6517 G_OBJECT_TYPE_NAME (widget),
6521 const GValue *peek_value;
6523 peek_value = _gtk_style_peek_property_value (widget->style,
6524 G_OBJECT_TYPE (widget),
6526 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
6528 /* auto-conversion of the caller's value type
6530 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
6531 g_value_copy (peek_value, value);
6532 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
6533 g_value_transform (peek_value, value);
6535 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
6537 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
6538 G_VALUE_TYPE_NAME (value));
6540 g_object_unref (widget);
6544 * gtk_widget_style_get_valist:
6545 * @widget: a #GtkWidget
6546 * @first_property_name: the name of the first property to get
6547 * @var_args: a <type>va_list</type> of pairs of property names and
6548 * locations to return the property values, starting with the location
6549 * for @first_property_name.
6551 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
6555 gtk_widget_style_get_valist (GtkWidget *widget,
6556 const gchar *first_property_name,
6561 g_return_if_fail (GTK_IS_WIDGET (widget));
6563 g_object_ref (widget);
6565 name = first_property_name;
6568 const GValue *peek_value;
6572 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6574 G_OBJECT_TYPE (widget),
6578 g_warning ("%s: widget class `%s' has no property named `%s'",
6580 G_OBJECT_TYPE_NAME (widget),
6584 /* style pspecs are always readable so we can spare that check here */
6586 peek_value = _gtk_style_peek_property_value (widget->style,
6587 G_OBJECT_TYPE (widget),
6589 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
6590 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
6593 g_warning ("%s: %s", G_STRLOC, error);
6598 name = va_arg (var_args, gchar*);
6601 g_object_unref (widget);
6605 * gtk_widget_style_get:
6606 * @widget: a #GtkWidget
6607 * @first_property_name: the name of the first property to get
6608 * @Varargs: pairs of property names and locations to
6609 * return the property values, starting with the location for
6610 * @first_property_name, terminated by %NULL.
6612 * Gets the values of a multiple style properties of @widget.
6615 gtk_widget_style_get (GtkWidget *widget,
6616 const gchar *first_property_name,
6621 g_return_if_fail (GTK_IS_WIDGET (widget));
6623 va_start (var_args, first_property_name);
6624 gtk_widget_style_get_valist (widget, first_property_name, var_args);
6630 * @widget: a #GtkWidget
6631 * @path_length: location to store length of the path, or %NULL
6632 * @path: location to store allocated path string, or %NULL
6633 * @path_reversed: location to store allocated reverse path string, or %NULL
6635 * Obtains the full path to @widget. The path is simply the name of a
6636 * widget and all its parents in the container hierarchy, separated by
6637 * periods. The name of a widget comes from
6638 * gtk_widget_get_name(). Paths are used to apply styles to a widget
6639 * in gtkrc configuration files. Widget names are the type of the
6640 * widget by default (e.g. "GtkButton") or can be set to an
6641 * application-specific value with gtk_widget_set_name(). By setting
6642 * the name of a widget, you allow users or theme authors to apply
6643 * styles to that specific widget in their gtkrc
6644 * file. @path_reversed_p fills in the path in reverse order,
6645 * i.e. starting with @widget's name instead of starting with the name
6646 * of @widget's outermost ancestor.
6650 gtk_widget_path (GtkWidget *widget,
6653 gchar **path_reversed)
6655 static gchar *rev_path = NULL;
6656 static guint tmp_path_len = 0;
6659 g_return_if_fail (GTK_IS_WIDGET (widget));
6664 const gchar *string;
6669 string = gtk_widget_get_name (widget);
6670 l = strlen (string);
6671 while (tmp_path_len <= len + l + 1)
6673 tmp_path_len += INIT_PATH_SIZE;
6674 rev_path = g_realloc (rev_path, tmp_path_len);
6682 widget = widget->parent;
6685 rev_path[len++] = '.';
6687 rev_path[len++] = 0;
6692 *path_length = len - 1;
6694 *path_reversed = g_strdup (rev_path);
6697 *path = g_strdup (rev_path);
6698 g_strreverse (*path);
6703 * gtk_widget_class_path:
6704 * @widget: a #GtkWidget
6705 * @path_length: location to store the length of the class path, or %NULL
6706 * @path: location to store the class path as an allocated string, or %NULL
6707 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
6709 * Same as gtk_widget_path(), but always uses the name of a widget's type,
6710 * never uses a custom name set with gtk_widget_set_name().
6714 gtk_widget_class_path (GtkWidget *widget,
6717 gchar **path_reversed)
6719 static gchar *rev_path = NULL;
6720 static guint tmp_path_len = 0;
6723 g_return_if_fail (GTK_IS_WIDGET (widget));
6728 const gchar *string;
6733 string = g_type_name (GTK_WIDGET_TYPE (widget));
6734 l = strlen (string);
6735 while (tmp_path_len <= len + l + 1)
6737 tmp_path_len += INIT_PATH_SIZE;
6738 rev_path = g_realloc (rev_path, tmp_path_len);
6746 widget = widget->parent;
6749 rev_path[len++] = '.';
6751 rev_path[len++] = 0;
6756 *path_length = len - 1;
6758 *path_reversed = g_strdup (rev_path);
6761 *path = g_strdup (rev_path);
6762 g_strreverse (*path);
6767 * gtk_requisition_copy:
6768 * @requisition: a #GtkRequisition.
6769 * @returns: a copy of @requisition.
6771 * Copies a #GtkRequisition.
6774 gtk_requisition_copy (const GtkRequisition *requisition)
6776 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
6780 * gtk_requisition_free:
6781 * @requisition: a #GtkRequisition.
6783 * Frees a #GtkRequisition.
6786 gtk_requisition_free (GtkRequisition *requisition)
6788 g_free (requisition);
6792 gtk_requisition_get_type (void)
6794 static GType our_type = 0;
6797 our_type = g_boxed_type_register_static ("GtkRequisition",
6798 (GBoxedCopyFunc) gtk_requisition_copy,
6799 (GBoxedFreeFunc) gtk_requisition_free);
6805 gtk_widget_get_accessible (GtkWidget *widget)
6807 GtkWidgetClass *klass;
6809 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6811 klass = GTK_WIDGET_GET_CLASS (widget);
6813 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
6815 return klass->get_accessible (widget);
6819 gtk_widget_real_get_accessible (GtkWidget *widget)
6821 AtkObject* accessible;
6823 accessible = g_object_get_qdata (G_OBJECT (widget),
6824 quark_accessible_object);
6827 AtkObjectFactory *factory;
6828 AtkRegistry *default_registry;
6830 default_registry = atk_get_default_registry ();
6831 factory = atk_registry_get_factory (default_registry,
6832 G_TYPE_FROM_INSTANCE (widget));
6834 atk_object_factory_create_accessible (factory,
6836 g_object_set_qdata (G_OBJECT (widget),
6837 quark_accessible_object,
6844 * Initialize a AtkImplementorIface instance's virtual pointers as
6845 * appropriate to this implementor's class (GtkWidget).
6848 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
6850 iface->ref_accessible = gtk_widget_ref_accessible;
6854 gtk_widget_ref_accessible (AtkImplementor *implementor)
6856 AtkObject *accessible;
6858 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
6860 g_object_ref (accessible);
6865 * gtk_widget_get_clipboard:
6866 * @widget: a #GtkWidget
6867 * @selection: a #GdkAtom which identifies the clipboard
6868 * to use. %GDK_SELECTION_CLIPBOARD gives the
6869 * default clipboard. Another common value
6870 * is %GDK_SELECTION_PRIMARY, which gives
6871 * the primary X selection.
6873 * Returns the clipboard object for the given selection to
6874 * be used with @widget. @widget must have a #GdkDisplay
6875 * associated with it, so must be attached to a toplevel
6878 * Return value: the appropriate clipboard object. If no
6879 * clipboard already exists, a new one will
6880 * be created. Once a clipboard object has
6881 * been created, it is persistent for all time.
6886 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
6888 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6889 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
6891 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),