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/.
32 #include "gtkcontainer.h"
33 #include "gtkaccelmap.h"
34 #include "gtkclipboard.h"
35 #include "gtkiconfactory.h"
38 #include "gtkmarshalers.h"
40 #include "gtkselection.h"
41 #include "gtksettings.h"
42 #include "gtksizegroup.h"
43 #include "gtkwidget.h"
44 #include "gtkwindow.h"
45 #include "gtkbindings.h"
46 #include "gtkprivate.h"
48 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
49 #include <gobject/gvaluecollector.h>
50 #include <gobject/gobjectnotifyqueue.c>
51 #include "gdk/gdkkeysyms.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltips.h"
55 #include "gtkinvisible.h"
57 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
58 #define INIT_PATH_SIZE (512)
98 PROPERTY_NOTIFY_EVENT,
99 SELECTION_CLEAR_EVENT,
100 SELECTION_REQUEST_EVENT,
101 SELECTION_NOTIFY_EVENT,
116 VISIBILITY_NOTIFY_EVENT,
120 ACCEL_CLOSURES_CHANGED,
140 PROP_RECEIVES_DEFAULT,
141 PROP_COMPOSITE_CHILD,
144 PROP_EXTENSION_EVENTS,
148 typedef struct _GtkStateData GtkStateData;
153 guint state_restoration : 1;
154 guint parent_sensitive : 1;
155 guint use_forall : 1;
159 /* --- prototypes --- */
160 static void gtk_widget_class_init (GtkWidgetClass *klass);
161 static void gtk_widget_init (GtkWidget *widget);
162 static void gtk_widget_set_property (GObject *object,
166 static void gtk_widget_get_property (GObject *object,
170 static void gtk_widget_dispose (GObject *object);
171 static void gtk_widget_real_destroy (GtkObject *object);
172 static void gtk_widget_finalize (GObject *object);
173 static void gtk_widget_real_show (GtkWidget *widget);
174 static void gtk_widget_real_hide (GtkWidget *widget);
175 static void gtk_widget_real_map (GtkWidget *widget);
176 static void gtk_widget_real_unmap (GtkWidget *widget);
177 static void gtk_widget_real_realize (GtkWidget *widget);
178 static void gtk_widget_real_unrealize (GtkWidget *widget);
179 static void gtk_widget_real_size_request (GtkWidget *widget,
180 GtkRequisition *requisition);
181 static void gtk_widget_real_size_allocate (GtkWidget *widget,
182 GtkAllocation *allocation);
183 static void gtk_widget_style_set (GtkWidget *widget,
184 GtkStyle *previous_style);
185 static void gtk_widget_direction_changed (GtkWidget *widget,
186 GtkTextDirection previous_direction);
188 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
189 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
190 GtkWidgetHelpType help_type);
192 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
194 GParamSpec **pspecs);
195 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
197 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
199 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
200 GdkEventFocus *event);
201 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
202 GdkEventFocus *event);
203 static gboolean gtk_widget_real_focus (GtkWidget *widget,
204 GtkDirectionType direction);
205 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
206 static void gtk_widget_propagate_state (GtkWidget *widget,
208 static void gtk_widget_reset_rc_style (GtkWidget *widget);
209 static void gtk_widget_set_style_internal (GtkWidget *widget,
211 gboolean initial_emission);
212 static gint gtk_widget_event_internal (GtkWidget *widget,
214 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
215 gboolean group_cycling);
216 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
217 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
218 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
219 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
220 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
222 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
223 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
224 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
227 static void gtk_widget_set_usize_internal (GtkWidget *widget,
232 /* --- variables --- */
233 static gpointer parent_class = NULL;
234 static guint widget_signals[LAST_SIGNAL] = { 0 };
235 static GMemChunk *aux_info_mem_chunk = NULL;
236 static GtkStyle *gtk_default_style = NULL;
237 static GSList *colormap_stack = NULL;
238 static guint composite_child_stack = 0;
239 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
240 static GParamSpecPool *style_property_spec_pool = NULL;
242 static GQuark quark_property_parser = 0;
243 static GQuark quark_aux_info = 0;
244 static GQuark quark_accel_path = 0;
245 static GQuark quark_accel_closures = 0;
246 static GQuark quark_event_mask = 0;
247 static GQuark quark_extension_event_mode = 0;
248 static GQuark quark_parent_window = 0;
249 static GQuark quark_shape_info = 0;
250 static GQuark quark_colormap = 0;
251 static GQuark quark_pango_context = 0;
252 static GQuark quark_rc_style = 0;
253 static GQuark quark_accessible_object = 0;
254 static GQuark quark_mnemonic_labels = 0;
255 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
256 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
258 /* --- functions --- */
260 gtk_widget_get_type (void)
262 static GType widget_type = 0;
266 static const GTypeInfo widget_info =
268 sizeof (GtkWidgetClass),
269 NULL, /* base_init */
270 NULL, /* base_finalize */
271 (GClassInitFunc) gtk_widget_class_init,
272 NULL, /* class_finalize */
273 NULL, /* class_init */
276 (GInstanceInitFunc) gtk_widget_init,
277 NULL, /* value_table */
280 static const GInterfaceInfo accessibility_info =
282 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
283 (GInterfaceFinalizeFunc) NULL,
284 NULL /* interface data */
287 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
288 &widget_info, G_TYPE_FLAG_ABSTRACT);
290 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
291 &accessibility_info) ;
299 child_property_notify_dispatcher (GObject *object,
303 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
307 gtk_widget_class_init (GtkWidgetClass *klass)
309 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
310 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
311 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
312 GtkBindingSet *binding_set;
314 parent_class = g_type_class_peek_parent (klass);
316 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
317 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
318 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
319 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
320 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
321 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
322 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
323 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
324 quark_colormap = g_quark_from_static_string ("gtk-colormap");
325 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
326 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
327 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
328 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
330 style_property_spec_pool = g_param_spec_pool_new (FALSE);
331 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
332 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
333 cpn_context.dispatcher = child_property_notify_dispatcher;
334 _gtk_widget_child_property_notify_context = &cpn_context;
336 gobject_class->dispose = gtk_widget_dispose;
337 gobject_class->finalize = gtk_widget_finalize;
338 gobject_class->set_property = gtk_widget_set_property;
339 gobject_class->get_property = gtk_widget_get_property;
341 object_class->destroy = gtk_widget_real_destroy;
343 klass->activate_signal = 0;
344 klass->set_scroll_adjustments_signal = 0;
345 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
346 klass->show = gtk_widget_real_show;
347 klass->show_all = gtk_widget_show;
348 klass->hide = gtk_widget_real_hide;
349 klass->hide_all = gtk_widget_hide;
350 klass->map = gtk_widget_real_map;
351 klass->unmap = gtk_widget_real_unmap;
352 klass->realize = gtk_widget_real_realize;
353 klass->unrealize = gtk_widget_real_unrealize;
354 klass->size_request = gtk_widget_real_size_request;
355 klass->size_allocate = gtk_widget_real_size_allocate;
356 klass->state_changed = NULL;
357 klass->parent_set = NULL;
358 klass->hierarchy_changed = NULL;
359 klass->style_set = gtk_widget_style_set;
360 klass->direction_changed = gtk_widget_direction_changed;
361 klass->grab_notify = NULL;
362 klass->child_notify = NULL;
363 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
364 klass->grab_focus = gtk_widget_real_grab_focus;
365 klass->focus = gtk_widget_real_focus;
367 klass->button_press_event = NULL;
368 klass->button_release_event = NULL;
369 klass->motion_notify_event = NULL;
370 klass->delete_event = NULL;
371 klass->destroy_event = NULL;
372 klass->expose_event = NULL;
373 klass->key_press_event = gtk_widget_real_key_press_event;
374 klass->key_release_event = gtk_widget_real_key_release_event;
375 klass->enter_notify_event = NULL;
376 klass->leave_notify_event = NULL;
377 klass->configure_event = NULL;
378 klass->focus_in_event = gtk_widget_real_focus_in_event;
379 klass->focus_out_event = gtk_widget_real_focus_out_event;
380 klass->map_event = NULL;
381 klass->unmap_event = NULL;
382 klass->window_state_event = NULL;
383 klass->property_notify_event = _gtk_selection_property_notify;
384 klass->selection_clear_event = gtk_selection_clear;
385 klass->selection_request_event = _gtk_selection_request;
386 klass->selection_notify_event = _gtk_selection_notify;
387 klass->selection_received = NULL;
388 klass->proximity_in_event = NULL;
389 klass->proximity_out_event = NULL;
390 klass->drag_begin = NULL;
391 klass->drag_end = NULL;
392 klass->drag_data_delete = NULL;
393 klass->drag_leave = NULL;
394 klass->drag_motion = NULL;
395 klass->drag_drop = NULL;
396 klass->drag_data_received = NULL;
397 klass->screen_changed = NULL;
398 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
400 klass->show_help = gtk_widget_real_show_help;
402 /* Accessibility support */
403 klass->get_accessible = gtk_widget_real_get_accessible;
405 klass->no_expose_event = NULL;
407 g_object_class_install_property (gobject_class,
409 g_param_spec_string ("name",
411 P_("The name of the widget"),
414 g_object_class_install_property (gobject_class,
416 g_param_spec_object ("parent",
418 P_("The parent widget of this widget. Must be a Container widget"),
422 g_object_class_install_property (gobject_class,
424 g_param_spec_int ("width_request",
426 P_("Override for width request of the widget, or -1 if natural request should be used"),
431 g_object_class_install_property (gobject_class,
433 g_param_spec_int ("height_request",
434 P_("Height request"),
435 P_("Override for height request of the widget, or -1 if natural request should be used"),
440 g_object_class_install_property (gobject_class,
442 g_param_spec_boolean ("visible",
444 P_("Whether the widget is visible"),
447 g_object_class_install_property (gobject_class,
449 g_param_spec_boolean ("sensitive",
451 P_("Whether the widget responds to input"),
454 g_object_class_install_property (gobject_class,
456 g_param_spec_boolean ("app_paintable",
457 P_("Application paintable"),
458 P_("Whether the application will paint directly on the widget"),
461 g_object_class_install_property (gobject_class,
463 g_param_spec_boolean ("can_focus",
465 P_("Whether the widget can accept the input focus"),
468 g_object_class_install_property (gobject_class,
470 g_param_spec_boolean ("has_focus",
472 P_("Whether the widget has the input focus"),
475 g_object_class_install_property (gobject_class,
477 g_param_spec_boolean ("is_focus",
479 P_("Whether the widget is the focus widget within the toplevel"),
482 g_object_class_install_property (gobject_class,
484 g_param_spec_boolean ("can_default",
486 P_("Whether the widget can be the default widget"),
489 g_object_class_install_property (gobject_class,
491 g_param_spec_boolean ("has_default",
493 P_("Whether the widget is the default widget"),
496 g_object_class_install_property (gobject_class,
497 PROP_RECEIVES_DEFAULT,
498 g_param_spec_boolean ("receives_default",
499 P_("Receives default"),
500 P_("If TRUE, the widget will receive the default action when it is focused"),
503 g_object_class_install_property (gobject_class,
504 PROP_COMPOSITE_CHILD,
505 g_param_spec_boolean ("composite_child",
506 P_("Composite child"),
507 P_("Whether the widget is part of a composite widget"),
510 g_object_class_install_property (gobject_class,
512 g_param_spec_object ("style",
514 P_("The style of the widget, which contains information about how it will look (colors etc)"),
517 g_object_class_install_property (gobject_class,
519 g_param_spec_flags ("events",
521 P_("The event mask that decides what kind of GdkEvents this widget gets"),
525 g_object_class_install_property (gobject_class,
526 PROP_EXTENSION_EVENTS,
527 g_param_spec_enum ("extension_events",
528 P_("Extension events"),
529 P_("The mask that decides what kind of extension events this widget gets"),
530 GDK_TYPE_EXTENSION_MODE,
531 GDK_EXTENSION_EVENTS_NONE,
533 g_object_class_install_property (gobject_class,
535 g_param_spec_boolean ("no_show_all",
537 P_("Whether gtk_widget_show_all() should not affect this widget"),
540 widget_signals[SHOW] =
541 g_signal_new ("show",
542 G_TYPE_FROM_CLASS (gobject_class),
544 G_STRUCT_OFFSET (GtkWidgetClass, show),
546 _gtk_marshal_VOID__VOID,
548 widget_signals[HIDE] =
549 g_signal_new ("hide",
550 G_TYPE_FROM_CLASS (gobject_class),
552 G_STRUCT_OFFSET (GtkWidgetClass, hide),
554 _gtk_marshal_VOID__VOID,
556 widget_signals[MAP] =
558 G_TYPE_FROM_CLASS (gobject_class),
560 G_STRUCT_OFFSET (GtkWidgetClass, map),
562 _gtk_marshal_VOID__VOID,
564 widget_signals[UNMAP] =
565 g_signal_new ("unmap",
566 G_TYPE_FROM_CLASS (gobject_class),
568 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
570 _gtk_marshal_VOID__VOID,
572 widget_signals[REALIZE] =
573 g_signal_new ("realize",
574 G_TYPE_FROM_CLASS (gobject_class),
576 G_STRUCT_OFFSET (GtkWidgetClass, realize),
578 _gtk_marshal_VOID__VOID,
580 widget_signals[UNREALIZE] =
581 g_signal_new ("unrealize",
582 G_TYPE_FROM_CLASS (gobject_class),
584 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
586 _gtk_marshal_VOID__VOID,
588 widget_signals[SIZE_REQUEST] =
589 g_signal_new ("size_request",
590 G_TYPE_FROM_CLASS (gobject_class),
592 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
594 _gtk_marshal_VOID__BOXED,
596 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
597 widget_signals[SIZE_ALLOCATE] =
598 g_signal_new ("size_allocate",
599 G_TYPE_FROM_CLASS (gobject_class),
601 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
603 _gtk_marshal_VOID__BOXED,
605 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
606 widget_signals[STATE_CHANGED] =
607 g_signal_new ("state_changed",
608 G_TYPE_FROM_CLASS (gobject_class),
610 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
612 _gtk_marshal_VOID__ENUM,
614 GTK_TYPE_STATE_TYPE);
615 widget_signals[PARENT_SET] =
616 g_signal_new ("parent_set",
617 G_TYPE_FROM_CLASS (gobject_class),
619 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
621 _gtk_marshal_VOID__OBJECT,
624 widget_signals[HIERARCHY_CHANGED] =
625 g_signal_new ("hierarchy_changed",
626 G_TYPE_FROM_CLASS (gobject_class),
628 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
630 _gtk_marshal_VOID__OBJECT,
633 widget_signals[STYLE_SET] =
634 g_signal_new ("style_set",
635 G_TYPE_FROM_CLASS (gobject_class),
637 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
639 _gtk_marshal_VOID__OBJECT,
642 widget_signals[DIRECTION_CHANGED] =
643 g_signal_new ("direction_changed",
644 G_TYPE_FROM_CLASS (gobject_class),
646 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
648 _gtk_marshal_VOID__ENUM,
650 GTK_TYPE_TEXT_DIRECTION);
651 widget_signals[GRAB_NOTIFY] =
652 g_signal_new ("grab_notify",
653 G_TYPE_FROM_CLASS (gobject_class),
655 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
657 _gtk_marshal_VOID__BOOLEAN,
662 * GtkWidget::child-notify:
663 * @widget: the object which received the signal.
664 * @pspec: the #GParamSpec of the changed child property.
666 * The ::child-notify signal is emitted for each child property that has
667 * changed on an object. The signal's detail holds the property name.
669 widget_signals[CHILD_NOTIFY] =
670 g_signal_new ("child_notify",
671 G_TYPE_FROM_CLASS (gobject_class),
672 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
673 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
675 g_cclosure_marshal_VOID__PARAM,
678 widget_signals[MNEMONIC_ACTIVATE] =
679 g_signal_new ("mnemonic_activate",
680 G_TYPE_FROM_CLASS (gobject_class),
682 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
683 _gtk_boolean_handled_accumulator, NULL,
684 _gtk_marshal_BOOLEAN__BOOLEAN,
687 widget_signals[GRAB_FOCUS] =
688 g_signal_new ("grab_focus",
689 G_TYPE_FROM_CLASS (gobject_class),
690 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
691 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
693 _gtk_marshal_VOID__VOID,
695 widget_signals[FOCUS] =
696 g_signal_new ("focus",
697 G_TYPE_FROM_CLASS (object_class),
699 G_STRUCT_OFFSET (GtkWidgetClass, focus),
700 _gtk_boolean_handled_accumulator, NULL,
701 _gtk_marshal_BOOLEAN__ENUM,
703 GTK_TYPE_DIRECTION_TYPE);
704 widget_signals[EVENT] =
705 g_signal_new ("event",
706 G_TYPE_FROM_CLASS (gobject_class),
708 G_STRUCT_OFFSET (GtkWidgetClass, event),
709 _gtk_boolean_handled_accumulator, NULL,
710 _gtk_marshal_BOOLEAN__BOXED,
712 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
713 widget_signals[EVENT_AFTER] =
714 g_signal_new ("event-after",
715 G_TYPE_FROM_CLASS (gobject_class),
719 _gtk_marshal_VOID__BOXED,
721 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
722 widget_signals[BUTTON_PRESS_EVENT] =
723 g_signal_new ("button_press_event",
724 G_TYPE_FROM_CLASS (gobject_class),
726 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
727 _gtk_boolean_handled_accumulator, NULL,
728 _gtk_marshal_BOOLEAN__BOXED,
730 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
731 widget_signals[BUTTON_RELEASE_EVENT] =
732 g_signal_new ("button_release_event",
733 G_TYPE_FROM_CLASS (gobject_class),
735 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
736 _gtk_boolean_handled_accumulator, NULL,
737 _gtk_marshal_BOOLEAN__BOXED,
739 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
740 widget_signals[SCROLL_EVENT] =
741 g_signal_new ("scroll_event",
742 G_TYPE_FROM_CLASS (gobject_class),
744 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
745 _gtk_boolean_handled_accumulator, NULL,
746 _gtk_marshal_BOOLEAN__BOXED,
748 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
749 widget_signals[MOTION_NOTIFY_EVENT] =
750 g_signal_new ("motion_notify_event",
751 G_TYPE_FROM_CLASS (gobject_class),
753 G_STRUCT_OFFSET (GtkWidgetClass, motion_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[DELETE_EVENT] =
759 g_signal_new ("delete_event",
760 G_TYPE_FROM_CLASS (gobject_class),
762 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
763 _gtk_boolean_handled_accumulator, NULL,
764 _gtk_marshal_BOOLEAN__BOXED,
766 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
767 widget_signals[DESTROY_EVENT] =
768 g_signal_new ("destroy_event",
769 G_TYPE_FROM_CLASS (gobject_class),
771 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
772 _gtk_boolean_handled_accumulator, NULL,
773 _gtk_marshal_BOOLEAN__BOXED,
775 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
776 widget_signals[EXPOSE_EVENT] =
777 g_signal_new ("expose_event",
778 G_TYPE_FROM_CLASS (gobject_class),
780 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
781 _gtk_boolean_handled_accumulator, NULL,
782 _gtk_marshal_BOOLEAN__BOXED,
784 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
785 widget_signals[KEY_PRESS_EVENT] =
786 g_signal_new ("key_press_event",
787 G_TYPE_FROM_CLASS (gobject_class),
789 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
790 _gtk_boolean_handled_accumulator, NULL,
791 _gtk_marshal_BOOLEAN__BOXED,
793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
794 widget_signals[KEY_RELEASE_EVENT] =
795 g_signal_new ("key_release_event",
796 G_TYPE_FROM_CLASS (gobject_class),
798 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
799 _gtk_boolean_handled_accumulator, NULL,
800 _gtk_marshal_BOOLEAN__BOXED,
802 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
803 widget_signals[ENTER_NOTIFY_EVENT] =
804 g_signal_new ("enter_notify_event",
805 G_TYPE_FROM_CLASS (gobject_class),
807 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
808 _gtk_boolean_handled_accumulator, NULL,
809 _gtk_marshal_BOOLEAN__BOXED,
811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
812 widget_signals[LEAVE_NOTIFY_EVENT] =
813 g_signal_new ("leave_notify_event",
814 G_TYPE_FROM_CLASS (gobject_class),
816 G_STRUCT_OFFSET (GtkWidgetClass, leave_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[CONFIGURE_EVENT] =
822 g_signal_new ("configure_event",
823 G_TYPE_FROM_CLASS (gobject_class),
825 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
826 _gtk_boolean_handled_accumulator, NULL,
827 _gtk_marshal_BOOLEAN__BOXED,
829 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
830 widget_signals[FOCUS_IN_EVENT] =
831 g_signal_new ("focus_in_event",
832 G_TYPE_FROM_CLASS (gobject_class),
834 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
835 _gtk_boolean_handled_accumulator, NULL,
836 _gtk_marshal_BOOLEAN__BOXED,
838 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
839 widget_signals[FOCUS_OUT_EVENT] =
840 g_signal_new ("focus_out_event",
841 G_TYPE_FROM_CLASS (gobject_class),
843 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
844 _gtk_boolean_handled_accumulator, NULL,
845 _gtk_marshal_BOOLEAN__BOXED,
847 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
848 widget_signals[MAP_EVENT] =
849 g_signal_new ("map_event",
850 G_TYPE_FROM_CLASS (gobject_class),
852 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
853 _gtk_boolean_handled_accumulator, NULL,
854 _gtk_marshal_BOOLEAN__BOXED,
856 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
857 widget_signals[UNMAP_EVENT] =
858 g_signal_new ("unmap_event",
859 G_TYPE_FROM_CLASS (gobject_class),
861 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
862 _gtk_boolean_handled_accumulator, NULL,
863 _gtk_marshal_BOOLEAN__BOXED,
865 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
866 widget_signals[PROPERTY_NOTIFY_EVENT] =
867 g_signal_new ("property_notify_event",
868 G_TYPE_FROM_CLASS (gobject_class),
870 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
871 _gtk_boolean_handled_accumulator, NULL,
872 _gtk_marshal_BOOLEAN__BOXED,
874 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
875 widget_signals[SELECTION_CLEAR_EVENT] =
876 g_signal_new ("selection_clear_event",
877 G_TYPE_FROM_CLASS (gobject_class),
879 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
880 _gtk_boolean_handled_accumulator, NULL,
881 _gtk_marshal_BOOLEAN__BOXED,
883 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
884 widget_signals[SELECTION_REQUEST_EVENT] =
885 g_signal_new ("selection_request_event",
886 G_TYPE_FROM_CLASS (gobject_class),
888 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
889 _gtk_boolean_handled_accumulator, NULL,
890 _gtk_marshal_BOOLEAN__BOXED,
892 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
893 widget_signals[SELECTION_NOTIFY_EVENT] =
894 g_signal_new ("selection_notify_event",
895 G_TYPE_FROM_CLASS (gobject_class),
897 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
898 _gtk_boolean_handled_accumulator, NULL,
899 _gtk_marshal_BOOLEAN__BOXED,
901 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
902 widget_signals[SELECTION_RECEIVED] =
903 g_signal_new ("selection_received",
904 G_TYPE_FROM_CLASS (gobject_class),
906 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
908 _gtk_marshal_VOID__BOXED_UINT,
910 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
912 widget_signals[SELECTION_GET] =
913 g_signal_new ("selection_get",
914 G_TYPE_FROM_CLASS (gobject_class),
916 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
918 _gtk_marshal_VOID__BOXED_UINT_UINT,
920 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
923 widget_signals[PROXIMITY_IN_EVENT] =
924 g_signal_new ("proximity_in_event",
925 G_TYPE_FROM_CLASS (gobject_class),
927 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
928 _gtk_boolean_handled_accumulator, NULL,
929 _gtk_marshal_BOOLEAN__BOXED,
931 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
932 widget_signals[PROXIMITY_OUT_EVENT] =
933 g_signal_new ("proximity_out_event",
934 G_TYPE_FROM_CLASS (gobject_class),
936 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
937 _gtk_boolean_handled_accumulator, NULL,
938 _gtk_marshal_BOOLEAN__BOXED,
940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
943 * GtkWidget::drag-leave:
944 * @widget: the object which received the signal.
945 * @drag_context: the drag context
946 * @time: the timestamp of the motion event
948 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
949 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
950 * undo highlighting with gtk_drag_unhighlight()
952 widget_signals[DRAG_LEAVE] =
953 g_signal_new ("drag_leave",
954 G_TYPE_FROM_CLASS (gobject_class),
956 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
958 _gtk_marshal_VOID__OBJECT_UINT,
960 GDK_TYPE_DRAG_CONTEXT,
964 * GtkWidget::drag-begin:
965 * @widget: the object which received the signal.
966 * @drag_context: the drag context
968 * The ::drag-begin signal is emitted on the drag source when a drag is started.
969 * A typical reason to connect to this signal is to set up a custom drag icon with
970 * gtk_drag_source_set_icon().
972 widget_signals[DRAG_BEGIN] =
973 g_signal_new ("drag_begin",
974 G_TYPE_FROM_CLASS (gobject_class),
976 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
978 _gtk_marshal_VOID__OBJECT,
980 GDK_TYPE_DRAG_CONTEXT);
983 * GtkWidget::drag-end:
984 * @widget: the object which received the signal.
985 * @drag_context: the drag context
987 * The ::drag-end signal is emitted on the drag source when a drag is finished.
988 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
990 widget_signals[DRAG_END] =
991 g_signal_new ("drag_end",
992 G_TYPE_FROM_CLASS (gobject_class),
994 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
996 _gtk_marshal_VOID__OBJECT,
998 GDK_TYPE_DRAG_CONTEXT);
1001 * GtkWidget::drag-data-delete:
1002 * @widget: the object which received the signal.
1003 * @drag_context: the drag context
1005 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1006 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1007 * the data that has been dropped. What "delete" means, depends on the context of the drag
1010 widget_signals[DRAG_DATA_DELETE] =
1011 g_signal_new ("drag_data_delete",
1012 G_TYPE_FROM_CLASS (gobject_class),
1014 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1016 _gtk_marshal_VOID__OBJECT,
1018 GDK_TYPE_DRAG_CONTEXT);
1021 * GtkWidget::drag-motion:
1022 * @widget: the object which received the signal.
1023 * @drag_context: the drag context
1024 * @x: the x coordinate of the current cursor position
1025 * @y: the y coordinate of the current cursor position
1026 * @time: the timestamp of the motion event
1027 * @returns: whether the cursor position is in a drop zone
1029 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1030 * the widget during a drag. The signal handler must determine whether the cursor position is in
1031 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1032 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1033 * providing the necessary information for displaying feedback to the user, by calling
1034 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1035 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1036 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1039 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1040 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1041 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1042 * the drop site with gtk_drag_highlight().
1044 * <informalexample><programlisting>
1046 * drag_motion (GtkWidget *widget,
1047 * GdkDragContext *context,
1054 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1056 * if (!private_data->drag_highlight)
1058 * private_data->drag_highlight = 1;
1059 * gtk_drag_highlight (widget);
1062 * target = gtk_drag_dest_find_target (widget, context, NULL);
1063 * if (target == GDK_NONE)
1064 * gdk_drag_status (context, 0, time);
1067 * private_data->pending_status = context->suggested_action;
1068 * gtk_drag_get_data (widget, context, target, time);
1075 * drag_data_received (GtkWidget *widget,
1076 * GdkDragContext *context,
1079 * GtkSelectionData *selection_data,
1083 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1085 * if (private_data->suggested_action)
1087 * private_data->suggested_action = 0;
1089 * /<!-- -->* We are getting this data due to a request in drag_motion,
1090 * * rather than due to a request in drag_drop, so we are just
1091 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1093 * str = gtk_selection_data_get_text (selection_data);
1094 * if (!data_is_acceptable (str))
1095 * gdk_drag_status (context, 0, time);
1097 * gdk_drag_status (context, private_data->suggested_action, time);
1101 * /<!-- -->* accept the drop *<!-- -->/
1104 * </programlisting></informalexample>
1106 widget_signals[DRAG_MOTION] =
1107 g_signal_new ("drag_motion",
1108 G_TYPE_FROM_CLASS (gobject_class),
1110 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1111 _gtk_boolean_handled_accumulator, NULL,
1112 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1114 GDK_TYPE_DRAG_CONTEXT,
1120 * GtkWidget::drag-drop:
1121 * @widget: the object which received the signal.
1122 * @drag_context: the drag context
1123 * @x: the x coordinate of the current cursor position
1124 * @y: the y coordinate of the current cursor position
1125 * @time: the timestamp of the motion event
1126 * @returns: whether the cursor position is in a drop zone
1128 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1129 * onto the widget. The signal handler must determine whether the cursor position is in
1130 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1131 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1132 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1133 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1134 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1135 * supported targets.
1137 widget_signals[DRAG_DROP] =
1138 g_signal_new ("drag_drop",
1139 G_TYPE_FROM_CLASS (gobject_class),
1141 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1142 _gtk_boolean_handled_accumulator, NULL,
1143 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1145 GDK_TYPE_DRAG_CONTEXT,
1151 * GtkWidget::drag-data-get:
1152 * @widget: the object which received the signal.
1153 * @drag_context: the drag context
1154 * @data: the #GtkSelectionData to be filled with the dragged data
1155 * @info: the info that has been registered with the target in the #GtkTargetList.
1156 * @time: the timestamp at which the data was requested
1158 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1159 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1160 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1161 * gtk_selection_data_set_text().
1163 widget_signals[DRAG_DATA_GET] =
1164 g_signal_new ("drag_data_get",
1165 G_TYPE_FROM_CLASS (gobject_class),
1167 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1169 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1171 GDK_TYPE_DRAG_CONTEXT,
1172 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1177 * GtkWidget::drag-data-received:
1178 * @widget: the object which received the signal.
1179 * @drag_context: the drag context
1180 * @x: where the drop happened
1181 * @y: where the drop happened
1182 * @data: the received data
1183 * @info: the info that has been registered with the target in the #GtkTargetList.
1184 * @time: the timestamp at which the data was received
1186 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1187 * received. If the data was received in order to determine whether the drop will be accepted,
1188 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1189 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1190 * received), the handler for this signal is expected to process the received data and then call
1191 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1194 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1195 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1196 * <informalexample><programlisting>
1198 * drag_data_received (GtkWidget *widget,
1199 * GdkDragContext *drag_context,
1202 * GtkSelectionData *data,
1206 * if ((data->length >= 0) && (data->format == 8))
1208 * if (drag_context->action == GDK_ACTION_ASK)
1210 * GtkWidget *dialog;
1213 * dialog = gtk_message_dialog_new (NULL,
1214 * GTK_DIALOG_MODAL |
1215 * GTK_DIALOG_DESTROY_WITH_PARENT,
1217 * GTK_BUTTONS_YES_NO,
1218 * "Move the data ?\n");
1219 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1220 * gtk_widget_destroy (dialog);
1222 * if (response == GTK_RESPONSE_YES)
1223 * drag_context->action = GDK_ACTION_MOVE;
1225 * drag_context->action = GDK_ACTION_COPY;
1228 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1232 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1234 * </programlisting></informalexample>
1236 widget_signals[DRAG_DATA_RECEIVED] =
1237 g_signal_new ("drag_data_received",
1238 G_TYPE_FROM_CLASS (gobject_class),
1240 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1242 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1244 GDK_TYPE_DRAG_CONTEXT,
1247 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1250 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1251 g_signal_new ("visibility_notify_event",
1252 G_TYPE_FROM_CLASS (gobject_class),
1254 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1255 _gtk_boolean_handled_accumulator, NULL,
1256 _gtk_marshal_BOOLEAN__BOXED,
1258 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1259 widget_signals[CLIENT_EVENT] =
1260 g_signal_new ("client_event",
1261 G_TYPE_FROM_CLASS (gobject_class),
1263 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1264 _gtk_boolean_handled_accumulator, NULL,
1265 _gtk_marshal_BOOLEAN__BOXED,
1267 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1268 widget_signals[NO_EXPOSE_EVENT] =
1269 g_signal_new ("no_expose_event",
1270 G_TYPE_FROM_CLASS (gobject_class),
1272 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1273 _gtk_boolean_handled_accumulator, NULL,
1274 _gtk_marshal_BOOLEAN__BOXED,
1276 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1277 widget_signals[WINDOW_STATE_EVENT] =
1278 g_signal_new ("window_state_event",
1279 G_TYPE_FROM_CLASS (gobject_class),
1281 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1282 _gtk_boolean_handled_accumulator, NULL,
1283 _gtk_marshal_BOOLEAN__BOXED,
1285 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1287 * GtkWidget::popup-menu
1288 * @widget: the object which received the signal
1289 * @returns: TRUE if a menu was activated
1291 * This signal gets emitted whenever a widget should pop up a context-sensitive
1292 * menu. This usually happens through the standard key binding mechanism; by
1293 * pressing a certain key while a widget is focused, the user can cause the
1294 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1295 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1296 * example of how to use this signal.
1298 widget_signals[POPUP_MENU] =
1299 g_signal_new ("popup_menu",
1300 G_TYPE_FROM_CLASS (gobject_class),
1301 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1302 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1303 _gtk_boolean_handled_accumulator, NULL,
1304 _gtk_marshal_BOOLEAN__VOID,
1306 widget_signals[SHOW_HELP] =
1307 g_signal_new ("show_help",
1308 G_TYPE_FROM_CLASS (gobject_class),
1309 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1310 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1311 _gtk_boolean_handled_accumulator, NULL,
1312 _gtk_marshal_BOOLEAN__ENUM,
1314 GTK_TYPE_WIDGET_HELP_TYPE);
1315 widget_signals[ACCEL_CLOSURES_CHANGED] =
1316 g_signal_new ("accel_closures_changed",
1317 G_TYPE_FROM_CLASS (gobject_class),
1321 _gtk_marshal_NONE__NONE,
1323 widget_signals[SCREEN_CHANGED] =
1324 g_signal_new ("screen_changed",
1325 G_TYPE_FROM_CLASS (gobject_class),
1327 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1329 _gtk_marshal_VOID__OBJECT,
1333 * GtkWidget::can-activate-accel:
1334 * @widget: the object which received the signal
1335 * @signal_id: the ID of a signal installed on @widget
1336 * @returns: %TRUE if the signal can be activated.
1338 * Determines whether an accelerator that activates the signal
1339 * identified by @signal_id can currently be activated.
1340 * This signal is present to allow applications and derived
1341 * widgets to override the default #GtkWidget handling
1342 * for determining whether an accelerator can be activated.
1344 widget_signals[CAN_ACTIVATE_ACCEL] =
1345 g_signal_new ("can_activate_accel",
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1349 _gtk_boolean_handled_accumulator, NULL,
1350 _gtk_marshal_BOOLEAN__UINT,
1351 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1353 binding_set = gtk_binding_set_by_class (klass);
1354 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1356 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1359 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1361 GTK_TYPE_WIDGET_HELP_TYPE,
1362 GTK_WIDGET_HELP_TOOLTIP);
1363 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1365 GTK_TYPE_WIDGET_HELP_TYPE,
1366 GTK_WIDGET_HELP_TOOLTIP);
1367 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1369 GTK_TYPE_WIDGET_HELP_TYPE,
1370 GTK_WIDGET_HELP_WHATS_THIS);
1371 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1373 GTK_TYPE_WIDGET_HELP_TYPE,
1374 GTK_WIDGET_HELP_WHATS_THIS);
1376 gtk_widget_class_install_style_property (klass,
1377 g_param_spec_boolean ("interior_focus",
1378 P_("Interior Focus"),
1379 P_("Whether to draw the focus indicator inside widgets"),
1383 gtk_widget_class_install_style_property (klass,
1384 g_param_spec_int ("focus-line-width",
1385 P_("Focus linewidth"),
1386 P_("Width, in pixels, of the focus indicator line"),
1390 gtk_widget_class_install_style_property (klass,
1391 g_param_spec_string ("focus-line-pattern",
1392 P_("Focus line dash pattern"),
1393 P_("Dash pattern used to draw the focus indicator"),
1396 gtk_widget_class_install_style_property (klass,
1397 g_param_spec_int ("focus-padding",
1398 P_("Focus padding"),
1399 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1402 gtk_widget_class_install_style_property (klass,
1403 g_param_spec_boxed ("cursor-color",
1405 P_("Color with which to draw insertion cursor"),
1408 gtk_widget_class_install_style_property (klass,
1409 g_param_spec_boxed ("secondary-cursor-color",
1410 P_("Secondary cursor color"),
1411 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1414 gtk_widget_class_install_style_property (klass,
1415 g_param_spec_float ("cursor-aspect-ratio",
1416 P_("Cursor line aspect ratio"),
1417 P_("Aspect ratio with which to draw insertion cursor"),
1423 gtk_widget_set_property (GObject *object,
1425 const GValue *value,
1428 GtkWidget *widget = GTK_WIDGET (object);
1432 guint32 saved_flags;
1435 gtk_widget_set_name (widget, g_value_get_string (value));
1438 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1440 case PROP_WIDTH_REQUEST:
1441 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1443 case PROP_HEIGHT_REQUEST:
1444 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1447 if (g_value_get_boolean (value))
1448 gtk_widget_show (widget);
1450 gtk_widget_hide (widget);
1452 case PROP_SENSITIVE:
1453 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1455 case PROP_APP_PAINTABLE:
1456 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1458 case PROP_CAN_FOCUS:
1459 saved_flags = GTK_WIDGET_FLAGS (widget);
1460 if (g_value_get_boolean (value))
1461 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1463 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1464 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1465 gtk_widget_queue_resize (widget);
1467 case PROP_HAS_FOCUS:
1468 if (g_value_get_boolean (value))
1469 gtk_widget_grab_focus (widget);
1472 if (g_value_get_boolean (value))
1473 gtk_widget_grab_focus (widget);
1475 case PROP_CAN_DEFAULT:
1476 saved_flags = GTK_WIDGET_FLAGS (widget);
1477 if (g_value_get_boolean (value))
1478 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1480 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1481 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1482 gtk_widget_queue_resize (widget);
1484 case PROP_HAS_DEFAULT:
1485 if (g_value_get_boolean (value))
1486 gtk_widget_grab_default (widget);
1488 case PROP_RECEIVES_DEFAULT:
1489 if (g_value_get_boolean (value))
1490 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1492 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1495 gtk_widget_set_style (widget, g_value_get_object (value));
1498 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1499 gtk_widget_set_events (widget, g_value_get_flags (value));
1501 case PROP_EXTENSION_EVENTS:
1502 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1504 case PROP_NO_SHOW_ALL:
1505 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1513 gtk_widget_get_property (GObject *object,
1518 GtkWidget *widget = GTK_WIDGET (object);
1523 GdkExtensionMode *modep;
1527 g_value_set_string (value, widget->name);
1529 g_value_set_string (value, "");
1533 g_value_set_object (value, widget->parent);
1535 g_value_set_object (value, NULL);
1537 case PROP_WIDTH_REQUEST:
1540 gtk_widget_get_size_request (widget, &w, NULL);
1541 g_value_set_int (value, w);
1544 case PROP_HEIGHT_REQUEST:
1547 gtk_widget_get_size_request (widget, NULL, &h);
1548 g_value_set_int (value, h);
1552 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1554 case PROP_SENSITIVE:
1555 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1557 case PROP_APP_PAINTABLE:
1558 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1560 case PROP_CAN_FOCUS:
1561 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1563 case PROP_HAS_FOCUS:
1564 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1567 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1569 case PROP_CAN_DEFAULT:
1570 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1572 case PROP_HAS_DEFAULT:
1573 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1575 case PROP_RECEIVES_DEFAULT:
1576 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1578 case PROP_COMPOSITE_CHILD:
1579 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1582 g_value_set_object (value, gtk_widget_get_style (widget));
1585 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1587 g_value_set_flags (value, 0);
1589 g_value_set_flags (value, *eventp);
1591 case PROP_EXTENSION_EVENTS:
1592 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1594 g_value_set_enum (value, 0);
1596 g_value_set_enum (value, (GdkExtensionMode) *modep);
1598 case PROP_NO_SHOW_ALL:
1599 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1602 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1608 gtk_widget_init (GtkWidget *widget)
1610 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1611 widget->state = GTK_STATE_NORMAL;
1612 widget->saved_state = GTK_STATE_NORMAL;
1613 widget->name = NULL;
1614 widget->requisition.width = 0;
1615 widget->requisition.height = 0;
1616 widget->allocation.x = -1;
1617 widget->allocation.y = -1;
1618 widget->allocation.width = 1;
1619 widget->allocation.height = 1;
1620 widget->window = NULL;
1621 widget->parent = NULL;
1623 GTK_WIDGET_SET_FLAGS (widget,
1625 GTK_PARENT_SENSITIVE |
1626 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1627 GTK_DOUBLE_BUFFERED);
1629 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1630 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1631 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1633 widget->style = gtk_widget_get_default_style ();
1634 g_object_ref (widget->style);
1639 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1641 GParamSpec **pspecs)
1643 GtkWidget *container = widget->parent;
1646 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1647 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1651 * gtk_widget_freeze_child_notify:
1652 * @widget: a #GtkWidget
1654 * Stops emission of "child-notify" signals on @widget. The signals are
1655 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1657 * This is the analogue of g_object_freeze_notify() for child properties.
1660 gtk_widget_freeze_child_notify (GtkWidget *widget)
1662 g_return_if_fail (GTK_IS_WIDGET (widget));
1664 if (!G_OBJECT (widget)->ref_count)
1667 g_object_ref (widget);
1668 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1669 g_object_unref (widget);
1673 * gtk_widget_child_notify:
1674 * @widget: a #GtkWidget
1675 * @child_property: the name of a child property installed on the
1676 * class of @widget<!-- -->'s parent.
1678 * Emits a "child-notify" signal for the
1679 * <link linkend="child-properties">child property</link> @child_property
1682 * This is the analogue of g_object_notify() for child properties.
1685 gtk_widget_child_notify (GtkWidget *widget,
1686 const gchar *child_property)
1690 g_return_if_fail (GTK_IS_WIDGET (widget));
1691 g_return_if_fail (child_property != NULL);
1692 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1695 g_object_ref (widget);
1696 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1698 G_OBJECT_TYPE (widget->parent),
1701 g_warning ("%s: container class `%s' has no child property named `%s'",
1703 G_OBJECT_TYPE_NAME (widget->parent),
1707 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1709 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1710 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1712 g_object_unref (widget);
1716 * gtk_widget_thaw_child_notify:
1717 * @widget: a #GtkWidget
1719 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1720 * This causes all queued "child-notify" signals on @widget to be emitted.
1723 gtk_widget_thaw_child_notify (GtkWidget *widget)
1725 GObjectNotifyQueue *nqueue;
1727 g_return_if_fail (GTK_IS_WIDGET (widget));
1729 if (!G_OBJECT (widget)->ref_count)
1732 g_object_ref (widget);
1733 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1734 if (!nqueue || !nqueue->freeze_count)
1735 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1736 G_OBJECT_TYPE_NAME (widget), widget);
1738 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1739 g_object_unref (widget);
1745 * @type: type ID of the widget to create
1746 * @first_property_name: name of first property to set
1747 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1749 * This is a convenience function for creating a widget and setting
1750 * its properties in one go. For example you might write:
1751 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1752 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1753 * g_object_new(), but returns a widget so you don't have to
1754 * cast the object yourself.
1756 * Return value: a new #GtkWidget of type @widget_type
1759 gtk_widget_new (GType type,
1760 const gchar *first_property_name,
1766 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1768 va_start (var_args, first_property_name);
1769 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1777 * @widget: a #GtkWidget
1778 * @first_property_name: name of first property to set
1779 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1781 * Like g_object_set() - there's no reason to use this instead of
1785 gtk_widget_set (GtkWidget *widget,
1786 const gchar *first_property_name,
1791 g_return_if_fail (GTK_IS_WIDGET (widget));
1793 va_start (var_args, first_property_name);
1794 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1799 gtk_widget_queue_draw_child (GtkWidget *widget)
1803 parent = widget->parent;
1804 if (parent && GTK_WIDGET_DRAWABLE (parent))
1805 gtk_widget_queue_draw_area (parent,
1806 widget->allocation.x,
1807 widget->allocation.y,
1808 widget->allocation.width,
1809 widget->allocation.height);
1813 * gtk_widget_unparent:
1814 * @widget: a #GtkWidget
1816 * This function is only for use in widget implementations.
1817 * Should be called by implementations of the remove method
1818 * on #GtkContainer, to dissociate a child from the container.
1821 gtk_widget_unparent (GtkWidget *widget)
1823 GObjectNotifyQueue *nqueue;
1824 GtkWidget *toplevel;
1825 GtkWidget *old_parent;
1827 g_return_if_fail (GTK_IS_WIDGET (widget));
1828 if (widget->parent == NULL)
1831 /* keep this function in sync with gtk_menu_detach()
1834 g_object_freeze_notify (G_OBJECT (widget));
1835 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1837 toplevel = gtk_widget_get_toplevel (widget);
1838 if (GTK_WIDGET_TOPLEVEL (toplevel))
1839 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1841 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1842 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1844 /* If we are unanchoring the child, we save around the toplevel
1845 * to emit hierarchy changed
1847 if (GTK_WIDGET_ANCHORED (widget->parent))
1848 g_object_ref (toplevel);
1852 gtk_widget_queue_draw_child (widget);
1854 /* Reset the width and height here, to force reallocation if we
1855 * get added back to a new parent. This won't work if our new
1856 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1857 * (would 0x0 be OK here?)
1859 widget->allocation.width = 1;
1860 widget->allocation.height = 1;
1862 if (GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_IN_REPARENT (widget))
1863 gtk_widget_unrealize (widget);
1865 /* Removing a widget from a container restores the child visible
1866 * flag to the default state, so it doesn't affect the child
1867 * in the next parent.
1869 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1871 old_parent = widget->parent;
1872 widget->parent = NULL;
1873 gtk_widget_set_parent_window (widget, NULL);
1874 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1877 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1878 g_object_unref (toplevel);
1881 g_object_notify (G_OBJECT (widget), "parent");
1882 g_object_thaw_notify (G_OBJECT (widget));
1883 if (!widget->parent)
1884 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1885 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1886 g_object_unref (widget);
1890 * gtk_widget_destroy:
1891 * @widget: a #GtkWidget
1893 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1894 * you don't have to cast the widget to #GtkObject. When a widget is
1895 * destroyed, it will break any references it holds to other objects.
1896 * If the widget is inside a container, the widget will be removed
1897 * from the container. If the widget is a toplevel (derived from
1898 * #GtkWindow), it will be removed from the list of toplevels, and the
1899 * reference GTK+ holds to it will be removed. Removing a
1900 * widget from its container or the list of toplevels results in the
1901 * widget being finalized, unless you've added additional references
1902 * to the widget with g_object_ref().
1904 * In most cases, only toplevel widgets (windows) require explicit
1905 * destruction, because when you destroy a toplevel its children will
1906 * be destroyed as well.
1910 gtk_widget_destroy (GtkWidget *widget)
1912 g_return_if_fail (GTK_IS_WIDGET (widget));
1914 gtk_object_destroy ((GtkObject*) widget);
1918 * gtk_widget_destroyed:
1919 * @widget: a #GtkWidget
1920 * @widget_pointer: address of a variable that contains @widget
1922 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1923 * %NULL. It's intended to be used as a callback connected to the
1924 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1925 * as a signal handler, and pass the address of your widget variable
1926 * as user data. Then when the widget is destroyed, the variable will
1927 * be set to %NULL. Useful for example to avoid multiple copies
1928 * of the same dialog.
1932 gtk_widget_destroyed (GtkWidget *widget,
1933 GtkWidget **widget_pointer)
1935 /* Don't make any assumptions about the
1937 * Even check widget_pointer.
1940 *widget_pointer = NULL;
1945 * @widget: a #GtkWidget
1947 * Flags a widget to be displayed. Any widget that isn't shown will
1948 * not appear on the screen. If you want to show all the widgets in a
1949 * container, it's easier to call gtk_widget_show_all() on the
1950 * container, instead of individually showing the widgets.
1952 * Remember that you have to show the containers containing a widget,
1953 * in addition to the widget itself, before it will appear onscreen.
1955 * When a toplevel container is shown, it is immediately realized and
1956 * mapped; other shown widgets are realized and mapped when their
1957 * toplevel container is realized and mapped.
1961 gtk_widget_show (GtkWidget *widget)
1963 if (!GTK_WIDGET_VISIBLE (widget))
1965 g_object_ref (widget);
1966 if (!GTK_WIDGET_TOPLEVEL (widget))
1967 gtk_widget_queue_resize (widget);
1968 g_signal_emit (widget, widget_signals[SHOW], 0);
1969 g_object_notify (G_OBJECT (widget), "visible");
1970 g_object_unref (widget);
1975 gtk_widget_real_show (GtkWidget *widget)
1977 if (!GTK_WIDGET_VISIBLE (widget))
1979 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
1981 if (widget->parent &&
1982 GTK_WIDGET_MAPPED (widget->parent) &&
1983 GTK_WIDGET_CHILD_VISIBLE (widget) &&
1984 !GTK_WIDGET_MAPPED (widget))
1985 gtk_widget_map (widget);
1990 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
1993 g_signal_handlers_disconnect_by_func (widget,
1994 gtk_widget_show_map_callback,
1999 * gtk_widget_show_now:
2000 * @widget: a #GtkWidget
2002 * Shows a widget. If the widget is an unmapped toplevel widget
2003 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2004 * loop and wait for the window to actually be mapped. Be careful;
2005 * because the main loop is running, anything can happen during
2009 gtk_widget_show_now (GtkWidget *widget)
2013 g_return_if_fail (GTK_IS_WIDGET (widget));
2015 /* make sure we will get event */
2016 if (!GTK_WIDGET_MAPPED (widget) &&
2017 GTK_WIDGET_TOPLEVEL (widget))
2019 gtk_widget_show (widget);
2021 g_signal_connect (widget, "map_event",
2022 G_CALLBACK (gtk_widget_show_map_callback),
2026 gtk_main_iteration ();
2029 gtk_widget_show (widget);
2034 * @widget: a #GtkWidget
2036 * Reverses the effects of gtk_widget_show(), causing the widget to be
2037 * hidden (invisible to the user).
2040 gtk_widget_hide (GtkWidget *widget)
2042 g_return_if_fail (GTK_IS_WIDGET (widget));
2044 if (GTK_WIDGET_VISIBLE (widget))
2046 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2048 g_object_ref (widget);
2049 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2050 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2052 g_signal_emit (widget, widget_signals[HIDE], 0);
2053 if (!GTK_WIDGET_TOPLEVEL (widget))
2054 gtk_widget_queue_resize (widget);
2055 g_object_notify (G_OBJECT (widget), "visible");
2056 g_object_unref (widget);
2061 gtk_widget_real_hide (GtkWidget *widget)
2063 if (GTK_WIDGET_VISIBLE (widget))
2065 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2067 if (GTK_WIDGET_MAPPED (widget))
2068 gtk_widget_unmap (widget);
2073 * gtk_widget_hide_on_delete:
2074 * @widget: a #GtkWidget
2076 * Utility function; intended to be connected to the "delete_event"
2077 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2078 * argument, then returns %TRUE. If connected to "delete_event", the
2079 * result is that clicking the close button for a window (on the
2080 * window frame, top right corner usually) will hide but not destroy
2081 * the window. By default, GTK+ destroys windows when "delete_event"
2084 * Return value: %TRUE
2087 gtk_widget_hide_on_delete (GtkWidget *widget)
2089 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2091 gtk_widget_hide (widget);
2097 * gtk_widget_show_all:
2098 * @widget: a #GtkWidget
2100 * Recursively shows a widget, and any child widgets (if the widget is
2104 gtk_widget_show_all (GtkWidget *widget)
2106 GtkWidgetClass *class;
2108 g_return_if_fail (GTK_IS_WIDGET (widget));
2110 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2113 class = GTK_WIDGET_GET_CLASS (widget);
2115 if (class->show_all)
2116 class->show_all (widget);
2120 * gtk_widget_hide_all:
2121 * @widget: a #GtkWidget
2123 * Recursively hides a widget and any child widgets.
2126 gtk_widget_hide_all (GtkWidget *widget)
2128 GtkWidgetClass *class;
2130 g_return_if_fail (GTK_IS_WIDGET (widget));
2132 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2135 class = GTK_WIDGET_GET_CLASS (widget);
2137 if (class->hide_all)
2138 class->hide_all (widget);
2143 * @widget: a #GtkWidget
2145 * This function is only for use in widget implementations. Causes
2146 * a widget to be mapped if it isn't already.
2150 gtk_widget_map (GtkWidget *widget)
2152 g_return_if_fail (GTK_IS_WIDGET (widget));
2153 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2154 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2156 if (!GTK_WIDGET_MAPPED (widget))
2158 if (!GTK_WIDGET_REALIZED (widget))
2159 gtk_widget_realize (widget);
2161 g_signal_emit (widget, widget_signals[MAP], 0);
2163 if (GTK_WIDGET_NO_WINDOW (widget))
2164 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2170 * @widget: a #GtkWidget
2172 * This function is only for use in widget implementations. Causes
2173 * a widget to be unmapped if it's currently mapped.
2177 gtk_widget_unmap (GtkWidget *widget)
2179 g_return_if_fail (GTK_IS_WIDGET (widget));
2181 if (GTK_WIDGET_MAPPED (widget))
2183 if (GTK_WIDGET_NO_WINDOW (widget))
2184 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2185 g_signal_emit (widget, widget_signals[UNMAP], 0);
2190 * gtk_widget_realize:
2191 * @widget: a #GtkWidget
2193 * Creates the GDK (windowing system) resources associated with a
2194 * widget. For example, @widget->window will be created when a widget
2195 * is realized. Normally realization happens implicitly; if you show
2196 * a widget and all its parent containers, then the widget will be
2197 * realized and mapped automatically.
2199 * Realizing a widget requires all
2200 * the widget's parent widgets to be realized; calling
2201 * gtk_widget_realize() realizes the widget's parents in addition to
2202 * @widget itself. If a widget is not yet inside a toplevel window
2203 * when you realize it, bad things will happen.
2205 * This function is primarily used in widget implementations, and
2206 * isn't very useful otherwise. Many times when you think you might
2207 * need it, a better approach is to connect to a signal that will be
2208 * called after the widget is realized automatically, such as
2209 * "expose_event". Or simply g_signal_connect_after() to the
2214 gtk_widget_realize (GtkWidget *widget)
2217 GdkExtensionMode mode;
2218 GtkWidgetShapeInfo *shape_info;
2220 g_return_if_fail (GTK_IS_WIDGET (widget));
2221 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2222 GTK_IS_INVISIBLE (widget));
2224 if (!GTK_WIDGET_REALIZED (widget))
2227 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2228 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2231 if (widget->parent == NULL &&
2232 !GTK_WIDGET_TOPLEVEL (widget))
2233 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2234 "inside a toplevel window is not going to work very well. "
2235 "Widgets must be inside a toplevel container before realizing them.");
2237 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2238 gtk_widget_realize (widget->parent);
2240 gtk_widget_ensure_style (widget);
2242 g_signal_emit (widget, widget_signals[REALIZE], 0);
2244 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2246 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2247 gdk_window_shape_combine_mask (widget->window,
2248 shape_info->shape_mask,
2249 shape_info->offset_x,
2250 shape_info->offset_y);
2253 if (!GTK_WIDGET_NO_WINDOW (widget))
2255 mode = gtk_widget_get_extension_events (widget);
2256 if (mode != GDK_EXTENSION_EVENTS_NONE)
2258 events = gtk_widget_get_events (widget);
2259 gdk_input_set_extension_events (widget->window, events, mode);
2267 * gtk_widget_unrealize:
2268 * @widget: a #GtkWidget
2270 * This function is only useful in widget implementations.
2271 * Causes a widget to be unrealized (frees all GDK resources
2272 * associated with the widget, such as @widget->window).
2276 gtk_widget_unrealize (GtkWidget *widget)
2278 g_return_if_fail (GTK_IS_WIDGET (widget));
2280 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2281 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2283 if (GTK_WIDGET_REALIZED (widget))
2285 g_object_ref (widget);
2286 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2287 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2288 g_object_unref (widget);
2292 /*****************************************
2294 *****************************************/
2297 * gtk_widget_queue_draw_area:
2298 * @widget: a #GtkWidget
2299 * @x: x coordinate of upper-left corner of rectangle to redraw
2300 * @y: y coordinate of upper-left corner of rectangle to redraw
2301 * @width: width of region to draw
2302 * @height: height of region to draw
2304 * Invalidates the rectangular area of @widget defined by @x, @y,
2305 * @width and @height by calling gdk_window_invalidate_rect() on the
2306 * widget's window and all its child windows. Once the main loop
2307 * becomes idle (after the current batch of events has been processed,
2308 * roughly), the window will receive expose events for the union of
2309 * all regions that have been invalidated.
2311 * Normally you would only use this function in widget
2312 * implementations. You might also use it, or
2313 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2314 * #GtkDrawingArea or some portion thereof.
2316 * Frequently you can just call gdk_window_invalidate_rect() or
2317 * gdk_window_invalidate_region() instead of this function. Those
2318 * functions will invalidate only a single window, instead of the
2319 * widget and all its children.
2321 * The advantage of adding to the invalidated region compared to
2322 * simply drawing immediately is efficiency; using an invalid region
2323 * ensures that you only have to redraw one time.
2327 gtk_widget_queue_draw_area (GtkWidget *widget,
2333 GdkRectangle invalid_rect;
2336 g_return_if_fail (GTK_IS_WIDGET (widget));
2338 if (!GTK_WIDGET_REALIZED (widget))
2341 /* Just return if the widget or one of its ancestors isn't mapped */
2342 for (w = widget; w != NULL; w = w->parent)
2343 if (!GTK_WIDGET_MAPPED (w))
2346 /* Find the correct widget */
2348 if (!GTK_WIDGET_NO_WINDOW (widget))
2352 /* Translate widget relative to window-relative */
2354 gint wx, wy, wwidth, wheight;
2356 gdk_window_get_position (widget->window, &wx, &wy);
2357 x -= wx - widget->allocation.x;
2358 y -= wy - widget->allocation.y;
2360 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2362 if (x + width <= 0 || y + height <= 0 ||
2363 x >= wwidth || y >= wheight)
2374 if (x + width > wwidth)
2376 if (y + height > wheight)
2377 height = wheight - y;
2383 invalid_rect.width = width;
2384 invalid_rect.height = height;
2386 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2390 * gtk_widget_queue_draw:
2391 * @widget: a #GtkWidget
2393 * Equivalent to calling gtk_widget_queue_draw_area() for the
2394 * entire area of a widget.
2398 gtk_widget_queue_draw (GtkWidget *widget)
2400 g_return_if_fail (GTK_IS_WIDGET (widget));
2402 if (widget->allocation.width || widget->allocation.height)
2404 if (GTK_WIDGET_NO_WINDOW (widget))
2405 gtk_widget_queue_draw_area (widget, widget->allocation.x,
2406 widget->allocation.y,
2407 widget->allocation.width,
2408 widget->allocation.height);
2410 gtk_widget_queue_draw_area (widget, 0, 0,
2411 widget->allocation.width,
2412 widget->allocation.height);
2416 /* Invalidates the given area (allocation-relative-coordinates)
2417 * in all of the widget's windows
2420 * gtk_widget_queue_clear_area:
2421 * @widget: a #GtkWidget
2422 * @x: x coordinate of upper-left corner of rectangle to redraw
2423 * @y: y coordinate of upper-left corner of rectangle to redraw
2424 * @width: width of region to draw
2425 * @height: height of region to draw
2427 * This function is no longer different from
2428 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2429 * gtk_widget_queue_draw_area(). Originally
2430 * gtk_widget_queue_clear_area() would force a redraw of the
2431 * background for %GTK_NO_WINDOW widgets, and
2432 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2433 * the background will be redrawn.
2435 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2438 gtk_widget_queue_clear_area (GtkWidget *widget,
2444 g_return_if_fail (GTK_IS_WIDGET (widget));
2446 gtk_widget_queue_draw_area (widget, x, y, width, height);
2450 * gtk_widget_queue_clear:
2451 * @widget: a #GtkWidget
2453 * This function does the same as gtk_widget_queue_draw().
2455 * @Deprecated: Use gtk_widget_queue_draw() instead.
2458 gtk_widget_queue_clear (GtkWidget *widget)
2460 g_return_if_fail (GTK_IS_WIDGET (widget));
2462 gtk_widget_queue_draw (widget);
2466 * gtk_widget_queue_resize:
2467 * @widget: a #GtkWidget
2469 * This function is only for use in widget implementations.
2470 * Flags a widget to have its size renegotiated; should
2471 * be called when a widget for some reason has a new size request.
2472 * For example, when you change the text in a #GtkLabel, #GtkLabel
2473 * queues a resize to ensure there's enough space for the new text.
2476 gtk_widget_queue_resize (GtkWidget *widget)
2478 g_return_if_fail (GTK_IS_WIDGET (widget));
2480 if (GTK_WIDGET_REALIZED (widget))
2481 gtk_widget_queue_shallow_draw (widget);
2483 _gtk_size_group_queue_resize (widget);
2487 * gtk_widget_queue_resize_no_redraw:
2488 * @widget: a #GtkWidget
2490 * This function works like gtk_widget_queue_resize(), except that the
2491 * widget is not invalidated.
2496 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2498 g_return_if_fail (GTK_IS_WIDGET (widget));
2500 _gtk_size_group_queue_resize (widget);
2505 * @widget: a #GtkWidget
2506 * @area: area to draw
2508 * In GTK+ 1.2, this function would immediately render the
2509 * region @area of a widget, by invoking the virtual draw method of a
2510 * widget. In GTK+ 2.0, the draw method is gone, and instead
2511 * gtk_widget_draw() simply invalidates the specified region of the
2512 * widget, then updates the invalid region of the widget immediately.
2513 * Usually you don't want to update the region immediately for
2514 * performance reasons, so in general gtk_widget_queue_draw_area() is
2515 * a better choice if you want to draw a region of a widget.
2519 gtk_widget_draw (GtkWidget *widget,
2522 g_return_if_fail (GTK_IS_WIDGET (widget));
2524 if (GTK_WIDGET_DRAWABLE (widget))
2527 gtk_widget_queue_draw_area (widget,
2529 area->width, area->height);
2531 gtk_widget_queue_draw (widget);
2533 gdk_window_process_updates (widget->window, TRUE);
2538 * gtk_widget_size_request:
2539 * @widget: a #GtkWidget
2540 * @requisition: a #GtkRequisition to be filled in
2542 * This function is typically used when implementing a #GtkContainer
2543 * subclass. Obtains the preferred size of a widget. The container
2544 * uses this information to arrange its child widgets and decide what
2545 * size allocations to give them with gtk_widget_size_allocate().
2547 * You can also call this function from an application, with some
2548 * caveats. Most notably, getting a size request requires the widget
2549 * to be associated with a screen, because font information may be
2550 * needed. Multihead-aware applications should keep this in mind.
2552 * Also remember that the size request is not necessarily the size
2553 * a widget will actually be allocated.
2555 * See also gtk_widget_get_child_requisition().
2558 gtk_widget_size_request (GtkWidget *widget,
2559 GtkRequisition *requisition)
2561 g_return_if_fail (GTK_IS_WIDGET (widget));
2563 #ifdef G_ENABLE_DEBUG
2564 if (requisition == &widget->requisition)
2565 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.");
2566 #endif /* G_ENABLE_DEBUG */
2568 _gtk_size_group_compute_requisition (widget, requisition);
2572 * gtk_widget_get_child_requisition:
2573 * @widget: a #GtkWidget
2574 * @requisition: a #GtkRequisition to be filled in
2576 * This function is only for use in widget implementations. Obtains
2577 * @widget->requisition, unless someone has forced a particular
2578 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2579 * case it returns that geometry instead of the widget's requisition.
2581 * This function differs from gtk_widget_size_request() in that
2582 * it retrieves the last size request value from @widget->requisition,
2583 * while gtk_widget_size_request() actually calls the "size_request" method
2584 * on @widget to compute the size request and fill in @widget->requisition,
2585 * and only then returns @widget->requisition.
2587 * Because this function does not call the "size_request" method, it
2588 * can only be used when you know that @widget->requisition is
2589 * up-to-date, that is, gtk_widget_size_request() has been called
2590 * since the last time a resize was queued. In general, only container
2591 * implementations have this information; applications should use
2592 * gtk_widget_size_request().
2595 gtk_widget_get_child_requisition (GtkWidget *widget,
2596 GtkRequisition *requisition)
2598 _gtk_size_group_get_child_requisition (widget, requisition);
2602 invalidate_predicate (GdkWindow *window,
2607 gdk_window_get_user_data (window, &user_data);
2609 return (user_data == data);
2612 /* Invalidate @region in widget->window and all children
2613 * of widget->window owned by widget. @region is in the
2614 * same coordinates as widget->allocation and will be
2615 * modified by this call.
2618 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2621 if (!GTK_WIDGET_REALIZED (widget))
2624 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2628 gdk_window_get_position (widget->window, &x, &y);
2629 gdk_region_offset (region, -x, -y);
2632 gdk_window_invalidate_maybe_recurse (widget->window, region,
2633 invalidate_predicate, widget);
2637 * gtk_widget_queue_shallow_draw:
2638 * @widget: a #GtkWidget
2640 * Like gtk_widget_queue_draw(), but only windows owned
2641 * by @widget are invalidated.
2644 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2648 g_return_if_fail (GTK_IS_WIDGET (widget));
2650 region = gdk_region_rectangle (&widget->allocation);
2651 gtk_widget_invalidate_widget_windows (widget, region);
2652 gdk_region_destroy (region);
2656 * gtk_widget_size_allocate:
2657 * @widget: a #GtkWidget
2658 * @allocation: position and size to be allocated to @widget
2660 * This function is only used by #GtkContainer subclasses, to assign a size
2661 * and position to their child widgets.
2665 gtk_widget_size_allocate (GtkWidget *widget,
2666 GtkAllocation *allocation)
2668 GtkWidgetAuxInfo *aux_info;
2669 GdkRectangle real_allocation;
2670 GdkRectangle old_allocation;
2671 gboolean alloc_needed;
2672 gboolean size_changed;
2673 gboolean position_changed;
2675 g_return_if_fail (GTK_IS_WIDGET (widget));
2677 #ifdef G_ENABLE_DEBUG
2678 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2689 parent = gtk_widget_get_parent (parent);
2692 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2693 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2694 2 * depth, " ", name,
2695 allocation->width, allocation->height);
2697 #endif /* G_ENABLE_DEBUG */
2699 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2700 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2701 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2703 old_allocation = widget->allocation;
2704 real_allocation = *allocation;
2705 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2709 if (aux_info->x_set)
2710 real_allocation.x = aux_info->x;
2711 if (aux_info->y_set)
2712 real_allocation.y = aux_info->y;
2715 if (real_allocation.width < 0 || real_allocation.height < 0)
2717 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2718 real_allocation.width,
2719 real_allocation.height);
2722 real_allocation.width = MAX (real_allocation.width, 1);
2723 real_allocation.height = MAX (real_allocation.height, 1);
2725 size_changed = (old_allocation.width != real_allocation.width ||
2726 old_allocation.height != real_allocation.height);
2727 position_changed = (old_allocation.x != real_allocation.x ||
2728 old_allocation.y != real_allocation.y);
2730 if (!alloc_needed && !size_changed && !position_changed)
2733 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2735 if (GTK_WIDGET_MAPPED (widget))
2737 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2739 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2741 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2742 gdk_region_union_with_rect (invalidate, &old_allocation);
2744 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2745 gdk_region_destroy (invalidate);
2750 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2752 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2754 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2755 gdk_region_union_with_rect (invalidate, &old_allocation);
2757 gtk_widget_invalidate_widget_windows (widget, invalidate);
2758 gdk_region_destroy (invalidate);
2763 if ((size_changed || position_changed) && widget->parent &&
2764 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2766 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2767 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2768 gdk_region_destroy (invalidate);
2773 * gtk_widget_common_ancestor:
2774 * @widget_a: a #GtkWidget
2775 * @widget_b: a #GtkWidget
2777 * Find the common ancestor of @widget_a and @widget_b that
2778 * is closest to the two widgets.
2780 * Return value: the closest common ancestor of @widget_a and
2781 * @widget_b or %NULL if @widget_a and @widget_b do not
2782 * share a common ancestor.
2785 gtk_widget_common_ancestor (GtkWidget *widget_a,
2786 GtkWidget *widget_b)
2788 GtkWidget *parent_a;
2789 GtkWidget *parent_b;
2793 parent_a = widget_a;
2794 while (parent_a->parent)
2796 parent_a = parent_a->parent;
2800 parent_b = widget_b;
2801 while (parent_b->parent)
2803 parent_b = parent_b->parent;
2807 if (parent_a != parent_b)
2810 while (depth_a > depth_b)
2812 widget_a = widget_a->parent;
2816 while (depth_b > depth_a)
2818 widget_b = widget_b->parent;
2822 while (widget_a != widget_b)
2824 widget_a = widget_a->parent;
2825 widget_b = widget_b->parent;
2832 * gtk_widget_translate_coordinates:
2833 * @src_widget: a #GtkWidget
2834 * @dest_widget: a #GtkWidget
2835 * @src_x: X position relative to @src_widget
2836 * @src_y: Y position relative to @src_widget
2837 * @dest_x: location to store X position relative to @dest_widget
2838 * @dest_y: location to store Y position relative to @dest_widget
2840 * Translate coordinates relative to @src_widget's allocation to coordinates
2841 * relative to @dest_widget's allocations. In order to perform this
2842 * operation, both widgets must be realized, and must share a common
2845 * Return value: %FALSE if either widget was not realized, or there
2846 * was no common ancestor. In this case, nothing is stored in
2847 * *@dest_x and *@dest_y. Otherwise %TRUE.
2850 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2851 GtkWidget *dest_widget,
2857 GtkWidget *ancestor;
2860 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2861 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2863 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2864 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2867 /* Translate from allocation relative to window relative */
2868 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2871 gdk_window_get_position (src_widget->window, &wx, &wy);
2873 src_x -= wx - src_widget->allocation.x;
2874 src_y -= wy - src_widget->allocation.y;
2878 src_x += src_widget->allocation.x;
2879 src_y += src_widget->allocation.y;
2882 /* Translate to the common ancestor */
2883 window = src_widget->window;
2884 while (window != ancestor->window)
2888 gdk_window_get_position (window, &dx, &dy);
2893 window = gdk_window_get_parent (window);
2895 if (!window) /* Handle GtkHandleBox */
2900 window = dest_widget->window;
2901 while (window != ancestor->window)
2905 gdk_window_get_position (window, &dx, &dy);
2910 window = gdk_window_get_parent (window);
2912 if (!window) /* Handle GtkHandleBox */
2916 /* Translate from window relative to allocation relative */
2917 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2920 gdk_window_get_position (dest_widget->window, &wx, &wy);
2922 src_x += wx - dest_widget->allocation.x;
2923 src_y += wy - dest_widget->allocation.y;
2927 src_x -= dest_widget->allocation.x;
2928 src_y -= dest_widget->allocation.y;
2940 gtk_widget_real_size_allocate (GtkWidget *widget,
2941 GtkAllocation *allocation)
2943 widget->allocation = *allocation;
2945 if (GTK_WIDGET_REALIZED (widget) &&
2946 !GTK_WIDGET_NO_WINDOW (widget))
2948 gdk_window_move_resize (widget->window,
2949 allocation->x, allocation->y,
2950 allocation->width, allocation->height);
2955 gtk_widget_real_can_activate_accel (GtkWidget *widget,
2958 /* widgets must be onscreen for accels to take effect */
2959 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
2963 * gtk_widget_can_activate_accel:
2964 * @widget: a #GtkWidget
2965 * @signal_id: the ID of a signal installed on @widget
2967 * Determines whether an accelerator that activates the signal
2968 * identified by @signal_id can currently be activated.
2969 * This is done by emitting the GtkWidget::can-activate-accel
2970 * signal on @widget; if the signal isn't overridden by a
2971 * handler or in a derived widget, then the default check is
2972 * that the widget must be sensitive, and the widget and all
2973 * its ancestors mapped.
2975 * Return value: %TRUE if the accelerator can be activated.
2980 gtk_widget_can_activate_accel (GtkWidget *widget,
2983 gboolean can_activate = FALSE;
2984 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2985 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
2986 return can_activate;
2995 closure_accel_activate (GClosure *closure,
2996 GValue *return_value,
2997 guint n_param_values,
2998 const GValue *param_values,
2999 gpointer invocation_hint,
3000 gpointer marshal_data)
3002 AccelClosure *aclosure = (AccelClosure*) closure;
3003 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3006 g_signal_emit (closure->data, aclosure->signal_id, 0);
3008 /* whether accelerator was handled */
3009 g_value_set_boolean (return_value, can_activate);
3013 closures_destroy (gpointer data)
3015 GSList *slist, *closures = data;
3017 for (slist = closures; slist; slist = slist->next)
3019 g_closure_invalidate (slist->data);
3020 g_closure_unref (slist->data);
3022 g_slist_free (closures);
3026 widget_new_accel_closure (GtkWidget *widget,
3029 AccelClosure *aclosure;
3030 GClosure *closure = NULL;
3031 GSList *slist, *closures;
3033 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3034 for (slist = closures; slist; slist = slist->next)
3035 if (!gtk_accel_group_from_accel_closure (slist->data))
3037 /* reuse this closure */
3038 closure = slist->data;
3043 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3044 closures = g_slist_prepend (closures, g_closure_ref (closure));
3045 g_closure_sink (closure);
3046 g_closure_set_marshal (closure, closure_accel_activate);
3048 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3050 aclosure = (AccelClosure*) closure;
3051 g_assert (closure->data == widget);
3052 g_assert (closure->marshal == closure_accel_activate);
3053 aclosure->signal_id = signal_id;
3059 * gtk_widget_add_accelerator
3060 * @widget: widget to install an accelerator on
3061 * @accel_signal: widget signal to emit on accelerator activation
3062 * @accel_group: accel group for this widget, added to its toplevel
3063 * @accel_key: GDK keyval of the accelerator
3064 * @accel_mods: modifier key combination of the accelerator
3065 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3067 * Installs an accelerator for this @widget in @accel_group that causes
3068 * @accel_signal to be emitted if the accelerator is activated.
3069 * The @accel_group needs to be added to the widget's toplevel via
3070 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3071 * Accelerators added through this function are not user changeable during
3072 * runtime. If you want to support accelerators that can be changed by the
3073 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3074 * gtk_menu_item_set_accel_path() instead.
3077 gtk_widget_add_accelerator (GtkWidget *widget,
3078 const gchar *accel_signal,
3079 GtkAccelGroup *accel_group,
3081 GdkModifierType accel_mods,
3082 GtkAccelFlags accel_flags)
3087 g_return_if_fail (GTK_IS_WIDGET (widget));
3088 g_return_if_fail (accel_signal != NULL);
3089 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3091 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3092 if (!query.signal_id ||
3093 !(query.signal_flags & G_SIGNAL_ACTION) ||
3094 query.return_type != G_TYPE_NONE ||
3097 /* hmm, should be elaborate enough */
3098 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3099 G_OBJECT_TYPE_NAME (widget), accel_signal);
3103 closure = widget_new_accel_closure (widget, query.signal_id);
3105 g_object_ref (widget);
3107 /* install the accelerator. since we don't map this onto an accel_path,
3108 * the accelerator will automatically be locked.
3110 gtk_accel_group_connect (accel_group,
3113 accel_flags | GTK_ACCEL_LOCKED,
3116 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3118 g_object_unref (widget);
3122 * gtk_widget_remove_accelerator:
3123 * @widget: widget to install an accelerator on
3124 * @accel_group: accel group for this widget
3125 * @accel_key: GDK keyval of the accelerator
3126 * @accel_mods: modifier key combination of the accelerator
3127 * @returns: whether an accelerator was installed and could be removed
3129 * Removes an accelerator from @widget, previously installed with
3130 * gtk_widget_add_accelerator().
3133 gtk_widget_remove_accelerator (GtkWidget *widget,
3134 GtkAccelGroup *accel_group,
3136 GdkModifierType accel_mods)
3138 GtkAccelGroupEntry *ag_entry;
3139 GList *slist, *clist;
3142 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3143 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3145 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3146 clist = gtk_widget_list_accel_closures (widget);
3147 for (slist = clist; slist; slist = slist->next)
3151 for (i = 0; i < n; i++)
3152 if (slist->data == (gpointer) ag_entry[i].closure)
3154 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3156 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3158 g_list_free (clist);
3163 g_list_free (clist);
3165 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3166 accel_key, accel_mods, accel_group,
3167 G_OBJECT_TYPE_NAME (widget), widget);
3173 * gtk_widget_list_accel_closures
3174 * @widget: widget to list accelerator closures for
3175 * @returns: a newly allocated #GList of closures
3177 * Lists the closures used by @widget for accelerator group connections
3178 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3179 * The closures can be used to monitor accelerator changes on @widget,
3180 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3181 * closure which can be found out with gtk_accel_group_from_accel_closure().
3184 gtk_widget_list_accel_closures (GtkWidget *widget)
3187 GList *clist = NULL;
3189 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3191 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3192 if (gtk_accel_group_from_accel_closure (slist->data))
3193 clist = g_list_prepend (clist, slist->data);
3200 GtkAccelGroup *accel_group;
3205 destroy_accel_path (gpointer data)
3207 AccelPath *apath = data;
3209 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3211 /* closures_destroy takes care of unrefing the closure */
3212 g_object_unref (apath->accel_group);
3219 * gtk_widget_set_accel_path:
3220 * @widget: a #GtkWidget
3221 * @accel_path: path used to look up the the accelerator
3222 * @accel_group: a #GtkAccelGroup.
3224 * Given an accelerator group, @accel_group, and an accelerator path,
3225 * @accel_path, sets up an accelerator in @accel_group so whenever the
3226 * key binding that is defined for @accel_path is pressed, @widget
3227 * will be activated. This removes any accelerators (for any
3228 * accelerator group) installed by previous calls to
3229 * gtk_widget_set_accel_path(). Associating accelerators with
3230 * paths allows them to be modified by the user and the modifications
3231 * to be saved for future use. (See gtk_accel_map_save().)
3233 * This function is a low level function that would most likely
3234 * be used by a menu creation system like #GtkItemFactory. If you
3235 * use #GtkItemFactory, setting up accelerator paths will be done
3238 * Even when you you aren't using #GtkItemFactory, if you only want to
3239 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3240 * provides a somewhat more convenient interface.
3243 gtk_widget_set_accel_path (GtkWidget *widget,
3244 const gchar *accel_path,
3245 GtkAccelGroup *accel_group)
3249 g_return_if_fail (GTK_IS_WIDGET (widget));
3250 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3254 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3255 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3257 gtk_accel_map_add_entry (accel_path, 0, 0);
3258 apath = g_new (AccelPath, 1);
3259 apath->widget = widget;
3260 apath->accel_group = g_object_ref (accel_group);
3261 apath->path_quark = g_quark_from_string (accel_path);
3262 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3267 /* also removes possible old settings */
3268 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3271 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3273 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3277 _gtk_widget_get_accel_path (GtkWidget *widget,
3282 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3284 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3286 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3287 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3291 gtk_widget_mnemonic_activate (GtkWidget *widget,
3292 gboolean group_cycling)
3296 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3298 group_cycling = group_cycling != FALSE;
3299 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3302 g_signal_emit (widget,
3303 widget_signals[MNEMONIC_ACTIVATE],
3311 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3312 gboolean group_cycling)
3314 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3315 gtk_widget_activate (widget);
3316 else if (GTK_WIDGET_CAN_FOCUS (widget))
3317 gtk_widget_grab_focus (widget);
3320 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3321 G_OBJECT_TYPE_NAME (widget));
3322 gdk_display_beep (gtk_widget_get_display (widget));
3328 gtk_widget_real_key_press_event (GtkWidget *widget,
3331 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3335 gtk_widget_real_key_release_event (GtkWidget *widget,
3338 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3342 gtk_widget_real_focus_in_event (GtkWidget *widget,
3343 GdkEventFocus *event)
3345 gtk_widget_queue_shallow_draw (widget);
3351 gtk_widget_real_focus_out_event (GtkWidget *widget,
3352 GdkEventFocus *event)
3354 gtk_widget_queue_shallow_draw (widget);
3359 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3360 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3364 * @widget: a #GtkWidget
3365 * @event: a #GdkEvent
3367 * Rarely-used function. This function is used to emit
3368 * the event signals on a widget (those signals should never
3369 * be emitted without using this function to do so).
3370 * If you want to synthesize an event though, don't use this function;
3371 * instead, use gtk_main_do_event() so the event will behave as if
3372 * it were in the event queue. Don't synthesize expose events; instead,
3373 * use gdk_window_invalidate_rect() to invalidate a region of the
3376 * Return value: return from the event signal emission (%TRUE if the event was handled)
3379 gtk_widget_event (GtkWidget *widget,
3382 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3383 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3385 if (event->type == GDK_EXPOSE)
3387 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3388 "the same effect, call gdk_window_invalidate_rect/region(), "
3389 "followed by gdk_window_process_updates().");
3393 return gtk_widget_event_internal (widget, event);
3398 * gtk_widget_send_expose:
3399 * @widget: a #GtkWidget
3400 * @event: a expose #GdkEvent
3402 * Very rarely-used function. This function is used to emit
3403 * an expose event signals on a widget. This function is not
3404 * normally used directly. The only time it is used is when
3405 * propagating an expose event to a child %NO_WINDOW widget, and
3406 * that is normally done using gtk_container_propagate_expose().
3408 * If you want to force an area of a window to be redrawn,
3409 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3410 * To cause the redraw to be done immediately, follow that call
3411 * with a call to gdk_window_process_updates().
3413 * Return value: return from the event signal emission (%TRUE if the event was handled)
3416 gtk_widget_send_expose (GtkWidget *widget,
3419 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3420 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3421 g_return_val_if_fail (event != NULL, TRUE);
3422 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3424 if (event->type != GDK_EXPOSE)
3427 return gtk_widget_event_internal (widget, event);
3431 event_window_is_still_viewable (GdkEvent *event)
3433 /* Some programs, such as gnome-theme-manager, fake widgets
3434 * into exposing onto a pixmap by sending expose events with
3435 * event->window pointing to a pixmap
3437 if (GDK_IS_PIXMAP (event->any.window))
3438 return event->type == GDK_EXPOSE;
3440 /* Check that we think the event's window is viewable before
3441 * delivering the event, to prevent suprises. We do this here
3442 * at the last moment, since the event may have been queued
3443 * up behind other events, held over a recursive main loop, etc.
3445 switch (event->type)
3448 case GDK_MOTION_NOTIFY:
3449 case GDK_BUTTON_PRESS:
3450 case GDK_2BUTTON_PRESS:
3451 case GDK_3BUTTON_PRESS:
3453 case GDK_ENTER_NOTIFY:
3454 case GDK_PROXIMITY_IN:
3456 return event->any.window && gdk_window_is_viewable (event->any.window);
3459 /* The following events are the second half of paired events;
3460 * we always deliver them to deal with widgets that clean up
3461 * on the second half.
3463 case GDK_BUTTON_RELEASE:
3464 case GDK_KEY_RELEASE:
3465 case GDK_LEAVE_NOTIFY:
3466 case GDK_PROXIMITY_OUT:
3470 /* Remaining events would make sense on an not-viewable window,
3471 * or don't have an associated window.
3478 gtk_widget_event_internal (GtkWidget *widget,
3481 gboolean return_val = FALSE;
3483 /* We check only once for is-still-visible; if someone
3484 * hides the window in on of the signals on the widget,
3485 * they are responsible for returning TRUE to terminate
3488 if (!event_window_is_still_viewable (event))
3491 g_object_ref (widget);
3493 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3494 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3499 switch (event->type)
3504 case GDK_BUTTON_PRESS:
3505 case GDK_2BUTTON_PRESS:
3506 case GDK_3BUTTON_PRESS:
3507 signal_num = BUTTON_PRESS_EVENT;
3510 signal_num = SCROLL_EVENT;
3512 case GDK_BUTTON_RELEASE:
3513 signal_num = BUTTON_RELEASE_EVENT;
3515 case GDK_MOTION_NOTIFY:
3516 signal_num = MOTION_NOTIFY_EVENT;
3519 signal_num = DELETE_EVENT;
3522 signal_num = DESTROY_EVENT;
3525 signal_num = KEY_PRESS_EVENT;
3527 case GDK_KEY_RELEASE:
3528 signal_num = KEY_RELEASE_EVENT;
3530 case GDK_ENTER_NOTIFY:
3531 signal_num = ENTER_NOTIFY_EVENT;
3533 case GDK_LEAVE_NOTIFY:
3534 signal_num = LEAVE_NOTIFY_EVENT;
3536 case GDK_FOCUS_CHANGE:
3537 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3540 signal_num = CONFIGURE_EVENT;
3543 signal_num = MAP_EVENT;
3546 signal_num = UNMAP_EVENT;
3548 case GDK_WINDOW_STATE:
3549 signal_num = WINDOW_STATE_EVENT;
3551 case GDK_PROPERTY_NOTIFY:
3552 signal_num = PROPERTY_NOTIFY_EVENT;
3554 case GDK_SELECTION_CLEAR:
3555 signal_num = SELECTION_CLEAR_EVENT;
3557 case GDK_SELECTION_REQUEST:
3558 signal_num = SELECTION_REQUEST_EVENT;
3560 case GDK_SELECTION_NOTIFY:
3561 signal_num = SELECTION_NOTIFY_EVENT;
3563 case GDK_PROXIMITY_IN:
3564 signal_num = PROXIMITY_IN_EVENT;
3566 case GDK_PROXIMITY_OUT:
3567 signal_num = PROXIMITY_OUT_EVENT;
3570 signal_num = NO_EXPOSE_EVENT;
3572 case GDK_CLIENT_EVENT:
3573 signal_num = CLIENT_EVENT;
3576 signal_num = EXPOSE_EVENT;
3578 case GDK_VISIBILITY_NOTIFY:
3579 signal_num = VISIBILITY_NOTIFY_EVENT;
3582 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3586 if (signal_num != -1)
3587 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3589 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3590 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3594 g_object_unref (widget);
3600 * gtk_widget_activate:
3601 * @widget: a #GtkWidget that's activatable
3603 * For widgets that can be "activated" (buttons, menu items, etc.)
3604 * this function activates them. Activation is what happens when you
3605 * press Enter on a widget during key navigation. If @widget isn't
3606 * activatable, the function returns %FALSE.
3608 * Return value: %TRUE if the widget was activatable
3611 gtk_widget_activate (GtkWidget *widget)
3613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3615 if (WIDGET_CLASS (widget)->activate_signal)
3617 /* FIXME: we should eventually check the signals signature here */
3618 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3627 * gtk_widget_set_scroll_adjustments:
3628 * @widget: a #GtkWidget
3629 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3630 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3632 * For widgets that support scrolling, sets the scroll adjustments and
3633 * returns %TRUE. For widgets that don't support scrolling, does
3634 * nothing and returns %FALSE. Widgets that don't support scrolling
3635 * can be scrolled by placing them in a #GtkViewport, which does
3636 * support scrolling.
3638 * Return value: %TRUE if the widget supports scrolling
3641 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3642 GtkAdjustment *hadjustment,
3643 GtkAdjustment *vadjustment)
3645 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3647 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3649 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3651 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3653 /* FIXME: we should eventually check the signals signature here */
3654 g_signal_emit (widget,
3655 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3656 hadjustment, vadjustment);
3664 gtk_widget_reparent_subwindows (GtkWidget *widget,
3665 GdkWindow *new_window)
3667 if (GTK_WIDGET_NO_WINDOW (widget))
3669 GList *children = gdk_window_get_children (widget->window);
3672 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3675 GdkWindow *window = tmp_list->data;
3677 gdk_window_get_user_data (window, (void **)&child);
3678 while (child && child != widget)
3679 child = child->parent;
3682 gdk_window_reparent (window, new_window, 0, 0);
3685 g_list_free (children);
3688 gdk_window_reparent (widget->window, new_window, 0, 0);
3692 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3693 gpointer client_data)
3695 g_return_if_fail (client_data != NULL);
3697 if (GTK_WIDGET_NO_WINDOW (widget))
3700 g_object_unref (widget->window);
3701 widget->window = (GdkWindow*) client_data;
3703 g_object_ref (widget->window);
3705 if (GTK_IS_CONTAINER (widget))
3706 gtk_container_forall (GTK_CONTAINER (widget),
3707 gtk_widget_reparent_fixup_child,
3713 * gtk_widget_reparent:
3714 * @widget: a #GtkWidget
3715 * @new_parent: a #GtkContainer to move the widget into
3717 * Moves a widget from one #GtkContainer to another, handling reference
3718 * count issues to avoid destroying the widget.
3722 gtk_widget_reparent (GtkWidget *widget,
3723 GtkWidget *new_parent)
3725 g_return_if_fail (GTK_IS_WIDGET (widget));
3726 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3727 g_return_if_fail (widget->parent != NULL);
3729 if (widget->parent != new_parent)
3731 /* First try to see if we can get away without unrealizing
3732 * the widget as we reparent it. if so we set a flag so
3733 * that gtk_widget_unparent doesn't unrealize widget
3735 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3736 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3738 g_object_ref (widget);
3739 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3740 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3741 g_object_unref (widget);
3743 if (GTK_WIDGET_IN_REPARENT (widget))
3745 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3747 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3748 gtk_widget_reparent_fixup_child (widget,
3749 gtk_widget_get_parent_window (widget));
3752 g_object_notify (G_OBJECT (widget), "parent");
3757 * gtk_widget_intersect:
3758 * @widget: a #GtkWidget
3759 * @area: a rectangle
3760 * @intersection: rectangle to store intersection of @widget and @area
3762 * Computes the intersection of a @widget's area and @area, storing
3763 * the intersection in @intersection, and returns %TRUE if there was
3764 * an intersection. @intersection may be %NULL if you're only
3765 * interested in whether there was an intersection.
3767 * Return value: %TRUE if there was an intersection
3770 gtk_widget_intersect (GtkWidget *widget,
3772 GdkRectangle *intersection)
3778 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3779 g_return_val_if_fail (area != NULL, FALSE);
3782 dest = intersection;
3786 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3788 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3790 intersection->x -= widget->allocation.x;
3791 intersection->y -= widget->allocation.y;
3798 * gtk_widget_region_intersect:
3799 * @widget: a #GtkWidget
3800 * @region: a #GdkRegion, in the same coordinate system as
3801 * @widget->allocation. That is, relative to @widget->window
3802 * for %NO_WINDOW widgets; relative to the parent window
3803 * of @widget->window for widgets with their own window.
3804 * @returns: A newly allocated region holding the intersection of @widget
3805 * and @region. The coordinates of the return value are
3806 * relative to @widget->window for %NO_WINDOW widgets, and
3807 * relative to the parent window of @widget->window for
3808 * widgets with their own window.
3810 * Computes the intersection of a @widget's area and @region, returning
3811 * the intersection. The result may be empty, use gdk_region_empty() to
3815 gtk_widget_region_intersect (GtkWidget *widget,
3820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3821 g_return_val_if_fail (region != NULL, NULL);
3823 dest = gdk_region_rectangle (&widget->allocation);
3825 gdk_region_intersect (dest, region);
3831 * _gtk_widget_grab_notify:
3832 * @widget: a #GtkWidget
3833 * @was_grabbed: whether a grab is now in effect
3835 * Emits the signal "grab_notify" on @widget.
3840 _gtk_widget_grab_notify (GtkWidget *widget,
3841 gboolean was_grabbed)
3843 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
3847 * gtk_widget_grab_focus:
3848 * @widget: a #GtkWidget
3850 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3851 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3852 * something like #GtkFrame won't work. (More precisely, it must have the
3853 * %GTK_CAN_FOCUS flag set.)
3857 gtk_widget_grab_focus (GtkWidget *widget)
3859 g_return_if_fail (GTK_IS_WIDGET (widget));
3861 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3864 g_object_ref (widget);
3865 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3866 g_object_notify (G_OBJECT (widget), "has_focus");
3867 g_object_unref (widget);
3871 reset_focus_recurse (GtkWidget *widget,
3874 if (GTK_IS_CONTAINER (widget))
3876 GtkContainer *container;
3878 container = GTK_CONTAINER (widget);
3879 gtk_container_set_focus_child (container, NULL);
3881 gtk_container_foreach (container,
3882 reset_focus_recurse,
3888 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3890 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3892 GtkWidget *toplevel;
3895 /* clear the current focus setting, break if the current widget
3896 * is the focus widget's parent, since containers above that will
3897 * be set by the next loop.
3899 toplevel = gtk_widget_get_toplevel (focus_widget);
3900 if (GTK_WIDGET_TOPLEVEL (toplevel))
3902 widget = GTK_WINDOW (toplevel)->focus_widget;
3904 if (widget == focus_widget)
3906 /* We call _gtk_window_internal_set_focus() here so that the
3907 * toplevel window can request the focus if necessary.
3908 * This is needed when the toplevel is a GtkPlug
3910 if (!GTK_WIDGET_HAS_FOCUS (widget))
3911 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3918 while (widget->parent && widget->parent != focus_widget->parent)
3920 widget = widget->parent;
3921 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3925 else if (toplevel != focus_widget)
3927 /* gtk_widget_grab_focus() operates on a tree without window...
3928 * actually, this is very questionable behaviour.
3931 gtk_container_foreach (GTK_CONTAINER (toplevel),
3932 reset_focus_recurse,
3936 /* now propagate the new focus up the widget tree and finally
3937 * set it on the window
3939 widget = focus_widget;
3940 while (widget->parent)
3942 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
3943 widget = widget->parent;
3945 if (GTK_IS_WINDOW (widget))
3946 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
3951 gtk_widget_real_show_help (GtkWidget *widget,
3952 GtkWidgetHelpType help_type)
3954 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
3956 _gtk_tooltips_toggle_keyboard_mode (widget);
3964 gtk_widget_real_focus (GtkWidget *widget,
3965 GtkDirectionType direction)
3967 if (!GTK_WIDGET_CAN_FOCUS (widget))
3970 if (!gtk_widget_is_focus (widget))
3972 gtk_widget_grab_focus (widget);
3980 * gtk_widget_is_focus:
3981 * @widget: a #GtkWidget
3983 * Determines if the widget is the focus widget within its
3984 * toplevel. (This does not mean that the %HAS_FOCUS flag is
3985 * necessarily set; %HAS_FOCUS will only be set if the
3986 * toplevel widget additionally has the global input focus.)
3988 * Return value: %TRUE if the widget is the focus widget.
3991 gtk_widget_is_focus (GtkWidget *widget)
3993 GtkWidget *toplevel;
3995 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3997 toplevel = gtk_widget_get_toplevel (widget);
3999 if (GTK_IS_WINDOW (toplevel))
4000 return widget == GTK_WINDOW (toplevel)->focus_widget;
4006 * gtk_widget_grab_default:
4007 * @widget: a #GtkWidget
4009 * Causes @widget to become the default widget. @widget must have the
4010 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4011 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4012 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4013 * presses Enter in a window. Default widgets must be activatable,
4014 * that is, gtk_widget_activate() should affect them.
4018 gtk_widget_grab_default (GtkWidget *widget)
4022 g_return_if_fail (GTK_IS_WIDGET (widget));
4023 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4025 window = gtk_widget_get_toplevel (widget);
4027 if (window && GTK_WIDGET_TOPLEVEL (window))
4028 gtk_window_set_default (GTK_WINDOW (window), widget);
4030 g_warning (G_STRLOC ": widget not within a GtkWindow");
4034 * gtk_widget_set_name:
4035 * @widget: a #GtkWidget
4036 * @name: name for the widget
4038 * Widgets can be named, which allows you to refer to them from a
4039 * gtkrc file. You can apply a style to widgets with a particular name
4040 * in the gtkrc file. See the documentation for gtkrc files (on the
4041 * same page as the docs for #GtkRcStyle).
4043 * Note that widget names are separated by periods in paths (see
4044 * gtk_widget_path()), so names with embedded periods may cause confusion.
4047 gtk_widget_set_name (GtkWidget *widget,
4052 g_return_if_fail (GTK_IS_WIDGET (widget));
4054 new_name = g_strdup (name);
4055 g_free (widget->name);
4056 widget->name = new_name;
4058 if (GTK_WIDGET_RC_STYLE (widget))
4059 gtk_widget_reset_rc_style (widget);
4061 g_object_notify (G_OBJECT (widget), "name");
4065 * gtk_widget_get_name:
4066 * @widget: a #GtkWidget
4068 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4069 * significance of widget names.
4071 * Return value: name of the widget. This string is owned by GTK+ and
4072 * should not be modified or freed
4074 G_CONST_RETURN gchar*
4075 gtk_widget_get_name (GtkWidget *widget)
4077 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4080 return widget->name;
4081 return g_type_name (GTK_WIDGET_TYPE (widget));
4085 * gtk_widget_set_state:
4086 * @widget: a #GtkWidget
4087 * @state: new state for @widget
4089 * This function is for use in widget implementations. Sets the state
4090 * of a widget (insensitive, prelighted, etc.) Usually you should set
4091 * the state using wrapper functions such as gtk_widget_set_sensitive().
4095 gtk_widget_set_state (GtkWidget *widget,
4098 g_return_if_fail (GTK_IS_WIDGET (widget));
4100 if (state == GTK_WIDGET_STATE (widget))
4103 if (state == GTK_STATE_INSENSITIVE)
4104 gtk_widget_set_sensitive (widget, FALSE);
4110 data.state_restoration = FALSE;
4111 data.use_forall = FALSE;
4113 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4115 data.parent_sensitive = TRUE;
4117 gtk_widget_propagate_state (widget, &data);
4119 if (GTK_WIDGET_DRAWABLE (widget))
4120 gtk_widget_queue_draw (widget);
4125 gtk_widget_set_app_paintable (GtkWidget *widget,
4126 gboolean app_paintable)
4128 g_return_if_fail (GTK_IS_WIDGET (widget));
4130 app_paintable = (app_paintable != FALSE);
4132 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4135 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4137 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4139 if (GTK_WIDGET_DRAWABLE (widget))
4140 gtk_widget_queue_draw (widget);
4142 g_object_notify (G_OBJECT (widget), "app_paintable");
4147 * gtk_widget_set_double_buffered:
4148 * @widget: a #GtkWidget
4149 * @double_buffered: %TRUE to double-buffer a widget
4151 * Widgets are double buffered by default; you can use this function
4152 * to turn off the buffering. "Double buffered" simply means that
4153 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4154 * automatically around expose events sent to the
4155 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4156 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4157 * buffer to the screen. The result is that users see the window
4158 * update in one smooth step, and don't see individual graphics
4159 * primitives being rendered.
4161 * In very simple terms, double buffered widgets don't flicker,
4162 * so you would only use this function to turn off double buffering
4163 * if you had special needs and really knew what you were doing.
4167 gtk_widget_set_double_buffered (GtkWidget *widget,
4168 gboolean double_buffered)
4170 g_return_if_fail (GTK_IS_WIDGET (widget));
4172 if (double_buffered)
4173 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4175 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4179 * gtk_widget_set_redraw_on_allocate:
4180 * @widget: a #GtkWidget
4181 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4182 * when it is allocated to a new size. Otherwise, only the
4183 * new portion of the widget will be redrawn.
4185 * Sets whether a when a widgets size allocation changes, the entire
4186 * widget is queued for drawing. By default, this setting is %TRUE and
4187 * the entire widget is redrawn on every size change. If your widget
4188 * leaves the upper left unchanged when made bigger, turning this
4189 * setting on will improve performance.
4191 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4192 * off all allocation on resizing: the widget will not even redraw if
4193 * its position changes; this is to allow containers that don't draw
4194 * anything to avoid excess invalidations. If you set this flag on a
4195 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4196 * you are responsible for invalidating both the old and new allocation
4197 * of the widget when the widget is moved and responsible for invalidating
4198 * regions newly when the widget increases size.
4201 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4202 gboolean redraw_on_allocate)
4204 g_return_if_fail (GTK_IS_WIDGET (widget));
4206 if (redraw_on_allocate)
4207 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4209 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4213 * gtk_widget_set_sensitive:
4214 * @widget: a #GtkWidget
4215 * @sensitive: %TRUE to make the widget sensitive
4217 * Sets the sensitivity of a widget. A widget is sensitive if the user
4218 * can interact with it. Insensitive widgets are "grayed out" and the
4219 * user can't interact with them. Insensitive widgets are known as
4220 * "inactive", "disabled", or "ghosted" in some other toolkits.
4224 gtk_widget_set_sensitive (GtkWidget *widget,
4229 g_return_if_fail (GTK_IS_WIDGET (widget));
4231 sensitive = (sensitive != FALSE);
4233 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4238 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4239 data.state = GTK_WIDGET_SAVED_STATE (widget);
4243 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4244 data.state = GTK_WIDGET_STATE (widget);
4246 data.state_restoration = TRUE;
4247 data.use_forall = TRUE;
4250 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4252 data.parent_sensitive = TRUE;
4254 gtk_widget_propagate_state (widget, &data);
4255 if (GTK_WIDGET_DRAWABLE (widget))
4256 gtk_widget_queue_draw (widget);
4258 g_object_notify (G_OBJECT (widget), "sensitive");
4262 * gtk_widget_set_parent:
4263 * @widget: a #GtkWidget
4264 * @parent: parent container
4266 * This function is useful only when implementing subclasses of #GtkContainer.
4267 * Sets the container as the parent of @widget, and takes care of
4268 * some details such as updating the state and style of the child
4269 * to reflect its new location. The opposite function is
4270 * gtk_widget_unparent().
4274 gtk_widget_set_parent (GtkWidget *widget,
4279 g_return_if_fail (GTK_IS_WIDGET (widget));
4280 g_return_if_fail (GTK_IS_WIDGET (parent));
4281 g_return_if_fail (widget != parent);
4282 if (widget->parent != NULL)
4284 g_warning ("Can't set a parent on widget which has a parent\n");
4287 if (GTK_WIDGET_TOPLEVEL (widget))
4289 g_warning ("Can't set a parent on a toplevel widget\n");
4293 /* keep this function in sync with gtk_menu_attach_to_widget()
4296 g_object_ref (widget);
4297 gtk_object_sink (GTK_OBJECT (widget));
4298 widget->parent = parent;
4300 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4301 data.state = GTK_WIDGET_STATE (parent);
4303 data.state = GTK_WIDGET_STATE (widget);
4304 data.state_restoration = FALSE;
4305 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4306 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4308 gtk_widget_propagate_state (widget, &data);
4310 gtk_widget_reset_rc_styles (widget);
4312 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4313 if (GTK_WIDGET_ANCHORED (widget->parent))
4314 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4315 g_object_notify (G_OBJECT (widget), "parent");
4317 /* Enforce realized/mapped invariants
4319 if (GTK_WIDGET_REALIZED (widget->parent))
4320 gtk_widget_realize (widget);
4322 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4323 GTK_WIDGET_VISIBLE (widget))
4325 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4326 GTK_WIDGET_MAPPED (widget->parent))
4327 gtk_widget_map (widget);
4329 gtk_widget_queue_resize (widget);
4334 * gtk_widget_get_parent:
4335 * @widget: a #GtkWidget
4337 * Returns the parent container of @widget.
4339 * Return value: the parent container of @widget, or %NULL
4342 gtk_widget_get_parent (GtkWidget *widget)
4344 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4346 return widget->parent;
4349 /*****************************************
4351 * see docs/styles.txt
4352 *****************************************/
4355 * gtk_widget_set_style:
4356 * @widget: a #GtkWidget
4357 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4358 * gtk_widget_set_style() and go back to the default style
4360 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4361 * want to use this function; it interacts badly with themes, because
4362 * themes work by replacing the #GtkStyle. Instead, use
4363 * gtk_widget_modify_style().
4367 gtk_widget_set_style (GtkWidget *widget,
4370 g_return_if_fail (GTK_IS_WIDGET (widget));
4374 gboolean initial_emission;
4376 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4378 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4379 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4381 gtk_widget_set_style_internal (widget, style, initial_emission);
4385 if (GTK_WIDGET_USER_STYLE (widget))
4386 gtk_widget_reset_rc_style (widget);
4391 * gtk_widget_ensure_style:
4392 * @widget: a #GtkWidget
4394 * Ensures that @widget has a style (@widget->style). Not a very useful
4395 * function; most of the time, if you want the style, the widget is
4396 * realized, and realized widgets are guaranteed to have a style
4401 gtk_widget_ensure_style (GtkWidget *widget)
4403 g_return_if_fail (GTK_IS_WIDGET (widget));
4405 if (!GTK_WIDGET_USER_STYLE (widget) &&
4406 !GTK_WIDGET_RC_STYLE (widget))
4407 gtk_widget_reset_rc_style (widget);
4410 /* Look up the RC style for this widget, unsetting any user style that
4411 * may be in effect currently
4414 gtk_widget_reset_rc_style (GtkWidget *widget)
4416 GtkStyle *new_style = NULL;
4417 gboolean initial_emission;
4419 g_return_if_fail (GTK_IS_WIDGET (widget));
4421 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4423 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4424 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4426 if (gtk_widget_has_screen (widget))
4427 new_style = gtk_rc_get_style (widget);
4429 new_style = gtk_widget_get_default_style ();
4431 if (initial_emission || new_style != widget->style)
4432 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4436 * gtk_widget_get_style:
4437 * @widget: a #GtkWidget
4439 * Simply an accessor function that returns @widget->style.
4441 * Return value: the widget's #GtkStyle
4444 gtk_widget_get_style (GtkWidget *widget)
4446 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4448 return widget->style;
4452 * gtk_widget_modify_style:
4453 * @widget: a #GtkWidget
4454 * @style: the #GtkRcStyle holding the style modifications
4456 * Modifies style values on the widget. Modifications made using this
4457 * technique take precedence over style values set via an RC file,
4458 * however, they will be overriden if a style is explicitely set on
4459 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4460 * is designed so each field can either be set or unset, so it is
4461 * possible, using this function, to modify some style values and
4462 * leave the others unchanged.
4464 * Note that modifications made with this function are not cumulative
4465 * with previous calls to gtk_widget_modify_style() or with such
4466 * functions as gtk_widget_modify_fg(). If you wish to retain
4467 * previous values, you must first call gtk_widget_get_modifier_style(),
4468 * make your modifications to the returned style, then call
4469 * gtk_widget_modify_style() with that style. On the other hand,
4470 * if you first call gtk_widget_modify_style(), subsequent calls
4471 * to such functions gtk_widget_modify_fg() will have a cumulative
4472 * effect with the initial modifications.
4475 gtk_widget_modify_style (GtkWidget *widget,
4478 GtkRcStyle *old_style;
4480 g_return_if_fail (GTK_IS_WIDGET (widget));
4481 g_return_if_fail (GTK_IS_RC_STYLE (style));
4483 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4485 g_object_set_qdata_full (G_OBJECT (widget),
4487 gtk_rc_style_copy (style),
4488 (GDestroyNotify) gtk_rc_style_unref);
4490 /* note that "style" may be invalid here if it was the old
4491 * modifier style and the only reference was our own.
4494 if (GTK_WIDGET_RC_STYLE (widget))
4495 gtk_widget_reset_rc_style (widget);
4499 * gtk_widget_get_modifier_style:
4500 * @widget: a #GtkWidget
4502 * Returns the current modifier style for the widget. (As set by
4503 * gtk_widget_modify_style().) If no style has previously set, a new
4504 * #GtkRcStyle will be created with all values unset, and set as the
4505 * modifier style for the widget. If you make changes to this rc
4506 * style, you must call gtk_widget_modify_style(), passing in the
4507 * returned rc style, to make sure that your changes take effect.
4509 * Caution: passing the style back to gtk_widget_modify_style() will
4510 * normally end up destroying it, because gtk_widget_modify_style() copies
4511 * the passed-in style and sets the copy as the new modifier style,
4512 * thus dropping any reference to the old modifier style. Add a reference
4513 * to the modifier style if you want to keep it alive.
4515 * Return value: the modifier style for the widget. This rc style is
4516 * owned by the widget. If you want to keep a pointer to value this
4517 * around, you must add a refcount using gtk_rc_style_ref().
4520 gtk_widget_get_modifier_style (GtkWidget *widget)
4522 GtkRcStyle *rc_style;
4524 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4526 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4530 rc_style = gtk_rc_style_new ();
4531 g_object_set_qdata_full (G_OBJECT (widget),
4534 (GDestroyNotify) gtk_rc_style_unref);
4541 gtk_widget_modify_color_component (GtkWidget *widget,
4542 GtkRcFlags component,
4544 const GdkColor *color)
4546 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4553 rc_style->fg[state] = *color;
4556 rc_style->bg[state] = *color;
4559 rc_style->text[state] = *color;
4562 rc_style->base[state] = *color;
4565 g_assert_not_reached();
4568 rc_style->color_flags[state] |= component;
4571 rc_style->color_flags[state] &= ~component;
4573 gtk_widget_modify_style (widget, rc_style);
4577 * gtk_widget_modify_fg:
4578 * @widget: a #GtkWidget.
4579 * @state: the state for which to set the foreground color.
4580 * @color: the color to assign (does not need to be allocated),
4581 * or %NULL to undo the effect of previous calls to
4582 * of gtk_widget_modify_fg().
4584 * Sets the foreground color for a widget in a particular state. All
4585 * other style values are left untouched. See also
4586 * gtk_widget_modify_style().
4589 gtk_widget_modify_fg (GtkWidget *widget,
4591 const GdkColor *color)
4593 g_return_if_fail (GTK_IS_WIDGET (widget));
4594 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4596 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
4600 * gtk_widget_modify_bg:
4601 * @widget: a #GtkWidget.
4602 * @state: the state for which to set the background color.
4603 * @color: the color to assign (does not need to be allocated),
4604 * or %NULL to undo the effect of previous calls to
4605 * of gtk_widget_modify_bg().
4607 * Sets the background color for a widget in a particular state. All
4608 * other style values are left untouched. See also
4609 * gtk_widget_modify_style().
4612 gtk_widget_modify_bg (GtkWidget *widget,
4614 const GdkColor *color)
4616 g_return_if_fail (GTK_IS_WIDGET (widget));
4617 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4619 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4623 * gtk_widget_modify_text:
4624 * @widget: a #GtkWidget.
4625 * @state: the state for which to set the text color.
4626 * @color: the color to assign (does not need to be allocated),
4627 * or %NULL to undo the effect of previous calls to
4628 * of gtk_widget_modify_text().
4630 * Sets the text color for a widget in a particular state. All other
4631 * style values are left untouched. The text color is the foreground
4632 * color used along with the base color (see gtk_widget_modify_base())
4633 * for widgets such as #GtkEntry and #GtkTextView. See also
4634 * gtk_widget_modify_style().
4637 gtk_widget_modify_text (GtkWidget *widget,
4639 const GdkColor *color)
4641 g_return_if_fail (GTK_IS_WIDGET (widget));
4642 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4644 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4648 * gtk_widget_modify_base:
4649 * @widget: a #GtkWidget.
4650 * @state: the state for which to set the base color.
4651 * @color: the color to assign (does not need to be allocated),
4652 * or %NULL to undo the effect of previous calls to
4653 * of gtk_widget_modify_base().
4655 * Sets the base color for a widget in a particular state.
4656 * All other style values are left untouched. The base color
4657 * is the background color used along with the text color
4658 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4659 * and #GtkTextView. See also gtk_widget_modify_style().
4662 gtk_widget_modify_base (GtkWidget *widget,
4664 const GdkColor *color)
4666 g_return_if_fail (GTK_IS_WIDGET (widget));
4667 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4669 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4673 * gtk_widget_modify_font:
4674 * @widget: a #GtkWidget
4675 * @font_desc: the font description to use, or %NULL to undo
4676 * the effect of previous calls to gtk_widget_modify_font().
4678 * Sets the font to use for a widget. All other style values are left
4679 * untouched. See also gtk_widget_modify_style().
4682 gtk_widget_modify_font (GtkWidget *widget,
4683 PangoFontDescription *font_desc)
4685 GtkRcStyle *rc_style;
4687 g_return_if_fail (GTK_IS_WIDGET (widget));
4689 rc_style = gtk_widget_get_modifier_style (widget);
4691 if (rc_style->font_desc)
4692 pango_font_description_free (rc_style->font_desc);
4695 rc_style->font_desc = pango_font_description_copy (font_desc);
4697 rc_style->font_desc = NULL;
4699 gtk_widget_modify_style (widget, rc_style);
4703 gtk_widget_direction_changed (GtkWidget *widget,
4704 GtkTextDirection previous_direction)
4706 gtk_widget_queue_resize (widget);
4710 gtk_widget_style_set (GtkWidget *widget,
4711 GtkStyle *previous_style)
4713 if (GTK_WIDGET_REALIZED (widget) &&
4714 !GTK_WIDGET_NO_WINDOW (widget))
4715 gtk_style_set_background (widget->style, widget->window, widget->state);
4719 gtk_widget_set_style_internal (GtkWidget *widget,
4721 gboolean initial_emission)
4723 g_object_ref (widget);
4724 g_object_freeze_notify (G_OBJECT (widget));
4726 if (widget->style != style || initial_emission)
4728 PangoContext *context = gtk_widget_peek_pango_context (widget);
4730 pango_context_set_font_description (context, style->font_desc);
4733 if (widget->style != style)
4735 GtkStyle *previous_style;
4737 if (GTK_WIDGET_REALIZED (widget))
4739 gtk_widget_reset_shapes (widget);
4740 gtk_style_detach (widget->style);
4743 previous_style = widget->style;
4744 widget->style = style;
4745 g_object_ref (widget->style);
4747 if (GTK_WIDGET_REALIZED (widget))
4748 widget->style = gtk_style_attach (widget->style, widget->window);
4750 g_signal_emit (widget,
4751 widget_signals[STYLE_SET],
4753 initial_emission ? NULL : previous_style);
4754 g_object_unref (previous_style);
4756 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4757 gtk_widget_queue_resize (widget);
4759 else if (initial_emission)
4760 g_signal_emit (widget,
4761 widget_signals[STYLE_SET],
4764 g_object_notify (G_OBJECT (widget), "style");
4765 g_object_thaw_notify (G_OBJECT (widget));
4766 g_object_unref (widget);
4770 GtkWidget *previous_toplevel;
4771 GdkScreen *previous_screen;
4772 GdkScreen *new_screen;
4773 } HierarchyChangedInfo;
4776 do_screen_change (GtkWidget *widget,
4777 GdkScreen *old_screen,
4778 GdkScreen *new_screen)
4780 if (old_screen != new_screen)
4784 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4786 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4789 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4794 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4795 gpointer client_data)
4797 gboolean new_anchored;
4798 HierarchyChangedInfo *info = client_data;
4800 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4801 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4803 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4805 g_object_ref (widget);
4808 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4810 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4812 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4813 do_screen_change (widget, info->previous_screen, info->new_screen);
4815 if (GTK_IS_CONTAINER (widget))
4816 gtk_container_forall (GTK_CONTAINER (widget),
4817 gtk_widget_propagate_hierarchy_changed_recurse,
4820 g_object_unref (widget);
4825 * _gtk_widget_propagate_hierarchy_changed:
4826 * @widget: a #GtkWidget
4827 * @previous_toplevel: Previous toplevel
4829 * Propagates changes in the anchored state to a widget and all
4830 * children, unsetting or setting the %ANCHORED flag, and
4831 * emitting ::hierarchy_changed.
4834 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4835 GtkWidget *previous_toplevel)
4837 HierarchyChangedInfo info;
4839 info.previous_toplevel = previous_toplevel;
4840 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4842 if (GTK_WIDGET_TOPLEVEL (widget) ||
4843 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4844 info.new_screen = gtk_widget_get_screen (widget);
4846 info.new_screen = NULL;
4848 if (info.previous_screen)
4849 g_object_ref (info.previous_screen);
4850 if (previous_toplevel)
4851 g_object_ref (previous_toplevel);
4853 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4855 if (previous_toplevel)
4856 g_object_unref (previous_toplevel);
4857 if (info.previous_screen)
4858 g_object_unref (info.previous_screen);
4862 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4863 gpointer client_data)
4865 HierarchyChangedInfo *info = client_data;
4867 g_object_ref (widget);
4869 do_screen_change (widget, info->previous_screen, info->new_screen);
4871 if (GTK_IS_CONTAINER (widget))
4872 gtk_container_forall (GTK_CONTAINER (widget),
4873 gtk_widget_propagate_screen_changed_recurse,
4876 g_object_unref (widget);
4880 * _gtk_widget_propagate_screen_changed:
4881 * @widget: a #GtkWidget
4882 * @previous_screen: Previous screen
4884 * Propagates changes in the screen for a widget to all
4885 * children, emitting ::screen_changed.
4888 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
4889 GdkScreen *previous_screen)
4891 HierarchyChangedInfo info;
4893 info.previous_screen = previous_screen;
4894 info.new_screen = gtk_widget_get_screen (widget);
4896 if (previous_screen)
4897 g_object_ref (previous_screen);
4899 gtk_widget_propagate_screen_changed_recurse (widget, &info);
4901 if (previous_screen)
4902 g_object_unref (previous_screen);
4906 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4908 if (GTK_WIDGET_RC_STYLE (widget))
4909 gtk_widget_reset_rc_style (widget);
4911 if (GTK_IS_CONTAINER (widget))
4912 gtk_container_forall (GTK_CONTAINER (widget),
4913 reset_rc_styles_recurse,
4918 gtk_widget_reset_rc_styles (GtkWidget *widget)
4920 g_return_if_fail (GTK_IS_WIDGET (widget));
4922 reset_rc_styles_recurse (widget, NULL);
4926 * gtk_widget_get_default_style:
4928 * Returns the default style used by all widgets initially.
4930 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
4931 * should not be modified or freed.
4934 gtk_widget_get_default_style (void)
4936 if (!gtk_default_style)
4938 gtk_default_style = gtk_style_new ();
4939 g_object_ref (gtk_default_style);
4942 return gtk_default_style;
4945 static PangoContext *
4946 gtk_widget_peek_pango_context (GtkWidget *widget)
4948 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4952 * gtk_widget_get_pango_context:
4953 * @widget: a #GtkWidget
4955 * Gets a #PangoContext with the appropriate colormap, font description
4956 * and base direction for this widget. Unlike the context returned
4957 * by gtk_widget_create_pango_context(), this context is owned by
4958 * the widget (it can be used until the screen for the widget changes
4959 * or the widget is removed from its toplevel), and will be updated to
4960 * match any changes to the widget's attributes.
4962 * If you create and keep a #PangoLayout using this context, you must
4963 * deal with changes to the context by calling pango_layout_context_changed()
4964 * on the layout in response to the ::style-set and ::direction-changed signals
4967 * Return value: the #PangoContext for the widget.
4970 gtk_widget_get_pango_context (GtkWidget *widget)
4972 PangoContext *context;
4974 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4976 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4979 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
4980 g_object_set_qdata_full (G_OBJECT (widget),
4981 quark_pango_context,
4990 * gtk_widget_create_pango_context:
4991 * @widget: a #GtkWidget
4993 * Creates a new #PangoContext with the appropriate colormap,
4994 * font description, and base direction for drawing text for
4995 * this widget. See also gtk_widget_get_pango_context().
4997 * Return value: the new #PangoContext
5000 gtk_widget_create_pango_context (GtkWidget *widget)
5003 PangoContext *context;
5005 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5007 screen = gtk_widget_get_screen_unchecked (widget);
5010 GTK_NOTE (MULTIHEAD,
5011 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5013 screen = gdk_screen_get_default ();
5016 context = gdk_pango_context_get_for_screen (screen);
5018 pango_context_set_base_dir (context,
5019 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5020 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5021 pango_context_set_font_description (context, widget->style->font_desc);
5022 pango_context_set_language (context, gtk_get_default_language ());
5028 * gtk_widget_create_pango_layout:
5029 * @widget: a #GtkWidget
5030 * @text: text to set on the layout (can be %NULL)
5032 * Creates a new #PangoLayout with the appropriate colormap,
5033 * font description, and base direction for drawing text for
5036 * If you keep a #PangoLayout created in this way around, in order
5037 * notify the layout of changes to the base direction or font of this
5038 * widget, you must call pango_layout_context_changed() in response to
5039 * the ::style-set and ::direction-changed signals for the widget.
5041 * Return value: the new #PangoLayout
5044 gtk_widget_create_pango_layout (GtkWidget *widget,
5047 PangoLayout *layout;
5048 PangoContext *context;
5050 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5052 context = gtk_widget_get_pango_context (widget);
5053 layout = pango_layout_new (context);
5056 pango_layout_set_text (layout, text, -1);
5062 * gtk_widget_render_icon:
5063 * @widget: a #GtkWidget
5064 * @stock_id: a stock ID
5065 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5066 * the size of the source and don't scale (if there are multiple
5067 * source sizes, GTK+ picks one of the available sizes).
5068 * @detail: render detail to pass to theme engine
5070 * A convenience function that uses the theme engine and RC file
5071 * settings for @widget to look up @stock_id and render it to
5072 * a pixbuf. @stock_id should be a stock icon ID such as
5073 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5074 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5075 * identifies the widget or code doing the rendering, so that
5076 * theme engines can special-case rendering for that widget or code.
5078 * The pixels in the returned #GdkPixbuf are shared with the rest of
5079 * the application and should not be modified. The pixbuf should be freed
5080 * after use with g_object_unref().
5082 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5085 gtk_widget_render_icon (GtkWidget *widget,
5086 const gchar *stock_id,
5088 const gchar *detail)
5090 GtkIconSet *icon_set;
5093 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5094 g_return_val_if_fail (stock_id != NULL, NULL);
5095 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5097 gtk_widget_ensure_style (widget);
5099 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5101 if (icon_set == NULL)
5104 retval = gtk_icon_set_render_icon (icon_set,
5106 gtk_widget_get_direction (widget),
5107 GTK_WIDGET_STATE (widget),
5116 * gtk_widget_set_parent_window:
5117 * @widget: a #GtkWidget.
5118 * @parent_window: the new parent window.
5120 * Sets a non default parent window for @widget.
5123 gtk_widget_set_parent_window (GtkWidget *widget,
5124 GdkWindow *parent_window)
5126 GdkWindow *old_parent_window;
5128 g_return_if_fail (GTK_IS_WIDGET (widget));
5130 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5131 quark_parent_window);
5133 if (parent_window != old_parent_window)
5135 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5137 if (old_parent_window)
5138 g_object_unref (old_parent_window);
5140 g_object_ref (parent_window);
5146 * gtk_widget_set_child_visible:
5147 * @widget: a #GtkWidget
5148 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5150 * Sets whether @widget should be mapped along with its when its parent
5151 * is mapped and @widget has been shown with gtk_widget_show().
5153 * The child visibility can be set for widget before it is added to
5154 * a container with gtk_widget_set_parent(), to avoid mapping
5155 * children unnecessary before immediately unmapping them. However
5156 * it will be reset to its default state of %TRUE when the widget
5157 * is removed from a container.
5159 * Note that changing the child visibility of a widget does not
5160 * queue a resize on the widget. Most of the time, the size of
5161 * a widget is computed from all visible children, whether or
5162 * not they are mapped. If this is not the case, the container
5163 * can queue a resize itself.
5165 * This function is only useful for container implementations and
5166 * never should be called by an application.
5169 gtk_widget_set_child_visible (GtkWidget *widget,
5170 gboolean is_visible)
5172 g_return_if_fail (GTK_IS_WIDGET (widget));
5173 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5175 g_object_ref (widget);
5178 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5181 GtkWidget *toplevel;
5183 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5185 toplevel = gtk_widget_get_toplevel (widget);
5186 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5187 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5190 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5192 if (GTK_WIDGET_MAPPED (widget->parent) &&
5193 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5194 GTK_WIDGET_VISIBLE (widget))
5195 gtk_widget_map (widget);
5197 gtk_widget_unmap (widget);
5200 g_object_unref (widget);
5204 * gtk_widget_get_child_visible:
5205 * @widget: a #GtkWidget
5207 * Gets the value set with gtk_widget_set_child_visible().
5208 * If you feel a need to use this function, your code probably
5209 * needs reorganization.
5211 * This function is only useful for container implementations and
5212 * never should be called by an application.
5214 * Return value: %TRUE if the widget is mapped with the parent.
5217 gtk_widget_get_child_visible (GtkWidget *widget)
5219 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5221 return GTK_WIDGET_CHILD_VISIBLE (widget);
5225 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5227 GtkWidget *toplevel;
5229 toplevel = gtk_widget_get_toplevel (widget);
5231 if (GTK_WIDGET_TOPLEVEL (toplevel))
5233 if (GTK_IS_WINDOW (toplevel))
5234 return GTK_WINDOW (toplevel)->screen;
5235 else if (GTK_IS_INVISIBLE (toplevel))
5236 return GTK_INVISIBLE (widget)->screen;
5243 * gtk_widget_get_screen:
5244 * @widget: a #GtkWidget
5246 * Get the #GdkScreen from the toplevel window associated with
5247 * this widget. This function can only be called after the widget
5248 * has been added to a widget hierarchy with a #GtkWindow
5251 * In general, you should only create screen specific
5252 * resources when a widget has been realized, and you should
5253 * free those resources when the widget is unrealized.
5255 * Return value: the #GdkScreen for the toplevel for this widget.
5260 gtk_widget_get_screen (GtkWidget *widget)
5264 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5266 screen = gtk_widget_get_screen_unchecked (widget);
5273 g_warning (G_STRLOC ": Can't get associated screen"
5274 " for a widget unless it is inside a toplevel GtkWindow\n"
5275 " widget type is %s associated top level type is %s",
5276 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5277 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5279 return gdk_screen_get_default ();
5284 * gtk_widget_has_screen:
5285 * @widget: a #GtkWidget
5287 * Checks whether there is a #GdkScreen is associated with
5288 * this widget. All toplevel widgets have an associated
5289 * screen, and all widgets added into a heirarchy with a toplevel
5290 * window at the top.
5292 * Return value: %TRUE if there is a #GdkScreen associcated
5298 gtk_widget_has_screen (GtkWidget *widget)
5300 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5302 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5306 * gtk_widget_get_display:
5307 * @widget: a #GtkWidget
5309 * Get the #GdkDisplay for the toplevel window associated with
5310 * this widget. This function can only be called after the widget
5311 * has been added to a widget hierarchy with a #GtkWindow at the top.
5313 * In general, you should only create display specific
5314 * resources when a widget has been realized, and you should
5315 * free those resources when the widget is unrealized.
5317 * Return value: the #GdkDisplay for the toplevel for this widget.
5322 gtk_widget_get_display (GtkWidget *widget)
5324 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5326 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5330 * gtk_widget_get_root_window:
5331 * @widget: a #GtkWidget
5333 * Get the root window where this widget is located. This function can
5334 * only be called after the widget has been added to a widget
5335 * heirarchy with #GtkWindow at the top.
5337 * The root window is useful for such purposes as creating a popup
5338 * #GdkWindow associated with the window. In general, you should only
5339 * create display specific resources when a widget has been realized,
5340 * and you should free those resources when the widget is unrealized.
5342 * Return value: the #GdkWindow root window for the toplevel for this widget.
5347 gtk_widget_get_root_window (GtkWidget *widget)
5349 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5351 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5355 * gtk_widget_get_parent_window:
5356 * @widget: a #GtkWidget.
5357 * @returns: the parent window of @widget.
5359 * Gets @widget's parent window.
5362 gtk_widget_get_parent_window (GtkWidget *widget)
5364 GdkWindow *parent_window;
5366 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5367 g_return_val_if_fail (widget->parent != NULL, NULL);
5369 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5371 return (parent_window != NULL) ? parent_window : widget->parent->window;
5375 * gtk_widget_child_focus:
5376 * @widget: a #GtkWidget
5377 * @direction: direction of focus movement
5379 * This function is used by custom widget implementations; if you're
5380 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5381 * to a particular widget, and gtk_container_set_focus_chain() to
5382 * change the focus tab order. So you may want to investigate those
5383 * functions instead.
5385 * gtk_widget_child_focus() is called by containers as the user moves
5386 * around the window using keyboard shortcuts. @direction indicates
5387 * what kind of motion is taking place (up, down, left, right, tab
5388 * forward, tab backward). gtk_widget_child_focus() invokes the
5389 * "focus" signal on #GtkWidget; widgets override the default handler
5390 * for this signal in order to implement appropriate focus behavior.
5392 * The "focus" default handler for a widget should return %TRUE if
5393 * moving in @direction left the focus on a focusable location inside
5394 * that widget, and %FALSE if moving in @direction moved the focus
5395 * outside the widget. If returning %TRUE, widgets normally
5396 * call gtk_widget_grab_focus() to place the focus accordingly;
5397 * if returning %FALSE, they don't modify the current focus location.
5399 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5400 * necessary to check that the child was visible, sensitive, and
5401 * focusable before calling
5402 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5403 * the widget is not currently in a focusable state, so there's no
5404 * need for those checks.
5406 * Return value: %TRUE if focus ended up inside @widget
5409 gtk_widget_child_focus (GtkWidget *widget,
5410 GtkDirectionType direction)
5412 gboolean return_val;
5414 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5416 if (!GTK_WIDGET_VISIBLE (widget) ||
5417 !GTK_WIDGET_IS_SENSITIVE (widget))
5420 /* child widgets must set CAN_FOCUS, containers
5421 * don't have to though.
5423 if (!GTK_IS_CONTAINER (widget) &&
5424 !GTK_WIDGET_CAN_FOCUS (widget))
5427 g_signal_emit (widget,
5428 widget_signals[FOCUS],
5430 direction, &return_val);
5436 * gtk_widget_set_uposition:
5437 * @widget: a #GtkWidget
5438 * @x: x position; -1 to unset x; -2 to leave x unchanged
5439 * @y: y position; -1 to unset y; -2 to leave y unchanged
5442 * Sets the position of a widget. The funny "u" in the name comes from
5443 * the "user position" hint specified by the X Window System, and
5444 * exists for legacy reasons. This function doesn't work if a widget
5445 * is inside a container; it's only really useful on #GtkWindow.
5447 * Don't use this function to center dialogs over the main application
5448 * window; most window managers will do the centering on your behalf
5449 * if you call gtk_window_set_transient_for(), and it's really not
5450 * possible to get the centering to work correctly in all cases from
5451 * application code. But if you insist, use gtk_window_set_position()
5452 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5455 * Note that although @x and @y can be individually unset, the position
5456 * is not honoured unless both @x and @y are set.
5459 gtk_widget_set_uposition (GtkWidget *widget,
5463 /* FIXME this function is the only place that aux_info->x and
5464 * aux_info->y are even used I believe, and this function is
5465 * deprecated. Should be cleaned up.
5467 * (Actually, size_allocate uses them) -Yosh
5470 GtkWidgetAuxInfo *aux_info;
5472 g_return_if_fail (GTK_IS_WIDGET (widget));
5474 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5479 aux_info->x_set = FALSE;
5482 aux_info->x_set = TRUE;
5490 aux_info->y_set = FALSE;
5493 aux_info->y_set = TRUE;
5498 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5499 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5501 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5502 gtk_widget_size_allocate (widget, &widget->allocation);
5506 gtk_widget_set_usize_internal (GtkWidget *widget,
5510 GtkWidgetAuxInfo *aux_info;
5511 gboolean changed = FALSE;
5513 g_return_if_fail (GTK_IS_WIDGET (widget));
5515 g_object_freeze_notify (G_OBJECT (widget));
5517 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5519 if (width > -2 && aux_info->width != width)
5521 g_object_notify (G_OBJECT (widget), "width_request");
5522 aux_info->width = width;
5525 if (height > -2 && aux_info->height != height)
5527 g_object_notify (G_OBJECT (widget), "height_request");
5528 aux_info->height = height;
5532 if (GTK_WIDGET_VISIBLE (widget) && changed)
5533 gtk_widget_queue_resize (widget);
5535 g_object_thaw_notify (G_OBJECT (widget));
5539 * gtk_widget_set_usize:
5540 * @widget: a #GtkWidget
5541 * @width: minimum width, or -1 to unset
5542 * @height: minimum height, or -1 to unset
5544 * Sets the minimum size of a widget; that is, the widget's size
5545 * request will be @width by @height. You can use this function to
5546 * force a widget to be either larger or smaller than it is. The
5547 * strange "usize" name dates from the early days of GTK+, and derives
5548 * from X Window System terminology. In many cases,
5549 * gtk_window_set_default_size() is a better choice for toplevel
5550 * windows than this function; setting the default size will still
5551 * allow users to shrink the window. Setting the usize will force them
5552 * to leave the window at least as large as the usize. When dealing
5553 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5556 * Note the inherent danger of setting any fixed size - themes,
5557 * translations into other languages, different fonts, and user action
5558 * can all change the appropriate size for a given widget. So, it's
5559 * basically impossible to hardcode a size that will always be
5562 * @Deprecated: Use gtk_widget_set_size_request() instead.
5565 gtk_widget_set_usize (GtkWidget *widget,
5569 g_return_if_fail (GTK_IS_WIDGET (widget));
5571 gtk_widget_set_usize_internal (widget, width, height);
5575 * gtk_widget_set_size_request:
5576 * @widget: a #GtkWidget
5577 * @width: width @widget should request, or -1 to unset
5578 * @height: height @widget should request, or -1 to unset
5580 * Sets the minimum size of a widget; that is, the widget's size
5581 * request will be @width by @height. You can use this function to
5582 * force a widget to be either larger or smaller than it normally
5585 * In most cases, gtk_window_set_default_size() is a better choice for
5586 * toplevel windows than this function; setting the default size will
5587 * still allow users to shrink the window. Setting the size request
5588 * will force them to leave the window at least as large as the size
5589 * request. When dealing with window sizes,
5590 * gtk_window_set_geometry_hints() can be a useful function as well.
5592 * Note the inherent danger of setting any fixed size - themes,
5593 * translations into other languages, different fonts, and user action
5594 * can all change the appropriate size for a given widget. So, it's
5595 * basically impossible to hardcode a size that will always be
5598 * The size request of a widget is the smallest size a widget can
5599 * accept while still functioning well and drawing itself correctly.
5600 * However in some strange cases a widget may be allocated less than
5601 * its requested size, and in many cases a widget may be allocated more
5602 * space than it requested.
5604 * If the size request in a given direction is -1 (unset), then
5605 * the "natural" size request of the widget will be used instead.
5607 * Widgets can't actually be allocated a size less than 1 by 1, but
5608 * you can pass 0,0 to this function to mean "as small as possible."
5611 gtk_widget_set_size_request (GtkWidget *widget,
5615 g_return_if_fail (GTK_IS_WIDGET (widget));
5616 g_return_if_fail (width >= -1);
5617 g_return_if_fail (height >= -1);
5624 gtk_widget_set_usize_internal (widget, width, height);
5629 * gtk_widget_get_size_request:
5630 * @widget: a #GtkWidget
5631 * @width: return location for width, or %NULL
5632 * @height: return location for height, or %NULL
5634 * Gets the size request that was explicitly set for the widget using
5635 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5636 * @height indicates that that dimension has not been set explicitly
5637 * and the natural requisition of the widget will be used intead. See
5638 * gtk_widget_set_size_request(). To get the size a widget will
5639 * actually use, call gtk_widget_size_request() instead of
5645 gtk_widget_get_size_request (GtkWidget *widget,
5649 GtkWidgetAuxInfo *aux_info;
5651 g_return_if_fail (GTK_IS_WIDGET (widget));
5653 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5656 *width = aux_info ? aux_info->width : -1;
5659 *height = aux_info ? aux_info->height : -1;
5663 * gtk_widget_set_events:
5664 * @widget: a #GtkWidget
5665 * @events: event mask
5667 * Sets the event mask (see #GdkEventMask) for a widget. The event
5668 * mask determines which events a widget will receive. Keep in mind
5669 * that different widgets have different default event masks, and by
5670 * changing the event mask you may disrupt a widget's functionality,
5671 * so be careful. This function must be called while a widget is
5672 * unrealized. Consider gtk_widget_add_events() for widgets that are
5673 * already realized, or if you want to preserve the existing event
5674 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5675 * to get events on those widgets, place them inside a #GtkEventBox
5676 * and receive events on the event box.
5680 gtk_widget_set_events (GtkWidget *widget,
5685 g_return_if_fail (GTK_IS_WIDGET (widget));
5686 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5688 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5693 eventp = g_new (gint, 1);
5696 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5701 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5704 g_object_notify (G_OBJECT (widget), "events");
5708 * gtk_widget_add_events:
5709 * @widget: a #GtkWidget
5710 * @events: an event mask, see #GdkEventMask
5712 * Adds the events in the bitfield @events to the event mask for
5713 * @widget. See gtk_widget_set_events() for details.
5717 gtk_widget_add_events (GtkWidget *widget,
5722 g_return_if_fail (GTK_IS_WIDGET (widget));
5724 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5730 eventp = g_new (gint, 1);
5735 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5740 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5743 if (GTK_WIDGET_REALIZED (widget))
5745 if (GTK_WIDGET_NO_WINDOW (widget))
5747 GList *children = gdk_window_get_children (widget->window);
5748 GList *tmp_list = children;
5752 GdkWindow *window = tmp_list->data;
5755 gdk_window_get_user_data (window, &user_data);
5756 if (user_data == widget)
5757 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5758 tmp_list = tmp_list->next;
5761 g_list_free (children);
5765 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5769 g_object_notify (G_OBJECT (widget), "events");
5773 * gtk_widget_set_extension_events:
5774 * @widget: a #GtkWidget
5775 * @mode: bitfield of extension events to receive
5777 * Sets the extension events mask to @mode. See #GdkExtensionMode
5778 * and gdk_input_set_extension_events().
5782 gtk_widget_set_extension_events (GtkWidget *widget,
5783 GdkExtensionMode mode)
5785 GdkExtensionMode *modep;
5787 g_return_if_fail (GTK_IS_WIDGET (widget));
5789 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5792 modep = g_new (GdkExtensionMode, 1);
5795 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5796 g_object_notify (G_OBJECT (widget), "extension_events");
5800 * gtk_widget_get_toplevel:
5801 * @widget: a #GtkWidget
5803 * This function returns the topmost widget in the container hierarchy
5804 * @widget is a part of. If @widget has no parent widgets, it will be
5805 * returned as the topmost widget. No reference will be added to the
5806 * returned widget; it should not be unreferenced.
5808 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5809 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5811 * %NULL if @widget wasn't inside a toplevel window, and if the
5812 * window was inside a #GtkWindow-derived widget which was in turn
5813 * inside the toplevel #GtkWindow. While the second case may
5814 * seem unlikely, it actually happens when a #GtkPlug is embedded
5815 * inside a #GtkSocket within the same application.
5817 * To reliably find the toplevel #GtkWindow, use
5818 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5819 * is set on the result.
5820 * <informalexample><programlisting>
5821 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5822 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5824 * [ Perform action on toplevel. ]
5826 * </programlisting></informalexample>
5828 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5831 gtk_widget_get_toplevel (GtkWidget *widget)
5833 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5835 while (widget->parent)
5836 widget = widget->parent;
5842 * gtk_widget_get_ancestor:
5843 * @widget: a #GtkWidget
5844 * @widget_type: ancestor type
5846 * Gets the first ancestor of @widget with type @widget_type. For example,
5847 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5848 * first #GtkBox that's
5849 * an ancestor of @widget. No reference will be added to the returned widget;
5850 * it should not be unreferenced. See note about checking for a toplevel
5851 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5853 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
5854 * considers @widget to be an ancestor of itself.
5856 * Return value: the ancestor widget, or %NULL if not found
5859 gtk_widget_get_ancestor (GtkWidget *widget,
5862 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5864 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5865 widget = widget->parent;
5867 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5874 * gtk_widget_get_colormap:
5875 * @widget: a #GtkWidget
5877 * Gets the colormap that will be used to render @widget. No reference will
5878 * be added to the returned colormap; it should not be unreferenced.
5880 * Return value: the colormap used by @widget
5883 gtk_widget_get_colormap (GtkWidget *widget)
5885 GdkColormap *colormap;
5886 GtkWidget *tmp_widget;
5888 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5892 colormap = gdk_drawable_get_colormap (widget->window);
5893 /* If window was destroyed previously, we'll get NULL here */
5898 tmp_widget = widget;
5901 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5905 tmp_widget= tmp_widget->parent;
5908 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5912 * gtk_widget_get_visual:
5913 * @widget: a #GtkWidget
5915 * Gets the visual that will be used to render @widget.
5917 * Return value: the visual for @widget
5920 gtk_widget_get_visual (GtkWidget *widget)
5922 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5924 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
5928 * gtk_widget_get_settings:
5929 * @widget: a #GtkWidget
5931 * Gets the settings object holding the settings (global property
5932 * settings, RC file information, etc) used for this widget.
5934 * Note that this function can only be called when the #GtkWidget
5935 * is attached to a toplevel, since the settings object is specific
5936 * to a particular #GdkScreen.
5938 * Return value: the relevant #GtkSettings object
5941 gtk_widget_get_settings (GtkWidget *widget)
5943 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5945 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
5949 * gtk_widget_set_colormap:
5950 * @widget: a #GtkWidget
5951 * @colormap: a colormap
5953 * Sets the colormap for the widget to the given value. Widget must not
5954 * have been previously realized. This probably should only be used
5955 * from an <function>init()</function> function (i.e. from the constructor
5960 gtk_widget_set_colormap (GtkWidget *widget,
5961 GdkColormap *colormap)
5963 g_return_if_fail (GTK_IS_WIDGET (widget));
5964 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5965 g_return_if_fail (GDK_IS_COLORMAP (colormap));
5967 g_object_ref (colormap);
5969 g_object_set_qdata_full (G_OBJECT (widget),
5976 * gtk_widget_get_events:
5977 * @widget: a #GtkWidget
5979 * Returns the event mask for the widget (a bitfield containing flags
5980 * from the #GdkEventMask enumeration). These are the events that the widget
5983 * Return value: event mask for @widget
5986 gtk_widget_get_events (GtkWidget *widget)
5990 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5992 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6000 * gtk_widget_get_extension_events:
6001 * @widget: a #GtkWidget
6003 * Retrieves the extension events the widget will receive; see
6004 * gdk_input_set_extension_events().
6006 * Return value: extension events for @widget
6009 gtk_widget_get_extension_events (GtkWidget *widget)
6011 GdkExtensionMode *mode;
6013 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6015 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6023 * gtk_widget_get_pointer:
6024 * @widget: a #GtkWidget
6025 * @x: return location for the X coordinate, or %NULL
6026 * @y: return location for the Y coordinate, or %NULL
6028 * Obtains the location of the mouse pointer in widget coordinates.
6029 * Widget coordinates are a bit odd; for historical reasons, they are
6030 * defined as @widget->window coordinates for widgets that are not
6031 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6032 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6036 gtk_widget_get_pointer (GtkWidget *widget,
6040 g_return_if_fail (GTK_IS_WIDGET (widget));
6047 if (GTK_WIDGET_REALIZED (widget))
6049 gdk_window_get_pointer (widget->window, x, y, NULL);
6051 if (GTK_WIDGET_NO_WINDOW (widget))
6054 *x -= widget->allocation.x;
6056 *y -= widget->allocation.y;
6062 * gtk_widget_is_ancestor:
6063 * @widget: a #GtkWidget
6064 * @ancestor: another #GtkWidget
6066 * Determines whether @widget is somewhere inside @ancestor, possibly with
6067 * intermediate containers.
6069 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6072 gtk_widget_is_ancestor (GtkWidget *widget,
6073 GtkWidget *ancestor)
6075 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6076 g_return_val_if_fail (ancestor != NULL, FALSE);
6080 if (widget->parent == ancestor)
6082 widget = widget->parent;
6088 static GQuark quark_composite_name = 0;
6091 * gtk_widget_set_composite_name:
6092 * @widget: a #GtkWidget.
6093 * @name: the name to set.
6095 * Sets a widgets composite name. The widget must be
6096 * a composite child of its parent; see gtk_widget_push_composite_child().
6099 gtk_widget_set_composite_name (GtkWidget *widget,
6102 g_return_if_fail (GTK_IS_WIDGET (widget));
6103 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6104 g_return_if_fail (name != NULL);
6106 if (!quark_composite_name)
6107 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6109 g_object_set_qdata_full (G_OBJECT (widget),
6110 quark_composite_name,
6116 * gtk_widget_get_composite_name:
6117 * @widget: a #GtkWidget.
6118 * @returns: the composite name of @widget, or %NULL if @widget is not
6119 * a composite child. The string should not be freed when it is no
6122 * Obtains the composite name of a widget.
6125 gtk_widget_get_composite_name (GtkWidget *widget)
6127 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6129 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6130 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6137 * gtk_widget_push_composite_child:
6139 * Makes all newly-created widgets as composite children until
6140 * the corresponding gtk_widget_pop_composite_child() call.
6142 * A composite child is a child that's an implementation detail of the
6143 * container it's inside and should not be visible to people using the
6144 * container. Composite children aren't treated differently by GTK (but
6145 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6146 * builders might want to treat them in a different way.
6148 * Here is a simple example:
6149 * <informalexample><programlisting>
6150 * gtk_widget_push_composite_child (<!-- -->);
6151 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6152 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6153 * gtk_widget_pop_composite_child (<!-- -->);
6154 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6155 * GTK_WIDGET (scrolled_window));
6156 * g_object_ref (scrolled_window->hscrollbar);
6157 * </programlisting></informalexample>
6160 gtk_widget_push_composite_child (void)
6162 composite_child_stack++;
6166 * gtk_widget_pop_composite_child:
6168 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6171 gtk_widget_pop_composite_child (void)
6173 if (composite_child_stack)
6174 composite_child_stack--;
6178 * gtk_widget_push_colormap:
6179 * @cmap: a #GdkColormap
6181 * Pushes @cmap onto a global stack of colormaps; the topmost
6182 * colormap on the stack will be used to create all widgets.
6183 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6184 * reason to use this function.
6188 gtk_widget_push_colormap (GdkColormap *cmap)
6190 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6192 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6196 * gtk_widget_pop_colormap:
6198 * Removes a colormap pushed with gtk_widget_push_colormap().
6202 gtk_widget_pop_colormap (void)
6205 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6209 * gtk_widget_set_default_colormap:
6210 * @colormap: a #GdkColormap
6212 * Sets the default colormap to use when creating widgets.
6213 * gtk_widget_push_colormap() is a better function to use if
6214 * you only want to affect a few widgets, rather than all widgets.
6217 gtk_widget_set_default_colormap (GdkColormap *colormap)
6219 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6221 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6226 * gtk_widget_get_default_colormap:
6228 * Obtains the default colormap used to create widgets.
6230 * Return value: default widget colormap
6233 gtk_widget_get_default_colormap (void)
6235 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6239 * gtk_widget_get_default_visual:
6241 * Obtains the visual of the default colormap. Not really useful;
6242 * used to be useful before gdk_colormap_get_visual() existed.
6244 * Return value: visual of the default colormap
6247 gtk_widget_get_default_visual (void)
6249 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6253 gtk_widget_emit_direction_changed (GtkWidget *widget,
6254 GtkTextDirection old_dir)
6256 PangoContext *context = gtk_widget_peek_pango_context (widget);
6259 pango_context_set_base_dir (context,
6260 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6261 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6263 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6267 * gtk_widget_set_direction:
6268 * @widget: a #GtkWidget
6269 * @dir: the new direction
6271 * Sets the reading direction on a particular widget. This direction
6272 * controls the primary direction for widgets containing text,
6273 * and also the direction in which the children of a container are
6274 * packed. The ability to set the direction is present in order
6275 * so that correct localization into languages with right-to-left
6276 * reading directions can be done. Generally, applications will
6277 * let the default reading direction present, except for containers
6278 * where the containers are arranged in an order that is explicitely
6279 * visual rather than logical (such as buttons for text justification).
6281 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6282 * set by gtk_widget_set_default_direction() will be used.
6285 gtk_widget_set_direction (GtkWidget *widget,
6286 GtkTextDirection dir)
6288 GtkTextDirection old_dir;
6290 g_return_if_fail (GTK_IS_WIDGET (widget));
6291 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6293 old_dir = gtk_widget_get_direction (widget);
6295 if (dir == GTK_TEXT_DIR_NONE)
6296 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6299 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6300 if (dir == GTK_TEXT_DIR_LTR)
6301 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6303 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6306 if (old_dir != gtk_widget_get_direction (widget))
6307 gtk_widget_emit_direction_changed (widget, old_dir);
6311 * gtk_widget_get_direction:
6312 * @widget: a #GtkWidget
6314 * Gets the reading direction for a particular widget. See
6315 * gtk_widget_set_direction().
6317 * Return value: the reading direction for the widget.
6320 gtk_widget_get_direction (GtkWidget *widget)
6322 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6324 if (GTK_WIDGET_DIRECTION_SET (widget))
6325 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6327 return gtk_default_direction;
6331 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6333 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6335 g_object_ref (widget);
6337 if (!GTK_WIDGET_DIRECTION_SET (widget))
6338 gtk_widget_emit_direction_changed (widget, old_dir);
6340 if (GTK_IS_CONTAINER (widget))
6341 gtk_container_forall (GTK_CONTAINER (widget),
6342 gtk_widget_set_default_direction_recurse,
6345 g_object_unref (widget);
6349 * gtk_widget_set_default_direction:
6350 * @dir: the new default direction. This cannot be
6351 * %GTK_TEXT_DIR_NONE.
6353 * Sets the default reading direction for widgets where the
6354 * direction has not been explicitly set by gtk_widget_set_direction().
6357 gtk_widget_set_default_direction (GtkTextDirection dir)
6359 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6361 if (dir != gtk_default_direction)
6363 GList *toplevels, *tmp_list;
6364 GtkTextDirection old_dir = gtk_default_direction;
6366 gtk_default_direction = dir;
6368 tmp_list = toplevels = gtk_window_list_toplevels ();
6369 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6373 gtk_widget_set_default_direction_recurse (tmp_list->data,
6374 GUINT_TO_POINTER (old_dir));
6375 g_object_unref (tmp_list->data);
6376 tmp_list = tmp_list->next;
6379 g_list_free (toplevels);
6384 * gtk_widget_get_default_direction:
6386 * Obtains the current default reading direction. See
6387 * gtk_widget_set_default_direction().
6389 * Return value: the current default direction.
6392 gtk_widget_get_default_direction (void)
6394 return gtk_default_direction;
6398 gtk_widget_dispose (GObject *object)
6400 GtkWidget *widget = GTK_WIDGET (object);
6403 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6404 else if (GTK_WIDGET_VISIBLE (widget))
6405 gtk_widget_hide (widget);
6407 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6408 if (GTK_WIDGET_REALIZED (widget))
6409 gtk_widget_unrealize (widget);
6411 G_OBJECT_CLASS (parent_class)->dispose (object);
6415 gtk_widget_real_destroy (GtkObject *object)
6417 /* gtk_object_destroy() will already hold a refcount on object */
6418 GtkWidget *widget = GTK_WIDGET (object);
6420 /* wipe accelerator closures (keep order) */
6421 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6422 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6424 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6425 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6427 gtk_grab_remove (widget);
6429 g_object_unref (widget->style);
6430 widget->style = gtk_widget_get_default_style ();
6431 g_object_ref (widget->style);
6433 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6437 gtk_widget_finalize (GObject *object)
6439 GtkWidget *widget = GTK_WIDGET (object);
6440 GtkWidgetAuxInfo *aux_info;
6442 GdkExtensionMode *mode;
6443 GtkAccessible *accessible;
6445 gtk_grab_remove (widget);
6447 g_object_unref (widget->style);
6448 widget->style = NULL;
6451 g_free (widget->name);
6453 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6455 gtk_widget_aux_info_destroy (aux_info);
6457 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6461 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6465 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6467 g_object_unref (accessible);
6469 G_OBJECT_CLASS (parent_class)->finalize (object);
6472 /*****************************************
6473 * gtk_widget_real_map:
6478 *****************************************/
6481 gtk_widget_real_map (GtkWidget *widget)
6483 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6485 if (!GTK_WIDGET_MAPPED (widget))
6487 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6489 if (!GTK_WIDGET_NO_WINDOW (widget))
6490 gdk_window_show (widget->window);
6494 /*****************************************
6495 * gtk_widget_real_unmap:
6500 *****************************************/
6503 gtk_widget_real_unmap (GtkWidget *widget)
6505 if (GTK_WIDGET_MAPPED (widget))
6507 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6509 if (!GTK_WIDGET_NO_WINDOW (widget))
6510 gdk_window_hide (widget->window);
6514 /*****************************************
6515 * gtk_widget_real_realize:
6520 *****************************************/
6523 gtk_widget_real_realize (GtkWidget *widget)
6525 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6527 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6530 widget->window = gtk_widget_get_parent_window (widget);
6531 g_object_ref (widget->window);
6533 widget->style = gtk_style_attach (widget->style, widget->window);
6536 /*****************************************
6537 * gtk_widget_real_unrealize:
6542 *****************************************/
6545 gtk_widget_real_unrealize (GtkWidget *widget)
6547 if (GTK_WIDGET_MAPPED (widget))
6548 gtk_widget_real_unmap (widget);
6550 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6552 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6555 /* We must do unrealize child widget BEFORE container widget.
6556 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6557 * So, unrealizing container widget bofore its children causes the problem
6558 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6561 if (GTK_IS_CONTAINER (widget))
6562 gtk_container_forall (GTK_CONTAINER (widget),
6563 (GtkCallback) gtk_widget_unrealize,
6566 gtk_style_detach (widget->style);
6567 if (!GTK_WIDGET_NO_WINDOW (widget))
6569 gdk_window_set_user_data (widget->window, NULL);
6570 gdk_window_destroy (widget->window);
6571 widget->window = NULL;
6575 g_object_unref (widget->window);
6576 widget->window = NULL;
6579 gtk_selection_remove_all (widget);
6581 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6585 gtk_widget_real_size_request (GtkWidget *widget,
6586 GtkRequisition *requisition)
6588 requisition->width = widget->requisition.width;
6589 requisition->height = widget->requisition.height;
6593 * _gtk_widget_peek_colormap:
6595 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6597 * Return value: the currently pushed colormap, or %NULL if there is none.
6600 _gtk_widget_peek_colormap (void)
6603 return (GdkColormap*) colormap_stack->data;
6608 gtk_widget_propagate_state (GtkWidget *widget,
6613 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6614 * parent_sensitive==TRUE on a sensitive widget
6617 old_state = GTK_WIDGET_STATE (widget);
6619 if (data->parent_sensitive)
6621 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6623 if (GTK_WIDGET_IS_SENSITIVE (widget))
6625 if (data->state_restoration)
6626 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6628 GTK_WIDGET_STATE (widget) = data->state;
6632 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6633 if (!data->state_restoration &&
6634 data->state != GTK_STATE_INSENSITIVE)
6635 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6640 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6641 if (!data->state_restoration)
6643 if (data->state != GTK_STATE_INSENSITIVE)
6644 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6646 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6647 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6648 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6651 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6655 window = gtk_widget_get_toplevel (widget);
6656 if (window && GTK_WIDGET_TOPLEVEL (window))
6657 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6660 if (old_state != GTK_WIDGET_STATE (widget))
6662 g_object_ref (widget);
6664 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6665 gtk_grab_remove (widget);
6667 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6669 if (GTK_IS_CONTAINER (widget))
6671 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6672 data->state = GTK_WIDGET_STATE (widget);
6673 if (data->use_forall)
6674 gtk_container_forall (GTK_CONTAINER (widget),
6675 (GtkCallback) gtk_widget_propagate_state,
6678 gtk_container_foreach (GTK_CONTAINER (widget),
6679 (GtkCallback) gtk_widget_propagate_state,
6682 g_object_unref (widget);
6687 * _gtk_widget_get_aux_info:
6688 * @widget: a #GtkWidget
6689 * @create: if %TRUE, create the structure if it doesn't exist
6691 * Get the #GtkWidgetAuxInfo structure for the widget.
6693 * Return value: the #GtkAuxInfo structure for the widget, or
6694 * %NULL if @create is %FALSE and one doesn't already exist.
6697 _gtk_widget_get_aux_info (GtkWidget *widget,
6700 GtkWidgetAuxInfo *aux_info;
6702 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6703 if (!aux_info && create)
6705 if (!aux_info_mem_chunk)
6706 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6707 sizeof (GtkWidgetAuxInfo),
6708 1024, G_ALLOC_AND_FREE);
6709 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6711 aux_info->width = -1;
6712 aux_info->height = -1;
6715 aux_info->x_set = FALSE;
6716 aux_info->y_set = FALSE;
6717 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6723 /*****************************************
6724 * gtk_widget_aux_info_destroy:
6729 *****************************************/
6732 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6734 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6738 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6740 g_object_unref (info->shape_mask);
6745 * gtk_widget_shape_combine_mask:
6746 * @widget: a #GtkWidget.
6747 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6748 * @offset_x: X position of shape mask with respect to @window.
6749 * @offset_y: Y position of shape mask with respect to @window.
6751 * Sets a shape for this widget's GDK window. This allows for
6752 * transparent windows etc., see gdk_window_shape_combine_mask()
6753 * for more information.
6756 gtk_widget_shape_combine_mask (GtkWidget *widget,
6757 GdkBitmap *shape_mask,
6761 GtkWidgetShapeInfo* shape_info;
6763 g_return_if_fail (GTK_IS_WIDGET (widget));
6764 /* set_shape doesn't work on widgets without gdk window */
6765 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6769 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6772 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6774 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6778 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6780 shape_info = g_new (GtkWidgetShapeInfo, 1);
6781 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6782 (GDestroyNotify) gtk_widget_shape_info_destroy);
6784 shape_info->shape_mask = g_object_ref (shape_mask);
6785 shape_info->offset_x = offset_x;
6786 shape_info->offset_y = offset_y;
6788 /* set shape if widget has a gdk window allready.
6789 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6792 gdk_window_shape_combine_mask (widget->window, shape_mask,
6793 offset_x, offset_y);
6798 gtk_reset_shapes_recurse (GtkWidget *widget,
6804 gdk_window_get_user_data (window, &data);
6808 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6809 for (list = gdk_window_peek_children (window); list; list = list->next)
6810 gtk_reset_shapes_recurse (widget, list->data);
6814 * gtk_widget_reset_shapes:
6815 * @widget: a #GtkWidget.
6817 * Recursively resets the shape on this widget and its descendants.
6820 gtk_widget_reset_shapes (GtkWidget *widget)
6822 g_return_if_fail (GTK_IS_WIDGET (widget));
6823 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6825 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6826 gtk_reset_shapes_recurse (widget, widget->window);
6831 * @widget: a #GtkWidget
6833 * Adds a reference to a widget. This function is exactly the same
6834 * as calling g_object_ref(), and exists mostly for historical
6835 * reasons. It can still be convenient to avoid casting a widget
6836 * to a #GObject, it saves a small amount of typing.
6838 * Return value: the widget that was referenced
6841 gtk_widget_ref (GtkWidget *widget)
6843 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6845 return (GtkWidget*) g_object_ref ((GObject*) widget);
6850 * @widget: a #GtkWidget
6852 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6856 gtk_widget_unref (GtkWidget *widget)
6858 g_return_if_fail (GTK_IS_WIDGET (widget));
6860 g_object_unref ((GObject*) widget);
6868 * gtk_widget_class_install_style_property_parser:
6869 * @klass: a #GtkWidgetClass
6870 * @pspec: the #GParamSpec for the style property
6871 * @parser: the parser for the style property
6873 * Installs a style property on a widget class.
6876 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
6878 GtkRcPropertyParser parser)
6880 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6881 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6882 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6883 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6885 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
6887 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6888 G_OBJECT_CLASS_NAME (klass),
6893 g_param_spec_ref (pspec);
6894 g_param_spec_sink (pspec);
6895 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6896 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
6900 * gtk_widget_class_install_style_property:
6901 * @klass: a #GtkWidgetClass
6902 * @pspec: the #GParamSpec for the property
6904 * Installs a style property on a widget class. The parser for the
6905 * style property is determined by the value type of @pspec.
6908 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
6911 GtkRcPropertyParser parser;
6913 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6914 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6916 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6918 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
6922 * gtk_widget_class_find_style_property:
6923 * @klass: a #GtkWidgetClass
6924 * @property_name: the name of the style property to find
6925 * @returns: the #GParamSpec of the style property or %NULL if @class has no
6926 * style property with that name.
6928 * Finds a style property of a widget class by name.
6933 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
6934 const gchar *property_name)
6936 g_return_val_if_fail (property_name != NULL, NULL);
6938 return g_param_spec_pool_lookup (style_property_spec_pool,
6940 G_OBJECT_CLASS_TYPE (klass),
6945 * gtk_widget_class_list_style_properties:
6946 * @klass: a #GtkWidgetClass
6947 * @n_properties: location to return the number of style properties found
6948 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
6950 * Returns all style properties of a widget class.
6955 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
6956 guint *n_properties)
6958 GParamSpec **pspecs;
6961 pspecs = g_param_spec_pool_list (style_property_spec_pool,
6962 G_OBJECT_CLASS_TYPE (klass),
6971 * gtk_widget_style_get_property:
6972 * @widget: a #GtkWidget
6973 * @property_name: the name of a style property
6974 * @value: location to return the property value
6976 * Gets the value of a style property of @widget.
6979 gtk_widget_style_get_property (GtkWidget *widget,
6980 const gchar *property_name,
6985 g_return_if_fail (GTK_IS_WIDGET (widget));
6986 g_return_if_fail (property_name != NULL);
6987 g_return_if_fail (G_IS_VALUE (value));
6989 g_object_ref (widget);
6990 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
6992 G_OBJECT_TYPE (widget),
6995 g_warning ("%s: widget class `%s' has no property named `%s'",
6997 G_OBJECT_TYPE_NAME (widget),
7001 const GValue *peek_value;
7003 peek_value = _gtk_style_peek_property_value (widget->style,
7004 G_OBJECT_TYPE (widget),
7006 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7008 /* auto-conversion of the caller's value type
7010 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7011 g_value_copy (peek_value, value);
7012 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7013 g_value_transform (peek_value, value);
7015 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7017 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7018 G_VALUE_TYPE_NAME (value));
7020 g_object_unref (widget);
7024 * gtk_widget_style_get_valist:
7025 * @widget: a #GtkWidget
7026 * @first_property_name: the name of the first property to get
7027 * @var_args: a <type>va_list</type> of pairs of property names and
7028 * locations to return the property values, starting with the location
7029 * for @first_property_name.
7031 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7035 gtk_widget_style_get_valist (GtkWidget *widget,
7036 const gchar *first_property_name,
7041 g_return_if_fail (GTK_IS_WIDGET (widget));
7043 g_object_ref (widget);
7045 name = first_property_name;
7048 const GValue *peek_value;
7052 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7054 G_OBJECT_TYPE (widget),
7058 g_warning ("%s: widget class `%s' has no property named `%s'",
7060 G_OBJECT_TYPE_NAME (widget),
7064 /* style pspecs are always readable so we can spare that check here */
7066 peek_value = _gtk_style_peek_property_value (widget->style,
7067 G_OBJECT_TYPE (widget),
7069 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7070 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7073 g_warning ("%s: %s", G_STRLOC, error);
7078 name = va_arg (var_args, gchar*);
7081 g_object_unref (widget);
7085 * gtk_widget_style_get:
7086 * @widget: a #GtkWidget
7087 * @first_property_name: the name of the first property to get
7088 * @Varargs: pairs of property names and locations to
7089 * return the property values, starting with the location for
7090 * @first_property_name, terminated by %NULL.
7092 * Gets the values of a multiple style properties of @widget.
7095 gtk_widget_style_get (GtkWidget *widget,
7096 const gchar *first_property_name,
7101 g_return_if_fail (GTK_IS_WIDGET (widget));
7103 va_start (var_args, first_property_name);
7104 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7110 * @widget: a #GtkWidget
7111 * @path_length: location to store length of the path, or %NULL
7112 * @path: location to store allocated path string, or %NULL
7113 * @path_reversed: location to store allocated reverse path string, or %NULL
7115 * Obtains the full path to @widget. The path is simply the name of a
7116 * widget and all its parents in the container hierarchy, separated by
7117 * periods. The name of a widget comes from
7118 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7119 * in gtkrc configuration files. Widget names are the type of the
7120 * widget by default (e.g. "GtkButton") or can be set to an
7121 * application-specific value with gtk_widget_set_name(). By setting
7122 * the name of a widget, you allow users or theme authors to apply
7123 * styles to that specific widget in their gtkrc
7124 * file. @path_reversed_p fills in the path in reverse order,
7125 * i.e. starting with @widget's name instead of starting with the name
7126 * of @widget's outermost ancestor.
7130 gtk_widget_path (GtkWidget *widget,
7133 gchar **path_reversed)
7135 static gchar *rev_path = NULL;
7136 static guint tmp_path_len = 0;
7139 g_return_if_fail (GTK_IS_WIDGET (widget));
7144 const gchar *string;
7149 string = gtk_widget_get_name (widget);
7150 l = strlen (string);
7151 while (tmp_path_len <= len + l + 1)
7153 tmp_path_len += INIT_PATH_SIZE;
7154 rev_path = g_realloc (rev_path, tmp_path_len);
7162 widget = widget->parent;
7165 rev_path[len++] = '.';
7167 rev_path[len++] = 0;
7172 *path_length = len - 1;
7174 *path_reversed = g_strdup (rev_path);
7177 *path = g_strdup (rev_path);
7178 g_strreverse (*path);
7183 * gtk_widget_class_path:
7184 * @widget: a #GtkWidget
7185 * @path_length: location to store the length of the class path, or %NULL
7186 * @path: location to store the class path as an allocated string, or %NULL
7187 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7189 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7190 * never uses a custom name set with gtk_widget_set_name().
7194 gtk_widget_class_path (GtkWidget *widget,
7197 gchar **path_reversed)
7199 static gchar *rev_path = NULL;
7200 static guint tmp_path_len = 0;
7203 g_return_if_fail (GTK_IS_WIDGET (widget));
7208 const gchar *string;
7213 string = g_type_name (GTK_WIDGET_TYPE (widget));
7214 l = strlen (string);
7215 while (tmp_path_len <= len + l + 1)
7217 tmp_path_len += INIT_PATH_SIZE;
7218 rev_path = g_realloc (rev_path, tmp_path_len);
7226 widget = widget->parent;
7229 rev_path[len++] = '.';
7231 rev_path[len++] = 0;
7236 *path_length = len - 1;
7238 *path_reversed = g_strdup (rev_path);
7241 *path = g_strdup (rev_path);
7242 g_strreverse (*path);
7247 * gtk_requisition_copy:
7248 * @requisition: a #GtkRequisition.
7249 * @returns: a copy of @requisition.
7251 * Copies a #GtkRequisition.
7254 gtk_requisition_copy (const GtkRequisition *requisition)
7256 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7260 * gtk_requisition_free:
7261 * @requisition: a #GtkRequisition.
7263 * Frees a #GtkRequisition.
7266 gtk_requisition_free (GtkRequisition *requisition)
7268 g_free (requisition);
7272 gtk_requisition_get_type (void)
7274 static GType our_type = 0;
7277 our_type = g_boxed_type_register_static ("GtkRequisition",
7278 (GBoxedCopyFunc) gtk_requisition_copy,
7279 (GBoxedFreeFunc) gtk_requisition_free);
7285 gtk_widget_get_accessible (GtkWidget *widget)
7287 GtkWidgetClass *klass;
7289 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7291 klass = GTK_WIDGET_GET_CLASS (widget);
7293 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7295 return klass->get_accessible (widget);
7299 gtk_widget_real_get_accessible (GtkWidget *widget)
7301 AtkObject* accessible;
7303 accessible = g_object_get_qdata (G_OBJECT (widget),
7304 quark_accessible_object);
7307 AtkObjectFactory *factory;
7308 AtkRegistry *default_registry;
7310 default_registry = atk_get_default_registry ();
7311 factory = atk_registry_get_factory (default_registry,
7312 G_TYPE_FROM_INSTANCE (widget));
7314 atk_object_factory_create_accessible (factory,
7316 g_object_set_qdata (G_OBJECT (widget),
7317 quark_accessible_object,
7324 * Initialize a AtkImplementorIface instance's virtual pointers as
7325 * appropriate to this implementor's class (GtkWidget).
7328 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7330 iface->ref_accessible = gtk_widget_ref_accessible;
7334 gtk_widget_ref_accessible (AtkImplementor *implementor)
7336 AtkObject *accessible;
7338 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7340 g_object_ref (accessible);
7345 * gtk_widget_get_clipboard:
7346 * @widget: a #GtkWidget
7347 * @selection: a #GdkAtom which identifies the clipboard
7348 * to use. %GDK_SELECTION_CLIPBOARD gives the
7349 * default clipboard. Another common value
7350 * is %GDK_SELECTION_PRIMARY, which gives
7351 * the primary X selection.
7353 * Returns the clipboard object for the given selection to
7354 * be used with @widget. @widget must have a #GdkDisplay
7355 * associated with it, so must be attached to a toplevel
7358 * Return value: the appropriate clipboard object. If no
7359 * clipboard already exists, a new one will
7360 * be created. Once a clipboard object has
7361 * been created, it is persistent for all time.
7366 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7368 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7369 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7371 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7376 * gtk_widget_list_mnemonic_labels:
7377 * @widget: a #GtkWidget
7379 * Returns a newly allocated list of the widgets, normally labels, for
7380 * which this widget is a the target of a mnemonic (see for example,
7381 * gtk_label_set_mnemonic_widget()).
7383 * The widgets in the list are not individually referenced. If you
7384 * want to iterate through the list and perform actions involving
7385 * callbacks that might destroy the widgets, you
7386 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7387 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7388 * widgets afterwards.
7390 * Return value: the list of mnemonic labels; free this list
7391 * with g_list_free() when you are done with it.
7396 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7401 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7403 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7404 list = g_list_prepend (list, l->data);
7410 * gtk_widget_add_mnemonic_label:
7411 * @widget: a #GtkWidget
7412 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7414 * Adds a widget to the list of mnemonic labels for
7415 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7416 * list of mnemonic labels for the widget is cleared when the
7417 * widget is destroyed, so the caller must make sure to update
7418 * it's internal state at this point as well, by using a connection
7419 * to the ::destroy signal or a weak notifier.
7424 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7427 GSList *old_list, *new_list;
7429 g_return_if_fail (GTK_IS_WIDGET (widget));
7430 g_return_if_fail (GTK_IS_WIDGET (label));
7432 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7433 new_list = g_slist_prepend (old_list, label);
7435 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7436 new_list, (GDestroyNotify) g_slist_free);
7440 * gtk_widget_remove_mnemonic_label:
7441 * @widget: a #GtkWidget
7442 * @label: a #GtkWidget that was previously set as a mnemnic label for
7443 * @widget with gtk_widget_add_mnemonic_label().
7445 * Removes a widget from the list of mnemonic labels for
7446 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7447 * must have previously been added to the list with
7448 * gtk_widget_add_mnemonic_label().
7453 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7456 GSList *old_list, *new_list;
7458 g_return_if_fail (GTK_IS_WIDGET (widget));
7459 g_return_if_fail (GTK_IS_WIDGET (label));
7461 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7462 new_list = g_slist_remove (old_list, label);
7465 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7466 new_list, (GDestroyNotify) g_slist_free);
7470 * gtk_widget_get_no_show_all:
7471 * @widget: a #GtkWidget
7473 * Returns the current value of the "no_show_all" property, which determines
7474 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7475 * will affect this widget.
7477 * Return value: the current value of the "no_show_all" property.
7482 gtk_widget_get_no_show_all (GtkWidget *widget)
7484 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7486 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7490 * gtk_widget_set_no_show_all:
7491 * @widget: a #GtkWidget
7492 * @no_show_all: the new value for the "no_show_all" property
7494 * Sets the "no_show_all" property, which determines whether calls to
7495 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7497 * This is mostly for use in constructing widget hierarchies with externally
7498 * controlled visibility, see #GtkUIManager.
7503 gtk_widget_set_no_show_all (GtkWidget *widget,
7504 gboolean no_show_all)
7506 g_return_if_fail (GTK_IS_WIDGET (widget));
7508 no_show_all = (no_show_all != FALSE);
7510 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7514 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7516 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7518 g_object_notify (G_OBJECT (widget), "no_show_all");