1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkcontainer.h"
31 #include "gtkiconfactory.h"
35 #include "gtkselection.h"
36 #include "gtksettings.h"
37 #include "gtksizegroup.h"
38 #include "gtksignal.h"
39 #include "gtkwidget.h"
40 #include "gtkwindow.h"
41 #include "gtkbindings.h"
42 #include "gtkprivate.h"
44 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
45 #include <gobject/gvaluecollector.h>
46 #include <gobject/gobjectnotifyqueue.c>
47 #include "gdk/gdkkeysyms.h"
49 #include "gtkaccessible.h"
50 #include "gtktooltips.h"
52 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
53 #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,
133 PROP_RECEIVES_DEFAULT,
134 PROP_COMPOSITE_CHILD,
137 PROP_EXTENSION_EVENTS
140 typedef struct _GtkStateData GtkStateData;
145 guint state_restoration : 1;
146 guint parent_sensitive : 1;
147 guint use_forall : 1;
151 /* --- prototypes --- */
152 static void gtk_widget_class_init (GtkWidgetClass *klass);
153 static void gtk_widget_init (GtkWidget *widget);
154 static void gtk_widget_set_property (GObject *object,
158 static void gtk_widget_get_property (GObject *object,
162 static void gtk_widget_dispose (GObject *object);
163 static void gtk_widget_real_destroy (GtkObject *object);
164 static void gtk_widget_finalize (GObject *object);
165 static void gtk_widget_real_show (GtkWidget *widget);
166 static void gtk_widget_real_hide (GtkWidget *widget);
167 static void gtk_widget_real_map (GtkWidget *widget);
168 static void gtk_widget_real_unmap (GtkWidget *widget);
169 static void gtk_widget_real_realize (GtkWidget *widget);
170 static void gtk_widget_real_unrealize (GtkWidget *widget);
171 static void gtk_widget_real_size_request (GtkWidget *widget,
172 GtkRequisition *requisition);
173 static void gtk_widget_real_size_allocate (GtkWidget *widget,
174 GtkAllocation *allocation);
175 static void gtk_widget_style_set (GtkWidget *widget,
176 GtkStyle *previous_style);
177 static void gtk_widget_direction_changed (GtkWidget *widget,
178 GtkTextDirection previous_direction);
180 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
181 static void gtk_widget_real_show_help (GtkWidget *widget,
182 GtkWidgetHelpType help_type);
184 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
186 GParamSpec **pspecs);
187 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
189 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
191 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
192 GdkEventFocus *event);
193 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
194 GdkEventFocus *event);
195 static gboolean gtk_widget_real_focus (GtkWidget *widget,
196 GtkDirectionType direction);
197 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
198 static void gtk_widget_reparent_container_child (GtkWidget *widget,
199 gpointer client_data);
200 static void gtk_widget_propagate_state (GtkWidget *widget,
202 static void gtk_widget_reset_rc_style (GtkWidget *widget);
203 static void gtk_widget_set_style_internal (GtkWidget *widget,
205 gboolean initial_emission);
206 static void gtk_widget_set_style_recurse (GtkWidget *widget,
207 gpointer client_data);
208 static gint gtk_widget_event_internal (GtkWidget *widget,
210 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
211 gboolean group_cycling);
212 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
213 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
214 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
215 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
217 /* --- variables --- */
218 static gpointer parent_class = NULL;
219 static guint widget_signals[LAST_SIGNAL] = { 0 };
220 static GMemChunk *aux_info_mem_chunk = NULL;
221 static GdkColormap *default_colormap = NULL;
222 static GtkStyle *gtk_default_style = NULL;
223 static GSList *colormap_stack = NULL;
224 static guint composite_child_stack = 0;
225 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
226 static GParamSpecPool *style_property_spec_pool = NULL;
228 static GQuark quark_property_parser = 0;
229 static GQuark quark_aux_info = 0;
230 static GQuark quark_event_mask = 0;
231 static GQuark quark_extension_event_mode = 0;
232 static GQuark quark_parent_window = 0;
233 static GQuark quark_shape_info = 0;
234 static GQuark quark_colormap = 0;
235 static GQuark quark_pango_context = 0;
236 static GQuark quark_rc_style = 0;
237 static GQuark quark_accessible_object = 0;
238 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
239 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
241 /* --- functions --- */
243 gtk_widget_get_type (void)
245 static GtkType widget_type = 0;
249 static const GtkTypeInfo widget_info =
253 sizeof (GtkWidgetClass),
254 (GtkClassInitFunc) gtk_widget_class_init,
255 (GtkObjectInitFunc) gtk_widget_init,
256 /* reserved_1 */ NULL,
257 /* reserved_2 */ NULL,
258 (GtkClassInitFunc) NULL,
261 static const GInterfaceInfo accessibility_info =
263 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
264 (GInterfaceFinalizeFunc) NULL,
265 NULL /* interface data */
269 widget_type = gtk_type_unique (GTK_TYPE_OBJECT, &widget_info);
271 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
272 &accessibility_info) ;
280 child_property_notify_dispatcher (GObject *object,
284 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
288 gtk_widget_class_init (GtkWidgetClass *klass)
290 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
291 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
292 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
293 GtkBindingSet *binding_set;
295 parent_class = g_type_class_peek_parent (klass);
297 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
298 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
299 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
300 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
301 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
302 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
303 quark_colormap = g_quark_from_static_string ("gtk-colormap");
304 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
305 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
306 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
308 style_property_spec_pool = g_param_spec_pool_new (FALSE);
309 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
310 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
311 cpn_context.dispatcher = child_property_notify_dispatcher;
312 _gtk_widget_child_property_notify_context = &cpn_context;
314 gobject_class->dispose = gtk_widget_dispose;
315 gobject_class->finalize = gtk_widget_finalize;
316 gobject_class->set_property = gtk_widget_set_property;
317 gobject_class->get_property = gtk_widget_get_property;
319 object_class->destroy = gtk_widget_real_destroy;
321 klass->activate_signal = 0;
322 klass->set_scroll_adjustments_signal = 0;
323 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
324 klass->show = gtk_widget_real_show;
325 klass->show_all = gtk_widget_show;
326 klass->hide = gtk_widget_real_hide;
327 klass->hide_all = gtk_widget_hide;
328 klass->map = gtk_widget_real_map;
329 klass->unmap = gtk_widget_real_unmap;
330 klass->realize = gtk_widget_real_realize;
331 klass->unrealize = gtk_widget_real_unrealize;
332 klass->size_request = gtk_widget_real_size_request;
333 klass->size_allocate = gtk_widget_real_size_allocate;
334 klass->state_changed = NULL;
335 klass->parent_set = NULL;
336 klass->hierarchy_changed = NULL;
337 klass->style_set = gtk_widget_style_set;
338 klass->direction_changed = gtk_widget_direction_changed;
339 klass->grab_notify = NULL;
340 klass->child_notify = NULL;
341 klass->add_accelerator = (void*) gtk_accel_group_handle_add;
342 klass->remove_accelerator = (void*) gtk_accel_group_handle_remove;
343 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
344 klass->grab_focus = gtk_widget_real_grab_focus;
345 klass->focus = gtk_widget_real_focus;
347 klass->button_press_event = NULL;
348 klass->button_release_event = NULL;
349 klass->motion_notify_event = NULL;
350 klass->delete_event = NULL;
351 klass->destroy_event = NULL;
352 klass->expose_event = NULL;
353 klass->key_press_event = gtk_widget_real_key_press_event;
354 klass->key_release_event = gtk_widget_real_key_release_event;
355 klass->enter_notify_event = NULL;
356 klass->leave_notify_event = NULL;
357 klass->configure_event = NULL;
358 klass->focus_in_event = gtk_widget_real_focus_in_event;
359 klass->focus_out_event = gtk_widget_real_focus_out_event;
360 klass->map_event = NULL;
361 klass->unmap_event = NULL;
362 klass->window_state_event = NULL;
363 klass->property_notify_event = gtk_selection_property_notify;
364 klass->selection_clear_event = gtk_selection_clear;
365 klass->selection_request_event = gtk_selection_request;
366 klass->selection_notify_event = gtk_selection_notify;
367 klass->selection_received = NULL;
368 klass->proximity_in_event = NULL;
369 klass->proximity_out_event = NULL;
370 klass->drag_begin = NULL;
371 klass->drag_end = NULL;
372 klass->drag_data_delete = NULL;
373 klass->drag_leave = NULL;
374 klass->drag_motion = NULL;
375 klass->drag_drop = NULL;
376 klass->drag_data_received = NULL;
378 klass->show_help = gtk_widget_real_show_help;
380 /* Accessibility support */
381 klass->get_accessible = gtk_widget_real_get_accessible;
383 klass->no_expose_event = NULL;
385 g_object_class_install_property (gobject_class,
387 g_param_spec_string ("name",
389 _("The name of the widget"),
392 g_object_class_install_property (gobject_class,
394 g_param_spec_object ("parent",
396 _("The parent widget of this widget. Must be a Container widget."),
400 g_object_class_install_property (gobject_class,
402 g_param_spec_int ("width_request",
404 _("Override for width request of the widget, or -1 if natural request should be used."),
409 g_object_class_install_property (gobject_class,
411 g_param_spec_int ("height_request",
413 _("Override for height request of the widget, or -1 if natural request should be used."),
418 g_object_class_install_property (gobject_class,
420 g_param_spec_boolean ("visible",
422 _("Whether the widget is visible"),
425 g_object_class_install_property (gobject_class,
427 g_param_spec_boolean ("sensitive",
429 _("Whether the widget responds to input"),
432 g_object_class_install_property (gobject_class,
434 g_param_spec_boolean ("app_paintable",
435 _("Application paintable"),
436 _("Whether the application will paint directly on the widget"),
439 g_object_class_install_property (gobject_class,
441 g_param_spec_boolean ("can_focus",
443 _("Whether the widget can accept the input focus"),
446 g_object_class_install_property (gobject_class,
448 g_param_spec_boolean ("has_focus",
450 _("Whether the widget has the input focus"),
453 g_object_class_install_property (gobject_class,
455 g_param_spec_boolean ("can_default",
457 _("Whether the widget can be the default widget"),
460 g_object_class_install_property (gobject_class,
462 g_param_spec_boolean ("has_default",
464 _("Whether the widget is the default widget"),
467 g_object_class_install_property (gobject_class,
468 PROP_RECEIVES_DEFAULT,
469 g_param_spec_boolean ("receives_default",
470 _("Receives default"),
471 _("If TRUE, the widget will receive the default action when it is focused."),
474 g_object_class_install_property (gobject_class,
475 PROP_COMPOSITE_CHILD,
476 g_param_spec_boolean ("composite_child",
477 _("Composite child"),
478 _("Whether the widget is composed of other widgets"),
481 g_object_class_install_property (gobject_class,
483 g_param_spec_object ("style",
485 _("The style of the widget, which contains information about how it will look (colors etc)."),
488 g_object_class_install_property (gobject_class,
490 g_param_spec_flags ("events",
492 _("The event mask that decides what kind of GdkEvents this widget gets."),
496 g_object_class_install_property (gobject_class,
497 PROP_EXTENSION_EVENTS,
498 g_param_spec_enum ("extension_events",
499 _("Extension events"),
500 _("The mask that decides what kind of extension events this widget gets."),
501 GDK_TYPE_EXTENSION_MODE,
502 GDK_EXTENSION_EVENTS_NONE,
504 widget_signals[SHOW] =
505 gtk_signal_new ("show",
507 GTK_CLASS_TYPE (object_class),
508 GTK_SIGNAL_OFFSET (GtkWidgetClass, show),
509 gtk_marshal_VOID__VOID,
511 widget_signals[HIDE] =
512 gtk_signal_new ("hide",
514 GTK_CLASS_TYPE (object_class),
515 GTK_SIGNAL_OFFSET (GtkWidgetClass, hide),
516 gtk_marshal_VOID__VOID,
518 widget_signals[MAP] =
519 gtk_signal_new ("map",
521 GTK_CLASS_TYPE (object_class),
522 GTK_SIGNAL_OFFSET (GtkWidgetClass, map),
523 gtk_marshal_VOID__VOID,
525 widget_signals[UNMAP] =
526 gtk_signal_new ("unmap",
528 GTK_CLASS_TYPE (object_class),
529 GTK_SIGNAL_OFFSET (GtkWidgetClass, unmap),
530 gtk_marshal_VOID__VOID,
532 widget_signals[REALIZE] =
533 gtk_signal_new ("realize",
535 GTK_CLASS_TYPE (object_class),
536 GTK_SIGNAL_OFFSET (GtkWidgetClass, realize),
537 gtk_marshal_VOID__VOID,
539 widget_signals[UNREALIZE] =
540 gtk_signal_new ("unrealize",
542 GTK_CLASS_TYPE (object_class),
543 GTK_SIGNAL_OFFSET (GtkWidgetClass, unrealize),
544 gtk_marshal_VOID__VOID,
546 widget_signals[SIZE_REQUEST] =
547 g_signal_new ("size_request",
548 G_OBJECT_CLASS_TYPE (object_class),
550 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
552 gtk_marshal_VOID__BOXED,
554 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
555 widget_signals[SIZE_ALLOCATE] =
556 gtk_signal_new ("size_allocate",
558 GTK_CLASS_TYPE (object_class),
559 GTK_SIGNAL_OFFSET (GtkWidgetClass, size_allocate),
560 gtk_marshal_VOID__BOXED,
562 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
563 widget_signals[STATE_CHANGED] =
564 gtk_signal_new ("state_changed",
566 GTK_CLASS_TYPE (object_class),
567 GTK_SIGNAL_OFFSET (GtkWidgetClass, state_changed),
568 gtk_marshal_VOID__ENUM,
570 GTK_TYPE_STATE_TYPE);
571 widget_signals[PARENT_SET] =
572 gtk_signal_new ("parent_set",
574 GTK_CLASS_TYPE (object_class),
575 GTK_SIGNAL_OFFSET (GtkWidgetClass, parent_set),
576 gtk_marshal_VOID__OBJECT,
579 widget_signals[HIERARCHY_CHANGED] =
580 gtk_signal_new ("hierarchy_changed",
582 GTK_CLASS_TYPE (object_class),
583 GTK_SIGNAL_OFFSET (GtkWidgetClass, hierarchy_changed),
584 gtk_marshal_VOID__OBJECT,
587 widget_signals[STYLE_SET] =
588 gtk_signal_new ("style_set",
590 GTK_CLASS_TYPE (object_class),
591 GTK_SIGNAL_OFFSET (GtkWidgetClass, style_set),
592 gtk_marshal_VOID__OBJECT,
595 widget_signals[DIRECTION_CHANGED] =
596 gtk_signal_new ("direction_changed",
598 GTK_CLASS_TYPE (object_class),
599 GTK_SIGNAL_OFFSET (GtkWidgetClass, direction_changed),
600 gtk_marshal_VOID__ENUM,
602 GTK_TYPE_TEXT_DIRECTION);
603 widget_signals[GRAB_NOTIFY] =
604 gtk_signal_new ("grab_notify",
606 GTK_CLASS_TYPE (object_class),
607 GTK_SIGNAL_OFFSET (GtkWidgetClass, grab_notify),
608 gtk_marshal_VOID__BOOLEAN,
611 widget_signals[CHILD_NOTIFY] =
612 g_signal_new ("child_notify",
613 G_TYPE_FROM_CLASS (klass),
614 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
615 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
617 g_cclosure_marshal_VOID__PARAM,
620 widget_signals[ADD_ACCELERATOR] =
621 gtk_accel_group_create_add (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
622 GTK_SIGNAL_OFFSET (GtkWidgetClass, add_accelerator));
623 widget_signals[REMOVE_ACCELERATOR] =
624 gtk_accel_group_create_remove (GTK_CLASS_TYPE (object_class), GTK_RUN_LAST,
625 GTK_SIGNAL_OFFSET (GtkWidgetClass, remove_accelerator));
626 widget_signals[ACTIVATE_MNEMONIC] =
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);
1021 binding_set = gtk_binding_set_by_class (klass);
1022 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1024 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1027 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1029 GTK_TYPE_WIDGET_HELP_TYPE,
1030 GTK_WIDGET_HELP_TOOLTIP);
1031 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1033 GTK_TYPE_WIDGET_HELP_TYPE,
1034 GTK_WIDGET_HELP_TOOLTIP);
1036 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1038 GTK_TYPE_WIDGET_HELP_TYPE,
1039 GTK_WIDGET_HELP_WHATS_THIS);
1040 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1042 GTK_TYPE_WIDGET_HELP_TYPE,
1043 GTK_WIDGET_HELP_WHATS_THIS);
1045 gtk_widget_class_install_style_property (klass,
1046 g_param_spec_boolean ("interior_focus",
1047 _("Interior Focus"),
1048 _("Whether to draw the focus indicator inside widgets."),
1054 gtk_widget_set_property (GObject *object,
1056 const GValue *value,
1061 widget = GTK_WIDGET (object);
1065 guint32 saved_flags;
1068 gtk_widget_set_name (widget, g_value_get_string (value));
1071 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1073 case PROP_WIDTH_REQUEST:
1074 gtk_widget_set_usize (widget, g_value_get_int (value), -2);
1076 case PROP_HEIGHT_REQUEST:
1077 gtk_widget_set_usize (widget, -2, g_value_get_int (value));
1080 if (g_value_get_boolean (value))
1081 gtk_widget_show (widget);
1083 gtk_widget_hide (widget);
1085 case PROP_SENSITIVE:
1086 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1088 case PROP_APP_PAINTABLE:
1089 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1091 case PROP_CAN_FOCUS:
1092 saved_flags = GTK_WIDGET_FLAGS (widget);
1093 if (g_value_get_boolean (value))
1094 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1096 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1097 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1098 gtk_widget_queue_resize (widget);
1100 case PROP_HAS_FOCUS:
1101 if (g_value_get_boolean (value))
1102 gtk_widget_grab_focus (widget);
1104 case PROP_CAN_DEFAULT:
1105 saved_flags = GTK_WIDGET_FLAGS (widget);
1106 if (g_value_get_boolean (value))
1107 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1109 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1110 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1111 gtk_widget_queue_resize (widget);
1113 case PROP_HAS_DEFAULT:
1114 if (g_value_get_boolean (value))
1115 gtk_widget_grab_default (widget);
1117 case PROP_RECEIVES_DEFAULT:
1118 if (g_value_get_boolean (value))
1119 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1121 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1124 gtk_widget_set_style (widget, g_value_get_object (value));
1127 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1128 gtk_widget_set_events (widget, g_value_get_flags (value));
1130 case PROP_EXTENSION_EVENTS:
1131 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1139 gtk_widget_get_property (GObject *object,
1146 widget = GTK_WIDGET (object);
1151 GdkExtensionMode *modep;
1155 g_value_set_string (value, widget->name);
1157 g_value_set_string (value, "");
1161 g_value_set_object (value, G_OBJECT (widget->parent));
1163 g_value_set_object (value, NULL);
1165 case PROP_WIDTH_REQUEST:
1168 gtk_widget_get_size_request (widget, &w, NULL);
1169 g_value_set_int (value, w);
1172 case PROP_HEIGHT_REQUEST:
1175 gtk_widget_get_size_request (widget, NULL, &h);
1176 g_value_set_int (value, h);
1180 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1182 case PROP_SENSITIVE:
1183 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1185 case PROP_APP_PAINTABLE:
1186 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1188 case PROP_CAN_FOCUS:
1189 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1191 case PROP_HAS_FOCUS:
1192 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1194 case PROP_CAN_DEFAULT:
1195 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1197 case PROP_HAS_DEFAULT:
1198 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1200 case PROP_RECEIVES_DEFAULT:
1201 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1203 case PROP_COMPOSITE_CHILD:
1204 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1207 g_value_set_object (value, G_OBJECT (gtk_widget_get_style (widget)));
1210 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
1212 g_value_set_flags (value, 0);
1214 g_value_set_flags (value, *eventp);
1216 case PROP_EXTENSION_EVENTS:
1217 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
1219 g_value_set_enum (value, 0);
1221 g_value_set_enum (value, (GdkExtensionMode) *modep);
1224 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1230 gtk_widget_init (GtkWidget *widget)
1232 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1233 widget->state = GTK_STATE_NORMAL;
1234 widget->saved_state = GTK_STATE_NORMAL;
1235 widget->name = NULL;
1236 widget->requisition.width = 0;
1237 widget->requisition.height = 0;
1238 widget->allocation.x = -1;
1239 widget->allocation.y = -1;
1240 widget->allocation.width = 1;
1241 widget->allocation.height = 1;
1242 widget->window = NULL;
1243 widget->parent = NULL;
1245 GTK_WIDGET_SET_FLAGS (widget,
1247 GTK_PARENT_SENSITIVE |
1248 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1249 GTK_DOUBLE_BUFFERED);
1251 widget->style = gtk_widget_get_default_style ();
1252 g_object_ref (widget->style);
1257 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1259 GParamSpec **pspecs)
1261 GtkWidget *container = widget->parent;
1264 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1265 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1269 gtk_widget_freeze_child_notify (GtkWidget *widget)
1271 g_return_if_fail (GTK_IS_WIDGET (widget));
1273 if (!G_OBJECT (widget)->ref_count)
1276 g_object_ref (widget);
1277 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1278 g_object_unref (widget);
1282 gtk_widget_child_notify (GtkWidget *widget,
1283 const gchar *child_property)
1287 g_return_if_fail (GTK_IS_WIDGET (widget));
1288 g_return_if_fail (child_property != NULL);
1289 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1292 g_object_ref (widget);
1293 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1295 G_OBJECT_TYPE (widget->parent),
1298 g_warning ("%s: container class `%s' has no child property named `%s'",
1300 G_OBJECT_TYPE_NAME (widget->parent),
1304 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1306 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1307 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1309 g_object_unref (widget);
1313 gtk_widget_thaw_child_notify (GtkWidget *widget)
1315 GObjectNotifyQueue *nqueue;
1317 g_return_if_fail (GTK_IS_WIDGET (widget));
1319 if (!G_OBJECT (widget)->ref_count)
1322 g_object_ref (widget);
1323 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1324 if (!nqueue || !nqueue->freeze_count)
1325 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1326 G_OBJECT_TYPE_NAME (widget), widget);
1328 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1329 g_object_unref (widget);
1335 * @type: type ID of the widget to create
1336 * @first_property_name: name of first property to set
1337 * @Varargs: value of first property, followed by more properties, NULL-terminated
1339 * This is a convenience function for creating a widget and setting
1340 * its properties in one go. For example you might write:
1341 * gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1342 * 0.0, NULL) to create a left-aligned label. Equivalent to
1343 * gtk_object_new(), but returns a widget so you don't have to
1344 * cast the object yourself.
1346 * Return value: a new #GtkWidget of type @widget_type
1349 gtk_widget_new (GtkType type,
1350 const gchar *first_property_name,
1356 g_return_val_if_fail (gtk_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1358 va_start (var_args, first_property_name);
1359 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1367 * @widget: a #GtkWidget
1368 * @first_property_name: name of first property to set
1369 * @Varargs: value of first property, followed by more properties, NULL-terminated
1371 * Like gtk_object_set() - there's no reason to use this instead of
1375 gtk_widget_set (GtkWidget *widget,
1376 const gchar *first_property_name,
1381 g_return_if_fail (GTK_IS_WIDGET (widget));
1383 va_start (var_args, first_property_name);
1384 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1389 gtk_widget_queue_clear_child (GtkWidget *widget)
1393 parent = widget->parent;
1394 if (parent && GTK_WIDGET_DRAWABLE (parent))
1395 gtk_widget_queue_clear_area (parent,
1396 widget->allocation.x,
1397 widget->allocation.y,
1398 widget->allocation.width,
1399 widget->allocation.height);
1403 * gtk_widget_unparent:
1404 * @widget: a #GtkWidget
1406 * This function is only for use in widget implementations.
1407 * Should be called by implementations of the remove method
1408 * on #GtkContainer, to dissociate a child from the container.
1411 gtk_widget_unparent (GtkWidget *widget)
1413 GObjectNotifyQueue *nqueue;
1414 GtkWidget *toplevel;
1415 GtkWidget *ancestor;
1416 GtkWidget *old_parent;
1418 g_return_if_fail (GTK_IS_WIDGET (widget));
1419 if (widget->parent == NULL)
1422 /* keep this function in sync with gtk_menu_detach()
1425 g_object_freeze_notify (G_OBJECT (widget));
1426 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1428 /* unset focused and default children properly, this code
1429 * should eventually move into some gtk_window_unparent_branch() or
1433 toplevel = gtk_widget_get_toplevel (widget);
1434 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1436 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1438 if (GTK_WIDGET_TOPLEVEL (toplevel))
1442 child = GTK_WINDOW (toplevel)->focus_widget;
1444 while (child && child != widget)
1445 child = child->parent;
1447 if (child == widget)
1448 gtk_window_set_focus (GTK_WINDOW (toplevel), NULL);
1451 if (GTK_WIDGET_TOPLEVEL (toplevel))
1455 child = GTK_WINDOW (toplevel)->default_widget;
1457 while (child && child != widget)
1458 child = child->parent;
1460 if (child == widget)
1461 gtk_window_set_default (GTK_WINDOW (toplevel), NULL);
1464 /* If we are unanchoring the child, we save around the toplevel
1465 * to emit hierarchy changed
1467 if (GTK_WIDGET_ANCHORED (widget->parent))
1468 g_object_ref (toplevel);
1472 if (GTK_IS_RESIZE_CONTAINER (widget))
1473 _gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
1475 /* Remove the widget and all its children from any ->resize_widgets list
1476 * of all the parents in our branch. This code should move into gtkcontainer.c
1477 * somwhen, since we mess around with ->resize_widgets, which is
1478 * actually not of our business.
1480 * Two ways to make this prettier:
1481 * Write a g_slist_conditional_remove (GSList, gboolean (*)(gpointer))
1482 * Change resize_widgets to a GList
1484 ancestor = widget->parent;
1490 if (!GTK_CONTAINER (ancestor)->resize_widgets)
1492 ancestor = ancestor->parent;
1497 slist = GTK_CONTAINER (ancestor)->resize_widgets;
1509 while (parent && (parent != widget))
1510 parent = parent->parent;
1512 if (parent == widget)
1514 GTK_PRIVATE_UNSET_FLAG (child, GTK_RESIZE_NEEDED);
1519 GTK_CONTAINER (ancestor)->resize_widgets = slist;
1521 g_slist_free_1 (last);
1527 ancestor = ancestor->parent;
1530 gtk_widget_queue_clear_child (widget);
1532 /* Reset the width and height here, to force reallocation if we
1533 * get added back to a new parent. This won't work if our new
1534 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1535 * (would 0x0 be OK here?)
1537 widget->allocation.width = 1;
1538 widget->allocation.height = 1;
1540 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1541 gtk_widget_unrealize (widget);
1543 /* Removing a widget from a container restores the child visible
1544 * flag to the default state, so it doesn't affect the child
1545 * in the next parent.
1547 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1549 old_parent = widget->parent;
1550 widget->parent = NULL;
1551 gtk_widget_set_parent_window (widget, NULL);
1552 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], old_parent);
1555 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1556 g_object_unref (toplevel);
1559 g_object_notify (G_OBJECT (widget), "parent");
1560 g_object_thaw_notify (G_OBJECT (widget));
1561 if (!widget->parent)
1562 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1563 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1564 gtk_widget_unref (widget);
1568 * gtk_widget_destroy:
1569 * @widget: a #GtkWidget
1571 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1572 * you don't have to cast the widget to #GtkObject. When a widget is
1573 * destroyed, it will break any references it holds to other objects.
1574 * If the widget is inside a container, the widget will be removed
1575 * from the container. If the widget is a toplevel (derived from
1576 * #GtkWindow), it will be removed from the list of toplevels, and the
1577 * reference GTK+ holds to it will be removed. Removing a
1578 * widget from its container or the list of toplevels results in the
1579 * widget being finalized, unless you've added additional references
1580 * to the widget with gtk_object_ref().
1582 * In most cases, only toplevel widgets (windows) require explicit
1583 * destruction, because when you destroy a toplevel its children will
1584 * be destroyed as well.
1588 gtk_widget_destroy (GtkWidget *widget)
1590 g_return_if_fail (GTK_IS_WIDGET (widget));
1592 gtk_object_destroy ((GtkObject*) widget);
1596 * gtk_widget_destroyed:
1597 * @widget: a #GtkWidget
1598 * @widget_pointer: address of a variable that contains @widget
1600 * This function sets *@widget_pointer to NULL if @widget_pointer !=
1601 * NULL. It's intended to be used as a callback connected to the
1602 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1603 * as a signal handler, and pass the address of your widget variable
1604 * as user data. Then when the widget is destroyed, the variable will
1605 * be set to NULL. Useful for example to avoid multiple copies
1606 * of the same dialog.
1610 gtk_widget_destroyed (GtkWidget *widget,
1611 GtkWidget **widget_pointer)
1613 /* Don't make any assumptions about the
1615 * Even check widget_pointer.
1618 *widget_pointer = NULL;
1623 * @widget: a #GtkWidget
1625 * Flags a widget to be displayed. Any widget that isn't shown will
1626 * not appear on the screen. If you want to show all the widgets in a
1627 * container, it's easier to call gtk_widget_show_all() on the
1628 * container, instead of individually showing the widgets.
1630 * Remember that you have to show the containers containing a widget,
1631 * in addition to the widget itself, before it will appear onscreen.
1633 * When a toplevel container is shown, it is immediately realized and
1634 * mapped; other shown widgets are realized and mapped when their
1635 * toplevel container is realized and mapped.
1639 gtk_widget_show (GtkWidget *widget)
1641 g_return_if_fail (GTK_IS_WIDGET (widget));
1643 if (!GTK_WIDGET_VISIBLE (widget))
1645 g_object_ref (G_OBJECT (widget));
1646 if (!GTK_WIDGET_TOPLEVEL (widget))
1647 gtk_widget_queue_resize (widget);
1648 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SHOW]);
1649 g_object_notify (G_OBJECT (widget), "visible");
1650 g_object_unref (G_OBJECT (widget));
1655 gtk_widget_real_show (GtkWidget *widget)
1657 g_return_if_fail (GTK_IS_WIDGET (widget));
1659 if (!GTK_WIDGET_VISIBLE (widget))
1661 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1663 if (widget->parent &&
1664 GTK_WIDGET_MAPPED (widget->parent) &&
1665 GTK_WIDGET_CHILD_VISIBLE (widget) &&
1666 !GTK_WIDGET_MAPPED (widget))
1667 gtk_widget_map (widget);
1672 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1675 gtk_signal_disconnect_by_data (GTK_OBJECT (widget), flag);
1679 * gtk_widget_show_now:
1680 * @widget: a #GtkWidget
1682 * Shows a widget. If the widget is an unmapped toplevel widget
1683 * (i.e. a #GtkWindow that has not yet been shown), enter the main
1684 * loop and wait for the window to actually be mapped. Be careful;
1685 * because the main loop is running, anything can happen during
1689 gtk_widget_show_now (GtkWidget *widget)
1693 g_return_if_fail (GTK_IS_WIDGET (widget));
1695 /* make sure we will get event */
1696 if (!GTK_WIDGET_MAPPED (widget) &&
1697 GTK_WIDGET_TOPLEVEL (widget))
1699 gtk_widget_show (widget);
1701 gtk_signal_connect (GTK_OBJECT (widget), "map_event",
1702 GTK_SIGNAL_FUNC (gtk_widget_show_map_callback),
1706 gtk_main_iteration();
1709 gtk_widget_show (widget);
1714 * @widget: a #GtkWidget
1716 * Reverses the effects of gtk_widget_show(), causing the widget to be
1717 * hidden (invisible to the user).
1720 gtk_widget_hide (GtkWidget *widget)
1722 g_return_if_fail (GTK_IS_WIDGET (widget));
1724 if (GTK_WIDGET_VISIBLE (widget))
1726 gtk_widget_ref (widget);
1727 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[HIDE]);
1728 if (!GTK_WIDGET_TOPLEVEL (widget) && GTK_WIDGET_REALIZED (widget))
1729 gtk_widget_queue_resize (widget);
1730 g_object_notify (G_OBJECT (widget), "visible");
1731 gtk_widget_unref (widget);
1736 gtk_widget_real_hide (GtkWidget *widget)
1738 g_return_if_fail (GTK_IS_WIDGET (widget));
1740 if (GTK_WIDGET_VISIBLE (widget))
1742 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
1744 if (GTK_WIDGET_MAPPED (widget))
1745 gtk_widget_unmap (widget);
1750 * gtk_widget_hide_on_delete:
1751 * @widget: a #GtkWidget
1753 * Utility function; intended to be connected to the "delete_event"
1754 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
1755 * argument, then returns %TRUE. If connected to "delete_event",
1756 * the result is that clicking the window manager close button for
1757 * will hide but not destroy the window. By default, GTK+ destroys
1758 * windows when "delete_event" is received.
1760 * Return value: %TRUE
1763 gtk_widget_hide_on_delete (GtkWidget *widget)
1765 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1767 gtk_widget_hide (widget);
1773 * gtk_widget_show_all:
1774 * @widget: a #GtkWidget
1776 * Recursively shows a widget, and any child widgets (if the widget is
1780 gtk_widget_show_all (GtkWidget *widget)
1782 GtkWidgetClass *class;
1784 g_return_if_fail (GTK_IS_WIDGET (widget));
1786 class = GTK_WIDGET_GET_CLASS (widget);
1788 if (class->show_all)
1789 class->show_all (widget);
1793 * gtk_widget_hide_all:
1794 * @widget: a #GtkWidget
1796 * Recursively hides a widget and any child widgets.
1799 gtk_widget_hide_all (GtkWidget *widget)
1801 GtkWidgetClass *class;
1803 g_return_if_fail (GTK_IS_WIDGET (widget));
1805 class = GTK_WIDGET_GET_CLASS (widget);
1807 if (class->hide_all)
1808 class->hide_all (widget);
1813 * @widget: a #GtkWidget
1815 * This function is only for use in widget implementations. Causes
1816 * a widget to be mapped if it isn't already.
1820 gtk_widget_map (GtkWidget *widget)
1822 g_return_if_fail (GTK_IS_WIDGET (widget));
1823 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
1824 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
1826 if (!GTK_WIDGET_MAPPED (widget))
1828 if (!GTK_WIDGET_REALIZED (widget))
1829 gtk_widget_realize (widget);
1831 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[MAP]);
1833 if (GTK_WIDGET_NO_WINDOW (widget))
1834 gtk_widget_queue_draw (widget);
1840 * @widget: a #GtkWidget
1842 * This function is only for use in widget implementations. Causes
1843 * a widget to be unmapped if it's currently mapped.
1847 gtk_widget_unmap (GtkWidget *widget)
1849 g_return_if_fail (GTK_IS_WIDGET (widget));
1851 if (GTK_WIDGET_MAPPED (widget))
1853 if (GTK_WIDGET_NO_WINDOW (widget))
1854 gtk_widget_queue_clear_child (widget);
1855 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNMAP]);
1860 * gtk_widget_realize:
1861 * @widget: a #GtkWidget
1863 * Creates the GDK (windowing system) resources associated with a
1864 * widget. For example, widget->window will be created when a widget
1865 * is realized. Normally realization happens implicitly; if you show
1866 * a widget and all its parent containers, then the widget will be
1867 * realized and mapped automatically.
1869 * Realizing a widget requires all
1870 * the widget's parent widgets to be realized; calling
1871 * gtk_widget_realize() realizes the widget's parents in addition to
1872 * @widget itself. If a widget is not yet inside a toplevel window
1873 * when you realize it, bad things will happen.
1875 * This function is primarily used in widget implementations, and
1876 * isn't very useful otherwise. Many times when you think you might
1877 * need it, a better approach is to connect to a signal that will be
1878 * called after the widget is realized automatically, such as
1879 * "expose_event". Or simply gtk_signal_connect_after() to the
1884 gtk_widget_realize (GtkWidget *widget)
1887 GdkExtensionMode mode;
1888 GtkWidgetShapeInfo *shape_info;
1890 g_return_if_fail (GTK_IS_WIDGET (widget));
1892 if (!GTK_WIDGET_REALIZED (widget))
1895 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1896 g_message ("gtk_widget_realize(%s)", gtk_type_name (GTK_WIDGET_TYPE (widget)));
1899 if (widget->parent == NULL &&
1900 !GTK_WIDGET_TOPLEVEL (widget))
1901 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
1902 "inside a toplevel window is not going to work very well. "
1903 "Widgets must be inside a toplevel container before realizing them.");
1905 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
1906 gtk_widget_realize (widget->parent);
1908 gtk_widget_ensure_style (widget);
1910 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[REALIZE]);
1912 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1914 shape_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_shape_info);
1915 gdk_window_shape_combine_mask (widget->window,
1916 shape_info->shape_mask,
1917 shape_info->offset_x,
1918 shape_info->offset_y);
1921 if (!GTK_WIDGET_NO_WINDOW (widget))
1923 mode = gtk_widget_get_extension_events (widget);
1924 if (mode != GDK_EXTENSION_EVENTS_NONE)
1926 events = gtk_widget_get_events (widget);
1927 gdk_input_set_extension_events (widget->window, events, mode);
1935 * gtk_widget_unrealize:
1936 * @widget: a #GtkWidget
1938 * This function is only useful in widget implementations.
1939 * Causes a widget to be unrealized (frees all GDK resources
1940 * associated with the widget, such as widget->window).
1944 gtk_widget_unrealize (GtkWidget *widget)
1946 g_return_if_fail (GTK_IS_WIDGET (widget));
1948 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
1949 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
1951 if (GTK_WIDGET_REALIZED (widget))
1953 gtk_widget_ref (widget);
1954 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[UNREALIZE]);
1955 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
1956 gtk_widget_unref (widget);
1960 /*****************************************
1962 *****************************************/
1965 * gtk_widget_queue_draw_area:
1966 * @widget: a #GtkWidget
1967 * @x: x coordinate of upper-left corner of rectangle to redraw
1968 * @y: y coordinate of upper-left corner of rectangle to redraw
1969 * @width: width of region to draw
1970 * @height: height of region to draw
1972 * Invalidates the rectangular area of @widget defined by @x, @y,
1973 * @width and @height by calling gdk_window_invalidate_rect() on the
1974 * widget's window and all its child windows. Once the main loop
1975 * becomes idle (after the current batch of events has been processed,
1976 * roughly), the window will receive expose events for the union of
1977 * all regions that have been invalidated.
1979 * Normally you would only use this function in widget
1980 * implementations. You might also use it, or
1981 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
1982 * #GtkDrawingArea or some portion thereof.
1984 * Frequently you can just call gdk_window_invalidate_rect() or
1985 * gdk_window_invalidate_region() instead of this function. Those
1986 * functions will invalidate only a single window, instead of the
1987 * widget and all its children.
1989 * The advantage of adding to the invalidated region compared to
1990 * simply drawing immediately is efficiency; using an invalid region
1991 * ensures that you only have to redraw one time.
1995 gtk_widget_queue_draw_area (GtkWidget *widget,
2001 g_return_if_fail (GTK_IS_WIDGET (widget));
2003 gtk_widget_queue_clear_area (widget, x, y, width, height);
2007 * gtk_widget_queue_draw:
2008 * @widget: a #GtkWidget
2010 * Equivalent to calling gtk_widget_queue_draw_area() for the
2011 * entire area of a widget.
2015 gtk_widget_queue_draw (GtkWidget *widget)
2017 g_return_if_fail (GTK_IS_WIDGET (widget));
2019 gtk_widget_queue_clear (widget);
2022 /* Invalidates the given area (allocation-relative-coordinates)
2023 * in all of the widget's windows
2026 * gtk_widget_queue_clear_area:
2027 * @widget: a #GtkWidget
2028 * @x: x coordinate of upper-left corner of rectangle to redraw
2029 * @y: y coordinate of upper-left corner of rectangle to redraw
2030 * @width: width of region to draw
2031 * @height: height of region to draw
2033 * DEPRECATED. This function is no longer different from
2034 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2035 * gtk_widget_queue_draw_area(). Originally
2036 * gtk_widget_queue_clear_area() would force a redraw of the
2037 * background for GTK_NO_WINDOW widgets, and
2038 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2039 * the background will be redrawn.
2043 gtk_widget_queue_clear_area (GtkWidget *widget,
2049 GdkRectangle invalid_rect;
2051 g_return_if_fail (GTK_IS_WIDGET (widget));
2053 if (!(widget->window && gdk_window_is_viewable (widget->window)))
2056 /* Find the correct widget */
2058 if (!GTK_WIDGET_NO_WINDOW (widget))
2062 /* Translate widget relative to window-relative */
2064 gint wx, wy, wwidth, wheight;
2066 gdk_window_get_position (widget->window, &wx, &wy);
2067 x -= wx - widget->allocation.x;
2068 y -= wy - widget->allocation.y;
2070 gdk_window_get_size (widget->window, &wwidth, &wheight);
2072 if (x + width <= 0 || y + height <= 0 ||
2073 x >= wwidth || y >= wheight)
2084 if (x + width > wwidth)
2086 if (y + height > wheight)
2087 height = wheight - y;
2093 invalid_rect.width = width;
2094 invalid_rect.height = height;
2096 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2100 * gtk_widget_queue_clear:
2101 * @widget: a #GtkWidget
2103 * DEPRECATED. Use gtk_widget_queue_draw() instead.
2106 gtk_widget_queue_clear (GtkWidget *widget)
2108 g_return_if_fail (GTK_IS_WIDGET (widget));
2110 if (widget->allocation.width || widget->allocation.height)
2112 if (GTK_WIDGET_NO_WINDOW (widget))
2113 gtk_widget_queue_clear_area (widget, widget->allocation.x,
2114 widget->allocation.y,
2115 widget->allocation.width,
2116 widget->allocation.height);
2118 gtk_widget_queue_clear_area (widget, 0, 0,
2119 widget->allocation.width,
2120 widget->allocation.height);
2125 * gtk_widget_queue_resize:
2126 * @widget: a #GtkWidget
2128 * This function is only for use in widget implementations.
2129 * Flags a widget to have its size renegotiated; should
2130 * be called when a widget for some reason has a new size request.
2131 * For example, when you change the text in a #GtkLabel, #GtkLabel
2132 * queues a resize to ensure there's enough space for the new text.
2136 gtk_widget_queue_resize (GtkWidget *widget)
2138 g_return_if_fail (GTK_IS_WIDGET (widget));
2140 gtk_widget_queue_clear (widget);
2142 _gtk_size_group_queue_resize (widget);
2147 * @widget: a #GtkWidget
2148 * @area: area to draw
2150 * DEPRECATED. In GTK+ 1.2, this function would immediately render the
2151 * region @area of a widget, by invoking the virtual draw method of a
2152 * widget. In GTK+ 2.0, the draw method is gone, and instead
2153 * gtk_widget_draw() simply invalidates the specified region of the
2154 * widget, then updates the invalid region of the widget immediately.
2155 * Usually you don't want to update the region immediately for
2156 * performance reasons, so in general gtk_widget_queue_draw_area() is
2157 * a better choice if you want to draw a region of a widget.
2161 gtk_widget_draw (GtkWidget *widget,
2164 g_return_if_fail (GTK_IS_WIDGET (widget));
2166 if (GTK_WIDGET_DRAWABLE (widget))
2169 gtk_widget_queue_draw_area (widget,
2171 area->width, area->height);
2173 gtk_widget_queue_draw (widget);
2175 gdk_window_process_updates (widget->window, TRUE);
2180 * gtk_widget_size_request:
2181 * @widget: a #GtkWidget
2182 * @requisition: a #GtkRequisition to be filled in
2184 * This function is typically used when implementing a #GtkContainer
2185 * subclass. Obtains the preferred size of a widget. The container
2186 * uses this information to arrange its child widgets and decide what
2187 * size allocations to give them with gtk_widget_size_allocate().
2189 * You can also call this function from an application, with some
2190 * caveats. Most notably, getting a size request requires the widget
2191 * to be associated with a screen, because font information may be
2192 * needed. Multihead-aware applications should keep this in mind.
2194 * Also remember that the size request is not necessarily the size
2195 * a widget will actually be allocated.
2197 * See also gtk_widget_get_child_requisition().
2200 gtk_widget_size_request (GtkWidget *widget,
2201 GtkRequisition *requisition)
2203 g_return_if_fail (GTK_IS_WIDGET (widget));
2205 #ifdef G_ENABLE_DEBUG
2206 if (requisition == &widget->requisition)
2207 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.");
2208 #endif /* G_ENABLE_DEBUG */
2210 _gtk_size_group_compute_requisition (widget, requisition);
2214 gtk_widget_get_child_requisition (widget, requisition);
2216 gtk_widget_unref (widget);
2221 * gtk_widget_get_child_requisition:
2222 * @widget: a #GtkWidget
2223 * @requisition: a #GtkRequisition to be filled in
2225 * This function is only for use in widget implementations. Obtains
2226 * @widget->requisition, unless someone has forced a particular
2227 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2228 * case it returns that geometry instead of the widget's requisition.
2230 * This function differs from gtk_widget_size_request() in that
2231 * it retrieves the last size request value from widget->requisition,
2232 * while gtk_widget_size_request() actually calls the "size_request" method
2233 * on @widget to compute the size request and fill in widget->requisition,
2234 * and only then returns widget->requisition.
2236 * Because this function does not call the "size_request" method, it
2237 * can only be used when you know that widget->requisition is
2238 * up-to-date, that is, gtk_widget_size_request() has been called
2239 * since the last time a resize was queued. In general, only container
2240 * implementations have this information; applications should use
2241 * gtk_widget_size_request().
2244 gtk_widget_get_child_requisition (GtkWidget *widget,
2245 GtkRequisition *requisition)
2247 _gtk_size_group_get_child_requisition (widget, requisition);
2251 * gtk_widget_size_allocate:
2252 * @widget: a #GtkWidget
2253 * @allocation: position and size to be allocated to @widget
2255 * This function is only used by #GtkContainer subclasses, to assign a size
2256 * and position to their child widgets.
2260 gtk_widget_size_allocate (GtkWidget *widget,
2261 GtkAllocation *allocation)
2263 GtkWidgetAuxInfo *aux_info;
2264 GtkAllocation real_allocation;
2265 gboolean needs_draw = FALSE;
2267 g_return_if_fail (GTK_IS_WIDGET (widget));
2269 real_allocation = *allocation;
2270 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2274 if (aux_info->x_set)
2275 real_allocation.x = aux_info->x;
2276 if (aux_info->y_set)
2277 real_allocation.y = aux_info->y;
2280 if (real_allocation.width < 0 || real_allocation.height < 0)
2282 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2283 real_allocation.width,
2284 real_allocation.height);
2287 real_allocation.width = MAX (real_allocation.width, 1);
2288 real_allocation.height = MAX (real_allocation.height, 1);
2290 if (GTK_WIDGET_NO_WINDOW (widget))
2292 if (widget->allocation.x != real_allocation.x ||
2293 widget->allocation.y != real_allocation.y ||
2294 widget->allocation.width != real_allocation.width ||
2295 widget->allocation.height != real_allocation.height)
2297 gtk_widget_queue_clear_child (widget);
2301 else if (widget->allocation.width != real_allocation.width ||
2302 widget->allocation.height != real_allocation.height)
2307 if (GTK_IS_RESIZE_CONTAINER (widget))
2308 _gtk_container_clear_resize_widgets (GTK_CONTAINER (widget));
2310 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[SIZE_ALLOCATE], &real_allocation);
2314 gtk_widget_queue_draw (widget);
2315 if (widget->parent && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2316 gtk_widget_queue_draw (widget->parent);
2321 gtk_widget_real_size_allocate (GtkWidget *widget,
2322 GtkAllocation *allocation)
2324 g_return_if_fail (GTK_IS_WIDGET (widget));
2326 widget->allocation = *allocation;
2328 if (GTK_WIDGET_REALIZED (widget) &&
2329 !GTK_WIDGET_NO_WINDOW (widget))
2331 gdk_window_move_resize (widget->window,
2332 allocation->x, allocation->y,
2333 allocation->width, allocation->height);
2338 gtk_widget_stop_add_accelerator (GtkWidget *widget)
2340 g_return_if_fail (GTK_IS_WIDGET (widget));
2342 gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[ADD_ACCELERATOR]);
2346 gtk_widget_stop_remove_accelerator (GtkWidget *widget)
2348 g_return_if_fail (GTK_IS_WIDGET (widget));
2350 gtk_signal_emit_stop (GTK_OBJECT (widget), widget_signals[REMOVE_ACCELERATOR]);
2354 gtk_widget_lock_accelerators (GtkWidget *widget)
2356 g_return_if_fail (GTK_IS_WIDGET (widget));
2358 if (!gtk_widget_accelerators_locked (widget))
2360 gtk_signal_connect (GTK_OBJECT (widget),
2362 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2364 gtk_signal_connect (GTK_OBJECT (widget),
2365 "remove_accelerator",
2366 GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2372 gtk_widget_unlock_accelerators (GtkWidget *widget)
2374 g_return_if_fail (GTK_IS_WIDGET (widget));
2376 if (gtk_widget_accelerators_locked (widget))
2378 gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2379 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2381 gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
2382 GTK_SIGNAL_FUNC (gtk_widget_stop_remove_accelerator),
2388 gtk_widget_accelerators_locked (GtkWidget *widget)
2390 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2392 return gtk_signal_handler_pending_by_func (GTK_OBJECT (widget),
2393 widget_signals[ADD_ACCELERATOR],
2395 GTK_SIGNAL_FUNC (gtk_widget_stop_add_accelerator),
2400 gtk_widget_add_accelerator (GtkWidget *widget,
2401 const gchar *accel_signal,
2402 GtkAccelGroup *accel_group,
2405 GtkAccelFlags accel_flags)
2407 g_return_if_fail (GTK_IS_WIDGET (widget));
2408 g_return_if_fail (accel_group != NULL);
2410 gtk_accel_group_add (accel_group,
2419 gtk_widget_remove_accelerator (GtkWidget *widget,
2420 GtkAccelGroup *accel_group,
2424 g_return_if_fail (GTK_IS_WIDGET (widget));
2425 g_return_if_fail (accel_group != NULL);
2427 gtk_accel_group_remove (accel_group,
2434 gtk_widget_remove_accelerators (GtkWidget *widget,
2435 const gchar *accel_signal,
2436 gboolean visible_only)
2441 g_return_if_fail (GTK_IS_WIDGET (widget));
2442 g_return_if_fail (accel_signal != NULL);
2444 signal_id = gtk_signal_lookup (accel_signal, GTK_OBJECT_TYPE (widget));
2445 g_return_if_fail (signal_id != 0);
2447 slist = gtk_accel_group_entries_from_object (G_OBJECT (widget));
2450 GtkAccelEntry *ac_entry;
2452 ac_entry = slist->data;
2453 slist = slist->next;
2454 if (ac_entry->accel_flags & GTK_ACCEL_VISIBLE &&
2455 ac_entry->signal_id == signal_id)
2456 gtk_widget_remove_accelerator (GTK_WIDGET (widget),
2457 ac_entry->accel_group,
2458 ac_entry->accelerator_key,
2459 ac_entry->accelerator_mods);
2464 gtk_widget_accelerator_signal (GtkWidget *widget,
2465 GtkAccelGroup *accel_group,
2469 GtkAccelEntry *ac_entry;
2471 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
2472 g_return_val_if_fail (accel_group != NULL, 0);
2474 ac_entry = gtk_accel_group_get_entry (accel_group, accel_key, accel_mods);
2476 if (ac_entry && ac_entry->object == (GObject*) widget)
2477 return ac_entry->signal_id;
2482 gtk_widget_mnemonic_activate (GtkWidget *widget,
2483 gboolean group_cycling)
2487 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2489 group_cycling = group_cycling != FALSE;
2490 if (!GTK_WIDGET_IS_SENSITIVE (widget))
2493 gtk_signal_emit (GTK_OBJECT (widget),
2494 widget_signals[ACTIVATE_MNEMONIC],
2501 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
2502 gboolean group_cycling)
2504 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
2505 gtk_widget_activate (widget);
2506 else if (GTK_WIDGET_CAN_FOCUS (widget))
2507 gtk_widget_grab_focus (widget);
2510 g_warning ("widget `%s' isn't suitable for mnemonic activation",
2511 G_OBJECT_TYPE_NAME (widget));
2518 gtk_widget_real_key_press_event (GtkWidget *widget,
2521 gboolean handled = FALSE;
2523 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2524 g_return_val_if_fail (event != NULL, handled);
2527 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2535 gtk_widget_real_key_release_event (GtkWidget *widget,
2538 gboolean handled = FALSE;
2540 g_return_val_if_fail (GTK_IS_WIDGET (widget), handled);
2541 g_return_val_if_fail (event != NULL, handled);
2544 handled = gtk_bindings_activate (GTK_OBJECT (widget),
2546 event->state | GDK_RELEASE_MASK);
2552 gtk_widget_real_focus_in_event (GtkWidget *widget,
2553 GdkEventFocus *event)
2555 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
2556 gtk_widget_queue_draw (widget);
2562 gtk_widget_real_focus_out_event (GtkWidget *widget,
2563 GdkEventFocus *event)
2565 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
2566 gtk_widget_queue_draw (widget);
2573 * @widget: a #GtkWidget
2574 * @event: a #GdkEvent
2576 * Rarely-used function. This function is used to emit
2577 * the event signals on a widget (those signals should never
2578 * be emitted without using this function to do so).
2579 * If you want to synthesize an event though, don't use this function;
2580 * instead, use gtk_main_do_event() so the event will behave as if
2581 * it were in the event queue. Don't synthesize expose events; instead,
2582 * use gdk_window_invalidate_rect() to invalidate a region of the
2585 * Return value: return from the event signal emission (%TRUE if the event was handled)
2588 gtk_widget_event (GtkWidget *widget,
2591 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2592 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
2594 if (event->type == GDK_EXPOSE)
2596 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
2597 "the same effect, call gdk_window_invalidate_rect/region(), "
2598 "followed by gdk_window_process_updates().");
2602 return gtk_widget_event_internal (widget, event);
2607 * gtk_widget_send_expose:
2608 * @widget: a #GtkWidget
2609 * @event: a expose #GdkEvent
2611 * Very rarely-used function. This function is used to emit
2612 * an expose event signals on a widget. This function is not
2613 * normally used directly. The only time it is used is when
2614 * propagating an expose event to a child NO_WINDOW widget, and
2615 * that is normally done using gtk_container_propagate_expose.
2617 * If you want to force an area of a window to be redrawn,
2618 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
2619 * To cause the redraw to be done immediately, follow that call
2620 * with a call to gdk_window_procss_updates().
2622 * Return value: return from the event signal emission (%TRUE if the event was handled)
2625 gtk_widget_send_expose (GtkWidget *widget,
2628 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
2629 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
2630 g_return_val_if_fail (event != NULL, TRUE);
2631 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
2633 if (event->type != GDK_EXPOSE)
2636 return gtk_widget_event_internal (widget, event);
2640 gtk_widget_event_internal (GtkWidget *widget,
2643 gboolean return_val = FALSE;
2645 gtk_widget_ref (widget);
2647 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT], event, &return_val);
2648 return_val |= !GTK_WIDGET_REALIZED (widget);
2653 switch (event->type)
2658 case GDK_BUTTON_PRESS:
2659 case GDK_2BUTTON_PRESS:
2660 case GDK_3BUTTON_PRESS:
2661 signal_num = BUTTON_PRESS_EVENT;
2664 signal_num = SCROLL_EVENT;
2666 case GDK_BUTTON_RELEASE:
2667 signal_num = BUTTON_RELEASE_EVENT;
2669 case GDK_MOTION_NOTIFY:
2670 signal_num = MOTION_NOTIFY_EVENT;
2673 signal_num = DELETE_EVENT;
2676 signal_num = DESTROY_EVENT;
2679 signal_num = KEY_PRESS_EVENT;
2681 case GDK_KEY_RELEASE:
2682 signal_num = KEY_RELEASE_EVENT;
2684 case GDK_ENTER_NOTIFY:
2685 signal_num = ENTER_NOTIFY_EVENT;
2687 case GDK_LEAVE_NOTIFY:
2688 signal_num = LEAVE_NOTIFY_EVENT;
2690 case GDK_FOCUS_CHANGE:
2691 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
2694 signal_num = CONFIGURE_EVENT;
2697 signal_num = MAP_EVENT;
2700 signal_num = UNMAP_EVENT;
2702 case GDK_WINDOW_STATE:
2703 signal_num = WINDOW_STATE_EVENT;
2705 case GDK_PROPERTY_NOTIFY:
2706 signal_num = PROPERTY_NOTIFY_EVENT;
2708 case GDK_SELECTION_CLEAR:
2709 signal_num = SELECTION_CLEAR_EVENT;
2711 case GDK_SELECTION_REQUEST:
2712 signal_num = SELECTION_REQUEST_EVENT;
2714 case GDK_SELECTION_NOTIFY:
2715 signal_num = SELECTION_NOTIFY_EVENT;
2717 case GDK_PROXIMITY_IN:
2718 signal_num = PROXIMITY_IN_EVENT;
2720 case GDK_PROXIMITY_OUT:
2721 signal_num = PROXIMITY_OUT_EVENT;
2724 signal_num = NO_EXPOSE_EVENT;
2726 case GDK_CLIENT_EVENT:
2727 signal_num = CLIENT_EVENT;
2730 signal_num = EXPOSE_EVENT;
2732 case GDK_VISIBILITY_NOTIFY:
2733 signal_num = VISIBILITY_NOTIFY_EVENT;
2736 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
2740 if (signal_num != -1)
2741 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[signal_num], event, &return_val);
2743 if (GTK_WIDGET_REALIZED (widget))
2744 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[EVENT_AFTER], event);
2748 gtk_widget_unref (widget);
2754 * gtk_widget_activate:
2755 * @widget: a #GtkWidget that's activatable
2757 * For widgets that can be "activated" (buttons, menu items, etc.)
2758 * this function activates them. Activation is what happens when you
2759 * press Enter on a widget during key navigation; clicking a button,
2760 * selecting a menu item, etc. If @widget isn't activatable,
2761 * the function returns %FALSE.
2763 * Return value: %TRUE if the widget was activatable
2766 gtk_widget_activate (GtkWidget *widget)
2768 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2770 if (WIDGET_CLASS (widget)->activate_signal)
2772 /* FIXME: we should eventually check the signals signature here */
2773 gtk_signal_emit (GTK_OBJECT (widget), WIDGET_CLASS (widget)->activate_signal);
2782 * gtk_widget_set_scroll_adjustments:
2783 * @widget: a #GtkWidget
2784 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
2785 * @vadjustment: an adjustment for vertical scrolling, or %NULL
2787 * For widgets that support scrolling, sets the scroll adjustments and
2788 * returns %TRUE. For widgets that don't support scrolling, does
2789 * nothing and returns %FALSE. Widgets that don't support scrolling
2790 * can be scrolled by placing them in a #GtkViewport, which does
2791 * support scrolling.
2793 * Return value: %TRUE if the widget supports scrolling
2796 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
2797 GtkAdjustment *hadjustment,
2798 GtkAdjustment *vadjustment)
2800 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2802 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
2804 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
2806 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
2808 /* FIXME: we should eventually check the signals signature here */
2809 gtk_signal_emit (GTK_OBJECT (widget),
2810 WIDGET_CLASS (widget)->set_scroll_adjustments_signal,
2811 hadjustment, vadjustment);
2818 /*****************************************
2819 * gtk_widget_reparent_container_child:
2820 * assistent function to gtk_widget_reparent
2825 *****************************************/
2828 gtk_widget_reparent_container_child (GtkWidget *widget,
2829 gpointer client_data)
2831 g_return_if_fail (GTK_IS_WIDGET (widget));
2832 g_return_if_fail (client_data != NULL);
2834 if (GTK_WIDGET_NO_WINDOW (widget))
2837 gdk_window_unref (widget->window);
2838 widget->window = (GdkWindow*) client_data;
2840 gdk_window_ref (widget->window);
2842 if (GTK_IS_CONTAINER (widget))
2843 gtk_container_forall (GTK_CONTAINER (widget),
2844 gtk_widget_reparent_container_child,
2848 gdk_window_reparent (widget->window,
2849 (GdkWindow*) client_data, 0, 0);
2853 * gtk_widget_reparent:
2854 * @widget: a #GtkWidget
2855 * @new_parent: a #GtkContainer to move the widget into
2857 * Moves a widget from one #GtkContainer to another, handling reference
2858 * count issues to avoid destroying the widget.
2862 gtk_widget_reparent (GtkWidget *widget,
2863 GtkWidget *new_parent)
2865 g_return_if_fail (GTK_IS_WIDGET (widget));
2866 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
2867 g_return_if_fail (widget->parent != NULL);
2869 if (widget->parent != new_parent)
2871 /* First try to see if we can get away without unrealizing
2872 * the widget as we reparent it. if so we set a flag so
2873 * that gtk_widget_unparent doesn't unrealize widget
2875 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
2876 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
2878 gtk_widget_ref (widget);
2879 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
2880 gtk_container_add (GTK_CONTAINER (new_parent), widget);
2881 gtk_widget_unref (widget);
2883 if (GTK_WIDGET_IN_REPARENT (widget))
2885 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
2887 gtk_widget_reparent_container_child (widget,
2888 gtk_widget_get_parent_window (widget));
2894 * gtk_widget_intersect:
2895 * @widget: a #GtkWidget
2896 * @area: a rectangle
2897 * @intersection: rectangle to store intersection of @widget and @area
2899 * Computes the intersection of a @widget's area and @area, storing
2900 * the intersection in @intersection, and returns %TRUE if there was
2901 * an intersection. @intersection may be %NULL if you're only
2902 * interested in whether there was an intersection.
2904 * Return value: %TRUE if there was an intersection
2907 gtk_widget_intersect (GtkWidget *widget,
2909 GdkRectangle *intersection)
2915 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2916 g_return_val_if_fail (area != NULL, FALSE);
2919 dest = intersection;
2923 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
2925 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
2927 intersection->x -= widget->allocation.x;
2928 intersection->y -= widget->allocation.y;
2935 * gtk_widget_region_intersect:
2936 * @widget: a #GtkWidget
2937 * @region: a #GdkRegion, in the same coordinate system as
2938 * widget->allocation. That is, relative to widget->window
2939 * for NO_WINDOW widgets; relative to the parent window
2940 * of widget->window for widgets with their own window.
2941 * @returns: A newly allocated region holding the intersection of @widget
2942 * and @region. The coordinates of the return value are
2943 * relative to widget->window for NO_WINDOW widgets, and
2944 * relative to the parent window of widget->window for
2945 * widgets with their own window.
2947 * Computes the intersection of a @widget's area and @region, returning
2948 * the intersection. The result may be empty, use #gdk_region_empty to
2952 gtk_widget_region_intersect (GtkWidget *widget,
2957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
2958 g_return_val_if_fail (region != NULL, NULL);
2960 dest = gdk_region_rectangle (&widget->allocation);
2962 gdk_region_intersect (dest, region);
2968 * gtk_widget_grab_focus:
2969 * @widget: a #GtkWidget
2971 * Causes @widget to have the keyboard focus for the #GtkWindow it's
2972 * inside. @widget must be a focusable widget, such as a #GtkEntry;
2973 * something like #GtkFrame won't work. (More precisely, it must have the
2974 * #GTK_CAN_FOCUS flag set.)
2978 gtk_widget_grab_focus (GtkWidget *widget)
2980 g_return_if_fail (GTK_IS_WIDGET (widget));
2982 g_object_ref (G_OBJECT (widget));
2983 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[GRAB_FOCUS]);
2984 g_object_notify (G_OBJECT (widget), "has_focus");
2985 g_object_unref (G_OBJECT (widget));
2989 reset_focus_recurse (GtkWidget *widget,
2992 if (GTK_IS_CONTAINER (widget))
2994 GtkContainer *container;
2996 container = GTK_CONTAINER (widget);
2997 gtk_container_set_focus_child (container, NULL);
2999 gtk_container_foreach (container,
3000 reset_focus_recurse,
3006 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3008 g_return_if_fail (GTK_IS_WIDGET (focus_widget));
3010 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3012 GtkWidget *toplevel;
3015 /* clear the current focus setting, break if the current widget
3016 * is the focus widget's parent, since containers above that will
3017 * be set by the next loop.
3019 toplevel = gtk_widget_get_toplevel (focus_widget);
3020 if (GTK_WIDGET_TOPLEVEL (toplevel))
3022 widget = GTK_WINDOW (toplevel)->focus_widget;
3024 if (widget == focus_widget)
3026 /* We call gtk_window_set_focus() here so that the
3027 * toplevel window can request the focus if necessary.
3028 * This is needed when the toplevel is a GtkPlug
3030 if (!GTK_WIDGET_HAS_FOCUS (widget))
3031 gtk_window_set_focus (GTK_WINDOW (toplevel), focus_widget);
3038 while (widget->parent && widget->parent != focus_widget->parent)
3040 widget = widget->parent;
3041 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3045 else if (toplevel != focus_widget)
3047 /* gtk_widget_grab_focus() operates on a tree without window...
3048 * actually, this is very questionable behaviour.
3051 gtk_container_foreach (GTK_CONTAINER (toplevel),
3052 reset_focus_recurse,
3056 /* now propagate the new focus up the widget tree and finally
3057 * set it on the window
3059 widget = focus_widget;
3060 while (widget->parent)
3062 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3063 widget = widget->parent;
3065 if (GTK_IS_WINDOW (widget))
3066 gtk_window_set_focus (GTK_WINDOW (widget), focus_widget);
3071 gtk_widget_real_show_help (GtkWidget *widget,
3072 GtkWidgetHelpType help_type)
3074 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3075 _gtk_tooltips_show_tip (widget);
3079 gtk_widget_real_focus (GtkWidget *widget,
3080 GtkDirectionType direction)
3082 if (!GTK_WIDGET_CAN_FOCUS (widget))
3085 if (!gtk_widget_is_focus (widget))
3087 gtk_widget_grab_focus (widget);
3095 * gtk_widget_is_focus:
3096 * @widget: a #GtkWidget
3098 * Determines if the widget is the focus widget within its
3099 * toplevel. (This does not mean that the HAS_FOCUS flag is
3100 * necessarily set; HAS_FOCUS will only be set if the
3101 * toplevel widget additionally has the global input focus.)
3103 * Return value: %TRUE if the widget is the focus widget.
3106 gtk_widget_is_focus (GtkWidget *widget)
3108 GtkWidget *toplevel;
3110 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3112 toplevel = gtk_widget_get_toplevel (widget);
3114 if (GTK_IS_WINDOW (toplevel))
3115 return widget == GTK_WINDOW (toplevel)->focus_widget;
3121 * gtk_widget_grab_default:
3122 * @widget: a #GtkWidget
3124 * Causes @widget to become the default widget. @widget must have the
3125 * #GTK_CAN_DEFAULT flag set; typically you have to set this flag
3126 * yourself by calling GTK_WIDGET_SET_FLAGS (@widget,
3127 * GTK_CAN_DEFAULT). The default widget is activated when the user
3128 * presses Enter in a window. Default widgets must be activatable,
3129 * that is, gtk_widget_activate() should affect them.
3133 gtk_widget_grab_default (GtkWidget *widget)
3136 GtkType window_type;
3138 g_return_if_fail (GTK_IS_WIDGET (widget));
3139 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
3141 window_type = GTK_TYPE_WINDOW;
3142 window = widget->parent;
3144 while (window && !gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3145 window = window->parent;
3147 if (window && gtk_type_is_a (GTK_WIDGET_TYPE (window), window_type))
3149 gtk_window_set_default (GTK_WINDOW (window), widget);
3150 g_object_notify (G_OBJECT (widget), "has_default");
3153 g_warning (G_STRLOC ": widget not within a GtkWindow");
3157 * gtk_widget_set_name:
3158 * @widget: a #GtkWidget
3159 * @name: name for the widget
3161 * Widgets can be named, which allows you to refer to them from a
3162 * gtkrc file. You can apply a style to widgets with a particular name
3163 * in the gtkrc file. See the documentation for gtkrc files (on the
3164 * same page as the docs for #GtkRcStyle).
3168 gtk_widget_set_name (GtkWidget *widget,
3171 g_return_if_fail (GTK_IS_WIDGET (widget));
3174 g_free (widget->name);
3175 widget->name = g_strdup (name);
3177 if (GTK_WIDGET_RC_STYLE (widget))
3178 gtk_widget_reset_rc_style (widget);
3180 g_object_notify (G_OBJECT (widget), "name");
3184 * gtk_widget_get_name:
3185 * @widget: a #GtkWidget
3187 * Retrieves the name of a widget. The return value should not be
3188 * freed. See gtk_widget_set_name() for the significance of widget
3191 * Return value: name of the widget
3193 G_CONST_RETURN gchar*
3194 gtk_widget_get_name (GtkWidget *widget)
3196 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3199 return widget->name;
3200 return gtk_type_name (GTK_WIDGET_TYPE (widget));
3204 * gtk_widget_set_state:
3205 * @widget: a #GtkWidget
3206 * @state: new state for @widget
3208 * This function is for use in widget implementations. Sets the state
3209 * of a widget (insensitive, prelighted, etc.) Usually you should set
3210 * the state using wrapper functions such as gtk_widget_set_sensitive().
3214 gtk_widget_set_state (GtkWidget *widget,
3217 g_return_if_fail (GTK_IS_WIDGET (widget));
3219 if (state == GTK_WIDGET_STATE (widget))
3222 if (state == GTK_STATE_INSENSITIVE)
3223 gtk_widget_set_sensitive (widget, FALSE);
3229 data.state_restoration = FALSE;
3230 data.use_forall = FALSE;
3232 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3234 data.parent_sensitive = TRUE;
3236 gtk_widget_propagate_state (widget, &data);
3238 if (GTK_WIDGET_DRAWABLE (widget))
3239 gtk_widget_queue_clear (widget);
3244 gtk_widget_set_app_paintable (GtkWidget *widget,
3245 gboolean app_paintable)
3247 g_return_if_fail (GTK_IS_WIDGET (widget));
3249 app_paintable = (app_paintable != FALSE);
3251 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
3254 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
3256 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
3258 if (GTK_WIDGET_DRAWABLE (widget))
3259 gtk_widget_queue_clear (widget);
3261 g_object_notify (G_OBJECT (widget), "app_paintable");
3266 * gtk_widget_set_double_buffered:
3267 * @widget: a #GtkWidget
3268 * @double_buffered: %TRUE to double-buffer a widget
3270 * Widgets are double buffered by default; you can use this function
3271 * to turn off the buffering. "Double buffered" simply means that
3272 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
3273 * automatically around expose events sent to the
3274 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
3275 * window to an offscreen buffer, and gdk_window_end_paint() draws the
3276 * buffer to the screen. The result is that users see the window
3277 * update in one smooth step, and don't see individual graphics
3278 * primitives being rendered.
3280 * In very simple terms, double buffered widgets don't flicker,
3281 * so you would only use this function to turn off double buffering
3282 * if you had special needs and really knew what you were doing.
3286 gtk_widget_set_double_buffered (GtkWidget *widget,
3287 gboolean double_buffered)
3289 g_return_if_fail (GTK_IS_WIDGET (widget));
3291 if (double_buffered)
3292 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3294 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
3298 * gtk_widget_set_sensitive:
3299 * @widget: a @widget
3300 * @sensitive: %TRUE to make the widget sensitive
3302 * Sets the sensitivity of a widget. A widget is sensitive if the user
3303 * can interact with it. Insensitive widgets are "grayed out" and the
3304 * user can't interact with them. Insensitive widgets are known as
3305 * "inactive" in some other toolkits.
3309 gtk_widget_set_sensitive (GtkWidget *widget,
3314 g_return_if_fail (GTK_IS_WIDGET (widget));
3316 sensitive = (sensitive != FALSE);
3318 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
3323 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
3324 data.state = GTK_WIDGET_SAVED_STATE (widget);
3328 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
3329 data.state = GTK_WIDGET_STATE (widget);
3331 data.state_restoration = TRUE;
3332 data.use_forall = TRUE;
3335 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
3337 data.parent_sensitive = TRUE;
3339 gtk_widget_propagate_state (widget, &data);
3340 if (GTK_WIDGET_DRAWABLE (widget))
3341 gtk_widget_queue_clear (widget);
3343 g_object_notify (G_OBJECT (widget), "sensitive");
3347 * gtk_widget_set_parent:
3348 * @widget: a #GtkWidget
3349 * @parent: parent container
3351 * This function is useful only when implementing subclasses of #GtkContainer.
3352 * Sets the container as the parent of @widget, and takes care of
3353 * some details such as updating the state and style of the child
3354 * to reflect its new location. The opposite function is
3355 * gtk_widget_unparent().
3359 gtk_widget_set_parent (GtkWidget *widget,
3364 g_return_if_fail (GTK_IS_WIDGET (widget));
3365 g_return_if_fail (widget->parent == NULL);
3366 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
3367 g_return_if_fail (GTK_IS_WIDGET (parent));
3368 g_return_if_fail (widget != parent);
3370 /* keep this function in sync with gtk_menu_attach_to_widget()
3373 gtk_widget_ref (widget);
3374 gtk_object_sink (GTK_OBJECT (widget));
3375 widget->parent = parent;
3377 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
3378 data.state = GTK_WIDGET_STATE (parent);
3380 data.state = GTK_WIDGET_STATE (widget);
3381 data.state_restoration = FALSE;
3382 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
3383 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
3385 gtk_widget_propagate_state (widget, &data);
3387 gtk_widget_set_style_recurse (widget, NULL);
3389 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[PARENT_SET], NULL);
3390 if (GTK_WIDGET_ANCHORED (widget->parent))
3391 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
3392 g_object_notify (G_OBJECT (widget), "parent");
3394 /* Enforce realized/mapped invariants
3396 if (GTK_WIDGET_REALIZED (widget->parent))
3397 gtk_widget_realize (widget);
3399 if (GTK_WIDGET_VISIBLE (widget->parent) &&
3400 GTK_WIDGET_VISIBLE (widget))
3402 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
3403 GTK_WIDGET_MAPPED (widget->parent))
3404 gtk_widget_map (widget);
3406 gtk_widget_queue_resize (widget);
3411 * gtk_widget_get_parent:
3412 * @widget: a #GtkWidget
3414 * Returns the parent container of @widget.
3416 * Return value: the parent container of @widget, or %NULL
3419 gtk_widget_get_parent (GtkWidget *widget)
3421 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3423 return widget->parent;
3426 /*****************************************
3428 * see docs/styles.txt
3429 *****************************************/
3432 * gtk_widget_set_style:
3433 * @widget: a #GtkWidget
3434 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
3435 * gtk_widget_set_style and go back to the default style
3437 * Sets the #GtkStyle for a widget (widget->style). You probably don't
3438 * want to use this function; it interacts badly with themes, because
3439 * themes work by replacing the #GtkStyle. Instead, use
3440 * gtk_widget_modify_style().
3444 gtk_widget_set_style (GtkWidget *widget,
3447 g_return_if_fail (GTK_IS_WIDGET (widget));
3451 gboolean initial_emission;
3453 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3455 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
3456 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
3458 gtk_widget_set_style_internal (widget, style, initial_emission);
3462 if (GTK_WIDGET_USER_STYLE (widget))
3463 gtk_widget_reset_rc_style (widget);
3468 * gtk_widget_ensure_style:
3469 * @widget: a #GtkWidget
3471 * Ensures that @widget has a style (widget->style). Not a very useful
3472 * function; most of the time, if you want the style, the widget is
3473 * realized, and realized widgets are guaranteed to have a style
3478 gtk_widget_ensure_style (GtkWidget *widget)
3480 g_return_if_fail (GTK_IS_WIDGET (widget));
3482 if (!GTK_WIDGET_USER_STYLE (widget) &&
3483 !GTK_WIDGET_RC_STYLE (widget))
3484 gtk_widget_reset_rc_style (widget);
3487 /* Look up the RC style for this widget, unsetting any user style that
3488 * may be in effect currently
3491 gtk_widget_reset_rc_style (GtkWidget *widget)
3493 GtkStyle *new_style;
3494 gboolean initial_emission;
3496 g_return_if_fail (GTK_IS_WIDGET (widget));
3498 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
3500 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
3501 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
3503 new_style = gtk_rc_get_style (widget);
3505 new_style = gtk_widget_get_default_style ();
3507 if (initial_emission || new_style != widget->style)
3508 gtk_widget_set_style_internal (widget, new_style, initial_emission);
3512 * gtk_widget_get_style:
3513 * @widget: a #GtkWidget
3515 * Simply an accessor function that returns widget->style.
3517 * Return value: the widget's #GtkStyle
3520 gtk_widget_get_style (GtkWidget *widget)
3522 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3524 return widget->style;
3528 * gtk_widget_modify_style:
3529 * @widget: a #GtkWidget
3530 * @style: the #GtkRcStyle holding the style modifications
3532 * Modify style values on the widget. Modifications made using this
3533 * technique take precendence over style values set via an RC file,
3534 * however, they will be overriden if a style is explicitely set on
3535 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
3536 * is designed so each field can either be set or unset, so it is
3537 * possible, using this function, to modify some style values and
3538 * leave the others unchanged.
3540 * Note that modifications made with this function are not cumulative
3541 * with previous calls to gtk_widget_modify_style() or with such
3542 * functions as gtk_widget_modify_fg(). If you wish to retain
3543 * previous values, you must first call gtk_widget_get_modifier_style(),
3544 * make your modifications to the returned style, then call
3545 * gtk_widget_modify_style() with that style. On the other hand,
3546 * if you first call gtk_widget_modify_style(), subsequent calls
3547 * to such functions gtk_widget_modify_fg() will be have a cumulative
3548 * effect with the inital modifications.
3551 gtk_widget_modify_style (GtkWidget *widget,
3554 GtkRcStyle *old_style;
3556 g_return_if_fail (GTK_IS_RC_STYLE (style));
3558 old_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3561 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3563 gtk_rc_style_copy (style),
3564 (GtkDestroyNotify)gtk_rc_style_unref);
3566 /* note that "style" may be invalid here if it was the old
3567 * modifier style and the only reference was our own.
3570 if (GTK_WIDGET_RC_STYLE (widget))
3571 gtk_widget_reset_rc_style (widget);
3575 * gtk_widget_get_modifier_style:
3576 * @widget: a #GtkWidget
3578 * Return the current modifier style for the widget. (As set by
3579 * gtk_widget_modify_style().) If no style has previously set, a new
3580 * #GtkRcStyle will be created with all values unset, and set as the
3581 * modifier style for the widget. If you make changes to this rc
3582 * style, you must call gtk_widget_modify_style(), passing in the
3583 * returned rc style, to make sure that your changes take effect.
3585 * Caution: passing the style back to gtk_widget_modify_style() will
3586 * normally end up destroying it, because gtk_widget_modify_style() copies
3587 * the passed-in style and sets the copy as the new modifier style,
3588 * thus dropping any reference to the old modifier style. Add a reference
3589 * to the modifier style if you want to keep it alive.
3591 * Return value: the modifier style for the widget. This rc style is
3592 * owned by the widget. If you want to keep a pointer to value this
3593 * around, you must add a refcount using gtk_rc_style_ref().
3596 gtk_widget_get_modifier_style (GtkWidget *widget)
3598 GtkRcStyle *rc_style;
3600 rc_style = gtk_object_get_data_by_id (GTK_OBJECT (widget),
3605 rc_style = gtk_rc_style_new ();
3606 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
3609 (GtkDestroyNotify)gtk_rc_style_unref);
3616 gtk_widget_modify_color_component (GtkWidget *widget,
3617 GtkRcFlags component,
3621 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
3626 rc_style->fg[state] = *color;
3629 rc_style->bg[state] = *color;
3632 rc_style->text[state] = *color;
3635 rc_style->base[state] = *color;
3638 g_assert_not_reached();
3641 rc_style->color_flags[state] |= component;
3643 gtk_widget_modify_style (widget, rc_style);
3647 * gtk_widget_modify_fg:
3648 * @widget: a #GtkWidget.
3649 * @state: the state for which to set the foreground color.
3650 * @color: the color to assign (does not need to be allocated).
3652 * Set the foreground color for a widget in a particular state. All
3653 * other style values are left untouched. See also
3654 * gtk_widget_modify_style().
3657 gtk_widget_modify_fg (GtkWidget *widget,
3661 g_return_if_fail (GTK_IS_WIDGET (widget));
3662 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3663 g_return_if_fail (color != NULL);
3665 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
3669 * gtk_widget_modify_bg:
3670 * @widget: a #GtkWidget.
3671 * @state: the state for which to set the background color.
3672 * @color: the color to assign (does not need to be allocated).
3674 * Set the background color for a widget in a particular state. All
3675 * other style values are left untouched. See also
3676 * gtk_widget_modify_style().
3679 gtk_widget_modify_bg (GtkWidget *widget,
3683 g_return_if_fail (GTK_IS_WIDGET (widget));
3684 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3685 g_return_if_fail (color != NULL);
3687 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
3691 * gtk_widget_modify_text:
3692 * @widget: a #GtkWidget.
3693 * @state: the state for which to set the text color.
3694 * @color: the color to assign (does not need to be allocated).
3696 * Set the text color for a widget in a particular state. All other
3697 * style values are left untouched. The text color is the foreground
3698 * color used along with the base color (see gtk_widget_modify_base)
3699 * for widgets such as #GtkEntry and #GtkTextView. See also
3700 * gtk_widget_modify_style().
3703 gtk_widget_modify_text (GtkWidget *widget,
3707 g_return_if_fail (GTK_IS_WIDGET (widget));
3708 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3709 g_return_if_fail (color != NULL);
3711 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
3715 * gtk_widget_modify_base:
3716 * @widget: a #GtkWidget.
3717 * @state: the state for which to set the base color.
3718 * @color: the color to assign (does not need to be allocated).
3720 * Set the base color for a widget in a particular state.
3721 * All other style values are left untouched. The base color
3722 * is the background color used along with the text color
3723 * (see gtk_widget_modify_text) for widgets such as #GtkEntry
3724 * and #GtkTextView. See also gtk_widget_modify_style().
3727 gtk_widget_modify_base (GtkWidget *widget,
3731 g_return_if_fail (GTK_IS_WIDGET (widget));
3732 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
3733 g_return_if_fail (color != NULL);
3735 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
3739 * gtk_widget_modify_font:
3740 * @widget: a #GtkWidget
3741 * @font_desc: the font description to use
3743 * Set the font to use for a widget. All other style values are left
3744 * untouched. See also gtk_widget_modify_style().
3747 gtk_widget_modify_font (GtkWidget *widget,
3748 PangoFontDescription *font_desc)
3750 GtkRcStyle *rc_style;
3752 g_return_if_fail (GTK_IS_WIDGET (widget));
3753 g_return_if_fail (font_desc != NULL);
3755 rc_style = gtk_widget_get_modifier_style (widget);
3757 if (rc_style->font_desc)
3758 pango_font_description_free (rc_style->font_desc);
3760 rc_style->font_desc = pango_font_description_copy (font_desc);
3762 gtk_widget_modify_style (widget, rc_style);
3766 gtk_widget_direction_changed (GtkWidget *widget,
3767 GtkTextDirection previous_direction)
3769 gtk_widget_queue_resize (widget);
3773 gtk_widget_style_set (GtkWidget *widget,
3774 GtkStyle *previous_style)
3776 if (GTK_WIDGET_REALIZED (widget) &&
3777 !GTK_WIDGET_NO_WINDOW (widget))
3778 gtk_style_set_background (widget->style, widget->window, widget->state);
3782 gtk_widget_set_style_internal (GtkWidget *widget,
3784 gboolean initial_emission)
3786 g_return_if_fail (GTK_IS_WIDGET (widget));
3787 g_return_if_fail (style != NULL);
3789 g_object_ref (G_OBJECT (widget));
3790 g_object_freeze_notify (G_OBJECT (widget));
3792 if (widget->style != style || initial_emission)
3794 PangoContext *context = gtk_widget_peek_pango_context (widget);
3796 pango_context_set_font_description (context, style->font_desc);
3799 if (widget->style != style)
3801 GtkStyle *previous_style;
3803 if (GTK_WIDGET_REALIZED (widget))
3805 gtk_widget_reset_shapes (widget);
3806 gtk_style_detach (widget->style);
3809 previous_style = widget->style;
3810 widget->style = style;
3811 g_object_ref (widget->style);
3813 if (GTK_WIDGET_REALIZED (widget))
3814 widget->style = gtk_style_attach (widget->style, widget->window);
3816 gtk_signal_emit (GTK_OBJECT (widget),
3817 widget_signals[STYLE_SET],
3818 initial_emission ? NULL : previous_style);
3819 g_object_unref (previous_style);
3821 if (widget->parent && !initial_emission)
3823 GtkRequisition old_requisition;
3825 old_requisition = widget->requisition;
3826 gtk_widget_size_request (widget, NULL);
3828 if ((old_requisition.width != widget->requisition.width) ||
3829 (old_requisition.height != widget->requisition.height))
3830 gtk_widget_queue_resize (widget);
3831 else if (GTK_WIDGET_DRAWABLE (widget))
3832 gtk_widget_queue_clear (widget);
3835 else if (initial_emission)
3836 gtk_signal_emit (GTK_OBJECT (widget),
3837 widget_signals[STYLE_SET],
3839 g_object_notify (G_OBJECT (widget), "style");
3840 g_object_thaw_notify (G_OBJECT (widget));
3841 g_object_unref (G_OBJECT (widget));
3845 gtk_widget_set_style_recurse (GtkWidget *widget,
3846 gpointer client_data)
3848 if (GTK_WIDGET_RC_STYLE (widget))
3849 gtk_widget_reset_rc_style (widget);
3851 if (GTK_IS_CONTAINER (widget))
3852 gtk_container_forall (GTK_CONTAINER (widget),
3853 gtk_widget_set_style_recurse,
3858 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
3859 gpointer client_data)
3861 gboolean new_anchored;
3863 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
3864 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
3866 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
3868 gtk_widget_ref (widget);
3871 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
3873 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
3875 g_signal_emit (GTK_OBJECT (widget), widget_signals[HIERARCHY_CHANGED],
3878 if (GTK_IS_CONTAINER (widget))
3879 gtk_container_forall (GTK_CONTAINER (widget),
3880 gtk_widget_propagate_hierarchy_changed_recurse,
3883 gtk_widget_unref (widget);
3888 * _gtk_widget_propagate_hierarchy_changed:
3889 * @widget: a #GtkWidget
3890 * @previous_toplevel: Previous toplevel
3892 * Propagate changes in the anchored state to a widget and all
3893 * children, unsetting or setting the ANCHORED flag, and
3894 * emitting hierarchy_changed.
3897 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
3898 GtkWidget *previous_toplevel)
3900 if (previous_toplevel)
3901 g_object_ref (previous_toplevel);
3903 gtk_widget_propagate_hierarchy_changed_recurse (widget, previous_toplevel);
3905 if (previous_toplevel)
3906 g_object_unref (previous_toplevel);
3910 gtk_widget_reset_rc_styles (GtkWidget *widget)
3912 g_return_if_fail (GTK_IS_WIDGET (widget));
3914 gtk_widget_set_style_recurse (widget, NULL);
3918 gtk_widget_get_default_style (void)
3920 if (!gtk_default_style)
3922 gtk_default_style = gtk_style_new ();
3923 g_object_ref (gtk_default_style);
3926 return gtk_default_style;
3929 static PangoContext *
3930 gtk_widget_peek_pango_context (GtkWidget *widget)
3932 return gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
3936 * gtk_widget_get_pango_context:
3937 * @widget: a #GtkWidget
3939 * Get a #PangoContext with the appropriate colormap, font description
3940 * and base direction for this widget. Unlike the context returned
3941 * by gtk_widget_create_pango_context(), this context is owned by
3942 * the widget (it can be used as long as widget exists), and will
3943 * be updated to match any changes to the widget's attributes.
3945 * If you create and keep a #PangoLayout using this context, you must
3946 * deal with changes to the context by calling pango_layout_context_changed()
3947 * on the layout in response to the ::style_set and ::direction_set signals
3950 * Return value: the #PangoContext for the widget.
3953 gtk_widget_get_pango_context (GtkWidget *widget)
3955 PangoContext *context;
3957 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3959 context = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_pango_context);
3962 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
3963 gtk_object_set_data_by_id_full (GTK_OBJECT (widget), quark_pango_context, context,
3964 (GDestroyNotify) g_object_unref);
3971 * gtk_widget_create_pango_context:
3972 * @widget: a #PangoWidget
3974 * Create a new pango context with the appropriate colormap,
3975 * font description, and base direction for drawing text for
3976 * this widget. See also gtk_widget_get_pango_context()
3978 * Return value: the new #PangoContext
3981 gtk_widget_create_pango_context (GtkWidget *widget)
3983 PangoContext *context;
3985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3987 context = gdk_pango_context_get ();
3989 gdk_pango_context_set_colormap (context, gtk_widget_get_colormap (widget));
3990 pango_context_set_base_dir (context,
3991 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
3992 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
3993 pango_context_set_font_description (context, widget->style->font_desc);
3994 pango_context_set_language (context, gtk_get_default_language ());
4000 * gtk_widget_create_pango_layout:
4001 * @widget: a #PangoWidget
4002 * @text: text to set on the layout (can be %NULL)
4004 * Create a new #PangoLayout with the appropriate colormap,
4005 * font description, and base direction for drawing text for
4008 * If you keep a #PangoLayout created in this way around, in order
4009 * notify the layout of changes to the base direction or font of this
4010 * widget, you must call pango_layout_context_changed() in response to
4011 * the ::style_set and ::direction_set signals for the widget.
4013 * Return value: the new #PangoLayout
4016 gtk_widget_create_pango_layout (GtkWidget *widget,
4019 PangoLayout *layout;
4020 PangoContext *context;
4022 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4024 context = gtk_widget_get_pango_context (widget);
4025 layout = pango_layout_new (context);
4028 pango_layout_set_text (layout, text, -1);
4034 * gtk_widget_render_icon:
4035 * @widget: a #GtkWidget
4036 * @stock_id: a stock ID
4037 * @size: a stock size
4038 * @detail: render detail to pass to theme engine
4040 * A convenience function that uses the theme engine and RC file
4041 * settings for @widget to look up @stock_id and render it to
4042 * a pixbuf. @stock_id should be a stock icon ID such as
4043 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
4044 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
4045 * identifies the widget or code doing the rendering, so that
4046 * theme engines can special-case rendering for that widget or code.
4048 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
4051 gtk_widget_render_icon (GtkWidget *widget,
4052 const gchar *stock_id,
4054 const gchar *detail)
4056 GtkIconSet *icon_set;
4059 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4060 g_return_val_if_fail (stock_id != NULL, NULL);
4061 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID, NULL);
4063 gtk_widget_ensure_style (widget);
4065 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
4067 if (icon_set == NULL)
4070 retval = gtk_icon_set_render_icon (icon_set,
4072 gtk_widget_get_direction (widget),
4073 GTK_WIDGET_STATE (widget),
4081 /*************************************************************
4082 * gtk_widget_set_parent_window:
4083 * Set a non default parent window for widget
4090 *************************************************************/
4093 gtk_widget_set_parent_window (GtkWidget *widget,
4094 GdkWindow *parent_window)
4096 GdkWindow *old_parent_window;
4098 g_return_if_fail (GTK_IS_WIDGET (widget));
4100 old_parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4101 quark_parent_window);
4103 if (parent_window != old_parent_window)
4105 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_parent_window,
4107 if (old_parent_window)
4108 gdk_window_unref (old_parent_window);
4110 gdk_window_ref (parent_window);
4116 * gtk_widget_set_child_visible:
4117 * @widget: a #GtkWidget
4118 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
4120 * Sets whether @widget should be mapped along with its when its parent
4121 * is mapped and @widget has been shown with gtk_widget_show().
4123 * The child visibility can be set for widget before it is added to
4124 * a container with gtk_widget_set_parent(), to avoid mapping
4125 * children unnecessary before immediately unmapping them. However
4126 * it will be reset to its default state of %TRUE when the widget
4127 * is removed from a container.
4129 * Note that changing the child visibility of a widget does not
4130 * queue a resize on the widget. Most of the time, the size of
4131 * a widget is computed from all visible children, whether or
4132 * not they are mapped. If this is not the case, the container
4133 * can queue a resize itself.
4135 * This function is only useful for container implementations and
4136 * never should be called by an application.
4139 gtk_widget_set_child_visible (GtkWidget *widget,
4140 gboolean is_visible)
4142 g_return_if_fail (GTK_IS_WIDGET (widget));
4143 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
4146 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
4148 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
4149 if (GTK_WIDGET_REALIZED (widget->parent))
4151 if (GTK_WIDGET_MAPPED (widget->parent) &&
4152 GTK_WIDGET_CHILD_VISIBLE (widget) &&
4153 GTK_WIDGET_VISIBLE (widget))
4154 gtk_widget_map (widget);
4156 gtk_widget_unmap (widget);
4161 * gtk_widget_get_child_visible:
4162 * @widget: a #GtkWidget
4164 * Gets the value set with gtk_widget_set_child_visible().
4165 * If you feel a need to use this function, your code probably
4166 * needs reorganization.
4168 * This function is only useful for container implementations and
4169 * never should be called by an application.
4171 * Return value: %TRUE if the widget is mapped with the parent.
4174 gtk_widget_get_child_visible (GtkWidget *widget)
4176 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4178 return GTK_WIDGET_CHILD_VISIBLE (widget);
4181 /*************************************************************
4182 * gtk_widget_get_parent_window:
4183 * Get widget's parent window
4190 *************************************************************/
4193 gtk_widget_get_parent_window (GtkWidget *widget)
4195 GdkWindow *parent_window;
4197 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4198 g_return_val_if_fail (widget->parent != NULL, NULL);
4200 parent_window = gtk_object_get_data_by_id (GTK_OBJECT (widget),
4201 quark_parent_window);
4203 return (parent_window != NULL) ? parent_window : widget->parent->window;
4207 * gtk_widget_child_focus:
4208 * @widget: a #GtkWidget
4209 * @direction: direction of focus movement
4211 * This function is used by custom widget implementations; if you're
4212 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
4213 * to a particular widget, and gtk_container_set_focus_chain() to
4214 * change the focus tab order. So you may want to investigate those
4215 * functions instead.
4217 * gtk_widget_child_focus() is called by containers as the user moves
4218 * around the window using keyboard shortcuts. @direction indicates
4219 * what kind of motion is taking place (up, down, left, right, tab
4220 * forward, tab backward). gtk_widget_child_focus() invokes the
4221 * "focus" signal on #GtkWidget; widgets override the default handler
4222 * for this signal in order to implement appropriate focus behavior.
4224 * The "focus" default handler for a widget should return %TRUE if
4225 * moving in @direction left the focus on a focusable location inside
4226 * that widget, and %FALSE if moving in @direction moved the focus
4227 * outside the widget. If returning %TRUE, widgets normally
4228 * call gtk_widget_grab_focus() to place the focus accordingly;
4229 * if returning %FALSE, they don't modify the current focus location.
4231 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
4232 * necessary to check that the child was visible, sensitive, and
4233 * focusable before calling
4234 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
4235 * the widget is not currently in a focusable state, so there's no
4236 * need for those checks.
4238 * Return value: %TRUE if focus ended up inside @widget
4241 gtk_widget_child_focus (GtkWidget *widget,
4242 GtkDirectionType direction)
4244 gboolean return_val;
4246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4248 if (!GTK_WIDGET_VISIBLE (widget) ||
4249 !GTK_WIDGET_IS_SENSITIVE (widget))
4252 /* child widgets must set CAN_FOCUS, containers
4253 * don't have to though.
4255 if (!GTK_IS_CONTAINER (widget) &&
4256 !GTK_WIDGET_CAN_FOCUS (widget))
4259 gtk_signal_emit (GTK_OBJECT (widget),
4260 widget_signals[FOCUS],
4261 direction, &return_val);
4267 * gtk_widget_set_uposition:
4268 * @widget: a #GtkWidget
4269 * @x: x position; -1 to unset x; -2 to leave x unchanged
4270 * @y: y position; -1 to unset y; -2 to leave y unchanged
4273 * Sets the position of a widget. The funny "u" in the name comes from
4274 * the "user position" hint specified by the X window system, and
4275 * exists for legacy reasons. This function doesn't work if a widget
4276 * is inside a container; it's only really useful on #GtkWindow.
4278 * Don't use this function to center dialogs over the main application
4279 * window; most window managers will do the centering on your behalf
4280 * if you call gtk_window_set_transient_for(), and it's really not
4281 * possible to get the centering to work correctly in all cases from
4282 * application code. But if you insist, use gtk_window_set_position()
4283 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
4286 * Note that although x and y can be individually unset, the position
4287 * is not honoured unless both x and y are set.
4290 gtk_widget_set_uposition (GtkWidget *widget,
4294 /* FIXME this function is the only place that aux_info->x and
4295 * aux_info->y are even used I believe, and this function is
4296 * deprecated. Should be cleaned up.
4299 GtkWidgetAuxInfo *aux_info;
4301 g_return_if_fail (GTK_IS_WIDGET (widget));
4303 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4308 aux_info->x_set = FALSE;
4311 aux_info->x_set = TRUE;
4319 aux_info->y_set = FALSE;
4322 aux_info->y_set = TRUE;
4327 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
4328 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
4330 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
4331 gtk_widget_size_allocate (widget, &widget->allocation);
4335 * gtk_widget_set_usize:
4336 * @widget: a #GtkWidget
4337 * @width: minimum width, or -1 to unset
4338 * @height: minimum height, or -1 to unset
4340 * This function is deprecated; use gtk_widget_set_size_request()
4343 * Sets the minimum size of a widget; that is, the widget's size
4344 * request will be @width by @height. You can use this function to
4345 * force a widget to be either larger or smaller than it is. The
4346 * strange "usize" name dates from the early days of GTK+, and derives
4347 * from X Window System terminology. In many cases,
4348 * gtk_window_set_default_size() is a better choice for toplevel
4349 * windows than this function; setting the default size will still
4350 * allow users to shrink the window. Setting the usize will force them
4351 * to leave the window at least as large as the usize. When dealing
4352 * with window sizes, gtk_window_set_geometry_hints() can be a useful
4355 * Note the inherent danger of setting any fixed size - themes,
4356 * translations into other languages, different fonts, and user action
4357 * can all change the appropriate size for a given widget. So, it's
4358 * basically impossible to hardcode a size that will always be
4363 gtk_widget_set_usize (GtkWidget *widget,
4367 GtkWidgetAuxInfo *aux_info;
4369 g_return_if_fail (GTK_IS_WIDGET (widget));
4371 g_object_freeze_notify (G_OBJECT (widget));
4373 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
4377 g_object_notify (G_OBJECT (widget), "width_request");
4378 aux_info->width = width;
4382 g_object_notify (G_OBJECT (widget), "height_request");
4383 aux_info->height = height;
4386 if (GTK_WIDGET_VISIBLE (widget))
4387 gtk_widget_queue_resize (widget);
4389 g_object_thaw_notify (G_OBJECT (widget));
4393 * gtk_widget_set_size_request:
4394 * @widget: a #GtkWidget
4395 * @width: width @widget should request, or -1 to unset
4396 * @height: height @widget should request, or -1 to unset
4398 * Sets the minimum size of a widget; that is, the widget's size
4399 * request will be @width by @height. You can use this function to
4400 * force a widget to be either larger or smaller than it normally
4403 * In most cases, gtk_window_set_default_size() is a better choice for
4404 * toplevel windows than this function; setting the default size will
4405 * still allow users to shrink the window. Setting the size request
4406 * will force them to leave the window at least as large as the size
4407 * request. When dealing with window sizes,
4408 * gtk_window_set_geometry_hints() can be a useful function as well.
4410 * Note the inherent danger of setting any fixed size - themes,
4411 * translations into other languages, different fonts, and user action
4412 * can all change the appropriate size for a given widget. So, it's
4413 * basically impossible to hardcode a size that will always be
4416 * The size request of a widget is the smallest size a widget can
4417 * accept while still functioning well and drawing itself correctly.
4418 * However in some strange cases a widget may be allocated less than
4419 * its requested size, and in many cases a widget may be allocated more
4420 * space than it requested.
4422 * If the size request in a given direction is -1 (unset), then
4423 * the "natural" size request of the widget will be used instead.
4425 * Widgets can't actually be allocated a size less than 1 by 1, but
4426 * you can pass 0,0 to this function to mean "as small as possible."
4429 gtk_widget_set_size_request (GtkWidget *widget,
4433 g_return_if_fail (GTK_IS_WIDGET (widget));
4434 g_return_if_fail (width >= -1);
4435 g_return_if_fail (height >= -1);
4442 gtk_widget_set_usize (widget, width, height);
4447 * gtk_widget_get_size_request:
4448 * @widget: a #GtkWidget
4449 * @width: return location for width, or %NULL
4450 * @height: return location for height, or %NULL
4452 * Gets the size request that was explicitly set for the widget using
4453 * gtk_widget_set_size_request(). A value of -1 stored in @width or
4454 * @height indicates that that dimension has not been set explicitly
4455 * and the natural requisition of the widget will be used intead. See
4456 * gtk_widget_set_size_request(). To get the size a widget will
4457 * actually use, call gtk_widget_size_request() instead of
4463 gtk_widget_get_size_request (GtkWidget *widget,
4467 GtkWidgetAuxInfo *aux_info;
4469 g_return_if_fail (GTK_IS_WIDGET (widget));
4471 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
4474 *width = aux_info ? aux_info->width : -1;
4477 *height = aux_info ? aux_info->height : -1;
4481 * gtk_widget_set_events:
4482 * @widget: a #GtkWidget
4483 * @events: event mask
4485 * Sets the event mask (see #GdkEventMask) for a widget. The event
4486 * mask determines which events a widget will receive. Keep in mind
4487 * that different widgets have different default event masks, and by
4488 * changing the event mask you may disrupt a widget's functionality,
4489 * so be careful. This function must be called while a widget is
4490 * unrealized. Consider gtk_widget_add_events() for widgets that are
4491 * already realized, or if you want to preserve the existing event
4492 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
4493 * to get events on those widgets, place them inside a #GtkEventBox
4494 * and receive events on the event box.
4498 gtk_widget_set_events (GtkWidget *widget,
4503 g_return_if_fail (GTK_IS_WIDGET (widget));
4504 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4505 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4507 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4512 eventp = g_new (gint, 1);
4515 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4520 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4523 g_object_notify (G_OBJECT (widget), "events");
4527 * gtk_widget_add_events:
4528 * @widget: a #GtkWidget
4529 * @events: an event mask, see #GdkEventMask
4531 * Adds the events in the bitfield @events to the event mask for
4532 * @widget. See gtk_widget_set_events() for details.
4536 gtk_widget_add_events (GtkWidget *widget,
4541 g_return_if_fail (GTK_IS_WIDGET (widget));
4542 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
4544 eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4550 eventp = g_new (gint, 1);
4555 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_event_mask, eventp);
4560 gtk_object_remove_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4563 if (GTK_WIDGET_REALIZED (widget))
4565 gdk_window_set_events (widget->window,
4566 gdk_window_get_events (widget->window) | events);
4569 g_object_notify (G_OBJECT (widget), "events");
4573 * gtk_widget_set_extension_events:
4574 * @widget: a #GtkWidget
4575 * @mode: bitfield of extension events to receive
4577 * Sets the extension events mask to @mode. See #GdkExtensionMode
4578 * and gdk_input_set_extension_events().
4582 gtk_widget_set_extension_events (GtkWidget *widget,
4583 GdkExtensionMode mode)
4585 GdkExtensionMode *modep;
4587 g_return_if_fail (GTK_IS_WIDGET (widget));
4589 modep = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4592 modep = g_new (GdkExtensionMode, 1);
4595 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode, modep);
4596 g_object_notify (G_OBJECT (widget), "extension_events");
4600 * gtk_widget_get_toplevel:
4601 * @widget: a #GtkWidget
4603 * This function returns the topmost widget in the container hierarchy
4604 * @widget is a part of. If @widget has no parent widgets, it will be
4605 * returned as the topmost widget. No reference will be added to the
4606 * returned widget; it should not be unreferenced.
4608 * Note the difference in behavior vs. gtk_widget_get_ancestor();
4609 * gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW) would return
4610 * %NULL if @widget wasn't inside a toplevel window, and if the
4611 * window was inside a GtkWindow-derived widget which was in turn
4612 * inside the toplevel GtkWindow. While the second case may
4613 * seem unlikely, it actually happens when a GtkPlug is embedded
4614 * inside a GtkSocket within the same application
4616 * To reliably find the toplevel GtkWindow, use
4617 * gtk_widget_get_toplevel() and check if the TOPLEVEL flags
4618 * is set on the result.
4620 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4621 * if (GTK_WIDGET_TOPLEVEL (toplevel))
4623 * [ Perform action on toplevel. ]
4626 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor
4629 gtk_widget_get_toplevel (GtkWidget *widget)
4631 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4633 while (widget->parent)
4634 widget = widget->parent;
4640 * gtk_widget_get_ancestor:
4641 * @widget: a #GtkWidget
4642 * @widget_type: ancestor type
4644 * Gets the first ancestor of @widget with type @widget_type. For example,
4645 * gtk_widget_get_ancestor (widget, GTK_TYPE_BOX) gets the first #GtkBox that's
4646 * an ancestor of @widget. No reference will be added to the returned widget;
4647 * it should not be unreferenced. See note about checking for a toplevel
4648 * GtkWindow in the docs for gtk_widget_get_toplevel().
4650 * Return value: the ancestor widget, or %NULL if not found
4653 gtk_widget_get_ancestor (GtkWidget *widget,
4654 GtkType widget_type)
4656 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4658 while (widget && !gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
4659 widget = widget->parent;
4661 if (!(widget && gtk_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
4668 * gtk_widget_get_colormap:
4669 * @widget: a #GtkWidget
4671 * Gets the colormap that will be used to render @widget. No reference will
4672 * be added to the returned colormap; it should not be unreferenced.
4674 * Return value: the colormap used by @widget
4677 gtk_widget_get_colormap (GtkWidget *widget)
4679 GdkColormap *colormap;
4681 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4685 colormap = gdk_window_get_colormap (widget->window);
4686 /* If window was destroyed previously, we'll get NULL here */
4693 colormap = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_colormap);
4697 widget = widget->parent;
4700 return gtk_widget_get_default_colormap ();
4704 * gtk_widget_get_visual:
4705 * @widget: a #GtkWidget
4707 * Gets the visual that will be used to render @widget.
4709 * Return value: the visual for @widget
4712 gtk_widget_get_visual (GtkWidget *widget)
4714 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4716 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
4720 * gtk_widget_get_settings:
4721 * @widget: a #GtkWidget
4723 * Get the settings object holding the settings (global property
4724 * settings, RC file information, etc) used for this widget.
4726 * Return value: the relevant #GtkSettings object
4729 gtk_widget_get_settings (GtkWidget *widget)
4731 return gtk_settings_get_default ();
4735 * gtk_widget_set_colormap:
4736 * @widget: a #GtkWidget
4737 * @colormap: a colormap
4739 * Set the colormap for the widget to the given value. Widget must not
4740 * have been previously realized. This probably should only be used
4741 * from an init() function (i.e. from the constructor for the widget).
4745 gtk_widget_set_colormap (GtkWidget *widget,
4746 GdkColormap *colormap)
4748 g_return_if_fail (GTK_IS_WIDGET (widget));
4749 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
4750 g_return_if_fail (GDK_IS_COLORMAP (colormap));
4752 g_object_ref (G_OBJECT (colormap));
4754 g_object_set_qdata_full (G_OBJECT (widget),
4757 (GtkDestroyNotify) g_object_unref);
4761 * gtk_widget_get_events:
4762 * @widget: a #GtkWidget
4764 * Returns the event mask for the widget (a bitfield containing flags
4765 * from the #GdkEventMask enumeration). These are the events that the widget
4768 * Return value: event mask for @widget
4771 gtk_widget_get_events (GtkWidget *widget)
4775 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4777 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
4785 * gtk_widget_get_extension_events:
4786 * @widget: a #GtkWidget
4788 * Retrieves the extension events the widget will receive; see
4789 * gdk_input_set_extension_events().
4791 * Return value: extension events for @widget
4794 gtk_widget_get_extension_events (GtkWidget *widget)
4796 GdkExtensionMode *mode;
4798 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4800 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
4808 * gtk_widget_get_pointer:
4809 * @widget: a #GtkWidget
4810 * @x: return location for the X coordinate, or %NULL
4811 * @y: return location for the Y coordinate, or %NULL
4813 * Obtains the location of the mouse pointer in widget coordinates.
4814 * Widget coordinates are a bit odd; for historical reasons, they are
4815 * defined as widget->window coordinates for widgets that are not
4816 * #GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
4817 * widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4821 gtk_widget_get_pointer (GtkWidget *widget,
4825 g_return_if_fail (GTK_IS_WIDGET (widget));
4832 if (GTK_WIDGET_REALIZED (widget))
4834 gdk_window_get_pointer (widget->window, x, y, NULL);
4836 if (GTK_WIDGET_NO_WINDOW (widget))
4839 *x -= widget->allocation.x;
4841 *y -= widget->allocation.y;
4847 * gtk_widget_is_ancestor:
4848 * @widget: a #GtkWidget
4849 * @ancestor: another #GtkWidget
4851 * Determines whether @widget is somewhere inside @ancestor, possibly with
4852 * intermediate containers.
4854 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
4857 gtk_widget_is_ancestor (GtkWidget *widget,
4858 GtkWidget *ancestor)
4860 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4861 g_return_val_if_fail (ancestor != NULL, FALSE);
4865 if (widget->parent == ancestor)
4867 widget = widget->parent;
4873 static GQuark quark_composite_name = 0;
4876 gtk_widget_set_composite_name (GtkWidget *widget,
4879 g_return_if_fail (GTK_IS_WIDGET (widget));
4880 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
4881 g_return_if_fail (name != NULL);
4883 if (!quark_composite_name)
4884 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
4886 gtk_object_set_data_by_id_full (GTK_OBJECT (widget),
4887 quark_composite_name,
4893 gtk_widget_get_composite_name (GtkWidget *widget)
4895 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4897 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
4898 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
4905 gtk_widget_push_composite_child (void)
4907 composite_child_stack++;
4911 gtk_widget_pop_composite_child (void)
4913 if (composite_child_stack)
4914 composite_child_stack--;
4918 * gtk_widget_push_colormap:
4919 * @cmap: a #GdkColormap
4921 * Pushes @cmap onto a global stack of colormaps; the topmost
4922 * colormap on the stack will be used to create all widgets.
4923 * Remove @cmap with gtk_widget_pop_colormap(). There's little
4924 * reason to use this function.
4928 gtk_widget_push_colormap (GdkColormap *cmap)
4930 g_return_if_fail (cmap != NULL);
4932 colormap_stack = g_slist_prepend (colormap_stack, cmap);
4936 * gtk_widget_pop_colormap:
4938 * Removes a colormap pushed with gtk_widget_push_colormap().
4942 gtk_widget_pop_colormap (void)
4945 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
4949 * gtk_widget_set_default_colormap:
4950 * @colormap: a #GdkColormap
4952 * Sets the default colormap to use when creating widgets.
4953 * gtk_widget_push_colormap() is a better function to use if
4954 * you only want to affect a few widgets, rather than all widgets.
4958 gtk_widget_set_default_colormap (GdkColormap *colormap)
4960 if (default_colormap != colormap)
4962 if (default_colormap)
4963 gdk_colormap_unref (default_colormap);
4964 default_colormap = colormap;
4965 if (default_colormap)
4966 gdk_colormap_ref (default_colormap);
4971 * gtk_widget_get_default_colormap:
4973 * Obtains the default colormap used to create widgets.
4975 * Return value: default widget colormap
4978 gtk_widget_get_default_colormap (void)
4980 if (!default_colormap)
4981 gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
4983 return default_colormap;
4987 * gtk_widget_get_default_visual:
4989 * Obtains the visual of the default colormap. Not really useful;
4990 * used to be useful before gdk_colormap_get_visual() existed.
4992 * Return value: visual of the default colormap
4995 gtk_widget_get_default_visual (void)
4997 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
5001 gtk_widget_emit_direction_changed (GtkWidget *widget,
5002 GtkTextDirection old_dir)
5004 PangoContext *context = gtk_widget_peek_pango_context (widget);
5007 pango_context_set_base_dir (context,
5008 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5009 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5011 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[DIRECTION_CHANGED], old_dir);
5015 * gtk_widget_set_direction:
5016 * @widget: a #GtkWidget
5017 * @dir: the new direction
5019 * Set the reading direction on a particular widget. This direction
5020 * controls the primary direction for widgets containing text,
5021 * and also the direction in which the children of a container are
5022 * packed. The ability to set the direction is present in order
5023 * so that correct localization into languages with right-to-left
5024 * reading directions can be done. Generally, applications will
5025 * let the default reading direction present, except for containers
5026 * where the containers are arranged in an order that is explicitely
5027 * visual rather than logical (such as buttons for text justificiation).
5029 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
5030 * set by gtk_widget_set_default_direction() will be used.
5033 gtk_widget_set_direction (GtkWidget *widget,
5034 GtkTextDirection dir)
5036 GtkTextDirection old_dir;
5038 g_return_if_fail (GTK_IS_WIDGET (widget));
5039 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
5041 old_dir = gtk_widget_get_direction (widget);
5043 if (dir == GTK_TEXT_DIR_NONE)
5044 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
5047 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
5048 if (dir == GTK_TEXT_DIR_LTR)
5049 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
5051 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
5054 if (old_dir != gtk_widget_get_direction (widget))
5055 gtk_widget_emit_direction_changed (widget, old_dir);
5059 * gtk_widget_get_direction:
5060 * @widget: a #GtkWidget
5062 * Get the reading direction for a particular widget. See
5063 * gtk_widget_set_direction().
5065 * Return value: the reading direction for the widget.
5068 gtk_widget_get_direction (GtkWidget *widget)
5070 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
5072 if (GTK_WIDGET_DIRECTION_SET (widget))
5073 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
5075 return gtk_default_direction;
5079 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
5081 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
5083 g_object_ref (G_OBJECT (widget));
5085 if (!GTK_WIDGET_DIRECTION_SET (widget))
5086 gtk_widget_emit_direction_changed (widget, old_dir);
5088 if (GTK_IS_CONTAINER (widget))
5089 gtk_container_forall (GTK_CONTAINER (widget),
5090 gtk_widget_set_default_direction_recurse,
5093 g_object_unref (G_OBJECT (widget));
5097 * gtk_widget_set_default_direction:
5098 * @dir: the new default direction. This cannot be
5099 * %GTK_TEXT_DIR_NONE.
5101 * Set the default reading direction for widgets where the
5102 * direction has not been explicitly set by gtk_widget_set_direction().
5105 gtk_widget_set_default_direction (GtkTextDirection dir)
5107 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
5109 if (dir != gtk_default_direction)
5111 GList *toplevels, *tmp_list;
5112 GtkTextDirection old_dir = gtk_default_direction;
5114 gtk_default_direction = dir;
5116 tmp_list = toplevels = gtk_window_list_toplevels ();
5117 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
5121 gtk_widget_set_default_direction_recurse (tmp_list->data,
5122 GUINT_TO_POINTER (old_dir));
5123 g_object_unref (tmp_list->data);
5124 tmp_list = tmp_list->next;
5127 g_list_free (toplevels);
5132 * gtk_widget_get_default_direction:
5134 * Return value: the current default direction. See
5135 * gtk_widget_set_direction().
5138 gtk_widget_get_default_direction (void)
5140 return gtk_default_direction;
5144 gtk_widget_dispose (GObject *object)
5146 GtkWidget *widget = GTK_WIDGET (object);
5149 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
5151 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
5152 if (GTK_WIDGET_REALIZED (widget))
5153 gtk_widget_unrealize (widget);
5155 G_OBJECT_CLASS (parent_class)->dispose (object);
5159 gtk_widget_real_destroy (GtkObject *object)
5163 /* gtk_object_destroy() will already hold a refcount on object
5165 widget = GTK_WIDGET (object);
5167 gtk_grab_remove (widget);
5168 gtk_selection_remove_all (widget);
5170 g_object_unref (widget->style);
5171 widget->style = gtk_widget_get_default_style ();
5172 g_object_ref (widget->style);
5174 GTK_OBJECT_CLASS (parent_class)->destroy (object);
5178 gtk_widget_finalize (GObject *object)
5180 GtkWidget *widget = GTK_WIDGET (object);
5181 GtkWidgetAuxInfo *aux_info;
5183 GdkExtensionMode *mode;
5184 GtkAccessible *accessible;
5186 gtk_grab_remove (widget);
5187 gtk_selection_remove_all (widget);
5189 g_object_unref (widget->style);
5190 widget->style = NULL;
5193 g_free (widget->name);
5195 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
5197 gtk_widget_aux_info_destroy (aux_info);
5199 events = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_event_mask);
5203 mode = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_extension_event_mode);
5207 accessible = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_accessible_object);
5209 g_object_unref (G_OBJECT (accessible));
5211 G_OBJECT_CLASS (parent_class)->finalize (object);
5214 /*****************************************
5215 * gtk_widget_real_map:
5220 *****************************************/
5223 gtk_widget_real_map (GtkWidget *widget)
5225 g_return_if_fail (GTK_IS_WIDGET (widget));
5226 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
5228 if (!GTK_WIDGET_MAPPED (widget))
5230 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
5232 if (!GTK_WIDGET_NO_WINDOW (widget))
5233 gdk_window_show (widget->window);
5237 /*****************************************
5238 * gtk_widget_real_unmap:
5243 *****************************************/
5246 gtk_widget_real_unmap (GtkWidget *widget)
5248 g_return_if_fail (GTK_IS_WIDGET (widget));
5250 if (GTK_WIDGET_MAPPED (widget))
5252 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5254 if (!GTK_WIDGET_NO_WINDOW (widget))
5255 gdk_window_hide (widget->window);
5259 /*****************************************
5260 * gtk_widget_real_realize:
5265 *****************************************/
5268 gtk_widget_real_realize (GtkWidget *widget)
5270 g_return_if_fail (GTK_IS_WIDGET (widget));
5271 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
5273 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
5276 widget->window = gtk_widget_get_parent_window (widget);
5277 gdk_window_ref (widget->window);
5279 widget->style = gtk_style_attach (widget->style, widget->window);
5282 /*****************************************
5283 * gtk_widget_real_unrealize:
5288 *****************************************/
5291 gtk_widget_real_unrealize (GtkWidget *widget)
5293 g_return_if_fail (GTK_IS_WIDGET (widget));
5295 if (GTK_WIDGET_MAPPED (widget))
5296 gtk_widget_real_unmap (widget);
5298 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
5300 /* printf ("unrealizing %s\n", gtk_type_name (GTK_OBJECT (widget)->klass->type));
5303 /* We must do unrealize child widget BEFORE container widget.
5304 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
5305 * So, unrealizing container widget bofore its children causes the problem
5306 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
5309 if (GTK_IS_CONTAINER (widget))
5310 gtk_container_forall (GTK_CONTAINER (widget),
5311 (GtkCallback) gtk_widget_unrealize,
5314 gtk_style_detach (widget->style);
5315 if (!GTK_WIDGET_NO_WINDOW (widget))
5317 gdk_window_set_user_data (widget->window, NULL);
5318 gdk_window_destroy (widget->window);
5319 widget->window = NULL;
5323 gdk_window_unref (widget->window);
5324 widget->window = NULL;
5327 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
5331 gtk_widget_real_size_request (GtkWidget *widget,
5332 GtkRequisition *requisition)
5334 g_return_if_fail (GTK_IS_WIDGET (widget));
5336 requisition->width = widget->requisition.width;
5337 requisition->height = widget->requisition.height;
5341 * _gtk_widget_peek_colormap:
5343 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
5345 * Return value: the currently pushed colormap, or %NULL if there is none.
5348 _gtk_widget_peek_colormap (void)
5351 return (GdkColormap*) colormap_stack->data;
5356 gtk_widget_propagate_state (GtkWidget *widget,
5361 /* don't call this function with state==GTK_STATE_INSENSITIVE,
5362 * parent_sensitive==TRUE on a sensitive widget
5365 old_state = GTK_WIDGET_STATE (widget);
5367 if (data->parent_sensitive)
5369 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5371 if (GTK_WIDGET_IS_SENSITIVE (widget))
5373 if (data->state_restoration)
5374 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
5376 GTK_WIDGET_STATE (widget) = data->state;
5380 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5381 if (!data->state_restoration &&
5382 data->state != GTK_STATE_INSENSITIVE)
5383 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5388 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
5389 if (!data->state_restoration)
5391 if (data->state != GTK_STATE_INSENSITIVE)
5392 GTK_WIDGET_SAVED_STATE (widget) = data->state;
5394 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
5395 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
5396 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
5399 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
5403 window = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
5405 gtk_window_set_focus (GTK_WINDOW (window), NULL);
5408 if (old_state != GTK_WIDGET_STATE (widget))
5410 gtk_widget_ref (widget);
5412 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
5413 gtk_grab_remove (widget);
5415 gtk_signal_emit (GTK_OBJECT (widget), widget_signals[STATE_CHANGED], old_state);
5418 if (GTK_IS_CONTAINER (widget))
5420 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
5421 data->state = GTK_WIDGET_STATE (widget);
5422 if (data->use_forall)
5423 gtk_container_forall (GTK_CONTAINER (widget),
5424 (GtkCallback) gtk_widget_propagate_state,
5427 gtk_container_foreach (GTK_CONTAINER (widget),
5428 (GtkCallback) gtk_widget_propagate_state,
5431 gtk_widget_unref (widget);
5436 * _gtk_widget_get_aux_info:
5437 * @widget: a #GtkWidget
5438 * @create: if %TRUE, create the structure if it doesn't exist
5440 * Get the #GtkWidgetAuxInfo structure for the widget.
5442 * Return value: the #GtkAuxInfo structure for the widget, or
5443 * %NULL if @create is %FALSE and one doesn't already exist.
5446 _gtk_widget_get_aux_info (GtkWidget *widget,
5449 GtkWidgetAuxInfo *aux_info;
5451 aux_info = gtk_object_get_data_by_id (GTK_OBJECT (widget), quark_aux_info);
5452 if (!aux_info && create)
5454 if (!aux_info_mem_chunk)
5455 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
5456 sizeof (GtkWidgetAuxInfo),
5457 1024, G_ALLOC_AND_FREE);
5458 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
5460 aux_info->width = -1;
5461 aux_info->height = -1;
5464 aux_info->x_set = FALSE;
5465 aux_info->y_set = FALSE;
5466 gtk_object_set_data_by_id (GTK_OBJECT (widget), quark_aux_info, aux_info);
5472 /*****************************************
5473 * gtk_widget_aux_info_destroy:
5478 *****************************************/
5481 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
5483 g_return_if_fail (aux_info != NULL);
5485 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
5489 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
5491 gdk_drawable_unref (info->shape_mask);
5495 /*****************************************
5496 * gtk_widget_shape_combine_mask:
5497 * set a shape for this widgets' gdk window, this allows for
5498 * transparent windows etc., see gdk_window_shape_combine_mask
5499 * for more information
5504 *****************************************/
5506 gtk_widget_shape_combine_mask (GtkWidget *widget,
5507 GdkBitmap *shape_mask,
5511 GtkWidgetShapeInfo* shape_info;
5513 g_return_if_fail (GTK_IS_WIDGET (widget));
5514 /* set_shape doesn't work on widgets without gdk window */
5515 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
5519 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5522 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
5524 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
5528 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
5530 shape_info = g_new (GtkWidgetShapeInfo, 1);
5531 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
5532 (GDestroyNotify) gtk_widget_shape_info_destroy);
5534 shape_info->shape_mask = gdk_drawable_ref (shape_mask);
5535 shape_info->offset_x = offset_x;
5536 shape_info->offset_y = offset_y;
5538 /* set shape if widget has a gdk window allready.
5539 * otherwise the shape is scheduled to be set by gtk_widget_realize.
5542 gdk_window_shape_combine_mask (widget->window, shape_mask,
5543 offset_x, offset_y);
5548 gtk_reset_shapes_recurse (GtkWidget *widget,
5554 gdk_window_get_user_data (window, &data);
5558 gdk_window_shape_combine_mask (window, NULL, 0, 0);
5559 for (list = gdk_window_peek_children (window); list; list = list->next)
5560 gtk_reset_shapes_recurse (widget, list->data);
5564 gtk_widget_reset_shapes (GtkWidget *widget)
5566 g_return_if_fail (GTK_IS_WIDGET (widget));
5567 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
5569 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
5570 gtk_reset_shapes_recurse (widget, widget->window);
5575 * @widget: a #GtkWidget
5577 * Adds a reference to a widget. This function is exactly the same
5578 * as calling g_object_ref(), and exists mostly for historical
5579 * reasons. It can still be convenient to avoid casting a widget
5580 * to a #GObject, it saves a small amount of typing.
5582 * Return value: the widget that was referenced
5585 gtk_widget_ref (GtkWidget *widget)
5587 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5589 return (GtkWidget*) g_object_ref ((GObject*) widget);
5594 * @widget: a #GtkWidget
5596 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
5600 gtk_widget_unref (GtkWidget *widget)
5602 g_return_if_fail (GTK_IS_WIDGET (widget));
5604 g_object_unref ((GObject*) widget);
5612 gtk_widget_class_install_style_property_parser (GtkWidgetClass *class,
5614 GtkRcPropertyParser parser)
5616 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5617 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5618 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
5619 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
5621 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
5623 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
5624 G_OBJECT_CLASS_NAME (class),
5629 g_param_spec_ref (pspec);
5630 g_param_spec_sink (pspec);
5631 g_param_spec_set_qdata (pspec, quark_property_parser, parser);
5632 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
5636 gtk_widget_class_install_style_property (GtkWidgetClass *class,
5639 GtkRcPropertyParser parser;
5641 g_return_if_fail (GTK_IS_WIDGET_CLASS (class));
5642 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
5644 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
5646 gtk_widget_class_install_style_property_parser (class, pspec, parser);
5650 gtk_widget_style_get_property (GtkWidget *widget,
5651 const gchar *property_name,
5656 g_return_if_fail (GTK_IS_WIDGET (widget));
5657 g_return_if_fail (property_name != NULL);
5658 g_return_if_fail (G_IS_VALUE (value));
5660 g_object_ref (widget);
5661 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5663 G_OBJECT_TYPE (widget),
5666 g_warning ("%s: widget class `%s' has no property named `%s'",
5668 G_OBJECT_TYPE_NAME (widget),
5672 const GValue *peek_value;
5674 peek_value = _gtk_style_peek_property_value (widget->style,
5675 G_OBJECT_TYPE (widget),
5677 g_param_spec_get_qdata (pspec, quark_property_parser));
5679 /* auto-conversion of the caller's value type
5681 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
5682 g_value_copy (peek_value, value);
5683 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
5684 g_value_transform (peek_value, value);
5686 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
5688 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
5689 G_VALUE_TYPE_NAME (value));
5691 g_object_unref (widget);
5695 gtk_widget_style_get_valist (GtkWidget *widget,
5696 const gchar *first_property_name,
5701 g_return_if_fail (GTK_IS_WIDGET (widget));
5703 g_object_ref (widget);
5705 name = first_property_name;
5708 const GValue *peek_value;
5712 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
5714 G_OBJECT_TYPE (widget),
5718 g_warning ("%s: widget class `%s' has no property named `%s'",
5720 G_OBJECT_TYPE_NAME (widget),
5724 /* style pspecs are always readable so we can spare that check here */
5726 peek_value = _gtk_style_peek_property_value (widget->style,
5727 G_OBJECT_TYPE (widget),
5729 g_param_spec_get_qdata (pspec, quark_property_parser));
5730 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
5733 g_warning ("%s: %s", G_STRLOC, error);
5738 name = va_arg (var_args, gchar*);
5741 g_object_unref (widget);
5745 gtk_widget_style_get (GtkWidget *widget,
5746 const gchar *first_property_name,
5751 g_return_if_fail (GTK_IS_WIDGET (widget));
5753 va_start (var_args, first_property_name);
5754 gtk_widget_style_get_valist (widget, first_property_name, var_args);
5760 * @widget: a #GtkWidget
5761 * @path_length: location to store length of the path
5762 * @path: location to store allocated path string
5763 * @path_reversed: location to store allocated reverse path string
5765 * Obtains the full path to @widget. The path is simply the name of a
5766 * widget and all its parents in the container hierarchy, separated by
5767 * periods. The name of a widget comes from
5768 * gtk_widget_get_name(). Paths are used to apply styles to a widget
5769 * in gtkrc configuration files. Widget names are the type of the
5770 * widget by default (e.g. "GtkButton") or can be set to an
5771 * application-specific value with gtk_widget_set_name(). By setting
5772 * the name of a widget, you allow users or theme authors to apply
5773 * styles to that specific widget in their gtkrc
5774 * file. @path_reversed_p fills in the path in reverse order,
5775 * i.e. starting with @widget's name instead of starting with the name
5776 * of @widget's outermost ancestor.
5780 gtk_widget_path (GtkWidget *widget,
5781 guint *path_length_p,
5783 gchar **path_reversed_p)
5785 static gchar *rev_path = NULL;
5786 static guint path_len = 0;
5789 g_return_if_fail (GTK_IS_WIDGET (widget));
5794 const gchar *string;
5799 string = gtk_widget_get_name (widget);
5800 l = strlen (string);
5801 while (path_len <= len + l + 1)
5803 path_len += INIT_PATH_SIZE;
5804 rev_path = g_realloc (rev_path, path_len);
5812 widget = widget->parent;
5815 rev_path[len++] = '.';
5817 rev_path[len++] = 0;
5822 *path_length_p = len - 1;
5823 if (path_reversed_p)
5824 *path_reversed_p = g_strdup (rev_path);
5827 *path_p = g_strdup (rev_path);
5828 g_strreverse (*path_p);
5833 * gtk_widget_class_path:
5834 * @widget: a #GtkWidget
5835 * @path_length: location to store the length of the class path
5836 * @path: location to store the class path as an allocated string
5837 * @path_reversed: location to store the reverse class path as an allocated string
5839 * Same as gtk_widget_path(), but always uses the name of a widget's type,
5840 * never uses a custom name set with gtk_widget_set_name().
5844 gtk_widget_class_path (GtkWidget *widget,
5845 guint *path_length_p,
5847 gchar **path_reversed_p)
5849 static gchar *rev_path = NULL;
5850 static guint path_len = 0;
5853 g_return_if_fail (GTK_IS_WIDGET (widget));
5858 const gchar *string;
5863 string = gtk_type_name (GTK_WIDGET_TYPE (widget));
5864 l = strlen (string);
5865 while (path_len <= len + l + 1)
5867 path_len += INIT_PATH_SIZE;
5868 rev_path = g_realloc (rev_path, path_len);
5876 widget = widget->parent;
5879 rev_path[len++] = '.';
5881 rev_path[len++] = 0;
5886 *path_length_p = len - 1;
5887 if (path_reversed_p)
5888 *path_reversed_p = g_strdup (rev_path);
5891 *path_p = g_strdup (rev_path);
5892 g_strreverse (*path_p);
5897 gtk_requisition_copy (const GtkRequisition *requisition)
5899 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
5903 gtk_requisition_free (GtkRequisition *requisition)
5905 g_free (requisition);
5908 AtkObject* gtk_widget_get_accessible (GtkWidget *widget)
5910 GtkWidgetClass *klass;
5912 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5914 klass = GTK_WIDGET_GET_CLASS (widget);
5916 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
5918 return klass->get_accessible (widget);
5921 AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget)
5923 AtkObject* accessible;
5925 accessible = g_object_get_qdata (G_OBJECT (widget),
5926 quark_accessible_object);
5929 AtkObjectFactory *factory;
5930 AtkRegistry *default_registry;
5932 default_registry = atk_get_default_registry ();
5933 factory = atk_registry_get_factory (default_registry,
5934 GTK_OBJECT_TYPE (widget));
5936 atk_object_factory_create_accessible (factory,
5938 g_object_set_qdata (G_OBJECT (widget),
5939 quark_accessible_object,
5946 * Initialize a AtkImplementorIface instance's virtual pointers as
5947 * appropriate to this implementor's class (GtkWidget).
5950 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
5952 iface->ref_accessible = gtk_widget_ref_accessible;
5956 gtk_widget_ref_accessible (AtkImplementor *implementor)
5958 AtkObject *accessible;
5960 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
5962 g_object_ref (G_OBJECT (accessible));