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/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup.h"
42 #include "gtkwidget.h"
43 #include "gtkwindow.h"
44 #include "gtkbindings.h"
45 #include "gtkprivate.h"
47 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
48 #include <gobject/gvaluecollector.h>
49 #include <gobject/gobjectnotifyqueue.c>
50 #include "gdk/gdkkeysyms.h"
52 #include "gtkaccessible.h"
53 #include "gtktooltips.h"
54 #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,
634 * GtkWidget::style-set:
635 * @widget: the object on which the signal is emitted
636 * @previous_style: the previous style, or %NULL if the widget
637 * just got its initial style
639 * The style-set signal is emitted when a new style has been set
640 * on a widget. Note that style-modifying functions like
641 * gtk_widget_modify_base() also cause this signal to be emitted.
643 widget_signals[STYLE_SET] =
644 g_signal_new ("style_set",
645 G_TYPE_FROM_CLASS (gobject_class),
647 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
649 _gtk_marshal_VOID__OBJECT,
652 widget_signals[DIRECTION_CHANGED] =
653 g_signal_new ("direction_changed",
654 G_TYPE_FROM_CLASS (gobject_class),
656 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
658 _gtk_marshal_VOID__ENUM,
660 GTK_TYPE_TEXT_DIRECTION);
661 widget_signals[GRAB_NOTIFY] =
662 g_signal_new ("grab_notify",
663 G_TYPE_FROM_CLASS (gobject_class),
665 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
667 _gtk_marshal_VOID__BOOLEAN,
672 * GtkWidget::child-notify:
673 * @widget: the object which received the signal.
674 * @pspec: the #GParamSpec of the changed child property.
676 * The ::child-notify signal is emitted for each child property that has
677 * changed on an object. The signal's detail holds the property name.
679 widget_signals[CHILD_NOTIFY] =
680 g_signal_new ("child_notify",
681 G_TYPE_FROM_CLASS (gobject_class),
682 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
683 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
685 g_cclosure_marshal_VOID__PARAM,
688 widget_signals[MNEMONIC_ACTIVATE] =
689 g_signal_new ("mnemonic_activate",
690 G_TYPE_FROM_CLASS (gobject_class),
692 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
693 _gtk_boolean_handled_accumulator, NULL,
694 _gtk_marshal_BOOLEAN__BOOLEAN,
697 widget_signals[GRAB_FOCUS] =
698 g_signal_new ("grab_focus",
699 G_TYPE_FROM_CLASS (gobject_class),
700 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
701 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
703 _gtk_marshal_VOID__VOID,
705 widget_signals[FOCUS] =
706 g_signal_new ("focus",
707 G_TYPE_FROM_CLASS (object_class),
709 G_STRUCT_OFFSET (GtkWidgetClass, focus),
710 _gtk_boolean_handled_accumulator, NULL,
711 _gtk_marshal_BOOLEAN__ENUM,
713 GTK_TYPE_DIRECTION_TYPE);
714 widget_signals[EVENT] =
715 g_signal_new ("event",
716 G_TYPE_FROM_CLASS (gobject_class),
718 G_STRUCT_OFFSET (GtkWidgetClass, event),
719 _gtk_boolean_handled_accumulator, NULL,
720 _gtk_marshal_BOOLEAN__BOXED,
722 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
723 widget_signals[EVENT_AFTER] =
724 g_signal_new ("event-after",
725 G_TYPE_FROM_CLASS (gobject_class),
729 _gtk_marshal_VOID__BOXED,
731 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
732 widget_signals[BUTTON_PRESS_EVENT] =
733 g_signal_new ("button_press_event",
734 G_TYPE_FROM_CLASS (gobject_class),
736 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
737 _gtk_boolean_handled_accumulator, NULL,
738 _gtk_marshal_BOOLEAN__BOXED,
740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
741 widget_signals[BUTTON_RELEASE_EVENT] =
742 g_signal_new ("button_release_event",
743 G_TYPE_FROM_CLASS (gobject_class),
745 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
746 _gtk_boolean_handled_accumulator, NULL,
747 _gtk_marshal_BOOLEAN__BOXED,
749 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
750 widget_signals[SCROLL_EVENT] =
751 g_signal_new ("scroll_event",
752 G_TYPE_FROM_CLASS (gobject_class),
754 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
755 _gtk_boolean_handled_accumulator, NULL,
756 _gtk_marshal_BOOLEAN__BOXED,
758 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
759 widget_signals[MOTION_NOTIFY_EVENT] =
760 g_signal_new ("motion_notify_event",
761 G_TYPE_FROM_CLASS (gobject_class),
763 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
764 _gtk_boolean_handled_accumulator, NULL,
765 _gtk_marshal_BOOLEAN__BOXED,
767 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
770 * GtkWidget::delete-event:
771 * @widget: the object which received the signal.
772 * @event: the event which triggered this signal
774 * The ::delete-event signal is emitted if a user requests that
775 * a toplevel window is closed. The default handler for this signal
776 * destroys the window. Connecting gtk_widget_hide_on_delete() to
777 * this signal will cause the window to be hidden instead, so that
778 * it can later be shown again without reconstructing it.
780 * Returns: %TRUE to stop other handlers from being invoked for the event.
781 * %FALSE to propagate the event further.
783 widget_signals[DELETE_EVENT] =
784 g_signal_new ("delete_event",
785 G_TYPE_FROM_CLASS (gobject_class),
787 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
788 _gtk_boolean_handled_accumulator, NULL,
789 _gtk_marshal_BOOLEAN__BOXED,
791 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
794 * GtkWidget::destroy-event:
795 * @widget: the object which received the signal.
796 * @event: the event which triggered this signal
798 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
799 * You rarely get this signal, because most widgets disconnect themselves
800 * from their window before they destroy it, so no widget owns the
801 * window at destroy time.
803 * Returns: %TRUE to stop other handlers from being invoked for the event.
804 * %FALSE to propagate the event further.
806 widget_signals[DESTROY_EVENT] =
807 g_signal_new ("destroy_event",
808 G_TYPE_FROM_CLASS (gobject_class),
810 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
811 _gtk_boolean_handled_accumulator, NULL,
812 _gtk_marshal_BOOLEAN__BOXED,
814 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
815 widget_signals[EXPOSE_EVENT] =
816 g_signal_new ("expose_event",
817 G_TYPE_FROM_CLASS (gobject_class),
819 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
820 _gtk_boolean_handled_accumulator, NULL,
821 _gtk_marshal_BOOLEAN__BOXED,
823 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
824 widget_signals[KEY_PRESS_EVENT] =
825 g_signal_new ("key_press_event",
826 G_TYPE_FROM_CLASS (gobject_class),
828 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
829 _gtk_boolean_handled_accumulator, NULL,
830 _gtk_marshal_BOOLEAN__BOXED,
832 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
833 widget_signals[KEY_RELEASE_EVENT] =
834 g_signal_new ("key_release_event",
835 G_TYPE_FROM_CLASS (gobject_class),
837 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
838 _gtk_boolean_handled_accumulator, NULL,
839 _gtk_marshal_BOOLEAN__BOXED,
841 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
842 widget_signals[ENTER_NOTIFY_EVENT] =
843 g_signal_new ("enter_notify_event",
844 G_TYPE_FROM_CLASS (gobject_class),
846 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
847 _gtk_boolean_handled_accumulator, NULL,
848 _gtk_marshal_BOOLEAN__BOXED,
850 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
851 widget_signals[LEAVE_NOTIFY_EVENT] =
852 g_signal_new ("leave_notify_event",
853 G_TYPE_FROM_CLASS (gobject_class),
855 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
856 _gtk_boolean_handled_accumulator, NULL,
857 _gtk_marshal_BOOLEAN__BOXED,
859 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
860 widget_signals[CONFIGURE_EVENT] =
861 g_signal_new ("configure_event",
862 G_TYPE_FROM_CLASS (gobject_class),
864 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
865 _gtk_boolean_handled_accumulator, NULL,
866 _gtk_marshal_BOOLEAN__BOXED,
868 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
869 widget_signals[FOCUS_IN_EVENT] =
870 g_signal_new ("focus_in_event",
871 G_TYPE_FROM_CLASS (gobject_class),
873 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
874 _gtk_boolean_handled_accumulator, NULL,
875 _gtk_marshal_BOOLEAN__BOXED,
877 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
878 widget_signals[FOCUS_OUT_EVENT] =
879 g_signal_new ("focus_out_event",
880 G_TYPE_FROM_CLASS (gobject_class),
882 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
883 _gtk_boolean_handled_accumulator, NULL,
884 _gtk_marshal_BOOLEAN__BOXED,
886 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
887 widget_signals[MAP_EVENT] =
888 g_signal_new ("map_event",
889 G_TYPE_FROM_CLASS (gobject_class),
891 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
892 _gtk_boolean_handled_accumulator, NULL,
893 _gtk_marshal_BOOLEAN__BOXED,
895 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
896 widget_signals[UNMAP_EVENT] =
897 g_signal_new ("unmap_event",
898 G_TYPE_FROM_CLASS (gobject_class),
900 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
901 _gtk_boolean_handled_accumulator, NULL,
902 _gtk_marshal_BOOLEAN__BOXED,
904 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
905 widget_signals[PROPERTY_NOTIFY_EVENT] =
906 g_signal_new ("property_notify_event",
907 G_TYPE_FROM_CLASS (gobject_class),
909 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
910 _gtk_boolean_handled_accumulator, NULL,
911 _gtk_marshal_BOOLEAN__BOXED,
913 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
914 widget_signals[SELECTION_CLEAR_EVENT] =
915 g_signal_new ("selection_clear_event",
916 G_TYPE_FROM_CLASS (gobject_class),
918 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
919 _gtk_boolean_handled_accumulator, NULL,
920 _gtk_marshal_BOOLEAN__BOXED,
922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
923 widget_signals[SELECTION_REQUEST_EVENT] =
924 g_signal_new ("selection_request_event",
925 G_TYPE_FROM_CLASS (gobject_class),
927 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
928 _gtk_boolean_handled_accumulator, NULL,
929 _gtk_marshal_BOOLEAN__BOXED,
931 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
932 widget_signals[SELECTION_NOTIFY_EVENT] =
933 g_signal_new ("selection_notify_event",
934 G_TYPE_FROM_CLASS (gobject_class),
936 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
937 _gtk_boolean_handled_accumulator, NULL,
938 _gtk_marshal_BOOLEAN__BOXED,
940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
941 widget_signals[SELECTION_RECEIVED] =
942 g_signal_new ("selection_received",
943 G_TYPE_FROM_CLASS (gobject_class),
945 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
947 _gtk_marshal_VOID__BOXED_UINT,
949 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
951 widget_signals[SELECTION_GET] =
952 g_signal_new ("selection_get",
953 G_TYPE_FROM_CLASS (gobject_class),
955 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
957 _gtk_marshal_VOID__BOXED_UINT_UINT,
959 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
962 widget_signals[PROXIMITY_IN_EVENT] =
963 g_signal_new ("proximity_in_event",
964 G_TYPE_FROM_CLASS (gobject_class),
966 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
967 _gtk_boolean_handled_accumulator, NULL,
968 _gtk_marshal_BOOLEAN__BOXED,
970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
971 widget_signals[PROXIMITY_OUT_EVENT] =
972 g_signal_new ("proximity_out_event",
973 G_TYPE_FROM_CLASS (gobject_class),
975 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
976 _gtk_boolean_handled_accumulator, NULL,
977 _gtk_marshal_BOOLEAN__BOXED,
979 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
982 * GtkWidget::drag-leave:
983 * @widget: the object which received the signal.
984 * @drag_context: the drag context
985 * @time: the timestamp of the motion event
987 * The ::drag-leave signal is emitted on the drop site when the cursor leaves the widget.
988 * A typical reason to connect to this signal is to undo things done in ::drag-motion, e.g.
989 * undo highlighting with gtk_drag_unhighlight()
991 widget_signals[DRAG_LEAVE] =
992 g_signal_new ("drag_leave",
993 G_TYPE_FROM_CLASS (gobject_class),
995 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
997 _gtk_marshal_VOID__OBJECT_UINT,
999 GDK_TYPE_DRAG_CONTEXT,
1003 * GtkWidget::drag-begin:
1004 * @widget: the object which received the signal.
1005 * @drag_context: the drag context
1007 * The ::drag-begin signal is emitted on the drag source when a drag is started.
1008 * A typical reason to connect to this signal is to set up a custom drag icon with
1009 * gtk_drag_source_set_icon().
1011 widget_signals[DRAG_BEGIN] =
1012 g_signal_new ("drag_begin",
1013 G_TYPE_FROM_CLASS (gobject_class),
1015 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
1017 _gtk_marshal_VOID__OBJECT,
1019 GDK_TYPE_DRAG_CONTEXT);
1022 * GtkWidget::drag-end:
1023 * @widget: the object which received the signal.
1024 * @drag_context: the drag context
1026 * The ::drag-end signal is emitted on the drag source when a drag is finished.
1027 * A typical reason to connect to this signal is to undo things done in ::drag-begin.
1029 widget_signals[DRAG_END] =
1030 g_signal_new ("drag_end",
1031 G_TYPE_FROM_CLASS (gobject_class),
1033 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
1035 _gtk_marshal_VOID__OBJECT,
1037 GDK_TYPE_DRAG_CONTEXT);
1040 * GtkWidget::drag-data-delete:
1041 * @widget: the object which received the signal.
1042 * @drag_context: the drag context
1044 * The ::drag-data-delete signal is emitted on the drag source when a drag with the action
1045 * %GDK_ACTION_MOVE is successfully completed. The signal handler is responsible for deleting
1046 * the data that has been dropped. What "delete" means, depends on the context of the drag
1049 widget_signals[DRAG_DATA_DELETE] =
1050 g_signal_new ("drag_data_delete",
1051 G_TYPE_FROM_CLASS (gobject_class),
1053 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
1055 _gtk_marshal_VOID__OBJECT,
1057 GDK_TYPE_DRAG_CONTEXT);
1060 * GtkWidget::drag-motion:
1061 * @widget: the object which received the signal.
1062 * @drag_context: the drag context
1063 * @x: the x coordinate of the current cursor position
1064 * @y: the y coordinate of the current cursor position
1065 * @time: the timestamp of the motion event
1066 * @returns: whether the cursor position is in a drop zone
1068 * The ::drag-motion signal is emitted on the drop site when the user moves the cursor over
1069 * the widget during a drag. The signal handler must determine whether the cursor position is in
1070 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further processing is
1071 * necessary. Otherwise, the handler returns %TRUE. In this case, the handler is responsible for
1072 * providing the necessary information for displaying feedback to the user, by calling
1073 * gdk_drag_status(). If the decision whether the drop will be accepted or rejected can't be made
1074 * based solely on the cursor position and the type of the data, the handler may inspect the dragged
1075 * data by calling gtk_drag_get_data() and defer the gdk_drag_status() call to the ::drag-data-received
1078 * Note that there is no ::drag-enter signal. The drag receiver has to keep track of whether
1079 * he has received any ::drag-motion signals since the last ::drag-leave and if not, treat the
1080 * ::drag-motion signal as an "enter" signal. Upon an "enter", the handler will typically highlight
1081 * the drop site with gtk_drag_highlight().
1083 * <informalexample><programlisting>
1085 * drag_motion (GtkWidget *widget,
1086 * GdkDragContext *context,
1093 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1095 * if (!private_data->drag_highlight)
1097 * private_data->drag_highlight = 1;
1098 * gtk_drag_highlight (widget);
1101 * target = gtk_drag_dest_find_target (widget, context, NULL);
1102 * if (target == GDK_NONE)
1103 * gdk_drag_status (context, 0, time);
1106 * private_data->pending_status = context->suggested_action;
1107 * gtk_drag_get_data (widget, context, target, time);
1114 * drag_data_received (GtkWidget *widget,
1115 * GdkDragContext *context,
1118 * GtkSelectionData *selection_data,
1122 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
1124 * if (private_data->suggested_action)
1126 * private_data->suggested_action = 0;
1128 * /<!-- -->* We are getting this data due to a request in drag_motion,
1129 * * rather than due to a request in drag_drop, so we are just
1130 * * supposed to call gdk_drag_status(<!-- -->), not actually paste in the data.
1132 * str = gtk_selection_data_get_text (selection_data);
1133 * if (!data_is_acceptable (str))
1134 * gdk_drag_status (context, 0, time);
1136 * gdk_drag_status (context, private_data->suggested_action, time);
1140 * /<!-- -->* accept the drop *<!-- -->/
1143 * </programlisting></informalexample>
1145 widget_signals[DRAG_MOTION] =
1146 g_signal_new ("drag_motion",
1147 G_TYPE_FROM_CLASS (gobject_class),
1149 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
1150 _gtk_boolean_handled_accumulator, NULL,
1151 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1153 GDK_TYPE_DRAG_CONTEXT,
1159 * GtkWidget::drag-drop:
1160 * @widget: the object which received the signal.
1161 * @drag_context: the drag context
1162 * @x: the x coordinate of the current cursor position
1163 * @y: the y coordinate of the current cursor position
1164 * @time: the timestamp of the motion event
1165 * @returns: whether the cursor position is in a drop zone
1167 * The ::drag-drop signal is emitted on the drop site when the user drops the data
1168 * onto the widget. The signal handler must determine whether the cursor position is in
1169 * a drop zone or not. If it is not in a drop zone, it returns %FALSE and no further
1170 * processing is necessary. Otherwise, the handler returns %TRUE. In this case, the handler
1171 * must ensure that gtk_drag_finish() is called to let the source know that the drop is done.
1172 * The call to gtk_drag_finish() can be done either directly or in a ::drag-data-received handler
1173 * which gets triggered by calling gtk_drop_get_data() to receive the data for one or more of the
1174 * supported targets.
1176 widget_signals[DRAG_DROP] =
1177 g_signal_new ("drag_drop",
1178 G_TYPE_FROM_CLASS (gobject_class),
1180 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
1181 _gtk_boolean_handled_accumulator, NULL,
1182 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
1184 GDK_TYPE_DRAG_CONTEXT,
1190 * GtkWidget::drag-data-get:
1191 * @widget: the object which received the signal.
1192 * @drag_context: the drag context
1193 * @data: the #GtkSelectionData to be filled with the dragged data
1194 * @info: the info that has been registered with the target in the #GtkTargetList.
1195 * @time: the timestamp at which the data was requested
1197 * The ::drag-data-get signal is emitted on the drag source when the drop site requests
1198 * the data which is dragged. It is the responsibility of the signal handler to fill @data
1199 * with the data in the format which is indicated by @info. See gtk_selection_data_set() and
1200 * gtk_selection_data_set_text().
1202 widget_signals[DRAG_DATA_GET] =
1203 g_signal_new ("drag_data_get",
1204 G_TYPE_FROM_CLASS (gobject_class),
1206 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
1208 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
1210 GDK_TYPE_DRAG_CONTEXT,
1211 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1216 * GtkWidget::drag-data-received:
1217 * @widget: the object which received the signal.
1218 * @drag_context: the drag context
1219 * @x: where the drop happened
1220 * @y: where the drop happened
1221 * @data: the received data
1222 * @info: the info that has been registered with the target in the #GtkTargetList.
1223 * @time: the timestamp at which the data was received
1225 * The ::drag-data-received signal is emitted on the drop site when the dragged data has been
1226 * received. If the data was received in order to determine whether the drop will be accepted,
1227 * the handler is expected to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
1228 * If the data was received in response to a ::drag-drop signal (and this is the last target to be
1229 * received), the handler for this signal is expected to process the received data and then call
1230 * gtk_drag_finish(), setting the @success parameter depending on whether the data was processed
1233 * The handler may inspect and modify @drag_context->action before calling gtk_drag_finish(),
1234 * e.g. to implement %GDK_ACTION_ASK as shown in the following example:
1235 * <informalexample><programlisting>
1237 * drag_data_received (GtkWidget *widget,
1238 * GdkDragContext *drag_context,
1241 * GtkSelectionData *data,
1245 * if ((data->length >= 0) && (data->format == 8))
1247 * if (drag_context->action == GDK_ACTION_ASK)
1249 * GtkWidget *dialog;
1252 * dialog = gtk_message_dialog_new (NULL,
1253 * GTK_DIALOG_MODAL |
1254 * GTK_DIALOG_DESTROY_WITH_PARENT,
1256 * GTK_BUTTONS_YES_NO,
1257 * "Move the data ?\n");
1258 * response = gtk_dialog_run (GTK_DIALOG (dialog));
1259 * gtk_widget_destroy (dialog);
1261 * if (response == GTK_RESPONSE_YES)
1262 * drag_context->action = GDK_ACTION_MOVE;
1264 * drag_context->action = GDK_ACTION_COPY;
1267 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
1271 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
1273 * </programlisting></informalexample>
1275 widget_signals[DRAG_DATA_RECEIVED] =
1276 g_signal_new ("drag_data_received",
1277 G_TYPE_FROM_CLASS (gobject_class),
1279 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
1281 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
1283 GDK_TYPE_DRAG_CONTEXT,
1286 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1289 widget_signals[VISIBILITY_NOTIFY_EVENT] =
1290 g_signal_new ("visibility_notify_event",
1291 G_TYPE_FROM_CLASS (gobject_class),
1293 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
1294 _gtk_boolean_handled_accumulator, NULL,
1295 _gtk_marshal_BOOLEAN__BOXED,
1297 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1298 widget_signals[CLIENT_EVENT] =
1299 g_signal_new ("client_event",
1300 G_TYPE_FROM_CLASS (gobject_class),
1302 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
1303 _gtk_boolean_handled_accumulator, NULL,
1304 _gtk_marshal_BOOLEAN__BOXED,
1306 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1307 widget_signals[NO_EXPOSE_EVENT] =
1308 g_signal_new ("no_expose_event",
1309 G_TYPE_FROM_CLASS (gobject_class),
1311 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
1312 _gtk_boolean_handled_accumulator, NULL,
1313 _gtk_marshal_BOOLEAN__BOXED,
1315 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1316 widget_signals[WINDOW_STATE_EVENT] =
1317 g_signal_new ("window_state_event",
1318 G_TYPE_FROM_CLASS (gobject_class),
1320 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
1321 _gtk_boolean_handled_accumulator, NULL,
1322 _gtk_marshal_BOOLEAN__BOXED,
1324 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1326 * GtkWidget::popup-menu
1327 * @widget: the object which received the signal
1328 * @returns: TRUE if a menu was activated
1330 * This signal gets emitted whenever a widget should pop up a context-sensitive
1331 * menu. This usually happens through the standard key binding mechanism; by
1332 * pressing a certain key while a widget is focused, the user can cause the
1333 * widget to pop up a menu. For example, the #GtkEntry widget creates a menu
1334 * with clipboard commands. See <xref linkend="checklist-popup-menu"/> for an
1335 * example of how to use this signal.
1337 widget_signals[POPUP_MENU] =
1338 g_signal_new ("popup_menu",
1339 G_TYPE_FROM_CLASS (gobject_class),
1340 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1341 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
1342 _gtk_boolean_handled_accumulator, NULL,
1343 _gtk_marshal_BOOLEAN__VOID,
1345 widget_signals[SHOW_HELP] =
1346 g_signal_new ("show_help",
1347 G_TYPE_FROM_CLASS (gobject_class),
1348 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1349 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
1350 _gtk_boolean_handled_accumulator, NULL,
1351 _gtk_marshal_BOOLEAN__ENUM,
1353 GTK_TYPE_WIDGET_HELP_TYPE);
1354 widget_signals[ACCEL_CLOSURES_CHANGED] =
1355 g_signal_new ("accel_closures_changed",
1356 G_TYPE_FROM_CLASS (gobject_class),
1360 _gtk_marshal_NONE__NONE,
1362 widget_signals[SCREEN_CHANGED] =
1363 g_signal_new ("screen_changed",
1364 G_TYPE_FROM_CLASS (gobject_class),
1366 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
1368 _gtk_marshal_VOID__OBJECT,
1372 * GtkWidget::can-activate-accel:
1373 * @widget: the object which received the signal
1374 * @signal_id: the ID of a signal installed on @widget
1375 * @returns: %TRUE if the signal can be activated.
1377 * Determines whether an accelerator that activates the signal
1378 * identified by @signal_id can currently be activated.
1379 * This signal is present to allow applications and derived
1380 * widgets to override the default #GtkWidget handling
1381 * for determining whether an accelerator can be activated.
1383 widget_signals[CAN_ACTIVATE_ACCEL] =
1384 g_signal_new ("can_activate_accel",
1385 G_TYPE_FROM_CLASS (gobject_class),
1387 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
1388 _gtk_boolean_handled_accumulator, NULL,
1389 _gtk_marshal_BOOLEAN__UINT,
1390 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
1392 binding_set = gtk_binding_set_by_class (klass);
1393 gtk_binding_entry_add_signal (binding_set, GDK_F10, GDK_SHIFT_MASK,
1395 gtk_binding_entry_add_signal (binding_set, GDK_Menu, 0,
1398 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_CONTROL_MASK,
1400 GTK_TYPE_WIDGET_HELP_TYPE,
1401 GTK_WIDGET_HELP_TOOLTIP);
1402 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_CONTROL_MASK,
1404 GTK_TYPE_WIDGET_HELP_TYPE,
1405 GTK_WIDGET_HELP_TOOLTIP);
1406 gtk_binding_entry_add_signal (binding_set, GDK_F1, GDK_SHIFT_MASK,
1408 GTK_TYPE_WIDGET_HELP_TYPE,
1409 GTK_WIDGET_HELP_WHATS_THIS);
1410 gtk_binding_entry_add_signal (binding_set, GDK_KP_F1, GDK_SHIFT_MASK,
1412 GTK_TYPE_WIDGET_HELP_TYPE,
1413 GTK_WIDGET_HELP_WHATS_THIS);
1415 gtk_widget_class_install_style_property (klass,
1416 g_param_spec_boolean ("interior-focus",
1417 P_("Interior Focus"),
1418 P_("Whether to draw the focus indicator inside widgets"),
1422 gtk_widget_class_install_style_property (klass,
1423 g_param_spec_int ("focus-line-width",
1424 P_("Focus linewidth"),
1425 P_("Width, in pixels, of the focus indicator line"),
1429 gtk_widget_class_install_style_property (klass,
1430 g_param_spec_string ("focus-line-pattern",
1431 P_("Focus line dash pattern"),
1432 P_("Dash pattern used to draw the focus indicator"),
1435 gtk_widget_class_install_style_property (klass,
1436 g_param_spec_int ("focus-padding",
1437 P_("Focus padding"),
1438 P_("Width, in pixels, between focus indicator and the widget 'box'"),
1441 gtk_widget_class_install_style_property (klass,
1442 g_param_spec_boxed ("cursor-color",
1444 P_("Color with which to draw insertion cursor"),
1447 gtk_widget_class_install_style_property (klass,
1448 g_param_spec_boxed ("secondary-cursor-color",
1449 P_("Secondary cursor color"),
1450 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
1453 gtk_widget_class_install_style_property (klass,
1454 g_param_spec_float ("cursor-aspect-ratio",
1455 P_("Cursor line aspect ratio"),
1456 P_("Aspect ratio with which to draw insertion cursor"),
1462 gtk_widget_set_property (GObject *object,
1464 const GValue *value,
1467 GtkWidget *widget = GTK_WIDGET (object);
1471 guint32 saved_flags;
1474 gtk_widget_set_name (widget, g_value_get_string (value));
1477 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
1479 case PROP_WIDTH_REQUEST:
1480 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
1482 case PROP_HEIGHT_REQUEST:
1483 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
1486 if (g_value_get_boolean (value))
1487 gtk_widget_show (widget);
1489 gtk_widget_hide (widget);
1491 case PROP_SENSITIVE:
1492 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
1494 case PROP_APP_PAINTABLE:
1495 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
1497 case PROP_CAN_FOCUS:
1498 saved_flags = GTK_WIDGET_FLAGS (widget);
1499 if (g_value_get_boolean (value))
1500 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
1502 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_FOCUS);
1503 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1504 gtk_widget_queue_resize (widget);
1506 case PROP_HAS_FOCUS:
1507 if (g_value_get_boolean (value))
1508 gtk_widget_grab_focus (widget);
1511 if (g_value_get_boolean (value))
1512 gtk_widget_grab_focus (widget);
1514 case PROP_CAN_DEFAULT:
1515 saved_flags = GTK_WIDGET_FLAGS (widget);
1516 if (g_value_get_boolean (value))
1517 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
1519 GTK_WIDGET_UNSET_FLAGS (widget, GTK_CAN_DEFAULT);
1520 if (saved_flags != GTK_WIDGET_FLAGS (widget))
1521 gtk_widget_queue_resize (widget);
1523 case PROP_HAS_DEFAULT:
1524 if (g_value_get_boolean (value))
1525 gtk_widget_grab_default (widget);
1527 case PROP_RECEIVES_DEFAULT:
1528 if (g_value_get_boolean (value))
1529 GTK_WIDGET_SET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1531 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RECEIVES_DEFAULT);
1534 gtk_widget_set_style (widget, g_value_get_object (value));
1537 if (!GTK_WIDGET_REALIZED (widget) && !GTK_WIDGET_NO_WINDOW (widget))
1538 gtk_widget_set_events (widget, g_value_get_flags (value));
1540 case PROP_EXTENSION_EVENTS:
1541 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
1543 case PROP_NO_SHOW_ALL:
1544 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
1552 gtk_widget_get_property (GObject *object,
1557 GtkWidget *widget = GTK_WIDGET (object);
1562 GdkExtensionMode *modep;
1566 g_value_set_string (value, widget->name);
1568 g_value_set_string (value, "");
1572 g_value_set_object (value, widget->parent);
1574 g_value_set_object (value, NULL);
1576 case PROP_WIDTH_REQUEST:
1579 gtk_widget_get_size_request (widget, &w, NULL);
1580 g_value_set_int (value, w);
1583 case PROP_HEIGHT_REQUEST:
1586 gtk_widget_get_size_request (widget, NULL, &h);
1587 g_value_set_int (value, h);
1591 g_value_set_boolean (value, (GTK_WIDGET_VISIBLE (widget) != FALSE));
1593 case PROP_SENSITIVE:
1594 g_value_set_boolean (value, (GTK_WIDGET_SENSITIVE (widget) != FALSE));
1596 case PROP_APP_PAINTABLE:
1597 g_value_set_boolean (value, (GTK_WIDGET_APP_PAINTABLE (widget) != FALSE));
1599 case PROP_CAN_FOCUS:
1600 g_value_set_boolean (value, (GTK_WIDGET_CAN_FOCUS (widget) != FALSE));
1602 case PROP_HAS_FOCUS:
1603 g_value_set_boolean (value, (GTK_WIDGET_HAS_FOCUS (widget) != FALSE));
1606 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
1608 case PROP_CAN_DEFAULT:
1609 g_value_set_boolean (value, (GTK_WIDGET_CAN_DEFAULT (widget) != FALSE));
1611 case PROP_HAS_DEFAULT:
1612 g_value_set_boolean (value, (GTK_WIDGET_HAS_DEFAULT (widget) != FALSE));
1614 case PROP_RECEIVES_DEFAULT:
1615 g_value_set_boolean (value, (GTK_WIDGET_RECEIVES_DEFAULT (widget) != FALSE));
1617 case PROP_COMPOSITE_CHILD:
1618 g_value_set_boolean (value, (GTK_WIDGET_COMPOSITE_CHILD (widget) != FALSE));
1621 g_value_set_object (value, gtk_widget_get_style (widget));
1624 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
1626 g_value_set_flags (value, 0);
1628 g_value_set_flags (value, *eventp);
1630 case PROP_EXTENSION_EVENTS:
1631 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
1633 g_value_set_enum (value, 0);
1635 g_value_set_enum (value, (GdkExtensionMode) *modep);
1637 case PROP_NO_SHOW_ALL:
1638 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
1641 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1647 gtk_widget_init (GtkWidget *widget)
1649 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
1650 widget->state = GTK_STATE_NORMAL;
1651 widget->saved_state = GTK_STATE_NORMAL;
1652 widget->name = NULL;
1653 widget->requisition.width = 0;
1654 widget->requisition.height = 0;
1655 widget->allocation.x = -1;
1656 widget->allocation.y = -1;
1657 widget->allocation.width = 1;
1658 widget->allocation.height = 1;
1659 widget->window = NULL;
1660 widget->parent = NULL;
1662 GTK_WIDGET_SET_FLAGS (widget,
1664 GTK_PARENT_SENSITIVE |
1665 (composite_child_stack ? GTK_COMPOSITE_CHILD : 0) |
1666 GTK_DOUBLE_BUFFERED);
1668 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
1669 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1670 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1672 widget->style = gtk_widget_get_default_style ();
1673 g_object_ref (widget->style);
1678 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
1680 GParamSpec **pspecs)
1682 GtkWidget *container = widget->parent;
1685 for (i = 0; widget->parent == container && i < n_pspecs; i++)
1686 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
1690 * gtk_widget_freeze_child_notify:
1691 * @widget: a #GtkWidget
1693 * Stops emission of "child-notify" signals on @widget. The signals are
1694 * queued until gtk_widget_thaw_child_notify() is called on @widget.
1696 * This is the analogue of g_object_freeze_notify() for child properties.
1699 gtk_widget_freeze_child_notify (GtkWidget *widget)
1701 g_return_if_fail (GTK_IS_WIDGET (widget));
1703 if (!G_OBJECT (widget)->ref_count)
1706 g_object_ref (widget);
1707 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1708 g_object_unref (widget);
1712 * gtk_widget_child_notify:
1713 * @widget: a #GtkWidget
1714 * @child_property: the name of a child property installed on the
1715 * class of @widget<!-- -->'s parent.
1717 * Emits a "child-notify" signal for the
1718 * <link linkend="child-properties">child property</link> @child_property
1721 * This is the analogue of g_object_notify() for child properties.
1724 gtk_widget_child_notify (GtkWidget *widget,
1725 const gchar *child_property)
1729 g_return_if_fail (GTK_IS_WIDGET (widget));
1730 g_return_if_fail (child_property != NULL);
1731 if (!G_OBJECT (widget)->ref_count || !widget->parent)
1734 g_object_ref (widget);
1735 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1737 G_OBJECT_TYPE (widget->parent),
1740 g_warning ("%s: container class `%s' has no child property named `%s'",
1742 G_OBJECT_TYPE_NAME (widget->parent),
1746 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1748 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
1749 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1751 g_object_unref (widget);
1755 * gtk_widget_thaw_child_notify:
1756 * @widget: a #GtkWidget
1758 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
1759 * This causes all queued "child-notify" signals on @widget to be emitted.
1762 gtk_widget_thaw_child_notify (GtkWidget *widget)
1764 GObjectNotifyQueue *nqueue;
1766 g_return_if_fail (GTK_IS_WIDGET (widget));
1768 if (!G_OBJECT (widget)->ref_count)
1771 g_object_ref (widget);
1772 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1773 if (!nqueue || !nqueue->freeze_count)
1774 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
1775 G_OBJECT_TYPE_NAME (widget), widget);
1777 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1778 g_object_unref (widget);
1784 * @type: type ID of the widget to create
1785 * @first_property_name: name of first property to set
1786 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1788 * This is a convenience function for creating a widget and setting
1789 * its properties in one go. For example you might write:
1790 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
1791 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
1792 * g_object_new(), but returns a widget so you don't have to
1793 * cast the object yourself.
1795 * Return value: a new #GtkWidget of type @widget_type
1798 gtk_widget_new (GType type,
1799 const gchar *first_property_name,
1805 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
1807 va_start (var_args, first_property_name);
1808 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
1816 * @widget: a #GtkWidget
1817 * @first_property_name: name of first property to set
1818 * @Varargs: value of first property, followed by more properties, %NULL-terminated
1820 * Like g_object_set() - there's no reason to use this instead of
1824 gtk_widget_set (GtkWidget *widget,
1825 const gchar *first_property_name,
1830 g_return_if_fail (GTK_IS_WIDGET (widget));
1832 va_start (var_args, first_property_name);
1833 g_object_set_valist (G_OBJECT (widget), first_property_name, var_args);
1838 gtk_widget_queue_draw_child (GtkWidget *widget)
1842 parent = widget->parent;
1843 if (parent && GTK_WIDGET_DRAWABLE (parent))
1844 gtk_widget_queue_draw_area (parent,
1845 widget->allocation.x,
1846 widget->allocation.y,
1847 widget->allocation.width,
1848 widget->allocation.height);
1852 * gtk_widget_unparent:
1853 * @widget: a #GtkWidget
1855 * This function is only for use in widget implementations.
1856 * Should be called by implementations of the remove method
1857 * on #GtkContainer, to dissociate a child from the container.
1860 gtk_widget_unparent (GtkWidget *widget)
1862 GObjectNotifyQueue *nqueue;
1863 GtkWidget *toplevel;
1864 GtkWidget *old_parent;
1866 g_return_if_fail (GTK_IS_WIDGET (widget));
1867 if (widget->parent == NULL)
1870 /* keep this function in sync with gtk_menu_detach()
1873 g_object_freeze_notify (G_OBJECT (widget));
1874 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
1876 toplevel = gtk_widget_get_toplevel (widget);
1877 if (GTK_WIDGET_TOPLEVEL (toplevel))
1878 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
1880 if (GTK_CONTAINER (widget->parent)->focus_child == widget)
1881 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), NULL);
1883 /* If we are unanchoring the child, we save around the toplevel
1884 * to emit hierarchy changed
1886 if (GTK_WIDGET_ANCHORED (widget->parent))
1887 g_object_ref (toplevel);
1891 gtk_widget_queue_draw_child (widget);
1893 /* Reset the width and height here, to force reallocation if we
1894 * get added back to a new parent. This won't work if our new
1895 * allocation is smaller than 1x1 and we actually want a size of 1x1...
1896 * (would 0x0 be OK here?)
1898 widget->allocation.width = 1;
1899 widget->allocation.height = 1;
1901 if (GTK_WIDGET_REALIZED (widget))
1903 if (GTK_WIDGET_IN_REPARENT (widget))
1906 g_print ("unmapping!\n");
1907 gtk_widget_unmap (widget);
1911 gtk_widget_unrealize (widget);
1914 /* Removing a widget from a container restores the child visible
1915 * flag to the default state, so it doesn't affect the child
1916 * in the next parent.
1918 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
1920 old_parent = widget->parent;
1921 widget->parent = NULL;
1922 gtk_widget_set_parent_window (widget, NULL);
1923 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
1926 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
1927 g_object_unref (toplevel);
1930 g_object_notify (G_OBJECT (widget), "parent");
1931 g_object_thaw_notify (G_OBJECT (widget));
1932 if (!widget->parent)
1933 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
1934 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
1935 g_object_unref (widget);
1939 * gtk_widget_destroy:
1940 * @widget: a #GtkWidget
1942 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
1943 * you don't have to cast the widget to #GtkObject. When a widget is
1944 * destroyed, it will break any references it holds to other objects.
1945 * If the widget is inside a container, the widget will be removed
1946 * from the container. If the widget is a toplevel (derived from
1947 * #GtkWindow), it will be removed from the list of toplevels, and the
1948 * reference GTK+ holds to it will be removed. Removing a
1949 * widget from its container or the list of toplevels results in the
1950 * widget being finalized, unless you've added additional references
1951 * to the widget with g_object_ref().
1953 * In most cases, only toplevel widgets (windows) require explicit
1954 * destruction, because when you destroy a toplevel its children will
1955 * be destroyed as well.
1959 gtk_widget_destroy (GtkWidget *widget)
1961 g_return_if_fail (GTK_IS_WIDGET (widget));
1963 gtk_object_destroy ((GtkObject*) widget);
1967 * gtk_widget_destroyed:
1968 * @widget: a #GtkWidget
1969 * @widget_pointer: address of a variable that contains @widget
1971 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
1972 * %NULL. It's intended to be used as a callback connected to the
1973 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
1974 * as a signal handler, and pass the address of your widget variable
1975 * as user data. Then when the widget is destroyed, the variable will
1976 * be set to %NULL. Useful for example to avoid multiple copies
1977 * of the same dialog.
1981 gtk_widget_destroyed (GtkWidget *widget,
1982 GtkWidget **widget_pointer)
1984 /* Don't make any assumptions about the
1986 * Even check widget_pointer.
1989 *widget_pointer = NULL;
1994 * @widget: a #GtkWidget
1996 * Flags a widget to be displayed. Any widget that isn't shown will
1997 * not appear on the screen. If you want to show all the widgets in a
1998 * container, it's easier to call gtk_widget_show_all() on the
1999 * container, instead of individually showing the widgets.
2001 * Remember that you have to show the containers containing a widget,
2002 * in addition to the widget itself, before it will appear onscreen.
2004 * When a toplevel container is shown, it is immediately realized and
2005 * mapped; other shown widgets are realized and mapped when their
2006 * toplevel container is realized and mapped.
2010 gtk_widget_show (GtkWidget *widget)
2012 if (!GTK_WIDGET_VISIBLE (widget))
2014 g_object_ref (widget);
2015 if (!GTK_WIDGET_TOPLEVEL (widget))
2016 gtk_widget_queue_resize (widget);
2017 g_signal_emit (widget, widget_signals[SHOW], 0);
2018 g_object_notify (G_OBJECT (widget), "visible");
2019 g_object_unref (widget);
2024 gtk_widget_real_show (GtkWidget *widget)
2026 if (!GTK_WIDGET_VISIBLE (widget))
2028 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
2030 if (widget->parent &&
2031 GTK_WIDGET_MAPPED (widget->parent) &&
2032 GTK_WIDGET_CHILD_VISIBLE (widget) &&
2033 !GTK_WIDGET_MAPPED (widget))
2034 gtk_widget_map (widget);
2039 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
2042 g_signal_handlers_disconnect_by_func (widget,
2043 gtk_widget_show_map_callback,
2048 * gtk_widget_show_now:
2049 * @widget: a #GtkWidget
2051 * Shows a widget. If the widget is an unmapped toplevel widget
2052 * (i.e. a #GtkWindow that has not yet been shown), enter the main
2053 * loop and wait for the window to actually be mapped. Be careful;
2054 * because the main loop is running, anything can happen during
2058 gtk_widget_show_now (GtkWidget *widget)
2062 g_return_if_fail (GTK_IS_WIDGET (widget));
2064 /* make sure we will get event */
2065 if (!GTK_WIDGET_MAPPED (widget) &&
2066 GTK_WIDGET_TOPLEVEL (widget))
2068 gtk_widget_show (widget);
2070 g_signal_connect (widget, "map_event",
2071 G_CALLBACK (gtk_widget_show_map_callback),
2075 gtk_main_iteration ();
2078 gtk_widget_show (widget);
2083 * @widget: a #GtkWidget
2085 * Reverses the effects of gtk_widget_show(), causing the widget to be
2086 * hidden (invisible to the user).
2089 gtk_widget_hide (GtkWidget *widget)
2091 g_return_if_fail (GTK_IS_WIDGET (widget));
2093 if (GTK_WIDGET_VISIBLE (widget))
2095 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2097 g_object_ref (widget);
2098 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
2099 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
2101 g_signal_emit (widget, widget_signals[HIDE], 0);
2102 if (!GTK_WIDGET_TOPLEVEL (widget))
2103 gtk_widget_queue_resize (widget);
2104 g_object_notify (G_OBJECT (widget), "visible");
2105 g_object_unref (widget);
2110 gtk_widget_real_hide (GtkWidget *widget)
2112 if (GTK_WIDGET_VISIBLE (widget))
2114 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
2116 if (GTK_WIDGET_MAPPED (widget))
2117 gtk_widget_unmap (widget);
2122 * gtk_widget_hide_on_delete:
2123 * @widget: a #GtkWidget
2125 * Utility function; intended to be connected to the "delete_event"
2126 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
2127 * argument, then returns %TRUE. If connected to "delete_event", the
2128 * result is that clicking the close button for a window (on the
2129 * window frame, top right corner usually) will hide but not destroy
2130 * the window. By default, GTK+ destroys windows when "delete_event"
2133 * Return value: %TRUE
2136 gtk_widget_hide_on_delete (GtkWidget *widget)
2138 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
2140 gtk_widget_hide (widget);
2146 * gtk_widget_show_all:
2147 * @widget: a #GtkWidget
2149 * Recursively shows a widget, and any child widgets (if the widget is
2153 gtk_widget_show_all (GtkWidget *widget)
2155 GtkWidgetClass *class;
2157 g_return_if_fail (GTK_IS_WIDGET (widget));
2159 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2162 class = GTK_WIDGET_GET_CLASS (widget);
2164 if (class->show_all)
2165 class->show_all (widget);
2169 * gtk_widget_hide_all:
2170 * @widget: a #GtkWidget
2172 * Recursively hides a widget and any child widgets.
2175 gtk_widget_hide_all (GtkWidget *widget)
2177 GtkWidgetClass *class;
2179 g_return_if_fail (GTK_IS_WIDGET (widget));
2181 if ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0)
2184 class = GTK_WIDGET_GET_CLASS (widget);
2186 if (class->hide_all)
2187 class->hide_all (widget);
2192 * @widget: a #GtkWidget
2194 * This function is only for use in widget implementations. Causes
2195 * a widget to be mapped if it isn't already.
2199 gtk_widget_map (GtkWidget *widget)
2201 g_return_if_fail (GTK_IS_WIDGET (widget));
2202 g_return_if_fail (GTK_WIDGET_VISIBLE (widget));
2203 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
2205 if (!GTK_WIDGET_MAPPED (widget))
2207 if (!GTK_WIDGET_REALIZED (widget))
2208 gtk_widget_realize (widget);
2210 g_signal_emit (widget, widget_signals[MAP], 0);
2212 if (GTK_WIDGET_NO_WINDOW (widget))
2213 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2219 * @widget: a #GtkWidget
2221 * This function is only for use in widget implementations. Causes
2222 * a widget to be unmapped if it's currently mapped.
2226 gtk_widget_unmap (GtkWidget *widget)
2228 g_return_if_fail (GTK_IS_WIDGET (widget));
2230 if (GTK_WIDGET_MAPPED (widget))
2232 if (GTK_WIDGET_NO_WINDOW (widget))
2233 gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
2234 g_signal_emit (widget, widget_signals[UNMAP], 0);
2239 * gtk_widget_realize:
2240 * @widget: a #GtkWidget
2242 * Creates the GDK (windowing system) resources associated with a
2243 * widget. For example, @widget->window will be created when a widget
2244 * is realized. Normally realization happens implicitly; if you show
2245 * a widget and all its parent containers, then the widget will be
2246 * realized and mapped automatically.
2248 * Realizing a widget requires all
2249 * the widget's parent widgets to be realized; calling
2250 * gtk_widget_realize() realizes the widget's parents in addition to
2251 * @widget itself. If a widget is not yet inside a toplevel window
2252 * when you realize it, bad things will happen.
2254 * This function is primarily used in widget implementations, and
2255 * isn't very useful otherwise. Many times when you think you might
2256 * need it, a better approach is to connect to a signal that will be
2257 * called after the widget is realized automatically, such as
2258 * "expose_event". Or simply g_signal_connect_after() to the
2263 gtk_widget_realize (GtkWidget *widget)
2266 GdkExtensionMode mode;
2267 GtkWidgetShapeInfo *shape_info;
2269 g_return_if_fail (GTK_IS_WIDGET (widget));
2270 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
2271 GTK_IS_INVISIBLE (widget));
2273 if (!GTK_WIDGET_REALIZED (widget))
2276 if (GTK_IS_CONTAINER (widget) && !GTK_WIDGET_NO_WINDOW (widget))
2277 g_message ("gtk_widget_realize(%s)", g_type_name (GTK_WIDGET_TYPE (widget)));
2280 if (widget->parent == NULL &&
2281 !GTK_WIDGET_TOPLEVEL (widget))
2282 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
2283 "inside a toplevel window is not going to work very well. "
2284 "Widgets must be inside a toplevel container before realizing them.");
2286 if (widget->parent && !GTK_WIDGET_REALIZED (widget->parent))
2287 gtk_widget_realize (widget->parent);
2289 gtk_widget_ensure_style (widget);
2291 g_signal_emit (widget, widget_signals[REALIZE], 0);
2293 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2295 shape_info = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
2296 gdk_window_shape_combine_mask (widget->window,
2297 shape_info->shape_mask,
2298 shape_info->offset_x,
2299 shape_info->offset_y);
2302 if (!GTK_WIDGET_NO_WINDOW (widget))
2304 mode = gtk_widget_get_extension_events (widget);
2305 if (mode != GDK_EXTENSION_EVENTS_NONE)
2307 events = gtk_widget_get_events (widget);
2308 gdk_input_set_extension_events (widget->window, events, mode);
2316 * gtk_widget_unrealize:
2317 * @widget: a #GtkWidget
2319 * This function is only useful in widget implementations.
2320 * Causes a widget to be unrealized (frees all GDK resources
2321 * associated with the widget, such as @widget->window).
2325 gtk_widget_unrealize (GtkWidget *widget)
2327 g_return_if_fail (GTK_IS_WIDGET (widget));
2329 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
2330 gtk_widget_shape_combine_mask (widget, NULL, -1, -1);
2332 if (GTK_WIDGET_REALIZED (widget))
2334 g_object_ref (widget);
2335 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
2336 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
2337 g_object_unref (widget);
2341 /*****************************************
2343 *****************************************/
2346 * gtk_widget_queue_draw_area:
2347 * @widget: a #GtkWidget
2348 * @x: x coordinate of upper-left corner of rectangle to redraw
2349 * @y: y coordinate of upper-left corner of rectangle to redraw
2350 * @width: width of region to draw
2351 * @height: height of region to draw
2353 * Invalidates the rectangular area of @widget defined by @x, @y,
2354 * @width and @height by calling gdk_window_invalidate_rect() on the
2355 * widget's window and all its child windows. Once the main loop
2356 * becomes idle (after the current batch of events has been processed,
2357 * roughly), the window will receive expose events for the union of
2358 * all regions that have been invalidated.
2360 * Normally you would only use this function in widget
2361 * implementations. You might also use it, or
2362 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
2363 * #GtkDrawingArea or some portion thereof.
2365 * Frequently you can just call gdk_window_invalidate_rect() or
2366 * gdk_window_invalidate_region() instead of this function. Those
2367 * functions will invalidate only a single window, instead of the
2368 * widget and all its children.
2370 * The advantage of adding to the invalidated region compared to
2371 * simply drawing immediately is efficiency; using an invalid region
2372 * ensures that you only have to redraw one time.
2376 gtk_widget_queue_draw_area (GtkWidget *widget,
2382 GdkRectangle invalid_rect;
2385 g_return_if_fail (GTK_IS_WIDGET (widget));
2387 if (!GTK_WIDGET_REALIZED (widget))
2390 /* Just return if the widget or one of its ancestors isn't mapped */
2391 for (w = widget; w != NULL; w = w->parent)
2392 if (!GTK_WIDGET_MAPPED (w))
2395 /* Find the correct widget */
2397 if (!GTK_WIDGET_NO_WINDOW (widget))
2401 /* Translate widget relative to window-relative */
2403 gint wx, wy, wwidth, wheight;
2405 gdk_window_get_position (widget->window, &wx, &wy);
2406 x -= wx - widget->allocation.x;
2407 y -= wy - widget->allocation.y;
2409 gdk_drawable_get_size (widget->window, &wwidth, &wheight);
2411 if (x + width <= 0 || y + height <= 0 ||
2412 x >= wwidth || y >= wheight)
2423 if (x + width > wwidth)
2425 if (y + height > wheight)
2426 height = wheight - y;
2432 invalid_rect.width = width;
2433 invalid_rect.height = height;
2435 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
2439 * gtk_widget_queue_draw:
2440 * @widget: a #GtkWidget
2442 * Equivalent to calling gtk_widget_queue_draw_area() for the
2443 * entire area of a widget.
2447 gtk_widget_queue_draw (GtkWidget *widget)
2449 g_return_if_fail (GTK_IS_WIDGET (widget));
2451 if (widget->allocation.width || widget->allocation.height)
2453 if (GTK_WIDGET_NO_WINDOW (widget))
2454 gtk_widget_queue_draw_area (widget, widget->allocation.x,
2455 widget->allocation.y,
2456 widget->allocation.width,
2457 widget->allocation.height);
2459 gtk_widget_queue_draw_area (widget, 0, 0,
2460 widget->allocation.width,
2461 widget->allocation.height);
2465 /* Invalidates the given area (allocation-relative-coordinates)
2466 * in all of the widget's windows
2469 * gtk_widget_queue_clear_area:
2470 * @widget: a #GtkWidget
2471 * @x: x coordinate of upper-left corner of rectangle to redraw
2472 * @y: y coordinate of upper-left corner of rectangle to redraw
2473 * @width: width of region to draw
2474 * @height: height of region to draw
2476 * This function is no longer different from
2477 * gtk_widget_queue_draw_area(), though it once was. Now it just calls
2478 * gtk_widget_queue_draw_area(). Originally
2479 * gtk_widget_queue_clear_area() would force a redraw of the
2480 * background for %GTK_NO_WINDOW widgets, and
2481 * gtk_widget_queue_draw_area() would not. Now both functions ensure
2482 * the background will be redrawn.
2484 * @Deprecated: Use gtk_widget_queue_draw_area() instead.
2487 gtk_widget_queue_clear_area (GtkWidget *widget,
2493 g_return_if_fail (GTK_IS_WIDGET (widget));
2495 gtk_widget_queue_draw_area (widget, x, y, width, height);
2499 * gtk_widget_queue_clear:
2500 * @widget: a #GtkWidget
2502 * This function does the same as gtk_widget_queue_draw().
2504 * @Deprecated: Use gtk_widget_queue_draw() instead.
2507 gtk_widget_queue_clear (GtkWidget *widget)
2509 g_return_if_fail (GTK_IS_WIDGET (widget));
2511 gtk_widget_queue_draw (widget);
2515 * gtk_widget_queue_resize:
2516 * @widget: a #GtkWidget
2518 * This function is only for use in widget implementations.
2519 * Flags a widget to have its size renegotiated; should
2520 * be called when a widget for some reason has a new size request.
2521 * For example, when you change the text in a #GtkLabel, #GtkLabel
2522 * queues a resize to ensure there's enough space for the new text.
2525 gtk_widget_queue_resize (GtkWidget *widget)
2527 g_return_if_fail (GTK_IS_WIDGET (widget));
2529 if (GTK_WIDGET_REALIZED (widget))
2530 gtk_widget_queue_shallow_draw (widget);
2532 _gtk_size_group_queue_resize (widget);
2536 * gtk_widget_queue_resize_no_redraw:
2537 * @widget: a #GtkWidget
2539 * This function works like gtk_widget_queue_resize(), except that the
2540 * widget is not invalidated.
2545 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
2547 g_return_if_fail (GTK_IS_WIDGET (widget));
2549 _gtk_size_group_queue_resize (widget);
2554 * @widget: a #GtkWidget
2555 * @area: area to draw
2557 * In GTK+ 1.2, this function would immediately render the
2558 * region @area of a widget, by invoking the virtual draw method of a
2559 * widget. In GTK+ 2.0, the draw method is gone, and instead
2560 * gtk_widget_draw() simply invalidates the specified region of the
2561 * widget, then updates the invalid region of the widget immediately.
2562 * Usually you don't want to update the region immediately for
2563 * performance reasons, so in general gtk_widget_queue_draw_area() is
2564 * a better choice if you want to draw a region of a widget.
2568 gtk_widget_draw (GtkWidget *widget,
2571 g_return_if_fail (GTK_IS_WIDGET (widget));
2573 if (GTK_WIDGET_DRAWABLE (widget))
2576 gtk_widget_queue_draw_area (widget,
2578 area->width, area->height);
2580 gtk_widget_queue_draw (widget);
2582 gdk_window_process_updates (widget->window, TRUE);
2587 * gtk_widget_size_request:
2588 * @widget: a #GtkWidget
2589 * @requisition: a #GtkRequisition to be filled in
2591 * This function is typically used when implementing a #GtkContainer
2592 * subclass. Obtains the preferred size of a widget. The container
2593 * uses this information to arrange its child widgets and decide what
2594 * size allocations to give them with gtk_widget_size_allocate().
2596 * You can also call this function from an application, with some
2597 * caveats. Most notably, getting a size request requires the widget
2598 * to be associated with a screen, because font information may be
2599 * needed. Multihead-aware applications should keep this in mind.
2601 * Also remember that the size request is not necessarily the size
2602 * a widget will actually be allocated.
2604 * See also gtk_widget_get_child_requisition().
2607 gtk_widget_size_request (GtkWidget *widget,
2608 GtkRequisition *requisition)
2610 g_return_if_fail (GTK_IS_WIDGET (widget));
2612 #ifdef G_ENABLE_DEBUG
2613 if (requisition == &widget->requisition)
2614 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.");
2615 #endif /* G_ENABLE_DEBUG */
2617 _gtk_size_group_compute_requisition (widget, requisition);
2621 * gtk_widget_get_child_requisition:
2622 * @widget: a #GtkWidget
2623 * @requisition: a #GtkRequisition to be filled in
2625 * This function is only for use in widget implementations. Obtains
2626 * @widget->requisition, unless someone has forced a particular
2627 * geometry on the widget (e.g. with gtk_widget_set_usize()), in which
2628 * case it returns that geometry instead of the widget's requisition.
2630 * This function differs from gtk_widget_size_request() in that
2631 * it retrieves the last size request value from @widget->requisition,
2632 * while gtk_widget_size_request() actually calls the "size_request" method
2633 * on @widget to compute the size request and fill in @widget->requisition,
2634 * and only then returns @widget->requisition.
2636 * Because this function does not call the "size_request" method, it
2637 * can only be used when you know that @widget->requisition is
2638 * up-to-date, that is, gtk_widget_size_request() has been called
2639 * since the last time a resize was queued. In general, only container
2640 * implementations have this information; applications should use
2641 * gtk_widget_size_request().
2644 gtk_widget_get_child_requisition (GtkWidget *widget,
2645 GtkRequisition *requisition)
2647 _gtk_size_group_get_child_requisition (widget, requisition);
2651 invalidate_predicate (GdkWindow *window,
2656 gdk_window_get_user_data (window, &user_data);
2658 return (user_data == data);
2661 /* Invalidate @region in widget->window and all children
2662 * of widget->window owned by widget. @region is in the
2663 * same coordinates as widget->allocation and will be
2664 * modified by this call.
2667 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
2670 if (!GTK_WIDGET_REALIZED (widget))
2673 if (!GTK_WIDGET_NO_WINDOW (widget) && widget->parent)
2677 gdk_window_get_position (widget->window, &x, &y);
2678 gdk_region_offset (region, -x, -y);
2681 gdk_window_invalidate_maybe_recurse (widget->window, region,
2682 invalidate_predicate, widget);
2686 * gtk_widget_queue_shallow_draw:
2687 * @widget: a #GtkWidget
2689 * Like gtk_widget_queue_draw(), but only windows owned
2690 * by @widget are invalidated.
2693 gtk_widget_queue_shallow_draw (GtkWidget *widget)
2697 g_return_if_fail (GTK_IS_WIDGET (widget));
2699 region = gdk_region_rectangle (&widget->allocation);
2700 gtk_widget_invalidate_widget_windows (widget, region);
2701 gdk_region_destroy (region);
2705 * gtk_widget_size_allocate:
2706 * @widget: a #GtkWidget
2707 * @allocation: position and size to be allocated to @widget
2709 * This function is only used by #GtkContainer subclasses, to assign a size
2710 * and position to their child widgets.
2714 gtk_widget_size_allocate (GtkWidget *widget,
2715 GtkAllocation *allocation)
2717 GtkWidgetAuxInfo *aux_info;
2718 GdkRectangle real_allocation;
2719 GdkRectangle old_allocation;
2720 gboolean alloc_needed;
2721 gboolean size_changed;
2722 gboolean position_changed;
2724 g_return_if_fail (GTK_IS_WIDGET (widget));
2726 #ifdef G_ENABLE_DEBUG
2727 if (gtk_debug_flags & GTK_DEBUG_GEOMETRY)
2738 parent = gtk_widget_get_parent (parent);
2741 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
2742 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
2743 2 * depth, " ", name,
2744 allocation->width, allocation->height);
2746 #endif /* G_ENABLE_DEBUG */
2748 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
2749 if (!GTK_WIDGET_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
2750 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
2752 old_allocation = widget->allocation;
2753 real_allocation = *allocation;
2754 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
2758 if (aux_info->x_set)
2759 real_allocation.x = aux_info->x;
2760 if (aux_info->y_set)
2761 real_allocation.y = aux_info->y;
2764 if (real_allocation.width < 0 || real_allocation.height < 0)
2766 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
2767 real_allocation.width,
2768 real_allocation.height);
2771 real_allocation.width = MAX (real_allocation.width, 1);
2772 real_allocation.height = MAX (real_allocation.height, 1);
2774 size_changed = (old_allocation.width != real_allocation.width ||
2775 old_allocation.height != real_allocation.height);
2776 position_changed = (old_allocation.x != real_allocation.x ||
2777 old_allocation.y != real_allocation.y);
2779 if (!alloc_needed && !size_changed && !position_changed)
2782 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
2784 if (GTK_WIDGET_MAPPED (widget))
2786 if (GTK_WIDGET_NO_WINDOW (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
2788 /* Invalidate union(old_allaction,widget->allocation) in widget->window
2790 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2791 gdk_region_union_with_rect (invalidate, &old_allocation);
2793 gdk_window_invalidate_region (widget->window, invalidate, FALSE);
2794 gdk_region_destroy (invalidate);
2799 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
2801 /* Invalidate union(old_allaction,widget->allocation) in widget->window and descendents owned by widget
2803 GdkRegion *invalidate = gdk_region_rectangle (&widget->allocation);
2804 gdk_region_union_with_rect (invalidate, &old_allocation);
2806 gtk_widget_invalidate_widget_windows (widget, invalidate);
2807 gdk_region_destroy (invalidate);
2812 if ((size_changed || position_changed) && widget->parent &&
2813 GTK_WIDGET_REALIZED (widget->parent) && GTK_CONTAINER (widget->parent)->reallocate_redraws)
2815 GdkRegion *invalidate = gdk_region_rectangle (&widget->parent->allocation);
2816 gtk_widget_invalidate_widget_windows (widget->parent, invalidate);
2817 gdk_region_destroy (invalidate);
2822 * gtk_widget_common_ancestor:
2823 * @widget_a: a #GtkWidget
2824 * @widget_b: a #GtkWidget
2826 * Find the common ancestor of @widget_a and @widget_b that
2827 * is closest to the two widgets.
2829 * Return value: the closest common ancestor of @widget_a and
2830 * @widget_b or %NULL if @widget_a and @widget_b do not
2831 * share a common ancestor.
2834 gtk_widget_common_ancestor (GtkWidget *widget_a,
2835 GtkWidget *widget_b)
2837 GtkWidget *parent_a;
2838 GtkWidget *parent_b;
2842 parent_a = widget_a;
2843 while (parent_a->parent)
2845 parent_a = parent_a->parent;
2849 parent_b = widget_b;
2850 while (parent_b->parent)
2852 parent_b = parent_b->parent;
2856 if (parent_a != parent_b)
2859 while (depth_a > depth_b)
2861 widget_a = widget_a->parent;
2865 while (depth_b > depth_a)
2867 widget_b = widget_b->parent;
2871 while (widget_a != widget_b)
2873 widget_a = widget_a->parent;
2874 widget_b = widget_b->parent;
2881 * gtk_widget_translate_coordinates:
2882 * @src_widget: a #GtkWidget
2883 * @dest_widget: a #GtkWidget
2884 * @src_x: X position relative to @src_widget
2885 * @src_y: Y position relative to @src_widget
2886 * @dest_x: location to store X position relative to @dest_widget
2887 * @dest_y: location to store Y position relative to @dest_widget
2889 * Translate coordinates relative to @src_widget's allocation to coordinates
2890 * relative to @dest_widget's allocations. In order to perform this
2891 * operation, both widgets must be realized, and must share a common
2894 * Return value: %FALSE if either widget was not realized, or there
2895 * was no common ancestor. In this case, nothing is stored in
2896 * *@dest_x and *@dest_y. Otherwise %TRUE.
2899 gtk_widget_translate_coordinates (GtkWidget *src_widget,
2900 GtkWidget *dest_widget,
2906 GtkWidget *ancestor;
2909 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
2910 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
2912 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
2913 if (!ancestor || !GTK_WIDGET_REALIZED (src_widget) || !GTK_WIDGET_REALIZED (dest_widget))
2916 /* Translate from allocation relative to window relative */
2917 if (!GTK_WIDGET_NO_WINDOW (src_widget) && src_widget->parent)
2920 gdk_window_get_position (src_widget->window, &wx, &wy);
2922 src_x -= wx - src_widget->allocation.x;
2923 src_y -= wy - src_widget->allocation.y;
2927 src_x += src_widget->allocation.x;
2928 src_y += src_widget->allocation.y;
2931 /* Translate to the common ancestor */
2932 window = src_widget->window;
2933 while (window != ancestor->window)
2937 gdk_window_get_position (window, &dx, &dy);
2942 window = gdk_window_get_parent (window);
2944 if (!window) /* Handle GtkHandleBox */
2949 window = dest_widget->window;
2950 while (window != ancestor->window)
2954 gdk_window_get_position (window, &dx, &dy);
2959 window = gdk_window_get_parent (window);
2961 if (!window) /* Handle GtkHandleBox */
2965 /* Translate from window relative to allocation relative */
2966 if (!GTK_WIDGET_NO_WINDOW (dest_widget) && dest_widget->parent)
2969 gdk_window_get_position (dest_widget->window, &wx, &wy);
2971 src_x += wx - dest_widget->allocation.x;
2972 src_y += wy - dest_widget->allocation.y;
2976 src_x -= dest_widget->allocation.x;
2977 src_y -= dest_widget->allocation.y;
2989 gtk_widget_real_size_allocate (GtkWidget *widget,
2990 GtkAllocation *allocation)
2992 widget->allocation = *allocation;
2994 if (GTK_WIDGET_REALIZED (widget) &&
2995 !GTK_WIDGET_NO_WINDOW (widget))
2997 gdk_window_move_resize (widget->window,
2998 allocation->x, allocation->y,
2999 allocation->width, allocation->height);
3004 gtk_widget_real_can_activate_accel (GtkWidget *widget,
3007 /* widgets must be onscreen for accels to take effect */
3008 return GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_DRAWABLE (widget) && gdk_window_is_viewable (widget->window);
3012 * gtk_widget_can_activate_accel:
3013 * @widget: a #GtkWidget
3014 * @signal_id: the ID of a signal installed on @widget
3016 * Determines whether an accelerator that activates the signal
3017 * identified by @signal_id can currently be activated.
3018 * This is done by emitting the GtkWidget::can-activate-accel
3019 * signal on @widget; if the signal isn't overridden by a
3020 * handler or in a derived widget, then the default check is
3021 * that the widget must be sensitive, and the widget and all
3022 * its ancestors mapped.
3024 * Return value: %TRUE if the accelerator can be activated.
3029 gtk_widget_can_activate_accel (GtkWidget *widget,
3032 gboolean can_activate = FALSE;
3033 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3034 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
3035 return can_activate;
3044 closure_accel_activate (GClosure *closure,
3045 GValue *return_value,
3046 guint n_param_values,
3047 const GValue *param_values,
3048 gpointer invocation_hint,
3049 gpointer marshal_data)
3051 AccelClosure *aclosure = (AccelClosure*) closure;
3052 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
3055 g_signal_emit (closure->data, aclosure->signal_id, 0);
3057 /* whether accelerator was handled */
3058 g_value_set_boolean (return_value, can_activate);
3062 closures_destroy (gpointer data)
3064 GSList *slist, *closures = data;
3066 for (slist = closures; slist; slist = slist->next)
3068 g_closure_invalidate (slist->data);
3069 g_closure_unref (slist->data);
3071 g_slist_free (closures);
3075 widget_new_accel_closure (GtkWidget *widget,
3078 AccelClosure *aclosure;
3079 GClosure *closure = NULL;
3080 GSList *slist, *closures;
3082 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
3083 for (slist = closures; slist; slist = slist->next)
3084 if (!gtk_accel_group_from_accel_closure (slist->data))
3086 /* reuse this closure */
3087 closure = slist->data;
3092 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
3093 closures = g_slist_prepend (closures, g_closure_ref (closure));
3094 g_closure_sink (closure);
3095 g_closure_set_marshal (closure, closure_accel_activate);
3097 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
3099 aclosure = (AccelClosure*) closure;
3100 g_assert (closure->data == widget);
3101 g_assert (closure->marshal == closure_accel_activate);
3102 aclosure->signal_id = signal_id;
3108 * gtk_widget_add_accelerator
3109 * @widget: widget to install an accelerator on
3110 * @accel_signal: widget signal to emit on accelerator activation
3111 * @accel_group: accel group for this widget, added to its toplevel
3112 * @accel_key: GDK keyval of the accelerator
3113 * @accel_mods: modifier key combination of the accelerator
3114 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
3116 * Installs an accelerator for this @widget in @accel_group that causes
3117 * @accel_signal to be emitted if the accelerator is activated.
3118 * The @accel_group needs to be added to the widget's toplevel via
3119 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
3120 * Accelerators added through this function are not user changeable during
3121 * runtime. If you want to support accelerators that can be changed by the
3122 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
3123 * gtk_menu_item_set_accel_path() instead.
3126 gtk_widget_add_accelerator (GtkWidget *widget,
3127 const gchar *accel_signal,
3128 GtkAccelGroup *accel_group,
3130 GdkModifierType accel_mods,
3131 GtkAccelFlags accel_flags)
3136 g_return_if_fail (GTK_IS_WIDGET (widget));
3137 g_return_if_fail (accel_signal != NULL);
3138 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3140 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
3141 if (!query.signal_id ||
3142 !(query.signal_flags & G_SIGNAL_ACTION) ||
3143 query.return_type != G_TYPE_NONE ||
3146 /* hmm, should be elaborate enough */
3147 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
3148 G_OBJECT_TYPE_NAME (widget), accel_signal);
3152 closure = widget_new_accel_closure (widget, query.signal_id);
3154 g_object_ref (widget);
3156 /* install the accelerator. since we don't map this onto an accel_path,
3157 * the accelerator will automatically be locked.
3159 gtk_accel_group_connect (accel_group,
3162 accel_flags | GTK_ACCEL_LOCKED,
3165 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3167 g_object_unref (widget);
3171 * gtk_widget_remove_accelerator:
3172 * @widget: widget to install an accelerator on
3173 * @accel_group: accel group for this widget
3174 * @accel_key: GDK keyval of the accelerator
3175 * @accel_mods: modifier key combination of the accelerator
3176 * @returns: whether an accelerator was installed and could be removed
3178 * Removes an accelerator from @widget, previously installed with
3179 * gtk_widget_add_accelerator().
3182 gtk_widget_remove_accelerator (GtkWidget *widget,
3183 GtkAccelGroup *accel_group,
3185 GdkModifierType accel_mods)
3187 GtkAccelGroupEntry *ag_entry;
3188 GList *slist, *clist;
3191 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3192 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
3194 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
3195 clist = gtk_widget_list_accel_closures (widget);
3196 for (slist = clist; slist; slist = slist->next)
3200 for (i = 0; i < n; i++)
3201 if (slist->data == (gpointer) ag_entry[i].closure)
3203 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
3205 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3207 g_list_free (clist);
3212 g_list_free (clist);
3214 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
3215 accel_key, accel_mods, accel_group,
3216 G_OBJECT_TYPE_NAME (widget), widget);
3222 * gtk_widget_list_accel_closures
3223 * @widget: widget to list accelerator closures for
3224 * @returns: a newly allocated #GList of closures
3226 * Lists the closures used by @widget for accelerator group connections
3227 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
3228 * The closures can be used to monitor accelerator changes on @widget,
3229 * by connecting to the ::accel_changed signal of the #GtkAccelGroup of a
3230 * closure which can be found out with gtk_accel_group_from_accel_closure().
3233 gtk_widget_list_accel_closures (GtkWidget *widget)
3236 GList *clist = NULL;
3238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3240 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
3241 if (gtk_accel_group_from_accel_closure (slist->data))
3242 clist = g_list_prepend (clist, slist->data);
3249 GtkAccelGroup *accel_group;
3254 destroy_accel_path (gpointer data)
3256 AccelPath *apath = data;
3258 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
3260 /* closures_destroy takes care of unrefing the closure */
3261 g_object_unref (apath->accel_group);
3268 * gtk_widget_set_accel_path:
3269 * @widget: a #GtkWidget
3270 * @accel_path: path used to look up the accelerator
3271 * @accel_group: a #GtkAccelGroup.
3273 * Given an accelerator group, @accel_group, and an accelerator path,
3274 * @accel_path, sets up an accelerator in @accel_group so whenever the
3275 * key binding that is defined for @accel_path is pressed, @widget
3276 * will be activated. This removes any accelerators (for any
3277 * accelerator group) installed by previous calls to
3278 * gtk_widget_set_accel_path(). Associating accelerators with
3279 * paths allows them to be modified by the user and the modifications
3280 * to be saved for future use. (See gtk_accel_map_save().)
3282 * This function is a low level function that would most likely
3283 * be used by a menu creation system like #GtkItemFactory. If you
3284 * use #GtkItemFactory, setting up accelerator paths will be done
3287 * Even when you you aren't using #GtkItemFactory, if you only want to
3288 * set up accelerators on menu items gtk_menu_item_set_accel_path()
3289 * provides a somewhat more convenient interface.
3292 gtk_widget_set_accel_path (GtkWidget *widget,
3293 const gchar *accel_path,
3294 GtkAccelGroup *accel_group)
3298 g_return_if_fail (GTK_IS_WIDGET (widget));
3299 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
3303 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
3304 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
3306 gtk_accel_map_add_entry (accel_path, 0, 0);
3307 apath = g_new (AccelPath, 1);
3308 apath->widget = widget;
3309 apath->accel_group = g_object_ref (accel_group);
3310 apath->path_quark = g_quark_from_string (accel_path);
3311 apath->closure = widget_new_accel_closure (apath->widget, GTK_WIDGET_GET_CLASS (apath->widget)->activate_signal);
3316 /* also removes possible old settings */
3317 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
3320 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
3322 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
3326 _gtk_widget_get_accel_path (GtkWidget *widget,
3331 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3333 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
3335 *locked = apath ? apath->accel_group->lock_count > 0 : TRUE;
3336 return apath ? g_quark_to_string (apath->path_quark) : NULL;
3340 gtk_widget_mnemonic_activate (GtkWidget *widget,
3341 gboolean group_cycling)
3345 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3347 group_cycling = group_cycling != FALSE;
3348 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3351 g_signal_emit (widget,
3352 widget_signals[MNEMONIC_ACTIVATE],
3360 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
3361 gboolean group_cycling)
3363 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
3364 gtk_widget_activate (widget);
3365 else if (GTK_WIDGET_CAN_FOCUS (widget))
3366 gtk_widget_grab_focus (widget);
3369 g_warning ("widget `%s' isn't suitable for mnemonic activation",
3370 G_OBJECT_TYPE_NAME (widget));
3371 gdk_display_beep (gtk_widget_get_display (widget));
3377 gtk_widget_real_key_press_event (GtkWidget *widget,
3380 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3384 gtk_widget_real_key_release_event (GtkWidget *widget,
3387 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
3391 gtk_widget_real_focus_in_event (GtkWidget *widget,
3392 GdkEventFocus *event)
3394 gtk_widget_queue_shallow_draw (widget);
3400 gtk_widget_real_focus_out_event (GtkWidget *widget,
3401 GdkEventFocus *event)
3403 gtk_widget_queue_shallow_draw (widget);
3408 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
3409 (event->type == GDK_FOCUS_CHANGE || GTK_WIDGET_REALIZED(widget))
3413 * @widget: a #GtkWidget
3414 * @event: a #GdkEvent
3416 * Rarely-used function. This function is used to emit
3417 * the event signals on a widget (those signals should never
3418 * be emitted without using this function to do so).
3419 * If you want to synthesize an event though, don't use this function;
3420 * instead, use gtk_main_do_event() so the event will behave as if
3421 * it were in the event queue. Don't synthesize expose events; instead,
3422 * use gdk_window_invalidate_rect() to invalidate a region of the
3425 * Return value: return from the event signal emission (%TRUE if the event was handled)
3428 gtk_widget_event (GtkWidget *widget,
3431 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3432 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
3434 if (event->type == GDK_EXPOSE)
3436 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
3437 "the same effect, call gdk_window_invalidate_rect/region(), "
3438 "followed by gdk_window_process_updates().");
3442 return gtk_widget_event_internal (widget, event);
3447 * gtk_widget_send_expose:
3448 * @widget: a #GtkWidget
3449 * @event: a expose #GdkEvent
3451 * Very rarely-used function. This function is used to emit
3452 * an expose event signals on a widget. This function is not
3453 * normally used directly. The only time it is used is when
3454 * propagating an expose event to a child %NO_WINDOW widget, and
3455 * that is normally done using gtk_container_propagate_expose().
3457 * If you want to force an area of a window to be redrawn,
3458 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
3459 * To cause the redraw to be done immediately, follow that call
3460 * with a call to gdk_window_process_updates().
3462 * Return value: return from the event signal emission (%TRUE if the event was handled)
3465 gtk_widget_send_expose (GtkWidget *widget,
3468 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
3469 g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), TRUE);
3470 g_return_val_if_fail (event != NULL, TRUE);
3471 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
3473 if (event->type != GDK_EXPOSE)
3476 return gtk_widget_event_internal (widget, event);
3480 event_window_is_still_viewable (GdkEvent *event)
3482 /* Some programs, such as gnome-theme-manager, fake widgets
3483 * into exposing onto a pixmap by sending expose events with
3484 * event->window pointing to a pixmap
3486 if (GDK_IS_PIXMAP (event->any.window))
3487 return event->type == GDK_EXPOSE;
3489 /* Check that we think the event's window is viewable before
3490 * delivering the event, to prevent suprises. We do this here
3491 * at the last moment, since the event may have been queued
3492 * up behind other events, held over a recursive main loop, etc.
3494 switch (event->type)
3497 case GDK_MOTION_NOTIFY:
3498 case GDK_BUTTON_PRESS:
3499 case GDK_2BUTTON_PRESS:
3500 case GDK_3BUTTON_PRESS:
3502 case GDK_ENTER_NOTIFY:
3503 case GDK_PROXIMITY_IN:
3505 return event->any.window && gdk_window_is_viewable (event->any.window);
3508 /* The following events are the second half of paired events;
3509 * we always deliver them to deal with widgets that clean up
3510 * on the second half.
3512 case GDK_BUTTON_RELEASE:
3513 case GDK_KEY_RELEASE:
3514 case GDK_LEAVE_NOTIFY:
3515 case GDK_PROXIMITY_OUT:
3519 /* Remaining events would make sense on an not-viewable window,
3520 * or don't have an associated window.
3527 gtk_widget_event_internal (GtkWidget *widget,
3530 gboolean return_val = FALSE;
3532 /* We check only once for is-still-visible; if someone
3533 * hides the window in on of the signals on the widget,
3534 * they are responsible for returning TRUE to terminate
3537 if (!event_window_is_still_viewable (event))
3540 g_object_ref (widget);
3542 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
3543 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
3548 switch (event->type)
3553 case GDK_BUTTON_PRESS:
3554 case GDK_2BUTTON_PRESS:
3555 case GDK_3BUTTON_PRESS:
3556 signal_num = BUTTON_PRESS_EVENT;
3559 signal_num = SCROLL_EVENT;
3561 case GDK_BUTTON_RELEASE:
3562 signal_num = BUTTON_RELEASE_EVENT;
3564 case GDK_MOTION_NOTIFY:
3565 signal_num = MOTION_NOTIFY_EVENT;
3568 signal_num = DELETE_EVENT;
3571 signal_num = DESTROY_EVENT;
3574 signal_num = KEY_PRESS_EVENT;
3576 case GDK_KEY_RELEASE:
3577 signal_num = KEY_RELEASE_EVENT;
3579 case GDK_ENTER_NOTIFY:
3580 signal_num = ENTER_NOTIFY_EVENT;
3582 case GDK_LEAVE_NOTIFY:
3583 signal_num = LEAVE_NOTIFY_EVENT;
3585 case GDK_FOCUS_CHANGE:
3586 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
3589 signal_num = CONFIGURE_EVENT;
3592 signal_num = MAP_EVENT;
3595 signal_num = UNMAP_EVENT;
3597 case GDK_WINDOW_STATE:
3598 signal_num = WINDOW_STATE_EVENT;
3600 case GDK_PROPERTY_NOTIFY:
3601 signal_num = PROPERTY_NOTIFY_EVENT;
3603 case GDK_SELECTION_CLEAR:
3604 signal_num = SELECTION_CLEAR_EVENT;
3606 case GDK_SELECTION_REQUEST:
3607 signal_num = SELECTION_REQUEST_EVENT;
3609 case GDK_SELECTION_NOTIFY:
3610 signal_num = SELECTION_NOTIFY_EVENT;
3612 case GDK_PROXIMITY_IN:
3613 signal_num = PROXIMITY_IN_EVENT;
3615 case GDK_PROXIMITY_OUT:
3616 signal_num = PROXIMITY_OUT_EVENT;
3619 signal_num = NO_EXPOSE_EVENT;
3621 case GDK_CLIENT_EVENT:
3622 signal_num = CLIENT_EVENT;
3625 signal_num = EXPOSE_EVENT;
3627 case GDK_VISIBILITY_NOTIFY:
3628 signal_num = VISIBILITY_NOTIFY_EVENT;
3631 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
3635 if (signal_num != -1)
3636 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
3638 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
3639 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
3643 g_object_unref (widget);
3649 * gtk_widget_activate:
3650 * @widget: a #GtkWidget that's activatable
3652 * For widgets that can be "activated" (buttons, menu items, etc.)
3653 * this function activates them. Activation is what happens when you
3654 * press Enter on a widget during key navigation. If @widget isn't
3655 * activatable, the function returns %FALSE.
3657 * Return value: %TRUE if the widget was activatable
3660 gtk_widget_activate (GtkWidget *widget)
3662 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3664 if (WIDGET_CLASS (widget)->activate_signal)
3666 /* FIXME: we should eventually check the signals signature here */
3667 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
3676 * gtk_widget_set_scroll_adjustments:
3677 * @widget: a #GtkWidget
3678 * @hadjustment: an adjustment for horizontal scrolling, or %NULL
3679 * @vadjustment: an adjustment for vertical scrolling, or %NULL
3681 * For widgets that support scrolling, sets the scroll adjustments and
3682 * returns %TRUE. For widgets that don't support scrolling, does
3683 * nothing and returns %FALSE. Widgets that don't support scrolling
3684 * can be scrolled by placing them in a #GtkViewport, which does
3685 * support scrolling.
3687 * Return value: %TRUE if the widget supports scrolling
3690 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
3691 GtkAdjustment *hadjustment,
3692 GtkAdjustment *vadjustment)
3694 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3696 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
3698 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
3700 if (WIDGET_CLASS (widget)->set_scroll_adjustments_signal)
3702 /* FIXME: we should eventually check the signals signature here */
3703 g_signal_emit (widget,
3704 WIDGET_CLASS (widget)->set_scroll_adjustments_signal, 0,
3705 hadjustment, vadjustment);
3713 gtk_widget_reparent_subwindows (GtkWidget *widget,
3714 GdkWindow *new_window)
3716 if (GTK_WIDGET_NO_WINDOW (widget))
3718 GList *children = gdk_window_get_children (widget->window);
3721 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3724 GdkWindow *window = tmp_list->data;
3726 gdk_window_get_user_data (window, (void **)&child);
3727 while (child && child != widget)
3728 child = child->parent;
3731 gdk_window_reparent (window, new_window, 0, 0);
3734 g_list_free (children);
3739 GList *tmp_list, *children;
3741 parent = gdk_window_get_parent (widget->window);
3744 gdk_window_reparent (widget->window, new_window, 0, 0);
3747 children = gdk_window_get_children (parent);
3749 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
3752 GdkWindow *window = tmp_list->data;
3754 gdk_window_get_user_data (window, (void **)&child);
3755 if (child == widget)
3756 gdk_window_reparent (window, new_window, 0, 0);
3759 g_list_free (children);
3765 gtk_widget_reparent_fixup_child (GtkWidget *widget,
3766 gpointer client_data)
3768 g_return_if_fail (client_data != NULL);
3770 if (GTK_WIDGET_NO_WINDOW (widget))
3773 g_object_unref (widget->window);
3774 widget->window = (GdkWindow*) client_data;
3776 g_object_ref (widget->window);
3778 if (GTK_IS_CONTAINER (widget))
3779 gtk_container_forall (GTK_CONTAINER (widget),
3780 gtk_widget_reparent_fixup_child,
3786 * gtk_widget_reparent:
3787 * @widget: a #GtkWidget
3788 * @new_parent: a #GtkContainer to move the widget into
3790 * Moves a widget from one #GtkContainer to another, handling reference
3791 * count issues to avoid destroying the widget.
3795 gtk_widget_reparent (GtkWidget *widget,
3796 GtkWidget *new_parent)
3798 g_return_if_fail (GTK_IS_WIDGET (widget));
3799 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
3800 g_return_if_fail (widget->parent != NULL);
3802 if (widget->parent != new_parent)
3804 /* First try to see if we can get away without unrealizing
3805 * the widget as we reparent it. if so we set a flag so
3806 * that gtk_widget_unparent doesn't unrealize widget
3808 if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
3809 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
3811 g_object_ref (widget);
3812 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
3813 gtk_container_add (GTK_CONTAINER (new_parent), widget);
3814 g_object_unref (widget);
3816 if (GTK_WIDGET_IN_REPARENT (widget))
3818 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
3820 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
3821 gtk_widget_reparent_fixup_child (widget,
3822 gtk_widget_get_parent_window (widget));
3825 g_object_notify (G_OBJECT (widget), "parent");
3830 * gtk_widget_intersect:
3831 * @widget: a #GtkWidget
3832 * @area: a rectangle
3833 * @intersection: rectangle to store intersection of @widget and @area
3835 * Computes the intersection of a @widget's area and @area, storing
3836 * the intersection in @intersection, and returns %TRUE if there was
3837 * an intersection. @intersection may be %NULL if you're only
3838 * interested in whether there was an intersection.
3840 * Return value: %TRUE if there was an intersection
3843 gtk_widget_intersect (GtkWidget *widget,
3845 GdkRectangle *intersection)
3851 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3852 g_return_val_if_fail (area != NULL, FALSE);
3855 dest = intersection;
3859 return_val = gdk_rectangle_intersect (&widget->allocation, area, dest);
3861 if (return_val && intersection && !GTK_WIDGET_NO_WINDOW (widget))
3863 intersection->x -= widget->allocation.x;
3864 intersection->y -= widget->allocation.y;
3871 * gtk_widget_region_intersect:
3872 * @widget: a #GtkWidget
3873 * @region: a #GdkRegion, in the same coordinate system as
3874 * @widget->allocation. That is, relative to @widget->window
3875 * for %NO_WINDOW widgets; relative to the parent window
3876 * of @widget->window for widgets with their own window.
3877 * @returns: A newly allocated region holding the intersection of @widget
3878 * and @region. The coordinates of the return value are
3879 * relative to @widget->window for %NO_WINDOW widgets, and
3880 * relative to the parent window of @widget->window for
3881 * widgets with their own window.
3883 * Computes the intersection of a @widget's area and @region, returning
3884 * the intersection. The result may be empty, use gdk_region_empty() to
3888 gtk_widget_region_intersect (GtkWidget *widget,
3893 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
3894 g_return_val_if_fail (region != NULL, NULL);
3896 dest = gdk_region_rectangle (&widget->allocation);
3898 gdk_region_intersect (dest, region);
3904 * _gtk_widget_grab_notify:
3905 * @widget: a #GtkWidget
3906 * @was_grabbed: whether a grab is now in effect
3908 * Emits the signal "grab_notify" on @widget.
3913 _gtk_widget_grab_notify (GtkWidget *widget,
3914 gboolean was_grabbed)
3916 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
3920 * gtk_widget_grab_focus:
3921 * @widget: a #GtkWidget
3923 * Causes @widget to have the keyboard focus for the #GtkWindow it's
3924 * inside. @widget must be a focusable widget, such as a #GtkEntry;
3925 * something like #GtkFrame won't work. (More precisely, it must have the
3926 * %GTK_CAN_FOCUS flag set.)
3930 gtk_widget_grab_focus (GtkWidget *widget)
3932 g_return_if_fail (GTK_IS_WIDGET (widget));
3934 if (!GTK_WIDGET_IS_SENSITIVE (widget))
3937 g_object_ref (widget);
3938 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
3939 g_object_notify (G_OBJECT (widget), "has_focus");
3940 g_object_unref (widget);
3944 reset_focus_recurse (GtkWidget *widget,
3947 if (GTK_IS_CONTAINER (widget))
3949 GtkContainer *container;
3951 container = GTK_CONTAINER (widget);
3952 gtk_container_set_focus_child (container, NULL);
3954 gtk_container_foreach (container,
3955 reset_focus_recurse,
3961 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
3963 if (GTK_WIDGET_CAN_FOCUS (focus_widget))
3965 GtkWidget *toplevel;
3968 /* clear the current focus setting, break if the current widget
3969 * is the focus widget's parent, since containers above that will
3970 * be set by the next loop.
3972 toplevel = gtk_widget_get_toplevel (focus_widget);
3973 if (GTK_WIDGET_TOPLEVEL (toplevel))
3975 widget = GTK_WINDOW (toplevel)->focus_widget;
3977 if (widget == focus_widget)
3979 /* We call _gtk_window_internal_set_focus() here so that the
3980 * toplevel window can request the focus if necessary.
3981 * This is needed when the toplevel is a GtkPlug
3983 if (!GTK_WIDGET_HAS_FOCUS (widget))
3984 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
3991 while (widget->parent && widget->parent != focus_widget->parent)
3993 widget = widget->parent;
3994 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
3998 else if (toplevel != focus_widget)
4000 /* gtk_widget_grab_focus() operates on a tree without window...
4001 * actually, this is very questionable behaviour.
4004 gtk_container_foreach (GTK_CONTAINER (toplevel),
4005 reset_focus_recurse,
4009 /* now propagate the new focus up the widget tree and finally
4010 * set it on the window
4012 widget = focus_widget;
4013 while (widget->parent)
4015 gtk_container_set_focus_child (GTK_CONTAINER (widget->parent), widget);
4016 widget = widget->parent;
4018 if (GTK_IS_WINDOW (widget))
4019 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
4024 gtk_widget_real_show_help (GtkWidget *widget,
4025 GtkWidgetHelpType help_type)
4027 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
4029 _gtk_tooltips_toggle_keyboard_mode (widget);
4037 gtk_widget_real_focus (GtkWidget *widget,
4038 GtkDirectionType direction)
4040 if (!GTK_WIDGET_CAN_FOCUS (widget))
4043 if (!gtk_widget_is_focus (widget))
4045 gtk_widget_grab_focus (widget);
4053 * gtk_widget_is_focus:
4054 * @widget: a #GtkWidget
4056 * Determines if the widget is the focus widget within its
4057 * toplevel. (This does not mean that the %HAS_FOCUS flag is
4058 * necessarily set; %HAS_FOCUS will only be set if the
4059 * toplevel widget additionally has the global input focus.)
4061 * Return value: %TRUE if the widget is the focus widget.
4064 gtk_widget_is_focus (GtkWidget *widget)
4066 GtkWidget *toplevel;
4068 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4070 toplevel = gtk_widget_get_toplevel (widget);
4072 if (GTK_IS_WINDOW (toplevel))
4073 return widget == GTK_WINDOW (toplevel)->focus_widget;
4079 * gtk_widget_grab_default:
4080 * @widget: a #GtkWidget
4082 * Causes @widget to become the default widget. @widget must have the
4083 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
4084 * yourself by calling <literal>GTK_WIDGET_SET_FLAGS (@widget,
4085 * GTK_CAN_DEFAULT)</literal>. The default widget is activated when the user
4086 * presses Enter in a window. Default widgets must be activatable,
4087 * that is, gtk_widget_activate() should affect them.
4091 gtk_widget_grab_default (GtkWidget *widget)
4095 g_return_if_fail (GTK_IS_WIDGET (widget));
4096 g_return_if_fail (GTK_WIDGET_CAN_DEFAULT (widget));
4098 window = gtk_widget_get_toplevel (widget);
4100 if (window && GTK_WIDGET_TOPLEVEL (window))
4101 gtk_window_set_default (GTK_WINDOW (window), widget);
4103 g_warning (G_STRLOC ": widget not within a GtkWindow");
4107 * gtk_widget_set_name:
4108 * @widget: a #GtkWidget
4109 * @name: name for the widget
4111 * Widgets can be named, which allows you to refer to them from a
4112 * gtkrc file. You can apply a style to widgets with a particular name
4113 * in the gtkrc file. See the documentation for gtkrc files (on the
4114 * same page as the docs for #GtkRcStyle).
4116 * Note that widget names are separated by periods in paths (see
4117 * gtk_widget_path()), so names with embedded periods may cause confusion.
4120 gtk_widget_set_name (GtkWidget *widget,
4125 g_return_if_fail (GTK_IS_WIDGET (widget));
4127 new_name = g_strdup (name);
4128 g_free (widget->name);
4129 widget->name = new_name;
4131 if (GTK_WIDGET_RC_STYLE (widget))
4132 gtk_widget_reset_rc_style (widget);
4134 g_object_notify (G_OBJECT (widget), "name");
4138 * gtk_widget_get_name:
4139 * @widget: a #GtkWidget
4141 * Retrieves the name of a widget. See gtk_widget_set_name() for the
4142 * significance of widget names.
4144 * Return value: name of the widget. This string is owned by GTK+ and
4145 * should not be modified or freed
4147 G_CONST_RETURN gchar*
4148 gtk_widget_get_name (GtkWidget *widget)
4150 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4153 return widget->name;
4154 return g_type_name (GTK_WIDGET_TYPE (widget));
4158 * gtk_widget_set_state:
4159 * @widget: a #GtkWidget
4160 * @state: new state for @widget
4162 * This function is for use in widget implementations. Sets the state
4163 * of a widget (insensitive, prelighted, etc.) Usually you should set
4164 * the state using wrapper functions such as gtk_widget_set_sensitive().
4168 gtk_widget_set_state (GtkWidget *widget,
4171 g_return_if_fail (GTK_IS_WIDGET (widget));
4173 if (state == GTK_WIDGET_STATE (widget))
4176 if (state == GTK_STATE_INSENSITIVE)
4177 gtk_widget_set_sensitive (widget, FALSE);
4183 data.state_restoration = FALSE;
4184 data.use_forall = FALSE;
4186 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4188 data.parent_sensitive = TRUE;
4190 gtk_widget_propagate_state (widget, &data);
4192 if (GTK_WIDGET_DRAWABLE (widget))
4193 gtk_widget_queue_draw (widget);
4198 gtk_widget_set_app_paintable (GtkWidget *widget,
4199 gboolean app_paintable)
4201 g_return_if_fail (GTK_IS_WIDGET (widget));
4203 app_paintable = (app_paintable != FALSE);
4205 if (GTK_WIDGET_APP_PAINTABLE (widget) != app_paintable)
4208 GTK_WIDGET_SET_FLAGS (widget, GTK_APP_PAINTABLE);
4210 GTK_WIDGET_UNSET_FLAGS (widget, GTK_APP_PAINTABLE);
4212 if (GTK_WIDGET_DRAWABLE (widget))
4213 gtk_widget_queue_draw (widget);
4215 g_object_notify (G_OBJECT (widget), "app_paintable");
4220 * gtk_widget_set_double_buffered:
4221 * @widget: a #GtkWidget
4222 * @double_buffered: %TRUE to double-buffer a widget
4224 * Widgets are double buffered by default; you can use this function
4225 * to turn off the buffering. "Double buffered" simply means that
4226 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
4227 * automatically around expose events sent to the
4228 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
4229 * window to an offscreen buffer, and gdk_window_end_paint() draws the
4230 * buffer to the screen. The result is that users see the window
4231 * update in one smooth step, and don't see individual graphics
4232 * primitives being rendered.
4234 * In very simple terms, double buffered widgets don't flicker,
4235 * so you would only use this function to turn off double buffering
4236 * if you had special needs and really knew what you were doing.
4240 gtk_widget_set_double_buffered (GtkWidget *widget,
4241 gboolean double_buffered)
4243 g_return_if_fail (GTK_IS_WIDGET (widget));
4245 if (double_buffered)
4246 GTK_WIDGET_SET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4248 GTK_WIDGET_UNSET_FLAGS (widget, GTK_DOUBLE_BUFFERED);
4252 * gtk_widget_set_redraw_on_allocate:
4253 * @widget: a #GtkWidget
4254 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
4255 * when it is allocated to a new size. Otherwise, only the
4256 * new portion of the widget will be redrawn.
4258 * Sets whether a when a widgets size allocation changes, the entire
4259 * widget is queued for drawing. By default, this setting is %TRUE and
4260 * the entire widget is redrawn on every size change. If your widget
4261 * leaves the upper left unchanged when made bigger, turning this
4262 * setting on will improve performance.
4264 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
4265 * off all allocation on resizing: the widget will not even redraw if
4266 * its position changes; this is to allow containers that don't draw
4267 * anything to avoid excess invalidations. If you set this flag on a
4268 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
4269 * you are responsible for invalidating both the old and new allocation
4270 * of the widget when the widget is moved and responsible for invalidating
4271 * regions newly when the widget increases size.
4274 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
4275 gboolean redraw_on_allocate)
4277 g_return_if_fail (GTK_IS_WIDGET (widget));
4279 if (redraw_on_allocate)
4280 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4282 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
4286 * gtk_widget_set_sensitive:
4287 * @widget: a #GtkWidget
4288 * @sensitive: %TRUE to make the widget sensitive
4290 * Sets the sensitivity of a widget. A widget is sensitive if the user
4291 * can interact with it. Insensitive widgets are "grayed out" and the
4292 * user can't interact with them. Insensitive widgets are known as
4293 * "inactive", "disabled", or "ghosted" in some other toolkits.
4297 gtk_widget_set_sensitive (GtkWidget *widget,
4302 g_return_if_fail (GTK_IS_WIDGET (widget));
4304 sensitive = (sensitive != FALSE);
4306 if (sensitive == (GTK_WIDGET_SENSITIVE (widget) != FALSE))
4311 GTK_WIDGET_SET_FLAGS (widget, GTK_SENSITIVE);
4312 data.state = GTK_WIDGET_SAVED_STATE (widget);
4316 GTK_WIDGET_UNSET_FLAGS (widget, GTK_SENSITIVE);
4317 data.state = GTK_WIDGET_STATE (widget);
4319 data.state_restoration = TRUE;
4320 data.use_forall = TRUE;
4323 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget->parent) != FALSE);
4325 data.parent_sensitive = TRUE;
4327 gtk_widget_propagate_state (widget, &data);
4328 if (GTK_WIDGET_DRAWABLE (widget))
4329 gtk_widget_queue_draw (widget);
4331 g_object_notify (G_OBJECT (widget), "sensitive");
4335 * gtk_widget_set_parent:
4336 * @widget: a #GtkWidget
4337 * @parent: parent container
4339 * This function is useful only when implementing subclasses of #GtkContainer.
4340 * Sets the container as the parent of @widget, and takes care of
4341 * some details such as updating the state and style of the child
4342 * to reflect its new location. The opposite function is
4343 * gtk_widget_unparent().
4347 gtk_widget_set_parent (GtkWidget *widget,
4352 g_return_if_fail (GTK_IS_WIDGET (widget));
4353 g_return_if_fail (GTK_IS_WIDGET (parent));
4354 g_return_if_fail (widget != parent);
4355 if (widget->parent != NULL)
4357 g_warning ("Can't set a parent on widget which has a parent\n");
4360 if (GTK_WIDGET_TOPLEVEL (widget))
4362 g_warning ("Can't set a parent on a toplevel widget\n");
4366 /* keep this function in sync with gtk_menu_attach_to_widget()
4369 g_object_ref (widget);
4370 gtk_object_sink (GTK_OBJECT (widget));
4371 widget->parent = parent;
4373 if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
4374 data.state = GTK_WIDGET_STATE (parent);
4376 data.state = GTK_WIDGET_STATE (widget);
4377 data.state_restoration = FALSE;
4378 data.parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (parent) != FALSE);
4379 data.use_forall = GTK_WIDGET_IS_SENSITIVE (parent) != GTK_WIDGET_IS_SENSITIVE (widget);
4381 gtk_widget_propagate_state (widget, &data);
4383 gtk_widget_reset_rc_styles (widget);
4385 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
4386 if (GTK_WIDGET_ANCHORED (widget->parent))
4387 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
4388 g_object_notify (G_OBJECT (widget), "parent");
4390 /* Enforce realized/mapped invariants
4392 if (GTK_WIDGET_REALIZED (widget->parent))
4393 gtk_widget_realize (widget);
4395 if (GTK_WIDGET_VISIBLE (widget->parent) &&
4396 GTK_WIDGET_VISIBLE (widget))
4398 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
4399 GTK_WIDGET_MAPPED (widget->parent))
4400 gtk_widget_map (widget);
4402 gtk_widget_queue_resize (widget);
4407 * gtk_widget_get_parent:
4408 * @widget: a #GtkWidget
4410 * Returns the parent container of @widget.
4412 * Return value: the parent container of @widget, or %NULL
4415 gtk_widget_get_parent (GtkWidget *widget)
4417 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4419 return widget->parent;
4422 /*****************************************
4424 * see docs/styles.txt
4425 *****************************************/
4428 * gtk_widget_set_style:
4429 * @widget: a #GtkWidget
4430 * @style: a #GtkStyle, or %NULL to remove the effect of a previous
4431 * gtk_widget_set_style() and go back to the default style
4433 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
4434 * want to use this function; it interacts badly with themes, because
4435 * themes work by replacing the #GtkStyle. Instead, use
4436 * gtk_widget_modify_style().
4440 gtk_widget_set_style (GtkWidget *widget,
4443 g_return_if_fail (GTK_IS_WIDGET (widget));
4447 gboolean initial_emission;
4449 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4451 GTK_WIDGET_UNSET_FLAGS (widget, GTK_RC_STYLE);
4452 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
4454 gtk_widget_set_style_internal (widget, style, initial_emission);
4458 if (GTK_WIDGET_USER_STYLE (widget))
4459 gtk_widget_reset_rc_style (widget);
4464 * gtk_widget_ensure_style:
4465 * @widget: a #GtkWidget
4467 * Ensures that @widget has a style (@widget->style). Not a very useful
4468 * function; most of the time, if you want the style, the widget is
4469 * realized, and realized widgets are guaranteed to have a style
4474 gtk_widget_ensure_style (GtkWidget *widget)
4476 g_return_if_fail (GTK_IS_WIDGET (widget));
4478 if (!GTK_WIDGET_USER_STYLE (widget) &&
4479 !GTK_WIDGET_RC_STYLE (widget))
4480 gtk_widget_reset_rc_style (widget);
4483 /* Look up the RC style for this widget, unsetting any user style that
4484 * may be in effect currently
4487 gtk_widget_reset_rc_style (GtkWidget *widget)
4489 GtkStyle *new_style = NULL;
4490 gboolean initial_emission;
4492 g_return_if_fail (GTK_IS_WIDGET (widget));
4494 initial_emission = !GTK_WIDGET_RC_STYLE (widget) && !GTK_WIDGET_USER_STYLE (widget);
4496 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
4497 GTK_WIDGET_SET_FLAGS (widget, GTK_RC_STYLE);
4499 if (gtk_widget_has_screen (widget))
4500 new_style = gtk_rc_get_style (widget);
4502 new_style = gtk_widget_get_default_style ();
4504 if (initial_emission || new_style != widget->style)
4505 gtk_widget_set_style_internal (widget, new_style, initial_emission);
4509 * gtk_widget_get_style:
4510 * @widget: a #GtkWidget
4512 * Simply an accessor function that returns @widget->style.
4514 * Return value: the widget's #GtkStyle
4517 gtk_widget_get_style (GtkWidget *widget)
4519 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4521 return widget->style;
4525 * gtk_widget_modify_style:
4526 * @widget: a #GtkWidget
4527 * @style: the #GtkRcStyle holding the style modifications
4529 * Modifies style values on the widget. Modifications made using this
4530 * technique take precedence over style values set via an RC file,
4531 * however, they will be overriden if a style is explicitely set on
4532 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
4533 * is designed so each field can either be set or unset, so it is
4534 * possible, using this function, to modify some style values and
4535 * leave the others unchanged.
4537 * Note that modifications made with this function are not cumulative
4538 * with previous calls to gtk_widget_modify_style() or with such
4539 * functions as gtk_widget_modify_fg(). If you wish to retain
4540 * previous values, you must first call gtk_widget_get_modifier_style(),
4541 * make your modifications to the returned style, then call
4542 * gtk_widget_modify_style() with that style. On the other hand,
4543 * if you first call gtk_widget_modify_style(), subsequent calls
4544 * to such functions gtk_widget_modify_fg() will have a cumulative
4545 * effect with the initial modifications.
4548 gtk_widget_modify_style (GtkWidget *widget,
4551 GtkRcStyle *old_style;
4553 g_return_if_fail (GTK_IS_WIDGET (widget));
4554 g_return_if_fail (GTK_IS_RC_STYLE (style));
4556 old_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4558 g_object_set_qdata_full (G_OBJECT (widget),
4560 gtk_rc_style_copy (style),
4561 (GDestroyNotify) gtk_rc_style_unref);
4563 /* note that "style" may be invalid here if it was the old
4564 * modifier style and the only reference was our own.
4567 if (GTK_WIDGET_RC_STYLE (widget))
4568 gtk_widget_reset_rc_style (widget);
4572 * gtk_widget_get_modifier_style:
4573 * @widget: a #GtkWidget
4575 * Returns the current modifier style for the widget. (As set by
4576 * gtk_widget_modify_style().) If no style has previously set, a new
4577 * #GtkRcStyle will be created with all values unset, and set as the
4578 * modifier style for the widget. If you make changes to this rc
4579 * style, you must call gtk_widget_modify_style(), passing in the
4580 * returned rc style, to make sure that your changes take effect.
4582 * Caution: passing the style back to gtk_widget_modify_style() will
4583 * normally end up destroying it, because gtk_widget_modify_style() copies
4584 * the passed-in style and sets the copy as the new modifier style,
4585 * thus dropping any reference to the old modifier style. Add a reference
4586 * to the modifier style if you want to keep it alive.
4588 * Return value: the modifier style for the widget. This rc style is
4589 * owned by the widget. If you want to keep a pointer to value this
4590 * around, you must add a refcount using gtk_rc_style_ref().
4593 gtk_widget_get_modifier_style (GtkWidget *widget)
4595 GtkRcStyle *rc_style;
4597 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4599 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
4603 rc_style = gtk_rc_style_new ();
4604 g_object_set_qdata_full (G_OBJECT (widget),
4607 (GDestroyNotify) gtk_rc_style_unref);
4614 gtk_widget_modify_color_component (GtkWidget *widget,
4615 GtkRcFlags component,
4617 const GdkColor *color)
4619 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
4626 rc_style->fg[state] = *color;
4629 rc_style->bg[state] = *color;
4632 rc_style->text[state] = *color;
4635 rc_style->base[state] = *color;
4638 g_assert_not_reached();
4641 rc_style->color_flags[state] |= component;
4644 rc_style->color_flags[state] &= ~component;
4646 gtk_widget_modify_style (widget, rc_style);
4650 * gtk_widget_modify_fg:
4651 * @widget: a #GtkWidget.
4652 * @state: the state for which to set the foreground color.
4653 * @color: the color to assign (does not need to be allocated),
4654 * or %NULL to undo the effect of previous calls to
4655 * of gtk_widget_modify_fg().
4657 * Sets the foreground color for a widget in a particular state. All
4658 * other style values are left untouched. See also
4659 * gtk_widget_modify_style().
4662 gtk_widget_modify_fg (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_FG, state, color);
4673 * gtk_widget_modify_bg:
4674 * @widget: a #GtkWidget.
4675 * @state: the state for which to set the background color.
4676 * @color: the color to assign (does not need to be allocated),
4677 * or %NULL to undo the effect of previous calls to
4678 * of gtk_widget_modify_bg().
4680 * Sets the background color for a widget in a particular state. All
4681 * other style values are left untouched. See also
4682 * gtk_widget_modify_style().
4685 gtk_widget_modify_bg (GtkWidget *widget,
4687 const GdkColor *color)
4689 g_return_if_fail (GTK_IS_WIDGET (widget));
4690 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4692 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
4696 * gtk_widget_modify_text:
4697 * @widget: a #GtkWidget.
4698 * @state: the state for which to set the text color.
4699 * @color: the color to assign (does not need to be allocated),
4700 * or %NULL to undo the effect of previous calls to
4701 * of gtk_widget_modify_text().
4703 * Sets the text color for a widget in a particular state. All other
4704 * style values are left untouched. The text color is the foreground
4705 * color used along with the base color (see gtk_widget_modify_base())
4706 * for widgets such as #GtkEntry and #GtkTextView. See also
4707 * gtk_widget_modify_style().
4710 gtk_widget_modify_text (GtkWidget *widget,
4712 const GdkColor *color)
4714 g_return_if_fail (GTK_IS_WIDGET (widget));
4715 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4717 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
4721 * gtk_widget_modify_base:
4722 * @widget: a #GtkWidget.
4723 * @state: the state for which to set the base color.
4724 * @color: the color to assign (does not need to be allocated),
4725 * or %NULL to undo the effect of previous calls to
4726 * of gtk_widget_modify_base().
4728 * Sets the base color for a widget in a particular state.
4729 * All other style values are left untouched. The base color
4730 * is the background color used along with the text color
4731 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
4732 * and #GtkTextView. See also gtk_widget_modify_style().
4735 gtk_widget_modify_base (GtkWidget *widget,
4737 const GdkColor *color)
4739 g_return_if_fail (GTK_IS_WIDGET (widget));
4740 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
4742 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
4746 * gtk_widget_modify_font:
4747 * @widget: a #GtkWidget
4748 * @font_desc: the font description to use, or %NULL to undo
4749 * the effect of previous calls to gtk_widget_modify_font().
4751 * Sets the font to use for a widget. All other style values are left
4752 * untouched. See also gtk_widget_modify_style().
4755 gtk_widget_modify_font (GtkWidget *widget,
4756 PangoFontDescription *font_desc)
4758 GtkRcStyle *rc_style;
4760 g_return_if_fail (GTK_IS_WIDGET (widget));
4762 rc_style = gtk_widget_get_modifier_style (widget);
4764 if (rc_style->font_desc)
4765 pango_font_description_free (rc_style->font_desc);
4768 rc_style->font_desc = pango_font_description_copy (font_desc);
4770 rc_style->font_desc = NULL;
4772 gtk_widget_modify_style (widget, rc_style);
4776 gtk_widget_direction_changed (GtkWidget *widget,
4777 GtkTextDirection previous_direction)
4779 gtk_widget_queue_resize (widget);
4783 gtk_widget_style_set (GtkWidget *widget,
4784 GtkStyle *previous_style)
4786 if (GTK_WIDGET_REALIZED (widget) &&
4787 !GTK_WIDGET_NO_WINDOW (widget))
4788 gtk_style_set_background (widget->style, widget->window, widget->state);
4792 gtk_widget_set_style_internal (GtkWidget *widget,
4794 gboolean initial_emission)
4796 g_object_ref (widget);
4797 g_object_freeze_notify (G_OBJECT (widget));
4799 if (widget->style != style || initial_emission)
4801 PangoContext *context = gtk_widget_peek_pango_context (widget);
4803 pango_context_set_font_description (context, style->font_desc);
4806 if (widget->style != style)
4808 GtkStyle *previous_style;
4810 if (GTK_WIDGET_REALIZED (widget))
4812 gtk_widget_reset_shapes (widget);
4813 gtk_style_detach (widget->style);
4816 previous_style = widget->style;
4817 widget->style = style;
4818 g_object_ref (widget->style);
4820 if (GTK_WIDGET_REALIZED (widget))
4821 widget->style = gtk_style_attach (widget->style, widget->window);
4823 g_signal_emit (widget,
4824 widget_signals[STYLE_SET],
4826 initial_emission ? NULL : previous_style);
4827 g_object_unref (previous_style);
4829 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
4830 gtk_widget_queue_resize (widget);
4832 else if (initial_emission)
4833 g_signal_emit (widget,
4834 widget_signals[STYLE_SET],
4837 g_object_notify (G_OBJECT (widget), "style");
4838 g_object_thaw_notify (G_OBJECT (widget));
4839 g_object_unref (widget);
4843 GtkWidget *previous_toplevel;
4844 GdkScreen *previous_screen;
4845 GdkScreen *new_screen;
4846 } HierarchyChangedInfo;
4849 do_screen_change (GtkWidget *widget,
4850 GdkScreen *old_screen,
4851 GdkScreen *new_screen)
4853 if (old_screen != new_screen)
4857 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
4859 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
4862 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
4867 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
4868 gpointer client_data)
4870 gboolean new_anchored;
4871 HierarchyChangedInfo *info = client_data;
4873 new_anchored = GTK_WIDGET_TOPLEVEL (widget) ||
4874 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent));
4876 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
4878 g_object_ref (widget);
4881 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
4883 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
4885 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
4886 do_screen_change (widget, info->previous_screen, info->new_screen);
4888 if (GTK_IS_CONTAINER (widget))
4889 gtk_container_forall (GTK_CONTAINER (widget),
4890 gtk_widget_propagate_hierarchy_changed_recurse,
4893 g_object_unref (widget);
4898 * _gtk_widget_propagate_hierarchy_changed:
4899 * @widget: a #GtkWidget
4900 * @previous_toplevel: Previous toplevel
4902 * Propagates changes in the anchored state to a widget and all
4903 * children, unsetting or setting the %ANCHORED flag, and
4904 * emitting ::hierarchy_changed.
4907 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
4908 GtkWidget *previous_toplevel)
4910 HierarchyChangedInfo info;
4912 info.previous_toplevel = previous_toplevel;
4913 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
4915 if (GTK_WIDGET_TOPLEVEL (widget) ||
4916 (widget->parent && GTK_WIDGET_ANCHORED (widget->parent)))
4917 info.new_screen = gtk_widget_get_screen (widget);
4919 info.new_screen = NULL;
4921 if (info.previous_screen)
4922 g_object_ref (info.previous_screen);
4923 if (previous_toplevel)
4924 g_object_ref (previous_toplevel);
4926 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
4928 if (previous_toplevel)
4929 g_object_unref (previous_toplevel);
4930 if (info.previous_screen)
4931 g_object_unref (info.previous_screen);
4935 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
4936 gpointer client_data)
4938 HierarchyChangedInfo *info = client_data;
4940 g_object_ref (widget);
4942 do_screen_change (widget, info->previous_screen, info->new_screen);
4944 if (GTK_IS_CONTAINER (widget))
4945 gtk_container_forall (GTK_CONTAINER (widget),
4946 gtk_widget_propagate_screen_changed_recurse,
4949 g_object_unref (widget);
4953 * _gtk_widget_propagate_screen_changed:
4954 * @widget: a #GtkWidget
4955 * @previous_screen: Previous screen
4957 * Propagates changes in the screen for a widget to all
4958 * children, emitting ::screen_changed.
4961 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
4962 GdkScreen *previous_screen)
4964 HierarchyChangedInfo info;
4966 info.previous_screen = previous_screen;
4967 info.new_screen = gtk_widget_get_screen (widget);
4969 if (previous_screen)
4970 g_object_ref (previous_screen);
4972 gtk_widget_propagate_screen_changed_recurse (widget, &info);
4974 if (previous_screen)
4975 g_object_unref (previous_screen);
4979 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
4981 if (GTK_WIDGET_RC_STYLE (widget))
4982 gtk_widget_reset_rc_style (widget);
4984 if (GTK_IS_CONTAINER (widget))
4985 gtk_container_forall (GTK_CONTAINER (widget),
4986 reset_rc_styles_recurse,
4991 gtk_widget_reset_rc_styles (GtkWidget *widget)
4993 g_return_if_fail (GTK_IS_WIDGET (widget));
4995 reset_rc_styles_recurse (widget, NULL);
4999 * gtk_widget_get_default_style:
5001 * Returns the default style used by all widgets initially.
5003 * Returns: the default style. This #GtkStyle object is owned by GTK+ and
5004 * should not be modified or freed.
5007 gtk_widget_get_default_style (void)
5009 if (!gtk_default_style)
5011 gtk_default_style = gtk_style_new ();
5012 g_object_ref (gtk_default_style);
5015 return gtk_default_style;
5018 static PangoContext *
5019 gtk_widget_peek_pango_context (GtkWidget *widget)
5021 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5025 * gtk_widget_get_pango_context:
5026 * @widget: a #GtkWidget
5028 * Gets a #PangoContext with the appropriate colormap, font description
5029 * and base direction for this widget. Unlike the context returned
5030 * by gtk_widget_create_pango_context(), this context is owned by
5031 * the widget (it can be used until the screen for the widget changes
5032 * or the widget is removed from its toplevel), and will be updated to
5033 * match any changes to the widget's attributes.
5035 * If you create and keep a #PangoLayout using this context, you must
5036 * deal with changes to the context by calling pango_layout_context_changed()
5037 * on the layout in response to the ::style-set and ::direction-changed signals
5040 * Return value: the #PangoContext for the widget.
5043 gtk_widget_get_pango_context (GtkWidget *widget)
5045 PangoContext *context;
5047 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5049 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
5052 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
5053 g_object_set_qdata_full (G_OBJECT (widget),
5054 quark_pango_context,
5063 * gtk_widget_create_pango_context:
5064 * @widget: a #GtkWidget
5066 * Creates a new #PangoContext with the appropriate colormap,
5067 * font description, and base direction for drawing text for
5068 * this widget. See also gtk_widget_get_pango_context().
5070 * Return value: the new #PangoContext
5073 gtk_widget_create_pango_context (GtkWidget *widget)
5076 PangoContext *context;
5078 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5080 screen = gtk_widget_get_screen_unchecked (widget);
5083 GTK_NOTE (MULTIHEAD,
5084 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
5086 screen = gdk_screen_get_default ();
5089 context = gdk_pango_context_get_for_screen (screen);
5091 pango_context_set_base_dir (context,
5092 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
5093 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
5094 pango_context_set_font_description (context, widget->style->font_desc);
5095 pango_context_set_language (context, gtk_get_default_language ());
5101 * gtk_widget_create_pango_layout:
5102 * @widget: a #GtkWidget
5103 * @text: text to set on the layout (can be %NULL)
5105 * Creates a new #PangoLayout with the appropriate colormap,
5106 * font description, and base direction for drawing text for
5109 * If you keep a #PangoLayout created in this way around, in order
5110 * notify the layout of changes to the base direction or font of this
5111 * widget, you must call pango_layout_context_changed() in response to
5112 * the ::style-set and ::direction-changed signals for the widget.
5114 * Return value: the new #PangoLayout
5117 gtk_widget_create_pango_layout (GtkWidget *widget,
5120 PangoLayout *layout;
5121 PangoContext *context;
5123 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5125 context = gtk_widget_get_pango_context (widget);
5126 layout = pango_layout_new (context);
5129 pango_layout_set_text (layout, text, -1);
5135 * gtk_widget_render_icon:
5136 * @widget: a #GtkWidget
5137 * @stock_id: a stock ID
5138 * @size: a stock size. A size of (GtkIconSize)-1 means render at
5139 * the size of the source and don't scale (if there are multiple
5140 * source sizes, GTK+ picks one of the available sizes).
5141 * @detail: render detail to pass to theme engine
5143 * A convenience function that uses the theme engine and RC file
5144 * settings for @widget to look up @stock_id and render it to
5145 * a pixbuf. @stock_id should be a stock icon ID such as
5146 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
5147 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
5148 * identifies the widget or code doing the rendering, so that
5149 * theme engines can special-case rendering for that widget or code.
5151 * The pixels in the returned #GdkPixbuf are shared with the rest of
5152 * the application and should not be modified. The pixbuf should be freed
5153 * after use with g_object_unref().
5155 * Return value: a new pixbuf, or %NULL if the stock ID wasn't known
5158 gtk_widget_render_icon (GtkWidget *widget,
5159 const gchar *stock_id,
5161 const gchar *detail)
5163 GtkIconSet *icon_set;
5166 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5167 g_return_val_if_fail (stock_id != NULL, NULL);
5168 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
5170 gtk_widget_ensure_style (widget);
5172 icon_set = gtk_style_lookup_icon_set (widget->style, stock_id);
5174 if (icon_set == NULL)
5177 retval = gtk_icon_set_render_icon (icon_set,
5179 gtk_widget_get_direction (widget),
5180 GTK_WIDGET_STATE (widget),
5189 * gtk_widget_set_parent_window:
5190 * @widget: a #GtkWidget.
5191 * @parent_window: the new parent window.
5193 * Sets a non default parent window for @widget.
5196 gtk_widget_set_parent_window (GtkWidget *widget,
5197 GdkWindow *parent_window)
5199 GdkWindow *old_parent_window;
5201 g_return_if_fail (GTK_IS_WIDGET (widget));
5203 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
5204 quark_parent_window);
5206 if (parent_window != old_parent_window)
5208 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
5210 if (old_parent_window)
5211 g_object_unref (old_parent_window);
5213 g_object_ref (parent_window);
5219 * gtk_widget_set_child_visible:
5220 * @widget: a #GtkWidget
5221 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
5223 * Sets whether @widget should be mapped along with its when its parent
5224 * is mapped and @widget has been shown with gtk_widget_show().
5226 * The child visibility can be set for widget before it is added to
5227 * a container with gtk_widget_set_parent(), to avoid mapping
5228 * children unnecessary before immediately unmapping them. However
5229 * it will be reset to its default state of %TRUE when the widget
5230 * is removed from a container.
5232 * Note that changing the child visibility of a widget does not
5233 * queue a resize on the widget. Most of the time, the size of
5234 * a widget is computed from all visible children, whether or
5235 * not they are mapped. If this is not the case, the container
5236 * can queue a resize itself.
5238 * This function is only useful for container implementations and
5239 * never should be called by an application.
5242 gtk_widget_set_child_visible (GtkWidget *widget,
5243 gboolean is_visible)
5245 g_return_if_fail (GTK_IS_WIDGET (widget));
5246 g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
5248 g_object_ref (widget);
5251 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
5254 GtkWidget *toplevel;
5256 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
5258 toplevel = gtk_widget_get_toplevel (widget);
5259 if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
5260 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
5263 if (widget->parent && GTK_WIDGET_REALIZED (widget->parent))
5265 if (GTK_WIDGET_MAPPED (widget->parent) &&
5266 GTK_WIDGET_CHILD_VISIBLE (widget) &&
5267 GTK_WIDGET_VISIBLE (widget))
5268 gtk_widget_map (widget);
5270 gtk_widget_unmap (widget);
5273 g_object_unref (widget);
5277 * gtk_widget_get_child_visible:
5278 * @widget: a #GtkWidget
5280 * Gets the value set with gtk_widget_set_child_visible().
5281 * If you feel a need to use this function, your code probably
5282 * needs reorganization.
5284 * This function is only useful for container implementations and
5285 * never should be called by an application.
5287 * Return value: %TRUE if the widget is mapped with the parent.
5290 gtk_widget_get_child_visible (GtkWidget *widget)
5292 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5294 return GTK_WIDGET_CHILD_VISIBLE (widget);
5298 gtk_widget_get_screen_unchecked (GtkWidget *widget)
5300 GtkWidget *toplevel;
5302 toplevel = gtk_widget_get_toplevel (widget);
5304 if (GTK_WIDGET_TOPLEVEL (toplevel))
5306 if (GTK_IS_WINDOW (toplevel))
5307 return GTK_WINDOW (toplevel)->screen;
5308 else if (GTK_IS_INVISIBLE (toplevel))
5309 return GTK_INVISIBLE (widget)->screen;
5316 * gtk_widget_get_screen:
5317 * @widget: a #GtkWidget
5319 * Get the #GdkScreen from the toplevel window associated with
5320 * this widget. This function can only be called after the widget
5321 * has been added to a widget hierarchy with a #GtkWindow
5324 * In general, you should only create screen specific
5325 * resources when a widget has been realized, and you should
5326 * free those resources when the widget is unrealized.
5328 * Return value: the #GdkScreen for the toplevel for this widget.
5333 gtk_widget_get_screen (GtkWidget *widget)
5337 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5339 screen = gtk_widget_get_screen_unchecked (widget);
5346 g_warning (G_STRLOC ": Can't get associated screen"
5347 " for a widget unless it is inside a toplevel GtkWindow\n"
5348 " widget type is %s associated top level type is %s",
5349 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
5350 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
5352 return gdk_screen_get_default ();
5357 * gtk_widget_has_screen:
5358 * @widget: a #GtkWidget
5360 * Checks whether there is a #GdkScreen is associated with
5361 * this widget. All toplevel widgets have an associated
5362 * screen, and all widgets added into a heirarchy with a toplevel
5363 * window at the top.
5365 * Return value: %TRUE if there is a #GdkScreen associcated
5371 gtk_widget_has_screen (GtkWidget *widget)
5373 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5375 return (gtk_widget_get_screen_unchecked (widget) != NULL);
5379 * gtk_widget_get_display:
5380 * @widget: a #GtkWidget
5382 * Get the #GdkDisplay for the toplevel window associated with
5383 * this widget. This function can only be called after the widget
5384 * has been added to a widget hierarchy with a #GtkWindow at the top.
5386 * In general, you should only create display specific
5387 * resources when a widget has been realized, and you should
5388 * free those resources when the widget is unrealized.
5390 * Return value: the #GdkDisplay for the toplevel for this widget.
5395 gtk_widget_get_display (GtkWidget *widget)
5397 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5399 return gdk_screen_get_display (gtk_widget_get_screen (widget));
5403 * gtk_widget_get_root_window:
5404 * @widget: a #GtkWidget
5406 * Get the root window where this widget is located. This function can
5407 * only be called after the widget has been added to a widget
5408 * heirarchy with #GtkWindow at the top.
5410 * The root window is useful for such purposes as creating a popup
5411 * #GdkWindow associated with the window. In general, you should only
5412 * create display specific resources when a widget has been realized,
5413 * and you should free those resources when the widget is unrealized.
5415 * Return value: the #GdkWindow root window for the toplevel for this widget.
5420 gtk_widget_get_root_window (GtkWidget *widget)
5422 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5424 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
5428 * gtk_widget_get_parent_window:
5429 * @widget: a #GtkWidget.
5430 * @returns: the parent window of @widget.
5432 * Gets @widget's parent window.
5435 gtk_widget_get_parent_window (GtkWidget *widget)
5437 GdkWindow *parent_window;
5439 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5440 g_return_val_if_fail (widget->parent != NULL, NULL);
5442 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
5444 return (parent_window != NULL) ? parent_window : widget->parent->window;
5448 * gtk_widget_child_focus:
5449 * @widget: a #GtkWidget
5450 * @direction: direction of focus movement
5452 * This function is used by custom widget implementations; if you're
5453 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
5454 * to a particular widget, and gtk_container_set_focus_chain() to
5455 * change the focus tab order. So you may want to investigate those
5456 * functions instead.
5458 * gtk_widget_child_focus() is called by containers as the user moves
5459 * around the window using keyboard shortcuts. @direction indicates
5460 * what kind of motion is taking place (up, down, left, right, tab
5461 * forward, tab backward). gtk_widget_child_focus() invokes the
5462 * "focus" signal on #GtkWidget; widgets override the default handler
5463 * for this signal in order to implement appropriate focus behavior.
5465 * The "focus" default handler for a widget should return %TRUE if
5466 * moving in @direction left the focus on a focusable location inside
5467 * that widget, and %FALSE if moving in @direction moved the focus
5468 * outside the widget. If returning %TRUE, widgets normally
5469 * call gtk_widget_grab_focus() to place the focus accordingly;
5470 * if returning %FALSE, they don't modify the current focus location.
5472 * This function replaces gtk_container_focus() from GTK+ 1.2. It was
5473 * necessary to check that the child was visible, sensitive, and
5474 * focusable before calling
5475 * gtk_container_focus(). gtk_widget_child_focus() returns %FALSE if
5476 * the widget is not currently in a focusable state, so there's no
5477 * need for those checks.
5479 * Return value: %TRUE if focus ended up inside @widget
5482 gtk_widget_child_focus (GtkWidget *widget,
5483 GtkDirectionType direction)
5485 gboolean return_val;
5487 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5489 if (!GTK_WIDGET_VISIBLE (widget) ||
5490 !GTK_WIDGET_IS_SENSITIVE (widget))
5493 /* child widgets must set CAN_FOCUS, containers
5494 * don't have to though.
5496 if (!GTK_IS_CONTAINER (widget) &&
5497 !GTK_WIDGET_CAN_FOCUS (widget))
5500 g_signal_emit (widget,
5501 widget_signals[FOCUS],
5503 direction, &return_val);
5509 * gtk_widget_set_uposition:
5510 * @widget: a #GtkWidget
5511 * @x: x position; -1 to unset x; -2 to leave x unchanged
5512 * @y: y position; -1 to unset y; -2 to leave y unchanged
5515 * Sets the position of a widget. The funny "u" in the name comes from
5516 * the "user position" hint specified by the X Window System, and
5517 * exists for legacy reasons. This function doesn't work if a widget
5518 * is inside a container; it's only really useful on #GtkWindow.
5520 * Don't use this function to center dialogs over the main application
5521 * window; most window managers will do the centering on your behalf
5522 * if you call gtk_window_set_transient_for(), and it's really not
5523 * possible to get the centering to work correctly in all cases from
5524 * application code. But if you insist, use gtk_window_set_position()
5525 * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
5528 * Note that although @x and @y can be individually unset, the position
5529 * is not honoured unless both @x and @y are set.
5532 gtk_widget_set_uposition (GtkWidget *widget,
5536 /* FIXME this function is the only place that aux_info->x and
5537 * aux_info->y are even used I believe, and this function is
5538 * deprecated. Should be cleaned up.
5540 * (Actually, size_allocate uses them) -Yosh
5543 GtkWidgetAuxInfo *aux_info;
5545 g_return_if_fail (GTK_IS_WIDGET (widget));
5547 aux_info =_gtk_widget_get_aux_info (widget, TRUE);
5552 aux_info->x_set = FALSE;
5555 aux_info->x_set = TRUE;
5563 aux_info->y_set = FALSE;
5566 aux_info->y_set = TRUE;
5571 if (GTK_IS_WINDOW (widget) && aux_info->x_set && aux_info->y_set)
5572 _gtk_window_reposition (GTK_WINDOW (widget), aux_info->x, aux_info->y);
5574 if (GTK_WIDGET_VISIBLE (widget) && widget->parent)
5575 gtk_widget_size_allocate (widget, &widget->allocation);
5579 gtk_widget_set_usize_internal (GtkWidget *widget,
5583 GtkWidgetAuxInfo *aux_info;
5584 gboolean changed = FALSE;
5586 g_return_if_fail (GTK_IS_WIDGET (widget));
5588 g_object_freeze_notify (G_OBJECT (widget));
5590 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
5592 if (width > -2 && aux_info->width != width)
5594 g_object_notify (G_OBJECT (widget), "width_request");
5595 aux_info->width = width;
5598 if (height > -2 && aux_info->height != height)
5600 g_object_notify (G_OBJECT (widget), "height_request");
5601 aux_info->height = height;
5605 if (GTK_WIDGET_VISIBLE (widget) && changed)
5606 gtk_widget_queue_resize (widget);
5608 g_object_thaw_notify (G_OBJECT (widget));
5612 * gtk_widget_set_usize:
5613 * @widget: a #GtkWidget
5614 * @width: minimum width, or -1 to unset
5615 * @height: minimum height, or -1 to unset
5617 * Sets the minimum size of a widget; that is, the widget's size
5618 * request will be @width by @height. You can use this function to
5619 * force a widget to be either larger or smaller than it is. The
5620 * strange "usize" name dates from the early days of GTK+, and derives
5621 * from X Window System terminology. In many cases,
5622 * gtk_window_set_default_size() is a better choice for toplevel
5623 * windows than this function; setting the default size will still
5624 * allow users to shrink the window. Setting the usize will force them
5625 * to leave the window at least as large as the usize. When dealing
5626 * with window sizes, gtk_window_set_geometry_hints() can be a useful
5629 * Note the inherent danger of setting any fixed size - themes,
5630 * translations into other languages, different fonts, and user action
5631 * can all change the appropriate size for a given widget. So, it's
5632 * basically impossible to hardcode a size that will always be
5635 * @Deprecated: Use gtk_widget_set_size_request() instead.
5638 gtk_widget_set_usize (GtkWidget *widget,
5642 g_return_if_fail (GTK_IS_WIDGET (widget));
5644 gtk_widget_set_usize_internal (widget, width, height);
5648 * gtk_widget_set_size_request:
5649 * @widget: a #GtkWidget
5650 * @width: width @widget should request, or -1 to unset
5651 * @height: height @widget should request, or -1 to unset
5653 * Sets the minimum size of a widget; that is, the widget's size
5654 * request will be @width by @height. You can use this function to
5655 * force a widget to be either larger or smaller than it normally
5658 * In most cases, gtk_window_set_default_size() is a better choice for
5659 * toplevel windows than this function; setting the default size will
5660 * still allow users to shrink the window. Setting the size request
5661 * will force them to leave the window at least as large as the size
5662 * request. When dealing with window sizes,
5663 * gtk_window_set_geometry_hints() can be a useful function as well.
5665 * Note the inherent danger of setting any fixed size - themes,
5666 * translations into other languages, different fonts, and user action
5667 * can all change the appropriate size for a given widget. So, it's
5668 * basically impossible to hardcode a size that will always be
5671 * The size request of a widget is the smallest size a widget can
5672 * accept while still functioning well and drawing itself correctly.
5673 * However in some strange cases a widget may be allocated less than
5674 * its requested size, and in many cases a widget may be allocated more
5675 * space than it requested.
5677 * If the size request in a given direction is -1 (unset), then
5678 * the "natural" size request of the widget will be used instead.
5680 * Widgets can't actually be allocated a size less than 1 by 1, but
5681 * you can pass 0,0 to this function to mean "as small as possible."
5684 gtk_widget_set_size_request (GtkWidget *widget,
5688 g_return_if_fail (GTK_IS_WIDGET (widget));
5689 g_return_if_fail (width >= -1);
5690 g_return_if_fail (height >= -1);
5697 gtk_widget_set_usize_internal (widget, width, height);
5702 * gtk_widget_get_size_request:
5703 * @widget: a #GtkWidget
5704 * @width: return location for width, or %NULL
5705 * @height: return location for height, or %NULL
5707 * Gets the size request that was explicitly set for the widget using
5708 * gtk_widget_set_size_request(). A value of -1 stored in @width or
5709 * @height indicates that that dimension has not been set explicitly
5710 * and the natural requisition of the widget will be used intead. See
5711 * gtk_widget_set_size_request(). To get the size a widget will
5712 * actually use, call gtk_widget_size_request() instead of
5718 gtk_widget_get_size_request (GtkWidget *widget,
5722 GtkWidgetAuxInfo *aux_info;
5724 g_return_if_fail (GTK_IS_WIDGET (widget));
5726 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
5729 *width = aux_info ? aux_info->width : -1;
5732 *height = aux_info ? aux_info->height : -1;
5736 * gtk_widget_set_events:
5737 * @widget: a #GtkWidget
5738 * @events: event mask
5740 * Sets the event mask (see #GdkEventMask) for a widget. The event
5741 * mask determines which events a widget will receive. Keep in mind
5742 * that different widgets have different default event masks, and by
5743 * changing the event mask you may disrupt a widget's functionality,
5744 * so be careful. This function must be called while a widget is
5745 * unrealized. Consider gtk_widget_add_events() for widgets that are
5746 * already realized, or if you want to preserve the existing event
5747 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
5748 * to get events on those widgets, place them inside a #GtkEventBox
5749 * and receive events on the event box.
5753 gtk_widget_set_events (GtkWidget *widget,
5758 g_return_if_fail (GTK_IS_WIDGET (widget));
5759 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
5761 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5766 eventp = g_new (gint, 1);
5769 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5774 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5777 g_object_notify (G_OBJECT (widget), "events");
5781 * gtk_widget_add_events:
5782 * @widget: a #GtkWidget
5783 * @events: an event mask, see #GdkEventMask
5785 * Adds the events in the bitfield @events to the event mask for
5786 * @widget. See gtk_widget_set_events() for details.
5790 gtk_widget_add_events (GtkWidget *widget,
5795 g_return_if_fail (GTK_IS_WIDGET (widget));
5797 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
5803 eventp = g_new (gint, 1);
5808 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, eventp);
5813 g_object_set_qdata (G_OBJECT (widget), quark_event_mask, NULL);
5816 if (GTK_WIDGET_REALIZED (widget))
5818 if (GTK_WIDGET_NO_WINDOW (widget))
5820 GList *children = gdk_window_get_children (widget->window);
5821 GList *tmp_list = children;
5825 GdkWindow *window = tmp_list->data;
5828 gdk_window_get_user_data (window, &user_data);
5829 if (user_data == widget)
5830 gdk_window_set_events (window, gdk_window_get_events (window) | events);
5831 tmp_list = tmp_list->next;
5834 g_list_free (children);
5838 gdk_window_set_events (widget->window, gdk_window_get_events (widget->window) | events);
5842 g_object_notify (G_OBJECT (widget), "events");
5846 * gtk_widget_set_extension_events:
5847 * @widget: a #GtkWidget
5848 * @mode: bitfield of extension events to receive
5850 * Sets the extension events mask to @mode. See #GdkExtensionMode
5851 * and gdk_input_set_extension_events().
5855 gtk_widget_set_extension_events (GtkWidget *widget,
5856 GdkExtensionMode mode)
5858 GdkExtensionMode *modep;
5860 g_return_if_fail (GTK_IS_WIDGET (widget));
5862 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
5865 modep = g_new (GdkExtensionMode, 1);
5868 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode, modep);
5869 g_object_notify (G_OBJECT (widget), "extension_events");
5873 * gtk_widget_get_toplevel:
5874 * @widget: a #GtkWidget
5876 * This function returns the topmost widget in the container hierarchy
5877 * @widget is a part of. If @widget has no parent widgets, it will be
5878 * returned as the topmost widget. No reference will be added to the
5879 * returned widget; it should not be unreferenced.
5881 * Note the difference in behavior vs. gtk_widget_get_ancestor();
5882 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
5884 * %NULL if @widget wasn't inside a toplevel window, and if the
5885 * window was inside a #GtkWindow-derived widget which was in turn
5886 * inside the toplevel #GtkWindow. While the second case may
5887 * seem unlikely, it actually happens when a #GtkPlug is embedded
5888 * inside a #GtkSocket within the same application.
5890 * To reliably find the toplevel #GtkWindow, use
5891 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
5892 * is set on the result.
5893 * <informalexample><programlisting>
5894 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5895 * if (GTK_WIDGET_TOPLEVEL (toplevel))
5897 * [ Perform action on toplevel. ]
5899 * </programlisting></informalexample>
5901 * Return value: the topmost ancestor of @widget, or @widget itself if there's no ancestor.
5904 gtk_widget_get_toplevel (GtkWidget *widget)
5906 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5908 while (widget->parent)
5909 widget = widget->parent;
5915 * gtk_widget_get_ancestor:
5916 * @widget: a #GtkWidget
5917 * @widget_type: ancestor type
5919 * Gets the first ancestor of @widget with type @widget_type. For example,
5920 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets the
5921 * first #GtkBox that's
5922 * an ancestor of @widget. No reference will be added to the returned widget;
5923 * it should not be unreferenced. See note about checking for a toplevel
5924 * #GtkWindow in the docs for gtk_widget_get_toplevel().
5926 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
5927 * considers @widget to be an ancestor of itself.
5929 * Return value: the ancestor widget, or %NULL if not found
5932 gtk_widget_get_ancestor (GtkWidget *widget,
5935 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5937 while (widget && !g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type))
5938 widget = widget->parent;
5940 if (!(widget && g_type_is_a (GTK_WIDGET_TYPE (widget), widget_type)))
5947 * gtk_widget_get_colormap:
5948 * @widget: a #GtkWidget
5950 * Gets the colormap that will be used to render @widget. No reference will
5951 * be added to the returned colormap; it should not be unreferenced.
5953 * Return value: the colormap used by @widget
5956 gtk_widget_get_colormap (GtkWidget *widget)
5958 GdkColormap *colormap;
5959 GtkWidget *tmp_widget;
5961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5965 colormap = gdk_drawable_get_colormap (widget->window);
5966 /* If window was destroyed previously, we'll get NULL here */
5971 tmp_widget = widget;
5974 colormap = g_object_get_qdata (G_OBJECT (tmp_widget), quark_colormap);
5978 tmp_widget= tmp_widget->parent;
5981 return gdk_screen_get_default_colormap (gtk_widget_get_screen (widget));
5985 * gtk_widget_get_visual:
5986 * @widget: a #GtkWidget
5988 * Gets the visual that will be used to render @widget.
5990 * Return value: the visual for @widget
5993 gtk_widget_get_visual (GtkWidget *widget)
5995 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5997 return gdk_colormap_get_visual (gtk_widget_get_colormap (widget));
6001 * gtk_widget_get_settings:
6002 * @widget: a #GtkWidget
6004 * Gets the settings object holding the settings (global property
6005 * settings, RC file information, etc) used for this widget.
6007 * Note that this function can only be called when the #GtkWidget
6008 * is attached to a toplevel, since the settings object is specific
6009 * to a particular #GdkScreen.
6011 * Return value: the relevant #GtkSettings object
6014 gtk_widget_get_settings (GtkWidget *widget)
6016 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6018 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
6022 * gtk_widget_set_colormap:
6023 * @widget: a #GtkWidget
6024 * @colormap: a colormap
6026 * Sets the colormap for the widget to the given value. Widget must not
6027 * have been previously realized. This probably should only be used
6028 * from an <function>init()</function> function (i.e. from the constructor
6033 gtk_widget_set_colormap (GtkWidget *widget,
6034 GdkColormap *colormap)
6036 g_return_if_fail (GTK_IS_WIDGET (widget));
6037 g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
6038 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6040 g_object_ref (colormap);
6042 g_object_set_qdata_full (G_OBJECT (widget),
6049 * gtk_widget_get_events:
6050 * @widget: a #GtkWidget
6052 * Returns the event mask for the widget (a bitfield containing flags
6053 * from the #GdkEventMask enumeration). These are the events that the widget
6056 * Return value: event mask for @widget
6059 gtk_widget_get_events (GtkWidget *widget)
6063 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6065 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6073 * gtk_widget_get_extension_events:
6074 * @widget: a #GtkWidget
6076 * Retrieves the extension events the widget will receive; see
6077 * gdk_input_set_extension_events().
6079 * Return value: extension events for @widget
6082 gtk_widget_get_extension_events (GtkWidget *widget)
6084 GdkExtensionMode *mode;
6086 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6088 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6096 * gtk_widget_get_pointer:
6097 * @widget: a #GtkWidget
6098 * @x: return location for the X coordinate, or %NULL
6099 * @y: return location for the Y coordinate, or %NULL
6101 * Obtains the location of the mouse pointer in widget coordinates.
6102 * Widget coordinates are a bit odd; for historical reasons, they are
6103 * defined as @widget->window coordinates for widgets that are not
6104 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
6105 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
6109 gtk_widget_get_pointer (GtkWidget *widget,
6113 g_return_if_fail (GTK_IS_WIDGET (widget));
6120 if (GTK_WIDGET_REALIZED (widget))
6122 gdk_window_get_pointer (widget->window, x, y, NULL);
6124 if (GTK_WIDGET_NO_WINDOW (widget))
6127 *x -= widget->allocation.x;
6129 *y -= widget->allocation.y;
6135 * gtk_widget_is_ancestor:
6136 * @widget: a #GtkWidget
6137 * @ancestor: another #GtkWidget
6139 * Determines whether @widget is somewhere inside @ancestor, possibly with
6140 * intermediate containers.
6142 * Return value: %TRUE if @ancestor contains @widget as a child, grandchild, great grandchild, etc.
6145 gtk_widget_is_ancestor (GtkWidget *widget,
6146 GtkWidget *ancestor)
6148 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6149 g_return_val_if_fail (ancestor != NULL, FALSE);
6153 if (widget->parent == ancestor)
6155 widget = widget->parent;
6161 static GQuark quark_composite_name = 0;
6164 * gtk_widget_set_composite_name:
6165 * @widget: a #GtkWidget.
6166 * @name: the name to set.
6168 * Sets a widgets composite name. The widget must be
6169 * a composite child of its parent; see gtk_widget_push_composite_child().
6172 gtk_widget_set_composite_name (GtkWidget *widget,
6175 g_return_if_fail (GTK_IS_WIDGET (widget));
6176 g_return_if_fail (GTK_WIDGET_COMPOSITE_CHILD (widget));
6177 g_return_if_fail (name != NULL);
6179 if (!quark_composite_name)
6180 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
6182 g_object_set_qdata_full (G_OBJECT (widget),
6183 quark_composite_name,
6189 * gtk_widget_get_composite_name:
6190 * @widget: a #GtkWidget.
6191 * @returns: the composite name of @widget, or %NULL if @widget is not
6192 * a composite child. The string should not be freed when it is no
6195 * Obtains the composite name of a widget.
6198 gtk_widget_get_composite_name (GtkWidget *widget)
6200 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6202 if (GTK_WIDGET_COMPOSITE_CHILD (widget) && widget->parent)
6203 return _gtk_container_child_composite_name (GTK_CONTAINER (widget->parent),
6210 * gtk_widget_push_composite_child:
6212 * Makes all newly-created widgets as composite children until
6213 * the corresponding gtk_widget_pop_composite_child() call.
6215 * A composite child is a child that's an implementation detail of the
6216 * container it's inside and should not be visible to people using the
6217 * container. Composite children aren't treated differently by GTK (but
6218 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
6219 * builders might want to treat them in a different way.
6221 * Here is a simple example:
6222 * <informalexample><programlisting>
6223 * gtk_widget_push_composite_child (<!-- -->);
6224 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
6225 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
6226 * gtk_widget_pop_composite_child (<!-- -->);
6227 * gtk_widget_set_parent (scrolled_window->hscrollbar,
6228 * GTK_WIDGET (scrolled_window));
6229 * g_object_ref (scrolled_window->hscrollbar);
6230 * </programlisting></informalexample>
6233 gtk_widget_push_composite_child (void)
6235 composite_child_stack++;
6239 * gtk_widget_pop_composite_child:
6241 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
6244 gtk_widget_pop_composite_child (void)
6246 if (composite_child_stack)
6247 composite_child_stack--;
6251 * gtk_widget_push_colormap:
6252 * @cmap: a #GdkColormap
6254 * Pushes @cmap onto a global stack of colormaps; the topmost
6255 * colormap on the stack will be used to create all widgets.
6256 * Remove @cmap with gtk_widget_pop_colormap(). There's little
6257 * reason to use this function.
6261 gtk_widget_push_colormap (GdkColormap *cmap)
6263 g_return_if_fail (!cmap || GDK_IS_COLORMAP (cmap));
6265 colormap_stack = g_slist_prepend (colormap_stack, cmap);
6269 * gtk_widget_pop_colormap:
6271 * Removes a colormap pushed with gtk_widget_push_colormap().
6275 gtk_widget_pop_colormap (void)
6278 colormap_stack = g_slist_delete_link (colormap_stack, colormap_stack);
6282 * gtk_widget_set_default_colormap:
6283 * @colormap: a #GdkColormap
6285 * Sets the default colormap to use when creating widgets.
6286 * gtk_widget_push_colormap() is a better function to use if
6287 * you only want to affect a few widgets, rather than all widgets.
6290 gtk_widget_set_default_colormap (GdkColormap *colormap)
6292 g_return_if_fail (GDK_IS_COLORMAP (colormap));
6294 gdk_screen_set_default_colormap (gdk_colormap_get_screen (colormap),
6299 * gtk_widget_get_default_colormap:
6301 * Obtains the default colormap used to create widgets.
6303 * Return value: default widget colormap
6306 gtk_widget_get_default_colormap (void)
6308 return gdk_screen_get_default_colormap (gdk_screen_get_default ());
6312 * gtk_widget_get_default_visual:
6314 * Obtains the visual of the default colormap. Not really useful;
6315 * used to be useful before gdk_colormap_get_visual() existed.
6317 * Return value: visual of the default colormap
6320 gtk_widget_get_default_visual (void)
6322 return gdk_colormap_get_visual (gtk_widget_get_default_colormap ());
6326 gtk_widget_emit_direction_changed (GtkWidget *widget,
6327 GtkTextDirection old_dir)
6329 PangoContext *context = gtk_widget_peek_pango_context (widget);
6332 pango_context_set_base_dir (context,
6333 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
6334 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
6336 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
6340 * gtk_widget_set_direction:
6341 * @widget: a #GtkWidget
6342 * @dir: the new direction
6344 * Sets the reading direction on a particular widget. This direction
6345 * controls the primary direction for widgets containing text,
6346 * and also the direction in which the children of a container are
6347 * packed. The ability to set the direction is present in order
6348 * so that correct localization into languages with right-to-left
6349 * reading directions can be done. Generally, applications will
6350 * let the default reading direction present, except for containers
6351 * where the containers are arranged in an order that is explicitely
6352 * visual rather than logical (such as buttons for text justification).
6354 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
6355 * set by gtk_widget_set_default_direction() will be used.
6358 gtk_widget_set_direction (GtkWidget *widget,
6359 GtkTextDirection dir)
6361 GtkTextDirection old_dir;
6363 g_return_if_fail (GTK_IS_WIDGET (widget));
6364 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
6366 old_dir = gtk_widget_get_direction (widget);
6368 if (dir == GTK_TEXT_DIR_NONE)
6369 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
6372 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
6373 if (dir == GTK_TEXT_DIR_LTR)
6374 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
6376 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
6379 if (old_dir != gtk_widget_get_direction (widget))
6380 gtk_widget_emit_direction_changed (widget, old_dir);
6384 * gtk_widget_get_direction:
6385 * @widget: a #GtkWidget
6387 * Gets the reading direction for a particular widget. See
6388 * gtk_widget_set_direction().
6390 * Return value: the reading direction for the widget.
6393 gtk_widget_get_direction (GtkWidget *widget)
6395 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
6397 if (GTK_WIDGET_DIRECTION_SET (widget))
6398 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
6400 return gtk_default_direction;
6404 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
6406 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
6408 g_object_ref (widget);
6410 if (!GTK_WIDGET_DIRECTION_SET (widget))
6411 gtk_widget_emit_direction_changed (widget, old_dir);
6413 if (GTK_IS_CONTAINER (widget))
6414 gtk_container_forall (GTK_CONTAINER (widget),
6415 gtk_widget_set_default_direction_recurse,
6418 g_object_unref (widget);
6422 * gtk_widget_set_default_direction:
6423 * @dir: the new default direction. This cannot be
6424 * %GTK_TEXT_DIR_NONE.
6426 * Sets the default reading direction for widgets where the
6427 * direction has not been explicitly set by gtk_widget_set_direction().
6430 gtk_widget_set_default_direction (GtkTextDirection dir)
6432 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
6434 if (dir != gtk_default_direction)
6436 GList *toplevels, *tmp_list;
6437 GtkTextDirection old_dir = gtk_default_direction;
6439 gtk_default_direction = dir;
6441 tmp_list = toplevels = gtk_window_list_toplevels ();
6442 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
6446 gtk_widget_set_default_direction_recurse (tmp_list->data,
6447 GUINT_TO_POINTER (old_dir));
6448 g_object_unref (tmp_list->data);
6449 tmp_list = tmp_list->next;
6452 g_list_free (toplevels);
6457 * gtk_widget_get_default_direction:
6459 * Obtains the current default reading direction. See
6460 * gtk_widget_set_default_direction().
6462 * Return value: the current default direction.
6465 gtk_widget_get_default_direction (void)
6467 return gtk_default_direction;
6471 gtk_widget_dispose (GObject *object)
6473 GtkWidget *widget = GTK_WIDGET (object);
6476 gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
6477 else if (GTK_WIDGET_VISIBLE (widget))
6478 gtk_widget_hide (widget);
6480 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
6481 if (GTK_WIDGET_REALIZED (widget))
6482 gtk_widget_unrealize (widget);
6484 G_OBJECT_CLASS (parent_class)->dispose (object);
6488 gtk_widget_real_destroy (GtkObject *object)
6490 /* gtk_object_destroy() will already hold a refcount on object */
6491 GtkWidget *widget = GTK_WIDGET (object);
6493 /* wipe accelerator closures (keep order) */
6494 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
6495 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
6497 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
6498 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
6500 gtk_grab_remove (widget);
6502 g_object_unref (widget->style);
6503 widget->style = gtk_widget_get_default_style ();
6504 g_object_ref (widget->style);
6506 GTK_OBJECT_CLASS (parent_class)->destroy (object);
6510 gtk_widget_finalize (GObject *object)
6512 GtkWidget *widget = GTK_WIDGET (object);
6513 GtkWidgetAuxInfo *aux_info;
6515 GdkExtensionMode *mode;
6516 GtkAccessible *accessible;
6518 gtk_grab_remove (widget);
6520 g_object_unref (widget->style);
6521 widget->style = NULL;
6524 g_free (widget->name);
6526 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
6528 gtk_widget_aux_info_destroy (aux_info);
6530 events = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
6534 mode = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
6538 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
6540 g_object_unref (accessible);
6542 G_OBJECT_CLASS (parent_class)->finalize (object);
6545 /*****************************************
6546 * gtk_widget_real_map:
6551 *****************************************/
6554 gtk_widget_real_map (GtkWidget *widget)
6556 g_return_if_fail (GTK_WIDGET_REALIZED (widget) == TRUE);
6558 if (!GTK_WIDGET_MAPPED (widget))
6560 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
6562 if (!GTK_WIDGET_NO_WINDOW (widget))
6563 gdk_window_show (widget->window);
6567 /*****************************************
6568 * gtk_widget_real_unmap:
6573 *****************************************/
6576 gtk_widget_real_unmap (GtkWidget *widget)
6578 if (GTK_WIDGET_MAPPED (widget))
6580 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6582 if (!GTK_WIDGET_NO_WINDOW (widget))
6583 gdk_window_hide (widget->window);
6587 /*****************************************
6588 * gtk_widget_real_realize:
6593 *****************************************/
6596 gtk_widget_real_realize (GtkWidget *widget)
6598 g_return_if_fail (GTK_WIDGET_NO_WINDOW (widget));
6600 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
6603 widget->window = gtk_widget_get_parent_window (widget);
6604 g_object_ref (widget->window);
6606 widget->style = gtk_style_attach (widget->style, widget->window);
6609 /*****************************************
6610 * gtk_widget_real_unrealize:
6615 *****************************************/
6618 gtk_widget_real_unrealize (GtkWidget *widget)
6620 if (GTK_WIDGET_MAPPED (widget))
6621 gtk_widget_real_unmap (widget);
6623 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
6625 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
6628 /* We must do unrealize child widget BEFORE container widget.
6629 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
6630 * So, unrealizing container widget bofore its children causes the problem
6631 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
6634 if (GTK_IS_CONTAINER (widget))
6635 gtk_container_forall (GTK_CONTAINER (widget),
6636 (GtkCallback) gtk_widget_unrealize,
6639 gtk_style_detach (widget->style);
6640 if (!GTK_WIDGET_NO_WINDOW (widget))
6642 gdk_window_set_user_data (widget->window, NULL);
6643 gdk_window_destroy (widget->window);
6644 widget->window = NULL;
6648 g_object_unref (widget->window);
6649 widget->window = NULL;
6652 gtk_selection_remove_all (widget);
6654 GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);
6658 gtk_widget_real_size_request (GtkWidget *widget,
6659 GtkRequisition *requisition)
6661 requisition->width = widget->requisition.width;
6662 requisition->height = widget->requisition.height;
6666 * _gtk_widget_peek_colormap:
6668 * Returns colormap currently pushed by gtk_widget_push_colormap, if any.
6670 * Return value: the currently pushed colormap, or %NULL if there is none.
6673 _gtk_widget_peek_colormap (void)
6676 return (GdkColormap*) colormap_stack->data;
6681 gtk_widget_propagate_state (GtkWidget *widget,
6686 /* don't call this function with state==GTK_STATE_INSENSITIVE,
6687 * parent_sensitive==TRUE on a sensitive widget
6690 old_state = GTK_WIDGET_STATE (widget);
6692 if (data->parent_sensitive)
6694 GTK_WIDGET_SET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6696 if (GTK_WIDGET_IS_SENSITIVE (widget))
6698 if (data->state_restoration)
6699 GTK_WIDGET_STATE (widget) = GTK_WIDGET_SAVED_STATE (widget);
6701 GTK_WIDGET_STATE (widget) = data->state;
6705 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6706 if (!data->state_restoration &&
6707 data->state != GTK_STATE_INSENSITIVE)
6708 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6713 GTK_WIDGET_UNSET_FLAGS (widget, GTK_PARENT_SENSITIVE);
6714 if (!data->state_restoration)
6716 if (data->state != GTK_STATE_INSENSITIVE)
6717 GTK_WIDGET_SAVED_STATE (widget) = data->state;
6719 else if (GTK_WIDGET_STATE (widget) != GTK_STATE_INSENSITIVE)
6720 GTK_WIDGET_SAVED_STATE (widget) = GTK_WIDGET_STATE (widget);
6721 GTK_WIDGET_STATE (widget) = GTK_STATE_INSENSITIVE;
6724 if (gtk_widget_is_focus (widget) && !GTK_WIDGET_IS_SENSITIVE (widget))
6728 window = gtk_widget_get_toplevel (widget);
6729 if (window && GTK_WIDGET_TOPLEVEL (window))
6730 gtk_window_set_focus (GTK_WINDOW (window), NULL);
6733 if (old_state != GTK_WIDGET_STATE (widget))
6735 g_object_ref (widget);
6737 if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
6738 gtk_grab_remove (widget);
6740 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
6742 if (GTK_IS_CONTAINER (widget))
6744 data->parent_sensitive = (GTK_WIDGET_IS_SENSITIVE (widget) != FALSE);
6745 data->state = GTK_WIDGET_STATE (widget);
6746 if (data->use_forall)
6747 gtk_container_forall (GTK_CONTAINER (widget),
6748 (GtkCallback) gtk_widget_propagate_state,
6751 gtk_container_foreach (GTK_CONTAINER (widget),
6752 (GtkCallback) gtk_widget_propagate_state,
6755 g_object_unref (widget);
6760 * _gtk_widget_get_aux_info:
6761 * @widget: a #GtkWidget
6762 * @create: if %TRUE, create the structure if it doesn't exist
6764 * Get the #GtkWidgetAuxInfo structure for the widget.
6766 * Return value: the #GtkAuxInfo structure for the widget, or
6767 * %NULL if @create is %FALSE and one doesn't already exist.
6770 _gtk_widget_get_aux_info (GtkWidget *widget,
6773 GtkWidgetAuxInfo *aux_info;
6775 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
6776 if (!aux_info && create)
6778 if (!aux_info_mem_chunk)
6779 aux_info_mem_chunk = g_mem_chunk_new ("widget aux info mem chunk",
6780 sizeof (GtkWidgetAuxInfo),
6781 1024, G_ALLOC_AND_FREE);
6782 aux_info = g_chunk_new (GtkWidgetAuxInfo, aux_info_mem_chunk);
6784 aux_info->width = -1;
6785 aux_info->height = -1;
6788 aux_info->x_set = FALSE;
6789 aux_info->y_set = FALSE;
6790 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
6796 /*****************************************
6797 * gtk_widget_aux_info_destroy:
6802 *****************************************/
6805 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
6807 g_mem_chunk_free (aux_info_mem_chunk, aux_info);
6811 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
6813 g_object_unref (info->shape_mask);
6818 * gtk_widget_shape_combine_mask:
6819 * @widget: a #GtkWidget.
6820 * @shape_mask: shape to be added, or %NULL to remove an existing shape.
6821 * @offset_x: X position of shape mask with respect to @window.
6822 * @offset_y: Y position of shape mask with respect to @window.
6824 * Sets a shape for this widget's GDK window. This allows for
6825 * transparent windows etc., see gdk_window_shape_combine_mask()
6826 * for more information.
6829 gtk_widget_shape_combine_mask (GtkWidget *widget,
6830 GdkBitmap *shape_mask,
6834 GtkWidgetShapeInfo* shape_info;
6836 g_return_if_fail (GTK_IS_WIDGET (widget));
6837 /* set_shape doesn't work on widgets without gdk window */
6838 g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
6842 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6845 gdk_window_shape_combine_mask (widget->window, NULL, 0, 0);
6847 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
6851 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
6853 shape_info = g_new (GtkWidgetShapeInfo, 1);
6854 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
6855 (GDestroyNotify) gtk_widget_shape_info_destroy);
6857 shape_info->shape_mask = g_object_ref (shape_mask);
6858 shape_info->offset_x = offset_x;
6859 shape_info->offset_y = offset_y;
6861 /* set shape if widget has a gdk window allready.
6862 * otherwise the shape is scheduled to be set by gtk_widget_realize.
6865 gdk_window_shape_combine_mask (widget->window, shape_mask,
6866 offset_x, offset_y);
6871 gtk_reset_shapes_recurse (GtkWidget *widget,
6877 gdk_window_get_user_data (window, &data);
6881 gdk_window_shape_combine_mask (window, NULL, 0, 0);
6882 for (list = gdk_window_peek_children (window); list; list = list->next)
6883 gtk_reset_shapes_recurse (widget, list->data);
6887 * gtk_widget_reset_shapes:
6888 * @widget: a #GtkWidget.
6890 * Recursively resets the shape on this widget and its descendants.
6893 gtk_widget_reset_shapes (GtkWidget *widget)
6895 g_return_if_fail (GTK_IS_WIDGET (widget));
6896 g_return_if_fail (GTK_WIDGET_REALIZED (widget));
6898 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
6899 gtk_reset_shapes_recurse (widget, widget->window);
6904 * @widget: a #GtkWidget
6906 * Adds a reference to a widget. This function is exactly the same
6907 * as calling g_object_ref(), and exists mostly for historical
6908 * reasons. It can still be convenient to avoid casting a widget
6909 * to a #GObject, it saves a small amount of typing.
6911 * Return value: the widget that was referenced
6914 gtk_widget_ref (GtkWidget *widget)
6916 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6918 return (GtkWidget*) g_object_ref ((GObject*) widget);
6923 * @widget: a #GtkWidget
6925 * Inverse of gtk_widget_ref(). Equivalent to g_object_unref().
6929 gtk_widget_unref (GtkWidget *widget)
6931 g_return_if_fail (GTK_IS_WIDGET (widget));
6933 g_object_unref ((GObject*) widget);
6941 * gtk_widget_class_install_style_property_parser:
6942 * @klass: a #GtkWidgetClass
6943 * @pspec: the #GParamSpec for the style property
6944 * @parser: the parser for the style property
6946 * Installs a style property on a widget class.
6949 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
6951 GtkRcPropertyParser parser)
6953 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6954 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6955 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
6956 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
6958 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
6960 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
6961 G_OBJECT_CLASS_NAME (klass),
6966 g_param_spec_ref (pspec);
6967 g_param_spec_sink (pspec);
6968 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
6969 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
6973 * gtk_widget_class_install_style_property:
6974 * @klass: a #GtkWidgetClass
6975 * @pspec: the #GParamSpec for the property
6977 * Installs a style property on a widget class. The parser for the
6978 * style property is determined by the value type of @pspec.
6981 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
6984 GtkRcPropertyParser parser;
6986 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
6987 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
6989 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
6991 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
6995 * gtk_widget_class_find_style_property:
6996 * @klass: a #GtkWidgetClass
6997 * @property_name: the name of the style property to find
6998 * @returns: the #GParamSpec of the style property or %NULL if @class has no
6999 * style property with that name.
7001 * Finds a style property of a widget class by name.
7006 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
7007 const gchar *property_name)
7009 g_return_val_if_fail (property_name != NULL, NULL);
7011 return g_param_spec_pool_lookup (style_property_spec_pool,
7013 G_OBJECT_CLASS_TYPE (klass),
7018 * gtk_widget_class_list_style_properties:
7019 * @klass: a #GtkWidgetClass
7020 * @n_properties: location to return the number of style properties found
7021 * @returns: an newly allocated array of #GParamSpec*. The array must be freed with g_free().
7023 * Returns all style properties of a widget class.
7028 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
7029 guint *n_properties)
7031 GParamSpec **pspecs;
7034 pspecs = g_param_spec_pool_list (style_property_spec_pool,
7035 G_OBJECT_CLASS_TYPE (klass),
7044 * gtk_widget_style_get_property:
7045 * @widget: a #GtkWidget
7046 * @property_name: the name of a style property
7047 * @value: location to return the property value
7049 * Gets the value of a style property of @widget.
7052 gtk_widget_style_get_property (GtkWidget *widget,
7053 const gchar *property_name,
7058 g_return_if_fail (GTK_IS_WIDGET (widget));
7059 g_return_if_fail (property_name != NULL);
7060 g_return_if_fail (G_IS_VALUE (value));
7062 g_object_ref (widget);
7063 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7065 G_OBJECT_TYPE (widget),
7068 g_warning ("%s: widget class `%s' has no property named `%s'",
7070 G_OBJECT_TYPE_NAME (widget),
7074 const GValue *peek_value;
7076 peek_value = _gtk_style_peek_property_value (widget->style,
7077 G_OBJECT_TYPE (widget),
7079 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7081 /* auto-conversion of the caller's value type
7083 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
7084 g_value_copy (peek_value, value);
7085 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
7086 g_value_transform (peek_value, value);
7088 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
7090 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
7091 G_VALUE_TYPE_NAME (value));
7093 g_object_unref (widget);
7097 * gtk_widget_style_get_valist:
7098 * @widget: a #GtkWidget
7099 * @first_property_name: the name of the first property to get
7100 * @var_args: a <type>va_list</type> of pairs of property names and
7101 * locations to return the property values, starting with the location
7102 * for @first_property_name.
7104 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
7108 gtk_widget_style_get_valist (GtkWidget *widget,
7109 const gchar *first_property_name,
7114 g_return_if_fail (GTK_IS_WIDGET (widget));
7116 g_object_ref (widget);
7118 name = first_property_name;
7121 const GValue *peek_value;
7125 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
7127 G_OBJECT_TYPE (widget),
7131 g_warning ("%s: widget class `%s' has no property named `%s'",
7133 G_OBJECT_TYPE_NAME (widget),
7137 /* style pspecs are always readable so we can spare that check here */
7139 peek_value = _gtk_style_peek_property_value (widget->style,
7140 G_OBJECT_TYPE (widget),
7142 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
7143 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
7146 g_warning ("%s: %s", G_STRLOC, error);
7151 name = va_arg (var_args, gchar*);
7154 g_object_unref (widget);
7158 * gtk_widget_style_get:
7159 * @widget: a #GtkWidget
7160 * @first_property_name: the name of the first property to get
7161 * @Varargs: pairs of property names and locations to
7162 * return the property values, starting with the location for
7163 * @first_property_name, terminated by %NULL.
7165 * Gets the values of a multiple style properties of @widget.
7168 gtk_widget_style_get (GtkWidget *widget,
7169 const gchar *first_property_name,
7174 g_return_if_fail (GTK_IS_WIDGET (widget));
7176 va_start (var_args, first_property_name);
7177 gtk_widget_style_get_valist (widget, first_property_name, var_args);
7183 * @widget: a #GtkWidget
7184 * @path_length: location to store length of the path, or %NULL
7185 * @path: location to store allocated path string, or %NULL
7186 * @path_reversed: location to store allocated reverse path string, or %NULL
7188 * Obtains the full path to @widget. The path is simply the name of a
7189 * widget and all its parents in the container hierarchy, separated by
7190 * periods. The name of a widget comes from
7191 * gtk_widget_get_name(). Paths are used to apply styles to a widget
7192 * in gtkrc configuration files. Widget names are the type of the
7193 * widget by default (e.g. "GtkButton") or can be set to an
7194 * application-specific value with gtk_widget_set_name(). By setting
7195 * the name of a widget, you allow users or theme authors to apply
7196 * styles to that specific widget in their gtkrc
7197 * file. @path_reversed_p fills in the path in reverse order,
7198 * i.e. starting with @widget's name instead of starting with the name
7199 * of @widget's outermost ancestor.
7203 gtk_widget_path (GtkWidget *widget,
7206 gchar **path_reversed)
7208 static gchar *rev_path = NULL;
7209 static guint tmp_path_len = 0;
7212 g_return_if_fail (GTK_IS_WIDGET (widget));
7217 const gchar *string;
7222 string = gtk_widget_get_name (widget);
7223 l = strlen (string);
7224 while (tmp_path_len <= len + l + 1)
7226 tmp_path_len += INIT_PATH_SIZE;
7227 rev_path = g_realloc (rev_path, tmp_path_len);
7235 widget = widget->parent;
7238 rev_path[len++] = '.';
7240 rev_path[len++] = 0;
7245 *path_length = len - 1;
7247 *path_reversed = g_strdup (rev_path);
7250 *path = g_strdup (rev_path);
7251 g_strreverse (*path);
7256 * gtk_widget_class_path:
7257 * @widget: a #GtkWidget
7258 * @path_length: location to store the length of the class path, or %NULL
7259 * @path: location to store the class path as an allocated string, or %NULL
7260 * @path_reversed: location to store the reverse class path as an allocated string, or %NULL
7262 * Same as gtk_widget_path(), but always uses the name of a widget's type,
7263 * never uses a custom name set with gtk_widget_set_name().
7267 gtk_widget_class_path (GtkWidget *widget,
7270 gchar **path_reversed)
7272 static gchar *rev_path = NULL;
7273 static guint tmp_path_len = 0;
7276 g_return_if_fail (GTK_IS_WIDGET (widget));
7281 const gchar *string;
7286 string = g_type_name (GTK_WIDGET_TYPE (widget));
7287 l = strlen (string);
7288 while (tmp_path_len <= len + l + 1)
7290 tmp_path_len += INIT_PATH_SIZE;
7291 rev_path = g_realloc (rev_path, tmp_path_len);
7299 widget = widget->parent;
7302 rev_path[len++] = '.';
7304 rev_path[len++] = 0;
7309 *path_length = len - 1;
7311 *path_reversed = g_strdup (rev_path);
7314 *path = g_strdup (rev_path);
7315 g_strreverse (*path);
7320 * gtk_requisition_copy:
7321 * @requisition: a #GtkRequisition.
7322 * @returns: a copy of @requisition.
7324 * Copies a #GtkRequisition.
7327 gtk_requisition_copy (const GtkRequisition *requisition)
7329 return (GtkRequisition *)g_memdup (requisition, sizeof (GtkRequisition));
7333 * gtk_requisition_free:
7334 * @requisition: a #GtkRequisition.
7336 * Frees a #GtkRequisition.
7339 gtk_requisition_free (GtkRequisition *requisition)
7341 g_free (requisition);
7345 gtk_requisition_get_type (void)
7347 static GType our_type = 0;
7350 our_type = g_boxed_type_register_static ("GtkRequisition",
7351 (GBoxedCopyFunc) gtk_requisition_copy,
7352 (GBoxedFreeFunc) gtk_requisition_free);
7358 * gtk_widget_get_accessible:
7359 * @widget: a #GtkWidget
7361 * Returns the accessible object that describes the widget to an
7362 * assistive technology.
7364 * If no accessibility library is loaded (i.e. no ATK implementation library is
7365 * loaded via <envar>GTK_MODULES</envar> or via another application library,
7366 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
7367 * if no class-specific #AtkObject implementation is available for the widget
7368 * instance in question, it will inherit an #AtkObject implementation from the
7369 * first ancestor class for which such an implementation is defined.
7371 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
7372 * library contains more information about accessible objects and their uses.
7374 * Returns: the #AtkObject associated with @widget
7377 gtk_widget_get_accessible (GtkWidget *widget)
7379 GtkWidgetClass *klass;
7381 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7383 klass = GTK_WIDGET_GET_CLASS (widget);
7385 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
7387 return klass->get_accessible (widget);
7391 gtk_widget_real_get_accessible (GtkWidget *widget)
7393 AtkObject* accessible;
7395 accessible = g_object_get_qdata (G_OBJECT (widget),
7396 quark_accessible_object);
7399 AtkObjectFactory *factory;
7400 AtkRegistry *default_registry;
7402 default_registry = atk_get_default_registry ();
7403 factory = atk_registry_get_factory (default_registry,
7404 G_TYPE_FROM_INSTANCE (widget));
7406 atk_object_factory_create_accessible (factory,
7408 g_object_set_qdata (G_OBJECT (widget),
7409 quark_accessible_object,
7416 * Initialize a AtkImplementorIface instance's virtual pointers as
7417 * appropriate to this implementor's class (GtkWidget).
7420 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
7422 iface->ref_accessible = gtk_widget_ref_accessible;
7426 gtk_widget_ref_accessible (AtkImplementor *implementor)
7428 AtkObject *accessible;
7430 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
7432 g_object_ref (accessible);
7437 * gtk_widget_get_clipboard:
7438 * @widget: a #GtkWidget
7439 * @selection: a #GdkAtom which identifies the clipboard
7440 * to use. %GDK_SELECTION_CLIPBOARD gives the
7441 * default clipboard. Another common value
7442 * is %GDK_SELECTION_PRIMARY, which gives
7443 * the primary X selection.
7445 * Returns the clipboard object for the given selection to
7446 * be used with @widget. @widget must have a #GdkDisplay
7447 * associated with it, so must be attached to a toplevel
7450 * Return value: the appropriate clipboard object. If no
7451 * clipboard already exists, a new one will
7452 * be created. Once a clipboard object has
7453 * been created, it is persistent for all time.
7458 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
7460 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7461 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
7463 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
7468 * gtk_widget_list_mnemonic_labels:
7469 * @widget: a #GtkWidget
7471 * Returns a newly allocated list of the widgets, normally labels, for
7472 * which this widget is a the target of a mnemonic (see for example,
7473 * gtk_label_set_mnemonic_widget()).
7475 * The widgets in the list are not individually referenced. If you
7476 * want to iterate through the list and perform actions involving
7477 * callbacks that might destroy the widgets, you
7478 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
7479 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
7480 * widgets afterwards.
7482 * Return value: the list of mnemonic labels; free this list
7483 * with g_list_free() when you are done with it.
7488 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
7493 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7495 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
7496 list = g_list_prepend (list, l->data);
7502 * gtk_widget_add_mnemonic_label:
7503 * @widget: a #GtkWidget
7504 * @label: a #GtkWidget that acts as a mnemonic label for @widget.
7506 * Adds a widget to the list of mnemonic labels for
7507 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
7508 * list of mnemonic labels for the widget is cleared when the
7509 * widget is destroyed, so the caller must make sure to update
7510 * its internal state at this point as well, by using a connection
7511 * to the ::destroy signal or a weak notifier.
7516 gtk_widget_add_mnemonic_label (GtkWidget *widget,
7519 GSList *old_list, *new_list;
7521 g_return_if_fail (GTK_IS_WIDGET (widget));
7522 g_return_if_fail (GTK_IS_WIDGET (label));
7524 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7525 new_list = g_slist_prepend (old_list, label);
7527 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7528 new_list, (GDestroyNotify) g_slist_free);
7532 * gtk_widget_remove_mnemonic_label:
7533 * @widget: a #GtkWidget
7534 * @label: a #GtkWidget that was previously set as a mnemnic label for
7535 * @widget with gtk_widget_add_mnemonic_label().
7537 * Removes a widget from the list of mnemonic labels for
7538 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
7539 * must have previously been added to the list with
7540 * gtk_widget_add_mnemonic_label().
7545 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
7548 GSList *old_list, *new_list;
7550 g_return_if_fail (GTK_IS_WIDGET (widget));
7551 g_return_if_fail (GTK_IS_WIDGET (label));
7553 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
7554 new_list = g_slist_remove (old_list, label);
7557 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
7558 new_list, (GDestroyNotify) g_slist_free);
7562 * gtk_widget_get_no_show_all:
7563 * @widget: a #GtkWidget
7565 * Returns the current value of the "no_show_all" property, which determines
7566 * whether calls to gtk_widget_show_all() and gtk_widget_hide_all()
7567 * will affect this widget.
7569 * Return value: the current value of the "no_show_all" property.
7574 gtk_widget_get_no_show_all (GtkWidget *widget)
7576 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7578 return (GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
7582 * gtk_widget_set_no_show_all:
7583 * @widget: a #GtkWidget
7584 * @no_show_all: the new value for the "no_show_all" property
7586 * Sets the "no_show_all" property, which determines whether calls to
7587 * gtk_widget_show_all() and gtk_widget_hide_all() will affect this widget.
7589 * This is mostly for use in constructing widget hierarchies with externally
7590 * controlled visibility, see #GtkUIManager.
7595 gtk_widget_set_no_show_all (GtkWidget *widget,
7596 gboolean no_show_all)
7598 g_return_if_fail (GTK_IS_WIDGET (widget));
7600 no_show_all = (no_show_all != FALSE);
7602 if (no_show_all == ((GTK_WIDGET_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0))
7606 GTK_WIDGET_SET_FLAGS (widget, GTK_NO_SHOW_ALL);
7608 GTK_WIDGET_UNSET_FLAGS (widget, GTK_NO_SHOW_ALL);
7610 g_object_notify (G_OBJECT (widget), "no_show_all");
7613 #define __GTK_WIDGET_C__
7614 #include "gtkaliasdef.c"