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 "gtkiconfactory.h"
35 #include "gtkselection.h"
36 #include "gtksettings.h"
37 #include "gtksizegroup.h"
38 #include "gtksignal.h"
39 #include "gtkwidget.h"
40 #include "gtkwindow.h"
41 #include "gtkbindings.h"
42 #include "gtkprivate.h"
44 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
45 #include <gobject/gvaluecollector.h>
46 #include <gobject/gobjectnotifyqueue.c>
47 #include "gdk/gdkkeysyms.h"
49 #include "gtkaccessible.h"
51 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
52 #define INIT_PATH_SIZE (512)
93 PROPERTY_NOTIFY_EVENT,
94 SELECTION_CLEAR_EVENT,
95 SELECTION_REQUEST_EVENT,
96 SELECTION_NOTIFY_EVENT,
111 VISIBILITY_NOTIFY_EVENT,
132 PROP_RECEIVES_DEFAULT,
133 PROP_COMPOSITE_CHILD,
136 PROP_EXTENSION_EVENTS
139 typedef struct _GtkStateData GtkStateData;
144 guint state_restoration : 1;
145 guint parent_sensitive : 1;
146 guint use_forall : 1;
150 /* --- prototypes --- */
151 static void gtk_widget_class_init (GtkWidgetClass *klass);
152 static void gtk_widget_init (GtkWidget *widget);
153 static void gtk_widget_set_property (GObject *object,
157 static void gtk_widget_get_property (GObject *object,
161 static void gtk_widget_shutdown (GObject *object);
162 static void gtk_widget_real_destroy (GtkObject *object);
163 static void gtk_widget_finalize (GObject *object);
164 static void gtk_widget_real_show (GtkWidget *widget);
165 static void gtk_widget_real_hide (GtkWidget *widget);
166 static void gtk_widget_real_map (GtkWidget *widget);
167 static void gtk_widget_real_unmap (GtkWidget *widget);
168 static void gtk_widget_real_realize (GtkWidget *widget);
169 static void gtk_widget_real_unrealize (GtkWidget *widget);
170 static void gtk_widget_real_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void gtk_widget_real_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static void gtk_widget_style_set (GtkWidget *widget,
175 GtkStyle *previous_style);
176 static void gtk_widget_direction_changed (GtkWidget *widget,
177 GtkTextDirection previous_direction);
178 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
179 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
181 GParamSpec **pspecs);
182 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
184 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
186 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
187 GdkEventFocus *event);
188 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
189 GdkEventFocus *event);
190 static gboolean gtk_widget_real_focus (GtkWidget *widget,
191 GtkDirectionType direction);
192 static GdkColormap* gtk_widget_peek_colormap (void);
193 static GtkStyle* gtk_widget_peek_style (void);
194 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
195 static void gtk_widget_reparent_container_child (GtkWidget *widget,
196 gpointer client_data);
197 static void gtk_widget_propagate_state (GtkWidget *widget,
199 static void gtk_widget_set_style_internal (GtkWidget *widget,
201 gboolean initial_emission);
202 static void gtk_widget_set_style_recurse (GtkWidget *widget,
203 gpointer client_data);
204 static gint gtk_widget_event_internal (GtkWidget *widget,
206 static void gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
207 gpointer client_data);
208 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
209 gboolean group_cycling);
210 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
211 static void gtk_widget_do_uposition (GtkWidget *widget);
212 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
213 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
214 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
217 /* --- variables --- */
218 static gpointer parent_class = NULL;
219 static guint widget_signals[LAST_SIGNAL] = { 0 };
220 static GMemChunk *aux_info_mem_chunk = NULL;
221 static GdkColormap *default_colormap = NULL;
222 static GtkStyle *gtk_default_style = NULL;
223 static GSList *colormap_stack = NULL;
224 static GSList *style_stack = NULL;
225 static guint composite_child_stack = 0;
226 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
227 static GParamSpecPool *style_property_spec_pool = NULL;
228 static GQuark quark_property_parser = 0;
229 static GQuark quark_aux_info = 0;
230 static GQuark quark_event_mask = 0;
231 static GQuark quark_extension_event_mode = 0;
232 static GQuark quark_parent_window = 0;
233 static GQuark quark_saved_default_style = 0;
234 static GQuark quark_shape_info = 0;
235 static GQuark quark_colormap = 0;
236 static GQuark quark_pango_context = 0;
237 static GQuark quark_rc_style = 0;
238 static GQuark quark_accessible_object = 0;
239 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
240 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
243 /* --- functions --- */
245 gtk_widget_get_type (void)
247 static GtkType widget_type = 0;
251 static const GtkTypeInfo widget_info =
255 sizeof (GtkWidgetClass),
256 (GtkClassInitFunc) gtk_widget_class_init,
257 (GtkObjectInitFunc) gtk_widget_init,
258 /* reserved_1 */ NULL,
259 /* reserved_2 */ NULL,
260 (GtkClassInitFunc) NULL,
263 static const GInterfaceInfo accessibility_info =
265 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
266 (GInterfaceFinalizeFunc) NULL,
267 NULL /* interface data */
271 widget_type = gtk_type_unique (GTK_TYPE_OBJECT, &widget_info);
273 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
274 &accessibility_info) ;
282 child_property_notify_dispatcher (GObject *object,
286 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
290 gtk_widget_class_init (GtkWidgetClass *klass)
292 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
293 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
294 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
295 GtkBindingSet *binding_set;
297 parent_class = g_type_class_peek_parent (klass);
299 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
300 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
301 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
302 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
303 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
304 quark_saved_default_style = g_quark_from_static_string ("gtk-saved-default-style");
305 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
306 quark_colormap = g_quark_from_static_string ("gtk-colormap");
307 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
308 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
309 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
311 style_property_spec_pool = g_param_spec_pool_new (FALSE);
312 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
313 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
314 cpn_context.dispatcher = child_property_notify_dispatcher;
315 _gtk_widget_child_property_notify_context = &cpn_context;
317 gobject_class->shutdown = gtk_widget_shutdown;
318 gobject_class->finalize = gtk_widget_finalize;
319 gobject_class->set_property = gtk_widget_set_property;
320 gobject_class->get_property = gtk_widget_get_property;
322 object_class->destroy = gtk_widget_real_destroy;
324 klass->activate_signal = 0;
325 klass->set_scroll_adjustments_signal = 0;
326 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
327 klass->show = gtk_widget_real_show;
328 klass->show_all = gtk_widget_show;
329 klass->hide = gtk_widget_real_hide;
330 klass->hide_all = gtk_widget_hide;
331 klass->map = gtk_widget_real_map;
332 klass->unmap = gtk_widget_real_unmap;
333 klass->realize = gtk_widget_real_realize;
334 klass->unrealize = gtk_widget_real_unrealize;
335 klass->size_request = gtk_widget_real_size_request;
336 klass->size_allocate = gtk_widget_real_size_allocate;
337 klass->state_changed = NULL;
338 klass->parent_set = NULL;
339 klass->hierarchy_changed = NULL;
340 klass->style_set = gtk_widget_style_set;
341 klass->direction_changed = gtk_widget_direction_changed;
342 klass->grab_notify = NULL;
343 klass->child_notify = NULL;
344 klass->add_accelerator = (void*) gtk_accel_group_handle_add;
345 klass->remove_accelerator = (void*) gtk_accel_group_handle_remove;
346 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
347 klass->grab_focus = gtk_widget_real_grab_focus;
348 klass->focus = gtk_widget_real_focus;
350 klass->button_press_event = NULL;
351 klass->button_release_event = NULL;
352 klass->motion_notify_event = NULL;
353 klass->delete_event = NULL;
354 klass->destroy_event = NULL;
355 klass->expose_event = NULL;
356 klass->key_press_event = gtk_widget_real_key_press_event;
357 klass->key_release_event = gtk_widget_real_key_release_event;
358 klass->enter_notify_event = NULL;
359 klass->leave_notify_event = NULL;
360 klass->configure_event = NULL;
361 klass->focus_in_event = gtk_widget_real_focus_in_event;
362 klass->focus_out_event = gtk_widget_real_focus_out_event;
363 klass->map_event = NULL;
364 klass->unmap_event = NULL;
365 klass->window_state_event = NULL;
366 klass->property_notify_event = gtk_selection_property_notify;
367 klass->selection_clear_event = gtk_selection_clear;
368 klass->selection_request_event = gtk_selection_request;
369 klass->selection_notify_event = gtk_selection_notify;
370 klass->selection_received = NULL;
371 klass->proximity_in_event = NULL;
372 klass->proximity_out_event = NULL;
373 klass->drag_begin = NULL;
374 klass->drag_end = NULL;
375 klass->drag_data_delete = NULL;
376 klass->drag_leave = NULL;
377 klass->drag_motion = NULL;
378 klass->drag_drop = NULL;
379 klass->drag_data_received = NULL;
380 klass->get_accessible = gtk_widget_real_get_accessible; /* Accessibility support */
381 klass->no_expose_event = NULL;
383 g_object_class_install_property (gobject_class,
385 g_param_spec_string ("name",
387 _("The name of the widget"),
391 g_object_class_install_property (gobject_class,
393 g_param_spec_object ("parent",
395 _("The parent widget of this widget. Must be a Container widget."),
399 g_object_class_install_property (gobject_class,
401 g_param_spec_int ("x",
403 _("The x coordinate of the top-left corner of the widget, or -1 if not set"),
409 g_object_class_install_property (gobject_class,
411 g_param_spec_int ("y",
413 _("The y coordinate of the top-left corner of the widget, or -1 if not set"),
419 g_object_class_install_property (gobject_class,
421 g_param_spec_int ("width",
423 _("The width of the widget, or -1 if unset."),
429 g_object_class_install_property (gobject_class,
431 g_param_spec_int ("height",
433 _("The height of the widget, or -1 if unset."),
439 g_object_class_install_property (gobject_class,
441 g_param_spec_boolean ("visible",
443 _("Whether the widget is visible"),
447 g_object_class_install_property (gobject_class,
449 g_param_spec_boolean ("sensitive",
451 _("Whether the widget responds to input"),
455 g_object_class_install_property (gobject_class,
457 g_param_spec_boolean ("app_paintable",
458 _("Application paintable"),
459 _("Whether the application will paint directly on the widget"),
463 g_object_class_install_property (gobject_class,
465 g_param_spec_boolean ("can_focus",
467 _("Whether the widget can accept the input focus"),
471 g_object_class_install_property (gobject_class,
473 g_param_spec_boolean ("has_focus",
475 _("Whether the widget has the input focus"),
479 g_object_class_install_property (gobject_class,
481 g_param_spec_boolean ("can_default",
483 _("Whether the widget can be the default widget"),
487 g_object_class_install_property (gobject_class,
489 g_param_spec_boolean ("has_default",
491 _("Whether the widget is the default widget"),
495 g_object_class_install_property (gobject_class,
496 PROP_RECEIVES_DEFAULT,
497 g_param_spec_boolean ("receives_default",
498 _("Receives default"),
499 _("If TRUE, the widget will receive the default action when it is focused."),
503 g_object_class_install_property (gobject_class,
504 PROP_COMPOSITE_CHILD,
505 g_param_spec_boolean ("composite_child",
506 _("Composite child"),
507 _("Whether the widget is composed of other widgets"),
512 g_object_class_install_property (gobject_class,
514 g_param_spec_object ("style",
516 _("The style of the widget, which contains information about how it will look (colors etc)."),
520 g_object_class_install_property (gobject_class,
522 g_param_spec_flags ("events",
524 _("The event mask that decides what kind of GdkEvents this widget gets."),
529 g_object_class_install_property (gobject_class,
530 PROP_EXTENSION_EVENTS,
531 g_param_spec_enum ("extension_events",
532 _("Extension events"),
533 _("The mask that decides what kind of extension events this widget gets."),
534 GDK_TYPE_EXTENSION_MODE,
535 GDK_EXTENSION_EVENTS_NONE,
537 widget_signals[SHOW] =
538 gtk_signal_new ("show",
540 GTK_CLASS_TYPE (object_class),
541 GTK_SIGNAL_OFFSET (GtkWidgetClass, show),
542 gtk_marshal_VOID__VOID,
544 widget_signals[HIDE] =
545 gtk_signal_new ("hide",
547 GTK_CLASS_TYPE (object_class),
548 GTK_SIGNAL_OFFSET (GtkWidgetClass, hide),
549 gtk_marshal_VOID__VOID,
551 widget_signals[MAP] =
552 gtk_signal_new ("map",
554 GTK_CLASS_TYPE (object_class),
555 GTK_SIGNAL_OFFSET (GtkWidgetClass, map),
556 gtk_marshal_VOID__VOID,
558 widget_signals[UNMAP] =
559 gtk_signal_new ("unmap",
561 GTK_CLASS_TYPE (object_class),
562 GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap),
563 gtk_marshal_VOID__VOID,
565 widget_signals[REALIZE] =
566 gtk_signal_new ("realize",
568 GTK_CLASS_TYPE (object_class),
569 GTK_SIGNAL_OFFSET (GtkWidgetClass, realize),
570 gtk_marshal_VOID__VOID,
572 widget_signals[UNREALIZE] =
573 gtk_signal_new ("unrealize",
575 GTK_CLASS_TYPE (object_class),
576 GTK_SIGNAL_OFFSET (GtkWidgetClass, unrealize),
577 gtk_marshal_VOID__VOID,
579 widget_signals[SIZE_REQUEST] =
580 g_signal_newc ("size_request",
581 G_OBJECT_CLASS_TYPE (object_class),
583 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
585 gtk_marshal_VOID__BOXED,
587 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
588 widget_signals[SIZE_ALLOCATE] =
589 gtk_signal_new ("size_allocate",
591 GTK_CLASS_TYPE (object_class),
592 GTK_SIGNAL_OFFSET (GtkWidgetClass, size_allocate),
593 gtk_marshal_VOID__BOXED,
595 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
596 widget_signals[STATE_CHANGED] =
597 gtk_signal_new ("state_changed",
599 GTK_CLASS_TYPE (object_class),
600 GTK_SIGNAL_OFFSET (GtkWidgetClass, state_changed),
601 gtk_marshal_VOID__ENUM,
603 GTK_TYPE_STATE_TYPE);
604 widget_signals[PARENT_SET] =
605 gtk_signal_new ("parent_set",
607 GTK_CLASS_TYPE (object_class),
608 GTK_SIGNAL_OFFSET (GtkWidgetClass, parent_set),
609 gtk_marshal_VOID__OBJECT,
612 widget_signals[HIERARCHY_CHANGED] =
613 gtk_signal_new ("hierarchy_changed",
615 GTK_CLASS_TYPE (object_class),
616 GTK_SIGNAL_OFFSET (GtkWidgetClass, hierarchy_changed),
617 gtk_marshal_NONE__NONE,
619 widget_signals[STYLE_SET] =
620 gtk_signal_new ("style_set",
622 GTK_CLASS_TYPE (object_class),
623 GTK_SIGNAL_OFFSET (GtkWidgetClass, style_set),
624 gtk_marshal_VOID__OBJECT,
627 widget_signals[DIRECTION_CHANGED] =
628 gtk_signal_new ("direction_changed",
630 GTK_CLASS_TYPE (object_class),
631 GTK_SIGNAL_OFFSET (GtkWidgetClass, direction_changed),
632 gtk_marshal_VOID__ENUM,
634 GTK_TYPE_TEXT_DIRECTION);
635 widget_signals[GRAB_NOTIFY] =
636 gtk_signal_new ("grab_notify",
638 GTK_CLASS_TYPE (object_class),
639 GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_notify),
640 gtk_marshal_VOID__BOOLEAN,
643 widget_signals[CHILD_NOTIFY] =
644 g_signal_newc ("child_notify",
645 G_TYPE_FROM_CLASS (klass),
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[ADD_ACCELERATOR] =
653 gtk_accel_group_create_add (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
654 GTK_SIGNAL_OFFSET (GtkWidgetClass, add_accelerator));
655 widget_signals[REMOVE_ACCELERATOR] =
656 gtk_accel_group_create_remove (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
657 GTK_SIGNAL_OFFSET (GtkWidgetClass, remove_accelerator));
658 widget_signals[ACTIVATE_MNEMONIC] =
659 g_signal_newc ("mnemonic_activate",
660 GTK_CLASS_TYPE (object_class),
662 GTK_SIGNAL_OFFSET (GtkWidgetClass, mnemonic_activate),
663 _gtk_boolean_handled_accumulator, NULL,
664 gtk_marshal_BOOLEAN__BOOLEAN,
667 widget_signals[GRAB_FOCUS] =
668 gtk_signal_new ("grab_focus",
669 GTK_RUN_LAST | GTK_RUN_ACTION,
670 GTK_CLASS_TYPE (object_class),
671 GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_focus),
672 gtk_marshal_VOID__VOID,
674 widget_signals[FOCUS] =
675 g_signal_newc ("focus",
676 G_TYPE_FROM_CLASS (object_class),
678 G_STRUCT_OFFSET (GtkWidgetClass, focus),
679 _gtk_boolean_handled_accumulator, NULL,
680 gtk_marshal_BOOLEAN__ENUM,
682 GTK_TYPE_DIRECTION_TYPE);
683 widget_signals[EVENT] =
684 g_signal_newc ("event",
685 G_TYPE_FROM_CLASS(object_class),
687 G_STRUCT_OFFSET(GtkWidgetClass, event),
688 _gtk_boolean_handled_accumulator, NULL,
689 gtk_marshal_BOOLEAN__BOXED,
692 widget_signals[BUTTON_PRESS_EVENT] =
693 g_signal_newc ("button_press_event",
694 G_TYPE_FROM_CLASS(object_class),
696 G_STRUCT_OFFSET(GtkWidgetClass, button_press_event),
697 _gtk_boolean_handled_accumulator, NULL,
698 gtk_marshal_BOOLEAN__BOXED,
701 widget_signals[BUTTON_RELEASE_EVENT] =
702 g_signal_newc ("button_release_event",
703 G_TYPE_FROM_CLASS(object_class),
705 G_STRUCT_OFFSET(GtkWidgetClass, button_release_event),
706 _gtk_boolean_handled_accumulator, NULL,
707 gtk_marshal_BOOLEAN__BOXED,
710 widget_signals[SCROLL_EVENT] =
711 g_signal_newc ("scroll_event",
712 G_TYPE_FROM_CLASS(object_class),
714 G_STRUCT_OFFSET(GtkWidgetClass, scroll_event),
715 _gtk_boolean_handled_accumulator, NULL,
716 gtk_marshal_BOOLEAN__BOXED,
719 widget_signals[MOTION_NOTIFY_EVENT] =
720 g_signal_newc ("motion_notify_event",
721 G_TYPE_FROM_CLASS(object_class),
723 G_STRUCT_OFFSET(GtkWidgetClass, motion_notify_event),
724 _gtk_boolean_handled_accumulator, NULL,
725 gtk_marshal_BOOLEAN__BOXED,
728 widget_signals[DELETE_EVENT] =
729 g_signal_newc ("delete_event",
730 G_TYPE_FROM_CLASS(object_class),
732 G_STRUCT_OFFSET(GtkWidgetClass, delete_event),
733 _gtk_boolean_handled_accumulator, NULL,
734 gtk_marshal_BOOLEAN__BOXED,
737 widget_signals[DESTROY_EVENT] =
738 g_signal_newc ("destroy_event",
739 G_TYPE_FROM_CLASS(object_class),
741 G_STRUCT_OFFSET(GtkWidgetClass, destroy_event),
742 _gtk_boolean_handled_accumulator, NULL,
743 gtk_marshal_BOOLEAN__BOXED,
746 widget_signals[EXPOSE_EVENT] =
747 g_signal_newc ("expose_event",
748 G_TYPE_FROM_CLASS(object_class),
750 G_STRUCT_OFFSET(GtkWidgetClass, expose_event),
751 _gtk_boolean_handled_accumulator, NULL,
752 gtk_marshal_BOOLEAN__BOXED,
755 widget_signals[KEY_PRESS_EVENT] =
756 g_signal_newc ("key_press_event",
757 G_TYPE_FROM_CLASS(object_class),
759 G_STRUCT_OFFSET(GtkWidgetClass, key_press_event),
760 _gtk_boolean_handled_accumulator, NULL,
761 gtk_marshal_BOOLEAN__BOXED,
764 widget_signals[KEY_RELEASE_EVENT] =
765 g_signal_newc ("key_release_event",
766 G_TYPE_FROM_CLASS(object_class),
768 G_STRUCT_OFFSET(GtkWidgetClass, key_release_event),
769 _gtk_boolean_handled_accumulator, NULL,
770 gtk_marshal_BOOLEAN__BOXED,
773 widget_signals[ENTER_NOTIFY_EVENT] =
774 g_signal_newc ("enter_notify_event",
775 G_TYPE_FROM_CLASS(object_class),
777 G_STRUCT_OFFSET(GtkWidgetClass, enter_notify_event),
778 _gtk_boolean_handled_accumulator, NULL,
779 gtk_marshal_BOOLEAN__BOXED,
782 widget_signals[LEAVE_NOTIFY_EVENT] =
783 g_signal_newc ("leave_notify_event",
784 G_TYPE_FROM_CLASS(object_class),
786 G_STRUCT_OFFSET(GtkWidgetClass, leave_notify_event),
787 _gtk_boolean_handled_accumulator, NULL,
788 gtk_marshal_BOOLEAN__BOXED,
791 widget_signals[CONFIGURE_EVENT] =
792 g_signal_newc ("configure_event",
793 G_TYPE_FROM_CLASS(object_class),
795 G_STRUCT_OFFSET(GtkWidgetClass, configure_event),
796 _gtk_boolean_handled_accumulator, NULL,
797 gtk_marshal_BOOLEAN__BOXED,
800 widget_signals[FOCUS_IN_EVENT] =
801 g_signal_newc ("focus_in_event",
802 G_TYPE_FROM_CLASS(object_class),
804 G_STRUCT_OFFSET(GtkWidgetClass, focus_in_event),
805 _gtk_boolean_handled_accumulator, NULL,
806 gtk_marshal_BOOLEAN__BOXED,
809 widget_signals[FOCUS_OUT_EVENT] =
810 g_signal_newc ("focus_out_event",
811 G_TYPE_FROM_CLASS(object_class),
813 G_STRUCT_OFFSET(GtkWidgetClass, focus_out_event),
814 _gtk_boolean_handled_accumulator, NULL,
815 gtk_marshal_BOOLEAN__BOXED,
818 widget_signals[MAP_EVENT] =
819 g_signal_newc ("map_event",
820 G_TYPE_FROM_CLASS(object_class),
822 G_STRUCT_OFFSET(GtkWidgetClass, map_event),
823 _gtk_boolean_handled_accumulator, NULL,
824 gtk_marshal_BOOLEAN__BOXED,
827 widget_signals[UNMAP_EVENT] =
828 g_signal_newc ("unmap_event",
829 G_TYPE_FROM_CLASS(object_class),
831 G_STRUCT_OFFSET(GtkWidgetClass, unmap_event),
832 _gtk_boolean_handled_accumulator, NULL,
833 gtk_marshal_BOOLEAN__BOXED,
836 widget_signals[PROPERTY_NOTIFY_EVENT] =
837 g_signal_newc ("property_notify_event",
838 G_TYPE_FROM_CLASS(object_class),
840 G_STRUCT_OFFSET(GtkWidgetClass, property_notify_event),
841 _gtk_boolean_handled_accumulator, NULL,
842 gtk_marshal_BOOLEAN__BOXED,
845 widget_signals[SELECTION_CLEAR_EVENT] =
846 g_signal_newc ("selection_clear_event",
847 G_TYPE_FROM_CLASS(object_class),
849 G_STRUCT_OFFSET(GtkWidgetClass, selection_clear_event),
850 _gtk_boolean_handled_accumulator, NULL,
851 gtk_marshal_BOOLEAN__BOXED,
854 widget_signals[SELECTION_REQUEST_EVENT] =
855 g_signal_newc ("selection_request_event",
856 G_TYPE_FROM_CLASS(object_class),
858 G_STRUCT_OFFSET(GtkWidgetClass, selection_request_event),
859 _gtk_boolean_handled_accumulator, NULL,
860 gtk_marshal_BOOLEAN__BOXED,
863 widget_signals[SELECTION_NOTIFY_EVENT] =
864 g_signal_newc ("selection_notify_event",
865 G_TYPE_FROM_CLASS(object_class),
867 G_STRUCT_OFFSET(GtkWidgetClass, selection_notify_event),
868 _gtk_boolean_handled_accumulator, NULL,
869 gtk_marshal_BOOLEAN__BOXED,
872 widget_signals[SELECTION_RECEIVED] =
873 gtk_signal_new ("selection_received",
875 GTK_CLASS_TYPE (object_class),
876 GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_received),
877 gtk_marshal_VOID__BOXED_UINT,
879 GTK_TYPE_SELECTION_DATA,
881 widget_signals[SELECTION_GET] =
882 gtk_signal_new ("selection_get",
884 GTK_CLASS_TYPE (object_class),
885 GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_get),
886 gtk_marshal_VOID__BOXED_UINT_UINT,
888 GTK_TYPE_SELECTION_DATA,
891 widget_signals[PROXIMITY_IN_EVENT] =
892 g_signal_newc ("proximity_in_event",
893 G_TYPE_FROM_CLASS(object_class),
895 G_STRUCT_OFFSET(GtkWidgetClass, proximity_in_event),
896 _gtk_boolean_handled_accumulator, NULL,
897 gtk_marshal_BOOLEAN__BOXED,
900 widget_signals[PROXIMITY_OUT_EVENT] =
901 g_signal_newc ("proximity_out_event",
902 G_TYPE_FROM_CLASS(object_class),
904 G_STRUCT_OFFSET(GtkWidgetClass, proximity_out_event),
905 _gtk_boolean_handled_accumulator, NULL,
906 gtk_marshal_BOOLEAN__BOXED,
909 widget_signals[DRAG_LEAVE] =
910 gtk_signal_new ("drag_leave",
912 GTK_CLASS_TYPE (object_class),
913 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_leave),
914 gtk_marshal_VOID__OBJECT_UINT,
916 GDK_TYPE_DRAG_CONTEXT,
918 widget_signals[DRAG_BEGIN] =
919 gtk_signal_new ("drag_begin",
921 GTK_CLASS_TYPE (object_class),
922 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin),
923 gtk_marshal_VOID__OBJECT,
925 GDK_TYPE_DRAG_CONTEXT);
926 widget_signals[DRAG_END] =
927 gtk_signal_new ("drag_end",
929 GTK_CLASS_TYPE (object_class),
930 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end),
931 gtk_marshal_VOID__OBJECT,
933 GDK_TYPE_DRAG_CONTEXT);
934 widget_signals[DRAG_DATA_DELETE] =
935 gtk_signal_new ("drag_data_delete",
937 GTK_CLASS_TYPE (object_class),
938 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_delete),
939 gtk_marshal_VOID__OBJECT,
941 GDK_TYPE_DRAG_CONTEXT);
942 widget_signals[DRAG_MOTION] =
943 g_signal_newc ("drag_motion",
944 G_TYPE_FROM_CLASS(object_class),
946 G_STRUCT_OFFSET(GtkWidgetClass, drag_motion),
947 _gtk_boolean_handled_accumulator, NULL,
948 gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
950 GDK_TYPE_DRAG_CONTEXT,
954 widget_signals[DRAG_DROP] =
955 g_signal_newc ("drag_drop",
956 G_TYPE_FROM_CLASS(object_class),
958 G_STRUCT_OFFSET(GtkWidgetClass, drag_drop),
959 _gtk_boolean_handled_accumulator, NULL,
960 gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
962 GDK_TYPE_DRAG_CONTEXT,
966 widget_signals[DRAG_DATA_GET] =
967 gtk_signal_new ("drag_data_get",
969 GTK_CLASS_TYPE (object_class),
970 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_get),
971 gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
973 GDK_TYPE_DRAG_CONTEXT,
974 GTK_TYPE_SELECTION_DATA,
977 widget_signals[DRAG_DATA_RECEIVED] =
978 gtk_signal_new ("drag_data_received",
980 GTK_CLASS_TYPE (object_class),
981 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_received),
982 gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
984 GDK_TYPE_DRAG_CONTEXT,
987 GTK_TYPE_SELECTION_DATA,
990 widget_signals[VISIBILITY_NOTIFY_EVENT] =
991 g_signal_newc ("visibility_notify_event",
992 G_TYPE_FROM_CLASS(object_class),
994 G_STRUCT_OFFSET(GtkWidgetClass, visibility_notify_event),
995 _gtk_boolean_handled_accumulator, NULL,
996 gtk_marshal_BOOLEAN__BOXED,
999 widget_signals[CLIENT_EVENT] =
1000 g_signal_newc ("client_event",
1001 G_TYPE_FROM_CLASS(object_class),
1003 G_STRUCT_OFFSET(GtkWidgetClass, client_event),
1004 _gtk_boolean_handled_accumulator, NULL,
1005 gtk_marshal_BOOLEAN__BOXED,
1008 widget_signals[NO_EXPOSE_EVENT] =
1009 g_signal_newc ("no_expose_event",
1010 G_TYPE_FROM_CLASS(object_class),
1012 G_STRUCT_OFFSET(GtkWidgetClass, no_expose_event),
1013 _gtk_boolean_handled_accumulator, NULL,
1014 gtk_marshal_BOOLEAN__BOXED,
1017 widget_signals[WINDOW_STATE_EVENT] =
1018 g_signal_newc ("window_state_event",
1019 G_TYPE_FROM_CLASS(object_class),
1021 G_STRUCT_OFFSET(GtkWidgetClass, window_state_event),
1022 _gtk_boolean_handled_accumulator, NULL,
1023 gtk_marshal_BOOLEAN__BOXED,
1026 widget_signals[POPUP_MENU] =
1027 gtk_signal_new ("popup_menu",
1028 GTK_RUN_LAST | GTK_RUN_ACTION,
1029 GTK_CLASS_TYPE (object_class),
1030 GTK_SIGNAL_OFFSET (GtkWidgetClass, popup_menu),
1031 gtk_marshal_NONE__NONE,
1034 binding_set = gtk_binding_set_by_class (klass);
1035 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1037 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1040 gtk_widget_class_install_style_property (klass,
1041 g_param_spec_boolean ("interior_focus",
1042 _("Interior Focus"),
1043 _("Whether to draw the focus indicator inside widgets."),
1049 gtk_widget_set_property (GObject *object,
1051 const GValue *value,
1055 GtkWidgetAuxInfo *aux_info;
1057 widget = GTK_WIDGET (object);
1061 guint32 saved_flags;
1064 gtk_widget_set_name (widget, g_value_get_string (value));
1067 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1070 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
1071 if (g_value_get_int (value) == -1)
1072 aux_info->x_set = FALSE;
1075 aux_info->x_set = TRUE;
1076 aux_info->x = g_value_get_int (value);
1078 gtk_widget_do_uposition (widget);
1081 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
1082 if (g_value_get_int (value) == -1)
1083 aux_info->y_set = FALSE;
1086 aux_info->y_set = TRUE;
1087 aux_info->y = g_value_get_int (value);
1089 gtk_widget_do_uposition (widget);
1092 gtk_widget_set_usize (widget, g_value_get_int (value), -2);
1095 gtk_widget_set_usize (widget, -2, g_value_get_int (value));
1098 if (g_value_get_boolean (value))
1099 gtk_widget_show (widget);
1101 gtk_widget_hide (widget);
1103 case PROP_SENSITIVE:
1104 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1106 case PROP_APP_PAINTABLE:
1107 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1109 case PROP_CAN_FOCUS:
1110 saved_flags = GTK_WIDGET_FLAGS (widget);
1111 if (g_value_get_boolean (value))
1112 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1114 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1115 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1116 gtk_widget_queue_resize (widget);
1118 case PROP_HAS_FOCUS:
1119 if (g_value_get_boolean (value))
1120 gtk_widget_grab_focus (widget);
1122 case PROP_CAN_DEFAULT:
1123 saved_flags = GTK_WIDGET_FLAGS (widget);
1124 if (g_value_get_boolean (value))
1125 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1127 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1128 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1129 gtk_widget_queue_resize (widget);
1131 case PROP_HAS_DEFAULT:
1132 if (g_value_get_boolean (value))
1133 gtk_widget_grab_default (widget);
1135 case PROP_RECEIVES_DEFAULT:
1136 if (g_value_get_boolean (value))
1137 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1139 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1141 case PROP_COMPOSITE_CHILD:
1142 if (g_value_get_boolean (value))
1143 GTK_WIDGET_SET_FLAGS (widget, GTK_COMPOSITE_CHILD);
1145 GTK_WIDGET_UNSET_FLAGS (widget, GTK_COMPOSITE_CHILD);
1148 gtk_widget_set_style (widget, g_value_get_object (value));
1151 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1152 gtk_widget_set_events (widget, g_value_get_flags (value));
1154 case PROP_EXTENSION_EVENTS:
1155 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1163 gtk_widget_get_property (GObject *object,
1170 widget = GTK_WIDGET (object);
1174 GtkWidgetAuxInfo *aux_info;
1176 GdkExtensionMode *modep;
1180 g_value_set_string (value, widget->name);
1182 g_value_set_string (value, "");
1186 g_value_set_object (value, G_OBJECT (widget->parent));
1188 g_value_set_object (value, NULL);
1191 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1192 if (!aux_info || !aux_info->x_set)
1193 g_value_set_int (value, -1);
1195 g_value_set_int (value, aux_info->x);
1198 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1199 if (!aux_info || !aux_info->y_set)
1200 g_value_set_int (value, -1);
1202 g_value_set_int (value, aux_info->y);
1205 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1207 g_value_set_int (value, -1);
1209 g_value_set_int (value, aux_info->width);
1212 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
1214 g_value_set_int (value, -1);
1216 g_value_set_int (value, aux_info->height);
1219 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1221 case PROP_SENSITIVE:
1222 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1224 case PROP_APP_PAINTABLE:
1225 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1227 case PROP_CAN_FOCUS:
1228 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1230 case PROP_HAS_FOCUS:
1231 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1233 case PROP_CAN_DEFAULT:
1234 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1236 case PROP_HAS_DEFAULT:
1237 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1239 case PROP_RECEIVES_DEFAULT:
1240 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1242 case PROP_COMPOSITE_CHILD:
1243 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1246 g_value_set_object (value, G_OBJECT (gtk_widget_get_style (widget)));
1249 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
1251 g_value_set_flags (value, 0);
1253 g_value_set_flags (value, *eventp);
1255 case PROP_EXTENSION_EVENTS:
1256 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
1258 g_value_set_enum (value, 0);
1260 g_value_set_enum (value, (GdkExtensionMode) *modep);
1263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1269 gtk_widget_init (GtkWidget *widget)
1271 GdkColormap *colormap;
1273 GTK_PRIVATE_FLAGS (widget) = 0;
1274 widget->state = GTK_STATE_NORMAL;
1275 widget->saved_state = GTK_STATE_NORMAL;
1276 widget->name = NULL;
1277 widget->requisition.width = 0;
1278 widget->requisition.height = 0;
1279 widget->allocation.x = -1;
1280 widget->allocation.y = -1;
1281 widget->allocation.width = 1;
1282 widget->allocation.height = 1;
1283 widget->window = NULL;
1284 widget->parent = NULL;
1286 GTK_WIDGET_SET_FLAGS (widget,
1288 GTK_PARENT_SENSITIVE |
1289 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1290 GTK_DOUBLE_BUFFERED);
1292 widget->style = gtk_widget_peek_style ();
1293 gtk_style_ref (widget->style);
1295 colormap = gtk_widget_peek_colormap ();
1297 if (colormap != gtk_widget_get_default_colormap ())
1298 gtk_widget_set_colormap (widget, colormap);
1303 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1305 GParamSpec **pspecs)
1307 GtkWidget *container = widget->parent;
1310 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1311 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1315 gtk_widget_freeze_child_notify (GtkWidget *widget)
1317 g_return_if_fail (GTK_IS_WIDGET (widget));
1319 if (!G_OBJECT (widget)->ref_count)
1322 g_object_ref (widget);
1323 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1324 g_object_unref (widget);
1328 gtk_widget_child_notify (GtkWidget *widget,
1329 const gchar *child_property)
1333 g_return_if_fail (GTK_IS_WIDGET (widget));
1334 g_return_if_fail (child_property != NULL);
1335 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1338 g_object_ref (widget);
1339 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1341 G_OBJECT_TYPE (widget->parent),
1344 g_warning ("%s: container class `%s' has no child property named `%s'",
1346 G_OBJECT_TYPE_NAME (widget->parent),
1350 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1352 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1353 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1355 g_object_unref (widget);
1359 gtk_widget_thaw_child_notify (GtkWidget *widget)
1361 GObjectNotifyQueue *nqueue;
1363 g_return_if_fail (GTK_IS_WIDGET (widget));
1365 if (!G_OBJECT (widget)->ref_count)
1368 g_object_ref (widget);
1369 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1370 if (!nqueue || !nqueue->freeze_count)
1371 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1372 G_OBJECT_TYPE_NAME (widget), widget);
1374 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1375 g_object_unref (widget);
1381 * @type: type ID of the widget to create
1382 * @first_property_name: name of first property to set
1383 * @Varargs: value of first property, followed by more properties, NULL-terminated
1385 * This is a convenience function for creating a widget and setting
1386 * its properties in one go. For example you might write:
1387 * gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1388 * 0.0, NULL) to create a left-aligned label. Equivalent to
1389 * gtk_object_new(), but returns a widget so you don't have to
1390 * cast the object yourself.
1392 * Return value: a new #GtkWidget of type @widget_type
1395 gtk_widget_new (GtkType type,
1396 const gchar *first_property_name,
1402 g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1404 va_start (var_args, first_property_name);
1405 widget = g_object_new_valist (type, first_property_name, var_args);
1413 * @widget: a #GtkWidget
1414 * @first_property_name: name of first property to set
1415 * @Varargs: value of first property, followed by more properties, NULL-terminated
1417 * Like gtk_object_set() - there's no reason to use this instead of
1421 gtk_widget_set (GtkWidget *widget,
1422 const gchar *first_property_name,
1427 g_return_if_fail (GTK_IS_WIDGET (widget));
1429 va_start (var_args, first_property_name);
1430 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1435 gtk_widget_queue_clear_child (GtkWidget *widget)
1439 parent = widget->parent;
1440 if (parent && GTK_WIDGET_DRAWABLE (parent))
1441 gtk_widget_queue_clear_area (parent,
1442 widget->allocation.x,
1443 widget->allocation.y,
1444 widget->allocation.width,
1445 widget->allocation.height);
1449 * gtk_widget_unparent:
1450 * @widget: a #GtkWidget
1452 * This function is only for use in widget implementations.
1453 * Should be called by implementations of the remove method
1454 * on #GtkContainer, to dissociate a child from the container.
1457 gtk_widget_unparent (GtkWidget *widget)
1459 GObjectNotifyQueue *nqueue;
1460 GtkWidget *toplevel;
1461 GtkWidget *old_parent;
1463 g_return_if_fail (widget != NULL);
1464 g_return_if_fail (GTK_IS_WIDGET (widget));
1465 if (widget->parent == NULL)
1468 /* keep this function in sync with gtk_menu_detach()
1471 g_object_freeze_notify (G_OBJECT (widget));
1472 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1474 /* unset focused and default children properly, this code
1475 * should eventually move into some gtk_window_unparent_branch() or
1479 toplevel = gtk_widget_get_toplevel (widget);
1480 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1482 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1484 if (GTK_IS_WINDOW (toplevel))
1488 child = GTK_WINDOW (toplevel)->focus_widget;
1490 while (child && child != widget)
1491 child = child->parent;
1493 if (child == widget)
1494 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1497 if (GTK_IS_WINDOW (toplevel))
1501 child = GTK_WINDOW (toplevel)->default_widget;
1503 while (child && child != widget)
1504 child = child->parent;
1506 if (child == widget)
1507 gtk_window_set_default (GTK_WINDOW (toplevel), NULL);
1510 if (GTK_IS_RESIZE_CONTAINER (widget))
1511 gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
1513 /* Remove the widget and all its children from any ->resize_widgets list
1514 * of all the parents in our branch. This code should move into gtkcontainer.c
1515 * somwhen, since we mess around with ->resize_widgets, which is
1516 * actually not of our business.
1518 * Two ways to make this prettier:
1519 * Write a g_slist_conditional_remove (GSList, gboolean (*)(gpointer))
1520 * Change resize_widgets to a GList
1522 toplevel = widget->parent;
1528 if (!GTK_CONTAINER (toplevel)->resize_widgets)
1530 toplevel = toplevel->parent;
1535 slist = GTK_CONTAINER (toplevel)->resize_widgets;
1547 while (parent && (parent != widget))
1548 parent = parent->parent;
1550 if (parent == widget)
1552 GTK_PRIVATE_UNSET_FLAG (child, GTK_RESIZE_NEEDED);
1557 GTK_CONTAINER (toplevel)->resize_widgets = slist;
1559 g_slist_free_1 (last);
1565 toplevel = toplevel->parent;
1568 gtk_widget_queue_clear_child (widget);
1570 /* Reset the width and height here, to force reallocation if we
1571 * get added back to a new parent. This won't work if our new
1572 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1573 * (would 0x0 be OK here?)
1575 widget->allocation.width = 1;
1576 widget->allocation.height = 1;
1578 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1579 gtk_widget_unrealize (widget);
1581 old_parent = widget->parent;
1582 widget->parent = NULL;
1583 gtk_widget_set_parent_window (widget, NULL);
1584 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], old_parent);
1585 gtk_widget_propagate_hierarchy_changed (widget, NULL);
1586 g_object_notify (G_OBJECT (widget), "parent");
1587 g_object_thaw_notify (G_OBJECT (widget));
1588 if (!widget->parent)
1589 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1590 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1591 gtk_widget_unref (widget);
1595 * gtk_widget_destroy:
1596 * @widget: a #GtkWidget
1598 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1599 * you don't have to cast the widget to #GtkObject. When a widget is
1600 * destroyed, it will break any references it holds to other objects.
1601 * If the widget is inside a container, the widget will be removed
1602 * from the container. If the widget is a toplevel (derived from
1603 * #GtkWindow), it will be removed from the list of toplevels, and the
1604 * reference GTK+ holds to it will be removed. Removing a
1605 * widget from its container or the list of toplevels results in the
1606 * widget being finalized, unless you've added additional references
1607 * to the widget with gtk_object_ref().
1609 * In most cases, only toplevel widgets (windows) require explicit
1610 * destruction, because when you destroy a toplevel its children will
1611 * be destroyed as well.
1615 gtk_widget_destroy (GtkWidget *widget)
1617 g_return_if_fail (widget != NULL);
1618 g_return_if_fail (GTK_IS_WIDGET (widget));
1620 gtk_object_destroy ((GtkObject*) widget);
1624 * gtk_widget_destroyed:
1625 * @widget: a #GtkWidget
1626 * @widget_pointer: address of a variable that contains @widget
1628 * This function sets *@widget_pointer to NULL if @widget_pointer !=
1629 * NULL. It's intended to be used as a callback connected to the
1630 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1631 * as a signal handler, and pass the address of your widget variable
1632 * as user data. Then when the widget is destroyed, the variable will
1633 * be set to NULL. Useful for example to avoid multiple copies
1634 * of the same dialog.
1638 gtk_widget_destroyed (GtkWidget *widget,
1639 GtkWidget **widget_pointer)
1641 /* Don't make any assumptions about the
1643 * Even check widget_pointer.
1646 *widget_pointer = NULL;
1651 * @widget: a #GtkWidget
1653 * Flags a widget to be displayed. Any widget that isn't shown will
1654 * not appear on the screen. If you want to show all the widgets in a
1655 * container, it's easier to call gtk_widget_show_all() on the
1656 * container, instead of individually showing the widgets.
1658 * Remember that you have to show the containers containing a widget,
1659 * in addition to the widget itself, before it will appear onscreen.
1661 * When a toplevel container is shown, it is immediately realized and
1662 * mapped; other shown widgets are realized and mapped when their
1663 * toplevel container is realized and mapped.
1667 gtk_widget_show (GtkWidget *widget)
1669 g_return_if_fail (widget != NULL);
1670 g_return_if_fail (GTK_IS_WIDGET (widget));
1672 if (!GTK_WIDGET_VISIBLE (widget))
1674 g_object_ref (G_OBJECT (widget));
1675 if (!GTK_WIDGET_TOPLEVEL (widget))
1676 gtk_widget_queue_resize (widget);
1677 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SHOW]);
1678 g_object_notify (G_OBJECT (widget), "visible");
1679 g_object_unref (G_OBJECT (widget));
1684 gtk_widget_real_show (GtkWidget *widget)
1686 g_return_if_fail (widget != NULL);
1687 g_return_if_fail (GTK_IS_WIDGET (widget));
1689 if (!GTK_WIDGET_VISIBLE (widget))
1691 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1693 if (widget->parent &&
1694 GTK_WIDGET_MAPPED (widget->parent) &&
1695 !GTK_WIDGET_MAPPED (widget))
1696 gtk_widget_map (widget);
1701 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1704 gtk_signal_disconnect_by_data (GTK_OBJECT (widget), flag);
1708 * gtk_widget_show_now:
1709 * @widget: a #GtkWidget
1711 * Shows a widget. If the widget is an unmapped toplevel widget
1712 * (i.e. a #GtkWindow that has not yet been shown), enter the main
1713 * loop and wait for the window to actually be mapped. Be careful;
1714 * because the main loop is running, anything can happen during
1718 gtk_widget_show_now (GtkWidget *widget)
1722 g_return_if_fail (widget != NULL);
1723 g_return_if_fail (GTK_IS_WIDGET (widget));
1725 /* make sure we will get event */
1726 if (!GTK_WIDGET_MAPPED (widget) &&
1727 GTK_WIDGET_TOPLEVEL (widget))
1729 gtk_widget_show (widget);
1731 gtk_signal_connect (GTK_OBJECT (widget), "map_event",
1732 GTK_SIGNAL_FUNC (gtk_widget_show_map_callback),
1736 gtk_main_iteration();
1739 gtk_widget_show (widget);
1744 * @widget: a #GtkWidget
1746 * Reverses the effects of gtk_widget_show(), causing the widget to be
1747 * hidden (invisible to the user).
1750 gtk_widget_hide (GtkWidget *widget)
1752 g_return_if_fail (widget != NULL);
1753 g_return_if_fail (GTK_IS_WIDGET (widget));
1755 if (GTK_WIDGET_VISIBLE (widget))
1757 gtk_widget_ref (widget);
1758 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[HIDE]);
1759 if (!GTK_WIDGET_TOPLEVEL (widget) && !GTK_OBJECT_DESTROYED (widget))
1760 gtk_widget_queue_resize (widget);
1761 g_object_notify (G_OBJECT (widget), "visible");
1762 gtk_widget_unref (widget);
1767 gtk_widget_real_hide (GtkWidget *widget)
1769 g_return_if_fail (widget != NULL);
1770 g_return_if_fail (GTK_IS_WIDGET (widget));
1772 if (GTK_WIDGET_VISIBLE (widget))
1774 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1776 if (GTK_WIDGET_MAPPED (widget))
1777 gtk_widget_unmap (widget);
1782 * gtk_widget_hide_on_delete:
1783 * @widget: a #GtkWidget
1785 * Utility function; intended to be connected to the "delete_event"
1786 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
1787 * argument, then returns %TRUE. If connected to "delete_event",
1788 * the result is that clicking the window manager close button for
1789 * will hide but not destroy the window. By default, GTK+ destroys
1790 * windows when "delete_event" is received.
1792 * Return value: %TRUE
1795 gtk_widget_hide_on_delete (GtkWidget *widget)
1797 g_return_val_if_fail (widget != NULL, FALSE);
1798 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1800 gtk_widget_hide (widget);
1806 * gtk_widget_show_all:
1807 * @widget: a #GtkWidget
1809 * Recursively shows a widget, and any child widgets (if the widget is
1813 gtk_widget_show_all (GtkWidget *widget)
1815 GtkWidgetClass *class;
1817 g_return_if_fail (widget != NULL);
1818 g_return_if_fail (GTK_IS_WIDGET (widget));
1820 class = GTK_WIDGET_GET_CLASS (widget);
1822 if (class->show_all)
1823 class->show_all (widget);
1827 * gtk_widget_hide_all:
1828 * @widget: a #GtkWidget
1830 * Recursively hides a widget and any child widgets.
1833 gtk_widget_hide_all (GtkWidget *widget)
1835 GtkWidgetClass *class;
1837 g_return_if_fail (widget != NULL);
1838 g_return_if_fail (GTK_IS_WIDGET (widget));
1840 class = GTK_WIDGET_GET_CLASS (widget);
1842 if (class->hide_all)
1843 class->hide_all (widget);
1848 * @widget: a #GtkWidget
1850 * This function is only for use in widget implementations. Causes
1851 * a widget to be mapped if it isn't already.
1855 gtk_widget_map (GtkWidget *widget)
1857 g_return_if_fail (GTK_IS_WIDGET (widget));
1858 g_return_if_fail (GTK_WIDGET_VISIBLE (widget) == TRUE);
1860 if (!GTK_WIDGET_MAPPED (widget))
1862 if (!GTK_WIDGET_REALIZED (widget))
1863 gtk_widget_realize (widget);
1865 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[MAP]);
1867 if (GTK_WIDGET_NO_WINDOW (widget))
1868 gtk_widget_queue_draw (widget);
1874 * @widget: a #GtkWidget
1876 * This function is only for use in widget implementations. Causes
1877 * a widget to be unmapped if it's currently mapped.
1881 gtk_widget_unmap (GtkWidget *widget)
1883 g_return_if_fail (widget != NULL);
1884 g_return_if_fail (GTK_IS_WIDGET (widget));
1886 if (GTK_WIDGET_MAPPED (widget))
1888 if (GTK_WIDGET_NO_WINDOW (widget))
1889 gtk_widget_queue_clear_child (widget);
1890 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNMAP]);
1895 * gtk_widget_realize:
1896 * @widget: a #GtkWidget
1898 * Creates the GDK (windowing system) resources associated with a
1899 * widget. For example, widget->window will be created when a widget
1900 * is realized. Normally realization happens implicitly; if you show
1901 * a widget and all its parent containers, then the widget will be
1902 * realized and mapped automatically.
1904 * Realizing a widget requires all
1905 * the widget's parent widgets to be realized; calling
1906 * gtk_widget_realize() realizes the widget's parents in addition to
1907 * @widget itself. If a widget is not yet inside a toplevel window
1908 * when you realize it, bad things will happen.
1910 * This function is primarily used in widget implementations, and
1911 * isn't very useful otherwise. Many times when you think you might
1912 * need it, a better approach is to connect to a signal that will be
1913 * called after the widget is realized automatically, such as
1914 * "expose_event". Or simply gtk_signal_connect_after() to the
1919 gtk_widget_realize (GtkWidget *widget)
1922 GdkExtensionMode mode;
1923 GtkWidgetShapeInfo *shape_info;
1925 g_return_if_fail (widget != NULL);
1926 g_return_if_fail (GTK_IS_WIDGET (widget));
1928 if (!GTK_WIDGET_REALIZED (widget))
1931 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1932 g_message ("gtk_widget_realize(%s)", gtk_type_name (GTK_WIDGET_TYPE (widget)));
1935 if (widget->parent == NULL &&
1936 !GTK_WIDGET_TOPLEVEL (widget))
1937 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
1938 "inside a toplevel window is not going to work very well. "
1939 "Widgets must be inside a toplevel container before realizing them.");
1941 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
1942 gtk_widget_realize (widget->parent);
1944 gtk_widget_ensure_style (widget);
1946 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[REALIZE]);
1948 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1950 shape_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_shape_info);
1951 gdk_window_shape_combine_mask (widget->window,
1952 shape_info->shape_mask,
1953 shape_info->offset_x,
1954 shape_info->offset_y);
1957 if (!GTK_WIDGET_NO_WINDOW (widget))
1959 mode = gtk_widget_get_extension_events (widget);
1960 if (mode != GDK_EXTENSION_EVENTS_NONE)
1962 events = gtk_widget_get_events (widget);
1963 gdk_input_set_extension_events (widget->window, events, mode);
1971 * gtk_widget_unrealize:
1972 * @widget: a #GtkWidget
1974 * This function is only useful in widget implementations.
1975 * Causes a widget to be unrealized (frees all GDK resources
1976 * associated with the widget, such as widget->window).
1980 gtk_widget_unrealize (GtkWidget *widget)
1982 g_return_if_fail (widget != NULL);
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 gtk_widget_ref (widget);
1991 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNREALIZE]);
1992 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
1993 gtk_widget_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 g_return_if_fail (widget != NULL);
2039 g_return_if_fail (GTK_IS_WIDGET (widget));
2041 gtk_widget_queue_clear_area (widget, x, y, width, height);
2045 * gtk_widget_queue_draw:
2046 * @widget: a #GtkWidget
2048 * Equivalent to calling gtk_widget_queue_draw_area() for the
2049 * entire area of a widget.
2053 gtk_widget_queue_draw (GtkWidget *widget)
2055 g_return_if_fail (widget != NULL);
2056 g_return_if_fail (GTK_IS_WIDGET (widget));
2058 gtk_widget_queue_clear (widget);
2061 /* Invalidates the given area (allocation-relative-coordinates)
2062 * in all of the widget's windows
2065 * gtk_widget_queue_clear_area:
2066 * @widget: a #GtkWidget
2067 * @x: x coordinate of upper-left corner of rectangle to redraw
2068 * @y: y coordinate of upper-left corner of rectangle to redraw
2069 * @width: width of region to draw
2070 * @height: height of region to draw
2072 * DEPRECATED. This function is no longer different from
2073 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2074 * gtk_widget_queue_draw_area(). Originally
2075 * gtk_widget_queue_clear_area() would force a redraw of the
2076 * background for GTK_NO_WINDOW widgets, and
2077 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2078 * the background will be redrawn.
2082 gtk_widget_queue_clear_area (GtkWidget *widget,
2088 GdkRectangle invalid_rect;
2090 g_return_if_fail (widget != NULL);
2091 g_return_if_fail (GTK_IS_WIDGET (widget));
2093 if (!(widget->window && gdk_window_is_viewable (widget->window)))
2096 /* Find the correct widget */
2098 if (!GTK_WIDGET_NO_WINDOW (widget))
2102 /* Translate widget relative to window-relative */
2104 gint wx, wy, wwidth, wheight;
2106 gdk_window_get_position (widget->window, &wx, &wy);
2107 x -= wx - widget->allocation.x;
2108 y -= wy - widget->allocation.y;
2110 gdk_window_get_size (widget->window, &wwidth, &wheight);
2112 if (x + width <= 0 || y + height <= 0 ||
2113 x >= wwidth || y >= wheight)
2124 if (x + width > wwidth)
2126 if (y + height > wheight)
2127 height = wheight - y;
2133 invalid_rect.width = width;
2134 invalid_rect.height = height;
2136 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2140 * gtk_widget_queue_clear:
2141 * @widget: a #GtkWidget
2143 * DEPRECATED. Use gtk_widget_queue_draw() instead.
2146 gtk_widget_queue_clear (GtkWidget *widget)
2148 g_return_if_fail (widget != NULL);
2149 g_return_if_fail (GTK_IS_WIDGET (widget));
2151 if (widget->allocation.width || widget->allocation.height)
2153 if (GTK_WIDGET_NO_WINDOW (widget))
2154 gtk_widget_queue_clear_area (widget, widget->allocation.x,
2155 widget->allocation.y,
2156 widget->allocation.width,
2157 widget->allocation.height);
2159 gtk_widget_queue_clear_area (widget, 0, 0,
2160 widget->allocation.width,
2161 widget->allocation.height);
2166 * gtk_widget_queue_resize:
2167 * @widget: a #GtkWidget
2169 * This function is only for use in widget implementations.
2170 * Flags a widget to have its size renegotiated; should
2171 * be called when a widget for some reason has a new size request.
2172 * For example, when you change the text in a #GtkLabel, #GtkLabel
2173 * queues a resize to ensure there's enough space for the new text.
2177 gtk_widget_queue_resize (GtkWidget *widget)
2179 g_return_if_fail (widget != NULL);
2180 g_return_if_fail (GTK_IS_WIDGET (widget));
2182 gtk_widget_queue_clear (widget);
2184 _gtk_size_group_queue_resize (widget);
2189 * @widget: a #GtkWidget
2190 * @area: area to draw
2192 * DEPRECATED. In GTK+ 1.2, this function would immediately render the
2193 * region @area of a widget, by invoking the virtual draw method of a
2194 * widget. In GTK+ 2.0, the draw method is gone, and instead
2195 * gtk_widget_draw() simply invalidates the specified region of the
2196 * widget, then updates the invalid region of the widget immediately.
2197 * Usually you don't want to update the region immediately for
2198 * performance reasons, so in general gtk_widget_queue_draw_area() is
2199 * a better choice if you want to draw a region of a widget.
2203 gtk_widget_draw (GtkWidget *widget,
2206 g_return_if_fail (widget != NULL);
2207 g_return_if_fail (GTK_IS_WIDGET (widget));
2209 if (GTK_WIDGET_DRAWABLE (widget))
2212 gtk_widget_queue_draw_area (widget,
2214 area->width, area->height);
2216 gtk_widget_queue_draw (widget);
2218 gdk_window_process_updates (widget->window, TRUE);
2223 * gtk_widget_size_request:
2224 * @widget: a #GtkWidget
2225 * @requisition: a #GtkRequisition to be filled in
2227 * This function is only used when implementing a #GtkContainer subclass.
2228 * Obtains the preferred size of a widget. The container uses this
2229 * information to arrange its child widgets and decide what size allocations
2230 * to give them with gtk_widget_size_allocate().
2233 gtk_widget_size_request (GtkWidget *widget,
2234 GtkRequisition *requisition)
2236 g_return_if_fail (widget != NULL);
2237 g_return_if_fail (GTK_IS_WIDGET (widget));
2239 #ifdef G_ENABLE_DEBUG
2240 if (requisition == &widget->requisition)
2241 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.");
2242 #endif /* G_ENABLE_DEBUG */
2244 _gtk_size_group_compute_requisition (widget, requisition);
2248 gtk_widget_get_child_requisition (widget, requisition);
2250 gtk_widget_unref (widget);
2255 * gtk_widget_get_child_requisition:
2256 * @widget: a #GtkWidget
2257 * @requisition: a #GtkRequisition to be filled in
2259 * This function is only for use in widget implementations. Obtains
2260 * @widget->requisition, unless someone has forced a particular
2261 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2262 * case it returns that geometry instead of the widget's requisition.
2265 gtk_widget_get_child_requisition (GtkWidget *widget,
2266 GtkRequisition *requisition)
2268 _gtk_size_group_get_child_requisition (widget, requisition);
2272 * gtk_widget_size_allocate:
2273 * @widget: a #GtkWidget
2274 * @allocation: position and size to be allocated to @widget
2276 * This function is only used by #GtkContainer subclasses, to assign a size
2277 * and position to their child widgets.
2281 gtk_widget_size_allocate (GtkWidget *widget,
2282 GtkAllocation *allocation)
2284 GtkWidgetAuxInfo *aux_info;
2285 GtkAllocation real_allocation;
2286 gboolean needs_draw = FALSE;
2288 g_return_if_fail (widget != NULL);
2289 g_return_if_fail (GTK_IS_WIDGET (widget));
2291 real_allocation = *allocation;
2292 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2296 if (aux_info->x_set)
2297 real_allocation.x = aux_info->x;
2298 if (aux_info->y_set)
2299 real_allocation.y = aux_info->y;
2302 real_allocation.width = MAX (real_allocation.width, 1);
2303 real_allocation.height = MAX (real_allocation.height, 1);
2305 if (real_allocation.width < 0 || real_allocation.height < 0)
2307 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2308 real_allocation.width,
2309 real_allocation.height);
2310 real_allocation.width = 1;
2311 real_allocation.height = 1;
2314 if (GTK_WIDGET_NO_WINDOW (widget))
2316 if (widget->allocation.x != real_allocation.x ||
2317 widget->allocation.y != real_allocation.y ||
2318 widget->allocation.width != real_allocation.width ||
2319 widget->allocation.height != real_allocation.height)
2321 gtk_widget_queue_clear_child (widget);
2325 else if (widget->allocation.width != real_allocation.width ||
2326 widget->allocation.height != real_allocation.height)
2331 if (GTK_IS_RESIZE_CONTAINER (widget))
2332 gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
2334 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE], &real_allocation);
2338 gtk_widget_queue_draw (widget);
2339 if (widget->parent && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2340 gtk_widget_queue_draw (widget->parent);
2345 gtk_widget_real_size_allocate (GtkWidget *widget,
2346 GtkAllocation *allocation)
2348 g_return_if_fail (widget != NULL);
2349 g_return_if_fail (GTK_IS_WIDGET (widget));
2351 widget->allocation = *allocation;
2353 if (GTK_WIDGET_REALIZED (widget) &&
2354 !GTK_WIDGET_NO_WINDOW (widget))
2356 gdk_window_move_resize (widget->window,
2357 allocation->x, allocation->y,
2358 allocation->width, allocation->height);
2363 gtk_widget_stop_add_accelerator (GtkWidget *widget)
2365 g_return_if_fail (widget != NULL);
2366 g_return_if_fail (GTK_IS_WIDGET (widget));
2368 gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[ADD_ACCELERATOR]);
2372 gtk_widget_stop_remove_accelerator (GtkWidget *widget)
2374 g_return_if_fail (widget != NULL);
2375 g_return_if_fail (GTK_IS_WIDGET (widget));
2377 gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[REMOVE_ACCELERATOR]);
2381 gtk_widget_lock_accelerators (GtkWidget *widget)
2383 g_return_if_fail (widget != NULL);
2384 g_return_if_fail (GTK_IS_WIDGET (widget));
2386 if (!gtk_widget_accelerators_locked (widget))
2388 gtk_signal_connect (GTK_OBJECT (widget),
2390 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2392 gtk_signal_connect (GTK_OBJECT (widget),
2393 "remove_accelerator",
2394 GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2400 gtk_widget_unlock_accelerators (GtkWidget *widget)
2402 g_return_if_fail (widget != NULL);
2403 g_return_if_fail (GTK_IS_WIDGET (widget));
2405 if (gtk_widget_accelerators_locked (widget))
2407 gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2408 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2410 gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2411 GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2417 gtk_widget_accelerators_locked (GtkWidget *widget)
2419 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2421 return gtk_signal_handler_pending_by_func (GTK_OBJECT (widget),
2422 widget_signals[ADD_ACCELERATOR],
2424 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2429 gtk_widget_add_accelerator (GtkWidget *widget,
2430 const gchar *accel_signal,
2431 GtkAccelGroup *accel_group,
2434 GtkAccelFlags accel_flags)
2436 g_return_if_fail (widget != NULL);
2437 g_return_if_fail (GTK_IS_WIDGET (widget));
2438 g_return_if_fail (accel_group != NULL);
2440 gtk_accel_group_add (accel_group,
2444 (GtkObject*) widget,
2449 gtk_widget_remove_accelerator (GtkWidget *widget,
2450 GtkAccelGroup *accel_group,
2454 g_return_if_fail (widget != NULL);
2455 g_return_if_fail (GTK_IS_WIDGET (widget));
2456 g_return_if_fail (accel_group != NULL);
2458 gtk_accel_group_remove (accel_group,
2461 (GtkObject*) widget);
2465 gtk_widget_remove_accelerators (GtkWidget *widget,
2466 const gchar *accel_signal,
2467 gboolean visible_only)
2472 g_return_if_fail (widget != NULL);
2473 g_return_if_fail (GTK_IS_WIDGET (widget));
2474 g_return_if_fail (accel_signal != NULL);
2476 signal_id = gtk_signal_lookup (accel_signal, GTK_OBJECT_TYPE (widget));
2477 g_return_if_fail (signal_id != 0);
2479 slist = gtk_accel_group_entries_from_object (GTK_OBJECT (widget));
2482 GtkAccelEntry *ac_entry;
2484 ac_entry = slist->data;
2485 slist = slist->next;
2486 if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE &&
2487 ac_entry->signal_id == signal_id)
2488 gtk_widget_remove_accelerator (GTK_WIDGET (widget),
2489 ac_entry->accel_group,
2490 ac_entry->accelerator_key,
2491 ac_entry->accelerator_mods);
2496 gtk_widget_accelerator_signal (GtkWidget *widget,
2497 GtkAccelGroup *accel_group,
2501 GtkAccelEntry *ac_entry;
2503 g_return_val_if_fail (widget != NULL, 0);
2504 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
2505 g_return_val_if_fail (accel_group != NULL, 0);
2507 ac_entry = gtk_accel_group_get_entry (accel_group, accel_key, accel_mods);
2509 if (ac_entry && ac_entry->object == (GtkObject*) widget)
2510 return ac_entry->signal_id;
2515 gtk_widget_mnemonic_activate (GtkWidget *widget,
2516 gboolean group_cycling)
2520 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2522 group_cycling = group_cycling != FALSE;
2523 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2526 gtk_signal_emit (GTK_OBJECT (widget),
2527 widget_signals[ACTIVATE_MNEMONIC],
2534 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
2535 gboolean group_cycling)
2537 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
2538 gtk_widget_activate (widget);
2539 else if (GTK_WIDGET_CAN_FOCUS (widget))
2540 gtk_widget_grab_focus (widget);
2543 g_warning ("widget `%s' isn't suitable for mnemonic activation",
2544 G_OBJECT_TYPE_NAME (widget));
2551 gtk_widget_real_key_press_event (GtkWidget *widget,
2554 gboolean handled = FALSE;
2556 g_return_val_if_fail (widget != NULL, handled);
2557 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2558 g_return_val_if_fail (event != NULL, handled);
2561 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2569 gtk_widget_real_key_release_event (GtkWidget *widget,
2572 gboolean handled = FALSE;
2574 g_return_val_if_fail (widget != NULL, handled);
2575 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2576 g_return_val_if_fail (event != NULL, handled);
2579 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2581 event->state | GDK_RELEASE_MASK);
2587 gtk_widget_real_focus_in_event (GtkWidget *widget,
2588 GdkEventFocus *event)
2590 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
2591 gtk_widget_queue_draw (widget);
2597 gtk_widget_real_focus_out_event (GtkWidget *widget,
2598 GdkEventFocus *event)
2600 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
2601 gtk_widget_queue_draw (widget);
2608 * @widget: a #GtkWidget
2609 * @event: a #GdkEvent
2611 * Rarely-used function. This function is used to emit
2612 * the event signals on a widget (those signals should never
2613 * be emitted without using this function to do so).
2614 * If you want to synthesize an event though, don't use this function;
2615 * instead, use gtk_main_do_event() so the event will behave as if
2616 * it were in the event queue. Don't synthesize expose events; instead,
2617 * use gdk_window_invalidate_rect() to invalidate a region of the
2620 * Return value: return from the event signal emission (%TRUE if the event was handled)
2623 gtk_widget_event (GtkWidget *widget,
2626 g_return_val_if_fail (widget != NULL, TRUE);
2627 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2629 if (event->type == GDK_EXPOSE)
2631 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
2632 "the same effect, call gdk_window_invalidate_rect/region(), "
2633 "followed by gdk_window_process_updates().");
2637 return gtk_widget_event_internal (widget, event);
2642 * gtk_widget_send_expose:
2643 * @widget: a #GtkWidget
2644 * @event: a expose #GdkEvent
2646 * Very rarely-used function. This function is used to emit
2647 * an expose event signals on a widget. This function is not
2648 * normally used directly. The only time it is used is when
2649 * propagating an expose event to a child NO_WINDOW widget, and
2650 * that is normally done using gtk_container_propagate_expose.
2652 * If you want to force an area of a window to be redrawn,
2653 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
2654 * To cause the redraw to be done immediately, follow that call
2655 * with a call to gdk_window_procss_updates().
2657 * Return value: return from the event signal emission (%TRUE if the event was handled)
2660 gtk_widget_send_expose (GtkWidget *widget,
2663 g_return_val_if_fail (widget != NULL, TRUE);
2664 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2665 g_return_val_if_fail (event != NULL, TRUE);
2666 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
2668 if (event->type != GDK_EXPOSE)
2671 return gtk_widget_event_internal (widget, event);
2675 gtk_widget_event_internal (GtkWidget *widget,
2678 gboolean return_val;
2681 gtk_widget_ref (widget);
2683 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT], event,
2685 if (return_val || GTK_OBJECT_DESTROYED (widget))
2688 switch (event->type)
2693 case GDK_BUTTON_PRESS:
2694 case GDK_2BUTTON_PRESS:
2695 case GDK_3BUTTON_PRESS:
2696 signal_num = BUTTON_PRESS_EVENT;
2699 signal_num = SCROLL_EVENT;
2701 case GDK_BUTTON_RELEASE:
2702 signal_num = BUTTON_RELEASE_EVENT;
2704 case GDK_MOTION_NOTIFY:
2705 signal_num = MOTION_NOTIFY_EVENT;
2708 signal_num = DELETE_EVENT;
2711 signal_num = DESTROY_EVENT;
2714 signal_num = KEY_PRESS_EVENT;
2716 case GDK_KEY_RELEASE:
2717 signal_num = KEY_RELEASE_EVENT;
2719 case GDK_ENTER_NOTIFY:
2720 signal_num = ENTER_NOTIFY_EVENT;
2722 case GDK_LEAVE_NOTIFY:
2723 signal_num = LEAVE_NOTIFY_EVENT;
2725 case GDK_FOCUS_CHANGE:
2726 if (event->focus_change.in)
2727 signal_num = FOCUS_IN_EVENT;
2729 signal_num = FOCUS_OUT_EVENT;
2732 signal_num = CONFIGURE_EVENT;
2735 signal_num = MAP_EVENT;
2738 signal_num = UNMAP_EVENT;
2740 case GDK_WINDOW_STATE:
2741 signal_num = WINDOW_STATE_EVENT;
2743 case GDK_PROPERTY_NOTIFY:
2744 signal_num = PROPERTY_NOTIFY_EVENT;
2746 case GDK_SELECTION_CLEAR:
2747 signal_num = SELECTION_CLEAR_EVENT;
2749 case GDK_SELECTION_REQUEST:
2750 signal_num = SELECTION_REQUEST_EVENT;
2752 case GDK_SELECTION_NOTIFY:
2753 signal_num = SELECTION_NOTIFY_EVENT;
2755 case GDK_PROXIMITY_IN:
2756 signal_num = PROXIMITY_IN_EVENT;
2758 case GDK_PROXIMITY_OUT:
2759 signal_num = PROXIMITY_OUT_EVENT;
2762 signal_num = NO_EXPOSE_EVENT;
2764 case GDK_CLIENT_EVENT:
2765 signal_num = CLIENT_EVENT;
2768 if (!event->any.window) /* Why is this necessary */
2771 signal_num = EXPOSE_EVENT;
2773 case GDK_VISIBILITY_NOTIFY:
2774 signal_num = VISIBILITY_NOTIFY_EVENT;
2777 g_warning ("could not determine signal number for event: %d", event->type);
2781 if (signal_num != -1)
2782 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[signal_num], event, &return_val);
2784 return_val |= GTK_OBJECT_DESTROYED (widget);
2787 gtk_widget_unref (widget);
2793 * gtk_widget_activate:
2794 * @widget: a #GtkWidget that's activatable
2796 * For widgets that can be "activated" (buttons, menu items, etc.)
2797 * this function activates them. Activation is what happens when you
2798 * press Enter on a widget during key navigation; clicking a button,
2799 * selecting a menu item, etc. If @widget isn't activatable,
2800 * the function returns %FALSE.
2802 * Return value: %TRUE if the widget was activatable
2805 gtk_widget_activate (GtkWidget *widget)
2807 g_return_val_if_fail (widget != NULL, FALSE);
2808 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2810 if (WIDGET_CLASS (widget)->activate_signal)
2812 /* FIXME: we should eventually check the signals signature here */
2813 gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal);
2822 * gtk_widget_set_scroll_adjustments:
2823 * @widget: a #GtkWidget
2824 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
2825 * @vadjustment: an adjustment for vertical scrolling, or %NULL
2827 * For widgets that support scrolling, sets the scroll adjustments and
2828 * returns %TRUE. For widgets that don't support scrolling, does
2829 * nothing and returns %FALSE. Widgets that don't support scrolling
2830 * can be scrolled by placing them in a #GtkViewport, which does
2831 * support scrolling.
2833 * Return value: %TRUE if the widget supports scrolling
2836 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
2837 GtkAdjustment *hadjustment,
2838 GtkAdjustment *vadjustment)
2840 g_return_val_if_fail (widget != NULL, FALSE);
2841 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2843 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
2845 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
2847 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
2849 /* FIXME: we should eventually check the signals signature here */
2850 gtk_signal_emit (GTK_OBJECT (widget),
2851 WIDGET_CLASS (widget)->set_scroll_adjustments_signal,
2852 hadjustment, vadjustment);
2859 /*****************************************
2860 * gtk_widget_reparent_container_child:
2861 * assistent function to gtk_widget_reparent
2866 *****************************************/
2869 gtk_widget_reparent_container_child (GtkWidget *widget,
2870 gpointer client_data)
2872 g_return_if_fail (widget != NULL);
2873 g_return_if_fail (GTK_IS_WIDGET (widget));
2874 g_return_if_fail (client_data != NULL);
2876 if (GTK_WIDGET_NO_WINDOW (widget))
2879 gdk_window_unref (widget->window);
2880 widget->window = (GdkWindow*) client_data;
2882 gdk_window_ref (widget->window);
2884 if (GTK_IS_CONTAINER (widget))
2885 gtk_container_forall (GTK_CONTAINER (widget),
2886 gtk_widget_reparent_container_child,
2890 gdk_window_reparent (widget->window,
2891 (GdkWindow*) client_data, 0, 0);
2895 * gtk_widget_reparent:
2896 * @widget: a #GtkWidget
2897 * @new_parent: a #GtkContainer to move the widget into
2899 * Moves a widget from one #GtkContainer to another, handling reference
2900 * count issues to avoid destroying the widget.
2904 gtk_widget_reparent (GtkWidget *widget,
2905 GtkWidget *new_parent)
2907 g_return_if_fail (widget != NULL);
2908 g_return_if_fail (GTK_IS_WIDGET (widget));
2909 g_return_if_fail (new_parent != NULL);
2910 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
2911 g_return_if_fail (widget->parent != NULL);
2913 if (widget->parent != new_parent)
2915 /* First try to see if we can get away without unrealizing
2916 * the widget as we reparent it. if so we set a flag so
2917 * that gtk_widget_unparent doesn't unrealize widget
2919 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
2920 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
2922 gtk_widget_ref (widget);
2923 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
2924 gtk_container_add (GTK_CONTAINER (new_parent), widget);
2925 gtk_widget_unref (widget);
2927 if (GTK_WIDGET_IN_REPARENT (widget))
2929 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
2931 gtk_widget_reparent_container_child (widget,
2932 gtk_widget_get_parent_window (widget));
2938 * gtk_widget_intersect:
2939 * @widget: a #GtkWidget
2940 * @area: a rectangle
2941 * @intersection: rectangle to store intersection of @widget and @area
2943 * Computes the intersection of a @widget's area and @area, storing
2944 * the intersection in @intersection, and returns %TRUE if there was
2945 * an intersection. @intersection may be %NULL if you're only
2946 * interested in whether there was an intersection.
2948 * Return value: %TRUE if there was an intersection
2951 gtk_widget_intersect (GtkWidget *widget,
2953 GdkRectangle *intersection)
2959 g_return_val_if_fail (widget != NULL, FALSE);
2960 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2961 g_return_val_if_fail (area != NULL, FALSE);
2964 dest = intersection;
2968 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
2970 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
2972 intersection->x -= widget->allocation.x;
2973 intersection->y -= widget->allocation.y;
2980 * gtk_widget_region_intersect:
2981 * @widget: a #GtkWidget
2982 * @region: a #GdkRegion, in the same coordinate system as
2983 * widget->allocation. That is, relative to widget->window
2984 * for NO_WINDOW widgets; relative to the parent window
2985 * of widget->window for widgets with their own window.
2986 * @returns: A newly allocated region holding the intersection of @widget
2987 * and @region. The coordinates of the return value are
2988 * relative to widget->window for NO_WINDOW widgets, and
2989 * relative to the parent window of widget->window for
2990 * widgets with their own window.
2992 * Computes the intersection of a @widget's area and @region, returning
2993 * the intersection. The result may be empty, use #gdk_region_empty to
2997 gtk_widget_region_intersect (GtkWidget *widget,
3002 g_return_val_if_fail (widget != NULL, NULL);
3003 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3004 g_return_val_if_fail (region != NULL, NULL);
3006 dest = gdk_region_rectangle (&widget->allocation);
3008 gdk_region_intersect (dest, region);
3014 * gtk_widget_grab_focus:
3015 * @widget: a #GtkWidget
3017 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3018 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3019 * something like #GtkFrame won't work. (More precisely, it must have the
3020 * #GTK_CAN_FOCUS flag set.)
3024 gtk_widget_grab_focus (GtkWidget *widget)
3026 g_return_if_fail (widget != NULL);
3027 g_return_if_fail (GTK_IS_WIDGET (widget));
3029 g_object_ref (G_OBJECT (widget));
3030 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]);
3031 g_object_notify (G_OBJECT (widget), "has_focus");
3032 g_object_unref (G_OBJECT (widget));
3036 reset_focus_recurse (GtkWidget *widget,
3039 if (GTK_IS_CONTAINER (widget))
3041 GtkContainer *container;
3043 container = GTK_CONTAINER (widget);
3044 gtk_container_set_focus_child (container, NULL);
3046 gtk_container_foreach (container,
3047 reset_focus_recurse,
3053 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3055 g_return_if_fail (focus_widget != NULL);
3056 g_return_if_fail (GTK_IS_WIDGET (focus_widget));
3058 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3060 GtkWidget *toplevel;
3063 /* clear the current focus setting, break if the current widget
3064 * is the focus widget's parent, since containers above that will
3065 * be set by the next loop.
3067 toplevel = gtk_widget_get_toplevel (focus_widget);
3068 if (GTK_IS_WINDOW (toplevel))
3070 widget = GTK_WINDOW (toplevel)->focus_widget;
3072 if (widget == focus_widget)
3074 /* We call gtk_window_set_focus() here so that the
3075 * toplevel window can request the focus if necessary.
3076 * This is needed when the toplevel is a GtkPlug
3078 if (!GTK_WIDGET_HAS_FOCUS (widget))
3079 gtk_window_set_focus (GTK_WINDOW (toplevel), focus_widget);
3086 while (widget->parent && widget->parent != focus_widget->parent)
3088 widget = widget->parent;
3089 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3093 else if (toplevel != focus_widget)
3095 /* gtk_widget_grab_focus() operates on a tree without window...
3096 * actually, this is very questionable behaviour.
3099 gtk_container_foreach (GTK_CONTAINER (toplevel),
3100 reset_focus_recurse,
3104 /* now propagate the new focus up the widget tree and finally
3105 * set it on the window
3107 widget = focus_widget;
3108 while (widget->parent)
3110 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3111 widget = widget->parent;
3113 if (GTK_IS_WINDOW (widget))
3114 gtk_window_set_focus (GTK_WINDOW (widget), focus_widget);
3119 gtk_widget_real_focus (GtkWidget *widget,
3120 GtkDirectionType direction)
3122 if (!GTK_WIDGET_CAN_FOCUS (widget))
3125 if (!GTK_WIDGET_HAS_FOCUS (widget))
3127 gtk_widget_grab_focus (widget);
3136 * gtk_widget_is_focus:
3137 * @widget: a #GtkWidget
3139 * Determines if the widget is the focus widget within its
3140 * toplevel. (This does not mean that the HAS_FOCUS flag is
3141 * necessarily set; HAS_FOCUS will only be set if the
3142 * toplevel widget additionally has the global input focus.)
3144 * Return value: %TRUE if the widget is the focus widget.
3147 gtk_widget_is_focus (GtkWidget *widget)
3149 GtkWidget *toplevel;
3151 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3153 toplevel = gtk_widget_get_toplevel (widget);
3155 if (GTK_IS_WINDOW (toplevel))
3156 return widget == GTK_WINDOW (toplevel)->focus_widget;
3162 * gtk_widget_grab_default:
3163 * @widget: a #GtkWidget
3165 * Causes @widget to become the default widget. @widget must have the
3166 * #GTK_CAN_DEFAULT flag set; typically you have to set this flag
3167 * yourself by calling GTK_WIDGET_SET_FLAGS (@widget,
3168 * GTK_CAN_DEFAULT). The default widget is activated when the user
3169 * presses Enter in a window. Default widgets must be activatable,
3170 * that is, gtk_widget_activate() should affect them.
3174 gtk_widget_grab_default (GtkWidget *widget)
3177 GtkType window_type;
3179 g_return_if_fail (widget != NULL);
3180 g_return_if_fail (GTK_IS_WIDGET (widget));
3181 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3183 window_type = GTK_TYPE_WINDOW;
3184 window = widget->parent;
3186 while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3187 window = window->parent;
3189 if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3191 gtk_window_set_default (GTK_WINDOW (window), widget);
3192 g_object_notify (G_OBJECT (widget), "has_default");
3195 g_warning (G_STRLOC ": widget not within a GtkWindow");
3199 * gtk_widget_set_name:
3200 * @widget: a #GtkWidget
3201 * @name: name for the widget
3203 * Widgets can be named, which allows you to refer to them from a
3204 * gtkrc file. You can apply a style to widgets with a particular name
3205 * in the gtkrc file. See the documentation for gtkrc files (on the
3206 * same page as the docs for #GtkRcStyle).
3210 gtk_widget_set_name (GtkWidget *widget,
3213 g_return_if_fail (widget != NULL);
3214 g_return_if_fail (GTK_IS_WIDGET (widget));
3217 g_free (widget->name);
3218 widget->name = g_strdup (name);
3220 if (GTK_WIDGET_RC_STYLE (widget))
3221 gtk_widget_set_rc_style (widget);
3223 g_object_notify (G_OBJECT (widget), "name");
3227 * gtk_widget_get_name:
3228 * @widget: a #GtkWidget
3230 * Retrieves the name of a widget. The return value should not be
3231 * freed. See gtk_widget_set_name() for the significance of widget
3234 * Return value: name of the widget
3236 G_CONST_RETURN gchar*
3237 gtk_widget_get_name (GtkWidget *widget)
3239 g_return_val_if_fail (widget != NULL, NULL);
3240 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3243 return widget->name;
3244 return gtk_type_name (GTK_WIDGET_TYPE (widget));
3248 * gtk_widget_set_state:
3249 * @widget: a #GtkWidget
3250 * @state: new state for @widget
3252 * This function is for use in widget implementations. Sets the state
3253 * of a widget (insensitive, prelighted, etc.) Usually you should set
3254 * the state using wrapper functions such as gtk_widget_set_sensitive().
3258 gtk_widget_set_state (GtkWidget *widget,
3261 g_return_if_fail (widget != NULL);
3262 g_return_if_fail (GTK_IS_WIDGET (widget));
3264 if (state == GTK_WIDGET_STATE (widget))
3267 if (state == GTK_STATE_INSENSITIVE)
3268 gtk_widget_set_sensitive (widget, FALSE);
3274 data.state_restoration = FALSE;
3275 data.use_forall = FALSE;
3277 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3279 data.parent_sensitive = TRUE;
3281 gtk_widget_propagate_state (widget, &data);
3283 if (GTK_WIDGET_DRAWABLE (widget))
3284 gtk_widget_queue_clear (widget);
3289 gtk_widget_set_app_paintable (GtkWidget *widget,
3290 gboolean app_paintable)
3292 g_return_if_fail (widget != NULL);
3293 g_return_if_fail (GTK_IS_WIDGET (widget));
3295 app_paintable = (app_paintable != FALSE);
3297 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
3300 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
3302 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
3304 if (GTK_WIDGET_DRAWABLE (widget))
3305 gtk_widget_queue_clear (widget);
3307 g_object_notify (G_OBJECT (widget), "app_paintable");
3312 * gtk_widget_set_double_buffered:
3313 * @widget: a #GtkWidget
3314 * @double_buffered: %TRUE to double-buffer a widget
3316 * Widgets are double buffered by default; you can use this function
3317 * to turn off the buffering. "Double buffered" simply means that
3318 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
3319 * automatically around expose events sent to the
3320 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
3321 * window to an offscreen buffer, and gdk_window_end_paint() draws the
3322 * buffer to the screen. The result is that users see the window
3323 * update in one smooth step, and don't see individual graphics
3324 * primitives being rendered.
3326 * In very simple terms, double buffered widgets don't flicker,
3327 * so you would only use this function to turn off double buffering
3328 * if you had special needs and really knew what you were doing.
3332 gtk_widget_set_double_buffered (GtkWidget *widget,
3333 gboolean double_buffered)
3335 g_return_if_fail (widget != NULL);
3336 g_return_if_fail (GTK_IS_WIDGET (widget));
3338 if (double_buffered)
3339 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3341 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3345 * gtk_widget_set_sensitive:
3346 * @widget: a @widget
3347 * @sensitive: %TRUE to make the widget sensitive
3349 * Sets the sensitivity of a widget. A widget is sensitive if the user
3350 * can interact with it. Insensitive widgets are "grayed out" and the
3351 * user can't interact with them. Insensitive widgets are known as
3352 * "inactive" in some other toolkits.
3356 gtk_widget_set_sensitive (GtkWidget *widget,
3361 g_return_if_fail (widget != NULL);
3362 g_return_if_fail (GTK_IS_WIDGET (widget));
3364 sensitive = (sensitive != FALSE);
3366 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
3371 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
3372 data.state = GTK_WIDGET_SAVED_STATE (widget);
3376 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
3377 data.state = GTK_WIDGET_STATE (widget);
3379 data.state_restoration = TRUE;
3380 data.use_forall = TRUE;
3383 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3385 data.parent_sensitive = TRUE;
3387 gtk_widget_propagate_state (widget, &data);
3388 if (GTK_WIDGET_DRAWABLE (widget))
3389 gtk_widget_queue_clear (widget);
3391 g_object_notify (G_OBJECT (widget), "sensitive");
3395 * gtk_widget_set_parent:
3396 * @widget: a #GtkWidget
3397 * @parent: parent container
3399 * This function is useful only when implementing subclasses of #GtkContainer.
3400 * Sets the container as the parent of @widget, and takes care of
3401 * some details such as updating the state and style of the child
3402 * to reflect its new location. The opposite function is
3403 * gtk_widget_unparent().
3407 gtk_widget_set_parent (GtkWidget *widget,
3412 g_return_if_fail (widget != NULL);
3413 g_return_if_fail (GTK_IS_WIDGET (widget));
3414 g_return_if_fail (widget->parent == NULL);
3415 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
3416 g_return_if_fail (parent != NULL);
3417 g_return_if_fail (GTK_IS_WIDGET (parent));
3418 g_return_if_fail (widget != parent);
3420 /* keep this function in sync with gtk_menu_attach_to_widget()
3423 gtk_widget_ref (widget);
3424 gtk_object_sink (GTK_OBJECT (widget));
3425 widget->parent = parent;
3427 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
3428 data.state = GTK_WIDGET_STATE (parent);
3430 data.state = GTK_WIDGET_STATE (widget);
3431 data.state_restoration = FALSE;
3432 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
3433 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
3435 gtk_widget_propagate_state (widget, &data);
3437 gtk_widget_set_style_recurse (widget, NULL);
3439 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], NULL);
3440 gtk_widget_propagate_hierarchy_changed (widget, NULL);
3441 g_object_notify (G_OBJECT (widget), "parent");
3444 /*****************************************
3446 * see docs/styles.txt
3447 *****************************************/
3450 * gtk_widget_set_style:
3451 * @widget: a #GtkWidget
3452 * @style: a #GtkStyle
3454 * Sets the #GtkStyle for a widget (widget->style). You probably don't
3455 * want to use this function; it interacts badly with themes, because
3456 * themes work by replacing the #GtkStyle. Instead, use
3457 * gtk_widget_modify_style().
3461 gtk_widget_set_style (GtkWidget *widget,
3464 GtkStyle *default_style;
3465 gboolean initial_emission;
3467 g_return_if_fail (widget != NULL);
3468 g_return_if_fail (GTK_IS_WIDGET (widget));
3469 g_return_if_fail (style != NULL);
3471 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3473 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
3474 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
3476 default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3479 gtk_style_ref (widget->style);
3480 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_saved_default_style, widget->style);
3483 gtk_widget_set_style_internal (widget, style, initial_emission);
3487 * gtk_widget_ensure_style:
3488 * @widget: a #GtkWidget
3490 * Ensures that @widget has a style (widget->style). Not a very useful
3491 * function; most of the time, if you want the style, the widget is
3492 * realized, and realized widgets are guaranteed to have a style
3497 gtk_widget_ensure_style (GtkWidget *widget)
3499 g_return_if_fail (widget != NULL);
3500 g_return_if_fail (GTK_IS_WIDGET (widget));
3502 if (!GTK_WIDGET_USER_STYLE (widget) &&
3503 !GTK_WIDGET_RC_STYLE (widget))
3504 gtk_widget_set_rc_style (widget);
3508 * gtk_widget_set_rc_style:
3509 * @widget: a #GtkWidget
3514 gtk_widget_set_rc_style (GtkWidget *widget)
3516 GtkStyle *saved_style;
3517 GtkStyle *new_style;
3518 gboolean initial_emission;
3520 g_return_if_fail (widget != NULL);
3521 g_return_if_fail (GTK_IS_WIDGET (widget));
3523 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3525 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3526 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
3528 saved_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3529 new_style = gtk_rc_get_style (widget);
3534 gtk_style_ref (widget->style);
3535 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_saved_default_style, widget->style);
3537 gtk_widget_set_style_internal (widget, new_style, initial_emission);
3543 g_assert (initial_emission == FALSE); /* FIXME: remove this line */
3545 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3546 gtk_widget_set_style_internal (widget, saved_style, initial_emission);
3547 gtk_style_unref (saved_style);
3551 if (initial_emission)
3552 gtk_widget_set_style_internal (widget, widget->style, TRUE);
3558 gtk_widget_restore_default_style (GtkWidget *widget)
3560 GtkStyle *default_style;
3562 g_return_if_fail (widget != NULL);
3563 g_return_if_fail (GTK_IS_WIDGET (widget));
3565 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3567 default_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3570 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
3571 gtk_widget_set_style_internal (widget, default_style, FALSE);
3572 gtk_style_unref (default_style);
3577 * gtk_widget_get_style:
3578 * @widget: a #GtkWidget
3580 * Simply an accessor function that returns widget->style.
3582 * Return value: the widget's #GtkStyle
3585 gtk_widget_get_style (GtkWidget *widget)
3587 g_return_val_if_fail (widget != NULL, NULL);
3588 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3590 return widget->style;
3594 * gtk_widget_modify_style:
3595 * @widget: a #GtkWidget
3596 * @style: the #GtkRcStyle holding the style modifications
3598 * Modify style values on the widget. Modifications made using this
3599 * technique take precendence over style values set via an RC file,
3600 * however, they will be overriden if a style is explicitely set on
3601 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
3602 * is designed so each field can either be set or unset, so it is
3603 * possible, using this function, to modify some style values and
3604 * leave the others unchanged.
3606 * Note that modifications made with this function are not cumulative
3607 * with previous calls to gtk_widget_modify_style() or with such
3608 * functions as gtk_widget_modify_fg(). If you wish to retain
3609 * previous values, you must first call gtk_widget_get_modifier_style(),
3610 * make your modifications to the returned style, then call
3611 * gtk_widget_modify_style() with that style. On the other hand,
3612 * if you first call gtk_widget_modify_style(), subsequent calls
3613 * to such functions gtk_widget_modify_fg() will be have a cumulative
3614 * effect with the inital modifications.
3617 gtk_widget_modify_style (GtkWidget *widget,
3620 GtkRcStyle *old_style;
3622 g_return_if_fail (GTK_IS_RC_STYLE (style));
3624 old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3627 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3629 gtk_rc_style_copy (style),
3630 (GtkDestroyNotify)gtk_rc_style_unref);
3632 /* note that "style" may be invalid here if it was the old
3633 * modifier style and the only reference was our own.
3636 if (GTK_WIDGET_RC_STYLE (widget))
3637 gtk_widget_set_rc_style (widget);
3641 * gtk_widget_get_modifier_style:
3642 * @widget: a #GtkWidget
3644 * Return the current modifier style for the widget. (As set by
3645 * gtk_widget_modify_style().) If no style has previously set, a new
3646 * #GtkRcStyle will be created with all values unset, and set as the
3647 * modifier style for the widget. If you make changes to this rc
3648 * style, you must call gtk_widget_modify_style(), passing in the
3649 * returned rc style, to make sure that your changes take effect.
3651 * Caution: passing the style back to gtk_widget_modify_style() will
3652 * normally end up destroying it, because gtk_widget_modify_style() copies
3653 * the passed-in style and sets the copy as the new modifier style,
3654 * thus dropping any reference to the old modifier style. Add a reference
3655 * to the modifier style if you want to keep it alive.
3657 * Return value: the modifier style for the widget. This rc style is
3658 * owned by the widget. If you want to keep a pointer to value this
3659 * around, you must add a refcount using gtk_rc_style_ref().
3662 gtk_widget_get_modifier_style (GtkWidget *widget)
3664 GtkRcStyle *rc_style;
3666 rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3671 rc_style = gtk_rc_style_new();
3672 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3675 (GtkDestroyNotify)gtk_rc_style_unref);
3682 gtk_widget_modify_color_component (GtkWidget *widget,
3683 GtkRcFlags component,
3687 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
3692 rc_style->fg[state] = *color;
3695 rc_style->bg[state] = *color;
3698 rc_style->text[state] = *color;
3701 rc_style->base[state] = *color;
3704 g_assert_not_reached();
3707 rc_style->color_flags[state] |= component;
3709 gtk_widget_modify_style (widget, rc_style);
3713 * gtk_widget_modify_fg:
3714 * @widget: a #GtkWidget
3715 * @state: the state for which to set the foreground color.
3716 * @color: the color to assign (does not need to be allocated)
3718 * Set the foreground color for a widget in a particular state. All
3719 * other style values are left untouched. See also
3720 * gtk_widget_modify_style().
3723 gtk_widget_modify_fg (GtkWidget *widget,
3727 g_return_if_fail (GTK_IS_WIDGET (widget));
3728 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3729 g_return_if_fail (color != NULL);
3731 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
3735 * gtk_widget_modify_bg:
3736 * @widget: a #GtkWidget
3737 * @state: the state for which to set the foreground color.
3738 * @color: the color to assign (does not need to be allocated)
3740 * Set the background color for a widget in a particular state. All
3741 * other style values are left untouched. See also
3742 * gtk_widget_modify_style().
3745 gtk_widget_modify_bg (GtkWidget *widget,
3749 g_return_if_fail (GTK_IS_WIDGET (widget));
3750 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3751 g_return_if_fail (color != NULL);
3753 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
3757 * gtk_widget_modify_base:
3758 * @widget: a #GtkWidget
3759 * @state: the state for which to set the foreground color.
3760 * @color: the color to assign (does not need to be allocated)
3762 * Set the text color for a widget in a particular state. All other
3763 * style values are left untouched. The text color is the foreground
3764 * color used along with the base color (see gtk_widget_modify_base)
3765 * for widgets such as #GtkEntry and #GtkTextView. See also
3766 * gtk_widget_modify_style().
3769 gtk_widget_modify_text (GtkWidget *widget,
3773 g_return_if_fail (GTK_IS_WIDGET (widget));
3774 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3775 g_return_if_fail (color != NULL);
3777 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
3781 * gtk_widget_modify_base:
3782 * @widget: a #GtkWidget
3783 * @state: the state for which to set the foreground color.
3784 * @color: the color to assign (does not need to be allocated)
3786 * Set the text color for a widget in a particular state.
3787 * All other style values are left untouched. The base color
3788 * is the background color used along with the text color
3789 * (see gtk_widget_modify_text) for widgets such as #GtkEntry
3790 * and #GtkTextView. See also gtk_widget_modify_style().
3793 gtk_widget_modify_base (GtkWidget *widget,
3797 g_return_if_fail (GTK_IS_WIDGET (widget));
3798 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3799 g_return_if_fail (color != NULL);
3801 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
3805 * gtk_widget_modify_font:
3806 * @widget: a #GtkWidget
3807 * @font_desc: the font description to use
3809 * Set the font to use for a widget. All other style values are left
3810 * untouched. See also gtk_widget_modify_style().
3813 gtk_widget_modify_font (GtkWidget *widget,
3814 PangoFontDescription *font_desc)
3816 GtkRcStyle *rc_style;
3818 g_return_if_fail (GTK_IS_WIDGET (widget));
3819 g_return_if_fail (font_desc != NULL);
3821 rc_style = gtk_widget_get_modifier_style (widget);
3823 if (rc_style->font_desc)
3824 pango_font_description_free (rc_style->font_desc);
3826 rc_style->font_desc = pango_font_description_copy (font_desc);
3828 gtk_widget_modify_style (widget, rc_style);
3832 gtk_widget_direction_changed (GtkWidget *widget,
3833 GtkTextDirection previous_direction)
3835 gtk_widget_queue_resize (widget);
3839 gtk_widget_style_set (GtkWidget *widget,
3840 GtkStyle *previous_style)
3842 if (GTK_WIDGET_REALIZED (widget) &&
3843 !GTK_WIDGET_NO_WINDOW (widget))
3844 gtk_style_set_background (widget->style, widget->window, widget->state);
3848 gtk_widget_set_style_internal (GtkWidget *widget,
3850 gboolean initial_emission)
3852 g_return_if_fail (widget != NULL);
3853 g_return_if_fail (GTK_IS_WIDGET (widget));
3854 g_return_if_fail (style != NULL);
3856 g_object_ref (G_OBJECT (widget));
3857 g_object_freeze_notify (G_OBJECT (widget));
3859 if (widget->style != style || initial_emission)
3861 PangoContext *context = gtk_widget_peek_pango_context (widget);
3863 pango_context_set_font_description (context, style->font_desc);
3866 if (widget->style != style)
3868 GtkStyle *previous_style;
3870 if (GTK_WIDGET_REALIZED (widget))
3872 gtk_widget_reset_shapes (widget);
3873 gtk_style_detach (widget->style);
3876 previous_style = widget->style;
3877 widget->style = style;
3878 gtk_style_ref (widget->style);
3880 if (GTK_WIDGET_REALIZED (widget))
3881 widget->style = gtk_style_attach (widget->style, widget->window);
3883 gtk_signal_emit (GTK_OBJECT (widget),
3884 widget_signals[STYLE_SET],
3885 initial_emission ? NULL : previous_style);
3886 gtk_style_unref (previous_style);
3888 if (widget->parent && !initial_emission)
3890 GtkRequisition old_requisition;
3892 old_requisition = widget->requisition;
3893 gtk_widget_size_request (widget, NULL);
3895 if ((old_requisition.width != widget->requisition.width) ||
3896 (old_requisition.height != widget->requisition.height))
3897 gtk_widget_queue_resize (widget);
3898 else if (GTK_WIDGET_DRAWABLE (widget))
3899 gtk_widget_queue_clear (widget);
3902 else if (initial_emission)
3903 gtk_signal_emit (GTK_OBJECT (widget),
3904 widget_signals[STYLE_SET],
3906 g_object_notify (G_OBJECT (widget), "style");
3907 g_object_thaw_notify (G_OBJECT (widget));
3908 g_object_unref (G_OBJECT (widget));
3912 gtk_widget_set_style_recurse (GtkWidget *widget,
3913 gpointer client_data)
3915 if (GTK_WIDGET_RC_STYLE (widget))
3916 gtk_widget_set_rc_style (widget);
3918 if (GTK_IS_CONTAINER (widget))
3919 gtk_container_forall (GTK_CONTAINER (widget),
3920 gtk_widget_set_style_recurse,
3925 gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
3926 gpointer client_data)
3928 gboolean new_anchored;
3930 new_anchored = widget->parent && GTK_WIDGET_ANCHORED (widget->parent);
3932 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
3934 gtk_widget_ref (widget);
3937 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
3939 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
3941 g_signal_emit (GTK_OBJECT (widget), widget_signals[HIERARCHY_CHANGED], 0);
3943 if (GTK_IS_CONTAINER (widget))
3944 gtk_container_forall (GTK_CONTAINER (widget),
3945 gtk_widget_propagate_hierarchy_changed,
3948 gtk_widget_unref (widget);
3953 gtk_widget_reset_rc_styles (GtkWidget *widget)
3955 g_return_if_fail (widget != NULL);
3956 g_return_if_fail (GTK_IS_WIDGET (widget));
3958 gtk_widget_set_style_recurse (widget, NULL);
3962 gtk_widget_set_default_style (GtkStyle *style)
3964 if (style != gtk_default_style)
3966 if (gtk_default_style)
3967 gtk_style_unref (gtk_default_style);
3968 gtk_default_style = style;
3969 if (gtk_default_style)
3970 gtk_style_ref (gtk_default_style);
3975 gtk_widget_get_default_style (void)
3977 if (!gtk_default_style)
3979 gtk_default_style = gtk_style_new ();
3980 gtk_style_ref (gtk_default_style);
3983 return gtk_default_style;
3987 gtk_widget_push_style (GtkStyle *style)
3989 g_return_if_fail (style != NULL);
3991 gtk_style_ref (style);
3992 style_stack = g_slist_prepend (style_stack, style);
3996 gtk_widget_peek_style (void)
3999 return (GtkStyle*) style_stack->data;
4001 return gtk_widget_get_default_style ();
4005 gtk_widget_pop_style (void)
4012 style_stack = style_stack->next;
4013 gtk_style_unref ((GtkStyle*) tmp->data);
4014 g_slist_free_1 (tmp);
4018 static PangoContext *
4019 gtk_widget_peek_pango_context (GtkWidget *widget)
4021 return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
4025 * gtk_widget_get_pango_context:
4026 * @widget: a #GtkWidget
4028 * Get a #PangoContext with the appropriate colormap, font description
4029 * and base direction for this widget. Unlike the context returned
4030 * by gtk_widget_create_pango_context(), this context is owned by
4031 * the widget (it can be used as long as widget exists), and will
4032 * be updated to match any changes to the widget's attributes.
4034 * If you create and keep a #PangoLayout using this context, you must
4035 * deal with changes to the context by calling pango_layout_context_changed()
4036 * on the layout in response to the ::style_set and ::direction_set signals
4039 * Return value: the #PangoContext for the widget.
4042 gtk_widget_get_pango_context (GtkWidget *widget)
4044 PangoContext *context;
4046 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4048 context = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
4051 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4052 gtk_object_set_data_by_id_full (GTK_OBJECT (widget), quark_pango_context, context,
4053 (GDestroyNotify) g_object_unref);
4060 * gtk_widget_create_pango_context:
4061 * @widget: a #PangoWidget
4063 * Create a new pango context with the appropriate colormap,
4064 * font description, and base direction for drawing text for
4065 * this widget. See also gtk_widget_get_pango_context()
4067 * Return value: the new #PangoContext
4070 gtk_widget_create_pango_context (GtkWidget *widget)
4072 PangoContext *context;
4074 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4076 context = gdk_pango_context_get ();
4078 gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
4079 pango_context_set_base_dir (context,
4080 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4081 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4082 pango_context_set_font_description (context, widget->style->font_desc);
4083 pango_context_set_language (context, gtk_get_default_language ());
4089 * gtk_widget_create_pango_layout:
4090 * @widget: a #PangoWidget
4091 * @text: text to set on the layout (can be %NULL)
4093 * Create a new #PangoLayout with the appropriate colormap,
4094 * font description, and base direction for drawing text for
4097 * If you keep a #PangoLayout created in this way around, in order
4098 * notify the layout of changes to the base direction or font of this
4099 * widget, you must call pango_layout_context_changed() in response to
4100 * the ::style_set and ::direction_set signals for the widget.
4102 * Return value: the new #PangoLayout
4105 gtk_widget_create_pango_layout (GtkWidget *widget,
4108 PangoLayout *layout;
4109 PangoContext *context;
4111 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4113 context = gtk_widget_get_pango_context (widget);
4114 layout = pango_layout_new (context);
4117 pango_layout_set_text (layout, text, -1);
4123 * gtk_widget_render_icon:
4124 * @widget: a #GtkWidget
4125 * @stock_id: a stock ID
4126 * @size: a stock size
4127 * @detail: render detail to pass to theme engine
4129 * A convenience function that uses the theme engine and RC file
4130 * settings for @widget to look up @stock_id and render it to
4131 * a pixbuf. @stock_id should be a stock icon ID such as
4132 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
4133 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
4134 * identifies the widget or code doing the rendering, so that
4135 * theme engines can special-case rendering for that widget or code.
4137 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
4140 gtk_widget_render_icon (GtkWidget *widget,
4141 const gchar *stock_id,
4143 const gchar *detail)
4145 GtkIconSet *icon_set;
4148 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4149 g_return_val_if_fail (stock_id != NULL, NULL);
4150 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
4152 gtk_widget_ensure_style (widget);
4154 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
4156 if (icon_set == NULL)
4159 retval = gtk_icon_set_render_icon (icon_set,
4161 gtk_widget_get_direction (widget),
4162 GTK_WIDGET_STATE (widget),
4170 /*************************************************************
4171 * gtk_widget_set_parent_window:
4172 * Set a non default parent window for widget
4179 *************************************************************/
4182 gtk_widget_set_parent_window (GtkWidget *widget,
4183 GdkWindow *parent_window)
4185 GdkWindow *old_parent_window;
4187 g_return_if_fail (widget != NULL);
4188 g_return_if_fail (GTK_IS_WIDGET (widget));
4190 old_parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4191 quark_parent_window);
4193 if (parent_window != old_parent_window)
4195 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_parent_window,
4197 if (old_parent_window)
4198 gdk_window_unref (old_parent_window);
4200 gdk_window_ref (parent_window);
4204 /*************************************************************
4205 * gtk_widget_get_parent_window:
4206 * Get widget's parent window
4213 *************************************************************/
4216 gtk_widget_get_parent_window (GtkWidget *widget)
4218 GdkWindow *parent_window;
4220 g_return_val_if_fail (widget != NULL, NULL);
4221 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4222 g_return_val_if_fail (widget->parent != NULL, NULL);
4224 parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4225 quark_parent_window);
4227 return (parent_window != NULL) ? parent_window : widget->parent->window;
4231 * gtk_widget_child_focus:
4232 * @widget: a #GtkWidget
4233 * @direction: direction of focus movement
4235 * This function is used by custom widget implementations; if you're
4236 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
4237 * to a particular widget, and gtk_container_set_focus_chain() to
4238 * change the focus tab order. So you may want to investigate those
4239 * functions instead.
4241 * gtk_widget_child_focus() is called by containers as the user moves
4242 * around the window using keyboard shortcuts. @direction indicates
4243 * what kind of motion is taking place (up, down, left, right, tab
4244 * forward, tab backward). gtk_widget_child_focus() invokes the
4245 * "focus" signal on #GtkWidget; widgets override the default handler
4246 * for this signal in order to implement appropriate focus behavior.
4248 * The "focus" default handler for a widget should return %TRUE if
4249 * moving in @direction left the focus on a focusable location inside
4250 * that widget, and %FALSE if moving in @direction moved the focus
4251 * outside the widget. If returning %TRUE, widgets normally
4252 * call gtk_widget_grab_focus() to place the focus accordingly;
4253 * if returning %FALSE, they don't modify the current focus location.
4255 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
4256 * necessary to check that the child was visible, sensitive, and
4257 * focusable before calling
4258 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
4259 * the widget is not currently in a focusable state, so there's no
4260 * need for those checks.
4262 * Return value: %TRUE if focus ended up inside @widget
4265 gtk_widget_child_focus (GtkWidget *widget,
4266 GtkDirectionType direction)
4268 gboolean return_val;
4270 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4272 if (!GTK_WIDGET_VISIBLE (widget) ||
4273 !GTK_WIDGET_IS_SENSITIVE (widget))
4276 /* child widgets must set CAN_FOCUS, containers
4277 * don't have to though.
4279 if (!GTK_IS_CONTAINER (widget) &&
4280 !GTK_WIDGET_CAN_FOCUS (widget))
4283 gtk_signal_emit (GTK_OBJECT (widget),
4284 widget_signals[FOCUS],
4285 direction, &return_val);
4290 /* Update the position from aux_info. Used from gtk_widget_set_uposition
4291 * and gtk_widget_set_property().
4294 gtk_widget_do_uposition (GtkWidget *widget)
4296 GtkWidgetAuxInfo *aux_info =_gtk_widget_get_aux_info (widget, FALSE);
4298 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
4299 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
4301 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
4302 gtk_widget_size_allocate (widget, &widget->allocation);
4304 g_object_freeze_notify (G_OBJECT (widget));
4305 if (aux_info->x_set)
4306 g_object_notify (G_OBJECT (widget), "x");
4307 if (aux_info->y_set)
4308 g_object_notify (G_OBJECT (widget), "y");
4309 g_object_thaw_notify (G_OBJECT (widget));
4313 * gtk_widget_set_uposition:
4314 * @widget: a #GtkWidget
4315 * @x: x position; -1 to unset x; -2 to leave x unchanged
4316 * @y: y position; -1 to unset y; -2 to leave y unchanged
4319 * Sets the position of a widget. The funny "u" in the name comes from
4320 * the "user position" hint specified by the X window system, and
4321 * exists for legacy reasons. This function doesn't work if a widget
4322 * is inside a container; it's only really useful on #GtkWindow.
4324 * Don't use this function to center dialogs over the main application
4325 * window; most window managers will do the centering on your behalf
4326 * if you call gtk_window_set_transient_for(), and it's really not
4327 * possible to get the centering to work correctly in all cases from
4328 * application code. But if you insist, use gtk_window_set_position()
4329 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
4332 * Note that although x and y can be individually unset, the position
4333 * is not honoured unless both x and y are set.
4336 gtk_widget_set_uposition (GtkWidget *widget,
4340 GtkWidgetAuxInfo *aux_info;
4342 g_return_if_fail (widget != NULL);
4343 g_return_if_fail (GTK_IS_WIDGET (widget));
4345 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4350 aux_info->x_set = FALSE;
4353 aux_info->x_set = TRUE;
4361 aux_info->y_set = FALSE;
4364 aux_info->y_set = TRUE;
4369 gtk_widget_do_uposition (widget);
4373 * gtk_widget_set_usize:
4374 * @widget: a #GtkWidget
4375 * @width: minimum width, or -1 to unset
4376 * @height: minimum height, or -1 to unset
4378 * Sets the minimum size of a widget; that is, the widget's size
4379 * request will be @width by @height. You can use this function to
4380 * force a widget to be either larger or smaller than it is. The
4381 * strange "usize" name dates from the early days of GTK+, and derives
4382 * from X Window System terminology. In many cases,
4383 * gtk_window_set_default_size() is a better choice for toplevel
4384 * windows than this function; setting the default size will still
4385 * allow users to shrink the window. Setting the usize will force them
4386 * to leave the window at least as large as the usize. When dealing
4387 * with window sizes, gtk_window_set_geometry_hints() can be a useful
4390 * Note the inherent danger of setting any fixed size - themes,
4391 * translations into other languages, different fonts, and user action
4392 * can all change the appropriate size for a given widget. So, it's
4393 * basically impossible to hardcode a size that will always be
4398 gtk_widget_set_usize (GtkWidget *widget,
4402 GtkWidgetAuxInfo *aux_info;
4404 g_return_if_fail (widget != NULL);
4405 g_return_if_fail (GTK_IS_WIDGET (widget));
4407 g_object_freeze_notify (G_OBJECT (widget));
4409 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4413 g_object_notify (G_OBJECT (widget), "width");
4414 aux_info->width = width;
4418 g_object_notify (G_OBJECT (widget), "height");
4419 aux_info->height = height;
4422 if (GTK_WIDGET_VISIBLE (widget))
4423 gtk_widget_queue_resize (widget);
4425 g_object_thaw_notify (G_OBJECT (widget));
4429 * gtk_widget_set_events:
4430 * @widget: a #GtkWidget
4431 * @events: event mask
4433 * Sets the event mask (see #GdkEventMask) for a widget. The event
4434 * mask determines which events a widget will receive. Keep in mind
4435 * that different widgets have different default event masks, and by
4436 * changing the event mask you may disrupt a widget's functionality,
4437 * so be careful. This function must be called while a widget is
4438 * unrealized. Consider gtk_widget_add_events() for widgets that are
4439 * already realized, or if you want to preserve the existing event
4440 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
4441 * to get events on those widgets, place them inside a #GtkEventBox
4442 * and receive events on the event box.
4446 gtk_widget_set_events (GtkWidget *widget,
4451 g_return_if_fail (widget != NULL);
4452 g_return_if_fail (GTK_IS_WIDGET (widget));
4453 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4454 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4456 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4461 eventp = g_new (gint, 1);
4464 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4469 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4472 g_object_notify (G_OBJECT (widget), "events");
4476 * gtk_widget_add_events:
4477 * @widget: a #GtkWidget
4478 * @events: an event mask, see #GdkEventMask
4480 * Adds the events in the bitfield @events to the event mask for
4481 * @widget. See gtk_widget_set_events() for details.
4485 gtk_widget_add_events (GtkWidget *widget,
4490 g_return_if_fail (widget != NULL);
4491 g_return_if_fail (GTK_IS_WIDGET (widget));
4492 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4494 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4500 eventp = g_new (gint, 1);
4505 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4510 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4513 if (GTK_WIDGET_REALIZED (widget))
4515 gdk_window_set_events (widget->window,
4516 gdk_window_get_events (widget->window) | events);
4519 g_object_notify (G_OBJECT (widget), "events");
4523 * gtk_widget_set_extension_events:
4524 * @widget: a #GtkWidget
4525 * @mode: bitfield of extension events to receive
4527 * Sets the extension events mask to @mode. See #GdkExtensionMode
4528 * and gdk_input_set_extension_events().
4532 gtk_widget_set_extension_events (GtkWidget *widget,
4533 GdkExtensionMode mode)
4535 GdkExtensionMode *modep;
4537 g_return_if_fail (widget != NULL);
4538 g_return_if_fail (GTK_IS_WIDGET (widget));
4540 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4543 modep = g_new (GdkExtensionMode, 1);
4546 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode, modep);
4547 g_object_notify (G_OBJECT (widget), "extension_events");
4551 * gtk_widget_get_toplevel:
4552 * @widget: a #GtkWidget
4554 * This function returns the topmost widget in the container hierarchy
4555 * @widget is a part of. If @widget has no parent widgets, it will be
4556 * returned as the topmost widget. No reference will be added to the
4557 * returned widget; it should not be unreferenced.
4559 * Note the difference in behavior vs. gtk_widget_get_ancestor();
4560 * gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW) would return
4561 * %NULL if @widget wasn't inside a toplevel window.
4563 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor
4566 gtk_widget_get_toplevel (GtkWidget *widget)
4568 g_return_val_if_fail (widget != NULL, NULL);
4569 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4571 while (widget->parent)
4572 widget = widget->parent;
4578 * gtk_widget_get_ancestor:
4579 * @widget: a #GtkWidget
4580 * @widget_type: ancestor type
4582 * Gets the first ancestor of @widget with type @widget_type. For example,
4583 * gtk_widget_get_ancestor (widget, GTK_TYPE_BOX) gets the first #GtkBox that's
4584 * an ancestor of @widget. No reference will be added to the returned widget;
4585 * it should not be unreferenced.
4587 * Return value: the ancestor widget, or %NULL if not found
4590 gtk_widget_get_ancestor (GtkWidget *widget,
4591 GtkType widget_type)
4593 g_return_val_if_fail (widget != NULL, NULL);
4594 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4596 while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
4597 widget = widget->parent;
4599 if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
4606 * gtk_widget_get_colormap:
4607 * @widget: a #GtkWidget
4609 * Gets the colormap that will be used to render @widget. No reference will
4610 * be added to the returned colormap; it should not be unreferenced.
4612 * Return value: the colormap used by @widget
4615 gtk_widget_get_colormap (GtkWidget *widget)
4617 GdkColormap *colormap;
4619 g_return_val_if_fail (widget != NULL, NULL);
4620 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4624 colormap = gdk_window_get_colormap (widget->window);
4625 /* If window was destroyed previously, we'll get NULL here */
4630 colormap = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_colormap);
4634 return gtk_widget_get_default_colormap ();
4638 * gtk_widget_get_visual:
4639 * @widget: a #GtkWidget
4641 * Gets the visual that will be used to render @widget.
4643 * Return value: the visual for @widget
4646 gtk_widget_get_visual (GtkWidget *widget)
4648 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4650 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
4655 * gtk_widget_set_colormap:
4656 * @widget: a #GtkWidget
4657 * @colormap: a colormap
4659 * Set the colormap for the widget to the given value. Widget must not
4660 * have been previously realized. This probably should only be used
4661 * from an init() function (i.e. from the constructor for the widget).
4665 gtk_widget_set_colormap (GtkWidget *widget,
4666 GdkColormap *colormap)
4668 g_return_if_fail (widget != NULL);
4669 g_return_if_fail (GTK_IS_WIDGET (widget));
4670 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4671 g_return_if_fail (GDK_IS_COLORMAP (colormap));
4673 g_object_ref (G_OBJECT (colormap));
4675 g_object_set_qdata_full (G_OBJECT (widget),
4678 (GtkDestroyNotify) g_object_unref);
4682 * gtk_widget_get_events:
4683 * @widget: a #GtkWidget
4685 * Returns the event mask for the widget (a bitfield containing flags
4686 * from the #GdkEventMask enumeration). These are the events that the widget
4689 * Return value: event mask for @widget
4692 gtk_widget_get_events (GtkWidget *widget)
4696 g_return_val_if_fail (widget != NULL, 0);
4697 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4699 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4707 * gtk_widget_get_extension_events:
4708 * @widget: a #GtkWidget
4710 * Retrieves the extension events the widget will receive; see
4711 * gdk_input_set_extension_events().
4713 * Return value: extension events for @widget
4716 gtk_widget_get_extension_events (GtkWidget *widget)
4718 GdkExtensionMode *mode;
4720 g_return_val_if_fail (widget != NULL, 0);
4721 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4723 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4731 * gtk_widget_get_pointer:
4732 * @widget: a #GtkWidget
4733 * @x: return location for the X coordinate, or %NULL
4734 * @y: return location for the Y coordinate, or %NULL
4736 * Obtains the location of the mouse pointer in widget coordinates.
4737 * Widget coordinates are a bit odd; for historical reasons, they are
4738 * defined as widget->window coordinates for widgets that are not
4739 * #GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
4740 * widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4744 gtk_widget_get_pointer (GtkWidget *widget,
4748 g_return_if_fail (widget != NULL);
4749 g_return_if_fail (GTK_IS_WIDGET (widget));
4756 if (GTK_WIDGET_REALIZED (widget))
4758 gdk_window_get_pointer (widget->window, x, y, NULL);
4760 if (GTK_WIDGET_NO_WINDOW (widget))
4763 *x -= widget->allocation.x;
4765 *y -= widget->allocation.y;
4771 * gtk_widget_is_ancestor:
4772 * @widget: a #GtkWidget
4773 * @ancestor: another #GtkWidget
4775 * Determines whether @widget is somewhere inside @ancestor, possibly with
4776 * intermediate containers.
4778 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
4781 gtk_widget_is_ancestor (GtkWidget *widget,
4782 GtkWidget *ancestor)
4784 g_return_val_if_fail (widget != NULL, FALSE);
4785 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4786 g_return_val_if_fail (ancestor != NULL, FALSE);
4790 if (widget->parent == ancestor)
4792 widget = widget->parent;
4798 static GQuark quark_composite_name = 0;
4801 gtk_widget_set_composite_name (GtkWidget *widget,
4804 g_return_if_fail (widget != NULL);
4805 g_return_if_fail (GTK_IS_WIDGET (widget));
4806 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
4807 g_return_if_fail (name != NULL);
4809 if (!quark_composite_name)
4810 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
4812 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
4813 quark_composite_name,
4819 gtk_widget_get_composite_name (GtkWidget *widget)
4821 g_return_val_if_fail (widget != NULL, NULL);
4822 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4824 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
4825 return gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
4832 gtk_widget_push_composite_child (void)
4834 composite_child_stack++;
4838 gtk_widget_pop_composite_child (void)
4840 if (composite_child_stack)
4841 composite_child_stack--;
4845 * gtk_widget_push_colormap:
4846 * @cmap: a #GdkColormap
4848 * Pushes @cmap onto a global stack of colormaps; the topmost
4849 * colormap on the stack will be used to create all widgets.
4850 * Remove @cmap with gtk_widget_pop_colormap(). There's little
4851 * reason to use this function.
4855 gtk_widget_push_colormap (GdkColormap *cmap)
4857 g_return_if_fail (cmap != NULL);
4859 colormap_stack = g_slist_prepend (colormap_stack, cmap);
4863 * gtk_widget_pop_colormap:
4865 * Removes a colormap pushed with gtk_widget_push_colormap().
4869 gtk_widget_pop_colormap (void)
4875 tmp = colormap_stack;
4876 colormap_stack = colormap_stack->next;
4877 g_slist_free_1 (tmp);
4882 * gtk_widget_set_default_colormap:
4883 * @colormap: a #GdkColormap
4885 * Sets the default colormap to use when creating widgets.
4886 * gtk_widget_push_colormap() is a better function to use if
4887 * you only want to affect a few widgets, rather than all widgets.
4891 gtk_widget_set_default_colormap (GdkColormap *colormap)
4893 if (default_colormap != colormap)
4895 if (default_colormap)
4896 gdk_colormap_unref (default_colormap);
4897 default_colormap = colormap;
4898 if (default_colormap)
4899 gdk_colormap_ref (default_colormap);
4904 * gtk_widget_get_default_colormap:
4906 * Obtains the default colormap used to create widgets.
4908 * Return value: default widget colormap
4911 gtk_widget_get_default_colormap (void)
4913 if (!default_colormap)
4914 gtk_widget_set_default_colormap (gdk_colormap_get_system ());
4916 return default_colormap;
4920 * gtk_widget_get_default_visual:
4922 * Obtains the visual of the default colormap. Not really useful;
4923 * used to be useful before gdk_colormap_get_visual() existed.
4925 * Return value: visual of the default colormap
4928 gtk_widget_get_default_visual (void)
4930 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
4934 gtk_widget_emit_direction_changed (GtkWidget *widget,
4935 GtkTextDirection old_dir)
4937 PangoContext *context = gtk_widget_peek_pango_context (widget);
4940 pango_context_set_base_dir (context,
4941 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4942 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4944 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
4948 * gtk_widget_set_direction:
4949 * @widget: a #GtkWidget
4950 * @dir: the new direction
4952 * Set the reading direction on a particular widget. This direction
4953 * controls the primary direction for widgets containing text,
4954 * and also the direction in which the children of a container are
4955 * packed. The ability to set the direction is present in order
4956 * so that correct localization into languages with right-to-left
4957 * reading directions can be done. Generally, applications will
4958 * let the default reading direction present, except for containers
4959 * where the containers are arranged in an order that is explicitely
4960 * visual rather than logical (such as buttons for text justificiation).
4962 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
4963 * set by gtk_widget_set_default_direction() will be used.
4966 gtk_widget_set_direction (GtkWidget *widget,
4967 GtkTextDirection dir)
4969 GtkTextDirection old_dir;
4971 g_return_if_fail (widget != NULL);
4972 g_return_if_fail (GTK_IS_WIDGET (widget));
4973 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
4975 old_dir = gtk_widget_get_direction (widget);
4977 if (dir == GTK_TEXT_DIR_NONE)
4978 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
4981 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
4982 if (dir == GTK_TEXT_DIR_LTR)
4983 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
4985 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
4988 if (old_dir != gtk_widget_get_direction (widget))
4989 gtk_widget_emit_direction_changed (widget, old_dir);
4993 * gtk_widget_get_direction:
4994 * @widget: a #GtkWidget
4996 * Get the reading direction for a particular widget. See
4997 * gtk_widget_set_direction().
4999 * Return value: the reading direction for the widget.
5002 gtk_widget_get_direction (GtkWidget *widget)
5004 g_return_val_if_fail (widget != NULL, GTK_TEXT_DIR_LTR);
5005 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
5007 if (GTK_WIDGET_DIRECTION_SET (widget))
5008 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
5010 return gtk_default_direction;
5014 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
5016 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
5018 g_object_ref (G_OBJECT (widget));
5020 if (!GTK_WIDGET_DIRECTION_SET (widget))
5021 gtk_widget_emit_direction_changed (widget, old_dir);
5023 if (GTK_IS_CONTAINER (widget))
5024 gtk_container_forall (GTK_CONTAINER (widget),
5025 gtk_widget_set_default_direction_recurse,
5028 g_object_unref (G_OBJECT (widget));
5032 * gtk_widget_set_default_direction:
5033 * @dir: the new default direction. This cannot be
5034 * %GTK_TEXT_DIR_NONE.
5036 * Set the default reading direction for widgets where the
5037 * direction has not been explicitly set by gtk_widget_set_direction().
5040 gtk_widget_set_default_direction (GtkTextDirection dir)
5042 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
5044 if (dir != gtk_default_direction)
5046 GList *toplevels, *tmp_list;
5047 GtkTextDirection old_dir = gtk_default_direction;
5049 gtk_default_direction = dir;
5051 tmp_list = toplevels = gtk_window_list_toplevels ();
5052 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
5056 gtk_widget_set_default_direction_recurse (tmp_list->data,
5057 GUINT_TO_POINTER (old_dir));
5058 g_object_unref (tmp_list->data);
5059 tmp_list = tmp_list->next;
5062 g_list_free (toplevels);
5067 * gtk_widget_get_default_direction:
5069 * Return value: the current default direction. See
5070 * gtk_widget_set_direction().
5073 gtk_widget_get_default_direction (void)
5075 return gtk_default_direction;
5079 gtk_widget_shutdown (GObject *object)
5081 GtkWidget *widget = GTK_WIDGET (object);
5084 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5086 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
5087 if (GTK_WIDGET_REALIZED (widget))
5088 gtk_widget_unrealize (widget);
5090 G_OBJECT_CLASS (parent_class)->shutdown (object);
5094 gtk_widget_real_destroy (GtkObject *object)
5097 GtkStyle *saved_style;
5099 /* gtk_object_destroy() will already hold a refcount on object
5101 widget = GTK_WIDGET (object);
5103 gtk_grab_remove (widget);
5104 gtk_selection_remove_all (widget);
5106 saved_style = gtk_object_get_data_by_id (object, quark_saved_default_style);
5109 gtk_style_unref (saved_style);
5110 gtk_object_remove_data_by_id (object, quark_saved_default_style);
5113 gtk_style_unref (widget->style);
5114 widget->style = gtk_widget_peek_style ();
5115 gtk_style_ref (widget->style);
5117 GTK_OBJECT_CLASS (parent_class)->destroy (object);
5121 gtk_widget_finalize (GObject *object)
5123 GtkWidget *widget = GTK_WIDGET (object);
5124 GtkWidgetAuxInfo *aux_info;
5126 GdkExtensionMode *mode;
5127 GtkStyle *saved_style;
5128 GtkAccessible *accessible;
5130 gtk_grab_remove (widget);
5131 gtk_selection_remove_all (widget);
5133 saved_style = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
5136 gtk_style_unref (saved_style);
5137 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_saved_default_style);
5140 gtk_style_unref (widget->style);
5141 widget->style = NULL;
5144 g_free (widget->name);
5146 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
5148 gtk_widget_aux_info_destroy (aux_info);
5150 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
5154 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
5158 accessible = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accessible_object);
5160 g_object_unref (G_OBJECT (accessible));
5162 G_OBJECT_CLASS (parent_class)->finalize (object);
5165 /*****************************************
5166 * gtk_widget_real_map:
5171 *****************************************/
5174 gtk_widget_real_map (GtkWidget *widget)
5176 g_return_if_fail (GTK_IS_WIDGET (widget));
5177 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
5179 if (!GTK_WIDGET_MAPPED (widget))
5181 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
5183 if (!GTK_WIDGET_NO_WINDOW (widget))
5184 gdk_window_show (widget->window);
5188 /*****************************************
5189 * gtk_widget_real_unmap:
5194 *****************************************/
5197 gtk_widget_real_unmap (GtkWidget *widget)
5199 g_return_if_fail (widget != NULL);
5200 g_return_if_fail (GTK_IS_WIDGET (widget));
5202 if (GTK_WIDGET_MAPPED (widget))
5204 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5206 if (!GTK_WIDGET_NO_WINDOW (widget))
5207 gdk_window_hide (widget->window);
5211 /*****************************************
5212 * gtk_widget_real_realize:
5217 *****************************************/
5220 gtk_widget_real_realize (GtkWidget *widget)
5222 g_return_if_fail (widget != NULL);
5223 g_return_if_fail (GTK_IS_WIDGET (widget));
5224 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
5226 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
5229 widget->window = gtk_widget_get_parent_window (widget);
5230 gdk_window_ref (widget->window);
5232 widget->style = gtk_style_attach (widget->style, widget->window);
5235 /*****************************************
5236 * gtk_widget_real_unrealize:
5241 *****************************************/
5244 gtk_widget_real_unrealize (GtkWidget *widget)
5246 g_return_if_fail (widget != NULL);
5247 g_return_if_fail (GTK_IS_WIDGET (widget));
5249 if (GTK_WIDGET_MAPPED (widget))
5250 gtk_widget_real_unmap (widget);
5252 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5254 /* printf ("unrealizing %s\n", gtk_type_name (GTK_OBJECT (widget)->klass->type));
5257 /* We must do unrealize child widget BEFORE container widget.
5258 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
5259 * So, unrealizing container widget bofore its children causes the problem
5260 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
5263 if (GTK_IS_CONTAINER (widget))
5264 gtk_container_forall (GTK_CONTAINER (widget),
5265 (GtkCallback) gtk_widget_unrealize,
5268 gtk_style_detach (widget->style);
5269 if (!GTK_WIDGET_NO_WINDOW (widget))
5271 gdk_window_set_user_data (widget->window, NULL);
5272 gdk_window_destroy (widget->window);
5273 widget->window = NULL;
5277 gdk_window_unref (widget->window);
5278 widget->window = NULL;
5281 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
5285 gtk_widget_real_size_request (GtkWidget *widget,
5286 GtkRequisition *requisition)
5288 g_return_if_fail (widget != NULL);
5289 g_return_if_fail (GTK_IS_WIDGET (widget));
5291 requisition->width = widget->requisition.width;
5292 requisition->height = widget->requisition.height;
5295 /*****************************************
5296 * gtk_widget_peek_colormap:
5301 *****************************************/
5304 gtk_widget_peek_colormap (void)
5307 return (GdkColormap*) colormap_stack->data;
5308 return gtk_widget_get_default_colormap ();
5312 gtk_widget_propagate_state (GtkWidget *widget,
5317 /* don't call this function with state==GTK_STATE_INSENSITIVE,
5318 * parent_sensitive==TRUE on a sensitive widget
5321 old_state = GTK_WIDGET_STATE (widget);
5323 if (data->parent_sensitive)
5325 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5327 if (GTK_WIDGET_IS_SENSITIVE (widget))
5329 if (data->state_restoration)
5330 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
5332 GTK_WIDGET_STATE (widget) = data->state;
5336 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5337 if (!data->state_restoration &&
5338 data->state != GTK_STATE_INSENSITIVE)
5339 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5344 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5345 if (!data->state_restoration)
5347 if (data->state != GTK_STATE_INSENSITIVE)
5348 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5350 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
5351 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
5352 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5355 if (GTK_WIDGET_HAS_FOCUS (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
5359 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
5361 gtk_window_set_focus (GTK_WINDOW (window), NULL);
5364 if (old_state != GTK_WIDGET_STATE (widget))
5366 gtk_widget_ref (widget);
5368 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
5369 gtk_grab_remove (widget);
5371 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STATE_CHANGED], old_state);
5374 if (GTK_IS_CONTAINER (widget))
5376 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
5377 data->state = GTK_WIDGET_STATE (widget);
5378 if (data->use_forall)
5379 gtk_container_forall (GTK_CONTAINER (widget),
5380 (GtkCallback) gtk_widget_propagate_state,
5383 gtk_container_foreach (GTK_CONTAINER (widget),
5384 (GtkCallback) gtk_widget_propagate_state,
5387 gtk_widget_unref (widget);
5392 * _gtk_widget_get_aux_info:
5393 * @widget: a #GtkWidget
5394 * @create: if %TRUE, create the structure if it doesn't exist
5396 * Get the #GtkWidgetAuxInfo structure for the widget.
5398 * Return value: the #GtkAuxInfo structure for the widget, or
5399 * %NULL if @create is %FALSE and one doesn't already exist.
5402 _gtk_widget_get_aux_info (GtkWidget *widget,
5405 GtkWidgetAuxInfo *aux_info;
5407 aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_aux_info);
5408 if (!aux_info && create)
5410 if (!aux_info_mem_chunk)
5411 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
5412 sizeof (GtkWidgetAuxInfo),
5413 1024, G_ALLOC_AND_FREE);
5414 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
5416 aux_info->width = -1;
5417 aux_info->height = -1;
5420 aux_info->x_set = FALSE;
5421 aux_info->y_set = FALSE;
5422 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_aux_info, aux_info);
5428 /*****************************************
5429 * gtk_widget_aux_info_destroy:
5434 *****************************************/
5437 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
5439 g_return_if_fail (aux_info != NULL);
5441 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
5445 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
5447 gdk_drawable_unref (info->shape_mask);
5451 /*****************************************
5452 * gtk_widget_shape_combine_mask:
5453 * set a shape for this widgets' gdk window, this allows for
5454 * transparent windows etc., see gdk_window_shape_combine_mask
5455 * for more information
5460 *****************************************/
5462 gtk_widget_shape_combine_mask (GtkWidget *widget,
5463 GdkBitmap *shape_mask,
5467 GtkWidgetShapeInfo* shape_info;
5469 g_return_if_fail (widget != NULL);
5470 g_return_if_fail (GTK_IS_WIDGET (widget));
5471 /* set_shape doesn't work on widgets without gdk window */
5472 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
5476 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5479 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
5481 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
5485 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5487 shape_info = g_new (GtkWidgetShapeInfo, 1);
5488 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
5489 (GDestroyNotify) gtk_widget_shape_info_destroy);
5491 shape_info->shape_mask = gdk_drawable_ref (shape_mask);
5492 shape_info->offset_x = offset_x;
5493 shape_info->offset_y = offset_y;
5495 /* set shape if widget has a gdk window allready.
5496 * otherwise the shape is scheduled to be set by gtk_widget_realize.
5499 gdk_window_shape_combine_mask (widget->window, shape_mask,
5500 offset_x, offset_y);
5505 gtk_reset_shapes_recurse (GtkWidget *widget,
5511 gdk_window_get_user_data (window, &data);
5515 gdk_window_shape_combine_mask (window, NULL, 0, 0);
5516 for (list = gdk_window_peek_children (window); list; list = list->next)
5517 gtk_reset_shapes_recurse (widget, list->data);
5521 gtk_widget_reset_shapes (GtkWidget *widget)
5523 g_return_if_fail (widget != NULL);
5524 g_return_if_fail (GTK_IS_WIDGET (widget));
5525 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
5527 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
5528 gtk_reset_shapes_recurse (widget, widget->window);
5533 * @widget: a #GtkWidget
5535 * Adds a reference to a widget. This function is exactly the same
5536 * as calling g_object_ref(), and exists mostly for historical
5537 * reasons. It can still be convenient to avoid casting a widget
5538 * to a #GObject, it saves a small amount of typing.
5540 * Return value: the widget that was referenced
5543 gtk_widget_ref (GtkWidget *widget)
5545 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5547 return (GtkWidget*) g_object_ref ((GObject*) widget);
5552 * @widget: a #GtkWidget
5554 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
5558 gtk_widget_unref (GtkWidget *widget)
5560 g_return_if_fail (GTK_IS_WIDGET (widget));
5562 g_object_unref ((GObject*) widget);
5570 gtk_widget_class_install_style_property_parser (GtkWidgetClass *class,
5572 GtkRcPropertyParser parser)
5574 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5575 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5576 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
5577 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
5579 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
5581 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
5582 G_OBJECT_CLASS_NAME (class),
5587 g_param_spec_ref (pspec);
5588 g_param_spec_sink (pspec);
5589 g_param_spec_set_qdata (pspec, quark_property_parser, parser);
5590 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
5594 gtk_widget_class_install_style_property (GtkWidgetClass *class,
5597 GtkRcPropertyParser parser;
5599 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5600 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5602 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
5604 gtk_widget_class_install_style_property_parser (class, pspec, parser);
5608 gtk_widget_style_get_property (GtkWidget *widget,
5609 const gchar *property_name,
5614 g_return_if_fail (GTK_IS_WIDGET (widget));
5615 g_return_if_fail (property_name != NULL);
5616 g_return_if_fail (G_IS_VALUE (value));
5618 g_object_ref (widget);
5619 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5621 G_OBJECT_TYPE (widget),
5624 g_warning ("%s: widget class `%s' has no property named `%s'",
5626 G_OBJECT_TYPE_NAME (widget),
5630 const GValue *peek_value;
5632 peek_value = _gtk_style_peek_property_value (widget->style,
5633 G_OBJECT_TYPE (widget),
5635 g_param_spec_get_qdata (pspec, quark_property_parser));
5637 /* auto-conversion of the caller's value type
5639 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
5640 g_value_copy (peek_value, value);
5641 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
5642 g_value_transform (peek_value, value);
5644 g_warning ("can't retrive style property `%s' of type `%s' as value of type `%s'",
5646 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
5647 G_VALUE_TYPE_NAME (value));
5649 g_object_unref (widget);
5653 gtk_widget_style_get_valist (GtkWidget *widget,
5654 const gchar *first_property_name,
5659 g_return_if_fail (GTK_IS_WIDGET (widget));
5661 g_object_ref (widget);
5663 name = first_property_name;
5666 const GValue *peek_value;
5670 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5672 G_OBJECT_TYPE (widget),
5676 g_warning ("%s: widget class `%s' has no property named `%s'",
5678 G_OBJECT_TYPE_NAME (widget),
5682 /* style pspecs are always readable so we can spare that check here */
5684 peek_value = _gtk_style_peek_property_value (widget->style,
5685 G_OBJECT_TYPE (widget),
5687 g_param_spec_get_qdata (pspec, quark_property_parser));
5688 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
5691 g_warning ("%s: %s", G_STRLOC, error);
5696 name = va_arg (var_args, gchar*);
5699 g_object_unref (widget);
5703 gtk_widget_style_get (GtkWidget *widget,
5704 const gchar *first_property_name,
5709 g_return_if_fail (GTK_IS_WIDGET (widget));
5711 va_start (var_args, first_property_name);
5712 gtk_widget_style_get_valist (widget, first_property_name, var_args);
5718 * @widget: a #GtkWidget
5719 * @path_length: location to store length of the path
5720 * @path: location to store allocated path string
5721 * @path_reversed: location to store allocated reverse path string
5723 * Obtains the full path to @widget. The path is simply the name of a
5724 * widget and all its parents in the container hierarchy, separated by
5725 * periods. The name of a widget comes from
5726 * gtk_widget_get_name(). Paths are used to apply styles to a widget
5727 * in gtkrc configuration files. Widget names are the type of the
5728 * widget by default (e.g. "GtkButton") or can be set to an
5729 * application-specific value with gtk_widget_set_name(). By setting
5730 * the name of a widget, you allow users or theme authors to apply
5731 * styles to that specific widget in their gtkrc
5732 * file. @path_reversed_p fills in the path in reverse order,
5733 * i.e. starting with @widget's name instead of starting with the name
5734 * of @widget's outermost ancestor.
5738 gtk_widget_path (GtkWidget *widget,
5739 guint *path_length_p,
5741 gchar **path_reversed_p)
5743 static gchar *rev_path = NULL;
5744 static guint path_len = 0;
5747 g_return_if_fail (widget != NULL);
5748 g_return_if_fail (GTK_IS_WIDGET (widget));
5753 const gchar *string;
5758 string = gtk_widget_get_name (widget);
5759 l = strlen (string);
5760 while (path_len <= len + l + 1)
5762 path_len += INIT_PATH_SIZE;
5763 rev_path = g_realloc (rev_path, path_len);
5771 widget = widget->parent;
5774 rev_path[len++] = '.';
5776 rev_path[len++] = 0;
5781 *path_length_p = len - 1;
5782 if (path_reversed_p)
5783 *path_reversed_p = g_strdup (rev_path);
5786 *path_p = g_strdup (rev_path);
5787 g_strreverse (*path_p);
5792 * gtk_widget_class_path:
5793 * @widget: a #GtkWidget
5794 * @path_length: location to store the length of the class path
5795 * @path: location to store the class path as an allocated string
5796 * @path_reversed: location to store the reverse class path as an allocated string
5798 * Same as gtk_widget_path(), but always uses the name of a widget's type,
5799 * never uses a custom name set with gtk_widget_set_name().
5803 gtk_widget_class_path (GtkWidget *widget,
5804 guint *path_length_p,
5806 gchar **path_reversed_p)
5808 static gchar *rev_path = NULL;
5809 static guint path_len = 0;
5812 g_return_if_fail (widget != NULL);
5813 g_return_if_fail (GTK_IS_WIDGET (widget));
5818 const gchar *string;
5823 string = gtk_type_name (GTK_WIDGET_TYPE (widget));
5824 l = strlen (string);
5825 while (path_len <= len + l + 1)
5827 path_len += INIT_PATH_SIZE;
5828 rev_path = g_realloc (rev_path, path_len);
5836 widget = widget->parent;
5839 rev_path[len++] = '.';
5841 rev_path[len++] = 0;
5846 *path_length_p = len - 1;
5847 if (path_reversed_p)
5848 *path_reversed_p = g_strdup (rev_path);
5851 *path_p = g_strdup (rev_path);
5852 g_strreverse (*path_p);
5857 gtk_requisition_copy (const GtkRequisition *requisition)
5859 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
5863 gtk_requisition_free (GtkRequisition *requisition)
5865 g_free (requisition);
5868 AtkObject* gtk_widget_get_accessible (GtkWidget *widget)
5870 GtkWidgetClass *klass;
5872 g_return_val_if_fail (widget != NULL, NULL);
5873 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5875 klass = GTK_WIDGET_GET_CLASS (widget);
5877 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
5879 return klass->get_accessible(widget);
5882 AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget)
5884 AtkObject* accessible;
5886 accessible = g_object_get_qdata (G_OBJECT (widget),
5887 quark_accessible_object);
5890 AtkObjectFactory *factory;
5891 AtkRegistry *default_registry;
5893 default_registry = atk_get_default_registry ();
5894 factory = atk_registry_get_factory (default_registry,
5895 GTK_OBJECT_TYPE (widget));
5897 atk_object_factory_create_accessible (factory,
5899 g_object_set_qdata (G_OBJECT (widget),
5900 quark_accessible_object,
5907 * Initialize a AtkImplementorIface instance's virtual pointers as
5908 * appropriate to this implementor's class (GtkWidget).
5911 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
5913 iface->ref_accessible = gtk_widget_ref_accessible;
5917 gtk_widget_ref_accessible(AtkImplementor *implementor)
5919 AtkObject *accessible;
5921 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
5923 g_object_ref (G_OBJECT (accessible));