1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkcontainer.h"
31 #include "gtkaccelmap.h"
32 #include "gtkiconfactory.h"
35 #include "gtkmarshalers.h"
37 #include "gtkselection.h"
38 #include "gtksettings.h"
39 #include "gtksizegroup.h"
40 #include "gtksignal.h"
41 #include "gtkwidget.h"
42 #include "gtkwindow.h"
43 #include "gtkbindings.h"
44 #include "gtkprivate.h"
46 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
47 #include <gobject/gvaluecollector.h>
48 #include <gobject/gobjectnotifyqueue.c>
49 #include "gdk/gdkkeysyms.h"
51 #include "gtkaccessible.h"
52 #include "gtktooltips.h"
54 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
55 #define INIT_PATH_SIZE (512)
95 PROPERTY_NOTIFY_EVENT,
96 SELECTION_CLEAR_EVENT,
97 SELECTION_REQUEST_EVENT,
98 SELECTION_NOTIFY_EVENT,
113 VISIBILITY_NOTIFY_EVENT,
117 ACCEL_CLOSURES_CHANGED,
134 PROP_RECEIVES_DEFAULT,
135 PROP_COMPOSITE_CHILD,
138 PROP_EXTENSION_EVENTS
141 typedef struct _GtkStateData GtkStateData;
146 guint state_restoration : 1;
147 guint parent_sensitive : 1;
148 guint use_forall : 1;
152 /* --- prototypes --- */
153 static void gtk_widget_class_init (GtkWidgetClass *klass);
154 static void gtk_widget_init (GtkWidget *widget);
155 static void gtk_widget_set_property (GObject *object,
159 static void gtk_widget_get_property (GObject *object,
163 static void gtk_widget_dispose (GObject *object);
164 static void gtk_widget_real_destroy (GtkObject *object);
165 static void gtk_widget_finalize (GObject *object);
166 static void gtk_widget_real_show (GtkWidget *widget);
167 static void gtk_widget_real_hide (GtkWidget *widget);
168 static void gtk_widget_real_map (GtkWidget *widget);
169 static void gtk_widget_real_unmap (GtkWidget *widget);
170 static void gtk_widget_real_realize (GtkWidget *widget);
171 static void gtk_widget_real_unrealize (GtkWidget *widget);
172 static void gtk_widget_real_size_request (GtkWidget *widget,
173 GtkRequisition *requisition);
174 static void gtk_widget_real_size_allocate (GtkWidget *widget,
175 GtkAllocation *allocation);
176 static void gtk_widget_style_set (GtkWidget *widget,
177 GtkStyle *previous_style);
178 static void gtk_widget_direction_changed (GtkWidget *widget,
179 GtkTextDirection previous_direction);
181 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
182 static void gtk_widget_real_show_help (GtkWidget *widget,
183 GtkWidgetHelpType help_type);
185 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
187 GParamSpec **pspecs);
188 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
190 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
192 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
193 GdkEventFocus *event);
194 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
195 GdkEventFocus *event);
196 static gboolean gtk_widget_real_focus (GtkWidget *widget,
197 GtkDirectionType direction);
198 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
199 static void gtk_widget_reparent_container_child (GtkWidget *widget,
200 gpointer client_data);
201 static void gtk_widget_propagate_state (GtkWidget *widget,
203 static void gtk_widget_reset_rc_style (GtkWidget *widget);
204 static void gtk_widget_set_style_internal (GtkWidget *widget,
206 gboolean initial_emission);
207 static void gtk_widget_set_style_recurse (GtkWidget *widget,
208 gpointer client_data);
209 static gint gtk_widget_event_internal (GtkWidget *widget,
211 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
212 gboolean group_cycling);
213 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
214 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
215 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
216 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
217 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
221 /* --- variables --- */
222 static gpointer parent_class = NULL;
223 static guint widget_signals[LAST_SIGNAL] = { 0 };
224 static GMemChunk *aux_info_mem_chunk = NULL;
225 static GdkColormap *default_colormap = NULL;
226 static GtkStyle *gtk_default_style = NULL;
227 static GSList *colormap_stack = NULL;
228 static guint composite_child_stack = 0;
229 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
230 static GParamSpecPool *style_property_spec_pool = NULL;
232 static GQuark quark_property_parser = 0;
233 static GQuark quark_aux_info = 0;
234 static GQuark quark_accel_path = 0;
235 static GQuark quark_accel_closures = 0;
236 static GQuark quark_event_mask = 0;
237 static GQuark quark_extension_event_mode = 0;
238 static GQuark quark_parent_window = 0;
239 static GQuark quark_shape_info = 0;
240 static GQuark quark_colormap = 0;
241 static GQuark quark_pango_context = 0;
242 static GQuark quark_rc_style = 0;
243 static GQuark quark_accessible_object = 0;
244 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
245 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
247 /* --- functions --- */
249 gtk_widget_get_type (void)
251 static GtkType widget_type = 0;
255 static const GtkTypeInfo widget_info =
259 sizeof (GtkWidgetClass),
260 (GtkClassInitFunc) gtk_widget_class_init,
261 (GtkObjectInitFunc) gtk_widget_init,
262 /* reserved_1 */ NULL,
263 /* reserved_2 */ NULL,
264 (GtkClassInitFunc) NULL,
267 static const GInterfaceInfo accessibility_info =
269 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
270 (GInterfaceFinalizeFunc) NULL,
271 NULL /* interface data */
275 widget_type = gtk_type_unique (GTK_TYPE_OBJECT, &widget_info);
277 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
278 &accessibility_info) ;
286 child_property_notify_dispatcher (GObject *object,
290 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
294 gtk_widget_class_init (GtkWidgetClass *klass)
296 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
297 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
298 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
299 GtkBindingSet *binding_set;
301 parent_class = g_type_class_peek_parent (klass);
303 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
304 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
305 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
306 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
307 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
308 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
309 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
310 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
311 quark_colormap = g_quark_from_static_string ("gtk-colormap");
312 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
313 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
314 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
316 style_property_spec_pool = g_param_spec_pool_new (FALSE);
317 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
318 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
319 cpn_context.dispatcher = child_property_notify_dispatcher;
320 _gtk_widget_child_property_notify_context = &cpn_context;
322 gobject_class->dispose = gtk_widget_dispose;
323 gobject_class->finalize = gtk_widget_finalize;
324 gobject_class->set_property = gtk_widget_set_property;
325 gobject_class->get_property = gtk_widget_get_property;
327 object_class->destroy = gtk_widget_real_destroy;
329 klass->activate_signal = 0;
330 klass->set_scroll_adjustments_signal = 0;
331 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
332 klass->show = gtk_widget_real_show;
333 klass->show_all = gtk_widget_show;
334 klass->hide = gtk_widget_real_hide;
335 klass->hide_all = gtk_widget_hide;
336 klass->map = gtk_widget_real_map;
337 klass->unmap = gtk_widget_real_unmap;
338 klass->realize = gtk_widget_real_realize;
339 klass->unrealize = gtk_widget_real_unrealize;
340 klass->size_request = gtk_widget_real_size_request;
341 klass->size_allocate = gtk_widget_real_size_allocate;
342 klass->state_changed = NULL;
343 klass->parent_set = NULL;
344 klass->hierarchy_changed = NULL;
345 klass->style_set = gtk_widget_style_set;
346 klass->direction_changed = gtk_widget_direction_changed;
347 klass->grab_notify = NULL;
348 klass->child_notify = NULL;
349 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
350 klass->grab_focus = gtk_widget_real_grab_focus;
351 klass->focus = gtk_widget_real_focus;
353 klass->button_press_event = NULL;
354 klass->button_release_event = NULL;
355 klass->motion_notify_event = NULL;
356 klass->delete_event = NULL;
357 klass->destroy_event = NULL;
358 klass->expose_event = NULL;
359 klass->key_press_event = gtk_widget_real_key_press_event;
360 klass->key_release_event = gtk_widget_real_key_release_event;
361 klass->enter_notify_event = NULL;
362 klass->leave_notify_event = NULL;
363 klass->configure_event = NULL;
364 klass->focus_in_event = gtk_widget_real_focus_in_event;
365 klass->focus_out_event = gtk_widget_real_focus_out_event;
366 klass->map_event = NULL;
367 klass->unmap_event = NULL;
368 klass->window_state_event = NULL;
369 klass->property_notify_event = gtk_selection_property_notify;
370 klass->selection_clear_event = gtk_selection_clear;
371 klass->selection_request_event = gtk_selection_request;
372 klass->selection_notify_event = gtk_selection_notify;
373 klass->selection_received = NULL;
374 klass->proximity_in_event = NULL;
375 klass->proximity_out_event = NULL;
376 klass->drag_begin = NULL;
377 klass->drag_end = NULL;
378 klass->drag_data_delete = NULL;
379 klass->drag_leave = NULL;
380 klass->drag_motion = NULL;
381 klass->drag_drop = NULL;
382 klass->drag_data_received = NULL;
384 klass->show_help = gtk_widget_real_show_help;
386 /* Accessibility support */
387 klass->get_accessible = gtk_widget_real_get_accessible;
389 klass->no_expose_event = NULL;
391 g_object_class_install_property (gobject_class,
393 g_param_spec_string ("name",
395 _("The name of the widget"),
398 g_object_class_install_property (gobject_class,
400 g_param_spec_object ("parent",
402 _("The parent widget of this widget. Must be a Container widget."),
406 g_object_class_install_property (gobject_class,
408 g_param_spec_int ("width_request",
410 _("Override for width request of the widget, or -1 if natural request should be used."),
415 g_object_class_install_property (gobject_class,
417 g_param_spec_int ("height_request",
419 _("Override for height request of the widget, or -1 if natural request should be used."),
424 g_object_class_install_property (gobject_class,
426 g_param_spec_boolean ("visible",
428 _("Whether the widget is visible"),
431 g_object_class_install_property (gobject_class,
433 g_param_spec_boolean ("sensitive",
435 _("Whether the widget responds to input"),
438 g_object_class_install_property (gobject_class,
440 g_param_spec_boolean ("app_paintable",
441 _("Application paintable"),
442 _("Whether the application will paint directly on the widget"),
445 g_object_class_install_property (gobject_class,
447 g_param_spec_boolean ("can_focus",
449 _("Whether the widget can accept the input focus"),
452 g_object_class_install_property (gobject_class,
454 g_param_spec_boolean ("has_focus",
456 _("Whether the widget has the input focus"),
459 g_object_class_install_property (gobject_class,
461 g_param_spec_boolean ("can_default",
463 _("Whether the widget can be the default widget"),
466 g_object_class_install_property (gobject_class,
468 g_param_spec_boolean ("has_default",
470 _("Whether the widget is the default widget"),
473 g_object_class_install_property (gobject_class,
474 PROP_RECEIVES_DEFAULT,
475 g_param_spec_boolean ("receives_default",
476 _("Receives default"),
477 _("If TRUE, the widget will receive the default action when it is focused."),
480 g_object_class_install_property (gobject_class,
481 PROP_COMPOSITE_CHILD,
482 g_param_spec_boolean ("composite_child",
483 _("Composite child"),
484 _("Whether the widget is composed of other widgets"),
487 g_object_class_install_property (gobject_class,
489 g_param_spec_object ("style",
491 _("The style of the widget, which contains information about how it will look (colors etc)."),
494 g_object_class_install_property (gobject_class,
496 g_param_spec_flags ("events",
498 _("The event mask that decides what kind of GdkEvents this widget gets."),
502 g_object_class_install_property (gobject_class,
503 PROP_EXTENSION_EVENTS,
504 g_param_spec_enum ("extension_events",
505 _("Extension events"),
506 _("The mask that decides what kind of extension events this widget gets."),
507 GDK_TYPE_EXTENSION_MODE,
508 GDK_EXTENSION_EVENTS_NONE,
510 widget_signals[SHOW] =
511 gtk_signal_new ("show",
513 GTK_CLASS_TYPE (object_class),
514 GTK_SIGNAL_OFFSET (GtkWidgetClass, show),
515 _gtk_marshal_VOID__VOID,
517 widget_signals[HIDE] =
518 gtk_signal_new ("hide",
520 GTK_CLASS_TYPE (object_class),
521 GTK_SIGNAL_OFFSET (GtkWidgetClass, hide),
522 _gtk_marshal_VOID__VOID,
524 widget_signals[MAP] =
525 gtk_signal_new ("map",
527 GTK_CLASS_TYPE (object_class),
528 GTK_SIGNAL_OFFSET (GtkWidgetClass, map),
529 _gtk_marshal_VOID__VOID,
531 widget_signals[UNMAP] =
532 gtk_signal_new ("unmap",
534 GTK_CLASS_TYPE (object_class),
535 GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap),
536 _gtk_marshal_VOID__VOID,
538 widget_signals[REALIZE] =
539 gtk_signal_new ("realize",
541 GTK_CLASS_TYPE (object_class),
542 GTK_SIGNAL_OFFSET (GtkWidgetClass, realize),
543 _gtk_marshal_VOID__VOID,
545 widget_signals[UNREALIZE] =
546 gtk_signal_new ("unrealize",
548 GTK_CLASS_TYPE (object_class),
549 GTK_SIGNAL_OFFSET (GtkWidgetClass, unrealize),
550 _gtk_marshal_VOID__VOID,
552 widget_signals[SIZE_REQUEST] =
553 g_signal_new ("size_request",
554 G_OBJECT_CLASS_TYPE (object_class),
556 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
558 _gtk_marshal_VOID__BOXED,
560 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
561 widget_signals[SIZE_ALLOCATE] =
562 gtk_signal_new ("size_allocate",
564 GTK_CLASS_TYPE (object_class),
565 GTK_SIGNAL_OFFSET (GtkWidgetClass, size_allocate),
566 _gtk_marshal_VOID__BOXED,
568 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
569 widget_signals[STATE_CHANGED] =
570 gtk_signal_new ("state_changed",
572 GTK_CLASS_TYPE (object_class),
573 GTK_SIGNAL_OFFSET (GtkWidgetClass, state_changed),
574 _gtk_marshal_VOID__ENUM,
576 GTK_TYPE_STATE_TYPE);
577 widget_signals[PARENT_SET] =
578 gtk_signal_new ("parent_set",
580 GTK_CLASS_TYPE (object_class),
581 GTK_SIGNAL_OFFSET (GtkWidgetClass, parent_set),
582 _gtk_marshal_VOID__OBJECT,
585 widget_signals[HIERARCHY_CHANGED] =
586 gtk_signal_new ("hierarchy_changed",
588 GTK_CLASS_TYPE (object_class),
589 GTK_SIGNAL_OFFSET (GtkWidgetClass, hierarchy_changed),
590 _gtk_marshal_VOID__OBJECT,
593 widget_signals[STYLE_SET] =
594 gtk_signal_new ("style_set",
596 GTK_CLASS_TYPE (object_class),
597 GTK_SIGNAL_OFFSET (GtkWidgetClass, style_set),
598 _gtk_marshal_VOID__OBJECT,
601 widget_signals[DIRECTION_CHANGED] =
602 gtk_signal_new ("direction_changed",
604 GTK_CLASS_TYPE (object_class),
605 GTK_SIGNAL_OFFSET (GtkWidgetClass, direction_changed),
606 _gtk_marshal_VOID__ENUM,
608 GTK_TYPE_TEXT_DIRECTION);
609 widget_signals[GRAB_NOTIFY] =
610 gtk_signal_new ("grab_notify",
612 GTK_CLASS_TYPE (object_class),
613 GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_notify),
614 _gtk_marshal_VOID__BOOLEAN,
617 widget_signals[CHILD_NOTIFY] =
618 g_signal_new ("child_notify",
619 G_TYPE_FROM_CLASS (klass),
620 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
621 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
623 g_cclosure_marshal_VOID__PARAM,
626 widget_signals[MNEMONIC_ACTIVATE] =
627 g_signal_new ("mnemonic_activate",
628 GTK_CLASS_TYPE (object_class),
630 GTK_SIGNAL_OFFSET (GtkWidgetClass, mnemonic_activate),
631 _gtk_boolean_handled_accumulator, NULL,
632 _gtk_marshal_BOOLEAN__BOOLEAN,
635 widget_signals[GRAB_FOCUS] =
636 gtk_signal_new ("grab_focus",
637 GTK_RUN_LAST | GTK_RUN_ACTION,
638 GTK_CLASS_TYPE (object_class),
639 GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_focus),
640 _gtk_marshal_VOID__VOID,
642 widget_signals[FOCUS] =
643 g_signal_new ("focus",
644 G_TYPE_FROM_CLASS (object_class),
646 G_STRUCT_OFFSET (GtkWidgetClass, focus),
647 _gtk_boolean_handled_accumulator, NULL,
648 _gtk_marshal_BOOLEAN__ENUM,
650 GTK_TYPE_DIRECTION_TYPE);
651 widget_signals[EVENT] =
652 g_signal_new ("event",
653 G_TYPE_FROM_CLASS (object_class),
655 G_STRUCT_OFFSET(GtkWidgetClass, event),
656 _gtk_boolean_handled_accumulator, NULL,
657 _gtk_marshal_BOOLEAN__BOXED,
659 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
660 widget_signals[EVENT_AFTER] =
661 g_signal_new ("event-after",
662 G_TYPE_FROM_CLASS (object_class),
666 _gtk_marshal_VOID__BOXED,
667 G_TYPE_NONE, 1, GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
668 widget_signals[BUTTON_PRESS_EVENT] =
669 g_signal_new ("button_press_event",
670 G_TYPE_FROM_CLASS (object_class),
672 G_STRUCT_OFFSET(GtkWidgetClass, button_press_event),
673 _gtk_boolean_handled_accumulator, NULL,
674 _gtk_marshal_BOOLEAN__BOXED,
676 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
677 widget_signals[BUTTON_RELEASE_EVENT] =
678 g_signal_new ("button_release_event",
679 G_TYPE_FROM_CLASS(object_class),
681 G_STRUCT_OFFSET(GtkWidgetClass, button_release_event),
682 _gtk_boolean_handled_accumulator, NULL,
683 _gtk_marshal_BOOLEAN__BOXED,
685 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
686 widget_signals[SCROLL_EVENT] =
687 g_signal_new ("scroll_event",
688 G_TYPE_FROM_CLASS(object_class),
690 G_STRUCT_OFFSET(GtkWidgetClass, scroll_event),
691 _gtk_boolean_handled_accumulator, NULL,
692 _gtk_marshal_BOOLEAN__BOXED,
694 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
695 widget_signals[MOTION_NOTIFY_EVENT] =
696 g_signal_new ("motion_notify_event",
697 G_TYPE_FROM_CLASS(object_class),
699 G_STRUCT_OFFSET(GtkWidgetClass, motion_notify_event),
700 _gtk_boolean_handled_accumulator, NULL,
701 _gtk_marshal_BOOLEAN__BOXED,
703 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
704 widget_signals[DELETE_EVENT] =
705 g_signal_new ("delete_event",
706 G_TYPE_FROM_CLASS(object_class),
708 G_STRUCT_OFFSET(GtkWidgetClass, delete_event),
709 _gtk_boolean_handled_accumulator, NULL,
710 _gtk_marshal_BOOLEAN__BOXED,
712 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
713 widget_signals[DESTROY_EVENT] =
714 g_signal_new ("destroy_event",
715 G_TYPE_FROM_CLASS(object_class),
717 G_STRUCT_OFFSET(GtkWidgetClass, destroy_event),
718 _gtk_boolean_handled_accumulator, NULL,
719 _gtk_marshal_BOOLEAN__BOXED,
721 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
722 widget_signals[EXPOSE_EVENT] =
723 g_signal_new ("expose_event",
724 G_TYPE_FROM_CLASS(object_class),
726 G_STRUCT_OFFSET(GtkWidgetClass, expose_event),
727 _gtk_boolean_handled_accumulator, NULL,
728 _gtk_marshal_BOOLEAN__BOXED,
730 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
731 widget_signals[KEY_PRESS_EVENT] =
732 g_signal_new ("key_press_event",
733 G_TYPE_FROM_CLASS(object_class),
735 G_STRUCT_OFFSET(GtkWidgetClass, key_press_event),
736 _gtk_boolean_handled_accumulator, NULL,
737 _gtk_marshal_BOOLEAN__BOXED,
739 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
740 widget_signals[KEY_RELEASE_EVENT] =
741 g_signal_new ("key_release_event",
742 G_TYPE_FROM_CLASS(object_class),
744 G_STRUCT_OFFSET(GtkWidgetClass, key_release_event),
745 _gtk_boolean_handled_accumulator, NULL,
746 _gtk_marshal_BOOLEAN__BOXED,
748 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
749 widget_signals[ENTER_NOTIFY_EVENT] =
750 g_signal_new ("enter_notify_event",
751 G_TYPE_FROM_CLASS(object_class),
753 G_STRUCT_OFFSET(GtkWidgetClass, enter_notify_event),
754 _gtk_boolean_handled_accumulator, NULL,
755 _gtk_marshal_BOOLEAN__BOXED,
757 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
758 widget_signals[LEAVE_NOTIFY_EVENT] =
759 g_signal_new ("leave_notify_event",
760 G_TYPE_FROM_CLASS(object_class),
762 G_STRUCT_OFFSET(GtkWidgetClass, leave_notify_event),
763 _gtk_boolean_handled_accumulator, NULL,
764 _gtk_marshal_BOOLEAN__BOXED,
766 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
767 widget_signals[CONFIGURE_EVENT] =
768 g_signal_new ("configure_event",
769 G_TYPE_FROM_CLASS(object_class),
771 G_STRUCT_OFFSET(GtkWidgetClass, configure_event),
772 _gtk_boolean_handled_accumulator, NULL,
773 _gtk_marshal_BOOLEAN__BOXED,
775 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
776 widget_signals[FOCUS_IN_EVENT] =
777 g_signal_new ("focus_in_event",
778 G_TYPE_FROM_CLASS(object_class),
780 G_STRUCT_OFFSET(GtkWidgetClass, focus_in_event),
781 _gtk_boolean_handled_accumulator, NULL,
782 _gtk_marshal_BOOLEAN__BOXED,
784 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
785 widget_signals[FOCUS_OUT_EVENT] =
786 g_signal_new ("focus_out_event",
787 G_TYPE_FROM_CLASS(object_class),
789 G_STRUCT_OFFSET(GtkWidgetClass, focus_out_event),
790 _gtk_boolean_handled_accumulator, NULL,
791 _gtk_marshal_BOOLEAN__BOXED,
793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
794 widget_signals[MAP_EVENT] =
795 g_signal_new ("map_event",
796 G_TYPE_FROM_CLASS(object_class),
798 G_STRUCT_OFFSET(GtkWidgetClass, map_event),
799 _gtk_boolean_handled_accumulator, NULL,
800 _gtk_marshal_BOOLEAN__BOXED,
802 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
803 widget_signals[UNMAP_EVENT] =
804 g_signal_new ("unmap_event",
805 G_TYPE_FROM_CLASS(object_class),
807 G_STRUCT_OFFSET(GtkWidgetClass, unmap_event),
808 _gtk_boolean_handled_accumulator, NULL,
809 _gtk_marshal_BOOLEAN__BOXED,
811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
812 widget_signals[PROPERTY_NOTIFY_EVENT] =
813 g_signal_new ("property_notify_event",
814 G_TYPE_FROM_CLASS(object_class),
816 G_STRUCT_OFFSET(GtkWidgetClass, property_notify_event),
817 _gtk_boolean_handled_accumulator, NULL,
818 _gtk_marshal_BOOLEAN__BOXED,
820 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
821 widget_signals[SELECTION_CLEAR_EVENT] =
822 g_signal_new ("selection_clear_event",
823 G_TYPE_FROM_CLASS(object_class),
825 G_STRUCT_OFFSET(GtkWidgetClass, selection_clear_event),
826 _gtk_boolean_handled_accumulator, NULL,
827 _gtk_marshal_BOOLEAN__BOXED,
829 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
830 widget_signals[SELECTION_REQUEST_EVENT] =
831 g_signal_new ("selection_request_event",
832 G_TYPE_FROM_CLASS(object_class),
834 G_STRUCT_OFFSET(GtkWidgetClass, selection_request_event),
835 _gtk_boolean_handled_accumulator, NULL,
836 _gtk_marshal_BOOLEAN__BOXED,
838 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
839 widget_signals[SELECTION_NOTIFY_EVENT] =
840 g_signal_new ("selection_notify_event",
841 G_TYPE_FROM_CLASS(object_class),
843 G_STRUCT_OFFSET(GtkWidgetClass, selection_notify_event),
844 _gtk_boolean_handled_accumulator, NULL,
845 _gtk_marshal_BOOLEAN__BOXED,
847 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
848 widget_signals[SELECTION_RECEIVED] =
849 g_signal_new ("selection_received",
850 G_TYPE_FROM_CLASS (object_class),
852 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
854 _gtk_marshal_VOID__BOXED_UINT,
856 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
858 widget_signals[SELECTION_GET] =
859 g_signal_new ("selection_get",
860 G_TYPE_FROM_CLASS (object_class),
862 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
864 _gtk_marshal_VOID__BOXED_UINT_UINT,
866 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
869 widget_signals[PROXIMITY_IN_EVENT] =
870 g_signal_new ("proximity_in_event",
871 G_TYPE_FROM_CLASS (object_class),
873 G_STRUCT_OFFSET(GtkWidgetClass, proximity_in_event),
874 _gtk_boolean_handled_accumulator, NULL,
875 _gtk_marshal_BOOLEAN__BOXED,
877 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
878 widget_signals[PROXIMITY_OUT_EVENT] =
879 g_signal_new ("proximity_out_event",
880 G_TYPE_FROM_CLASS(object_class),
882 G_STRUCT_OFFSET(GtkWidgetClass, proximity_out_event),
883 _gtk_boolean_handled_accumulator, NULL,
884 _gtk_marshal_BOOLEAN__BOXED,
886 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
887 widget_signals[DRAG_LEAVE] =
888 gtk_signal_new ("drag_leave",
890 GTK_CLASS_TYPE (object_class),
891 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_leave),
892 _gtk_marshal_VOID__OBJECT_UINT,
894 GDK_TYPE_DRAG_CONTEXT,
896 widget_signals[DRAG_BEGIN] =
897 gtk_signal_new ("drag_begin",
899 GTK_CLASS_TYPE (object_class),
900 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin),
901 _gtk_marshal_VOID__OBJECT,
903 GDK_TYPE_DRAG_CONTEXT);
904 widget_signals[DRAG_END] =
905 gtk_signal_new ("drag_end",
907 GTK_CLASS_TYPE (object_class),
908 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end),
909 _gtk_marshal_VOID__OBJECT,
911 GDK_TYPE_DRAG_CONTEXT);
912 widget_signals[DRAG_DATA_DELETE] =
913 gtk_signal_new ("drag_data_delete",
915 GTK_CLASS_TYPE (object_class),
916 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_delete),
917 _gtk_marshal_VOID__OBJECT,
919 GDK_TYPE_DRAG_CONTEXT);
920 widget_signals[DRAG_MOTION] =
921 g_signal_new ("drag_motion",
922 G_TYPE_FROM_CLASS(object_class),
924 G_STRUCT_OFFSET(GtkWidgetClass, drag_motion),
925 _gtk_boolean_handled_accumulator, NULL,
926 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
928 GDK_TYPE_DRAG_CONTEXT,
932 widget_signals[DRAG_DROP] =
933 g_signal_new ("drag_drop",
934 G_TYPE_FROM_CLASS(object_class),
936 G_STRUCT_OFFSET(GtkWidgetClass, drag_drop),
937 _gtk_boolean_handled_accumulator, NULL,
938 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
940 GDK_TYPE_DRAG_CONTEXT,
944 widget_signals[DRAG_DATA_GET] =
945 g_signal_new ("drag_data_get",
946 G_TYPE_FROM_CLASS (object_class),
948 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
950 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
952 GDK_TYPE_DRAG_CONTEXT,
953 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
956 widget_signals[DRAG_DATA_RECEIVED] =
957 g_signal_new ("drag_data_received",
958 G_TYPE_FROM_CLASS (object_class),
960 GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_received),
962 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
964 GDK_TYPE_DRAG_CONTEXT,
967 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
970 widget_signals[VISIBILITY_NOTIFY_EVENT] =
971 g_signal_new ("visibility_notify_event",
972 G_TYPE_FROM_CLASS(object_class),
974 G_STRUCT_OFFSET(GtkWidgetClass, visibility_notify_event),
975 _gtk_boolean_handled_accumulator, NULL,
976 _gtk_marshal_BOOLEAN__BOXED,
978 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
979 widget_signals[CLIENT_EVENT] =
980 g_signal_new ("client_event",
981 G_TYPE_FROM_CLASS(object_class),
983 G_STRUCT_OFFSET(GtkWidgetClass, client_event),
984 _gtk_boolean_handled_accumulator, NULL,
985 _gtk_marshal_BOOLEAN__BOXED,
987 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
988 widget_signals[NO_EXPOSE_EVENT] =
989 g_signal_new ("no_expose_event",
990 G_TYPE_FROM_CLASS(object_class),
992 G_STRUCT_OFFSET(GtkWidgetClass, no_expose_event),
993 _gtk_boolean_handled_accumulator, NULL,
994 _gtk_marshal_BOOLEAN__BOXED,
996 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
997 widget_signals[WINDOW_STATE_EVENT] =
998 g_signal_new ("window_state_event",
999 G_TYPE_FROM_CLASS(object_class),
1001 G_STRUCT_OFFSET(GtkWidgetClass, window_state_event),
1002 _gtk_boolean_handled_accumulator, NULL,
1003 _gtk_marshal_BOOLEAN__BOXED,
1005 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1006 widget_signals[POPUP_MENU] =
1007 gtk_signal_new ("popup_menu",
1008 GTK_RUN_LAST | GTK_RUN_ACTION,
1009 GTK_CLASS_TYPE (object_class),
1010 GTK_SIGNAL_OFFSET (GtkWidgetClass, popup_menu),
1011 _gtk_marshal_NONE__NONE,
1013 widget_signals[SHOW_HELP] =
1014 gtk_signal_new ("show_help",
1015 GTK_RUN_LAST | GTK_RUN_ACTION,
1016 GTK_CLASS_TYPE (object_class),
1017 GTK_SIGNAL_OFFSET (GtkWidgetClass, show_help),
1018 _gtk_marshal_NONE__ENUM,
1019 GTK_TYPE_NONE, 1, GTK_TYPE_WIDGET_HELP_TYPE);
1020 widget_signals[ACCEL_CLOSURES_CHANGED] =
1021 gtk_signal_new ("accel_closures_changed",
1023 GTK_CLASS_TYPE (object_class),
1025 gtk_marshal_NONE__NONE,
1028 binding_set = gtk_binding_set_by_class (klass);
1029 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1031 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1034 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1036 GTK_TYPE_WIDGET_HELP_TYPE,
1037 GTK_WIDGET_HELP_TOOLTIP);
1038 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1040 GTK_TYPE_WIDGET_HELP_TYPE,
1041 GTK_WIDGET_HELP_TOOLTIP);
1042 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1044 GTK_TYPE_WIDGET_HELP_TYPE,
1045 GTK_WIDGET_HELP_WHATS_THIS);
1046 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1048 GTK_TYPE_WIDGET_HELP_TYPE,
1049 GTK_WIDGET_HELP_WHATS_THIS);
1051 gtk_widget_class_install_style_property (klass,
1052 g_param_spec_boolean ("interior_focus",
1053 _("Interior Focus"),
1054 _("Whether to draw the focus indicator inside widgets."),
1058 gtk_widget_class_install_style_property (klass,
1059 g_param_spec_int ("focus-line-width",
1060 _("Focus linewidth"),
1061 _("Width, in pixels, of the focus indicator line."),
1063 G_PARAM_READWRITE));
1065 gtk_widget_class_install_style_property (klass,
1066 g_param_spec_string ("focus-line-pattern",
1067 _("Focus line dash pattern"),
1068 _("Dash pattern used to draw the focus indicator."),
1070 G_PARAM_READWRITE));
1071 gtk_widget_class_install_style_property (klass,
1072 g_param_spec_int ("focus-padding",
1074 _("Width, in pixels, between focus indicator and the widget 'box'."),
1076 G_PARAM_READWRITE));
1081 gtk_widget_set_property (GObject *object,
1083 const GValue *value,
1088 widget = GTK_WIDGET (object);
1092 guint32 saved_flags;
1095 gtk_widget_set_name (widget, g_value_get_string (value));
1098 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1100 case PROP_WIDTH_REQUEST:
1101 gtk_widget_set_usize (widget, g_value_get_int (value), -2);
1103 case PROP_HEIGHT_REQUEST:
1104 gtk_widget_set_usize (widget, -2, g_value_get_int (value));
1107 if (g_value_get_boolean (value))
1108 gtk_widget_show (widget);
1110 gtk_widget_hide (widget);
1112 case PROP_SENSITIVE:
1113 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1115 case PROP_APP_PAINTABLE:
1116 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1118 case PROP_CAN_FOCUS:
1119 saved_flags = GTK_WIDGET_FLAGS (widget);
1120 if (g_value_get_boolean (value))
1121 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1123 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1124 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1125 gtk_widget_queue_resize (widget);
1127 case PROP_HAS_FOCUS:
1128 if (g_value_get_boolean (value))
1129 gtk_widget_grab_focus (widget);
1131 case PROP_CAN_DEFAULT:
1132 saved_flags = GTK_WIDGET_FLAGS (widget);
1133 if (g_value_get_boolean (value))
1134 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1136 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1137 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1138 gtk_widget_queue_resize (widget);
1140 case PROP_HAS_DEFAULT:
1141 if (g_value_get_boolean (value))
1142 gtk_widget_grab_default (widget);
1144 case PROP_RECEIVES_DEFAULT:
1145 if (g_value_get_boolean (value))
1146 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1148 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1151 gtk_widget_set_style (widget, g_value_get_object (value));
1154 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1155 gtk_widget_set_events (widget, g_value_get_flags (value));
1157 case PROP_EXTENSION_EVENTS:
1158 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1166 gtk_widget_get_property (GObject *object,
1173 widget = GTK_WIDGET (object);
1178 GdkExtensionMode *modep;
1182 g_value_set_string (value, widget->name);
1184 g_value_set_string (value, "");
1188 g_value_set_object (value, widget->parent);
1190 g_value_set_object (value, NULL);
1192 case PROP_WIDTH_REQUEST:
1195 gtk_widget_get_size_request (widget, &w, NULL);
1196 g_value_set_int (value, w);
1199 case PROP_HEIGHT_REQUEST:
1202 gtk_widget_get_size_request (widget, NULL, &h);
1203 g_value_set_int (value, h);
1207 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1209 case PROP_SENSITIVE:
1210 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1212 case PROP_APP_PAINTABLE:
1213 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1215 case PROP_CAN_FOCUS:
1216 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1218 case PROP_HAS_FOCUS:
1219 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1221 case PROP_CAN_DEFAULT:
1222 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1224 case PROP_HAS_DEFAULT:
1225 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1227 case PROP_RECEIVES_DEFAULT:
1228 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1230 case PROP_COMPOSITE_CHILD:
1231 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1234 g_value_set_object (value, gtk_widget_get_style (widget));
1237 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
1239 g_value_set_flags (value, 0);
1241 g_value_set_flags (value, *eventp);
1243 case PROP_EXTENSION_EVENTS:
1244 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
1246 g_value_set_enum (value, 0);
1248 g_value_set_enum (value, (GdkExtensionMode) *modep);
1251 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1257 gtk_widget_init (GtkWidget *widget)
1259 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1260 widget->state = GTK_STATE_NORMAL;
1261 widget->saved_state = GTK_STATE_NORMAL;
1262 widget->name = NULL;
1263 widget->requisition.width = 0;
1264 widget->requisition.height = 0;
1265 widget->allocation.x = -1;
1266 widget->allocation.y = -1;
1267 widget->allocation.width = 1;
1268 widget->allocation.height = 1;
1269 widget->window = NULL;
1270 widget->parent = NULL;
1272 GTK_WIDGET_SET_FLAGS (widget,
1274 GTK_PARENT_SENSITIVE |
1275 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1276 GTK_DOUBLE_BUFFERED);
1278 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1280 widget->style = gtk_widget_get_default_style ();
1281 g_object_ref (widget->style);
1286 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1288 GParamSpec **pspecs)
1290 GtkWidget *container = widget->parent;
1293 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1294 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1298 gtk_widget_freeze_child_notify (GtkWidget *widget)
1300 g_return_if_fail (GTK_IS_WIDGET (widget));
1302 if (!G_OBJECT (widget)->ref_count)
1305 g_object_ref (widget);
1306 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1307 g_object_unref (widget);
1311 gtk_widget_child_notify (GtkWidget *widget,
1312 const gchar *child_property)
1316 g_return_if_fail (GTK_IS_WIDGET (widget));
1317 g_return_if_fail (child_property != NULL);
1318 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1321 g_object_ref (widget);
1322 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1324 G_OBJECT_TYPE (widget->parent),
1327 g_warning ("%s: container class `%s' has no child property named `%s'",
1329 G_OBJECT_TYPE_NAME (widget->parent),
1333 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1335 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1336 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1338 g_object_unref (widget);
1342 * gtk_widget_thaw_child_notify:
1343 * @widget: a #GtkWidget
1345 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1348 gtk_widget_thaw_child_notify (GtkWidget *widget)
1350 GObjectNotifyQueue *nqueue;
1352 g_return_if_fail (GTK_IS_WIDGET (widget));
1354 if (!G_OBJECT (widget)->ref_count)
1357 g_object_ref (widget);
1358 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1359 if (!nqueue || !nqueue->freeze_count)
1360 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1361 G_OBJECT_TYPE_NAME (widget), widget);
1363 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1364 g_object_unref (widget);
1370 * @type: type ID of the widget to create
1371 * @first_property_name: name of first property to set
1372 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1374 * This is a convenience function for creating a widget and setting
1375 * its properties in one go. For example you might write:
1376 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1377 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1378 * gtk_object_new(), but returns a widget so you don't have to
1379 * cast the object yourself.
1381 * Return value: a new #GtkWidget of type @widget_type
1384 gtk_widget_new (GtkType type,
1385 const gchar *first_property_name,
1391 g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1393 va_start (var_args, first_property_name);
1394 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1402 * @widget: a #GtkWidget
1403 * @first_property_name: name of first property to set
1404 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1406 * Like gtk_object_set() - there's no reason to use this instead of
1410 gtk_widget_set (GtkWidget *widget,
1411 const gchar *first_property_name,
1416 g_return_if_fail (GTK_IS_WIDGET (widget));
1418 va_start (var_args, first_property_name);
1419 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1424 gtk_widget_queue_clear_child (GtkWidget *widget)
1428 parent = widget->parent;
1429 if (parent && GTK_WIDGET_DRAWABLE (parent))
1430 gtk_widget_queue_clear_area (parent,
1431 widget->allocation.x,
1432 widget->allocation.y,
1433 widget->allocation.width,
1434 widget->allocation.height);
1438 * gtk_widget_unparent:
1439 * @widget: a #GtkWidget
1441 * This function is only for use in widget implementations.
1442 * Should be called by implementations of the remove method
1443 * on #GtkContainer, to dissociate a child from the container.
1446 gtk_widget_unparent (GtkWidget *widget)
1448 GObjectNotifyQueue *nqueue;
1449 GtkWidget *toplevel;
1450 GtkWidget *old_parent;
1452 g_return_if_fail (GTK_IS_WIDGET (widget));
1453 if (widget->parent == NULL)
1456 /* keep this function in sync with gtk_menu_detach()
1459 g_object_freeze_notify (G_OBJECT (widget));
1460 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1462 /* unset focused and default children properly, this code
1463 * should eventually move into some gtk_window_unparent_branch() or
1467 toplevel = gtk_widget_get_toplevel (widget);
1468 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1470 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1472 if (GTK_WIDGET_TOPLEVEL (toplevel))
1476 child = GTK_WINDOW (toplevel)->focus_widget;
1478 while (child && child != widget)
1479 child = child->parent;
1481 if (child == widget)
1482 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1485 if (GTK_WIDGET_TOPLEVEL (toplevel))
1489 child = GTK_WINDOW (toplevel)->default_widget;
1491 while (child && child != widget)
1492 child = child->parent;
1494 if (child == widget)
1495 gtk_window_set_default (GTK_WINDOW (toplevel), NULL);
1498 /* If we are unanchoring the child, we save around the toplevel
1499 * to emit hierarchy changed
1501 if (GTK_WIDGET_ANCHORED (widget->parent))
1502 g_object_ref (toplevel);
1506 gtk_widget_queue_clear_child (widget);
1508 /* Reset the width and height here, to force reallocation if we
1509 * get added back to a new parent. This won't work if our new
1510 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1511 * (would 0x0 be OK here?)
1513 widget->allocation.width = 1;
1514 widget->allocation.height = 1;
1516 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1517 gtk_widget_unrealize (widget);
1519 /* Removing a widget from a container restores the child visible
1520 * flag to the default state, so it doesn't affect the child
1521 * in the next parent.
1523 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1525 old_parent = widget->parent;
1526 widget->parent = NULL;
1527 gtk_widget_set_parent_window (widget, NULL);
1528 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], old_parent);
1531 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1532 g_object_unref (toplevel);
1535 g_object_notify (G_OBJECT (widget), "parent");
1536 g_object_thaw_notify (G_OBJECT (widget));
1537 if (!widget->parent)
1538 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1539 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1540 gtk_widget_unref (widget);
1544 * gtk_widget_destroy:
1545 * @widget: a #GtkWidget
1547 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1548 * you don't have to cast the widget to #GtkObject. When a widget is
1549 * destroyed, it will break any references it holds to other objects.
1550 * If the widget is inside a container, the widget will be removed
1551 * from the container. If the widget is a toplevel (derived from
1552 * #GtkWindow), it will be removed from the list of toplevels, and the
1553 * reference GTK+ holds to it will be removed. Removing a
1554 * widget from its container or the list of toplevels results in the
1555 * widget being finalized, unless you've added additional references
1556 * to the widget with gtk_object_ref().
1558 * In most cases, only toplevel widgets (windows) require explicit
1559 * destruction, because when you destroy a toplevel its children will
1560 * be destroyed as well.
1564 gtk_widget_destroy (GtkWidget *widget)
1566 g_return_if_fail (GTK_IS_WIDGET (widget));
1568 gtk_object_destroy ((GtkObject*) widget);
1572 * gtk_widget_destroyed:
1573 * @widget: a #GtkWidget
1574 * @widget_pointer: address of a variable that contains @widget
1576 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1577 * %NULL. It's intended to be used as a callback connected to the
1578 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1579 * as a signal handler, and pass the address of your widget variable
1580 * as user data. Then when the widget is destroyed, the variable will
1581 * be set to %NULL. Useful for example to avoid multiple copies
1582 * of the same dialog.
1586 gtk_widget_destroyed (GtkWidget *widget,
1587 GtkWidget **widget_pointer)
1589 /* Don't make any assumptions about the
1591 * Even check widget_pointer.
1594 *widget_pointer = NULL;
1599 * @widget: a #GtkWidget
1601 * Flags a widget to be displayed. Any widget that isn't shown will
1602 * not appear on the screen. If you want to show all the widgets in a
1603 * container, it's easier to call gtk_widget_show_all() on the
1604 * container, instead of individually showing the widgets.
1606 * Remember that you have to show the containers containing a widget,
1607 * in addition to the widget itself, before it will appear onscreen.
1609 * When a toplevel container is shown, it is immediately realized and
1610 * mapped; other shown widgets are realized and mapped when their
1611 * toplevel container is realized and mapped.
1615 gtk_widget_show (GtkWidget *widget)
1617 g_return_if_fail (GTK_IS_WIDGET (widget));
1619 if (!GTK_WIDGET_VISIBLE (widget))
1621 g_object_ref (G_OBJECT (widget));
1622 if (!GTK_WIDGET_TOPLEVEL (widget))
1623 gtk_widget_queue_resize (widget);
1624 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SHOW]);
1625 g_object_notify (G_OBJECT (widget), "visible");
1626 g_object_unref (G_OBJECT (widget));
1631 gtk_widget_real_show (GtkWidget *widget)
1633 g_return_if_fail (GTK_IS_WIDGET (widget));
1635 if (!GTK_WIDGET_VISIBLE (widget))
1637 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1639 if (widget->parent &&
1640 GTK_WIDGET_MAPPED (widget->parent) &&
1641 GTK_WIDGET_CHILD_VISIBLE (widget) &&
1642 !GTK_WIDGET_MAPPED (widget))
1643 gtk_widget_map (widget);
1648 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1651 gtk_signal_disconnect_by_data (GTK_OBJECT (widget), flag);
1655 * gtk_widget_show_now:
1656 * @widget: a #GtkWidget
1658 * Shows a widget. If the widget is an unmapped toplevel widget
1659 * (i.e. a #GtkWindow that has not yet been shown), enter the main
1660 * loop and wait for the window to actually be mapped. Be careful;
1661 * because the main loop is running, anything can happen during
1665 gtk_widget_show_now (GtkWidget *widget)
1669 g_return_if_fail (GTK_IS_WIDGET (widget));
1671 /* make sure we will get event */
1672 if (!GTK_WIDGET_MAPPED (widget) &&
1673 GTK_WIDGET_TOPLEVEL (widget))
1675 gtk_widget_show (widget);
1677 gtk_signal_connect (GTK_OBJECT (widget), "map_event",
1678 GTK_SIGNAL_FUNC (gtk_widget_show_map_callback),
1682 gtk_main_iteration();
1685 gtk_widget_show (widget);
1690 * @widget: a #GtkWidget
1692 * Reverses the effects of gtk_widget_show(), causing the widget to be
1693 * hidden (invisible to the user).
1696 gtk_widget_hide (GtkWidget *widget)
1698 g_return_if_fail (GTK_IS_WIDGET (widget));
1700 if (GTK_WIDGET_VISIBLE (widget))
1702 gtk_widget_ref (widget);
1703 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[HIDE]);
1704 if (!GTK_WIDGET_TOPLEVEL (widget) && GTK_WIDGET_REALIZED (widget))
1705 gtk_widget_queue_resize (widget);
1706 g_object_notify (G_OBJECT (widget), "visible");
1707 gtk_widget_unref (widget);
1712 gtk_widget_real_hide (GtkWidget *widget)
1714 g_return_if_fail (GTK_IS_WIDGET (widget));
1716 if (GTK_WIDGET_VISIBLE (widget))
1718 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1720 if (GTK_WIDGET_MAPPED (widget))
1721 gtk_widget_unmap (widget);
1726 * gtk_widget_hide_on_delete:
1727 * @widget: a #GtkWidget
1729 * Utility function; intended to be connected to the "delete_event"
1730 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
1731 * argument, then returns %TRUE. If connected to "delete_event",
1732 * the result is that clicking the window manager close button for
1733 * will hide but not destroy the window. By default, GTK+ destroys
1734 * windows when "delete_event" is received.
1736 * Return value: %TRUE
1739 gtk_widget_hide_on_delete (GtkWidget *widget)
1741 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1743 gtk_widget_hide (widget);
1749 * gtk_widget_show_all:
1750 * @widget: a #GtkWidget
1752 * Recursively shows a widget, and any child widgets (if the widget is
1756 gtk_widget_show_all (GtkWidget *widget)
1758 GtkWidgetClass *class;
1760 g_return_if_fail (GTK_IS_WIDGET (widget));
1762 class = GTK_WIDGET_GET_CLASS (widget);
1764 if (class->show_all)
1765 class->show_all (widget);
1769 * gtk_widget_hide_all:
1770 * @widget: a #GtkWidget
1772 * Recursively hides a widget and any child widgets.
1775 gtk_widget_hide_all (GtkWidget *widget)
1777 GtkWidgetClass *class;
1779 g_return_if_fail (GTK_IS_WIDGET (widget));
1781 class = GTK_WIDGET_GET_CLASS (widget);
1783 if (class->hide_all)
1784 class->hide_all (widget);
1789 * @widget: a #GtkWidget
1791 * This function is only for use in widget implementations. Causes
1792 * a widget to be mapped if it isn't already.
1796 gtk_widget_map (GtkWidget *widget)
1798 g_return_if_fail (GTK_IS_WIDGET (widget));
1799 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
1800 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
1802 if (!GTK_WIDGET_MAPPED (widget))
1804 if (!GTK_WIDGET_REALIZED (widget))
1805 gtk_widget_realize (widget);
1807 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[MAP]);
1809 if (GTK_WIDGET_NO_WINDOW (widget))
1810 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
1816 * @widget: a #GtkWidget
1818 * This function is only for use in widget implementations. Causes
1819 * a widget to be unmapped if it's currently mapped.
1823 gtk_widget_unmap (GtkWidget *widget)
1825 g_return_if_fail (GTK_IS_WIDGET (widget));
1827 if (GTK_WIDGET_MAPPED (widget))
1829 if (GTK_WIDGET_NO_WINDOW (widget))
1830 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
1831 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNMAP]);
1836 * gtk_widget_realize:
1837 * @widget: a #GtkWidget
1839 * Creates the GDK (windowing system) resources associated with a
1840 * widget. For example, @widget->window will be created when a widget
1841 * is realized. Normally realization happens implicitly; if you show
1842 * a widget and all its parent containers, then the widget will be
1843 * realized and mapped automatically.
1845 * Realizing a widget requires all
1846 * the widget's parent widgets to be realized; calling
1847 * gtk_widget_realize() realizes the widget's parents in addition to
1848 * @widget itself. If a widget is not yet inside a toplevel window
1849 * when you realize it, bad things will happen.
1851 * This function is primarily used in widget implementations, and
1852 * isn't very useful otherwise. Many times when you think you might
1853 * need it, a better approach is to connect to a signal that will be
1854 * called after the widget is realized automatically, such as
1855 * "expose_event". Or simply gtk_signal_connect_after() to the
1860 gtk_widget_realize (GtkWidget *widget)
1863 GdkExtensionMode mode;
1864 GtkWidgetShapeInfo *shape_info;
1866 g_return_if_fail (GTK_IS_WIDGET (widget));
1868 if (!GTK_WIDGET_REALIZED (widget))
1871 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1872 g_message ("gtk_widget_realize(%s)", gtk_type_name (GTK_WIDGET_TYPE (widget)));
1875 if (widget->parent == NULL &&
1876 !GTK_WIDGET_TOPLEVEL (widget))
1877 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
1878 "inside a toplevel window is not going to work very well. "
1879 "Widgets must be inside a toplevel container before realizing them.");
1881 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
1882 gtk_widget_realize (widget->parent);
1884 gtk_widget_ensure_style (widget);
1886 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[REALIZE]);
1888 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1890 shape_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_shape_info);
1891 gdk_window_shape_combine_mask (widget->window,
1892 shape_info->shape_mask,
1893 shape_info->offset_x,
1894 shape_info->offset_y);
1897 if (!GTK_WIDGET_NO_WINDOW (widget))
1899 mode = gtk_widget_get_extension_events (widget);
1900 if (mode != GDK_EXTENSION_EVENTS_NONE)
1902 events = gtk_widget_get_events (widget);
1903 gdk_input_set_extension_events (widget->window, events, mode);
1911 * gtk_widget_unrealize:
1912 * @widget: a #GtkWidget
1914 * This function is only useful in widget implementations.
1915 * Causes a widget to be unrealized (frees all GDK resources
1916 * associated with the widget, such as @widget->window).
1920 gtk_widget_unrealize (GtkWidget *widget)
1922 g_return_if_fail (GTK_IS_WIDGET (widget));
1924 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1925 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
1927 if (GTK_WIDGET_REALIZED (widget))
1929 gtk_widget_ref (widget);
1930 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNREALIZE]);
1931 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
1932 gtk_widget_unref (widget);
1936 /*****************************************
1938 *****************************************/
1941 * gtk_widget_queue_draw_area:
1942 * @widget: a #GtkWidget
1943 * @x: x coordinate of upper-left corner of rectangle to redraw
1944 * @y: y coordinate of upper-left corner of rectangle to redraw
1945 * @width: width of region to draw
1946 * @height: height of region to draw
1948 * Invalidates the rectangular area of @widget defined by @x, @y,
1949 * @width and @height by calling gdk_window_invalidate_rect() on the
1950 * widget's window and all its child windows. Once the main loop
1951 * becomes idle (after the current batch of events has been processed,
1952 * roughly), the window will receive expose events for the union of
1953 * all regions that have been invalidated.
1955 * Normally you would only use this function in widget
1956 * implementations. You might also use it, or
1957 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
1958 * #GtkDrawingArea or some portion thereof.
1960 * Frequently you can just call gdk_window_invalidate_rect() or
1961 * gdk_window_invalidate_region() instead of this function. Those
1962 * functions will invalidate only a single window, instead of the
1963 * widget and all its children.
1965 * The advantage of adding to the invalidated region compared to
1966 * simply drawing immediately is efficiency; using an invalid region
1967 * ensures that you only have to redraw one time.
1971 gtk_widget_queue_draw_area (GtkWidget *widget,
1977 g_return_if_fail (GTK_IS_WIDGET (widget));
1979 gtk_widget_queue_clear_area (widget, x, y, width, height);
1983 * gtk_widget_queue_draw:
1984 * @widget: a #GtkWidget
1986 * Equivalent to calling gtk_widget_queue_draw_area() for the
1987 * entire area of a widget.
1991 gtk_widget_queue_draw (GtkWidget *widget)
1993 g_return_if_fail (GTK_IS_WIDGET (widget));
1995 gtk_widget_queue_clear (widget);
1998 /* Invalidates the given area (allocation-relative-coordinates)
1999 * in all of the widget's windows
2002 * gtk_widget_queue_clear_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 * DEPRECATED. This function is no longer different from
2010 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2011 * gtk_widget_queue_draw_area(). Originally
2012 * gtk_widget_queue_clear_area() would force a redraw of the
2013 * background for %GTK_NO_WINDOW widgets, and
2014 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2015 * the background will be redrawn.
2019 gtk_widget_queue_clear_area (GtkWidget *widget,
2025 GdkRectangle invalid_rect;
2027 g_return_if_fail (GTK_IS_WIDGET (widget));
2029 if (!(widget->window && gdk_window_is_viewable (widget->window)))
2032 /* Find the correct widget */
2034 if (!GTK_WIDGET_NO_WINDOW (widget))
2038 /* Translate widget relative to window-relative */
2040 gint wx, wy, wwidth, wheight;
2042 gdk_window_get_position (widget->window, &wx, &wy);
2043 x -= wx - widget->allocation.x;
2044 y -= wy - widget->allocation.y;
2046 gdk_window_get_size (widget->window, &wwidth, &wheight);
2048 if (x + width <= 0 || y + height <= 0 ||
2049 x >= wwidth || y >= wheight)
2060 if (x + width > wwidth)
2062 if (y + height > wheight)
2063 height = wheight - y;
2069 invalid_rect.width = width;
2070 invalid_rect.height = height;
2072 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2076 * gtk_widget_queue_clear:
2077 * @widget: a #GtkWidget
2079 * DEPRECATED. Use gtk_widget_queue_draw() instead.
2082 gtk_widget_queue_clear (GtkWidget *widget)
2084 g_return_if_fail (GTK_IS_WIDGET (widget));
2086 if (widget->allocation.width || widget->allocation.height)
2088 if (GTK_WIDGET_NO_WINDOW (widget))
2089 gtk_widget_queue_clear_area (widget, widget->allocation.x,
2090 widget->allocation.y,
2091 widget->allocation.width,
2092 widget->allocation.height);
2094 gtk_widget_queue_clear_area (widget, 0, 0,
2095 widget->allocation.width,
2096 widget->allocation.height);
2101 * gtk_widget_queue_resize:
2102 * @widget: a #GtkWidget
2104 * This function is only for use in widget implementations.
2105 * Flags a widget to have its size renegotiated; should
2106 * be called when a widget for some reason has a new size request.
2107 * For example, when you change the text in a #GtkLabel, #GtkLabel
2108 * queues a resize to ensure there's enough space for the new text.
2112 gtk_widget_queue_resize (GtkWidget *widget)
2116 g_return_if_fail (GTK_IS_WIDGET (widget));
2118 if (GTK_WIDGET_REALIZED (widget))
2120 region = gdk_region_rectangle (&widget->allocation);
2121 gtk_widget_invalidate_widget_windows (widget, region);
2122 gdk_region_destroy (region);
2125 _gtk_size_group_queue_resize (widget);
2130 * @widget: a #GtkWidget
2131 * @area: area to draw
2133 * DEPRECATED. In GTK+ 1.2, this function would immediately render the
2134 * region @area of a widget, by invoking the virtual draw method of a
2135 * widget. In GTK+ 2.0, the draw method is gone, and instead
2136 * gtk_widget_draw() simply invalidates the specified region of the
2137 * widget, then updates the invalid region of the widget immediately.
2138 * Usually you don't want to update the region immediately for
2139 * performance reasons, so in general gtk_widget_queue_draw_area() is
2140 * a better choice if you want to draw a region of a widget.
2144 gtk_widget_draw (GtkWidget *widget,
2147 g_return_if_fail (GTK_IS_WIDGET (widget));
2149 if (GTK_WIDGET_DRAWABLE (widget))
2152 gtk_widget_queue_draw_area (widget,
2154 area->width, area->height);
2156 gtk_widget_queue_draw (widget);
2158 gdk_window_process_updates (widget->window, TRUE);
2163 * gtk_widget_size_request:
2164 * @widget: a #GtkWidget
2165 * @requisition: a #GtkRequisition to be filled in
2167 * This function is typically used when implementing a #GtkContainer
2168 * subclass. Obtains the preferred size of a widget. The container
2169 * uses this information to arrange its child widgets and decide what
2170 * size allocations to give them with gtk_widget_size_allocate().
2172 * You can also call this function from an application, with some
2173 * caveats. Most notably, getting a size request requires the widget
2174 * to be associated with a screen, because font information may be
2175 * needed. Multihead-aware applications should keep this in mind.
2177 * Also remember that the size request is not necessarily the size
2178 * a widget will actually be allocated.
2180 * See also gtk_widget_get_child_requisition().
2183 gtk_widget_size_request (GtkWidget *widget,
2184 GtkRequisition *requisition)
2186 g_return_if_fail (GTK_IS_WIDGET (widget));
2188 #ifdef G_ENABLE_DEBUG
2189 if (requisition == &widget->requisition)
2190 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.");
2191 #endif /* G_ENABLE_DEBUG */
2193 _gtk_size_group_compute_requisition (widget, requisition);
2197 * gtk_widget_get_child_requisition:
2198 * @widget: a #GtkWidget
2199 * @requisition: a #GtkRequisition to be filled in
2201 * This function is only for use in widget implementations. Obtains
2202 * @widget->requisition, unless someone has forced a particular
2203 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2204 * case it returns that geometry instead of the widget's requisition.
2206 * This function differs from gtk_widget_size_request() in that
2207 * it retrieves the last size request value from @widget->requisition,
2208 * while gtk_widget_size_request() actually calls the "size_request" method
2209 * on @widget to compute the size request and fill in @widget->requisition,
2210 * and only then returns @widget->requisition.
2212 * Because this function does not call the "size_request" method, it
2213 * can only be used when you know that @widget->requisition is
2214 * up-to-date, that is, gtk_widget_size_request() has been called
2215 * since the last time a resize was queued. In general, only container
2216 * implementations have this information; applications should use
2217 * gtk_widget_size_request().
2220 gtk_widget_get_child_requisition (GtkWidget *widget,
2221 GtkRequisition *requisition)
2223 _gtk_size_group_get_child_requisition (widget, requisition);
2227 invalidate_predicate (GdkWindow *window,
2232 gdk_window_get_user_data (window, &user_data);
2234 return (user_data == data);
2237 /* Invalidate @region in widget->window and all children
2238 * of widget->window owned by widget. @region is in the
2239 * same coordinates as widget->allocation and will be
2240 * modified by this call.
2243 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2246 if (!GTK_WIDGET_NO_WINDOW (widget))
2250 gdk_window_get_position (widget->window, &x, &y);
2251 gdk_region_offset (region, -x, -y);
2254 gdk_window_invalidate_maybe_recurse (widget->window, region,
2255 invalidate_predicate, widget);
2259 * gtk_widget_size_allocate:
2260 * @widget: a #GtkWidget
2261 * @allocation: position and size to be allocated to @widget
2263 * This function is only used by #GtkContainer subclasses, to assign a size
2264 * and position to their child widgets.
2268 gtk_widget_size_allocate (GtkWidget *widget,
2269 GtkAllocation *allocation)
2271 GtkWidgetAuxInfo *aux_info;
2272 GdkRectangle real_allocation;
2273 GdkRectangle old_allocation;
2274 gboolean alloc_needed;
2275 gboolean size_changed;
2276 gboolean position_changed;
2278 g_return_if_fail (GTK_IS_WIDGET (widget));
2280 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2281 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2283 old_allocation = widget->allocation;
2284 real_allocation = *allocation;
2285 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2289 if (aux_info->x_set)
2290 real_allocation.x = aux_info->x;
2291 if (aux_info->y_set)
2292 real_allocation.y = aux_info->y;
2295 if (real_allocation.width < 0 || real_allocation.height < 0)
2297 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2298 real_allocation.width,
2299 real_allocation.height);
2302 real_allocation.width = MAX (real_allocation.width, 1);
2303 real_allocation.height = MAX (real_allocation.height, 1);
2305 size_changed = (old_allocation.width != real_allocation.width ||
2306 old_allocation.height != real_allocation.height);
2307 position_changed = (old_allocation.x != real_allocation.x ||
2308 old_allocation.y != real_allocation.y);
2310 if (!alloc_needed && !size_changed && !position_changed)
2313 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE], &real_allocation);
2315 if (GTK_WIDGET_MAPPED (widget))
2317 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2319 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2321 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2322 gdk_region_union_with_rect (invalidate, &old_allocation);
2324 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2325 gdk_region_destroy (invalidate);
2330 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2332 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2334 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2335 gdk_region_union_with_rect (invalidate, &old_allocation);
2337 gtk_widget_invalidate_widget_windows (widget, invalidate);
2338 gdk_region_destroy (invalidate);
2343 if ((size_changed || position_changed) && widget->parent &&
2344 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2346 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2347 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2348 gdk_region_destroy (invalidate);
2353 * gtk_widget_common_ancestor:
2354 * @widget_a: a #GtkWidget
2355 * @widget_b: a #GtkWidget
2357 * Find the common ancestor of @widget_a and @widget_b that
2358 * is closest to the two widgets.
2360 * Return value: the closest common ancestor of @widget_a and
2361 * @widget_b or %NULL if @widget_a and @widget_b do not
2362 * share a common ancestor.
2365 gtk_widget_common_ancestor (GtkWidget *widget_a,
2366 GtkWidget *widget_b)
2368 GtkWidget *parent_a;
2369 GtkWidget *parent_b;
2373 parent_a = widget_a;
2374 while (parent_a->parent)
2376 parent_a = parent_a->parent;
2380 parent_b = widget_b;
2381 while (parent_b->parent)
2383 parent_b = parent_b->parent;
2387 if (parent_a != parent_b)
2390 while (depth_a > depth_b)
2392 widget_a = widget_a->parent;
2396 while (depth_b > depth_a)
2398 widget_b = widget_b->parent;
2402 while (widget_a != widget_b)
2404 widget_a = widget_a->parent;
2405 widget_b = widget_b->parent;
2412 * gtk_widget_translate_coordinates:
2413 * @src_widget: a #GtkWidget
2414 * @dest_widget: a #GtkWidget
2415 * @src_x: X position relative to @src_widget
2416 * @src_y: Y position relative to @src_widget
2417 * @dest_x: location to store X position relative to @dest_widget
2418 * @dest_y: location to store Y position relative to @dest_widget
2420 * Translate coordinates relative to @src_widget's allocation to coordinates
2421 * relative to @dest_widget's allocations. In order to perform this
2422 * operation, both widgets must be realized, and must share a common
2425 * Return value: %FALSE if either widget was not realized, or there
2426 * was no common ancestor. In this case, nothing is stored in
2427 * *@dest_x and *@dest_y. Otherwise %TRUE.
2430 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2431 GtkWidget *dest_widget,
2437 GtkWidget *ancestor;
2440 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2441 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2443 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2444 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2447 /* Translate from allocation relative to window relative */
2448 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2451 gdk_window_get_position (src_widget->window, &wx, &wy);
2453 src_x -= wx - src_widget->allocation.x;
2454 src_y -= wy - src_widget->allocation.y;
2458 src_x += src_widget->allocation.x;
2459 src_y += src_widget->allocation.y;
2462 /* Translate to the common ancestor */
2463 window = src_widget->window;
2464 while (window != ancestor->window)
2468 gdk_window_get_position (window, &dx, &dy);
2473 window = gdk_window_get_parent (window);
2477 window = dest_widget->window;
2478 while (window != ancestor->window)
2482 gdk_window_get_position (window, &dx, &dy);
2487 window = gdk_window_get_parent (window);
2490 /* Translate from window relative to allocation relative */
2491 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2494 gdk_window_get_position (dest_widget->window, &wx, &wy);
2496 src_x += wx - dest_widget->allocation.x;
2497 src_y += wy - dest_widget->allocation.y;
2501 src_x -= dest_widget->allocation.x;
2502 src_y -= dest_widget->allocation.y;
2514 gtk_widget_real_size_allocate (GtkWidget *widget,
2515 GtkAllocation *allocation)
2517 g_return_if_fail (GTK_IS_WIDGET (widget));
2519 widget->allocation = *allocation;
2521 if (GTK_WIDGET_REALIZED (widget) &&
2522 !GTK_WIDGET_NO_WINDOW (widget))
2524 gdk_window_move_resize (widget->window,
2525 allocation->x, allocation->y,
2526 allocation->width, allocation->height);
2536 closure_accel_activate (GClosure *closure,
2537 GValue *return_value,
2538 guint n_param_values,
2539 const GValue *param_values,
2540 gpointer invocation_hint,
2541 gpointer marshal_data)
2543 AccelClosure *aclosure = (AccelClosure*) closure;
2545 if (GTK_WIDGET_IS_SENSITIVE (closure->data))
2546 g_signal_emit (closure->data, aclosure->signal_id, 0);
2548 /* we handled the accelerator */
2549 g_value_set_boolean (return_value, TRUE);
2553 closures_destroy (gpointer data)
2555 GSList *slist, *closures = data;
2557 for (slist = closures; slist; slist = slist->next)
2559 g_closure_invalidate (slist->data);
2560 g_closure_unref (slist->data);
2562 g_slist_free (closures);
2566 widget_new_accel_closure (GtkWidget *widget,
2569 AccelClosure *aclosure;
2570 GClosure *closure = NULL;
2571 GSList *slist, *closures;
2573 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
2574 for (slist = closures; slist; slist = slist->next)
2575 if (!gtk_accel_group_from_accel_closure (slist->data))
2577 /* reuse this closure */
2578 closure = slist->data;
2583 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
2584 closures = g_slist_prepend (closures, g_closure_ref (closure));
2585 g_closure_sink (closure);
2586 g_closure_set_marshal (closure, closure_accel_activate);
2588 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
2590 aclosure = (AccelClosure*) closure;
2591 g_assert (closure->data == widget);
2592 g_assert (closure->marshal == closure_accel_activate);
2593 aclosure->signal_id = signal_id;
2599 * gtk_widget_add_accelerator
2600 * @widget: widget to install an accelerator on
2601 * @accel_signal: widget signal to emit on accelerator actiavtion
2602 * @accel_group: accel group for this widget, added to its toplevel
2603 * @accel_key: GDK keyval of the accelerator
2604 * @accel_mods: modifier key combination of the accelerator
2605 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
2607 * Installs an accelerator for this @widget in @accel_group, that causes
2608 * @accel_signal to be emitted if the accelerator is activated.
2609 * The @accel_group needs to be added to the widget's toplevel via
2610 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
2611 * Accelerators added through this function are not user changable during
2612 * runtime. If you want to support accelerators that can be changed by the
2613 * user, use gtk_accel_map_add_entry() and gtk_menu_item_set_accel_path()
2617 gtk_widget_add_accelerator (GtkWidget *widget,
2618 const gchar *accel_signal,
2619 GtkAccelGroup *accel_group,
2622 GtkAccelFlags accel_flags)
2627 g_return_if_fail (GTK_IS_WIDGET (widget));
2628 g_return_if_fail (accel_signal != NULL);
2629 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
2631 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
2632 if (!query.signal_id ||
2633 !(query.signal_flags & G_SIGNAL_ACTION) ||
2634 query.return_type != G_TYPE_NONE ||
2637 /* hmm, should be elaborate enough */
2638 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
2639 G_OBJECT_TYPE_NAME (widget), accel_signal);
2643 closure = widget_new_accel_closure (widget, query.signal_id);
2645 g_object_ref (widget);
2647 /* install the accelerator. since we don't map this onto an accel_path,
2648 * the accelerator will automatically be locked.
2650 gtk_accel_group_connect (accel_group,
2653 accel_flags | GTK_ACCEL_LOCKED,
2656 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2658 g_object_unref (widget);
2662 * gtk_widget_remove_accelerator:
2663 * @widget: widget to install an accelerator on
2664 * @accel_group: accel group for this widget
2665 * @accel_key: GDK keyval of the accelerator
2666 * @accel_mods: modifier key combination of the accelerator
2667 * @returns: whether an accelerator was installed and could be removed
2669 * Removes an accelerator from @widget, previously installed with
2670 * gtk_widget_add_accelerator().
2673 gtk_widget_remove_accelerator (GtkWidget *widget,
2674 GtkAccelGroup *accel_group,
2678 GtkAccelGroupEntry *ag_entry;
2679 GList *slist, *clist;
2682 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2683 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
2685 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
2686 clist = gtk_widget_list_accel_closures (widget);
2687 for (slist = clist; slist; slist = slist->next)
2691 for (i = 0; i < n; i++)
2692 if (slist->data == (gpointer) ag_entry[i].closure)
2694 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
2696 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2698 g_list_free (clist);
2703 g_list_free (clist);
2705 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
2706 accel_key, accel_mods, accel_group,
2707 G_OBJECT_TYPE_NAME (widget), widget);
2713 * gtk_widget_list_accel_closures
2714 * @widget: widget to list accelerator closures for
2715 * @returns: a newly allocated #GList of closures
2717 * Lists the closures used by @widget for accelerator group connections
2718 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
2719 * The closures can be used to monitor accelerator changes on @widget,
2720 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
2721 * closure which can be found out with gtk_accel_group_from_accel_closure().
2724 gtk_widget_list_accel_closures (GtkWidget *widget)
2727 GList *clist = NULL;
2729 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2731 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
2732 if (gtk_accel_group_from_accel_closure (slist->data))
2733 clist = g_list_prepend (clist, slist->data);
2740 GtkAccelGroup *accel_group;
2745 destroy_accel_path (gpointer data)
2747 AccelPath *apath = data;
2749 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
2751 /* closures_destroy takes care of unrefing the closure */
2752 g_object_unref (apath->accel_group);
2757 /* accel_group: the accel group used to activate this widget
2758 * accel_path: the accel path, associating the accelerator
2759 * to activate this widget
2760 * set accel path through which this widget can be actiavated.
2763 _gtk_widget_set_accel_path (GtkWidget *widget,
2764 const gchar *accel_path,
2765 GtkAccelGroup *accel_group)
2769 g_return_if_fail (GTK_IS_WIDGET (widget));
2770 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
2774 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
2775 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
2777 gtk_accel_map_add_entry (accel_path, 0, 0);
2778 apath = g_new (AccelPath, 1);
2779 apath->widget = widget;
2780 apath->accel_group = g_object_ref (accel_group);
2781 apath->path_quark = g_quark_from_string (accel_path);
2782 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
2787 /* also removes possible old settings */
2788 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
2791 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
2793 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
2797 _gtk_widget_get_accel_path (GtkWidget *widget)
2801 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2803 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
2804 return apath ? g_quark_to_string (apath->path_quark) : NULL;
2808 gtk_widget_mnemonic_activate (GtkWidget *widget,
2809 gboolean group_cycling)
2813 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2815 group_cycling = group_cycling != FALSE;
2816 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2819 gtk_signal_emit (GTK_OBJECT (widget),
2820 widget_signals[MNEMONIC_ACTIVATE],
2827 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
2828 gboolean group_cycling)
2830 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
2831 gtk_widget_activate (widget);
2832 else if (GTK_WIDGET_CAN_FOCUS (widget))
2833 gtk_widget_grab_focus (widget);
2836 g_warning ("widget `%s' isn't suitable for mnemonic activation",
2837 G_OBJECT_TYPE_NAME (widget));
2844 gtk_widget_real_key_press_event (GtkWidget *widget,
2847 gboolean handled = FALSE;
2849 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2850 g_return_val_if_fail (event != NULL, handled);
2853 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2861 gtk_widget_real_key_release_event (GtkWidget *widget,
2864 gboolean handled = FALSE;
2866 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2867 g_return_val_if_fail (event != NULL, handled);
2870 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2872 event->state | GDK_RELEASE_MASK);
2878 gtk_widget_real_focus_in_event (GtkWidget *widget,
2879 GdkEventFocus *event)
2881 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
2882 gtk_widget_queue_draw (widget);
2888 gtk_widget_real_focus_out_event (GtkWidget *widget,
2889 GdkEventFocus *event)
2891 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
2892 gtk_widget_queue_draw (widget);
2899 * @widget: a #GtkWidget
2900 * @event: a #GdkEvent
2902 * Rarely-used function. This function is used to emit
2903 * the event signals on a widget (those signals should never
2904 * be emitted without using this function to do so).
2905 * If you want to synthesize an event though, don't use this function;
2906 * instead, use gtk_main_do_event() so the event will behave as if
2907 * it were in the event queue. Don't synthesize expose events; instead,
2908 * use gdk_window_invalidate_rect() to invalidate a region of the
2911 * Return value: return from the event signal emission (%TRUE if the event was handled)
2914 gtk_widget_event (GtkWidget *widget,
2917 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2918 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
2920 if (event->type == GDK_EXPOSE)
2922 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
2923 "the same effect, call gdk_window_invalidate_rect/region(), "
2924 "followed by gdk_window_process_updates().");
2928 return gtk_widget_event_internal (widget, event);
2933 * gtk_widget_send_expose:
2934 * @widget: a #GtkWidget
2935 * @event: a expose #GdkEvent
2937 * Very rarely-used function. This function is used to emit
2938 * an expose event signals on a widget. This function is not
2939 * normally used directly. The only time it is used is when
2940 * propagating an expose event to a child %NO_WINDOW widget, and
2941 * that is normally done using gtk_container_propagate_expose().
2943 * If you want to force an area of a window to be redrawn,
2944 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
2945 * To cause the redraw to be done immediately, follow that call
2946 * with a call to gdk_window_process_updates().
2948 * Return value: return from the event signal emission (%TRUE if the event was handled)
2951 gtk_widget_send_expose (GtkWidget *widget,
2954 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2955 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
2956 g_return_val_if_fail (event != NULL, TRUE);
2957 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
2959 if (event->type != GDK_EXPOSE)
2962 return gtk_widget_event_internal (widget, event);
2966 gtk_widget_event_internal (GtkWidget *widget,
2969 gboolean return_val = FALSE;
2971 gtk_widget_ref (widget);
2973 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT], event, &return_val);
2974 return_val |= !GTK_WIDGET_REALIZED (widget);
2979 switch (event->type)
2984 case GDK_BUTTON_PRESS:
2985 case GDK_2BUTTON_PRESS:
2986 case GDK_3BUTTON_PRESS:
2987 signal_num = BUTTON_PRESS_EVENT;
2990 signal_num = SCROLL_EVENT;
2992 case GDK_BUTTON_RELEASE:
2993 signal_num = BUTTON_RELEASE_EVENT;
2995 case GDK_MOTION_NOTIFY:
2996 signal_num = MOTION_NOTIFY_EVENT;
2999 signal_num = DELETE_EVENT;
3002 signal_num = DESTROY_EVENT;
3005 signal_num = KEY_PRESS_EVENT;
3007 case GDK_KEY_RELEASE:
3008 signal_num = KEY_RELEASE_EVENT;
3010 case GDK_ENTER_NOTIFY:
3011 signal_num = ENTER_NOTIFY_EVENT;
3013 case GDK_LEAVE_NOTIFY:
3014 signal_num = LEAVE_NOTIFY_EVENT;
3016 case GDK_FOCUS_CHANGE:
3017 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3020 signal_num = CONFIGURE_EVENT;
3023 signal_num = MAP_EVENT;
3026 signal_num = UNMAP_EVENT;
3028 case GDK_WINDOW_STATE:
3029 signal_num = WINDOW_STATE_EVENT;
3031 case GDK_PROPERTY_NOTIFY:
3032 signal_num = PROPERTY_NOTIFY_EVENT;
3034 case GDK_SELECTION_CLEAR:
3035 signal_num = SELECTION_CLEAR_EVENT;
3037 case GDK_SELECTION_REQUEST:
3038 signal_num = SELECTION_REQUEST_EVENT;
3040 case GDK_SELECTION_NOTIFY:
3041 signal_num = SELECTION_NOTIFY_EVENT;
3043 case GDK_PROXIMITY_IN:
3044 signal_num = PROXIMITY_IN_EVENT;
3046 case GDK_PROXIMITY_OUT:
3047 signal_num = PROXIMITY_OUT_EVENT;
3050 signal_num = NO_EXPOSE_EVENT;
3052 case GDK_CLIENT_EVENT:
3053 signal_num = CLIENT_EVENT;
3056 signal_num = EXPOSE_EVENT;
3058 case GDK_VISIBILITY_NOTIFY:
3059 signal_num = VISIBILITY_NOTIFY_EVENT;
3062 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3066 if (signal_num != -1)
3067 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[signal_num], event, &return_val);
3069 if (GTK_WIDGET_REALIZED (widget))
3070 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT_AFTER], event);
3074 gtk_widget_unref (widget);
3080 * gtk_widget_activate:
3081 * @widget: a #GtkWidget that's activatable
3083 * For widgets that can be "activated" (buttons, menu items, etc.)
3084 * this function activates them. Activation is what happens when you
3085 * press Enter on a widget during key navigation; clicking a button,
3086 * selecting a menu item, etc. If @widget isn't activatable,
3087 * the function returns %FALSE.
3089 * Return value: %TRUE if the widget was activatable
3092 gtk_widget_activate (GtkWidget *widget)
3094 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3096 if (WIDGET_CLASS (widget)->activate_signal)
3098 /* FIXME: we should eventually check the signals signature here */
3099 gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal);
3108 * gtk_widget_set_scroll_adjustments:
3109 * @widget: a #GtkWidget
3110 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3111 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3113 * For widgets that support scrolling, sets the scroll adjustments and
3114 * returns %TRUE. For widgets that don't support scrolling, does
3115 * nothing and returns %FALSE. Widgets that don't support scrolling
3116 * can be scrolled by placing them in a #GtkViewport, which does
3117 * support scrolling.
3119 * Return value: %TRUE if the widget supports scrolling
3122 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3123 GtkAdjustment *hadjustment,
3124 GtkAdjustment *vadjustment)
3126 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3128 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3130 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3132 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3134 /* FIXME: we should eventually check the signals signature here */
3135 gtk_signal_emit (GTK_OBJECT (widget),
3136 WIDGET_CLASS (widget)->set_scroll_adjustments_signal,
3137 hadjustment, vadjustment);
3144 /*****************************************
3145 * gtk_widget_reparent_container_child:
3146 * assistent function to gtk_widget_reparent
3151 *****************************************/
3154 gtk_widget_reparent_container_child (GtkWidget *widget,
3155 gpointer client_data)
3157 g_return_if_fail (GTK_IS_WIDGET (widget));
3158 g_return_if_fail (client_data != NULL);
3160 if (GTK_WIDGET_NO_WINDOW (widget))
3163 gdk_window_unref (widget->window);
3164 widget->window = (GdkWindow*) client_data;
3166 gdk_window_ref (widget->window);
3168 if (GTK_IS_CONTAINER (widget))
3169 gtk_container_forall (GTK_CONTAINER (widget),
3170 gtk_widget_reparent_container_child,
3174 gdk_window_reparent (widget->window,
3175 (GdkWindow*) client_data, 0, 0);
3179 * gtk_widget_reparent:
3180 * @widget: a #GtkWidget
3181 * @new_parent: a #GtkContainer to move the widget into
3183 * Moves a widget from one #GtkContainer to another, handling reference
3184 * count issues to avoid destroying the widget.
3188 gtk_widget_reparent (GtkWidget *widget,
3189 GtkWidget *new_parent)
3191 g_return_if_fail (GTK_IS_WIDGET (widget));
3192 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3193 g_return_if_fail (widget->parent != NULL);
3195 if (widget->parent != new_parent)
3197 /* First try to see if we can get away without unrealizing
3198 * the widget as we reparent it. if so we set a flag so
3199 * that gtk_widget_unparent doesn't unrealize widget
3201 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3202 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3204 gtk_widget_ref (widget);
3205 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3206 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3207 gtk_widget_unref (widget);
3209 if (GTK_WIDGET_IN_REPARENT (widget))
3211 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3213 gtk_widget_reparent_container_child (widget,
3214 gtk_widget_get_parent_window (widget));
3220 * gtk_widget_intersect:
3221 * @widget: a #GtkWidget
3222 * @area: a rectangle
3223 * @intersection: rectangle to store intersection of @widget and @area
3225 * Computes the intersection of a @widget's area and @area, storing
3226 * the intersection in @intersection, and returns %TRUE if there was
3227 * an intersection. @intersection may be %NULL if you're only
3228 * interested in whether there was an intersection.
3230 * Return value: %TRUE if there was an intersection
3233 gtk_widget_intersect (GtkWidget *widget,
3235 GdkRectangle *intersection)
3241 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3242 g_return_val_if_fail (area != NULL, FALSE);
3245 dest = intersection;
3249 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3251 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3253 intersection->x -= widget->allocation.x;
3254 intersection->y -= widget->allocation.y;
3261 * gtk_widget_region_intersect:
3262 * @widget: a #GtkWidget
3263 * @region: a #GdkRegion, in the same coordinate system as
3264 * @widget->allocation. That is, relative to @widget->window
3265 * for %NO_WINDOW widgets; relative to the parent window
3266 * of @widget->window for widgets with their own window.
3267 * @returns: A newly allocated region holding the intersection of @widget
3268 * and @region. The coordinates of the return value are
3269 * relative to @widget->window for %NO_WINDOW widgets, and
3270 * relative to the parent window of @widget->window for
3271 * widgets with their own window.
3273 * Computes the intersection of a @widget's area and @region, returning
3274 * the intersection. The result may be empty, use gdk_region_empty() to
3278 gtk_widget_region_intersect (GtkWidget *widget,
3283 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3284 g_return_val_if_fail (region != NULL, NULL);
3286 dest = gdk_region_rectangle (&widget->allocation);
3288 gdk_region_intersect (dest, region);
3294 * gtk_widget_grab_focus:
3295 * @widget: a #GtkWidget
3297 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3298 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3299 * something like #GtkFrame won't work. (More precisely, it must have the
3300 * %GTK_CAN_FOCUS flag set.)
3304 gtk_widget_grab_focus (GtkWidget *widget)
3306 g_return_if_fail (GTK_IS_WIDGET (widget));
3308 g_object_ref (G_OBJECT (widget));
3309 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]);
3310 g_object_notify (G_OBJECT (widget), "has_focus");
3311 g_object_unref (G_OBJECT (widget));
3315 reset_focus_recurse (GtkWidget *widget,
3318 if (GTK_IS_CONTAINER (widget))
3320 GtkContainer *container;
3322 container = GTK_CONTAINER (widget);
3323 gtk_container_set_focus_child (container, NULL);
3325 gtk_container_foreach (container,
3326 reset_focus_recurse,
3332 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3334 g_return_if_fail (GTK_IS_WIDGET (focus_widget));
3336 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3338 GtkWidget *toplevel;
3341 /* clear the current focus setting, break if the current widget
3342 * is the focus widget's parent, since containers above that will
3343 * be set by the next loop.
3345 toplevel = gtk_widget_get_toplevel (focus_widget);
3346 if (GTK_WIDGET_TOPLEVEL (toplevel))
3348 widget = GTK_WINDOW (toplevel)->focus_widget;
3350 if (widget == focus_widget)
3352 /* We call _gtk_window_internal_set_focus() here so that the
3353 * toplevel window can request the focus if necessary.
3354 * This is needed when the toplevel is a GtkPlug
3356 if (!GTK_WIDGET_HAS_FOCUS (widget))
3357 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3364 while (widget->parent && widget->parent != focus_widget->parent)
3366 widget = widget->parent;
3367 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3371 else if (toplevel != focus_widget)
3373 /* gtk_widget_grab_focus() operates on a tree without window...
3374 * actually, this is very questionable behaviour.
3377 gtk_container_foreach (GTK_CONTAINER (toplevel),
3378 reset_focus_recurse,
3382 /* now propagate the new focus up the widget tree and finally
3383 * set it on the window
3385 widget = focus_widget;
3386 while (widget->parent)
3388 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3389 widget = widget->parent;
3391 if (GTK_IS_WINDOW (widget))
3392 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3397 gtk_widget_real_show_help (GtkWidget *widget,
3398 GtkWidgetHelpType help_type)
3400 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3401 _gtk_tooltips_show_tip (widget);
3405 gtk_widget_real_focus (GtkWidget *widget,
3406 GtkDirectionType direction)
3408 if (!GTK_WIDGET_CAN_FOCUS (widget))
3411 if (!gtk_widget_is_focus (widget))
3413 gtk_widget_grab_focus (widget);
3421 * gtk_widget_is_focus:
3422 * @widget: a #GtkWidget
3424 * Determines if the widget is the focus widget within its
3425 * toplevel. (This does not mean that the %HAS_FOCUS flag is
3426 * necessarily set; %HAS_FOCUS will only be set if the
3427 * toplevel widget additionally has the global input focus.)
3429 * Return value: %TRUE if the widget is the focus widget.
3432 gtk_widget_is_focus (GtkWidget *widget)
3434 GtkWidget *toplevel;
3436 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3438 toplevel = gtk_widget_get_toplevel (widget);
3440 if (GTK_IS_WINDOW (toplevel))
3441 return widget == GTK_WINDOW (toplevel)->focus_widget;
3447 * gtk_widget_grab_default:
3448 * @widget: a #GtkWidget
3450 * Causes @widget to become the default widget. @widget must have the
3451 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
3452 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
3453 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
3454 * presses Enter in a window. Default widgets must be activatable,
3455 * that is, gtk_widget_activate() should affect them.
3459 gtk_widget_grab_default (GtkWidget *widget)
3463 g_return_if_fail (GTK_IS_WIDGET (widget));
3464 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3466 window = gtk_widget_get_toplevel (widget);
3468 if (window && GTK_WIDGET_TOPLEVEL (window))
3469 gtk_window_set_default (GTK_WINDOW (window), widget);
3471 g_warning (G_STRLOC ": widget not within a GtkWindow");
3475 * gtk_widget_set_name:
3476 * @widget: a #GtkWidget
3477 * @name: name for the widget
3479 * Widgets can be named, which allows you to refer to them from a
3480 * gtkrc file. You can apply a style to widgets with a particular name
3481 * in the gtkrc file. See the documentation for gtkrc files (on the
3482 * same page as the docs for #GtkRcStyle).
3486 gtk_widget_set_name (GtkWidget *widget,
3489 g_return_if_fail (GTK_IS_WIDGET (widget));
3492 g_free (widget->name);
3493 widget->name = g_strdup (name);
3495 if (GTK_WIDGET_RC_STYLE (widget))
3496 gtk_widget_reset_rc_style (widget);
3498 g_object_notify (G_OBJECT (widget), "name");
3502 * gtk_widget_get_name:
3503 * @widget: a #GtkWidget
3505 * Retrieves the name of a widget. The return value should not be
3506 * freed. See gtk_widget_set_name() for the significance of widget
3509 * Return value: name of the widget
3511 G_CONST_RETURN gchar*
3512 gtk_widget_get_name (GtkWidget *widget)
3514 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3517 return widget->name;
3518 return gtk_type_name (GTK_WIDGET_TYPE (widget));
3522 * gtk_widget_set_state:
3523 * @widget: a #GtkWidget
3524 * @state: new state for @widget
3526 * This function is for use in widget implementations. Sets the state
3527 * of a widget (insensitive, prelighted, etc.) Usually you should set
3528 * the state using wrapper functions such as gtk_widget_set_sensitive().
3532 gtk_widget_set_state (GtkWidget *widget,
3535 g_return_if_fail (GTK_IS_WIDGET (widget));
3537 if (state == GTK_WIDGET_STATE (widget))
3540 if (state == GTK_STATE_INSENSITIVE)
3541 gtk_widget_set_sensitive (widget, FALSE);
3547 data.state_restoration = FALSE;
3548 data.use_forall = FALSE;
3550 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3552 data.parent_sensitive = TRUE;
3554 gtk_widget_propagate_state (widget, &data);
3556 if (GTK_WIDGET_DRAWABLE (widget))
3557 gtk_widget_queue_clear (widget);
3562 gtk_widget_set_app_paintable (GtkWidget *widget,
3563 gboolean app_paintable)
3565 g_return_if_fail (GTK_IS_WIDGET (widget));
3567 app_paintable = (app_paintable != FALSE);
3569 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
3572 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
3574 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
3576 if (GTK_WIDGET_DRAWABLE (widget))
3577 gtk_widget_queue_clear (widget);
3579 g_object_notify (G_OBJECT (widget), "app_paintable");
3584 * gtk_widget_set_double_buffered:
3585 * @widget: a #GtkWidget
3586 * @double_buffered: %TRUE to double-buffer a widget
3588 * Widgets are double buffered by default; you can use this function
3589 * to turn off the buffering. "Double buffered" simply means that
3590 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
3591 * automatically around expose events sent to the
3592 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
3593 * window to an offscreen buffer, and gdk_window_end_paint() draws the
3594 * buffer to the screen. The result is that users see the window
3595 * update in one smooth step, and don't see individual graphics
3596 * primitives being rendered.
3598 * In very simple terms, double buffered widgets don't flicker,
3599 * so you would only use this function to turn off double buffering
3600 * if you had special needs and really knew what you were doing.
3604 gtk_widget_set_double_buffered (GtkWidget *widget,
3605 gboolean double_buffered)
3607 g_return_if_fail (GTK_IS_WIDGET (widget));
3609 if (double_buffered)
3610 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3612 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3616 * gtk_widget_set_redraw_on_allocate:
3617 * @widget: a #GtkWidget
3618 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
3619 * when it is allocated to a new size. Otherwise, only the
3620 * new portion of the widget will be redrawn.
3622 * Sets whether a when a widgets size allocation changes, the entire
3623 * widget is queued for drawing. By default, this setting is %TRUE and
3624 * the entire widget is redrawn on every size change. If your widget
3625 * leaves the upper left are unchanged when made bigger, turning this
3626 * setting on will improve performance.
3628 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
3629 * off all allocation on resizing: the widget will not even redraw if
3630 * its position changes; this is to allow containers that don't draw
3631 * anything to avoid excess invalidations. If you set this flag on a
3632 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
3633 * you are responsible for invalidating both the old and new allocation
3634 * of the widget when the widget is moved and responsible for invalidating
3635 * regions newly when the widget increases size.
3638 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
3639 gboolean redraw_on_allocate)
3641 g_return_if_fail (GTK_IS_WIDGET (widget));
3643 if (redraw_on_allocate)
3644 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3646 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3650 * gtk_widget_set_sensitive:
3651 * @widget: a #GtkWidget
3652 * @sensitive: %TRUE to make the widget sensitive
3654 * Sets the sensitivity of a widget. A widget is sensitive if the user
3655 * can interact with it. Insensitive widgets are "grayed out" and the
3656 * user can't interact with them. Insensitive widgets are known as
3657 * "inactive", "disabled", or "ghosted" in some other toolkits.
3661 gtk_widget_set_sensitive (GtkWidget *widget,
3666 g_return_if_fail (GTK_IS_WIDGET (widget));
3668 sensitive = (sensitive != FALSE);
3670 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
3675 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
3676 data.state = GTK_WIDGET_SAVED_STATE (widget);
3680 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
3681 data.state = GTK_WIDGET_STATE (widget);
3683 data.state_restoration = TRUE;
3684 data.use_forall = TRUE;
3687 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3689 data.parent_sensitive = TRUE;
3691 gtk_widget_propagate_state (widget, &data);
3692 if (GTK_WIDGET_DRAWABLE (widget))
3693 gtk_widget_queue_clear (widget);
3695 g_object_notify (G_OBJECT (widget), "sensitive");
3699 * gtk_widget_set_parent:
3700 * @widget: a #GtkWidget
3701 * @parent: parent container
3703 * This function is useful only when implementing subclasses of #GtkContainer.
3704 * Sets the container as the parent of @widget, and takes care of
3705 * some details such as updating the state and style of the child
3706 * to reflect its new location. The opposite function is
3707 * gtk_widget_unparent().
3711 gtk_widget_set_parent (GtkWidget *widget,
3716 g_return_if_fail (GTK_IS_WIDGET (widget));
3717 g_return_if_fail (widget->parent == NULL);
3718 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
3719 g_return_if_fail (GTK_IS_WIDGET (parent));
3720 g_return_if_fail (widget != parent);
3722 /* keep this function in sync with gtk_menu_attach_to_widget()
3725 gtk_widget_ref (widget);
3726 gtk_object_sink (GTK_OBJECT (widget));
3727 widget->parent = parent;
3729 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
3730 data.state = GTK_WIDGET_STATE (parent);
3732 data.state = GTK_WIDGET_STATE (widget);
3733 data.state_restoration = FALSE;
3734 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
3735 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
3737 gtk_widget_propagate_state (widget, &data);
3739 gtk_widget_set_style_recurse (widget, NULL);
3741 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], NULL);
3742 if (GTK_WIDGET_ANCHORED (widget->parent))
3743 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
3744 g_object_notify (G_OBJECT (widget), "parent");
3746 /* Enforce realized/mapped invariants
3748 if (GTK_WIDGET_REALIZED (widget->parent))
3749 gtk_widget_realize (widget);
3751 if (GTK_WIDGET_VISIBLE (widget->parent) &&
3752 GTK_WIDGET_VISIBLE (widget))
3754 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
3755 GTK_WIDGET_MAPPED (widget->parent))
3756 gtk_widget_map (widget);
3758 gtk_widget_queue_resize (widget);
3763 * gtk_widget_get_parent:
3764 * @widget: a #GtkWidget
3766 * Returns the parent container of @widget.
3768 * Return value: the parent container of @widget, or %NULL
3771 gtk_widget_get_parent (GtkWidget *widget)
3773 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3775 return widget->parent;
3778 /*****************************************
3780 * see docs/styles.txt
3781 *****************************************/
3784 * gtk_widget_set_style:
3785 * @widget: a #GtkWidget
3786 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
3787 * gtk_widget_set_style() and go back to the default style
3789 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
3790 * want to use this function; it interacts badly with themes, because
3791 * themes work by replacing the #GtkStyle. Instead, use
3792 * gtk_widget_modify_style().
3796 gtk_widget_set_style (GtkWidget *widget,
3799 g_return_if_fail (GTK_IS_WIDGET (widget));
3803 gboolean initial_emission;
3805 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3807 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
3808 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
3810 gtk_widget_set_style_internal (widget, style, initial_emission);
3814 if (GTK_WIDGET_USER_STYLE (widget))
3815 gtk_widget_reset_rc_style (widget);
3820 * gtk_widget_ensure_style:
3821 * @widget: a #GtkWidget
3823 * Ensures that @widget has a style (@widget->style). Not a very useful
3824 * function; most of the time, if you want the style, the widget is
3825 * realized, and realized widgets are guaranteed to have a style
3830 gtk_widget_ensure_style (GtkWidget *widget)
3832 g_return_if_fail (GTK_IS_WIDGET (widget));
3834 if (!GTK_WIDGET_USER_STYLE (widget) &&
3835 !GTK_WIDGET_RC_STYLE (widget))
3836 gtk_widget_reset_rc_style (widget);
3839 /* Look up the RC style for this widget, unsetting any user style that
3840 * may be in effect currently
3843 gtk_widget_reset_rc_style (GtkWidget *widget)
3845 GtkStyle *new_style;
3846 gboolean initial_emission;
3848 g_return_if_fail (GTK_IS_WIDGET (widget));
3850 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3852 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3853 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
3855 new_style = gtk_rc_get_style (widget);
3857 new_style = gtk_widget_get_default_style ();
3859 if (initial_emission || new_style != widget->style)
3860 gtk_widget_set_style_internal (widget, new_style, initial_emission);
3864 * gtk_widget_get_style:
3865 * @widget: a #GtkWidget
3867 * Simply an accessor function that returns @widget->style.
3869 * Return value: the widget's #GtkStyle
3872 gtk_widget_get_style (GtkWidget *widget)
3874 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3876 return widget->style;
3880 * gtk_widget_modify_style:
3881 * @widget: a #GtkWidget
3882 * @style: the #GtkRcStyle holding the style modifications
3884 * Modifies style values on the widget. Modifications made using this
3885 * technique take precedence over style values set via an RC file,
3886 * however, they will be overriden if a style is explicitely set on
3887 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
3888 * is designed so each field can either be set or unset, so it is
3889 * possible, using this function, to modify some style values and
3890 * leave the others unchanged.
3892 * Note that modifications made with this function are not cumulative
3893 * with previous calls to gtk_widget_modify_style() or with such
3894 * functions as gtk_widget_modify_fg(). If you wish to retain
3895 * previous values, you must first call gtk_widget_get_modifier_style(),
3896 * make your modifications to the returned style, then call
3897 * gtk_widget_modify_style() with that style. On the other hand,
3898 * if you first call gtk_widget_modify_style(), subsequent calls
3899 * to such functions gtk_widget_modify_fg() will have a cumulative
3900 * effect with the initial modifications.
3903 gtk_widget_modify_style (GtkWidget *widget,
3906 GtkRcStyle *old_style;
3908 g_return_if_fail (GTK_IS_RC_STYLE (style));
3910 old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3913 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3915 gtk_rc_style_copy (style),
3916 (GtkDestroyNotify)gtk_rc_style_unref);
3918 /* note that "style" may be invalid here if it was the old
3919 * modifier style and the only reference was our own.
3922 if (GTK_WIDGET_RC_STYLE (widget))
3923 gtk_widget_reset_rc_style (widget);
3927 * gtk_widget_get_modifier_style:
3928 * @widget: a #GtkWidget
3930 * Returns the current modifier style for the widget. (As set by
3931 * gtk_widget_modify_style().) If no style has previously set, a new
3932 * #GtkRcStyle will be created with all values unset, and set as the
3933 * modifier style for the widget. If you make changes to this rc
3934 * style, you must call gtk_widget_modify_style(), passing in the
3935 * returned rc style, to make sure that your changes take effect.
3937 * Caution: passing the style back to gtk_widget_modify_style() will
3938 * normally end up destroying it, because gtk_widget_modify_style() copies
3939 * the passed-in style and sets the copy as the new modifier style,
3940 * thus dropping any reference to the old modifier style. Add a reference
3941 * to the modifier style if you want to keep it alive.
3943 * Return value: the modifier style for the widget. This rc style is
3944 * owned by the widget. If you want to keep a pointer to value this
3945 * around, you must add a refcount using gtk_rc_style_ref().
3948 gtk_widget_get_modifier_style (GtkWidget *widget)
3950 GtkRcStyle *rc_style;
3952 rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3957 rc_style = gtk_rc_style_new ();
3958 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3961 (GtkDestroyNotify)gtk_rc_style_unref);
3968 gtk_widget_modify_color_component (GtkWidget *widget,
3969 GtkRcFlags component,
3973 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
3978 rc_style->fg[state] = *color;
3981 rc_style->bg[state] = *color;
3984 rc_style->text[state] = *color;
3987 rc_style->base[state] = *color;
3990 g_assert_not_reached();
3993 rc_style->color_flags[state] |= component;
3995 gtk_widget_modify_style (widget, rc_style);
3999 * gtk_widget_modify_fg:
4000 * @widget: a #GtkWidget.
4001 * @state: the state for which to set the foreground color.
4002 * @color: the color to assign (does not need to be allocated).
4004 * Sets the foreground color for a widget in a particular state. All
4005 * other style values are left untouched. See also
4006 * gtk_widget_modify_style().
4009 gtk_widget_modify_fg (GtkWidget *widget,
4013 g_return_if_fail (GTK_IS_WIDGET (widget));
4014 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4015 g_return_if_fail (color != NULL);
4017 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4021 * gtk_widget_modify_bg:
4022 * @widget: a #GtkWidget.
4023 * @state: the state for which to set the background color.
4024 * @color: the color to assign (does not need to be allocated).
4026 * Sets the background color for a widget in a particular state. All
4027 * other style values are left untouched. See also
4028 * gtk_widget_modify_style().
4031 gtk_widget_modify_bg (GtkWidget *widget,
4035 g_return_if_fail (GTK_IS_WIDGET (widget));
4036 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4037 g_return_if_fail (color != NULL);
4039 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4043 * gtk_widget_modify_text:
4044 * @widget: a #GtkWidget.
4045 * @state: the state for which to set the text color.
4046 * @color: the color to assign (does not need to be allocated).
4048 * Sets the text color for a widget in a particular state. All other
4049 * style values are left untouched. The text color is the foreground
4050 * color used along with the base color (see gtk_widget_modify_base())
4051 * for widgets such as #GtkEntry and #GtkTextView. See also
4052 * gtk_widget_modify_style().
4055 gtk_widget_modify_text (GtkWidget *widget,
4059 g_return_if_fail (GTK_IS_WIDGET (widget));
4060 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4061 g_return_if_fail (color != NULL);
4063 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4067 * gtk_widget_modify_base:
4068 * @widget: a #GtkWidget.
4069 * @state: the state for which to set the base color.
4070 * @color: the color to assign (does not need to be allocated).
4072 * Sets the base color for a widget in a particular state.
4073 * All other style values are left untouched. The base color
4074 * is the background color used along with the text color
4075 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4076 * and #GtkTextView. See also gtk_widget_modify_style().
4079 gtk_widget_modify_base (GtkWidget *widget,
4083 g_return_if_fail (GTK_IS_WIDGET (widget));
4084 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4085 g_return_if_fail (color != NULL);
4087 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4091 * gtk_widget_modify_font:
4092 * @widget: a #GtkWidget
4093 * @font_desc: the font description to use
4095 * Sets the font to use for a widget. All other style values are left
4096 * untouched. See also gtk_widget_modify_style().
4099 gtk_widget_modify_font (GtkWidget *widget,
4100 PangoFontDescription *font_desc)
4102 GtkRcStyle *rc_style;
4104 g_return_if_fail (GTK_IS_WIDGET (widget));
4105 g_return_if_fail (font_desc != NULL);
4107 rc_style = gtk_widget_get_modifier_style (widget);
4109 if (rc_style->font_desc)
4110 pango_font_description_free (rc_style->font_desc);
4112 rc_style->font_desc = pango_font_description_copy (font_desc);
4114 gtk_widget_modify_style (widget, rc_style);
4118 gtk_widget_direction_changed (GtkWidget *widget,
4119 GtkTextDirection previous_direction)
4121 gtk_widget_queue_resize (widget);
4125 gtk_widget_style_set (GtkWidget *widget,
4126 GtkStyle *previous_style)
4128 if (GTK_WIDGET_REALIZED (widget) &&
4129 !GTK_WIDGET_NO_WINDOW (widget))
4130 gtk_style_set_background (widget->style, widget->window, widget->state);
4134 gtk_widget_set_style_internal (GtkWidget *widget,
4136 gboolean initial_emission)
4138 g_return_if_fail (GTK_IS_WIDGET (widget));
4139 g_return_if_fail (style != NULL);
4141 g_object_ref (G_OBJECT (widget));
4142 g_object_freeze_notify (G_OBJECT (widget));
4144 if (widget->style != style || initial_emission)
4146 PangoContext *context = gtk_widget_peek_pango_context (widget);
4148 pango_context_set_font_description (context, style->font_desc);
4151 if (widget->style != style)
4153 GtkStyle *previous_style;
4155 if (GTK_WIDGET_REALIZED (widget))
4157 gtk_widget_reset_shapes (widget);
4158 gtk_style_detach (widget->style);
4161 previous_style = widget->style;
4162 widget->style = style;
4163 g_object_ref (widget->style);
4165 if (GTK_WIDGET_REALIZED (widget))
4166 widget->style = gtk_style_attach (widget->style, widget->window);
4168 gtk_signal_emit (GTK_OBJECT (widget),
4169 widget_signals[STYLE_SET],
4170 initial_emission ? NULL : previous_style);
4171 g_object_unref (previous_style);
4173 if (widget->parent && !initial_emission)
4174 gtk_widget_queue_resize (widget);
4176 else if (initial_emission)
4177 gtk_signal_emit (GTK_OBJECT (widget),
4178 widget_signals[STYLE_SET],
4180 g_object_notify (G_OBJECT (widget), "style");
4181 g_object_thaw_notify (G_OBJECT (widget));
4182 g_object_unref (G_OBJECT (widget));
4186 gtk_widget_set_style_recurse (GtkWidget *widget,
4187 gpointer client_data)
4189 if (GTK_WIDGET_RC_STYLE (widget))
4190 gtk_widget_reset_rc_style (widget);
4192 if (GTK_IS_CONTAINER (widget))
4193 gtk_container_forall (GTK_CONTAINER (widget),
4194 gtk_widget_set_style_recurse,
4199 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4200 gpointer client_data)
4202 gboolean new_anchored;
4204 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4205 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4207 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4209 gtk_widget_ref (widget);
4212 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4214 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4216 g_signal_emit (GTK_OBJECT (widget), widget_signals[HIERARCHY_CHANGED],
4219 if (GTK_IS_CONTAINER (widget))
4220 gtk_container_forall (GTK_CONTAINER (widget),
4221 gtk_widget_propagate_hierarchy_changed_recurse,
4224 gtk_widget_unref (widget);
4229 * _gtk_widget_propagate_hierarchy_changed:
4230 * @widget: a #GtkWidget
4231 * @previous_toplevel: Previous toplevel
4233 * Propagates changes in the anchored state to a widget and all
4234 * children, unsetting or setting the %ANCHORED flag, and
4235 * emitting ::hierarchy_changed.
4238 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4239 GtkWidget *previous_toplevel)
4241 if (previous_toplevel)
4242 g_object_ref (previous_toplevel);
4244 gtk_widget_propagate_hierarchy_changed_recurse (widget, previous_toplevel);
4246 if (previous_toplevel)
4247 g_object_unref (previous_toplevel);
4251 gtk_widget_reset_rc_styles (GtkWidget *widget)
4253 g_return_if_fail (GTK_IS_WIDGET (widget));
4255 gtk_widget_set_style_recurse (widget, NULL);
4259 * gtk_widget_get_default_style:
4261 * Returns the default style used by all widgets initially.
4263 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4264 * should not be modified or freed.
4267 gtk_widget_get_default_style (void)
4269 if (!gtk_default_style)
4271 gtk_default_style = gtk_style_new ();
4272 g_object_ref (gtk_default_style);
4275 return gtk_default_style;
4278 static PangoContext *
4279 gtk_widget_peek_pango_context (GtkWidget *widget)
4281 return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
4285 * gtk_widget_get_pango_context:
4286 * @widget: a #GtkWidget
4288 * Gets a #PangoContext with the appropriate colormap, font description
4289 * and base direction for this widget. Unlike the context returned
4290 * by gtk_widget_create_pango_context(), this context is owned by
4291 * the widget (it can be used as long as widget exists), and will
4292 * be updated to match any changes to the widget's attributes.
4294 * If you create and keep a #PangoLayout using this context, you must
4295 * deal with changes to the context by calling pango_layout_context_changed()
4296 * on the layout in response to the ::style_set and ::direction_set signals
4299 * Return value: the #PangoContext for the widget.
4302 gtk_widget_get_pango_context (GtkWidget *widget)
4304 PangoContext *context;
4306 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4308 context = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
4311 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4312 gtk_object_set_data_by_id_full (GTK_OBJECT (widget), quark_pango_context, context,
4313 (GDestroyNotify) g_object_unref);
4320 * gtk_widget_create_pango_context:
4321 * @widget: a #GtkWidget
4323 * Creates a new #PangoContext with the appropriate colormap,
4324 * font description, and base direction for drawing text for
4325 * this widget. See also gtk_widget_get_pango_context().
4327 * Return value: the new #PangoContext
4330 gtk_widget_create_pango_context (GtkWidget *widget)
4332 PangoContext *context;
4334 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4336 context = gdk_pango_context_get ();
4338 gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
4339 pango_context_set_base_dir (context,
4340 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
4341 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
4342 pango_context_set_font_description (context, widget->style->font_desc);
4343 pango_context_set_language (context, gtk_get_default_language ());
4349 * gtk_widget_create_pango_layout:
4350 * @widget: a #GtkWidget
4351 * @text: text to set on the layout (can be %NULL)
4353 * Creates a new #PangoLayout with the appropriate colormap,
4354 * font description, and base direction for drawing text for
4357 * If you keep a #PangoLayout created in this way around, in order
4358 * notify the layout of changes to the base direction or font of this
4359 * widget, you must call pango_layout_context_changed() in response to
4360 * the ::style_set and ::direction_set signals for the widget.
4362 * Return value: the new #PangoLayout
4365 gtk_widget_create_pango_layout (GtkWidget *widget,
4368 PangoLayout *layout;
4369 PangoContext *context;
4371 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4373 context = gtk_widget_get_pango_context (widget);
4374 layout = pango_layout_new (context);
4377 pango_layout_set_text (layout, text, -1);
4383 * gtk_widget_render_icon:
4384 * @widget: a #GtkWidget
4385 * @stock_id: a stock ID
4386 * @size: a stock size
4387 * @detail: render detail to pass to theme engine
4389 * A convenience function that uses the theme engine and RC file
4390 * settings for @widget to look up @stock_id and render it to
4391 * a pixbuf. @stock_id should be a stock icon ID such as
4392 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
4393 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
4394 * identifies the widget or code doing the rendering, so that
4395 * theme engines can special-case rendering for that widget or code.
4397 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
4400 gtk_widget_render_icon (GtkWidget *widget,
4401 const gchar *stock_id,
4403 const gchar *detail)
4405 GtkIconSet *icon_set;
4408 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4409 g_return_val_if_fail (stock_id != NULL, NULL);
4410 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
4412 gtk_widget_ensure_style (widget);
4414 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
4416 if (icon_set == NULL)
4419 retval = gtk_icon_set_render_icon (icon_set,
4421 gtk_widget_get_direction (widget),
4422 GTK_WIDGET_STATE (widget),
4431 * gtk_widget_set_parent_window:
4432 * @widget: a #GtkWidget.
4433 * @parent_window: the new parent window.
4435 * Sets a non default parent window for @widget.
4438 gtk_widget_set_parent_window (GtkWidget *widget,
4439 GdkWindow *parent_window)
4441 GdkWindow *old_parent_window;
4443 g_return_if_fail (GTK_IS_WIDGET (widget));
4445 old_parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4446 quark_parent_window);
4448 if (parent_window != old_parent_window)
4450 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_parent_window,
4452 if (old_parent_window)
4453 gdk_window_unref (old_parent_window);
4455 gdk_window_ref (parent_window);
4461 * gtk_widget_set_child_visible:
4462 * @widget: a #GtkWidget
4463 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
4465 * Sets whether @widget should be mapped along with its when its parent
4466 * is mapped and @widget has been shown with gtk_widget_show().
4468 * The child visibility can be set for widget before it is added to
4469 * a container with gtk_widget_set_parent(), to avoid mapping
4470 * children unnecessary before immediately unmapping them. However
4471 * it will be reset to its default state of %TRUE when the widget
4472 * is removed from a container.
4474 * Note that changing the child visibility of a widget does not
4475 * queue a resize on the widget. Most of the time, the size of
4476 * a widget is computed from all visible children, whether or
4477 * not they are mapped. If this is not the case, the container
4478 * can queue a resize itself.
4480 * This function is only useful for container implementations and
4481 * never should be called by an application.
4484 gtk_widget_set_child_visible (GtkWidget *widget,
4485 gboolean is_visible)
4487 g_return_if_fail (GTK_IS_WIDGET (widget));
4488 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
4491 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
4493 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
4494 if (GTK_WIDGET_REALIZED (widget->parent))
4496 if (GTK_WIDGET_MAPPED (widget->parent) &&
4497 GTK_WIDGET_CHILD_VISIBLE (widget) &&
4498 GTK_WIDGET_VISIBLE (widget))
4499 gtk_widget_map (widget);
4501 gtk_widget_unmap (widget);
4506 * gtk_widget_get_child_visible:
4507 * @widget: a #GtkWidget
4509 * Gets the value set with gtk_widget_set_child_visible().
4510 * If you feel a need to use this function, your code probably
4511 * needs reorganization.
4513 * This function is only useful for container implementations and
4514 * never should be called by an application.
4516 * Return value: %TRUE if the widget is mapped with the parent.
4519 gtk_widget_get_child_visible (GtkWidget *widget)
4521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4523 return GTK_WIDGET_CHILD_VISIBLE (widget);
4527 * gtk_widget_get_parent_window:
4528 * @widget: a #GtkWidget.
4529 * @returns: the parent window of @widget.
4531 * Gets @widget's parent window.
4534 gtk_widget_get_parent_window (GtkWidget *widget)
4536 GdkWindow *parent_window;
4538 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4539 g_return_val_if_fail (widget->parent != NULL, NULL);
4541 parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4542 quark_parent_window);
4544 return (parent_window != NULL) ? parent_window : widget->parent->window;
4548 * gtk_widget_child_focus:
4549 * @widget: a #GtkWidget
4550 * @direction: direction of focus movement
4552 * This function is used by custom widget implementations; if you're
4553 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
4554 * to a particular widget, and gtk_container_set_focus_chain() to
4555 * change the focus tab order. So you may want to investigate those
4556 * functions instead.
4558 * gtk_widget_child_focus() is called by containers as the user moves
4559 * around the window using keyboard shortcuts. @direction indicates
4560 * what kind of motion is taking place (up, down, left, right, tab
4561 * forward, tab backward). gtk_widget_child_focus() invokes the
4562 * "focus" signal on #GtkWidget; widgets override the default handler
4563 * for this signal in order to implement appropriate focus behavior.
4565 * The "focus" default handler for a widget should return %TRUE if
4566 * moving in @direction left the focus on a focusable location inside
4567 * that widget, and %FALSE if moving in @direction moved the focus
4568 * outside the widget. If returning %TRUE, widgets normally
4569 * call gtk_widget_grab_focus() to place the focus accordingly;
4570 * if returning %FALSE, they don't modify the current focus location.
4572 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
4573 * necessary to check that the child was visible, sensitive, and
4574 * focusable before calling
4575 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
4576 * the widget is not currently in a focusable state, so there's no
4577 * need for those checks.
4579 * Return value: %TRUE if focus ended up inside @widget
4582 gtk_widget_child_focus (GtkWidget *widget,
4583 GtkDirectionType direction)
4585 gboolean return_val;
4587 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4589 if (!GTK_WIDGET_VISIBLE (widget) ||
4590 !GTK_WIDGET_IS_SENSITIVE (widget))
4593 /* child widgets must set CAN_FOCUS, containers
4594 * don't have to though.
4596 if (!GTK_IS_CONTAINER (widget) &&
4597 !GTK_WIDGET_CAN_FOCUS (widget))
4600 gtk_signal_emit (GTK_OBJECT (widget),
4601 widget_signals[FOCUS],
4602 direction, &return_val);
4608 * gtk_widget_set_uposition:
4609 * @widget: a #GtkWidget
4610 * @x: x position; -1 to unset x; -2 to leave x unchanged
4611 * @y: y position; -1 to unset y; -2 to leave y unchanged
4614 * Sets the position of a widget. The funny "u" in the name comes from
4615 * the "user position" hint specified by the X Window System, and
4616 * exists for legacy reasons. This function doesn't work if a widget
4617 * is inside a container; it's only really useful on #GtkWindow.
4619 * Don't use this function to center dialogs over the main application
4620 * window; most window managers will do the centering on your behalf
4621 * if you call gtk_window_set_transient_for(), and it's really not
4622 * possible to get the centering to work correctly in all cases from
4623 * application code. But if you insist, use gtk_window_set_position()
4624 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
4627 * Note that although @x and @y can be individually unset, the position
4628 * is not honoured unless both @x and @y are set.
4631 gtk_widget_set_uposition (GtkWidget *widget,
4635 /* FIXME this function is the only place that aux_info->x and
4636 * aux_info->y are even used I believe, and this function is
4637 * deprecated. Should be cleaned up.
4640 GtkWidgetAuxInfo *aux_info;
4642 g_return_if_fail (GTK_IS_WIDGET (widget));
4644 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4649 aux_info->x_set = FALSE;
4652 aux_info->x_set = TRUE;
4660 aux_info->y_set = FALSE;
4663 aux_info->y_set = TRUE;
4668 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
4669 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
4671 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
4672 gtk_widget_size_allocate (widget, &widget->allocation);
4676 * gtk_widget_set_usize:
4677 * @widget: a #GtkWidget
4678 * @width: minimum width, or -1 to unset
4679 * @height: minimum height, or -1 to unset
4681 * This function is deprecated; use gtk_widget_set_size_request()
4684 * Sets the minimum size of a widget; that is, the widget's size
4685 * request will be @width by @height. You can use this function to
4686 * force a widget to be either larger or smaller than it is. The
4687 * strange "usize" name dates from the early days of GTK+, and derives
4688 * from X Window System terminology. In many cases,
4689 * gtk_window_set_default_size() is a better choice for toplevel
4690 * windows than this function; setting the default size will still
4691 * allow users to shrink the window. Setting the usize will force them
4692 * to leave the window at least as large as the usize. When dealing
4693 * with window sizes, gtk_window_set_geometry_hints() can be a useful
4696 * Note the inherent danger of setting any fixed size - themes,
4697 * translations into other languages, different fonts, and user action
4698 * can all change the appropriate size for a given widget. So, it's
4699 * basically impossible to hardcode a size that will always be
4704 gtk_widget_set_usize (GtkWidget *widget,
4708 GtkWidgetAuxInfo *aux_info;
4710 g_return_if_fail (GTK_IS_WIDGET (widget));
4712 g_object_freeze_notify (G_OBJECT (widget));
4714 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4718 g_object_notify (G_OBJECT (widget), "width_request");
4719 aux_info->width = width;
4723 g_object_notify (G_OBJECT (widget), "height_request");
4724 aux_info->height = height;
4727 if (GTK_WIDGET_VISIBLE (widget))
4728 gtk_widget_queue_resize (widget);
4730 g_object_thaw_notify (G_OBJECT (widget));
4734 * gtk_widget_set_size_request:
4735 * @widget: a #GtkWidget
4736 * @width: width @widget should request, or -1 to unset
4737 * @height: height @widget should request, or -1 to unset
4739 * Sets the minimum size of a widget; that is, the widget's size
4740 * request will be @width by @height. You can use this function to
4741 * force a widget to be either larger or smaller than it normally
4744 * In most cases, gtk_window_set_default_size() is a better choice for
4745 * toplevel windows than this function; setting the default size will
4746 * still allow users to shrink the window. Setting the size request
4747 * will force them to leave the window at least as large as the size
4748 * request. When dealing with window sizes,
4749 * gtk_window_set_geometry_hints() can be a useful function as well.
4751 * Note the inherent danger of setting any fixed size - themes,
4752 * translations into other languages, different fonts, and user action
4753 * can all change the appropriate size for a given widget. So, it's
4754 * basically impossible to hardcode a size that will always be
4757 * The size request of a widget is the smallest size a widget can
4758 * accept while still functioning well and drawing itself correctly.
4759 * However in some strange cases a widget may be allocated less than
4760 * its requested size, and in many cases a widget may be allocated more
4761 * space than it requested.
4763 * If the size request in a given direction is -1 (unset), then
4764 * the "natural" size request of the widget will be used instead.
4766 * Widgets can't actually be allocated a size less than 1 by 1, but
4767 * you can pass 0,0 to this function to mean "as small as possible."
4770 gtk_widget_set_size_request (GtkWidget *widget,
4774 g_return_if_fail (GTK_IS_WIDGET (widget));
4775 g_return_if_fail (width >= -1);
4776 g_return_if_fail (height >= -1);
4783 gtk_widget_set_usize (widget, width, height);
4788 * gtk_widget_get_size_request:
4789 * @widget: a #GtkWidget
4790 * @width: return location for width, or %NULL
4791 * @height: return location for height, or %NULL
4793 * Gets the size request that was explicitly set for the widget using
4794 * gtk_widget_set_size_request(). A value of -1 stored in @width or
4795 * @height indicates that that dimension has not been set explicitly
4796 * and the natural requisition of the widget will be used intead. See
4797 * gtk_widget_set_size_request(). To get the size a widget will
4798 * actually use, call gtk_widget_size_request() instead of
4804 gtk_widget_get_size_request (GtkWidget *widget,
4808 GtkWidgetAuxInfo *aux_info;
4810 g_return_if_fail (GTK_IS_WIDGET (widget));
4812 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
4815 *width = aux_info ? aux_info->width : -1;
4818 *height = aux_info ? aux_info->height : -1;
4822 * gtk_widget_set_events:
4823 * @widget: a #GtkWidget
4824 * @events: event mask
4826 * Sets the event mask (see #GdkEventMask) for a widget. The event
4827 * mask determines which events a widget will receive. Keep in mind
4828 * that different widgets have different default event masks, and by
4829 * changing the event mask you may disrupt a widget's functionality,
4830 * so be careful. This function must be called while a widget is
4831 * unrealized. Consider gtk_widget_add_events() for widgets that are
4832 * already realized, or if you want to preserve the existing event
4833 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
4834 * to get events on those widgets, place them inside a #GtkEventBox
4835 * and receive events on the event box.
4839 gtk_widget_set_events (GtkWidget *widget,
4844 g_return_if_fail (GTK_IS_WIDGET (widget));
4845 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4847 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4852 eventp = g_new (gint, 1);
4855 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4860 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4863 g_object_notify (G_OBJECT (widget), "events");
4867 * gtk_widget_add_events:
4868 * @widget: a #GtkWidget
4869 * @events: an event mask, see #GdkEventMask
4871 * Adds the events in the bitfield @events to the event mask for
4872 * @widget. See gtk_widget_set_events() for details.
4876 gtk_widget_add_events (GtkWidget *widget,
4881 g_return_if_fail (GTK_IS_WIDGET (widget));
4883 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4889 eventp = g_new (gint, 1);
4894 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4899 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4902 if (GTK_WIDGET_REALIZED (widget))
4904 if (GTK_WIDGET_NO_WINDOW (widget))
4906 GList *children = gdk_window_get_children (widget->window);
4907 GList *tmp_list = children;
4911 GdkWindow *window = tmp_list->data;
4914 gdk_window_get_user_data (window, &user_data);
4915 if (user_data == widget)
4916 gdk_window_set_events (window, gdk_window_get_events (window) | events);
4919 g_list_free (children);
4923 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
4927 g_object_notify (G_OBJECT (widget), "events");
4931 * gtk_widget_set_extension_events:
4932 * @widget: a #GtkWidget
4933 * @mode: bitfield of extension events to receive
4935 * Sets the extension events mask to @mode. See #GdkExtensionMode
4936 * and gdk_input_set_extension_events().
4940 gtk_widget_set_extension_events (GtkWidget *widget,
4941 GdkExtensionMode mode)
4943 GdkExtensionMode *modep;
4945 g_return_if_fail (GTK_IS_WIDGET (widget));
4947 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4950 modep = g_new (GdkExtensionMode, 1);
4953 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode, modep);
4954 g_object_notify (G_OBJECT (widget), "extension_events");
4958 * gtk_widget_get_toplevel:
4959 * @widget: a #GtkWidget
4961 * This function returns the topmost widget in the container hierarchy
4962 * @widget is a part of. If @widget has no parent widgets, it will be
4963 * returned as the topmost widget. No reference will be added to the
4964 * returned widget; it should not be unreferenced.
4966 * Note the difference in behavior vs. gtk_widget_get_ancestor();
4967 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
4969 * %NULL if @widget wasn't inside a toplevel window, and if the
4970 * window was inside a #GtkWindow-derived widget which was in turn
4971 * inside the toplevel #GtkWindow. While the second case may
4972 * seem unlikely, it actually happens when a #GtkPlug is embedded
4973 * inside a #GtkSocket within the same application.
4975 * To reliably find the toplevel #GtkWindow, use
4976 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
4977 * is set on the result.
4978 * <informalexample><programlisting>
4979 * <!>GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4980 * <!>if (GTK_WIDGET_TOPLEVEL (toplevel))
4982 * <!> [ Perform action on toplevel. ]
4984 * </programlisting></informalexample>
4986 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
4989 gtk_widget_get_toplevel (GtkWidget *widget)
4991 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4993 while (widget->parent)
4994 widget = widget->parent;
5000 * gtk_widget_get_ancestor:
5001 * @widget: a #GtkWidget
5002 * @widget_type: ancestor type
5004 * Gets the first ancestor of @widget with type @widget_type. For example,
5005 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5006 * first #GtkBox that's
5007 * an ancestor of @widget. No reference will be added to the returned widget;
5008 * it should not be unreferenced. See note about checking for a toplevel
5009 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5011 * Return value: the ancestor widget, or %NULL if not found
5014 gtk_widget_get_ancestor (GtkWidget *widget,
5015 GtkType widget_type)
5017 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5019 while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5020 widget = widget->parent;
5022 if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5029 * gtk_widget_get_colormap:
5030 * @widget: a #GtkWidget
5032 * Gets the colormap that will be used to render @widget. No reference will
5033 * be added to the returned colormap; it should not be unreferenced.
5035 * Return value: the colormap used by @widget
5038 gtk_widget_get_colormap (GtkWidget *widget)
5040 GdkColormap *colormap;
5042 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5046 colormap = gdk_window_get_colormap (widget->window);
5047 /* If window was destroyed previously, we'll get NULL here */
5054 colormap = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_colormap);
5058 widget = widget->parent;
5061 return gtk_widget_get_default_colormap ();
5065 * gtk_widget_get_visual:
5066 * @widget: a #GtkWidget
5068 * Gets the visual that will be used to render @widget.
5070 * Return value: the visual for @widget
5073 gtk_widget_get_visual (GtkWidget *widget)
5075 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5077 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5081 * gtk_widget_get_settings:
5082 * @widget: a #GtkWidget
5084 * Gets the settings object holding the settings (global property
5085 * settings, RC file information, etc) used for this widget.
5087 * Return value: the relevant #GtkSettings object
5090 gtk_widget_get_settings (GtkWidget *widget)
5092 return gtk_settings_get_default ();
5096 * gtk_widget_set_colormap:
5097 * @widget: a #GtkWidget
5098 * @colormap: a colormap
5100 * Sets the colormap for the widget to the given value. Widget must not
5101 * have been previously realized. This probably should only be used
5102 * from an <function>init()</function> function (i.e. from the constructor
5107 gtk_widget_set_colormap (GtkWidget *widget,
5108 GdkColormap *colormap)
5110 g_return_if_fail (GTK_IS_WIDGET (widget));
5111 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5112 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5114 g_object_ref (G_OBJECT (colormap));
5116 g_object_set_qdata_full (G_OBJECT (widget),
5119 (GtkDestroyNotify) g_object_unref);
5123 * gtk_widget_get_events:
5124 * @widget: a #GtkWidget
5126 * Returns the event mask for the widget (a bitfield containing flags
5127 * from the #GdkEventMask enumeration). These are the events that the widget
5130 * Return value: event mask for @widget
5133 gtk_widget_get_events (GtkWidget *widget)
5137 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5139 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
5147 * gtk_widget_get_extension_events:
5148 * @widget: a #GtkWidget
5150 * Retrieves the extension events the widget will receive; see
5151 * gdk_input_set_extension_events().
5153 * Return value: extension events for @widget
5156 gtk_widget_get_extension_events (GtkWidget *widget)
5158 GdkExtensionMode *mode;
5160 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5162 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
5170 * gtk_widget_get_pointer:
5171 * @widget: a #GtkWidget
5172 * @x: return location for the X coordinate, or %NULL
5173 * @y: return location for the Y coordinate, or %NULL
5175 * Obtains the location of the mouse pointer in widget coordinates.
5176 * Widget coordinates are a bit odd; for historical reasons, they are
5177 * defined as @widget->window coordinates for widgets that are not
5178 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
5179 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
5183 gtk_widget_get_pointer (GtkWidget *widget,
5187 g_return_if_fail (GTK_IS_WIDGET (widget));
5194 if (GTK_WIDGET_REALIZED (widget))
5196 gdk_window_get_pointer (widget->window, x, y, NULL);
5198 if (GTK_WIDGET_NO_WINDOW (widget))
5201 *x -= widget->allocation.x;
5203 *y -= widget->allocation.y;
5209 * gtk_widget_is_ancestor:
5210 * @widget: a #GtkWidget
5211 * @ancestor: another #GtkWidget
5213 * Determines whether @widget is somewhere inside @ancestor, possibly with
5214 * intermediate containers.
5216 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
5219 gtk_widget_is_ancestor (GtkWidget *widget,
5220 GtkWidget *ancestor)
5222 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5223 g_return_val_if_fail (ancestor != NULL, FALSE);
5227 if (widget->parent == ancestor)
5229 widget = widget->parent;
5235 static GQuark quark_composite_name = 0;
5238 * gtk_widget_set_composite_name:
5239 * @widget: a #GtkWidget.
5240 * @name: the name to set.
5242 * Sets a widgets composite name. The widget must be
5243 * a composite child of its parent; see gtk_widget_push_composite_child().
5246 gtk_widget_set_composite_name (GtkWidget *widget,
5249 g_return_if_fail (GTK_IS_WIDGET (widget));
5250 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
5251 g_return_if_fail (name != NULL);
5253 if (!quark_composite_name)
5254 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
5256 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
5257 quark_composite_name,
5263 * gtk_widget_get_composite_name:
5264 * @widget: a #GtkWidget.
5265 * @returns: the composite name of @widget, or %NULL if @widget is not
5266 * a composite child. The string should not be freed when it is no
5269 * Obtains the composite name of a widget.
5272 gtk_widget_get_composite_name (GtkWidget *widget)
5274 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5276 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
5277 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
5284 * gtk_widget_push_composite_child:
5286 * Makes all newly-created widgets as composite children until
5287 * the corresponding gtk_widget_pop_composite_child() call.
5289 * Here is a simple example:
5290 * <informalexample><programlisting>
5291 * <!> gtk_widget_push_composite_child (<!>);
5292 * <!> scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
5293 * <!> gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
5294 * <!> gtk_widget_pop_composite_child (<!>);
5295 * <!> gtk_widget_set_parent (scrolled_window->hscrollbar,
5296 * <!> GTK_WIDGET (scrolled_window));
5297 * <!> gtk_widget_ref (scrolled_window->hscrollbar);
5298 * </programlisting></informalexample>
5301 gtk_widget_push_composite_child (void)
5303 composite_child_stack++;
5307 * gtk_widget_pop_composite_child:
5309 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
5312 gtk_widget_pop_composite_child (void)
5314 if (composite_child_stack)
5315 composite_child_stack--;
5319 * gtk_widget_push_colormap:
5320 * @cmap: a #GdkColormap
5322 * Pushes @cmap onto a global stack of colormaps; the topmost
5323 * colormap on the stack will be used to create all widgets.
5324 * Remove @cmap with gtk_widget_pop_colormap(). There's little
5325 * reason to use this function.
5329 gtk_widget_push_colormap (GdkColormap *cmap)
5331 g_return_if_fail (cmap != NULL);
5333 colormap_stack = g_slist_prepend (colormap_stack, cmap);
5337 * gtk_widget_pop_colormap:
5339 * Removes a colormap pushed with gtk_widget_push_colormap().
5343 gtk_widget_pop_colormap (void)
5346 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
5350 * gtk_widget_set_default_colormap:
5351 * @colormap: a #GdkColormap
5353 * Sets the default colormap to use when creating widgets.
5354 * gtk_widget_push_colormap() is a better function to use if
5355 * you only want to affect a few widgets, rather than all widgets.
5359 gtk_widget_set_default_colormap (GdkColormap *colormap)
5361 if (default_colormap != colormap)
5363 if (default_colormap)
5364 gdk_colormap_unref (default_colormap);
5365 default_colormap = colormap;
5366 if (default_colormap)
5367 gdk_colormap_ref (default_colormap);
5372 * gtk_widget_get_default_colormap:
5374 * Obtains the default colormap used to create widgets.
5376 * Return value: default widget colormap
5379 gtk_widget_get_default_colormap (void)
5381 if (!default_colormap)
5382 gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
5384 return default_colormap;
5388 * gtk_widget_get_default_visual:
5390 * Obtains the visual of the default colormap. Not really useful;
5391 * used to be useful before gdk_colormap_get_visual() existed.
5393 * Return value: visual of the default colormap
5396 gtk_widget_get_default_visual (void)
5398 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
5402 gtk_widget_emit_direction_changed (GtkWidget *widget,
5403 GtkTextDirection old_dir)
5405 PangoContext *context = gtk_widget_peek_pango_context (widget);
5408 pango_context_set_base_dir (context,
5409 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5410 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5412 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
5416 * gtk_widget_set_direction:
5417 * @widget: a #GtkWidget
5418 * @dir: the new direction
5420 * Sets the reading direction on a particular widget. This direction
5421 * controls the primary direction for widgets containing text,
5422 * and also the direction in which the children of a container are
5423 * packed. The ability to set the direction is present in order
5424 * so that correct localization into languages with right-to-left
5425 * reading directions can be done. Generally, applications will
5426 * let the default reading direction present, except for containers
5427 * where the containers are arranged in an order that is explicitely
5428 * visual rather than logical (such as buttons for text justification).
5430 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
5431 * set by gtk_widget_set_default_direction() will be used.
5434 gtk_widget_set_direction (GtkWidget *widget,
5435 GtkTextDirection dir)
5437 GtkTextDirection old_dir;
5439 g_return_if_fail (GTK_IS_WIDGET (widget));
5440 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
5442 old_dir = gtk_widget_get_direction (widget);
5444 if (dir == GTK_TEXT_DIR_NONE)
5445 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
5448 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
5449 if (dir == GTK_TEXT_DIR_LTR)
5450 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
5452 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
5455 if (old_dir != gtk_widget_get_direction (widget))
5456 gtk_widget_emit_direction_changed (widget, old_dir);
5460 * gtk_widget_get_direction:
5461 * @widget: a #GtkWidget
5463 * Gets the reading direction for a particular widget. See
5464 * gtk_widget_set_direction().
5466 * Return value: the reading direction for the widget.
5469 gtk_widget_get_direction (GtkWidget *widget)
5471 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
5473 if (GTK_WIDGET_DIRECTION_SET (widget))
5474 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
5476 return gtk_default_direction;
5480 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
5482 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
5484 g_object_ref (G_OBJECT (widget));
5486 if (!GTK_WIDGET_DIRECTION_SET (widget))
5487 gtk_widget_emit_direction_changed (widget, old_dir);
5489 if (GTK_IS_CONTAINER (widget))
5490 gtk_container_forall (GTK_CONTAINER (widget),
5491 gtk_widget_set_default_direction_recurse,
5494 g_object_unref (G_OBJECT (widget));
5498 * gtk_widget_set_default_direction:
5499 * @dir: the new default direction. This cannot be
5500 * %GTK_TEXT_DIR_NONE.
5502 * Sets the default reading direction for widgets where the
5503 * direction has not been explicitly set by gtk_widget_set_direction().
5506 gtk_widget_set_default_direction (GtkTextDirection dir)
5508 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
5510 if (dir != gtk_default_direction)
5512 GList *toplevels, *tmp_list;
5513 GtkTextDirection old_dir = gtk_default_direction;
5515 gtk_default_direction = dir;
5517 tmp_list = toplevels = gtk_window_list_toplevels ();
5518 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
5522 gtk_widget_set_default_direction_recurse (tmp_list->data,
5523 GUINT_TO_POINTER (old_dir));
5524 g_object_unref (tmp_list->data);
5525 tmp_list = tmp_list->next;
5528 g_list_free (toplevels);
5533 * gtk_widget_get_default_direction:
5535 * Obtains the current default reading direction. See
5536 * gtk_widget_set_default_direction().
5538 * Return value: the current default direction.
5541 gtk_widget_get_default_direction (void)
5543 return gtk_default_direction;
5547 gtk_widget_dispose (GObject *object)
5549 GtkWidget *widget = GTK_WIDGET (object);
5552 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5554 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
5555 if (GTK_WIDGET_REALIZED (widget))
5556 gtk_widget_unrealize (widget);
5558 G_OBJECT_CLASS (parent_class)->dispose (object);
5562 gtk_widget_real_destroy (GtkObject *object)
5566 /* gtk_object_destroy() will already hold a refcount on object
5568 widget = GTK_WIDGET (object);
5570 /* wipe accelerator closures (keep order) */
5571 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
5572 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
5574 gtk_grab_remove (widget);
5575 gtk_selection_remove_all (widget);
5577 g_object_unref (widget->style);
5578 widget->style = gtk_widget_get_default_style ();
5579 g_object_ref (widget->style);
5581 GTK_OBJECT_CLASS (parent_class)->destroy (object);
5585 gtk_widget_finalize (GObject *object)
5587 GtkWidget *widget = GTK_WIDGET (object);
5588 GtkWidgetAuxInfo *aux_info;
5590 GdkExtensionMode *mode;
5591 GtkAccessible *accessible;
5593 gtk_grab_remove (widget);
5594 gtk_selection_remove_all (widget);
5596 g_object_unref (widget->style);
5597 widget->style = NULL;
5600 g_free (widget->name);
5602 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
5604 gtk_widget_aux_info_destroy (aux_info);
5606 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
5610 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
5614 accessible = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accessible_object);
5616 g_object_unref (G_OBJECT (accessible));
5618 G_OBJECT_CLASS (parent_class)->finalize (object);
5621 /*****************************************
5622 * gtk_widget_real_map:
5627 *****************************************/
5630 gtk_widget_real_map (GtkWidget *widget)
5632 g_return_if_fail (GTK_IS_WIDGET (widget));
5633 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
5635 if (!GTK_WIDGET_MAPPED (widget))
5637 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
5639 if (!GTK_WIDGET_NO_WINDOW (widget))
5640 gdk_window_show (widget->window);
5644 /*****************************************
5645 * gtk_widget_real_unmap:
5650 *****************************************/
5653 gtk_widget_real_unmap (GtkWidget *widget)
5655 g_return_if_fail (GTK_IS_WIDGET (widget));
5657 if (GTK_WIDGET_MAPPED (widget))
5659 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5661 if (!GTK_WIDGET_NO_WINDOW (widget))
5662 gdk_window_hide (widget->window);
5666 /*****************************************
5667 * gtk_widget_real_realize:
5672 *****************************************/
5675 gtk_widget_real_realize (GtkWidget *widget)
5677 g_return_if_fail (GTK_IS_WIDGET (widget));
5678 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
5680 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
5683 widget->window = gtk_widget_get_parent_window (widget);
5684 gdk_window_ref (widget->window);
5686 widget->style = gtk_style_attach (widget->style, widget->window);
5689 /*****************************************
5690 * gtk_widget_real_unrealize:
5695 *****************************************/
5698 gtk_widget_real_unrealize (GtkWidget *widget)
5700 g_return_if_fail (GTK_IS_WIDGET (widget));
5702 if (GTK_WIDGET_MAPPED (widget))
5703 gtk_widget_real_unmap (widget);
5705 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5707 /* printf ("unrealizing %s\n", gtk_type_name (GTK_OBJECT (widget)->klass->type));
5710 /* We must do unrealize child widget BEFORE container widget.
5711 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
5712 * So, unrealizing container widget bofore its children causes the problem
5713 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
5716 if (GTK_IS_CONTAINER (widget))
5717 gtk_container_forall (GTK_CONTAINER (widget),
5718 (GtkCallback) gtk_widget_unrealize,
5721 gtk_style_detach (widget->style);
5722 if (!GTK_WIDGET_NO_WINDOW (widget))
5724 gdk_window_set_user_data (widget->window, NULL);
5725 gdk_window_destroy (widget->window);
5726 widget->window = NULL;
5730 gdk_window_unref (widget->window);
5731 widget->window = NULL;
5734 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
5738 gtk_widget_real_size_request (GtkWidget *widget,
5739 GtkRequisition *requisition)
5741 g_return_if_fail (GTK_IS_WIDGET (widget));
5743 requisition->width = widget->requisition.width;
5744 requisition->height = widget->requisition.height;
5748 * _gtk_widget_peek_colormap:
5750 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
5752 * Return value: the currently pushed colormap, or %NULL if there is none.
5755 _gtk_widget_peek_colormap (void)
5758 return (GdkColormap*) colormap_stack->data;
5763 gtk_widget_propagate_state (GtkWidget *widget,
5768 /* don't call this function with state==GTK_STATE_INSENSITIVE,
5769 * parent_sensitive==TRUE on a sensitive widget
5772 old_state = GTK_WIDGET_STATE (widget);
5774 if (data->parent_sensitive)
5776 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5778 if (GTK_WIDGET_IS_SENSITIVE (widget))
5780 if (data->state_restoration)
5781 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
5783 GTK_WIDGET_STATE (widget) = data->state;
5787 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5788 if (!data->state_restoration &&
5789 data->state != GTK_STATE_INSENSITIVE)
5790 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5795 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5796 if (!data->state_restoration)
5798 if (data->state != GTK_STATE_INSENSITIVE)
5799 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5801 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
5802 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
5803 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5806 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
5810 window = gtk_widget_get_toplevel (widget);
5811 if (window && GTK_WIDGET_TOPLEVEL (window))
5812 gtk_window_set_focus (GTK_WINDOW (window), NULL);
5815 if (old_state != GTK_WIDGET_STATE (widget))
5817 gtk_widget_ref (widget);
5819 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
5820 gtk_grab_remove (widget);
5822 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STATE_CHANGED], old_state);
5825 if (GTK_IS_CONTAINER (widget))
5827 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
5828 data->state = GTK_WIDGET_STATE (widget);
5829 if (data->use_forall)
5830 gtk_container_forall (GTK_CONTAINER (widget),
5831 (GtkCallback) gtk_widget_propagate_state,
5834 gtk_container_foreach (GTK_CONTAINER (widget),
5835 (GtkCallback) gtk_widget_propagate_state,
5838 gtk_widget_unref (widget);
5843 * _gtk_widget_get_aux_info:
5844 * @widget: a #GtkWidget
5845 * @create: if %TRUE, create the structure if it doesn't exist
5847 * Get the #GtkWidgetAuxInfo structure for the widget.
5849 * Return value: the #GtkAuxInfo structure for the widget, or
5850 * %NULL if @create is %FALSE and one doesn't already exist.
5853 _gtk_widget_get_aux_info (GtkWidget *widget,
5856 GtkWidgetAuxInfo *aux_info;
5858 aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_aux_info);
5859 if (!aux_info && create)
5861 if (!aux_info_mem_chunk)
5862 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
5863 sizeof (GtkWidgetAuxInfo),
5864 1024, G_ALLOC_AND_FREE);
5865 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
5867 aux_info->width = -1;
5868 aux_info->height = -1;
5871 aux_info->x_set = FALSE;
5872 aux_info->y_set = FALSE;
5873 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_aux_info, aux_info);
5879 /*****************************************
5880 * gtk_widget_aux_info_destroy:
5885 *****************************************/
5888 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
5890 g_return_if_fail (aux_info != NULL);
5892 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
5896 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
5898 gdk_drawable_unref (info->shape_mask);
5903 * gtk_widget_shape_combine_mask:
5904 * @widget: a #GtkWidget.
5905 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
5906 * @offset_x: X position of shape mask with respect to @window.
5907 * @offset_y: Y position of shape mask with respect to @window.
5909 * Sets a shape for this widget's GDK window. This allows for
5910 * transparent windows etc., see gdk_window_shape_combine_mask()
5911 * for more information.
5914 gtk_widget_shape_combine_mask (GtkWidget *widget,
5915 GdkBitmap *shape_mask,
5919 GtkWidgetShapeInfo* shape_info;
5921 g_return_if_fail (GTK_IS_WIDGET (widget));
5922 /* set_shape doesn't work on widgets without gdk window */
5923 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
5927 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5930 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
5932 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
5936 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5938 shape_info = g_new (GtkWidgetShapeInfo, 1);
5939 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
5940 (GDestroyNotify) gtk_widget_shape_info_destroy);
5942 shape_info->shape_mask = gdk_drawable_ref (shape_mask);
5943 shape_info->offset_x = offset_x;
5944 shape_info->offset_y = offset_y;
5946 /* set shape if widget has a gdk window allready.
5947 * otherwise the shape is scheduled to be set by gtk_widget_realize.
5950 gdk_window_shape_combine_mask (widget->window, shape_mask,
5951 offset_x, offset_y);
5956 gtk_reset_shapes_recurse (GtkWidget *widget,
5962 gdk_window_get_user_data (window, &data);
5966 gdk_window_shape_combine_mask (window, NULL, 0, 0);
5967 for (list = gdk_window_peek_children (window); list; list = list->next)
5968 gtk_reset_shapes_recurse (widget, list->data);
5972 * gtk_widget_reset_shapes:
5973 * @widget: a #GtkWidget.
5975 * Recursively resets the shape on this widget and its descendants.
5978 gtk_widget_reset_shapes (GtkWidget *widget)
5980 g_return_if_fail (GTK_IS_WIDGET (widget));
5981 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
5983 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
5984 gtk_reset_shapes_recurse (widget, widget->window);
5989 * @widget: a #GtkWidget
5991 * Adds a reference to a widget. This function is exactly the same
5992 * as calling g_object_ref(), and exists mostly for historical
5993 * reasons. It can still be convenient to avoid casting a widget
5994 * to a #GObject, it saves a small amount of typing.
5996 * Return value: the widget that was referenced
5999 gtk_widget_ref (GtkWidget *widget)
6001 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6003 return (GtkWidget*) g_object_ref ((GObject*) widget);
6008 * @widget: a #GtkWidget
6010 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6014 gtk_widget_unref (GtkWidget *widget)
6016 g_return_if_fail (GTK_IS_WIDGET (widget));
6018 g_object_unref ((GObject*) widget);
6026 gtk_widget_class_install_style_property_parser (GtkWidgetClass *class,
6028 GtkRcPropertyParser parser)
6030 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
6031 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6032 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6033 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6035 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
6037 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6038 G_OBJECT_CLASS_NAME (class),
6043 g_param_spec_ref (pspec);
6044 g_param_spec_sink (pspec);
6045 g_param_spec_set_qdata (pspec, quark_property_parser, parser);
6046 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
6050 gtk_widget_class_install_style_property (GtkWidgetClass *class,
6053 GtkRcPropertyParser parser;
6055 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
6056 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6058 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6060 gtk_widget_class_install_style_property_parser (class, pspec, parser);
6064 * gtk_widget_style_get_property:
6065 * @widget: a #GtkWidget
6066 * @property_name: the name of a style property
6067 * @value: location to return the property value
6069 * Gets the value of a style property of @widget.
6072 gtk_widget_style_get_property (GtkWidget *widget,
6073 const gchar *property_name,
6078 g_return_if_fail (GTK_IS_WIDGET (widget));
6079 g_return_if_fail (property_name != NULL);
6080 g_return_if_fail (G_IS_VALUE (value));
6082 g_object_ref (widget);
6083 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6085 G_OBJECT_TYPE (widget),
6088 g_warning ("%s: widget class `%s' has no property named `%s'",
6090 G_OBJECT_TYPE_NAME (widget),
6094 const GValue *peek_value;
6096 peek_value = _gtk_style_peek_property_value (widget->style,
6097 G_OBJECT_TYPE (widget),
6099 g_param_spec_get_qdata (pspec, quark_property_parser));
6101 /* auto-conversion of the caller's value type
6103 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
6104 g_value_copy (peek_value, value);
6105 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
6106 g_value_transform (peek_value, value);
6108 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
6110 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
6111 G_VALUE_TYPE_NAME (value));
6113 g_object_unref (widget);
6117 * gtk_widget_style_get_valist:
6118 * @widget: a #GtkWidget
6119 * @first_property_name: the name of the first property to get
6120 * @var_args: a <type>va_list</type> of pairs of property names and
6121 * locations to return the property values, starting with the location
6122 * for @first_property_name.
6124 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
6128 gtk_widget_style_get_valist (GtkWidget *widget,
6129 const gchar *first_property_name,
6134 g_return_if_fail (GTK_IS_WIDGET (widget));
6136 g_object_ref (widget);
6138 name = first_property_name;
6141 const GValue *peek_value;
6145 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6147 G_OBJECT_TYPE (widget),
6151 g_warning ("%s: widget class `%s' has no property named `%s'",
6153 G_OBJECT_TYPE_NAME (widget),
6157 /* style pspecs are always readable so we can spare that check here */
6159 peek_value = _gtk_style_peek_property_value (widget->style,
6160 G_OBJECT_TYPE (widget),
6162 g_param_spec_get_qdata (pspec, quark_property_parser));
6163 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
6166 g_warning ("%s: %s", G_STRLOC, error);
6171 name = va_arg (var_args, gchar*);
6174 g_object_unref (widget);
6178 * gtk_widget_style_get:
6179 * @widget: a #GtkWidget
6180 * @first_property_name: the name of the first property to get
6181 * @Varargs: pairs of property names and locations to
6182 * return the property values, starting with the location for
6183 * @first_property_name, terminated by %NULL.
6185 * Gets the values of a multiple style properties of @widget.
6188 gtk_widget_style_get (GtkWidget *widget,
6189 const gchar *first_property_name,
6194 g_return_if_fail (GTK_IS_WIDGET (widget));
6196 va_start (var_args, first_property_name);
6197 gtk_widget_style_get_valist (widget, first_property_name, var_args);
6203 * @widget: a #GtkWidget
6204 * @path_length: location to store length of the path, or %NULL
6205 * @path: location to store allocated path string, or %NULL
6206 * @path_reversed: location to store allocated reverse path string, or %NULL
6208 * Obtains the full path to @widget. The path is simply the name of a
6209 * widget and all its parents in the container hierarchy, separated by
6210 * periods. The name of a widget comes from
6211 * gtk_widget_get_name(). Paths are used to apply styles to a widget
6212 * in gtkrc configuration files. Widget names are the type of the
6213 * widget by default (e.g. "GtkButton") or can be set to an
6214 * application-specific value with gtk_widget_set_name(). By setting
6215 * the name of a widget, you allow users or theme authors to apply
6216 * styles to that specific widget in their gtkrc
6217 * file. @path_reversed_p fills in the path in reverse order,
6218 * i.e. starting with @widget's name instead of starting with the name
6219 * of @widget's outermost ancestor.
6223 gtk_widget_path (GtkWidget *widget,
6226 gchar **path_reversed)
6228 static gchar *rev_path = NULL;
6229 static guint tmp_path_len = 0;
6232 g_return_if_fail (GTK_IS_WIDGET (widget));
6237 const gchar *string;
6242 string = gtk_widget_get_name (widget);
6243 l = strlen (string);
6244 while (tmp_path_len <= len + l + 1)
6246 tmp_path_len += INIT_PATH_SIZE;
6247 rev_path = g_realloc (rev_path, tmp_path_len);
6255 widget = widget->parent;
6258 rev_path[len++] = '.';
6260 rev_path[len++] = 0;
6265 *path_length = len - 1;
6267 *path_reversed = g_strdup (rev_path);
6270 *path = g_strdup (rev_path);
6271 g_strreverse (*path);
6276 * gtk_widget_class_path:
6277 * @widget: a #GtkWidget
6278 * @path_length: location to store the length of the class path, or %NULL
6279 * @path: location to store the class path as an allocated string, or %NULL
6280 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
6282 * Same as gtk_widget_path(), but always uses the name of a widget's type,
6283 * never uses a custom name set with gtk_widget_set_name().
6287 gtk_widget_class_path (GtkWidget *widget,
6290 gchar **path_reversed)
6292 static gchar *rev_path = NULL;
6293 static guint tmp_path_len = 0;
6296 g_return_if_fail (GTK_IS_WIDGET (widget));
6301 const gchar *string;
6306 string = gtk_type_name (GTK_WIDGET_TYPE (widget));
6307 l = strlen (string);
6308 while (tmp_path_len <= len + l + 1)
6310 tmp_path_len += INIT_PATH_SIZE;
6311 rev_path = g_realloc (rev_path, tmp_path_len);
6319 widget = widget->parent;
6322 rev_path[len++] = '.';
6324 rev_path[len++] = 0;
6329 *path_length = len - 1;
6331 *path_reversed = g_strdup (rev_path);
6334 *path = g_strdup (rev_path);
6335 g_strreverse (*path);
6340 * gtk_requisition_copy:
6341 * @requisition: a #GtkRequisition.
6342 * @returns: a copy of @requisition.
6344 * Copies a #GtkRequisition.
6347 gtk_requisition_copy (const GtkRequisition *requisition)
6349 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
6353 * gtk_requisition_free:
6354 * @requisition: a #GtkRequisition.
6356 * Frees a #GtkRequisition.
6359 gtk_requisition_free (GtkRequisition *requisition)
6361 g_free (requisition);
6365 gtk_widget_get_accessible (GtkWidget *widget)
6367 GtkWidgetClass *klass;
6369 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6371 klass = GTK_WIDGET_GET_CLASS (widget);
6373 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
6375 return klass->get_accessible (widget);
6379 gtk_widget_real_get_accessible (GtkWidget *widget)
6381 AtkObject* accessible;
6383 accessible = g_object_get_qdata (G_OBJECT (widget),
6384 quark_accessible_object);
6387 AtkObjectFactory *factory;
6388 AtkRegistry *default_registry;
6390 default_registry = atk_get_default_registry ();
6391 factory = atk_registry_get_factory (default_registry,
6392 GTK_OBJECT_TYPE (widget));
6394 atk_object_factory_create_accessible (factory,
6396 g_object_set_qdata (G_OBJECT (widget),
6397 quark_accessible_object,
6404 * Initialize a AtkImplementorIface instance's virtual pointers as
6405 * appropriate to this implementor's class (GtkWidget).
6408 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
6410 iface->ref_accessible = gtk_widget_ref_accessible;
6414 gtk_widget_ref_accessible (AtkImplementor *implementor)
6416 AtkObject *accessible;
6418 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
6420 g_object_ref (G_OBJECT (accessible));